From e357f2ba44acb7bc98fe958c9b7e55f89aa3ae31 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 24 Oct 2023 10:44:48 -0400 Subject: [PATCH] Initialize USB controllers from Usb instead of Pci --- src/hulk/hulk.d | 2 ++ src/hulk/pci.d | 57 +++++++----------------------------------- src/hulk/usb/package.d | 3 +++ src/hulk/usb/usb.d | 24 ++++++++++++++++++ 4 files changed, 38 insertions(+), 48 deletions(-) create mode 100644 src/hulk/usb/package.d create mode 100644 src/hulk/usb/usb.d diff --git a/src/hulk/hulk.d b/src/hulk/hulk.d index c198c55..59e94fe 100644 --- a/src/hulk/hulk.d +++ b/src/hulk/hulk.d @@ -22,6 +22,7 @@ import hulk.acpi; import hulk.apic; import hulk.rtc; import hulk.serial; +import hulk.usb; extern extern(C) __gshared ubyte _hulk_bss_size; @@ -82,6 +83,7 @@ void hulk_start() t.year, t.month, t.day, t.hour, t.minute, t.second); Pci.initialize(); + Usb.initialize(); sti(); for (;;) diff --git a/src/hulk/pci.d b/src/hulk/pci.d index 80fb184..a6a0891 100644 --- a/src/hulk/pci.d +++ b/src/hulk/pci.d @@ -14,22 +14,28 @@ import hulk.list; struct Pci { - /* IO address for PCI configuration address. */ + /** IO address for PCI configuration address. */ enum IO_ADDR_CONFIG_ADDRESS = 0xCF8u; - /* IO address for PCI configuration data. */ + /** IO address for PCI configuration data. */ enum IO_ADDR_CONFIG_DATA = 0xCFCu; + /** Maximum number of devices on a bus. */ enum MAX_DEVICES_PER_BUS = 32; + /** Maximum number of functions on a devices. */ enum MAX_FUNCTIONS_PER_DEVICE = 8; + /** XHCI controller device type. */ + enum XHCI_CONTROLLER = Type(0x0Cu, 0x03u, 0x30u); + /** * PCI device address (bus number, device number, function number). */ struct Address { uint address; + alias address this; this(ubyte bus_nr, ubyte device_nr, ubyte function_nr) { @@ -67,6 +73,7 @@ struct Pci struct Type { uint type; + alias type this; this(ubyte class_id, ubyte subclass_id, ubyte interface_id) { @@ -125,8 +132,6 @@ struct Pci { map_memory_regions(); } - - spawn_device_instance(); } private void map_memory_regions() @@ -193,50 +198,6 @@ struct Pci } } } - - private void spawn_device_instance() - { - switch (config.class_id) - { - case SerialBusController.ID: - switch (config.subclass_id) - { - case SerialBusController.USBController.ID: - switch (config.interface_id) - { - case SerialBusController.USBController.XHCIController.ID: - XHCI.build(&this); - break; - - default: - break; - } - break; - - default: - break; - } - break; - - default: - break; - } - } - } - - struct SerialBusController - { - enum ID = 0x0Cu; - - struct USBController - { - enum ID = 0x03u; - - struct XHCIController - { - enum ID = 0x30u; - } - } } /** diff --git a/src/hulk/usb/package.d b/src/hulk/usb/package.d new file mode 100644 index 0000000..94fb91d --- /dev/null +++ b/src/hulk/usb/package.d @@ -0,0 +1,3 @@ +module hulk.usb; + +public import hulk.usb.usb; diff --git a/src/hulk/usb/usb.d b/src/hulk/usb/usb.d new file mode 100644 index 0000000..1528911 --- /dev/null +++ b/src/hulk/usb/usb.d @@ -0,0 +1,24 @@ +/** + * USB (Universal Serial Bus) functionality. + */ +module hulk.usb.usb; + +import hulk.klog; +import hulk.usb.xhci; +import hulk.pci; + +struct Usb +{ + public static void initialize() + { + Klog.writefln("\a3Initializing USB"); + + foreach (pci_device; Pci.devices) + { + if (pci_device.type == Pci.XHCI_CONTROLLER) + { + XHCI.build(&pci_device); + } + } + } +}