UefiPayloadPkg: Support Debug function when Hob was not available.

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4786

Initialize mUartInfo with PCD for debug message
when Hob was not available.

Signed-off-by: Linus Liu <linus.liu@intel.com>
This commit is contained in:
Linus Liu 2024-08-21 01:10:28 -07:00 committed by mergify[bot]
parent 04d8d94a42
commit a297b81b62
8 changed files with 97 additions and 8 deletions

View File

@ -6,7 +6,7 @@
**/
#ifndef BUILD_FDT_LIB_H_
#define BUILD_FDT__LIB_H_
#define BUILD_FDT_LIB_H_
/**
It will build FDT for UPL consumed.
@ -14,7 +14,7 @@
@retval EFI_SUCCESS If it completed successfully.
@retval Others If it failed to build required FDT.
**/
EFI_STATUS
BuildFdtForUPL (
IN VOID *FdtBase
);

View File

@ -143,6 +143,75 @@ SerialPortInitialize (
return RETURN_SUCCESS;
}
if (GetHobList () == NULL) {
mUartCount = 0;
SerialRegisterBase = PcdGet64 (PcdSerialRegisterBase);
MmioEnable = PcdGetBool (PcdSerialUseMmio);
BaudRate = PcdGet32 (PcdSerialBaudRate);
RegisterStride = (UINT8)PcdGet32 (PcdSerialRegisterStride);
mUartInfo[mUartCount].BaseAddress = SerialRegisterBase;
mUartInfo[mUartCount].UseMmio = MmioEnable;
mUartInfo[mUartCount].BaudRate = BaudRate;
mUartInfo[mUartCount].RegisterStride = RegisterStride;
mUartCount++;
Divisor = PcdGet32 (PcdSerialClockRate) / (BaudRate * 16);
if ((PcdGet32 (PcdSerialClockRate) % (BaudRate * 16)) >= BaudRate * 8) {
Divisor++;
}
//
// See if the serial port is already initialized
//
Initialized = TRUE;
if ((SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnable, RegisterStride) & 0x3F) != (PcdGet8 (PcdSerialLineControl) & 0x3F)) {
Initialized = FALSE;
}
Value = (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnable, RegisterStride) | B_UART_LCR_DLAB);
SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, MmioEnable, RegisterStride);
CurrentDivisor = SerialPortReadRegister (SerialRegisterBase, R_UART_BAUD_HIGH, MmioEnable, RegisterStride) << 8;
CurrentDivisor |= (UINT32)SerialPortReadRegister (SerialRegisterBase, R_UART_BAUD_LOW, MmioEnable, RegisterStride);
Value = (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnable, RegisterStride) & ~B_UART_LCR_DLAB);
SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, MmioEnable, RegisterStride);
if (CurrentDivisor != Divisor) {
Initialized = FALSE;
}
//
// Configure baud rate
//
SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, B_UART_LCR_DLAB, MmioEnable, RegisterStride);
SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_HIGH, (UINT8)(Divisor >> 8), MmioEnable, RegisterStride);
SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_LOW, (UINT8)(Divisor & 0xff), MmioEnable, RegisterStride);
//
// Clear DLAB and configure Data Bits, Parity, and Stop Bits.
// Strip reserved bits from PcdSerialLineControl
//
SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(PcdGet8 (PcdSerialLineControl) & 0x3F), MmioEnable, RegisterStride);
//
// Enable and reset FIFOs
// Strip reserved bits from PcdSerialFifoControl
//
SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, 0x00, MmioEnable, RegisterStride);
SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, (UINT8)(PcdGet8 (PcdSerialFifoControl) & (B_UART_FCR_FIFOE | B_UART_FCR_FIFO64)), MmioEnable, RegisterStride);
//
// Set FIFO Polled Mode by clearing IER after setting FCR
//
SerialPortWriteRegister (SerialRegisterBase, R_UART_IER, 0x00, MmioEnable, RegisterStride);
//
// Put Modem Control Register(MCR) into its reset state of 0x00.
//
SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00, MmioEnable, RegisterStride);
return RETURN_SUCCESS;
}
GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);
while (GuidHob != NULL) {
SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *)GET_GUID_HOB_DATA (GuidHob);

View File

@ -34,6 +34,12 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSUMES
[Guids]
gUniversalPayloadSerialPortInfoGuid

View File

@ -6,7 +6,6 @@
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeBaseSerialPortLibHob
@ -15,7 +14,6 @@
VERSION_STRING = 1.0
LIBRARY_CLASS = SerialPortLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
CONSTRUCTOR = DxeBaseSerialPortLibHobConstructor
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
@ -25,7 +23,7 @@
IoLib
HobLib
TimerLib
PlatformHookLib
[Sources]
DxeBaseSerialPortLibHob.c
BaseSerialPortLibHob.c
@ -36,6 +34,12 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSUMES
[Guids]
gUniversalPayloadSerialPortInfoGuid

View File

@ -35,6 +35,10 @@ GetDebugPrintErrorLevel (
UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;
UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL *DebugPrintErrorLevel;
if (GetHobList () == NULL) {
return PcdGet32 (PcdDebugPrintErrorLevel);
}
if (!gDebugPrintErrorLevelInitialized) {
gDebugPrintErrorLevelInitialized = TRUE;
gDebugPrintErrorLevel = PcdGet32 (PcdDebugPrintErrorLevel);

View File

@ -31,7 +31,6 @@ GetHobList (
VOID
)
{
ASSERT (mHobList != NULL);
return mHobList;
}
@ -109,6 +108,7 @@ CreateHob (
VOID *Hob;
HandOffHob = GetHobList ();
ASSERT (HandOffHob != NULL);
//
// Check Length to avoid data overflow.
@ -175,6 +175,7 @@ BuildResourceDescriptorHob (
Hob->ResourceAttribute = ResourceAttribute;
Hob->PhysicalStart = PhysicalStart;
Hob->ResourceLength = NumberOfBytes;
ZeroMem (&(Hob->Owner), sizeof (EFI_GUID));
}
/**
@ -305,6 +306,7 @@ GetFirstGuidHob (
VOID *HobList;
HobList = GetHobList ();
ASSERT (HobList != NULL);
return GetNextGuidHob (Guid, HobList);
}
@ -651,6 +653,7 @@ UpdateStackHob (
EFI_PEI_HOB_POINTERS Hob;
Hob.Raw = GetHobList ();
ASSERT (Hob.Raw != NULL);
while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {
//
@ -709,6 +712,7 @@ BuildMemoryAllocationHob (
}
ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
Hob->AllocDescriptor.MemoryLength = Length;
Hob->AllocDescriptor.MemoryType = MemoryType;

View File

@ -26,7 +26,6 @@
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec
[LibraryClasses]
BaseLib
@ -36,4 +35,3 @@
[Guids]
gEfiHobMemoryAllocModuleGuid
gEfiHobMemoryAllocStackGuid

View File

@ -51,6 +51,10 @@ PlatformHookSerialPortInitialize (
UINT8 *GuidHob;
UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;
if (GetHobList () == NULL) {
return RETURN_SUCCESS;
}
GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);
if (GuidHob == NULL) {
return EFI_NOT_FOUND;