pci: add is64bits and physical address to pcibar_t

This commit is contained in:
Matheus
2023-10-15 20:57:09 -03:00
parent f362f017bc
commit 676be91ac0
2 changed files with 7 additions and 2 deletions
+4
View File
@@ -5,6 +5,8 @@
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#define PCI_BAR_BASE 0x10
// 2 byte fields // 2 byte fields
#define PCI_CONFIG_VENDOR 0x0 #define PCI_CONFIG_VENDOR 0x0
#define PCI_CONFIG_DEVICEID 0x2 #define PCI_CONFIG_DEVICEID 0x2
@@ -37,8 +39,10 @@ typedef struct {
typedef struct { typedef struct {
uintptr_t address; uintptr_t address;
uintptr_t physical;
size_t length; size_t length;
bool mmio; bool mmio;
bool is64bits;
bool prefetchable; bool prefetchable;
} pcibar_t; } pcibar_t;
+3 -2
View File
@@ -146,9 +146,10 @@ pcibar_t pci_getbar(pcienum_t *e, int n) {
} else { } else {
ret.mmio = true; ret.mmio = true;
ret.prefetchable = bar & BAR_PREFETCHABLE; ret.prefetchable = bar & BAR_PREFETCHABLE;
ret.address = bar & 0xfffffff0; ret.address = ret.physical = bar & 0xfffffff0;
ret.length = -1; ret.length = -1;
if ((bar & BAR_TYPE_MASK) == BAR_TYPE_64BIT) ret.is64bits = (bar & BAR_TYPE_MASK) == BAR_TYPE_64BIT;
if (ret.is64bits)
ret.address += (uint64_t)pci_read32(e->bus, e->device, e->function, offset + 4) << 32; ret.address += (uint64_t)pci_read32(e->bus, e->device, e->function, offset + 4) << 32;
pci_write32(e->bus, e->device, e->function, offset, -1); pci_write32(e->bus, e->device, e->function, offset, -1);