1 // PCI config space access functions.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU GPLv3 license.
8 #include "pci.h" // PCIDevice
9 #include "ioport.h" // outl
11 void pci_config_writel(PCIDevice d, u32 addr, u32 val)
13 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
15 outl(val, PORT_PCI_DATA);
18 void pci_config_writew(PCIDevice d, u32 addr, u16 val)
20 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
22 outw(val, PORT_PCI_DATA + (addr & 2));
25 void pci_config_writeb(PCIDevice d, u32 addr, u8 val)
27 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
29 outb(val, PORT_PCI_DATA + (addr & 3));
32 u32 pci_config_readl(PCIDevice d, u32 addr)
34 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
36 return inl(PORT_PCI_DATA);
39 u16 pci_config_readw(PCIDevice d, u32 addr)
41 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
43 return inw(PORT_PCI_DATA + (addr & 2));
46 u8 pci_config_readb(PCIDevice d, u32 addr)
48 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
50 return inb(PORT_PCI_DATA + (addr & 3));
54 pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev)
57 u32 id = (devid << 16) | vendid;
58 for (devfn=0; devfn<0x100; devfn++) {
59 PCIDevice d = pci_bd(0, devfn);
60 u32 v = pci_config_readl(d, 0x00);
75 pci_find_class(u32 classid, int index, PCIDevice *dev)
78 u32 id = classid << 8;
79 for (devfn=0; devfn<0x100; devfn++) {
80 PCIDevice d = pci_bd(0, devfn);
81 u32 v = pci_config_readl(d, 0x08);