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