Browse Source

KabylakeOpenBoardPkg: Add HdmiDebugPchDetectionLib

This library detects the type of PCH present on
the system to the granualarity level needed to
determine which GMBUS pins to use to access the
HDMI DDC I2C bus.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Benjamin Doron <benjamin.doron00@gmail.com>
Cc: Michael Kubacki <michael.kubacki@microsoft.com>
Cc: Jeremy Soller <jeremy@system76.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Reviewed-by: Isaac Oram <isaac.w.oram@intel.com>
Nate DeSimone 1 year ago
parent
commit
5f9e175123

+ 1 - 0
Platform/Intel/KabylakeOpenBoardPkg/AspireVn7Dash572G/OpenBoardPkg.dsc

@@ -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
+  HdmiDebugPchDetectionLib|$(PLATFORM_BOARD_PACKAGE)/Library/HdmiDebugPchDetectionLib/HdmiDebugPchDetectionLib.inf
 
   # Thunderbolt
 !if gKabylakeOpenBoardPkgTokenSpaceGuid.PcdTbtEnable == TRUE

+ 1 - 0
Platform/Intel/KabylakeOpenBoardPkg/GalagoPro3/OpenBoardPkg.dsc

@@ -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
+  HdmiDebugPchDetectionLib|$(PLATFORM_BOARD_PACKAGE)/Library/HdmiDebugPchDetectionLib/HdmiDebugPchDetectionLib.inf
 
   # Thunderbolt
 !if gKabylakeOpenBoardPkgTokenSpaceGuid.PcdTbtEnable == TRUE

+ 34 - 0
Platform/Intel/KabylakeOpenBoardPkg/Include/Library/HdmiDebugPchDetectionLib.h

@@ -0,0 +1,34 @@
+/** @file
+  PCH Detection 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_PCH_DETECTION_LIB_H_
+#define HDMI_DEBUG_PCH_DETECTION_LIB_H_
+
+#include <Uefi/UefiBaseType.h>
+
+typedef enum {
+  PchTypeUnknown = 0,
+  PchTypeSptLp,
+  PchTypeSptH,
+  PchTypeKbpH,
+  PchTypeCnlLp,
+  PchTypeCnlH,
+  PchTypeMax
+} PCH_TYPE;
+
+/**
+  Returns the type of PCH on the system
+
+  @retval   The PCH type.
+**/
+PCH_TYPE
+GetPchTypeInternal (
+  VOID
+  );
+
+#endif

+ 1 - 0
Platform/Intel/KabylakeOpenBoardPkg/KabylakeRvp3/OpenBoardPkg.dsc

@@ -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
+  HdmiDebugPchDetectionLib|$(PLATFORM_BOARD_PACKAGE)/Library/HdmiDebugPchDetectionLib/HdmiDebugPchDetectionLib.inf
 
   # Thunderbolt
 !if gKabylakeOpenBoardPkgTokenSpaceGuid.PcdTbtEnable == TRUE

+ 67 - 0
Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugPchDetectionLib/HdmiDebugPchDetectionLib.c

@@ -0,0 +1,67 @@
+/** @file
+  PCH Detection for the HDMI I2C Debug Port
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi/UefiBaseType.h>
+#include <Library/PciLib.h>
+#include <Library/HdmiDebugPchDetectionLib.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_CNL_LP_PCH_START_DEVICE_ID                      0x9D80
+#define V_CNL_LP_PCH_END_DEVICE_ID                        0x9D9F
+#define V_CNL_H_PCH_START_DEVICE_ID                       0xA300
+#define V_CNL_H_PCH_END_DEVICE_ID                         0xA31F
+
+#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
+
+/**
+  Returns the type of PCH on the system
+
+  @retval   The PCH type.
+**/
+PCH_TYPE
+GetPchTypeInternal (
+  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;
+    }
+  } else if ((DeviceId >= V_CNL_LP_PCH_START_DEVICE_ID) && (DeviceId <= V_CNL_LP_PCH_END_DEVICE_ID)) {
+    PchType = PchTypeCnlLp;
+  } else if ((DeviceId >= V_CNL_H_PCH_START_DEVICE_ID) && (DeviceId <= V_CNL_H_PCH_END_DEVICE_ID)) {
+    PchType = PchTypeCnlH;
+  }
+
+  return PchType;
+}

+ 38 - 0
Platform/Intel/KabylakeOpenBoardPkg/Library/HdmiDebugPchDetectionLib/HdmiDebugPchDetectionLib.inf

@@ -0,0 +1,38 @@
+### @file
+# Component description file for the HDMI I2C Debug Port PCH Detection library
+#
+# Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = BaseHdmiDebugPchDetectionLib
+  FILE_GUID                      = EA098B52-45DF-4367-A32D-F36ACF91A0A9
+  VERSION_STRING                 = 1.0
+  MODULE_TYPE                    = BASE
+  LIBRARY_CLASS                  = HdmiDebugPchDetectionLib
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[LibraryClasses]
+  BaseLib
+  PciLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  KabylakeOpenBoardPkg/OpenBoardPkg.dec
+
+[Sources]
+  HdmiDebugPchDetectionLib.c
+
+[Ppis]
+
+[Guids]
+
+[Pcd]