public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [edk2-platforms][PATCH 0/5] Add IPMI SSIF support
@ 2024-08-01  9:36 Nhi Pham via groups.io
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function Nhi Pham via groups.io
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Nhi Pham via groups.io @ 2024-08-01  9:36 UTC (permalink / raw)
  To: devel; +Cc: quic_llindhol, chuong, rebecca, nhi

This updates the I2C library and implements SMBUS PEI/DXE drivers to
support IPMI SSIF in the Mt. Jade platform.

Nhi Pham (5):
  AmpereAltraPkg/DwI2cLib: Add SmbusRead() function
  AmpereSiliconPkg: Define PCDs for SMBUS and BMC
  AmpereAltraPkg: Add SmbusHc PEI and DXE drivers
  JadePkg: Add PlatformBmcReadyLib to support BMC ready check
  Ampere/Jade: Enable IPMI SSIF

 Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec                        |  12 +
 Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc                        |  23 ++
 Platform/Ampere/JadePkg/Jade.dsc                                            |   2 +
 Platform/Ampere/JadePkg/Jade.fdf                                            |  17 ++
 Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.inf |  29 ++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf                |  43 +++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf                |  43 +++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h               |  95 +++++++
 Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h                      |  31 +++
 Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.c   |  30 +++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c               | 262 ++++++++++++++++++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c                  | 277 ++++++++++++++++++++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c                  | 263 +++++++++++++++++++
 Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c                   | 137 +++++++++-
 14 files changed, 1259 insertions(+), 5 deletions(-)
 create mode 100755 Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.inf
 create mode 100644 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf
 create mode 100644 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf
 create mode 100644 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h
 create mode 100644 Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.c
 create mode 100644 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c
 create mode 100644 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c
 create mode 100644 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c

--
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120162): https://edk2.groups.io/g/devel/message/120162
Mute This Topic: https://groups.io/mt/107662231/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function
  2024-08-01  9:36 [edk2-devel] [edk2-platforms][PATCH 0/5] Add IPMI SSIF support Nhi Pham via groups.io
@ 2024-08-01  9:36 ` Nhi Pham via groups.io
  2024-08-01 15:14   ` Leif Lindholm
  2024-08-01 15:18   ` Leif Lindholm
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 2/5] AmpereSiliconPkg: Define PCDs for SMBUS and BMC Nhi Pham via groups.io
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 12+ messages in thread
From: Nhi Pham via groups.io @ 2024-08-01  9:36 UTC (permalink / raw)
  To: devel; +Cc: quic_llindhol, chuong, rebecca, nhi

This adds the SmbusRead() function designed for SMBUS transaction to
support the extraction of the data lenth byte from the initial byte of
the SMBUS Block Read, allowing the I2C master to accurately read the
SMBUS response with the exact data length. This addresses the issue
where the SmbusLib:SmBusReadBlock() function consistently reads a
32-byte block of data.

Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
---
 Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h    |  31 +++++
 Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c | 137 +++++++++++++++++++-
 2 files changed, 163 insertions(+), 5 deletions(-)

diff --git a/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h b/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
index f13794171029..d460f49efccb 100644
--- a/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
+++ b/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
@@ -65,6 +65,37 @@ I2cRead (
   IN OUT UINT32 *ReadLength
   );
 
+/**
+  SMBUS block read.
+
+  @param[in]     Bus          I2C bus Id.
+  @param[in]     SlaveAddr    The address of slave device on the bus.
+  @param[in]     BufCmd       Buffer where to send the command.
+  @param[in]     CmdLength    Length of BufCmd.
+  @param[in,out] Buf          Buffer where to put the read data to.
+  @param[in,out] ReadLength   Pointer to length of buffer.
+  @param[in]     PecCheck     If Packet Error Code (PEC) checking is required for this operation.
+
+  @retval EFI_SUCCESS            Read successfully.
+  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
+  @retval EFI_UNSUPPORTED        The bus is not supported.
+  @retval EFI_NOT_READY          The device/bus is not ready.
+  @retval EFI_TIMEOUT            Timeout when transferring data.
+  @retval EFI_CRC_ERROR          There are errors on receiving data.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusRead (
+  IN     UINT32  Bus,
+  IN     UINT32  SlaveAddr,
+  IN     UINT8   *BufCmd,
+  IN     UINT32  CmdLength,
+  IN OUT UINT8   *Buf,
+  IN OUT UINT32  *ReadLength,
+  IN     BOOLEAN PecCheck
+  );
+
 /**
  Setup new transaction with I2C slave device.
 
diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c b/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
index 669ba2ea98a4..9e52ae69e7cd 100644
--- a/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
+++ b/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
@@ -337,6 +337,11 @@ I2cWaitTxData (
       DEBUG ((DEBUG_ERROR, "%a: Timeout waiting for TX buffer available\n", __FUNCTION__));
       return EFI_TIMEOUT;
     }
+
+    if ((I2cCheckErrors (Bus) & DW_IC_INTR_TX_ABRT) != 0) {
+      return EFI_ABORTED;
+    }
+
     MicroSecondDelay (mI2cBusList[Bus].PollingTime);
   }
 
@@ -542,13 +547,61 @@ InternalI2cWrite (
   return Status;
 }
 
+EFI_STATUS
+InternalSmbusReadDataLength (
+  UINT32  Bus,
+  UINT32 *Length
+  )
+{
+  EFI_STATUS Status;
+  UINTN      Base;
+  UINT32     CmdSend;
+
+  Base = mI2cBusList[Bus].Base;
+
+  CmdSend = DW_IC_DATA_CMD_CMD;
+  MmioWrite32 (Base + DW_IC_DATA_CMD, CmdSend);
+  I2cSync ();
+
+  if (I2cCheckErrors (Bus) != 0) {
+    DEBUG ((DEBUG_ERROR, "%a: Sending reading command error\n", __func__));
+    return EFI_CRC_ERROR;
+  }
+
+  Status = I2cWaitRxData (Bus);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Reading Smbus data length failed to wait data\n",
+      __func__
+      ));
+
+    if (Status != EFI_ABORTED) {
+      MmioWrite32 (Base + DW_IC_DATA_CMD, DW_IC_DATA_CMD_STOP);
+      I2cSync ();
+    }
+
+    return Status;
+  }
+
+  *Length = MmioRead32 (Base + DW_IC_DATA_CMD) & DW_IC_DATA_CMD_DAT_MASK;
+  I2cSync ();
+
+  if (I2cCheckErrors (Bus) != 0) {
+    DEBUG ((DEBUG_ERROR, "%a: Sending reading command error\n", __func__));
+    return EFI_CRC_ERROR;
+  }
+  return EFI_SUCCESS;
+}
+
 EFI_STATUS
 InternalI2cRead (
   UINT32  Bus,
-  UINT8  *BufCmd,
-  UINT32 CmdLength,
-  UINT8  *Buf,
-  UINT32 *Length
+  UINT8   *BufCmd,
+  UINT32  CmdLength,
+  UINT8   *Buf,
+  UINT32  *Length,
+  BOOLEAN IsSmbus,
+  BOOLEAN PecCheck
   )
 {
   EFI_STATUS Status;
@@ -559,6 +612,7 @@ InternalI2cRead (
   UINTN      Count;
   UINTN      ReadCount;
   UINTN      WriteCount;
+  UINT32     ResponseLen;
 
   Status = EFI_SUCCESS;
   Base = mI2cBusList[Bus].Base;
@@ -601,6 +655,36 @@ InternalI2cRead (
   }
 
   WriteCount = 0;
+  if (IsSmbus) {
+    //
+    // Read Smbus Data Length, first byte of the Smbus response data.
+    //
+    Status = InternalSmbusReadDataLength (Bus, &ResponseLen);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: InternalSmbusReadDataLength failed\n", __func__));
+      goto Exit;
+    }
+
+    WriteCount++;
+    Buf[ReadCount++] = ResponseLen;
+
+    //
+    // Abort the transaction when the requested length is shorter than the actual response data
+    // or if there is no response data when PEC disabled.
+    //
+    if ((*Length < (ResponseLen + 2)) || (!PecCheck && ResponseLen == 0)) {
+      MmioWrite32 (Base + DW_IC_DATA_CMD, DW_IC_DATA_CMD_CMD | DW_IC_DATA_CMD_STOP);
+      I2cSync ();
+      Status = EFI_INVALID_PARAMETER;
+      goto Exit;
+    }
+
+    *Length = ResponseLen + 1; // Response Data Length + 8-bit Byte Count field
+    if (PecCheck) {
+      *Length += 1; // ++ 8-bit PEC field
+    }
+  }
+
   while ((*Length - ReadCount) != 0) {
     TxLimit = mI2cBusList[Bus].TxFifo - MmioRead32 (Base + DW_IC_TXFLR);
     RxLimit = mI2cBusList[Bus].RxFifo - MmioRead32 (Base + DW_IC_RXFLR);
@@ -742,7 +826,50 @@ I2cRead (
 
   I2cSetSlaveAddr (Bus, SlaveAddr);
 
-  return InternalI2cRead (Bus, BufCmd, CmdLength, Buf, ReadLength);
+  return InternalI2cRead (Bus, BufCmd, CmdLength, Buf, ReadLength, FALSE, FALSE);
+}
+
+/**
+  SMBUS block read.
+
+  @param[in]     Bus          I2C bus Id.
+  @param[in]     SlaveAddr    The address of slave device on the bus.
+  @param[in]     BufCmd       Buffer where to send the command.
+  @param[in]     CmdLength    Length of BufCmd.
+  @param[in,out] Buf          Buffer where to put the read data to.
+  @param[in,out] ReadLength   Pointer to length of buffer.
+  @param[in]     PecCheck     If Packet Error Code (PEC) checking is required for this operation.
+
+  @retval EFI_SUCCESS            Read successfully.
+  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
+  @retval EFI_UNSUPPORTED        The bus is not supported.
+  @retval EFI_NOT_READY          The device/bus is not ready.
+  @retval EFI_TIMEOUT            Timeout when transferring data.
+  @retval EFI_CRC_ERROR          There are errors on receiving data.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusRead (
+  IN     UINT32  Bus,
+  IN     UINT32  SlaveAddr,
+  IN     UINT8   *BufCmd,
+  IN     UINT32  CmdLength,
+  IN OUT UINT8   *Buf,
+  IN OUT UINT32  *ReadLength,
+  IN     BOOLEAN PecCheck
+  )
+{
+  if (Bus >= AC01_I2C_MAX_BUS_NUM
+      || Buf == NULL
+      || ReadLength == NULL)
+  {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  I2cSetSlaveAddr (Bus, SlaveAddr);
+
+  return InternalI2cRead (Bus, BufCmd, CmdLength, Buf, ReadLength, TRUE, PecCheck);
 }
 
 /**
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120163): https://edk2.groups.io/g/devel/message/120163
Mute This Topic: https://groups.io/mt/107662232/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [edk2-devel] [edk2-platforms][PATCH 2/5] AmpereSiliconPkg: Define PCDs for SMBUS and BMC
  2024-08-01  9:36 [edk2-devel] [edk2-platforms][PATCH 0/5] Add IPMI SSIF support Nhi Pham via groups.io
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function Nhi Pham via groups.io
@ 2024-08-01  9:36 ` Nhi Pham via groups.io
  2024-08-01 15:02   ` Leif Lindholm
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 3/5] AmpereAltraPkg: Add SmbusHc PEI and DXE drivers Nhi Pham via groups.io
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Nhi Pham via groups.io @ 2024-08-01  9:36 UTC (permalink / raw)
  To: devel; +Cc: quic_llindhol, chuong, rebecca, nhi

This introduces fixed PCDs for SMBUS and BMC as specified to Ampere.

Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
---
 Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
index 56e8b2fd2f11..5c5015c1bf21 100644
--- a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
+++ b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
@@ -69,6 +69,18 @@ [PcdsFixedAtBuild]
   gAmpereTokenSpaceGuid.PcdSmbiosTables0MajorVersion|0xFF|UINT8|0x00000005
   gAmpereTokenSpaceGuid.PcdSmbiosTables0MinorVersion|0xFF|UINT8|0x00000006
 
+  #
+  # SMBUS
+  #
+  gAmpereTokenSpaceGuid.PcdSmbusI2cBusNumber|0x00|UINT8|0x00000007
+  gAmpereTokenSpaceGuid.PcdSmbusI2cBusSpeed|100000|UINT32|0x00000008 # Hz
+
+  #
+  # BMC
+  #
+  gAmpereTokenSpaceGuid.PcdBmcSlaveAddr|0x10|UINT8|0x00000009
+  gAmpereTokenSpaceGuid.PcdBmcReadyGpio|0x18|UINT8|0x0000000A
+
 [PcdsFixedAtBuild, PcdsDynamic, PcdsDynamicEx]
   #
   # Firmware Volume Pcds
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120164): https://edk2.groups.io/g/devel/message/120164
Mute This Topic: https://groups.io/mt/107662236/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [edk2-devel] [edk2-platforms][PATCH 3/5] AmpereAltraPkg: Add SmbusHc PEI and DXE drivers
  2024-08-01  9:36 [edk2-devel] [edk2-platforms][PATCH 0/5] Add IPMI SSIF support Nhi Pham via groups.io
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function Nhi Pham via groups.io
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 2/5] AmpereSiliconPkg: Define PCDs for SMBUS and BMC Nhi Pham via groups.io
@ 2024-08-01  9:36 ` Nhi Pham via groups.io
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 4/5] JadePkg: Add PlatformBmcReadyLib to support BMC ready check Nhi Pham via groups.io
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 5/5] Ampere/Jade: Enable IPMI SSIF Nhi Pham via groups.io
  4 siblings, 0 replies; 12+ messages in thread
