--- /dev/null
+/** @file\r
+\r
+ Common Platform Runtime Mechanism (PRM) definitions.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef PRM_H_\r
+#define PRM_H_\r
+\r
+#include <Uefi.h>\r
+#include <PrmContextBuffer.h>\r
+\r
+#if defined(_MSC_VER)\r
+ #define PRM_EXPORT_API __declspec(dllexport)\r
+#else\r
+ #define PRM_EXPORT_API\r
+#endif\r
+\r
+#define PRM_HANDLER_NAME_MAXIMUM_LENGTH 128\r
+\r
+#define PRM_STRING_(x) #x\r
+#define PRM_STRING(x) PRM_STRING_(x)\r
+\r
+/**\r
+ A Platform Runtime Mechanism (PRM) handler function.\r
+\r
+ @param[in] ParameterBuffer A pointer to a buffer with arbitrary data that is allocated and populated\r
+ by the PRM handler caller.\r
+ @param[in] ContextBuffer A pointer to a buffer with arbitrary data that is allocated in the firmware\r
+ boot environment.\r
+\r
+ @retval EFI_STATUS The PRM handler executed successfully.\r
+ @retval Others An error occurred in the PRM handler.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI PRM_HANDLER) (\r
+ IN VOID *ParameterBuffer OPTIONAL,\r
+ IN PRM_CONTEXT_BUFFER *ContextBuffer OPTIONAL\r
+ );\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+\r
+ Definitions for the Platform Runtime Mechanism (PRM) context buffer structures.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef PRM_CONTEXT_BUFFER_H_\r
+#define PRM_CONTEXT_BUFFER_H_\r
+\r
+#include <PrmDataBuffer.h>\r
+#include <PrmMmio.h>\r
+#include <Uefi.h>\r
+\r
+#define PRM_CONTEXT_BUFFER_SIGNATURE SIGNATURE_32('P','R','M','C')\r
+#define PRM_CONTEXT_BUFFER_INTERFACE_VERSION 1\r
+\r
+#pragma pack(push, 1)\r
+\r
+//\r
+// This is the context buffer structure that is passed to a PRM handler.\r
+//\r
+// At OS runtime, the OS will allocate and populate this structure and\r
+// place virtual addresses in the pointer fields.\r
+//\r
+// It is also reused internally in FW (in the PRM_MODULE_CONTEXT_BUFFERS structure)\r
+// to track context buffers within a given PRM module. In that internal usage,\r
+// the addresses will be physical addresses.\r
+//\r
+typedef struct {\r
+ ///\r
+ /// Signature of this interface.\r
+ ///\r
+ UINT32 Signature;\r
+\r
+ ///\r
+ /// Version of this interface.\r
+ ///\r
+ UINT16 Version;\r
+\r
+ ///\r
+ /// Reserved field.\r
+ ///\r
+ UINT16 Reserved;\r
+\r
+ ///\r
+ /// The GUID of the PRM handler represented by this context instance.\r
+ ///\r
+ EFI_GUID HandlerGuid;\r
+\r
+ ///\r
+ /// A virtual address pointer to the static data buffer allocated for\r
+ /// the PRM handler represented by this context instance.\r
+ ///\r
+ /// The static buffer is intended to be populated in the PRM module\r
+ /// configuration library and treated as read-only data at OS runtime.\r
+ ///\r
+ /// This pointer may be NULL if a static data buffer is not needed.\r
+ ///\r
+ PRM_DATA_BUFFER *StaticDataBuffer;\r
+\r
+ ///\r
+ /// A virtual address pointer to an array of PRM_RUNTIME_MMIO_RANGE\r
+ /// structures that describe MMIO physical address ranges mapped to\r
+ /// virtual memory addresses for access at OS runtime.\r
+ ///\r
+ /// This pointer is ignored in firmware internal usage of this structure\r
+ /// as this field is present to allow a PRM handler to get the list\r
+ /// of MMIO ranges described as accessible by its PRM module.\r
+ ///\r
+ /// The module list of MMIO ranges is specified by the PRM configuration\r
+ /// code as a single array in PRM_MODULE_CONTEXT_BUFFERS.\r
+ ///\r
+ /// The OS is responsible for ensuring the pointer to the array in this\r
+ /// structure is converted to a virtual address during construction of\r
+ /// of the context buffer in the OS.\r
+ ///\r
+ /// This pointer may be NULL if runtime memory ranges are not needed.\r
+ ///\r
+ PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges;\r
+} PRM_CONTEXT_BUFFER;\r
+\r
+//\r
+// A firmware internal data structure used to track context buffer and\r
+// runtime MMIO range usage across a PRM module.\r
+//\r
+typedef struct\r
+{\r
+ ///\r
+ /// The GUID of the PRM module.\r
+ ///\r
+ EFI_GUID ModuleGuid;\r
+\r
+ ///\r
+ /// The number of PRM context buffers in ContextBuffers[].\r
+ /// This count should equal the number of PRM handlers in the module being configured.\r
+ ///\r
+ UINTN BufferCount;\r
+\r
+ ///\r
+ /// A pointer to an array of PRM context buffers\r
+ ///\r
+ PRM_CONTEXT_BUFFER *Buffer;\r
+\r
+ /// The MMIO ranges are defined in the firmware boot environment.\r
+ /// The addresses within the PRM_RUNTIME_MMIO_RANGES structure will\r
+ /// be converted to virtual addresses by firmware.\r
+\r
+ ///\r
+ /// A physical address pointer to an array of PRM_RUNTIME_MMIO_RANGE\r
+ /// structures that describe memory ranges that need to be mapped to\r
+ /// virtual memory addresses for access at OS runtime.\r
+ ///\r
+ /// This is a consolidated array of MMIO ranges accessed by any PRM\r
+ /// handler in the PRM module at OS runtime. The MMIO range physical\r
+ /// addresses registered here will automatically be converted to the\r
+ /// corresponding virtual address in the structure by PRM infrastructure\r
+ /// code. No action is required to convert MMIO range base physical\r
+ /// addresses to virtual addresses by either the PRM configuration code\r
+ /// or the OS.\r
+ ///\r
+ /// This pointer may be NULL if runtime memory ranges are not needed.\r
+ ///\r
+ PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges;\r
+} PRM_MODULE_CONTEXT_BUFFERS;\r
+\r
+#pragma pack(pop)\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+\r
+ Definitions for the Platform Runtime Mechanism (PRM) data buffer structures.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef PRM_DATA_BUFFER_H_\r
+#define PRM_DATA_BUFFER_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#define PRM_DATA_BUFFER_HEADER_SIGNATURE SIGNATURE_32('P','R','M','D')\r
+\r
+#pragma pack(push, 1)\r
+\r
+///\r
+/// A generic header that describes the PRM data buffer.\r
+///\r
+typedef struct {\r
+ ///\r
+ /// PRM Data Buffer signature.\r
+ ///\r
+ UINT32 Signature;\r
+ ///\r
+ /// Length of the entire data buffer, including the size of the header.\r
+ ///\r
+ UINT32 Length;\r
+} PRM_DATA_BUFFER_HEADER;\r
+\r
+///\r
+/// A PRM data buffer is a generic header followed by variable length arbitrary data.\r
+///\r
+typedef struct {\r
+ ///\r
+ /// The header is required at the beginning of every PRM data buffer.\r
+ ///\r
+ PRM_DATA_BUFFER_HEADER Header;\r
+\r
+ ///\r
+ /// The beginning of data immediately follows the header.\r
+ ///\r
+ UINT8 Data[1];\r
+} PRM_DATA_BUFFER;\r
+\r
+#pragma pack(pop)\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+\r
+ Definitions for the Platform Runtime Mechanism (PRM) export descriptor structures.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef PRM_EXPORT_DESCRIPTOR_H_\r
+#define PRM_EXPORT_DESCRIPTOR_H_\r
+\r
+#include <Prm.h>\r
+\r
+#define PRM_MODULE_EXPORT_DESCRIPTOR_NAME PrmModuleExportDescriptor\r
+#define PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE SIGNATURE_64 ('P', 'R', 'M', '_', 'M', 'E', 'D', 'T')\r
+#define PRM_MODULE_EXPORT_REVISION 0x0\r
+\r
+//\r
+// Platform Runtime Mechanism (PRM) Export Descriptor Structures\r
+//\r
+#pragma pack(push, 1)\r
+\r
+typedef struct {\r
+ GUID PrmHandlerGuid;\r
+ CHAR8 PrmHandlerName[PRM_HANDLER_NAME_MAXIMUM_LENGTH];\r
+} PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT;\r
+\r
+typedef struct {\r
+ UINT64 Signature;\r
+ UINT16 Revision;\r
+ UINT16 NumberPrmHandlers;\r
+ GUID ModuleGuid;\r
+ PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT PrmHandlerExportDescriptors[3];\r
+} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT;\r
+\r
+#pragma pack(pop)\r
+\r
+/**\r
+ A macro that declares a PRM Handler Export Descriptor for a PRM Handler.\r
+\r
+ This macro is intended to be used once per PRM Handler to describe the handler when the\r
+ module description is defined. It should be provided as an argument to PRM_MODULE_EXPORT.\r
+\r
+ @param Guid The GUID of the PRM Handler being exported.\r
+\r
+ @param Name The name of the PRM Handler being exported. This string should exactly\r
+ match the function name.\r
+\r
+**/\r
+#define PRM_HANDLER_EXPORT_ENTRY(Guid, Name) \\r
+ { \\r
+ Guid, \\r
+ PRM_STRING_(Name) \\r
+ } \\r
+\r
+/**\r
+ A macro that returns the count of the number of variable-length arguments given.\r
+\r
+ @param VariableArgumentList A variable argument list of elements that will be included\r
+ in the return value of the list count.\r
+**/\r
+#define VA_ARG_COUNT(...) (sizeof((PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT[]){__VA_ARGS__})/sizeof(PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT))\r
+\r
+/**\r
+ A macro that declares the PRM Module Export Descriptor for a PRM Module.\r
+\r
+ This macro is intended to be used once in a PRM Module after all of the PRM Handler definitions\r
+ to describe the PRM Handlers being exported in the module.\r
+\r
+ @param PrmHandlerExportEntries A variable argument list of PRM_HANDLER_EXPORT_ENTRY values.\r
+ This list should include all PRM Handlers being exported by\r
+ this module.\r
+\r
+**/\r
+#define PRM_MODULE_EXPORT(...) \\r
+ PRM_EXPORT_API PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT PRM_MODULE_EXPORT_DESCRIPTOR_NAME = { \\r
+ { \\r
+ PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE, \\r
+ PRM_MODULE_EXPORT_REVISION, \\r
+ VA_ARG_COUNT(__VA_ARGS__), \\r
+ EFI_CALLER_ID_GUID \\r
+ }, \\r
+ { __VA_ARGS__ } \\r
+ } \\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+\r
+ Definitions for the Platform Runtime Mechanism (PRM) MMIO elements.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef PRM_MMIO_H_\r
+#define PRM_MMIO_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#pragma pack(push, 1)\r
+\r
+///\r
+/// Describes a memory range that needs to be made accessible at OS runtime.\r
+///\r
+/// The memory range with the given base address and length will be marked as EFI_MEMORY_RUNTIME.\r
+///\r
+typedef struct {\r
+ EFI_PHYSICAL_ADDRESS PhysicalBaseAddress;\r
+ EFI_PHYSICAL_ADDRESS VirtualBaseAddress;\r
+ UINT32 Length;\r
+} PRM_RUNTIME_MMIO_RANGE;\r
+\r
+///\r
+/// Describes a buffer with an array of PRM module\r
+/// config runtime memory ranges.\r
+///\r
+typedef struct {\r
+ ///\r
+ /// The number of runtime memory range elements in this buffer.\r
+ ///\r
+ UINT64 Count;\r
+ ///\r
+ /// The beginning of the runtime memory range data.\r
+ ///\r
+ PRM_RUNTIME_MMIO_RANGE Range[1];\r
+} PRM_RUNTIME_MMIO_RANGES;\r
+\r
+#pragma pack(pop)\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+\r
+ Common definitions needed for Platform Runtime Mechanism (PRM) modules.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef PRM_MODULE_H_\r
+#define PRM_MODULE_H_\r
+\r
+#include <Prm.h>\r
+#include <PrmContextBuffer.h>\r
+#include <PrmDataBuffer.h>\r
+#include <PrmExportDescriptor.h>\r
+#include <PrmMmio.h>\r
+#include <PrmModuleUpdate.h>\r
+#include <PrmOsServices.h>\r
+\r
+/**\r
+ Macro that provides a condensed form of a PRM Handler.\r
+\r
+ This macro can be used to define a PRM Handler that uses the standard PRM Handle\r
+ signature. It is simply provided for convenience.\r
+\r
+**/\r
+#define PRM_HANDLER_EXPORT(Name) \\r
+ STATIC_ASSERT (sizeof (PRM_STRING_(Name)) <= PRM_HANDLER_NAME_MAXIMUM_LENGTH, "The PRM handler exceeds the maximum allowed size of 128."); \\r
+ \\r
+/** \\r
+ A Platform Runtime Mechanism (PRM) handler. \\r
+ \\r
+ @param[in] ParameterBuffer A pointer to the PRM handler parameter buffer \\r
+ @param[in] ContextBUffer A pointer to the PRM handler context buffer \\r
+ \\r
+ @retval EFI_STATUS The PRM handler executed successfully. \\r
+ @retval Others An error occurred in the PRM handler. \\r
+ \\r
+**/ \\r
+ EFI_STATUS \\r
+ PRM_EXPORT_API \\r
+ EFIAPI \\r
+ Name ( \\r
+ IN VOID *ParameterBuffer, \\r
+ IN PRM_CONTEXT_BUFFER *ContextBuffer \\r
+ ) \\r
+\r
+/**\r
+ A macro that declares the PRM Module Update Lock Descriptor for a PRM Module.\r
+\r
+ This macro is intended to be used once in a PRM Module so the module update lock descriptor is\r
+ exported for the module.\r
+\r
+**/\r
+#define PRM_MODULE_UPDATE_LOCK_EXPORT \\r
+ PRM_EXPORT_API PRM_MODULE_UPDATE_LOCK_DESCRIPTOR PRM_MODULE_UPDATE_LOCK_DESCRIPTOR_NAME = { \\r
+ PRM_MODULE_UPDATE_LOCK_DESCRIPTOR_SIGNATURE, \\r
+ PRM_MODULE_UPDATE_LOCK_REVISION, \\r
+ { 0 } \\r
+ } \\r
+\r
+//\r
+// A PRM module is required to export the PRM Module Update Lock\r
+//\r
+PRM_MODULE_UPDATE_LOCK_EXPORT;\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+\r
+ Definition for the Platform Runtime Mechanism (PRM) module update structures.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef PRM_MODULE_UPDATE_H_\r
+#define PRM_MODULE_UPDATE_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#define PRM_MODULE_UPDATE_LOCK_DESCRIPTOR_NAME PrmModuleUpdateLock\r
+#define PRM_MODULE_UPDATE_LOCK_DESCRIPTOR_SIGNATURE SIGNATURE_64 ('P', 'R', 'M', '_', 'M', 'U', 'L', '_')\r
+#define PRM_MODULE_UPDATE_LOCK_REVISION 0x0\r
+\r
+#pragma pack(push, 1)\r
+\r
+///\r
+/// Maintains the PRM Module Update Lock state\r
+///\r
+typedef union {\r
+ ///\r
+ /// Individual bit fields\r
+ ///\r
+ struct {\r
+ UINT8 Acquired : 1; ///< [0] - If 1 lock is acquired. If 0 lock is released.\r
+ UINT8 Reserved : 7; ///< [7:1] - Reserved\r
+ } Bits;\r
+ ///\r
+ /// All bit fields as an 8-bit value\r
+ ///\r
+ UINT8 Uint8;\r
+} PRM_MODULE_UPDATE_LOCK;\r
+\r
+typedef struct {\r
+ UINT64 Signature;\r
+ UINT16 Revision;\r
+ PRM_MODULE_UPDATE_LOCK Lock;\r
+} PRM_MODULE_UPDATE_LOCK_DESCRIPTOR;\r
+\r
+#pragma pack(pop)\r
+\r
+#endif\r
--- /dev/null
+/** @file\r
+\r
+ Definitions for the Platform Runtime Mechanism (PRM) OS Services.\r
+\r
+ Note: OS Services have been removed from POR. This file has been reduced to just debug print\r
+ OS Service for use during PRM enabling.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef PRM_OS_SERVICES_H_\r
+#define PRM_OS_SERVICES_H_\r
+\r
+#include <Uefi.h>\r
+\r
+typedef struct _PRM_OS_SERVICES PRM_OS_SERVICES;\r
+\r
+//\r
+// PRM OS Services function signatures\r
+//\r
+typedef\r
+VOID\r
+(EFIAPI *PRM_OS_SERVICE_DEBUG_PRINT) (\r
+ IN CONST CHAR8 *String\r
+ );\r
+\r
+#pragma pack(push, 1)\r
+\r
+//\r
+// PRM OS Services table\r
+//\r
+struct _PRM_OS_SERVICES {\r
+ // Structure information\r
+ UINT16 MajorVersion;\r
+ UINT16 MinorVersion;\r
+\r
+ // OS Services\r
+ PRM_OS_SERVICE_DEBUG_PRINT DebugPrint;\r
+};\r
+\r
+#pragma pack(pop)\r
+\r
+#endif\r
--- /dev/null
+## @file PrmPkg.dec\r
+# This package provides support for the Platform Runtime Mechanism (PRM).\r
+#\r
+# The following key elements of PRM are maintained in this package:\r
+#\r
+# 1. PRM interfaces - Comprised of interfaces shared with the operating system such as ACPI table structures\r
+# in addition to internal firmware interfaces such as protocols and library interfaces.\r
+#\r
+# 2. PRM generic drivers - EDK II drivers that implement generic functionality such that a platform can quickly\r
+# and reliably adopt PRM.\r
+#\r
+# 3. PRM module - An independently updatable PE/COFF binary that conforms to the unique requirements of a PRM module.\r
+# PRM modules expose functions for operating system invocation referred to as PRM handlers.\r
+#\r
+# 4. PRM handler - A function in a PRM module. The function is identified through PRM interfaces in the OS by a GUID.\r
+#\r
+# Copyright (c) Microsoft Corporation<BR>\r
+## SPDX-License-Identifier: BSD-2-Clause-Patent\r
+##\r
+\r
+[Defines]\r
+ DEC_SPECIFICATION = 0x00010005\r
+ PACKAGE_NAME = PrmPkg\r
+ PACKAGE_UNI_FILE = PrmPkg.uni\r
+ PACKAGE_GUID = 3D22F66E-9090-46CE-B260-1836070AFA5E\r
+ PACKAGE_VERSION = 0.1\r
+\r
+[Includes]\r
+ Include\r
+\r
+[Guids]\r
+ gPrmPkgTokenSpaceGuid = { 0x46f56acc, 0x600b, 0x450f, { 0xa5, 0x9c, 0x3a, 0x1a, 0x4a, 0xd4, 0x35, 0x3e }}\r
+\r
+[LibraryClasses]\r
+ ## @libraryclass Provides a general abstraction for PRM context buffer management\r
+ #\r
+ PrmContextBufferLib|Include/Library/PrmContextBufferLib.h\r
+\r
+[Protocols]\r
+ ## PRM Configuration Protocol\r
+ #\r
+ gPrmConfigProtocolGuid = { 0x4e5b4fea, 0x936a, 0x45bc, { 0xac, 0x6a, 0x2f, 0x8f, 0x14, 0xa6, 0xc2, 0x9e }}\r
+\r
+[PcdsFixedAtBuild]\r
+ ## Flash base address of a PRM firmware volume\r
+ gPrmPkgTokenSpaceGuid.PcdFlashFvPrmBase|0x00000000|UINT32|0x00000001\r
+\r
+ ## Size in bytes of a PRM firmware volume\r
+ gPrmPkgTokenSpaceGuid.PcdFlashFvPrmSize|0x00000000|UINT32|0x00000002\r
--- /dev/null
+// /** @file\r
+//\r
+// Copyright (c) Microsoft Corporation\r
+// SPDX-License-Identifier: BSD-2-Clause-Patent\r
+// **/\r
+\r
+\r
+#string STR_PACKAGE_ABSTRACT #language en-US "This package provides support for the Platform Runtime Mechanism (PRM)."\r
+\r
+#string STR_PACKAGE_DESCRIPTION #language en-US "Provides infrastructure support code and sample PRM modules for PRM authors."\r