Initialize mUartInfo with PCD for debug message when Hob was not available.
Cc: Benny Lin <benny....@intel.com> Cc: Gua Guo <gua....@intel.com> Cc: Chasel Chiu <chasel.c...@intel.com> Cc: James Lu <james...@intel.com> Cc: Dhaval Sharma <dha...@rivosinc.com> Signed-off-by: Linus Liu <linus....@intel.com> --- UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c | 69 ++++++++++++++++++++ UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c | 5 ++ UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c | 7 +- UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c | 4 ++ UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf | 10 +++ UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf | 13 ++-- UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf | 1 + 7 files changed, 104 insertions(+), 5 deletions(-) diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c index 82d0dd585508..55e85dce8598 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/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c index 10bdbe2bbc1f..e9cce86bb853 100644 --- a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c +++ b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibHob.c @@ -13,6 +13,7 @@ #include <Library/PcdLib.h> #include <Library/HobLib.h> #include <Guid/DebugPrintErrorLevel.h> +#include <Guid/UniversalPayloadBase.h> #include <Library/DebugPrintErrorLevelLib.h> #include <UniversalPayload/UniversalPayload.h> @@ -35,6 +36,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 51c2e28d7ddd..05cd0ea997f1 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)); } /** @@ -239,6 +240,7 @@ GetFirstHob ( VOID *HobList; HobList = GetHobList (); + ASSERT (HobList != NULL); return GetNextHob (Type, HobList); } @@ -305,6 +307,7 @@ GetFirstGuidHob ( VOID *HobList; HobList = GetHobList (); + ASSERT (HobList != NULL); return GetNextGuidHob (Guid, HobList); } @@ -651,6 +654,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 +713,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/PlatformHookLib/PlatformHookLib.c b/UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c index 60a17b8fc256..efaab326bb68 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; diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf index ac857d3eea7c..76e431c2f102 100644 --- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf @@ -18,6 +18,7 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + UefiPayloadPkg/UefiPayloadPkg.dec [LibraryClasses] PcdLib @@ -34,6 +35,15 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSUMES + gUefiPayloadPkgTokenSpaceGuid.PcdHandOffFdtEnable + + [Guids] gUniversalPayloadSerialPortInfoGuid diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf index 7bb3a6ae96dd..552ae6c4f786 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,27 +14,33 @@ 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 + UefiPayloadPkg/UefiPayloadPkg.dec [LibraryClasses] PcdLib IoLib HobLib TimerLib - + PlatformHookLib [Sources] DxeBaseSerialPortLibHob.c BaseSerialPortLibHob.c - [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSUMES + gUefiPayloadPkgTokenSpaceGuid.PcdHandOffFdtEnable [Guids] gUniversalPayloadSerialPortInfoGuid diff --git a/UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf b/UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf index cbb4f02efc15..6a19cfb5c214 100644 --- a/UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf +++ b/UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf @@ -36,4 +36,5 @@ [Guids] gEfiHobMemoryAllocModuleGuid gEfiHobMemoryAllocStackGuid + gUniversalPayloadDeviceTreeGuid -- 2.39.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119195): https://edk2.groups.io/g/devel/message/119195 Mute This Topic: https://groups.io/mt/106275989/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-