hazel/kernel/pci.c

20 lines
595 B
C
Raw Normal View History

2024-08-01 14:22:25 -04:00
#include <kernel/pci.h>
#include <kernel/io.h>
uint16_t pci_read_cfg(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;
// Create configuration address as per Figure 1
address = (uint32_t)((lbus << 16) | (lslot << 11) |
(lfunc << 8) | (offset & 0xFC) | ((uint32_t)0x80000000));
outl(PCI_CONFIG_ADDR, address);
tmp = (uint16_t)((inl(PCI_CONFIG_DATA) >> ((offset & 2) * 8)) & 0xFFFF);
return tmp;
}