public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Zhai, MingXin (Duke) via groups.io" <duke.zhai=amd.com@groups.io>
To: <devel@edk2.groups.io>
Cc: Eric Xing <eric.xing@amd.com>, Ken Yao <ken.yao@amd.com>,
	Igniculus Fu <igniculus.fu@amd.com>,
	Abner Chang <abner.chang@amd.com>
Subject: [edk2-devel] [PATCH V3 31/32] AMD/VanGoghBoard: Check in AMD SmmControlPei module
Date: Fri, 26 Jan 2024 21:11:24 +0800	[thread overview]
Message-ID: <20240126131125.1881-32-duke.zhai@amd.com> (raw)
In-Reply-To: <20240126131125.1881-1-duke.zhai@amd.com>

From: Duke Zhai <Duke.Zhai@amd.com>

BZ #:4640
In V2: Improve coding style.
  1.Remove the leading underscore and use double underscore at trailing in C header files.
  2.Remove old tianocore licenses and redundant license description.
  3.Improve coding style. For example: remove space between @param.

In V1:
  Initial AMD SmmControlPei module in Silicon folder.
  This module initializes SMM-related registers, and installs gPeiSmmControlPpi.

Signed-off-by: Duke Zhai <duke.zhai@amd.com>
Cc: Eric Xing <eric.xing@amd.com>
Cc: Ken Yao <ken.yao@amd.com>
Cc: Igniculus Fu <igniculus.fu@amd.com>
Cc: Abner Chang <abner.chang@amd.com>
---
 .../Smm/SmmControlPei/SmmControlPei.c         | 307 ++++++++++++++++++
 .../Smm/SmmControlPei/SmmControlPei.inf       |  40 +++
 2 files changed, 347 insertions(+)
 create mode 100644 Silicon/AMD/VanGoghBoard/Smm/SmmControlPei/SmmControlPei.c
 create mode 100644 Silicon/AMD/VanGoghBoard/Smm/SmmControlPei/SmmControlPei.inf

