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 static struct pci_controller *get_hose(void)
27 return pci_bus_to_hose(0);
30 unsigned int x86_pci_read_config8(pci_dev_t dev, unsigned where)
34 if (pci_hose_read_config_byte(get_hose(), dev, where, &value))
40 unsigned int x86_pci_read_config16(pci_dev_t dev, unsigned where)
44 if (pci_hose_read_config_word(get_hose(), dev, where, &value))
50 unsigned int x86_pci_read_config32(pci_dev_t dev, unsigned where)
54 if (pci_hose_read_config_dword(get_hose(), dev, where, &value))
60 void x86_pci_write_config8(pci_dev_t dev, unsigned where, unsigned value)
62 pci_hose_write_config_byte(get_hose(), dev, where, value);
65 void x86_pci_write_config16(pci_dev_t dev, unsigned where, unsigned value)
67 pci_hose_write_config_word(get_hose(), dev, where, value);
70 void x86_pci_write_config32(pci_dev_t dev, unsigned where, unsigned value)
72 pci_hose_write_config_dword(get_hose(), dev, where, value);
75 int pci_x86_read_config(struct udevice *bus, pci_dev_t bdf, uint offset,
76 ulong *valuep, enum pci_size_t size)
78 outl(bdf | (offset & 0xfc) | PCI_CFG_EN, PCI_REG_ADDR);
81 *valuep = inb(PCI_REG_DATA + (offset & 3));
84 *valuep = inw(PCI_REG_DATA + (offset & 2));
87 *valuep = inl(PCI_REG_DATA);
94 int pci_x86_write_config(struct udevice *bus, pci_dev_t bdf, uint offset,
95 ulong value, enum pci_size_t size)
97 outl(bdf | (offset & 0xfc) | PCI_CFG_EN, PCI_REG_ADDR);
100 outb(value, PCI_REG_DATA + (offset & 3));
103 outw(value, PCI_REG_DATA + (offset & 2));
106 outl(value, PCI_REG_DATA);
113 void pci_assign_irqs(int bus, int device, u8 irq[4])
120 for (func = 0; func < 8; func++) {
121 bdf = PCI_BDF(bus, device, func);
122 vendor = x86_pci_read_config16(bdf, PCI_VENDOR_ID);
123 if (vendor == 0xffff || vendor == 0x0000)
126 pin = x86_pci_read_config8(bdf, PCI_INTERRUPT_PIN);
128 /* PCI spec says all values except 1..4 are reserved */
129 if ((pin < 1) || (pin > 4))
136 debug("Assigning IRQ %d to PCI device %d.%x.%d (INT%c)\n",
137 line, bus, device, func, 'A' + pin - 1);
139 x86_pci_write_config8(bdf, PCI_INTERRUPT_LINE, line);