summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Liu <linus.liu@intel.com>2024-08-21 01:10:28 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-08-28 11:39:12 +0000
commita297b81b623cc2c9a817a0a0c5b798353ea87064 (patch)
treedef472e589adab9c08913aa080c85262e7290f76
parent04d8d94a42e2b5d193bd2a8476dac117c01fe284 (diff)
downloadedk2-a297b81b623cc2c9a817a0a0c5b798353ea87064.tar.gz
edk2-a297b81b623cc2c9a817a0a0c5b798353ea87064.tar.bz2
edk2-a297b81b623cc2c9a817a0a0c5b798353ea87064.zip
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>
-rw-r--r--UefiPayloadPkg/Include/Library/BuildFdtLib.h4
-rw-r--r--UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c69
-rw-r--r--UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf6
-rw-r--r--UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf10
-rw-r--r--UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c4
-rw-r--r--UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c6
-rw-r--r--UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf2
-rw-r--r--UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c4
8 files changed, 97 insertions, 8 deletions
diff --git a/UefiPayloadPkg/Include/Library/BuildFdtLib.h b/UefiPayloadPkg/Include/Library/BuildFdtLib.h
index 2bde7ab66a..b674a6cab2 100644
--- a/UefiPayloadPkg/Include/Library/BuildFdtLib.h
+++ b/UefiPayloadPkg/Include/Library/BuildFdtLib.h
@@ -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
);
diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
index 82d0dd5855..55e85dce85 100644
--- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
+++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
@@ -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);
diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf
index ac857d3eea..5ebfe99f65 100644
--- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf
+++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf
@@ -34,6 +34,12 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSUMES
+
+
[Guids]
gUniversalPayloadSerialPortInfoGuid
diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf
index 7bb3a6ae96..d79fc5aa70 100644
--- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf
+++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf
@@ -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
diff --git a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
index 10bdbe2bbc..ecffc5c3a9 100644
--- a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
+++ b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c
@@ -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);
diff --git a/UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c b/UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
index 51c2e28d7d..dea6476711 100644
--- a/UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
+++ b/UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c
@@ -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;
diff --git a/UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf b/UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf
index cbb4f02efc..496a5c8319 100644
--- a/UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf
+++ b/UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf
@@ -26,7 +26,6 @@
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
- UefiPayloadPkg/UefiPayloadPkg.dec
[LibraryClasses]
BaseLib
@@ -36,4 +35,3 @@
[Guids]
gEfiHobMemoryAllocModuleGuid
gEfiHobMemoryAllocStackGuid
-
diff --git a/UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c b/UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c
index 60a17b8fc2..efaab326bb 100644
--- a/UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c
+++ b/UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c
@@ -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;