diff --git a/MdeModulePkg/Include/Guid/DebugMask.h b/MdeModulePkg/Include/Guid/DebugMask.h index cfb0a69372..1e6beb562e 100644 --- a/MdeModulePkg/Include/Guid/DebugMask.h +++ b/MdeModulePkg/Include/Guid/DebugMask.h @@ -62,6 +62,7 @@ extern EFI_GUID gEfiDebugMaskProtocolGuid; /// /// 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 \ { 0x59d1c24f, 0x50f1, 0x401a, {0xb1, 0x01, 0xf3, 0x3e, 0x0d, 0xae, 0xd4, 0x43} } diff --git a/MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelLib.c b/MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelLib.c index 1182e2eb5b..cad57024cd 100644 --- a/MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelLib.c +++ b/MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelLib.c @@ -19,6 +19,7 @@ #include #include +#include #include @@ -89,10 +90,11 @@ BOOLEAN mGlobalErrorLevelInitialized = FALSE; /// Global variable that contains the current debug error level mask for the /// module that is using this library instance. This variable is initially /// set to the PcdDebugPrintErrorLevel value. If the EFI Variable exists that -/// contains the global debug print error level mask, then that override the -/// PcdDebugPrintErrorLevel value. If the Debug Mask Protocol SetDebugMask() -/// service is called, then that overrides bit the PcdDebugPrintErrorLevel and -/// the EFI Variable setting. +/// contains the global debug print error level mask, then that overrides the +/// PcdDebugPrintErrorLevel value. The EFI Variable can optionally be +/// discovered via a HOB so early DXE drivers can access the variable. If the +/// Debug Mask Protocol SetDebugMask() service is called, then that overrides +/// the PcdDebugPrintErrorLevel and the EFI Variable setting. /// UINT32 mDebugPrintErrorLevel = 0; @@ -122,13 +124,13 @@ DxeDebugPrintErrorLevelLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - + EFI_STATUS Status; + // // Initialize the error level mask from PCD setting. // mDebugPrintErrorLevel = PcdGet32 (PcdDebugPrintErrorLevel); - + // // Install Debug Mask Protocol onto ImageHandle // @@ -142,7 +144,8 @@ DxeDebugPrintErrorLevelLibConstructor ( // // 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 - // 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. // GetDebugPrintErrorLevel (); @@ -194,6 +197,7 @@ GetDebugPrintErrorLevel ( EFI_TPL CurrentTpl; UINTN Size; UINTN GlobalErrorLevel; + VOID *Hob; // // If the constructor has not been executed yet, then just return the PCD value. @@ -203,10 +207,10 @@ GetDebugPrintErrorLevel ( if (mSystemTable == NULL) { return PcdGet32 (PcdDebugPrintErrorLevel); } - + // - // Check to see if an attempt has been mde to retrieve the global debug print - // error level mask. Since this libtrary instance stores the global debug print + // Check to see if an attempt has been made to retrieve 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 // once to reduce the overhead of reading the EFI Variable on every debug print // @@ -242,6 +246,18 @@ GetDebugPrintErrorLevel ( // 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; + } + } } } } diff --git a/MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelLib.inf b/MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelLib.inf index a4a44b1c2e..65c0dc0034 100644 --- a/MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelLib.inf +++ b/MdeModulePkg/Library/DxeDebugPrintErrorLevelLib/DxeDebugPrintErrorLevelLib.inf @@ -39,6 +39,7 @@ [LibraryClasses] PcdLib + HobLib [Protocols] gEfiDebugMaskProtocolGuid diff --git a/MdeModulePkg/Library/PeiDebugPrintHobLib/PeiDebugPrintHobLib.c b/MdeModulePkg/Library/PeiDebugPrintHobLib/PeiDebugPrintHobLib.c new file mode 100644 index 0000000000..4bcf0030a0 --- /dev/null +++ b/MdeModulePkg/Library/PeiDebugPrintHobLib/PeiDebugPrintHobLib.c @@ -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.
+ 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 + +#include +#include +#include + +#include +#include + + +/** + 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; +} diff --git a/MdeModulePkg/Library/PeiDebugPrintHobLib/PeiDebugPrintHobLib.inf b/MdeModulePkg/Library/PeiDebugPrintHobLib/PeiDebugPrintHobLib.inf new file mode 100644 index 0000000000..492f03271e --- /dev/null +++ b/MdeModulePkg/Library/PeiDebugPrintHobLib/PeiDebugPrintHobLib.inf @@ -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.
+# +# 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 \ No newline at end of file diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 7a42d12c85..dec51cd2c8 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -244,6 +244,7 @@ MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf + MdeModulePkg/Library/PeiDebugPrintHobLib/PeiDebugPrintHobLib.inf MdeModulePkg/Universal/CapsulePei/CapsulePei.inf MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf