From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.65]) by mx.groups.io with SMTP id smtpd.web11.33931.1679453356117240880 for ; Tue, 21 Mar 2023 19:49:16 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=zFtsdXsC; 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.243.65, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cz1qZTAmldz2qnkV/D7ZTkmiYcUJwf4aSsC3mFGoqNVNxvuPHRxWm79VTmQBxcH0mZse6DzxrpomXaY/NrJH1uOkGN072+PJiAJK445vh/Qa7//3Yzd51MTQRr0fFd8kl+DOjFxlTYKETcvjtYFTLyiS3s35kcbIX2FCiJWtklVIJZsVgBNlSP61eEdo+uK3jiGR5b1/la8F750WigVOe2sRt+w0ilL28YGFFQpg69hu6SzOUYdjD+dbs+J61XyWWCS+TT9OQPHTiP/lwG7DFTZ+KZf7QZx9d5hNMBg1G8Ww1jGHh7zvDotoup52wTdTXFX3t5fKXUPHErxMy5YZag== 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=5z0VtrvDssZxd9sDV28XXxx/lNzJyYRkLInXIyZ8+Tw=; b=bBkVt39cJMayBdXqLsdbRiqcIyh2wubnK9gyhFR8NzBo3/XrTYXZq13+DfvmdvemWqXKztMporXBOgtIgMTDsi+YgzeDwN+1Qei0//3kqLSRLnlQNtG86yHRHJ1aDf6Basc7PxkJ/uLg4StJaLe9uEcPQvAqjPxyjyTDW5gRcMoFP3FOsvkhYzSGpH9gHFWIw0a7AIR+X1PhoALLMP110cuNCjvC26rIX4JuAVfypXzyl3/un7h0xrqQMZHKwVZNk1stMNwjGHPUT05AFXg791WT/Z8dFShH+dB+DUK5BmFv60HWzefSg7jgtyUFL/LVu71NYHPDlIldbOrcvR53sw== 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=5z0VtrvDssZxd9sDV28XXxx/lNzJyYRkLInXIyZ8+Tw=; b=zFtsdXsCo+C68a2cJgG3k5G0lHYluC+1ZiA1CNWJApJ4AhaQBYCYGOe6uEuCW7PY5WPoi8nqbq10HPnS/LobQo88STggTReTdUoU15ohwZPYXNe5H+qE8gPwRLzU4YSIb+eFoBM7s6OzIvq+TveG9VV/jC5wFUuFvYOjXD1RbKc= Received: from DM6PR07CA0123.namprd07.prod.outlook.com (2603:10b6:5:330::24) by DM6PR12MB4353.namprd12.prod.outlook.com (2603:10b6:5:2a6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Wed, 22 Mar 2023 02:49:13 +0000 Received: from DS1PEPF0000E654.namprd02.prod.outlook.com (2603:10b6:5:330:cafe::9f) by DM6PR07CA0123.outlook.office365.com (2603:10b6:5:330::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37 via Frontend Transport; Wed, 22 Mar 2023 02:49:13 +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 DS1PEPF0000E654.mail.protection.outlook.com (10.167.18.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.30 via Frontend Transport; Wed, 22 Mar 2023 02:49:13 +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; Tue, 21 Mar 2023 21:49:11 -0500 From: "Chang, Abner" To: CC: Liming Gao , Isaac Oram , Nate DeSimone , Nickle Wang , Igor Kulchytskyy , "Abdul Lateef Attar" Subject: [PATCH v4 5/9] ManageabilityPkg: Add ManageabilityTransportHelperLib Date: Wed, 22 Mar 2023 10:48:36 +0800 Message-ID: <20230322024840.1629-5-abner.chang@amd.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20230322024840.1629-1-abner.chang@amd.com> References: <20230322024840.1629-1-abner.chang@amd.com> MIME-Version: 1.0 Return-Path: Abner.Chang@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E654:EE_|DM6PR12MB4353:EE_ X-MS-Office365-Filtering-Correlation-Id: 19a94da3-e201-4ddf-2d69-08db2a800571 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SmZkxMEbjtMuxCUMDMcmP5fjkrbDfjHTivmGHyLSe1Ffjyy/ohVZWLX++WYHZRZ2j9A7cC5q4OL6N1QkyY9Cmit+zQZ2SKQl2e/J2MdD7ID/I3b8/WuJHU8wjYn4ABl0mL3QqXJwiV22o++2udly8r4pYePZyvO9NMTSb7fvzm0e96uTOKgBy8GTWf8pFzh7I5vlREr2vynBideo5zwXrMJU2NZOJ/JVVPYfIrzIr1z2qcK+aYBOBgJGKSQLcCeA7e5tXxeryuWaZDaguvCtiEI/Kg0lNbS/2Fr3aVpO8yKKLQgA+WOz+bTSgVmkh6SVFr0qJMmGRb/sPRX99bjTb0mIGtVThB1UTx4XTREeL6FPwZdHsfm/QqzZujtRMVfxHpeu0rYV+LewwH3HW460Dgaolh2R6EXWQ0p315bdFMtH/J5xwHBa6A/eWqPAQi4BKyyA5dsKtyvwaHqtaLeqe+t6dgJZ3kHmIHqc+AEiXznuyFAfWjirSV3nob3aZv2AZh0pGctSSPBUUKYuKZiRM8RQ+EtRwrsYpyVwkDwrgF24iKotg6w3ifEaX10C+QWvqXYPUzgWlrVUTewrh1FOKRf0VIDOda8R/aXCnpiMJ0XU2kaYRWG/bnGMgNu5MaK5DLUObsZFXV1zgfB+uf3BEVZBIkG6eyITcJCkEnwvvDKMSTKMa46FDbwqUulERrO/xvUYxJbaSrdEx2256HooFgK0vLm9avpit2qanOjbUxBJJwsrVUYHZfqzlKXq0+7TSCn5kCFYqb5gD/Gjrqt6QQ== 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:(13230025)(4636009)(346002)(376002)(396003)(39860400002)(136003)(451199018)(46966006)(40470700004)(36840700001)(2876002)(47076005)(19627235002)(426003)(7696005)(30864003)(70206006)(54906003)(8676002)(316002)(83380400001)(40480700001)(5660300002)(70586007)(36756003)(8936002)(6916009)(4326008)(41300700001)(36860700001)(82310400005)(478600001)(2906002)(81166007)(40460700003)(82740400003)(336012)(6666004)(356005)(86362001)(2616005)(16526019)(1076003)(186003)(26005)(36900700001)(44824005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2023 02:49:13.7759 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 19a94da3-e201-4ddf-2d69-08db2a800571 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: DS1PEPF0000E654.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4353 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Abner Chang The helper functions library facilitates reducing duplicated code in the manageability transport library instances. Signed-off-by: Abner Chang Cc: Liming Gao Cc: Isaac Oram Cc: Nate DeSimone Cc: Nickle Wang Cc: Igor Kulchytskyy Cc: Abdul Lateef Attar --- .../ManageabilityPkg/ManageabilityPkg.dec | 24 +- .../Include/Dsc/Manageability.dsc | 2 + .../BaseManageabilityTransportHelper.inf | 41 +++ .../Library/ManageabilityTransportHelperLib.h | 93 +++++++ .../BaseManageabilityTransportHelper.c | 261 ++++++++++++++++++ .../BaseManageabilityTransportHelper.uni | 13 + 6 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 Features/ManageabilityPkg/Library/BaseManageabilityTran= sportHelperLib/BaseManageabilityTransportHelper.inf create mode 100644 Features/ManageabilityPkg/Include/Library/Manageability= TransportHelperLib.h create mode 100644 Features/ManageabilityPkg/Library/BaseManageabilityTran= sportHelperLib/BaseManageabilityTransportHelper.c create mode 100644 Features/ManageabilityPkg/Library/BaseManageabilityTran= sportHelperLib/BaseManageabilityTransportHelper.uni diff --git a/Features/ManageabilityPkg/ManageabilityPkg.dec b/Features/Mana= geabilityPkg/ManageabilityPkg.dec index 92ba4538c0..ebbb04dc0e 100644 --- a/Features/ManageabilityPkg/ManageabilityPkg.dec +++ b/Features/ManageabilityPkg/ManageabilityPkg.dec @@ -22,5 +22,27 @@ # Manageability Transport Library definitions ManageabilityTransportLib|Include/Library/ManageabilityTransportLib.h =20 + ## @libraryclass Manageability Transport Helper Library + # Provide the help functions to use ManageabilityTransportLib + ManageabilityTransportHelperLib|Include/Library/ManageabilityTransportHe= lperLib.h + [Guids] - gManageabilityPkgTokenSpaceGuid =3D { 0xBDEFFF48, 0x1C31, 0x49CD, { 0xA7= , 0x6D, 0x92, 0x9E, 0x60, 0xDB, 0xB9, 0xF8 } } + gManageabilityPkgTokenSpaceGuid =3D { 0xBDEFFF48, 0x1C31, 0x49CD, { 0x= A7, 0x6D, 0x92, 0x9E, 0x60, 0xDB, 0xB9, 0xF8 } } + + # Manageability Transport Interface type + # + # Manageability Transport KCS + gManageabilityTransportKcsGuid =3D { 0x5A6E64E9, 0xFD47, 0x4086, { 0x= AA, 0xB0, 0x7A, 0x5F, 0xD7, 0x6B, 0x02, 0x2E } } + # Manageability Transport I2C + gManageabilityTransportI2CGuid =3D { 0x5B174658, 0x8263, 0x4CB8, { 0x= A0, 0x0F, 0xD6, 0x82, 0xE6, 0xBC, 0x74, 0x93 } } + # Manageability Transport PCI VDM + gManageabilityTransportPciVdmGuid =3D { 0x388021A7, 0xFB59, 0x4811, { 0x= 9D, 0xA7, 0xD5, 0x63, 0x7D, 0x04, 0xA7, 0x2F } } + + # Manageability Protocol Specification + # + # Manageability Protocol IPMI + gManageabilityProtocolIpmiGuid =3D { 0x36ACA47C, 0xCC80, 0x473B, { 0x= AB, 0xEC, 0xF3, 0x98, 0xFF, 0x87, 0x74, 0x5B } } + # Manageability Protocol MCTP + gManageabilityProtocolMctpGuid =3D { 0x76FED8F1, 0x0BE5, 0x4269, { 0x= A3, 0x1A, 0x38, 0x0F, 0x54, 0xF1, 0xA1, 0x8A } } + # Manageability Protocol PLDM + gManageabilityProtocolPldmGuid =3D { 0x3958090D, 0x69DD, 0x4868, { 0x= 9C, 0x41, 0xC9, 0xAC, 0x31, 0xB5, 0x25, 0xC5 } } diff --git a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc b/Feat= ures/ManageabilityPkg/Include/Dsc/Manageability.dsc index 2cb63c1ca6..994c93f17c 100644 --- a/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc +++ b/Features/ManageabilityPkg/Include/Dsc/Manageability.dsc @@ -5,6 +5,8 @@ # SPDX-License-Identifier: BSD-2-Clause-Patent # ## +[LibraryClasses] + ManageabilityTransportHelperLib|ManageabilityPkg/Library/BaseManageabili= tyTransportHelperLib/BaseManageabilityTransportHelper.inf =20 [LibraryClasses.ARM, LibraryClasses.AARCH64] # diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHe= lperLib/BaseManageabilityTransportHelper.inf b/Features/ManageabilityPkg/Li= brary/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.= inf new file mode 100644 index 0000000000..95c3362ddb --- /dev/null +++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib= /BaseManageabilityTransportHelper.inf @@ -0,0 +1,41 @@ +## @file +# Null instance of Manageability Transport Helper Library +# +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D BaseManageabilityTransportHelper + MODULE_UNI_FILE =3D BaseManageabilityTransportHelper.uni + FILE_GUID =3D 52F2DE11-A8FC-4A06-B8C6-10DCF4A7397C + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ManageabilityTransportHelperLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# + +[Sources] + BaseManageabilityTransportHelper.c + +[LibraryClasses] + BaseMemoryLib + DebugLib + +[Packages] + ManageabilityPkg/ManageabilityPkg.dec + MdePkg/MdePkg.dec + +[Guids] + gManageabilityTransportKcsGuid + gManageabilityTransportI2CGuid + gManageabilityTransportPciVdmGuid + gManageabilityTransportMctpGuid + gManageabilityProtocolIpmiGuid + gManageabilityProtocolMctpGuid + gManageabilityProtocolPldmGuid + diff --git a/Features/ManageabilityPkg/Include/Library/ManageabilityTranspo= rtHelperLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTran= sportHelperLib.h new file mode 100644 index 0000000000..718ac34a1f --- /dev/null +++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelpe= rLib.h @@ -0,0 +1,93 @@ +/** @file + + This file defines the manageability transport interface library and func= tions. + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef MANAGEABILITY_TRANSPORT_HELPER_LIB_H_ +#define MANAGEABILITY_TRANSPORT_HELPER_LIB_H_ + +#include + +typedef struct _MANAGEABILITY_PROTOCOL_NAME MANAGEABILITY_PROTOCOL_NAME; + +/** + Helper function returns the human readable name of Manageability specifi= cation. + + @param[out] SpecificationGuid The Manageability specification G= UID + + @retval !NULL Human readable name is returned; + @retval NULL No string found, the given Manageability specificati= on is + not supported. +**/ +CHAR16 * +HelperManageabilitySpecName ( + IN EFI_GUID *SpecificationGuid + ); + +/** + Helper function to check if the Manageability specification is supported + by transport interface or not. + + @param[in] TransportGuid GUID of the transport = interface. + @param[in] SupportedManageabilityProtocolArray The Manageability prot= ocols supported + by the transport inter= face. + @param[in] NumberOfSupportedProtocolInArray Number of protocols in= the array. + @param[in] ManageabilityProtocolToCheck The Manageability spec= ification to check. + + @retval EFI_SUCCESS Token is created successfully. + @retval EFI_INVALID_PARAMETER Either NumberOfSupportedProtocolInAr= ray =3D 0 or + SupportedManageabilityProtocolArray = =3D NULL. + @retval EFI_UNSUPPORTED Out of resource to create a new tran= sport session. + Otherwise Other errors. +**/ +EFI_STATUS +HelperManageabilityCheckSupportedSpec ( + IN EFI_GUID *TransportGuid, + IN EFI_GUID **SupportedManageabilityProtocolArray, + IN UINT8 NumberOfSupportedProtocolInArray, + IN EFI_GUID *ManageabilityProtocolToCheck + ); + +/** + Helper function to acquire the Manageability transport token. + + @param[in] ManageabilityProtocolSpec The Manageability protocol speci= fication. + @param[out] TransportToken Pointer to receive Manageability= transport + token. + + @retval EFI_SUCCESS Token is created successfully. + @retval EFI_OUT_OF_RESOURCES Out of resource to create a new tran= sport session. + @retval EFI_UNSUPPORTED Token is created successfully. + @retval EFI_DEVICE_ERROR The transport interface has problems + @retval EFI_INVALID_PARAMETER INput parameter is not valid. + Otherwise Other errors. +**/ +EFI_STATUS +HelperAcquireManageabilityTransport ( + IN EFI_GUID *ManageabilityProtocolSpec, + OUT MANAGEABILITY_TRANSPORT_TOKEN **TransportToken + ); + +/** + Helper function to initial the transport interface. + + @param[in] TransportToken Transport token. + @param[in] HardwareInfo Optional hardware information of= transport interface. + @param[out] TransportAdditionalStatus Transport additional status. + + @retval EFI_SUCCESS Transport interface is initiated suc= cessfully. + @retval EFI_DEVICE_ERROR The transport interface has problems + @retval EFI_INVALID_PARAMETER INput parameter is not valid. + Otherwise Other errors. +**/ +EFI_STATUS +HelperInitManageabilityTransport ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + IN MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION HardwareInfo OPTIONAL, + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *TransportAdditionalSt= atus OPTIONAL + ); + +#endif diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHe= lperLib/BaseManageabilityTransportHelper.c b/Features/ManageabilityPkg/Libr= ary/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c new file mode 100644 index 0000000000..81da209764 --- /dev/null +++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib= /BaseManageabilityTransportHelper.c @@ -0,0 +1,261 @@ +/** @file + Null instance of Manageability Transport Helper Library + + Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include + +// +// BaseManageabilityTransportHelper is used by PEI, DXE and SMM. +// Make sure the global variables added here should be unchangable. +// +MANAGEABILITY_SPECIFICATION_NAME ManageabilitySpecNameTable[] =3D { + { &gManageabilityTransportKcsGuid, L"KCS" }, + { &gManageabilityTransportI2CGuid, L"I2C" }, + { &gManageabilityTransportPciVdmGuid, L"PCI VDM" }, + { &gManageabilityTransportMctpGuid, L"MCTP" }, + { &gManageabilityProtocolIpmiGuid, L"IPMI" }, + { &gManageabilityProtocolMctpGuid, L"MCTP" }, + { &gManageabilityProtocolPldmGuid, L"PLDM" } +}; + +UINT16 mManageabilitySpecNum =3D sizeof (ManageabilitySpecNameTable)/ siz= eof (MANAGEABILITY_SPECIFICATION_NAME); + +/** + Helper function returns the human readable name of Manageability specifi= cation. + + @param[in] SpecificationGuid The Manageability specification GU= ID + + @retval !NULL Human readable name is returned; + @retval NULL No string found, the given Manageability specificati= on is + not supported. +**/ +CHAR16 * +HelperManageabilitySpecName ( + IN EFI_GUID *SpecificationGuid + ) +{ + UINT16 Index; + MANAGEABILITY_SPECIFICATION_NAME *ThisSpec; + + if (mManageabilitySpecNum =3D=3D 0) { + return NULL; + } + + if (SpecificationGuid =3D=3D NULL || IsZeroGuid (SpecificationGuid)) { + DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero G= UID.\n", __FUNCTION__)); + return NULL; + } + + ThisSpec =3D ManageabilitySpecNameTable; + for (Index =3D 0; Index < mManageabilitySpecNum; Index++) { + if (CompareGuid ( + SpecificationGuid, + ThisSpec->SpecificationGuid + )) + { + return ThisSpec->SpecificationName; + } + + ThisSpec++; + } + + return NULL; +} + +/** + Helper function to check if the Manageability specification is supported + by transport interface or not. + + @param[in] TransportGuid GUID of the transport = interface. + @param[in] SupportedManageabilityProtocolArray The Manageability prot= ocols supported + by the transport inter= face. + @param[in] NumberOfSupportedProtocolInArray Number of protocols in= the array. + @param[in] ManageabilityProtocolToCheck The Manageability spec= ification to check. + + @retval EFI_SUCCESS Token is created successfully. + @retval EFI_INVALID_PARAMETER Either NumberOfSupportedProtocolInAr= ray =3D 0 or + SupportedManageabilityProtocolArray = =3D NULL. + @retval EFI_UNSUPPORTED Out of resource to create a new tran= sport session. + Otherwise Other errors. +**/ +EFI_STATUS +HelperManageabilityCheckSupportedSpec ( + IN EFI_GUID *TransportGuid, + IN EFI_GUID **SupportedManageabilityProtocolArray, + IN UINT8 NumberOfSupportedProtocolInArray, + IN EFI_GUID *ManageabilityProtocolToCheck + ) +{ + UINT16 Index; + EFI_GUID **ThisSpecGuid; + + if ((NumberOfSupportedProtocolInArray =3D=3D 0) || (SupportedManageabili= tyProtocolArray =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (TransportGuid =3D=3D NULL || + IsZeroGuid (TransportGuid) || + ManageabilityProtocolToCheck =3D=3D NULL || + IsZeroGuid (ManageabilityProtocolToCheck) + ) { + DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero= GUID.\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + ThisSpecGuid =3D SupportedManageabilityProtocolArray; + for (Index =3D 0; Index < NumberOfSupportedProtocolInArray; Index++) { + if (CompareGuid ( + *ThisSpecGuid, + ManageabilityProtocolToCheck + )) + { + DEBUG (( + DEBUG_VERBOSE, + "%a: Transport interface %s supports %s manageability specificatio= n.\n", + __FUNCTION__, + HelperManageabilitySpecName (TransportGuid), + HelperManageabilitySpecName (ManageabilityProtocolToCheck) + )); + return EFI_SUCCESS; + } + + ThisSpecGuid++; + } + + DEBUG (( + DEBUG_ERROR, + "%a: Transport interface %s doesn't support %s manageability specifica= tion.\n", + __FUNCTION__, + HelperManageabilitySpecName (TransportGuid), + HelperManageabilitySpecName (ManageabilityProtocolToCheck) + )); + return EFI_UNSUPPORTED; +} + +/** + Helper function to acquire the Manageability transport token. + + @param[in] ManageabilityProtocolSpec The Manageability protocol speci= fication. + @param[out] TransportToken Pointer to receive Manageability= transport + token. + + @retval EFI_SUCCESS Token is created successfully. + @retval EFI_OUT_OF_RESOURCES Out of resource to create a new tran= sport session. + @retval EFI_UNSUPPORTED Token is created successfully. + @retval EFI_INVALID_PARAMETER Input parameter is not valid. + Otherwise Other errors. +**/ +EFI_STATUS +HelperAcquireManageabilityTransport ( + IN EFI_GUID *ManageabilityProtocolSpec, + OUT MANAGEABILITY_TRANSPORT_TOKEN **TransportToken + ) +{ + EFI_STATUS Status; + CHAR16 *ManageabilityProtocolName; + CHAR16 *ManageabilityTransportName; + + DEBUG ((DEBUG_INFO, "%a: Entry\n", __FUNCTION__)); + if ((TransportToken =3D=3D NULL) || (ManageabilityProtocolSpec =3D=3D NU= LL)) { + DEBUG ((DEBUG_ERROR, "%a: One of the required input parameters is NULL= .\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + *TransportToken =3D NULL; + ManageabilityProtocolName =3D HelperManageabilitySpecName (Manageability= ProtocolSpec); + if (ManageabilityProtocolName =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Unsupported Manageability Protocol Specifica= tion.\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + DEBUG ((DEBUG_INFO, " Manageability protocol %s is going to acquire tra= nsport interface token...\n", ManageabilityProtocolName)); + + Status =3D AcquireTransportSession (ManageabilityProtocolSpec, Transport= Token); + if (Status =3D=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_ERROR, "%a: No supported transport interface for %s pack= et.\n", __FUNCTION__, ManageabilityProtocolName)); + return Status; + } + + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Fail to acquire Manageability transport token for %s (%r).\n", + __FUNCTION__, + ManageabilityProtocolName, + Status + )); + return Status; + } + + ManageabilityTransportName =3D HelperManageabilitySpecName ((*TransportT= oken)->Transport->ManageabilityTransportSpecification); + if (ManageabilityTransportName =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Unsupported Manageability Transport Interfac= e Specification\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + DEBUG ((DEBUG_INFO, "%a: This is the transfer session for %s over %s\n",= __FUNCTION__, ManageabilityProtocolName, ManageabilityTransportName)); + return Status; +} + +/** + Helper function to initial the transport interface. + + @param[in] TransportToken Transport token. + @param[in] HardwareInfo Optional hardware information of= transport interface. + @param[out] TransportAdditionalStatus Transport additional status. + + @retval EFI_SUCCESS Transport interface is initiated suc= cessfully. + @retval EFI_DEVICE_ERROR The transport interface has problems + @retval EFI_INVALID_PARAMETER INput parameter is not valid. + Otherwise Other errors. +**/ +EFI_STATUS +HelperInitManageabilityTransport ( + IN MANAGEABILITY_TRANSPORT_TOKEN *TransportToken, + IN MANAGEABILITY_TRANSPORT_HARDWARE_INFORMATION HardwareInfo OPTIONAL, + OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *TransportAdditionalSt= atus OPTIONAL + ) +{ + EFI_STATUS Status; + + if (TransportToken =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: TransportToken is invalid.\n", __FUNCTION__)= ); + return EFI_INVALID_PARAMETER; + } + + // Initial transport interface. + Status =3D TransportToken->Transport->Function.Version1_0->TransportInit= (TransportToken, HardwareInfo); + if ((Status !=3D EFI_SUCCESS) && (Status !=3D EFI_ALREADY_STARTED)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + // Try to reset the transport and initialize it again. + Status =3D TransportToken->Transport->Function.Version1_0->Transport= Reset ( + Transport= Token, + Transport= AdditionalStatus + ); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_ERROR, "%a: Transport interface doesn't have reset= capability.\n", __FUNCTION__)); + } else { + DEBUG ((DEBUG_ERROR, "%a: Fail to reset transport interface (%r)= .\n", __FUNCTION__, Status)); + } + + Status =3D EFI_DEVICE_ERROR; + } else { + Status =3D TransportToken->Transport->Function.Version1_0->Transpo= rtInit (TransportToken, HardwareInfo); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Transport interface is not able to use= after the reset (%r).\n", __FUNCTION__, Status)); + } + } + } else { + DEBUG ((DEBUG_ERROR, "%a: Transport interface is not able to use (%r= ).\n", __FUNCTION__, Status)); + } + } + + return Status; +} diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHe= lperLib/BaseManageabilityTransportHelper.uni b/Features/ManageabilityPkg/Li= brary/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.= uni new file mode 100644 index 0000000000..dfb6051aeb --- /dev/null +++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib= /BaseManageabilityTransportHelper.uni @@ -0,0 +1,13 @@ +// /** @file +// Null instance of Manageability Transport Helper Library +// +// Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Manageability Tra= nsport Helper Library" + +#string STR_MODULE_DESCRIPTION #language en-US "Manageability Tra= nsport Helper Functions." + --=20 2.37.1.windows.1