BarinkOS/src/kernel/pci.cpp

29 lines
662 B
C++
Raw Normal View History

#include "pci.h"
2021-11-25 21:05:16 +00:00
#include "tty/kterm.h"
#define PCI_BUS_ADDR_SHIFT 16
#define PCI_DEVICE_ADDR_SHIFT 11
#define PCI_FUNCTION_ADDR_SHIFT 8
#define PCI_ENABLE_ADDR_SHIFT 31
2021-11-25 21:05:16 +00:00
uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset){
uint32_t address;
2021-11-25 21:05:16 +00:00
address = (uint32_t) (
((uint32_t) 1 << PCI_ENABLE_ADDR_SHIFT) |
((uint32_t)bus << PCI_BUS_ADDR_SHIFT) |
((uint32_t)device << PCI_DEVICE_ADDR_SHIFT) |
((uint32_t)func << PCI_FUNCTION_ADDR_SHIFT) |
offset );
// printf("PCI address read 0x%x", address);
2021-11-25 21:05:16 +00:00
2021-11-25 21:05:16 +00:00
outl(CONFIG_ADDRESS, address);
2021-11-25 21:05:16 +00:00
return inl(CONFIG_DATA);
}