From: Nhi Pham via groups.io @ 2024-08-01  9:36 UTC (permalink / raw)
  To: devel; +Cc: quic_llindhol, chuong, rebecca, nhi

This adds the implementation of SMBUS PPI and Protocol to produce SMBUS
interface in both PEI and DXE phases for use by IPMI SSIF.

Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
---
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf  |  43 +++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf  |  43 +++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h |  95 +++++++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c | 262 ++++++++++++++++++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c    | 277 ++++++++++++++++++++
 Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c    | 263 +++++++++++++++++++
 6 files changed, 983 insertions(+)

diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf
new file mode 100644
index 000000000000..7e8c8176658e
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf
@@ -0,0 +1,43 @@
+## @file
+#
+# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001B
+  BASE_NAME                      = SmbusHcDxe
+  FILE_GUID                      = A92C6874-B59E-49A7-957D-8511C9D8520E
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = InitializeSmbus
+
+[Sources]
+  SmbusHcCommon.c
+  SmbusHcDxe.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec
+  Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  DebugLib
+  GpioLib
+  I2cLib
+  UefiBootServicesTableLib
+  UefiDriverEntryPoint
+
+[Protocols]
+  gEfiSmbusHcProtocolGuid        # PRODUCES
+
+[Pcd]
+  gAmpereTokenSpaceGuid.PcdSmbusI2cBusNumber
+  gAmpereTokenSpaceGuid.PcdSmbusI2cBusSpeed
+
+[Depex]
+  TRUE
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf
new file mode 100644
index 000000000000..810a583feab3
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf
@@ -0,0 +1,43 @@
+## @file
+#
+# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001B
+  BASE_NAME                      = SmbusHcPeim
+  FILE_GUID                      = 1D770ACE-36E9-4B74-B548-4F423B60A26C
+  MODULE_TYPE                    = PEIM
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = InitializeSmbusPeim
+
+[Sources]
+  SmbusHcCommon.c
+  SmbusHcPei.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec
+  Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  DebugLib
+  GpioLib
+  I2cLib
+  PeimEntryPoint
+  PeiServicesLib
+
+[Ppis]
+  gEfiPeiSmbus2PpiGuid        # PRODUCES
+
+[Pcd]
+  gAmpereTokenSpaceGuid.PcdSmbusI2cBusNumber
+  gAmpereTokenSpaceGuid.PcdSmbusI2cBusSpeed
+
+[Depex]
+  TRUE
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h
new file mode 100644
index 000000000000..db19d50b0f2a
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.h
@@ -0,0 +1,95 @@
+/** @file
+
+  Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef SMBUS_HC_COMMON_LIB_H_
+#define SMBUS_HC_COMMON_LIB_H_
+
+#include <Library/PcdLib.h>
+#include <IndustryStandard/SmBus.h>
+#include <Uefi/UefiBaseType.h>
+
+//
+// I2C Based SMBus info
+//
+#define I2C_BUS_NUMBER  (FixedPcdGet8 (PcdSmbusI2cBusNumber))
+#define I2C_BUS_SPEED   (FixedPcdGet32 (PcdSmbusI2cBusSpeed))
+#define I2C_WRITE_ADDRESS(Addr)  ((Addr) << 1 | 0)
+#define I2C_READ_ADDRESS(Addr)   ((Addr) << 1 | 1)
+
+//
+// SMBus 2.0
+//
+#define SMBUS_MAX_BLOCK_LENGTH   0x20
+#define SMBUS_READ_TEMP_LENGTH   (SMBUS_MAX_BLOCK_LENGTH + 2)  // Length + 32 Bytes + PEC
+#define SMBUS_WRITE_TEMP_LENGTH  (SMBUS_MAX_BLOCK_LENGTH + 3)  // CMD + Length + 32 Bytes + PEC
+
+//
+// SMBus PEC
+//
+#define CRC8_POLYNOMINAL_KEY  0x107     // X^8 + X^2 + X + 1
+
+/**
+  Executes an SMBus operation to an SMBus controller. Returns when either the command has been
+  executed or an error is encountered in doing the operation.
+
+  The Execute() function provides a standard way to execute an operation as defined in the System
+  Management Bus (SMBus) Specification. The resulting transaction will be either that the SMBus
+  slave devices accept this transaction or that this function returns with error.
+
+  @param  This                    A pointer to the EFI_SMBUS_HC_PROTOCOL instance.
+  @param  SlaveAddress            The SMBus slave address of the device with which to communicate.
+  @param  Command                 This command is transmitted by the SMBus host controller to the
+                                  SMBus slave device and the interpretation is SMBus slave device
+                                  specific. It can mean the offset to a list of functions inside an
+                                  SMBus slave device. Not all operations or slave devices support
+                                  this command's registers.
+  @param  Operation               Signifies which particular SMBus hardware protocol instance that
+                                  it will use to execute the SMBus transactions. This SMBus
+                                  hardware protocol is defined by the SMBus Specification and is
+                                  not related to EFI.
+  @param  PecCheck                Defines if Packet Error Code (PEC) checking is required for this
+                                  operation.
+  @param  Length                  Signifies the number of bytes that this operation will do. The
+                                  maximum number of bytes can be revision specific and operation
+                                  specific. This field will contain the actual number of bytes that
+                                  are executed for this operation. Not all operations require this
+                                  argument.
+  @param  Buffer                  Contains the value of data to execute to the SMBus slave device.
+                                  Not all operations require this argument. The length of this
+                                  buffer is identified by Length.
+
+  @retval EFI_SUCCESS             The last data that was returned from the access matched the poll
+                                  exit criteria.
+  @retval EFI_CRC_ERROR           Checksum is not correct (PEC is incorrect).
+  @retval EFI_TIMEOUT             Timeout expired before the operation was completed. Timeout is
+                                  determined by the SMBus host controller device.
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a lack of resources.
+  @retval EFI_DEVICE_ERROR        The request was not completed because a failure that was
+                                  reflected in the Host Status Register bit. Device errors are a
+                                  result of a transaction collision, illegal command field,
+                                  unclaimed cycle (host initiated), or bus errors (collisions).
+  @retval EFI_INVALID_PARAMETER   Operation is not defined in EFI_SMBUS_OPERATION.
+  @retval EFI_INVALID_PARAMETER   Length/Buffer is NULL for operations except for EfiSmbusQuickRead
+                                  and EfiSmbusQuickWrite. Length is outside the range of valid
+                                  values.
+  @retval EFI_UNSUPPORTED         The SMBus operation or PEC is not supported.
+  @retval EFI_BUFFER_TOO_SMALL    Buffer is not sufficient for this operation.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcCommonExecute (
+  IN       EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress,
+  IN       EFI_SMBUS_DEVICE_COMMAND  Command,
+  IN       EFI_SMBUS_OPERATION       Operation,
+  IN       BOOLEAN                   PecCheck,
+  IN OUT   UINTN                     *Length,
+  IN OUT   VOID                      *Buffer
+  );
+
+#endif /* SMBUS_HC_COMMON_LIB_H_ */
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c
new file mode 100644
index 000000000000..6219c99cda18
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcCommon.c
@@ -0,0 +1,262 @@
+/** @file
+  SmbusHcCommon implement common api for SmbusHc
+
+  Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/GpioLib.h>
+#include <Library/I2cLib.h>
+#include <Library/PcdLib.h>
+
+#include "SmbusHcCommon.h"
+
+/**
+  Incremental calculate Pec base on previous Pec value and CRC8 of data array
+  pointed to by Buffer
+
+  @param  Pec        Previous Pec
+  @param  Buffer     Pointer to data array
+  @param  Length     Array count
+
+  @retval Pec
+
+**/
+UINT8
+CalculatePec (
+  UINT8   Pec,
+  UINT8   *Buffer,
+  UINT32  Length
+  )
+{
+  UINT8  Offset, Index;
+
+  for (Offset = 0; Offset < Length; Offset++) {
+    Pec ^= Buffer[Offset];
+    for (Index = 0; Index < 8; Index++) {
+      if ((Pec & 0x80) != 0) {
+        Pec = (UINT8)((Pec << 1) ^ CRC8_POLYNOMINAL_KEY);
+      } else {
+        Pec <<= 1;
+      }
+    }
+  }
+
+  return Pec & 0xFF;
+}
+
+/**
+  Executes an SMBus operation to an SMBus controller. Returns when either the command has been
+  executed or an error is encountered in doing the operation.
+
+  The Execute() function provides a standard way to execute an operation as defined in the System
+  Management Bus (SMBus) Specification. The resulting transaction will be either that the SMBus
+  slave devices accept this transaction or that this function returns with error.
+
+  @param  SlaveAddress            The SMBus slave address of the device with which to communicate.
+  @param  Command                 This command is transmitted by the SMBus host controller to the
+                                  SMBus slave device and the interpretation is SMBus slave device
+                                  specific. It can mean the offset to a list of functions inside an
+                                  SMBus slave device. Not all operations or slave devices support
+                                  this command's registers.
+  @param  Operation               Signifies which particular SMBus hardware protocol instance that
+                                  it will use to execute the SMBus transactions. This SMBus
+                                  hardware protocol is defined by the SMBus Specification and is
+                                  not related to EFI.
+  @param  PecCheck                Defines if Packet Error Code (PEC) checking is required for this
+                                  operation.
+  @param  Length                  Signifies the number of bytes that this operation will do. The
+                                  maximum number of bytes can be revision specific and operation
+                                  specific. This field will contain the actual number of bytes that
+                                  are executed for this operation. Not all operations require this
+                                  argument.
+  @param  Buffer                  Contains the value of data to execute to the SMBus slave device.
+                                  Not all operations require this argument. The length of this
+                                  buffer is identified by Length.
+
+  @retval EFI_SUCCESS             The last data that was returned from the access matched the poll
+                                  exit criteria.
+  @retval EFI_CRC_ERROR           Checksum is not correct (PEC is incorrect).
+  @retval EFI_TIMEOUT             Timeout expired before the operation was completed. Timeout is
+                                  determined by the SMBus host controller device.
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a lack of resources.
+  @retval EFI_DEVICE_ERROR        The request was not completed because a failure that was
+                                  reflected in the Host Status Register bit. Device errors are a
+                                  result of a transaction collision, illegal command field,
+                                  unclaimed cycle (host initiated), or bus errors (collisions).
+  @retval EFI_INVALID_PARAMETER   Operation is not defined in EFI_SMBUS_OPERATION.
+  @retval EFI_INVALID_PARAMETER   Length/Buffer is NULL for operations except for EfiSmbusQuickRead
+                                  and EfiSmbusQuickWrite. Length is outside the range of valid
+                                  values.
+  @retval EFI_UNSUPPORTED         The SMBus operation or PEC is not supported.
+  @retval EFI_BUFFER_TOO_SMALL    Buffer is not sufficient for this operation.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcCommonExecute (
+  IN       EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress,
+  IN       EFI_SMBUS_DEVICE_COMMAND  Command,
+  IN       EFI_SMBUS_OPERATION       Operation,
+  IN       BOOLEAN                   PecCheck,
+  IN OUT   UINTN                     *Length,
+  IN OUT   VOID                      *Buffer
+  )
+{
+  EFI_STATUS  Status;
+  UINTN       DataLen, Idx;
+  UINT8       ReadTemp[SMBUS_READ_TEMP_LENGTH];
+  UINT8       WriteTemp[SMBUS_WRITE_TEMP_LENGTH];
+  UINT8       CrcTemp[10];
+  UINT8       Pec;
+
+  if (  ((Operation != EfiSmbusQuickRead) && (Operation != EfiSmbusQuickWrite))
+     && ((Length == NULL) || (Buffer == NULL)))
+  {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Switch to correct I2C bus and speed
+  //
+  Status = I2cProbe (I2C_BUS_NUMBER, I2C_BUS_SPEED);
+  if (EFI_ERROR (Status)) {
+    return EFI_DEVICE_ERROR;
+  }
+
+  //
+  // Process Operation
+  //
+  switch (Operation) {
+    case EfiSmbusWriteBlock:
+      if (*Length > SMBUS_MAX_BLOCK_LENGTH) {
+        return EFI_INVALID_PARAMETER;
+      }
+
+      WriteTemp[0] = Command;
+      WriteTemp[1] = *Length;
+      CopyMem (&WriteTemp[2], Buffer, *Length);
+      DataLen = *Length + 2;
+
+      //
+      // PEC handling
+      //
+      if (PecCheck) {
+        CrcTemp[0] = I2C_WRITE_ADDRESS (SlaveAddress.SmbusDeviceAddress);
+        Pec        = CalculatePec (0, &CrcTemp[0], 1);
+        Pec        = CalculatePec (Pec, WriteTemp, DataLen);
+        DEBUG ((DEBUG_VERBOSE, "\nWriteBlock PEC = 0x%x \n", Pec));
+        WriteTemp[DataLen] = Pec;
+        DataLen           += 1;
+      }
+
+      DEBUG ((DEBUG_VERBOSE, "W %d: ", DataLen));
+      for (Idx = 0; Idx < DataLen; Idx++) {
+        DEBUG ((DEBUG_VERBOSE, "0x%x ", WriteTemp[Idx]));
+      }
+
+      DEBUG ((DEBUG_VERBOSE, "\n"));
+
+      Status = I2cWrite (
+                 I2C_BUS_NUMBER,
+                 SlaveAddress.SmbusDeviceAddress,
+                 WriteTemp,
+                 (UINT32 *)&DataLen
+                 );
+      if (EFI_ERROR (Status)) {
+        if (Status != EFI_TIMEOUT) {
+          Status = EFI_DEVICE_ERROR;
+        }
+      }
+
+      break;
+
+    case EfiSmbusReadBlock:
+      WriteTemp[0] = Command;
+      DataLen      = *Length + 2; // +1 byte for Data Length +1 byte for PEC
+      Status       = SmbusRead (
+                       I2C_BUS_NUMBER,
+                       SlaveAddress.SmbusDeviceAddress,
+                       WriteTemp,
+                       1,
+                       ReadTemp,
+                       (UINT32 *)&DataLen,
+                       PecCheck
+                       );
+      if (EFI_ERROR (Status)) {
+        if (Status != EFI_TIMEOUT) {
+          Status = EFI_DEVICE_ERROR;
+        }
+
+        *Length = 0;
+        break;
+      }
+
+      DEBUG ((DEBUG_VERBOSE, "R %d: ", DataLen));
+      for (Idx = 0; Idx < DataLen; Idx++) {
+        DEBUG ((DEBUG_VERBOSE, "0x%x ", ReadTemp[Idx]));
+      }
+
+      DEBUG ((DEBUG_VERBOSE, "\n"));
+
+      DataLen = ReadTemp[0];
+
+      //
+      // PEC handling
+      //
+      if (PecCheck) {
+        CrcTemp[0] = I2C_WRITE_ADDRESS (SlaveAddress.SmbusDeviceAddress);
+        CrcTemp[1] = Command;
+        CrcTemp[2] = I2C_READ_ADDRESS (SlaveAddress.SmbusDeviceAddress);
+
+        Pec = CalculatePec (0, &CrcTemp[0], 3);
+        Pec = CalculatePec (Pec, ReadTemp, DataLen + 1);
+
+        if (Pec != ReadTemp[DataLen + 1]) {
+          DEBUG ((DEBUG_ERROR, "ReadBlock PEC cal = 0x%x != 0x%x\n", Pec, ReadTemp[DataLen + 1]));
+          return EFI_CRC_ERROR;
+        } else {
+          DEBUG ((DEBUG_VERBOSE, "ReadBlock PEC 0x%x\n", ReadTemp[DataLen + 1]));
+        }
+      }
+
+      if ((DataLen == 0) || (DataLen > SMBUS_MAX_BLOCK_LENGTH)) {
+        DEBUG ((DEBUG_ERROR, "%a: Invalid length = %d\n", __func__, DataLen));
+        *Length = 0;
+        Status  = EFI_INVALID_PARAMETER;
+      } else if (DataLen > *Length) {
+        DEBUG ((DEBUG_ERROR, "%a: Buffer too small\n", __func__));
+        *Length = 0;
+        Status  = EFI_BUFFER_TOO_SMALL;
+      } else {
+        *Length = DataLen;
+        CopyMem (Buffer, &ReadTemp[1], DataLen);
+      }
+
+      break;
+
+    case EfiSmbusQuickRead:
+    case EfiSmbusQuickWrite:
+    case EfiSmbusReceiveByte:
+    case EfiSmbusSendByte:
+    case EfiSmbusReadByte:
+    case EfiSmbusWriteByte:
+    case EfiSmbusReadWord:
+    case EfiSmbusWriteWord:
+    case EfiSmbusProcessCall:
+    case EfiSmbusBWBRProcessCall:
+      DEBUG ((DEBUG_ERROR, "%a: Unsupported command\n", __func__));
+      Status = EFI_UNSUPPORTED;
+      break;
+
+    default:
+      Status = EFI_INVALID_PARAMETER;
+  }
+
+  return Status;
+}
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c
new file mode 100644
index 000000000000..49a16a2c3d7e
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.c
@@ -0,0 +1,277 @@
+/** SmbusHc protocol implementation follows SMBus 2.0 specification.
+
+  Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/GpioLib.h>
+#include <Library/I2cLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/SmbusHc.h>
+
+#include "SmbusHcCommon.h"
+
+//
+// Handle to install SMBus Host Controller protocol.
+//
+EFI_HANDLE  mSmbusHcHandle = NULL;
+
+/**
+  Executes an SMBus operation to an SMBus controller. Returns when either the command has been
+  executed or an error is encountered in doing the operation.
+
+  The Execute() function provides a standard way to execute an operation as defined in the System
+  Management Bus (SMBus) Specification. The resulting transaction will be either that the SMBus
+  slave devices accept this transaction or that this function returns with error.
+
+  @param  This                    A pointer to the EFI_SMBUS_HC_PROTOCOL instance.
+  @param  SlaveAddress            The SMBus slave address of the device with which to communicate.
+  @param  Command                 This command is transmitted by the SMBus host controller to the
+                                  SMBus slave device and the interpretation is SMBus slave device
+                                  specific. It can mean the offset to a list of functions inside an
+                                  SMBus slave device. Not all operations or slave devices support
+                                  this command's registers.
+  @param  Operation               Signifies which particular SMBus hardware protocol instance that
+                                  it will use to execute the SMBus transactions. This SMBus
+                                  hardware protocol is defined by the SMBus Specification and is
+                                  not related to EFI.
+  @param  PecCheck                Defines if Packet Error Code (PEC) checking is required for this
+                                  operation.
+  @param  Length                  Signifies the number of bytes that this operation will do. The
+                                  maximum number of bytes can be revision specific and operation
+                                  specific. This field will contain the actual number of bytes that
+                                  are executed for this operation. Not all operations require this
+                                  argument.
+  @param  Buffer                  Contains the value of data to execute to the SMBus slave device.
+                                  Not all operations require this argument. The length of this
+                                  buffer is identified by Length.
+
+  @retval EFI_SUCCESS             The last data that was returned from the access matched the poll
+                                  exit criteria.
+  @retval EFI_CRC_ERROR           Checksum is not correct (PEC is incorrect).
+  @retval EFI_TIMEOUT             Timeout expired before the operation was completed. Timeout is
+                                  determined by the SMBus host controller device.
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a lack of resources.
+  @retval EFI_DEVICE_ERROR        The request was not completed because a failure that was
+                                  reflected in the Host Status Register bit. Device errors are a
+                                  result of a transaction collision, illegal command field,
+                                  unclaimed cycle (host initiated), or bus errors (collisions).
+  @retval EFI_INVALID_PARAMETER   Operation is not defined in EFI_SMBUS_OPERATION.
+  @retval EFI_INVALID_PARAMETER   Length/Buffer is NULL for operations except for EfiSmbusQuickRead
+                                  and EfiSmbusQuickWrite. Length is outside the range of valid
+                                  values.
+  @retval EFI_UNSUPPORTED         The SMBus operation or PEC is not supported.
+  @retval EFI_BUFFER_TOO_SMALL    Buffer is not sufficient for this operation.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcExecute (
+  IN CONST EFI_SMBUS_HC_PROTOCOL     *This,
+  IN       EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress,
+  IN       EFI_SMBUS_DEVICE_COMMAND  Command,
+  IN       EFI_SMBUS_OPERATION       Operation,
+  IN       BOOLEAN                   PecCheck,
+  IN OUT   UINTN                     *Length,
+  IN OUT   VOID                      *Buffer
+  )
+{
+  EFI_STATUS  Status;
+  EFI_TPL     OldTpl;
+
+  ASSERT (This != NULL);
+
+  OldTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
+
+  Status = SmbusHcCommonExecute (SlaveAddress, Command, Operation, PecCheck, Length, Buffer);
+
+  gBS->RestoreTPL (OldTpl);
+
+  return Status;
+}
+
+/**
+
+  The SmbusHcArpDevice() function provides a standard way for a device driver to
+  enumerate the entire SMBus or specific devices on the bus.
+
+  @param This           A pointer to the EFI_SMBUS_HC_PROTOCOL instance.
+
+  @param ArpAll         A Boolean expression that indicates if the
+                        host drivers need to enumerate all the devices
+                        or enumerate only the device that is
+                        identified by SmbusUdid. If ArpAll is TRUE,
+                        SmbusUdid and SlaveAddress are optional. If
+                        ArpAll is FALSE, ArpDevice will enumerate
+                        SmbusUdid and the address will be at
+                        SlaveAddress.
+
+  @param SmbusUdid      The Unique Device Identifier (UDID) that is
+                        associated with this device. Type
+                        EFI_SMBUS_UDID is defined in
+                        EFI_PEI_SMBUS_PPI.ArpDevice() in the
+                        Platform Initialization SMBus PPI
+                        Specification.
+
+  @param SlaveAddress   The SMBus slave address that is
+                        associated with an SMBus UDID.
+
+  @retval EFI_SUCCESS           The last data that was returned from the
+                                access matched the poll exit criteria.
+
+  @retval EFI_CRC_ERROR         Checksum is not correct (PEC is
+                                incorrect).
+
+  @retval EFI_TIMEOUT           Timeout expired before the operation was
+                                completed. Timeout is determined by the
+                                SMBus host controller device.
+
+  @retval EFI_OUT_OF_RESOURCES  The request could not be
+                                completed due to a lack of
+                                resources.
+
+  @retval EFI_DEVICE_ERROR      The request was not completed
+                                because a failure was reflected in
+                                the Host Status Register bit. Device
+                                Errors are a result of a transaction
+                                collision, illegal command field,
+                                unclaimed cycle (host initiated), or
+                                bus errors (collisions).
+
+  @retval EFI_UNSUPPORTED       ArpDevice, GetArpMap, and Notify are
+                                not implemented by this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcArpDevice (
+  IN CONST EFI_SMBUS_HC_PROTOCOL *This,
+  IN       BOOLEAN ArpAll,
+  IN       EFI_SMBUS_UDID *SmbusUdid, OPTIONAL
+  IN OUT   EFI_SMBUS_DEVICE_ADDRESS *SlaveAddress OPTIONAL
+  )
+{
+  //
+  // Not supported
+  //
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  The SmbusHcGetArpMap() function returns the mapping of all the SMBus devices
+  that were enumerated by the SMBus host driver.
+
+  @param This           A pointer to the EFI_SMBUS_HC_PROTOCOL instance.
+
+  @param Length         Size of the buffer that contains the SMBus
+                        device map.
+
+  @param SmbusDeviceMap The pointer to the device map as
+                        enumerated by the SMBus controller
+                        driver.
+
+  @retval EFI_SUCCESS       The SMBus returned the current device map.
+
+  @retval EFI_UNSUPPORTED   ArpDevice, GetArpMap, and Notify are
+                            not implemented by this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcGetArpMap (
+  IN CONST EFI_SMBUS_HC_PROTOCOL  *This,
+  IN OUT   UINTN                  *Length,
+  IN OUT   EFI_SMBUS_DEVICE_MAP   **SmbusDeviceMap
+  )
+{
+  //
+  // Not supported
+  //
+  return EFI_UNSUPPORTED;
+}
+
+/**
+
+  The SmbusHcNotify() function registers all the callback functions to
+  allow the bus driver to call these functions when the
+  SlaveAddress/Data pair happens.
+
+  @param  This            A pointer to the EFI_SMBUS_HC_PROTOCOL instance.
+
+  @param  SlaveAddress    Address that the host controller detects
+                          as sending a message and calls all the registered function.
+
+  @param  Data            Data that the host controller detects as sending
+                          message and calls all the registered function.
+
+
+  @param  NotifyFunction  The function to call when the bus
+                          driver detects the SlaveAddress and
+                          Data pair.
+
+  @retval EFI_SUCCESS       NotifyFunction was registered.
+
+  @retval EFI_UNSUPPORTED   ArpDevice, GetArpMap, and Notify are
+                            not implemented by this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcNotify (
+  IN CONST EFI_SMBUS_HC_PROTOCOL      *This,
+  IN       EFI_SMBUS_DEVICE_ADDRESS   SlaveAddress,
+  IN       UINTN                      Data,
+  IN       EFI_SMBUS_NOTIFY_FUNCTION  NotifyFunction
+  )
+{
+  //
+  // Not supported
+  //
+  return EFI_UNSUPPORTED;
+}
+
+//
+// Interface defintion of SMBUS Host Controller Protocol.
+//
+EFI_SMBUS_HC_PROTOCOL  mSmbusHcProtocol = {
+  SmbusHcExecute,
+  SmbusHcArpDevice,
+  SmbusHcGetArpMap,
+  SmbusHcNotify
+};
+
+/**
+  SmbusHc driver entry point
+
+  @param[in] ImageHandle          ImageHandle of this module
+  @param[in] SystemTable          EFI System Table
+
+  @retval EFI_SUCCESS             Driver initializes successfully
+  @retval Other values            Some error occurred
+**/
+EFI_STATUS
+InitializeSmbus (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS  Status;
+
+  //
+  // Install Smbus protocol
+  //
+  Status = gBS->InstallMultipleProtocolInterfaces (
+                  &mSmbusHcHandle,
+                  &gEfiSmbusHcProtocolGuid,
+                  &mSmbusHcProtocol,
+                  NULL
+                  );
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
+}
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c
new file mode 100644
index 000000000000..39483a2a602a
--- /dev/null
+++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.c
@@ -0,0 +1,263 @@
+/** @file
+  SmbusHc protocol implementation follows SMBus 2.0 specification.
+
+  Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Ppi/Smbus2.h>
+
+#include "SmbusHcCommon.h"
+
+/**
+  Executes an SMBus operation to an SMBus controller. Returns when either the command has been
+  executed or an error is encountered in doing the operation.
+
+  The Execute() function provides a standard way to execute an operation as defined in the System
+  Management Bus (SMBus) Specification. The resulting transaction will be either that the SMBus
+  slave devices accept this transaction or that this function returns with error.
+
+  @param  This                    A pointer to the EFI_PEI_SMBUS2_PPI instance.
+  @param  SlaveAddress            The SMBus slave address of the device with which to communicate.
+  @param  Command                 This command is transmitted by the SMBus host controller to the
+                                  SMBus slave device and the interpretation is SMBus slave device
+                                  specific. It can mean the offset to a list of functions inside an
+                                  SMBus slave device. Not all operations or slave devices support
+                                  this command's registers.
+  @param  Operation               Signifies which particular SMBus hardware protocol instance that
+                                  it will use to execute the SMBus transactions. This SMBus
+                                  hardware protocol is defined by the SMBus Specification and is
+                                  not related to EFI.
+  @param  PecCheck                Defines if Packet Error Code (PEC) checking is required for this
+                                  operation.
+  @param  Length                  Signifies the number of bytes that this operation will do. The
+                                  maximum number of bytes can be revision specific and operation
+                                  specific. This field will contain the actual number of bytes that
+                                  are executed for this operation. Not all operations require this
+                                  argument.
+  @param  Buffer                  Contains the value of data to execute to the SMBus slave device.
+                                  Not all operations require this argument. The length of this
+                                  buffer is identified by Length.
+
+  @retval EFI_SUCCESS             The last data that was returned from the access matched the poll
+                                  exit criteria.
+  @retval EFI_CRC_ERROR           Checksum is not correct (PEC is incorrect).
+  @retval EFI_TIMEOUT             Timeout expired before the operation was completed. Timeout is
+                                  determined by the SMBus host controller device.
+  @retval EFI_OUT_OF_RESOURCES    The request could not be completed due to a lack of resources.
+  @retval EFI_DEVICE_ERROR        The request was not completed because a failure that was
+                                  reflected in the Host Status Register bit. Device errors are a
+                                  result of a transaction collision, illegal command field,
+                                  unclaimed cycle (host initiated), or bus errors (collisions).
+  @retval EFI_INVALID_PARAMETER   Operation is not defined in EFI_SMBUS_OPERATION.
+  @retval EFI_INVALID_PARAMETER   Length/Buffer is NULL for operations except for EfiSmbusQuickRead
+                                  and EfiSmbusQuickWrite. Length is outside the range of valid
+                                  values.
+  @retval EFI_UNSUPPORTED         The SMBus operation or PEC is not supported.
+  @retval EFI_BUFFER_TOO_SMALL    Buffer is not sufficient for this operation.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcExecute (
+  IN CONST EFI_PEI_SMBUS2_PPI        *This,
+  IN       EFI_SMBUS_DEVICE_ADDRESS  SlaveAddress,
+  IN       EFI_SMBUS_DEVICE_COMMAND  Command,
+  IN       EFI_SMBUS_OPERATION       Operation,
+  IN       BOOLEAN                   PecCheck,
+  IN OUT   UINTN                     *Length,
+  IN OUT   VOID                      *Buffer
+  )
+{
+  ASSERT (This != NULL);
+  return SmbusHcCommonExecute (SlaveAddress, Command, Operation, PecCheck, Length, Buffer);
+}
+
+/**
+
+  The SmbusHcArpDevice() function provides a standard way for a device driver to
+  enumerate the entire SMBus or specific devices on the bus.
+
+  @param This           A pointer to the EFI_PEI_SMBUS2_PPI instance.
+
+  @param ArpAll         A Boolean expression that indicates if the
+                        host drivers need to enumerate all the devices
+                        or enumerate only the device that is
+                        identified by SmbusUdid. If ArpAll is TRUE,
+                        SmbusUdid and SlaveAddress are optional. If
+                        ArpAll is FALSE, ArpDevice will enumerate
+                        SmbusUdid and the address will be at
+                        SlaveAddress.
+
+  @param SmbusUdid      The Unique Device Identifier (UDID) that is
+                        associated with this device. Type
+                        EFI_SMBUS_UDID is defined in
+                        EFI_PEI_SMBUS_PPI.ArpDevice() in the
+                        Platform Initialization SMBus PPI
+                        Specification.
+
+  @param SlaveAddress   The SMBus slave address that is
+                        associated with an SMBus UDID.
+
+  @retval EFI_SUCCESS           The last data that was returned from the
+                                access matched the poll exit criteria.
+
+  @retval EFI_CRC_ERROR         Checksum is not correct (PEC is
+                                incorrect).
+
+  @retval EFI_TIMEOUT           Timeout expired before the operation was
+                                completed. Timeout is determined by the
+                                SMBus host controller device.
+
+  @retval EFI_OUT_OF_RESOURCES  The request could not be
+                                completed due to a lack of
+                                resources.
+
+  @retval EFI_DEVICE_ERROR      The request was not completed
+                                because a failure was reflected in
+                                the Host Status Register bit. Device
+                                Errors are a result of a transaction
+                                collision, illegal command field,
+                                unclaimed cycle (host initiated), or
+                                bus errors (collisions).
+
+  @retval EFI_UNSUPPORTED       ArpDevice, GetArpMap, and Notify are
+                                not implemented by this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcArpDevice (
+  IN CONST EFI_PEI_SMBUS2_PPI *This,
+  IN       BOOLEAN ArpAll,
+  IN       EFI_SMBUS_UDID *SmbusUdid, OPTIONAL
+  IN OUT   EFI_SMBUS_DEVICE_ADDRESS *SlaveAddress OPTIONAL
+  )
+{
+  //
+  // Not supported
+  //
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  The SmbusHcGetArpMap() function returns the mapping of all the SMBus devices
+  that were enumerated by the SMBus host driver.
+
+  @param This           A pointer to the EFI_PEI_SMBUS2_PPI instance.
+
+  @param Length         Size of the buffer that contains the SMBus
+                        device map.
+
+  @param SmbusDeviceMap The pointer to the device map as
+                        enumerated by the SMBus controller
+                        driver.
+
+  @retval EFI_SUCCESS       The SMBus returned the current device map.
+
+  @retval EFI_UNSUPPORTED   ArpDevice, GetArpMap, and Notify are
+                            not implemented by this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcGetArpMap (
+  IN CONST EFI_PEI_SMBUS2_PPI    *This,
+  IN OUT   UINTN                 *Length,
+  IN OUT   EFI_SMBUS_DEVICE_MAP  **SmbusDeviceMap
+  )
+{
+  //
+  // Not supported
+  //
+  return EFI_UNSUPPORTED;
+}
+
+/**
+
+  The SmbusHcNotify() function registers all the callback functions to
+  allow the bus driver to call these functions when the
+  SlaveAddress/Data pair happens.
+
+  @param  This            A pointer to the EFI_PEI_SMBUS2_PPI instance.
+
+  @param  SlaveAddress    Address that the host controller detects
+                          as sending a message and calls all the registered function.
+
+  @param  Data            Data that the host controller detects as sending
+                          message and calls all the registered function.
+
+
+  @param  NotifyFunction  The function to call when the bus
+                          driver detects the SlaveAddress and
+                          Data pair.
+
+  @retval EFI_SUCCESS       NotifyFunction was registered.
+
+  @retval EFI_UNSUPPORTED   ArpDevice, GetArpMap, and Notify are
+                            not implemented by this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+SmbusHcNotify (
+  IN CONST EFI_PEI_SMBUS2_PPI              *This,
+  IN       EFI_SMBUS_DEVICE_ADDRESS        SlaveAddress,
+  IN       UINTN                           Data,
+  IN       EFI_PEI_SMBUS_NOTIFY2_FUNCTION  NotifyFunction
+  )
+{
+  //
+  // Not supported
+  //
+  return EFI_UNSUPPORTED;
+}
+
+//
+// Interface defintion of SMBUS Host Controller Protocol.
+//
+EFI_PEI_SMBUS2_PPI  mSmbusHcPpi = {
+  SmbusHcExecute,
+  SmbusHcArpDevice,
+  SmbusHcGetArpMap,
+  SmbusHcNotify
+};
+
+EFI_PEI_PPI_DESCRIPTOR  gPpiSmbusHcPpiList = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  &gEfiPeiSmbus2PpiGuid,
+  &mSmbusHcPpi
+};
+
+/**
+  SmbusHc driver entry point
+
+  @param[in] ImageHandle          ImageHandle of this module
+  @param[in]  PeiServices         An indirect pointer to the PEI Services Table
+                                  published by the PEI Foundation.
+
+  @retval EFI_SUCCESS             Driver initializes successfully
+  @retval Other values            Some error occurred
+**/
+EFI_STATUS
+EFIAPI
+InitializeSmbusPeim (
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,
+  IN CONST EFI_PEI_SERVICES     **PeiServices
+  )
+{
+  EFI_STATUS  Status;
+
+  //
+  // Install Smbus Ppi
+  //
+  Status = PeiServicesInstallPpi (&gPpiSmbusHcPpiList);
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
+}
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120165): https://edk2.groups.io/g/devel/message/120165
Mute This Topic: https://groups.io/mt/107662237/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [edk2-devel] [edk2-platforms][PATCH 4/5] JadePkg: Add PlatformBmcReadyLib to support BMC ready check
  2024-08-01  9:36 [edk2-devel] [edk2-platforms][PATCH 0/5] Add IPMI SSIF support Nhi Pham via groups.io
                   ` (2 preceding siblings ...)
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 3/5] AmpereAltraPkg: Add SmbusHc PEI and DXE drivers Nhi Pham via groups.io
@ 2024-08-01  9:36 ` Nhi Pham via groups.io
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 5/5] Ampere/Jade: Enable IPMI SSIF Nhi Pham via groups.io
  4 siblings, 0 replies; 12+ messages in thread
