summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-10-12 13:01:18 -0400
committerIan Moffett <ian@osmora.org>2025-10-12 13:01:58 -0400
commit17b73f78080f6bc545e61153793d6c1af8524db5 (patch)
treee8c9f4e8e5eb178aa5ac0fc52403d4593c1e1997 /src
parenta39d7ebfd504110ab3e84fa3990bd79f7ba2271f (diff)
kern: xhci: Allocate and init command ring / CRCR
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src')
-rw-r--r--src/sys/include/io/usb/xhcivar.h1
-rw-r--r--src/sys/io/usb/hcd/xhci.c35
2 files changed, 36 insertions, 0 deletions
diff --git a/src/sys/include/io/usb/xhcivar.h b/src/sys/include/io/usb/xhcivar.h
index f98207f..ee6c0b8 100644
--- a/src/sys/include/io/usb/xhcivar.h
+++ b/src/sys/include/io/usb/xhcivar.h
@@ -48,6 +48,7 @@ struct xhci_hcd {
uint32_t max_intrs;
uint32_t max_ports;
uintptr_t dcbaap_pa;
+ uintptr_t cmd_ring;
};
#define XHCI_TIMEOUT_MSEC 500
diff --git a/src/sys/io/usb/hcd/xhci.c b/src/sys/io/usb/hcd/xhci.c
index e5a794a..2692e07 100644
--- a/src/sys/io/usb/hcd/xhci.c
+++ b/src/sys/io/usb/hcd/xhci.c
@@ -172,6 +172,36 @@ xhci_init_dcbaap(struct xhci_hcd *hcd)
}
/*
+ * Initialize the command ring
+ */
+static int
+xhci_init_cmdring(struct xhci_hcd *hcd)
+{
+ struct xhci_opregs *opregs;
+ void *va;
+
+ if (hcd == NULL) {
+ return -EINVAL;
+ }
+
+ /* Allocate the actual command ring */
+ hcd->cmd_ring = vm_alloc_frame(1);
+ if (hcd->cmd_ring == 0) {
+ pr_trace("failed to allocate command ring\n");
+ return -ENOMEM;
+ }
+
+ /* Zero it */
+ va = PHYS_TO_VIRT(hcd->cmd_ring);
+ memset(va, 0, DEFAULT_PAGESIZE);
+
+ /* Write CRCR with the physical address */
+ opregs = XHCI_OPBASE(hcd->capspace);
+ mmio_write64(&opregs->cmd_ring, hcd->cmd_ring);
+ return 0;
+}
+
+/*
* Initialize the host controller
*/
static int
@@ -211,6 +241,11 @@ xhci_init_hc(struct xhci_hcd *hcd)
if ((error = xhci_init_dcbaap(hcd)) < 0) {
return error;
}
+
+ if ((error = xhci_init_cmdring(hcd)) < 0) {
+ return error;
+ }
+
return 0;
}