From 1c6c922b4586517a2c616fe637bf0da75a24bc59 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 22 Oct 2023 21:30:36 -0400 Subject: [PATCH] Add Pci.Type struct --- src/hulk/pci.d | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/hulk/pci.d b/src/hulk/pci.d index 255220c..2c7cb14 100644 --- a/src/hulk/pci.d +++ b/src/hulk/pci.d @@ -1,3 +1,6 @@ +/** + * PCI (Peripheral Component Interconnect) functionality. + */ module hulk.pci; import hulk.cpu; @@ -20,6 +23,9 @@ struct Pci enum MAX_FUNCTIONS_PER_DEVICE = 8; + /** + * PCI device address (bus number, device number, function number). + */ struct Address { /** Bus number (0-255). */ @@ -32,10 +38,29 @@ struct Pci ubyte function_nr; } + /** + * PCI device type (class ID, subclass ID, interface ID). + */ + struct Type + { + /** Class ID. */ + ubyte class_id; + + /** Subclass ID. */ + ubyte subclass_id; + + /** Interface ID. */ + ubyte interface_id; + } + + /** + * PCI device object. + */ static struct Device { Configuration * config; Address address; + Type type; bool multifunction; Range[6] memory_ranges; @@ -43,9 +68,12 @@ struct Pci { this.config = config; this.address = address; + type.class_id = config.class_id; + type.subclass_id = config.subclass_id; + type.interface_id = config.interface_id; Klog.writefln("Found PCI device %04x:%04x (%02x:%02x:%02x) at %02u:%02u.%u", config.vendor_id, config.device_id, - config.class_id, config.subclass_id, config.interface_id, + type.class_id, type.subclass_id, type.interface_id, address.bus_nr, address.device_nr, address.function_nr); multifunction = (address.function_nr == 0u) && ((config.header_type & 0x80u) != 0u); ubyte header_type = config.header_type & 0x7Fu;