]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c
MdeModulePkg/SdMmc: Add break to avoid dead loop when polling OCR Reg
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / SdBlockIoPei / SdHci.c
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