]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
MdeModulePkg: Use IsZeroGuid API for zero GUID checking
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Presentation.c
index 99a30bcfbfd2ee49692c4ef953dd790f018c3b8c..6856cc5d96c9da2526307506fa4a78a5b21663ce 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
 Utility functions for UI presentation.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -178,7 +179,7 @@ UpdateStatement (
 **/\r
 VOID\r
 EFIAPI\r
-RefreshEventNotify(\r
+RefreshEventNotifyForStatement(\r
   IN      EFI_EVENT Event,\r
   IN      VOID      *Context\r
   )\r
@@ -190,6 +191,23 @@ RefreshEventNotify(
   gBS->SignalEvent (mValueChangedEvent);\r
 }\r
 \r
+/**\r
+  Refresh the questions within this form.\r
+  \r
+  @param Event    The event which has this function related.\r
+  @param Context  The input context info related to this event or the status code return to the caller.\r
+**/\r
+VOID\r
+EFIAPI\r
+RefreshEventNotifyForForm(\r
+  IN      EFI_EVENT Event,\r
+  IN      VOID      *Context\r
+  )\r
+{\r
+  gCurrentSelection->Action = UI_ACTION_REFRESH_FORMSET;\r
+\r
+  gBS->SignalEvent (mValueChangedEvent);\r
+}\r
 \r
 /**\r
   Create refresh hook event for statement which has refresh event or interval.\r
@@ -198,7 +216,7 @@ RefreshEventNotify(
 \r
 **/\r
 VOID\r
-CreateRefreshEvent (\r
+CreateRefreshEventForStatement (\r
   IN     FORM_BROWSER_STATEMENT        *Statement\r
   )\r
 {\r
@@ -212,7 +230,7 @@ CreateRefreshEvent (
   Status = gBS->CreateEventEx (\r
                     EVT_NOTIFY_SIGNAL,\r
                     TPL_CALLBACK,\r
-                    RefreshEventNotify,\r
+                    RefreshEventNotifyForStatement,\r
                     Statement,\r
                     &Statement->RefreshGuid,\r
                     &RefreshEvent);\r
@@ -224,6 +242,39 @@ CreateRefreshEvent (
   InsertTailList(&mRefreshEventList, &EventNode->Link);\r
 }\r
 \r
+/**\r
+  Create refresh hook event for form which has refresh event or interval.\r
+\r
+  @param Form           The form need to check.\r
+\r
+**/\r
+VOID\r
+CreateRefreshEventForForm (\r
+  IN     FORM_BROWSER_FORM        *Form\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_EVENT                       RefreshEvent;\r
+  FORM_BROWSER_REFRESH_EVENT_NODE *EventNode;\r
+\r
+  //\r
+  // If question has refresh guid, create the notify function.\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_CALLBACK,\r
+                    RefreshEventNotifyForForm,\r
+                    Form,\r
+                    &Form->RefreshGuid,\r
+                    &RefreshEvent);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  EventNode = AllocateZeroPool (sizeof (FORM_BROWSER_REFRESH_EVENT_NODE));\r
+  ASSERT (EventNode != NULL);\r
+  EventNode->RefreshEvent = RefreshEvent;\r
+  InsertTailList(&mRefreshEventList, &EventNode->Link);\r
+}\r
+\r
 /**\r
 \r
   Initialize the Display statement structure data.\r
@@ -307,8 +358,8 @@ InitializeDisplayStatement (
   //\r
   // Create the refresh event process function.\r
   //\r
-  if (!CompareGuid (&Statement->RefreshGuid, &gZeroGuid)) {\r
-    CreateRefreshEvent (Statement);\r
+  if (!IsZeroGuid (&Statement->RefreshGuid)) {\r
+    CreateRefreshEventForStatement (Statement);\r
   }\r
 \r
   //\r
@@ -322,7 +373,7 @@ InitializeDisplayStatement (
   // Create the refresh guid hook event.\r
   // If the statement in this form has refresh event or refresh interval, browser will create this event for display engine.\r
   //\r
-  if ((!CompareGuid (&Statement->RefreshGuid, &gZeroGuid)) || (Statement->RefreshInterval != 0)) {\r
+  if ((!IsZeroGuid (&Statement->RefreshGuid)) || (Statement->RefreshInterval != 0)) {\r
     gDisplayFormData.FormRefreshEvent = mValueChangedEvent;\r
   }\r
 \r
@@ -495,6 +546,21 @@ AddStatementToDisplayForm (
     InsertTailList(&gDisplayFormData.StatementListOSF, &DisplayStatement->DisplayLink);\r
   }\r
 \r
+  //\r
+  // treat formset as statement outside the form,get its opcode.\r
+  //\r
+  DisplayStatement = AllocateZeroPool (sizeof (FORM_DISPLAY_ENGINE_STATEMENT));\r
+  ASSERT (DisplayStatement != NULL);\r
+\r
+  DisplayStatement->Signature = FORM_DISPLAY_ENGINE_STATEMENT_SIGNATURE;\r
+  DisplayStatement->Version   = FORM_DISPLAY_ENGINE_STATEMENT_VERSION_1;\r
+  DisplayStatement->OpCode = gCurrentSelection->FormSet->OpCode;\r
+\r
+  InitializeListHead (&DisplayStatement->NestStatementList);\r
+  InitializeListHead (&DisplayStatement->OptionListHead);\r
+\r
+  InsertTailList(&gDisplayFormData.StatementListOSF, &DisplayStatement->DisplayLink);\r
+\r
   //\r
   // Process the statement in this form.\r
   //\r
@@ -559,6 +625,16 @@ AddStatementToDisplayForm (
     InsertTailList(&mRefreshEventList, &EventNode->Link);\r
   }\r
 \r
+  //\r
+  // Create the refresh event process function for Form.\r
+  //\r
+  if (!IsZeroGuid (&gCurrentSelection->Form->RefreshGuid)) {\r
+    CreateRefreshEventForForm (gCurrentSelection->Form);\r
+    if (gDisplayFormData.FormRefreshEvent == NULL) {\r
+      gDisplayFormData.FormRefreshEvent = mValueChangedEvent;\r
+    }\r
+  }\r
+\r
   //\r
   // Update hotkey list field.\r
   //\r
@@ -817,6 +893,13 @@ UpdateStatementStatusForForm (
     Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);\r
     Link = GetNextNode (&Form->StatementListHead, Link);\r
 \r
+    //\r
+    // For password opcode, not set the the value changed flag.\r
+    //\r
+    if (Question->Operand == EFI_IFR_PASSWORD_OP) {\r
+      continue;\r
+    }\r
+\r
     IsQuestionValueChanged(FormSet, Form, Question, GetSetValueWithBuffer);\r
   }\r
 }\r
@@ -921,7 +1004,7 @@ ProcessAction (
   }\r
 \r
   if ((Action & BROWSER_ACTION_DEFAULT) == BROWSER_ACTION_DEFAULT) {\r
-    ExtractDefault (gCurrentSelection->FormSet, gCurrentSelection->Form, DefaultId, gBrowserSettingScope, GetDefaultForAll, NULL, FALSE);\r
+    ExtractDefault (gCurrentSelection->FormSet, gCurrentSelection->Form, DefaultId, gBrowserSettingScope, GetDefaultForAll, NULL, FALSE, FALSE);\r
     UpdateStatementStatus (gCurrentSelection->FormSet, gCurrentSelection->Form, gBrowserSettingScope);\r
   }\r
 \r
@@ -1228,15 +1311,7 @@ FindParentFormSet (
   FORM_ENTRY_INFO            *ParentMenu;\r
 \r
   CurrentMenu = Selection->CurrentMenu;\r
-  ParentMenu  = UiFindParentMenu(CurrentMenu);\r
-\r
-  //\r
-  // Find a menu which has different formset guid with current.\r
-  //\r
-  while (ParentMenu != NULL && CompareGuid (&CurrentMenu->FormSetGuid, &ParentMenu->FormSetGuid)) {\r
-    CurrentMenu = ParentMenu;\r
-    ParentMenu  = UiFindParentMenu(CurrentMenu);\r
-  }\r
+  ParentMenu  = UiFindParentMenu(CurrentMenu, FormSetLevel);\r
 \r
   if (ParentMenu != NULL) {\r
     CopyMem (&Selection->FormSetGuid, &ParentMenu->FormSetGuid, sizeof (EFI_GUID));\r
@@ -1335,7 +1410,7 @@ ProcessGotoOpCode (
     CopyMem (&Selection->FormSetGuid,&Statement->HiiValue.Value.ref.FormSetGuid, sizeof (EFI_GUID));\r
     Selection->FormId = Statement->HiiValue.Value.ref.FormId;\r
     Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId;\r
-  } else if (!CompareGuid (&Statement->HiiValue.Value.ref.FormSetGuid, &gZeroGuid)) {\r
+  } else if (!IsZeroGuid (&Statement->HiiValue.Value.ref.FormSetGuid)) {\r
     if (Selection->Form->ModalForm) {\r
       return Status;\r
     }\r
@@ -1427,6 +1502,8 @@ ProcessQuestionConfig (
   ConfigResp = GetToken (Question->QuestionConfig, Selection->FormSet->HiiHandle);\r
   if (ConfigResp == NULL) {\r
     return EFI_NOT_FOUND;\r
+  } else if (ConfigResp[0] == L'\0') {\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   //\r
@@ -1446,21 +1523,20 @@ ProcessQuestionConfig (
   Process the user input data.\r
 \r
   @param UserInput               The user input data.\r
-  @param ChangeHighlight         Whether need to change the highlight statement.  \r
 \r
   @retval EFI_SUCESSS            This function always return successfully for now.\r
 \r
 **/\r
 EFI_STATUS\r
 ProcessUserInput (\r
-  IN USER_INPUT               *UserInput,\r
-  IN BOOLEAN                  ChangeHighlight\r
+  IN USER_INPUT               *UserInput\r
   )\r
 {\r
   EFI_STATUS                    Status;\r
   FORM_BROWSER_STATEMENT        *Statement;\r
 \r
-  Status = EFI_SUCCESS;\r
+  Status    = EFI_SUCCESS;\r
+  Statement = NULL;\r
 \r
   //\r
   // When Exit from FormDisplay function, one of the below two cases must be true.\r
@@ -1471,62 +1547,35 @@ ProcessUserInput (
   // Remove the last highligh question id, this id will update when show next form.\r
   //\r
   gCurrentSelection->QuestionId = 0;\r
+  if (UserInput->SelectedStatement != NULL){\r
+    Statement = GetBrowserStatement(UserInput->SelectedStatement);\r
+    ASSERT (Statement != NULL);\r
+\r
+    //\r
+    // This question is the current user select one,record it and later\r
+    // show it as the highlight question.\r
+    //\r
+    gCurrentSelection->CurrentMenu->QuestionId = Statement->QuestionId;\r
+    //\r
+    // For statement like text, actio, it not has question id.\r
+    // So use FakeQuestionId to save the question.\r
+    //\r
+    if (gCurrentSelection->CurrentMenu->QuestionId == 0) {\r
+      mCurFakeQestId = Statement->FakeQuestionId;\r
+    } else {\r
+      mCurFakeQestId = 0;\r
+    }\r
+  }\r
 \r
   //\r
   // First process the Action field in USER_INPUT.\r
   //\r
   if (UserInput->Action != 0) {\r
     Status = ProcessAction (UserInput->Action, UserInput->DefaultId);\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
-\r
-    //\r
-    // Clear the highlight info.\r
-    //\r
     gCurrentSelection->Statement = NULL;\r
-\r
-    if (UserInput->SelectedStatement != NULL) {\r
-      Statement = GetBrowserStatement(UserInput->SelectedStatement);\r
-      ASSERT (Statement != NULL);\r
-      //\r
-      // Save the current highlight menu in the menu history data.\r
-      // which will be used when later browse back to this form.\r
-      //\r
-      gCurrentSelection->CurrentMenu->QuestionId = Statement->QuestionId;\r
-      //\r
-      // For statement like text, actio, it not has question id.\r
-      // So use FakeQuestionId to save the question.\r
-      //\r
-      if (gCurrentSelection->CurrentMenu->QuestionId == 0) {\r
-        mCurFakeQestId = Statement->FakeQuestionId;\r
-      } else {\r
-        mCurFakeQestId = 0;\r
-      }\r
-    }\r
   } else {\r
-    Statement = GetBrowserStatement(UserInput->SelectedStatement);\r
     ASSERT (Statement != NULL);\r
-\r
     gCurrentSelection->Statement = Statement;\r
-\r
-    if (ChangeHighlight) {\r
-      //\r
-      // This question is the current user select one,record it and later\r
-      // show it as the highlight question.\r
-      //\r
-      gCurrentSelection->CurrentMenu->QuestionId = Statement->QuestionId;\r
-      //\r
-      // For statement like text, actio, it not has question id.\r
-      // So use FakeQuestionId to save the question.\r
-      //\r
-      if (gCurrentSelection->CurrentMenu->QuestionId == 0) {\r
-        mCurFakeQestId = Statement->FakeQuestionId;\r
-      } else {\r
-        mCurFakeQestId = 0;\r
-      }\r
-    }\r
-\r
     switch (Statement->Operand) {\r
     case EFI_IFR_REF_OP:\r
       Status = ProcessGotoOpCode(Statement, gCurrentSelection);\r
@@ -1543,7 +1592,7 @@ ProcessUserInput (
       //\r
       // Reset Question to default value specified by DefaultId\r
       //\r
-      Status = ExtractDefault (gCurrentSelection->FormSet, NULL, Statement->DefaultId, FormSetLevel, GetDefaultForAll, NULL, FALSE);\r
+      Status = ExtractDefault (gCurrentSelection->FormSet, NULL, Statement->DefaultId, FormSetLevel, GetDefaultForAll, NULL, FALSE, FALSE);\r
       UpdateStatementStatus (gCurrentSelection->FormSet, NULL, FormSetLevel);\r
       break;\r
 \r
@@ -1613,7 +1662,6 @@ DisplayForm (
   EFI_STATUS               Status;\r
   USER_INPUT               UserInput;\r
   FORM_ENTRY_INFO          *CurrentMenu;\r
-  BOOLEAN                  ChangeHighlight;\r
 \r
   ZeroMem (&UserInput, sizeof (USER_INPUT));\r
 \r
@@ -1637,9 +1685,6 @@ DisplayForm (
 \r
   gCurrentSelection->CurrentMenu = CurrentMenu;\r
 \r
-  //\r
-  // Find currrent highlight statement.\r
-  //\r
   if (gCurrentSelection->QuestionId == 0) {\r
     //\r
     // Highlight not specified, fetch it from cached menu\r
@@ -1647,9 +1692,6 @@ DisplayForm (
     gCurrentSelection->QuestionId = CurrentMenu->QuestionId;\r
   }\r
 \r
-  //\r
-  // Evaluate all the Expressions in this Form\r
-  //\r
   Status = EvaluateFormExpressions (gCurrentSelection->FormSet, gCurrentSelection->Form);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -1657,34 +1699,15 @@ DisplayForm (
 \r
   UpdateDisplayFormData ();\r
 \r
-  //\r
-  // Three possible status maybe return.\r
-  //\r
-  // EFI_INVALID_PARAMETER: The input dimension info is not valid.\r
-  // EFI_NOT_FOUND:         The input value for oneof/orderedlist opcode is not valid\r
-  //                        and an valid value has return.\r
-  // EFI_SUCCESS:           Success shows form and get user input in UserInput paramenter.\r
-  //\r
   ASSERT (gDisplayFormData.BrowserStatus == BROWSER_SUCCESS);\r
   Status = mFormDisplay->FormDisplay (&gDisplayFormData, &UserInput);\r
-  if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {\r
+  if (EFI_ERROR (Status)) {\r
     FreeDisplayFormData();\r
     return Status;\r
   }\r
 \r
-  //\r
-  // If status is EFI_SUCCESS, means user has change the highlight menu and new user input return.\r
-  //                           in this case, browser need to change the highlight menu.\r
-  // If status is EFI_NOT_FOUND, means the input DisplayFormData has error for oneof/orderedlist \r
-  //                          opcode and new valid value has return, browser core need to adjust\r
-  //                          value for this opcode and shows this form again.\r
-  //\r
-  ChangeHighlight = (Status == EFI_SUCCESS ? TRUE :FALSE);\r
-\r
-  Status = ProcessUserInput (&UserInput, ChangeHighlight);\r
-\r
+  Status = ProcessUserInput (&UserInput);\r
   FreeDisplayFormData();\r
-\r
   return Status;\r
 }\r
 \r
@@ -1812,7 +1835,7 @@ IsNvUpdateRequiredForForm (
 BOOLEAN\r
 FindNextMenu (\r
   IN OUT UI_MENU_SELECTION        *Selection,\r
-  IN       BROWSER_SETTING_SCOPE  SettingLevel\r
+  IN     BROWSER_SETTING_SCOPE     SettingLevel\r
   )\r
 {\r
   FORM_ENTRY_INFO            *CurrentMenu;\r
@@ -1820,31 +1843,16 @@ FindNextMenu (
   BROWSER_SETTING_SCOPE      Scope;\r
   \r
   CurrentMenu = Selection->CurrentMenu;\r
-  ParentMenu  = NULL;\r
   Scope       = FormSetLevel;\r
 \r
-  if (CurrentMenu != NULL && (ParentMenu = UiFindParentMenu(CurrentMenu)) != NULL) {\r
-    //\r
-    // we have a parent, so go to the parent menu\r
-    //\r
-    if (CompareGuid (&CurrentMenu->FormSetGuid, &ParentMenu->FormSetGuid)) {\r
-      if (SettingLevel == FormSetLevel) {\r
-        //\r
-        // Find a menu which has different formset guid with current.\r
-        //\r
-        while (CompareGuid (&CurrentMenu->FormSetGuid, &ParentMenu->FormSetGuid)) {\r
-          CurrentMenu = ParentMenu;\r
-          if ((ParentMenu = UiFindParentMenu(CurrentMenu)) == NULL) {\r
-            break;\r
-          }\r
-        }\r
+  ParentMenu = UiFindParentMenu(CurrentMenu, SettingLevel);\r
+  while (ParentMenu != NULL && !ValidateHiiHandle(ParentMenu->HiiHandle)) {\r
+    ParentMenu = UiFindParentMenu(ParentMenu, SettingLevel);\r
+  }\r
 \r
-        if (ParentMenu != NULL) {\r
-          Scope = FormSetLevel;\r
-        }\r
-      } else {\r
-        Scope = FormLevel;\r
-      }\r
+  if (ParentMenu != NULL) {\r
+    if (CompareGuid (&CurrentMenu->FormSetGuid, &ParentMenu->FormSetGuid)) {\r
+      Scope = FormLevel;\r
     } else {\r
       Scope = FormSetLevel;\r
     }\r
@@ -1892,6 +1900,30 @@ FindNextMenu (
   return TRUE;\r
 }\r
 \r
+/**\r
+  Reconnect the controller.\r
+\r
+  @param DriverHandle          The controller handle which need to be reconnect.\r
+\r
+  @retval   TRUE     do the reconnect behavior success.\r
+  @retval   FALSE    do the reconnect behavior failed.\r
+  \r
+**/\r
+BOOLEAN\r
+ReconnectController (\r
+  IN EFI_HANDLE   DriverHandle\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+\r
+  Status = gBS->DisconnectController(DriverHandle, NULL, NULL);\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->ConnectController(DriverHandle, NULL, NULL, TRUE);\r
+  }\r
+\r
+  return Status == EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Call the call back function for the question and process the return action.\r
 \r
@@ -1919,6 +1951,7 @@ ProcessCallBackFunction (
   )\r
 {\r
   EFI_STATUS                      Status;\r
+  EFI_STATUS                      InternalStatus;\r
   EFI_BROWSER_ACTION_REQUEST      ActionRequest;\r
   EFI_HII_CONFIG_ACCESS_PROTOCOL  *ConfigAccess;\r
   EFI_HII_VALUE                   *HiiValue;\r
@@ -2011,6 +2044,7 @@ ProcessCallBackFunction (
 \r
         ASSERT (StrLen (NewString) * sizeof (CHAR16) <= Statement->StorageWidth);\r
         if (StrLen (NewString) * sizeof (CHAR16) <= Statement->StorageWidth) {\r
+          ZeroMem (Statement->BufferValue, Statement->StorageWidth);\r
           CopyMem (Statement->BufferValue, NewString, StrSize (NewString));\r
         } else {\r
           CopyMem (Statement->BufferValue, NewString, Statement->StorageWidth);\r
@@ -2062,6 +2096,10 @@ ProcessCallBackFunction (
           SettingLevel          = FormLevel;\r
           break;\r
 \r
+        case EFI_BROWSER_ACTION_REQUEST_RECONNECT:\r
+          gCallbackReconnect    = TRUE;\r
+          break;\r
+\r
         default:\r
           break;\r
         }\r
@@ -2073,6 +2111,11 @@ ProcessCallBackFunction (
         //\r
         Status = ValueChangedValidation (gCurrentSelection->FormSet, gCurrentSelection->Form, Statement);\r
         if (!EFI_ERROR (Status)) {\r
+          //\r
+          //check whether the question value  changed compared with edit buffer before updating edit buffer\r
+          // if changed, set the ValueChanged flag to TRUE,in order to trig the CHANGED callback function\r
+          //\r
+          IsQuestionValueChanged(gCurrentSelection->FormSet, gCurrentSelection->Form, Statement, GetSetValueWithEditBuffer);\r
           //\r
           // According the spec, return value from call back of "changing" and \r
           // "retrieve" should update to the question's temp buffer.\r
@@ -2108,8 +2151,13 @@ ProcessCallBackFunction (
         //\r
         // Do the question validation.\r
         //\r
-        Status = ValueChangedValidation (gCurrentSelection->FormSet, gCurrentSelection->Form, Statement);\r
-        if (!EFI_ERROR (Status)) {\r
+        InternalStatus = ValueChangedValidation (gCurrentSelection->FormSet, gCurrentSelection->Form, Statement);\r
+        if (!EFI_ERROR (InternalStatus)) {\r
+          //\r
+          //check whether the question value  changed compared with edit buffer before updating edit buffer\r
+          // if changed, set the ValueChanged flag to TRUE,in order to trig the CHANGED callback function\r
+          //\r
+          IsQuestionValueChanged(gCurrentSelection->FormSet, gCurrentSelection->Form, Statement, GetSetValueWithEditBuffer);\r
           SetQuestionValue(FormSet, Form, Statement, GetSetValueWithEditBuffer);\r
         }\r
       }\r
@@ -2118,8 +2166,15 @@ ProcessCallBackFunction (
       // According the spec, return fail from call back of "changing" and \r
       // "retrieve", should restore the question's value.\r
       //\r
-      if ((Action == EFI_BROWSER_ACTION_CHANGING && Status != EFI_UNSUPPORTED) || \r
-           Action == EFI_BROWSER_ACTION_RETRIEVE) {\r
+      if (Action == EFI_BROWSER_ACTION_CHANGING && Status != EFI_UNSUPPORTED) {\r
+        if (Statement->Storage != NULL) {\r
+          GetQuestionValue(FormSet, Form, Statement, GetSetValueWithEditBuffer);\r
+        } else if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
+          ProcessCallBackFunction (Selection, FormSet, Form, Question, EFI_BROWSER_ACTION_RETRIEVE, FALSE);\r
+        }\r
+      }\r
+\r
+      if (Action == EFI_BROWSER_ACTION_RETRIEVE) {\r
         GetQuestionValue(FormSet, Form, Statement, GetSetValueWithEditBuffer);\r
       }\r
 \r
@@ -2134,6 +2189,37 @@ ProcessCallBackFunction (
     if (BackUpBuffer != NULL) {\r
       FreePool (BackUpBuffer);\r
     }\r
+\r
+    //\r
+    // If Question != NULL, means just process one question\r
+    // and if code reach here means this question has finished\r
+    // processing, so just break.\r
+    //\r
+    if (Question != NULL) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (gCallbackReconnect && (EFI_BROWSER_ACTION_CHANGED == Action)) {\r
+    //\r
+    // Confirm changes with user first.\r
+    //\r
+    if (IsNvUpdateRequiredForFormSet(FormSet)) {\r
+      if (BROWSER_ACTION_DISCARD == PopupErrorMessage(BROWSER_RECONNECT_SAVE_CHANGES, NULL, NULL, NULL)) {\r
+        gCallbackReconnect = FALSE;\r
+        DiscardFormIsRequired = TRUE;\r
+      } else {\r
+        SubmitFormIsRequired = TRUE;\r
+      }\r
+    } else {\r
+      PopupErrorMessage(BROWSER_RECONNECT_REQUIRED, NULL, NULL, NULL);\r
+    }\r
+\r
+    //\r
+    // Exit current formset before do the reconnect.\r
+    //\r
+    NeedExit = TRUE;\r
+    SettingLevel = FormSetLevel;\r
   }\r
 \r
   if (SubmitFormIsRequired && !SkipSaveOrDiscard) {\r
@@ -2208,6 +2294,7 @@ ProcessRetrieveForQuestion (
 \r
     ASSERT (StrLen (NewString) * sizeof (CHAR16) <= Statement->StorageWidth);\r
     if (StrLen (NewString) * sizeof (CHAR16) <= Statement->StorageWidth) {\r
+      ZeroMem (Statement->BufferValue, Statement->StorageWidth);\r
       CopyMem (Statement->BufferValue, NewString, StrSize (NewString));\r
     } else {\r
       CopyMem (Statement->BufferValue, NewString, Statement->StorageWidth);\r
@@ -2275,8 +2362,16 @@ SetupBrowser (
   mCurFakeQestId = 0;\r
 \r
   do {\r
+\r
+    //\r
+    // Reset Status to prevent the next break from returning incorrect error status.\r
+    //\r
+    Status = EFI_SUCCESS;\r
+\r
     //\r
     // IFR is updated, force to reparse the IFR binary\r
+    // This check is shared by EFI_BROWSER_ACTION_FORM_CLOSE and \r
+    // EFI_BROWSER_ACTION_RETRIEVE, so code place here.\r
     //\r
     if (mHiiPackageListUpdated) {\r
       Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
@@ -2348,7 +2443,7 @@ SetupBrowser (
         }\r
 \r
         //\r
-        // IFR is updated during callback of open form, force to reparse the IFR binary\r
+        // IFR is updated during callback of EFI_BROWSER_ACTION_FORM_OPEN, force to reparse the IFR binary\r
         //\r
         if (mHiiPackageListUpdated) {\r
           Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
@@ -2419,20 +2514,29 @@ SetupBrowser (
           //\r
           if (EFI_ERROR (Status)) {\r
             //\r
-            // Cross reference will not be taken\r
+            // Cross reference will not be taken, restore all essential field\r
             //\r
-            Selection->FormId = Selection->Form->FormId;\r
+            Selection->Handle = mCurrentHiiHandle;\r
+            CopyMem (&Selection->FormSetGuid, &mCurrentFormSetGuid, sizeof (EFI_GUID));\r
+            Selection->FormId = mCurrentFormId;\r
             Selection->QuestionId = 0;\r
+            Selection->Action = UI_ACTION_REFRESH_FORM;\r
           }\r
         }\r
 \r
-        //\r
-        // Verify whether question value has checked, update the ValueChanged flag in Question.\r
-        //\r
-        IsQuestionValueChanged(gCurrentSelection->FormSet, gCurrentSelection->Form, Statement, GetSetValueWithBuffer);\r
 \r
-        if (!EFI_ERROR (Status) && Statement->Operand != EFI_IFR_REF_OP) {\r
+        if (!EFI_ERROR (Status) && \r
+            (Statement->Operand != EFI_IFR_REF_OP) && \r
+            ((Statement->Storage == NULL) || (Statement->Storage != NULL && Statement->ValueChanged))) {\r
+          //\r
+          // Only question value has been changed, browser will trig CHANGED callback.\r
+          //\r
           ProcessCallBackFunction(Selection, Selection->FormSet, Selection->Form, Statement, EFI_BROWSER_ACTION_CHANGED, FALSE);\r
+          //\r
+          //check whether the question value changed compared with buffer value\r
+          //if doesn't change ,set the ValueChanged flag to FALSE ,in order not to display the "configuration changed "information on the screen\r
+          //\r
+          IsQuestionValueChanged(gCurrentSelection->FormSet, gCurrentSelection->Form, Statement, GetSetValueWithBuffer);\r
         }\r
       } else {\r
         //\r
@@ -2449,13 +2553,18 @@ SetupBrowser (
       }\r
 \r
       //\r
-      // If question has EFI_IFR_FLAG_RESET_REQUIRED flag and without storage and process question success till here, \r
-      // trig the gResetFlag.\r
+      // If question has EFI_IFR_FLAG_RESET_REQUIRED/EFI_IFR_FLAG_RECONNECT_REQUIRED flag and without storage \r
+      // and process question success till here, trig the gResetFlag/gFlagReconnect.\r
       //\r
       if ((Status == EFI_SUCCESS) && \r
-          (Statement->Storage == NULL) && \r
-          ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) != 0)) {\r
-        gResetRequired = TRUE;\r
+          (Statement->Storage == NULL)) { \r
+        if ((Statement->QuestionFlags & EFI_IFR_FLAG_RESET_REQUIRED) != 0) {\r
+          gResetRequired = TRUE;\r
+        }\r
+\r
+        if ((Statement->QuestionFlags & EFI_IFR_FLAG_RECONNECT_REQUIRED) != 0) {\r
+          gFlagReconnect = TRUE;\r
+        }\r
       }\r
     }\r
 \r