--- /dev/null
+/** @file\r
+\r
+ The boot services environment configuration library for the ACPI Parameter Buffer Sample PRM module.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Protocol/PrmConfig.h>\r
+\r
+STATIC EFI_HANDLE mPrmConfigProtocolHandle;\r
+\r
+// {dc2a58a6-5927-4776-b995-d118a27335a2}\r
+STATIC CONST EFI_GUID mPrmModuleGuid = {0xdc2a58a6, 0x5927, 0x4776, {0xb9, 0x95, 0xd1, 0x18, 0xa2, 0x73, 0x35, 0xa2}};\r
+\r
+// {2e4f2d13-6240-4ed0-a401-c723fbdc34e8}\r
+STATIC CONST EFI_GUID mCheckParamBufferPrmHandlerGuid = {0x2e4f2d13, 0x6240, 0x4ed0, {0xa4, 0x01, 0xc7, 0x23, 0xfb, 0xdc, 0x34, 0xe8}};\r
+\r
+/**\r
+ Constructor of the PRM configuration library.\r
+\r
+ @param[in] ImageHandle The image handle of the driver.\r
+ @param[in] SystemTable The EFI System Table pointer.\r
+\r
+ @retval EFI_SUCCESS The shell command handlers were installed successfully.\r
+ @retval EFI_UNSUPPORTED The shell level required was not found.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AcpiParameterBufferModuleConfigLibConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ VOID *AcpiParameterBuffer;\r
+ ACPI_PARAMETER_BUFFER_DESCRIPTOR *AcpiParamBufferDescriptor;\r
+ PRM_CONFIG_PROTOCOL *PrmConfigProtocol;\r
+\r
+ AcpiParameterBuffer = NULL;\r
+ AcpiParamBufferDescriptor = NULL;\r
+ PrmConfigProtocol = NULL;\r
+\r
+ /*\r
+ In this sample PRM module, the protocol describing this sample module's resources is simply\r
+ installed in the constructor.\r
+\r
+ However, if some data is not available until later, this constructor could register a callback\r
+ on the dependency for the data to be available (e.g. ability to communicate with some device)\r
+ and then install the protocol. The requirement is that the protocol is installed before end of DXE.\r
+ */\r
+\r
+ // Allocate the ACPI parameter buffer\r
+\r
+ // A parameter buffer is arbitrary data that is handler specific. This handler buffer is specified\r
+ // to consist of a UINT32 that represents the test data signature ('T', 'E', 'S', 'T').\r
+ AcpiParameterBuffer = AllocateRuntimeZeroPool (sizeof (UINT32));\r
+ ASSERT (AcpiParameterBuffer != NULL);\r
+ if (AcpiParameterBuffer == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
+\r
+ // Allocate the ACPI Parameter Buffer Descriptor structure for a single PRM handler\r
+ AcpiParamBufferDescriptor = AllocateZeroPool (sizeof (*AcpiParamBufferDescriptor));\r
+ ASSERT (AcpiParamBufferDescriptor != NULL);\r
+ if (AcpiParamBufferDescriptor == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
+\r
+ // Allocate the PRM Configuration protocol structure for this PRM module\r
+ PrmConfigProtocol = AllocateZeroPool (sizeof (*PrmConfigProtocol));\r
+ ASSERT (PrmConfigProtocol != NULL);\r
+ if (PrmConfigProtocol == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
+ CopyGuid (&PrmConfigProtocol->ModuleContextBuffers.ModuleGuid, &mPrmModuleGuid);\r
+\r
+ // Populate the ACPI Parameter Buffer Descriptor structure\r
+ CopyGuid (&AcpiParamBufferDescriptor->HandlerGuid, &mCheckParamBufferPrmHandlerGuid);\r
+ AcpiParamBufferDescriptor->AcpiParameterBufferAddress = (UINT64) (UINTN) AcpiParameterBuffer;\r
+\r
+ // Populate the PRM Module Context Buffers structure\r
+ PrmConfigProtocol->ModuleContextBuffers.AcpiParameterBufferDescriptorCount = 1;\r
+ PrmConfigProtocol->ModuleContextBuffers.AcpiParameterBufferDescriptors = AcpiParamBufferDescriptor;\r
+\r
+ //\r
+ // Install the PRM Configuration Protocol for this module. This indicates the configuration\r
+ // library has completed resource initialization for the PRM module.\r
+ //\r
+ Status = gBS->InstallProtocolInterface (\r
+ &mPrmConfigProtocolHandle,\r
+ &gPrmConfigProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ (VOID *) PrmConfigProtocol\r
+ );\r
+\r
+Done:\r
+ if (EFI_ERROR (Status)) {\r
+ if (AcpiParameterBuffer != NULL) {\r
+ FreePool (AcpiParameterBuffer);\r
+ }\r
+ if (AcpiParamBufferDescriptor != NULL) {\r
+ FreePool (AcpiParamBufferDescriptor);\r
+ }\r
+ if (PrmConfigProtocol != NULL) {\r
+ FreePool (PrmConfigProtocol);\r
+ }\r
+ }\r
+\r
+ return Status;\r
+}\r
--- /dev/null
+/** @file\r
+\r
+ This PRM Module demonstrates how to define an ACPI parameter buffer that is used by a PRM handler.\r
+\r
+ Copyright (c) Microsoft Corporation\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <PrmModule.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+// TEMP\r
+#include <Library/DebugLib.h>\r
+\r
+#define PARAM_BUFFER_TEST_SIGNATURE SIGNATURE_32('T','E','S','T')\r
+\r
+//\r
+// PRM Handler GUIDs\r
+//\r
+\r
+// {2e4f2d13-6240-4ed0-a401-c723fbdc34e8}\r
+#define CHECK_PARAM_BUFFER_PRM_HANDLER_GUID {0x2e4f2d13, 0x6240, 0x4ed0, {0xa4, 0x01, 0xc7, 0x23, 0xfb, 0xdc, 0x34, 0xe8}}\r
+\r
+/**\r
+ A sample Platform Runtime Mechanism (PRM) handler.\r
+\r
+ This sample handler checks if a parameter buffer is provided with the data signature\r
+ ('T', 'E', 'S', 'T') at the beginning of the buffer.\r
+\r
+ The contents are expected to be updated by ACPI code at OS runtime.\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
+PRM_HANDLER_EXPORT (CheckParamBufferPrmHandler)\r
+{\r
+ if (ParameterBuffer == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (*((UINT32 *) ParameterBuffer) == PARAM_BUFFER_TEST_SIGNATURE) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ return EFI_NOT_FOUND;\r
+}\r
+\r
+//\r
+// Register the PRM export information for this PRM Module\r
+//\r
+PRM_MODULE_EXPORT (\r
+ PRM_HANDLER_EXPORT_ENTRY (CHECK_PARAM_BUFFER_PRM_HANDLER_GUID, CheckParamBufferPrmHandler)\r
+ );\r
+\r
+/**\r
+ Module entry point.\r
+\r
+ @param[in] ImageHandle The image handle.\r
+ @param[in] SystemTable A pointer to the system table.\r
+\r
+ @retval EFI_SUCCESS This function always returns success.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PrmSampleAcpiParameterBufferModuleInit (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ return EFI_SUCCESS;\r
+}\r