From 098d39181d3819c7e503116c8efe1c6731652c95 Mon Sep 17 00:00:00 2001 From: xj Date: Tue, 16 Jul 2024 06:10:40 -0700 Subject: [PATCH] Command RING Initialize --- .../drivers/usb/components/port/xhci/xhci.c | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/xhci.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/xhci.c index 8484d7430..09552e602 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/xhci.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/xhci.c @@ -867,13 +867,31 @@ err_alloc_array_vir: */ static int xhci_command_alloc ( struct xhci_host *xhci ) { uintptr_t crp; - int rc; + uintptr_t cmds_addr, cmds_phy; + size_t len; + int rc, i; + struct xhci_trb_link *trb_link; /* Allocate TRB ring */ +#if 0 xhci->cmds = usb_align(XHCI_RING_SIZE, sizeof(*xhci->cmds)); /* command ring */ if (! xhci->cmds) goto err_ring_alloc; +#endif + len = sizeof(*xhci->cmds); + rc = naive_mmap(&cmds_addr, &cmds_phy, len, false); + + if(rc != 0){ + USB_LOG_ERR("XHCI %s could not allocate CMD RING\n", xhci->name ); + rc = -ENOMEM; + goto err_ring_alloc; + } + + xhci->cmds_addr = cmds_addr; + xhci->cmds_phy = cmds_phy; + + xhci->cmds = (struct xhci_ring *)cmds_addr; memset(xhci->cmds, 0U, sizeof(*xhci->cmds)); xhci->cmds->lock = usb_osal_mutex_create(); @@ -882,10 +900,26 @@ static int xhci_command_alloc ( struct xhci_host *xhci ) { xhci->cmds->cs = 1; /* cycle state = 1 */ /* Program command ring control register */ - crp = (uintptr_t)( xhci->cmds ); +// crp = (uintptr_t)( xhci->cmds ); + +#if 0 if ( ( rc = xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ), xhci->op + XHCI_OP_CRCR ) ) != 0 ) goto err_writeq; +#endif + + for(i = 0; i < XHCI_RING_ITEMS; i++){ + trb_link = (struct xhci_trb_link *)&xhci->cmds->ring[i]; + trb_link->reserved_c |= XHCI_TRB_C; + + } + + trb_link = (struct xhci_trb_link *)&xhci->cmds->ring[XHCI_RING_ITEMS - 1]; + trb_link->reserved_c |= XHCI_TRB_TC; + +if ( ( rc = xhci_writeq ( xhci, ( cmds_phy | XHCI_CRCR_RCS ), + xhci->op_addr + XHCI_OP_CRCR ) ) != 0 ) + goto err_writeq; USB_LOG_DBG("XHCI %s CRCR at [%08lx,%08lx)\n", xhci->name, ( xhci->cmds->ring ),