From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.99]) by mx.groups.io with SMTP id smtpd.web11.50541.1681147448672783306 for ; Mon, 10 Apr 2023 10:24:09 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="no key for verify" header.i=@amperemail.onmicrosoft.com header.s=selector1-amperemail-onmicrosoft-com header.b=38wn4eor; spf=pass (domain: os.amperecomputing.com, ip: 40.107.223.99, mailfrom: tinhnguyen@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YInIWAL5SfjGTfUzxmLDMgAVAQC9UV3rRMSeHUZK+iTNlbpI7I33Mf7QkhdM9ZtOW3ZfXO8qLsxmvSE8EMjfzFRvjdftQmHg/EXB8yv/ZeQdk2Wu5ECrsb/NjA9RgV7tNu4N8RsIoCQXwbW3ft8dZlCbuyTYOrH4j/lUkj19fPVSFs+5cORKRQSykuWCTafAh6wjOxQ85SIsIJcep1Ukcsnr7q7+v74kZnsReGlG7nn9HbCiwImt/TmTlasdp6IpLCJmzio0YgyfEWsFPa8HtEqnNtzM7IfTj9+84SOZT8dPxNGtSG0mtZJIwFxmCjlkwPYSOAnAc+83ewNL9rnSnQ== 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=IEdmVjNNWz9/XKp2bDf3TYdMuKq10yEMDYYl2h4Bw/k=; b=btfEfzFRM1bmvZ3P6Hh0rlxcM5qsrjJ8CmJqwwKQ4/pT9XMvUPl8nG1W09VNlwtcgJyovR3AgL+f31W/dWQPWNC3TAzwPH9YSwcN1N8pughR39J9IzizfcgYxDgbHO4fB9EzBA8GjRuSU+s346A0vIfgjm1uGmI+EaE/P0zss8zWiAlD5LVApKBV21miRnb+Uq7zX/uANJk+ebfxaYx5qb43JpakYpSx3eBTOSGqDa7HM0Z47p2EBYuvPe5G2HE0pSIKEigih4e0/C0S/XwNGO/MdTRbHqvqegx5d7BGqSDRV6uFFYTysESFjLx4VoEGvW4LDfL4l64MPh5JeJV1Og== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=amperemail.onmicrosoft.com; dkim=pass header.d=amperemail.onmicrosoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amperemail.onmicrosoft.com; s=selector1-amperemail-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IEdmVjNNWz9/XKp2bDf3TYdMuKq10yEMDYYl2h4Bw/k=; b=38wn4eorh+yA/+yuL7AuhYnpYLXpS7zX6YXJjf2B4fGW1JtlR2icDtvTQpeNJsVE1xnE2a/aYik4xTJu21RlmkEDM18U1UQT727lH3V/4BTpr8kSIFRYuTkpzvVxVCEsRvmfeI780bDXjUv2QxgqC3cYtAoCZjebnoBio8XSnyo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amperemail.onmicrosoft.com; Received: from DM5PR0102MB3336.prod.exchangelabs.com (2603:10b6:4:9f::11) by PH0PR01MB6554.prod.exchangelabs.com (2603:10b6:510:7b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.25; Mon, 10 Apr 2023 17:24:03 +0000 Received: from DM5PR0102MB3336.prod.exchangelabs.com ([fe80::812c:e04f:eb2d:c1e]) by DM5PR0102MB3336.prod.exchangelabs.com ([fe80::812c:e04f:eb2d:c1e%6]) with mapi id 15.20.6298.021; Mon, 10 Apr 2023 17:24:03 +0000 Message-ID: Date: Tue, 11 Apr 2023 00:23:55 +0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [edk2-devel] [edk2-platforms][PATCH 01/14] ManageabilityPkg: Add more helper functions To: devel@edk2.groups.io, abner.chang@amd.com Cc: Isaac Oram , Abdul Lateef Attar , Nickle Wang , Igor Kulchytskyy References: <20230403150459.925-1-abner.chang@amd.com> <20230403150459.925-2-abner.chang@amd.com> From: "Tinh Nguyen" In-Reply-To: <20230403150459.925-2-abner.chang@amd.com> X-ClientProxiedBy: SI2PR02CA0054.apcprd02.prod.outlook.com (2603:1096:4:196::13) To DM5PR0102MB3336.prod.exchangelabs.com (2603:10b6:4:9f::11) Return-Path: tinhnguyen@os.amperecomputing.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR0102MB3336:EE_|PH0PR01MB6554:EE_ X-MS-Office365-Filtering-Correlation-Id: 063de8c3-2206-4332-ed97-08db39e8615d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: glZqSCoIrb+9Q4nnLbKIu89ofl2gISldUmc8mrMPM1HMAVo8v3RcYx0dJ7Q8iZOQ1WUcDitU7C/m+JALhoDv2VN34Fl6gDMCARJ84hxJbwAVWCgvS8ovP+PnJuPYz6Fy86xS/kueKQEeYfdqjFwq80mq0K2K3UcXziw6I6K7058iHgKogbF4R/k8FBdjoUO9FAMVwNhnP3wWnMtVpF3UawAhxi544xj8ubETJTpNeP5CWhABChFM44btmLLgM/KjI6Ic0zpShzsmZ+gvLX4DxREitoHfgqjG1vfRNCeLvMB9Ca1A4jKUBWpm9wGQBYdAtjWo5GYVFCZ+LCemtK3Mpw1QzccqncMHUQYSTsib4Nj2kQVVsl7lk/D0/3eeHuxxtbpiESjJusfs3Xc6r3FUn+URoySyMx5DcXDPe29VpTLP72bhYoKgeLflvg/fkxqbhRY01nnkAF7ToVZ/SfSDpYqJs+P3NuZ7biE0kwzzemXVFuzHDgdSlmcbAIqe8kxpUjZcGIPnMk0gj99RGm0JM0SH3rYERHV/CeQZigwyKbatIy0ZfUnc3DaASmyeSM/ViWIMXnjxcn3AmfWrgFgtyFtfJupWL/igBTuxStKxnKm7OL/VsL9KLLQKvriIT0kT X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR0102MB3336.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(136003)(39850400004)(346002)(396003)(366004)(451199021)(42882007)(2616005)(83380400001)(54906003)(6666004)(186003)(478600001)(6486002)(26005)(6506007)(53546011)(6512007)(30864003)(2906002)(5660300002)(38100700002)(83170400001)(4326008)(41300700001)(66556008)(66476007)(66946007)(8936002)(31696002)(8676002)(316002)(31686004)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dFJKQkxnV2dYMUFDVmdKblprK1p0dWVVZjFndURaRStydEFSeXk0OGtzSWpD?= =?utf-8?B?RWdvOEc5Y3JiM0FiT0lCVnNaWVhCSWhUcDZ2VHZNN0FRd3YwZzZ0bUYwb1Nh?= =?utf-8?B?YmJqOXpGbm02RGtTMHdwRXJQaHNxeURhaEszWW9IbHZ6QjAvNEVqOHorNGg2?= =?utf-8?B?QXVhc0EwUk95NmJXOG9IQ3RYRUF5aEdKTGxGVVE1NytnNU1qZHJGM3RmL2c3?= =?utf-8?B?dDlkbU5Samw0ZDBFRzhLRi9Od2lJSXk3amhvWkgzYmdTQzc3eFU4Sk9DbXZF?= =?utf-8?B?L0c2RGNUVi9wc3NXc3lEZm9yelFZUGtjLzNYOVNqTThsOGtsTzNBVytyeWw2?= =?utf-8?B?Q0FBb05xMzQ5S3FNTDg4S3JuOTZJRnF5a1VQOEFZK1QrOTRYVWdxcC8wczJB?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ginatorOrg: amperemail.onmicrosoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 063de8c3-2206-4332-ed97-08db39e8615d X-MS-Exchange-CrossTenant-AuthSource: DM5PR0102MB3336.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2023 17:24:03.4832 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4SGa/t1wh8KFhCWArC/lTGA1pq9KHviwOtHtKsq9XIdjZsANViiBKLMy7735Mhd2VWqbjT/sLHDC3ASHD2ZHHYSh5w8sbTqsmyBe0CwYXn6DyIuQzRkrGrZfLelaHRlm X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR01MB6554 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Please find my inline comment below On 4/3/2023 10:04 PM, Chang, Abner via groups.io wrote: > From: Abner Chang > > 1. Add a helper function to output payload binary > to debug output device. > 2. Add a helper function to split payload into > packages according to maximum transfer unit > of transport interface. > 3. Add a helper function to generate CRC8. > > Signed-off-by: Abner Chang > Cc: Isaac Oram > Cc: Abdul Lateef Attar > Cc: Nickle Wang > Cc: Igor Kulchytskyy > --- > .../BaseManageabilityTransportHelper.inf | 1 + > .../Library/ManageabilityTransportHelperLib.h | 98 ++++++++ > .../BaseManageabilityTransportHelper.c | 218 +++++++++++++++++- > 3 files changed, 310 insertions(+), 7 deletions(-) > > diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf > index 95c3362ddb..c31a89aa49 100644 > --- a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf > +++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.inf > @@ -25,6 +25,7 @@ > [LibraryClasses] > BaseMemoryLib > DebugLib > + MemoryAllocationLib > > [Packages] > ManageabilityPkg/ManageabilityPkg.dec > diff --git a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h > index 718ac34a1f..0dbf5ccb3c 100644 > --- a/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h > +++ b/Features/ManageabilityPkg/Include/Library/ManageabilityTransportHelperLib.h > @@ -11,8 +11,24 @@ > > #include > > +#define DEBUG_MANAGEABILITY_INFO DEBUG_INFO Why did you redefine this macro? I saw that you used both DEBUG_INFO and DEBUG_MANAGEABILITY_INFO throughout this library. Please use them consistently. If you want to change the debug level for all statements in a function, you can declare an argument as the debug level. > + > typedef struct _MANAGEABILITY_PROTOCOL_NAME MANAGEABILITY_PROTOCOL_NAME; > > +typedef struct { > + UINT8 *PayloadPointer; > + UINT32 PayloadSize; > +} MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR; > + > +// > +// The information of multi portions of payload it is > +// splitted according to transport interface Maximum > +// Transfer Unit. > +typedef struct { > + UINT16 NumberOfPackages; ///< Number of packages in MultiPackages. > + MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR MultiPackages[]; > +} MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES; > + > /** > Helper function returns the human readable name of Manageability specification. > > @@ -90,4 +106,86 @@ HelperInitManageabilityTransport ( > OUT MANAGEABILITY_TRANSPORT_ADDITIONAL_STATUS *TransportAdditionalStatus OPTIONAL > ); > > +/** > + This function splits payload into multiple packages according to > + the given transport interface Maximum Transfer Unit (MTU). > + > + @param[in] PreambleSize The additional data size precedes > + each package. > + @param[in] PostambleSize The additional data size succeeds > + each package. > + @param[in] Payload Pointer to payload. > + @param[in] PayloadSize Payload size in byte. > + @param[in] MaximumTransferUnit MTU of transport interface. > + @param[out] MultiplePackages Pointer to receive > + MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES > + structure. Caller has to free the memory > + allocated for MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES. > + > + @retval EFI_SUCCESS MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure > + is returned successfully. > + @retval EFI_OUT_OF_RESOURCE Not enough resource to create > + MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure. > +**/ > +EFI_STATUS > +HelperManageabilitySplitPayload ( > + IN UINT16 PreambleSize, > + IN UINT16 PostambleSize, > + IN UINT8 *Payload, > + IN UINT32 PayloadSize, > + IN UINT32 MaximumTransferUnit, > + OUT MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES **MultiplePackages > + ); > + > +/** > + This function generates CRC8 with given polynomial. > + > + @param[in] Polynomial Polynomial in 8-bit. > + @param[in] CrcInitialValue CRC initial value. > + @param[in] BufferStart Pointer to buffer starts the CRC calculation. > + @param[in] BufferSize Size of buffer. > + > + @retval UINT8 CRC value. > +**/ > +UINT8 > +HelperManageabilityGenerateCrc8 ( > + IN UINT8 Polynomial, > + IN UINT8 CrcInitialValue, > + IN UINT8 *BufferStart, > + IN UINT32 BufferSize > + ); > + > +/** > + Print out manageability transmit payload to the debug output device. > + > + @param[in] Payload Payload to print. > + @param[in] PayloadSize Payload size. > + > +**/ > +VOID > +EFIAPI > +HelperManageabilityPayLoadDebugPrint ( > + IN VOID *Payload, > + IN UINT32 PayloadSize > + ); > + > +/** > + Prints a debug message and manageability payload to the debug output device. > + > + @param[in] Payload Payload to print. > + @param[in] PayloadSize Payload size. > + @param[in] Format The format string for the debug message to print. > + @param[in] ... The variable argument list whose contents are accessed > + based on the format string specified by Format. > + > +**/ > +VOID > +EFIAPI > +HelperManageabilityDebugPrint ( > + IN VOID *Payload, > + IN UINT32 PayloadSize, > + IN CONST CHAR8 *Format, > + ... > + ); > + > #endif > diff --git a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c > index 81da209764..9d20ed49ff 100644 > --- a/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c > +++ b/Features/ManageabilityPkg/Library/BaseManageabilityTransportHelperLib/BaseManageabilityTransportHelper.c > @@ -8,11 +8,12 @@ > #include > #include > #include > +#include > #include > > // > // BaseManageabilityTransportHelper is used by PEI, DXE and SMM. > -// Make sure the global variables added here should be unchangable. > +// Make sure the global variables added here should be unchangeable. > // > MANAGEABILITY_SPECIFICATION_NAME ManageabilitySpecNameTable[] = { > { &gManageabilityTransportKcsGuid, L"KCS" }, > @@ -47,8 +48,8 @@ HelperManageabilitySpecName ( > return NULL; > } > > - if (SpecificationGuid == NULL || IsZeroGuid (SpecificationGuid)) { > - DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__)); > + if ((SpecificationGuid == NULL) || IsZeroGuid (SpecificationGuid)) { > + DEBUG ((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__)); > return NULL; > } > > @@ -99,12 +100,13 @@ HelperManageabilityCheckSupportedSpec ( > return EFI_INVALID_PARAMETER; > } > > - if (TransportGuid == NULL || > + if ((TransportGuid == NULL) || > IsZeroGuid (TransportGuid) || > - ManageabilityProtocolToCheck == NULL || > + (ManageabilityProtocolToCheck == NULL) || > IsZeroGuid (ManageabilityProtocolToCheck) > - ) { > - DEBUG((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__)); > + ) > + { > + DEBUG ((DEBUG_ERROR, "%a: Improper input GUIDs, could be NULL or zero GUID.\n", __FUNCTION__)); > return EFI_INVALID_PARAMETER; > } > > @@ -259,3 +261,205 @@ HelperInitManageabilityTransport ( > > return Status; > } > + > +/** > + This function generates CRC8 with given polynomial. > + > + @param[in] Polynomial Polynomial in 8-bit. > + @param[in] CrcInitialValue CRC initial value. > + @param[in] BufferStart Pointer to buffer starts the CRC calculation. > + @param[in] BufferSize Size of buffer. > + > + @retval UINT8 CRC value. > +**/ > +UINT8 > +HelperManageabilityGenerateCrc8 ( > + IN UINT8 Polynomial, > + IN UINT8 CrcInitialValue, > + IN UINT8 *BufferStart, > + IN UINT32 BufferSize > + ) > +{ > + UINT8 BitIndex; > + UINT32 BufferIndex; > + > + BufferIndex = 0; > + while (BufferIndex < BufferSize) { > + CrcInitialValue = CrcInitialValue ^ *(BufferStart + BufferIndex); > + BufferIndex++; > + > + for (BitIndex = 0; BitIndex < 8; BitIndex++) { > + if ((CrcInitialValue & 0x80) != 0) { > + CrcInitialValue = (CrcInitialValue << 1) ^ Polynomial; > + } else { > + CrcInitialValue <<= 1; > + } > + } > + } > + > + return CrcInitialValue; > +} > + > +/** > + This function splits payload into multiple packages according to > + the given transport interface Maximum Transfer Unit (MTU). > + > + > + @param[in] PreambleSize The additional data size precedes > + each package. > + @param[in] PostambleSize The additional data size succeeds > + each package. > + @param[in] Payload Pointer to payload. > + @param[in] PayloadSize Payload size in byte. > + @param[in] MaximumTransferUnit MTU of transport interface. > + @param[out] MultiplePackages Pointer to receive > + MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES > + structure. Caller has to free the memory > + allocated for MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES. > + > + @retval EFI_SUCCESS MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure > + is returned successfully. > + @retval EFI_OUT_OF_RESOURCE Not enough resource to create > + MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES structure. > +**/ > +EFI_STATUS > +HelperManageabilitySplitPayload ( > + IN UINT16 PreambleSize, > + IN UINT16 PostambleSize, > + IN UINT8 *Payload, > + IN UINT32 PayloadSize, > + IN UINT32 MaximumTransferUnit, > + OUT MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES **MultiplePackages > + ) > +{ > + UINT16 NumberOfPackages; > + UINT16 IndexOfPackage; > + UINT32 PackagePayloadSize; > + UINT32 TotalPayloadRemaining; > + MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES *ThisMultiplePackages; > + MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *ThisPackage; > + > + if ((INT16)(MaximumTransferUnit - PreambleSize - PostambleSize) < 0) { > + DEBUG (( > + DEBUG_ERROR, > + "%a: (Preamble 0x%x + PostambleSize 0x%x) is greater than MaximumTransferUnit 0x%x.\n", > + __FUNCTION__, > + PreambleSize, > + PostambleSize, > + MaximumTransferUnit > + )); > + return EFI_INVALID_PARAMETER; > + } > + > + PackagePayloadSize = MaximumTransferUnit -PreambleSize - PostambleSize; > + NumberOfPackages = (UINT16)((PayloadSize + (PackagePayloadSize - 1)) / PackagePayloadSize); > + ThisMultiplePackages = (MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES *)AllocateZeroPool ( > + sizeof (MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES) + > + sizeof (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR) * NumberOfPackages > + ); > + if (ThisMultiplePackages == NULL) { > + DEBUG ((DEBUG_ERROR, "%a: Not enough memory for MANAGEABILITY_TRANSMISSION_MULTI_PACKAGES\n")); > + return EFI_INVALID_PARAMETER; > + } > + > + ThisMultiplePackages->NumberOfPackages = NumberOfPackages; > + ThisPackage = (MANAGEABILITY_TRANSMISSION_PACKAGE_ATTR *)(ThisMultiplePackages + 1); > + TotalPayloadRemaining = PayloadSize; > + for (IndexOfPackage = 0; IndexOfPackage < NumberOfPackages; IndexOfPackage++) { > + ThisPackage->PayloadPointer = Payload + (IndexOfPackage * PackagePayloadSize); > + ThisPackage->PayloadSize = MIN (TotalPayloadRemaining, PackagePayloadSize); > + TotalPayloadRemaining -= ThisPackage->PayloadSize; > + ThisPackage++; > + } > + > + if (TotalPayloadRemaining != 0) { > + DEBUG ((DEBUG_ERROR, "%a: Error processing multiple packages (TotalPayloadRemaining != 0)\n", __FUNCTION__)); > + return EFI_INVALID_PARAMETER; > + } > + > + *MultiplePackages = ThisMultiplePackages; > + return EFI_SUCCESS; > +} > + > +/** > + Print out manageability transmit payload to the debug output device. > + > + @param[in] Payload Payload to print. > + @param[in] PayloadSize Payload size. > + > +**/ > +VOID > +EFIAPI > +HelperManageabilityPayLoadDebugPrint ( > + IN VOID *Payload, > + IN UINT32 PayloadSize > + ) > +{ > + UINT16 Page256; > + UINT16 Row16; > + UINT16 Column16; > + UINT32 RemainingBytes; > + UINT32 TotalBytePrinted; > + > + RemainingBytes = PayloadSize; > + TotalBytePrinted = 0; > + while (TRUE) { > + if (TotalBytePrinted % 256 == 0) { > + Page256 = (UINT16)TotalBytePrinted / 256; > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "======== Manageability Payload %04xH - %04xH =========\n", Page256 * 256, Page256 * 256 + MIN (RemainingBytes, 256) - 1)); > + DEBUG ((DEBUG_MANAGEABILITY_INFO, " ")); > + for (Column16 = 0; Column16 < 16; Column16++) { > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", Column16)); > + } > + > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n -----------------------------------------------\n")); > + } > + > + for (Row16 = 0; Row16 < 16; Row16++) { > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%04x | ", Page256 * 256 + Row16 * 16)); > + for (Column16 = 0; Column16 < MIN (RemainingBytes, 16); Column16++) { > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "%02x ", *((UINT8 *)Payload + Page256 * 256 + Row16 * 16 + Column16))); > + } > + > + RemainingBytes -= Column16; > + TotalBytePrinted += Column16; > + if (RemainingBytes == 0) { > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n")); > + return; > + } > + DEBUG((DEBUG_MANAGEABILITY_INFO, "\n")); > + } > + > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n")); > + } > + > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "\n\n")); > +} > + > +/** > + Prints a debug message and manageability payload to the debug output device. > + > + @param[in] Payload Payload to print. > + @param[in] PayloadSize Payload size. > + @param[in] Format The format string for the debug message to print. > + @param[in] ... The variable argument list whose contents are accessed > + based on the format string specified by Format. > + > +**/ > +VOID > +EFIAPI > +HelperManageabilityDebugPrint ( > + IN VOID *Payload, > + IN UINT32 PayloadSize, > + IN CONST CHAR8 *Format, > + ... > + ) > +{ > + VA_LIST Marker; > + > + VA_START (Marker, Format); > + DEBUG ((DEBUG_MANAGEABILITY_INFO, "Manageability Transmission: ")); > + DebugVPrint ((UINTN)DEBUG_MANAGEABILITY_INFO, Format, Marker); > + HelperManageabilityPayLoadDebugPrint (Payload, PayloadSize); > + VA_END (Marker); > +}