/** @file\r
\r
- Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php.\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
UINT64 Remaining;\r
UINT32 Address;\r
\r
- Data = (EFI_PHYSICAL_ADDRESS)(UINTN)Trb->Data;\r
+ Data = Trb->DataPhy;\r
DataLen = Trb->DataLen;\r
//\r
// Only support 32bit ADMA Descriptor Table\r
EMMC_TRB *Trb;\r
EFI_STATUS Status;\r
EMMC_HC_SLOT_CAP Capability;\r
+ EDKII_IOMMU_OPERATION MapOp;\r
+ UINTN MapLength;\r
\r
//\r
// Calculate a divisor for SD clock frequency\r
return NULL;\r
}\r
\r
- Trb = EmmcPeimAllocateMem (Slot->Private->Pool, sizeof (EMMC_TRB));\r
+ Trb = AllocateZeroPool (sizeof (EMMC_TRB));\r
if (Trb == NULL) {\r
return NULL;\r
}\r
goto Error;\r
}\r
\r
- if (Trb->DataLen < Trb->BlockSize) {\r
+ if ((Trb->DataLen != 0) && (Trb->DataLen < Trb->BlockSize)) {\r
Trb->BlockSize = (UINT16)Trb->DataLen;\r
}\r
\r
if (Packet->EmmcCmdBlk->CommandIndex == EMMC_SEND_TUNING_BLOCK) {\r
Trb->Mode = EmmcPioMode;\r
} else {\r
+ if (Trb->Read) {\r
+ MapOp = EdkiiIoMmuOperationBusMasterWrite;\r
+ } else {\r
+ MapOp = EdkiiIoMmuOperationBusMasterRead;\r
+ }\r
+\r
+ if (Trb->DataLen != 0) {\r
+ MapLength = Trb->DataLen;\r
+ Status = IoMmuMap (MapOp, Trb->Data, &MapLength, &Trb->DataPhy, &Trb->DataMap);\r
+\r
+ if (EFI_ERROR (Status) || (MapLength != Trb->DataLen)) {\r
+ DEBUG ((DEBUG_ERROR, "EmmcPeimCreateTrb: Fail to map data buffer.\n"));\r
+ goto Error;\r
+ }\r
+ }\r
+\r
if (Trb->DataLen == 0) {\r
Trb->Mode = EmmcNoData;\r
} else if (Capability.Adma2 != 0) {\r
IN EMMC_TRB *Trb\r
)\r
{\r
+ if ((Trb != NULL) && (Trb->DataMap != NULL)) {\r
+ IoMmuUnmap (Trb->DataMap);\r
+ }\r
+\r
if ((Trb != NULL) && (Trb->AdmaDesc != NULL)) {\r
EmmcPeimFreeMem (Trb->Slot->Private->Pool, Trb->AdmaDesc, Trb->AdmaDescSize);\r
}\r
\r
if (Trb != NULL) {\r
- EmmcPeimFreeMem (Trb->Slot->Private->Pool, Trb, sizeof (EMMC_TRB));\r
+ FreePool (Trb);\r
}\r
return;\r
}\r
EmmcPeimHcLedOnOff (Bar, TRUE);\r
\r
if (Trb->Mode == EmmcSdmaMode) {\r
- if ((UINT64)(UINTN)Trb->Data >= 0x100000000ul) {\r
+ if ((UINT64)(UINTN)Trb->DataPhy >= 0x100000000ul) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- SdmaAddr = (UINT32)(UINTN)Trb->Data;\r
+ SdmaAddr = (UINT32)(UINTN)Trb->DataPhy;\r
Status = EmmcPeimHcRwMmio (Bar + EMMC_HC_SDMA_ADDR, FALSE, sizeof (SdmaAddr), &SdmaAddr);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
//\r
// Update SDMA Address register.\r
//\r
- SdmaAddr = EMMC_SDMA_ROUND_UP ((UINT32)(UINTN)Trb->Data, EMMC_SDMA_BOUNDARY);\r
+ SdmaAddr = EMMC_SDMA_ROUND_UP ((UINT32)(UINTN)Trb->DataPhy, EMMC_SDMA_BOUNDARY);\r
Status = EmmcPeimHcRwMmio (\r
Bar + EMMC_HC_SDMA_ADDR,\r
FALSE,\r
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
- Trb->Data = (VOID*)(UINTN)SdmaAddr;\r
+ Trb->DataPhy = (UINT32)(UINTN)SdmaAddr;\r
}\r
\r
if ((Packet->EmmcCmdBlk->CommandType != EmmcCommandTypeAdtc) &&\r
\r
HsTiming = 1;\r
Status = EmmcPeimSwitchClockFreq (Slot, Rca, HsTiming, ClockFreq);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
\r
return Status;\r
}\r
EFI_STATUS Status;\r
UINT32 Ocr;\r
UINT32 Rca;\r
+ UINTN Retry;\r
\r
Status = EmmcPeimReset (Slot);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
\r
- Ocr = 0;\r
+ Ocr = 0;\r
+ Retry = 0;\r
do {\r
Status = EmmcPeimGetOcr (Slot, &Ocr);\r
if (EFI_ERROR (Status)) {\r
DEBUG ((EFI_D_ERROR, "EmmcPeimIdentification: EmmcPeimGetOcr fails with %r\n", Status));\r
return Status;\r
}\r
+\r
+ if (Retry++ == 100) {\r
+ DEBUG ((EFI_D_ERROR, "EmmcPeimIdentification: EmmcPeimGetOcr fails too many times\n"));\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+ MicroSecondDelay (10 * 1000);\r
} while ((Ocr & BIT31) == 0);\r
\r
Status = EmmcPeimGetAllCid (Slot);\r