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/include/io/pci/pci.h | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/sys/include/io/pci') diff --git a/src/sys/include/io/pci/pci.h b/src/sys/include/io/pci/pci.h index cff5f0a..9184c00 100644 --- a/src/sys/include/io/pci/pci.h +++ b/src/sys/include/io/pci/pci.h @@ -32,6 +32,22 @@ #include #include +#include + +/* + * Use for making instances of the pci_adv + * structure. + */ +#define PCI_CS_ID(CLASS, SUBCLASS) \ + { \ + .class = (CLASS), \ + .subclass = (SUBCLASS) \ + } +#define PCI_DV_ID(DEVICE, VENDOR) \ + { \ + .device = (DEVICE), \ + .vendor = (VENDOR) \ + } /* PCI specific types */ typedef uint32_t pcireg_t; @@ -58,6 +74,25 @@ struct pci_device { TAILQ_ENTRY(pci_device) link; }; +/* + * Structure that allows a device driver of a PCI + * bus node to advocate for its workings. In other words, + * it registers itself to be the driver of the device. + * + * @lookup: Lookup arguments + * @attach: Attach the driver + * @classrev: IF 1, identified by class/subclass + * + * XXX: The `lookup` field is used for both input arguments + * as well as output results + */ +struct pci_adv { + struct pci_device lookup; + int(*attach)(struct pci_adv *ap); + uint8_t classrev : 1; + TAILQ_ENTRY(pci_adv) link; +}; + typedef enum { PCI_LU_VENDEV, /* Vendor / device */ PCI_LU_CLASSREV, /* Class / subclass */ @@ -72,6 +107,16 @@ typedef enum { */ int pci_bus_lookup(struct pci_device *lookup, lookup_type_t type); +/* + * Advocate for a specific device as its driver. + * + * @advp: Advocation descriptor + * + * Returns zero on success, otherwise a less than + * zero value on failure. + */ +int pci_advoc(struct pci_adv *advp); + /* * Read from a specific register on a specific PCI * enabled device. -- cgit v1.2.3