From nobody Sat Nov 2 10:35:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 149251962282912.456863831608189; Tue, 18 Apr 2017 05:47:02 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1CFDA2195408B; Tue, 18 Apr 2017 05:47:01 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 33CDC2195408B for ; Tue, 18 Apr 2017 05:47:00 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 18 Apr 2017 05:47:00 -0700 Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by fmsmga005.fm.intel.com with ESMTP; 18 Apr 2017 05:46:59 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,219,1488873600"; d="scan'208";a="90823085" From: Dandan Bi To: edk2-devel@lists.01.org Date: Tue, 18 Apr 2017 20:46:31 +0800 Message-Id: <1492519592-173060-4-git-send-email-dandan.bi@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1492519592-173060-1-git-send-email-dandan.bi@intel.com> References: <1492519592-173060-1-git-send-email-dandan.bi@intel.com> Subject: [edk2] [RFC patch 3/4] MdeModulePkg/HiiDatabase: Handle questions with Bit VarStore X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Dong , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" For oneof/numeric/checkbox, their storage may be bit field. When generating string to get default value for these questions, we need to parse the Ifr data to get the bit Varstore info,and then generating the correct string. Cc: Eric Dong Cc: Liming Gao Cc: Dandan Bi Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi --- .../Universal/HiiDatabaseDxe/ConfigRouting.c | 197 +++++++++++++++++= ++-- .../Universal/HiiDatabaseDxe/HiiDatabase.h | 3 + 2 files changed, 186 insertions(+), 14 deletions(-) diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeMod= ulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c index c9ff1cf..5da0ba6 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c @@ -13,10 +13,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. **/ =20 =20 #include "HiiDatabase.h" extern HII_DATABASE_PRIVATE_DATA mPrivate; +EFI_GUID mBitVarstoreGuid =3D {0x82DDD68B, 0x9163, 0x4187, {0x9B,= 0x27, 0x20, 0xA8, 0xFD, 0x60 ,0xA7 , 0x1D}}; +BOOLEAN mNeedUpdateBlockData =3D FALSE; +BOOLEAN mQuestionReferBitVar =3D FALSE; =20 /** Calculate the number of Unicode characters of the incoming Configuration= string, not including NULL terminator. =20 @@ -1223,19 +1226,19 @@ InsertBlockData ( // Insert block data in its Offset and Width order. // for (Link =3D BlockLink->ForwardLink; Link !=3D BlockLink; Link =3D Link= ->ForwardLink) { BlockArray =3D BASE_CR (Link, IFR_BLOCK_DATA, Entry); if (BlockArray->Offset =3D=3D BlockSingleData->Offset) { - if (BlockArray->Width > BlockSingleData->Width) { + if ((BlockArray->Width > BlockSingleData->Width) || (BlockSingleData= ->IsBitVar && BlockArray->Width =3D=3D BlockSingleData->Width)) { // // Insert this block data in the front of block array // InsertTailList (Link, &BlockSingleData->Entry); return; } =20 - if (BlockArray->Width =3D=3D BlockSingleData->Width) { + if ((!BlockSingleData->IsBitVar) && BlockArray->Width =3D=3D BlockSi= ngleData->Width) { // // The same block array has been added. // if (BlockSingleData !=3D BlockArray) { FreePool (BlockSingleData); @@ -1991,17 +1994,21 @@ IsThisOpcodeRequired ( IN IFR_BLOCK_DATA *RequestBlockArray, IN EFI_HII_HANDLE HiiHandle, IN OUT IFR_VARSTORAGE_DATA *VarStorageData, IN EFI_IFR_OP_HEADER *IfrOpHdr, IN UINT16 VarWidth, - OUT IFR_BLOCK_DATA **ReturnData + OUT IFR_BLOCK_DATA **ReturnData, + IN BOOLEAN IsBitVar ) { IFR_BLOCK_DATA *BlockData; UINT16 VarOffset; EFI_STRING_ID NameId; EFI_IFR_QUESTION_HEADER *IfrQuestionHdr; + UINT16 BitOffset; + UINT16 BitWidth; + UINT16 BitVarWidth; =20 NameId =3D 0; VarOffset =3D 0; IfrQuestionHdr =3D (EFI_IFR_QUESTION_HEADER *)((CHAR8 *) IfrOpHdr + siz= eof (EFI_IFR_OP_HEADER)); =20 @@ -2016,11 +2023,19 @@ IsThisOpcodeRequired ( // This question is not in the requested string. Skip it. // return EFI_NOT_FOUND; } } else { - VarOffset =3D IfrQuestionHdr->VarStoreInfo.VarOffset; + if (IsBitVar) { + BitOffset =3D IfrQuestionHdr->VarStoreInfo.VarOffset; + VarOffset =3D BitOffset / 8; + BitVarWidth =3D VarWidth; + BitWidth =3D BitOffset - (VarOffset * 8) + BitVarWidth; + VarWidth =3D (BitWidth % 8 =3D=3D 0 ? BitWidth / 8: BitWidth / 8 += 1); + } else { + VarOffset =3D IfrQuestionHdr->VarStoreInfo.VarOffset; + } =20 // // Check whether this question is in requested block array. // if (!BlockArrayCheck (RequestBlockArray, VarOffset, VarWidth, FALSE, H= iiHandle)) { @@ -2051,10 +2066,13 @@ IsThisOpcodeRequired ( =20 BlockData->Width =3D VarWidth; BlockData->QuestionId =3D IfrQuestionHdr->QuestionId; BlockData->OpCode =3D IfrOpHdr->OpCode; BlockData->Scope =3D IfrOpHdr->Scope; + BlockData->IsBitVar =3D IsBitVar; + BlockData->BitOffset =3D IfrQuestionHdr->VarStoreInfo.VarOffset; + BlockData->BitWidth =3D BitVarWidth; InitializeListHead (&BlockData->DefaultValueEntry); // // Add Block Data into VarStorageData BlockEntry // InsertBlockData (&VarStorageData->BlockEntry, &BlockData); @@ -2124,10 +2142,11 @@ ParseIfrData ( EFI_HII_PACKAGE_HEADER *PackageHeader; EFI_VARSTORE_ID VarStoreId; UINT16 SmallestDefaultId; BOOLEAN SmallestIdFromFlag; BOOLEAN FromOtherDefaultOpcode; + BOOLEAN IsBitVar; =20 Status =3D EFI_SUCCESS; BlockData =3D NULL; DefaultDataPtr =3D NULL; FirstOneOfOption =3D FALSE; @@ -2135,10 +2154,11 @@ ParseIfrData ( FirstOrderedList =3D FALSE; VarStoreName =3D NULL; ZeroMem (&DefaultData, sizeof (IFR_DEFAULT_DATA)); SmallestDefaultId =3D 0xFFFF; FromOtherDefaultOpcode =3D FALSE; + IsBitVar =3D FALSE; =20 // // Go through the form package to parse OpCode one by one. // PackageOffset =3D sizeof (EFI_HII_PACKAGE_HEADER); @@ -2309,11 +2329,11 @@ ParseIfrData ( // if (BlockData !=3D NULL){ BlockData =3D NULL; } =20 - Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData); + Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status =3D=3D EFI_NOT_FOUND){ // //The opcode is not required,exit and parse other opcode. // @@ -2341,20 +2361,28 @@ ParseIfrData ( // IfrOneOf =3D (EFI_IFR_ONE_OF *) IfrOpHdr; if (IfrOneOf->Question.VarStoreId !=3D VarStoreId) { break; } - VarWidth =3D (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE= )); + + if (mQuestionReferBitVar) { + mQuestionReferBitVar =3D FALSE; + VarWidth =3D IfrOneOf->Flags & 0X0F; + IsBitVar =3D TRUE; + } else { + VarWidth =3D (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SI= ZE)); + IsBitVar =3D FALSE; + } =20 // // The BlockData may allocate by other opcode,need to clean. // if (BlockData !=3D NULL){ BlockData =3D NULL; } =20 - Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData); + Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData, IsBitVar); if (EFI_ERROR (Status)) { if (Status =3D=3D EFI_NOT_FOUND){ // //The opcode is not required,exit and parse other opcode. // @@ -2439,11 +2467,11 @@ ParseIfrData ( // if (BlockData !=3D NULL){ BlockData =3D NULL; } =20 - Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData); + Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status =3D=3D EFI_NOT_FOUND){ // //The opcode is not required,exit and parse other opcode. // @@ -2484,11 +2512,19 @@ ParseIfrData ( // if (BlockData !=3D NULL){ BlockData =3D NULL; } =20 - Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData); + if (mQuestionReferBitVar) { + mQuestionReferBitVar =3D FALSE; + VarWidth =3D 1; + IsBitVar =3D TRUE; + } else { + IsBitVar =3D FALSE; + } + + Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData, IsBitVar); if (EFI_ERROR (Status)) { if (Status =3D=3D EFI_NOT_FOUND){ // //The opcode is not required,exit and parse other opcode. // @@ -2612,11 +2648,11 @@ ParseIfrData ( if (BlockData !=3D NULL){ BlockData =3D NULL; } =20 VarWidth =3D (UINT16) sizeof (EFI_HII_DATE); - Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData); + Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status =3D=3D EFI_NOT_FOUND){ // //The opcode is not required,exit and parse other opcode. // @@ -2654,11 +2690,11 @@ ParseIfrData ( if (BlockData !=3D NULL){ BlockData =3D NULL; } =20 VarWidth =3D (UINT16) sizeof (EFI_HII_TIME); - Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData); + Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status =3D=3D EFI_NOT_FOUND){ // //The opcode is not required,exit and parse other opcode. // @@ -2696,11 +2732,11 @@ ParseIfrData ( if (BlockData !=3D NULL){ BlockData =3D NULL; } =20 VarWidth =3D (UINT16) (IfrString->MaxSize * sizeof (UINT16)); - Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData); + Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status =3D=3D EFI_NOT_FOUND){ // //The opcode is not required,exit and parse other opcode. // @@ -2738,11 +2774,11 @@ ParseIfrData ( if (BlockData !=3D NULL){ BlockData =3D NULL; } =20 VarWidth =3D (UINT16) (IfrPassword->MaxSize * sizeof (UINT16)); - Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData); + Status =3D IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarSto= rageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status =3D=3D EFI_NOT_FOUND){ // //The opcode is not required,exit and parse other opcode. // @@ -2985,13 +3021,19 @@ ParseIfrData ( // SmallestDefaultId =3D 0xFFFF; FromOtherDefaultOpcode =3D FALSE; } } + mQuestionReferBitVar =3D FALSE; =20 break; =20 + case EFI_IFR_GUID_OP: + if (CompareGuid ((EFI_GUID *)((UINT8*)IfrOpHdr + sizeof (EFI_IFR_OP_= HEADER)), &mBitVarstoreGuid)) { + mQuestionReferBitVar =3D TRUE; + } + default: if (BlockData !=3D NULL) { if (BlockData->Scope > 0) { BlockData->Scope =3D (UINT8) (BlockData->Scope + IfrOpHdr->Scope= ); } @@ -3567,13 +3609,138 @@ GetStorageWidth ( =20 return StorageWidth; } =20 /** +For some question (oneof/numeric/checkbox),their storage may be bit filed, +their block data may have same OFFSET and WIDTH, this function merge the +same block data to one. + +@param BlockLink The Link of the block data. + +**/ +VOID +UpdateBlockDataArray( + IN LIST_ENTRY *BlockLink +) +{ + LIST_ENTRY *Link; + LIST_ENTRY *TempLink; + LIST_ENTRY *ListEntry; + LIST_ENTRY *NextListEntry; + LIST_ENTRY *LinkDefault; + LIST_ENTRY *NextLinkDefault; + IFR_BLOCK_DATA *BlockData; + IFR_BLOCK_DATA *NextBlockeData; + IFR_DEFAULT_DATA *DefaultValueData; + IFR_DEFAULT_DATA *NextDefaultValueData; + UINT32 Value; + UINT32 Mask; + UINT32 PreBits; + UINT32 *DefaultValue; + UINT8 *BufferValue; + BOOLEAN BlockDataChanged; + BOOLEAN DefaultIdChanged; + BOOLEAN NextBlockChanged; + + Value =3D 0; + Link =3D BlockLink->ForwardLink; + BlockDataChanged =3D TRUE; + DefaultIdChanged =3D FALSE; + NextBlockChanged =3D FALSE; + + while (Link !=3D BlockLink) { + BlockData =3D BASE_CR (Link, IFR_BLOCK_DATA, Entry); + TempLink =3D Link->ForwardLink; + if (!BlockData ->IsBitVar) { + Link =3D Link->ForwardLink; + continue; + } + + while (TempLink !=3D Link) { + NextBlockeData =3D BASE_CR (TempLink, IFR_BLOCK_DATA, Entry); + TempLink =3D TempLink->ForwardLink; + if (BlockData->Offset !=3D NextBlockeData->Offset || BlockData->Widt= h !=3D NextBlockeData->Width) { + continue; + } + // + // They are the same blocks, merge them to one, and update the defau= lt value. + // + ListEntry =3D &BlockData->DefaultValueEntry; + for (LinkDefault =3D ListEntry->ForwardLink; LinkDefault !=3D ListEn= try; LinkDefault =3D LinkDefault->ForwardLink) { + DefaultValueData =3D BASE_CR (LinkDefault, IFR_DEFAULT_DATA, Entry= ); + NextListEntry =3D &NextBlockeData->DefaultValueEntry; + for (NextLinkDefault =3D NextListEntry->ForwardLink; NextLinkDefau= lt !=3D NextListEntry; NextLinkDefault =3D NextLinkDefault->ForwardLink) { + NextDefaultValueData =3D BASE_CR (NextLinkDefault, IFR_DEFAULT_D= ATA, Entry); + if (DefaultValueData->DefaultId !=3D NextDefaultValueData->Defau= ltId) { + continue; + } + // + // The default value with same default id. + // + if (BlockDataChanged) { + Mask =3D (1 << BlockData->BitWidth) - 1; + PreBits =3D BlockData->BitOffset - BlockData->Offset * 8; + DefaultValue =3D (UINT32*)&(DefaultValueData->Value); + *DefaultValue <<=3D PreBits; + Mask <<=3D PreBits; + Value =3D (Value & (~Mask)) | *DefaultValue; + BlockDataChanged =3D FALSE; + } else if (!BlockDataChanged && !NextBlockChanged && DefaultIdCh= anged){ + Mask =3D (1 << BlockData->BitWidth) - 1; + PreBits =3D BlockData->BitOffset - BlockData->Offset * 8; + DefaultValue =3D (UINT32*)&(DefaultValueData->Value); + *DefaultValue <<=3D PreBits; + Mask <<=3D PreBits; + Value =3D (Value & (~Mask)) | *DefaultValue; + DefaultIdChanged =3D FALSE; + } else if (!BlockDataChanged && NextBlockChanged) { + BufferValue =3D (UINT8*)&(DefaultValueData->Value); + Value =3D (UINTN)(*BufferValue); + } + + Mask =3D (1 << NextBlockeData->BitWidth) - 1; + PreBits =3D NextBlockeData->BitOffset - NextBlockeData->Offset *= 8; + DefaultValue =3D (UINT32*) & (NextDefaultValueData->Value); + *DefaultValue <<=3D PreBits; + Mask <<=3D PreBits; + Value =3D (Value & (~Mask)) | *DefaultValue; + + CopyMem (&DefaultValueData->Value, &Value, sizeof (EFI_IFR_TYPE_= VALUE)); + } + DefaultIdChanged =3D TRUE; + } + RemoveEntryList (&NextBlockeData->Entry); + if (NextBlockeData->Name !=3D NULL) { + FreePool (NextBlockeData->Name); + } + // + // Free default value link array + // + while (!IsListEmpty (&NextBlockeData->DefaultValueEntry)) { + DefaultValueData =3D BASE_CR (NextBlockeData->DefaultValueEntry.Fo= rwardLink, IFR_DEFAULT_DATA, Entry); + RemoveEntryList (&DefaultValueData->Entry); + FreePool (DefaultValueData); + } + FreePool (NextBlockeData); + + Link->ForwardLink =3D TempLink; + NextBlockChanged =3D TRUE; + } + + Link =3D Link->ForwardLink; + BlockDataChanged =3D TRUE; + NextBlockChanged =3D FALSE; + DefaultIdChanged =3D FALSE; + } +} + +/** Generate ConfigAltResp string base on the varstore info. =20 - @param HiiHandle Hii Handle for this hii package. + Contributed-under: TianoCore Contribution Agreement 1.0 +Signed-off-by: Dandan Bi Hii Handle for = this hii package. @param ConfigHdr The config header for this varstore. @param VarStorageData The varstore info. @param DefaultIdArray The Default id array. @param DefaultAltCfgResp The DefaultAltCfgResp info may be retu= rn. =20 @@ -3610,10 +3777,12 @@ GenerateAltConfigResp ( // // Add length for + '\0' // Length =3D StrLen (ConfigHdr) + 1; =20 + UpdateBlockDataArray (&VarStorageData->BlockEntry); + for (Link =3D DefaultIdArray->Entry.ForwardLink; Link !=3D &DefaultIdArr= ay->Entry; Link =3D Link->ForwardLink) { DefaultId =3D BASE_CR (Link, IFR_DEFAULT_DATA, Entry); // // Add length for "&&ALTCFG=3DXXXX" // |1| StrLen (ConfigHdr) | 8 | 4 | diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h b/MdeModul= ePkg/Universal/HiiDatabaseDxe/HiiDatabase.h index e6760c3..e9962be 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h @@ -75,15 +75,18 @@ typedef struct { =20 typedef struct { LIST_ENTRY Entry; // Link to Block array UINT16 Offset; UINT16 Width; + UINT16 BitOffset; + UINT16 BitWidth; EFI_QUESTION_ID QuestionId; UINT8 OpCode; UINT8 Scope; LIST_ENTRY DefaultValueEntry; // Link to its default value array CHAR16 *Name; + BOOLEAN IsBitVar; } IFR_BLOCK_DATA; =20 // // Get default value from IFR data. // --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel