From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id D2CF27803CE for ; Fri, 24 May 2024 04:13:31 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=xVH3ykHMA8I16oivZJSIPETBS1feAkaMugDYBdEH1dA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1716524009; v=1; b=vCA842liJz3iUMlFy9uCriDMPOm7/wO+unMDrr87MyEK2XnzrXQrbQgwXGASruZwDv7qWYjq IWj8kcI9eteOzo7ZT0cRy+2yfwFz8uPUFCYjXhrgfB487nC3Igl+1UxFxacqYwx4+07khNDNzR2 MrBrsTpEjj6JKIiv4pY3Nt2QKbRQbuv7t9waOlV+qkjD0KFZO785tayBzYzCnK0mqX49t8Bv6Ej sdxYPGNkks1oHBH3fFc9yK5o82Yn+A4A/stNShZaGErDc7Vv3ZtkZ77upqoAzRtO33kDpmrX3SP mKRjD9aqbeUerV3nDwHHhjCPQbebqGB/s0fMI2Y2Ej6gg== X-Received: by 127.0.0.2 with SMTP id 9WXbYY7687511xYOBsM5haDh; Thu, 23 May 2024 21:13:29 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by mx.groups.io with SMTP id smtpd.web10.8306.1716524005751425324 for ; Thu, 23 May 2024 21:13:25 -0700 X-CSE-ConnectionGUID: fKfcGr1wROqgpev6Wlwuvg== X-CSE-MsgGUID: LMTi6JlgQl+9WnFIap4/Ew== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="12715323" X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="12715323" X-Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 21:13:25 -0700 X-CSE-ConnectionGUID: 7UunGZTKTPuKhg+v+AHWrw== X-CSE-MsgGUID: sqbkP6EYShq5pw/oHHCNJg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="38334986" X-Received: from linusliu-desk1.gar.corp.intel.com ([10.225.76.64]) by fmviesa003.fm.intel.com with ESMTP; 23 May 2024 21:13:23 -0700 From: "Linus Liu" To: devel@edk2.groups.io Cc: Benny Lin , Gua Guo , Chasel Chiu , James Lu , Dhaval Sharma Subject: [edk2-devel] [PATCH v3 3/6] UefiPayloadPkg: Support Debug function when Hob was not available. Date: Thu, 23 May 2024 21:13:19 -0700 Message-Id: <20240524041319.1099-1-linus.liu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Thu, 23 May 2024 21:13:25 -0700 Resent-From: linus.liu@intel.com Reply-To: devel@edk2.groups.io,linus.liu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: A7X7TcMFWMWtytHlVoYvd0WKx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=vCA842li; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io Initialize mUartInfo with PCD for debug message when Hob was not available. Cc: Benny Lin Cc: Gua Guo Cc: Chasel Chiu Cc: James Lu Cc: Dhaval Sharma Signed-off-by: Linus Liu --- UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c = | 69 ++++++++++++++++++++ UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLevelLibH= ob.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/BaseSerialPortLibH= ob.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;=0D }=0D =0D + if (GetHobList () =3D=3D NULL) {=0D + mUartCount =3D 0;=0D + SerialRegisterBase =3D PcdGet64 (PcdSerialRegisterBase);=0D + MmioEnable =3D PcdGetBool (PcdSerialUseMmio);=0D + BaudRate =3D PcdGet32 (PcdSerialBaudRate);=0D + RegisterStride =3D (UINT8)PcdGet32 (PcdSerialRegisterStride);=0D +=0D + mUartInfo[mUartCount].BaseAddress =3D SerialRegisterBase;=0D + mUartInfo[mUartCount].UseMmio =3D MmioEnable;=0D + mUartInfo[mUartCount].BaudRate =3D BaudRate;=0D + mUartInfo[mUartCount].RegisterStride =3D RegisterStride;=0D + mUartCount++;=0D +=0D + Divisor =3D PcdGet32 (PcdSerialClockRate) / (BaudRate * 16);=0D + if ((PcdGet32 (PcdSerialClockRate) % (BaudRate * 16)) >=3D BaudRate * = 8) {=0D + Divisor++;=0D + }=0D +=0D + //=0D + // See if the serial port is already initialized=0D + //=0D + Initialized =3D TRUE;=0D + if ((SerialPortReadRegister (SerialRegisterBase, R_UART_LCR, MmioEnabl= e, RegisterStride) & 0x3F) !=3D (PcdGet8 (PcdSerialLineControl) & 0x3F)) {= =0D + Initialized =3D FALSE;=0D + }=0D +=0D + Value =3D (UINT8)(SerialPortReadRegister (SerialRegisterBase, R_UART_L= CR, MmioEnable, RegisterStride) | B_UART_LCR_DLAB);=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, MmioEn= able, RegisterStride);=0D + CurrentDivisor =3D SerialPortReadRegister (SerialRegisterBase, R_UAR= T_BAUD_HIGH, MmioEnable, RegisterStride) << 8;=0D + CurrentDivisor |=3D (UINT32)SerialPortReadRegister (SerialRegisterBase= , R_UART_BAUD_LOW, MmioEnable, RegisterStride);=0D + Value =3D (UINT8)(SerialPortReadRegister (SerialRegisterBase= , R_UART_LCR, MmioEnable, RegisterStride) & ~B_UART_LCR_DLAB);=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, Value, MmioEn= able, RegisterStride);=0D + if (CurrentDivisor !=3D Divisor) {=0D + Initialized =3D FALSE;=0D + }=0D +=0D + //=0D + // Configure baud rate=0D + //=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, B_UART_LCR_DL= AB, MmioEnable, RegisterStride);=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_HIGH, (UINT8)= (Divisor >> 8), MmioEnable, RegisterStride);=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_BAUD_LOW, (UINT8)(= Divisor & 0xff), MmioEnable, RegisterStride);=0D +=0D + //=0D + // Clear DLAB and configure Data Bits, Parity, and Stop Bits.=0D + // Strip reserved bits from PcdSerialLineControl=0D + //=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_LCR, (UINT8)(PcdGe= t8 (PcdSerialLineControl) & 0x3F), MmioEnable, RegisterStride);=0D +=0D + //=0D + // Enable and reset FIFOs=0D + // Strip reserved bits from PcdSerialFifoControl=0D + //=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, 0x00, MmioEna= ble, RegisterStride);=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_FCR, (UINT8)(PcdGe= t8 (PcdSerialFifoControl) & (B_UART_FCR_FIFOE | B_UART_FCR_FIFO64)), MmioEn= able, RegisterStride);=0D +=0D + //=0D + // Set FIFO Polled Mode by clearing IER after setting FCR=0D + //=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_IER, 0x00, MmioEna= ble, RegisterStride);=0D +=0D + //=0D + // Put Modem Control Register(MCR) into its reset state of 0x00.=0D + //=0D + SerialPortWriteRegister (SerialRegisterBase, R_UART_MCR, 0x00, MmioEna= ble, RegisterStride);=0D +=0D + return RETURN_SUCCESS;=0D + }=0D +=0D GuidHob =3D GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);=0D while (GuidHob !=3D NULL) {=0D SerialPortInfo =3D (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *)GET_GUID_= HOB_DATA (GuidHob);=0D diff --git a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintEr= rorLevelLibHob.c b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugP= rintErrorLevelLibHob.c index 10bdbe2bbc1f..e9cce86bb853 100644 --- a/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLeve= lLibHob.c +++ b/UefiPayloadPkg/Library/DebugPrintErrorLevelLibHob/DebugPrintErrorLeve= lLibHob.c @@ -13,6 +13,7 @@ #include =0D #include =0D #include =0D +#include =0D #include =0D #include =0D =0D @@ -35,6 +36,10 @@ GetDebugPrintErrorLevel ( UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;=0D UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL *DebugPrintErrorLevel;=0D =0D + if (GetHobList () =3D=3D NULL) {=0D + return PcdGet32 (PcdDebugPrintErrorLevel);=0D + }=0D +=0D if (!gDebugPrintErrorLevelInitialized) {=0D gDebugPrintErrorLevelInitialized =3D TRUE;=0D gDebugPrintErrorLevel =3D PcdGet32 (PcdDebugPrintErrorLevel= );=0D diff --git a/UefiPayloadPkg/Library/PayloadEntryHobLib/Hob.c b/UefiPayloadP= kg/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=0D )=0D {=0D - ASSERT (mHobList !=3D NULL);=0D return mHobList;=0D }=0D =0D @@ -109,6 +108,7 @@ CreateHob ( VOID *Hob;=0D =0D HandOffHob =3D GetHobList ();=0D + ASSERT (HandOffHob !=3D NULL);=0D =0D //=0D // Check Length to avoid data overflow.=0D @@ -175,6 +175,7 @@ BuildResourceDescriptorHob ( Hob->ResourceAttribute =3D ResourceAttribute;=0D Hob->PhysicalStart =3D PhysicalStart;=0D Hob->ResourceLength =3D NumberOfBytes;=0D + ZeroMem (&(Hob->Owner), sizeof (EFI_GUID));=0D }=0D =0D /**=0D @@ -239,6 +240,7 @@ GetFirstHob ( VOID *HobList;=0D =0D HobList =3D GetHobList ();=0D + ASSERT (HobList !=3D NULL);=0D return GetNextHob (Type, HobList);=0D }=0D =0D @@ -305,6 +307,7 @@ GetFirstGuidHob ( VOID *HobList;=0D =0D HobList =3D GetHobList ();=0D + ASSERT (HobList !=3D NULL);=0D return GetNextGuidHob (Guid, HobList);=0D }=0D =0D @@ -651,6 +654,7 @@ UpdateStackHob ( EFI_PEI_HOB_POINTERS Hob;=0D =0D Hob.Raw =3D GetHobList ();=0D + ASSERT (Hob.Raw !=3D NULL);=0D while ((Hob.Raw =3D GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)= ) !=3D NULL) {=0D if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationS= tack->AllocDescriptor.Name))) {=0D //=0D @@ -709,6 +713,7 @@ BuildMemoryAllocationHob ( }=0D =0D ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));=0D +=0D Hob->AllocDescriptor.MemoryBaseAddress =3D BaseAddress;=0D Hob->AllocDescriptor.MemoryLength =3D Length;=0D Hob->AllocDescriptor.MemoryType =3D MemoryType;=0D diff --git a/UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.c b/Uef= iPayloadPkg/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;=0D UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;=0D =0D + if (GetHobList () =3D=3D NULL) {=0D + return RETURN_SUCCESS;=0D + }=0D +=0D GuidHob =3D GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);=0D if (GuidHob =3D=3D NULL) {=0D return EFI_NOT_FOUND;=0D diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibH= ob.inf b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.i= nf index ac857d3eea7c..76e431c2f102 100644 --- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf @@ -18,6 +18,7 @@ [Packages]=0D MdePkg/MdePkg.dec=0D MdeModulePkg/MdeModulePkg.dec=0D + UefiPayloadPkg/UefiPayloadPkg.dec=0D =0D [LibraryClasses]=0D PcdLib=0D @@ -34,6 +35,15 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSU= MES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable ## SOMET= IMES_CONSUMES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase ## CONSU= MES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSU= MES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo ## CONSU= MES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSU= MES=0D + gUefiPayloadPkgTokenSpaceGuid.PcdHandOffFdtEnable=0D +=0D +=0D =0D [Guids]=0D gUniversalPayloadSerialPortInfoGuid=0D diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortL= ibHob.inf b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLi= bHob.inf index 7bb3a6ae96dd..552ae6c4f786 100644 --- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.i= nf +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.i= nf @@ -6,7 +6,6 @@ # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D ##=0D -=0D [Defines]=0D INF_VERSION =3D 0x00010005=0D BASE_NAME =3D DxeBaseSerialPortLibHob=0D @@ -15,27 +14,33 @@ VERSION_STRING =3D 1.0=0D LIBRARY_CLASS =3D SerialPortLib|DXE_CORE DXE_DRIVER DXE= _RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER=0D CONSTRUCTOR =3D DxeBaseSerialPortLibHobConstructor=0D -=0D [Packages]=0D MdePkg/MdePkg.dec=0D MdeModulePkg/MdeModulePkg.dec=0D + UefiPayloadPkg/UefiPayloadPkg.dec=0D =0D [LibraryClasses]=0D PcdLib=0D IoLib=0D HobLib=0D TimerLib=0D -=0D + PlatformHookLib=0D [Sources]=0D DxeBaseSerialPortLibHob.c=0D BaseSerialPortLibHob.c=0D -=0D [Pcd]=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize=0D gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSU= MES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable ## SOMET= IMES_CONSUMES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase ## CONSU= MES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSU= MES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo ## CONSU= MES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSU= MES=0D + gUefiPayloadPkgTokenSpaceGuid.PcdHandOffFdtEnable=0D =0D [Guids]=0D gUniversalPayloadSerialPortInfoGuid=0D diff --git a/UefiPayloadPkg/Library/PayloadEntryHobLib/HobLib.inf b/UefiPay= loadPkg/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]=0D gEfiHobMemoryAllocModuleGuid=0D gEfiHobMemoryAllocStackGuid=0D + gUniversalPayloadDeviceTreeGuid=0D =0D --=20 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-