summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-06-11 21:33:29 -0400
committerIan Moffett <ian@osmora.org>2025-06-11 21:33:29 -0400
commit70dae4150a98cc93ab9da7bfbf93e21070dc8753 (patch)
tree0ee7bc83e2756fb35802942f334667bd244c4e8a /sys/dev
parent12ca8e0711704d73bdf5c99e6306c321f3bea373 (diff)
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 <ian@osmora.org>
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/pci.c30
1 files changed, 30 insertions, 0 deletions
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 <sys/spinlock.h>
#include <dev/pci/pci.h>
#include <dev/pci/pciregs.h>
+#include <machine/pci/pci.h>
#include <vm/dynalloc.h>
#include <lib/assert.h>
@@ -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);