From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.44]) by mx.groups.io with SMTP id smtpd.web12.6576.1664852509892081632 for ; Mon, 03 Oct 2022 20:01:50 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=r6EnfmJA; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.220.44, mailfrom: gmahadevan@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cAsIMDhEYYnimHPMBd2vm+LkeZRABnGACpatH5RjJDpgf7eCBAMPKlIToIowBdmovUSoWgNr5RmY4ph9tbNGjpNSPYExI8U9K80C0hf1MLdY7YEdu2dnR22lrDcFBcxM8TNqFkjdg9lY9lah/jtbjRScuAgSbUz0ix7AdN93+cNrd1M4Z9d6+q4Fo8yR+GXaii70olQ4SZpxtHlHlQ1ZHbHYnM1GiJbOdUFokkMbSM/i6/U5WV1g8jMg2ex8btPL9xqDLEQu20othQO+dfa9oUMNEVy7M/oIPl4kH/B6ugvZaZgjGHxoRFb0/na1Gh55096JxtptKKEhz7vg/YUHWA== 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=Tz8Fg+T708gknCt+ZGU768LJjXzU7VjOgLfNd7feDDQ=; b=Ycj8kFa2Z6RMvmINH4OGD2B+U+7QjjKAlfnw7ILZiGNy5sEEuMQYuSwXH4WJ1AlUt1IjJFkaxTUIzHyiuODxVwf6T2UgyUFeSpI8jvKGdwxAoWpHxdR0s65G6ag0HeKK07QBsWQ9R3FQ6Uxv4XH2fAOjlFBstMLuU8YNbXEATWWDW2OsYPBYdWSUlfvZoaNDoXZ7Ea3KvgNdBVdYVwwGWUfiDO5MH2RYSSdAeaAgSlg2F12iV+PEKjDbJlAKzsat59X6ZCN6Lr7TtiUbgl3QUVYwIDnBVZZlunx9YWI6yiVGR0kLU8rlmabSeKnVX4cADbgukb+6Hjg22Ix/Jr09Lw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Tz8Fg+T708gknCt+ZGU768LJjXzU7VjOgLfNd7feDDQ=; b=r6EnfmJAreK3BlrVcoUYlvsbrWbLij8f+IkGsciI3mYoryCwKhLISjsdaRwbaEDHzmIiR5wp8vsKMIwI3FTGzn0dfZD3uIXVJvd58KK3hHXKyoIz9Djaz5R4kGm6yJCkjAZEu4emEj8l42jjKHTYxZmlqqFtep79tjDQxv17wfwchDNfrmHLwsiNCx7A9askT3JxJ57Bw7T2zUR/zW4M9TIUful3y9pOpPBWQ61/hiDI8HetEOnLYKKDjMfw4obeVR52/VB7p7ftK3GkyiqFKq3hnoOlh2wRRFaxTAMVl8vY6QEV8AgCUJKWerp0T/JOwVE9b4FSm3Z+wlJtnQefSw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from CY5PR12MB6297.namprd12.prod.outlook.com (2603:10b6:930:22::19) by SA0PR12MB4559.namprd12.prod.outlook.com (2603:10b6:806:9e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.24; Tue, 4 Oct 2022 03:01:47 +0000 Received: from CY5PR12MB6297.namprd12.prod.outlook.com ([fe80::b00c:10c1:3a2e:5b98]) by CY5PR12MB6297.namprd12.prod.outlook.com ([fe80::b00c:10c1:3a2e:5b98%6]) with mapi id 15.20.5676.028; Tue, 4 Oct 2022 03:01:47 +0000 Message-ID: <73ca18d0-1984-e428-2c2a-96244172e9f3@nvidia.com> Date: Mon, 3 Oct 2022 21:01:44 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH v1 1/1] DynamicTablesPkg: Add SMBIOS String table helper library To: Sami Mujawar , devel@edk2.groups.io Cc: Alexei.Fedorov@arm.com, pierre.gondois@arm.com, jbrasen@nvidia.com, ashishsingha@nvidia.com, nramirez@nvidia.com, wwatson@nvidia.com, Samer.El-Haj-Mahmoud@arm.com, Akanksha.Jain2@arm.com, Matteo.Carlini@arm.com, Ben.Adderson@arm.com, nd@arm.com References: <20220912141850.35064-1-sami.mujawar@arm.com> From: "Girish Mahadevan" In-Reply-To: <20220912141850.35064-1-sami.mujawar@arm.com> X-ClientProxiedBy: BYAPR06CA0041.namprd06.prod.outlook.com (2603:10b6:a03:14b::18) To CY5PR12MB6297.namprd12.prod.outlook.com (2603:10b6:930:22::19) Return-Path: gmahadevan@nvidia.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6297:EE_|SA0PR12MB4559:EE_ X-MS-Office365-Filtering-Correlation-Id: f80e3a09-35c5-49ee-81fe-08daa5b4c691 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RkMfQQnCKRKleLZEQ4KhyzALGx+fQanI7EJFRx+ftA4GJnfLDXai2drAZXLUygAKWiKFBs7ajrw9K1CGwllSDI++VSVohPOhNeJIrRzuApo9Cgra0aIThwld23qTvv/zed75AzelJmQAXXOh8Kx1HMIOWyw8Q0z185nCp/IF153pACUcfVQ41kX/ehF/l83O5YpXU4H4OQ21nCZ68sa12TEz0td6VPXXZEQFwbaen8s0J+LeXZlV3sgWYOMlCc9vd1vS+LdCbo8qsWp3vedmgCEYfgD337y/+j7pwo5hEgzTJx1Ea1AVo7pQx+cXK+Ne9Iicyn6IOoEBBaGi46FT09G2FkMUrO8Jtow5kDOpOg/3/BuFsIng9uCO+Aq7MlKl3Kwr6Z7ypNIZiUJWk8cBQ+7HaUqzqeHUmJSGrgQPZCVlaVVEYvZLdD7azYS0Jk4V6rVTUn0WmFwAKmZHnbBFlVSLBT1FWZRUEUqUOXJxJ84hdvEVvecCHMOqGWee7xqNEeyXP4ddDXkRnMgVzGx3dAyck8aLtXP8HPhHScWL/BPN98EcyGkQ9C1ow9IzdmOr8LdfrCTSGeg91mcZWC/lyqx9gboh3kNnyhxRyjUUYVy1JzVGNuxazNV5G9AY2js3baomMRE74nGXEW4Qke26xBRP1QK21oFYCSplffYTlE9H1Gjlc6FEgm9ILjeSCBK5dUp4mWA2CmX4sWqOxxY/FJrj5rUmGPXazizTSZolBWkrB35e1Yw3l4Qy/JkZKQF2GQGbjEpG+QQfrWk8KxGmgD1qHT1l82laGa4H+ckdEWZ4TbPcCl0UWqoanB83OLPh X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6297.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(396003)(376002)(136003)(39860400002)(346002)(451199015)(86362001)(31696002)(83380400001)(38100700002)(186003)(30864003)(5660300002)(8936002)(316002)(19627235002)(8676002)(66946007)(66556008)(66476007)(4326008)(53546011)(6506007)(41300700001)(6666004)(26005)(6512007)(2616005)(2906002)(478600001)(966005)(6486002)(31686004)(36756003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ejhLb3RlRTBhU0xPUjczNWFt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lzcVAwYjNMK3BEVkt0b2k1Rkc2?= =?utf-8?B?UlNKVHFUQ0lsZkhQWTgzcm1sRnFTbTFBMWxDL0JodVp6ODB2emtBT3Fxd3FX?= =?utf-8?B?dEtUcy9Ic3dOVzFwZUR6TWlpZ0U1M2lKc0JGNHFCZXFWNlYrcXBEcHJINlZh?= =?utf-8?B?dHdDVElnNWM3Mjl2a3lQdWtxQWZkdVk4Vytocjk3a25TS2tCMmN2QUNiUGly?= =?utf-8?B?L0twSG9tUFVrSHAvcmRRekJuS3ZIMW1NQ3EyUkZiYWtWd2lVcXAxbEpQRzJD?= =?utf-8?B?dVB6NTBqRjY4Q0k1TGh2dHJFelROYkoveFNzZjVjOGxZTk1LckFnNmU2RUlk?= =?utf-8?B?S09EWjdEWkVmcWd5TzRpcjQyVTc3ZzBhZldUZlBPRUZzU2RobUdNZWttSnFB?= =?utf-8?B?Y0E9PQ==?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f80e3a09-35c5-49ee-81fe-08daa5b4c691 X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6297.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2022 03:01:47.2186 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JbT8/wx9IGDufBswgSbIyAlb/rcMWrFphDvLovDQTdbhptu/uQdwDubte66FlrM9gfizawaArAxKGDsl7BYQnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4559 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hello Sami, My apologies for the late response. I had one question/comment. Comment marked with [GM] inline. Best Regards Girish On 9/12/2022 8:18 AM, Sami Mujawar wrote: > External email: Use caution opening links or attachments > > > The Section 6.1.3, SMBIOS specification version 3.6.0 describes the > handling of test strings in SMBIOS tables. > > Test strings are added at the end of the formatted portion of the SMBIOS > structure and are referenced by index in the SMBIOS structure. > > Therefore, introduce a SmbiosStringTableLib to simplify the publishing > of the string set. > > SmbiosStringTableLib introduces a concept of string table which records > the references to the SMBIOS strings as they are added and returns an > string reference which is then assigned to the string field in the > formatted portion of the SMBIOS structure. Once all strings are added, > the library provides an interface to get the required size for the string > set. This allows sufficient memory to be allocated for the SMBIOS table. > The library also provides an interface to publish the string set in > accordance with the SMBIOS specification. > > Example: > EFI_STATUS > BuildSmbiosType17Table () { > STRING_TABLE StrTable; > UINT8 DevLocatorRef; > UINT8 BankLocatorRef; > SMBIOS_TABLE_TYPE17 *SmbiosRecord; > CHAR8 *StringSet; > ... > > // Initialize string table for 7 strings > StringTableInitialize (&StrTable, 7); > > StringTableAddString (&StrTable, "SIMM 3", &DevLocatorRef); > StringTableAddString (&StrTable, "Bank 0", &BankLocatorRef); > ... > > SmbiosRecord = AllocateZeroPool ( > sizeof (SMBIOS_TABLE_TYPE17) + > StringTableGetStringSetSize (&StrTable) > ); > ... > SmbiosRecord->DeviceLocator = DevLocatorRef; > SmbiosRecord->BankLocator = BankLocatorRef; > ... > // get the string set area > StringSet = (CHAR8*)(SmbiosRecord + 1); > > // publish the string set > StringTablePublishStringSet ( > &StrTable, > StringSet, > StringTableGetStringSetSize (&StrTable) > ); > > // free string table > StringTableFree (&StrTable); > > return EFI_SUCCESS; > } > > Signed-off-by: Sami Mujawar > Cc: Alexei Fedorov > Cc: Pierre Gondois > Cc: Girish Mahadevan > Cc: Jeff Brasen > Cc: Ashish Singhal > Cc: Nick Ramirez > Cc: William Watson > Cc: Samer El-Haj-Mahmoud > --- > The changes can be seen at: > https://github.com/samimujawar/edk2/tree/2370_smbios_stringlib_v1 > > DynamicTablesPkg/DynamicTables.dsc.inc | 3 +- > DynamicTablesPkg/DynamicTablesPkg.dec | 5 +- > DynamicTablesPkg/DynamicTablesPkg.dsc | 3 +- > DynamicTablesPkg/Include/Library/SmbiosStringTableLib.h | 119 ++++++++++ > DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.c | 227 ++++++++++++++++++++ > DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.inf | 25 +++ > 6 files changed, 379 insertions(+), 3 deletions(-) > > diff --git a/DynamicTablesPkg/DynamicTables.dsc.inc b/DynamicTablesPkg/DynamicTables.dsc.inc > index 3d4fa0c4c4b67d6770aee8705c80cc18d20c823a..d35acc1788f2ddc5e2b5fc3e4bedfd48251f7ec8 100644 > --- a/DynamicTablesPkg/DynamicTables.dsc.inc > +++ b/DynamicTablesPkg/DynamicTables.dsc.inc > @@ -1,7 +1,7 @@ > ## @file > # Dsc include file for Dynamic Tables Framework. > # > -# Copyright (c) 2017 - 2021, Arm Limited. All rights reserved.
> +# Copyright (c) 2017 - 2022, Arm Limited. All rights reserved.
> # > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -18,6 +18,7 @@ [LibraryClasses.common] > SsdtPcieSupportLib|DynamicTablesPkg/Library/Common/SsdtPcieSupportLib/SsdtPcieSupportLib.inf > SsdtSerialPortFixupLib|DynamicTablesPkg/Library/Common/SsdtSerialPortFixupLib/SsdtSerialPortFixupLib.inf > TableHelperLib|DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf > + SmbiosStringTableLib|DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.inf > > [Components.common] > # > diff --git a/DynamicTablesPkg/DynamicTablesPkg.dec b/DynamicTablesPkg/DynamicTablesPkg.dec > index cc34c2bdd6ff9b5ca508961b3d0fe85ffbb73c12..2a79cfd4edebbdff05bee66fa01a17d68252e8a7 100644 > --- a/DynamicTablesPkg/DynamicTablesPkg.dec > +++ b/DynamicTablesPkg/DynamicTablesPkg.dec > @@ -1,7 +1,7 @@ > ## @file > # dec file for Dynamic Tables Framework. > # > -# Copyright (c) 2017 - 2021, Arm Limited. All rights reserved.
> +# Copyright (c) 2017 - 2022, Arm Limited. All rights reserved.
> # > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -39,6 +39,9 @@ [LibraryClasses] > ## @libraryclass Defines a set of helper methods. > TableHelperLib|Include/Library/TableHelperLib.h > > + ## @libraryclass Defines a set of SMBIOS string helper methods. > + SmbiosStringTableLib|Include/Library/SmbiosStringTableLib.h > + > [Protocols] > # Configuration Manager Protocol GUID > gEdkiiConfigurationManagerProtocolGuid = { 0xd85a4835, 0x5a82, 0x4894, { 0xac, 0x2, 0x70, 0x6f, 0x43, 0xd5, 0x97, 0x8e } } > diff --git a/DynamicTablesPkg/DynamicTablesPkg.dsc b/DynamicTablesPkg/DynamicTablesPkg.dsc > index 07cc837552f587fe5bf9031e0061b0234e8698d4..bd5084a9008f040acdd16200ae8cdb23455ac101 100644 > --- a/DynamicTablesPkg/DynamicTablesPkg.dsc > +++ b/DynamicTablesPkg/DynamicTablesPkg.dsc > @@ -2,7 +2,7 @@ > # Dsc file for Dynamic Tables Framework. > # > # Copyright (c) 2019, Linaro Limited. All rights reserved.
> -# Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.
> +# Copyright (c) 2019 - 2022, Arm Limited. All rights reserved.
> # > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -46,6 +46,7 @@ [Components.common] > DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf > DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoParserLib.inf > DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/DynamicPlatRepoLib.inf > + DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.inf > > [BuildOptions] > *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES > diff --git a/DynamicTablesPkg/Include/Library/SmbiosStringTableLib.h b/DynamicTablesPkg/Include/Library/SmbiosStringTableLib.h > new file mode 100644 > index 0000000000000000000000000000000000000000..246d4d30ddf901640ea720c108e2971552ec6c96 > --- /dev/null > +++ b/DynamicTablesPkg/Include/Library/SmbiosStringTableLib.h > @@ -0,0 +1,119 @@ > +/** @file > + SMBIOS String Table Helper library. > + > + Copyright (c) 2022, Arm Limited. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#ifndef SMBIOS_STRING_TABLE_H_ > +#define SMBIOS_STRING_TABLE_H_ > + > +/** A structure representing a string in the string table. > +*/ > +typedef struct StringElement { > + /// Length of the string (does not include the NULL termination) > + UINTN StringLen; > + > + /// Reference to the string > + CONST CHAR8 *String; > +} STRING_ELEMENT; > + > +/** A structure representing a string table. > +*/ > +typedef struct StringTable { > + /// Count of strings in the table > + UINT8 StrCount; > + > + /// Total length of all strings in the table (does not include > + // the NULL termination for each string) > + UINTN TotalStrLen; > + > + /// Maximum string count > + UINT8 MaxStringElements; > + > + /// Pointer to the string table elements > + STRING_ELEMENT *Elements; > +} STRING_TABLE; > + > +/** Add a string to the string table > + > + @param [IN] StrTable Pointer to the string table > + @param [IN] Str Pointer to the string > + @param [OUT] StrRef Optional pointer to retrieve the string field > + reference of the string in the string table > + > + @return EFI_SUCCESS Success > + @return EFI_INVALID_PARAMETER Invalid string table pointer > + @return EFI_BUFFER_TOO_SMALL Insufficient space to add string > +**/ > +EFI_STATUS > +EFIAPI > +StringTableAddString ( > + IN STRING_TABLE *CONST StrTable, > + IN CONST CHAR8 *Str, > + OUT UINT8 *StrRef OPTIONAL > + ); > + > +/** Returns the total size required to publish the strings to the SMBIOS > + string area. > + > + @param [IN] StrTable Pointer to the string table > + > + @return Total size required to publish the strings in the SMBIOS string area. > +**/ > +UINTN > +EFIAPI > +StringTableGetStringSetSize ( > + IN STRING_TABLE *CONST StrTable > + ); > + > +/** Iterate through the string table and publish the strings in the SMBIOS > + string area. > + > + @param [IN] StrTable Pointer to the string table > + @param [IN] SmbiosStringAreaStart Start address of the SMBIOS string area. > + @param [IN] SmbiosStringAreaSize Size of the SMBIOS string area. > + > + @return EFI_SUCCESS Success > + @return EFI_INVALID_PARAMETER Invalid string table pointer > + @return EFI_BUFFER_TOO_SMALL Insufficient space to publish strings > +**/ > +EFI_STATUS > +EFIAPI > +StringTablePublishStringSet ( > + IN STRING_TABLE *CONST StrTable, > + IN CHAR8 *CONST SmbiosStringAreaStart, > + IN CONST UINTN SmbiosStringAreaSize > + ); > + > +/** Initialise the string table and allocate memory for the string elements. > + > + @param [IN] StrTable Pointer to the string table > + @param [IN] MaxStringElements Maximum number of strings that the string > + table can hold. > + > + @return EFI_SUCCESS Success > + @return EFI_INVALID_PARAMETER Invalid string table pointer > + @return EFI_OUT_OF_RESOURCES Failed to allocate memory for string elements > +**/ > +EFI_STATUS > +EFIAPI > +StringTableInitialize ( > + IN STRING_TABLE *CONST StrTable, > + IN UINTN MaxStringElements > + ); > + > +/** Free memory allocated for the string elements in the string table. > + > + @param [IN] StrTable Pointer to the string table > + > + @return EFI_SUCCESS Success > + @return EFI_INVALID_PARAMETER Invalid string table pointer or string elements > +**/ > +EFI_STATUS > +EFIAPI > +StringTableFree ( > + IN STRING_TABLE *CONST StrTable > + ); > + > +#endif // SMBIOS_STRING_TABLE_H_ > diff --git a/DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.c b/DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.c > new file mode 100644 > index 0000000000000000000000000000000000000000..bd186f27fe1613cf819b6600e62960c003a796d6 > --- /dev/null > +++ b/DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.c > @@ -0,0 +1,227 @@ > +/** @file > + SMBIOS String Table Helper > + > + Copyright (c) 2022, Arm Limited. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + @par Reference(s): > + - DSP0134 - SMBIOS Specification Version 3.6.0, 2022-06-17 > +**/ > + > +#include > +#include > +#include > +#include > +#include > + > +/** Add a string to the string table > + > + @param [IN] StrTable Pointer to the string table > + @param [IN] Str Pointer to the string > + @param [OUT] StrRef Optional pointer to retrieve the string field > + reference of the string in the string table > + > + @return EFI_SUCCESS Success > + @return EFI_INVALID_PARAMETER Invalid string table pointer > + @return EFI_BUFFER_TOO_SMALL Insufficient space to add string > +**/ > +EFI_STATUS > +EFIAPI > +StringTableAddString ( > + IN STRING_TABLE *CONST StrTable, > + IN CONST CHAR8 *Str, > + OUT UINT8 *StrRef OPTIONAL > + ) > +{ > + UINTN StrLength; > + STRING_ELEMENT *StrElement; > + > + if ((StrTable == NULL) || (Str == NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (StrTable->StrCount >= StrTable->MaxStringElements) { > + return EFI_BUFFER_TOO_SMALL; > + } > + > + StrLength = AsciiStrLen (Str); > + if (StrLength == 0) { > + return EFI_INVALID_PARAMETER; > + } > + > + // Update the string element > + StrElement = &StrTable->Elements[StrTable->StrCount]; > + StrElement->StringLen = StrLength; > + StrElement->String = Str; > + > + // Update String table information > + StrTable->TotalStrLen += StrLength; > + StrTable->StrCount++; > + > + // Return the index of the string in the string table if requested > + if (StrRef != NULL) { > + // Note: SMBIOS string field references start at 1. So, return the > + // StrCount as the string refrence after it is updated. > + *StrRef = StrTable->StrCount; > + } > + > + return EFI_SUCCESS; > +} > + > +/** Returns the total size required to publish the strings to the SMBIOS > + string area. > + > + @param [IN] StrTable Pointer to the string table > + > + @return Total size required to publish the strings in the SMBIOS string area. > +**/ > +UINTN > +EFIAPI > +StringTableGetStringSetSize ( > + IN STRING_TABLE *CONST StrTable > + ) > +{ > + if (StrTable == NULL) { > + ASSERT (0); > + return 0; > + } > + > + // See Section 6.1.3 Text strings, SMBIOS Specification Version 3.6.0 > + // - If the formatted portion of the structure contains string-reference > + // fields and all the string fields are set to 0 (no string references), > + // the formatted section of the structure is followed by two null (00h) > + // BYTES. > + // - Each string is terminated with a null (00h) BYTE > + // - and the set of strings is terminated with an additional null (00h) BYTE. > + > + // Therefore, if string count = 0, return 2 > + // if string count > 0, the string set size = > + // StrTable->TotalStrLen (total length of the strings in the string table) > + // + StrTable->StrCount (add string count to include '\0' for each string) > + // +1 (an additional '\0' is required at the end of the string set). > + return (StrTable->StrCount == 0) ? 2 : > + (StrTable->TotalStrLen + StrTable->StrCount + 1); > +} > + > +/** Iterate through the string table and publish the strings in the SMBIOS > + string area. > + > + @param [IN] StrTable Pointer to the string table > + @param [IN] SmbiosStringAreaStart Start address of the SMBIOS string area. > + @param [IN] SmbiosStringAreaSize Size of the SMBIOS string area. > + > + @return EFI_SUCCESS Success > + @return EFI_INVALID_PARAMETER Invalid string table pointer > + @return EFI_BUFFER_TOO_SMALL Insufficient space to publish strings > +**/ > +EFI_STATUS > +EFIAPI > +StringTablePublishStringSet ( > + IN STRING_TABLE *CONST StrTable, > + IN CHAR8 *CONST SmbiosStringAreaStart, > + IN CONST UINTN SmbiosStringAreaSize > + ) > +{ > + UINT8 Index; > + STRING_ELEMENT *StrElement; > + CHAR8 *SmbiosString; > + UINTN BytesRemaining; > + UINTN BytesCopied; > + > + if ((StrTable == NULL) || (SmbiosStringAreaStart == NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (SmbiosStringAreaSize < StringTableGetStringSetSize (StrTable)) { > + return EFI_BUFFER_TOO_SMALL; > + } > + > + SmbiosString = SmbiosStringAreaStart; > + BytesRemaining = SmbiosStringAreaSize; > + > + if (StrTable->StrCount == 0) { > + // See Section 6.1.3 Text strings, SMBIOS Specification Version 3.6.0 > + // If the formatted portion of the structure contains string-reference > + // fields and all the string fields are set to 0 (no string references), > + // the formatted section of the structure is followed by two null (00h) > + // BYTES. > + *SmbiosString++ = '\0'; > + } else { > + for (Index = 0; Index < StrTable->StrCount; Index++) { > + StrElement = &StrTable->Elements[Index]; > + AsciiStrCpyS (SmbiosString, BytesRemaining, StrElement->String); > + > + // See Section 6.1.3 Text strings, SMBIOS Specification Version 3.6.0 > + // - Each string is terminated with a null (00h) BYTE > + // Bytes Copied = String length + 1 for the string NULL terminator. > + BytesCopied = StrElement->StringLen + 1; > + BytesRemaining -= BytesCopied; > + SmbiosString += BytesCopied; > + } > + } > + > + // See Section 6.1.3 Text strings, SMBIOS Specification Version 3.6.0 > + // - the set of strings is terminated with an additional null (00h) BYTE. > + *SmbiosString = '\0'; [GM] Shouldn't you advance the SmbiosString pointer by one more ? After the loop isn't SmbiosString going to be at the NULL char of the last string ? And we're trying to add one more NULL character ? Should it be: SmbiosString++; *SmbiosString = '\0'; > + return EFI_SUCCESS; > +} > + > +/** Initialise the string table and allocate memory for the string elements. > + > + @param [IN] StrTable Pointer to the string table > + @param [IN] MaxStringElements Maximum number of strings that the string > + table can hold. > + > + @return EFI_SUCCESS Success > + @return EFI_INVALID_PARAMETER Invalid string table pointer > + @return EFI_OUT_OF_RESOURCES Failed to allocate memory for string elements > +**/ > +EFI_STATUS > +EFIAPI > +StringTableInitialize ( > + IN STRING_TABLE *CONST StrTable, > + IN UINTN MaxStringElements > + ) > +{ > + STRING_ELEMENT *Elements; > + > + if ((StrTable == NULL) || (MaxStringElements > MAX_UINT8)) { > + return EFI_INVALID_PARAMETER; > + } > + > + ZeroMem (StrTable, sizeof (STRING_TABLE)); > + > + Elements = (STRING_ELEMENT *)AllocateZeroPool ( > + sizeof (STRING_ELEMENT) * MaxStringElements > + ); > + if (Elements == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + StrTable->Elements = Elements; > + StrTable->MaxStringElements = (UINT8)MaxStringElements; > + return EFI_SUCCESS; > +} > + > +/** Free memory allocated for the string elements in the string table. > + > + @param [IN] StrTable Pointer to the string table > + > + @return EFI_SUCCESS Success > + @return EFI_INVALID_PARAMETER Invalid string table pointer or string elements > +**/ > +EFI_STATUS > +EFIAPI > +StringTableFree ( > + IN STRING_TABLE *CONST StrTable > + ) > +{ > + if ((StrTable == NULL) || (StrTable->Elements == NULL)) { > + return EFI_INVALID_PARAMETER; > + } > + > + FreePool (StrTable->Elements); > + ZeroMem (StrTable, sizeof (STRING_TABLE)); > + return EFI_SUCCESS; > +} > diff --git a/DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.inf b/DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.inf > new file mode 100644 > index 0000000000000000000000000000000000000000..88624c50e3f3e930074222b6d686f75485538b26 > --- /dev/null > +++ b/DynamicTablesPkg/Library/Common/SmbiosStringTableLib/SmbiosStringTableLib.inf > @@ -0,0 +1,25 @@ > +## @file > +# SMBIOS String Table Helper library. > +# > +# Copyright (c) 2022, Arm Limited. All rights reserved. > +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +## > + > +[Defines] > + INF_VERSION = 0x0001001B > + BASE_NAME = SmbiosStringTableLib > + FILE_GUID = 8C570DD8-531E-473F-85C6-9252746DBAC1 > + VERSION_STRING = 1.0 > + MODULE_TYPE = DXE_DRIVER > + LIBRARY_CLASS = SmbiosStringTableLib > + > +[Sources] > + SmbiosStringTableLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + DynamicTablesPkg/DynamicTablesPkg.dec > + > +[LibraryClasses] > + BaseLib > -- > 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' >