summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Bus/Pci
diff options
context:
space:
mode:
authorFeng Tian <feng.tian@intel.com>2017-03-13 11:20:41 +0800
committerFeng Tian <feng.tian@intel.com>2017-03-13 21:41:46 +0800
commitec86d28558d4f9f325926be1444b2d4ce32a0dc2 (patch)
treef1569fa712cead79fe0ce47241707c92701692c2 /MdeModulePkg/Bus/Pci
parent1c3ac4b91efaa366d899cbe23451a0b2906d4d13 (diff)
downloadedk2-ec86d28558d4f9f325926be1444b2d4ce32a0dc2.zip
edk2-ec86d28558d4f9f325926be1444b2d4ce32a0dc2.tar.gz
edk2-ec86d28558d4f9f325926be1444b2d4ce32a0dc2.tar.bz2
MdeModulePkg/SdMmc: Add break to avoid dead loop when polling OCR Reg
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>
Diffstat (limited to 'MdeModulePkg/Bus/Pci')
-rwxr-xr-xMdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c10
-rw-r--r--MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c9
2 files changed, 18 insertions, 1 deletions
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
index 9dbec10..c5fd214 100755
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
@@ -1109,6 +1109,7 @@ EmmcIdentification (
EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
UINT32 Ocr;
UINT16 Rca;
+ UINTN Retry;
PciIo = Private->PciIo;
PassThru = &Private->PassThru;
@@ -1119,7 +1120,8 @@ EmmcIdentification (
return Status;
}
- Ocr = 0;
+ Ocr = 0;
+ Retry = 0;
do {
Status = EmmcGetOcr (PassThru, Slot, &Ocr);
if (EFI_ERROR (Status)) {
@@ -1127,6 +1129,12 @@ EmmcIdentification (
return Status;
}
Ocr |= BIT30;
+
+ if (Retry++ == 100) {
+ DEBUG ((DEBUG_VERBOSE, "EmmcIdentification: Executing Cmd1 fails too many times\n"));
+ return EFI_DEVICE_ERROR;
+ }
+ gBS->Stall(10 * 1000);
} while ((Ocr & BIT31) == 0);
Status = EmmcGetAllCid (PassThru, Slot);
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
index 9122848..9e70de9 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
@@ -1017,6 +1017,7 @@ SdCardIdentification (
UINT8 PowerCtrl;
UINT32 PresentState;
UINT8 HostCtrl2;
+ UINTN Retry;
PciIo = Private->PciIo;
PassThru = &Private->PassThru;
@@ -1097,12 +1098,20 @@ SdCardIdentification (
// Note here we only support the cards complied with SD physical
// layer simplified spec version 2.0 and version 3.0 and above.
//
+ Ocr = 0;
+ Retry = 0;
do {
Status = SdCardSendOpCond (PassThru, Slot, 0, Ocr, S18r, Xpc, TRUE, &Ocr);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails with %r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));
return EFI_DEVICE_ERROR;
}
+
+ if (Retry++ == 100) {
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails too many times\n"));
+ return EFI_DEVICE_ERROR;
+ }
+ gBS->Stall(10 * 1000);
} while ((Ocr & BIT31) == 0);
//