From d48465508bd7ef0777e627ff9fd07d67ef92ae93 Mon Sep 17 00:00:00 2001 From: Tuan Phan Date: Mon, 8 Jun 2026 19:30:38 -0700 Subject: [PATCH] UefiCpuPkg: RiscV64: CpuTimerLib: Add SEC/PEI and DXE library instances Commit c27b5554 introduced a constructor that calls GetPerformanceCounterProperties() to help initializing mTimeBase early. However, in the PEI phase, this constructor may run before the HOB list is available, leading to a crash. This patch fixes the issue by providing a separate library instances for the SEC/PEI phases that avoid invoking this constructor. Also, rename this library as it can not be base library anymore. Signed-off-by: Tuan Phan --- .../CpuTimerLib.c | 4 +-- .../RiscV64CpuTimerDxeLib.inf} | 11 +++--- .../RiscV64CpuTimerLib.uni} | 0 .../RiscV64CpuTimerSecLib.inf | 36 +++++++++++++++++++ UefiCpuPkg/UefiCpuPkg.dsc | 3 +- 5 files changed, 46 insertions(+), 8 deletions(-) rename UefiCpuPkg/Library/{BaseRiscV64CpuTimerLib => RiscV64CpuTimerLib}/CpuTimerLib.c (95%) rename UefiCpuPkg/Library/{BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf => RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf} (58%) rename UefiCpuPkg/Library/{BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.uni => RiscV64CpuTimerLib/RiscV64CpuTimerLib.uni} (100%) create mode 100644 UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c b/UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c similarity index 95% rename from UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c rename to UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c index df4f8c2245..243ae48c33 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/CpuTimerLib.c +++ b/UefiCpuPkg/Library/RiscV64CpuTimerLib/CpuTimerLib.c @@ -124,7 +124,7 @@ GetPerformanceCounter ( return (UINT64)RiscVReadTimer (); } -/**return +/** Retrieves the 64-bit frequency in Hz and the range of performance counter values. @@ -275,7 +275,7 @@ GetTimeInNanoSecond ( **/ EFI_STATUS EFIAPI -BaseRiscV64CpuTimerLibConstructor ( +RiscV64CpuTimerLibConstructor ( VOID ) { diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf similarity index 58% rename from UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf rename to UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf index a3d25cda41..999d601005 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf +++ b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf @@ -1,8 +1,9 @@ ## @file -# RISC-V Base CPU Timer Library Instance +# RISC-V CPU Timer Library Instance # # Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# Copyright (C) 2026 Qualcomm Technologies, Inc. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -10,13 +11,13 @@ [Defines] INF_VERSION = 0x0001001B - BASE_NAME = BaseRisV64CpuTimerLib + BASE_NAME = RiscV64CpuTimerDxeLib FILE_GUID = B635A600-EA24-4199-88E8-5761EEA96A51 MODULE_TYPE = BASE VERSION_STRING = 1.0 - LIBRARY_CLASS = TimerLib - MODULE_UNI_FILE = BaseRisV64CpuTimerLib.uni - CONSTRUCTOR = BaseRiscV64CpuTimerLibConstructor + LIBRARY_CLASS = TimerLib | DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_DRIVER UEFI_APPLICATION + MODULE_UNI_FILE = RiscV64CpuTimerLib.uni + CONSTRUCTOR = RiscV64CpuTimerLibConstructor [Sources] CpuTimerLib.c diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.uni b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerLib.uni similarity index 100% rename from UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.uni rename to UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerLib.uni diff --git a/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf new file mode 100644 index 0000000000..e4f0bf36e4 --- /dev/null +++ b/UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf @@ -0,0 +1,36 @@ +## @file +# RISC-V CPU Timer Library Instance +# +# Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.
+# Copyright (c) 2022, Ventana Micro Systems Inc. All rights reserved.
+# Copyright (C) 2026 Qualcomm Technologies, Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = RiscV64CpuTimerSecLib + FILE_GUID = 59D73C04-6D8F-4F7A-A444-86F059CCF939 + MODULE_TYPE = SEC + VERSION_STRING = 1.0 + LIBRARY_CLASS = TimerLib | SEC PEI_CORE PEIM + MODULE_UNI_FILE = RiscV64CpuTimerLib.uni + +[Sources] + CpuTimerLib.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + PcdLib + DebugLib + FdtLib + HobLib + +[Guids] + gFdtHobGuid diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index e7a72a370c..f281c1174b 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -224,8 +224,9 @@ UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf [Components.RISCV64] - UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf + UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerDxeLib.inf + UefiCpuPkg/Library/RiscV64CpuTimerLib/RiscV64CpuTimerSecLib.inf UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf UefiCpuPkg/CpuDxeRiscV64/CpuDxeRiscV64.inf UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf