diff --git a/MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointer.c b/MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointer.c new file mode 100644 index 0000000000..a71efcbeea --- /dev/null +++ b/MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointer.c @@ -0,0 +1,77 @@ +/** @file + PEI Services Table Pointer Library. + + According to PI specification, the peiservice pointer is stored in the SSCRATCH + register of RISC-V architecture. + + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +/** + Caches a pointer PEI Services Table. + + Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer + in a CPU specific manner as specified in the CPU binding section of the Platform Initialization + Pre-EFI Initialization Core Interface Specification. + + If PeiServicesTablePointer is NULL, then ASSERT(). + + @param PeiServicesTablePointer The address of PeiServices pointer. +**/ +VOID +EFIAPI +SetPeiServicesTablePointer ( + IN CONST EFI_PEI_SERVICES **PeiServicesTablePointer + ) +{ + ASSERT (PeiServicesTablePointer != NULL); + RiscVSetSupervisorScratch ((UINT64)PeiServicesTablePointer); +} + +/** + Retrieves the cached value of the PEI Services Table pointer. + + Returns the cached value of the PEI Services Table pointer in a CPU specific manner + as specified in the CPU binding section of the Platform Initialization Pre-EFI + Initialization Core Interface Specification. + + If the cached PEI Services Table pointer is NULL, then ASSERT(). + + @return The pointer to PeiServices. + +**/ +CONST EFI_PEI_SERVICES ** +EFIAPI +GetPeiServicesTablePointer ( + VOID + ) +{ + return (CONST EFI_PEI_SERVICES **)RiscVGetSupervisorScratch (); +} + +/** + Perform CPU specific actions required to migrate the PEI Services Table + pointer from temporary RAM to permanent RAM. + +**/ +VOID +EFIAPI +MigratePeiServicesTablePointer ( + VOID + ) +{ + // + // PEI Services Table pointer is stored in CSR_SSCRATCH register. No additional + // migration actions are required. + // + return; +} diff --git a/MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointerLib.inf b/MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointerLib.inf new file mode 100644 index 0000000000..9c6d9e1fb5 --- /dev/null +++ b/MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointerLib.inf @@ -0,0 +1,33 @@ +## @file +# Instance of PEI Services Table Pointer Library using global variable for the table pointer. +# +# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 1.30 + BASE_NAME = PeiServicesTablePointerLib + MODULE_UNI_FILE = PeiServicesTablePointerLib.uni + FILE_GUID = 3b5bccaa-366f-42d1-93b1-64dd7ecb9fa7 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = PeiServicesTablePointerLib|PEIM PEI_CORE SEC + +# +# VALID_ARCHITECTURES = RISCV64 +# + +[Sources] + PeiServicesTablePointer.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib diff --git a/MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointerLib.uni b/MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointerLib.uni new file mode 100644 index 0000000000..0e9921f3d2 --- /dev/null +++ b/MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointerLib.uni @@ -0,0 +1,15 @@ +// /** @file +// Instance of PEI Services Table Pointer Library for RISCV. +// +// Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+// Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Instance of PEI Services Table Pointer Library using global variable for the table pointer" + +#string STR_MODULE_DESCRIPTION #language en-US "The PEI Services Table Pointer Library implementation that retrieves a pointer to the PEI Services Table from a global variable. Not available to modules that execute from read-only memory." + diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 066507b579..f8b3ff54c3 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -213,6 +213,7 @@ MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf MdePkg/Library/BaseSerialPortLibRiscVSbiLib/BaseSerialPortLibRiscVSbiLib.inf MdePkg/Library/BaseSerialPortLibRiscVSbiLib/BaseSerialPortLibRiscVSbiLibRam.inf + MdePkg/Library/PeiServicesTablePointerLibRiscV/PeiServicesTablePointerLib.inf [Components.LOONGARCH64] MdePkg/Library/PeiServicesTablePointerLibKs0/PeiServicesTablePointerLibKs0.inf