From: Nhi Pham via groups.io @ 2024-08-01  9:36 UTC (permalink / raw)
  To: devel; +Cc: quic_llindhol, chuong, rebecca, nhi

This adds the PlatformBmcReadyLib library instance, which provides a
function to check whether the BMC is ready for transaction or not. The
function checks the GPIO pin specified by the PcdBmcReadyGpio PCD and
returns TRUE if the pin is set to a logic high level, indicating that
the BMC is ready.

Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
---
 Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.inf | 29 +++++++++++++++++++
 Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.c   | 30 ++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.inf b/Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.inf
new file mode 100755
index 000000000000..493178c3fc5e
--- /dev/null
+++ b/Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.inf
@@ -0,0 +1,29 @@
+## @file
+#
+# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001B
+  BASE_NAME                      = PlatformBmcReadyLib
+  FILE_GUID                      = D7D58480-96D5-4820-AC2D-472F4E0B9903
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = PlatformBmcReadyLib
+
+[Sources]
+  PlatformBmcReadyLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
+  Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec
+
+[LibraryClasses]
+  GpioLib
+
+[Pcd]
+  gAmpereTokenSpaceGuid.PcdBmcReadyGpio
diff --git a/Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.c b/Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.c
new file mode 100644
index 000000000000..b1712ff393c8
--- /dev/null
+++ b/Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.c
@@ -0,0 +1,30 @@
+/** @file
+
+  Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/GpioLib.h>
+#include <Library/PcdLib.h>
+
+/**
+  This function checks whether BMC is ready for transaction or not.
+
+  @retval TRUE   The BMC is ready.
+  @retval FALSE  The BMC is not ready.
+
+**/
+BOOLEAN
+EFIAPI
+PlatformBmcReady (
+  VOID
+  )
+{
+  //
+  // The BMC is considered ready if its GPIO pin is set to a logic high level.
+  //
+  return GpioReadBit (FixedPcdGet8 (PcdBmcReadyGpio)) == 0x1;
+}
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120166): https://edk2.groups.io/g/devel/message/120166
Mute This Topic: https://groups.io/mt/107662240/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [edk2-devel] [edk2-platforms][PATCH 5/5] Ampere/Jade: Enable IPMI SSIF
  2024-08-01  9:36 [edk2-devel] [edk2-platforms][PATCH 0/5] Add IPMI SSIF support Nhi Pham via groups.io
                   ` (3 preceding siblings ...)
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 4/5] JadePkg: Add PlatformBmcReadyLib to support BMC ready check Nhi Pham via groups.io
@ 2024-08-01  9:36 ` Nhi Pham via groups.io
  4 siblings, 0 replies; 12+ messages in thread
