]> git.proxmox.com Git - mirror_edk2.git/commitdiff
PrmPkg: Add initial PrmSampleMemoryAllocationModule
authorMichael Kubacki <michael.kubacki@microsoft.com>
Tue, 7 Apr 2020 18:30:21 +0000 (11:30 -0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 5 Apr 2022 00:42:38 +0000 (00:42 +0000)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3812

DEPRECATED: This module is no longer relevant since OS Services that
allow memory allocation have been removed. It is still present in the
source tree in the event dynamic memory allocation at OS runtime is
needed again.

  Adds a sample PRM module that demonstrates:
  1. How to write a PRM module
  2. How to use a basic PRM OS service
  3. How to dynamically allocate memory at OS runtime

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/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemoryAllocationModule.c [new file with mode: 0644]
PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemoryAllocationModule.inf [new file with mode: 0644]

diff --git a/PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemoryAllocationModule.c b/PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemoryAllocationModule.c
new file mode 100644 (file)
index 0000000..f124566
--- /dev/null
@@ -0,0 +1,115 @@
+/** @file\r
+\r
+  A sample PRM Module implementation. This PRM Module provides 3 PRM handlers that simply take a DEBUG print\r
+  function from the OS and invoke it with a debug message internal the 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/BaseMemoryLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+//\r
+// PRM Handler GUIDs\r
+//\r
+\r
+// {149a5cb3-6a9c-403f-940a-156abf63938a}\r
+#define PRM_HANDLER_1_GUID {0x149a5cb3, 0x6a9c, 0x403f, {0x94, 0x0a, 0x15, 0x6a, 0xbf, 0x63, 0x93, 0x8a}}\r
+\r
+// Note: If the signature size is modified, the PRM Handler test code in this module needs to be updated.\r
+#define MEMORY_ALLOCATION_TEST_DATA_SIGNATURE     SIGNATURE_32('T','E','S','T')\r
+#define MEMORY_ALLOCATION_TEST_DATA_SIZE          sizeof(UINT32)\r
+#define MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE   256\r
+\r
+/**\r
+  A sample Platform Runtime Mechanism (PRM) handler.\r
+\r
+  This sample handler currently uses the OS_SERVICES to write a debug message\r
+  indicating this is PRM handler 1.\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
+PrmHandler1 (\r
+  IN VOID                         *ParameterBuffer,\r
+  IN PRM_CONTEXT_BUFFER           *ContextBUffer\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  UINTN                           Index;\r
+  VOID                            *NonPagedPool;\r
+  CHAR8                           DebugMessage[256];\r
+\r
+  if (OsServices == NULL || OsServices->DebugPrint == NULL || OsServices->AllocateMemory == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OsServices->DebugPrint ("Memory Allocation PrmHandler1 entry.\n");\r
+  OsServices->DebugPrint ("  Requesting allocation of a 256 byte non-paged pool...\n");\r
+\r
+  NonPagedPool = NULL;\r
+  NonPagedPool = OsServices->AllocateMemory (MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE, FALSE);\r
+  if (NonPagedPool == NULL) {\r
+    OsServices->DebugPrint ("  NULL was returned from AllocateMemory()...\n");\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  AsciiSPrint (\r
+    &DebugMessage[0],\r
+    ARRAY_SIZE (DebugMessage),\r
+    "  Buffer address returned from AllocateMemory() = 0x%016lx.\n",\r
+    (UINTN) NonPagedPool\r
+    );\r
+  OsServices->DebugPrint (&DebugMessage[0]);\r
+\r
+  // Write the test data\r
+  OsServices->DebugPrint ("  Beginning memory buffer write and read back test...\n");\r
+  SetMem32 (NonPagedPool, MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE, MEMORY_ALLOCATION_TEST_DATA_SIGNATURE);\r
+\r
+  // Read back and verify the test data is valid\r
+  for (Index = 0, Status = EFI_SUCCESS; Index < (MEMORY_ALLOCATION_TEST_DATA_BUFFER_SIZE / MEMORY_ALLOCATION_TEST_DATA_SIZE); Index++) {\r
+    if (((UINT32 *) NonPagedPool)[Index] != MEMORY_ALLOCATION_TEST_DATA_SIGNATURE) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      break;\r
+    }\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    OsServices->DebugPrint ("    Memory write & read test failed.\n");\r
+  } else {\r
+    OsServices->DebugPrint ("    Memory write & read test passed.\n");\r
+  }\r
+\r
+  OsServices->DebugPrint ("Memory Allocation PrmHandler1 exit.\n");\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+//\r
+// Register the PRM export information for this PRM Module\r
+//\r
+PRM_MODULE_EXPORT (\r
+  PRM_HANDLER_EXPORT_ENTRY (PRM_HANDLER_1_GUID, PrmHandler1)\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PrmSampleMemoryAllocationModuleInit (\r
+  IN  EFI_HANDLE                  ImageHandle,\r
+  IN  EFI_SYSTEM_TABLE            *SystemTable\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemoryAllocationModule.inf b/PrmPkg/Samples/PrmSampleMemoryAllocationModule/PrmSampleMemoryAllocationModule.inf
new file mode 100644 (file)
index 0000000..e6798af
--- /dev/null
@@ -0,0 +1,41 @@
+## @file\r
+#  Sample PRM Driver\r
+#\r
+#  This driver simply uses an OS-provided debug message print service to write\r
+#  a debug message. Three PRM handlers are provided that each print a unique\r
+#  debug message.\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                      = PrmSampleMemoryAllocationModule\r
+  FILE_GUID                      = C6B3E74A-12E3-4364-8FB4-8C8B34DD153B\r
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = PrmSampleMemoryAllocationModuleInit\r
+\r
+[Sources]\r
+  PrmSampleMemoryAllocationModule.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  PrmPkg/PrmPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  PrintLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+\r
+[Depex]\r
+  TRUE\r
+\r
+[BuildOptions.common]\r
+  MSFT:*_*_*_DLINK_FLAGS  = /DLL /SUBSYSTEM:CONSOLE\r