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 B396B9417A1 for ; Thu, 4 Apr 2024 13:34:07 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=0rIwq+f5e5FDRS0FUbh5AJaDwdRCgAcuV6JgnxgUGR0=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language: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-Language:Content-Type:Content-Transfer-Encoding; s=20240206; t=1712237646; v=1; b=vpI1jdMkMpLIXrevWr+btxvaO0RklTi6+YZvW8dJB21mn1Vbp1gcKPTPJ5WUTQlLh5ordavp E9sWIsOKGhiPYcjLIAMg/rscDR3NSCDZz7kZrHz1H3N/6aUCNKc+1crPi+X/lywrrBwSQdDEY+2 hiSsQCTUs6c6myfplSxo47QbYboaiv2qRc+p/gxX3c5w48YkSH1ixHlqsdgok2l/lJhwvbkxF++ tNjwYf1fNS1I56tpZ4TuIZoOUc/NEPSe9LsH/0JoTnJC1NBOwF9mXPdZyzL8emDwBs0SB8Dy18c hzBJ9kEwi9PfiPLiT9YnIPWmYumix1+6JdTxz2ZFFwyRg== X-Received: by 127.0.0.2 with SMTP id DS88YY7687511x9IeE59fgbE; Thu, 04 Apr 2024 06:34:06 -0700 X-Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.99]) by mx.groups.io with SMTP id smtpd.web10.38197.1712237645246598447 for ; Thu, 04 Apr 2024 06:34:05 -0700 X-Received: from BLAPR10MB5185.namprd10.prod.outlook.com (2603:10b6:208:328::16) by SJ0PR10MB5552.namprd10.prod.outlook.com (2603:10b6:a03:3da::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Thu, 4 Apr 2024 13:34:01 +0000 X-Received: from BLAPR10MB5185.namprd10.prod.outlook.com ([fe80::a03f:4d36:9713:33d0]) by BLAPR10MB5185.namprd10.prod.outlook.com ([fe80::a03f:4d36:9713:33d0%5]) with mapi id 15.20.7409.042; Thu, 4 Apr 2024 13:34:01 +0000 From: "Igor Kulchytskyy via groups.io" To: "abner.chang@amd.com" , "devel@edk2.groups.io" CC: Nickle Wang Subject: Re: [edk2-devel] [PATCH V3 1/6] RedfishPkg/RedfishPlatformConfigDxe: Config language searching optimization Thread-Topic: [EXTERNAL] [PATCH V3 1/6] RedfishPkg/RedfishPlatformConfigDxe: Config language searching optimization Thread-Index: AQHahnlzcEewSlt4Q0aqb/OAXhzhHbFYHIkQ Date: Thu, 4 Apr 2024 13:34:01 +0000 Message-ID: References: <20240404101758.84-1-abner.chang@amd.com> <20240404101758.84-2-abner.chang@amd.com> In-Reply-To: <20240404101758.84-2-abner.chang@amd.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BLAPR10MB5185:EE_|SJ0PR10MB5552:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: KcPVyt12dx5j1Qk9tSQuDGjmGnPNw8VL4xFTFovnVFbj/Seuc8vRKRxOUSDzqEpI4zvpHbcCq4E+Tt6qetS5iMtKuHdal/Ane5IpJBvMs9NhUnPH/3fbID9TZIxe/+Dze0l8BzE/wxX7dyKey72KN78nuf2u5WjyrtnoNyaKgaKL7qxqCYEIezC7ipz7JbaTdFB/Hrmq5S8dql7XZnFWhVe62ENdxQ//H+F5GJe7bIl8x+IBjvd4vNGMostl/5WduaOnJIr80Vh3GKgtkmMxYOGeMB4YaGftsNQTpptb4yr4mE2a05GJqT5kZjfHzhpQtQdKiJQvZ03NvvUdCIzmbWZatiDxRjVRqHDEPe9cV5oLa0UwZu4gZ0UGldkJTOcXSp3NwDnpwXmI3RWjm2AjDw0QDCX9Q01E4+7jIGk9LXNNHjd9/3KNSEqnimU/E4wxE4Va9I6TUCnXLDGUqpZXJyrL6QtuCn8YqAOY8BxCHg9fjzbRLLukEawzgRALwojmz77da74+KCzmeeuPBtvvoPNDygfpno1ccFc0wGfvrJ/6CMAm3TTns53Qw2zHqrqD4Ez9Nw+y6O4jDSwY9PZXnkbyi7++Ie8u6Z+i+CwPKpvJa0LkBYgpzBvqCp0qmDlXHrfwVIclZbeXzczBh7uphu9BrXJnQ08d2nB4KjBWfVs= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?DS+Ce5aXAi29FJz6GifYaUfK/exDCcDPSMkYh/rRJ1qNf1mBeDZouEkVBr+k?= =?us-ascii?Q?kwSk9GLF5UKVPPEXQ6qFeKVbPawzoSQ5ig5E4CFoOtfP2pQQYuznuyWitWZ8?= =?us-ascii?Q?XW/ZGDX68BkmbLQBEXLVHPVjZkrfO8gBkvoWeD7muo8OGR0eVtMLC0C5JJ/y?= =?us-ascii?Q?2RtjRrqKGz5BtahtuUQEIP6or/xi8IfYqtqNBL489GyUAKW80XqpUXSboeFO?= =?us-ascii?Q?k7YVvq9RCERWl77w6D27Jh7SyxB9YFWjHeTv8E82yFokP6RPtUC8Tyi9tZMN?= =?us-ascii?Q?nShLbWiewPGqp1gb4oATzsbqK6K+iJUIe1WRuFibDKe+KPiAzJ5pWBJ7EoTF?= =?us-ascii?Q?Tjk6xspc3LW6hMg70Li0KE9Ln2zIMBjijWB2UsSVBsKlnZiq636CGM/e6eg7?= =?us-ascii?Q?/+CZJKIsdhtXHQkbv3dfoduohfkHKZhcqx3KwLa1tBcqoutmBr3N+41BO8Gv?= =?us-ascii?Q?mCy7QOJtvkM9YFojPSa08akfnpE91jk24micA7GQODstBRbNa+7tg3F5iUD3?= =?us-ascii?Q?FXDX0k2zq7krAcv2bL4bK5LTBtGJrfqNhaxQZIn0F1+e+m7lzQeZ96KCmYA6?= =?us-ascii?Q?qUTmUjAqKKxQOdwAXpsSic0xlg6eRv7eTucsmr+2ZOMMZ9YgwfZfobPVfXxU?= =?us-ascii?Q?4pS+mvgQk3XetSom3bCA1YsqzBJf4GOR4GNnySYrHeO6ylqUIH0345ugTAEt?= =?us-ascii?Q?FylT+R5dVlNS5xc83ngsAAVLYEmwQY4wNFL/XtJjLvax3Xsc6T4aZc66FUEC?= =?us-ascii?Q?GV2bZ1SKukitXJ4l+b5mUEDpAyNgNvGgoLTkbeZ6faegd5nZTIFUwJzILE78?= =?us-ascii?Q?AZkTWUJ9PPYWZKU2EmxV7WWkdoF9tVjFeAA5IsLJFN+GAc1iTCmRQ85TVWI8?= =?us-ascii?Q?Jsh8PRyKn2SNpYAvitTz7h0K1NFFkpjw9yDqgAAyN5vyaHWolLpUQOrbOsUJ?= =?us-ascii?Q?Ucq3TuBVdVeurRxRe0G/syuucEST5Ttm1K/6pRUnBC7q62z9D9ytohKNDXrm?= =?us-ascii?Q?joklvUovUOC/sx80njXQ7UhFMdl1HOIl9OZP2G0vhiYSTOHZox3eKgUaBjmC?= =?us-ascii?Q?rJlxSrss3wxtr22u5fO49NxVJbSw7cPgcI1CYZzMiveWcFBJR0L0Yuha/wE7?= =?us-ascii?Q?bBLBnMrYLNg7NWv4bgTIaW9zbnpEpbfAU0U08l6ThAbuzqxv6+jSj203ebe+?= =?us-ascii?Q?Il+h0k23PTztsiniDav2SkH21fyO4MuRnh2MY0tbYEwY2HC/JTA6GoiI2vw+?= =?us-ascii?Q?72kmgUMJjjC6ZLGR8BZArptHK3Mks3yx4yYWe98C5AVb0R6YetAQ40LWPnyw?= =?us-ascii?Q?1ZvXeIfEd3f0dNrM6GUbiEPLUWAxiVqyeGXSsnunI7jQsriT8+hZE0W+1XBm?= =?us-ascii?Q?9pn+CnddXUVxniuxLe0sFlTCut6vNZjfuMCTp5NxQpftTQBBx4hr4jy+UbuY?= =?us-ascii?Q?yFg8OPiTwSRNk3IxukIywMAcbhXYO/eAIih33kM070nI8ug+heJKemEMm10u?= =?us-ascii?Q?HRNNnQxCC0kbAkmHvuQ66SDc8UdQQ5lmsqSIe4QFIEZ0mjpLzMU7W6yq57Og?= =?us-ascii?Q?UdppMyNKRRYQQvmzjqQ=3D?= MIME-Version: 1.0 X-OriginatorOrg: ami.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BLAPR10MB5185.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1857b562-aac9-484a-4ebe-08dc54abe3cd X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Apr 2024 13:34:01.7650 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 27e97857-e15f-486c-b58e-86c2b3040f93 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tDnjQdIdL1TDTJ5PuAlSV+MbVANqllIs5Qy1aH9bhGhVEDSoUWZE3XoECiUKjOtv X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5552 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: Thu, 04 Apr 2024 06:34:05 -0700 Resent-From: igork@ami.com Reply-To: devel@edk2.groups.io,igork@ami.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 6TBTbM6iCMUfnq4m6B3XOb0Cx7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=vpI1jdMk; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Reviewed-by: Igor Kulchytskyy Regards, Igor -----Original Message----- From: abner.chang@amd.com Sent: Thursday, April 4, 2024 6:18 AM To: devel@edk2.groups.io Cc: Nickle Wang ; Igor Kulchytskyy Subject: [EXTERNAL] [PATCH V3 1/6] RedfishPkg/RedfishPlatformConfigDxe: Con= fig language searching optimization **CAUTION: The e-mail below is from an external source. Please exercise cau= tion before opening attachments, clicking links, or following guidance.** From: abnchang Build up the x-uefi-redfish string database for the Redfish confg language searching, instead of using HII String protocol. This can improve the time consumption lot on searching strings. Signed-off-by: Abner Chang Co-authored-by: Nickle Wang Cc: Igor Kulchytskyy Reviewed-by: Nickle Wang --- .../RedfishPlatformConfigImpl.h | 107 ++- .../RedfishPlatformConfigDxe.c | 23 +- .../RedfishPlatformConfigImpl.c | 819 +++++++++++++++++- 3 files changed, 877 insertions(+), 72 deletions(-) diff --git a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.= h b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.h index 9f4312decf5..8b8c544d58e 100644 --- a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.h +++ b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.h @@ -2,7 +2,8 @@ This file defines the EDKII Redfish Platform Config Protocol private str= ucture. (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
- Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -30,6 +31,10 @@ #define ENGLISH_LANGUAGE_CODE "en-US" #define X_UEFI_SCHEMA_PREFIX "x-uefi-redfish-" +#define MAX_X_UEFI_REDFISH_STRING_SIZE (128 * 2)// 128 character in UCS. + +typedef struct _REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE REDFISH_PLATFORM= _CONFIG_STATEMENT_PRIVATE; + // // Definition of REDFISH_PLATFORM_CONFIG_PRIVATE. // @@ -46,17 +51,49 @@ typedef struct { CHAR8 **SchemaList; // Schema list } REDFISH_PLATFORM_CONFIG_SCHEMA; +// Defines the number of elements in array +#define X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER 1024 + +// +// Definition of x-uefi-redfish string element. +// +typedef struct { + EFI_STRING_ID StringId; + CHAR16 *UcsString; +} REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT; + +// +// Discrete string array buffer, each has X_UEFI_REDFISH_STRING_ARRAY_NUMB= ER element. +// +typedef struct { + LIST_ENTRY NextArray; + REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT *ArrayEntryAddress; +} REDFISH_X_UEFI_STRINGS_ARRAY; + +// +// x-uefi-redfish string database, x-uefi-redfish language based. +// +typedef struct { + LIST_ENTRY NextXuefiRedfishLanguage; = // Link to the next suppoted x-uefi-Redfish language. + CHAR8 *XuefiRedfishLanguage; = // x-uefi-redfish language. + UINTN StringsArrayBlocks; = // Number of the array blocks that accommodate X_UEFI_REDFISH_STRING_AR= RAY_NUMBER + = // elements in each. + LIST_ENTRY XuefiRedfishStringArrays; = // Link entry of x-uefi-redfish string array. +} REDFISH_X_UEFI_STRING_DATABASE; + // // Definition of REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE // typedef struct { LIST_ENTRY Link; - HII_FORMSET *HiiFormSet; // Pointer to HII for= mset data. - EFI_GUID Guid; // Formset GUID. - EFI_HII_HANDLE HiiHandle; // Hii Handle of this= formset. - LIST_ENTRY HiiFormList; // Form list that kee= p form data under this formset. - CHAR16 *DevicePathStr; // Device path of thi= s formset. - REDFISH_PLATFORM_CONFIG_SCHEMA SupportedSchema; // Schema that is sup= ported in this formset. + HII_FORMSET *HiiFormSet; // Pointer= to HII formset data. + EFI_GUID Guid; // Formset= GUID. + EFI_HII_HANDLE HiiHandle; // Hii Han= dle of this formset. + EFI_HII_PACKAGE_LIST_HEADER *HiiPackageListHeader; // Hii Pac= kage list header. + LIST_ENTRY HiiFormList; // Form li= st that keep form data under this formset. + CHAR16 *DevicePathStr; // Device = path of this formset. + REDFISH_PLATFORM_CONFIG_SCHEMA SupportedSchema; // Schema = that is supported in this formset. + LIST_ENTRY XuefiRedfishStringDatabase; // x-uefi-= redfish string/Id data base; } REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE; #define REDFISH_PLATFORM_CONFIG_FORMSET_FROM_LINK(a) BASE_CR (a, REDFISH_= PLATFORM_CONFIG_FORM_SET_PRIVATE, Link) @@ -90,19 +127,19 @@ typedef struct { // // Definition of REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE // -typedef struct { +struct _REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE { LIST_ENTRY Link; REDFISH_PLATFORM_CONFIG_FORM_PRIVATE *ParentForm; - HII_STATEMENT *HiiStatement; // Pointer to = HII statement data. - EFI_QUESTION_ID QuestionId; // Question ID= of this statement. - EFI_STRING_ID Description; // String toke= n of this question. - EFI_STRING_ID Help; // String toke= n of help message. - EFI_STRING DesStringCache; // The string = cache for search function. - UINT8 Flags; // The stateme= nt flag. - REDFISH_PLATFORM_CONFIG_STATEMENT_DATA StatementData; // The max/min= for statement value. - BOOLEAN Suppressed; // Statement i= s suppressed. - BOOLEAN GrayedOut; // Statement i= s GrayedOut. -} REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE; + HII_STATEMENT *HiiStatement; // Pointer = to HII statement data. + EFI_QUESTION_ID QuestionId; // Question= ID of this statement. + EFI_STRING_ID Description; // String t= oken of this question. + CHAR16 *XuefiRedfishStr; // x-uefi-r= edfish string of this question. + EFI_STRING_ID Help; // String t= oken of help message. + UINT8 Flags; // The stat= ement flag. + REDFISH_PLATFORM_CONFIG_STATEMENT_DATA StatementData; // The max/= min for statement value. + BOOLEAN Suppressed; // Statemen= t is suppressed. + BOOLEAN GrayedOut; // Statemen= t is GrayedOut. +}; #define REDFISH_PLATFORM_CONFIG_STATEMENT_FROM_LINK(a) BASE_CR (a, REDFIS= H_PLATFORM_CONFIG_STATEMENT_PRIVATE, Link) @@ -347,4 +384,38 @@ ReleaseStatementList ( IN REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE_LIST *StatementList ); +/** + Return the HII string length. We don't check word alignment + of the input string as the same as the checking in StrLen + function. Because the HII string in the database is compact + at the byte alignment. + + @param[in] String Input UCS format string. + + @retval Length of + +**/ +UINTN +EFIAPI +HiiStrLen ( + IN CONST CHAR16 *String + ); + +/** + Return the HII string size. We don't check word alignment + of the input string as the same as the checking in StrLen + function. Because the HII string in the database is compact + at the byte alignment. + + @param[in] String Input UCS format string. + + @retval Size of the string. + +**/ +UINTN +EFIAPI +HiiStrSize ( + IN CONST CHAR16 *String + ); + #endif diff --git a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c= b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c index f970e317b3f..0d1c96e7125 100644 --- a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c +++ b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c @@ -2,7 +2,8 @@ The implementation of EDKII Redfish Platform Config Protocol. (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
- Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -928,6 +929,10 @@ HiiStringToOneOfOptionValue ( Option =3D HII_QUESTION_OPTION_FROM_LINK (Link); TmpString =3D HiiGetRedfishString (Statement->ParentForm->ParentFormse= t->HiiHandle, Schema, Option->Text); + if (TmpString =3D=3D NULL) { + TmpString =3D HiiGetRedfishString (Statement->ParentForm->ParentForm= set->HiiHandle, ENGLISH_LANGUAGE_CODE, Option->Text); + } + if (TmpString !=3D NULL) { if (StrCmp (TmpString, HiiString) =3D=3D 0) { CopyMem (Value, &Option->Value, sizeof (HII_STATEMENT_VALUE)); @@ -1227,6 +1232,10 @@ HiiStringToOrderedListOptionValue ( Option =3D HII_QUESTION_OPTION_FROM_LINK (Link); TmpString =3D HiiGetRedfishString (Statement->ParentForm->ParentFormse= t->HiiHandle, Schema, Option->Text); + if (TmpString =3D=3D NULL) { + TmpString =3D HiiGetRedfishString (Statement->ParentForm->ParentForm= set->HiiHandle, ENGLISH_LANGUAGE_CODE, Option->Text); + } + if (TmpString !=3D NULL) { if (StrCmp (TmpString, HiiString) =3D=3D 0) { *Value =3D ExtendHiiValueToU64 (&Option->Value); @@ -1491,7 +1500,7 @@ StrToAsciiStr ( return NULL; } - StringLen =3D StrLen (UnicodeString) + 1; + StringLen =3D HiiStrLen (UnicodeString) + 1; Buffer =3D AllocatePool (StringLen * sizeof (CHAR8)); if (Buffer =3D=3D NULL) { return NULL; @@ -2000,7 +2009,6 @@ RedfishPlatformConfigProtocolGetConfigureLang ( REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE_LIST StatementList; REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE_REF *StatementRef; LIST_ENTRY *NextLink; - EFI_STRING TmpString; EFI_STRING *TmpConfigureLangList; UINTN Index; CHAR8 *FullSchema; @@ -2054,12 +2062,9 @@ RedfishPlatformConfigProtocolGetConfigureLang ( ASSERT (StatementRef->Statement->Description !=3D 0); if (StatementRef->Statement->Description !=3D 0) { - TmpString =3D HiiGetRedfishString (StatementRef->Statement->Parent= Form->ParentFormset->HiiHandle, FullSchema, StatementRef->Statement->Descri= ption); - ASSERT (TmpString !=3D NULL); - if (TmpString !=3D NULL) { - TmpConfigureLangList[Index] =3D TmpString; - ++Index; - } + ASSERT (StatementRef->Statement->XuefiRedfishStr !=3D NULL); + TmpConfigureLangList[Index] =3D AllocateCopyPool (HiiStrSize (Stat= ementRef->Statement->XuefiRedfishStr), (VOID *)StatementRef->Statement->Xue= fiRedfishStr); + ++Index; } } } diff --git a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.= c b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.c index 47d35abc088..36e5da24f0a 100644 --- a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.c +++ b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.c @@ -3,6 +3,7 @@ (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights res= erved. + Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -143,6 +144,88 @@ DumpFormsetList ( return EFI_SUCCESS; } +/** + Return the HII string length. We don't check word alignment + of the input string as same as the checking in StrLen + function, because the HII string in the database is compact + at the byte alignment. + + @param[in] String Input UCS format string. + + @retval Length of the string. + +**/ +UINTN +EFIAPI +HiiStrLen ( + IN CONST CHAR16 *String + ) +{ + UINTN Length; + + ASSERT (String !=3D NULL); + + for (Length =3D 0; *String !=3D L'\0'; String++, Length++) { + } + + return Length; +} + +/** + Return the HII string size. We don't check word alignment + of the input string as same as the checking in StrLen + function, because the HII string in the database is compact + at the byte alignment. + + @param[in] String Input UCS format string. + + @retval Size of the string. + +**/ +UINTN +EFIAPI +HiiStrSize ( + IN CONST CHAR16 *String + ) +{ + return (HiiStrLen (String) + 1) * sizeof (*String); +} + +/** + Compare two HII strings. We don't check word alignment + of the input string as same as the checking in StrLen + function, because the HII string in the database is compact + at the byte alignment. + + @param[in] FirstString Input UCS format of string to search. + @param[in] SecondString Input UCS format of string to look for in + FirstString; + + @retval 0 The strings are identical. + !0 The strings are not identical. + +**/ +INTN +EFIAPI +HiiStrCmp ( + IN CONST CHAR16 *FirstString, + IN CONST CHAR16 *SecondString + ) +{ + // + // ASSERT both strings are less long than PcdMaximumUnicodeStringLength + // + ASSERT (HiiStrSize (FirstString) !=3D 0); + ASSERT (HiiStrSize (SecondString) !=3D 0); + + while ((*FirstString !=3D L'\0') && (*FirstString =3D=3D *SecondString))= { + FirstString++; + SecondString++; + } + + return *FirstString - *SecondString; +} + /** Delete a string from HII Package List by given HiiHandle. @@ -301,28 +384,6 @@ HiiGetRedfishAsciiString ( return AsciiString; } -/** - Get string from HII database in English language. The returned string is= allocated - using AllocatePool(). The caller is responsible for freeing the allocate= d buffer using - FreePool(). - - @param[in] HiiHandle A handle that was previously registered in= the HII Database. - @param[in] StringId The identifier of the string to retrieved = from the string - package associated with HiiHandle. - - @retval NULL The string specified by StringId is not present in the st= ring package. - @retval Other The string was returned. - -**/ -EFI_STRING -HiiGetEnglishString ( - IN EFI_HII_HANDLE HiiHandle, - IN EFI_STRING_ID StringId - ) -{ - return HiiGetRedfishString (HiiHandle, ENGLISH_LANGUAGE_CODE, StringId); -} - /** Get ASCII string from HII database in English language. The returned str= ing is allocated using AllocatePool(). The caller is responsible for freeing the allocate= d buffer using @@ -562,7 +623,7 @@ GetStatementPrivateByConfigureLangRegex ( HiiStatementPrivate =3D REDFISH_PLATFORM_CONFIG_STATEMENT_FROM_LI= NK (HiiStatementLink); if ((HiiStatementPrivate->Description !=3D 0) && !HiiStatementPriv= ate->Suppressed) { - TmpString =3D HiiGetRedfishString (HiiFormsetPrivate->HiiHandle,= Schema, HiiStatementPrivate->Description); + TmpString =3D HiiStatementPrivate->XuefiRedfishStr; if (TmpString !=3D NULL) { Status =3D RegularExpressionProtocol->MatchString ( RegularExpressionProtoco= l, @@ -592,8 +653,9 @@ GetStatementPrivateByConfigureLangRegex ( InsertTailList (&StatementList->StatementList, &StatementRef= ->Link); ++StatementList->Count; } - - FreePool (TmpString); + } else { + DEBUG ((DEBUG_ERROR, "%a: HiiStatementPrivate->XuefiRedfishStr= is NULL, x-uefi-string has something wrong.\n", __func__)); + ASSERT (FALSE); } } @@ -676,14 +738,11 @@ GetStatementPrivateByConfigureLang ( ); if (HiiStatementPrivate->Description !=3D 0) { - TmpString =3D HiiGetRedfishString (HiiFormsetPrivate->HiiHandle,= Schema, HiiStatementPrivate->Description); + TmpString =3D HiiStatementPrivate->XuefiRedfishStr; if (TmpString !=3D NULL) { - if (StrCmp (TmpString, ConfigureLang) =3D=3D 0) { - FreePool (TmpString); + if (HiiStrCmp (TmpString, ConfigureLang) =3D=3D 0) { return HiiStatementPrivate; } - - FreePool (TmpString); } } @@ -741,10 +800,74 @@ GetFormsetPrivateByHiiHandle ( return NULL; } +/** + Release x-uefi-string related information. + + @param[in] FormsetPrivate Pointer to HII form-set private instance. + + @retval EFI_STATUS + +**/ +EFI_STATUS +ReleaseXuefiStringDatabase ( + IN REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE *FormsetPrivate + ) +{ + REDFISH_X_UEFI_STRING_DATABASE *ThisDatabase; + REDFISH_X_UEFI_STRING_DATABASE *PreDatabase; + REDFISH_X_UEFI_STRINGS_ARRAY *ThisStringArray; + REDFISH_X_UEFI_STRINGS_ARRAY *PreStringArray; + BOOLEAN EndDatabase; + BOOLEAN EndArray; + + if (FormsetPrivate->HiiPackageListHeader !=3D NULL) { + FreePool (FormsetPrivate->HiiPackageListHeader); + } + + // Walk through x-uefi-redfish string database. + if (!IsListEmpty (&FormsetPrivate->XuefiRedfishStringDatabase)) { + EndDatabase =3D FALSE; + ThisDatabase =3D (REDFISH_X_UEFI_STRING_DATABASE *)GetFirstNode (&Form= setPrivate->XuefiRedfishStringDatabase); + while (!EndDatabase) { + // Walk through string arrays. + if (!IsListEmpty (&ThisDatabase->XuefiRedfishStringArrays)) { + EndArray =3D FALSE; + ThisStringArray =3D (REDFISH_X_UEFI_STRINGS_ARRAY *)GetFirstNode (= &ThisDatabase->XuefiRedfishStringArrays); + while (!EndArray) { + // Remove this array + FreePool (ThisStringArray->ArrayEntryAddress); + EndArray =3D IsNodeAtEnd (&ThisDatabase->XuefiRedfishStrin= gArrays, &ThisStringArray->NextArray); + PreStringArray =3D ThisStringArray; + if (!EndArray) { + ThisStringArray =3D (REDFISH_X_UEFI_STRINGS_ARRAY *)GetNextNod= e (&ThisDatabase->XuefiRedfishStringArrays, &ThisStringArray->NextArray); + } + + RemoveEntryList (&PreStringArray->NextArray); + FreePool (PreStringArray); + } + } + + // + // Remove this database + // + EndDatabase =3D IsNodeAtEnd (&FormsetPrivate->XuefiRedfishStringData= base, &ThisDatabase->NextXuefiRedfishLanguage); + PreDatabase =3D ThisDatabase; + if (!EndDatabase) { + ThisDatabase =3D (REDFISH_X_UEFI_STRING_DATABASE *)GetNextNode (&F= ormsetPrivate->XuefiRedfishStringDatabase, &ThisDatabase->NextXuefiRedfishL= anguage); + } + + RemoveEntryList (&PreDatabase->NextXuefiRedfishLanguage); + FreePool (PreDatabase); + } + } + + return EFI_SUCCESS; +} + /** Release formset and all the forms and statements that belong to this for= mset. - @param[in] FormsetPrivate Pointer to HP_HII_FORM_SET_PRIVATE + @param[in] FormsetPrivate Pointer to HII form-set private instance. @retval EFI_STATUS @@ -779,12 +902,6 @@ ReleaseFormset ( // // HiiStatementPrivate->HiiStatement will be released in DestroyForm= Set(). // - - if (HiiStatementPrivate->DesStringCache !=3D NULL) { - FreePool (HiiStatementPrivate->DesStringCache); - HiiStatementPrivate->DesStringCache =3D NULL; - } - RemoveEntryList (&HiiStatementPrivate->Link); FreePool (HiiStatementPrivate); HiiStatementLink =3D HiiNextStatementLink; @@ -821,6 +938,8 @@ ReleaseFormset ( FormsetPrivate->SupportedSchema.Count =3D 0; } + ReleaseXuefiStringDatabase (FormsetPrivate); + return EFI_SUCCESS; } @@ -846,17 +965,606 @@ NewFormsetPrivate ( // Initial newly created formset private data. // InitializeListHead (&NewFormsetPrivate->HiiFormList); + InitializeListHead (&NewFormsetPrivate->XuefiRedfishStringDatabase); return NewFormsetPrivate; } +/** + Create new x-uefi-redfish string array. + + @param[in] XuefiRedfishStringDatabase The x-uefi-redfish string da= tabase. + + @retval EFI_OUT_OF_RESOURCES Not enough memory for creating a n= ew array. + EFI_SUCCESS New array is created successfully. + +**/ +EFI_STATUS +NewRedfishXuefiStringArray ( + IN REDFISH_X_UEFI_STRING_DATABASE *XuefiRedfishStringDatabase + ) +{ + REDFISH_X_UEFI_STRINGS_ARRAY *ArrayAddress; + + // Initial first REDFISH_X_UEFI_STRINGS_ARRAY memory. + ArrayAddress =3D (REDFISH_X_UEFI_STRINGS_ARRAY *)AllocateZeroPool (sizeo= f (REDFISH_X_UEFI_STRINGS_ARRAY)); + if (ArrayAddress =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate REDFISH_X_UEFI_STRINGS_AR= RAY.\n", __func__)); + return EFI_OUT_OF_RESOURCES; + } + + InitializeListHead (&ArrayAddress->NextArray); + + // Allocate memory buffer for REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT eleme= nts. + ArrayAddress->ArrayEntryAddress =3D \ + (REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT *)AllocateZeroPool (sizeof (REDF= ISH_X_UEFI_STRINGS_ARRAY_ELEMENT) * X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBE= R); + if (ArrayAddress->ArrayEntryAddress =3D=3D NULL) { + FreePool (ArrayAddress); + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate array for REDFISH_X_UEFI_= STRINGS_ARRAY_ELEMENTs.\n", __func__)); + return EFI_OUT_OF_RESOURCES; + } + + XuefiRedfishStringDatabase->StringsArrayBlocks++; + InsertTailList (&XuefiRedfishStringDatabase->XuefiRedfishStringArrays, &= ArrayAddress->NextArray); + return EFI_SUCCESS; +} + +/** + Get the pointer of x-uefi-redfish database or create a new database. + + @param[in] FormsetPrivate Pointer to HII form-set private = instance. + @param[in] HiiStringPackageHeader HII string package header. + + @retval Pointer to REDFISH_X_UEFI_STRING_DATABASE. + If NULL, it fails to obtain x-uefi-redfish database. + +**/ +REDFISH_X_UEFI_STRING_DATABASE * +GetExitOrCreateXuefiStringDatabase ( + IN REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE *FormsetPrivate, + IN EFI_HII_STRING_PACKAGE_HDR *HiiStringPackageHeader + ) +{ + EFI_STATUS Status; + BOOLEAN CreateNewOne; + REDFISH_X_UEFI_STRING_DATABASE *XuefiRedfishStringDatabase; + + DEBUG ((DEBUG_INFO, "%a: Entry\n", __func__)); + + CreateNewOne =3D TRUE; + XuefiRedfishStringDatabase =3D NULL; + if (!IsListEmpty (&FormsetPrivate->XuefiRedfishStringDatabase)) { + XuefiRedfishStringDatabase =3D (REDFISH_X_UEFI_STRING_DATABASE *)GetFi= rstNode (&FormsetPrivate->XuefiRedfishStringDatabase); + + while (TRUE) { + if (AsciiStriCmp (XuefiRedfishStringDatabase->XuefiRedfishLanguage, = HiiStringPackageHeader->Language) =3D=3D 0) { + CreateNewOne =3D FALSE; + break; + } + + if (IsNodeAtEnd (&FormsetPrivate->XuefiRedfishStringDatabase, &Xuefi= RedfishStringDatabase->NextXuefiRedfishLanguage)) { + break; + } + + XuefiRedfishStringDatabase =3D \ + (REDFISH_X_UEFI_STRING_DATABASE *)GetNextNode (&FormsetPrivate->Xu= efiRedfishStringDatabase, &XuefiRedfishStringDatabase->NextXuefiRedfishLang= uage); + } + } + + if (CreateNewOne) { + DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, " Creating x-uefi-redfish (%a)= string database...\n", HiiStringPackageHeader->Language)); + XuefiRedfishStringDatabase =3D (REDFISH_X_UEFI_STRING_DATABASE *)Alloc= ateZeroPool (sizeof (REDFISH_X_UEFI_STRING_DATABASE)); + if (XuefiRedfishStringDatabase =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, " Failed to allocate REDFISH_X_UEFI_STRING_DAT= ABASE.\n")); + return NULL; + } + + InitializeListHead (&XuefiRedfishStringDatabase->NextXuefiRedfishLangu= age); + InitializeListHead (&XuefiRedfishStringDatabase->XuefiRedfishStringArr= ays); + XuefiRedfishStringDatabase->StringsArrayBlocks =3D 0; + XuefiRedfishStringDatabase->XuefiRedfishLanguage =3D HiiStringPackageH= eader->Language; + + Status =3D NewRedfishXuefiStringArray (XuefiRedfishStringDatabase); + if (EFI_ERROR (Status)) { + FreePool (XuefiRedfishStringDatabase); + return NULL; + } + + DEBUG (( + REDFISH_PLATFORM_CONFIG_DEBUG, + " x-uefi-redfish (%a):\n String array is added to XuefiRedfishSt= ringDatabase, total %d arrays now.\n", + XuefiRedfishStringDatabase->XuefiRedfishLanguage, + XuefiRedfishStringDatabase->StringsArrayBlocks + )); + + // Link string database to FormsetPrivate. + InsertTailList (&FormsetPrivate->XuefiRedfishStringDatabase, &XuefiRed= fishStringDatabase->NextXuefiRedfishLanguage); + } + + return XuefiRedfishStringDatabase; +} + +/** + Check and allocate a new x-uefi-redfish array if it is insufficient for = the + newly added x-uefi-redfish string. + + @param[in] FormsetPrivate Pointer to HII form-set priv= ate instance. + @param[in] XuefiRedfishStringDatabase Pointer to the x-uefi-redfis= h database. + @param[in] StringId String ID added to database. + + @retval EFI_SUCCESS The size of x-uefi-string ar= ray is adjusted or + is not required to be adjust= ed. + Otherwise, refer to the error code returned from NewRedf= ishXuefiStringArray(). + +**/ +EFI_STATUS +RedfishXuefiStringAdjustArrays ( + IN REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE *FormsetPrivate, + IN REDFISH_X_UEFI_STRING_DATABASE *XuefiRedfishStringDatabas= e, + IN EFI_STRING_ID StringId + ) +{ + EFI_STATUS Status; + + while (((StringId + X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER) / X_UEFI_R= EDFISH_STRING_ARRAY_ENTRY_NUMBER) > (UINT16)XuefiRedfishStringDatabase->Str= ingsArrayBlocks) { + Status =3D NewRedfishXuefiStringArray (XuefiRedfishStringDatabase); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to adjust x-uefi-string array", __f= unc__)); + return Status; + } + } + + return EFI_SUCCESS; +} + +/** + Insert a x-uefi-redfish string to database. + + @param[in] FormsetPrivate Pointer to HII form-set private = instance. + @param[in] HiiStringPackageHeader Pointer to HII string package. + @param[in] StringId The HII string ID + @param[in] StringTextPtr Pointer to HII string text. + + @retval EFI_SUCCESS The HII string is added to datab= ase. + EFI_LOAD_ERROR Something wrong when insert an H= II string + to database. + +**/ +EFI_STATUS +RedfishXuefiStringInsertDatabase ( + IN REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE *FormsetPrivate, + IN EFI_HII_STRING_PACKAGE_HDR *HiiStringPackageHeader, + IN EFI_STRING_ID StringId, + IN CHAR16 *StringTextPtr + ) +{ + EFI_STATUS Status; + UINTN StringIdOffset; + REDFISH_X_UEFI_STRING_DATABASE *XuefiRedfishStringDatabase; + REDFISH_X_UEFI_STRINGS_ARRAY *ThisArray; + + XuefiRedfishStringDatabase =3D GetExitOrCreateXuefiStringDatabase (Forms= etPrivate, HiiStringPackageHeader); + if (XuefiRedfishStringDatabase =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get REDFISH_X_UEFI_STRING_DATABASE= of x-uefi-redfish language %a.\n", __func__, HiiStringPackageHeader->Langu= age)); + ReleaseXuefiStringDatabase (FormsetPrivate); + return EFI_LOAD_ERROR; + } + + Status =3D RedfishXuefiStringAdjustArrays (FormsetPrivate, XuefiRedfishS= tringDatabase, StringId); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to adjust x-uefi-redfish string array= .\n", __func__)); + ReleaseXuefiStringDatabase (FormsetPrivate); + return EFI_LOAD_ERROR; + } + + // Insert string to x-uefi-redfish string array. + StringIdOffset =3D (UINTN)StringId; + ThisArray =3D (REDFISH_X_UEFI_STRINGS_ARRAY *)GetFirstNode (&XuefiR= edfishStringDatabase->XuefiRedfishStringArrays); + while (StringIdOffset >=3D X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER) { + ThisArray =3D (REDFISH_X_UEFI_STRINGS_ARRAY *)GetNextNode (&Xuef= iRedfishStringDatabase->XuefiRedfishStringArrays, &ThisArray->NextArray); + StringIdOffset -=3D X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER; + } + + // Insert string + (ThisArray->ArrayEntryAddress + StringIdOffset)->StringId =3D StringId; + (ThisArray->ArrayEntryAddress + StringIdOffset)->UcsString =3D StringTex= tPtr; + + DEBUG (( + REDFISH_PLATFORM_CONFIG_DEBUG, + " Insert string ID: (%d) to database\n x-uefi-string: \"%s\"\n = Language: %a.\n", + StringId, + StringTextPtr, + HiiStringPackageHeader->Language + )); + return EFI_SUCCESS; +} + +/** + Get x-uefi-redfish string and language by string ID. + + @param[in] FormsetPrivate Pointer to HII form-set private = instance. + @param[in] HiiStringPackageHeader HII string package header. + + @retval TRUE x-uefi-redfish string and ID map is inserted to database= . + FALSE Something is wrong when insert x-uefi-redfish string and= ID map. + +**/ +BOOLEAN +CreateXuefiLanguageStringIdMap ( + IN REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE *FormsetPrivate, + IN EFI_HII_STRING_PACKAGE_HDR *HiiStringPackageHeader + ) +{ + EFI_STATUS Status; + UINT8 *BlockHdr; + EFI_STRING_ID CurrentStringId; + UINTN BlockSize; + UINTN Index; + UINT8 *StringTextPtr; + UINTN Offset; + UINT16 StringCount; + UINT16 SkipCount; + UINT8 Length8; + EFI_HII_SIBT_EXT2_BLOCK Ext2; + UINT32 Length32; + UINT8 *StringBlockInfo; + + // + // Parse the string blocks to get the string text and font. + // + StringBlockInfo =3D (UINT8 *)((UINTN)HiiStringPackageHeader + HiiStringP= ackageHeader->StringInfoOffset); + BlockHdr =3D StringBlockInfo; + BlockSize =3D 0; + Offset =3D 0; + CurrentStringId =3D 1; + while (*BlockHdr !=3D EFI_HII_SIBT_END) { + switch (*BlockHdr) { + case EFI_HII_SIBT_STRING_SCSU: + Offset =3D sizeof (EFI_HII_STRING_BLOCK); + StringTextPtr =3D BlockHdr + Offset; + BlockSize +=3D Offset + AsciiStrSize ((CHAR8 *)StringTextPtr); + CurrentStringId++; + break; + + case EFI_HII_SIBT_STRING_SCSU_FONT: + Offset =3D sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK) - s= izeof (UINT8); + StringTextPtr =3D BlockHdr + Offset; + BlockSize +=3D Offset + AsciiStrSize ((CHAR8 *)StringTextPtr); + CurrentStringId++; + break; + + case EFI_HII_SIBT_STRINGS_SCSU: + CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), s= izeof (UINT16)); + StringTextPtr =3D (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT= _STRINGS_SCSU_BLOCK) - sizeof (UINT8)); + BlockSize +=3D StringTextPtr - BlockHdr; + + for (Index =3D 0; Index < StringCount; Index++) { + BlockSize +=3D AsciiStrSize ((CHAR8 *)StringTextPtr); + StringTextPtr =3D StringTextPtr + AsciiStrSize ((CHAR8 *)StringT= extPtr); + CurrentStringId++; + } + + break; + + case EFI_HII_SIBT_STRINGS_SCSU_FONT: + CopyMem ( + &StringCount, + (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + size= of (UINT8)), + sizeof (UINT16) + ); + StringTextPtr =3D (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT= _STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8)); + BlockSize +=3D StringTextPtr - BlockHdr; + + for (Index =3D 0; Index < StringCount; Index++) { + BlockSize +=3D AsciiStrSize ((CHAR8 *)StringTextPtr); + StringTextPtr =3D StringTextPtr + AsciiStrSize ((CHAR8 *)StringT= extPtr); + CurrentStringId++; + } + + break; + + case EFI_HII_SIBT_STRING_UCS2: + Offset =3D sizeof (EFI_HII_STRING_BLOCK); + StringTextPtr =3D BlockHdr + Offset; + + // x-uefi-redfish string is always encoded as UCS and started with= '/'. + if (*StringTextPtr =3D=3D (UINT16)'/') { + Status =3D RedfishXuefiStringInsertDatabase ( + FormsetPrivate, + HiiStringPackageHeader, + CurrentStringId, + (CHAR16 *)StringTextPtr + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to insert x-uefi-redfish stri= ng %s.\n", __func__, StringTextPtr)); + return FALSE; + } + } + + BlockSize +=3D (Offset + HiiStrSize ((CHAR16 *)StringTextPtr)); + CurrentStringId++; + break; + + case EFI_HII_SIBT_STRING_UCS2_FONT: + Offset =3D sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - = sizeof (CHAR16); + StringTextPtr =3D BlockHdr + Offset; + BlockSize +=3D (Offset + HiiStrSize ((CHAR16 *)StringTextPtr)); + CurrentStringId++; + break; + + case EFI_HII_SIBT_STRINGS_UCS2: + Offset =3D sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK) - sizeo= f (CHAR16); + StringTextPtr =3D BlockHdr + Offset; + BlockSize +=3D Offset; + CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), s= izeof (UINT16)); + for (Index =3D 0; Index < StringCount; Index++) { + BlockSize +=3D HiiStrSize ((CHAR16 *)StringTextPtr); + StringTextPtr =3D StringTextPtr + HiiStrSize ((CHAR16 *)StringTe= xtPtr); + CurrentStringId++; + } + + break; + + case EFI_HII_SIBT_STRINGS_UCS2_FONT: + Offset =3D sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK) - = sizeof (CHAR16); + StringTextPtr =3D BlockHdr + Offset; + BlockSize +=3D Offset; + CopyMem ( + &StringCount, + (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + size= of (UINT8)), + sizeof (UINT16) + ); + for (Index =3D 0; Index < StringCount; Index++) { + BlockSize +=3D HiiStrSize ((CHAR16 *)StringTextPtr); + StringTextPtr =3D StringTextPtr + HiiStrSize ((CHAR16 *)StringTe= xtPtr); + CurrentStringId++; + } + + break; + + case EFI_HII_SIBT_DUPLICATE: + BlockSize +=3D sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK); + CurrentStringId++; + break; + + case EFI_HII_SIBT_SKIP1: + SkipCount =3D (UINT16)(*(UINT8 *)((UINTN)BlockHdr + sizeof (= EFI_HII_STRING_BLOCK))); + CurrentStringId =3D (UINT16)(CurrentStringId + SkipCount); + BlockSize +=3D sizeof (EFI_HII_SIBT_SKIP1_BLOCK); + break; + + case EFI_HII_SIBT_SKIP2: + CopyMem (&SkipCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), siz= eof (UINT16)); + CurrentStringId =3D (UINT16)(CurrentStringId + SkipCount); + BlockSize +=3D sizeof (EFI_HII_SIBT_SKIP2_BLOCK); + break; + + case EFI_HII_SIBT_EXT1: + CopyMem ( + &Length8, + (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + size= of (UINT8)), + sizeof (UINT8) + ); + BlockSize +=3D Length8; + break; + + case EFI_HII_SIBT_EXT2: + CopyMem (&Ext2, BlockHdr, sizeof (EFI_HII_SIBT_EXT2_BLOCK)); + BlockSize +=3D Ext2.Length; + break; + + case EFI_HII_SIBT_EXT4: + CopyMem ( + &Length32, + (UINT8 *)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + size= of (UINT8)), + sizeof (UINT32) + ); + + BlockSize +=3D Length32; + break; + + default: + break; + } + + BlockHdr =3D (UINT8 *)(StringBlockInfo + BlockSize); + } + + return TRUE; +} + +/** + Get x-uefi-redfish string and language by string ID. + + @param[in] FormsetPrivate Pointer to HII form-set private ins= tance. + @param[in] StringId The HII string ID. + @param[out] String Optionally return USC string. + @param[out] Language Optionally return x-uefi-redfish la= nguage. + @param[out] XuefiStringDatabase Optionally return x-uefi-redfish da= tabase. + + @retval EFI_SUCCESS String information is returned. + EFI_INVALID_PARAMETER One of the given parameters to this func= tion is + invalid. + EFI_NOT_FOUND String is not found. + +**/ +EFI_STATUS +GetXuefiStringAndLangByStringId ( + IN REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE *FormsetPrivate, + IN EFI_STRING_ID StringId, + OUT CHAR16 **String OPTIONAL, + OUT CHAR8 **Language OPTIONAL, + OUT REDFISH_X_UEFI_STRING_DATABASE **XuefiStringDatabase OPT= IONAL + ) +{ + REDFISH_X_UEFI_STRING_DATABASE *XuefiRedfishStringDatabase; + REDFISH_X_UEFI_STRINGS_ARRAY *StringArray; + UINT16 StringIndex; + + if ((String =3D=3D NULL) && (Language =3D=3D NULL) && (XuefiStringDataba= se =3D=3D NULL)) { + DEBUG ((DEBUG_ERROR, "%a: Invalid parameters for this function.\n", __= func__)); + return EFI_INVALID_PARAMETER; + } + + if (IsListEmpty (&FormsetPrivate->XuefiRedfishStringDatabase)) { + return EFI_NOT_FOUND; + } + + XuefiRedfishStringDatabase =3D (REDFISH_X_UEFI_STRING_DATABASE *)GetFirs= tNode (&FormsetPrivate->XuefiRedfishStringDatabase); + while (TRUE) { + if (Language !=3D NULL) { + *Language =3D XuefiRedfishStringDatabase->XuefiRedfishLanguage; + } + + StringArray =3D (REDFISH_X_UEFI_STRINGS_ARRAY *)GetFirstNode (&XuefiRe= dfishStringDatabase->XuefiRedfishStringArrays); + + // Loop to the correct string array. + StringIndex =3D StringId; + while (StringIndex >=3D X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER) { + if (IsNodeAtEnd (&XuefiRedfishStringDatabase->XuefiRedfishStringArra= ys, &StringArray->NextArray)) { + goto ErrorEixt; + } + + StringArray =3D (REDFISH_X_UEFI_STRINGS_ARRAY *)GetNextNode (&Xuefi= RedfishStringDatabase->XuefiRedfishStringArrays, &StringArray->NextArray); + StringIndex -=3D X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER; + } + + // + // NOTE: The string ID in the formset is a unique number. + // If the string in the array is NULL, then the matched string I= D + // should be in another x-uefi-redfish database. + // + if ((StringArray->ArrayEntryAddress + StringIndex)->UcsString !=3D NUL= L) { + // + // String ID is belong to this x-uef-redfish language database. + // + if (String !=3D NULL) { + *String =3D (StringArray->ArrayEntryAddress + StringIndex)->UcsStr= ing; + } + + if (XuefiStringDatabase !=3D NULL) { + *XuefiStringDatabase =3D XuefiRedfishStringDatabase; + } + + return EFI_SUCCESS; + } + + if (IsNodeAtEnd (&FormsetPrivate->XuefiRedfishStringDatabase, &XuefiRe= dfishStringDatabase->NextXuefiRedfishLanguage)) { + return EFI_NOT_FOUND; + } + + XuefiRedfishStringDatabase =3D (REDFISH_X_UEFI_STRING_DATABASE *)GetNe= xtNode ( + &Form= setPrivate->XuefiRedfishStringDatabase, + &Xuef= iRedfishStringDatabase->NextXuefiRedfishLanguage + ); + } + +ErrorEixt:; + DEBUG ((DEBUG_ERROR, "%a: String ID (%d) is not in any x-uef-redfish str= ing databases.\n", __func__, StringId)); + return EFI_NOT_FOUND; +} + +/** + Build a x-uefi-redfish database for the newly added x-uefi-redfish langu= age. + + @param[in] FormsetPrivate Pointer to HII form-set private = instance. + +**/ +VOID +BuildXUefiRedfishStringDatabase ( + IN REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE *FormsetPrivate + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + EFI_HII_PACKAGE_HEADER *PackageHeader; + UINTN EndingPackageAddress; + EFI_HII_STRING_PACKAGE_HDR *HiiStringPackageHeader; + UINTN SupportedSchemaLangCount; + CHAR8 **SupportedSchemaLang; + BOOLEAN StringIdMapIsBuilt; + + DEBUG ((DEBUG_INFO, "%a: Building x-uefi-redfish string database, HII Fo= rmset GUID - %g.\n", __func__, FormsetPrivate->Guid)); + + BufferSize =3D 0; + Status =3D mRedfishPlatformConfigPrivate->HiiDatabase->ExportPackage= Lists ( + mRedfishPlatf= ormConfigPrivate->HiiDatabase, + FormsetPrivat= e->HiiHandle, + &BufferSize, + FormsetPrivat= e->HiiPackageListHeader + ); + if (Status !=3D EFI_BUFFER_TOO_SMALL) { + DEBUG ((DEBUG_ERROR, " Failed to export package list.\n")); + return; + } + + FormsetPrivate->HiiPackageListHeader =3D (EFI_HII_PACKAGE_LIST_HEADER *)= AllocateZeroPool (BufferSize); + if (FormsetPrivate->HiiPackageListHeader =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, " Failed to allocate memory for the exported pac= kage list.\n")); + return; + } + + Status =3D mRedfishPlatformConfigPrivate->HiiDatabase->ExportPackageList= s ( + mRedfishPlatformC= onfigPrivate->HiiDatabase, + FormsetPrivate->H= iiHandle, + &BufferSize, + FormsetPrivate->H= iiPackageListHeader + ); + if (EFI_ERROR (Status)) { + return; + } + + // + // Finding the string package. + // + EndingPackageAddress =3D (UINTN)FormsetPrivate->HiiPackageListHeader + F= ormsetPrivate->HiiPackageListHeader->PackageLength; + PackageHeader =3D (EFI_HII_PACKAGE_HEADER *)(FormsetPrivate->HiiP= ackageListHeader + 1); + SupportedSchemaLang =3D FormsetPrivate->SupportedSchema.SchemaList; + while ((UINTN)PackageHeader < EndingPackageAddress) { + switch (PackageHeader->Type) { + case EFI_HII_PACKAGE_STRINGS: + StringIdMapIsBuilt =3D FALSE; + HiiStringPackageHeader =3D (EFI_HII_STRING_PACKAGE_HDR *)PackageHe= ader; + + // Check if this is the string package for x-uefi-redfish + for (SupportedSchemaLangCount =3D 0; + SupportedSchemaLangCount < FormsetPrivate->SupportedSchema.Co= unt; + SupportedSchemaLangCount++ + ) + { + if (AsciiStrnCmp ( + *(SupportedSchemaLang + SupportedSchemaLangCount), + HiiStringPackageHeader->Language, + AsciiStrLen (HiiStringPackageHeader->Language) + ) =3D=3D 0) + { + StringIdMapIsBuilt =3D CreateXuefiLanguageStringIdMap (Formset= Private, HiiStringPackageHeader); + break; + } + } + + if (StringIdMapIsBuilt =3D=3D FALSE) { + if (AsciiStrStr (HiiStringPackageHeader->Language, X_UEFI_SCHEMA= _PREFIX) =3D=3D NULL) { + DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, " No need to build x-u= efi-redfish string ID map for HII language %a\n", HiiStringPackageHeader->L= anguage)); + } else { + DEBUG ((DEBUG_ERROR, " Failed to build x-uefi-redfish string = ID map of HII language %a\n", HiiStringPackageHeader->Language)); + } + } + + default: + PackageHeader =3D (EFI_HII_PACKAGE_HEADER *)((UINTN)PackageHeader = + PackageHeader->Length); + } + } +} + /** Load the HII formset from the given HII handle. @param[in] HiiHandle Target HII handle to load. @param[out] FormsetPrivate The formset private data. - @retval EFI_STATUS + @retval EFI_STATUS The formset is loaded successfully. + @retval EFI_UNSUPPORTED This formset doesn't have any x-uefi-redfish= configuration. **/ EFI_STATUS @@ -875,6 +1583,7 @@ LoadFormset ( REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE *HiiStatementPrivate; EFI_GUID ZeroGuid; EXPRESS_RESULT ExpressionResult; + CHAR16 *String; if ((HiiHandle =3D=3D NULL) || (FormsetPrivate =3D=3D NULL)) { return EFI_INVALID_PARAMETER; @@ -882,6 +1591,7 @@ LoadFormset ( HiiFormSet =3D AllocateZeroPool (sizeof (HII_FORMSET)); if (HiiFormSet =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: No memory resource for HII_FORMSET - %g\n", = __func__, FormsetPrivate->Guid)); return EFI_OUT_OF_RESOURCES; } @@ -891,6 +1601,7 @@ LoadFormset ( ZeroMem (&ZeroGuid, sizeof (ZeroGuid)); Status =3D CreateFormSetFromHiiHandle (HiiHandle, &ZeroGuid, HiiFormSet)= ; if (EFI_ERROR (Status) || IsListEmpty (&HiiFormSet->FormListHead)) { + DEBUG ((DEBUG_ERROR, "%a: Formset not found by HII handle - %g\n", __f= unc__, FormsetPrivate->Guid)); Status =3D EFI_NOT_FOUND; goto ErrorExit; } @@ -909,7 +1620,11 @@ LoadFormset ( FormsetPrivate->DevicePathStr =3D ConvertDevicePathToText (HiiFormSet->D= evicePath, FALSE, FALSE); Status =3D GetSupportedSchema (FormsetPrivate->Hi= iHandle, &FormsetPrivate->SupportedSchema); if (EFI_ERROR (Status)) { - DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: No schema from HII handle:= 0x%x found: %r\n", __func__, FormsetPrivate->HiiHandle, Status)); + DEBUG ((REDFISH_PLATFORM_CONFIG_DEBUG, "%a: No x-uefi-redfish configur= ation found on the formset - %g\n", __func__, FormsetPrivate->Guid)); + return EFI_UNSUPPORTED; // Can't build AttributeRegistry Meni path wit= h returning EFI_UNSUPPORTED. + } else { + // Building x-uefi-redfish string database + BuildXUefiRedfishStringDatabase (FormsetPrivate); } HiiFormLink =3D GetFirstNode (&HiiFormSet->FormListHead); @@ -919,6 +1634,7 @@ LoadFormset ( HiiFormPrivate =3D AllocateZeroPool (sizeof (REDFISH_PLATFORM_CONFIG_F= ORM_PRIVATE)); if (HiiFormPrivate =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; + DEBUG ((DEBUG_ERROR, "%a: No memory resource for REDFISH_PLATFORM_CO= NFIG_FORM_PRIVATE.\n", __func__)); goto ErrorExit; } @@ -944,6 +1660,7 @@ LoadFormset ( HiiStatementPrivate =3D AllocateZeroPool (sizeof (REDFISH_PLATFORM_C= ONFIG_STATEMENT_PRIVATE)); if (HiiStatementPrivate =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: No memory resource for REDFISH_PLATFORM_= CONFIG_STATEMENT_PRIVATE.\n", __func__)); Status =3D EFI_OUT_OF_RESOURCES; goto ErrorExit; } @@ -981,10 +1698,18 @@ LoadFormset ( } } - // - // Attach to statement list. - // - InsertTailList (&HiiFormPrivate->StatementList, &HiiStatementPrivate= ->Link); + // Get x-uefi-redfish string using String ID. + Status =3D GetXuefiStringAndLangByStringId (FormsetPrivate, HiiState= mentPrivate->Description, &String, NULL, NULL); + if (!EFI_ERROR (Status)) { + HiiStatementPrivate->XuefiRedfishStr =3D String; + // + // Attach to statement list. + // + InsertTailList (&HiiFormPrivate->StatementList, &HiiStatementPriva= te->Link); + } else { + FreePool (HiiStatementPrivate); + } + HiiStatementLink =3D GetNextNode (&HiiForm->StatementListHead, HiiSt= atementLink); } @@ -1052,7 +1777,7 @@ LoadFormsetList ( // Status =3D LoadFormset (HiiHandle, FormsetPrivate); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: failed to load formset: %r\n", __func__, Sta= tus)); + DEBUG ((DEBUG_ERROR, "%a: Formset is not loaded for edk2 redfish: %r\n= ", __func__, Status)); FreePool (FormsetPrivate); return Status; } @@ -1325,7 +2050,11 @@ ProcessPendingList ( Status =3D LoadFormsetList (Target->HiiHandle, FormsetList); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: load formset from HII handle: 0x%x faile= d: %r\n", __func__, Target->HiiHandle, Status)); + if (Status =3D=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_ERROR, " The formset has no x-uefi-redfish config= urations.\n")); + } else { + DEBUG ((DEBUG_ERROR, " load formset from HII handle: 0x%x faile= d: %r\n", Target->HiiHandle, Status)); + } } } -- 2.37.1.windows.1 -The information contained in this message may be confidential and propriet= ary to American Megatrends (AMI). This communication is intended to be read= only by the individual or entity to whom it is addressed or by their desig= nee. If the reader of this message is not the intended recipient, you are o= n notice that any distribution of this message, in any form, is strictly pr= ohibited. Please promptly notify the sender by reply e-mail or by telephone= at 770-246-8600, and then delete or destroy all copies of the transmission= . -=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 (#117433): https://edk2.groups.io/g/devel/message/117433 Mute This Topic: https://groups.io/mt/105326104/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-