commit f69e9f899a048a149673e09638e7bcd6cc6b8f33
parent fa9230d5d6d42b6140253eb097a7963a1fc89e93
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 23 Apr 2024 15:50:10 +0900
set MaxSlotsEn
Diffstat:
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/sys/include/xhc.h b/sys/include/xhc.h
@@ -4,6 +4,9 @@ typedef struct xhc_capability_registers xhc_capability_registers;
typedef struct xhc_operational_registers xhc_operational_registers;
typedef struct xhc_runtime_registers xhc_runtime_registers;
typedef struct xhc_doorbell_registers xhc_doorbell_registers;
+typedef struct xhc_device_context xhc_device_context;
+typedef struct xhc_slot_context xhc_slot_context;
+typedef struct xhc_endpoint_context xhc_endpoint_context;
typedef struct Xhc {
uintptr base;
@@ -13,8 +16,6 @@ typedef struct Xhc {
xhc_doorbell_registers *doorbell;
} Xhc;
-extern Xhc xhc;
-
struct xhc_capability_registers {
uint8 CAPLENGTH;
uint8 Rsvd0;
@@ -56,3 +57,18 @@ struct xhc_runtime_registers {
struct xhc_doorbell_registers {
// TODO: implement.
};
+
+struct xhc_slot_context {
+ // TODO: implement.
+ uint8 byte[32];
+};
+
+struct xhc_endpoint_context {
+ // TODO: implement.
+ uint8 byte[32];
+};
+
+struct xhc_device_context {
+ xhc_slot_context slot_context;
+ xhc_endpoint_context ep_context[31];
+};
diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c
@@ -69,6 +69,7 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
// TODO: find the following calculation in some specification.
// only article found is osdev's page:
// osdev.org/PCI#Address_and_size_of_the_BAR
+ Xhc xhc;
xhc.base = ((uintptr) pci_xhc->t0.base_address_register[1]) << 32 |
(pci_xhc->t0.base_address_register[0]&0xfffffff0);
xhc.cap = (xhc_capability_registers *) xhc.base;
@@ -89,6 +90,16 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
}
cons_printf(&con0, "usb controller ready\n");
+ if ((uint8) (xhc.cap->HCSPARAMS1&0xff) < 1) { // HCSPARAMS1.MaxSlots
+ cons_printf(&con0, "Max Device Slot is too small: %d\n", (uint8) (xhc.cap->HCSPARAMS1&0xff));
+ goto halt;
+ }
+ xhc.op->CONFIG |= 1; // CONFIG.MaxSlotsEn
+ cons_printf(&con0, "CONFIG: %x\n", xhc.op->CONFIG);
+ xhc_device_context *DCBAAP[2] = {0};
+ xhc_device_context device_context;
+ DCBAAP[1] = &device_context;
+
cons_printf(&con0, "local apic id: %x\n", *(uint32 *) (0xfee00020) >> 24);
uintptr pci_config_base = (uintptr) pci_xhc;
PCICap *cap = (PCICap *) (pci_config_base + pci_xhc->capabilities_pointer);
diff --git a/sys/src/kernel/xhc.c b/sys/src/kernel/xhc.c
@@ -1,4 +1,2 @@
#include <libc.h>
#include <xhc.h>
-
-Xhc xhc;