From 13d9e8ec98ee3f9f14a45471b38a22b9fd66d1ce Mon Sep 17 00:00:00 2001 From: "Ke, VincentX" Date: Thu, 23 Dec 2021 15:07:54 +0800 Subject: MdeModulePkg: Put off UFS HCS.DP checking to fix timing problem BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3776 Put off UFS HCS.DP (Device Attached) checking until UfsDeviceDetection() to fix timing problem. Cc: Hao A Wu Cc: Ray Ni Cc: Ian Chiu Cc: Maggie Chu Signed-off-by: VincentX Ke Reviewed-by: Hao A Wu --- MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c | 47 ++++++++++++----------------- 1 file changed, 19 insertions(+), 28 deletions(-) (limited to 'MdeModulePkg') diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c index 409ea283f5..d19a7fed6e 100644 --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c @@ -1355,23 +1355,6 @@ UfsExecUicCommands ( } } - // - // Check value of HCS.DP and make sure that there is a device attached to the Link. - // - Address = UfsHcBase + UFS_HC_STATUS_OFFSET; - Data = MmioRead32 (Address); - if ((Data & UFS_HC_HCS_DP) == 0) { - Address = UfsHcBase + UFS_HC_IS_OFFSET; - Status = UfsWaitMemSet (Address, UFS_HC_IS_ULSS, UFS_HC_IS_ULSS, UFS_TIMEOUT); - if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; - } - - return EFI_NOT_FOUND; - } - - DEBUG ((DEBUG_INFO, "UfsblockioPei: found a attached UFS device\n")); - return EFI_SUCCESS; } @@ -1445,6 +1428,8 @@ UfsDeviceDetection ( ) { UINTN Retry; + UINTN Address; + UINT32 Data; EFI_STATUS Status; // @@ -1453,22 +1438,28 @@ UfsDeviceDetection ( // for (Retry = 0; Retry < 3; Retry++) { Status = UfsExecUicCommands (Private, UfsUicDmeLinkStartup, 0, 0, 0); - if (!EFI_ERROR (Status)) { - break; + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; } - if (Status == EFI_NOT_FOUND) { - continue; + // + // Check value of HCS.DP and make sure that there is a device attached to the Link + // + Address = Private->UfsHcBase + UFS_HC_STATUS_OFFSET; + Data = MmioRead32 (Address); + if ((Data & UFS_HC_HCS_DP) == 0) { + Address = Private->UfsHcBase + UFS_HC_IS_OFFSET; + Status = UfsWaitMemSet (Address, UFS_HC_IS_ULSS, UFS_HC_IS_ULSS, UFS_TIMEOUT); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + } else { + DEBUG ((DEBUG_INFO, "UfsblockioPei: found a attached UFS device\n")); + return EFI_SUCCESS; } - - return EFI_DEVICE_ERROR; } - if (Retry == 3) { - return EFI_NOT_FOUND; - } - - return EFI_SUCCESS; + return EFI_NOT_FOUND; } /** -- cgit v1.2.3