From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.49]) by mx.groups.io with SMTP id smtpd.web11.73103.1680534335738937161 for ; Mon, 03 Apr 2023 08:05:35 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=fJinmJdO; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.244.49, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XMBv4ARwqrBMlMq4yDnl/ILpxxW261I1hK5uivOBikrW4oU/z5XMfRqzGyU+dmlMK4j8EyNGQb7H2eDYg4CFcamY/iRA0YeGAWT9IeJT4CK9AM8D9FtoWqyUpID/zbuz5NiNpX+By2+jUlb5054vqSAhnaz5kI+s3vMM+6995QBBQz/thB+6IQ+yFn1EyYM1bZPrg6j3J56bk9VzDF+2xJDk4pK4vPjx0B4v84mgN9/aBLs3x7tcQO3Xe7lPPbLjGHKI6PuDCubMUHYC5Aa6DjfIBvzyr+GmgxPd8/2aFIkVizfjYC6HJB3xahAZ39bcsxP1un3D247Rf62ln/S0Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7kuz4cQHk3WxFxtK1Hr9NEhdRZ0oum56U4cH8f+2k/Q=; b=ArT1lrwLZWYjwHpwKrjGSIXf4bBmeZcipjjzcHsRzPTHZCYaG0NgwLcM/cbSIn3hg5+6GUp9rBn3nLxfLKTxCQv9woLH7kdf9zs0kPx9pFt6pU4QNFV7eoKnC+xsHNFJpsJKSuCo/7lXONLDMifV6tE7x1bOZOnYt8pv7oFYWncP1nYnRqWU8DnajTEmQ0+rw0+YrPcZkuzj0eEiLxLQb0/zidAnIgCuYjtCGxjnYnZpiimafHACpRUhKnDs5dn5R3D8CLPlm7qMRMcwpBIOFRhtjWmtaCg2Md3icEZSEZyFPEZ4wGt36KXC5pa822PEqy8BYFiXz/MuXCCM9jDS5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7kuz4cQHk3WxFxtK1Hr9NEhdRZ0oum56U4cH8f+2k/Q=; b=fJinmJdOBuUqtUBX7ipu2E6hD+/T6YHeXwdn9mCa+t5iOrN9CJcVOi8qUNw3GNXjBpUQ1MV2BYHLeQ6hULA7cWMehkcnRK3bhbW6PNts/LKiK5/EQ/pwSgczoENbV6Rv+eFNKS1L3lxG3HxmMHJGLqTszIn3y/n6IMuY97D1jyY= Received: from DM5PR07CA0073.namprd07.prod.outlook.com (2603:10b6:4:ad::38) by IA1PR12MB8189.namprd12.prod.outlook.com (2603:10b6:208:3f0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.33; Mon, 3 Apr 2023 15:05:31 +0000 Received: from DM6NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:4:ad:cafe::ba) by DM5PR07CA0073.outlook.office365.com (2603:10b6:4:ad::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.22 via Frontend Transport; Mon, 3 Apr 2023 15:05:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT041.mail.protection.outlook.com (10.13.172.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6277.15 via Frontend Transport; Mon, 3 Apr 2023 15:05:30 +0000 Received: from TPE-L1-ABNCHANG.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 3 Apr 2023 10:05:28 -0500 From: "Chang, Abner" To: CC: Isaac Oram , Abdul Lateef Attar , Nickle Wang , Igor Kulchytskyy Subject: [edk2-platforms][PATCH 06/14] ManageabilityPkg: Add PldmSmbiosTransferDxe driver Date: Mon, 3 Apr 2023 23:04:51 +0800 Message-ID: <20230403150459.925-7-abner.chang@amd.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20230403150459.925-1-abner.chang@amd.com> References: <20230403150459.925-1-abner.chang@amd.com> MIME-Version: 1.0 Return-Path: Abner.Chang@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT041:EE_|IA1PR12MB8189:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b7d7758-4ea4-4414-4cb1-08db3454ddfa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FKQmk2TGdApSYc1PU5+mZz/TJjC5RElv76DCejC23pJ+vLApfsLDzFm/jHGHdzbFWoQbRR+DuW5BMEfX1Y7zCpMqsuldk6K7ldp7ogeSII7SM2PQ27hA4lwBFBxIW2zSSo9fLn1j+yAudIVHN6jxU2hh0w8+aRGjPjFtte1yWQNldHcBsIGfDqWUxDprD6/gW0P5D7nCfCDb5k6CYAAw1VoIBrG2/tJrcBDH+vyWmKnQAYRfGUCO0wOlDYlCyBQ7Ulj8v5t21GefEj4C/lMTxPPAnWuWUOnck6L3Sp82y8rGvWgCh8ZFQNX7867gx+YkzsHvZZESNAHQMs53y125bZat1YjeGdXvWdXofeLECs9ISH6aH+GNHlApQBubzZtM8T0a04yZYaZ2kauOKAfhWVznWqMAjQLPW7EduP9xsqttH9ApMXLQFS2ZTnvwi0Hv6RhbmLVRyeDR60IwaIWv8qecrnXXG+u3IzoCqQXPSVBoJbfAE/GemUKTPFZsPTmWlYEOmFqufijOcXAOI3KaXPipUZzH6yNF+ELy4/b9JxA30Q0xODN57XgVloE0uT0Kzd2lxW9q99csntbOhnOvfiIFAsqFyU9lWyR81df7sydWU+WOHqtNTR1xZOwM9zFWwL4ubokyj/c5bJ6QQ5fPoJMzNpc/y2TUh09FHNOaN1v9DULNDK2ijKEfHtvHFp+W6lb7Kn7DmVRIJ1YUrI3kXcPUSJVRPR7hLrd2kIAUFTY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(39860400002)(376002)(346002)(396003)(451199021)(40470700004)(36840700001)(46966006)(2876002)(2906002)(40480700001)(47076005)(186003)(36756003)(83380400001)(16526019)(336012)(2616005)(426003)(1076003)(26005)(6666004)(36860700001)(40460700003)(7696005)(966005)(81166007)(5660300002)(8936002)(82740400003)(54906003)(316002)(356005)(19627235002)(30864003)(70206006)(4326008)(8676002)(82310400005)(41300700001)(6916009)(70586007)(86362001)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Apr 2023 15:05:30.8341 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b7d7758-4ea4-4414-4cb1-08db3454ddfa X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8189 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: abnchang Add edk2 driver that supports PLDM SMBIOS Transfer Specification. https://www.dmtf.org/sites/default/files/standards/documents/DSP0246_1.0.1.= pdf We currently only support "Push" mode of PLDM SMBIOS transfer. That says only BIOS to BMC direction is supported. The functionality is verified by checking the binary debug output of payload. Signed-off-by: Abner Chang Cc: Isaac Oram Cc: Abdul Lateef Attar Cc: Nickle Wang Cc: Igor Kulchytskyy --- .../ManageabilityPkg/ManageabilityPkg.dec | 1 + .../Include/Dsc/Manageability.dsc | 1 + .../PldmSmbiosTransferDxe.inf | 47 ++ .../Protocol/PldmSmbiosTransferProtocol.h | 184 +++++++ .../PldmSmbiosTransferDxe.c | 518 ++++++++++++++++++ 5 files changed, 751 insertions(+) create mode 100644 Features/ManageabilityPkg/Universal/PldmSmbiosTransferD= xe/PldmSmbiosTransferDxe.inf create mode 100644 Features/ManageabilityPkg/Include/Protocol/PldmSmbiosTr= ansferProtocol.h create mode 100644 Features/ManageabilityPkg/Universal/PldmSmbiosTransferD= xe/PldmSmbiosTransferDxe.c diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dec b/Features/Mana= geabilityPkg/ManageabilityPkg.dec index 1e9245c8dc..309faa8c98 100644 --- a/Features/ManageabilityPkg/ManageabilityPkg.dec +++ b/Features/ManageabilityPkg/ManageabilityPkg.dec @@ -51,3 +51,4 @@ =20 [Protocols] gEdkiiPldmProtocolGuid =3D { 0x60997616, 0xDB70, 0x4B5F, = { 0x86, 0xA4, 0x09, 0x58, 0xA3, 0x71, 0x47, 0xB4 } } + gEdkiiPldmSmbiosTransferProtocolGuid =3D { 0xFA431C3C, 0x816B, 0x4B32, = { 0xA3, 0xE0, 0xAD, 0x9B, 0x7F, 0x64, 0x27, 0x2E } } diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Feat= ures/ManageabilityPkg/Include/Dsc/Manageability.dsc index 59549eb39a..a5a4fd6615 100644 --- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc +++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc @@ -25,4 +25,5 @@ [Components.X64] ManageabilityPkg/Universal/IpmiProtocol/Dxe/IpmiProtocolDxe.inf ManageabilityPkg/Universal/IpmiProtocol/Smm/IpmiProtocolSmm.inf + ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosTransferDxe.i= nf =20 diff --git a/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/Pldm= SmbiosTransferDxe.inf b/Features/ManageabilityPkg/Universal/PldmSmbiosTrans= ferDxe/PldmSmbiosTransferDxe.inf new file mode 100644 index 0000000000..da49057982 --- /dev/null +++ b/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosT= ransferDxe.inf @@ -0,0 +1,47 @@ +## @file +# PLDM SMBIOS Transfer DXE Driver. +# +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001d + BASE_NAME =3D PldmSmbiosTransferDxe + FILE_GUID =3D 71BF5CF0-CE09-4C7C-912B-944BF4E4CBC0 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D DxePldmSmbiosTransferEntry + UNLOAD_IMAGE =3D PldmSmbiosTransferUnloadImage + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# + +[Sources] + PldmSmbiosTransferDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ManageabilityPkg/ManageabilityPkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + ManageabilityTransportLib + ManageabilityTransportHelperLib + PldmProtocolLib + UefiLib + UefiDriverEntryPoint + UefiBootServicesTableLib + +[Guids] + gEfiSmbios3TableGuid + +[Protocols] + gEfiSmbiosProtocolGuid + gEdkiiPldmSmbiosTransferProtocolGuid + +[Depex] + gEdkiiPldmProtocolGuid ## ALWAYS_CONSUMES diff --git a/Features/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferP= rotocol.h b/Features/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferPr= otocol.h new file mode 100644 index 0000000000..7903e12726 --- /dev/null +++ b/Features/ManageabilityPkg/Include/Protocol/PldmSmbiosTransferProtocol= .h @@ -0,0 +1,184 @@ +/** @file + Protocol of EDKII PLDM SMBIOS Transfer Protocol. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_H_ +#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_H_ + +#include + +typedef struct _EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL EDKII_PLDM_SMBIOS_TRA= NSFER_PROTOCOL; + +#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_GUID \ + { \ + 0xFA431C3C, 0x816B, 0x4B32, 0xA3, 0xE0, 0xAD, 0x9B, 0x7F, 0x64, 0x27, = 0x2E \ + } + +#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_VERSION_MAJOR 1 +#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_VERSION_MINOR 0 +#define EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_VERSION ((EDKII_PLDM_SM= BIOS_TRANSFER_PROTOCOL_VERSION_MAJOR << 8) |\ + EDKII_PLDM_SMBIOS_T= RANSFER_PROTOCOL_VERSION_MINOR) + +/** + This function gets SMBIOS table metadata. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance. + @param [out] Buffer Buffer to receive the SMBIOS table metadata. + + @retval EFI_SUCCESS Get SMBIOS table metadata Successfu= lly. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to get SMBIOS table metadata. +**/ +typedef +EFI_STATUS +(EFIAPI *PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA)( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + OUT PLDM_SMBIOS_STRUCTURE_TABLE_METADATA *Buffer + ); + +/** + This function sets SMBIOS table metadata. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance. + @param [in] Buffer Pointer to SMBIOS table metadata. + + @retval EFI_SUCCESS Set SMBIOS table metadata Successfu= lly. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to set SMBIOS table metadata. +**/ +typedef +EFI_STATUS +(EFIAPI *PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA)( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + IN PLDM_SMBIOS_STRUCTURE_TABLE_METADATA *Buffer + ); + +/** + This function gets SMBIOS structure table. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance. + @param [out] Buffer Pointer to the returned SMBIOS structure table= . + Caller has to free this memory block when it + is no longer needed. + @param [out] BufferSize Size of the returned message payload in buffer= . + + @retval EFI_SUCCESS Gets SMBIOS structure table success= fully. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to get SMBIOS structure table. +**/ +typedef +EFI_STATUS +(EFIAPI *PLDM_GET_SMBIOS_STRUCTURE_TABLE)( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + OUT UINT8 **Buffer, + OUT UINT32 *BufferSize + ); + +/** + This function sets SMBIOS structure table. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance. + + @retval EFI_SUCCESS Successful + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to set SMBIOS structure table. +**/ +typedef +EFI_STATUS +(EFIAPI *PLDM_SET_SMBIOS_STRUCTURE_TABLE)( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This + ); + +/** + This function gets particular type of SMBIOS structure. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL i= nstance. + @param [in] TypeId The type of SMBIOS structure. + @param [in] StructureInstanceId The instance ID of particular type of= SMBIOS structure. + @param [out] Buffer Pointer to the returned SMBIOS struct= ure. + Caller has to free this memory block = when it + is no longer needed. + @param [out] BufferSize Size of the returned message payload = in buffer. + + @retval EFI_SUCCESS Gets particular type of SMBIOS struct= ure successfully. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to set SMBIOS structure table. +**/ +typedef +EFI_STATUS +(EFIAPI *PLDM_GET_SMBIOS_STRUCTURE_BY_TYPE)( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + IN UINT8 TypeId, + IN UINT16 StructureInstanceId, + OUT UINT8 **Buffer, + OUT UINT32 *BufferSize + ); + +/** + This function gets particular handle of SMBIOS structure. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL i= nstance. + @param [in] Handle The handle of SMBIOS structure. + @param [out] Buffer Pointer to the returned SMBIOS struct= ure. + Caller has to free this memory block = when it + is no longer needed. + @param [out] BufferSize Size of the returned message payload = in buffer. + + @retval EFI_SUCCESS Gets particular handle of SMBIOS stru= cture successfully. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to set SMBIOS structure table. +**/ +typedef +EFI_STATUS +(EFIAPI *PLDM_GET_SMBIOS_STRUCTURE_BY_HANDLE)( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + IN UINT16 Handle, + OUT UINT8 **Buffer, + OUT UINT32 *BufferSize + ); + +// +// EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL +// +typedef struct { + PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA GetSmbiosStructureTableMetaD= ata; + PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA SetSmbiosStructureTableMetaD= ata; + PLDM_GET_SMBIOS_STRUCTURE_TABLE GetSmbiosStructureTable; + PLDM_SET_SMBIOS_STRUCTURE_TABLE SetSmbiosStructureTable; + PLDM_GET_SMBIOS_STRUCTURE_BY_TYPE GetSmbiosStructureByType; + PLDM_GET_SMBIOS_STRUCTURE_BY_HANDLE GetSmbiosStructureByHandle; +} EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_V1_0; + +/// +/// Definitions of EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL. +/// This is a union that can accommodate the new functionalities defined +/// in PLDM SMBIOS Transfer specification in the future. +/// The new added function must has its own EDKII_PLDM_SMBIOS_TRANSFER_PRO= TOCOL +/// structure with the incremental version number. +/// e.g., EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_V1_1. +/// +/// The new function must be added base on the last version of +/// EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL to keep the backward compatibility= . +/// +typedef union { + EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_V1_0 *Version1_0; +} EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_FUNCTION; + +struct _EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL { + UINT16 ProtocolVersion; + EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_FUNCTION Functions; +}; + +extern EFI_GUID gEdkiiPldmSmbiosTransferProtocolGuid; + +#endif // EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_H_ diff --git a/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/Pldm= SmbiosTransferDxe.c b/Features/ManageabilityPkg/Universal/PldmSmbiosTransfe= rDxe/PldmSmbiosTransferDxe.c new file mode 100644 index 0000000000..5f1b1028f3 --- /dev/null +++ b/Features/ManageabilityPkg/Universal/PldmSmbiosTransferDxe/PldmSmbiosT= ransferDxe.c @@ -0,0 +1,518 @@ +/** @file + This file provides edk2 PLDM SMBIOS Transfer Protocol implementation. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Revision Reference: + Platform Level Data Model (PLDM) for SMBIOS Data Transfer Specification + Version 1.0.1 + https://www.dmtf.org/sites/default/files/standards/documents/DSP0246_1.= 0.1.pdf +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +UINT32 SetSmbiosStructureTableHandle; + +/** + Get the full size of SMBIOS structure including optional strings that fo= llow the formatted structure. + + @param Head Pointer to the beginning of SMBIOS structu= re. + @param NumberOfStrings The returned number of optional strings th= at follow the formatted structure. + + @return Size The returned size. +**/ +UINTN +GetSmbiosStructureSize ( + IN EFI_SMBIOS_TABLE_HEADER *Head, + OUT UINTN *NumberOfStrings + ) +{ + UINTN Size; + UINTN StrLen; + CHAR8 *CharInStr; + UINTN StringsNumber; + + CharInStr =3D (CHAR8 *)Head + Head->Length; + Size =3D Head->Length; + StringsNumber =3D 0; + StrLen =3D 0; + // + // look for the two consecutive zeros, check the string limit by the way= . + // + while (*CharInStr !=3D 0 || *(CharInStr+1) !=3D 0) { + if (*CharInStr =3D=3D 0) { + Size +=3D 1; + CharInStr++; + } + + for (StrLen =3D 0; StrLen < SMBIOS_STRING_MAX_LENGTH; StrLen++) { + if (*(CharInStr+StrLen) =3D=3D 0) { + break; + } + } + + if (StrLen =3D=3D SMBIOS_STRING_MAX_LENGTH) { + return 0; + } + + // + // forward the pointer + // + CharInStr +=3D StrLen; + Size +=3D StrLen; + StringsNumber +=3D 1; + } + + // + // count ending two zeros. + // + Size +=3D 2; + + if (NumberOfStrings !=3D NULL) { + *NumberOfStrings =3D StringsNumber; + } + + return Size; +} + +/** + + This function returns full SMBIOS table length. + + @param TableAddress SMBIOS table based address + @param TableMaximumSize Maximum size of SMBIOS table + + @return SMBIOS table length + +**/ +UINTN +GetSmbiosTableLength ( + IN VOID *TableAddress, + IN UINTN TableMaximumSize + ) +{ + VOID *TableEntry; + VOID *TableAddressEnd; + UINTN TableEntryLength; + + TableAddressEnd =3D (VOID *)((UINTN)TableAddress + TableMaximumSize); + TableEntry =3D TableAddress; + while (TableEntry < TableAddressEnd) { + TableEntryLength =3D GetSmbiosStructureSize (TableEntry, NULL); + if (TableEntryLength =3D=3D 0) { + break; + } + + if (((SMBIOS_STRUCTURE *)TableEntry)->Type =3D=3D 127) { + TableEntry =3D (VOID *)((UINTN)TableEntry + TableEntryLength); + break; + } + + TableEntry =3D (VOID *)((UINTN)TableEntry + TableEntryLength); + } + + return ((UINTN)TableEntry - (UINTN)TableAddress); +} + +/** + This function gets SMBIOS table metadata. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance. + @param [out] Buffer Buffer to receive the SMBIOS table metadata. + + @retval EFI_SUCCESS Get SMBIOS table metadata Successfu= lly. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to get SMBIOS table metadata. +**/ +EFI_STATUS +EFIAPI +GetSmbiosStructureTableMetaData ( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + OUT PLDM_SMBIOS_STRUCTURE_TABLE_METADATA *Buffer + ) +{ + EFI_STATUS Status; + UINT32 ResponseSize; + + DEBUG((DEBUG_INFO, "%a: Set SMBIOS structure table metafile.\n", __FUNCT= ION__)); + + ResponseSize =3D sizeof (PLDM_SMBIOS_STRUCTURE_TABLE_METADATA); + Status =3D PldmSubmitCommand ( + PLDM_TYPE_SMBIOS, + PLDM_GET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_CODE, + NULL, + 0, + (UINT8 *)Buffer, + &ResponseSize + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fails to get SMBIOS structure table metafile= .\n", __FUNCTION__)); + } + if (ResponseSize !=3D 0) { + HelperManageabilityDebugPrint( + (VOID *)Buffer, + ResponseSize, + "SMBIOS structure table metafile got from BMC.\n" + ); + } + return Status; +} + +/** + This function sets SMBIOS table metadata. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance. + + @retval EFI_SUCCESS Set SMBIOS table metadata Successfu= lly. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to set SMBIOS table metadata. +**/ +EFI_STATUS +EFIAPI +SetSmbiosStructureTableMetaData ( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + IN PLDM_SMBIOS_STRUCTURE_TABLE_METADATA *Buffer + ) +{ + EFI_STATUS Status; + UINT32 ResponseSize; + UINT32 RequestSize; + + DEBUG((DEBUG_INFO, "%a: Get SMBIOS structure table metafile.\n", __FUNCT= ION__)); + + RequestSize =3D sizeof(PLDM_SMBIOS_STRUCTURE_TABLE_METADATA); + ResponseSize =3D 0; + + Status =3D PldmSubmitCommand ( + PLDM_TYPE_SMBIOS, + PLDM_SET_SMBIOS_STRUCTURE_TABLE_METADATA_COMMAND_CODE, + (UINT8 *)Buffer, + RequestSize, + (UINT8 *)NULL, + &ResponseSize + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fails to set SMBIOS structure table metafile= .\n", __FUNCTION__)); + } + + return Status; +} + +/** + This function gets SMBIOS structure table. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance. + @param [out] Buffer Pointer to the returned SMBIOS structure table= . + Caller has to free this memory block when it + is no longer needed. + @param [out] BufferSize Size of the returned message payload in buffer= . + + @retval EFI_SUCCESS Gets SMBIOS structure table success= fully. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to get SMBIOS structure table. +**/ +EFI_STATUS +EFIAPI +GetSmbiosStructureTable ( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + OUT UINT8 **Buffer, + OUT UINT32 *BufferSize + ) +{ + DEBUG ((DEBUG_INFO, "%a: Unsupported.\n", __FUNCTION__)); + // Only support PLDM SMBIOS Transfer push mode. + return EFI_UNSUPPORTED; +} + +/** + This function sets SMBIOS structure table. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL instance. + + @retval EFI_SUCCESS Successful + @retval EFI_NOT_FOUND No SMBIOS record found on system. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to set SMBIOS structure table. +**/ +EFI_STATUS +EFIAPI +SetSmbiosStructureTable ( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This + ) +{ + EFI_STATUS Status; + SMBIOS_TABLE_3_0_ENTRY_POINT *SmbiosEntry; + EFI_SMBIOS_HANDLE SmbiosHandle; + EFI_SMBIOS_PROTOCOL *Smbios; + UINT32 PaddingSize; + UINT32 ResponseSize; + UINT32 RequestSize; + UINT8 *RequestBuffer; + UINT8 *DataPointer; + UINT32 Crc32; + UINT16 TableLength; + EFI_SMBIOS_TABLE_HEADER *Record; + PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST *PldmSetSmbiosStructureTable; + + DEBUG((DEBUG_INFO, "%a: Set SMBIOS structure table.\n", __FUNCTION__)); + + Status =3D gBS->LocateProtocol ( + &gEfiSmbiosProtocolGuid, + NULL, + (VOID **)&Smbios + ); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "%a: No Efi SMBIOS Protocol installed.\n")); + return EFI_UNSUPPORTED; + } + if (Smbios->MajorVersion < 3) { + DEBUG((DEBUG_ERROR, "%a: We don't support SMBIOS spec version earlier = than v3.0.\n")); + return EFI_UNSUPPORTED; + } + Status =3D EfiGetSystemConfigurationTable ( + &gEfiSmbios3TableGuid, + (VOID **)&SmbiosEntry + ); + if (Status !=3D EFI_SUCCESS) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get system configuration table.\n"= )); + return Status; + } + + // + // Print out SMBIOS table information. + DEBUG ((DEBUG_INFO, "PldmSetSmbiosStructureTable SmbiosTable:\n")); + DEBUG (( + DEBUG_INFO, + "AnchorString ------ '%c%c%c%c%c'\n", + SmbiosEntry->AnchorString[0], + SmbiosEntry->AnchorString[1], + SmbiosEntry->AnchorString[2], + SmbiosEntry->AnchorString[3], + SmbiosEntry->AnchorString[4] + )); + + DEBUG((DEBUG_INFO, "EntryPointStructureChecksum ------ 0x%02x\n", Smbios= Entry->EntryPointStructureChecksum)); + DEBUG((DEBUG_INFO, "EntryPointLength ------ 0x%02x\n", Smbios= Entry->EntryPointLength)); + DEBUG((DEBUG_INFO, "MajorVersion ------ 0x%02x\n", Smbios= Entry->MajorVersion)); + DEBUG((DEBUG_INFO, "MinorVersion ------ 0x%02x\n", Smbios= Entry->MinorVersion)); + DEBUG((DEBUG_INFO, "DocRev ------ 0x%02x\n", Smbios= Entry->DocRev)); + DEBUG((DEBUG_INFO, "MaxStructureSize ------ 0x%08x\n", Smbios= Entry->TableMaximumSize)); + DEBUG((DEBUG_INFO, "EntryPointRevision - 0x%02x\n", Smbios= Entry->EntryPointRevision)); + DEBUG((DEBUG_INFO, "TableMaximumSize - 0x%08x\n", Smbios= Entry->TableMaximumSize)); + DEBUG((DEBUG_INFO, "TableAddress - 0x%016lx\n", Smbi= osEntry->TableAddress)); + + SmbiosHandle =3D SMBIOS_HANDLE_PI_RESERVED; + do { + Status =3D Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL= ); + if (EFI_ERROR(Status)) { + break; + } + DEBUG((DEBUG_INFO, " SMBIOS type %d to BMC\n", Record->Type)); + } while(Status =3D=3D EFI_SUCCESS); + + TableLength =3D GetSmbiosTableLength ((VOID *)(UINTN)SmbiosEntry->TableA= ddress, SmbiosEntry->TableMaximumSize); + + // Padding requirement (0 ~ 3 bytes) + PaddingSize =3D (4 - (TableLength % 4)) % 4; + + // Total request buffer size =3D PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST= + SMBIOS tables + padding + checksum + RequestSize =3D (UINT32)(sizeof(PLDM_SET_SMBIOS_STRUCTURE_TABLE_REQUEST)= + TableLength + PaddingSize + sizeof(Crc32)); + RequestBuffer =3D (UINT8 *)AllocatePool (RequestSize); + if (RequestBuffer =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: No memory resource for sending SetSmbiosStru= ctureTable.\n")); + return EFI_OUT_OF_RESOURCES; + } + + // Fill in smbios tables + CopyMem ( + (VOID *)((UINT8 *)RequestBuffer + sizeof(PLDM_SET_SMBIOS_STRUCTURE_TAB= LE_REQUEST)), + (VOID *)(UINTN) SmbiosEntry->TableAddress, + TableLength + ); + + // Fill in padding + DataPointer =3D RequestBuffer + sizeof(PLDM_SET_SMBIOS_STRUCTURE_TABLE_R= EQUEST) + TableLength; + ZeroMem ((VOID *)DataPointer, PaddingSize); + + // Fill in checksum + gBS->CalculateCrc32 ( + (VOID *)(RequestBuffer + sizeof(PLDM_SET_SMBIOS_STRUCTURE_TABLE_R= EQUEST)), + TableLength + PaddingSize, + &Crc32 + ); + DataPointer +=3D PaddingSize; + CopyMem ((VOID *)DataPointer, (VOID *)&Crc32, 4); + + PldmSetSmbiosStructureTable =3D (PLDM_SET_SMBIOS_STR= UCTURE_TABLE_REQUEST *)RequestBuffer; + PldmSetSmbiosStructureTable->DataTransferHandle =3D SetSmbiosStructureTa= bleHandle; + PldmSetSmbiosStructureTable->TransferFlag =3D PLDM_TRANSFER_FLAG_S= TART_AND_END; + ResponseSize =3D sizeof (SetSmbiosStr= uctureTableHandle); + + Status =3D PldmSubmitCommand ( + PLDM_TYPE_SMBIOS, + PLDM_SET_SMBIOS_STRUCTURE_TABLE_COMMAND_CODE, + RequestBuffer, + RequestSize, + (UINT8 *)&SetSmbiosStructureTableHandle, + &ResponseSize + ); + if (RequestBuffer !=3D NULL) { + FreePool (RequestBuffer); + } + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Set SMBIOS structure table.\n", __FUNCTION__= )); + } + if (ResponseSize !=3D 0 && ResponseSize <=3D sizeof(SetSmbiosStructureTa= bleHandle)) { + HelperManageabilityDebugPrint( + (VOID *)&SetSmbiosStructureTableHandle, + ResponseSize, + "Set SMBIOS structure table response got from BMC.\n" + ); + } + return Status; +} + +/** + This function gets particular type of SMBIOS structure. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL i= nstance. + @param [in] TypeId The type of SMBIOS structure. + @param [in] StructureInstanceId The instance ID of particular type of= SMBIOS structure. + @param [out] Buffer Pointer to the returned SMBIOS struct= ure. + Caller has to free this memory block = when it + is no longer needed. + @param [out] BufferSize Size of the returned message payload = in buffer. + + @retval EFI_SUCCESS Gets particular type of SMBIOS struct= ure successfully. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to set SMBIOS structure table. +**/ +EFI_STATUS +EFIAPI +GetSmbiosStructureByType ( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + IN UINT8 TypeId, + IN UINT16 StructureInstanceId, + OUT UINT8 **Buffer, + OUT UINT32 *BufferSize + ) +{ + DEBUG ((DEBUG_INFO, "%a: Unsupported.\n", __FUNCTION__)); + // Only support PLDM SMBIOS Transfer push mode. + return EFI_UNSUPPORTED; +} + +/** + This function gets particular handle of SMBIOS structure. + + @param [in] This EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL i= nstance. + @param [in] Handle The handle of SMBIOS structure. + @param [out] Buffer Pointer to the returned SMBIOS struct= ure. + Caller has to free this memory block = when it + is no longer needed. + @param [out] BufferSize Size of the returned message payload = in buffer. + + @retval EFI_SUCCESS Gets particular handle of SMBIOS stru= cture successfully. + @retval EFI_UNSUPPORTED The function is unsupported by this + driver instance. + @retval Other values Fail to set SMBIOS structure table. +**/ +EFI_STATUS +EFIAPI +GetSmbiosStructureByHandle ( + IN EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL *This, + IN UINT16 Handle, + OUT UINT8 **Buffer, + OUT UINT32 *BufferSize + ) +{ + DEBUG ((DEBUG_INFO, "%a: Unsupported.\n", __FUNCTION__)); + // Only support PLDM SMBIOS Transfer push mode. + return EFI_UNSUPPORTED; +} + +EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL_V1_0 mPldmSmbiosTransferProtocolV10 = =3D { + GetSmbiosStructureTableMetaData, + SetSmbiosStructureTableMetaData, + GetSmbiosStructureTable, + SetSmbiosStructureTable, + GetSmbiosStructureByType, + GetSmbiosStructureByHandle +}; + +EDKII_PLDM_SMBIOS_TRANSFER_PROTOCOL mPldmSmbiosTransferProtocol; + +/** + The entry point of the PLDM SMBIOS Transfer DXE driver. + + @param[in] ImageHandle - Handle of this driver image + @param[in] SystemTable - Table containing standard EFI services + + @retval EFI_SUCCESS - IPMI Protocol is installed successfully. + @retval Otherwise - Other errors. +**/ +EFI_STATUS +EFIAPI +DxePldmSmbiosTransferEntry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_HANDLE Handle; + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "%a: Entry.\n", __FUNCTION__)); + + SetSmbiosStructureTableHandle =3D 0; + + Handle =3D NULL; + mPldmSmbiosTransferProtocol.ProtocolVersion =3D EDKII_PLDM_SMBIOS_T= RANSFER_PROTOCOL_VERSION; + mPldmSmbiosTransferProtocol.Functions.Version1_0 =3D &mPldmSmbiosTransfe= rProtocolV10; + Status =3D gBS->InstallProtoco= lInterface ( + &Handle, + &gEdkiiPldmSmb= iosTransferProtocolGuid, + EFI_NATIVE_INT= ERFACE, + (VOID **)&mPld= mSmbiosTransferProtocol + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to install EDKII_PLDM_SMBIOS_TRANSFER_P= ROTOCOL.\n", __FUNCTION__)); + } + + return Status; +} + +/** + This is the unload handler of PLDM SMBIOS Transfer DXE driver. + + @param[in] ImageHandle The driver's image handle. + + @retval EFI_SUCCESS The image is unloaded. + @retval Others Failed to unload the image. + +**/ +EFI_STATUS +EFIAPI +PldmSmbiosTransferUnloadImage ( + IN EFI_HANDLE ImageHandle + ) +{ + return EFI_SUCCESS; +} --=20 2.37.1.windows.1