From 139d593640cf8e7cc666818a29a689d5def541ef Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 7 May 2024 19:15:26 -0400 Subject: kernel: pci: Add macros for fetching BAR base Signed-off-by: Ian Moffett --- sys/include/dev/pci/pci.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'sys') diff --git a/sys/include/dev/pci/pci.h b/sys/include/dev/pci/pci.h index 66ecb91..ad3f7ac 100644 --- a/sys/include/dev/pci/pci.h +++ b/sys/include/dev/pci/pci.h @@ -34,6 +34,7 @@ #include #include #include +#include /* Lookup bits */ #define PCI_DEVICE_ID __BIT(0) @@ -41,6 +42,14 @@ #define PCI_CLASS __BIT(2) #define PCI_SUBCLASS __BIT(3) +/* Base address masks for BARs */ +#define PCI_BAR_MEMMASK ~7 +#define PCI_BAR_IOMASK ~3 + +/* Macros to fetch base address from BAR */ +#define PCI_BAR_MEMBASE(BAR) PHYS_TO_VIRT(BAR & PCI_BAR_MEMMASK) +#define PCI_BAR_IOBASE(BAR) PHYS_TO_VIRT(BAR & PCI_BAR_IOMASK) + /* For PCI lookups */ struct pci_lookup { uint16_t device_id; -- cgit v1.2.3