From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BD310803A5 for ; Sun, 12 Mar 2017 22:12:16 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP; 12 Mar 2017 22:12:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,157,1486454400"; d="scan'208";a="74653417" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga005.jf.intel.com with ESMTP; 12 Mar 2017 22:12:16 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 12 Mar 2017 22:12:15 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.59]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.204]) with mapi id 14.03.0248.002; Mon, 13 Mar 2017 13:12:12 +0800 From: "Wu, Hao A" To: "Tian, Feng" , "edk2-devel@lists.01.org" Thread-Topic: [patch] MdeModulePkg/SdMmc: Add break to avoid dead loop when polling OCR Reg Thread-Index: AQHSm6lHpf6UAz1lkEyv+WVIWvT0laGSOEog Date: Mon, 13 Mar 2017 05:12:11 +0000 Message-ID: References: In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [patch] MdeModulePkg/SdMmc: Add break to avoid dead loop when polling OCR Reg X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Mar 2017 05:12:16 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Tian, Feng > Sent: Monday, March 13, 2017 11:24 AM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A > Subject: [patch] MdeModulePkg/SdMmc: Add break to avoid dead loop when > polling OCR Reg >=20 > 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. >=20 > Cc: Hao Wu > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Feng Tian > --- > MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c | 9 ++++++++- > MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c | 8 ++++++++ > MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c | 9 ++++++++- > MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c | 9 ++++++++- > 4 files changed, 32 insertions(+), 3 deletions(-) >=20 > diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c > b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c > index 9dbec10..6653a87 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; >=20 > PciIo =3D Private->PciIo; > PassThru =3D &Private->PassThru; > @@ -1119,7 +1120,8 @@ EmmcIdentification ( > return Status; > } >=20 > - Ocr =3D 0; > + Ocr =3D 0; > + Retry =3D 0; > do { > Status =3D EmmcGetOcr (PassThru, Slot, &Ocr); > if (EFI_ERROR (Status)) { > @@ -1127,6 +1129,11 @@ EmmcIdentification ( > return Status; > } > Ocr |=3D BIT30; > + > + if (Retry++ =3D=3D 100) { Hi Feng, Maybe a debug message can be added here to indicate the type of error, like other error handling logics in this function. Apart from that, the patch is good to me. Reviewed-by: Hao Wu Best Regards, Hao Wu > + return EFI_DEVICE_ERROR; > + } > + gBS->Stall(10 * 1000); > } while ((Ocr & BIT31) =3D=3D 0); >=20 > Status =3D EmmcGetAllCid (PassThru, Slot); > diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c > b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c > index 9122848..1da0849 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; >=20 > PciIo =3D Private->PciIo; > PassThru =3D &Private->PassThru; > @@ -1097,12 +1098,19 @@ 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 =3D 0; > + Retry =3D 0; > do { > Status =3D 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++ =3D=3D 100) { > + return EFI_DEVICE_ERROR; > + } > + gBS->Stall(10 * 1000); > } while ((Ocr & BIT31) =3D=3D 0); >=20 > // > diff --git a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c > b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c > index 2c0baca..5cb20a3 100644 > --- a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c > +++ b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c > @@ -2827,6 +2827,7 @@ EmmcPeimIdentification ( > EFI_STATUS Status; > UINT32 Ocr; > UINT32 Rca; > + UINTN Retry; >=20 > Status =3D EmmcPeimReset (Slot); > if (EFI_ERROR (Status)) { > @@ -2834,13 +2835,19 @@ EmmcPeimIdentification ( > return Status; > } >=20 > - Ocr =3D 0; > + Ocr =3D 0; > + Retry =3D 0; > do { > Status =3D EmmcPeimGetOcr (Slot, &Ocr); > if (EFI_ERROR (Status)) { > DEBUG ((EFI_D_ERROR, "EmmcPeimIdentification: EmmcPeimGetOcr fails > with %r\n", Status)); > return Status; > } > + > + if (Retry++ =3D=3D 100) { > + return EFI_DEVICE_ERROR; > + } > + MicroSecondDelay (10 * 1000); > } while ((Ocr & BIT31) =3D=3D 0); >=20 > Status =3D EmmcPeimGetAllCid (Slot); > diff --git a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c > b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c > index 23e6563..81076ba 100644 > --- a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c > +++ b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c > @@ -2754,7 +2754,7 @@ SdPeimIdentification ( > UINT32 PresentState; > UINT8 HostCtrl2; > SD_HC_SLOT_CAP Capability; > - > + UINTN Retry; > // > // 1. Send Cmd0 to the device > // > @@ -2842,12 +2842,19 @@ SdPeimIdentification ( > // Note here we only support the cards complied with SD physical > // layer simplified spec version 2.0 and version 3.0 and above. > // > + Ocr =3D 0; > + Retry =3D 0; > do { > Status =3D SdPeimSendOpCond (Slot, 0, Ocr, S18r, Xpc, TRUE, &Ocr); > if (EFI_ERROR (Status)) { > DEBUG ((EFI_D_ERROR, "SdPeimIdentification: SdPeimSendOpCond fails > with %r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc)); > return EFI_DEVICE_ERROR; > } > + > + if (Retry++ =3D=3D 100) { > + return EFI_DEVICE_ERROR; > + } > + MicroSecondDelay (10 * 1000); > } while ((Ocr & BIT31) =3D=3D 0); >=20 > // > -- > 2.7.1.windows.2