Why need a separate DebugLib instance? > -----Original Message----- > From: Sravanthi, K KavyaX <k.kavyax.sravan...@intel.com> > Sent: Thursday, July 14, 2022 12:31 PM > To: devel@edk2.groups.io > Cc: Sravanthi, K KavyaX <k.kavyax.sravan...@intel.com>; Dong, Guo > <guo.d...@intel.com>; Ni, Ray <ray...@intel.com>; > Maurice Ma <maurice...@intel.com>; You, Benjamin <benjamin....@intel.com>; > Rhodes, Sean > <sean@starlabs.systems> > Subject: [PATCH 1/3] UefiPayloadPkg: Implement a new DebugLib instance > > Add new Debug library instance to support multiple channel debug message. > > Cc: Guo Dong <guo.d...@intel.com> > Cc: Ray Ni <ray...@intel.com> > Cc: Maurice Ma <maurice...@intel.com> > Cc: Benjamin You <benjamin....@intel.com> > Cc: Sean Rhodes <sean@starlabs.systems> > Signed-off-by: Kavya <k.kavyax.sravan...@intel.com> > --- > UefiPayloadPkg/Library/BaseDebugLibHob/BaseDebugLibHob.c | 295 > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++ > UefiPayloadPkg/Library/BaseDebugLibHob/BaseDebugLibHob.inf | 37 > +++++++++++++++++++++++++++++++++++++ > 2 files changed, 332 insertions(+) > > diff --git a/UefiPayloadPkg/Library/BaseDebugLibHob/BaseDebugLibHob.c > b/UefiPayloadPkg/Library/BaseDebugLibHob/BaseDebugLibHob.c > new file mode 100644 > index 0000000000..0fd9e795a3 > --- /dev/null > +++ b/UefiPayloadPkg/Library/BaseDebugLibHob/BaseDebugLibHob.c > @@ -0,0 +1,295 @@ > +/** @file > + Instance of Debug Library based on Serial Port Library. > + > + Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include <Base.h> > +#include <Library/BaseLib.h> > +#include <Library/BaseMemoryLib.h> > +#include <Library/DebugLib.h> > +#include <Library/PrintLib.h> > +#include <Library/PcdLib.h> > +#include <Library/DebugPrintErrorLevelLib.h> > + > +// > +// Define the maximum debug and assert message length that this library > supports > +// > +#define MAX_DEBUG_MESSAGE_LENGTH 0x100 > + > +/** > + Initialize the serial device hardware. > + > + If no initialization is required, then return RETURN_SUCCESS. > + If the serial device was successfully initialized, then return > RETURN_SUCCESS. > + If the serial device could not be initialized, then return > RETURN_DEVICE_ERROR. > + If gUniversalPayloadSerialPortInfoGuid not found, then return > RETURN_NOT_FOUND. > + > + @retval RETURN_SUCCESS The serial device was initialized. > + @retval RETURN_DEVICE_ERROR The serial device could not be initialized. > + @retval RETURN_NOT_FOUND GuidHob not found. > + > +**/ > +RETURN_STATUS > +EFIAPI > +SerialPortInitialize ( > + VOID > + ); > + > +/** > + Write data from buffer to serial device. > + > + Writes NumberOfBytes data bytes from Buffer to the serial device. > + The number of bytes actually written to the serial device is returned. > + If the return value is less than NumberOfBytes, then the write operation > failed. > + If Buffer is NULL, then return 0. > + If NumberOfBytes is zero, then return 0. > + > + @param Buffer Pointer to the data buffer to be written. > + @param NumberOfBytes Number of bytes to written to the serial device. > + > + @retval 0 NumberOfBytes is 0. > + @retval >0 The number of bytes written to the serial device. > + If this value is less than NumberOfBytes, then > the write operation failed. > + > +**/ > +UINTN > +EFIAPI > +SerialPortWrite ( > + IN UINT8 *Buffer, > + IN UINTN NumberOfBytes > + ); > + > +/** > + Prints a debug message to the debug output device if the specified error > level is enabled. > + > + If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function > + GetDebugPrintErrorLevel (), then print the message specified by Format and > the > + associated variable argument list to the debug output device. > + > + If Format is NULL, then ASSERT(). > + > + @param ErrorLevel The error level of the debug message. > + @param Format Format string for the debug message to print. > + @param ... Variable argument list whose contents are accessed > + based on the format string specified by Format. > + > +**/ > +VOID > +EFIAPI > +DebugPrint ( > + IN UINTN ErrorLevel, > + IN CONST CHAR8 *Format, > + ... > + ) > +{ > + CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; > + VA_LIST Marker; > + > + // > + // If Format is NULL, then ASSERT(). > + // > + ASSERT (Format != NULL); > + > + // > + // Check driver debug mask value and global mask > + // > + if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) { > + return; > + } > + > + // > + // Convert the DEBUG() message to an ASCII String > + // > + VA_START (Marker, Format); > + AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); > + VA_END (Marker); > + > + SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer)); > +} > + > +/** > + Prints an assert message containing a filename, line number, and > description. > + This may be followed by a breakpoint or a dead loop. > + > + Print a message of the form "ASSERT <FileName>(<LineNumber>): > <Description>\n" > + to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED > bit of > + PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if > + DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set > then > + CpuDeadLoop() is called. If neither of these bits are set, then this > function > + returns immediately after the message is printed to the debug output > device. > + DebugAssert() must actively prevent recursion. If DebugAssert() is called > while > + processing another DebugAssert(), then DebugAssert() must return > immediately. > + > + If FileName is NULL, then a <FileName> string of "(NULL) Filename" is > printed. > + If Description is NULL, then a <Description> string of "(NULL) > Description" is printed. > + > + @param FileName The pointer to the name of the source file that > generated the assert condition. > + @param LineNumber The line number in the source file that generated the > assert condition > + @param Description The pointer to the description of the assert > condition. > + > +**/ > +VOID > +EFIAPI > +DebugAssert ( > + IN CONST CHAR8 *FileName, > + IN UINTN LineNumber, > + IN CONST CHAR8 *Description > + ) > +{ > + CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; > + > + // > + // Generate the ASSERT() message in Ascii format > + // > + AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT [%a] %a(%d): %a\n", > gEfiCallerBaseName, FileName, LineNumber, > Description); > + > + SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer)); > + > + // > + // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings > + // > + if ((PcdGet8(PcdDebugPropertyMask) & > DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) { > + CpuBreakpoint (); > + } else if ((PcdGet8(PcdDebugPropertyMask) & > DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) { > + CpuDeadLoop (); > + } > +} > + > +/** > + Fills a target buffer with PcdDebugClearMemoryValue, and returns the > target buffer. > + > + This function fills Length bytes of Buffer with the value specified by > + PcdDebugClearMemoryValue, and returns Buffer. > + > + If Buffer is NULL, then ASSERT(). > + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). > + > + @param Buffer Pointer to the target buffer to be filled with > PcdDebugClearMemoryValue. > + @param Length Number of bytes in Buffer to fill with zeros > PcdDebugClearMemoryValue. > + > + @return Buffer Pointer to the target buffer filled with > PcdDebugClearMemoryValue. > + > +**/ > +VOID * > +EFIAPI > +DebugClearMemory ( > + OUT VOID *Buffer, > + IN UINTN Length > + ) > +{ > + ASSERT (Buffer != NULL); > + > + return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue)); > +} > + > +/** > + Returns TRUE if ASSERT() macros are enabled. > + > + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit > of > + PcdDebugProperyMask is set. Otherwise FALSE is returned. > + > + @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of > PcdDebugProperyMask is set. > + @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of > PcdDebugProperyMask is clear. > + > +**/ > +BOOLEAN > +EFIAPI > +DebugAssertEnabled ( > + VOID > + ) > +{ > + return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & > DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0); > +} > + > +/** > + Returns TRUE if DEBUG() macros are enabled. > + > + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of > + PcdDebugProperyMask is set. Otherwise FALSE is returned. > + > + @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of > PcdDebugProperyMask is set. > + @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of > PcdDebugProperyMask is clear. > + > +**/ > +BOOLEAN > +EFIAPI > +DebugPrintEnabled ( > + VOID > + ) > +{ > + return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & > DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0); > +} > + > +/** > + Returns TRUE if DEBUG_CODE() macros are enabled. > + > + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of > + PcdDebugProperyMask is set. Otherwise FALSE is returned. > + > + @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of > PcdDebugProperyMask is set. > + @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of > PcdDebugProperyMask is clear. > + > +**/ > +BOOLEAN > +EFIAPI > +DebugCodeEnabled ( > + VOID > + ) > +{ > + return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & > DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0); > +} > + > +/** > + Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled. > + > + This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit > of > + PcdDebugProperyMask is set. Otherwise FALSE is returned. > + > + @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of > PcdDebugProperyMask is set. > + @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of > PcdDebugProperyMask is clear. > + > +**/ > +BOOLEAN > +EFIAPI > +DebugClearMemoryEnabled ( > + VOID > + ) > +{ > + return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & > DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0); > +} > + > +/** > + Returns TRUE if any one of the bit is set both in ErrorLevel and > PcdFixedDebugPrintErrorLevel. > + > + This function compares the bit mask of ErrorLevel and > PcdFixedDebugPrintErrorLevel. > + > + @retval TRUE Current ErrorLevel is supported. > + @retval FALSE Current ErrorLevel is not supported. > + > +**/ > +BOOLEAN > +EFIAPI > +DebugPrintLevelEnabled ( > + IN CONST UINTN ErrorLevel > + ) > +{ > + return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != > 0); > +} > + > +/** > + The constructor function to initialize Debug port Library > + > + @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. > + > +**/ > +RETURN_STATUS > +EFIAPI > +BaseDebugLibHobConstructor ( > + VOID > + ) > +{ > + return SerialPortInitialize (); > +} > diff --git a/UefiPayloadPkg/Library/BaseDebugLibHob/BaseDebugLibHob.inf > b/UefiPayloadPkg/Library/BaseDebugLibHob/BaseDebugLibHob.inf > new file mode 100644 > index 0000000000..11ed8de08b > --- /dev/null > +++ b/UefiPayloadPkg/Library/BaseDebugLibHob/BaseDebugLibHob.inf > @@ -0,0 +1,37 @@ > +## @file > +# Instance of Debug Library based on Serial Port Library. > +# > +# Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> > +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x00010005 > + BASE_NAME = BaseDebugLibHob > + FILE_GUID = ae4cc887-ea47-4d5c-a8f9-1d08405b5f8b > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = DebugLib > + CONSTRUCTOR = BaseDebugLibHobConstructor > + > +[Sources] > + BaseDebugLibHob.c > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + > +[LibraryClasses] > + BaseLib > + PcdLib > + DebugPrintErrorLevelLib > + BaseMemoryLib > + PrintLib > + SerialPortLib > + > +[Pcd] > + gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue > + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask > + gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel > -- > 2.30.2.windows.1
-=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#91342): https://edk2.groups.io/g/devel/message/91342 Mute This Topic: https://groups.io/mt/92373389/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-