]> git.proxmox.com Git - mirror_edk2.git/commitdiff
PrmPkg/SampleAcpiParameterBufferModule: Add initial module
authorMichael Kubacki <michael.kubacki@microsoft.com>
Wed, 10 Jun 2020 23:55:02 +0000 (16:55 -0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 5 Apr 2022 00:42:38 +0000 (00:42 +0000)
Adds a new PRM module called SampleAcpiParameterBufferModule that
demonstrates how a PRM module can use an ACPI parameter buffer with
a PRM handler.

Cc: Andrew Fish <afish@apple.com>
Cc: Kang Gao <kang.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Michael Kubacki <michael.kubacki@microsoft.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Benjamin You <benjamin.you@intel.com>
Cc: Liu Yun <yun.y.liu@intel.com>
Cc: Ankit Sinha <ankit.sinha@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Acked-by: Michael D Kinney <michael.d.kinney@intel.com>
Acked-by: Liming Gao <gaoliming@byosoft.com.cn>
Acked-by: Leif Lindholm <quic_llindhol@quicinc.com>
Reviewed-by: Ankit Sinha <ankit.sinha@intel.com>
PrmPkg/PrmPkg.dsc
PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.c [new file with mode: 0644]
PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.inf [new file with mode: 0644]
PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameterBufferModule.c [new file with mode: 0644]
PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameterBufferModule.inf [new file with mode: 0644]

index 6d352dfadb2669cc608d235ca434c1d9fb3385e3..2409378926b9dd96a7f4d4bc21a2ed7add1c2008 100644 (file)
@@ -68,6 +68,7 @@
   # PRM Libraries\r
   #\r
   $(PLATFORM_PACKAGE)/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf\r
+  $(PLATFORM_PACKAGE)/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.inf\r
   $(PLATFORM_PACKAGE)/Samples/PrmSampleContextBufferModule/Library/DxeContextBufferModuleConfigLib/DxeContextBufferModuleConfigLib.inf\r
   $(PLATFORM_PACKAGE)/Samples/PrmSampleHardwareAccessModule/Library/DxeHardwareAccessModuleConfigLib/DxeHardwareAccessModuleConfigLib.inf\r
 \r
@@ -76,6 +77,7 @@
   #\r
   $(PLATFORM_PACKAGE)/PrmConfigDxe/PrmConfigDxe.inf {\r
     <LibraryClasses>\r
+      NULL|$(PLATFORM_PACKAGE)/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.inf\r
       NULL|$(PLATFORM_PACKAGE)/Samples/PrmSampleContextBufferModule/Library/DxeContextBufferModuleConfigLib/DxeContextBufferModuleConfigLib.inf\r
   }\r
 \r
@@ -93,6 +95,7 @@
   # PRM Sample Modules\r
   #\r
   $(PLATFORM_PACKAGE)/Samples/PrmSamplePrintModule/PrmSamplePrintModule.inf\r
+  $(PLATFORM_PACKAGE)/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameterBufferModule.inf\r
   $(PLATFORM_PACKAGE)/Samples/PrmSampleHardwareAccessModule/PrmSampleHardwareAccessModule.inf {\r
     <LibraryClasses>\r
       DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
diff --git a/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.c b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.c
new file mode 100644 (file)
index 0000000..b135517
--- /dev/null
@@ -0,0 +1,120 @@
+/** @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
diff --git a/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.inf b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.inf
new file mode 100644 (file)
index 0000000..9ac8385
--- /dev/null
@@ -0,0 +1,39 @@
+## @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           = DxeAcpiParameterBufferModuleConfigLib\r
+  FILE_GUID           = D43D19E9-007A-4D40-AC4A-418F958AFB9D\r
+  MODULE_TYPE         = DXE_DRIVER\r
+  VERSION_STRING      = 1.0\r
+  LIBRARY_CLASS       = NULL |DXE_DRIVER\r
+  CONSTRUCTOR         = AcpiParameterBufferModuleConfigLibConstructor\r
+\r
+[Sources]\r
+  DxeAcpiParameterBufferModuleConfigLib.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
diff --git a/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameterBufferModule.c b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameterBufferModule.c
new file mode 100644 (file)
index 0000000..ebb5ba0
--- /dev/null
@@ -0,0 +1,79 @@
+/** @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
diff --git a/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameterBufferModule.inf b/PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameterBufferModule.inf
new file mode 100644 (file)
index 0000000..e8b71a9
--- /dev/null
@@ -0,0 +1,41 @@
+## @file\r
+#  Sample PRM Driver\r
+#\r
+#  A sample PRM Module implementation. This PRM Module includes a PRM Module configuration library instance\r
+#  that applies the configuration for an ACPI parameter buffer in the boot environment. A PRM handler\r
+#  is provided that checks for a specific value in the parameter buffer that should be provided by ACPI\r
+#  code at OS runtime.\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           = PrmSampleAcpiParameterBufferModule\r
+  FILE_GUID           = DC2A58A6-5927-4776-B995-D118A27335A2\r
+  MODULE_TYPE         = DXE_RUNTIME_DRIVER\r
+  VERSION_STRING      = 1.0\r
+  ENTRY_POINT         = PrmSampleAcpiParameterBufferModuleInit\r
+\r
+[Sources]\r
+  PrmSampleAcpiParameterBufferModule.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  PrmPkg/PrmPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+\r
+[Depex]\r
+  TRUE\r
+\r
+[BuildOptions.common]\r
+  MSFT:*_*_*_DLINK_FLAGS  = /DLL /SUBSYSTEM:CONSOLE /VERSION:1.0\r
+  MSFT:*_*_*_GENFW_FLAGS = --keepoptionalheader\r