From: Nhi Pham via groups.io @ 2024-08-01  9:36 UTC (permalink / raw)
  To: devel; +Cc: quic_llindhol, chuong, rebecca, nhi

This adds the building of IPMI SSIf and associated modules.

Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
---
 Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc | 23 ++++++++++++++++++++
 Platform/Ampere/JadePkg/Jade.dsc                     |  2 ++
 Platform/Ampere/JadePkg/Jade.fdf                     | 17 +++++++++++++++
 3 files changed, 42 insertions(+)

diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc
index e9c97a353a98..6d4eedf513ea 100644
--- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc
+++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc
@@ -91,6 +91,7 @@ [LibraryClasses.common]
   GpioLib|Silicon/Ampere/AmpereAltraPkg/Library/DwGpioLib/DwGpioLib.inf
   MmCommunicationLib|Silicon/Ampere/AmpereAltraPkg/Library/MmCommunicationLib/MmCommunicationLib.inf
   FlashLib|Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/FlashLib.inf
+  ManageabilityTransportHelperLib|ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf
 
   #
   # ARM PL011 UART Driver
@@ -211,6 +212,10 @@ [LibraryClasses.common.PEIM]
   ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
   PeiServicesTablePointerLib|ArmPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
 
+  SmbusLib|MdePkg/Library/PeiSmbusLibSmbus2Ppi/PeiSmbusLibSmbus2Ppi.inf
+  IpmiLib|MdeModulePkg/Library/PeiIpmiLibIpmiPpi/PeiIpmiLibIpmiPpi.inf
+  ManageabilityTransportLib|ManageabilityPkg/Library/ManageabilityTransportSsifLib/Pei/PeiManageabilityTransportSsif.inf
+
 [LibraryClasses.common.SEC, LibraryClasses.common.PEIM]
   MemoryInitPeiLib|Silicon/Ampere/AmpereAltraPkg/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
