From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.58]) by mx.groups.io with SMTP id smtpd.web10.4747.1679368944460317144 for ; Mon, 20 Mar 2023 20:22:24 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=e+3OE+AE; 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.92.58, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lrtorCE0ZvaxX7qmAsWVOPRdYlKEawJsYxPUdrNS/aksSfikhwtMGEvHFlOSRW9I0YLYBMs6Vrpena9WrJ2hDUXPa2Mw15fIhgatPas8Qt+Uc2AfvXuWaMXog6/oPORUvrRjIUdDXoi1G/177U4x1S0RW3G63bWVEDgWTW0Qwn7ET4Wnh3j/JYyCVeyOAn6ZOHSCAzJVSF8hbmmypFYl+VtwYxXCaoCc2ZyjjFybQ5jXlTEPRZ7IckOHNUWj1f+FqiBQ5VMltcykXZW4Y9BzZ2siNSWcyND8raUq+upuWEw+Yeiig8HRhWh+3i9zRMaKPNuz54OMDNCk3uuClAvTmg== 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=czRQW81bB/P29+C0FIHUkNs5w6GsyphwQPdfRf1r0bo=; b=YV7U/6C+4VaXtczlVeQ9PXNhxrwAVC2P5GwaLWbXLByTeyiaYtu4mLu2vBKS38JUqU/18s2DrIRAtddNU4sluVTwlv6Q2JupO2a7hZHm8P+loEHuw3iKiEX4W8zy/Q521X8H8lemLyR7DUvmhlm7seUA/fIavoX6DKXF4yADPGTzeaoEjoDx9HQ6P8c5E9rFH2Z3WejHFwPcf9MDC707a1mvj92f01SP8wIKQuzd6/cpmT8EuVsSSpuEQbCLZ0ik0qP65531nIDszfArCmb/eKU7zNHHgz4gVTWiPRI+aXmeymxX2PV+5AdYz+D6lCAtDz4QwNAf/GR2HQgg6lMr2Q== 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=czRQW81bB/P29+C0FIHUkNs5w6GsyphwQPdfRf1r0bo=; b=e+3OE+AEYUPgNvd00Y/v6FhfrDpkybvLfJoXMiCotGRYZq02PX8ELNzh6JKNyXE/JfWN53ou4q+KMqKfrrPQkySc4npGQiyv4Xo3DRc30JkSr6wC/ttP+auxQdLQX/fNk8nrbk+boAyeJpUbrGODZ9jInpi7F2qBjhaZO0vaGUI= Received: from MW4PR04CA0379.namprd04.prod.outlook.com (2603:10b6:303:81::24) by DS0PR12MB7828.namprd12.prod.outlook.com (2603:10b6:8:14b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.37; Tue, 21 Mar 2023 03:22:21 +0000 Received: from CO1NAM11FT013.eop-nam11.prod.protection.outlook.com (2603:10b6:303:81:cafe::27) by MW4PR04CA0379.outlook.office365.com (2603:10b6:303:81::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; Tue, 21 Mar 2023 03:22:21 +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 CO1NAM11FT013.mail.protection.outlook.com (10.13.174.227) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6222.16 via Frontend Transport; Tue, 21 Mar 2023 03:22:21 +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, 20 Mar 2023 22:22:05 -0500 From: "Chang, Abner" To: CC: Liming Gao , Isaac Oram , Nate DeSimone , Nickle Wang , Igor Kulchytskyy , "Abdul Lateef Attar" Subject: [PATCH v3 4/8] ManageabilityPkg: Add ManageabilityTransportHelperLib Date: Tue, 21 Mar 2023 11:21:43 +0800 Message-ID: <20230321032147.1616-2-abner.chang@amd.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20230321032147.1616-1-abner.chang@amd.com> References: <20230321032147.1616-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: CO1NAM11FT013:EE_|DS0PR12MB7828:EE_ X-MS-Office365-Filtering-Correlation-Id: a139e031-c4f7-4d68-8221-08db29bb7bc0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eHrCYd60RuRboCri0m9R7n1dE55BQiCbEp90G5Izs4u25PKP2vWDYnzOxcl+xeupBS6TOE6fm39nJKDEnCeS+JcCQGaStiyJcQRS261OGlOqUTn0R8M95yQtP784WdUWozemJjd0qZphRwspPLM6Tq7eqlnhXw6mz1jHTaKF95kWJ+Ere/kPXEcS3lT/fHjTU53C3bE9Inq/Gakwdjd9rEUivicYEvkp9aogIrnXanNI6xKFDMZUVrY1H7+yOKFZyzIxuXp3CfKQVkqlU0A+b4gmohsOaVQE1yi2aouxPDNvg5n+SkDgfOoLsd65AWBljHpJzqnKPOqHc3zX7jQU0J/frSPWAMQU+F+X2DVlsRJnl3zWVfvV4N3rk+6nAsIK74jbtT/++LH7/3j34OZUrJ+EF8WJ+UToIuywGu1OHRE1oNUDA7TH191Ek4eQzjSMYqnqXiX3xtGiFO+pZX/PDPMy7RZ3cudXxrBx6oWxLd8sDv6fR3OTCsdfhpZEWjcCE7pYFi/acLDh5NkTw+/YrPNLs1ODMUdHOpmCvAcsaUIiW4PLDTM4wiVKjTKes2zfrM6GwaDSZjYwVFoLHl54S9sXwlMOVC3obbWw7JJjLU4z9TWaHjasqjiN20wSImpklEfF+429td5tSF+uz47zt2rfcS8C6+iOJNEOy1A96A4Ylyk/xGTRUmxGPHXe7fbU+1u/v3lOWV/skpEhAGG+jAhUlqljxZXgCAO2p0iO6Lfpvg4wkOjadInHsUi3+2WoN9h44/K/hGlzCo2dhlRP7A== 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)(376002)(396003)(136003)(39860400002)(346002)(451199018)(36840700001)(46966006)(40470700004)(8936002)(41300700001)(2906002)(30864003)(8676002)(2876002)(70206006)(4326008)(6916009)(70586007)(5660300002)(316002)(54906003)(19627235002)(86362001)(478600001)(40460700003)(7696005)(82740400003)(36756003)(1076003)(40480700001)(6666004)(186003)(26005)(47076005)(16526019)(336012)(83380400001)(2616005)(426003)(81166007)(82310400005)(36860700001)(356005)(36900700001)(44824005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2023 03:22:21.3331 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a139e031-c4f7-4d68-8221-08db29bb7bc0 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: CO1NAM11FT013.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7828 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 | 23 +- .../Include/Dsc/Manageability.dsc | 2 + .../BaseManageabilityTransportHelper.inf | 41 +++ .../Library/ManageabilityTransportHelperLib.h | 93 +++++++ .../BaseManageabilityTransportHelper.c | 261 ++++++++++++++++++ .../BaseManageabilityTransportHelper.uni | 13 + 6 files changed, 432 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 ebf6e6315e..ebbb04dc0e 100644 --- a/Features/ManageabilityPkg/ManageabilityPkg.dec +++ b/Features/ManageabilityPkg/ManageabilityPkg.dec @@ -22,6 +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 } } =20 + # 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