diff --git a/AdvLoggerPkg/AdvLoggerPkg.dec b/AdvLoggerPkg/AdvLoggerPkg.dec index ffa1395255..770d0bc300 100644 --- a/AdvLoggerPkg/AdvLoggerPkg.dec +++ b/AdvLoggerPkg/AdvLoggerPkg.dec @@ -57,6 +57,16 @@ # gAdvancedLoggerPreDxeLogsGuid = { 0x751fc006, 0x5804, 0x440d, { 0x8b, 0x15, 0x61, 0x8c, 0xf6, 0x56, 0xae, 0x76 } } + ## GUID for specifying Advanced logger interim hob, which is used to indicate whether the logger in the + # interim phase of logger buffer being initialized. + # + gAdvancedLoggerInterimHobGuid = { 0x36587034, 0xfcde, 0x45b4, { 0x9a, 0x2b, 0xd5, 0xc4, 0xc1, 0x39, 0x96, 0x5a } } + + ## GUID for specifying Advanced logger interim buffer hob, which is used to carry interim log entries during the + # interim phase of being initialized. + # + gAdvancedLoggerInterimBufHobGuid = { 0x4c4f8c0b, 0xbe54, 0x49b3, { 0xba, 0x54, 0x33, 0xbf, 0x14, 0x47, 0x75, 0x24 } } + [Ppis] ## Advanced Logger Ppi - Communication from PEIM to PEI_CORE library implementation # diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/AdvancedLoggerLib.c b/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/AdvancedLoggerLib.c index 38823c4830..1315bdb730 100644 --- a/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/AdvancedLoggerLib.c +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/AdvancedLoggerLib.c @@ -9,7 +9,10 @@ #include #include +#include #include +#include +#include /** Including the PeiMain.h from PeiCore in order to access the Platform Blob data member. @@ -440,16 +443,20 @@ AdvancedLoggerGetLoggerInfo ( VOID ) { - UINTN BufferSize; - EFI_HOB_GUID_TYPE *GuidHob; - PEI_CORE_INSTANCE *PeiCoreInstance; - ADVANCED_LOGGER_INFO *LoggerInfo; - ADVANCED_LOGGER_INFO *LoggerInfoSec; - ADVANCED_LOGGER_PTR *LogPtr; - EFI_PHYSICAL_ADDRESS NewLoggerInfo; - UINTN Pages; - CONST EFI_PEI_SERVICES **PeiServices; - EFI_STATUS Status; + UINTN BufferSize; + EFI_HOB_GUID_TYPE *GuidHob; + EFI_HOB_GUID_TYPE *GuidHobInterim; + EFI_HOB_GUID_TYPE *GuidHobInterimBuf; + PEI_CORE_INSTANCE *PeiCoreInstance; + ADVANCED_LOGGER_INFO *LoggerInfo; + ADVANCED_LOGGER_INFO *LoggerInfoSec; + ADVANCED_LOGGER_PTR *LogPtr; + EFI_PHYSICAL_ADDRESS NewLoggerInfo; + UINTN Pages; + CONST EFI_PEI_SERVICES **PeiServices; + EFI_STATUS Status; + EFI_MEMORY_TYPE Type; + ADVANCED_LOGGER_MESSAGE_ENTRY_V2 *LogEntry; // Try to do the minimum work at the start of this function as this // is called quite often. @@ -492,6 +499,40 @@ AdvancedLoggerGetLoggerInfo ( } } + GuidHobInterim = GetFirstGuidHob (&gAdvancedLoggerInterimHobGuid); + if (GuidHobInterim != NULL) { + // In the middle of initialization, save the log to the interim hobs + Status = PeiServicesCreateHob ( + EFI_HOB_TYPE_GUID_EXTENSION, + (UINT16)(sizeof (EFI_HOB_GUID_TYPE) + sizeof (ADVANCED_LOGGER_INFO) + ADVANCED_LOGGER_MAX_MESSAGE_SIZE), + (VOID **)&GuidHobInterimBuf + ); + if (EFI_ERROR (Status)) { + return NULL; + } + + LoggerInfo = (ADVANCED_LOGGER_INFO *)GET_GUID_HOB_DATA (GuidHobInterimBuf); + BufferSize = sizeof (ADVANCED_LOGGER_INFO) + ADVANCED_LOGGER_MAX_MESSAGE_SIZE; + ZeroMem ((VOID *)LoggerInfo, BufferSize); + LoggerInfo->Signature = ADVANCED_LOGGER_SIGNATURE; + LoggerInfo->Version = ADVANCED_LOGGER_VERSION; + LoggerInfo->LogBuffer = PA_FROM_PTR (LoggerInfo + 1); + LoggerInfo->LogBufferSize = (UINT32)(BufferSize - sizeof (ADVANCED_LOGGER_INFO)); + LoggerInfo->LogCurrent = LoggerInfo->LogBuffer; + LoggerInfo->HwPrintLevel = FixedPcdGet32 (PcdAdvancedLoggerHdwPortDebugPrintErrorLevel); + AdvancedLoggerHdwPortInitialize (); + CopyGuid (&GuidHobInterimBuf->Name, &gAdvancedLoggerInterimBufHobGuid); + LoggerInfo->HdwPortInitialized = TRUE; + return LoggerInfo; + } else { + Status = PeiServicesCreateHob ( + EFI_HOB_TYPE_GUID_EXTENSION, + (UINT16)(sizeof (EFI_HOB_GUID_TYPE)), + (VOID **)&GuidHobInterim + ); + CopyGuid (&GuidHobInterim->Name, &gAdvancedLoggerInterimHobGuid); + } + // // No Logger Info - this must be the time to allocate a new LoggerInfo and save // the pointer in the PeiCoreInstance. @@ -516,14 +557,17 @@ AdvancedLoggerGetLoggerInfo ( if (FeaturePcdGet (PcdAdvancedLoggerPeiInRAM)) { Pages = FixedPcdGet32 (PcdAdvancedLoggerPages); + Type = EfiReservedMemoryType; } else { Pages = FixedPcdGet32 (PcdAdvancedLoggerPreMemPages); + // This is to avoid the interim buffer being allocated to consume 64KB on ARM64 platforms. + Type = EfiBootServicesData; } BufferSize = EFI_PAGES_TO_SIZE (Pages); Status = PeiServicesAllocatePages ( - EfiReservedMemoryType, + Type, Pages, &NewLoggerInfo ); @@ -561,6 +605,20 @@ AdvancedLoggerGetLoggerInfo ( UpdateSecLoggerInfo (LoggerInfo); } + // + // Check to see if we have anything in the interim buffer + // + GuidHobInterimBuf = GetFirstGuidHob (&gAdvancedLoggerInterimBufHobGuid); + while (GuidHobInterimBuf != NULL) { + // + // If we have an interim buffer, copy it to the new buffer + // + LoggerInfo = (ADVANCED_LOGGER_INFO *)GET_GUID_HOB_DATA (GuidHobInterimBuf); + LogEntry = (ADVANCED_LOGGER_MESSAGE_ENTRY_V2 *)(UINTN)LoggerInfo->LogBuffer; + AdvancedLoggerMemoryLoggerWrite (LogEntry->DebugLevel, LogEntry->MessageText, LogEntry->MessageLen); + GuidHobInterimBuf = GetNextGuidHob (&gAdvancedLoggerInterimHobGuid, GuidHobInterimBuf); + } + // // Publish the Advanced Logger Ppi // diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/AdvancedLoggerLib.inf b/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/AdvancedLoggerLib.inf index 9ba99c4f33..5348657e4f 100644 --- a/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/AdvancedLoggerLib.inf +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/PeiCore/AdvancedLoggerLib.inf @@ -46,6 +46,8 @@ [Guids] gAdvancedLoggerHobGuid gEfiFirmwareFileSystem2Guid + gAdvancedLoggerInterimHobGuid + gAdvancedLoggerInterimBufHobGuid [Ppis] gAdvancedLoggerPpiGuid ## PRODUCES