@@ -264,6 +269,12 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER]
   AmpereCpuLib|Silicon/Ampere/AmpereAltraPkg/Library/AmpereCpuLib/RuntimeAmpereCpuLib.inf
   FlashLib|Silicon/Ampere/AmpereAltraPkg/Library/FlashLib/RuntimeFlashLib.inf
 
+[LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.UEFI_APPLICATION, LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.DXE_DRIVER]
+  SmbusLib|MdePkg/Library/DxeSmbusLib/DxeSmbusLib.inf
+  IpmiLib|MdeModulePkg/Library/DxeIpmiLibIpmiProtocol/DxeIpmiLibIpmiProtocol.inf
+  IpmiCommandLib|ManageabilityPkg/Library/IpmiCommandLib/IpmiCommandLib.inf
+  ManageabilityTransportLib|ManageabilityPkg/Library/ManageabilityTransportSsifLib/Dxe/DxeManageabilityTransportSsif.inf
+
 [LibraryClasses.ARM,LibraryClasses.AARCH64]
   #
   # It is not possible to prevent the ARM compiler for generic intrinsic functions.
@@ -547,6 +558,12 @@ [Components.common]
   MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
   Silicon/Ampere/AmpereAltraPkg/Drivers/BootProgress/BootProgressPeim/BootProgressPeim.inf
 
+  #
+  # IPMI SSIF
+  #
+  Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf
+  ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiPei.inf
+
   #
   # DXE Phase modules
   #
@@ -689,6 +706,12 @@ [Components.common]
   #
   Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.inf
 
+  #
+  # IPMI SSIF
+  #
+  Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf
+  ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocolDxe.inf
+
   #
   # Bds
   #
diff --git a/Platform/Ampere/JadePkg/Jade.dsc b/Platform/Ampere/JadePkg/Jade.dsc
index 1bd9f2ec1583..29d43f0d4a49 100644
--- a/Platform/Ampere/JadePkg/Jade.dsc
+++ b/Platform/Ampere/JadePkg/Jade.dsc
@@ -89,6 +89,8 @@ [LibraryClasses]
 
   OemMiscLib|Platform/Ampere/JadePkg/Library/OemMiscLib/OemMiscLib.inf
 
+  PlatformBmcReadyLib|Platform/Ampere/JadePkg/Library/PlatformBmcReadyLib/PlatformBmcReadyLib.inf
+
 ################################################################################
 #
 # Specific Platform Pcds
diff --git a/Platform/Ampere/JadePkg/Jade.fdf b/Platform/Ampere/JadePkg/Jade.fdf
index 2745ee44c20a..9cb0eed19271 100644
--- a/Platform/Ampere/JadePkg/Jade.fdf
+++ b/Platform/Ampere/JadePkg/Jade.fdf
@@ -146,6 +146,11 @@ [FV.FVMAIN_COMPACT]
   INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
   INF MdeModulePkg/Universal/ReportStatusCodeRouter/Pei/ReportStatusCodeRouterPei.inf
   INF MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
