X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FEhciDxe%2FEhciSched.c;h=fea6f47f4c04146e85cae140a9689dde97527403;hp=4b1cc7399f026febce6689466df448f61f85d4e9;hb=d1102dba7210b95e41d06c2338a22ba6af248645;hpb=6d3ea23f1183f3378a53e44d34c0a27aebec7d9a diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c index 4b1cc7399f..fea6f47f4c 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c @@ -2,8 +2,8 @@ EHCI transfer scheduling routines. -Copyright (c) 2007 - 2009, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -34,11 +34,12 @@ EhcCreateHelpQ ( EHC_QH *Qh; QH_HW *QhHw; EHC_QTD *Qtd; + EFI_PHYSICAL_ADDRESS PciAddr; // // Create an inactive Qtd to terminate the short packet read. // - Qtd = EhcCreateQtd (Ehc, NULL, 0, QTD_PID_INPUT, 0, 64); + Qtd = EhcCreateQtd (Ehc, NULL, NULL, 0, QTD_PID_INPUT, 0, 64); if (Qtd == NULL) { return EFI_OUT_OF_RESOURCES; @@ -68,10 +69,12 @@ EhcCreateHelpQ ( return EFI_OUT_OF_RESOURCES; } + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Qh, sizeof (EHC_QH)); QhHw = &Qh->QhHw; - QhHw->HorizonLink = QH_LINK (QhHw, EHC_TYPE_QH, FALSE); + QhHw->HorizonLink = QH_LINK (PciAddr + OFFSET_OF(EHC_QH, QhHw), EHC_TYPE_QH, FALSE); QhHw->Status = QTD_STAT_HALTED; QhHw->ReclaimHead = 1; + Qh->NextQh = Qh; Ehc->ReclaimHead = Qh; // @@ -114,8 +117,8 @@ EhcInitSched ( UINTN Pages; UINTN Bytes; UINTN Index; - UINT32 *Desc; EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS PciAddr; // // First initialize the periodical schedule data: @@ -156,10 +159,17 @@ EhcInitSched ( return EFI_OUT_OF_RESOURCES; } - Ehc->PeriodFrameHost = Buf; - Ehc->PeriodFrame = (VOID *) ((UINTN) PhyAddr); + Ehc->PeriodFrame = Buf; Ehc->PeriodFrameMap = Map; - Ehc->High32bitAddr = EHC_HIGH_32BIT (PhyAddr); + + // + // Program the FRAMELISTBASE register with the low 32 bit addr + // + EhcWriteOpReg (Ehc, EHC_FRAME_BASE_OFFSET, EHC_LOW_32BIT (PhyAddr)); + // + // Program the CTRLDSSEGMENT register with the high 32 bit addr + // + EhcWriteOpReg (Ehc, EHC_CTRLDSSEG_OFFSET, EHC_HIGH_32BIT (PhyAddr)); // // Init memory pool management then create the helper @@ -168,38 +178,73 @@ EhcInitSched ( // Ehc->MemPool = UsbHcInitMemPool ( PciIo, - EHC_BIT_IS_SET (Ehc->HcCapParams, HCCP_64BIT), - Ehc->High32bitAddr + Ehc->Support64BitDma, + EHC_HIGH_32BIT (PhyAddr) ); if (Ehc->MemPool == NULL) { - return EFI_OUT_OF_RESOURCES; + Status = EFI_OUT_OF_RESOURCES; + goto ErrorExit1; } Status = EhcCreateHelpQ (Ehc); if (EFI_ERROR (Status)) { - return Status; + goto ErrorExit; } // // Initialize the frame list entries then set the registers // - Desc = (UINT32 *) Ehc->PeriodFrame; + Ehc->PeriodFrameHost = AllocateZeroPool (EHC_FRAME_LEN * sizeof (UINTN)); + if (Ehc->PeriodFrameHost == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto ErrorExit; + } + + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Ehc->PeriodOne, sizeof (EHC_QH)); for (Index = 0; Index < EHC_FRAME_LEN; Index++) { - Desc[Index] = QH_LINK (Ehc->PeriodOne, EHC_TYPE_QH, FALSE); + // + // Store the pci bus address of the QH in period frame list which will be accessed by pci bus master. + // + ((UINT32 *)(Ehc->PeriodFrame))[Index] = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE); + // + // Store the host address of the QH in period frame list which will be accessed by host. + // + ((UINTN *)(Ehc->PeriodFrameHost))[Index] = (UINTN)Ehc->PeriodOne; } - EhcWriteOpReg (Ehc, EHC_FRAME_BASE_OFFSET, EHC_LOW_32BIT (Ehc->PeriodFrame)); - // // Second initialize the asynchronous schedule: // Only need to set the AsynListAddr register to // the reclamation header // - EhcWriteOpReg (Ehc, EHC_ASYNC_HEAD_OFFSET, EHC_LOW_32BIT (Ehc->ReclaimHead)); + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Ehc->ReclaimHead, sizeof (EHC_QH)); + EhcWriteOpReg (Ehc, EHC_ASYNC_HEAD_OFFSET, EHC_LOW_32BIT (PciAddr)); return EFI_SUCCESS; + +ErrorExit: + if (Ehc->PeriodOne != NULL) { + UsbHcFreeMem (Ehc->MemPool, Ehc->PeriodOne, sizeof (EHC_QH)); + Ehc->PeriodOne = NULL; + } + + if (Ehc->ReclaimHead != NULL) { + UsbHcFreeMem (Ehc->MemPool, Ehc->ReclaimHead, sizeof (EHC_QH)); + Ehc->ReclaimHead = NULL; + } + + if (Ehc->ShortReadStop != NULL) { + UsbHcFreeMem (Ehc->MemPool, Ehc->ShortReadStop, sizeof (EHC_QTD)); + Ehc->ShortReadStop = NULL; + } + +ErrorExit1: + PciIo->FreeBuffer (PciIo, Pages, Buf); + PciIo->Unmap (PciIo, Map); + + return Status; } @@ -248,11 +293,16 @@ EhcFreeSched ( PciIo->FreeBuffer ( PciIo, EFI_SIZE_TO_PAGES (EFI_PAGE_SIZE), - Ehc->PeriodFrameHost + Ehc->PeriodFrame ); Ehc->PeriodFrame = NULL; } + + if (Ehc->PeriodFrameHost != NULL) { + FreePool (Ehc->PeriodFrameHost); + Ehc->PeriodFrameHost = NULL; + } } @@ -274,6 +324,7 @@ EhcLinkQhToAsync ( ) { EHC_QH *Head; + EFI_PHYSICAL_ADDRESS PciAddr; // // Append the queue head after the reclaim header, then @@ -285,8 +336,10 @@ EhcLinkQhToAsync ( Qh->NextQh = Head->NextQh; Head->NextQh = Qh; - Qh->QhHw.HorizonLink = QH_LINK (Head, EHC_TYPE_QH, FALSE);; - Head->QhHw.HorizonLink = QH_LINK (Qh, EHC_TYPE_QH, FALSE); + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Qh->NextQh, sizeof (EHC_QH)); + Qh->QhHw.HorizonLink = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE); + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Head->NextQh, sizeof (EHC_QH)); + Head->QhHw.HorizonLink = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE); } @@ -306,6 +359,7 @@ EhcUnlinkQhFromAsync ( { EHC_QH *Head; EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS PciAddr; ASSERT (Ehc->ReclaimHead->NextQh == Qh); @@ -319,7 +373,8 @@ EhcUnlinkQhFromAsync ( Head->NextQh = Qh->NextQh; Qh->NextQh = NULL; - Head->QhHw.HorizonLink = QH_LINK (Head, EHC_TYPE_QH, FALSE); + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Head->NextQh, sizeof (EHC_QH)); + Head->QhHw.HorizonLink = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE); // // Set and wait the door bell to synchronize with the hardware @@ -347,20 +402,18 @@ EhcLinkQhToPeriod ( IN EHC_QH *Qh ) { - UINT32 *Frames; UINTN Index; EHC_QH *Prev; EHC_QH *Next; - - Frames = Ehc->PeriodFrame; + EFI_PHYSICAL_ADDRESS PciAddr; for (Index = 0; Index < EHC_FRAME_LEN; Index += Qh->Interval) { // // First QH can't be NULL because we always keep PeriodOne // heads on the frame list // - ASSERT (!EHC_LINK_TERMINATED (Frames[Index])); - Next = EHC_ADDR (Ehc->High32bitAddr, Frames[Index]); + ASSERT (!EHC_LINK_TERMINATED (((UINT32*)Ehc->PeriodFrame)[Index])); + Next = (EHC_QH*)((UINTN*)Ehc->PeriodFrameHost)[Index]; Prev = NULL; // @@ -408,7 +461,8 @@ EhcLinkQhToPeriod ( Prev->NextQh = Qh; Qh->QhHw.HorizonLink = Prev->QhHw.HorizonLink; - Prev->QhHw.HorizonLink = QH_LINK (Qh, EHC_TYPE_QH, FALSE); + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Qh, sizeof (EHC_QH)); + Prev->QhHw.HorizonLink = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE); break; } @@ -419,14 +473,18 @@ EhcLinkQhToPeriod ( // if (Qh->NextQh == NULL) { Qh->NextQh = Next; - Qh->QhHw.HorizonLink = QH_LINK (Next, EHC_TYPE_QH, FALSE); + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Next, sizeof (EHC_QH)); + Qh->QhHw.HorizonLink = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE); } + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Qh, sizeof (EHC_QH)); + if (Prev == NULL) { - Frames[Index] = QH_LINK (Qh, EHC_TYPE_QH, FALSE); + ((UINT32*)Ehc->PeriodFrame)[Index] = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE); + ((UINTN*)Ehc->PeriodFrameHost)[Index] = (UINTN)Qh; } else { Prev->NextQh = Qh; - Prev->QhHw.HorizonLink = QH_LINK (Qh, EHC_TYPE_QH, FALSE); + Prev->QhHw.HorizonLink = QH_LINK (PciAddr, EHC_TYPE_QH, FALSE); } } } @@ -446,20 +504,17 @@ EhcUnlinkQhFromPeriod ( IN EHC_QH *Qh ) { - UINT32 *Frames; UINTN Index; EHC_QH *Prev; EHC_QH *This; - Frames = Ehc->PeriodFrame; - for (Index = 0; Index < EHC_FRAME_LEN; Index += Qh->Interval) { // // Frame link can't be NULL because we always keep PeroidOne // on the frame list // - ASSERT (!EHC_LINK_TERMINATED (Frames[Index])); - This = EHC_ADDR (Ehc->High32bitAddr, Frames[Index]); + ASSERT (!EHC_LINK_TERMINATED (((UINT32*)Ehc->PeriodFrame)[Index])); + This = (EHC_QH*)((UINTN*)Ehc->PeriodFrameHost)[Index]; Prev = NULL; // @@ -483,7 +538,8 @@ EhcUnlinkQhFromPeriod ( // // Qh is the first entry in the frame // - Frames[Index] = Qh->QhHw.HorizonLink; + ((UINT32*)Ehc->PeriodFrame)[Index] = Qh->QhHw.HorizonLink; + ((UINTN*)Ehc->PeriodFrameHost)[Index] = (UINTN)Qh->NextQh; } else { Prev->NextQh = Qh->NextQh; Prev->QhHw.HorizonLink = Qh->QhHw.HorizonLink; @@ -513,6 +569,7 @@ EhcCheckUrbResult ( QTD_HW *QtdHw; UINT8 State; BOOLEAN Finished; + EFI_PHYSICAL_ADDRESS PciAddr; ASSERT ((Ehc != NULL) && (Urb != NULL) && (Urb->Qh != NULL)); @@ -582,14 +639,15 @@ EhcCheckUrbResult ( // ShortReadStop. If it is a setup transfer, need to check the // Status Stage of the setup transfer to get the finial result // - if (QtdHw->AltNext == QTD_LINK (Ehc->ShortReadStop, FALSE)) { - DEBUG ((EFI_D_INFO, "EhcCheckUrbResult: Short packet read, break\n")); + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Ehc->ShortReadStop, sizeof (EHC_QTD)); + if (QtdHw->AltNext == QTD_LINK (PciAddr, FALSE)) { + DEBUG ((EFI_D_VERBOSE, "EhcCheckUrbResult: Short packet read, break\n")); Finished = TRUE; goto ON_EXIT; } - DEBUG ((EFI_D_INFO, "EhcCheckUrbResult: Short packet read, continue\n")); + DEBUG ((EFI_D_VERBOSE, "EhcCheckUrbResult: Short packet read, continue\n")); } } } @@ -633,19 +691,30 @@ EhcExecTransfer ( UINTN Index; UINTN Loop; BOOLEAN Finished; + BOOLEAN InfiniteLoop; - Status = EFI_SUCCESS; - Loop = (TimeOut * EHC_1_MILLISECOND / EHC_SYNC_POLL_INTERVAL) + 1; - Finished = FALSE; + Status = EFI_SUCCESS; + Loop = TimeOut * EHC_1_MILLISECOND; + Finished = FALSE; + InfiniteLoop = FALSE; - for (Index = 0; Index < Loop; Index++) { + // + // According to UEFI spec section 16.2.4, If Timeout is 0, then the caller + // must wait for the function to be completed until EFI_SUCCESS or EFI_DEVICE_ERROR + // is returned. + // + if (TimeOut == 0) { + InfiniteLoop = TRUE; + } + + for (Index = 0; InfiniteLoop || (Index < Loop); Index++) { Finished = EhcCheckUrbResult (Ehc, Urb); if (Finished) { break; } - gBS->Stall (EHC_SYNC_POLL_INTERVAL); + gBS->Stall (EHC_1_MICROSECOND); } if (!Finished) { @@ -803,11 +872,13 @@ ON_ERROR: /** Update the queue head for next round of asynchronous transfer. + @param Ehc The EHCI device. @param Urb The URB to update. **/ VOID EhcUpdateAsyncRequest ( + IN USB2_HC_DEV *Ehc, IN URB *Urb ) { @@ -817,6 +888,7 @@ EhcUpdateAsyncRequest ( EHC_QTD *Qtd; QTD_HW *QtdHw; UINTN Index; + EFI_PHYSICAL_ADDRESS PciAddr; Qtd = NULL; @@ -843,7 +915,12 @@ EhcUpdateAsyncRequest ( QtdHw->ErrCnt = QTD_MAX_ERR; QtdHw->CurPage = 0; QtdHw->TotalBytes = (UINT32) Qtd->DataLen; - QtdHw->Page[0] = EHC_LOW_32BIT (Qtd->Data); + // + // calculate physical address by offset. + // + PciAddr = (UINTN)Urb->DataPhy + ((UINTN)Qtd->Data - (UINTN)Urb->Data); + QtdHw->Page[0] = EHC_LOW_32BIT (PciAddr); + QtdHw->PageHigh[0]= EHC_HIGH_32BIT (PciAddr); } // @@ -860,7 +937,7 @@ EhcUpdateAsyncRequest ( QhHw->Pid = 0; QhHw->ErrCnt = 0; QhHw->CurPage = 0; - QhHw->IOC = 0; + QhHw->Ioc = 0; QhHw->TotalBytes = 0; for (Index = 0; Index < 5; Index++) { @@ -868,7 +945,8 @@ EhcUpdateAsyncRequest ( QhHw->PageHigh[Index] = 0; } - QhHw->NextQtd = QTD_LINK (FirstQtd, FALSE); + PciAddr = UsbHcGetPciAddressForHostMem (Ehc->MemPool, FirstQtd, sizeof (EHC_QTD)); + QhHw->NextQtd = QTD_LINK (PciAddr, FALSE); } return ; @@ -936,14 +1014,14 @@ EhcMonitorAsyncRequests ( ProcBuf = AllocatePool (Urb->Completed); if (ProcBuf == NULL) { - EhcUpdateAsyncRequest (Urb); + EhcUpdateAsyncRequest (Ehc, Urb); continue; } CopyMem (ProcBuf, Urb->Data, Urb->Completed); } - EhcUpdateAsyncRequest (Urb); + EhcUpdateAsyncRequest (Ehc, Urb); // // Leave error recovery to its related device driver. A