]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add support for EFI_IFR_QUESTION_REF3 opcode for browser when this opcode has the...
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 22 Nov 2011 07:46:35 +0000 (07:46 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 22 Nov 2011 07:46:35 +0000 (07:46 +0000)
Signed-off-by: ydong10
Reviewed-by: lgao4
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12759 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
MdeModulePkg/Universal/SetupBrowserDxe/Setup.h

index 883693fde59233acd397001b1bf3d8b290bb5246..b6028cb31f1f6d22ab720a4bf1c2354a67dfa1cb 100644 (file)
@@ -522,7 +522,7 @@ IdToQuestion2 (
   LIST_ENTRY              *Link;\r
   FORM_BROWSER_STATEMENT  *Question;\r
 \r
-  if (QuestionId == 0) {\r
+  if (QuestionId == 0 || Form == NULL) {\r
     //\r
     // The value of zero is reserved\r
     //\r
@@ -757,6 +757,7 @@ IfrToString (
     // so need 1 byte to align, also need 2 bytes for L'\0'.\r
     //\r
     TmpBuf = AllocateZeroPool (Value.BufferLen + 3);\r
+    ASSERT (TmpBuf != NULL);\r
     if (Format == EFI_IFR_STRING_ASCII) {\r
       CopyMem (TmpBuf, Value.Buffer, Value.BufferLen);\r
       PrintFormat = L"%a"; \r
@@ -1651,6 +1652,151 @@ CheckUserPrivilege (
   return FALSE;\r
 }\r
 \r
+/**\r
+  Get question value from the predefined formset.\r
+\r
+  @param  DevicePath             The driver's device path which produece the formset data.\r
+  @param  InputHiiHandle         The hii handle associate with the formset data.\r
+  @param  FormSetGuid            The formset guid which include the question.\r
+  @param  QuestionId             The question id which need to get value from.\r
+  @param  Value                  The return data about question's value.\r
+  \r
+  @retval TRUE                   Get the question value success.\r
+  @retval FALSE                  Get the question value failed.\r
+**/\r
+BOOLEAN \r
+GetQuestionValueFromForm (\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN EFI_HII_HANDLE            InputHiiHandle,\r
+  IN EFI_GUID                  *FormSetGuid,\r
+  IN EFI_QUESTION_ID           QuestionId,\r
+  OUT EFI_HII_VALUE            *Value\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  EFI_HANDLE                   DriverHandle;\r
+  EFI_HANDLE                   Handle;\r
+  EFI_HII_HANDLE               *HiiHandles;\r
+  EFI_HII_HANDLE               HiiHandle;\r
+  UINTN                        Index;\r
+  FORM_BROWSER_STATEMENT       *Question;\r
+  FORM_BROWSER_FORMSET         *FormSet;\r
+  FORM_BROWSER_FORM            *Form;\r
+  BOOLEAN                      GetTheVal;\r
+  LIST_ENTRY                   *Link;\r
+\r
+  // \r
+  // The input parameter DevicePath or InputHiiHandle must have one valid input. \r
+  //\r
+  ASSERT ((DevicePath != NULL && InputHiiHandle == NULL) || \r
+          (DevicePath == NULL && InputHiiHandle != NULL) );\r
+\r
+  GetTheVal    = TRUE;\r
+  DriverHandle = NULL;\r
+  HiiHandle    = NULL;\r
+  Question     = NULL;\r
+  Form         = NULL;\r
+\r
+  //\r
+  // Get HiiHandle.\r
+  //\r
+  if (DevicePath != NULL) {\r
+    //\r
+    // 1. Get Driver handle.\r
+    //\r
+    Status = gBS->LocateDevicePath (\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    &DevicePath,\r
+                    &DriverHandle\r
+                    );\r
+    if (EFI_ERROR (Status) || (DriverHandle == NULL)) {\r
+      return FALSE;\r
+    }\r
+\r
+    //\r
+    // 2. Get Hii handle\r
+    //\r
+    HiiHandles = HiiGetHiiHandles (NULL);\r
+    if (HiiHandles == NULL) {\r
+      return FALSE;\r
+    }\r
+\r
+    for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r
+      Status = mHiiDatabase->GetPackageListHandle (\r
+                               mHiiDatabase,\r
+                               HiiHandles[Index],\r
+                               &Handle\r
+                               );\r
+      if (!EFI_ERROR (Status) && (Handle == DriverHandle)) {\r
+        HiiHandle = HiiHandles[Index];\r
+        break;\r
+      }\r
+    }\r
+    FreePool (HiiHandles);\r
+  } else {\r
+    HiiHandle = InputHiiHandle;\r
+  } \r
+  ASSERT (HiiHandle != NULL);\r
+\r
+  //\r
+  // Get the formset data include this question.\r
+  //\r
+  FormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET));\r
+  ASSERT (FormSet != NULL);\r
+  Status = InitializeFormSet(HiiHandle, FormSetGuid, FormSet, FALSE);\r
+  if (EFI_ERROR (Status)) {\r
+    GetTheVal = FALSE;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Base on the Question Id to get the question info.\r
+  //  \r
+  Question = IdToQuestion(FormSet, NULL, QuestionId);\r
+  if (Question == NULL) {\r
+    GetTheVal = FALSE;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Search form in the formset scope\r
+  //\r
+  Link = GetFirstNode (&FormSet->FormListHead);\r
+  while (!IsNull (&FormSet->FormListHead, Link)) {\r
+    Form = FORM_BROWSER_FORM_FROM_LINK (Link);\r
+\r
+    Question = IdToQuestion2 (Form, QuestionId);\r
+    if (Question != NULL) {\r
+      break;\r
+    }\r
+\r
+    Link = GetNextNode (&FormSet->FormListHead, Link);\r
+    Form = NULL;\r
+  }\r
+  ASSERT (Form != NULL);\r
+  \r
+  //\r
+  // Get the question value.\r
+  //\r
+  Status = GetQuestionValue(FormSet, Form, Question, FALSE);\r
+  if (EFI_ERROR (Status)) {\r
+    GetTheVal = FALSE;\r
+    goto Done;\r
+  }\r
+\r
+  CopyMem (Value, &Question->HiiValue, sizeof (EFI_HII_VALUE));\r
+  \r
+Done:\r
+  //\r
+  // Clean the formset structure and restore the global parameter.\r
+  //\r
+  if (FormSet != NULL) {\r
+    DestroyFormSet (FormSet);\r
+  }\r
+  \r
+  return GetTheVal;\r
+}\r
+\r
 /**\r
   Evaluate the result of a HII expression.\r
 \r
@@ -1699,6 +1845,7 @@ EvaluateExpression (
   UINT8                   DigitUint8;\r
   UINT8                   *TempBuffer;\r
   EFI_TIME                EfiTime;\r
+  EFI_HII_VALUE           QuestionVal;\r
 \r
   //\r
   // Save current stack offset.\r
@@ -1931,24 +2078,42 @@ EvaluateExpression (
       break;\r
 \r
     case EFI_IFR_QUESTION_REF3_OP:\r
-      if (OpCode->DevicePath == 0) {\r
-        //\r
-        // EFI_IFR_QUESTION_REF3\r
-        // Pop an expression from the expression stack\r
-        //\r
-        Status = PopExpression (Value);\r
-        if (EFI_ERROR (Status)) {\r
+      //\r
+      // EFI_IFR_QUESTION_REF3\r
+      // Pop an expression from the expression stack\r
+      //\r
+      Status = PopExpression (Value);\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
+    \r
+      //\r
+      // Validate the expression value\r
+      //\r
+      if ((Value->Type > EFI_IFR_TYPE_NUM_SIZE_64) || (Value->Value.u64 > 0xffff)) {\r
+        Status = EFI_NOT_FOUND;\r
+        goto Done;\r
+      }\r
+\r
+      if (OpCode->DevicePath != 0) {\r
+        StrPtr = GetToken (OpCode->DevicePath, FormSet->HiiHandle);\r
+        if (StrPtr == NULL) {\r
+          Status = EFI_NOT_FOUND;\r
           goto Done;\r
         }\r
 \r
-        //\r
-        // Validate the expression value\r
-        //\r
-        if ((Value->Type > EFI_IFR_TYPE_NUM_SIZE_64) || (Value->Value.u64 > 0xffff)) {\r
+        if (!GetQuestionValueFromForm((EFI_DEVICE_PATH_PROTOCOL*)StrPtr, NULL, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
           Status = EFI_NOT_FOUND;\r
           goto Done;\r
         }\r
-\r
+        Value = &QuestionVal;\r
+      } else if (CompareGuid (&OpCode->Guid, &gZeroGuid) != 0) {\r
+        if (!GetQuestionValueFromForm(NULL, FormSet->HiiHandle, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
+          Status = EFI_NOT_FOUND;\r
+          goto Done;\r
+        }\r
+        Value = &QuestionVal;        \r
+      } else {\r
         Question = IdToQuestion (FormSet, Form, Value->Value.u16);\r
         if (Question == NULL) {\r
           Status = EFI_NOT_FOUND;\r
@@ -1959,13 +2124,6 @@ EvaluateExpression (
         // push the questions' value on to the expression stack\r
         //\r
         Value = &Question->HiiValue;\r
-      } else {\r
-        //\r
-        // BUGBUG: push 0 for EFI_IFR_QUESTION_REF3_2 and EFI_IFR_QUESTION_REF3_3,\r
-        // since it is impractical to evaluate the value of a Question in another\r
-        // Hii Package list.\r
-        //\r
-        ZeroMem (Value, sizeof (EFI_HII_VALUE));\r
       }\r
       break;\r
 \r
index 92582f35d83cebfd274bdb49dbf1aacc5d15f930..6b169cd0a1f3b882ed1d22c55e2cc5fb80e5f26f 100644 (file)
@@ -329,7 +329,7 @@ SendForm (
       //\r
       // Initialize internal data structures of FormSet\r
       //\r
-      Status = InitializeFormSet (Selection->Handle, &Selection->FormSetGuid, FormSet);\r
+      Status = InitializeFormSet (Selection->Handle, &Selection->FormSetGuid, FormSet, TRUE);\r
       if (EFI_ERROR (Status) || IsListEmpty (&FormSet->FormListHead)) {\r
         DestroyFormSet (FormSet);\r
         break;\r
@@ -1220,6 +1220,7 @@ GetQuestionValue (
 \r
   Status = EFI_SUCCESS;\r
   Value  = NULL;\r
+  Result = NULL;\r
 \r
   //\r
   // Statement don't have storage, skip them\r
@@ -1428,7 +1429,7 @@ GetQuestionValue (
       FreePool (Value);\r
     }\r
   } else {\r
-    if (Storage->Type == EFI_HII_VARSTORE_BUFFER) {\r
+    if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
       //\r
       // Request current settings from Configuration Driver\r
       //\r
@@ -1541,9 +1542,9 @@ GetQuestionValue (
           }\r
         }\r
       }\r
-      FreePool (Result);\r
 \r
       if (EFI_ERROR (Status)) {\r
+        FreePool (Result);\r
         return Status;\r
       }\r
     } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
@@ -1579,6 +1580,10 @@ GetQuestionValue (
     } else {\r
       SetValueByName (Storage, Question->VariableName, Value, TRUE);\r
     }\r
+\r
+    if (Result != NULL) {\r
+      FreePool (Result);\r
+    }\r
   }\r
 \r
   return Status;\r
@@ -1783,7 +1788,7 @@ SetQuestionValue (
   }\r
 \r
   if (!Cached) {\r
-    if (Storage->Type == EFI_HII_VARSTORE_BUFFER) {\r
+    if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
       //\r
       // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||\r
       //                <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"\r
@@ -2991,7 +2996,6 @@ ExtractDefault (
   EFI_HII_HANDLE          *HiiHandles;\r
   UINTN                   Index;\r
   EFI_GUID                ZeroGuid;\r
-  UINTN                   BackUpClassOfVfr;\r
 \r
   //\r
   // Check the supported setting level.\r
@@ -3051,7 +3055,6 @@ ExtractDefault (
     // Open all FormSet by locate HII packages.\r
     // Initiliaze the maintain FormSet to store default data as back up data.\r
     //\r
-    BackUpClassOfVfr = gClassOfVfr;\r
     BackUpFormSet    = gOldFormSet;\r
     gOldFormSet      = NULL;\r
 \r
@@ -3078,7 +3081,7 @@ ExtractDefault (
       LocalFormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET));\r
       ASSERT (LocalFormSet != NULL);\r
       ZeroMem (&ZeroGuid, sizeof (ZeroGuid));\r
-      Status = InitializeFormSet (HiiHandles[Index], &ZeroGuid, LocalFormSet);\r
+      Status = InitializeFormSet (HiiHandles[Index], &ZeroGuid, LocalFormSet, FALSE);\r
       if (EFI_ERROR (Status) || IsListEmpty (&LocalFormSet->FormListHead)) {\r
         DestroyFormSet (LocalFormSet);\r
         continue;\r
@@ -3108,7 +3111,6 @@ ExtractDefault (
     //\r
     FreePool (HiiHandles);\r
     gOldFormSet = BackUpFormSet;\r
-    gClassOfVfr = BackUpClassOfVfr;\r
        \r
     //\r
     // Set Default Value for each FormSet in the maintain list.\r
@@ -3660,6 +3662,7 @@ GetIfrBinaryData (
                                  found in package list.\r
                                  On output, GUID of the formset found(if not NULL).\r
   @param  FormSet                FormSet data structure.\r
+  @param  UpdateGlobalVar        Whether need to update the global variable.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
   @retval EFI_NOT_FOUND          The specified FormSet could not be found.\r
@@ -3669,7 +3672,8 @@ EFI_STATUS
 InitializeFormSet (\r
   IN  EFI_HII_HANDLE                   Handle,\r
   IN OUT EFI_GUID                      *FormSetGuid,\r
-  OUT FORM_BROWSER_FORMSET             *FormSet\r
+  OUT FORM_BROWSER_FORMSET             *FormSet,\r
+  IN  BOOLEAN                          UpdateGlobalVar                   \r
   )\r
 {\r
   EFI_STATUS                Status;\r
@@ -3714,6 +3718,13 @@ InitializeFormSet (
     return Status;\r
   }\r
 \r
+  // \r
+  // If not need to update the global variable, just return.\r
+  //\r
+  if (!UpdateGlobalVar) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Set VFR type by FormSet SubClass field\r
   //\r
index 168979a52ac3e60de6ca9afe1ae4438dbfdb5de2..214102c2131c9c2fb11734b29502cc2c4a903ff9 100644 (file)
@@ -1026,6 +1026,7 @@ InitializeCurrentSetting (
                                  GUID), take the first FormSet found in package\r
                                  list.\r
   @param  FormSet                FormSet data structure.\r
+  @param  UpdateGlobalVar        Whether need to update the global variable.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
   @retval EFI_NOT_FOUND          The specified FormSet could not be found.\r
@@ -1035,7 +1036,8 @@ EFI_STATUS
 InitializeFormSet (\r
   IN  EFI_HII_HANDLE                   Handle,\r
   IN OUT EFI_GUID                      *FormSetGuid,\r
-  OUT FORM_BROWSER_FORMSET             *FormSet\r
+  OUT FORM_BROWSER_FORMSET             *FormSet,\r
+  IN  BOOLEAN                          UpdateGlobalVar                   \r
   );\r
 \r
 /**\r