From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by mx.groups.io with SMTP id smtpd.web09.2155.1662485227737167961 for ; Tue, 06 Sep 2022 10:27:08 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NFrYCEm7; spf=pass (domain: gmail.com, ip: 209.85.219.52, mailfrom: benjamin.doron00@gmail.com) Received: by mail-qv1-f52.google.com with SMTP id j1so8825353qvv.8 for ; Tue, 06 Sep 2022 10:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=jsbujtUkkv+ErXJBUMaJO+H+5G2qRhZnFN8CXnvToIw=; b=NFrYCEm7XYo2Xfm5h5qE7NdDISZTdExqdWRxQLSNLjKF/yeQibtRJXzdjJjzmHWNDX xHvirzNtCMiFp9M3ByQiYORE0P0cdaDOfK6d6R/BufJKfM147qGPsxau2Z9k6/xqA/yP 2FBleEnkmJk/vQAl7+HTHCL0b7+tlcNurLq5s535rBtBfhKPlRvCx5Z7/ZymewFIVqzy qkebkbPCRX8qxrcpLuaAcvHzdB1ZahibMhIrQLJlhMWUhnIJFllJ7bM5zZV0K/m4Fqg+ Miz7lDIYj/qp/6DTzknjLtV506XbeFErAsPej+VjTdYrs4tkeYwBXVBXDIil4GCLJfgy tRFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=jsbujtUkkv+ErXJBUMaJO+H+5G2qRhZnFN8CXnvToIw=; b=mPfnWNFT43FwAoW85qC9yLqf0IiFOOoDvPG2p+Ei+qBmG128ZoPzbSUL3YwXVGRokI Y0+k2qV53x9N/1Kpoc8OUhIDNcukZFjD5o+XsONQOS3eawUTwsIvnhDb9vM8VXXnqe26 WMJoxsNwuWisWOQ/Z+y6YJi3lZIECXk6FztGQ2UJYKgbsOQetXmN1h6OoB/y3RPONbJD 0y4lts4E6s2G/e0UK5f4bVusOlAl5I1xvEthcXC3QTPYYASaFBsQTRaq1ZYd/AEXHury wi3B09R1TqQd1oY+kjiy3TQ3A/3ECorQk1KcOwacQ9avgDiIGQNhjxmJzedJf6AfgFE5 k5iQ== X-Gm-Message-State: ACgBeo0ywJh7fM4FLN9PX0Hz28bhv7J4YLyVTKNVkKTE6i4BuG7MtSwh Qg4oUFnIiizyrqVCJOUWbSkpoDDi6fzDEA== X-Google-Smtp-Source: AA6agR55MtKvuRHQQ/ajYaFdY35NGq9+++db2Rr7GR0MW5/AhnTnumhABp8/bSgvrCZaavSQPz+izQ== X-Received: by 2002:ad4:5b87:0:b0:476:c32f:f4e9 with SMTP id 7-20020ad45b87000000b00476c32ff4e9mr45802825qvp.50.1662485226518; Tue, 06 Sep 2022 10:27:06 -0700 (PDT) Return-Path: Received: from aturtleortwo-benjamindomain.. ([2607:f2c0:e98c:e:46bc:db07:bbf3:df6d]) by smtp.gmail.com with ESMTPSA id j2-20020a05620a410200b006b9ab3364ffsm12169038qko.11.2022.09.06.10.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 10:27:05 -0700 (PDT) From: "Benjamin Doron" To: devel@edk2.groups.io Cc: Sai Chaganty , Isaac Oram , Nate DeSimone , Ankit Sinha , Chasel Chiu Subject: [edk2-devel][edk2-platforms][PATCH v1 2/3] [WIP] KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Commit local Date: Tue, 6 Sep 2022 13:26:53 -0400 Message-Id: <667ed46bd371079c17fef615fb46d1fa933f7e0c.1662484082.git.benjamin.doron00@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable While the key patches here should probably be merged into the initial patches for this library, it appears it isn't being merged soon. Therefore, commit the patches that improve the library for S3 use. Other than edits to INF LibraryClasses and header `#include`s, the primary patch here assists runtime by creating events to toggle a boolean such that gBS is not used after end-of-BS. This is necessary for DebugLibSerialPort, but not RSC, which uninstalls the serial port handler at end-of-BS. For S3 resume, a key finding was that this is still insufficient. The image is copied into the lockbox for its own security at DxeSmmReadyToLock, so toggling booleans in the data section is ineffective. Early DXE is fairly single-threaded and testing indicates that simply consuming ..TplNull.c is workable. Also, GCC 12 requires a patch to a `switch` block that improved flow coherency. Cc: Sai Chaganty Cc: Isaac Oram Cc: Nate DeSimone Cc: Ankit Sinha Cc: Chasel Chiu Signed-off-by: Benjamin Doron --- ...ptExecutorDxeI2cHdmiDebugSerialPortLib.inf | 48 ++++++++++ .../DxeI2cHdmiDebugSerialPortLib.inf | 8 +- .../DxeSmmI2cHdmiDebugSerialPortLib.c | 2 - .../Library/I2cHdmiDebugSerialPortLib/Gmbus.c | 39 ++++---- .../I2cDebugPortProtocol.c | 2 - .../I2cDebugPortTplDxe.c | 9 ++ .../I2cDebugPortTplRuntimeDxe.c | 93 +++++++++++++++++++ .../I2cHdmiDebugSerialPortLib.c | 3 - .../I2cHdmiDebugSerialPortLib/IgfxI2c.c | 9 +- .../PeiI2cHdmiDebugSerialPortLib.c | 1 - .../PeiI2cHdmiDebugSerialPortLib.inf | 5 +- .../RuntimeDxeI2cHdmiDebugSerialPortLib.inf | 51 ++++++++++ .../SecI2cHdmiDebugSerialPortLib.c | 1 - .../SecI2cHdmiDebugSerialPortLib.inf | 7 +- .../SmmI2cHdmiDebugSerialPortLib.inf | 6 +- 15 files changed, 231 insertions(+), 53 deletions(-) create mode 100644 Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebu= gSerialPortLib/BootScriptExecutorDxeI2cHdmiDebugSerialPortLib.inf create mode 100644 Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebu= gSerialPortLib/I2cDebugPortTplRuntimeDxe.c create mode 100644 Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebu= gSerialPortLib/RuntimeDxeI2cHdmiDebugSerialPortLib.inf diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/BootScriptExecutorDxeI2cHdmiDebugSerialPortLib.inf b/Platform/Intel= /KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/BootScriptExecutorD= xeI2cHdmiDebugSerialPortLib.inf new file mode 100644 index 000000000000..995e67bde7d4 --- /dev/null +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /BootScriptExecutorDxeI2cHdmiDebugSerialPortLib.inf @@ -0,0 +1,48 @@ +### @file=0D +# Component description file for Serial I/O Port library for the HDMI I2C = Debug Port=0D +#=0D +# Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D RuntimeDxeI2cHdmiDebugSerialPortLib=0D + FILE_GUID =3D 7E514680-470B-409C-8FC4-2FE62BF010BC= =0D + VERSION_STRING =3D 1.0=0D + MODULE_TYPE =3D DXE_DRIVER=0D + LIBRARY_CLASS =3D SerialPortLib|DXE_CORE DXE_DRIVER DXE= _RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[LibraryClasses]=0D + BaseMemoryLib=0D + PcdLib=0D + TimerLib=0D + IoLib=0D + PciLib=0D + UefiLib=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + KabylakeOpenBoardPkg/OpenBoardPkg.dec=0D +=0D +[Sources]=0D + DxeSmmI2cHdmiDebugSerialPortLib.c=0D + Gmbus.c=0D + Gmbus.h=0D + I2cDebugPortProtocol.c=0D + I2cDebugPortProtocol.h=0D + I2cDebugPortTplNull.c=0D + I2cHdmiDebugSerialPortLib.c=0D + IgfxI2c.c=0D + IgfxI2c.h=0D +=0D +[Pcd]=0D + gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel = ## CONSUMES=0D + gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress = ## CONSUMES=0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/DxeI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoard= Pkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf index 5403d8ae0fd7..5eeee504c7ec 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /DxeI2cHdmiDebugSerialPortLib.inf +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /DxeI2cHdmiDebugSerialPortLib.inf @@ -21,11 +21,13 @@ #=0D =0D [LibraryClasses]=0D - BaseLib=0D BaseMemoryLib=0D PcdLib=0D TimerLib=0D + IoLib=0D PciLib=0D + UefiBootServicesTableLib=0D + UefiLib=0D =0D [Packages]=0D MdePkg/MdePkg.dec=0D @@ -42,10 +44,6 @@ IgfxI2c.c=0D IgfxI2c.h=0D =0D -[Ppis]=0D -=0D -[Guids]=0D -=0D [Pcd]=0D gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel = ## CONSUMES=0D gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress = ## CONSUMES=0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/DxeSmmI2cHdmiDebugSerialPortLib.c b/Platform/Intel/KabylakeOpenBoar= dPkg/Library/I2cHdmiDebugSerialPortLib/DxeSmmI2cHdmiDebugSerialPortLib.c index 5556e09a7419..46827c6cefae 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /DxeSmmI2cHdmiDebugSerialPortLib.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /DxeSmmI2cHdmiDebugSerialPortLib.c @@ -8,10 +8,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/=0D =0D #include =0D -#include =0D #include =0D #include =0D -#include =0D =0D #include =0D #include =0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/Gmbus.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugS= erialPortLib/Gmbus.c index c04bcd285060..df5dfd70a5f2 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /Gmbus.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /Gmbus.c @@ -7,8 +7,7 @@ **/=0D =0D #include =0D -#include =0D -#include =0D +//#include =0D #include =0D #include =0D #include =0D @@ -33,6 +32,7 @@ GmbusGetGttMmAdr ( // Check if GTT Memory Mapped BAR has been already assigned, initialize = if not=0D //=0D GttMmPciAddress =3D PCI_LIB_ADDRESS (SA_IGD_BUS, SA_IGD_DEV, SA_IGD_FUN_= 0, R_SA_IGD_GTTMMADR);=0D + // TODO(benjamindoron): TigerLake has 64-bit BAR=0D GttMmAdr =3D PciRead32 (GttMmPciAddress) & 0xFFFFFFF0;=0D //DEBUG ((DEBUG_INFO, "GttMmPciAddress =3D %x\n", (UINTN) GttMmPciAddres= s)); //@TODO=0D //DEBUG ((DEBUG_INFO, "GttMmAdr =3D %x\n", (UINTN) GttMmAdr)); //@TODO=0D @@ -361,6 +361,7 @@ GmbusPrepare ( }=0D //=0D // Wait for GMBUS to complete any pending commands=0D + // - TODO(benjamindoron): GmbusRecoverError()=0D //=0D Status =3D GmbusWaitForReady (B_SA_GTTMMADR_GMBUS2_INUSE, FALSE);=0D if (EFI_ERROR (Status)) {=0D @@ -488,28 +489,28 @@ GmbusRead ( // Input Validation=0D //=0D if ((*ByteCount) <=3D 0) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - ByteCount is 0, no bytes to read.\n= ", __FUNCTION__));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - ByteCount is 0, no bytes to read.= \n", __FUNCTION__));=0D return EFI_INVALID_PARAMETER;=0D }=0D if ((*ByteCount) > GMBUS_MAX_BYTES) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - ByteCount is greater than GMBUS_MAX= _BYTES[%d].\n", __FUNCTION__, GMBUS_MAX_BYTES));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - ByteCount is greater than GMBUS_M= AX_BYTES[%d].\n", __FUNCTION__, GMBUS_MAX_BYTES));=0D return EFI_INVALID_PARAMETER;=0D }=0D if (ReadBuffer =3D=3D NULL) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - ReadBuffer is NULL.\n", __FUNCTION_= _));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - ReadBuffer is NULL.\n", __FUNCTIO= N__));=0D return EFI_INVALID_PARAMETER;=0D }=0D if ((SlaveAddress & BIT0) !=3D BIT0) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - BIT0 of SlaveAddress should be set = for an I2C read.\n", __FUNCTION__));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - BIT0 of SlaveAddress should be se= t for an I2C read.\n", __FUNCTION__));=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D //=0D // Configure Gmbus port and clock speed=0D - //=0D + //GMBUS_CLOCK_RATE_100K @todo=0D Status =3D GmbusPrepare (GMBUS_CLOCK_RATE_50K, (DdcBusPinPair & B_SA_GTT= MMADR_GMBUS0_PIN_PAIR_MASK));=0D if (EFI_ERROR (Status)) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - GmbusPrepare() failed - %r\n", __FU= NCTION__, Status));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - GmbusPrepare() failed - %r\n", __= FUNCTION__, Status));=0D goto Done;=0D }=0D =0D @@ -534,7 +535,7 @@ GmbusRead ( //=0D Status =3D SetGmbus1Command (GmbusCmdSts);=0D if (EFI_ERROR (Status)) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - SetGmbus1Command() failed - %r\n", = __FUNCTION__, Status));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - SetGmbus1Command() failed - %r\n"= , __FUNCTION__, Status));=0D goto Done;=0D }=0D =0D @@ -556,7 +557,7 @@ GmbusRead ( //=0D Status =3D GmbusWaitForReady (B_SA_GTTMMADR_GMBUS2_HW_RDY, TRUE);=0D if (EFI_ERROR (Status)) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - GmbusWaitForReady() failed - %r\n= ", __FUNCTION__, Status));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - GmbusWaitForReady() failed - %r= \n", __FUNCTION__, Status));=0D }=0D //=0D // Check the GMBUS2 register for error conditions (NACK or Slave Stall= Timeout)=0D @@ -564,13 +565,13 @@ GmbusRead ( Status2 =3D GetGmbus2Status (&GmbusStatus);=0D if (EFI_ERROR (Status2)) {=0D Status =3D Status2;=0D - DEBUG ((DEBUG_INFO, "Error: %a() - GetGmbus2Status() failed - %r\n",= __FUNCTION__, Status));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - GetGmbus2Status() failed - %r\n= ", __FUNCTION__, Status));=0D goto Done;=0D }=0D if (EFI_ERROR (Status) && ((GmbusStatus & B_SA_GTTMMADR_GMBUS2_NACK_IN= DICATOR) =3D=3D 0)) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - Unexpected behavior detected!\n",= __FUNCTION__));=0D - DEBUG ((DEBUG_INFO, "The GMBUS controller did not encounter a NACK a= nd it did not set the HW_RDY bit.\n"));=0D - DEBUG ((DEBUG_INFO, "Status =3D %r\n", Status));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - Unexpected behavior detected!\n= ", __FUNCTION__));=0D + //DEBUG ((DEBUG_INFO, "The GMBUS controller did not encounter a NACK= and it did not set the HW_RDY bit.\n"));=0D + //DEBUG ((DEBUG_INFO, "Status =3D %r\n", Status));=0D Status =3D EFI_DEVICE_ERROR;=0D goto Done;=0D }=0D @@ -580,10 +581,10 @@ GmbusRead ( // If a NACK or Slave Stall Timeout occurs, then a bus error has occ= urred.=0D // In the event of a bus error, one must reset the GMBUS controller = to resume normal operation.=0D //=0D - DEBUG ((DEBUG_INFO, "Error: %a() - NACK occurred during read operati= on.\n", __FUNCTION__));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - NACK occurred during read opera= tion.\n", __FUNCTION__));=0D Status =3D GmbusRecoverError ();=0D if (EFI_ERROR (Status)) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - GmbusRecoverError() failed - %r= \n", __FUNCTION__, Status));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - GmbusRecoverError() failed - = %r\n", __FUNCTION__, Status));=0D goto Done;=0D }=0D Status =3D EFI_DEVICE_ERROR;=0D @@ -594,7 +595,7 @@ GmbusRead ( //=0D Status =3D GetGmbus3Data (&GmbusData);=0D if (EFI_ERROR (Status)) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - GetGmbus3Data() failed - %r\n", _= _FUNCTION__, Status));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - GetGmbus3Data() failed - %r\n",= __FUNCTION__, Status));=0D goto Done;=0D }=0D for (Index =3D 0; (Index < sizeof (UINT32)) && (BytesRead < (*ByteCoun= t)); Index++) {=0D @@ -608,7 +609,7 @@ GmbusRead ( //=0D Status =3D GmbusWaitForReady (B_SA_GTTMMADR_GMBUS2_BUS_ACTIVE, FALSE);=0D if (EFI_ERROR (Status)) {=0D - DEBUG ((DEBUG_INFO, "Error: %a() - GmbusWaitForReady() failed - %r\n",= __FUNCTION__, Status));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - GmbusWaitForReady() failed - %r\n= ", __FUNCTION__, Status));=0D return Status;=0D }=0D =0D @@ -616,7 +617,7 @@ Done: Status2 =3D GmbusRelease ();=0D if (EFI_ERROR (Status2)) {=0D Status =3D Status2;=0D - DEBUG ((DEBUG_INFO, "Error: %a() - GmbusRelease() failed - %r\n", __FU= NCTION__, Status));=0D + //DEBUG ((DEBUG_INFO, "Error: %a() - GmbusRelease() failed - %r\n", __= FUNCTION__, Status));=0D }=0D GmbusResetBusMaster ();=0D =0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/I2cDebugPortProtocol.c b/Platform/Intel/KabylakeOpenBoardPkg/Librar= y/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c index 1a31c98347db..51eeadd75af9 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /I2cDebugPortProtocol.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /I2cDebugPortProtocol.c @@ -7,9 +7,7 @@ **/=0D =0D #include =0D -#include =0D #include =0D -#include =0D #include =0D =0D #include =0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/I2cDebugPortTplDxe.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/= I2cHdmiDebugSerialPortLib/I2cDebugPortTplDxe.c index 9d69c0365795..d92b8d262793 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /I2cDebugPortTplDxe.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /I2cDebugPortTplDxe.c @@ -22,6 +22,11 @@ RaiseTplForI2cDebugPortAccess ( VOID=0D )=0D {=0D + // DebugLibSerialPort exposes potential DEBUG bugs, such as early assert= ions=0D + if (gBS =3D=3D NULL) {=0D + return;=0D + }=0D +=0D if (EfiGetCurrentTpl () < TPL_NOTIFY) {=0D mPreviousTpl =3D gBS->RaiseTPL (TPL_NOTIFY);=0D }=0D @@ -37,6 +42,10 @@ RestoreTplAfterI2cDebugPortAccess ( VOID=0D )=0D {=0D + if (gBS =3D=3D NULL) {=0D + return;=0D + }=0D +=0D if (mPreviousTpl > 0) {=0D gBS->RestoreTPL (mPreviousTpl);=0D mPreviousTpl =3D 0;=0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/I2cDebugPortTplRuntimeDxe.c b/Platform/Intel/KabylakeOpenBoardPkg/L= ibrary/I2cHdmiDebugSerialPortLib/I2cDebugPortTplRuntimeDxe.c new file mode 100644 index 000000000000..7aa95157d734 --- /dev/null +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /I2cDebugPortTplRuntimeDxe.c @@ -0,0 +1,93 @@ +/** @file=0D + Serial I/O Port library implementation for the HDMI I2C Debug Port=0D + DXE Library implementation=0D +=0D +Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +=0D +STATIC EFI_TPL mPreviousTpl =3D 0;=0D +STATIC EFI_EVENT mEvent =3D NULL;=0D +STATIC UINT8 mEndOfBootServices =3D 0;=0D +=0D +/**=0D + Exit Boot Services Event notification handler.=0D +=0D + @param[in] Event Event whose notification function is being invoked= =0D + @param[in] Context Pointer to the notification function's context=0D +=0D +**/=0D +VOID=0D +EFIAPI=0D +OnExitBootServices (=0D + IN EFI_EVENT Event,=0D + IN VOID *Context=0D + )=0D +{=0D + mEndOfBootServices =3D 1;=0D +=0D + gBS->CloseEvent (Event);=0D +}=0D +=0D +/**=0D + For boot phases that utilize task priority levels (TPLs), this function = raises=0D + the TPL to the appriopriate level needed to execute I/O to the I2C Debug= Port=0D +**/=0D +VOID=0D +RaiseTplForI2cDebugPortAccess (=0D + VOID=0D + )=0D +{=0D + // DebugLibSerialPort exposes potential DEBUG bugs, such as early assert= ions=0D + if (gBS =3D=3D NULL || mEndOfBootServices =3D=3D 1) {=0D + return;=0D + }=0D +=0D + // An event is required for a boolean to bypass TPL modification after=0D + // exit-BS. RSC obviates this, requiring it for runtime DebugLibSerialPo= rt.=0D + // - Consider creating a TplRuntimeDxe, although UefiRuntimeLib uses gST= ?=0D + // - BootScriptExecutorDxe is a special-case, where booleans are ineffec= tive=0D + //=0D + // A constructor would cycle, SerialPortInitialize() takes no arguments,= =0D + // and no BootServicesTableLib can be called by AutoGen early enough.=0D + // Therefore, we generate the event here.=0D + if (mEvent =3D=3D NULL) {=0D + gBS->CreateEventEx (=0D + EVT_NOTIFY_SIGNAL,=0D + TPL_NOTIFY,=0D + OnExitBootServices,=0D + NULL,=0D + &gEfiEventExitBootServicesGuid,=0D + &mEvent=0D + );=0D + }=0D +=0D + if (EfiGetCurrentTpl () < TPL_NOTIFY) {=0D + mPreviousTpl =3D gBS->RaiseTPL (TPL_NOTIFY);=0D + }=0D +}=0D +=0D +/**=0D + For boot phases that utilize task priority levels (TPLs), this function= =0D + restores the TPL to the previous level after I/O to the I2C Debug Port i= s=0D + complete=0D +**/=0D +VOID=0D +RestoreTplAfterI2cDebugPortAccess (=0D + VOID=0D + )=0D +{=0D + if (gBS =3D=3D NULL || mEndOfBootServices =3D=3D 1) {=0D + return;=0D + }=0D +=0D + if (mPreviousTpl > 0) {=0D + gBS->RestoreTPL (mPreviousTpl);=0D + mPreviousTpl =3D 0;=0D + }=0D +}=0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/I2cHdmiDebugSerialPortLib.c b/Platform/Intel/KabylakeOpenBoardPkg/L= ibrary/I2cHdmiDebugSerialPortLib/I2cHdmiDebugSerialPortLib.c index 89a01b868da3..402b5a3033a9 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /I2cHdmiDebugSerialPortLib.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /I2cHdmiDebugSerialPortLib.c @@ -7,10 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/=0D =0D #include =0D -#include =0D #include =0D -#include =0D -#include =0D =0D #include =0D #include =0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/IgfxI2c.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebu= gSerialPortLib/IgfxI2c.c index b1273c7a5d10..886351ad4297 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /IgfxI2c.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /IgfxI2c.c @@ -7,8 +7,6 @@ **/=0D =0D #include =0D -#include =0D -#include =0D #include =0D #include =0D =0D @@ -84,7 +82,6 @@ GetGmbusBusPinPair ( default:=0D return EFI_INVALID_PARAMETER;=0D }=0D - break;=0D // The PCH design lineage from newer CoffeeLake & WhiskeyLake=0D case PchTypeCnlLp:=0D case PchTypeCnlH:=0D @@ -105,8 +102,8 @@ GetGmbusBusPinPair ( default:=0D return EFI_INVALID_PARAMETER;=0D }=0D - break;=0D - }=0D =0D - return EFI_UNSUPPORTED;=0D + default:=0D + return EFI_UNSUPPORTED;=0D + }=0D }=0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/PeiI2cHdmiDebugSerialPortLib.c b/Platform/Intel/KabylakeOpenBoardPk= g/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.c index c99821367354..05b2d31bbfc2 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /PeiI2cHdmiDebugSerialPortLib.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /PeiI2cHdmiDebugSerialPortLib.c @@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D =0D -#include =0D #include =0D #include =0D #include =0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/PeiI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoard= Pkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf index 62b3cd3e1e49..64d8f682b786 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /PeiI2cHdmiDebugSerialPortLib.inf +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /PeiI2cHdmiDebugSerialPortLib.inf @@ -21,10 +21,11 @@ #=0D =0D [LibraryClasses]=0D - BaseLib=0D BaseMemoryLib=0D PcdLib=0D + HobLib=0D TimerLib=0D + IoLib=0D PciLib=0D =0D [Packages]=0D @@ -42,8 +43,6 @@ IgfxI2c.c=0D IgfxI2c.h=0D =0D -[Ppis]=0D -=0D [Guids]=0D gI2cHdmiDebugHobGuid=0D =0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/RuntimeDxeI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOp= enBoardPkg/Library/I2cHdmiDebugSerialPortLib/RuntimeDxeI2cHdmiDebugSerialPo= rtLib.inf new file mode 100644 index 000000000000..eefe85f2814c --- /dev/null +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /RuntimeDxeI2cHdmiDebugSerialPortLib.inf @@ -0,0 +1,51 @@ +### @file=0D +# Component description file for Serial I/O Port library for the HDMI I2C = Debug Port=0D +#=0D +# Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D RuntimeDxeI2cHdmiDebugSerialPortLib=0D + FILE_GUID =3D 08891D97-994C-48E9-9983-E99D622D32C8= =0D + VERSION_STRING =3D 1.0=0D + MODULE_TYPE =3D DXE_DRIVER=0D + LIBRARY_CLASS =3D SerialPortLib|DXE_CORE DXE_DRIVER DXE= _RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[LibraryClasses]=0D + BaseMemoryLib=0D + PcdLib=0D + TimerLib=0D + IoLib=0D + PciLib=0D + UefiLib=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + KabylakeOpenBoardPkg/OpenBoardPkg.dec=0D +=0D +[Sources]=0D + DxeSmmI2cHdmiDebugSerialPortLib.c=0D + Gmbus.c=0D + Gmbus.h=0D + I2cDebugPortProtocol.c=0D + I2cDebugPortProtocol.h=0D + I2cDebugPortTplRuntimeDxe.c=0D + I2cHdmiDebugSerialPortLib.c=0D + IgfxI2c.c=0D + IgfxI2c.h=0D +=0D +[Guids]=0D + gEfiEventExitBootServicesGuid = ## CONSUMES ## Event=0D +=0D +[Pcd]=0D + gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel = ## CONSUMES=0D + gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress = ## CONSUMES=0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/SecI2cHdmiDebugSerialPortLib.c b/Platform/Intel/KabylakeOpenBoardPk= g/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.c index 416114d4363c..e4a65a66d9c1 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /SecI2cHdmiDebugSerialPortLib.c +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /SecI2cHdmiDebugSerialPortLib.c @@ -8,7 +8,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/=0D =0D #include =0D -#include =0D #include =0D #include =0D =0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/SecI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoard= Pkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf index 3ae724926fdd..a9780decd1a7 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /SecI2cHdmiDebugSerialPortLib.inf +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /SecI2cHdmiDebugSerialPortLib.inf @@ -21,10 +21,9 @@ #=0D =0D [LibraryClasses]=0D - BaseLib=0D BaseMemoryLib=0D - PcdLib=0D TimerLib=0D + IoLib=0D PciLib=0D =0D [Packages]=0D @@ -42,10 +41,6 @@ IgfxI2c.h=0D SecI2cHdmiDebugSerialPortLib.c=0D =0D -[Ppis]=0D -=0D -[Guids]=0D -=0D [Pcd]=0D gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel = ## CONSUMES=0D gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress = ## CONSUMES=0D diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerial= PortLib/SmmI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoard= Pkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf index dcbf43b886c1..65f2b4f5f731 100644 --- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /SmmI2cHdmiDebugSerialPortLib.inf +++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib= /SmmI2cHdmiDebugSerialPortLib.inf @@ -21,10 +21,10 @@ #=0D =0D [LibraryClasses]=0D - BaseLib=0D BaseMemoryLib=0D PcdLib=0D TimerLib=0D + IoLib=0D PciLib=0D =0D [Packages]=0D @@ -42,10 +42,6 @@ IgfxI2c.c=0D IgfxI2c.h=0D =0D -[Ppis]=0D -=0D -[Guids]=0D -=0D [Pcd]=0D gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel = ## CONSUMES=0D gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress = ## CONSUMES=0D --=20 2.37.2