1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2011 The Chromium OS Authors.
4 * (C) Copyright 2008,2009
5 * Graeme Russ, <graeme.russ@gmail.com>
8 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
19 int pci_x86_read_config(pci_dev_t bdf, uint offset, ulong *valuep,
22 outl(bdf | (offset & 0xfc) | PCI_CFG_EN, PCI_REG_ADDR);
25 *valuep = inb(PCI_REG_DATA + (offset & 3));
28 *valuep = inw(PCI_REG_DATA + (offset & 2));
31 *valuep = inl(PCI_REG_DATA);
38 int pci_x86_write_config(pci_dev_t bdf, uint offset, ulong value,
41 outl(bdf | (offset & 0xfc) | PCI_CFG_EN, PCI_REG_ADDR);
44 outb(value, PCI_REG_DATA + (offset & 3));
47 outw(value, PCI_REG_DATA + (offset & 2));
50 outl(value, PCI_REG_DATA);
57 int pci_x86_clrset_config(pci_dev_t bdf, uint offset, ulong clr, ulong set,
63 ret = pci_x86_read_config(bdf, offset, &value, size);
69 return pci_x86_write_config(bdf, offset, value, size);
72 void pci_assign_irqs(int bus, int device, u8 irq[4])
79 for (func = 0; func < 8; func++) {
80 bdf = PCI_BDF(bus, device, func);
81 pci_read_config16(bdf, PCI_VENDOR_ID, &vendor);
82 if (vendor == 0xffff || vendor == 0x0000)
85 pci_read_config8(bdf, PCI_INTERRUPT_PIN, &pin);
87 /* PCI spec says all values except 1..4 are reserved */
88 if ((pin < 1) || (pin > 4))
95 debug("Assigning IRQ %d to PCI device %d.%x.%d (INT%c)\n",
96 line, bus, device, func, 'A' + pin - 1);
98 pci_write_config8(bdf, PCI_INTERRUPT_LINE, line);