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 143C07803CC for ; Tue, 25 Jul 2023 23:38:42 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Lq282f8EepZ8ZNttqZBDZSgEzqBkEfCoyhWzvWcA+Hc=; 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=1690328321; v=1; b=wuU7Rfzk8rk+ppylwdgs1ZjqAl37eYQXjWgvr1SaLHsFY/8SMzE69CJCiz8v350O3E4PoXRe nOdnkABdrQnsSB9rther2yIIq0Z+U/TfNgzmggrxvM3hZLtrrLg0leJpLXk2qfFEAHqUDvo2pj0 2jh2TSAa5naJdD8E8Vf9oOBM= X-Received: by 127.0.0.2 with SMTP id kGB2YY7687511xFlmWjm1tbB; Tue, 25 Jul 2023 16:38:41 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.61]) by mx.groups.io with SMTP id smtpd.web10.126.1690328320865529950 for ; Tue, 25 Jul 2023 16:38:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z8EaXftpOAKOyit9FiFoB11ml7+B+Wtay4MKVKzkMGZ/ZdneUgB4J2wqGd+GPbRbu0hFVSJYt1kiaZnuBaa9cg7Gv/zqWGSFMp77hyqk7veO2IOKAz4RKPM1C1g34amJaxwXoZfXmP+LC1BsB5oB0o2msWjQ/SS6MO0VNYVGn+5nGZzrNaiYhRadJxfgaLKnpjDl6teVPE3MoIXVWNiV6SlDAV5Sb7t3nOJt9NUApqlFT7krgtYUwTutJhZm17hmRLiHcEbo0qvGtyMvyLJDEvCTgPgy6K61NiF71I3XHMG54tfCqsRmh2907XHRdKAOCK6nRzu8haU2KlV1zk5Y2Q== 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=wy/XJSdlZODh5y+B4XhQZkObuVDmPNUGe2oAV326eEY=; b=fOwSS1xsATs3Fv6tfMF6JxaQz/CXKxAz8D0wdNi39Y0SBT8xGJe+fOZP1E6tUgYcEguD8+Y3BHi1Fw2k6ko7UpnrcJuEKLJzWucIjQYoJNHaNliRKmI5prqO0WYiP4B1HOFVM81Ou2qWRF2JVK/xZpG5JwpCe14Pev3HtujAFW0kY4ymZjMTA5fQgkSGAmXx2djMXrpgpyyKiXy+nbThzVRShSv0QFjAIMK1uAddYkjrL9CmgIV11I4tIFxZ/UIXpT/cSMmmJiWloaDvascQcWkj+5sHoZMwC0rosgmHEquCYjgEYtl+e3mO5BbNIdGmOVfTBnx6Fh3SnPx5Gu4TJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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 MW4PR03CA0170.namprd03.prod.outlook.com (2603:10b6:303:8d::25) by MN0PR12MB5739.namprd12.prod.outlook.com (2603:10b6:208:372::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 23:38:38 +0000 X-Received: from CO1NAM11FT026.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8d:cafe::59) by MW4PR03CA0170.outlook.office365.com (2603:10b6:303:8d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33 via Frontend Transport; Tue, 25 Jul 2023 23:38:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C X-Received: from mail.nvidia.com (216.228.117.160) by CO1NAM11FT026.mail.protection.outlook.com (10.13.175.67) 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:37 +0000 X-Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) 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:24 -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:24 -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 4/5] DynamicTablesPkg: Smbios Memory Device (Type 17) Date: Tue, 25 Jul 2023 23:38:04 +0000 Message-ID: <20230725233805.646668-5-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: CO1NAM11FT026:EE_|MN0PR12MB5739:EE_ X-MS-Office365-Filtering-Correlation-Id: cca55658-5f6a-42df-5d61-08db8d6844df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: +FKNegoHG0odcf6XS76ElO36CwmiyU7uiQ1+zj/qlRYtY24xfFosyDVW3V914JAW8ppo+dNgSDEaNPOsSyVbVfsdDJuemIRKmYf0e08fg+HF+/5KUB+STW9z2RC9b/qDB+GnZklgyE2GbSrk0t93U88ANBnjdD9GkvMEw66B3ASoNX8I4S3k46Dehof7CF15BASUIHSMXrXrJQnxNPFCdhn9fLG+RcG59FN55CM3AexHMjyDyVr7fvXjh7z83T3ktudGuCjLS+vV4efC5igPgy6X3FdKv7whLT9htyr1YfTFtuGP29vlnYtUtpwGBIgiMC19GVohN6xKIku6zbZYE25m8yOTTvQmDX0pQWFFzo59KxfS8JPXX0lD6nl1YDVHvAt8KdFO2hcLy1YnqkDr1PX2DsIsnMubWEEc70REKdV67CHBlsNiOACIg1rlQJehcOEdwG0e7vkdGH2660cphUAknU9L9N48JNzgvpctz/e6YujyCbLkQpKPdiR8EmWiIzEER3itx+Ec4iStwvj7mCEeVTKyd0iRITuOtISqa2uPdcyx6WLg94wTCmHPXuF2YOspaO8o5RJ9ASgRMwZX+BmM1z2WBYf417rANY56Jt3stbxMUNJwPQfhLknyB0IfcGTHcqlCvcs2X/wBUwei8qVELu0Hj32ydkw0xba1Bj40MymFYnaNFPBgL++6tP/IUthyuS2nRt4TV2IZzs1Suchys3fCnS0xkC7OerUs7kPfBSAR4VAgce1BIueOtrcq X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 23:38:37.3724 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cca55658-5f6a-42df-5d61-08db8d6844df 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.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT026.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5739 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: 2lwkStRlYJP70LJWDhmkccKfx7686176AA= 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=wuU7Rfzk; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); 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 Add the Generator library for SMBIOS Table Type 17 - Memory Device. Signed-off-by: Girish Mahadevan Reviewed-by: Jeff Brasen --- .../Include/SmbiosNameSpaceObjects.h | 70 +++ .../SmbiosType17Lib/SmbiosType17Generator.c | 445 ++++++++++++++++++ .../SmbiosType17Lib/SmbiosType17Lib.inf | 36 ++ 3 files changed, 551 insertions(+) create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf diff --git a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h index 836c902e40..e44d703fac 100644 --- a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h +++ b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h @@ -13,6 +13,8 @@ #ifndef SMBIOS_NAMESPACE_OBJECTS_H_ #define SMBIOS_NAMESPACE_OBJECTS_H_ +#include + #pragma pack(1) typedef enum SmbiosObjectID { @@ -37,6 +39,74 @@ typedef enum SmbiosObjectID { ESmbiosObjMax } ESMBIOS_OBJECT_ID; +/** A structure that describes the physical memory device. + + The physical memory devices on the system are described by this object. + + SMBIOS Specification v3.5.0 Type17 + + ID: ESmbiosObjMemoryDeviceInfo, +*/ +typedef struct CmSmbiosMemoryDeviceInfo { + /** Size of the device. + Size of the device in bytes. + */ + UINT64 Size; + + /** Device Set */ + UINT8 DeviceSet; + + /** Speed of the device + Speed of the device in MegaTransfers/second. + */ + UINT32 Speed; + + /** Serial Number of device */ + CHAR8 *SerialNum; + + /** AssetTag identifying the device */ + CHAR8 *AssetTag; + + /** Device Locator String for the device. + String that describes the slot or position of the device on the board. + */ + CHAR8 *DeviceLocator; + + /** Bank locator string for the device. + String that describes the bank where the device is located. + */ + CHAR8 *BankLocator; + + /** Firmware version of the memory device */ + CHAR8 *FirmwareVersion; + + /** Manufacturer Id. + 2 byte Manufacturer Id as per JEDEC Standard JEP106AV + */ + UINT16 ModuleManufacturerId; + + /** Manufacturer Product Id + 2 byte Manufacturer Id as designated by Manufacturer. + */ + UINT16 ModuleProductId; + + CM_OBJECT_TOKEN MemoryDeviceInfoToken; + CM_OBJECT_TOKEN PhysicalArrayToken; + UINT16 DataWidth; + UINT16 TotalWidth; + UINT8 Rank; + + MEMORY_DEVICE_TYPE DeviceType; + MEMORY_DEVICE_TYPE_DETAIL TypeDetail; + MEMORY_DEVICE_TECHNOLOGY DeviceTechnology; + MEMORY_FORM_FACTOR FormFactor; +} CM_SMBIOS_MEMORY_DEVICE_INFO; + +typedef struct { + CM_OBJECT_TOKEN CmObjToken; + SMBIOS_TABLE_GENERATOR_ID GeneratorId; +} CONTAINED_CM_OBJECTS; + #pragma pack() #endif // SMBIOS_NAMESPACE_OBJECTS_H_ diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c new file mode 100644 index 0000000000..27f2dfc235 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c @@ -0,0 +1,445 @@ +/** @file + SMBIOS Type17 Table Generator. + + Copyright (c) 2022 - 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, + ESmbiosObjMemoryDeviceInfo, + CM_SMBIOS_MEMORY_DEVICE_INFO + ) + +#define EXTENDED_SIZE_THRESHOLD (0x7FFF00000LL) +#define SIZE_GRANULARITY_THRESHOLD (0x100000L) +#define SIZE_GRANULARITY_BITMASK (0x8000) +#define EXTENDED_SPEED_THRESHOLD (0xFFFF) +#define SMBIOS_TYPE17_MAX_STRINGS (7) +#define RANK_MASK (0x7) + +STATIC +EFI_STATUS +FreeSmbiosType17TableEx ( + 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; +} + +STATIC +VOID +AddPhysArrHandle ( + IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *CONST TableFactoryProtocol, + IN CM_OBJECT_TOKEN CmObjToken, + OUT SMBIOS_TABLE_TYPE17 *SmbiosRecord + ) +{ + EFI_SMBIOS_HANDLE PhysMemArrHandle; + SMBIOS_HANDLE_MAP *HandleMap; + + HandleMap = TableFactoryProtocol->GetSmbiosHandle (CmObjToken); + if (HandleMap == NULL) { + DEBUG ((DEBUG_ERROR, "%a:Failed to get SMBIOS Handle\n", __FUNCTION__)); + PhysMemArrHandle = 0; + } else { + PhysMemArrHandle = HandleMap->SmbiosTblHandle; + } + + SmbiosRecord->MemoryArrayHandle = PhysMemArrHandle; +} + +STATIC +VOID +UpdateSmbiosType17Size ( + IN UINT64 Size, + OUT SMBIOS_TABLE_TYPE17 *SmbiosRecord + ) +{ + if (Size < SIZE_GRANULARITY_THRESHOLD) { + SmbiosRecord->Size = Size / SIZE_1KB; + SmbiosRecord->Size |= SIZE_GRANULARITY_BITMASK; + } else if (Size >= EXTENDED_SIZE_THRESHOLD) { + SmbiosRecord->Size = 0x7FFF; + SmbiosRecord->ExtendedSize = (Size / SIZE_1MB); + } else { + SmbiosRecord->Size = (Size / SIZE_1MB); + } +} + +STATIC +VOID +UpdateSmbiosType17Speed ( + IN UINT32 Speed, + OUT SMBIOS_TABLE_TYPE17 *SmbiosRecord + ) +{ + if (Speed > -EXTENDED_SPEED_THRESHOLD) { + SmbiosRecord->Speed = EXTENDED_SPEED_THRESHOLD; + SmbiosRecord->ExtendedSpeed = Speed; + } else { + SmbiosRecord->Speed = Speed; + } +} + +STATIC +VOID +UpdateSmbiosType17Rank ( + IN UINT8 Rank, + OUT SMBIOS_TABLE_TYPE17 *SmbiosRecord + ) +{ + if (Rank > RANK_MASK) { + SmbiosRecord->Attributes = 0; + } else { + SmbiosRecord->Attributes |= (Rank & RANK_MASK); + } +} + +/** Construct SMBIOS Type17 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] 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. + + @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 +BuildSmbiosType17TableEx ( + 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; + UINT32 NumMemDevices; + SMBIOS_STRUCTURE **TableList; + CM_OBJECT_TOKEN *CmObjectList; + CM_SMBIOS_MEMORY_DEVICE_INFO *MemoryDevicesInfo; + UINTN Index; + UINT8 SerialNumRef; + UINT8 AssetTagRef; + UINT8 DeviceLocatorRef; + UINT8 BankLocatorRef; + UINT8 FirmwareVersionRef; + CHAR8 *OptionalStrings; + SMBIOS_TABLE_TYPE17 *SmbiosRecord; + UINTN SmbiosRecordSize; + STRING_TABLE StrTable; + + 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 = GetESmbiosObjMemoryDeviceInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &MemoryDevicesInfo, + &NumMemDevices + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Failed to get Memory Devices CM Object %r\n", + Status + )); + return Status; + } + + TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * NumMemDevices); + if (TableList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a:Failed to alloc memory for %u devices table\n", + __FUNCTION__, + NumMemDevices + )); + Status = EFI_OUT_OF_RESOURCES; + goto exit; + } + + CmObjectList = (CM_OBJECT_TOKEN *)AllocateZeroPool (sizeof (CM_OBJECT_TOKEN *) * NumMemDevices); + if (CmObjectList == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to alloc memory for %u CM Objects\n", + __FUNCTION__, + NumMemDevices + )); + Status = EFI_OUT_OF_RESOURCES; + goto exit; + } + + for (Index = 0; Index < NumMemDevices; Index++) { + StringTableInitialize (&StrTable, SMBIOS_TYPE17_MAX_STRINGS); + + SerialNumRef = 0; + AssetTagRef = 0; + DeviceLocatorRef = 0; + BankLocatorRef = 0; + FirmwareVersionRef = 0; + + if (MemoryDevicesInfo[Index].DeviceLocator != NULL) { + Status = StringTableAddString ( + &StrTable, + MemoryDevicesInfo[Index].DeviceLocator, + &DeviceLocatorRef + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add DeviceLocator String %r \n", Status)); + } + } + + if (MemoryDevicesInfo[Index].BankLocator != NULL) { + Status = StringTableAddString ( + &StrTable, + MemoryDevicesInfo[Index].BankLocator, + &BankLocatorRef + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to BankLocator String %r \n", Status)); + } + } + + if (MemoryDevicesInfo[Index].SerialNum != NULL) { + Status = StringTableAddString ( + &StrTable, + MemoryDevicesInfo[Index].SerialNum, + &SerialNumRef + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add SerialNum String %r \n", Status)); + } + } + + if (MemoryDevicesInfo[Index].AssetTag != NULL) { + Status = StringTableAddString ( + &StrTable, + MemoryDevicesInfo[Index].AssetTag, + &AssetTagRef + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add Asset Tag String %r \n", Status)); + } + } + + if (MemoryDevicesInfo[Index].FirmwareVersion != NULL) { + Status = StringTableAddString ( + &StrTable, + MemoryDevicesInfo[Index].FirmwareVersion, + &FirmwareVersionRef + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to add Asset Tag String %r \n", Status)); + } + } + + SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE17) + + StringTableGetStringSetSize (&StrTable); + SmbiosRecord = (SMBIOS_TABLE_TYPE17 *)AllocateZeroPool (SmbiosRecordSize); + if (SmbiosRecord == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto exit; + } + + UpdateSmbiosType17Size (MemoryDevicesInfo[Index].Size, SmbiosRecord); + UpdateSmbiosType17Speed (MemoryDevicesInfo[Index].Speed, SmbiosRecord); + UpdateSmbiosType17Rank (MemoryDevicesInfo[Index].Rank, SmbiosRecord); + + SmbiosRecord->DeviceSet = MemoryDevicesInfo[Index].DeviceSet; + SmbiosRecord->ModuleManufacturerID = + MemoryDevicesInfo[Index].ModuleManufacturerId; + SmbiosRecord->ModuleProductID = + MemoryDevicesInfo[Index].ModuleProductId; + SmbiosRecord->DataWidth = MemoryDevicesInfo[Index].DataWidth; + SmbiosRecord->TotalWidth = MemoryDevicesInfo[Index].TotalWidth; + SmbiosRecord->MemoryType = MemoryDevicesInfo[Index].DeviceType; + SmbiosRecord->FormFactor = MemoryDevicesInfo[Index].FormFactor; + SmbiosRecord->MemoryTechnology = MemoryDevicesInfo[Index].DeviceTechnology; + // Is there a reference to a Physical Array Device. + if (MemoryDevicesInfo[Index].PhysicalArrayToken != CM_NULL_TOKEN) { + AddPhysArrHandle ( + TableFactoryProtocol, + MemoryDevicesInfo[Index].PhysicalArrayToken, + SmbiosRecord + ); + } + + SmbiosRecord->DeviceLocator = DeviceLocatorRef; + SmbiosRecord->BankLocator = BankLocatorRef; + SmbiosRecord->AssetTag = AssetTagRef; + SmbiosRecord->SerialNumber = SerialNumRef; + SmbiosRecord->FirmwareVersion = FirmwareVersionRef; + OptionalStrings = (CHAR8 *)(SmbiosRecord + 1); + // publish the string set + StringTablePublishStringSet ( + &StrTable, + OptionalStrings, + (SmbiosRecordSize - sizeof (SMBIOS_TABLE_TYPE17)) + ); + // setup the header + SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_DEVICE; + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE17); + TableList[Index] = (SMBIOS_STRUCTURE *)SmbiosRecord; + CmObjectList[Index] = MemoryDevicesInfo[Index].MemoryDeviceInfoToken; + StringTableFree (&StrTable); + } + + *Table = TableList; + *CmObjectToken = CmObjectList; + *TableCount = NumMemDevices; +exit: + // free string table + return Status; +} + +/** The interface for the SMBIOS Type17 Table Generator. +*/ +STATIC +CONST +SMBIOS_TABLE_GENERATOR SmbiosType17Generator = { + // Generator ID + CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType17), + // Generator Description + L"SMBIOS.TYPE17.GENERATOR", + // SMBIOS Table Type + EFI_SMBIOS_TYPE_MEMORY_DEVICE, + NULL, + NULL, + // Build table function Extended. + BuildSmbiosType17TableEx, + // Free function Extended. + FreeSmbiosType17TableEx +}; + +/** 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 +SmbiosType17LibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = RegisterSmbiosTableGenerator (&SmbiosType17Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type 17: 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 +SmbiosType17LibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = DeregisterSmbiosTableGenerator (&SmbiosType17Generator); + DEBUG (( + DEBUG_INFO, + "SMBIOS Type17: Deregister Generator. Status = %r\n", + Status + )); + ASSERT_EFI_ERROR (Status); + return Status; +} diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf new file mode 100644 index 0000000000..e5067f3000 --- /dev/null +++ b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf @@ -0,0 +1,36 @@ +## @file +# SMBIOS Type17 Table Generator +# +# Copyright (c) 2022, 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 = SmbiosType17LibArm + FILE_GUID = 1f063bac-f8f1-4e08-8ffd-9aae52c75497 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = NULL|DXE_DRIVER + CONSTRUCTOR = SmbiosType17LibConstructor + DESTRUCTOR = SmbiosType17LibDestructor + +[Sources] + SmbiosType17Generator.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 + SmbiosStringTableLib -- 2.17.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107256): https://edk2.groups.io/g/devel/message/107256 Mute This Topic: https://groups.io/mt/100361560/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-