From e3f27812adad6393026b9c7c08c4fc93dc500202 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 23 Feb 2025 20:52:36 -0500 Subject: [PATCH] Allocate memory regions for XHCI --- src/hulk/usb/xhci.d | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/hulk/usb/xhci.d b/src/hulk/usb/xhci.d index a1a4321..de54d42 100644 --- a/src/hulk/usb/xhci.d +++ b/src/hulk/usb/xhci.d @@ -9,7 +9,9 @@ module hulk.usb.xhci; import hulk.pci; +import hulk.hurl; import hulk.hurl.a1; +import hulk.hippo; import hulk.klog; import hulk.time; import hulk.volatile; @@ -358,6 +360,39 @@ struct XHCI Klog.writefln("XHCI controller failed to initialize"); return; } + + /* Allocate memory for various controller data structures. */ + ubyte * page = cast(ubyte *)Hippo.allocate_page(); + /* Device Context Index: 2K */ + void * device_context_index = page; + /* Device Context: 2K */ + void * device_context = &page[2048]; + page = cast(ubyte *)Hippo.allocate_page(); + /* Input Control Context: 64 bytes */ + void * input_control_context = page; + /* Slot Context: 64 bytes */ + void * slot_context = &page[64]; + /* Endpoint Context: 64 bytes */ + void * endpoint_context = &page[128]; + /* Stream Context: 16 bytes */ + void * stream_context = &page[192]; + /* Scratchpad Buffer Array: 248 bytes */ + void * scratchpad_buffer_array = &page[256]; + /* Stream Array (Linear): 1M */ + void * stream_array_linear = Hippo.allocate_aligned_region(1024 * 1024, PAGE_SIZE); + /* Stream Array (Pri/Sec): 4K */ + void * stream_array_pri_sec = Hippo.allocate_page(); + /* Transfer Ring Segments: 64K */ + void * transfer_ring_segments = Hippo.allocate_aligned_region(64 * 1024, 64 * 1024); + /* Command Ring Segments: 64K */ + void * command_ring_segments = Hippo.allocate_aligned_region(64 * 1024, 64 * 1024); + /* Event Ring Segments: 64K */ + void * event_ring_segments = Hippo.allocate_aligned_region(64 * 1024, 64 * 1024); + /* Event Ring Segment Table: 512K */ + void * event_ring_segment_table = Hippo.allocate_aligned_region(512 * 1024, PAGE_SIZE); + /* Scratchpad Buffers: 4K */ + void * scratchpad_buffers = Hippo.allocate_page(); + /* TODO: write dcbaap. */ /* TODO: write cr_ctrl. */ /+ TODO: