From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id A0117941E19 for ; Wed, 5 Feb 2025 22:09:53 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Xq8yU0gac3p/U5oOW5u/Ox2D1pTgnQ64PGVIKlPtF3M=; c=relaxed/simple; d=groups.io; h=Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20240830; t=1738793393; v=1; x=1739052592; b=X0pdGLZI2Bl+Q7+yymR6uXMWlPEv8oAruJSNKqdpJzQ0XWxWHsP21RTWVMQJJXMqN6JPl6e6 Wzr6s1qk1fOBJjOFjyJtN6Jq5+OhReBcpyltkDB3/0bCYXbIqV6C+bIZJfEfECJmSHKZNenupNn P6L0mgRcEf8os5BX/iS2m/HVVEbtfkpZcW4M4cAYRhgBrawZ5d5GtpZKB+/jj6pSFx4kpxzGuqo fZ/WC7oISZGrQlFHU+sw6iYE6UchLDEsxzRnasqg5dxLMYF2rl75fQBx1N3x3fX9aJgyUJ1vFkI q2jS+xdn3f9ibedDJpszI7Wy0RUQm9Ji2OODBCJUHCpJQ== X-Received: by 127.0.0.2 with SMTP id S4jBYY7687511xpkeGa73PW4; Wed, 05 Feb 2025 14:09:52 -0800 X-Received: from NAM02-DM3-obe.outbound.protection.outlook.com (NAM02-DM3-obe.outbound.protection.outlook.com [40.107.95.71]) by mx.groups.io with SMTP id smtpd.web11.25791.1738793388246374173 for ; Wed, 05 Feb 2025 14:09:48 -0800 X-Received: from MN2PR07CA0022.namprd07.prod.outlook.com (2603:10b6:208:1a0::32) by MN0PR12MB5836.namprd12.prod.outlook.com (2603:10b6:208:37b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8422.12; Wed, 5 Feb 2025 22:09:42 +0000 X-Received: from BN2PEPF000055E0.namprd21.prod.outlook.com (2603:10b6:208:1a0:cafe::26) by MN2PR07CA0022.outlook.office365.com (2603:10b6:208:1a0::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8398.24 via Frontend Transport; Wed, 5 Feb 2025 22:09:42 +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 BN2PEPF000055E0.mail.protection.outlook.com (10.167.245.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8398.0 via Frontend Transport; Wed, 5 Feb 2025 22:09:41 +0000 X-Received: from rnnvmail204.nvidia.com (10.129.68.6) 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.1544.4; Wed, 5 Feb 2025 14:09:24 -0800 X-Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Wed, 5 Feb 2025 14:09:23 -0800 X-Received: from NV-PF4WDED0.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.1544.14 via Frontend Transport; Wed, 5 Feb 2025 14:09:23 -0800 From: "Girish Mahadevan via groups.io" To: , , , , , CC: , , , , Subject: [edk2-devel] [staging/dynamictables-reorg PATCH v0 11/12] DynamicTablesPkg: Smbios Physical Memory Array (Type 16) Date: Wed, 5 Feb 2025 15:09:09 -0700 Message-ID: <7db0fc68bb33cbf2abbfee031411a6203dd5ca1e.1738793024.git.gmahadevan@nvidia.com> In-Reply-To: References: MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: AnonymousSubmission X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000055E0:EE_|MN0PR12MB5836:EE_ X-MS-Office365-Filtering-Correlation-Id: 4edfa9e2-d4ad-49af-621c-08dd4631ca77 X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?uJnU/tLmFPKmjy1mCh+3/xXr2I8+rkQ9y2Xa64P3U9rtohXpCcCt3wpk1BGt?= =?us-ascii?Q?/kwDZeiL0WBJQz9blgjViCk/cd1Mx+ahEWzwMqOZZeJpOMejlVrsh9eocSnb?= =?us-ascii?Q?1nVz4pwiPhqLiPkXRBRRO1oErVHN5dcjWIbIrDScwGyEjBXIBcfUdEQCS1r8?= =?us-ascii?Q?WnSGrSRgdEg5iqG7675lUdQ8MrFmYwV8+lbz12pjykQ4G+VYVz8aEqVkFC/B?= =?us-ascii?Q?StR0G3Ft8S+vw9GX9SiFwo/OkGdHwxNPe2Lv3bO4PX6kSkqFxZ4O28lWUp2J?= =?us-ascii?Q?pTFnRhb/B556pYv0IwxRDhCBzQ/WUyJr2Hj+/aN2ckwrJ7Kivs4Id0xN23lq?= =?us-ascii?Q?scSe9yVxJJVMyhKn6PVQevTXlSK1c5zPONtIVszEgO+q53pDnU1CLMUVS9qa?= =?us-ascii?Q?psU2IfpcYSUmAGoYtK+i/ejifwSCzNvTYWXXiDsqcU64uTsP+MIe0Hn+r1zk?= =?us-ascii?Q?vIzUYf5zVFyUtuQWv+EKttWCQ/wSETGoAr83Dh+CZGRkf5DkHGqxTEFAoZiF?= =?us-ascii?Q?8gVTKwF2TUL6YQnYs5Zj2j4rSMsKbUlxMpF4POcQELzryJ3lEfIIz+qG7bRG?= =?us-ascii?Q?6zmIM5A83jMYH+DeN9Jbwc5Ba3EUv0FcGiu+Zla3Fb38ePaRKsQX27gRqS27?= =?us-ascii?Q?IvIwFpJlTw5b3ic9BAazoXjaDLToOtN5O7DUhmS4sQQoDBcS/HzgPpBBQrN0?= =?us-ascii?Q?2BGRW104YusRu4WiFo9D5dk2n9GFRjOrRSDOKUvkcoAaFHwvoIdrn0QvuZXe?= =?us-ascii?Q?KbOhApLUoPYEt0l1NSH52cColfLrb617N9XB0BbsLV5ABOOCPE8mPa3gS69J?= =?us-ascii?Q?wVh/RwWDpGZfZjMNkejKwhzmkgd1d5GprSXUgGfyoynYNL8RIXeD5TCq+vpQ?= =?us-ascii?Q?TqiYB/XXC2SnIztZyyNX+gpGHe6WYeZmFpz1NQnGV0wI5Fp9v8aXKIMXFTL8?= =?us-ascii?Q?KkfwMV00KHspY8TBr32+BM/k3t/5n22CXLgVR1wc5hSRJyiWTUHU8Rep1d/Q?= =?us-ascii?Q?qkzXkrdo5UKQrx0KR0iEdz8CjlHmOv5TuLsDpujRna/rdfSP9yauFwod+FeE?= =?us-ascii?Q?OE1OOIW/+PZT/8MQOljAjwSsSeiCJQ3la4z5BxNCPz0+CMIjzX47GRzvkwn/?= =?us-ascii?Q?6v7fULucR9LU1TjQDDaJbNAtOs0mU0uljhH04SinaI4pvtqvHIAp2HHxgeii?= =?us-ascii?Q?XJ59WSIToajlsCPVmIaMb4oFk795Pi4wht0+wUvQc0zmuqwHkKpH/c9kfgs3?= =?us-ascii?Q?waiUUjuVAe+WExIgkthAmHNoxQh0K2/Z/GK7vW+APYg2GxUUC5NvRVhqwZOI?= =?us-ascii?Q?vL2+ZqWFZgvpxeIxjTksuGsKMV7lztbgucuMOC0cxxwbtFTtgTtv5QxlkCRU?= =?us-ascii?Q?Qxx6UXfR6DPxojbPmkWh90HQtFoS6DAfdw/l2Fob9krlKsr9mo+fhd3t9uN3?= =?us-ascii?Q?ot+gApr10n8uhixGnUQvZsJXuUR5rYGqGed9R+jBYEkrL1EIFrMPvlo2XQZk?= =?us-ascii?Q?dvCOv9GowAY5jxY=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2025 22:09:41.8610 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4edfa9e2-d4ad-49af-621c-08dd4631ca77 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: BN2PEPF000055E0.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5836 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 Resent-Date: Wed, 05 Feb 2025 14:09:48 -0800 Resent-From: gmahadevan@nvidia.com Reply-To: devel@edk2.groups.io,gmahadevan@nvidia.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: gDE0VuUQMo0MCS3kPBGbmea0x7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240830 header.b=X0pdGLZI; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io 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/SmbiosT= ype16Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosT= ype16Lib.inf diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBui= lder.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder= .c index bf6e657bcf..f33213f061 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c @@ -311,7 +311,6 @@ exit_handler: } } =20 - DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status)); return Status; } =20 @@ -431,7 +430,6 @@ BuildAndInstallSmbiosTable ( )); } =20 - DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status)); return Status; } =20 @@ -515,7 +513,6 @@ ProcessSmbiosTables ( )); } =20 - DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status)); return Status; } =20 diff --git a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h b/DynamicTab= lesPkg/Include/SmbiosNameSpaceObjects.h index e9bde2a712..7e883e1b89 100644 --- a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h @@ -132,6 +132,25 @@ typedef struct { SMBIOS_TABLE_GENERATOR_ID GeneratorId; } CONTAINED_CM_OBJECTS; =20 +/** 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() =20 #endif // SMBIOS_NAMESPACE_OBJECTS_H_ diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Ge= nerator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Gen= erator.c new file mode 100644 index 0000000000..37592ee560 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator= .c @@ -0,0 +1,361 @@ +/** @file + SMBIOS Type16 Table Generator. + + Copyright (c) 2024, 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 informati= on. + * @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 TableFa= ctoryProtocol, + IN CONST CM_STD_OBJ_SMBIOS_TABLE_INFO *CONST SmbiosT= ableInfo, + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrP= rotocol, + IN SMBIOS_STRUCTURE ***CONST Table, + IN CM_OBJECT_TOKEN **CmObj= ectToken, + IN CONST UINTN TableCo= unt + ) +{ + UINTN Index; + SMBIOS_STRUCTURE **TableList; + + TableList =3D *Table; + for (Index =3D 0; Index < TableCount; Index++) { + if (TableList[Index] !=3D NULL) { + FreePool (TableList[Index]); + } + } + + if (*CmObjectToken !=3D NULL) { + FreePool (*CmObjectToken); + } + + if (TableList !=3D 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 =3D SizeBytes / SIZE_1KB; + + if (SizeBytes < EXTENDED_SIZE_THRESHOLD) { + SmbiosRecord->MaximumCapacity =3D SizeKb; + } else { + SmbiosRecord->MaximumCapacity =3D 0x80000000; + SmbiosRecord->ExtendedMaximumCapacity =3D SizeKb; + } +} + +/** + * Add the SMBIOS table handle reference to the Error Tables. + * + * @param [in] TableFactoryProtocol Pointer to the SMBIOS Table Fac= tory. + * @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 TableFactoryPro= tocol, + IN CM_OBJECT_TOKEN CmObjToken, + OUT SMBIOS_TABLE_TYPE16 *SmbiosRecord + ) +{ + EFI_SMBIOS_HANDLE Handle; + SMBIOS_HANDLE_MAP *HandleMap; + + HandleMap =3D TableFactoryProtocol->GetSmbiosHandle (CmObjToken); + if (HandleMap =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a:Failed to get SMBIOS Handle\n", __FUNCTION__)= ); + Handle =3D 0xFFFF; + } else { + Handle =3D HandleMap->SmbiosTblHandle; + } + + SmbiosRecord->MemoryErrorInformationHandle =3D 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 informati= on. + * @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 TableFactoryPro= tocol, + 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 !=3D NULL); + ASSERT (SmbiosTableInfo !=3D NULL); + ASSERT (CfgMgrProtocol !=3D NULL); + ASSERT (Table !=3D NULL); + ASSERT (TableCount !=3D NULL); + ASSERT (SmbiosTableInfo->TableGeneratorId =3D=3D This->GeneratorID); + + if ((This =3D=3D NULL) || (SmbiosTableInfo =3D=3D NULL) || (CfgMgrProtoc= ol =3D=3D NULL) || + (Table =3D=3D NULL) || (TableCount =3D=3D NULL) || + (SmbiosTableInfo->TableGeneratorId !=3D This->GeneratorID)) + { + DEBUG ((DEBUG_ERROR, "%a:Invalid Paramater\n ", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + *Table =3D NULL; + Status =3D 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 =3D (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRU= CTURE *) * NumObj); + if (TableList =3D=3D NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u devices table\n", + __FUNCTION__, + NumObj + )); + Status =3D EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType16Table; + } + + CmObjectList =3D (CM_OBJECT_TOKEN *)AllocateZeroPool (sizeof (CM_OBJECT_= TOKEN *) * NumObj); + if (CmObjectList =3D=3D NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u CM Objects.\n", + __FUNCTION__, + NumObj + )); + Status =3D EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType16Table; + } + + for (Index =3D 0; Index < NumObj; Index++) { + /** + * Per Spec each structure is terminated by a double-NULL if there are= no + * strings. + */ + SmbiosRecord =3D (SMBIOS_TABLE_TYPE16 *)AllocateZeroPool (sizeof (SMBI= OS_TABLE_TYPE16) + 1 + 1); + if (SmbiosRecord =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto exitBuildSmbiosType16Table; + } + + UpdateSmbiosType16Size (PhysMemoryArray->Size, SmbiosRecord); + SmbiosRecord->Location =3D PhysMemoryArray[Index].Locatio= n; + SmbiosRecord->Use =3D PhysMemoryArray[Index].Use; + SmbiosRecord->MemoryErrorCorrection =3D PhysMemoryArray[Index].MemoryE= rrorCorrectionType; + SmbiosRecord->NumberOfMemoryDevices =3D PhysMemoryArray->NumMemDevices= ; + if (PhysMemoryArray[Index].MemoryErrInfoToken !=3D CM_NULL_TOKEN) { + AddMemErrDeviceHandle ( + TableFactoryProtocol, + PhysMemoryArray[Index].MemoryErrInfoToken, + SmbiosRecord + ); + } else { + SmbiosRecord->MemoryErrorInformationHandle =3D 0xFFFF; + } + + // Setup the header + SmbiosRecord->Hdr.Type =3D EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY; + SmbiosRecord->Hdr.Length =3D sizeof (SMBIOS_TABLE_TYPE16); + + TableList[Index] =3D (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] =3D PhysMemoryArray[Index].PhysMemArrayToken; + } + + *Table =3D TableList; + *CmObjectToken =3D CmObjectList; + *TableCount =3D NumObj; +exitBuildSmbiosType16Table: + return Status; +} + +/** The interface for the SMBIOS Type16 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType16Generator =3D { + // 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 =3D RegisterSmbiosTableGenerator (&SmbiosType16Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 16: Register Generator. Status =3D %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 =3D DeregisterSmbiosTableGenerator (&SmbiosType16Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type16: Deregister Generator. Status =3D %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Li= b.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf new file mode 100644 index 0000000000..4d85c88d7f --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf @@ -0,0 +1,35 @@ +## @file +# SMBIOS Type16 Table Generator +# +# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserve= d. +# Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D SmbiosType16LibArm + FILE_GUID =3D a256956a-de0b-4aa7-8eac-5ce13bbfbb1f + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D DXE_DRIVER + LIBRARY_CLASS =3D NULL|DXE_DRIVER + CONSTRUCTOR =3D SmbiosType16LibConstructor + DESTRUCTOR =3D 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 --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#121094): https://edk2.groups.io/g/devel/message/121094 Mute This Topic: https://groups.io/mt/111022014/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-