+  INF Silicon/Ampere/AmpereAltraPkg/Drivers/ATFHobPei/ATFHobPeim.inf
+  INF Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf
+  INF ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiPei.inf
+  INF Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.inf
+  INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
 }
 
   INF ArmPlatformPkg/PrePeiCore/PrePeiCoreUniCore.inf
@@ -164,6 +169,12 @@ [FV.FVMAIN_COMPACT]
   INF MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf
   INF Silicon/Ampere/AmpereAltraPkg/Drivers/PcieInitPei/PcieInitPei.inf
 
+  #
+  # IPMI SSIF
+  #
+  INF Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcPei.inf
+  INF ManageabilityPkg/Universal/IpmiProtocol/Pei/IpmiPpiPei.inf
+
   #
   # Print platform information before passing control into the Driver Execution Environment (DXE) phase
   #
@@ -311,6 +322,12 @@ [FV.FvMain]
   #
   INF Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.inf
 
+  #
+  # IPMI SSIF
+  #
+  INF Silicon/Ampere/AmpereAltraPkg/Drivers/SmbusHc/SmbusHcDxe.inf
+  INF ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocolDxe.inf
+
   #
   # UEFI application (Shell Embedded Boot Loader)
   #
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120167): https://edk2.groups.io/g/devel/message/120167
Mute This Topic: https://groups.io/mt/107662241/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 2/5] AmpereSiliconPkg: Define PCDs for SMBUS and BMC
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 2/5] AmpereSiliconPkg: Define PCDs for SMBUS and BMC Nhi Pham via groups.io
@ 2024-08-01 15:02   ` Leif Lindholm
  2024-08-05  3:18     ` Nhi Pham via groups.io
  0 siblings, 1 reply; 12+ messages in thread
From: Leif Lindholm @ 2024-08-01 15:02 UTC (permalink / raw)
  To: Nhi Pham; +Cc: devel, chuong, rebecca

On Thu, Aug 01, 2024 at 16:36:15 +0700, Nhi Pham wrote:
> This introduces fixed PCDs for SMBUS and BMC as specified to Ampere.
> 
> Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
> ---
>  Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
> index 56e8b2fd2f11..5c5015c1bf21 100644
> --- a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
> +++ b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
> @@ -69,6 +69,18 @@ [PcdsFixedAtBuild]
>    gAmpereTokenSpaceGuid.PcdSmbiosTables0MajorVersion|0xFF|UINT8|0x00000005
>    gAmpereTokenSpaceGuid.PcdSmbiosTables0MinorVersion|0xFF|UINT8|0x00000006
>  
> +  #
> +  # SMBUS
> +  #
> +  gAmpereTokenSpaceGuid.PcdSmbusI2cBusNumber|0x00|UINT8|0x00000007
> +  gAmpereTokenSpaceGuid.PcdSmbusI2cBusSpeed|100000|UINT32|0x00000008 # Hz
> +
> +  #
> +  # BMC
> +  #
> +  gAmpereTokenSpaceGuid.PcdBmcSlaveAddr|0x10|UINT8|0x00000009

Current Smbus specification uses controller/target terminology.

/
    Leif

> +  gAmpereTokenSpaceGuid.PcdBmcReadyGpio|0x18|UINT8|0x0000000A
> +
>  [PcdsFixedAtBuild, PcdsDynamic, PcdsDynamicEx]
>    #
>    # Firmware Volume Pcds
> -- 
> 2.25.1
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120180): https://edk2.groups.io/g/devel/message/120180
Mute This Topic: https://groups.io/mt/107662236/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function Nhi Pham via groups.io
@ 2024-08-01 15:14   ` Leif Lindholm
  2024-08-05  3:44     ` Nhi Pham via groups.io
  2024-08-01 15:18   ` Leif Lindholm
  1 sibling, 1 reply; 12+ messages in thread
From: Leif Lindholm @ 2024-08-01 15:14 UTC (permalink / raw)
  To: devel, nhi; +Cc: chuong, rebecca

On Thu, Aug 01, 2024 at 16:36:14 +0700, Nhi Pham via groups.io wrote:
> This adds the SmbusRead() function designed for SMBUS transaction to
> support the extraction of the data lenth byte from the initial byte of

length

> the SMBUS Block Read, allowing the I2C master to accurately read the
> SMBUS response with the exact data length. This addresses the issue
> where the SmbusLib:SmBusReadBlock() function consistently reads a
> 32-byte block of data.

Doh, I managed to start reviewing on 2/5 instead 1/5.
Regardless, since this is new code, please update to controller/target
terminology to match current versions of protocol specifications,
throughout the set.

> Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
> ---
>  Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h    |  31 +++++
>  Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c | 137 +++++++++++++++++++-
>  2 files changed, 163 insertions(+), 5 deletions(-)
> 
> diff --git a/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h b/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
> index f13794171029..d460f49efccb 100644
> --- a/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
> +++ b/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
> @@ -65,6 +65,37 @@ I2cRead (
>    IN OUT UINT32 *ReadLength
>    );
>  
> +/**
> +  SMBUS block read.
> +
> +  @param[in]     Bus          I2C bus Id.
> +  @param[in]     SlaveAddr    The address of slave device on the bus.
> +  @param[in]     BufCmd       Buffer where to send the command.
> +  @param[in]     CmdLength    Length of BufCmd.
> +  @param[in,out] Buf          Buffer where to put the read data to.
> +  @param[in,out] ReadLength   Pointer to length of buffer.
> +  @param[in]     PecCheck     If Packet Error Code (PEC) checking is required for this operation.
> +
> +  @retval EFI_SUCCESS            Read successfully.
> +  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
> +  @retval EFI_UNSUPPORTED        The bus is not supported.
> +  @retval EFI_NOT_READY          The device/bus is not ready.
> +  @retval EFI_TIMEOUT            Timeout when transferring data.
> +  @retval EFI_CRC_ERROR          There are errors on receiving data.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmbusRead (
> +  IN     UINT32  Bus,
> +  IN     UINT32  SlaveAddr,
> +  IN     UINT8   *BufCmd,
> +  IN     UINT32  CmdLength,
> +  IN OUT UINT8   *Buf,
> +  IN OUT UINT32  *ReadLength,
> +  IN     BOOLEAN PecCheck
> +  );
> +
>  /**
>   Setup new transaction with I2C slave device.
>  
> diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c b/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
> index 669ba2ea98a4..9e52ae69e7cd 100644
> --- a/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
> +++ b/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
> @@ -337,6 +337,11 @@ I2cWaitTxData (
>        DEBUG ((DEBUG_ERROR, "%a: Timeout waiting for TX buffer available\n", __FUNCTION__));
>        return EFI_TIMEOUT;
>      }
> +
> +    if ((I2cCheckErrors (Bus) & DW_IC_INTR_TX_ABRT) != 0) {
> +      return EFI_ABORTED;
> +    }
> +
>      MicroSecondDelay (mI2cBusList[Bus].PollingTime);
>    }
>  
> @@ -542,13 +547,61 @@ InternalI2cWrite (
>    return Status;
>  }
>  
> +EFI_STATUS
> +InternalSmbusReadDataLength (
> +  UINT32  Bus,
> +  UINT32 *Length
> +  )
> +{
> +  EFI_STATUS Status;
> +  UINTN      Base;
> +  UINT32     CmdSend;
> +
> +  Base = mI2cBusList[Bus].Base;
> +
> +  CmdSend = DW_IC_DATA_CMD_CMD;
> +  MmioWrite32 (Base + DW_IC_DATA_CMD, CmdSend);
> +  I2cSync ();
> +
> +  if (I2cCheckErrors (Bus) != 0) {
> +    DEBUG ((DEBUG_ERROR, "%a: Sending reading command error\n", __func__));
> +    return EFI_CRC_ERROR;
> +  }
> +
> +  Status = I2cWaitRxData (Bus);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Reading Smbus data length failed to wait data\n",
> +      __func__
> +      ));
> +
> +    if (Status != EFI_ABORTED) {
> +      MmioWrite32 (Base + DW_IC_DATA_CMD, DW_IC_DATA_CMD_STOP);
> +      I2cSync ();
> +    }
> +
> +    return Status;
> +  }
> +
> +  *Length = MmioRead32 (Base + DW_IC_DATA_CMD) & DW_IC_DATA_CMD_DAT_MASK;
> +  I2cSync ();
> +
> +  if (I2cCheckErrors (Bus) != 0) {
> +    DEBUG ((DEBUG_ERROR, "%a: Sending reading command error\n", __func__));
> +    return EFI_CRC_ERROR;
> +  }
> +  return EFI_SUCCESS;
> +}
> +
>  EFI_STATUS
>  InternalI2cRead (
>    UINT32  Bus,
> -  UINT8  *BufCmd,
> -  UINT32 CmdLength,
> -  UINT8  *Buf,
> -  UINT32 *Length
> +  UINT8   *BufCmd,
> +  UINT32  CmdLength,
> +  UINT8   *Buf,
> +  UINT32  *Length,
> +  BOOLEAN IsSmbus,

Can this really change on a per-transaction basis?
If not, can it move to a state held in DW_I2C_CONTEXT_T?

> +  BOOLEAN PecCheck

I guess the same question as above really.

/
    Leif

>    )
>  {
>    EFI_STATUS Status;
> @@ -559,6 +612,7 @@ InternalI2cRead (
>    UINTN      Count;
>    UINTN      ReadCount;
>    UINTN      WriteCount;
> +  UINT32     ResponseLen;
>  
>    Status = EFI_SUCCESS;
>    Base = mI2cBusList[Bus].Base;
> @@ -601,6 +655,36 @@ InternalI2cRead (
>    }
>  
>    WriteCount = 0;
> +  if (IsSmbus) {
> +    //
> +    // Read Smbus Data Length, first byte of the Smbus response data.
> +    //
> +    Status = InternalSmbusReadDataLength (Bus, &ResponseLen);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "%a: InternalSmbusReadDataLength failed\n", __func__));
> +      goto Exit;
> +    }
> +
> +    WriteCount++;
> +    Buf[ReadCount++] = ResponseLen;
> +
> +    //
> +    // Abort the transaction when the requested length is shorter than the actual response data
> +    // or if there is no response data when PEC disabled.
> +    //
> +    if ((*Length < (ResponseLen + 2)) || (!PecCheck && ResponseLen == 0)) {
> +      MmioWrite32 (Base + DW_IC_DATA_CMD, DW_IC_DATA_CMD_CMD | DW_IC_DATA_CMD_STOP);
> +      I2cSync ();
> +      Status = EFI_INVALID_PARAMETER;
> +      goto Exit;
> +    }
> +
> +    *Length = ResponseLen + 1; // Response Data Length + 8-bit Byte Count field
> +    if (PecCheck) {
> +      *Length += 1; // ++ 8-bit PEC field
> +    }
> +  }
> +
>    while ((*Length - ReadCount) != 0) {
>      TxLimit = mI2cBusList[Bus].TxFifo - MmioRead32 (Base + DW_IC_TXFLR);
>      RxLimit = mI2cBusList[Bus].RxFifo - MmioRead32 (Base + DW_IC_RXFLR);
> @@ -742,7 +826,50 @@ I2cRead (
>  
>    I2cSetSlaveAddr (Bus, SlaveAddr);
>  
> -  return InternalI2cRead (Bus, BufCmd, CmdLength, Buf, ReadLength);
> +  return InternalI2cRead (Bus, BufCmd, CmdLength, Buf, ReadLength, FALSE, FALSE);
> +}
> +
> +/**
> +  SMBUS block read.
> +
> +  @param[in]     Bus          I2C bus Id.
> +  @param[in]     SlaveAddr    The address of slave device on the bus.
> +  @param[in]     BufCmd       Buffer where to send the command.
> +  @param[in]     CmdLength    Length of BufCmd.
> +  @param[in,out] Buf          Buffer where to put the read data to.
> +  @param[in,out] ReadLength   Pointer to length of buffer.
> +  @param[in]     PecCheck     If Packet Error Code (PEC) checking is required for this operation.
> +
> +  @retval EFI_SUCCESS            Read successfully.
> +  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
> +  @retval EFI_UNSUPPORTED        The bus is not supported.
> +  @retval EFI_NOT_READY          The device/bus is not ready.
> +  @retval EFI_TIMEOUT            Timeout when transferring data.
> +  @retval EFI_CRC_ERROR          There are errors on receiving data.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmbusRead (
> +  IN     UINT32  Bus,
> +  IN     UINT32  SlaveAddr,
> +  IN     UINT8   *BufCmd,
> +  IN     UINT32  CmdLength,
> +  IN OUT UINT8   *Buf,
> +  IN OUT UINT32  *ReadLength,
> +  IN     BOOLEAN PecCheck
> +  )
> +{
> +  if (Bus >= AC01_I2C_MAX_BUS_NUM
> +      || Buf == NULL
> +      || ReadLength == NULL)
> +  {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  I2cSetSlaveAddr (Bus, SlaveAddr);
> +
> +  return InternalI2cRead (Bus, BufCmd, CmdLength, Buf, ReadLength, TRUE, PecCheck);
>  }
>  
>  /**
> -- 
> 2.25.1
> 
> 
> 
> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120181): https://edk2.groups.io/g/devel/message/120181
Mute This Topic: https://groups.io/mt/107662232/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function
  2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function Nhi Pham via groups.io
  2024-08-01 15:14   ` Leif Lindholm
