]> git.proxmox.com Git - mirror_edk2.git/blob - UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
UefiPayloadPkg: Fix debug print error level hob not save correct
[mirror_edk2.git] / UefiPayloadPkg / Library / DebugPrintErrorLevelLibHob / DebugPrintErrorLevelLibHob.c
1 /** @file
2 Debug Print Error Level library instance that retrieves
3 the DebugPrintErrorLevel from bootloader.
4
5 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <Base.h>
11 #include <Uefi.h>
12 #include <PiDxe.h>
13 #include <Library/PcdLib.h>
14 #include <Library/HobLib.h>
15 #include <Guid/DebugPrintErrorLevel.h>
16 #include <Library/DebugPrintErrorLevelLib.h>
17 #include <UniversalPayload/UniversalPayload.h>
18
19 STATIC UINT32 gDebugPrintErrorLevel;
20 STATIC BOOLEAN gDebugPrintErrorLevelInitialized = FALSE;
21
22 /**
23 Returns the debug print error level mask for the current module.
24
25 @return Debug print error level mask for the current module.
26
27 **/
28 UINT32
29 EFIAPI
30 GetDebugPrintErrorLevel (
31 VOID
32 )
33 {
34 VOID *GuidHob;
35 UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;
36 UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL *DebugPrintErrorLevel;
37
38 if (!gDebugPrintErrorLevelInitialized) {
39 gDebugPrintErrorLevelInitialized = TRUE;
40 gDebugPrintErrorLevel = PcdGet32 (PcdDebugPrintErrorLevel);
41 GuidHob = GetFirstGuidHob (&gEdkiiDebugPrintErrorLevelGuid);
42 if (GuidHob != NULL) {
43 GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *)GET_GUID_HOB_DATA (GuidHob);
44 if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) < GET_GUID_HOB_DATA_SIZE (GuidHob)) &&
45 (GenericHeader->Length <= GET_GUID_HOB_DATA_SIZE (GuidHob)))
46 {
47 if (GenericHeader->Revision == UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL_REVISION) {
48 DebugPrintErrorLevel = (UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL *)GET_GUID_HOB_DATA (GuidHob);
49 if (DebugPrintErrorLevel->Header.Length >= UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL, ErrorLevel)) {
50 gDebugPrintErrorLevel = DebugPrintErrorLevel->ErrorLevel;
51 }
52 }
53 }
54 }
55 }
56
57 return gDebugPrintErrorLevel;
58 }
59
60 /**
61 Sets the global debug print error level mask fpr the entire platform.
62
63 @param ErrorLevel Global debug print error level.
64
65 @retval TRUE The debug print error level mask was sucessfully set.
66 @retval FALSE The debug print error level mask could not be set.
67
68 **/
69 BOOLEAN
70 EFIAPI
71 SetDebugPrintErrorLevel (
72 UINT32 ErrorLevel
73 )
74 {
75 //
76 // This library uinstance does not support setting the global debug print error
77 // level mask.
78 //
79 return FALSE;
80 }