2 * Copyright (c) 2011 The Chromium OS Authors.
3 * (C) Copyright 2008,2009
4 * Graeme Russ, <graeme.russ@gmail.com>
7 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
9 * SPDX-License-Identifier: GPL-2.0+
20 DECLARE_GLOBAL_DATA_PTR;
22 int pci_x86_read_config(struct udevice *bus, pci_dev_t bdf, uint offset,
23 ulong *valuep, enum pci_size_t size)
25 outl(bdf | (offset & 0xfc) | PCI_CFG_EN, PCI_REG_ADDR);
28 *valuep = inb(PCI_REG_DATA + (offset & 3));
31 *valuep = inw(PCI_REG_DATA + (offset & 2));
34 *valuep = inl(PCI_REG_DATA);
41 int pci_x86_write_config(struct udevice *bus, pci_dev_t bdf, uint offset,
42 ulong value, enum pci_size_t size)
44 outl(bdf | (offset & 0xfc) | PCI_CFG_EN, PCI_REG_ADDR);
47 outb(value, PCI_REG_DATA + (offset & 3));
50 outw(value, PCI_REG_DATA + (offset & 2));
53 outl(value, PCI_REG_DATA);
60 void pci_assign_irqs(int bus, int device, u8 irq[4])
67 for (func = 0; func < 8; func++) {
68 bdf = PCI_BDF(bus, device, func);
69 pci_read_config16(bdf, PCI_VENDOR_ID, &vendor);
70 if (vendor == 0xffff || vendor == 0x0000)
73 pci_read_config8(bdf, PCI_INTERRUPT_PIN, &pin);
75 /* PCI spec says all values except 1..4 are reserved */
76 if ((pin < 1) || (pin > 4))
83 debug("Assigning IRQ %d to PCI device %d.%x.%d (INT%c)\n",
84 line, bus, device, func, 'A' + pin - 1);
86 pci_write_config8(bdf, PCI_INTERRUPT_LINE, line);