From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.28376.1684258532855852719 for ; Tue, 16 May 2023 10:35:33 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=nv3VOi6p; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: isaac.w.oram@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684258532; x=1715794532; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E8m8iYCbeyKUjBSO9VInLSRSTj9ut+Xu7rXGW2cBns0=; b=nv3VOi6p26UmGcOhnUpUDYRNx1eCxlRu0ounwa+Po4nfa0ohO50eiQD+ ojrYA7q5f7qckuum1RgJ1TYoW4/8WLDHqWAugWt7U4Rcv6YOrdikhLz+l klo+pAOdGvrzdvWTPywSNzSEI7R9wZTvvqrwCGf0Hnm+MefDQBWXOsJzS nba5jF3+IgL0f+8fpyxV7qsiHko5vbxcJahZyR18HS41EtWQ8ZqmqZyRf N5YuxgpDgEB+71XoxtocTUQOvOMYQLCZcHKqAzOdidKkx2g/VGRoETG2d oeKYeGeAfDko75iI14o7c3GGE26nT+hqLwRMgwm5oML0qSeF8OGn24uMY Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10712"; a="414948838" X-IronPort-AV: E=Sophos;i="5.99,278,1677571200"; d="scan'208";a="414948838" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2023 10:35:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10712"; a="1031375900" X-IronPort-AV: E=Sophos;i="5.99,278,1677571200"; d="scan'208";a="1031375900" Received: from fid-iworam.amr.corp.intel.com ([10.54.76.158]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2023 10:35:01 -0700 From: "Isaac Oram" To: devel@edk2.groups.io Cc: Isaac Oram , Jian J Wang , Liming Gao Subject: [edk2-devel][edk2-platforms][RFC PATCH V1 1/1] MdeModulePkg/StatusCodeHandlerSmm: Add debug strings to memory buffering Date: Tue, 16 May 2023 10:34:41 -0700 Message-Id: <4267c728bb494b5ba60862b2166fb848589f47ef.1684258196.git.isaac.w.oram@intel.com> X-Mailer: git-send-email 2.40.0.windows.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Extend the MemoryStatusCodeWorker functionality to log the debug strings. In the event of an assert, dump the strings to serial port. The rationale is that SMI latency is very important. This provides a means to log messages quickly (to memory) and dump them in the event of an assert. Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Isaac Oram --- .../Include/Guid/MemoryStatusCodeRecord.h | 7 + .../Smm/MemoryStatusCodeWorker.c | 199 ++++++++++++++++++ 2 files changed, 206 insertions(+) diff --git a/MdeModulePkg/Include/Guid/MemoryStatusCodeRecord.h b/MdeModulePkg/Include/Guid/MemoryStatusCodeRecord.h index a924c592c9..d37b6304c6 100644 --- a/MdeModulePkg/Include/Guid/MemoryStatusCodeRecord.h +++ b/MdeModulePkg/Include/Guid/MemoryStatusCodeRecord.h @@ -10,6 +10,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef __MEMORY_STATUS_CODE_RECORD_H__ #define __MEMORY_STATUS_CODE_RECORD_H__ +#include + /// /// Global ID used to identify GUIDed HOBs that start with a structure of type /// MEMORY_STATUSCODE_PACKET_HEADER, followed by an array of structures of type @@ -90,6 +92,11 @@ typedef struct { /// the system. Valid instance numbers start with the number 1. /// UINT32 Instance; + + // + // Extra data + // + UINT64 Data[(MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)) + 1]; } MEMORY_STATUSCODE_RECORD; extern EFI_GUID gMemoryStatusCodeRecordGuid; diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c index 80c94e4682..c482c4bd9a 100644 --- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c +++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c @@ -11,6 +11,141 @@ RUNTIME_MEMORY_STATUSCODE_HEADER *mMmMemoryStatusCodeTable; +VOID +DumpBufferToSerial ( + VOID + ); + +EFI_STATUS +EFIAPI +DumpRecordToSerial ( + IN EFI_STATUS_CODE_TYPE CodeType, + IN EFI_STATUS_CODE_VALUE Value, + IN UINT32 Instance, + IN EFI_GUID *CallerId, + IN EFI_STATUS_CODE_DATA *Data OPTIONAL + ) +{ + CHAR8 *Filename; + CHAR8 *Description; + CHAR8 *Format; + CHAR8 Buffer[MAX_EXTENDED_DATA_SIZE + sizeof (UINT64)]; + UINT32 ErrorLevel; + UINT32 LineNumber; + UINTN CharCount; + BASE_LIST Marker; + + Buffer[0] = '\0'; + + if ((Data != NULL) && + ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) + { + // + // Print ASSERT() information into output buffer. + // + CharCount = AsciiSPrint ( + Buffer, + sizeof (Buffer), + "\n\rDXE_ASSERT!: %a (%d): %a\n\r", + Filename, + LineNumber, + Description + ); + } else if ((Data != NULL) && + ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) + { + // + // Print DEBUG() information into output buffer. + // + CharCount = AsciiBSPrint ( + Buffer, + sizeof (Buffer), + Format, + Marker + ); + } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) { + // + // Print ERROR information into output buffer. + // + CharCount = AsciiSPrint ( + Buffer, + sizeof (Buffer), + "ERROR: C%08x:V%08x I%x", + CodeType, + Value, + Instance + ); + ASSERT (CharCount > 0); + + if (CallerId != NULL) { + CharCount += AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + " %g", + CallerId + ); + } + + if (Data != NULL) { + CharCount += AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + " %x", + Data + ); + } + + CharCount += AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + "\n\r" + ); + } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) { + // + // Print PROGRESS information into output buffer. + // + CharCount = AsciiSPrint ( + Buffer, + sizeof (Buffer), + "PROGRESS CODE: V%08x I%x\n\r", + Value, + Instance + ); + } else if ((Data != NULL) && + CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) && + (((EFI_STATUS_CODE_STRING_DATA *)Data)->StringType == EfiStringAscii)) + { + // + // EFI_STATUS_CODE_STRING_DATA + // + CharCount = AsciiSPrint ( + Buffer, + sizeof (Buffer), + "%a", + ((EFI_STATUS_CODE_STRING_DATA *)Data)->String.Ascii + ); + } else { + // + // Code type is not defined. + // + CharCount = AsciiSPrint ( + Buffer, + sizeof (Buffer), + "Undefined: C%08x:V%08x I%x\n\r", + CodeType, + Value, + Instance + ); + } + + // + // Call SerialPort Lib function to do print. + // + SerialPortWrite ((UINT8 *)Buffer, CharCount); + + return EFI_SUCCESS; +} + /** Initialize MM memory status code table as initialization for memory status code worker @@ -69,6 +204,9 @@ MemoryStatusCodeReportWorker ( ) { MEMORY_STATUSCODE_RECORD *Record; + CHAR8 *Filename; + CHAR8 *Description; + UINT32 LineNumber; // // Locate current record buffer. @@ -82,6 +220,7 @@ MemoryStatusCodeReportWorker ( Record->CodeType = CodeType; Record->Value = Value; Record->Instance = Instance; + CopyMem (&Record->Data, Data, (Data->HeaderSize + Data->Size)); // // If record index equals to max record number, then wrap around record index to zero. @@ -99,5 +238,65 @@ MemoryStatusCodeReportWorker ( mMmMemoryStatusCodeTable->RecordIndex = 0; } + if ((Data != NULL) && ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) { + // Found an assert, dump the buffer + DumpBufferToSerial (); + } + return EFI_SUCCESS; } + +VOID +DumpBufferToSerial ( + VOID + ) +{ + MEMORY_STATUSCODE_RECORD *CurrentRecord; + UINT32 CurrentIndex; + UINT32 RecordsToPrint; + CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; + UINTN CharCount; + + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Begin dump of SMM debug messages\n"); + SerialPortWrite ((UINT8 *)Buffer, CharCount); + + // + // Determine number of records to print + // + + RecordsToPrint = mMmMemoryStatusCodeTable->NumberOfRecords; + + // + // Determine first record in case we rolled over. + // + if (mMmMemoryStatusCodeTable->NumberOfRecords >= mMmMemoryStatusCodeTable->MaxRecordsNumber) { + RecordsToPrint = mMmMemoryStatusCodeTable->MaxRecordsNumber; + CurrentIndex = mMmMemoryStatusCodeTable->RecordIndex; + } else { + RecordsToPrint = mMmMemoryStatusCodeTable->NumberOfRecords; + CurrentIndex = 0; + } + + + // + // Locate first record. + // + CurrentRecord = (MEMORY_STATUSCODE_RECORD *)(mMmMemoryStatusCodeTable + 1); + CurrentRecord = &CurrentRecord[CurrentIndex]; + + // + // Print records + // + while (CurrentIndex < RecordsToPrint) { + DumpRecordToSerial (CurrentRecord->CodeType, CurrentRecord->Value, CurrentRecord->Instance, NULL, (EFI_STATUS_CODE_DATA *)CurrentRecord->Data); + CurrentIndex++; + if (CurrentIndex == mMmMemoryStatusCodeTable->MaxRecordsNumber) { + CurrentIndex = 0; + } + CurrentRecord = (MEMORY_STATUSCODE_RECORD *)(mMmMemoryStatusCodeTable + 1); + CurrentRecord = &CurrentRecord[CurrentIndex]; + } + + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "End dump of SMM debug messages\n"); + SerialPortWrite ((UINT8 *)Buffer, CharCount); +} -- 2.40.0.windows.1