]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / EmmcBlockIoPei / EmmcHci.c
index d6d3bdbd91ebfbaccfc5c6480c6b94c0f159fe45..679646eeb27706bdb9627aa9b3f3873cca201fb7 100644 (file)
@@ -1,13 +1,7 @@
 /** @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
@@ -929,7 +923,7 @@ BuildAdmaDescTable (
   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
@@ -998,6 +992,8 @@ EmmcPeimCreateTrb (
   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
@@ -1007,7 +1003,7 @@ EmmcPeimCreateTrb (
     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
@@ -1032,13 +1028,29 @@ EmmcPeimCreateTrb (
     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
@@ -1071,12 +1083,16 @@ EmmcPeimFreeTrb (
   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
@@ -1241,11 +1257,11 @@ EmmcPeimExecTrb (
   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
@@ -1480,7 +1496,7 @@ EmmcPeimCheckTrbResult (
     //\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
@@ -1490,7 +1506,7 @@ EmmcPeimCheckTrbResult (
     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
@@ -2520,9 +2536,6 @@ EmmcPeimSwitchToHighSpeed (
 \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
@@ -2830,6 +2843,7 @@ EmmcPeimIdentification (
   EFI_STATUS                     Status;\r
   UINT32                         Ocr;\r
   UINT32                         Rca;\r
+  UINTN                          Retry;\r
 \r
   Status = EmmcPeimReset (Slot);\r
   if (EFI_ERROR (Status)) {\r
@@ -2837,13 +2851,20 @@ EmmcPeimIdentification (
     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