]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
UefiPayloadPkg: Add a new DebugPrintErrorLevelLib instance
[mirror_edk2.git] / UefiPayloadPkg / Library / DebugPrintErrorLevelLibHob / DebugPrintErrorLevelLibHob.c
diff --git a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
new file mode 100644 (file)
index 0000000..4f6b4ef
--- /dev/null
@@ -0,0 +1,80 @@
+/** @file\r
+  Debug Print Error Level library instance that retrieves\r
+  the DebugPrintErrorLevel from bootloader.\r
+\r
+  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+#include <Uefi.h>\r
+#include <PiDxe.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Guid/DebugPrintErrorLevel.h>\r
+#include <Library/DebugPrintErrorLevelLib.h>\r
+#include <UniversalPayload/UniversalPayload.h>\r
+\r
+STATIC UINT32   gDebugPrintErrorLevel;\r
+STATIC BOOLEAN  gDebugPrintErrorLevelInitialized = FALSE;\r
+\r
+/**\r
+  Returns the debug print error level mask for the current module.\r
+\r
+  @return  Debug print error level mask for the current module.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+GetDebugPrintErrorLevel (\r
+  VOID\r
+  )\r
+{\r
+  VOID                                  *GuidHob;\r
+  UNIVERSAL_PAYLOAD_GENERIC_HEADER      *GenericHeader;\r
+  UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL  *DebugPrintErrorLevel;\r
+\r
+  if (!gDebugPrintErrorLevelInitialized) {\r
+    gDebugPrintErrorLevelInitialized = TRUE;\r
+    gDebugPrintErrorLevel            = PcdGet32 (PcdDebugPrintErrorLevel);\r
+    GuidHob                          = GetFirstGuidHob (&gEdkiiDebugPrintErrorLevelGuid);\r
+    if (GuidHob != NULL) {\r
+      GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *)GET_GUID_HOB_DATA (GuidHob);\r
+      if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) < GET_GUID_HOB_DATA_SIZE (GuidHob)) &&\r
+          (GenericHeader->Length <= GET_GUID_HOB_DATA_SIZE (GuidHob)))\r
+      {\r
+        if (GenericHeader->Revision == UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL_REVISION) {\r
+          DebugPrintErrorLevel =  (UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL *)GET_GUID_HOB_DATA (GuidHob);\r
+          if (DebugPrintErrorLevel->Header.Length > UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL, ErrorLevel)) {\r
+            gDebugPrintErrorLevel = DebugPrintErrorLevel->ErrorLevel;\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return gDebugPrintErrorLevel;\r
+}\r
+\r
+/**\r
+  Sets the global debug print error level mask fpr the entire platform.\r
+\r
+  @param   ErrorLevel     Global debug print error level.\r
+\r
+  @retval  TRUE           The debug print error level mask was sucessfully set.\r
+  @retval  FALSE          The debug print error level mask could not be set.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+SetDebugPrintErrorLevel (\r
+  UINT32  ErrorLevel\r
+  )\r
+{\r
+  //\r
+  // This library uinstance does not support setting the global debug print error\r
+  // level mask.\r
+  //\r
+  return FALSE;\r
+}\r