--- /dev/null
+/** @file\r
+\r
+ The boot services environment configuration library for the Hardware Access 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
+#include <Samples/PrmSampleHardwareAccessModule/Hpet.h>\r
+\r
+STATIC EFI_HANDLE mPrmConfigProtocolHandle;\r
+\r
+// {0ef93ed7-14ae-425b-928f-b85a6213b57e}\r
+STATIC CONST EFI_GUID mPrmModuleGuid = {0x0ef93ed7, 0x14ae, 0x425b, {0x92, 0x8f, 0xb8, 0x5a, 0x62, 0x13, 0xb5, 0x7e}};\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
+HardwareAccessModuleConfigLibConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges;\r
+ PRM_CONFIG_PROTOCOL *PrmConfigProtocol;\r
+\r
+ RuntimeMmioRanges = 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
+ // Runtime MMIO Ranges structure\r
+\r
+ // Since this sample module only uses 1 runtime MMIO range, it can use the PRM_RUNTIME_MMIO_RANGES\r
+ // type directly without extending the size of the data buffer for additional MMIO ranges.\r
+ RuntimeMmioRanges = AllocateRuntimeZeroPool (sizeof (*RuntimeMmioRanges));\r
+ ASSERT (RuntimeMmioRanges != NULL);\r
+ if (RuntimeMmioRanges == 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 Runtime MMIO Ranges structure\r
+ RuntimeMmioRanges->Count = 1;\r
+ RuntimeMmioRanges->Range[0].PhysicalBaseAddress = HPET_BASE_ADDRESS;\r
+ RuntimeMmioRanges->Range[0].Length = HPET_RANGE_LENGTH;\r
+\r
+ PrmConfigProtocol->ModuleContextBuffers.RuntimeMmioRanges = RuntimeMmioRanges;\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 (RuntimeMmioRanges != NULL) {\r
+ FreePool (RuntimeMmioRanges);\r
+ }\r
+ if (PrmConfigProtocol != NULL) {\r
+ FreePool (PrmConfigProtocol);\r
+ }\r
+ }\r
+\r
+ return Status;\r
+}\r
--- /dev/null
+## @file\r
+# Sample PRM Configuration Library Instance\r
+#\r
+# The PRM configuration library instance is responsible for initializing and setting the corresponding\r
+# PRM module's configuration in the boot environment.\r
+#\r
+# Copyright (c) Microsoft Corporation\r
+#\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = DxeHardwareAccessModuleConfigLib\r
+ FILE_GUID = 88AA72FE-AE5A-435F-A267-E24D526C666C\r
+ MODULE_TYPE = DXE_DRIVER\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = NULL |DXE_DRIVER\r
+ CONSTRUCTOR = HardwareAccessModuleConfigLibConstructor\r
+\r
+[Sources]\r
+ DxeHardwareAccessModuleConfigLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ PrmPkg/PrmPkg.dec\r
+\r
+[Protocols]\r
+ gPrmConfigProtocolGuid\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ BaseMemoryLib\r
+ DebugLib\r
+ MemoryAllocationLib\r
+ UefiBootServicesTableLib\r
+ UefiDriverEntryPoint\r