public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Nate DeSimone" <nathaniel.l.desimone@intel.com>
To: devel@edk2.groups.io
Cc: Isaac Oram <isaac.w.oram@intel.com>,
	Sai Chaganty <rangasai.v.chaganty@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Michael Kubacki <michael.kubacki@microsoft.com>
Subject: [edk2-platforms] [PATCH v1 7/9] IpmiFeaturePkg: Add GenericIpmi SMM Driver
Date: Mon,  1 Mar 2021 18:28:02 -0800	[thread overview]
Message-ID: <20210302022804.8641-8-nathaniel.l.desimone@intel.com> (raw)
In-Reply-To: <20210302022804.8641-1-nathaniel.l.desimone@intel.com>

From: Isaac Oram <isaac.w.oram@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3242

Adds the SMM version of the generic
IPMI transport driver.

Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Michael Kubacki <michael.kubacki@microsoft.com>
Signed-off-by: Isaac Oram <isaac.w.oram@intel.com>
Co-authored-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
---
 .../GenericIpmi/Smm/SmmGenericIpmi.c          | 208 ++++++++++++++++++
 .../GenericIpmi/Smm/SmmGenericIpmi.inf        |  53 +++++
 2 files changed, 261 insertions(+)
 create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/GenericIpmi/Smm/SmmGenericIpmi.c
 create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/GenericIpmi/Smm/SmmGenericIpmi.inf

diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/GenericIpmi/Smm/SmmGenericIpmi.c b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/GenericIpmi/Smm/SmmGenericIpmi.c
new file mode 100644
index 0000000000..fda215baaa
--- /dev/null
+++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/GenericIpmi/Smm/SmmGenericIpmi.c
@@ -0,0 +1,208 @@
+/** @file
+  Generic SMM IPMI stack driver
+
+  @copyright
+  Copyright 1999 - 2021 Intel Corporation. <BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+//
+// Statements that include other files
+//
+#include <IndustryStandard/Ipmi.h>
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/SmmLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/IpmiBaseLib.h>
+#include <SmStatusCodes.h>
+#include "IpmiHooks.h"
+#include "IpmiBmcCommon.h"
+#include "IpmiBmc.h"
+#include <Library/TimerLib.h>
+
+IPMI_BMC_INSTANCE_DATA             *mIpmiInstance;
+EFI_HANDLE                         mImageHandle;
+
+
+EFI_STATUS
+GetDeviceId (
+  IN      IPMI_BMC_INSTANCE_DATA       *IpmiInstance,
+  IN      EFI_STATUS_CODE_VALUE        StatusCodeValue[ ],
+  IN OUT  UINT8                        *ErrorCount
+  )
+/*++
+
+Routine Description:
+  Execute the Get Device ID command to determine whether or not the BMC is in Force Update
+  Mode.  If it is, then report it to the error manager.
+
+Arguments:
+  IpmiInstance    - Data structure describing BMC variables and used for sending commands
+  StatusCodeValue - An array used to accumulate error codes for later reporting.
+  ErrorCount      - Counter used to keep track of error codes in StatusCodeValue
+
+Returns:
+  Status
+
+--*/
+{
+  EFI_STATUS               Status;
+  UINT32                   DataSize;
+  SM_CTRL_INFO             *ControllerInfo;
+  UINT8                    TimeOut;
+  UINT8                    Retries;
+
+  TimeOut = 0;
+  Retries = PcdGet8 (PcdIpmiBmcReadyDelayTimer);
+
+  do {
+    //
+    // Get the device ID information for the BMC.
+    //
+    DataSize = MAX_TEMP_DATA;
+    Status = IpmiSendCommand (
+               &IpmiInstance->IpmiTransport,
+               IPMI_NETFN_APP,
+               0,
+               IPMI_APP_GET_DEVICE_ID,
+               NULL,
+               0,
+               IpmiInstance->TempData,
+               &DataSize
+               );
+    if (Status == EFI_SUCCESS) {
+      DEBUG ((EFI_D_INFO, "IPMI: SendCommand success!\n"));
+      break;
+    } else {
+      //
+      // Display message and retry.
+      //
+      DEBUG (
+        (EFI_D_ERROR | EFI_D_INFO,
+         "IPMI: Waiting for BMC (KCS 0x%x)...\n",
+         IpmiInstance->IpmiIoBase)
+        );
+      MicroSecondDelay (500 * 1000);
+      TimeOut++;
+    }
+  } while (TimeOut < Retries);
+
+  //
+  // If there is no error then proceed to check the data returned by the BMC
+  //
+  if (!EFI_ERROR (Status)) {
+    ControllerInfo = (SM_CTRL_INFO *) IpmiInstance->TempData;
+    //
+    // If the controller is in Update Mode and the maximum number of errors has not been exceeded, then
+    // save the error code to the StatusCode array and increment the counter.  Set the BMC Status to indicate
+    // the BMC is in force update mode.
+    //
+    if (ControllerInfo->UpdateMode != 0) {
+      IpmiInstance->BmcStatus = BMC_UPDATE_IN_PROGRESS;
+      if (*ErrorCount < MAX_SOFT_COUNT) {
+        StatusCodeValue[*ErrorCount] = EFI_COMPUTING_UNIT_FIRMWARE_PROCESSOR | CU_FP_EC_FORCE_UPDATE_MODE;
+        (*ErrorCount)++;
+      }
+    }
+  }
+
+  return Status;
+}
+
+EFI_STATUS
+SmmInitializeIpmiKcsPhysicalLayer (
+  IN EFI_HANDLE             ImageHandle,
+  IN EFI_SYSTEM_TABLE       *SystemTable
+  )
+/*++
+
+Routine Description:
+  Setup and initialize the BMC for the DXE phase.  In order to verify the BMC is functioning
+  as expected, the BMC Selftest is performed.  The results are then checked and any errors are
+  reported to the error manager.  Errors are collected throughout this routine and reported
+  just prior to installing the driver.  If there are more errors than MAX_SOFT_COUNT, then they
+  will be ignored.
+
+Arguments:
+  ImageHandle - Handle of this driver image
+  SystemTable - Table containing standard EFI services
+
+Returns:
+  EFI_SUCCESS - Successful driver initialization
+
+--*/
+{
+  EFI_STATUS                       Status;
+  UINT8                            ErrorCount;
+  EFI_HANDLE                       Handle;
+  EFI_STATUS_CODE_VALUE            StatusCodeValue[MAX_SOFT_COUNT];
+
+  DEBUG ((DEBUG_INFO,"SmmInitializeIpmiKcsPhysicalLayer entry \n"));
+  ErrorCount = 0;
+  mImageHandle = ImageHandle;
+
+  mIpmiInstance = AllocateZeroPool (sizeof (IPMI_BMC_INSTANCE_DATA));
+  ASSERT (mIpmiInstance != NULL);
+  if (mIpmiInstance == NULL) {
+    DEBUG ((EFI_D_ERROR, "ERROR!! Null Pointer returned by AllocateZeroPool ()\n"));
+    ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES);
+    return EFI_OUT_OF_RESOURCES;
+  } else {
+
+    //
+    // Initialize the KCS transaction timeout. Assume delay unit is 1000 us.
+    //
+    mIpmiInstance->KcsTimeoutPeriod = (BMC_KCS_TIMEOUT * 1000*1000) / KCS_DELAY_UNIT;
+
+    //
+    // Initialize IPMI IO Base, we still use SMS IO base to get device ID and Seltest result since SMM IF may have different cmds supported
+    //
+    mIpmiInstance->IpmiIoBase                       = PcdGet16 (PcdIpmiSmmIoBaseAddress);
+    mIpmiInstance->Signature                        = SM_IPMI_BMC_SIGNATURE;
+    mIpmiInstance->SlaveAddress                     = BMC_SLAVE_ADDRESS;
+    mIpmiInstance->BmcStatus                        = BMC_NOTREADY;
+    mIpmiInstance->IpmiTransport.IpmiSubmitCommand  = IpmiSendCommand;
+    mIpmiInstance->IpmiTransport.GetBmcStatus       = IpmiGetBmcStatus;
+
+    DEBUG ((DEBUG_INFO,"IPMI: Waiting for Getting BMC DID in SMM \n"));
+    //
+    // Get the Device ID and check if the system is in Force Update mode.
+    //
+    // Just obey the Spec..
+    // If we want to improve performance, we're going to comment it.
+    //
+    Status = GetDeviceId (
+               mIpmiInstance,
+               StatusCodeValue,
+               &ErrorCount
+               );
+    ASSERT_EFI_ERROR (Status);
+    Handle = NULL;
+    Status = gSmst->SmmInstallProtocolInterface (
+                      &Handle,
+                      &gSmmIpmiTransportProtocolGuid,
+                      EFI_NATIVE_INTERFACE,
+                      &mIpmiInstance->IpmiTransport
+                      );
+    ASSERT_EFI_ERROR (Status);
+
+    DEBUG ((DEBUG_INFO,"SmmInitializeIpmiKcsPhysicalLayer exit \n"));
+
+    return EFI_SUCCESS;
+  }
+}
+
+EFI_STATUS
+InitializeSmmGenericIpmi (
+  IN EFI_HANDLE             ImageHandle,
+  IN EFI_SYSTEM_TABLE       *SystemTable
+  )
+{
+  SmmInitializeIpmiKcsPhysicalLayer (ImageHandle, SystemTable);
+  return EFI_SUCCESS;
+}
diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/GenericIpmi/Smm/SmmGenericIpmi.inf b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/GenericIpmi/Smm/SmmGenericIpmi.inf
new file mode 100644
index 0000000000..a534f7dac8
--- /dev/null
+++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/GenericIpmi/Smm/SmmGenericIpmi.inf
@@ -0,0 +1,53 @@
+## @file
+# Generic IPMI SMM Driver.
+#
+# @copyright
+# Copyright 2010 - 2021 Intel Corporation. <BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION                         = 0x00010005
+  BASE_NAME                           = SmmGenericIpmi
+  FILE_GUID                           = D14443FF-3626-4bcc-8204-196D11F06BC5
+  MODULE_TYPE                         = DXE_SMM_DRIVER
+  PI_SPECIFICATION_VERSION            = 0x0001000A
+  VERSION_STRING                      = 1.0
+  ENTRY_POINT                         = InitializeSmmGenericIpmi
+
+[Sources]
+  ../Common/IpmiHooks.h
+  ../Common/IpmiHooks.c
+  ../Common/IpmiBmcCommon.h
+  ../Common/KcsBmc.c
+  ../Common/KcsBmc.h
+  ../Common/IpmiBmc.c
+  ../Common/IpmiBmc.h
+  SmmGenericIpmi.c          #GenericIpmi.c+IpmiBmcInitialize.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OutOfBandManagement/IpmiFeaturePkg/IpmiFeaturePkg.dec
+
+[LibraryClasses]
+  MemoryAllocationLib
+  BaseLib
+  UefiBootServicesTableLib
+  SmmServicesTableLib
+  DebugLib
+  UefiDriverEntryPoint
+  IoLib
+  ReportStatusCodeLib
+  TimerLib
+
+[Protocols]
+  gSmmIpmiTransportProtocolGuid                     # PROTOCOL ALWAYS_PRODUCED
+
+[Guids]
+
+[Pcd]
+  gIpmiFeaturePkgTokenSpaceGuid.PcdIpmiSmmIoBaseAddress
+  gIpmiFeaturePkgTokenSpaceGuid.PcdIpmiBmcReadyDelayTimer
+
+[Depex]
+ gIpmiTransportProtocolGuid
-- 
2.27.0.windows.1


  parent reply	other threads:[~2021-03-02  2:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02  2:27 [edk2-platforms] [PATCH v1 0/9] IpmiFeaturePkg: Add IPMI transport drivers Nate DeSimone
2021-03-02  2:27 ` [edk2-platforms] [PATCH v1 1/9] IpmiFeaturePkg: Add IPMI driver Include headers Nate DeSimone
2021-03-02  2:27 ` [edk2-platforms] [PATCH v1 2/9] IpmiFeaturePkg: Add IpmiBaseLib and IpmiCommandLib Nate DeSimone
2021-03-02  2:27 ` [edk2-platforms] [PATCH v1 3/9] IpmiFeaturePkg: Add IpmiInit driver DEPEXs Nate DeSimone
2021-03-02  2:27 ` [edk2-platforms] [PATCH v1 4/9] IpmiFeaturePkg: Add GenericIpmi driver common code Nate DeSimone
2021-03-02  2:28 ` [edk2-platforms] [PATCH v1 5/9] IpmiFeaturePkg: Add GenericIpmi PEIM Nate DeSimone
2021-03-02  2:28 ` [edk2-platforms] [PATCH v1 6/9] IpmiFeaturePkg: Add GenericIpmi DXE Driver Nate DeSimone
2021-03-02  2:28 ` Nate DeSimone [this message]
2021-03-02  2:28 ` [edk2-platforms] [PATCH v1 8/9] IpmiFeaturePkg: Add IPMI driver build files Nate DeSimone
2021-03-02  2:28 ` [edk2-platforms] [PATCH v1 9/9] Maintainers.txt: Add IpmiFeaturePkg maintainers Nate DeSimone
2021-03-03 19:22 ` [edk2-devel] [edk2-platforms] [PATCH v1 0/9] IpmiFeaturePkg: Add IPMI transport drivers Michael Kubacki
2021-03-04 23:33   ` Oram, Isaac W
2021-03-05 11:06     ` Nhi Pham
2021-03-11 19:29 ` Chaganty, Rangasai V

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=20210302022804.8641-8-nathaniel.l.desimone@intel.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