Add a GUIDed HOB to init Debug Print error level earlier in DXE. Add NULL PEIM library to init HOB.

Debug Print Error level can be controled by an EFI variable. Update the DXE version of the library to use a HOB if the variable services are not yet availilbe. This allows the variable to be used early in the DXE phase. 

approved-by: andrewfish
reviewed-by: lgao4



git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12516 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
andrewfish 2011-10-08 21:00:13 +00:00
parent f2a4d59359
commit d4a78455c6
6 changed files with 154 additions and 11 deletions

View File

@ -62,6 +62,7 @@ extern EFI_GUID gEfiDebugMaskProtocolGuid;
/// ///
/// GUID used to store the global debug mask in an the "EFIDebug" EFI Variabe /// GUID used to store the global debug mask in an the "EFIDebug" EFI Variabe
/// Also used as a GUIDed HOB that contains a UINT32 debug mask default value
/// ///
#define EFI_GENERIC_VARIABLE_GUID \ #define EFI_GENERIC_VARIABLE_GUID \
{ 0x59d1c24f, 0x50f1, 0x401a, {0xb1, 0x01, 0xf3, 0x3e, 0x0d, 0xae, 0xd4, 0x43} } { 0x59d1c24f, 0x50f1, 0x401a, {0xb1, 0x01, 0xf3, 0x3e, 0x0d, 0xae, 0xd4, 0x43} }

View File

@ -19,6 +19,7 @@
#include <Library/DebugPrintErrorLevelLib.h> #include <Library/DebugPrintErrorLevelLib.h>
#include <Library/PcdLib.h> #include <Library/PcdLib.h>
#include <Library/HobLib.h>
#include <Guid/DebugMask.h> #include <Guid/DebugMask.h>
@ -89,10 +90,11 @@ BOOLEAN mGlobalErrorLevelInitialized = FALSE;
/// Global variable that contains the current debug error level mask for the /// Global variable that contains the current debug error level mask for the
/// module that is using this library instance. This variable is initially /// module that is using this library instance. This variable is initially
/// set to the PcdDebugPrintErrorLevel value. If the EFI Variable exists that /// set to the PcdDebugPrintErrorLevel value. If the EFI Variable exists that
/// contains the global debug print error level mask, then that override the /// contains the global debug print error level mask, then that overrides the
/// PcdDebugPrintErrorLevel value. If the Debug Mask Protocol SetDebugMask() /// PcdDebugPrintErrorLevel value. The EFI Variable can optionally be
/// service is called, then that overrides bit the PcdDebugPrintErrorLevel and /// discovered via a HOB so early DXE drivers can access the variable. If the
/// the EFI Variable setting. /// Debug Mask Protocol SetDebugMask() service is called, then that overrides
/// the PcdDebugPrintErrorLevel and the EFI Variable setting.
/// ///
UINT32 mDebugPrintErrorLevel = 0; UINT32 mDebugPrintErrorLevel = 0;
@ -122,7 +124,7 @@ DxeDebugPrintErrorLevelLibConstructor (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
// //
// Initialize the error level mask from PCD setting. // Initialize the error level mask from PCD setting.
@ -142,7 +144,8 @@ DxeDebugPrintErrorLevelLibConstructor (
// //
// Attempt to retrieve the global debug print error level mask from the EFI Variable // Attempt to retrieve the global debug print error level mask from the EFI Variable
// If the EFI Variable can not be accessed when this module's library constructors are // If the EFI Variable can not be accessed when this module's library constructors are
// executed, then the EFI Variable access will be reattempted on every DEBUG() print // executed a HOB can be used to set the global debug print error level. If no value
// was found then the EFI Variable access will be reattempted on every DEBUG() print
// from this module until the EFI Variable services are available. // from this module until the EFI Variable services are available.
// //
GetDebugPrintErrorLevel (); GetDebugPrintErrorLevel ();
@ -194,6 +197,7 @@ GetDebugPrintErrorLevel (
EFI_TPL CurrentTpl; EFI_TPL CurrentTpl;
UINTN Size; UINTN Size;
UINTN GlobalErrorLevel; UINTN GlobalErrorLevel;
VOID *Hob;
// //
// If the constructor has not been executed yet, then just return the PCD value. // If the constructor has not been executed yet, then just return the PCD value.
@ -205,8 +209,8 @@ GetDebugPrintErrorLevel (
} }
// //
// Check to see if an attempt has been mde to retrieve the global debug print // Check to see if an attempt has been made to retrieve the global debug print
// error level mask. Since this libtrary instance stores the global debug print // error level mask. Since this library instance stores the global debug print
// error level mask in an EFI Variable, the EFI Variable should only be accessed // error level mask in an EFI Variable, the EFI Variable should only be accessed
// once to reduce the overhead of reading the EFI Variable on every debug print // once to reduce the overhead of reading the EFI Variable on every debug print
// //
@ -242,6 +246,18 @@ GetDebugPrintErrorLevel (
// //
mDebugPrintErrorLevel = (UINT32)GlobalErrorLevel; mDebugPrintErrorLevel = (UINT32)GlobalErrorLevel;
} }
} else {
//
// If variable services are not yet availible optionally get the global
// debug print error level mask from a HOB.
//
Hob = GetFirstGuidHob (&gEfiGenericVariableGuid);
if (Hob != NULL) {
if (GET_GUID_HOB_DATA_SIZE (Hob) == sizeof (UINT32)) {
mDebugPrintErrorLevel = *(UINT32 *)GET_GUID_HOB_DATA (Hob);
mGlobalErrorLevelInitialized = TRUE;
}
}
} }
} }
} }

