From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web12.3173.1614652144809506276 for ; Mon, 01 Mar 2021 18:29:04 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: nathaniel.l.desimone@intel.com) IronPort-SDR: fRvrtIxph1dFeSOp1gP8xw00I3oMt+8Ou5bFTOt6hrwi9KizPRxgxPU9Z3ExYadzkOvPS8qXbQ boa5LscSz8OA== X-IronPort-AV: E=McAfee;i="6000,8403,9910"; a="173797231" X-IronPort-AV: E=Sophos;i="5.81,216,1610438400"; d="scan'208";a="173797231" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2021 18:29:01 -0800 IronPort-SDR: wNC2gLFCPliCtPQbTbQ4BNAOwleskwi6D6Mssz51T5MLCvAJUgjBm2WFJufdDtq9AZstSz4Nid bHxS8QJlwP6Q== X-IronPort-AV: E=Sophos;i="5.81,216,1610438400"; d="scan'208";a="427169859" Received: from nldesimo-desk1.amr.corp.intel.com ([10.212.174.59]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2021 18:29:01 -0800 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: Isaac Oram , Sai Chaganty , Liming Gao , Michael Kubacki Subject: [edk2-platforms] [PATCH v1 2/9] IpmiFeaturePkg: Add IpmiBaseLib and IpmiCommandLib Date: Mon, 1 Mar 2021 18:27:57 -0800 Message-Id: <20210302022804.8641-3-nathaniel.l.desimone@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20210302022804.8641-1-nathaniel.l.desimone@intel.com> References: <20210302022804.8641-1-nathaniel.l.desimone@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Isaac Oram REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3242 Adds IpmiBaseLib and adds new commands to IpmiCommandLib Cc: Sai Chaganty Cc: Liming Gao Cc: Michael Kubacki Signed-off-by: Isaac Oram Co-authored-by: Nate DeSimone --- .../Library/IpmiBaseLib/IpmiBaseLib.c | 155 +++++++++++++++ .../Library/IpmiBaseLib/IpmiBaseLib.inf | 28 +++ .../Library/IpmiBaseLibNull/IpmiBaseLibNull.c | 76 ++++++++ .../IpmiBaseLibNull/IpmiBaseLibNull.inf | 36 ++++ .../Library/IpmiCommandLib/IpmiCommandLib.inf | 4 +- .../IpmiCommandLib/IpmiCommandLibNetFnApp.c | 7 +- .../IpmiCommandLibNetFnChassis.c | 51 ++++- .../IpmiCommandLibNetFnStorage.c | 7 +- .../IpmiCommandLibNetFnTransport.c | 7 +- .../Library/PeiIpmiBaseLib/PeiIpmiBaseLib.c | 111 +++++++++++ .../Library/PeiIpmiBaseLib/PeiIpmiBaseLib.inf | 30 +++ .../Library/SmmIpmiBaseLib/SmmIpmiBaseLib.c | 180 ++++++++++++++++++ .../Library/SmmIpmiBaseLib/SmmIpmiBaseLib.inf | 29 +++ 13 files changed, 703 insertions(+), 18 deletions(-) create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLib/IpmiBaseLib.c create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLib/IpmiBaseLib.inf create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLibNull/IpmiBaseLibNull.c create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLibNull/IpmiBaseLibNull.inf create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/PeiIpmiBaseLib/PeiIpmiBaseLib.c create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/PeiIpmiBaseLib/PeiIpmiBaseLib.inf create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/SmmIpmiBaseLib/SmmIpmiBaseLib.c create mode 100644 Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/SmmIpmiBaseLib/SmmIpmiBaseLib.inf diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLib/IpmiBaseLib.c b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLib/IpmiBaseLib.c new file mode 100644 index 0000000000..6b2e0a9e1e --- /dev/null +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLib/IpmiBaseLib.c @@ -0,0 +1,155 @@ +/** @file + A Library to support all BMC access via IPMI command during Dxe Phase. + + @copyright + Copyright 1999 - 2021 Intel Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include + +STATIC IPMI_TRANSPORT *mIpmiTransport = NULL; +VOID *mEfiIpmiProtocolNotifyReg; +EFI_EVENT mEfiIpmiProtocolEvent; + +/** + Callback function for locating the IpmiTransport protocol. + @param[in] Event Event on which the callback is called. + @param[in] Context The context of the Callback. + + @retval EFI_SUCCESS Return from EfiLocateProtocolInterface function. + @retval Other Failure. + +**/ +EFI_STATUS +NotifyIpmiTransportCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + Status = EFI_SUCCESS; + if (mIpmiTransport == NULL) { + Status = gBS->LocateProtocol ( + &gIpmiTransportProtocolGuid, + NULL, + (VOID **) &mIpmiTransport + ); + } + + return Status; +} + +/** + Initialize the global varible with the pointer of IpmiTransport Protocol. + + @retval EFI_SUCCESS Always return success. + +**/ +EFI_STATUS +InitializeIpmiBase ( + VOID + ) +{ + EFI_STATUS Status; + + if (mIpmiTransport == NULL) { + Status = gBS->CreateEvent (EVT_NOTIFY_SIGNAL, TPL_CALLBACK, (EFI_EVENT_NOTIFY) NotifyIpmiTransportCallback, NULL, &mEfiIpmiProtocolEvent); + ASSERT_EFI_ERROR (Status); + if (Status != EFI_SUCCESS) { + return Status; + } + + Status = gBS->RegisterProtocolNotify (&gIpmiTransportProtocolGuid, mEfiIpmiProtocolEvent, &mEfiIpmiProtocolNotifyReg); + ASSERT_EFI_ERROR (Status); + if (Status != EFI_SUCCESS) { + return Status; + } + + gBS->SignalEvent (mEfiIpmiProtocolEvent); + } + + return EFI_SUCCESS; +} + +/** + Routine to send commands to BMC. + @param[in] NetFunction Net function of the command + @param[in] Command IPMI Command + @param[in] CommandData Command Data + @param[in] CommandDataSize Size of CommandData + @param[out] ResponseData Response Data + @param[in, out] ResponseDataSize Response Data Size + + @retval EFI_SUCCESS Return Successly. + @retval EFI_NOT_AVAILABLE_YET IpmiTransport Protocol is not installed yet + @retval Other Failure. + +**/ +EFI_STATUS +IpmiSubmitCommand ( + IN UINT8 NetFunction, + IN UINT8 Command, + IN UINT8 *CommandData, + IN UINT32 CommandDataSize, + OUT UINT8 *ResponseData, + IN OUT UINT32 *ResponseDataSize + ) +{ + EFI_STATUS Status; + + Status = gBS->LocateProtocol (&gIpmiTransportProtocolGuid, NULL, (VOID **) &mIpmiTransport); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + Status = mIpmiTransport->IpmiSubmitCommand ( + mIpmiTransport, + NetFunction, + 0, + Command, + CommandData, + CommandDataSize, + ResponseData, + ResponseDataSize + ); + return Status; +} + +/** + Routine to send commands to BMC. + @param[out] BmcStatus A pointer to the BMC_STATUS. + @param[out] ComAddress Pointer to the SM_COM_ADDRESS. + + @retval EFI_SUCCESS Restart Successly. + @retval EFI_NOT_AVAILABLE_YET IpmiTransport Protocol is not installed yet. + @retval Other Failure. + +**/ +EFI_STATUS +IpmiGetBmcStatus ( + OUT BMC_STATUS *BmcStatus, + OUT SM_COM_ADDRESS *ComAddress + ) +{ + EFI_STATUS Status; + + Status = gBS->LocateProtocol (&gIpmiTransportProtocolGuid, NULL, (VOID **) &mIpmiTransport); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + Status = mIpmiTransport->GetBmcStatus ( + mIpmiTransport, + BmcStatus, + ComAddress + ); + return Status; +} + diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLib/IpmiBaseLib.inf b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLib/IpmiBaseLib.inf new file mode 100644 index 0000000000..b429d3b7b9 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLib/IpmiBaseLib.inf @@ -0,0 +1,28 @@ +## @file +# +# @copyright +# Copyright 2010 - 2021 Intel Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = IpmiBaseLib + FILE_GUID = 2B5AD78E-5CF8-45d2-B2AC-749A09425911 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = IpmiBaseLib|DXE_RUNTIME_DRIVER DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER + +[sources] + IpmiBaseLib.c + +[Packages] + MdePkg/MdePkg.dec + OutOfBandManagement/IpmiFeaturePkg/IpmiFeaturePkg.dec + +[LibraryClasses] + UefiBootServicesTableLib + DebugLib + +[Protocols] + gIpmiTransportProtocolGuid diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLibNull/IpmiBaseLibNull.c b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLibNull/IpmiBaseLibNull.c new file mode 100644 index 0000000000..7c4c67f6ac --- /dev/null +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLibNull/IpmiBaseLibNull.c @@ -0,0 +1,76 @@ +/** @file + A Null Library to support all BMC access via IPMI command. + + @copyright + Copyright 2011 - 2021 Intel Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include + +/** + + Initialize the global varible with the pointer of IpmiTransport Protocol + + @retval EFI_SUCCESS Always return success. + +**/ +EFI_STATUS +InitializeIpmiBase ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** + Routine to send commands to BMC. + @param [in] NetFunction Net function of the command + @param [in] Command IPMI Command + @param [in] CommandData Command Data + @param [in] CommandDataSize Size of CommandData + @param [out] ResponseData Response Data + @param [out] ResponseDataSize Response Data Size + + @retval EFI_SUCCESS Restart Successly. + @retval EFI_NOT_AVAILABLE_YET IpmiTransport Protocol is not installed yet. + @retval Other Failure. + +**/ +EFI_STATUS +IpmiSubmitCommand ( + IN UINT8 NetFunction, + IN UINT8 Command, + IN UINT8 *CommandData, + IN UINT32 CommandDataSize, + OUT UINT8 *ResponseData, + OUT UINT32 *ResponseDataSize + ) +{ + return EFI_SUCCESS; +} + +/** + Routine to send commands to BMC. + @param [out] BmcStatus A pointer to BMC_STATUS. + @param [out] ComAddress A pointer to SM_COM_ADDRESS. + + @retval EFI_SUCCESS Restart Successly. + @retval EFI_NOT_AVAILABLE_YET - IpmiTransport Protocol is not installed yet. + @retval Other Failure. + +**/ +EFI_STATUS +GetBmcStatus ( + OUT BMC_STATUS *BmcStatus, + OUT SM_COM_ADDRESS *ComAddress + ) +{ + return EFI_SUCCESS; +} + diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLibNull/IpmiBaseLibNull.inf b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLibNull/IpmiBaseLibNull.inf new file mode 100644 index 0000000000..5478f9842b --- /dev/null +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiBaseLibNull/IpmiBaseLibNull.inf @@ -0,0 +1,36 @@ +## @file +# +# @copyright +# Copyright 2011 - 2021 Intel Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = IpmiBaseLibNull + FILE_GUID = 3444CF4F-8B88-4579-9A95-2E7678C0E945 + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = IpmiBaseLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources.common] + IpmiBaseLibNull.c + +[Packages] + MdePkg/MdePkg.dec + OutOfBandManagement/IpmiFeaturePkg/IpmiFeaturePkg.dec + +[LibraryClasses] + BaseLib + UefiBootServicesTableLib + DxeServicesLib + DebugLib + +[Guids] + diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLib.inf b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLib.inf index 0bdace8688..f8e7ba5a8f 100644 --- a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLib.inf +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLib.inf @@ -1,7 +1,7 @@ ### @file # Component description file for IPMI Command Library. # -# Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2018 - 2021, Intel Corporation. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -29,4 +29,4 @@ [LibraryClasses] BaseMemoryLib DebugLib - IpmiLib + IpmiBaseLib diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnApp.c b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnApp.c index b57db50610..addabc554e 100644 --- a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnApp.c +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnApp.c @@ -1,15 +1,14 @@ /** @file IPMI Command - NetFnApp. -Copyright (c) 2018, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - + Copyright (c) 2018 - 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include #include #include -#include +#include #include diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnChassis.c b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnChassis.c index 1b86aa888e..9c19f52ce4 100644 --- a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnChassis.c +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnChassis.c @@ -1,15 +1,14 @@ /** @file IPMI Command - NetFnChassis. -Copyright (c) 2018, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - + Copyright (c) 2018 - 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include #include #include -#include +#include #include @@ -99,3 +98,47 @@ IpmiSetPowerRestorePolicy ( ); return Status; } + +EFI_STATUS +EFIAPI +IpmiSetSystemBootOptions ( + IN IPMI_SET_BOOT_OPTIONS_REQUEST *BootOptionsRequest, + OUT IPMI_SET_BOOT_OPTIONS_RESPONSE *BootOptionsResponse + ) +{ + EFI_STATUS Status; + UINT32 DataSize; + + DataSize = sizeof(*BootOptionsResponse); + Status = IpmiSubmitCommand ( + IPMI_NETFN_CHASSIS, + IPMI_CHASSIS_SET_SYSTEM_BOOT_OPTIONS, + (VOID *)BootOptionsRequest, + sizeof(*BootOptionsRequest), + (VOID *)BootOptionsResponse, + &DataSize + ); + return Status; +} + +EFI_STATUS +EFIAPI +IpmiGetSystemBootOptions ( + IN IPMI_GET_BOOT_OPTIONS_REQUEST *BootOptionsRequest, + OUT IPMI_GET_BOOT_OPTIONS_RESPONSE *BootOptionsResponse + ) +{ + EFI_STATUS Status; + UINT32 DataSize; + + DataSize = sizeof(*BootOptionsResponse); + Status = IpmiSubmitCommand ( + IPMI_NETFN_CHASSIS, + IPMI_CHASSIS_GET_SYSTEM_BOOT_OPTIONS, + (VOID *)BootOptionsRequest, + sizeof(*BootOptionsRequest), + (VOID *)BootOptionsResponse, + &DataSize + ); + return Status; +} diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnStorage.c b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnStorage.c index 8e892c5f84..2215028089 100644 --- a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnStorage.c +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnStorage.c @@ -1,15 +1,14 @@ /** @file IPMI Command - NetFnStorage. -Copyright (c) 2018, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - + Copyright (c) 2018 - 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include #include #include -#include +#include #include diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnTransport.c b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnTransport.c index 3b9b17b909..7dfcf86126 100644 --- a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnTransport.c +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/IpmiCommandLib/IpmiCommandLibNetFnTransport.c @@ -1,15 +1,14 @@ /** @file IPMI Command - NetFnTransport. -Copyright (c) 2018, Intel Corporation. All rights reserved.
-SPDX-License-Identifier: BSD-2-Clause-Patent - + Copyright (c) 2018 - 2021, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include #include #include -#include +#include #include diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/PeiIpmiBaseLib/PeiIpmiBaseLib.c b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/PeiIpmiBaseLib/PeiIpmiBaseLib.c new file mode 100644 index 0000000000..8679cd95db --- /dev/null +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/PeiIpmiBaseLib/PeiIpmiBaseLib.c @@ -0,0 +1,111 @@ +/** @file + A Library to support all BMC access via IPMI command during PEI Phase. + + @copyright + Copyright 2017 - 2021 Intel Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include + + +/** + Initialize the global varible with the pointer of IpmiTransport Protocol. + + @return EFI_SUCCESS - Always return success + +**/ +EFI_STATUS +InitializeIpmiBase ( + VOID + ) +{ + EFI_STATUS Status; + PEI_IPMI_TRANSPORT_PPI *IpmiTransport; + + Status = PeiServicesLocatePpi (&gPeiIpmiTransportPpiGuid, 0, NULL, (VOID **) &IpmiTransport); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + } + return Status; +} + +/** + Routine to send commands to BMC. + + @param NetFunction - Net function of the command + @param Command - IPMI Command + @param CommandData - Command Data + @param CommandDataSize - Size of CommandData + @param ResponseData - Response Data + @param ResponseDataSize - Response Data Size + + @return EFI_NOT_AVAILABLE_YET - IpmiTransport Protocol is not installed yet + +**/ +EFI_STATUS +IpmiSubmitCommand ( + IN UINT8 NetFunction, + IN UINT8 Command, + IN UINT8 *CommandData, + IN UINT32 CommandDataSize, + OUT UINT8 *ResponseData, + IN OUT UINT32 *ResponseDataSize + ) +{ + EFI_STATUS Status; + PEI_IPMI_TRANSPORT_PPI *IpmiTransport; + + Status = PeiServicesLocatePpi (&gPeiIpmiTransportPpiGuid, 0, NULL, (VOID **) &IpmiTransport); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + Status = IpmiTransport->IpmiSubmitCommand ( + IpmiTransport, + NetFunction, + 0, + Command, + CommandData, + CommandDataSize, + ResponseData, + ResponseDataSize + ); + return Status; +} + +/** + Routine to send commands to BMC. + + @param BmcStatus - Ststus of Bmc + @param ComAddress - IPMI Address + + @return EFI_NOT_AVAILABLE_YET - IpmiTransport Protocol is not installed yet + +**/ +EFI_STATUS +GetBmcStatus ( + OUT BMC_STATUS *BmcStatus, + OUT SM_COM_ADDRESS *ComAddress + ) +{ + EFI_STATUS Status; + PEI_IPMI_TRANSPORT_PPI *IpmiTransport; + + Status = PeiServicesLocatePpi (&gPeiIpmiTransportPpiGuid, 0, NULL, (VOID **) &IpmiTransport); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + Status = IpmiTransport->GetBmcStatus ( + IpmiTransport, + BmcStatus, + ComAddress + ); + return Status; +} + diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/PeiIpmiBaseLib/PeiIpmiBaseLib.inf b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/PeiIpmiBaseLib/PeiIpmiBaseLib.inf new file mode 100644 index 0000000000..f89614adfb --- /dev/null +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/PeiIpmiBaseLib/PeiIpmiBaseLib.inf @@ -0,0 +1,30 @@ +## @file +# +# @copyright +# Copyright 2014 - 2021 Intel Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiIpmiBaseLib + FILE_GUID = 616A8628-9A5C-4d19-9C62-3874C5E6F4A6 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = IpmiBaseLib|PEIM PEI_CORE + +[sources] + PeiIpmiBaseLib.c + +[Packages] + MdePkg/MdePkg.dec + OutOfBandManagement/IpmiFeaturePkg/IpmiFeaturePkg.dec + +[LibraryClasses] + DebugLib + BaseMemoryLib + PeiServicesLib + + +[Ppis] + gPeiIpmiTransportPpiGuid diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/SmmIpmiBaseLib/SmmIpmiBaseLib.c b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/SmmIpmiBaseLib/SmmIpmiBaseLib.c new file mode 100644 index 0000000000..6282adc269 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/SmmIpmiBaseLib/SmmIpmiBaseLib.c @@ -0,0 +1,180 @@ +/** @file + A Library to support all BMC access via IPMI command during SMM Phase. + + @copyright + Copyright 1999 - 2021 Intel Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include + +STATIC IPMI_TRANSPORT *mIpmiTransport = NULL; +VOID *mEfiIpmiProtocolNotifyReg = NULL; +EFI_EVENT mEfiIpmiProtocolEvent; + +/** + Callback function for locating the IpmiTransport protocol. + + @param Protocol A pointer to EFI_GUID + @param Interface A pointer to Interface + @param Handle Handle + + @retval EFI_SUCCESS: Callback successfully + +**/ +EFI_STATUS +NotifyIpmiTransportCallback ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + Status = EFI_SUCCESS; + if (mIpmiTransport == NULL) { + Status = gSmst->SmmLocateProtocol ( + &gSmmIpmiTransportProtocolGuid, + NULL, + (VOID **) &mIpmiTransport + ); + } + + return Status; +} + +/** + Routine to send commands to BMC. + + @retval EFI_SUCCESS: Always return success + +**/ +EFI_STATUS +InitializeIpmiBase ( + VOID + ) +{ + EFI_STATUS Status; + if (mIpmiTransport == NULL) { + Status = gSmst->SmmLocateProtocol ( + &gSmmIpmiTransportProtocolGuid, + NULL, + (VOID **) &mIpmiTransport + ); + if (EFI_ERROR (Status)) { + Status = gSmst->SmmRegisterProtocolNotify ( + &gSmmIpmiTransportProtocolGuid, + (EFI_SMM_NOTIFY_FN) NotifyIpmiTransportCallback, + &mEfiIpmiProtocolNotifyReg + ); + } + ASSERT_EFI_ERROR (Status); + if (Status != EFI_SUCCESS) { + return Status; + } + } + + return EFI_SUCCESS; +} + +/** + Routine to send commands to BMC. + + @param NetFunction - Net function of the command + @param Command - IPMI Command + @param CommandData - Command Data + @param CommandDataSize - Size of CommandData + @param ResponseData - Response Data + @param ResponseDataSize - Response Data Size + + @retval EFI_SUCCESS: Get successfully + @retval EFI_NOT_AVAILABLE_YET + +**/ +EFI_STATUS +IpmiSubmitCommand ( + IN UINT8 NetFunction, + IN UINT8 Command, + IN UINT8 *CommandData, + IN UINT32 CommandDataSize, + OUT UINT8 *ResponseData, + IN OUT UINT32 *ResponseDataSize + ) +/*++ + +Routine Description: + + Routine to send commands to BMC + +Arguments: + + NetFunction - Net function of the command + Command - IPMI Command + CommandData - Command Data + CommandDataSize - Size of CommandData + ResponseData - Response Data + ResponseDataSize - Response Data Size + +Returns: + + EFI_NOT_AVAILABLE_YET - IpmiTransport Protocol is not installed yet + +--*/ +{ + EFI_STATUS Status; + + Status = gSmst->SmmLocateProtocol (&gSmmIpmiTransportProtocolGuid, NULL, (VOID **) &mIpmiTransport); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + Status = mIpmiTransport->IpmiSubmitCommand ( + mIpmiTransport, + NetFunction, + 0, + Command, + CommandData, + CommandDataSize, + ResponseData, + ResponseDataSize + ); + return Status; +} + +/** + Routine to send commands to BMC. + + @param BmcStatus The ConnectAllComplete EFI Event. + @param ComAddress Event context pass to create function + + @retval EFI_SUCCESS: Get successfully + @retval EFI_NOT_AVAILABLE_YET + +**/ +EFI_STATUS +GetBmcStatus ( + OUT BMC_STATUS *BmcStatus, + OUT SM_COM_ADDRESS *ComAddress + ) +{ + EFI_STATUS Status; + + Status = gSmst->SmmLocateProtocol (&gSmmIpmiTransportProtocolGuid, NULL, (VOID **) &mIpmiTransport); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + Status = mIpmiTransport->GetBmcStatus ( + mIpmiTransport, + BmcStatus, + ComAddress + ); + return Status; +} + diff --git a/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/SmmIpmiBaseLib/SmmIpmiBaseLib.inf b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/SmmIpmiBaseLib/SmmIpmiBaseLib.inf new file mode 100644 index 0000000000..bb1ccf1ca2 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/IpmiFeaturePkg/Library/SmmIpmiBaseLib/SmmIpmiBaseLib.inf @@ -0,0 +1,29 @@ +## @file +# +# @copyright +# Copyright 2010 - 2021 Intel Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SmmIpmiBaseLib + FILE_GUID = 2B5AD78E-5CF8-45d2-B2AC-749A09425911 + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = IpmiBaseLib|DXE_SMM_DRIVER SMM_CORE + +[sources] + SmmIpmiBaseLib.c + +[Packages] + MdePkg/MdePkg.dec + OutOfBandManagement/IpmiFeaturePkg/IpmiFeaturePkg.dec + +[LibraryClasses] + UefiBootServicesTableLib + DebugLib + SmmServicesTableLib + +[Protocols] + gSmmIpmiTransportProtocolGuid -- 2.27.0.windows.1