commit f3294d1323a3c63ef40c3680fca074fbbd1853e8
parent 905898fdce5117298a54c419e06fa984bfbca3a9
Author: Matsuda Kenji <info@mtkn.jp>
Date: Wed, 1 May 2024 12:04:14 +0900
setup an event ring
Diffstat:
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/sys/include/xhc.h b/sys/include/xhc.h
@@ -36,10 +36,11 @@ struct xhc_operational_registers {
uint32 PAGESIZE;
uint8 RsvdZ0[8];
uint32 NDCTRL;
- uint32 CRCR;
+ uint64 CRCR;
uint8 RsvdZ1[16];
uint64 DCBAAP;
uint32 CONFIG;
+ // TODO: port register set
};
struct xhc_runtime_registers {
diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c
@@ -95,7 +95,7 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
goto halt;
}
xhc.op->CONFIG |= 1; // CONFIG.MaxSlotsEn
- cons_printf(&con0, "set CONFIG.MaxSlotsEn: %x\n", xhc.op->CONFIG);
+ cons_printf(&con0, "CONFIG: %x\n", xhc.op->CONFIG);
// TODO: align DCBAAP in 64-byte.
// I don't like __attribute__
xhc_device_context *DCBAAP[2] __attribute__((aligned(64))) = {0};
@@ -106,7 +106,24 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
xhc_device_context device_context;
DCBAAP[1] = &device_context;
xhc.op->DCBAAP = (uint64) DCBAAP;
- cons_printf(&con0, "DCBAAP set to: %x\n", xhc.op->DCBAAP);
+ cons_printf(&con0, "DCBAAP: %x\n", xhc.op->DCBAAP);
+
+ // setup the command ring.
+ xhc_trb command_ring[16] __attribute__((aligned(64))) = {0};
+ // set link TRB.
+ command_ring[15].parameter = (uint64) command_ring;
+ command_ring[15].control = 6 << 10; // TRB type: link TRB
+ xhc.op->CRCR = (uint64) command_ring;
+
+ // setup an event ring.
+ xhc_trb event_ring_segment_table[1] __attribute__((aligned(64))) = {0};
+ xhc_trb event_ring_segment[16] __attribute__((aligned(16))) = {0};
+ event_ring_segment_table[0].parameter = (uint64) event_ring_segment;
+ xhc.runtime->IR[0].ERSTSZ = sizeof(event_ring_segment_table) / sizeof(event_ring_segment_table[0]);
+ xhc.runtime->IR[0].ERDP = (uint64) event_ring_segment;
+ xhc.runtime->IR[0].ERSTBA = (uint64) event_ring_segment_table;
+
+ // setup the primary interrupter
cons_printf(&con0, "local apic id: %x\n", *(uint32 *) (0xfee00020) >> 24);
uintptr pci_config_base = (uintptr) pci_xhc;