From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web12.15246.1601219832706374202 for ; Sun, 27 Sep 2020 08:17:12 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@hpe.com header.s=pps0720 header.b=C+7Ab/ml; spf=pass (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=05397b83fd=abner.chang@hpe.com) Received: from pps.filterd (m0148664.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08RFHC0m009777; Sun, 27 Sep 2020 15:17:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pps0720; bh=eh0e78pHyv3ecmOWHsIMJfGv1IyPpPTlj0t33fPm9go=; b=C+7Ab/mlBNWOc97zFB08/oFCE8ku7vjUiocR7eTzpuL0F8s9+9lo+Dfbdyt2guq4UbO8 sdOuUwtPo2kv2zO6vvNVtofJQsMIXFyAekEqJY8erGtPJIak3aGQwBhrbZjmDuJBRh/O v4vGP0WvzvDg84L4qLnKiZagdxDv3U7GgL2mnucl6bz6FwE1cvgWvoQlj0PX4cMgaPql ORaHBi/TSYBsi37IXyN1GjLJP6czJKWUkqzE0X5JNs2wF4SLlnxd5Zl5cuJA/VNbBf6e 1eaNALDnJ4hs/+IHgV2Kv16LCnGI3rpgsw7uVCp5+i1KJAQzvH3Y7f95JId6aeq/+4io og== Received: from g9t5009.houston.hpe.com (g9t5009.houston.hpe.com [15.241.48.73]) by mx0b-002e3701.pphosted.com with ESMTP id 33svruy3mj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 27 Sep 2020 15:17:11 +0000 Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g9t5009.houston.hpe.com (Postfix) with ESMTP id CE10355; Sun, 27 Sep 2020 15:16:59 +0000 (UTC) Received: from SAC2XFT1JT.asiapacific.hpqcorp.net (sac2xft1jt.asiapacific.hpqcorp.net [10.43.42.132]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id 3EA8348; Sun, 27 Sep 2020 15:16:58 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: abner.chang@hpe.com, Jiaxin Wu , Siyuan Fu , Fan Wang , Jiewen Yao , Nickle Wang Subject: [edk2-staging/RedfishHostInterfaceDxe PATCH 4/5] RedfishPkg/RedfishHostInterfaceDxe: RedfishHostInterface driver Date: Sun, 27 Sep 2020 23:16:57 +0800 Message-Id: <20200927151657.461956-1-abner.chang@hpe.com> X-Mailer: git-send-email 2.21.0.windows.1 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-09-27_12:2020-09-24,2020-09-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 adultscore=0 clxscore=1015 bulkscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=809 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009270146 X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-002e3701.pphosted.com id 08RFHC0m009777 Content-Type: text/plain; charset=unknown-8bit Content-Transfer-Encoding: quoted-printable BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2912 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 --- .../BZ2912RedfishHostInterfaceDxe.c | 243 ++++++++++++++++++ .../BZ2912RedfishHostInterfaceDxe.inf | 50 ++++ 2 files changed, 293 insertions(+) create mode 100644 RedfishPkg/RedfishHostInterfaceDxe/BZ2912RedfishHostI= nterfaceDxe.c create mode 100644 RedfishPkg/RedfishHostInterfaceDxe/BZ2912RedfishHostI= nterfaceDxe.inf diff --git a/RedfishPkg/RedfishHostInterfaceDxe/BZ2912RedfishHostInterfac= eDxe.c b/RedfishPkg/RedfishHostInterfaceDxe/BZ2912RedfishHostInterfaceDxe= .c new file mode 100644 index 00000000000..91de4703554 --- /dev/null +++ b/RedfishPkg/RedfishHostInterfaceDxe/BZ2912RedfishHostInterfaceDxe.c @@ -0,0 +1,243 @@ +=EF=BB=BF/** @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, = &DeviceDescriptor); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_NOT_FOUND) { + DEBUG ((DEBUG_ERROR, "%a: No Redfish host interface descriptor is = provided on this platform.", __FUNCTION__)); + return EFI_NOT_FOUND; + } + DEBUG((DEBUG_ERROR, "%a: Fail to get device descriptor, %r.", __FUNC= TION__, 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 0= 5h as Redfish host interface.", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + if (DeviceType =3D=3D REDFISH_HOST_INTERFACE_DEVICE_TYPE_PCI_PCIE_V2) = { + DeviceDataLength =3D DeviceDescriptor->DeviceDescriptor.PciPcieDevic= eV2.Length; + } else { + DeviceDataLength =3D DeviceDescriptor->DeviceDescriptor.UsbDeviceV2.= Length; + } + // + // 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 proto= col 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) - si= zeof(ProtocolRecord->ProtocolTypeData) + ProtocolRecord->ProtocolTypeData= Len; + 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, Protocol= DataSize); + NewProtocolRecords =3D ProtocolRecords; + } else { + NewProtocolRecords =3D ReallocatePool(CurrentProtocolsDataLength, = NewProtocolsDataLength, (VOID *)ProtocolRecords); + if (NewProtocolRecords =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Fail to allocate memory for Redfish ho= st interface protocol data.")); + FreePool (ProtocolRecords); + FreePool (ProtocolRecord); + return EFI_OUT_OF_RESOURCES; + } + CopyMem ( + (VOID *)((UINT8 *)NewProtocolRecords + CurrentProtocolsDataLengt= h), + (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 ind= icator + // 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 C= ount + + CurrentProtocolsDataLength + + 2 /// Double NULL terminato= r/ + ); + if (Type42Record =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto ON_EXIT; + } + + Type42Record->Hdr.Type =3D EFI_SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOS= T_INTERFACE; + Type42Record->Hdr.Length =3D sizeof (SMBIOS_TABLE_TYPE42) - 4 + + DeviceDataLength + + 1 + + CurrentProtocolsDataLength; + Type42Record->Hdr.Handle =3D 0; + Type42Record->InterfaceType =3D MCHostInterfaceTypeNetworkHostInterfac= e; // Network Host Interface + + // + // Fill in InterfaceTypeSpecificDataLength field + // + Type42Record->InterfaceTypeSpecificDataLength =3D DeviceDataLength; + + // + // Fill in InterfaceTypeSpecificData field + // + CopyMem (Type42Record->InterfaceTypeSpecificData, DeviceDescriptor, De= viceDataLength); + FreePool (DeviceDescriptor); + DeviceDescriptor =3D NULL; + + // + // Fill in InterfaceTypeSpecificData Protocol Count field + // + *(Type42Record->InterfaceTypeSpecificData + DeviceDataLength) =3D Prot= ocolCount; + + // + // 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/BZ2912RedfishHostInterfac= eDxe.inf b/RedfishPkg/RedfishHostInterfaceDxe/BZ2912RedfishHostInterfaceD= xe.inf new file mode 100644 index 00000000000..509dadf81b6 --- /dev/null +++ b/RedfishPkg/RedfishHostInterfaceDxe/BZ2912RedfishHostInterfaceDxe.in= f @@ -0,0 +1,50 @@ +=EF=BB=BF## @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-FEAD92C4A0A= 4 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D RedfishHostInterfaceDxeEntryPoint + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 RISCV64 +# + +[Sources] + BZ2912RedfishHostInterfaceDxe.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.21.0.windows.1