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
10 #include "util.h" // dprintf
14 void pci_config_writel(PCIDevice d, u32 addr, u32 val)
16 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
18 outl(val, PORT_PCI_DATA);
21 void pci_config_writew(PCIDevice d, u32 addr, u16 val)
23 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
25 outw(val, PORT_PCI_DATA + (addr & 2));
28 void pci_config_writeb(PCIDevice d, u32 addr, u8 val)
30 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
32 outb(val, PORT_PCI_DATA + (addr & 3));
35 u32 pci_config_readl(PCIDevice d, u32 addr)
37 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
39 return inl(PORT_PCI_DATA);
42 u16 pci_config_readw(PCIDevice d, u32 addr)
44 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
46 return inw(PORT_PCI_DATA + (addr & 2));
49 u8 pci_config_readb(PCIDevice d, u32 addr)
51 outl(0x80000000 | (d.bus << 16) | (d.devfn << 8) | (addr & 0xfc)
53 return inb(PORT_PCI_DATA + (addr & 3));
57 pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev)
60 u32 id = (devid << 16) | vendid;
61 for (bus=0; bus < MAX_BUS; bus++) {
62 for (devfn=0; devfn<0x100; devfn++) {
63 PCIDevice d = pci_bd(bus, devfn);
64 u32 v = pci_config_readl(d, 0x00);
80 pci_find_class(u32 classid, int index, PCIDevice *dev)
83 for (bus=0; bus < MAX_BUS; bus++) {
84 for (devfn=0; devfn<0x100; devfn++) {
85 PCIDevice d = pci_bd(bus, devfn);
86 u32 v = pci_config_readl(d, 0x08);
87 if ((v>>8) != classid)