diff --git a/Silicon/AMD/VanGoghBoard/Smm/SmmControlPei/SmmControlPei.c b/Silicon/AMD/VanGoghBoard/Smm/SmmControlPei/SmmControlPei.c
new file mode 100644
index 0000000000..4752aede9c
--- /dev/null
+++ b/Silicon/AMD/VanGoghBoard/Smm/SmmControlPei/SmmControlPei.c
@@ -0,0 +1,307 @@
+/** @file
+  Implements SmmControlPei.c
+
+  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Ppi/SmmControl.h>
+#include <Include/FchRegistersCommon.h>
+
+/**
+  This routine generates an SMI
+
+  @param[in]       PeiServices           Describes the list of possible PEI Services.
+  @param[in]       This                  The pointer to this instance of this PPI.
+  @param[in, out]  ArgumentBuffer        The buffer of argument
+  @param[in, out]  ArgumentBufferSize    The size of the argument buffer
+  @param[in]       Periodic              TRUE to indicate a periodical SMI
+  @param[in]       ActivationInterval    Interval of periodic SMI
+
+  @retval  EFI_SUCCESS            SMI generated.
+  @retval  EFI_INVALID_PARAMETER  Some parameter value passed is not supported
+**/
+EFI_STATUS
+EFIAPI
+PeiTrigger (
+  IN     EFI_PEI_SERVICES     **PeiServices,
+  IN     PEI_SMM_CONTROL_PPI  *This,
+  IN OUT INT8                 *ArgumentBuffer OPTIONAL,
+  IN OUT UINTN                *ArgumentBufferSize OPTIONAL,
+  IN     BOOLEAN              Periodic OPTIONAL,
+  IN     UINTN                ActivationInterval OPTIONAL
+  );
+
+/**
+  Clear SMI related chipset status.
+
+  @param[in]  PeiServices           Describes the list of possible PEI Services.
+  @param[in]  This                  The pointer to this instance of this PPI.
+  @param[in]  Periodic              TRUE to indicate a periodical SMI.
+
+  @return  Return value from ClearSmi()
+**/
+EFI_STATUS
+EFIAPI
+PeiClear (
+  IN EFI_PEI_SERVICES     **PeiServices,
+  IN PEI_SMM_CONTROL_PPI  *This,
+  IN BOOLEAN              Periodic OPTIONAL
+  );
+
+STATIC PEI_SMM_CONTROL_PPI  mSmmControlPpi = {
+  PeiTrigger,
+  PeiClear
+};
+
+STATIC EFI_PEI_PPI_DESCRIPTOR  mPpiList = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  &gPeiSmmControlPpiGuid,
+  &mSmmControlPpi
+};
+
+/**
+ Init related registers
+
+ @param [in]        None
+
+ @retval  EFI_LOAD_ERROR  Get ACPI MMIO base error.
+ @retval  EFI_SUCCESS     The function completed successfully..
+*/
+EFI_STATUS
+SmmControlPeiPreInit (
+  VOID
+  )
+{
+  UINT16  SmmControlData16;
+  UINT16  SmmControlMask16;
+  UINT32  SmmControlData32;
+  UINT8   SmmControlIndex;
+  UINT16  AcpiPmBase;
+
+  //
+  // Get ACPI MMIO base and AcpiPm1EvtBlk address
+  //
+  AcpiPmBase = MmioRead16 (ACPI_MMIO_BASE + PMIO_BASE + FCH_PMIOA_REG60);
+
+  if (0 == AcpiPmBase) {
+    return EFI_LOAD_ERROR;
+  }
+
+  //
+  // Clean up all SMI status and enable bits
+  //
+  // Clear all SmiControl registers
+  SmmControlData32 = 0;
+  for (SmmControlIndex = FCH_SMI_REGA0; SmmControlIndex <= FCH_SMI_REGC4; SmmControlIndex += 4) {
+    MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + SmmControlIndex, SmmControlData32);
+  }
+
+  // Clear all SmiStatus registers (SmiStatus0-4)
+  SmmControlData32 = 0xFFFFFFFF;
+  MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG80, SmmControlData32);
+  MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG84, SmmControlData32);
+  MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG88, SmmControlData32);
+  MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG8C, SmmControlData32);
+  MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG90, SmmControlData32);
+
+  //
+  // If SCI is not enabled, clean up all ACPI PM status/enable registers
+  //
+  SmmControlData16 = IoRead16 (AcpiPmBase + R_FCH_ACPI_PM_CONTROL);
+  if (!(SmmControlData16 & BIT0)) {
+    // Clear WAKE_EN, RTC_EN, SLPBTN_EN, GBL_EN and TMR_EN
+    SmmControlData16 = 0;
+    SmmControlMask16 = (UINT16) ~(BIT15 + BIT10 + BIT9 + BIT5 + BIT0);
+    IoAndThenOr16 (AcpiPmBase + R_FCH_ACPI_PM1_ENABLE, SmmControlMask16, SmmControlData16);
+
+    // Clear WAKE_STS, RTC_STS, SLPBTN_STS, GBL_STS and TMR_STS
+    SmmControlData16 = BIT15 + BIT10 + BIT9 + BIT5 + BIT0;
+    IoWrite16 (AcpiPmBase + R_FCH_ACPI_PM1_STATUS, SmmControlData16);
+  }
+
+  //
+  // Set the EOS Bit
+  // Clear SmiEnB to enable SMI function
+  //
+  SmmControlData32  = MmioRead32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG98);
+  SmmControlData32 |= BIT28;
+  SmmControlData32 &= ~BIT31;
+  MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG98, SmmControlData32);
+
+  //
+  // Enable CmdPort SMI
+  //
+  SmmControlData32  = MmioRead32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REGB0);
+  SmmControlData32 &= ~(BIT22 + BIT23);
+  SmmControlData32 |= BIT22;
+  MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REGB0, SmmControlData32);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Clear the SMI status
+
+
+  @retval EFI_SUCCESS             The function completes successfully
+**/
+EFI_STATUS
+ClearSmi (
+  VOID
+  )
+{
+  UINT32  SmmControlData32;
+
+  //
+  // Clear SmiCmdPort Status Bit
+  //
+  SmmControlData32 = BIT11;
+  MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG88, SmmControlData32);
+
+  //
+  // Set the EOS Bit if it is currently cleared so we can get an SMI otherwise
+  // leave the register alone
+  //
+  SmmControlData32 = MmioRead32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG98);
+  if ((SmmControlData32 & BIT28) == 0) {
+    SmmControlData32 |= BIT28;
+    MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REG98, SmmControlData32);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  This routine generates an SMI
+
+  @param[in]       PeiServices           Describes the list of possible PEI Services.
+  @param[in]       This                  The pointer to this instance of this PPI.
+  @param[in, out]  ArgumentBuffer        The buffer of argument
+  @param[in, out]  ArgumentBufferSize    The size of the argument buffer
+  @param[in]       Periodic              TRUE to indicate a periodical SMI
+  @param[in]       ActivationInterval    Interval of periodic SMI
+
+  @retval  EFI_SUCCESS            SMI generated.
+  @retval  EFI_INVALID_PARAMETER  Some parameter value passed is not supported
+**/
+EFI_STATUS
+EFIAPI
+PeiTrigger (
+  IN     EFI_PEI_SERVICES     **PeiServices,
+  IN     PEI_SMM_CONTROL_PPI  *This,
+  IN OUT INT8                 *ArgumentBuffer OPTIONAL,
+  IN OUT UINTN                *ArgumentBufferSize OPTIONAL,
+  IN     BOOLEAN              Periodic OPTIONAL,
+  IN     UINTN                ActivationInterval OPTIONAL
+  )
+{
+  UINT8   bIndex;
+  UINT8   bData;
+  UINT32  SmmControlData32;
+  UINT16  SmiCmdPort;
+
+  if (Periodic) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (NULL == ArgumentBuffer) {
+    bIndex = 0xff;
+  } else {
+    bIndex = *ArgumentBuffer;
+  }
+
+  if (NULL == ArgumentBufferSize) {
+    bData = 0xff;
+  } else {
+    bData = (UINT8)*ArgumentBufferSize;
+  }
+
+  //
+  // Enable CmdPort SMI
+  //
+  SmmControlData32  = MmioRead32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REGB0);
+  SmmControlData32 &= ~(BIT22 + BIT23);
+  SmmControlData32 |= BIT22;
+  MmioWrite32 (ACPI_MMIO_BASE + SMI_BASE + FCH_SMI_REGB0, SmmControlData32);
+
+  SmiCmdPort = PcdGet16 (PcdAmdFchCfgSmiCmdPortAddr);
+
+  //
+  // Issue command port SMI
+  //
+  IoWrite16 (SmiCmdPort, (bData << 8) + bIndex);
+  return EFI_SUCCESS;
+}
+
+/**
+  Clear SMI related chipset status.
+
+  @param[in]  PeiServices           Describes the list of possible PEI Services.
+  @param[in]  This                  The pointer to this instance of this PPI.
+  @param[in]  Periodic              TRUE to indicate a periodical SMI.
+
+  @return  Return value from ClearSmi()
+**/
+EFI_STATUS
+EFIAPI
+PeiClear (
+  IN EFI_PEI_SERVICES     **PeiServices,
+  IN PEI_SMM_CONTROL_PPI  *This,
+  IN BOOLEAN              Periodic OPTIONAL
+  )
+{
+  if (Periodic) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  return ClearSmi ();
+}
+
+/**
+  This is the constructor for the SMM Control Ppi.
+
+  This function installs PEI_SMM_CONTROL_PPI.
+
+  @param   FileHandle       Handle of the file being invoked.
+  @param   PeiServices      Describes the list of possible PEI Services.
+
+  @retval EFI_UNSUPPORTED There's no Intel ICH on this platform
+  @return The status returned from PeiServicesInstallPpi().
+
+--*/
+EFI_STATUS
+SmmControlPeiEntry (
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,
+  IN CONST EFI_PEI_SERVICES     **PeiServices
+  )
+{
+  EFI_STATUS     Status;
+  EFI_BOOT_MODE  BootMode;
+
+  Status = PeiServicesGetBootMode (&BootMode);
+  ASSERT_EFI_ERROR (Status);
+
+  DEBUG ((DEBUG_INFO, "PeiSmmControl Enter\n"));
+
+  if (BootMode != BOOT_ON_S3_RESUME) {
+    return EFI_UNSUPPORTED;
+  }
+
+  //
+  // Initialize EFI library
+  //
+  Status = SmmControlPeiPreInit ();
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = PeiServicesInstallPpi (&mPpiList);
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
+}
diff --git a/Silicon/AMD/VanGoghBoard/Smm/SmmControlPei/SmmControlPei.inf b/Silicon/AMD/VanGoghBoard/Smm/SmmControlPei/SmmControlPei.inf
new file mode 100644
index 0000000000..d6c984f02a
--- /dev/null
+++ b/Silicon/AMD/VanGoghBoard/Smm/SmmControlPei/SmmControlPei.inf
@@ -0,0 +1,40 @@
+## @file
+# AMD Smm Contro lPei
+#
+# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = PeiSmmControl
+  FILE_GUID                      = EC9519B1-E788-4C45-B695-244457442D64
+  MODULE_TYPE                    = PEIM
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = SmmControlPeiEntry
+
+[Sources.common]
+  SmmControlPei.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  AgesaPublic/AgesaPublic.dec
+
+[LibraryClasses]
+  IoLib
+  DebugLib
+  PeiServicesLib
+  PeimEntryPoint
+
+[Guids]
+
+[Pcd]
+  gEfiAmdAgesaPkgTokenSpaceGuid.PcdAmdFchCfgSmiCmdPortAddr      ## CONSUMES
+
+[Ppis]
+  gPeiSmmControlPpiGuid            #PRODUCED
+
+[Depex]
+  gEfiPeiMasterBootModePpiGuid
-- 
2.31.1



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



  parent reply	other threads:[~2024-01-26 13:13 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26 13:10 [edk2-devel] [PATCH V3 00/32] Introduce AMD Vangogh platform reference code Zhai, MingXin (Duke) via groups.io
2024-01-26 13:10 ` [edk2-devel] [PATCH V3 01/32] AMD/AmdPlatformPkg: Check in AMD S3 logo Zhai, MingXin (Duke) via groups.io
2024-01-29 10:37   ` Chang, Abner via groups.io
2024-01-29 10:42     ` Zhai, MingXin (Duke) via groups.io
2024-01-29 10:59       ` Chang, Abner via groups.io
2024-01-26 13:10 ` [edk2-devel] [PATCH V3 02/32] AMD/VanGoghBoard: Check in ACPI tables Zhai, MingXin (Duke) via groups.io
2024-01-26 13:10 ` [edk2-devel] [PATCH V3 03/32] AMD/VanGoghBoard: Check in Capsule update Zhai, MingXin (Duke) via groups.io
2024-01-26 13:10 ` [edk2-devel] [PATCH V3 04/32] AMD/VanGoghBoard: Check in AgesaPublicPkg Zhai, MingXin (Duke) via groups.io
2024-01-26 13:10 ` [edk2-devel] [PATCH V3 05/32] AMD/VanGoghBoard: Check in PlatformSecLib Zhai, MingXin (Duke) via groups.io
2024-01-26 13:10 ` [edk2-devel] [PATCH V3 06/32] AMD/VanGoghBoard: Check in AmdIdsExtLib Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 07/32] AMD/VanGoghBoard: Check in PciPlatform Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 08/32] AMD/VanGoghBoard: Check in UDKFlashUpdate Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 09/32] AMD/VanGoghBoard: Check in Flash_AB Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 10/32] AMD/VanGoghBoard: Check in FlashUpdate Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 11/32] AMD/VanGoghBoard: Check in FvbServices Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 12/32] AMD/VanGoghBoard: Check in AMD BaseSerialPortLib Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 13/32] AMD/VanGoghBoard: Check in PlatformFlashAccessLib Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 14/32] AMD/VanGoghBoard: Check in SmbiosLib Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 15/32] AMD/VanGoghBoard: Check in SpiFlashDeviceLib Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 16/32] AMD/VanGoghBoard: Check in BaseTscTimerLib Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 17/32] AMD/VanGoghBoard: Check in Smm access module Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 18/32] AMD/VanGoghBoard: Check in PciHostBridge module Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 19/32] AMD/VanGoghBoard: Check in PcatRealTimeClockRuntimeDxe module Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 20/32] AMD/VanGoghBoard: Check in FTPM module Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 21/32] AMD/VanGoghBoard: Check in SignedCapsule Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 22/32] AMD/VanGoghBoard: Check in Vtf0 Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 23/32] AMD/VanGoghBoard: Check in AcpiPlatform Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 24/32] AMD/VanGoghBoard: Check in FchSpi module Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 25/32] AMD/VanGoghBoard: Check in PlatformInitPei module Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 26/32] AMD/VanGoghBoard: Check in Smbios platform dxe drivers Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 27/32] AMD/VanGoghBoard: Check in Fsp2WrapperPkg Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 28/32] AMD/VanGoghBoard: Check in SmmCpuFeaturesLibCommon module Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 29/32] AMD/VanGoghBoard: Check in SmramSaveState module Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 30/32] AMD/VanGoghBoard: Check in EDK2 override files Zhai, MingXin (Duke) via groups.io
2024-01-26 13:11 ` Zhai, MingXin (Duke) via groups.io [this message]
2024-01-26 13:11 ` [edk2-devel] [PATCH V3 32/32] AMD/VanGoghBoard: Check in Chachani board project files and build script Zhai, MingXin (Duke) via groups.io
2024-01-26 13:30 ` [edk2-devel] [PATCH V3 00/32] Introduce AMD Vangogh platform reference code Chang, Abner via groups.io
2024-01-29  3:23   ` Zhai, MingXin (Duke) via groups.io
2024-01-29  4:46     ` Chang, Abner via groups.io

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240126131125.1881-32-duke.zhai@amd.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox