]> git.proxmox.com Git - mirror_edk2.git/commitdiff
PrmPkg/PrmContextBufferLib: Add initial library instance
authorMichael Kubacki <michael.kubacki@microsoft.com>
Tue, 7 Apr 2020 18:19:49 +0000 (11:19 -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

This library is introduced to add  a general abstraction for PRM context
buffer management.

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/Include/Library/PrmContextBufferLib.h [new file with mode: 0644]
PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c [new file with mode: 0644]
PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf [new file with mode: 0644]

diff --git a/PrmPkg/Include/Library/PrmContextBufferLib.h b/PrmPkg/Include/Library/PrmContextBufferLib.h
new file mode 100644 (file)
index 0000000..93dcd1e
--- /dev/null
@@ -0,0 +1,99 @@
+/** @file\r
+\r
+  The PRM Buffer Context library provides a general abstraction for context buffer management.\r
+\r
+  Copyright (c) Microsoft Corporation\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef PRM_CONTEXT_BUFFER_LIB_H_\r
+#define PRM_CONTEXT_BUFFER_LIB_H_\r
+\r
+#include <Base.h>\r
+#include <PrmContextBuffer.h>\r
+#include <Uefi.h>\r
+\r
+typedef enum {\r
+  ///\r
+  /// Search by the PRM module GUID\r
+  ///\r
+  ByModuleGuid,\r
+  ///\r
+  /// Search by the PRM handler GUID\r
+  ///\r
+  ByHandlerGuid\r
+} PRM_GUID_SEARCH_TYPE;\r
+\r
+/**\r
+  Finds a PRM context buffer for the given PRM handler GUID.\r
+\r
+  Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_CONTEXT_BUFFER is at the PRM handler level.\r
+\r
+  @param[in]  HandlerGuid                 A pointer to the PRM handler GUID.\r
+  @param[in]  ModuleContextBuffers        A pointer to the PRM context buffers structure for the PRM module.\r
+  @param[out] PrmModuleContextBuffer      A pointer to a pointer that will be set to the PRM context buffer\r
+                                          if successfully found.\r
+\r
+  @retval EFI_SUCCESS                     The PRM context buffer was found.\r
+  @retval EFI_INVALID_PARAMETER           A required parameter pointer is NULL.\r
+  @retval EFI_NOT_FOUND                   The context buffer for the given PRM handler GUID could not be found.\r
+\r
+**/\r
+EFI_STATUS\r
+FindContextBufferInModuleBuffers (\r
+  IN  CONST EFI_GUID                      *HandlerGuid,\r
+  IN  CONST PRM_MODULE_CONTEXT_BUFFERS    *ModuleContextBuffers,\r
+  OUT CONST PRM_CONTEXT_BUFFER            **ContextBuffer\r
+  );\r
+\r
+/**\r
+  Returns a PRM context buffers structure for the given PRM search type.\r
+\r
+  This function allows a caller to get the context buffers structure for a PRM module with either the PRM module\r
+  GUID or the GUID for a PRM handler in the module.\r
+\r
+  Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_CONTEXT_BUFFER is at the PRM handler level.\r
+\r
+  @param[in]  GuidSearchType              The type of GUID passed in the Guid argument.\r
+  @param[in]  Guid                        A pointer to the GUID of a PRM module or PRM handler. The actual GUID type\r
+                                          will be interpreted based on the value passed in GuidSearchType.\r
+  @param[out] PrmModuleContextBuffers     A pointer to a pointer that will be set to the PRM context buffers\r
+                                          structure if successfully found.\r
+\r
+  @retval EFI_SUCCESS                     The PRM context buffers structure was found.\r
+  @retval EFI_INVALID_PARAMETER           A required parameter pointer is NULL.\r
+  @retval EFI_NOT_FOUND                   The context buffers for the given GUID could not be found.\r
+\r
+**/\r
+EFI_STATUS\r
+GetModuleContextBuffers (\r
+  IN  PRM_GUID_SEARCH_TYPE                GuidSearchType,\r
+  IN  CONST EFI_GUID                      *Guid,\r
+  OUT CONST PRM_MODULE_CONTEXT_BUFFERS    **PrmModuleContextBuffers\r
+  );\r
+\r
+/**\r
+  Returns a PRM context buffer for the given PRM handler.\r
+\r
+  @param[in]  PrmHandlerGuid              A pointer to the GUID for the PRM handler.\r
+  @param[in]  PrmModuleContextBuffers     A pointer to a PRM_MODULE_CONTEXT_BUFFERS structure. If this optional\r
+                                          parameter is provided, the handler context buffer will be searched for in this\r
+                                          buffer structure which saves time by not performing a global search for the\r
+                                          module buffer structure.\r
+  @param[out] PrmContextBuffer            A pointer to a pointer that will be set to the PRM context buffer\r
+                                          if successfully found.\r
+\r
+  @retval EFI_SUCCESS                     The PRM context buffer was found.\r
+  @retval EFI_INVALID_PARAMETER           A required parameter pointer is NULL.\r
+  @retval EFI_NOT_FOUND                   The context buffer for the PRM handler could not be found.\r
+\r
+**/\r
+EFI_STATUS\r
+GetContextBuffer (\r
+  IN  CONST EFI_GUID                      *PrmHandlerGuid,\r
+  IN  CONST PRM_MODULE_CONTEXT_BUFFERS    *PrmModuleContextBuffers  OPTIONAL,\r
+  OUT CONST PRM_CONTEXT_BUFFER            **PrmContextBuffer\r
+  );\r
+\r
+#endif\r
diff --git a/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c
new file mode 100644 (file)
index 0000000..1a1a15b
--- /dev/null
@@ -0,0 +1,196 @@
+/** @file\r
+\r
+  The PRM Buffer Context library provides a general abstraction for context buffer management.\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/PrmContextBufferLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Protocol/PrmConfig.h>\r
+\r
+#define _DBGMSGID_        "[PRMCONTEXTBUFFERLIB]"\r
+\r
+/**\r
+  Finds a PRM context buffer for the given PRM handler GUID.\r
+\r
+  Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_CONTEXT_BUFFER is at the PRM handler level.\r
+\r
+  @param[in]  HandlerGuid                 A pointer to the PRM handler GUID.\r
+  @param[in]  ModuleContextBuffers        A pointer to the PRM context buffers structure for the PRM module.\r
+  @param[out] PrmModuleContextBuffer      A pointer to a pointer that will be set to the PRM context buffer\r
+                                          if successfully found.\r
+\r
+  @retval EFI_SUCCESS                     The PRM context buffer was found.\r
+  @retval EFI_INVALID_PARAMETER           A required parameter pointer is NULL.\r
+  @retval EFI_NOT_FOUND                   The context buffer for the given PRM handler GUID could not be found.\r
+\r
+**/\r
+EFI_STATUS\r
+FindContextBufferInModuleBuffers (\r
+  IN  CONST EFI_GUID                      *HandlerGuid,\r
+  IN  CONST PRM_MODULE_CONTEXT_BUFFERS    *ModuleContextBuffers,\r
+  OUT CONST PRM_CONTEXT_BUFFER            **ContextBuffer\r
+  )\r
+{\r
+  UINTN                                   Index;\r
+\r
+  DEBUG ((DEBUG_INFO, "    %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__));\r
+\r
+  if (HandlerGuid == NULL || ModuleContextBuffers == NULL || ContextBuffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  for (Index = 0; Index < ModuleContextBuffers->BufferCount; Index++) {\r
+    if (CompareGuid (&ModuleContextBuffers->Buffer[Index].HandlerGuid, HandlerGuid)) {\r
+      *ContextBuffer = &ModuleContextBuffers->Buffer[Index];\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+/**\r
+  Returns a PRM context buffers structure for the given PRM search type.\r
+\r
+  This function allows a caller to get the context buffers structure for a PRM module with either the PRM module\r
+  GUID or the GUID for a PRM handler in the module.\r
+\r
+  Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_CONTEXT_BUFFER is at the PRM handler level.\r
+\r
+  @param[in]  GuidSearchType              The type of GUID passed in the Guid argument.\r
+  @param[in]  Guid                        A pointer to the GUID of a PRM module or PRM handler. The actual GUID type\r
+                                          will be interpreted based on the value passed in GuidSearchType.\r
+  @param[out] PrmModuleContextBuffers     A pointer to a pointer that will be set to the PRM context buffers\r
+                                          structure if successfully found.\r
+\r
+  @retval EFI_SUCCESS                     The PRM context buffers structure was found.\r
+  @retval EFI_INVALID_PARAMETER           A required parameter pointer is NULL.\r
+  @retval EFI_NOT_FOUND                   The context buffers for the given GUID could not be found.\r
+\r
+**/\r
+EFI_STATUS\r
+GetModuleContextBuffers (\r
+  IN  PRM_GUID_SEARCH_TYPE                GuidSearchType,\r
+  IN  CONST EFI_GUID                      *Guid,\r
+  OUT CONST PRM_MODULE_CONTEXT_BUFFERS    **PrmModuleContextBuffers\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  UINTN                       HandleCount;\r
+  UINTN                       Index;\r
+  EFI_HANDLE                  *HandleBuffer;\r
+  PRM_CONFIG_PROTOCOL         *PrmConfigProtocol;\r
+  CONST PRM_CONTEXT_BUFFER    *PrmContextBuffer;\r
+\r
+  DEBUG ((DEBUG_INFO, "    %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__));\r
+\r
+  if (Guid == NULL || PrmModuleContextBuffers == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  *PrmModuleContextBuffers = NULL;\r
+\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gPrmConfigProtocolGuid,\r
+                  NULL,\r
+                  &HandleCount,\r
+                  &HandleBuffer\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    for (Index = 0; Index < HandleCount; Index++) {\r
+      Status = gBS->HandleProtocol (\r
+                      HandleBuffer[Index],\r
+                      &gPrmConfigProtocolGuid,\r
+                      (VOID **) &PrmConfigProtocol\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+      if (EFI_ERROR (Status) || PrmConfigProtocol == NULL) {\r
+        continue;\r
+      }\r
+\r
+      if (GuidSearchType == ByModuleGuid) {\r
+        if (CompareGuid (&PrmConfigProtocol->ModuleContextBuffers.ModuleGuid, Guid)) {\r
+          DEBUG ((\r
+            DEBUG_INFO,\r
+            "      %a %a: Found a PRM configuration protocol for PRM module %g.\n",\r
+            _DBGMSGID_,\r
+            __FUNCTION__,\r
+            Guid\r
+            ));\r
+\r
+          *PrmModuleContextBuffers = &PrmConfigProtocol->ModuleContextBuffers;\r
+          return EFI_SUCCESS;\r
+        }\r
+      } else {\r
+        Status = FindContextBufferInModuleBuffers (Guid, &PrmConfigProtocol->ModuleContextBuffers, &PrmContextBuffer);\r
+        if (!EFI_ERROR (Status)) {\r
+          *PrmModuleContextBuffers = &PrmConfigProtocol->ModuleContextBuffers;\r
+          return EFI_SUCCESS;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  DEBUG ((\r
+    DEBUG_INFO,\r
+    "      %a %a: Could not locate a PRM configuration protocol for PRM handler %g.\n",\r
+    _DBGMSGID_,\r
+    __FUNCTION__,\r
+    Guid\r
+    ));\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+/**\r
+  Returns a PRM context buffer for the given PRM handler.\r
+\r
+  @param[in]  PrmHandlerGuid              A pointer to the GUID for the PRM handler.\r
+  @param[in]  PrmModuleContextBuffers     A pointer to a PRM_MODULE_CONTEXT_BUFFERS structure. If this optional\r
+                                          parameter is provided, the handler context buffer will be searched for in this\r
+                                          buffer structure which saves time by not performing a global search for the\r
+                                          module buffer structure.\r
+  @param[out] PrmContextBuffer            A pointer to a pointer that will be set to the PRM context buffer\r
+                                          if successfully found.\r
+\r
+  @retval EFI_SUCCESS                     The PRM context buffer was found.\r
+  @retval EFI_INVALID_PARAMETER           A required parameter pointer is NULL.\r
+  @retval EFI_NOT_FOUND                   The context buffer for the PRM handler could not be found.\r
+\r
+**/\r
+EFI_STATUS\r
+GetContextBuffer (\r
+  IN  CONST EFI_GUID                      *PrmHandlerGuid,\r
+  IN  CONST PRM_MODULE_CONTEXT_BUFFERS    *PrmModuleContextBuffers  OPTIONAL,\r
+  OUT CONST PRM_CONTEXT_BUFFER            **PrmContextBuffer\r
+  )\r
+{\r
+  EFI_STATUS                              Status;\r
+  CONST PRM_MODULE_CONTEXT_BUFFERS        *ContextBuffers;\r
+\r
+  DEBUG ((DEBUG_INFO, "    %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__));\r
+\r
+  if (PrmHandlerGuid == NULL || PrmContextBuffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  *PrmContextBuffer = NULL;\r
+\r
+  if (PrmModuleContextBuffers == NULL) {\r
+    Status = GetModuleContextBuffers (ByHandlerGuid, PrmHandlerGuid, &ContextBuffers);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+  } else {\r
+    ContextBuffers = PrmModuleContextBuffers;\r
+  }\r
+  Status = FindContextBufferInModuleBuffers (PrmHandlerGuid, ContextBuffers, PrmContextBuffer);\r
+\r
+  return Status;\r
+}\r
diff --git a/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf
new file mode 100644 (file)
index 0000000..16ed1ed
--- /dev/null
@@ -0,0 +1,35 @@
+## @file\r
+#  PRM Context Buffer Library\r
+#\r
+#  Provides a general abstraction for PRM context buffer management.\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           = DxePrmContextBufferLib\r
+  FILE_GUID           = 49828E93-29FA-4665-B8B1-19BA4059D140\r
+  MODULE_TYPE         = DXE_DRIVER\r
+  VERSION_STRING      = 1.0\r
+  LIBRARY_CLASS       = PrmContextBufferLib|DXE_DRIVER UEFI_DRIVER UEFI_APPLICATION\r
+\r
+[Sources]\r
+  DxePrmContextBufferLib.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
+  UefiBootServicesTableLib\r