[edk2-devel] [edk2-platforms] [PATCH V1 2/5] KabylakeOpenBoardPkg: Add HdmiDebugGpioInitLib

Nate DeSimone nathaniel.l.desimone at intel.com
Sat Jun 18 04:05:47 UTC 2022


This library initializes any GPIOs nessesary for
the HDMI DDC bus to operate. This can be called
very early (SEC phase) to enable closed chassis
debug through the HDMI DDC I2C bus.

Cc: Chasel Chiu <chasel.chiu at intel.com>
Cc: Sai Chaganty <rangasai.v.chaganty at intel.com>
Cc: Isaac Oram <isaac.w.oram at intel.com>
Cc: Benjamin Doron <benjamin.doron00 at gmail.com>
Cc: Michael Kubacki <michael.kubacki at microsoft.com>
Cc: Jeremy Soller <jeremy at system76.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone at intel.com>
---
 .../AspireVn7Dash572G/OpenBoardPkg.dsc        |   3 +-
 .../GalagoPro3/OpenBoardPkg.dsc               |   3 +-
 .../Include/Library/HdmiDebugGpioInitLib.h    |  26 +++
 .../KabylakeRvp3/OpenBoardPkg.dsc             |   3 +-
 .../HdmiDebugGpioInitLib.c                    | 221 ++++++++++++++++++
 .../HdmiDebugGpioInitLib.inf                  |  42 ++++
 6 files changed, 295 insertions(+), 3 deletions(-)
 create mode 100644 Platform/Intel/KabylakeOpenBoardPkg/Include/Library/HdmiDebugGpioInitLib.h
 create mode 100644 Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.c
 create mode 100644 Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.inf

diff --git a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/OpenBoardPkg.dsc b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/OpenBoardPkg.dsc
index 29aa8d9111..ec5591e00f 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/OpenBoardPkg.dsc
+++ b/Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/OpenBoardPkg.dsc
@@ -1,7 +1,7 @@
 ## @file
 #  The main build description file for the Aspire VN7-572G board.
 #
-# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.<BR>
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -184,6 +184,7 @@
   GpioExpanderLib|$(PLATFORM_BOARD_PACKAGE)/Library/BaseGpioExpanderLib/BaseGpioExpanderLib.inf
   I2cAccessLib|$(PLATFORM_BOARD_PACKAGE)/Library/PeiI2cAccessLib/PeiI2cAccessLib.inf
   PlatformSecLib|$(PLATFORM_PACKAGE)/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf
+  HdmiDebugGpioInitLib|$(PLATFORM_BOARD_PACKAGE)/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.inf
 
   # Thunderbolt
 !if gKabylakeOpenBoardPkgTokenSpaceGuid.PcdTbtEnable == TRUE
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/GalagoPro3/OpenBoardPkg.dsc b/Platform/Intel/KabylakeOpenBoardPkg/GalagoPro3/OpenBoardPkg.dsc
index 93cf93942b..1df3cf13a3 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/GalagoPro3/OpenBoardPkg.dsc
+++ b/Platform/Intel/KabylakeOpenBoardPkg/GalagoPro3/OpenBoardPkg.dsc
@@ -1,7 +1,7 @@
 ## @file
 #  The main build description file for the GalagoPro3 board.
 #
-# Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -128,6 +128,7 @@
   GpioExpanderLib|$(PLATFORM_BOARD_PACKAGE)/Library/BaseGpioExpanderLib/BaseGpioExpanderLib.inf
   I2cAccessLib|$(PLATFORM_BOARD_PACKAGE)/Library/PeiI2cAccessLib/PeiI2cAccessLib.inf
   PlatformSecLib|$(PLATFORM_PACKAGE)/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf
+  HdmiDebugGpioInitLib|$(PLATFORM_BOARD_PACKAGE)/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.inf
 
   # Thunderbolt
 !if gKabylakeOpenBoardPkgTokenSpaceGuid.PcdTbtEnable == TRUE
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/HdmiDebugGpioInitLib.h b/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/HdmiDebugGpioInitLib.h
new file mode 100644
index 0000000000..33bdeb74fc
--- /dev/null
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Include/Library/HdmiDebugGpioInitLib.h
@@ -0,0 +1,26 @@
+/** @file
+  GPIO initialization for the HDMI I2C Debug Port
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef HDMI_DEBUG_GPIO_INIT_LIB_H_
+#define HDMI_DEBUG_GPIO_INIT_LIB_H_
+
+#include <Uefi.h>
+
+/**
+  Configures GPIOs to enable usage of the HDMI DDC I2C Bus
+
+  @retval EFI_SUCCESS        The function completed successfully
+  @retval EFI_UNSUPPORTED    The platform is using a PCH that is not supported yet.
+
+**/
+EFI_STATUS
+HdmiDebugGpioInit (
+  VOID
+  );
+
+#endif
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc
index a46d36b056..1f2950be72 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc
+++ b/Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc
@@ -1,7 +1,7 @@
 ## @file
 #  The main build description file for the KabylakeRvp3 board.
 #
-# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.<BR>
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -171,6 +171,7 @@
   GpioExpanderLib|$(PLATFORM_BOARD_PACKAGE)/Library/BaseGpioExpanderLib/BaseGpioExpanderLib.inf
   I2cAccessLib|$(PLATFORM_BOARD_PACKAGE)/Library/PeiI2cAccessLib/PeiI2cAccessLib.inf
   PlatformSecLib|$(PLATFORM_PACKAGE)/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf
+  HdmiDebugGpioInitLib|$(PLATFORM_BOARD_PACKAGE)/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.inf
 
   # Thunderbolt
 !if gKabylakeOpenBoardPkgTokenSpaceGuid.PcdTbtEnable == TRUE
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.c
new file mode 100644
index 0000000000..3d9e37f34a
--- /dev/null
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.c
@@ -0,0 +1,221 @@
+/** @file
+  GPIO initialization for the HDMI I2C Debug Port
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/PcdLib.h>
+#include <Library/PciLib.h>
+
+#include <Library/GpioLib.h>
+#include <GpioPinsSklLp.h>
+#include <GpioPinsSklH.h>
+
+//
+// PCH Detection Registers
+//
+#define PCH_PCI_BUS                                       0
+#define PCH_LPC_PCI_DEV                                   31
+#define PCH_LPC_PCI_FUN                                   0
+#define R_PCH_LPC_DID                                     0x02
+
+#define V_SPT_LP_PCH_START_DEVICE_ID                      0x9D40
+#define V_SPT_LP_PCH_END_DEVICE_ID                        0x9D5F
+#define V_SPT_H_PCH_START_DEVICE_ID                       0xA140
+#define V_SPT_H_PCH_END_DEVICE_ID                         0xA15F
+#define V_KBP_H_PCH_START_DEVICE_ID                       0xA2C0
+#define V_KBP_H_PCH_END_DEVICE_ID                         0xA2DF
+
+#define V_KBP_H_PCH_DEVICE_ID_ES                          0xA2C0        ///< This is SKL-PCH-H in KBL-PCH-H package
+#define V_KBP_H_PCH_DEVICE_ID_SVR_ES                      0xA2D0        ///< This is SKL-PCH-H in KBL-PCH-H package
+
+//GPIO Table Terminator
+#define END_OF_GPIO_TABLE 0xFFFFFFFF
+
+typedef enum {
+  PchTypeUnknown = 0,
+  PchTypeSptLp,
+  PchTypeSptH,
+  PchTypeKbpH,
+  PchTypeCnlLp,
+  PchTypeCnlH,
+  PchTypeMax
+} PCH_TYPE;
+
+typedef enum {
+  PchH           = 1,
+  PchLp,
+  PchUnknownSeries
+} PCH_SERIES;
+
+typedef enum {
+  EnumDdcUnknown = 0,
+  EnumDdcA,
+  EnumDdcB,
+  EnumDdcC,
+  EnumDdcD,
+  EnumDdcE,
+  EnumDdcF,
+  EnumI2cChannelMax
+} IGFX_I2C_CHANNEL;
+
+/*** SKL-LP ***/
+
+// HDMI-B DDC GPIO Pins
+GPIO_INIT_CONFIG mDebugGpioTableSklLpDdpB[] =
+{
+  {GPIO_SKL_LP_GPP_E18, {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPB_CTRLCLK
+  {GPIO_SKL_LP_GPP_E19, {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPB_CTRLDATA
+  {END_OF_GPIO_TABLE,   {GpioPadModeGpio,    GpioHostOwnGpio,    GpioDirNone,    GpioOutDefault, GpioIntDis, GpioDswReset,  GpioTermNone}},//Marking End of Table
+};
+UINT16 mDebugGpioTableSklLpDdpBSize = sizeof (mDebugGpioTableSklLpDdpB) / sizeof (GPIO_INIT_CONFIG) - 1;
+
+// HDMI-C DDC GPIO Pins
+GPIO_INIT_CONFIG mDebugGpioTableSklLpDdpC[] =
+{
+  {GPIO_SKL_LP_GPP_E20, {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPC_CTRLCLK
+  {GPIO_SKL_LP_GPP_E21, {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPC_CTRLDATA
+  {END_OF_GPIO_TABLE,   {GpioPadModeGpio,    GpioHostOwnGpio,    GpioDirNone,    GpioOutDefault, GpioIntDis, GpioDswReset,  GpioTermNone}},//Marking End of Table
+};
+UINT16 mDebugGpioTableSklLpDdpCSize = sizeof (mDebugGpioTableSklLpDdpC) / sizeof (GPIO_INIT_CONFIG) - 1;
+
+// HDMI-D DDC GPIO Pins
+GPIO_INIT_CONFIG mDebugGpioTableSklLpDdpD[] =
+{
+  {GPIO_SKL_LP_GPP_E22, {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPD_CTRLCLK
+  {GPIO_SKL_LP_GPP_E23, {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPD_CTRLDATA
+  {END_OF_GPIO_TABLE,   {GpioPadModeGpio,    GpioHostOwnGpio,    GpioDirNone,    GpioOutDefault, GpioIntDis, GpioDswReset,  GpioTermNone}},//Marking End of Table
+};
+UINT16 mDebugGpioTableSklLpDdpDSize = sizeof (mDebugGpioTableSklLpDdpD) / sizeof (GPIO_INIT_CONFIG) - 1;
+
+/*** SKL-H ***/
+
+// HDMI-B DDC GPIO Pins
+GPIO_INIT_CONFIG mDebugGpioTableSklHDdpB[] =
+{
+  {GPIO_SKL_H_GPP_I5,   {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPB_CTRLCLK
+  {GPIO_SKL_H_GPP_I6,   {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPB_CTRLDATA
+  {END_OF_GPIO_TABLE,   {GpioPadModeGpio,    GpioHostOwnGpio,    GpioDirNone,    GpioOutDefault, GpioIntDis, GpioDswReset,  GpioTermNone}},//Marking End of Table
+};
+UINT16 mDebugGpioTableSklHDdpBSize = sizeof (mDebugGpioTableSklHDdpB) / sizeof (GPIO_INIT_CONFIG) - 1;
+
+// HDMI-C DDC GPIO Pins
+GPIO_INIT_CONFIG mDebugGpioTableSklHDdpC[] =
+{
+  {GPIO_SKL_H_GPP_I7,   {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPC_CTRLCLK
+  {GPIO_SKL_H_GPP_I8,   {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPC_CTRLDATA
+  {END_OF_GPIO_TABLE,   {GpioPadModeGpio,    GpioHostOwnGpio,    GpioDirNone,    GpioOutDefault, GpioIntDis, GpioDswReset,  GpioTermNone}},//Marking End of Table
+};
+UINT16 mDebugGpioTableSklHDdpCSize = sizeof (mDebugGpioTableSklHDdpC) / sizeof (GPIO_INIT_CONFIG) - 1;
+
+// HDMI-D DDC GPIO Pins
+GPIO_INIT_CONFIG mDebugGpioTableSklHDdpD[] =
+{
+  {GPIO_SKL_H_GPP_I9,   {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPD_CTRLCLK
+  {GPIO_SKL_H_GPP_I10,  {GpioPadModeNative1, GpioHostOwnDefault, GpioDirNone,    GpioOutDefault, GpioIntDis, GpioHostDeepReset, GpioTermNone}}, //DDPD_CTRLDATA
+  {END_OF_GPIO_TABLE,   {GpioPadModeGpio,    GpioHostOwnGpio,    GpioDirNone,    GpioOutDefault, GpioIntDis, GpioDswReset,  GpioTermNone}},//Marking End of Table
+};
+UINT16 mDebugGpioTableSklHDdpDSize = sizeof (mDebugGpioTableSklHDdpD) / sizeof (GPIO_INIT_CONFIG) - 1;
+
+/**
+  Configures GPIO
+
+  @param[in]  GpioTable       Point to Platform Gpio table
+  @param[in]  GpioTableCount  Number of Gpio table entries
+
+**/
+VOID
+HdmiDebugConfigureGpio (
+  IN GPIO_INIT_CONFIG                 *GpioDefinition,
+  IN UINT16                           GpioTableCount
+  )
+{
+  EFI_STATUS          Status;
+
+  Status = GpioConfigurePads (GpioTableCount, GpioDefinition);
+
+}
+
+
+PCH_TYPE
+HdmiGpioInitGetPchType (
+  VOID
+  )
+{
+  PCH_TYPE  PchType;
+  UINT16    DeviceId;
+
+  PchType   = PchTypeUnknown;
+  DeviceId  = PciRead16 (PCI_LIB_ADDRESS (PCH_PCI_BUS, PCH_LPC_PCI_DEV, PCH_LPC_PCI_FUN, R_PCH_LPC_DID));
+  if ((DeviceId >= V_SPT_LP_PCH_START_DEVICE_ID) && (DeviceId <= V_SPT_LP_PCH_END_DEVICE_ID)) {
+    PchType = PchTypeSptLp;
+  } else if ((DeviceId >= V_SPT_H_PCH_START_DEVICE_ID) && (DeviceId <= V_SPT_H_PCH_END_DEVICE_ID )) {
+    PchType = PchTypeSptH;
+  } else if ((DeviceId >= V_KBP_H_PCH_START_DEVICE_ID) && (DeviceId <= V_KBP_H_PCH_END_DEVICE_ID)) {
+    PchType = PchTypeKbpH;
+    if ((DeviceId == V_KBP_H_PCH_DEVICE_ID_ES) || (DeviceId == V_KBP_H_PCH_DEVICE_ID_SVR_ES)) {
+      PchType = PchTypeSptH;
+    }
+  }
+
+  return PchType;
+}
+
+/**
+  Configures GPIOs to enable usage of the HDMI DDC I2C Bus
+
+  @retval EFI_SUCCESS        The function completed successfully
+  @retval EFI_UNSUPPORTED    The platform is using a PCH that is not supported yet.
+
+**/
+EFI_STATUS
+HdmiDebugGpioInit (
+  VOID
+  )
+{
+  IGFX_I2C_CHANNEL  Channel;
+  PCH_TYPE  PchType;
+
+  PchType = HdmiGpioInitGetPchType ();
+  Channel = (IGFX_I2C_CHANNEL) PcdGet32 (PcdI2cHdmiDebugPortDdcI2cChannel);
+  switch (PchType) {
+    case PchTypeSptLp:
+      switch (Channel) {
+        case EnumDdcB:
+          HdmiDebugConfigureGpio (mDebugGpioTableSklLpDdpB, mDebugGpioTableSklLpDdpBSize);
+          return EFI_SUCCESS;
+        case EnumDdcC:
+          HdmiDebugConfigureGpio (mDebugGpioTableSklLpDdpC, mDebugGpioTableSklLpDdpCSize);
+          return EFI_SUCCESS;
+        case EnumDdcD:
+          HdmiDebugConfigureGpio (mDebugGpioTableSklLpDdpD, mDebugGpioTableSklLpDdpDSize);
+          return EFI_SUCCESS;
+
+        default:
+          return EFI_UNSUPPORTED;
+      }
+      break;
+    case PchTypeSptH:
+    case PchTypeKbpH:
+      switch (Channel) {
+        case EnumDdcB:
+          HdmiDebugConfigureGpio (mDebugGpioTableSklHDdpB, mDebugGpioTableSklHDdpBSize);
+          return EFI_SUCCESS;
+        case EnumDdcC:
+          HdmiDebugConfigureGpio (mDebugGpioTableSklHDdpC, mDebugGpioTableSklHDdpCSize);
+          return EFI_SUCCESS;
+        case EnumDdcD:
+          HdmiDebugConfigureGpio (mDebugGpioTableSklHDdpD, mDebugGpioTableSklHDdpDSize);
+          return EFI_SUCCESS;
+
+        default:
+          return EFI_UNSUPPORTED;
+      }
+      break;
+    default:
+      return EFI_UNSUPPORTED;
+  }
+}
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.inf
new file mode 100644
index 0000000000..3c83f68774
--- /dev/null
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugGpioInitLib/HdmiDebugGpioInitLib.inf
@@ -0,0 +1,42 @@
+### @file
+# Component description file for the HDMI I2C Debug Port GPIO initialization library
+#
+# Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = BaseHdmiDebugGpioInitLib
+  FILE_GUID                      = 4CC9D17A-B6D4-4FE2-AB82-27D539A8D8A9
+  VERSION_STRING                 = 1.0
+  MODULE_TYPE                    = BASE
+  LIBRARY_CLASS                  = HdmiDebugGpioInitLib
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[LibraryClasses]
+  BaseLib
+  PcdLib
+  PciLib
+  GpioLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  KabylakeOpenBoardPkg/OpenBoardPkg.dec
+  KabylakeSiliconPkg/SiPkg.dec
+
+[Sources]
+  HdmiDebugGpioInitLib.c
+
+[Ppis]
+
+[Guids]
+
+[Pcd]
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES
-- 
2.27.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#90594): https://edk2.groups.io/g/devel/message/90594
Mute This Topic: https://groups.io/mt/91835975/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list