summaryrefslogtreecommitdiff
path: root/src/sys/include/io
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-19 21:48:10 -0400
committerIan Moffett <ian@osmora.org>2025-09-19 21:48:10 -0400
commitdafae63886c6f97e03d436084a4b757f3137767e (patch)
tree5d70f39ffaac42b008fe11a254a35d3e0fef77ba /src/sys/include/io
parentb81c469c7e1a7c154df49ae95ba05ac20da7532e (diff)
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 <ian@osmora.org>
Diffstat (limited to 'src/sys/include/io')
-rw-r--r--src/sys/include/io/pci/pci.h45
1 files changed, 45 insertions, 0 deletions
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 <sys/types.h>
#include <sys/queue.h>
+#include <sys/cdefs.h>
+
+/*
+ * 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 */
@@ -73,6 +108,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.
*