From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (EUR04-HE1-obe.outbound.protection.outlook.com [40.107.7.75]) by mx.groups.io with SMTP id smtpd.web09.8117.1662992350461826673 for ; Mon, 12 Sep 2022 07:19:11 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=jpUcgJJU; spf=pass (domain: arm.com, ip: 40.107.7.75, mailfrom: sami.mujawar@arm.com) ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=GwGSnyaZeBAQA4g0KLNEHdRqImjwhegNXAYycd0GdLugIIO8+UIcEYHY4yWNjzAaaS7eUx+kxy7NuFBm8qDsH4kTE9wjJMjjGNFobZEGybM/Fh/cGe6Nh+3mJhsualFJzKjq+AGQ8A4krJa/Xq26BT5E/06fBFdK+xHkumER6aFc2XAUDgMJLgBgtfOTaoRxGqWJb6tZ3oioj/YdOTPjfy9ouAog/PmgZaB9EB/x5/i53g2a7abtmDZ+0ROx6DBQvPFsAaaGhA2MgPJQJLH7Vig40ZxpJmnzYhpkQ5+JeeK4TTzGOI9OhSpnkX1zPhrMq/dhfMCRr1irPcMKVql8yQ== ARC-Message-Signature: i=2; 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=jdRmsVMXQICrT1CgLJgOgm56Fh58UPDzAEVqqtg3KiQ=; b=Ef4ggGunujdbS/v64HdhVTwkOa+sPi/jU2+UD0L7XEhavZxf7gDOkqKNdo/yBdeYJQEn1O+rF2vvr59QD3ZcvnUZlbsKuRNeU4fiPUcxXtsOHM+WAaSuaFOydad6DCLTMmvoV/HwFkXNWKbK/rkvKToq8V6Lxel/T34Pk0xJ2LSJ638eesOS6p+7MnCqSCP0CA75Y5TQ3LZ5qacLIz7xrycBdfAdvYaIWqtCkEj64lGMg1znuJxBITLGNoEA5IkhtzEGB5fnykvbg+a1NjXy5THbZUtcxm45nhRzGsZdwDezEfGjcX6iZ3oRsn/KI1NYY7TiQF4C4zgvDuInRSQYJA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jdRmsVMXQICrT1CgLJgOgm56Fh58UPDzAEVqqtg3KiQ=; b=jpUcgJJUMKpF2B8x1XBNG6iTRbnF8v3ytpXoC85rdJ/RZuOgJB+uuhsCRfEGeqHDjww8UtWt7OYjoQWMYNPWs+fpldVu0CiZcNoCvJBiPbDBlEXw3k9j8CZapxCVv7SRWYlLUNkv6YnK3u9JNll42Z4HbSZXdmPU3Js7RXJ3xeI= Received: from DB6PR0301CA0081.eurprd03.prod.outlook.com (2603:10a6:6:30::28) by DBBPR08MB5961.eurprd08.prod.outlook.com (2603:10a6:10:203::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.14; Mon, 12 Sep 2022 14:19:06 +0000 Received: from DBAEUR03FT031.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:30:cafe::2e) by DB6PR0301CA0081.outlook.office365.com (2603:10a6:6:30::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.22 via Frontend Transport; Mon, 12 Sep 2022 14:19:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT031.mail.protection.outlook.com (100.127.142.173) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.13 via Frontend Transport; Mon, 12 Sep 2022 14:19:06 +0000 Received: ("Tessian outbound fa99bf31ee7d:v123"); Mon, 12 Sep 2022 14:19:06 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ef3bcc9ab5555b32 X-CR-MTA-TID: 64aa7808 Received: from a5bb5ea1a13d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D436EB24-5BEC-4E55-9F51-0B2B0421E91F.1; Mon, 12 Sep 2022 14:18:59 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a5bb5ea1a13d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 12 Sep 2022 14:18:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ezI9XrEY9mXLgbyn5TVDnNi8m9XkupRedznRkwqb3J+XlnUU8DGpUgxxMC+PopvXsJC9A2Gt4HWtelb/Zv3x2+USHFpr9nJdFibhoLIjvwQQ8U1HnsL44EWPqaWc9/xMbXm2OABVd+Lhh+tZSXXt/967vS3k03f9YJYh2OqApfxMFvfaj6BotqQpixBMmKTkfiWZx+WAkaymNXWBYCNB3GxtgkeNS4EV2UxWw4VzMRzQsZuSqjKMCJeff48jIjU6jojefW5ur34Its2PL7yKfTYw2c4JdfJYAcbSj/jtxlvYmeO1TStp8NBQIPdTWRt6jxdsl8lEcPmRTIOAlsL8aw== 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=jdRmsVMXQICrT1CgLJgOgm56Fh58UPDzAEVqqtg3KiQ=; b=SpQlUknouLrlwkKueNpJ/3tfSCfhpP/w57m/GNGKTX/CrpqMptSpcmeM/G0ptA4U0QtsaCI55pcIexn86WhK1E+rzP3NswrNdJi4gI2c+UWERzil6FcCvOwmOKV32sKw0PbCZ7T9znMl/3KFGnJNA803b8oBcyVu8fyZxKHtq0He3J2YgnoS2n/xq03xblJtjaoUct0ewDw8uamnuN5bbACubcHkrOZ2ojbVDe5D1spZM1HjNYeaR+1X+qB24NQYGCBBqC6LyOwgyaNuinOhb3V9n4Tphkn7U++LC5FL7dvNQJA9vQCYXVY4KCKg9QTGZwIqj9y5/wn+rfcvlacw0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jdRmsVMXQICrT1CgLJgOgm56Fh58UPDzAEVqqtg3KiQ=; b=jpUcgJJUMKpF2B8x1XBNG6iTRbnF8v3ytpXoC85rdJ/RZuOgJB+uuhsCRfEGeqHDjww8UtWt7OYjoQWMYNPWs+fpldVu0CiZcNoCvJBiPbDBlEXw3k9j8CZapxCVv7SRWYlLUNkv6YnK3u9JNll42Z4HbSZXdmPU3Js7RXJ3xeI= Received: from AM5PR0601CA0041.eurprd06.prod.outlook.com (2603:10a6:203:68::27) by PAVPR08MB9724.eurprd08.prod.outlook.com (2603:10a6:102:31f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.22; Mon, 12 Sep 2022 14:18:55 +0000 Received: from AM7EUR03FT045.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:68:cafe::78) by AM5PR0601CA0041.outlook.office365.com (2603:10a6:203:68::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.12 via Frontend Transport; Mon, 12 Sep 2022 14:18:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT045.mail.protection.outlook.com (100.127.140.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5612.13 via Frontend Transport; Mon, 12 Sep 2022 14:18:53 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2507.9; Mon, 12 Sep 2022 14:18:53 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.9; Mon, 12 Sep 2022 14:18:51 +0000 Received: from E114225.Arm.com (10.1.196.36) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2507.9 via Frontend Transport; Mon, 12 Sep 2022 14:18:51 +0000 From: "Sami Mujawar" To: CC: Sami Mujawar , , , , , , , , , , , , Subject: [PATCH v1 1/1] DynamicTablesPkg: Add SMBIOS String table helper library Date: Mon, 12 Sep 2022 15:18:50 +0100 Message-ID: <20220912141850.35064-1-sami.mujawar@arm.com> X-Mailer: git-send-email 2.16.2.windows.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT045:EE_|PAVPR08MB9724:EE_|DBAEUR03FT031:EE_|DBBPR08MB5961:EE_ X-MS-Office365-Filtering-Correlation-Id: aaf55fd4-27b9-46d6-1c66-08da94c9c098 X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: SI+LLNaAMdC4NnBIasGq+wd2Oqio/1nSXV+SnYIcGP8qd/Zcg4XEkcOa4QjQg7Mft2wjIK6pXKKqqnnn93z84iHE7nrYQBesFkMj8xO2o+HKFl0dZP+yBBthAoRiQutfU7x5mvr4+ZlhAUxUq82eSoeqrRPHEC/WSC4Hr+7yALAR8y7E81iHdKwksmynw5D8zNqTZptg3r2f6igXsO9gW38woYLUmky+O1c0XrPZRlQka5bDZSaWHUWzNl4zqQUznk9ep/YMlFCeBwQzjDo65oZFAWxOkbXxn8FiiCzuYtLH7k/0/dV4/wd91sBhmVftZTs1X+1mH3QitOrQPaoST4ybpsyQkJXwOdyqAA8pc0mVY8T/xTBxqcewUPcNFprvmeQuIB7RfFPwio8nWmp/MBv66ZU9UX8ink19BeGDCB0jNZnWUW+6ii5pCfSX6Mhvs93RtLtQ6fr5MijtVaMCAEJgbT+Xl/KG0CU0vbiIu5baN6fwCrKIpsRWbTDkKU30a3bwb32PcPT+7MDb0TIGuedQVjeOHpLDQLz0gbE9jZ7inXMFMhrL36DBAunqiJf+iDYpIkvPH2nRjdxo63u6sYeFVnosGWWNrAcQff3CfOtSXoFCJuExZf5fHlUi/AH+x6x9Y6k4gYfc8GLoRTAl88ty0Uk92XUATU8ulcDNypAcbNoA/sonCRkCK/zYBxH9YaNkkR8Kral09zQykkYEIepo8THDo6kecoyFKpRT1w/uGU/d3GoHwXmjIHfNTSqHa6122Go0yMX7gbgmMxpAABcFLuKpvJ4G70g4qqXh3y1w3OXJtjsoMycy+s6JE2nRv24KqgfN/aO677sieaUtaA== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230016)(4636009)(39860400002)(136003)(346002)(376002)(396003)(46966006)(36840700001)(40470700004)(40480700001)(26005)(36756003)(41300700001)(47076005)(83380400001)(426003)(2906002)(8936002)(82310400005)(44832011)(2616005)(1076003)(186003)(7696005)(336012)(30864003)(5660300002)(86362001)(8676002)(36860700001)(4326008)(966005)(6916009)(316002)(478600001)(40460700003)(54906003)(82740400003)(70206006)(70586007)(81166007)(356005)(19627235002)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9724 Return-Path: Sami.Mujawar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 53f1b8cc-f179-457e-ea82-08da94c9b8ed X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O8ZWDnlPLbmshKo05ReR8Jnjy/6Gf7CjDoCXSYC9hKA9hjWPeWyQ2jD7E55tJdbBZq3W/D3tIijLkq5f2Sy033Oaji/eq0doHcoTaYpgGrKRjYvkWNUKX0VtTIn9ow8WFbqqgg6Q7kxYO+X+XnJb1x9BRRyteMYjN89Uzn32o5vf4ay2TwsSnj1m7XjWt/b5XpJ+b7KDsh+CACQzRHsnQYm721tBUcWM+O7Fj402dQ5YfWSbRh+IyKFkfNod1vvGRFDvL/bnskoLe9K6/DnkSg14NAwvhAVutxNqcOc1eOdBUplHI2lcJyXShcierjJUJggO+RSLdrSDgQU/r6rfvwH1OhcgUEg1Clv5bLXmZcxUc4AghNOeI14p+G71NDZJtuMsVu1iWEqBiIrlwrFNnS3EVZCmhstD6rvpp1Diy+D9bLA4oGXfORI8yHDmguLFPm4fmMfPIQa/C+INTHxZBxooY0OkKVKi1RD7BclSaRdt3BexR/OlP9oKOQeKXV+RwvPaT8DbEmDk9aP7sdCY5xG8b89U93RsieNIpd7rlt2b0hj44q6n9NvcQOfrp286bceXfWbDJwz+Y9x6105G8D3D9ZmaZwsGi59q8vjz937iZNojWbFsFrHm+k8ciiswVIEktdT3eRX4PehSCSsgXcHYbSyhz0/njj6xzj+1uCypTDbSsuBQbVexUUKsoDsgxeHlIy45m2PmlToqtgTCLmFAnJsp6PFOAZWvtIc2bowoLgw10N+cu2/d3fY5otiNyLvqtbJjnVACU7hcRjNx3DeI/HNPvV6D2ZThFOrGqos= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230016)(4636009)(376002)(396003)(39860400002)(136003)(346002)(36840700001)(46966006)(40470700004)(70586007)(8676002)(966005)(70206006)(44832011)(4326008)(30864003)(41300700001)(478600001)(5660300002)(36860700001)(86362001)(36756003)(82310400005)(8936002)(54906003)(6916009)(336012)(47076005)(26005)(316002)(186003)(19627235002)(1076003)(7696005)(2616005)(426003)(82740400003)(81166007)(40460700003)(83380400001)(40480700001)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2022 14:19:06.6721 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aaf55fd4-27b9-46d6-1c66-08da94c9c098 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT031.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB5961 Content-Type: text/plain 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'; + 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)'