From nobody Wed May 8 17:51:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+66159+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+66159+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1602564807; cv=none; d=zohomail.com; s=zohoarc; b=Wn7akPXi0kElU62+dUreM0ukW4oF2uIFM8CUn4j7qaurRmc6ja3WBMcDHQpQXMfSD1TYdarEC89a10wMw5kgbHpLGitUCjFNtytwowg3nE4c/8Vi8uZFNqjV2544PX8gdZmUCfbLLOhstpjIpuMiP0glxc1gk1dUMG63lPd33O4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602564807; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Lsfen0CuFA6UDXi3t7StSudbti2coHhosqrJWcCrpUQ=; b=TOniuV5Rq0A16a8QL5kdIEHyzFobskLSvaWtDALZ8pf7F4rWMcd9nLjodsD0NRQ6HutuB0ukjI9PqMdpR8roNta+hBxaedipY+SEGOljxco8lK4SZ7M1sPyMEwTqKmcMlgMnG3XpY/lXywXRqYMItuOXO75KbJGjD+Fj2h6Oh3k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+66159+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1602564807248598.8212454809616; Mon, 12 Oct 2020 21:53:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id pxK0YY1788612xaLacaIYv1S; Mon, 12 Oct 2020 21:53:26 -0700 X-Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web10.4804.1602564805283850685 for ; Mon, 12 Oct 2020 21:53:25 -0700 X-Received: from pps.filterd (m0134423.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 09D4rOqN015429; Tue, 13 Oct 2020 04:53:24 GMT X-Received: from g4t3427.houston.hpe.com (g4t3427.houston.hpe.com [15.241.140.73]) by mx0b-002e3701.pphosted.com with ESMTP id 343avatu86-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Oct 2020 04:53:24 +0000 X-Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g4t3427.houston.hpe.com (Postfix) with ESMTP id A3A4C5E; Tue, 13 Oct 2020 04:52:48 +0000 (UTC) X-Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g4t3433.houston.hpecorp.net (Postfix) with ESMTP id 4873445; Tue, 13 Oct 2020 04:52:47 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Jiaxin Wu , Siyuan Fu , Fan Wang , Jiewen Yao , Nickle Wang Subject: [edk2-devel] [EFI Redfish Host Interface PATCH 4/5] RedfishPkg/RedfishHostInterfaceDxe: Create SMBIOS type 42 record Date: Tue, 13 Oct 2020 12:08:04 +0800 Message-Id: <20201013040805.20523-5-abner.chang@hpe.com> In-Reply-To: <20201013040805.20523-1-abner.chang@hpe.com> References: <20201013040805.20523-1-abner.chang@hpe.com> X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@hpe.com X-Gm-Message-State: VfprABmbnDADdYvnSHw2d0WSx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1602564806; bh=PPwydnlwzpFvHGdXWvOTkDzJo90h7HrRX/2KCdjfGO0=; h=Cc:Date:From:Reply-To:Subject:To; b=TEsAQOH9dvlPb8amyQWICgX9s8aXii8lfgmlYEP8D0oxnKCgkB0FYKssTQ1R67RiOK5 RFV8o0VVl858AQP5rbVBZB6XaNseHetX+7rQkYByq1rPP3JvVOLVQKbLTyHb/Sp9xVLCW SWgIlsHZo6385dpoW+KeaFa6vvffD2cmJWQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is the abstract driver to consume the contents of SMBIOS type 42h device descriptor and protocol type data which provided by PlatformHostInterfaceLib, and create SMBIOS type 42 record through EFI SMBIOS protocol. Signed-off-by: Abner Chang Cc: Jiaxin Wu Cc: Siyuan Fu Cc: Fan Wang Cc: Jiewen Yao Cc: Nickle Wang Reviewed-by: Nickle Wang --- .../RedfishHostInterfaceDxe.c | 243 ++++++++++++++++++ .../RedfishHostInterfaceDxe.inf | 50 ++++ 2 files changed, 293 insertions(+) create mode 100644 RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterface= Dxe.c create mode 100644 RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterface= Dxe.inf diff --git a/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c b= /RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c new file mode 100644 index 0000000000..ec7faefed7 --- /dev/null +++ b/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.c @@ -0,0 +1,243 @@ +/** @file + RedfishHostInterfaceDxe builds up SMBIOS Type 42h host interface + record for Redfish service host interface using EFI MBIOS Protocol. + RedfishHostInterfacePlatformLib is the platform-level library which + provides the content of Redfish host interface type 42h record. + + Copyright (c) 2019, Intel Corporation. All rights reserved.
+ (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + Create SMBIOS type 42 record for Redfish host interface. + + @retval EFI_SUCESS SMBIOS type 42 record is created. + @retval Others Fail to create SMBIOS 42 record. + +**/ +EFI_STATUS +RedfishCreateSmbiosTable42 ( + VOID + ) +{ + REDFISH_INTERFACE_DATA *DeviceDescriptor; + UINT8 DeviceDataLength; + UINT8 DeviceType; + EFI_STATUS Status; + MC_HOST_INTERFACE_PROTOCOL_RECORD *ProtocolRecord; + VOID *ProtocolRecords; + VOID *NewProtocolRecords; + UINT8 ProtocolCount; + UINT8 CurrentProtocolsDataLength; + UINT8 NewProtocolsDataLength; + UINT8 ProtocolDataSize; + SMBIOS_TABLE_TYPE42 *Type42Record; + EFI_SMBIOS_PROTOCOL *Smbios; + EFI_SMBIOS_HANDLE MemArrayMappedAddrSmbiosHandle; + + // + // Get platform Redfish host interface device type descriptor data. + // + Status =3D RedfishPlatformHostInterfaceDeviceDescriptor (&DeviceType, &D= eviceDescriptor); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_NOT_FOUND) { + DEBUG ((DEBUG_ERROR, "%a: No Redfish host interface descriptor is pr= ovided on this platform.", __FUNCTION__)); + return EFI_NOT_FOUND; + } + DEBUG((DEBUG_ERROR, "%a: Fail to get device descriptor, %r.", __FUNCTI= ON__, Status)); + return Status; + } + if (DeviceType !=3D REDFISH_HOST_INTERFACE_DEVICE_TYPE_USB_V2 && + DeviceType !=3D REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2 + ) { + DEBUG ((DEBUG_ERROR, "%a: Only support either protocol type 04h or 05h= as Redfish host interface.", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + if (DeviceType =3D=3D REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) { + DeviceDataLength =3D DeviceDescriptor->DeviceDescriptor.PciPcieDeviceV= 2.Length; + } else { + DeviceDataLength =3D DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.Le= ngth; + } + // + // Loop to get platform Redfish host interface protocol type data. + // + ProtocolRecord =3D NULL; + ProtocolRecords =3D NULL; + NewProtocolRecords =3D NULL; + Type42Record =3D NULL; + ProtocolCount =3D 0; + CurrentProtocolsDataLength =3D 0; + NewProtocolsDataLength =3D 0; + while (TRUE) { + Status =3D RedfishPlatformHostInterfaceProtocolData (&ProtocolRecord, = ProtocolCount); + if (Status =3D=3D EFI_NOT_FOUND) { + break; + } + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to get Redfish host interafce protoco= l type data.", __FUNCTION__)); + if (ProtocolRecords !=3D NULL) { + FreePool (ProtocolRecords); + } + if (ProtocolRecord !=3D NULL) { + FreePool (ProtocolRecord); + } + return Status; + } + ProtocolDataSize =3D sizeof (MC_HOST_INTERFACE_PROTOCOL_RECORD) - size= of(ProtocolRecord->ProtocolTypeData) + ProtocolRecord->ProtocolTypeDataLen; + NewProtocolsDataLength +=3D ProtocolDataSize; + if (ProtocolRecords =3D=3D NULL) { + ProtocolRecords =3D AllocateZeroPool (NewProtocolsDataLength); + if (ProtocolRecords =3D=3D NULL) { + FreePool (ProtocolRecord); + return EFI_OUT_OF_RESOURCES; + } + CopyMem ((VOID *)ProtocolRecords, (VOID *)ProtocolRecord, ProtocolDa= taSize); + NewProtocolRecords =3D ProtocolRecords; + } else { + NewProtocolRecords =3D ReallocatePool(CurrentProtocolsDataLength, Ne= wProtocolsDataLength, (VOID *)ProtocolRecords); + if (NewProtocolRecords =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for Redfish host= interface protocol data.")); + FreePool (ProtocolRecords); + FreePool (ProtocolRecord); + return EFI_OUT_OF_RESOURCES; + } + CopyMem ( + (VOID *)((UINT8 *)NewProtocolRecords + CurrentProtocolsDataLength), + (VOID *)ProtocolRecord, + ProtocolDataSize + ); + } + FreePool (ProtocolRecord); + CurrentProtocolsDataLength =3D NewProtocolsDataLength; + ProtocolCount ++; + }; + if (ProtocolCount =3D=3D 0) { + goto ON_EXIT; + } + // + // Construct SMBIOS Type 42h for Redfish host inteface. + // + // SMBIOS type 42 Record for Redfish Interface + // 00h Type BYTE 42 Management Controller Host Interface structure indic= ator + // 01h Length BYTE Varies Length of the structure, a minimum of 09h + // 02h Handle WORD Varies + // 04h Interface Type BYTE Varies Management Controller Interface Type. + // 05h Interface Specific Data Length (n) + // 06h Interface Specific data + // 06h+n number of protocols defined for the host interface (typically 1) + // 07h+n Include a Protocol Record for each protocol supported. + // + Type42Record =3D (SMBIOS_TABLE_TYPE42 *) AllocateZeroPool ( + sizeof (SMBIOS_TABLE_TYPE42) - 4 + + DeviceDataLength + + 1 /// For Protocol Record Cou= nt + + CurrentProtocolsDataLength + + 2 /// Double NULL terminator/ + ); + if (Type42Record =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + + Type42Record->Hdr.Type =3D EFI_SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_= INTERFACE; + Type42Record->Hdr.Length =3D sizeof (SMBIOS_TABLE_TYPE42) - 4 + + DeviceDataLength + + 1 + + CurrentProtocolsDataLength; + Type42Record->Hdr.Handle =3D 0; + Type42Record->InterfaceType =3D MCHostInterfaceTypeNetworkHostInterface;= // Network Host Interface + + // + // Fill in InterfaceTypeSpecificDataLength field + // + Type42Record->InterfaceTypeSpecificDataLength =3D DeviceDataLength; + + // + // Fill in InterfaceTypeSpecificData field + // + CopyMem (Type42Record->InterfaceTypeSpecificData, DeviceDescriptor, Devi= ceDataLength); + FreePool (DeviceDescriptor); + DeviceDescriptor =3D NULL; + + // + // Fill in InterfaceTypeSpecificData Protocol Count field + // + *(Type42Record->InterfaceTypeSpecificData + DeviceDataLength) =3D Protoc= olCount; + + // + // Fill in Redfish Protocol Data + // + CopyMem ( + Type42Record->InterfaceTypeSpecificData + DeviceDataLength + 1, + NewProtocolRecords, + CurrentProtocolsDataLength + ); + + // + // 5. Add Redfish interface data record to SMBIOS table 42 + // + Status =3D gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID**)&= Smbios); + if (EFI_ERROR (Status)) { + goto ON_EXIT; + } + + MemArrayMappedAddrSmbiosHandle =3D SMBIOS_HANDLE_PI_RESERVED; + Status =3D Smbios->Add ( + Smbios, + NULL, + &MemArrayMappedAddrSmbiosHandle, + (EFI_SMBIOS_TABLE_HEADER*) Type42Record + ); + DEBUG ((DEBUG_INFO, "RedfishPlatformDxe: Smbios->Add() - %r\n", Status)); + if (EFI_ERROR (Status)) { + goto ON_EXIT; + } + Status =3D EFI_SUCCESS; + +ON_EXIT: + if (DeviceDescriptor !=3D NULL) { + FreePool (DeviceDescriptor); + } + if (NewProtocolRecords !=3D NULL) { + FreePool (NewProtocolRecords); + } + if (Type42Record !=3D NULL) { + FreePool (Type42Record); + } + return Status; +} + +/** + Main entry for this driver. + + @param ImageHandle Image handle this driver. + @param SystemTable Pointer to SystemTable. + + @retval EFI_SUCESS This function always complete successfully. + +**/ +EFI_STATUS +EFIAPI +RedfishHostInterfaceDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + // + // Create SMBIOS type 42 record. + // + return RedfishCreateSmbiosTable42 (); +} diff --git a/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.inf= b/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.inf new file mode 100644 index 0000000000..6c1f60bca5 --- /dev/null +++ b/RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.inf @@ -0,0 +1,50 @@ +## @file +# RedfishHostInterfaceDxe builds up SMBIOS Type 42h host interface +# record for Redfish service host interface using SMBIOS Protocol. +# RedfishHostInterfacePlatformLib is the platform-level library which +# provides the content of Redfish host interface type 42h record. +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+ +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001000b + BASE_NAME =3D RedfishHostInterfaceDxe + FILE_GUID =3D 592626DA-4A1E-8B39-28BA-FEAD92C4A0A4 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D RedfishHostInterfaceDxeEntryPoint + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 RISCV64 +# + +[Sources] + RedfishHostInterfaceDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishPkg/RedfishPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PrintLib + RedfishPlatformHostInterfaceLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + +[Protocols] + gEfiSmbiosProtocolGuid ## TO_START + +[Depex] + gEfiSmbiosProtocolGuid + --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#66159): https://edk2.groups.io/g/devel/message/66159 Mute This Topic: https://groups.io/mt/77477512/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-