This implements the BMC configuration screen to provide basic information such as IPMI version, BMC version, and BMC IPv4.
Signed-off-by: Nhi Pham <n...@os.amperecomputing.com> --- Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec | 8 +- Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.inf | 44 +++ Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.h | 35 +++ Silicon/Ampere/AmpereSiliconPkg/Include/Guid/BmcConfigHii.h | 19 ++ Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigVfr.vfr | 42 +++ Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.c | 326 ++++++++++++++++++++ Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.uni | 18 ++ 7 files changed, 491 insertions(+), 1 deletion(-) diff --git a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec index 56e8b2fd2f11..9886bd809a02 100644 --- a/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec +++ b/Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec @@ -1,6 +1,6 @@ ## @file # -# Copyright (c) 2020 - 2023, Ampere Computing LLC. All rights reserved.<BR> +# Copyright (c) 2020 - 2024, Ampere Computing LLC. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -47,6 +47,12 @@ [Guids] ## Include/Guid/PlatformManagerHii.h gPlatformManagerExitEventGuid = { 0xE8887242, 0x4EFF, 0x4323, { 0x81, 0xF4, 0xC9, 0x5F, 0xD5, 0x8D, 0x80, 0xD5 } } + # + # BMC Configuration formset UUID + # + ## Include/Guid/BmcConfigHii.h + gBmcConfigFormSetGuid = { 0xC4D6ED50, 0x769D, 0x4319, { 0xEB, 0xB7, 0xCC, 0xDD, 0xC8, 0x9D, 0x3D, 0x2D } } + [Ppis] [PcdsFixedAtBuild] diff --git a/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.inf b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.inf new file mode 100644 index 000000000000..93938ac0163c --- /dev/null +++ b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.inf @@ -0,0 +1,44 @@ +## @file +# +# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = BmcConfigDxe + FILE_GUID = 5D1B9008-9CF5-4A12-AF0F-FB9C06005643 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = BmcConfigEntry + +[Sources.common] + BmcConfigDxe.c + BmcConfigDxe.uni + BmcConfigVfr.vfr + +[Packages] + Features/ManageabilityPkg/ManageabilityPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + HiiLib + IpmiCommandLib + MemoryAllocationLib + PrintLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Guids] + gBmcConfigFormSetGuid + gEfiIfrTianoGuid + gPlatformManagerFormsetGuid + +[Depex] + TRUE diff --git a/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.h b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.h new file mode 100644 index 000000000000..1ebb4be743df --- /dev/null +++ b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.h @@ -0,0 +1,35 @@ +/** @file + + Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef BMC_CONFIG_DXE_H_ +#define BMC_CONFIG_DXE_H_ + +// +// This is the generated IFR binary data for each formset defined in VFR. +// This data array is ready to be used as input of HiiAddPackages() to +// create a packagelist (which contains Form packages, String packages, etc). +// +extern UINT8 BmcConfigVfrBin[]; + +// +// This is the generated String package data for all .UNI files. +// This data array is ready to be used as input of HiiAddPackages() to +// create a packagelist (which contains Form packages, String packages, etc). +// +extern UINT8 BmcConfigDxeStrings[]; + +// +// Form definitions +// +#define MAIN_FORM_ID 0x1000 +#define LABEL_UPDATE 0x2000 +#define LABEL_END 0x2300 + +#define MAX_STRING_SIZE 40 + +#endif // BMC_CONFIG_DXE_H_ diff --git a/Silicon/Ampere/AmpereSiliconPkg/Include/Guid/BmcConfigHii.h b/Silicon/Ampere/AmpereSiliconPkg/Include/Guid/BmcConfigHii.h new file mode 100644 index 000000000000..4466fc457c0b --- /dev/null +++ b/Silicon/Ampere/AmpereSiliconPkg/Include/Guid/BmcConfigHii.h @@ -0,0 +1,19 @@ +/** @file + + Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef BMC_CONFIG_HII_H_ +#define BMC_CONFIG_HII_H_ + +#define BMC_CONFIG_FORMSET_GUID \ + { \ + 0xC4D6ED50, 0x769D, 0x4319, { 0xEB, 0xB7, 0xCC, 0xDD, 0xC8, 0x9D, 0x3D, 0x2D } \ + } + +extern EFI_GUID gBmcConfigFormSetGuid; + +#endif /* BMC_CONFIG_HII_H_ */ diff --git a/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigVfr.vfr b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigVfr.vfr new file mode 100644 index 000000000000..dca4d598fc3a --- /dev/null +++ b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigVfr.vfr @@ -0,0 +1,42 @@ +/** @file + + Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Guid/PlatformManagerHii.h> +#include <Guid/BmcConfigHii.h> +#include "BmcConfigDxe.h" + +formset + guid = BMC_CONFIG_FORMSET_GUID, + title = STRING_TOKEN(STR_BMC_CONFIG_FORM), + help = STRING_TOKEN(STR_BMC_CONFIG_HELP), + classguid = gPlatformManagerFormsetGuid, + + form + formid = MAIN_FORM_ID, + title = STRING_TOKEN(STR_BMC_CONFIG_FORM); + + text + help = STRING_TOKEN(STR_BMC_FIRMWARE_REV_LABEL), + text = STRING_TOKEN(STR_BMC_FIRMWARE_REV_LABEL), + text = STRING_TOKEN(STR_BMC_FIRMWARE_REV_VALUE), + flags = 0, + key = 0; + + text + help = STRING_TOKEN(STR_BMC_IPMI_VER_LABEL), + text = STRING_TOKEN(STR_BMC_IPMI_VER_LABEL), + text = STRING_TOKEN(STR_BMC_IPMI_VER_VALUE), + flags = 0, + key = 0; + + label LABEL_UPDATE; + // dynamic content here + label LABEL_END; + + endform; +endformset; diff --git a/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.c b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.c new file mode 100644 index 000000000000..c2453ef83bea --- /dev/null +++ b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.c @@ -0,0 +1,326 @@ +/** @file + BMC Configuration screen + + Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Uefi.h> + +#include <Guid/BmcConfigHii.h> +#include <Guid/MdeModuleHii.h> +#include <IndustryStandard/Ipmi.h> +#include <IndustryStandard/IpmiNetFnApp.h> +#include <IndustryStandard/IpmiNetFnTransport.h> +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/HiiLib.h> +#include <Library/IpmiCommandLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/PrintLib.h> +#include <Library/UefiBootServicesTableLib.h> + +#include "BmcConfigDxe.h" + +// +// HII Handle for BMC Configuration package +// +EFI_HII_HANDLE mHiiHandle; + +/** + Get BMC LAN Information of specific channel. + + @param[in] BmcChannel BMC Channel to retrieve LAN information. + @param[out] BmcIpAddress Pointer to buffer to receive BMC IPv4 address. + @param[out] BmcSubnetMask Pointer to buffer to receive BMC subnet mask. + + @retval EFI_SUCCESS The command byte stream was successfully submit to the device + and a response was successfully received. + @retval EFI_INVALID_PARAMETER BmcIpAddress or BmcSubnetMask is NULL. + @retval other Failed to get BMC LAN info. +**/ +EFI_STATUS +EFIAPI +IpmiGetBmcLanInfo ( + IN UINT8 BmcChannel, + OUT IPMI_LAN_IP_ADDRESS *BmcIpAddress, + OUT IPMI_LAN_SUBNET_MASK *BmcSubnetMask + ) +{ + EFI_STATUS Status; + IPMI_GET_CHANNEL_INFO_REQUEST GetChannelInfoRequest; + IPMI_GET_CHANNEL_INFO_RESPONSE GetChannelInfoResponse; + IPMI_GET_LAN_CONFIGURATION_PARAMETERS_REQUEST GetConfigurationParametersRequest; + IPMI_GET_LAN_CONFIGURATION_PARAMETERS_RESPONSE *GetConfigurationParametersResponse; + UINT32 ResponseSize; + + if ((BmcIpAddress == NULL) || (BmcSubnetMask == NULL)) { + return EFI_INVALID_PARAMETER; + } + + // + // Get Channel Information + // + ZeroMem (&GetChannelInfoRequest, sizeof (GetChannelInfoRequest)); + GetChannelInfoRequest.ChannelNumber.Bits.ChannelNo = BmcChannel; + ResponseSize = sizeof (GetChannelInfoResponse); + + Status = IpmiGetChannelInfo (&GetChannelInfoRequest, &GetChannelInfoResponse, &ResponseSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get BMC channel info\n", __func__)); + return Status; + } + + // + // Check for LAN interface + // + if ( EFI_ERROR (Status) + || (GetChannelInfoResponse.CompletionCode != IPMI_COMP_CODE_NORMAL) + || (GetChannelInfoResponse.MediumType.Bits.ChannelMediumType != IPMI_CHANNEL_MEDIA_TYPE_802_3_LAN)) + { + return EFI_NOT_FOUND; + } + + GetConfigurationParametersResponse = AllocateZeroPool ( + sizeof (*GetConfigurationParametersResponse) + + sizeof (IPMI_LAN_IP_ADDRESS) + ); + if (GetConfigurationParametersResponse == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Get LAN IP Address + // + ZeroMem (&GetConfigurationParametersRequest, sizeof (GetConfigurationParametersRequest)); + GetConfigurationParametersRequest.ChannelNumber.Uint8 = BmcChannel; + GetConfigurationParametersRequest.ParameterSelector = IpmiLanIpAddress; + GetConfigurationParametersRequest.SetSelector = 0; + GetConfigurationParametersRequest.BlockSelector = 0; + + ResponseSize = sizeof (*GetConfigurationParametersResponse) + sizeof (IPMI_LAN_IP_ADDRESS); + + Status = IpmiGetLanConfigurationParameters (&GetConfigurationParametersRequest, GetConfigurationParametersResponse, &ResponseSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get the LAN configuration parameter\n", __func__)); + goto Exit; + } + + if (GetChannelInfoResponse.CompletionCode != IPMI_COMP_CODE_NORMAL) { + Status = EFI_NOT_FOUND; + goto Exit; + } + + CopyMem ( + BmcIpAddress->IpAddress, + GetConfigurationParametersResponse->ParameterData, + sizeof (IPMI_LAN_IP_ADDRESS) + ); + + // + // Get Subnet Mask + // + ZeroMem (&GetConfigurationParametersRequest, sizeof (GetConfigurationParametersRequest)); + GetConfigurationParametersRequest.ChannelNumber.Uint8 = BmcChannel; + GetConfigurationParametersRequest.ParameterSelector = IpmiLanSubnetMask; + GetConfigurationParametersRequest.SetSelector = 0; + GetConfigurationParametersRequest.BlockSelector = 0; + + ResponseSize = sizeof (*GetConfigurationParametersResponse) + sizeof (IPMI_LAN_SUBNET_MASK); + + Status = IpmiGetLanConfigurationParameters (&GetConfigurationParametersRequest, GetConfigurationParametersResponse, &ResponseSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get the LAN configuration parameter\n", __func__)); + goto Exit; + } + + if (GetChannelInfoResponse.CompletionCode != IPMI_COMP_CODE_NORMAL) { + Status = EFI_NOT_FOUND; + goto Exit; + } + + CopyMem ( + BmcSubnetMask->IpAddress, + GetConfigurationParametersResponse->ParameterData, + sizeof (IPMI_LAN_SUBNET_MASK) + ); + +Exit: + FreePool (GetConfigurationParametersResponse); + return Status; +} + +/** + This function updates the BMC information. + + @param[in] VOID + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +UpdateBmcConfigForm ( + VOID + ) +{ + EFI_IFR_GUID_LABEL *EndLabel; + EFI_IFR_GUID_LABEL *StartLabel; + EFI_STATUS Status; + IPMI_GET_DEVICE_ID_RESPONSE DeviceId; + IPMI_LAN_IP_ADDRESS BmcIpAddress; + IPMI_LAN_SUBNET_MASK BmcSubnetMask; + UINT16 StrBuf[MAX_STRING_SIZE]; + UINT8 BmcChannel; + VOID *EndOpCodeHandle; + VOID *StartOpCodeHandle; + + Status = IpmiGetDeviceId (&DeviceId); + if ( !EFI_ERROR (Status) + && (DeviceId.CompletionCode == IPMI_COMP_CODE_NORMAL)) + { + // + // Firmware Revision + // + UnicodeSPrint ( + StrBuf, + sizeof (StrBuf), + L"%d.%02d", + DeviceId.FirmwareRev1.Bits.MajorFirmwareRev, + BcdToDecimal8 (DeviceId.MinorFirmwareRev) + ); + HiiSetString (mHiiHandle, STRING_TOKEN (STR_BMC_FIRMWARE_REV_VALUE), StrBuf, NULL); + + // + // IPMI Version + // + UnicodeSPrint ( + StrBuf, + sizeof (StrBuf), + L"%d.%d", + DeviceId.SpecificationVersion & 0x0F, + (DeviceId.SpecificationVersion >> 4) & 0x0F + ); + HiiSetString (mHiiHandle, STRING_TOKEN (STR_BMC_IPMI_VER_VALUE), StrBuf, NULL); + } + + // + // Initialize the container for dynamic opcodes + // + StartOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (StartOpCodeHandle != NULL); + + EndOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle != NULL); + + // + // Create Hii Extend Label OpCode as the start opcode + // + StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( + StartOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + StartLabel->Number = LABEL_UPDATE; + + // + // Create Hii Extend Label OpCode as the end opcode + // + EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( + EndOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndLabel->Number = LABEL_END; + + for (BmcChannel = IPMI_CHANNEL_NUMBER_IMPLEMENTATION_SPECIFIC_1; BmcChannel < IPMI_CHANNEL_NUMBER_IMPLEMENTATION_SPECIFIC_11; BmcChannel++) { + ZeroMem (&BmcIpAddress, sizeof (BmcIpAddress)); + ZeroMem (&BmcSubnetMask, sizeof (BmcSubnetMask)); + Status = IpmiGetBmcLanInfo (BmcChannel, &BmcIpAddress, &BmcSubnetMask); + if ( EFI_ERROR (Status) || (BmcIpAddress.IpAddress[0] == 0)) { + continue; + } + + UnicodeSPrint ( + StrBuf, + sizeof (StrBuf), + L"%d.%d.%d.%d", + BmcIpAddress.IpAddress[0], + BmcIpAddress.IpAddress[1], + BmcIpAddress.IpAddress[2], + BmcIpAddress.IpAddress[3] + ); + + HiiCreateTextOpCode ( + StartOpCodeHandle, + STRING_TOKEN (STR_BMC_IP_ADDRESS_LABEL), + STRING_TOKEN (STR_BMC_IP_ADDRESS_LABEL), + HiiSetString (mHiiHandle, 0, StrBuf, NULL) + ); + + HiiUpdateForm ( + mHiiHandle, // HII handle + &gBmcConfigFormSetGuid, // Formset GUID + MAIN_FORM_ID, // Form ID + StartOpCodeHandle, // Label for where to insert opcodes + EndOpCodeHandle // Insert data + ); + + break; + } + + return Status; +} + +/** + The user Entry Point for the BMC Configuration driver. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +BmcConfigEntry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE DriverHandle; + + Status = EFI_SUCCESS; + DriverHandle = NULL; + + // + // Publish our HII data + // + mHiiHandle = HiiAddPackages ( + &gBmcConfigFormSetGuid, + DriverHandle, + BmcConfigDxeStrings, + BmcConfigVfrBin, + NULL + ); + if (mHiiHandle == NULL) { + ASSERT (mHiiHandle != NULL); + return EFI_OUT_OF_RESOURCES; + } + + Status = UpdateBmcConfigForm (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a Failed to update the BMC Configuration screen\n", __func__)); + } + + return Status; +} diff --git a/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.uni b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.uni new file mode 100644 index 000000000000..2d4b3c620eb9 --- /dev/null +++ b/Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.uni @@ -0,0 +1,18 @@ +// +// Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR> +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// + +#langdef en-US "English" // English + +#string STR_BMC_CONFIG_FORM #language en-US "BMC Configuration" +#string STR_BMC_CONFIG_HELP #language en-US "BMC Configuration" + +#string STR_BMC_FIRMWARE_REV_LABEL #language en-US "BMC Firmware Revision" +#string STR_BMC_FIRMWARE_REV_VALUE #language en-US "Unknown" + +#string STR_BMC_IPMI_VER_LABEL #language en-US "IPMI Version" +#string STR_BMC_IPMI_VER_VALUE #language en-US "Unknown" + +#string STR_BMC_IP_ADDRESS_LABEL #language en-US "LAN IP Address" -- 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#120333): https://edk2.groups.io/g/devel/message/120333 Mute This Topic: https://groups.io/mt/107889121/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-