public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "duke.zhai 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 31/33] AMD/VanGoghBoard: Check in AMD SmmControlPei module
Date: Thu, 18 Jan 2024 14:50:44 +0800	[thread overview]
Message-ID: <20240118065046.961-32-duke.zhai@amd.com> (raw)
In-Reply-To: <20240118065046.961-1-duke.zhai@amd.com>

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


BZ #:4640

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 (#114078): https://edk2.groups.io/g/devel/message/114078
Mute This Topic: https://groups.io/mt/103831201/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-19 14:58 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18  6:50 [edk2-devel] [PATCH 00/33] Introduce AMD Vangogh platform reference code duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 01/33] AMD/AmdPlatformPkg: Check in AMD S3 logo duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 02/33] AMD/VanGoghBoard: Check in ACPI tables duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 03/33] AMD/VanGoghBoard: Check in Capsule update duke.zhai via groups.io
2024-01-23  4:42   ` Chang, Abner via groups.io
2024-01-25  8:25     ` Zhai, MingXin (Duke) via groups.io
2024-01-25 11:45       ` Chang, Abner via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 04/33] AMD/VanGoghBoard: Check in AgesaPublic pkg duke.zhai via groups.io
2024-01-23  4:44   ` Chang, Abner via groups.io
2024-01-25  8:17     ` Xing, Eric via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 05/33] AMD/VanGoghBoard: Check in PlatformSecLib duke.zhai via groups.io
2024-01-23  4:46   ` Chang, Abner via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 06/33] AMD/VanGoghBoard: Check in AmdIdsExtLib duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 07/33] AMD/VanGoghBoard: Check in PciPlatform duke.zhai via groups.io
2024-01-23  4:50   ` Chang, Abner via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 08/33] AMD/VanGoghBoard: Check in UDKFlashUpdate duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 09/33] AMD/VanGoghBoard: Check in Flash_AB duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 10/33] AMD/VanGoghBoard: Check in FlashUpdate duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 11/33] AMD/VanGoghBoard: Check in FvbServices duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 12/33] AMD/VanGoghBoard: Check in AMD BaseSerialPortLib duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 13/33] AMD/VanGoghBoard: Check in PlatformFlashAccessLib duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 14/33] AMD/VanGoghBoard: Check in SmbiosLib duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 15/33] AMD/VanGoghBoard: Check in SpiFlashDeviceLib duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 16/33] AMD/VanGoghBoard: Check in BaseTscTimerLib duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 17/33] AMD/VanGoghBoard: Check in Smm access module duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 18/33] AMD/VanGoghBoard: Check in PciHostBridge module duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 19/33] AMD/VanGoghBoard: Check in PcatRealTimeClockRuntimeDxe module duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 20/33] AMD/VanGoghBoard: Check in FTPM module duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 21/33] AMD/VanGoghBoard: Check in SignedCapsule duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 22/33] AMD/VanGoghBoard: Check in Vtf0 duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 23/33] AMD/VanGoghBoard: Check in AcpiPlatform duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 24/33] AMD/VanGoghBoard: Check in FchSpi module duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 25/33] AMD/VanGoghBoard: Check in PlatformInitPei module duke.zhai via groups.io
2024-01-23  6:35   ` Chang, Abner via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 26/33] AMD/VanGoghBoard: Check in Smbios platform dxe drivers duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 27/33] AMD/VanGoghBoard: Check in Fsp2WrapperPkg duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 28/33] AMD/VanGoghBoard: Check in SmmCpuFeaturesLibCommon module duke.zhai via groups.io
2024-01-23  5:14   ` Chang, Abner via groups.io
2024-01-23 10:20     ` Xing, Eric via groups.io
2024-01-23 10:44       ` Chang, Abner via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 29/33] AMD/VanGoghBoard: Check in SmramSaveState module duke.zhai via groups.io
2024-01-20 14:37   ` Abdul Lateef Attar via groups.io
2024-01-23  5:15     ` Chang, Abner via groups.io
2024-01-23 10:27       ` Xing, Eric via groups.io
2024-01-23 10:44         ` Chang, Abner via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 30/33] AMD/VanGoghBoard: Check in EDK2 override files duke.zhai via groups.io
2024-01-18  6:50 ` duke.zhai via groups.io [this message]
2024-01-18  6:50 ` [edk2-devel] [PATCH 32/33] AMD/VanGoghBoard: Check in Chachani board project files and build script duke.zhai via groups.io
2024-01-18  6:50 ` [edk2-devel] [PATCH 33/33] AMD/VanGoghBoard: Improvement coding style duke.zhai 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=20240118065046.961-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