Command RING Initialize

This commit is contained in:
xj 2024-07-16 06:10:40 -07:00
parent 6504f11f00
commit 098d39181d
1 changed files with 36 additions and 2 deletions

View File

@ -867,13 +867,31 @@ err_alloc_array_vir:
*/ */
static int xhci_command_alloc ( struct xhci_host *xhci ) { static int xhci_command_alloc ( struct xhci_host *xhci ) {
uintptr_t crp; 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 */ /* Allocate TRB ring */
#if 0
xhci->cmds = usb_align(XHCI_RING_SIZE, sizeof(*xhci->cmds)); /* command ring */ xhci->cmds = usb_align(XHCI_RING_SIZE, sizeof(*xhci->cmds)); /* command ring */
if (! xhci->cmds) if (! xhci->cmds)
goto err_ring_alloc; 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)); memset(xhci->cmds, 0U, sizeof(*xhci->cmds));
xhci->cmds->lock = usb_osal_mutex_create(); 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 */ xhci->cmds->cs = 1; /* cycle state = 1 */
/* Program command ring control register */ /* 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 ), if ( ( rc = xhci_writeq ( xhci, ( crp | XHCI_CRCR_RCS ),
xhci->op + XHCI_OP_CRCR ) ) != 0 ) xhci->op + XHCI_OP_CRCR ) ) != 0 )
goto err_writeq; 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, USB_LOG_DBG("XHCI %s CRCR at [%08lx,%08lx)\n", xhci->name,
( xhci->cmds->ring ), ( xhci->cmds->ring ),