59 return ((
uint64_t) dword1 << 32) | dword2;
64 return (dword >> ((off & 2) * 8)) & 0xFFFF;
69 return (dword >> ((off & 3) * 8)) & 0xFF;
85 pci_write32(bus, dev, func, (off & ~3) + 4, dword2);
92 dword = (dword & (
uint32_t) ~(0xFFFF << shift))
115 LOG_INFO(
"PCI",
"device id : 0x%x",
pci->device_id);
116 LOG_INFO(
"PCI",
"vendor id : 0x%x",
pci->vendor_id);
120 if ((
pci->status & (1 << 4))) {
122 pci->capability_ptr = cap_ptr;
134 for (
int i = 0; i < 6; i++) {
146 pci->bar[i].iospace = 1;
147 pci->bar[i].address =
bar & ~3UL;
149 pci->bar[i].address);
154 pci->bar[i].iospace = 0;
155 pci->bar[i].address =
bar & ~0xFUL;
159 if ((
bar & 0x6) == 0x4) {
165 " 64-bit BAR detected at index %d (0x%lx)", i,
185 addr, size_4kb, 0b10011);
191 LOG_INFO(
"PCI",
"[%d] BAR 0x%lx [0x%lx] (0x%lx) size: %d KB",
194 pci->bar[bar_idx].address = vaddr;
202 if ((
pci->vendor_id == 0x8086 &&
pci->device_id == 0x10D3)
203 || (
pci->vendor_id == 0x8086 &&
pci->device_id == 0x24C2)
204 || (
pci->vendor_id == 0x8086 &&
pci->device_id == 0x2922)
205 || (
pci->vendor_id == 0x1AF4)) {
214 auto bus_master = (
cmd & (1 << 2)) >> 2;
215 auto memory_space = (
cmd & (1 << 1)) >> 1;
216 LOG_INFO(
"PCI",
"bus master : %d", bus_master);
217 LOG_INFO(
"PCI",
"memory space : %d", memory_space);
239 LOG_INFO(
"PCI",
"class : 0x%x subclass : 0x%x",
pci->classes,
243 switch (
pci->classes) {
245 switch (
pci->subclass) {
247 LOG_INFO(
"PCI",
"Unclassified device");
250 LOG_INFO(
"PCI",
"Mass storage controller");
253 LOG_INFO(
"PCI",
"Network controller");
256 LOG_INFO(
"PCI",
"Display controller");
259 LOG_INFO(
"PCI",
"Multimedia controller");
262 LOG_INFO(
"PCI",
"Memory controller");
268 LOG_INFO(
"PCI",
"Simple communication controller");
271 LOG_INFO(
"PCI",
"Base system peripheral");
274 LOG_INFO(
"PCI",
"Input device controller");
283 LOG_INFO(
"PCI",
"Serial bus controller");
286 LOG_INFO(
"PCI",
"Wireless controller");
289 LOG_INFO(
"PCI",
"Intelligent controller");
292 LOG_INFO(
"PCI",
"Satellite communication controller");
295 LOG_INFO(
"PCI",
"Encryption controller");
298 LOG_INFO(
"PCI",
"Signal processing controller");
301 LOG_INFO(
"PCI",
"Processing accelerators");
304 LOG_INFO(
"PCI",
"Non-Essential Instrumentation");
311 "Device does not fit in any defined class");
319 switch (
pci->subclass) {
321 LOG_INFO(
"PCI",
"SCSI storage controller");
329 switch (
pci->subclass) {
331 LOG_INFO(
"PCI",
"Ethernet controller");
336 switch (
pci->subclass) {
338 switch (
pci->prog_if) {
349 switch (
pci->vendor_id) {
351 LOG_INFO(
"PCI",
"virtio device found w device_id : 0x%x",
353 switch (
pci->device_id) {
355 LOG_INFO(
"PCI",
"found virtio VGA device");
375 if (
class == 0x06 && subclass == 0x04) {
385 for (
uint8_t dev = 0; dev < 32; dev++) {
388 if (vendor == 0xFFFF || vendor == 0x0000)
394 for (
uint8_t func = 0; func < func_count; func++) {
398 if ((
id & 0xFFFF) == 0xFFFF || (
id & 0xFFFF) == 0x0000)
401 LOG_INFO(
"PCI",
"device found %d:%d:%d", bus, dev,
413 if (host_header & 0x80) {
414 for (
uint8_t func = 0; func < 8; func++) {
427 LOG_INFO(
"pci",
"No MCFG, fallback to PCI");
430 LOG_INFO(
"pci",
"Found MCFG, using pcie");
438 LOG_INFO(
"PCI",
"Scanning segment %d (bus %d-%d)",
void serial_printf(const char *fmt,...)
void ioforge_attach(struct ioforge_device *parent, struct ioforge_device *child)
struct ioforge_device * ioforge_get_pci_root()
struct ioforge_pci_device pci
void * kalloc(size_t size)
#define ALIGN_DOWN(x, align)
void paging_reload(page_t p)
page_t paging_get_highest_page_map(void)
void vxMultipleMmap(page_t page_dir, uint64_t virt, uint64_t phys, uint64_t size, uint64_t flags)
void legacy_write32(uintptr_t base, uint8_t bus, uint8_t dev, uint8_t func, uint16_t offset, uint32_t val)
uint32_t legacy_read32(uintptr_t base, uint8_t bus, uint8_t dev, uint8_t func, uint16_t offset)
struct pci_segment pci_segment_t
struct pci_access_ops pci_access_ops_t
uint8_t pci_read8(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off)
static void pci_scan_bus(pci_segment_t *s)
uint64_t pci_read64(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off)
static pci_access_ops_t legacy_ops
static void vxPCIGatheringBusInfo(uint8_t bus, uint8_t device, uint8_t func)
static pci_segment_t segments[16]
void pci_write16(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off, uint16_t val)
void pci_write32(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off, uint32_t val)
static void pci_check_func(uint8_t bus, uint8_t dev, uint8_t func)
uint16_t pci_read16(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off)
static size_t segment_count
static void pci_check_bus(uint8_t bus)
void pci_write64(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off, uint64_t val)
uint8_t pci_read8(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off)
static pci_segment_t * find_segment(uint8_t bus)
void register_segment(uint16_t seg_id, uint8_t start, uint8_t end, uintptr_t vbase, pci_access_ops_t *ops, PCI_SEGMENT_TYPE type)
uint32_t pci_read32(uint8_t bus, uint8_t dev, uint8_t func, uint16_t off)
#define LOG_INFO(mod, fmt,...)
#define serial_trace(...)
void memset(void *ptr, int value, size_t num)
uint32_t(* read32)(uintptr_t base, uint8_t bus, uint8_t dev, uint8_t func, uint16_t offset)
void(* write32)(uintptr_t base, uint8_t bus, uint8_t dev, uint8_t func, uint16_t offset, uint32_t val)
uintptr_t vma_lookup_free_vaddr(struct virtual_memory_page *page, mem_vma_region region, size_t size)
void vma_register(struct virtual_memory_page *page, uintptr_t phys_address, uintptr_t virt_addr, size_t size)
struct virtual_memory_page * get_kernel_vmm_page()