43 lines
1.1 KiB
C
43 lines
1.1 KiB
C
#include <kernel/x86/io.h>
|
|
#include <kernel/x86/pci.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
/**
|
|
* None of this is working. I'm assuming that QEMU (and bochs) are using pcie purely memory mapped, without legacy PCI support
|
|
*
|
|
* so we'll need to setup ACPI first :)
|
|
*/
|
|
|
|
uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset)
|
|
{
|
|
uint32_t address;
|
|
uint32_t lbus = (uint32_t) bus;
|
|
uint32_t lslot = (uint32_t) slot;
|
|
uint32_t lfunc = (uint32_t) func;
|
|
uint16_t tmp = 0;
|
|
|
|
|
|
address = (uint32_t) ((lbus << 16) | (lslot << 11) |
|
|
(lfunc << 8) | (offset & 0xFC) | ((uint32_t) 0x80000000));
|
|
|
|
printf("%b\n", address);
|
|
|
|
outb_32(PCI_CONFIG_ADDRESS, address);
|
|
|
|
tmp = (uint16_t)((inb(PCI_CONFIG_DATA) >> ((offset & 2) * 8)) & 0xFFFF);
|
|
return tmp;
|
|
}
|
|
|
|
uint16_t pci_check_vendor(uint8_t bus, uint8_t slot, uint8_t func)
|
|
{
|
|
uint16_t vendor, device;
|
|
|
|
if ((vendor = pci_config_read_word(bus, slot, func, 0)) != 0xFFFF) {
|
|
device = pci_config_read_word(bus, slot, func, 2);
|
|
// we'll do something here, store all the pcis in memory or something
|
|
device++;
|
|
}
|
|
return vendor;
|
|
}
|