summaryrefslogtreecommitdiffstats
path: root/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
blob: 4f6b4ef1fb013382236c1c113e23940bf186f0fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/** @file
  Debug Print Error Level library instance that retrieves
  the DebugPrintErrorLevel from bootloader.

  Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <Base.h>
#include <Uefi.h>
#include <PiDxe.h>
#include <Library/PcdLib.h>
#include <Library/HobLib.h>
#include <Guid/DebugPrintErrorLevel.h>
#include <Library/DebugPrintErrorLevelLib.h>
#include <UniversalPayload/UniversalPayload.h>

STATIC UINT32   gDebugPrintErrorLevel;
STATIC BOOLEAN  gDebugPrintErrorLevelInitialized = FALSE;

/**
  Returns the debug print error level mask for the current module.

  @return  Debug print error level mask for the current module.

**/
UINT32
EFIAPI
GetDebugPrintErrorLevel (
  VOID
  )
{
  VOID                                  *GuidHob;
  UNIVERSAL_PAYLOAD_GENERIC_HEADER      *GenericHeader;
  UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL  *DebugPrintErrorLevel;

  if (!gDebugPrintErrorLevelInitialized) {
    gDebugPrintErrorLevelInitialized = TRUE;
    gDebugPrintErrorLevel            = PcdGet32 (PcdDebugPrintErrorLevel);
    GuidHob                          = GetFirstGuidHob (&gEdkiiDebugPrintErrorLevelGuid);
    if (GuidHob != NULL) {
      GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *)GET_GUID_HOB_DATA (GuidHob);
      if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) < GET_GUID_HOB_DATA_SIZE (GuidHob)) &&
          (GenericHeader->Length <= GET_GUID_HOB_DATA_SIZE (GuidHob)))
      {
        if (GenericHeader->Revision == UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL_REVISION) {
          DebugPrintErrorLevel =  (UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL *)GET_GUID_HOB_DATA (GuidHob);
          if (DebugPrintErrorLevel->Header.Length > UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL, ErrorLevel)) {
            gDebugPrintErrorLevel = DebugPrintErrorLevel->ErrorLevel;
          }
        }
      }
    }
  }

  return gDebugPrintErrorLevel;
}

/**
  Sets the global debug print error level mask fpr the entire platform.

  @param   ErrorLevel     Global debug print error level.

  @retval  TRUE           The debug print error level mask was sucessfully set.
  @retval  FALSE          The debug print error level mask could not be set.

**/
BOOLEAN
EFIAPI
SetDebugPrintErrorLevel (
  UINT32  ErrorLevel
  )
{
  //
  // This library uinstance does not support setting the global debug print error
  // level mask.
  //
  return FALSE;
}