Initialize USB controllers from Usb instead of Pci

This commit is contained in:
Josh Holtrop 2023-10-24 10:44:48 -04:00
parent f8f9b72588
commit e357f2ba44
4 changed files with 38 additions and 48 deletions

View File

@ -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 (;;)

View File

@ -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;
}
}
}
/**

3
src/hulk/usb/package.d Normal file
View File

@ -0,0 +1,3 @@
module hulk.usb;
public import hulk.usb.usb;

24
src/hulk/usb/usb.d Normal file
View File

@ -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);
}
}
}
}