View File

@ -39,6 +39,7 @@
[LibraryClasses] [LibraryClasses]
PcdLib PcdLib
HobLib
[Protocols] [Protocols]
gEfiDebugMaskProtocolGuid gEfiDebugMaskProtocolGuid

View File

@ -0,0 +1,78 @@
/** @file
NULL Library class that reads Debug Mask variable and if it exists makes a
HOB that contains the debug mask.
Copyright (c) 2011, Apple, Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiPei.h>
#include <Library/HobLib.h>
#include <Library/DebugLib.h>
#include <Library/PeiServicesLib.h>
#include <Ppi/ReadOnlyVariable2.h>
#include <Guid/DebugMask.h>
/**
The constructor reads variable and sets HOB
@param FileHandle The handle of FFS header the loaded driver.
@param PeiServices The pointer to the PEI services.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
PeiDebugPrintHobLibConstructor (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;
UINTN Size;
UINT64 GlobalErrorLevel;
UINT32 HobErrorLevel;
Status = PeiServicesLocatePpi (
&gEfiPeiReadOnlyVariable2PpiGuid,
0,
NULL,
(VOID **)&Variable
);
if (!EFI_ERROR (Status)) {
Size = sizeof (GlobalErrorLevel);
Status = Variable->GetVariable (
Variable,
DEBUG_MASK_VARIABLE_NAME,
&gEfiGenericVariableGuid,
NULL,
&Size,
&GlobalErrorLevel
);
if (!EFI_ERROR (Status)) {
//
// Build the GUID'ed HOB for DXE
//
HobErrorLevel = (UINT32)GlobalErrorLevel;
BuildGuidDataHob (
&gEfiGenericVariableGuid,
&HobErrorLevel,
sizeof (HobErrorLevel)
);
}
}
return EFI_SUCCESS;
}

View File

@ -0,0 +1,46 @@
## @file
# NULL Library class that reads Debug Mask variable and if it exists makes a
# HOB that contains the debug mask.
#
# Copyright (c) 2011, Apple, Inc. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = PeiDebugPrintHobLib
FILE_GUID = EB0BDD73-DABB-E74B-BF51-62DC1DA521E1
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
LIBRARY_CLASS = NULL|PEIM
CONSTRUCTOR = PeiDebugPrintHobLibConstructor
[Sources]
PeiDebugPrintHobLib.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
PeiServicesLib
DebugLib
[Ppis]
gEfiPeiReadOnlyVariable2PpiGuid
[Guids]
gEfiGenericVariableGuid
[Depex]
gEfiPeiReadOnlyVariable2PpiGuid

View File

@ -244,6 +244,7 @@
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
MdeModulePkg/Library/PeiDebugPrintHobLib/PeiDebugPrintHobLib.inf
MdeModulePkg/Universal/CapsulePei/CapsulePei.inf MdeModulePkg/Universal/CapsulePei/CapsulePei.inf
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf