From 70dae4150a98cc93ab9da7bfbf93e21070dc8753 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 11 Jun 2025 21:33:29 -0400 Subject: kernel: pci: Add 'cam_hook' structure for PCI I/O This change improves flexibility and allows for easy future integration of the PCI Express Enhanced Configuration Access Mechanism (ECAM) Signed-off-by: Ian Moffett --- sys/dev/pci/pci.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'sys/dev/pci/pci.c') diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index d59f68f..95fc5e2 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,11 @@ static TAILQ_HEAD(, pci_device) device_list; static struct spinlock devlist_lock = {0}; +struct cam_hook { + pcireg_t(*cam_readl)(struct pci_device *dev, uint32_t off); + void(*cam_writel)(struct pci_device *dev, uint32_t off, pcireg_t val); +} cam_hook = { NULL }; + static bool pci_dev_exists(uint8_t bus, uint8_t slot, uint8_t func) { @@ -273,12 +279,36 @@ pci_add_device(struct pci_device *dev) spinlock_release(&devlist_lock); } + +pcireg_t +pci_readl(struct pci_device *dev, uint32_t offset) +{ + if (cam_hook.cam_readl == NULL) { + return (pcireg_t)-1; + } + + return cam_hook.cam_readl(dev, offset); +} + +void +pci_writel(struct pci_device *dev, uint32_t offset, pcireg_t val) +{ + if (cam_hook.cam_writel == NULL) { + return; + } + + cam_hook.cam_writel(dev, offset, val); +} + int pci_init(void) { size_t ndev; TAILQ_INIT(&device_list); + cam_hook.cam_readl = md_pci_readl; + cam_hook.cam_writel = md_pci_writel; + /* Recursively scan bus 0 */ pci_scan_bus(0); ndev = TAILQ_NELEM(&device_list); -- cgit v1.2.3