From dafae63886c6f97e03d436084a4b757f3137767e Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 19 Sep 2025 21:48:10 -0400 Subject: kern: pci: Implement PCI leaf drivers + AHCI stub This commit introduces the support for having PCI specific device drivers while providing a tiny AHCI stub that logs the existence of the host bus adapter. The PCI bus itself has a driver for enumerating the devices and associating a specific driver to it, the device drivers themselve must advertise themselves to the PCI driver. Signed-off-by: Ian Moffett --- src/sys/io/pci/pci.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/sys/io/pci') diff --git a/src/sys/io/pci/pci.c b/src/sys/io/pci/pci.c index c308c20..af5c113 100644 --- a/src/sys/io/pci/pci.c +++ b/src/sys/io/pci/pci.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,7 @@ #endif /* __PCI_MAX_BUS */ static TAILQ_HEAD(, pci_device) devlist; +static TAILQ_HEAD(, pci_adv) advlist; static struct cam_hook cam; /* @@ -266,10 +268,34 @@ pci_writel(struct pci_device *dp, pcireg_t reg, uint32_t v) return cam.cam_writel(dp, reg, v); } +/* + * Advocate for a specific device + */ +int +pci_advoc(struct pci_adv *advp) +{ + struct pci_adv *adv_new; + + if (advp == NULL) { + return -EINVAL; + } + + adv_new = kalloc(sizeof(*adv_new)); + if (adv_new == NULL) { + printf("pci_advoc: could not alloc adv\n"); + return -ENOMEM; + } + *adv_new = *advp; + TAILQ_INSERT_TAIL(&advlist, advp, link); + return 0; +} + void pci_init_bus(void) { - struct pci_device *dp; + struct pci_adv *advp; + struct pci_device dev; + lookup_type_t lup; int error; error = pci_cam_init(&cam); @@ -278,11 +304,26 @@ pci_init_bus(void) panic("pci_init_bus: failed to init CAM\n"); } - printf("pci: enumerating %d buses\n", PCI_MAX_BUS); + /* Initialize device and advocation list */ TAILQ_INIT(&devlist); + TAILQ_INIT(&advlist); + + printf("pci: enumerating %d buses\n", PCI_MAX_BUS); for (int i = 0; i < PCI_MAX_BUS; ++i) { pci_enum_bus(i); } + __MODULES_INIT(MODTYPE_PCI); printf("bridge: detected %d devices\n", devlist.nelem); + + /* Now allocate load the drivers */ + TAILQ_FOREACH(advp, &advlist, link) { + dev = advp->lookup; + lup = advp->classrev ? PCI_LU_CLASSREV : PCI_LU_VENDEV; + + error = pci_bus_lookup(&dev, lup); + if (error == 0) { + advp->attach(advp); + } + } } -- cgit v1.2.3