1 /** @file
2   NULL Library class that reads Debug Mask variable and if it exists makes a
3   HOB that contains the debug mask.
4 
5   Copyright (c) 2011, Apple, Inc. All rights reserved.<BR>
6   This program and the accompanying materials
7   are licensed and made available under the terms and conditions of the BSD License
8   which accompanies this distribution.  The full text of the license may be found at
9   http://opensource.org/licenses/bsd-license.php
10 
11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #include <PiPei.h>
17 
18 #include <Library/HobLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/PeiServicesLib.h>
21 
22 #include <Ppi/ReadOnlyVariable2.h>
23 #include <Guid/DebugMask.h>
24 
25 
26 /**
27   The constructor reads variable and sets HOB
28 
29   @param  FileHandle   The handle of FFS header the loaded driver.
30   @param  PeiServices  The pointer to the PEI services.
31 
32   @retval EFI_SUCCESS  The constructor always returns EFI_SUCCESS.
33 
34 **/
35 EFI_STATUS
36 EFIAPI
PeiDebugPrintHobLibConstructor(IN EFI_PEI_FILE_HANDLE FileHandle,IN CONST EFI_PEI_SERVICES ** PeiServices)37 PeiDebugPrintHobLibConstructor (
38   IN EFI_PEI_FILE_HANDLE        FileHandle,
39   IN CONST EFI_PEI_SERVICES     **PeiServices
40   )
41 {
42   EFI_STATUS                      Status;
43   EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;
44   UINTN                           Size;
45   UINT64                          GlobalErrorLevel;
46   UINT32                          HobErrorLevel;
47 
48   Status = PeiServicesLocatePpi (
49              &gEfiPeiReadOnlyVariable2PpiGuid,
50              0,
51              NULL,
52              (VOID **)&Variable
53              );
54   if (!EFI_ERROR (Status)) {
55     Size = sizeof (GlobalErrorLevel);
56     Status = Variable->GetVariable (
57                          Variable,
58                          DEBUG_MASK_VARIABLE_NAME,
59                          &gEfiGenericVariableGuid,
60                          NULL,
61                          &Size,
62                          &GlobalErrorLevel
63                          );
64     if (!EFI_ERROR (Status)) {
65       //
66       // Build the GUID'ed HOB for DXE
67       //
68       HobErrorLevel = (UINT32)GlobalErrorLevel;
69       BuildGuidDataHob (
70         &gEfiGenericVariableGuid,
71         &HobErrorLevel,
72         sizeof (HobErrorLevel)
73         );
74     }
75   }
76 
77   return EFI_SUCCESS;
78 }
79