From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 95FCA740032 for ; Tue, 25 Jul 2023 23:38:47 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=sLP3bfgYUFf6m/nSNtLpdPiScqGsSLJBp2LZW7HmzZo=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:X-Received:X-Received:X-MS-Exchange-Authentication-Results:Received-SPF:X-Received:X-Received:X-Received:X-Received:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:X-NVConfidentiality:MIME-Version:X-NV-OnPremToCloud:X-EOPAttributedMessage:X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam-Message-Info:X-OriginatorOrg:X-MS-Exchange-CrossTenant-OriginalArrivalTime:X-MS-Exchange-CrossTenant-Network-Message-Id:X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp:X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs:X-MS-Exchange-CrossTenant-FromEntityHeader:X-MS-Exchange-Transport-CrossTenantHeadersStamped:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscrib e:X-Gm-Message-State:Content-Type; s=20140610; t=1690328326; v=1; b=qmhmJ8gVN3EtLnQpwMO1k+p9AbH+wCT7r69FY12QcbLi0dVgeeWPmp7HeCajGmjhbMUfkEQc gapQJnHlSkBZAXFvxq8mtgsIZnioPlQN19I6Oi8dfII83Ob2GsrabZTwyRisfrownOueFj3Y+aK qTm11fxLk0v8HN6RzulJzuhY= X-Received: by 127.0.0.2 with SMTP id TmqVYY7687511x91oG5n2grX; Tue, 25 Jul 2023 16:38:46 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.49]) by mx.groups.io with SMTP id smtpd.web11.111.1690328325633186739 for ; Tue, 25 Jul 2023 16:38:45 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SaQEppTf0veQZtVpZVtw6mB5D6SLO+Zso/7q3ZpNc6B4mf/4BaS4LN36WObUuOlv1BLuLy4Y+E6qo2NHmi20FZPSdSiOGuqm9B4O22cJiSvLBfhWCp77phKPbgGXa1OJiEXpZv9QTuFYdsMaktj+DQ9T1soFuuQpBuIRly8vjNczg3p8in9bV6VsG9RK4I1KZNm+PY/+AGmY7+frGprQXgn5NAmvMmD+hWUT9huLwVynHvhjeQL2HS55GVddXux7DXopkXF0LfF4XPd0FKHPStak9C7Y3Q5YI3So24WGJhJrRu4dypC4qcaExOY90SD+kBON4gNwPTR2AhzAXxmHtg== 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=QLiVkqgCXu9vjtFluhxO5VcSSxqVNzgZW4XPrhTL97g=; b=P+MYHxWi1hOnlcixkTj38rKpHQXdtELVTMf37n7vZ9HaPJbJQFhEJjgEIFiwZnGaH8dsVTbVt3WbC2a/5pPOvqGZwWLfz7C6XodFIAY4G9NNo3oLGfGMRSxsH06NOBnAL2q+rYm32dKMgJMEl9N5tnqyF16o711LGC8aBuyWD6TsaGg4C33QXWhj50EvX97GwADHL3WfSt9G+MkKExiDV0oE5reQzwnUr9sIV4karEcTg22pR0MbdB5h6hQoThr45GHsr3niegT4FqsuRwio2ODU83W8iXYiGD32yt/YHg7rBB0uk6A+4WwnpqMHvgzWsgBKzpOuVVfxWdQywgywUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none X-Received: from MW4P222CA0019.NAMP222.PROD.OUTLOOK.COM (2603:10b6:303:114::24) by IA1PR12MB6483.namprd12.prod.outlook.com (2603:10b6:208:3a8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Tue, 25 Jul 2023 23:38:41 +0000 X-Received: from CO1NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:303:114:cafe::9f) by MW4P222CA0019.outlook.office365.com (2603:10b6:303:114::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Tue, 25 Jul 2023 23:38:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT011.mail.protection.outlook.com (10.13.175.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29 via Frontend Transport; Tue, 25 Jul 2023 23:38:41 +0000 X-Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Tue, 25 Jul 2023 16:38:25 -0700 X-Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Tue, 25 Jul 2023 16:38:25 -0700 X-Received: from build-gmahadevan-20230109T020417557.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.37 via Frontend Transport; Tue, 25 Jul 2023 16:38:24 -0700 From: "Girish Mahadevan via groups.io" To: , CC: , , , , , Subject: [edk2-devel] [PATCH v3 5/5] DynamicTablesPkg: Smbios Physical Memory Array (Type 16) Date: Tue, 25 Jul 2023 23:38:05 +0000 Message-ID: <20230725233805.646668-6-gmahadevan@nvidia.com> In-Reply-To: <20230725233805.646668-1-gmahadevan@nvidia.com> References: <20230725233805.646668-1-gmahadevan@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT011:EE_|IA1PR12MB6483:EE_ X-MS-Office365-Filtering-Correlation-Id: 41b90e01-81e4-434b-e5d3-08db8d684710 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: jYWrXX8WMOrp4KOCrdZRy/UfQUS491IdlL+kosD/5ggkAx9uUAtTh1SZXYjhmMAq4DwSynrIE8Zp+QJ11VN+M08k2dUZzMEWviBAT0Zw6NVEFq00x2N7Kub4WyXcpo3mFOaaPKH17u7/97mwMaQzsTxzhl3Cim35wlM0xGVHIO4xlV2Avcch1CypDzz4JE3+1NIpoOFZwP6XMqiOtw6TpxOXHhEh7XfE8Xe2u/0y30q4cxzetPY7lsv+uaE6NzpS03ZoEWTnUf0Z/S/5phcpbde5gocTklMAqKXsEJg1yIRkXy4wz4eEA8VLZmbNblahMPJNPqmBz0qLBbaX814946mwebsC8psRbw9BG4MVU+VXfxCcL4Xk40kcO1G61vBNnpSGH20cZEcgswGIZdn+FhjxUgXs9ulhEG3xlMIMzQgewX0MY2UKteqrQtA35VtkR9JPmL5rcdZrhCHiPtcWktIXQ1BT/DdZ2K0jm1ke6lWMRTG29HuaVDPQrtIqR/e2HS460IBH0a97OKqddtWfISUZC8iNejfLo8S8gFWI/DoRBohxPu/GrYu4gEOmX0dn062aFLV26bmLKlantsfw3sr3VpBYuYT19Xqni6g3N+XgdyvnTa/IJXyWjQlZLanNCUfM8+Gqu0K6kmx4g/zt3xYgpt/m008FkbaRHZv99N1U7Ud27eRjcDgKnlhz7sHWN0xlMcXu+MFe2y5qPal3EVbWy4XeNHqEyFnP5IGdZSPrdelb6TOhFZ84yy+uRRKU X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 23:38:41.0055 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41b90e01-81e4-434b-e5d3-08db8d684710 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6483 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gmahadevan@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: bWyTs64Yx4MYgO7vYmbBGlsZx7686176AA= Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=qmhmJ8gV; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") Add the Generator library for SMBIOS Table Type 16 - Physical Memory Array. Signed-off-by: Girish Mahadevan Reviewed-by: Jeff Brasen Reviewed-by: Nick Ramirez --- .../SmbiosTableBuilder.c | 3 - .../Include/SmbiosNameSpaceObjects.h | 19 + .../SmbiosType16Lib/SmbiosType16Generator.c | 361 ++++++++++++++++++ .../SmbiosType16Lib/SmbiosType16Lib.inf | 35 ++ 4 files changed, 415 insertions(+), 3 deletions(-) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c index bfddaac3aa..5feafcac66 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c @@ -312,7 +312,6 @@ exit_handler: } } - DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status)); return Status; } @@ -432,7 +431,6 @@ BuildAndInstallSmbiosTable ( )); } - DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status)); return Status; } @@ -516,7 +514,6 @@ ProcessSmbiosTables ( )); } - DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status)); return Status; } diff --git a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h index e44d703fac..760b082021 100644 --- a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h @@ -107,6 +107,25 @@ typedef struct { SMBIOS_TABLE_GENERATOR_ID GeneratorId; } CONTAINED_CM_OBJECTS; +/** A structure that describes the Physical Memory Array. + + SMBIOS Specification v3.6.0 Type 16 + + ID: ESmbiosObjPhysicalMemoryArray +**/ +typedef struct CmSmbiosPhysicalMemoryArray { + UINT8 Use; + UINT8 Location; + UINT16 MemoryErrorCorrection; + UINT16 MemoryErrorInformationHandle; + UINT16 NumberOfMemoryDevices; + UINT8 MemoryErrorCorrectionType; + UINT64 Size; + UINT8 NumMemDevices; + CM_OBJECT_TOKEN MemoryErrInfoToken; + CM_OBJECT_TOKEN PhysMemArrayToken; +} CM_SMBIOS_PHYSICAL_MEMORY_ARRAY; + #pragma pack() #endif // SMBIOS_NAMESPACE_OBJECTS_H_ diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c new file mode 100644 index 0000000000..dad7588ed5 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c @@ -0,0 +1,361 @@ +/** @file + SMBIOS Type16 Table Generator. + + Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include +#include + +/** This macro expands to a function that retrieves the Memory Device + information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceSmbios, + ESmbiosObjPhysicalMemoryArray, + CM_SMBIOS_PHYSICAL_MEMORY_ARRAY + ) + +#define EXTENDED_SIZE_THRESHOLD (SIZE_2TB) + +/** + * Free any resources allocated when installing SMBIOS Type16 table. + * + * @param [in] This Pointer to the SMBIOS table generator. + * @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + Protocol interface. + + * @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + * @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol interface. + * @param [in] Table Pointer to the SMBIOS table. + * @param [in] CmObjectToken Pointer to the CM ObjectToken Array. + * @param [in] TableCount Number of SMBIOS tables. + + * @retval EFI_SUCCESS Table generated successfully. + * @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for + the requested object. + * @retval EFI_INVALID_PARAMETER A parameter is invalid. + * @retval EFI_NOT_FOUND Could not find information. + * @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + * @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +FreeSmbiosType16TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *CONST This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObjectToken, + IN CONST UINTN TableCount + ) +{ + UINTN Index; + SMBIOS_STRUCTURE **TableList; + + TableList = *Table; + for (Index = 0; Index < TableCount; Index++) { + if (TableList[Index] != NULL) { + FreePool (TableList[Index]); + } + } + + if (*CmObjectToken != NULL) { + FreePool (*CmObjectToken); + } + + if (TableList != NULL) { + FreePool (TableList); + } + + return EFI_SUCCESS; +} + +/** + * Update the Size encoding for Type 16. + * + * @param [in] SizeBytes Size of the Memory device. + * @param [out] SmbiosRecord SMBIOS record to update. +**/ +STATIC +VOID +UpdateSmbiosType16Size ( + IN UINT64 SizeBytes, + IN OUT SMBIOS_TABLE_TYPE16 *SmbiosRecord + ) +{ + UINT64 SizeKb = SizeBytes / SIZE_1KB; + + if (SizeBytes < EXTENDED_SIZE_THRESHOLD) { + SmbiosRecord->MaximumCapacity = SizeKb; + } else { + SmbiosRecord->MaximumCapacity = 0x80000000; + SmbiosRecord->ExtendedMaximumCapacity = SizeKb; + } +} + +/** + * Add the SMBIOS table handle reference to the Error Tables. + * + * @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory. + * @param [in] CmObjToken CM Token to lookup.. + * @param [out] SmbiosRecord SMBIOS record to update. +**/ +STATIC +VOID +AddMemErrDeviceHandle ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_OBJECT_TOKEN CmObjToken, + OUT SMBIOS_TABLE_TYPE16 *SmbiosRecord + ) +{ + EFI_SMBIOS_HANDLE Handle; + SMBIOS_HANDLE_MAP *HandleMap; + + HandleMap = TableFactoryProtocol->GetSmbiosHandle (CmObjToken); + if (HandleMap == NULL) { + DEBUG ((DEBUG_ERROR, "%a:Failed to get SMBIOS Handle\n", __FUNCTION__)); + Handle = 0xFFFF; + } else { + Handle = HandleMap->SmbiosTblHandle; + } + + SmbiosRecord->MemoryErrorInformationHandle = Handle; +} + +/** Construct SMBIOS Type16 Table describing memory devices. + + If this function allocates any resources then they must be freed + in the FreeXXXXTableResources function. + + * @param [in] This Pointer to the SMBIOS table generator. + * @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Factory + * Protocol interface. + * @param [in] SmbiosTableInfo Pointer to the SMBIOS table information. + * @param [in] CfgMgrProtocol Pointer to the Configuration Manager + * Protocol interface. + * @param [out] Table Pointer to the SMBIOS table. + * @param [out] CmObjectToken Pointer to the CM Object Token Array. + * @param [out] TableCount Number of tables installed. + + * @retval EFI_SUCCESS Table generated successfully. + * @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + * Manager is less than the Object size for + * the requested object. + * @retval EFI_INVALID_PARAMETER A parameter is invalid. + * @retval EFI_NOT_FOUND Could not find information. + * @retval EFI_OUT_OF_RESOURCES Could not allocate memory. + * @retval EFI_UNSUPPORTED Unsupported configuration. +**/ +STATIC +EFI_STATUS +BuildSmbiosType16TableEx ( + IN CONST SMBIOS_TABLE_GENERATOR *This, + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosTableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + OUT SMBIOS_STRUCTURE ***Table, + OUT CM_OBJECT_TOKEN **CmObjectToken, + OUT UINTN *CONST TableCount + ) +{ + EFI_STATUS Status; + SMBIOS_STRUCTURE **TableList; + SMBIOS_TABLE_TYPE16 *SmbiosRecord; + CM_OBJECT_TOKEN *CmObjectList; + CM_SMBIOS_PHYSICAL_MEMORY_ARRAY *PhysMemoryArray; + UINT32 NumObj; + UINTN Index; + + ASSERT (This != NULL); + ASSERT (SmbiosTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Table != NULL); + ASSERT (TableCount != NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID); + + if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) || + (Table == NULL) || (TableCount == NULL) || + (SmbiosTableInfo->TableGeneratorId != This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a:Invalid Paramater\n ", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + *Table = NULL; + Status = GetESmbiosObjPhysicalMemoryArray ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &PhysMemoryArray, + &NumObj + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to get Memory Devices CM Object %r\n", + __FUNCTION__, + Status + )); + return Status; + } + + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * NumObj); + if (TableList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u devices table\n", + __FUNCTION__, + NumObj + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType16Table; + } + + CmObjectList = (CM_OBJECT_TOKEN *)AllocateZeroPool (sizeof (CM_OBJECT_TOKEN *) * NumObj); + if (CmObjectList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u CM Objects.\n", + __FUNCTION__, + NumObj + )); + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType16Table; + } + + for (Index = 0; Index < NumObj; Index++) { + /** + * Per Spec each structure is terminated by a double-NULL if there are no + * strings. + */ + SmbiosRecord = (SMBIOS_TABLE_TYPE16 *)AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE16) + 1 + 1); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType16Table; + } + + UpdateSmbiosType16Size (PhysMemoryArray->Size, SmbiosRecord); + SmbiosRecord->Location = PhysMemoryArray[Index].Location; + SmbiosRecord->Use = PhysMemoryArray[Index].Use; + SmbiosRecord->MemoryErrorCorrection = PhysMemoryArray[Index].MemoryErrorCorrectionType; + SmbiosRecord->NumberOfMemoryDevices = PhysMemoryArray->NumMemDevices; + if (PhysMemoryArray[Index].MemoryErrInfoToken != CM_NULL_TOKEN) { + AddMemErrDeviceHandle ( + TableFactoryProtocol, + PhysMemoryArray[Index].MemoryErrInfoToken, + SmbiosRecord + ); + } else { + SmbiosRecord->MemoryErrorInformationHandle = 0xFFFF; + } + + // Setup the header + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY; + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE16); + + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = PhysMemoryArray[Index].PhysMemArrayToken; + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = NumObj; +exitBuildSmbiosType16Table: + return Status; +} + +/** The interface for the SMBIOS Type16 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType16Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType16), + // Generator Description + L"SMBIOS.TYPE16.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY, + NULL, + NULL, + // Build table function. + BuildSmbiosType16TableEx, + // Free function. + FreeSmbiosType16TableEx, +}; + +/** Register the Generator with the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is registered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_ALREADY_STARTED The Generator for the Table ID + is already registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType16LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType16Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 16: Register Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** Deregister the Generator from the SMBIOS Table Factory. + + @param [in] ImageHandle The handle to the image. + @param [in] SystemTable Pointer to the System Table. + + @retval EFI_SUCCESS The Generator is deregistered. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The Generator is not registered. +**/ +EFI_STATUS +EFIAPI +SmbiosType16LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType16Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type16: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf new file mode 100644 index 0000000000..5bb40db21c --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf @@ -0,0 +1,35 @@ +## @file +# SMBIOS Type17 Table Generator +# +# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SmbiosType16LibArm + FILE_GUID = a256956a-de0b-4aa7-8eac-5ce13bbfbb1f + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType16LibConstructor + DESTRUCTOR = SmbiosType16LibDestructor + +[Sources] + SmbiosType16Generator.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[Protocols] + gEfiSmbiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED + +[LibraryClasses] + BaseLib + DebugLib -- 2.17.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107259): https://edk2.groups.io/g/devel/message/107259 Mute This Topic: https://groups.io/mt/100361564/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-