@ 2024-08-01 15:18   ` Leif Lindholm
  2024-08-05  3:46     ` Nhi Pham via groups.io
  1 sibling, 1 reply; 12+ messages in thread
From: Leif Lindholm @ 2024-08-01 15:18 UTC (permalink / raw)
  To: devel, nhi; +Cc: chuong, rebecca

On Thu, Aug 01, 2024 at 16:36:14 +0700, Nhi Pham via groups.io wrote:
> This adds the SmbusRead() function designed for SMBUS transaction to
> support the extraction of the data lenth byte from the initial byte of
> the SMBUS Block Read, allowing the I2C master to accurately read the
> SMBUS response with the exact data length. This addresses the issue
> where the SmbusLib:SmBusReadBlock() function consistently reads a
> 32-byte block of data.

This change also changes the API to pass the PecCheck parameter,
without actuaklly using it for anyone. Regardless of my previous
comment, I don't think that's very useful.
So if you can't move it to the struct, can you move it to the later
patch instead?

/
    Leif

> Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
> ---
>  Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h    |  31 +++++
>  Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c | 137 +++++++++++++++++++-
>  2 files changed, 163 insertions(+), 5 deletions(-)
> 
> diff --git a/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h b/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
> index f13794171029..d460f49efccb 100644
> --- a/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
> +++ b/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
> @@ -65,6 +65,37 @@ I2cRead (
>    IN OUT UINT32 *ReadLength
>    );
>  
> +/**
> +  SMBUS block read.
> +
> +  @param[in]     Bus          I2C bus Id.
> +  @param[in]     SlaveAddr    The address of slave device on the bus.
> +  @param[in]     BufCmd       Buffer where to send the command.
> +  @param[in]     CmdLength    Length of BufCmd.
> +  @param[in,out] Buf          Buffer where to put the read data to.
> +  @param[in,out] ReadLength   Pointer to length of buffer.
> +  @param[in]     PecCheck     If Packet Error Code (PEC) checking is required for this operation.
> +
> +  @retval EFI_SUCCESS            Read successfully.
> +  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
> +  @retval EFI_UNSUPPORTED        The bus is not supported.
> +  @retval EFI_NOT_READY          The device/bus is not ready.
> +  @retval EFI_TIMEOUT            Timeout when transferring data.
> +  @retval EFI_CRC_ERROR          There are errors on receiving data.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmbusRead (
> +  IN     UINT32  Bus,
> +  IN     UINT32  SlaveAddr,
> +  IN     UINT8   *BufCmd,
> +  IN     UINT32  CmdLength,
> +  IN OUT UINT8   *Buf,
> +  IN OUT UINT32  *ReadLength,
> +  IN     BOOLEAN PecCheck
> +  );
> +
>  /**
>   Setup new transaction with I2C slave device.
>  
> diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c b/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
> index 669ba2ea98a4..9e52ae69e7cd 100644
> --- a/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
> +++ b/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
> @@ -337,6 +337,11 @@ I2cWaitTxData (
>        DEBUG ((DEBUG_ERROR, "%a: Timeout waiting for TX buffer available\n", __FUNCTION__));
>        return EFI_TIMEOUT;
>      }
> +
> +    if ((I2cCheckErrors (Bus) & DW_IC_INTR_TX_ABRT) != 0) {
> +      return EFI_ABORTED;
> +    }
> +
>      MicroSecondDelay (mI2cBusList[Bus].PollingTime);
>    }
>  
> @@ -542,13 +547,61 @@ InternalI2cWrite (
>    return Status;
>  }
>  
> +EFI_STATUS
> +InternalSmbusReadDataLength (
> +  UINT32  Bus,
> +  UINT32 *Length
> +  )
> +{
> +  EFI_STATUS Status;
> +  UINTN      Base;
> +  UINT32     CmdSend;
> +
> +  Base = mI2cBusList[Bus].Base;
> +
> +  CmdSend = DW_IC_DATA_CMD_CMD;
> +  MmioWrite32 (Base + DW_IC_DATA_CMD, CmdSend);
> +  I2cSync ();
> +
> +  if (I2cCheckErrors (Bus) != 0) {
> +    DEBUG ((DEBUG_ERROR, "%a: Sending reading command error\n", __func__));
> +    return EFI_CRC_ERROR;
> +  }
> +
> +  Status = I2cWaitRxData (Bus);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Reading Smbus data length failed to wait data\n",
> +      __func__
> +      ));
> +
> +    if (Status != EFI_ABORTED) {
> +      MmioWrite32 (Base + DW_IC_DATA_CMD, DW_IC_DATA_CMD_STOP);
> +      I2cSync ();
> +    }
> +
> +    return Status;
> +  }
> +
> +  *Length = MmioRead32 (Base + DW_IC_DATA_CMD) & DW_IC_DATA_CMD_DAT_MASK;
> +  I2cSync ();
> +
> +  if (I2cCheckErrors (Bus) != 0) {
> +    DEBUG ((DEBUG_ERROR, "%a: Sending reading command error\n", __func__));
> +    return EFI_CRC_ERROR;
> +  }
> +  return EFI_SUCCESS;
> +}
> +
>  EFI_STATUS
>  InternalI2cRead (
>    UINT32  Bus,
> -  UINT8  *BufCmd,
> -  UINT32 CmdLength,
> -  UINT8  *Buf,
> -  UINT32 *Length
> +  UINT8   *BufCmd,
> +  UINT32  CmdLength,
> +  UINT8   *Buf,
> +  UINT32  *Length,
> +  BOOLEAN IsSmbus,
> +  BOOLEAN PecCheck
>    )
>  {
>    EFI_STATUS Status;
> @@ -559,6 +612,7 @@ InternalI2cRead (
>    UINTN      Count;
>    UINTN      ReadCount;
>    UINTN      WriteCount;
> +  UINT32     ResponseLen;
>  
>    Status = EFI_SUCCESS;
>    Base = mI2cBusList[Bus].Base;
> @@ -601,6 +655,36 @@ InternalI2cRead (
>    }
>  
>    WriteCount = 0;
> +  if (IsSmbus) {
> +    //
> +    // Read Smbus Data Length, first byte of the Smbus response data.
> +    //
> +    Status = InternalSmbusReadDataLength (Bus, &ResponseLen);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "%a: InternalSmbusReadDataLength failed\n", __func__));
> +      goto Exit;
> +    }
> +
> +    WriteCount++;
> +    Buf[ReadCount++] = ResponseLen;
> +
> +    //
> +    // Abort the transaction when the requested length is shorter than the actual response data
> +    // or if there is no response data when PEC disabled.
> +    //
> +    if ((*Length < (ResponseLen + 2)) || (!PecCheck && ResponseLen == 0)) {
> +      MmioWrite32 (Base + DW_IC_DATA_CMD, DW_IC_DATA_CMD_CMD | DW_IC_DATA_CMD_STOP);
> +      I2cSync ();
> +      Status = EFI_INVALID_PARAMETER;
> +      goto Exit;
> +    }
> +
> +    *Length = ResponseLen + 1; // Response Data Length + 8-bit Byte Count field
> +    if (PecCheck) {
> +      *Length += 1; // ++ 8-bit PEC field
> +    }
> +  }
> +
>    while ((*Length - ReadCount) != 0) {
>      TxLimit = mI2cBusList[Bus].TxFifo - MmioRead32 (Base + DW_IC_TXFLR);
>      RxLimit = mI2cBusList[Bus].RxFifo - MmioRead32 (Base + DW_IC_RXFLR);
> @@ -742,7 +826,50 @@ I2cRead (
>  
>    I2cSetSlaveAddr (Bus, SlaveAddr);
>  
> -  return InternalI2cRead (Bus, BufCmd, CmdLength, Buf, ReadLength);
> +  return InternalI2cRead (Bus, BufCmd, CmdLength, Buf, ReadLength, FALSE, FALSE);
> +}
> +
> +/**
> +  SMBUS block read.
> +
> +  @param[in]     Bus          I2C bus Id.
> +  @param[in]     SlaveAddr    The address of slave device on the bus.
> +  @param[in]     BufCmd       Buffer where to send the command.
> +  @param[in]     CmdLength    Length of BufCmd.
> +  @param[in,out] Buf          Buffer where to put the read data to.
> +  @param[in,out] ReadLength   Pointer to length of buffer.
> +  @param[in]     PecCheck     If Packet Error Code (PEC) checking is required for this operation.
> +
> +  @retval EFI_SUCCESS            Read successfully.
> +  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
> +  @retval EFI_UNSUPPORTED        The bus is not supported.
> +  @retval EFI_NOT_READY          The device/bus is not ready.
> +  @retval EFI_TIMEOUT            Timeout when transferring data.
> +  @retval EFI_CRC_ERROR          There are errors on receiving data.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmbusRead (
> +  IN     UINT32  Bus,
> +  IN     UINT32  SlaveAddr,
> +  IN     UINT8   *BufCmd,
> +  IN     UINT32  CmdLength,
> +  IN OUT UINT8   *Buf,
> +  IN OUT UINT32  *ReadLength,
> +  IN     BOOLEAN PecCheck
> +  )
> +{
> +  if (Bus >= AC01_I2C_MAX_BUS_NUM
> +      || Buf == NULL
> +      || ReadLength == NULL)
> +  {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  I2cSetSlaveAddr (Bus, SlaveAddr);
> +
> +  return InternalI2cRead (Bus, BufCmd, CmdLength, Buf, ReadLength, TRUE, PecCheck);
>  }
>  
>  /**
> -- 
> 2.25.1
> 
> 
> 
> 
> 
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120182): https://edk2.groups.io/g/devel/message/120182
Mute This Topic: https://groups.io/mt/107662232/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 2/5] AmpereSiliconPkg: Define PCDs for SMBUS and BMC
  2024-08-01 15:02   ` Leif Lindholm
@ 2024-08-05  3:18     ` Nhi Pham via groups.io
  0 siblings, 0 replies; 12+ messages in thread
From: Nhi Pham via groups.io @ 2024-08-05  3:18 UTC (permalink / raw)
  To: devel, quic_llindhol; +Cc: chuong, rebecca

On 8/1/2024 10:02 PM, Leif Lindholm via groups.io wrote:
> On Thu, Aug 01, 2024 at 16:36:15 +0700, Nhi Pham wrote:
>> This introduces fixed PCDs for SMBUS and BMC as specified to Ampere.
>>
>> Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
>> ---
>>   Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
>> index 56e8b2fd2f11..5c5015c1bf21 100644
>> --- a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
>> +++ b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec
>> @@ -69,6 +69,18 @@ [PcdsFixedAtBuild]
>>     gAmpereTokenSpaceGuid.PcdSmbiosTables0MajorVersion|0xFF|UINT8|0x00000005
>>     gAmpereTokenSpaceGuid.PcdSmbiosTables0MinorVersion|0xFF|UINT8|0x00000006
>>   
>> +  #
>> +  # SMBUS
>> +  #
>> +  gAmpereTokenSpaceGuid.PcdSmbusI2cBusNumber|0x00|UINT8|0x00000007
>> +  gAmpereTokenSpaceGuid.PcdSmbusI2cBusSpeed|100000|UINT32|0x00000008 # Hz
>> +
>> +  #
>> +  # BMC
>> +  #
>> +  gAmpereTokenSpaceGuid.PcdBmcSlaveAddr|0x10|UINT8|0x00000009
> 
> Current Smbus specification uses controller/target terminology.
> 
> /
>      Leif

I will update in the next version, thanks Leif.

Regards,
Nhi


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120219): https://edk2.groups.io/g/devel/message/120219
Mute This Topic: https://groups.io/mt/107662236/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function
  2024-08-01 15:14   ` Leif Lindholm
@ 2024-08-05  3:44     ` Nhi Pham via groups.io
  0 siblings, 0 replies; 12+ messages in thread
From: Nhi Pham via groups.io @ 2024-08-05  3:44 UTC (permalink / raw)
  To: Leif Lindholm, devel; +Cc: chuong, rebecca

On 8/1/2024 10:14 PM, Leif Lindholm wrote:
> On Thu, Aug 01, 2024 at 16:36:14 +0700, Nhi Pham via groups.io wrote:
>> This adds the SmbusRead() function designed for SMBUS transaction to
>> support the extraction of the data lenth byte from the initial byte of
> 
> length

I will fix, thanks.

> 
>> the SMBUS Block Read, allowing the I2C master to accurately read the
>> SMBUS response with the exact data length. This addresses the issue
>> where the SmbusLib:SmBusReadBlock() function consistently reads a
>> 32-byte block of data.
> 
> Doh, I managed to start reviewing on 2/5 instead 1/5.
> Regardless, since this is new code, please update to controller/target
> terminology to match current versions of protocol specifications,
> throughout the set.

I will update, thanks.

> 
>> Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
>> ---
>>   Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h    |  31 +++++
>>   Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c | 137 +++++++++++++++++++-
>>   2 files changed, 163 insertions(+), 5 deletions(-)
>>
>> diff --git a/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h b/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
>> index f13794171029..d460f49efccb 100644
>> --- a/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
>> +++ b/Silicon/Ampere/AmpereAltraPkg/Include/Library/I2cLib.h
>> @@ -65,6 +65,37 @@ I2cRead (
>>     IN OUT UINT32 *ReadLength
>>     );
>>   
>> +/**
>> +  SMBUS block read.
>> +
>> +  @param[in]     Bus          I2C bus Id.
>> +  @param[in]     SlaveAddr    The address of slave device on the bus.
>> +  @param[in]     BufCmd       Buffer where to send the command.
>> +  @param[in]     CmdLength    Length of BufCmd.
>> +  @param[in,out] Buf          Buffer where to put the read data to.
>> +  @param[in,out] ReadLength   Pointer to length of buffer.
>> +  @param[in]     PecCheck     If Packet Error Code (PEC) checking is required for this operation.
>> +
>> +  @retval EFI_SUCCESS            Read successfully.
>> +  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
>> +  @retval EFI_UNSUPPORTED        The bus is not supported.
>> +  @retval EFI_NOT_READY          The device/bus is not ready.
>> +  @retval EFI_TIMEOUT            Timeout when transferring data.
>> +  @retval EFI_CRC_ERROR          There are errors on receiving data.
>> +
>> +**/
>> +EFI_STATUS
>> +EFIAPI
>> +SmbusRead (
>> +  IN     UINT32  Bus,
>> +  IN     UINT32  SlaveAddr,
>> +  IN     UINT8   *BufCmd,
>> +  IN     UINT32  CmdLength,
>> +  IN OUT UINT8   *Buf,
>> +  IN OUT UINT32  *ReadLength,
>> +  IN     BOOLEAN PecCheck
>> +  );
>> +
>>   /**
>>    Setup new transaction with I2C slave device.
>>   
>> diff --git a/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c b/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
>> index 669ba2ea98a4..9e52ae69e7cd 100644
>> --- a/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
>> +++ b/Silicon/Ampere/AmpereAltraPkg/Library/DwI2cLib/DwI2cLib.c
>> @@ -337,6 +337,11 @@ I2cWaitTxData (
>>         DEBUG ((DEBUG_ERROR, "%a: Timeout waiting for TX buffer available\n", __FUNCTION__));
>>         return EFI_TIMEOUT;
>>       }
>> +
>> +    if ((I2cCheckErrors (Bus) & DW_IC_INTR_TX_ABRT) != 0) {
>> +      return EFI_ABORTED;
>> +    }
>> +
>>       MicroSecondDelay (mI2cBusList[Bus].PollingTime);
>>     }
>>   
>> @@ -542,13 +547,61 @@ InternalI2cWrite (
>>     return Status;
>>   }
>>   
>> +EFI_STATUS
>> +InternalSmbusReadDataLength (
>> +  UINT32  Bus,
>> +  UINT32 *Length
>> +  )
>> +{
>> +  EFI_STATUS Status;
>> +  UINTN      Base;
>> +  UINT32     CmdSend;
>> +
>> +  Base = mI2cBusList[Bus].Base;
>> +
>> +  CmdSend = DW_IC_DATA_CMD_CMD;
>> +  MmioWrite32 (Base + DW_IC_DATA_CMD, CmdSend);
>> +  I2cSync ();
>> +
>> +  if (I2cCheckErrors (Bus) != 0) {
>> +    DEBUG ((DEBUG_ERROR, "%a: Sending reading command error\n", __func__));
>> +    return EFI_CRC_ERROR;
>> +  }
>> +
>> +  Status = I2cWaitRxData (Bus);
>> +  if (EFI_ERROR (Status)) {
>> +    DEBUG ((DEBUG_ERROR,
>> +      "%a: Reading Smbus data length failed to wait data\n",
>> +      __func__
>> +      ));
>> +
>> +    if (Status != EFI_ABORTED) {
>> +      MmioWrite32 (Base + DW_IC_DATA_CMD, DW_IC_DATA_CMD_STOP);
>> +      I2cSync ();
>> +    }
>> +
>> +    return Status;
>> +  }
>> +
>> +  *Length = MmioRead32 (Base + DW_IC_DATA_CMD) & DW_IC_DATA_CMD_DAT_MASK;
>> +  I2cSync ();
>> +
>> +  if (I2cCheckErrors (Bus) != 0) {
>> +    DEBUG ((DEBUG_ERROR, "%a: Sending reading command error\n", __func__));
>> +    return EFI_CRC_ERROR;
>> +  }
>> +  return EFI_SUCCESS;
>> +}
>> +
>>   EFI_STATUS
>>   InternalI2cRead (
>>     UINT32  Bus,
>> -  UINT8  *BufCmd,
>> -  UINT32 CmdLength,
>> -  UINT8  *Buf,
>> -  UINT32 *Length
>> +  UINT8   *BufCmd,
>> +  UINT32  CmdLength,
>> +  UINT8   *Buf,
>> +  UINT32  *Length,
>> +  BOOLEAN IsSmbus,
> 
> Can this really change on a per-transaction basis?
> If not, can it move to a state held in DW_I2C_CONTEXT_T?
> 
>> +  BOOLEAN PecCheck
> 
> I guess the same question as above really.
> 
> /
>      Leif

That makes sense, thanks Leif. I will pass IsSmbus and PecCheck in 
I2cProbe() and cache in the DW_I2C_CONTEXT_T.

Regards,
Nhi


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120220): https://edk2.groups.io/g/devel/message/120220
Mute This Topic: https://groups.io/mt/107662232/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function
  2024-08-01 15:18   ` Leif Lindholm
@ 2024-08-05  3:46     ` Nhi Pham via groups.io
  0 siblings, 0 replies; 12+ messages in thread
From: Nhi Pham via groups.io @ 2024-08-05  3:46 UTC (permalink / raw)
  To: devel, quic_llindhol; +Cc: chuong, rebecca

On 8/1/2024 10:18 PM, Leif Lindholm via groups.io wrote:
> On Thu, Aug 01, 2024 at 16:36:14 +0700, Nhi Pham via groups.io wrote:
>> This adds the SmbusRead() function designed for SMBUS transaction to
>> support the extraction of the data lenth byte from the initial byte of
>> the SMBUS Block Read, allowing the I2C master to accurately read the
>> SMBUS response with the exact data length. This addresses the issue
>> where the SmbusLib:SmBusReadBlock() function consistently reads a
>> 32-byte block of data.
> 
> This change also changes the API to pass the PecCheck parameter,
> without actuaklly using it for anyone. Regardless of my previous
> comment, I don't think that's very useful.
> So if you can't move it to the struct, can you move it to the later
> patch instead?
> 
> /
>      Leif
> 

I will try to split them out.

Regards,
Nhi


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120221): https://edk2.groups.io/g/devel/message/120221
Mute This Topic: https://groups.io/mt/107662232/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-08-05  3:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-01  9:36 [edk2-devel] [edk2-platforms][PATCH 0/5] Add IPMI SSIF support Nhi Pham via groups.io
2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 1/5] AmpereAltraPkg/DwI2cLib: Add SmbusRead() function Nhi Pham via groups.io
2024-08-01 15:14   ` Leif Lindholm
2024-08-05  3:44     ` Nhi Pham via groups.io
2024-08-01 15:18   ` Leif Lindholm
2024-08-05  3:46     ` Nhi Pham via groups.io
2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 2/5] AmpereSiliconPkg: Define PCDs for SMBUS and BMC Nhi Pham via groups.io
2024-08-01 15:02   ` Leif Lindholm
2024-08-05  3:18     ` Nhi Pham via groups.io
2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 3/5] AmpereAltraPkg: Add SmbusHc PEI and DXE drivers Nhi Pham via groups.io
2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 4/5] JadePkg: Add PlatformBmcReadyLib to support BMC ready check Nhi Pham via groups.io
2024-08-01  9:36 ` [edk2-devel] [edk2-platforms][PATCH 5/5] Ampere/Jade: Enable IPMI SSIF Nhi Pham via groups.io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox