20 #include "pedigree/kernel/machine/Pci.h" 21 #include "pedigree/kernel/Log.h" 22 #include "pedigree/kernel/machine/Device.h" 23 #include "pedigree/kernel/processor/IoPort.h" 24 #include "pedigree/kernel/processor/types.h" 25 #include "pedigree/kernel/utilities/utility.h" 27 #define CONFIG_ADDRESS 0 32 static IoPort configSpace(
"PCI config space");
40 uint32_t
function : 3;
43 uint32_t reserved : 7;
63 ERROR(
"PCI: Config space - unable to allocate IO port!");
67 configSpace.
write32(0x80000000, CONFIG_ADDRESS);
68 if (configSpace.
read32(CONFIG_ADDRESS) != 0x80000000)
70 ERROR(
"PCI: Controller not detected.");
78 ByteSet(&addr, 0,
sizeof(addr));
85 configSpace.
write32(addr.raw, CONFIG_ADDRESS);
86 return configSpace.
read32(CONFIG_DATA);
90 uint8_t bus, uint8_t device, uint8_t
function, uint8_t offset)
93 ByteSet(&addr, 0,
sizeof(addr));
95 addr.function =
function;
100 configSpace.
write32(addr.raw, CONFIG_ADDRESS);
101 return configSpace.
read32(CONFIG_DATA);
107 ByteSet(&addr, 0,
sizeof(addr));
108 addr.offset = offset;
114 configSpace.
write32(addr.raw, CONFIG_ADDRESS);
115 configSpace.
write32(data, CONFIG_DATA);
119 uint8_t bus, uint8_t device, uint8_t
function, uint8_t offset,
123 ByteSet(&addr, 0,
sizeof(addr));
124 addr.offset = offset;
125 addr.function =
function;
126 addr.device = device;
130 configSpace.
write32(addr.raw, CONFIG_ADDRESS);
131 configSpace.
write32(data, CONFIG_DATA);
uint32_t getPciDevicePosition()
uint32_t getPciBusPosition()
virtual void write32(uint32_t value, size_t offset=0)
uint32_t getPciFunctionNumber()
uint32_t readConfigSpace(Device *pDev, uint8_t offset)
bool allocate(io_port_t ioPort, size_t size)
virtual uint32_t read32(size_t offset=0)
void writeConfigSpace(Device *pDev, uint8_t offset, uint32_t data)