XHCI: allocate device context buffer for each slot

This commit is contained in:
Josh Holtrop 2025-05-23 09:21:48 -04:00
parent e3f27812ad
commit ea159db100

View File

@ -118,6 +118,11 @@ struct XHCI
* 31:12 VTIO register space offset (xHCI v1.2+)
*/
Volatile!uint vtios_offset;
@property ubyte max_slots()
{
return this.hcs_params1 & 0xFFu;
}
}
static assert(CapabilityRegisters.sizeof == 0x24u);
@ -364,9 +369,7 @@ struct XHCI
/* 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];
void ** device_context_index = cast(void **)page;
page = cast(ubyte *)Hippo.allocate_page();
/* Input Control Context: 64 bytes */
void * input_control_context = page;
@ -377,7 +380,7 @@ struct XHCI
/* Stream Context: 16 bytes */
void * stream_context = &page[192];
/* Scratchpad Buffer Array: 248 bytes */
void * scratchpad_buffer_array = &page[256];
void ** scratchpad_buffer_array = cast(void **)&page[256];
/* Stream Array (Linear): 1M */
void * stream_array_linear = Hippo.allocate_aligned_region(1024 * 1024, PAGE_SIZE);
/* Stream Array (Pri/Sec): 4K */
@ -393,6 +396,24 @@ struct XHCI
/* Scratchpad Buffers: 4K */
void * scratchpad_buffers = Hippo.allocate_page();
device_context_index[0] = scratchpad_buffer_array;
size_t max_slots = m_capability_registers.max_slots;
for (size_t i = 0u; i < max_slots; i++)
{
void * addr;
if ((i & 1) == 0)
{
page = cast(ubyte *)Hippo.allocate_page();
addr = page;
}
else
{
addr = &page[2048];
}
device_context_index[1 + i] = addr;
}
/* TODO: write dcbaap. */
/* TODO: write cr_ctrl. */
/+ TODO: