From 17b73f78080f6bc545e61153793d6c1af8524db5 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 12 Oct 2025 13:01:18 -0400 Subject: kern: xhci: Allocate and init command ring / CRCR Signed-off-by: Ian Moffett --- src/sys/io/usb/hcd/xhci.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/sys/io/usb/hcd/xhci.c') 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 @@ -171,6 +171,36 @@ xhci_init_dcbaap(struct xhci_hcd *hcd) return 0; } +/* + * 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 */ @@ -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; } -- cgit v1.2.3