]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/SdMmc: Add break to avoid dead loop when polling OCR Reg
authorFeng Tian <feng.tian@intel.com>
Mon, 13 Mar 2017 03:20:41 +0000 (11:20 +0800)
committerFeng Tian <feng.tian@intel.com>
Mon, 13 Mar 2017 13:41:46 +0000 (21:41 +0800)
At worst case, OCR register may always not set BIT31. It will cause
original code enter to dead loop. Adding a break for such case.

Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c
MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c

index 9dbec1016d52a125b33eaedb0ac513ddd33d4caf..c5fd214307ff5658bd80b17115c32fe67167372d 100755 (executable)
@@ -1109,6 +1109,7 @@ EmmcIdentification (
   EFI_SD_MMC_PASS_THRU_PROTOCOL  *PassThru;\r
   UINT32                         Ocr;\r
   UINT16                         Rca;\r
+  UINTN                          Retry;\r
 \r
   PciIo    = Private->PciIo;\r
   PassThru = &Private->PassThru;\r
@@ -1119,7 +1120,8 @@ EmmcIdentification (
     return Status;\r
   }\r
 \r
-  Ocr = 0;\r
+  Ocr   = 0;\r
+  Retry = 0;\r
   do {\r
     Status = EmmcGetOcr (PassThru, Slot, &Ocr);\r
     if (EFI_ERROR (Status)) {\r
@@ -1127,6 +1129,12 @@ EmmcIdentification (
       return Status;\r
     }\r
     Ocr |= BIT30;\r
+\r
+    if (Retry++ == 100) {\r
+      DEBUG ((DEBUG_VERBOSE, "EmmcIdentification: Executing Cmd1 fails too many times\n"));\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+    gBS->Stall(10 * 1000);\r
   } while ((Ocr & BIT31) == 0);\r
 \r
   Status = EmmcGetAllCid (PassThru, Slot);\r
index 91228480219bf924ae44fe39dae33dc2b57d05ad..9e70de956f36a33cda9bcc1220b9e0a72903cdfc 100644 (file)
@@ -1017,6 +1017,7 @@ SdCardIdentification (
   UINT8                          PowerCtrl;\r
   UINT32                         PresentState;\r
   UINT8                          HostCtrl2;\r
+  UINTN                          Retry;\r
 \r
   PciIo    = Private->PciIo;\r
   PassThru = &Private->PassThru;\r
@@ -1097,12 +1098,20 @@ SdCardIdentification (
   //    Note here we only support the cards complied with SD physical\r
   //    layer simplified spec version 2.0 and version 3.0 and above.\r
   //\r
+  Ocr   = 0;\r
+  Retry = 0;\r
   do {\r
     Status = SdCardSendOpCond (PassThru, Slot, 0, Ocr, S18r, Xpc, TRUE, &Ocr);\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails with %r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));\r
       return EFI_DEVICE_ERROR;\r
     }\r
+\r
+    if (Retry++ == 100) {\r
+      DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails too many times\n"));\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+    gBS->Stall(10 * 1000);\r
   } while ((Ocr & BIT31) == 0);\r
 \r
   //\r
index 2c0baca3e34ef9de54505f87ca7c1ff3e1141a0c..7c40892da063ae6b66300e54f1d148d077eb3978 100644 (file)
@@ -2827,6 +2827,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
@@ -2834,13 +2835,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
index 23e6563d499144f4fb3914ede68ab098fe0e372d..eebadd79bc9879efcab9cd88e1c3fdcbf56ae3b2 100644 (file)
@@ -2754,7 +2754,7 @@ SdPeimIdentification (
   UINT32                         PresentState;\r
   UINT8                          HostCtrl2;\r
   SD_HC_SLOT_CAP                 Capability;\r
-\r
+  UINTN                          Retry;\r
   //\r
   // 1. Send Cmd0 to the device\r
   //\r
@@ -2842,12 +2842,20 @@ SdPeimIdentification (
   //    Note here we only support the cards complied with SD physical\r
   //    layer simplified spec version 2.0 and version 3.0 and above.\r
   //\r
+  Ocr   = 0;\r
+  Retry = 0;\r
   do {\r
     Status = SdPeimSendOpCond (Slot, 0, Ocr, S18r, Xpc, TRUE, &Ocr);\r
     if (EFI_ERROR (Status)) {\r
       DEBUG ((EFI_D_ERROR, "SdPeimIdentification: SdPeimSendOpCond fails with %r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));\r
       return EFI_DEVICE_ERROR;\r
     }\r
+\r
+    if (Retry++ == 100) {\r
+      DEBUG ((EFI_D_ERROR, "SdPeimIdentification: SdPeimSendOpCond fails too many times\n"));\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+    MicroSecondDelay (10 * 1000);\r
   } while ((Ocr & BIT31) == 0);\r
 \r
   //\r