]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
Update the browser logic, make the storage as browser level instead of form set level.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Setup.c
index f4081679c633c123a910dd4c337687dd49ecb0b1..b077a3c0a0335d29ee62788629e478ab777d0b51 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Entry and initialization module for the browser.\r
 \r
-Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<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
@@ -20,15 +20,25 @@ SETUP_DRIVER_PRIVATE_DATA  mPrivateData = {
   {\r
     SendForm,\r
     BrowserCallback\r
+  },\r
+  {\r
+    SetScope,\r
+    RegisterHotKey,\r
+    RegiserExitHandler,\r
+    SaveReminder\r
   }\r
 };\r
 \r
 EFI_HII_DATABASE_PROTOCOL         *mHiiDatabase;\r
 EFI_HII_STRING_PROTOCOL           *mHiiString;\r
 EFI_HII_CONFIG_ROUTING_PROTOCOL   *mHiiConfigRouting;\r
+EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mPathFromText;\r
 \r
 UINTN           gBrowserContextCount = 0;\r
 LIST_ENTRY      gBrowserContextList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserContextList);\r
+LIST_ENTRY      gBrowserFormSetList = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserFormSetList);\r
+LIST_ENTRY      gBrowserHotKeyList  = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserHotKeyList);\r
+LIST_ENTRY      gBrowserStorageList  = INITIALIZE_LIST_HEAD_VARIABLE (gBrowserStorageList);\r
 \r
 BANNER_DATA           *gBannerData;\r
 EFI_HII_HANDLE        gFrontPageHandle;\r
@@ -38,17 +48,21 @@ BOOLEAN               gResetRequired;
 EFI_HII_HANDLE        gHiiHandle;\r
 UINT16                gDirection;\r
 EFI_SCREEN_DESCRIPTOR gScreenDimensions;\r
+BROWSER_SETTING_SCOPE gBrowserSettingScope = FormSetLevel;\r
+BOOLEAN               mBrowserScopeFirstSet = TRUE;\r
+EXIT_HANDLER          ExitHandlerFunction = NULL;\r
+UINTN                 gFooterHeight;\r
 \r
 //\r
 // Browser Global Strings\r
 //\r
-CHAR16            *gFunctionNineString;\r
-CHAR16            *gFunctionTenString;\r
+CHAR16            *gSaveFailed;\r
+CHAR16            *gDiscardFailed;\r
+CHAR16            *gDefaultFailed;\r
 CHAR16            *gEnterString;\r
 CHAR16            *gEnterCommitString;\r
 CHAR16            *gEnterEscapeString;\r
 CHAR16            *gEscapeString;\r
-CHAR16            *gSaveFailed;\r
 CHAR16            *gMoveHighlight;\r
 CHAR16            *gMakeSelection;\r
 CHAR16            *gDecNumericInput;\r
@@ -72,6 +86,7 @@ CHAR16            *gAdjustNumber;
 CHAR16            *gSaveChanges;\r
 CHAR16            *gOptionMismatch;\r
 CHAR16            *gFormSuppress;\r
+CHAR16            *gProtocolNotFound;\r
 \r
 CHAR16            *mUnknownString = L"!";\r
 \r
@@ -84,7 +99,7 @@ EFI_GUID  gSetupBrowserGuid = {
   0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}\r
 };\r
 \r
-FORM_BROWSER_FORMSET  *gOldFormSet;\r
+FORM_BROWSER_FORMSET  *gOldFormSet = NULL;\r
 \r
 FUNCTIION_KEY_SETTING gFunctionKeySettingTable[] = {\r
   //\r
@@ -214,12 +229,33 @@ SendForm (
   UI_MENU_SELECTION             *Selection;\r
   UINTN                         Index;\r
   FORM_BROWSER_FORMSET          *FormSet;\r
+  LIST_ENTRY                    *Link;\r
+\r
+  //\r
+  // Calculate total number of Register HotKeys. \r
+  //\r
+  Index = 0;\r
+  Link  = GetFirstNode (&gBrowserHotKeyList);\r
+  while (!IsNull (&gBrowserHotKeyList, Link)) {\r
+    Link = GetNextNode (&gBrowserHotKeyList, Link);\r
+    Index ++;\r
+  }\r
+  //\r
+  // Show three HotKeys help information on one ROW.\r
+  //\r
+  gFooterHeight = FOOTER_HEIGHT + (Index / 3);\r
+\r
+  //\r
+  // Clean the history menu list.\r
+  //\r
+  InitializeListHead (&gMenuList);\r
 \r
   //\r
   // Save globals used by SendForm()\r
   //\r
   SaveBrowserContext ();\r
 \r
+  gResetRequired = FALSE;\r
   Status = EFI_SUCCESS;\r
   ZeroMem (&gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
 \r
@@ -254,7 +290,7 @@ SendForm (
             SCROLL_ARROW_HEIGHT *\r
             2 +\r
             FRONT_PAGE_HEADER_HEIGHT +\r
-            FOOTER_HEIGHT +\r
+            gFooterHeight +\r
             1\r
           )\r
         ) {\r
@@ -275,8 +311,6 @@ SendForm (
   //\r
   InitializeBrowserStrings ();\r
 \r
-  gFunctionKeySetting = DEFAULT_FUNCTION_KEY_SETTING;\r
-\r
   //\r
   // Ensure we are in Text mode\r
   //\r
@@ -290,10 +324,10 @@ SendForm (
     if (FormSetGuid != NULL) {\r
       CopyMem (&Selection->FormSetGuid, FormSetGuid, sizeof (EFI_GUID));\r
       Selection->FormId = FormId;\r
+    } else {\r
+      CopyMem (&Selection->FormSetGuid, &gEfiHiiPlatformSetupFormsetGuid, sizeof (EFI_GUID));\r
     }\r
 \r
-    gOldFormSet = NULL;\r
-\r
     do {\r
       FormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET));\r
       ASSERT (FormSet != NULL);\r
@@ -301,13 +335,18 @@ 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
       }\r
       Selection->FormSet = FormSet;\r
 \r
+      //\r
+      // Try to find pre FormSet in the maintain backup list.\r
+      //\r
+      gOldFormSet = GetFormSetFromHiiHandle (Selection->Handle);\r
+\r
       //\r
       // Display this formset\r
       //\r
@@ -324,7 +363,13 @@ SendForm (
     } while (Selection->Action == UI_ACTION_REFRESH_FORMSET);\r
 \r
     if (gOldFormSet != NULL) {\r
-      DestroyFormSet (gOldFormSet);\r
+      //\r
+      // If no data is changed, don't need to save current FormSet into the maintain list.\r
+      //\r
+      if (!IsNvUpdateRequired (gOldFormSet)) {\r
+        RemoveEntryList (&gOldFormSet->Link);\r
+        DestroyFormSet (gOldFormSet);\r
+      }\r
       gOldFormSet = NULL;\r
     }\r
 \r
@@ -339,6 +384,7 @@ SendForm (
   }\r
 \r
   FreeBrowserStrings ();\r
+  UiFreeMenuList(&gMenuList);\r
 \r
   gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
   gST->ConOut->ClearScreen (gST->ConOut);\r
@@ -430,8 +476,9 @@ BrowserCallback (
       Storage = FORMSET_STORAGE_FROM_LINK (Link);\r
       Link = GetNextNode (&FormSet->StorageListHead, Link);\r
 \r
-      if (CompareGuid (&Storage->Guid, (EFI_GUID *) VariableGuid)) {\r
-        if (Storage->Type == EFI_HII_VARSTORE_BUFFER) {\r
+      if (CompareGuid (&Storage->BrowserStorage->Guid, (EFI_GUID *) VariableGuid)) {\r
+        if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_BUFFER ||\r
+            Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
           //\r
           // Buffer storage require both GUID and Name\r
           //\r
@@ -439,7 +486,7 @@ BrowserCallback (
             return EFI_NOT_FOUND;\r
           }\r
 \r
-          if (StrCmp (Storage->Name, (CHAR16 *) VariableName) != 0) {\r
+          if (StrCmp (Storage->BrowserStorage->Name, (CHAR16 *) VariableName) != 0) {\r
             continue;\r
           }\r
         }\r
@@ -469,7 +516,7 @@ BrowserCallback (
     //\r
     // Generate <ConfigResp>\r
     //\r
-    Status = StorageToConfigResp (Storage, &ConfigResp, FALSE);\r
+    Status = StorageToConfigResp (Storage->BrowserStorage, &ConfigResp, Storage->ConfigRequest);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -477,7 +524,7 @@ BrowserCallback (
     //\r
     // Skip <ConfigHdr> and '&' to point to <ConfigBody>\r
     //\r
-    StrPtr = ConfigResp + StrLen (Storage->ConfigHdr) + 1;\r
+    StrPtr = ConfigResp + StrLen (Storage->BrowserStorage->ConfigHdr) + 1;\r
 \r
     BufferSize = StrSize (StrPtr);\r
     if (*ResultsDataSize < BufferSize) {\r
@@ -496,18 +543,18 @@ BrowserCallback (
     // Prepare <ConfigResp>\r
     //\r
     TmpSize = StrLen (ResultsData);\r
-    BufferSize = (TmpSize + StrLen (Storage->ConfigHdr) + 2) * sizeof (CHAR16);\r
+    BufferSize = (TmpSize + StrLen (Storage->BrowserStorage->ConfigHdr) + 2) * sizeof (CHAR16);\r
     ConfigResp = AllocateZeroPool (BufferSize);\r
     ASSERT (ConfigResp != NULL);\r
 \r
-    StrCpy (ConfigResp, Storage->ConfigHdr);\r
+    StrCpy (ConfigResp, Storage->BrowserStorage->ConfigHdr);\r
     StrCat (ConfigResp, L"&");\r
     StrCat (ConfigResp, ResultsData);\r
 \r
     //\r
     // Update Browser uncommited data\r
     //\r
-    Status = ConfigRespToStorage (Storage, ConfigResp);\r
+    Status = ConfigRespToStorage (Storage->BrowserStorage, ConfigResp);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -516,7 +563,6 @@ BrowserCallback (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Initialize Setup Browser driver.\r
 \r
@@ -535,6 +581,8 @@ InitializeSetup (
   )\r
 {\r
   EFI_STATUS                  Status;\r
+  EFI_INPUT_KEY               DefaultHotKey;\r
+  EFI_STRING                  HelpString;\r
 \r
   //\r
   // Locate required Hii relative protocols\r
@@ -560,6 +608,12 @@ InitializeSetup (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiDevicePathFromTextProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &mPathFromText\r
+                  );\r
+\r
   //\r
   // Publish our HII data\r
   //\r
@@ -576,6 +630,13 @@ InitializeSetup (
   //\r
   gBannerData = AllocateZeroPool (sizeof (BANNER_DATA));\r
   ASSERT (gBannerData != NULL);\r
+  \r
+  //\r
+  // Initialize generic help strings.\r
+  //\r
+  gSaveFailed    = GetToken (STRING_TOKEN (SAVE_FAILED), gHiiHandle);\r
+  gDiscardFailed = GetToken (STRING_TOKEN (DISCARD_FAILED), gHiiHandle);\r
+  gDefaultFailed = GetToken (STRING_TOKEN (DEFAULT_FAILED), gHiiHandle);\r
 \r
   //\r
   // Install FormBrowser2 protocol\r
@@ -589,6 +650,34 @@ InitializeSetup (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Install default HotKey F10 for Save\r
+  //\r
+  DefaultHotKey.UnicodeChar = CHAR_NULL;\r
+  HelpString             = GetToken (STRING_TOKEN (FUNCTION_TEN_STRING), gHiiHandle);\r
+  DefaultHotKey.ScanCode = SCAN_F10;\r
+  RegisterHotKey (&DefaultHotKey, BROWSER_ACTION_SUBMIT, 0, HelpString);\r
+  FreePool (HelpString);\r
+  //\r
+  // Install default HotKey F9 for Reset To Defaults\r
+  //\r
+  DefaultHotKey.ScanCode    = SCAN_F9;\r
+  HelpString                = GetToken (STRING_TOKEN (FUNCTION_NINE_STRING), gHiiHandle);\r
+  RegisterHotKey (&DefaultHotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, HelpString);\r
+  FreePool (HelpString);\r
+\r
+  //\r
+  // Install FormBrowserEx protocol\r
+  //\r
+  mPrivateData.Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &mPrivateData.Handle,\r
+                  &gEfiFormBrowserExProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mPrivateData.FormBrowserEx\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return Status;\r
 }\r
 \r
@@ -665,7 +754,7 @@ GetToken (
 \r
   String = HiiGetString (HiiHandle, Token, NULL);\r
   if (String == NULL) {\r
-    String = AllocateCopyPool (sizeof (mUnknownString), mUnknownString);\r
+    String = AllocateCopyPool (StrSize (mUnknownString), mUnknownString);\r
     ASSERT (String != NULL);\r
   }\r
   return (CHAR16 *) String;\r
@@ -727,14 +816,19 @@ NewStringCat (
 \r
 \r
 /**\r
-  Synchronize Storage's Edit copy to Shadow copy.\r
+  Synchronize or restore Storage's Edit copy and Shadow copy.\r
 \r
-  @param  Storage                The Storage to be synchronized.\r
+  @param  Storage          The Storage to be synchronized.\r
+  @param  SyncOrRestore    Sync the buffer to editbuffer or Restore  the \r
+                           editbuffer to buffer\r
+                           if TRUE, copy the editbuffer to the buffer.\r
+                           if FALSE, copy the buffer to the editbuffer.\r
 \r
 **/\r
 VOID\r
 SynchronizeStorage (\r
-  IN FORMSET_STORAGE         *Storage\r
+  IN BROWSER_STORAGE         *Storage,\r
+  IN BOOLEAN                 SyncOrRestore\r
   )\r
 {\r
   LIST_ENTRY              *Link;\r
@@ -742,7 +836,12 @@ SynchronizeStorage (
 \r
   switch (Storage->Type) {\r
   case EFI_HII_VARSTORE_BUFFER:\r
-    CopyMem (Storage->Buffer, Storage->EditBuffer, Storage->Size);\r
+  case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER:\r
+    if (SyncOrRestore) {\r
+      CopyMem (Storage->Buffer, Storage->EditBuffer, Storage->Size);\r
+    } else {\r
+      CopyMem (Storage->EditBuffer, Storage->Buffer, Storage->Size);\r
+    }\r
     break;\r
 \r
   case EFI_HII_VARSTORE_NAME_VALUE:\r
@@ -750,7 +849,11 @@ SynchronizeStorage (
     while (!IsNull (&Storage->NameValueListHead, Link)) {\r
       Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
 \r
-      NewStringCpy (&Node->Value, Node->EditValue);\r
+      if (SyncOrRestore) {\r
+        NewStringCpy (&Node->Value, Node->EditValue);\r
+      } else {\r
+        NewStringCpy (&Node->EditValue, Node->Value);\r
+      }\r
 \r
       Link = GetNextNode (&Storage->NameValueListHead, Link);\r
     }\r
@@ -769,6 +872,7 @@ SynchronizeStorage (
   @param  Storage                The NameValue Storage.\r
   @param  Name                   The Name.\r
   @param  Value                  The retured Value.\r
+  @param  GetValueFrom           Where to get source value, from EditValue or Value.\r
 \r
   @retval EFI_SUCCESS            Value found for given Name.\r
   @retval EFI_NOT_FOUND          No such Name found in NameValue storage.\r
@@ -776,14 +880,19 @@ SynchronizeStorage (
 **/\r
 EFI_STATUS\r
 GetValueByName (\r
-  IN FORMSET_STORAGE         *Storage,\r
-  IN CHAR16                  *Name,\r
-  IN OUT CHAR16              **Value\r
+  IN BROWSER_STORAGE             *Storage,\r
+  IN CHAR16                      *Name,\r
+  IN OUT CHAR16                  **Value,\r
+  IN GET_SET_QUESTION_VALUE_WITH GetValueFrom\r
   )\r
 {\r
   LIST_ENTRY              *Link;\r
   NAME_VALUE_NODE         *Node;\r
 \r
+  if (GetValueFrom != GetSetValueWithEditBuffer && GetValueFrom != GetSetValueWithBuffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   *Value = NULL;\r
 \r
   Link = GetFirstNode (&Storage->NameValueListHead);\r
@@ -791,7 +900,11 @@ GetValueByName (
     Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
 \r
     if (StrCmp (Name, Node->Name) == 0) {\r
-      NewStringCpy (Value, Node->EditValue);\r
+      if (GetValueFrom == GetSetValueWithEditBuffer) {\r
+        NewStringCpy (Value, Node->EditValue);\r
+      } else {\r
+        NewStringCpy (Value, Node->Value);\r
+      }\r
       return EFI_SUCCESS;\r
     }\r
 \r
@@ -808,7 +921,7 @@ GetValueByName (
   @param  Storage                The NameValue Storage.\r
   @param  Name                   The Name.\r
   @param  Value                  The Value to set.\r
-  @param  Edit                   Whether update editValue or Value.\r
+  @param  SetValueTo             Whether update editValue or Value.\r
 \r
   @retval EFI_SUCCESS            Value found for given Name.\r
   @retval EFI_NOT_FOUND          No such Name found in NameValue storage.\r
@@ -816,22 +929,26 @@ GetValueByName (
 **/\r
 EFI_STATUS\r
 SetValueByName (\r
-  IN FORMSET_STORAGE         *Storage,\r
+  IN BROWSER_STORAGE         *Storage,\r
   IN CHAR16                  *Name,\r
   IN CHAR16                  *Value,\r
-  IN BOOLEAN                 Edit\r
+  IN GET_SET_QUESTION_VALUE_WITH SetValueTo\r
   )\r
 {\r
   LIST_ENTRY              *Link;\r
   NAME_VALUE_NODE         *Node;\r
   CHAR16                  *Buffer;\r
 \r
+  if (SetValueTo != GetSetValueWithEditBuffer && SetValueTo != GetSetValueWithBuffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   Link = GetFirstNode (&Storage->NameValueListHead);\r
   while (!IsNull (&Storage->NameValueListHead, Link)) {\r
     Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
 \r
     if (StrCmp (Name, Node->Name) == 0) {\r
-      if (Edit) {\r
+      if (SetValueTo == GetSetValueWithEditBuffer) {\r
         Buffer = Node->EditValue;\r
       } else {\r
         Buffer = Node->Value;\r
@@ -841,7 +958,7 @@ SetValueByName (
       }\r
       Buffer = AllocateCopyPool (StrSize (Value), Value);\r
       ASSERT (Buffer != NULL);\r
-      if (Edit) {\r
+      if (SetValueTo == GetSetValueWithEditBuffer) {\r
         Node->EditValue = Buffer;\r
       } else {\r
         Node->Value = Buffer;\r
@@ -859,9 +976,9 @@ SetValueByName (
 /**\r
   Convert setting of Buffer Storage or NameValue Storage to <ConfigResp>.\r
 \r
-  @param  Buffer                 The Storage to be conveted.\r
+  @param  Storage                The Storage to be conveted.\r
   @param  ConfigResp             The returned <ConfigResp>.\r
-  @param  SingleForm             Whether update data for single form or formset level.\r
+  @param  ConfigRequest          The ConfigRequest string.\r
 \r
   @retval EFI_SUCCESS            Convert success.\r
   @retval EFI_INVALID_PARAMETER  Incorrect storage type.\r
@@ -869,31 +986,21 @@ SetValueByName (
 **/\r
 EFI_STATUS\r
 StorageToConfigResp (\r
-  IN VOID                    *Buffer,\r
+  IN BROWSER_STORAGE         *Storage,\r
   IN CHAR16                  **ConfigResp,\r
-  IN BOOLEAN                 SingleForm\r
+  IN CHAR16                  *ConfigRequest\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  EFI_STRING  Progress;\r
+  EFI_STATUS              Status;\r
+  EFI_STRING              Progress;\r
   LIST_ENTRY              *Link;\r
   NAME_VALUE_NODE         *Node;\r
-  CHAR16                  *ConfigRequest;\r
-  FORMSET_STORAGE         *Storage;\r
-  FORM_BROWSER_CONFIG_REQUEST  *ConfigInfo;\r
 \r
   Status = EFI_SUCCESS;\r
-  if (SingleForm) {\r
-    ConfigInfo    = (FORM_BROWSER_CONFIG_REQUEST *) Buffer;\r
-    Storage       = ConfigInfo->Storage;\r
-    ConfigRequest = ConfigInfo->ConfigRequest;\r
-  } else {\r
-    Storage       = (FORMSET_STORAGE *) Buffer;\r
-    ConfigRequest = Storage->ConfigRequest;\r
-  }\r
 \r
   switch (Storage->Type) {\r
   case EFI_HII_VARSTORE_BUFFER:\r
+  case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER:\r
     Status = mHiiConfigRouting->BlockToConfig (\r
                                   mHiiConfigRouting,\r
                                   ConfigRequest,\r
@@ -944,7 +1051,7 @@ StorageToConfigResp (
 **/\r
 EFI_STATUS\r
 ConfigRespToStorage (\r
-  IN FORMSET_STORAGE         *Storage,\r
+  IN BROWSER_STORAGE         *Storage,\r
   IN CHAR16                  *ConfigResp\r
   )\r
 {\r
@@ -959,6 +1066,7 @@ ConfigRespToStorage (
 \r
   switch (Storage->Type) {\r
   case EFI_HII_VARSTORE_BUFFER:\r
+  case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER:\r
     BufferSize = Storage->Size;\r
     Status = mHiiConfigRouting->ConfigToBlock (\r
                                   mHiiConfigRouting,\r
@@ -996,7 +1104,7 @@ ConfigRespToStorage (
       if (StrPtr != NULL) {\r
         *StrPtr = 0;\r
       }\r
-      SetValueByName (Storage, Name, Value, TRUE);\r
+      SetValueByName (Storage, Name, Value, GetSetValueWithEditBuffer);\r
     }\r
     break;\r
 \r
@@ -1016,8 +1124,7 @@ ConfigRespToStorage (
   @param  FormSet                FormSet data structure.\r
   @param  Form                   Form data structure.\r
   @param  Question               Question to be initialized.\r
-  @param  Cached                 TRUE:  get from Edit copy FALSE: get from original\r
-                                 Storage\r
+  @param  GetValueFrom           Where to get value, may from editbuffer, buffer or hii driver.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
 \r
@@ -1027,7 +1134,7 @@ GetQuestionValue (
   IN FORM_BROWSER_FORMSET             *FormSet,\r
   IN FORM_BROWSER_FORM                *Form,\r
   IN OUT FORM_BROWSER_STATEMENT       *Question,\r
-  IN BOOLEAN                          Cached\r
+  IN GET_SET_QUESTION_VALUE_WITH      GetValueFrom\r
   )\r
 {\r
   EFI_STATUS          Status;\r
@@ -1036,7 +1143,7 @@ GetQuestionValue (
   UINT8               *Dst;\r
   UINTN               StorageWidth;\r
   EFI_TIME            EfiTime;\r
-  FORMSET_STORAGE     *Storage;\r
+  BROWSER_STORAGE     *Storage;\r
   EFI_IFR_TYPE_VALUE  *QuestionValue;\r
   CHAR16              *ConfigRequest;\r
   CHAR16              *Progress;\r
@@ -1050,8 +1157,15 @@ GetQuestionValue (
   BOOLEAN             IsString;\r
   CHAR16              TemStr[5];\r
   UINT8               DigitUint8;\r
+  UINT8               *TemBuffer;\r
 \r
   Status = EFI_SUCCESS;\r
+  Value  = NULL;\r
+  Result = NULL;\r
+\r
+  if (GetValueFrom >= GetSetValueWithMax) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   //\r
   // Statement don't have storage, skip them\r
@@ -1066,7 +1180,19 @@ GetQuestionValue (
   if (Question->ValueExpression != NULL) {\r
     Status = EvaluateExpression (FormSet, Form, Question->ValueExpression);\r
     if (!EFI_ERROR (Status)) {\r
-      CopyMem (&Question->HiiValue, &Question->ValueExpression->Result, sizeof (EFI_HII_VALUE));\r
+      if (Question->ValueExpression->Result.Type == EFI_IFR_TYPE_BUFFER) {\r
+        ASSERT (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER && Question->HiiValue.Buffer != NULL);\r
+        if (Question->StorageWidth > Question->ValueExpression->Result.BufferLen) {\r
+          CopyMem (Question->HiiValue.Buffer, Question->ValueExpression->Result.Buffer, Question->ValueExpression->Result.BufferLen);\r
+          Question->HiiValue.BufferLen = Question->ValueExpression->Result.BufferLen;\r
+        } else {\r
+          CopyMem (Question->HiiValue.Buffer, Question->ValueExpression->Result.Buffer, Question->StorageWidth);\r
+          Question->HiiValue.BufferLen = Question->StorageWidth;\r
+        }\r
+        FreePool (Question->ValueExpression->Result.Buffer);\r
+      }\r
+      Question->HiiValue.Type = Question->ValueExpression->Result.Type;\r
+      CopyMem (&Question->HiiValue.Value, &Question->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE));      \r
     }\r
     return Status;\r
   }\r
@@ -1076,11 +1202,24 @@ GetQuestionValue (
   //\r
   if (Question->ReadExpression != NULL && Form->FormType == STANDARD_MAP_FORM_TYPE) {\r
     Status = EvaluateExpression (FormSet, Form, Question->ReadExpression);\r
-    if (!EFI_ERROR (Status) && (Question->ReadExpression->Result.Type < EFI_IFR_TYPE_OTHER)) {\r
+    if (!EFI_ERROR (Status) && \r
+      ((Question->ReadExpression->Result.Type < EFI_IFR_TYPE_OTHER) || (Question->ReadExpression->Result.Type == EFI_IFR_TYPE_BUFFER))) {\r
       //\r
       // Only update question value to the valid result.\r
       //\r
-      CopyMem (&Question->HiiValue, &Question->ReadExpression->Result, sizeof (EFI_HII_VALUE));\r
+      if (Question->ReadExpression->Result.Type == EFI_IFR_TYPE_BUFFER) {\r
+        ASSERT (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER && Question->HiiValue.Buffer != NULL);\r
+        if (Question->StorageWidth > Question->ReadExpression->Result.BufferLen) {\r
+          CopyMem (Question->HiiValue.Buffer, Question->ReadExpression->Result.Buffer, Question->ReadExpression->Result.BufferLen);\r
+          Question->HiiValue.BufferLen = Question->ReadExpression->Result.BufferLen;\r
+        } else {\r
+          CopyMem (Question->HiiValue.Buffer, Question->ReadExpression->Result.Buffer, Question->StorageWidth);\r
+          Question->HiiValue.BufferLen = Question->StorageWidth;\r
+        }\r
+        FreePool (Question->ReadExpression->Result.Buffer);\r
+      }\r
+      Question->HiiValue.Type = Question->ReadExpression->Result.Type;\r
+      CopyMem (&Question->HiiValue.Value, &Question->ReadExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE));       \r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -1172,17 +1311,29 @@ GetQuestionValue (
     Dst = (UINT8 *) &Question->HiiValue.Value;\r
   }\r
 \r
-  IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE);\r
+  if (Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
+      Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
+    IsBufferStorage = TRUE;\r
+  } else {\r
+    IsBufferStorage = FALSE;\r
+  }\r
   IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ?  TRUE : FALSE);\r
-  if (Cached) {\r
+  if (GetValueFrom == GetSetValueWithEditBuffer || GetValueFrom == GetSetValueWithBuffer ) {\r
     if (IsBufferStorage) {\r
-      //\r
-      // Copy from storage Edit buffer\r
-      //\r
-      CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth);\r
+      if (GetValueFrom == GetSetValueWithEditBuffer) {\r
+        //\r
+        // Copy from storage Edit buffer\r
+        //\r
+        CopyMem (Dst, Storage->EditBuffer + Question->VarStoreInfo.VarOffset, StorageWidth);\r
+      } else {\r
+        //\r
+        // Copy from storage Edit buffer\r
+        //\r
+        CopyMem (Dst, Storage->Buffer + Question->VarStoreInfo.VarOffset, StorageWidth);\r
+      }\r
     } else {\r
       Value = NULL;\r
-      Status = GetValueByName (Storage, Question->VariableName, &Value);\r
+      Status = GetValueByName (Storage, Question->VariableName, &Value, GetValueFrom);\r
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
@@ -1230,115 +1381,147 @@ GetQuestionValue (
       FreePool (Value);\r
     }\r
   } else {\r
-    //\r
-    // Request current settings from Configuration Driver\r
-    //\r
-    if (FormSet->ConfigAccess == NULL) {\r
-      return EFI_NOT_FOUND;\r
-    }\r
-\r
-    //\r
-    // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||\r
-    //                   <ConfigHdr> + "&" + <VariableName>\r
-    //\r
-    if (IsBufferStorage) {\r
-      Length = StrLen (Storage->ConfigHdr);\r
-      Length += StrLen (Question->BlockName);\r
-    } else {\r
-      Length = StrLen (Storage->ConfigHdr);\r
-      Length += StrLen (Question->VariableName) + 1;\r
-    }\r
-    ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));\r
-    ASSERT (ConfigRequest != NULL);\r
-\r
-    StrCpy (ConfigRequest, Storage->ConfigHdr);\r
-    if (IsBufferStorage) {\r
-      StrCat (ConfigRequest, Question->BlockName);\r
-    } else {\r
-      StrCat (ConfigRequest, L"&");\r
-      StrCat (ConfigRequest, Question->VariableName);\r
-    }\r
-\r
-    Status = FormSet->ConfigAccess->ExtractConfig (\r
-                                      FormSet->ConfigAccess,\r
-                                      ConfigRequest,\r
-                                      &Progress,\r
-                                      &Result\r
-                                      );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\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
+      if (FormSet->ConfigAccess == NULL) {\r
+        return EFI_NOT_FOUND;\r
+      }\r
 \r
-    //\r
-    // Skip <ConfigRequest>\r
-    //\r
-    Value = Result + Length;\r
-    if (IsBufferStorage) {\r
       //\r
-      // Skip "&VALUE"\r
+      // <ConfigRequest> ::= <ConfigHdr> + <BlockName> ||\r
+      //                   <ConfigHdr> + "&" + <VariableName>\r
       //\r
-      Value = Value + 6;\r
-    }\r
-    if (*Value != '=') {\r
-      FreePool (Result);\r
-      return EFI_NOT_FOUND;\r
-    }\r
-    //\r
-    // Skip '=', point to value\r
-    //\r
-    Value = Value + 1;\r
+      if (IsBufferStorage) {\r
+        Length = StrLen (Storage->ConfigHdr);\r
+        Length += StrLen (Question->BlockName);\r
+      } else {\r
+        Length = StrLen (Storage->ConfigHdr);\r
+        Length += StrLen (Question->VariableName) + 1;\r
+      }\r
+      ConfigRequest = AllocateZeroPool ((Length + 1) * sizeof (CHAR16));\r
+      ASSERT (ConfigRequest != NULL);\r
 \r
-    //\r
-    // Suppress <AltResp> if any\r
-    //\r
-    StringPtr = Value;\r
-    while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
-      StringPtr++;\r
-    }\r
-    *StringPtr = L'\0';\r
+      StrCpy (ConfigRequest, Storage->ConfigHdr);\r
+      if (IsBufferStorage) {\r
+        StrCat (ConfigRequest, Question->BlockName);\r
+      } else {\r
+        StrCat (ConfigRequest, L"&");\r
+        StrCat (ConfigRequest, Question->VariableName);\r
+      }\r
+\r
+      Status = FormSet->ConfigAccess->ExtractConfig (\r
+                                        FormSet->ConfigAccess,\r
+                                        ConfigRequest,\r
+                                        &Progress,\r
+                                        &Result\r
+                                        );\r
+      FreePool (ConfigRequest);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
 \r
-    LengthStr = StrLen (Value);\r
-    Status    = EFI_SUCCESS;\r
-    if (!IsBufferStorage && IsString) {\r
       //\r
-      // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"\r
-      // Add string tail char L'\0' into Length\r
+      // Skip <ConfigRequest>\r
       //\r
-      Length    = StorageWidth + sizeof (CHAR16);\r
-      if (Length < ((LengthStr / 4 + 1) * 2)) {\r
-        Status = EFI_BUFFER_TOO_SMALL;\r
-      } else {\r
-        StringPtr = (CHAR16 *) Dst;\r
-        ZeroMem (TemStr, sizeof (TemStr));\r
-        for (Index = 0; Index < LengthStr; Index += 4) {\r
-          StrnCpy (TemStr, Value + Index, 4);\r
-          StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);\r
+      if (IsBufferStorage) {\r
+        Value = StrStr (Result, L"&VALUE");\r
+        if (Value == NULL) {\r
+          FreePool (Result);\r
+          return EFI_NOT_FOUND;\r
         }\r
         //\r
-        // Add tailing L'\0' character\r
+        // Skip "&VALUE"\r
         //\r
-        StringPtr[Index/4] = L'\0';\r
+        Value = Value + 6;\r
+      } else {\r
+        Value = Result + Length;\r
       }\r
-    } else {\r
-      if (StorageWidth < ((LengthStr + 1) / 2)) {\r
-        Status = EFI_BUFFER_TOO_SMALL;\r
+      if (*Value != '=') {\r
+        FreePool (Result);\r
+        return EFI_NOT_FOUND;\r
+      }\r
+      //\r
+      // Skip '=', point to value\r
+      //\r
+      Value = Value + 1;\r
+\r
+      //\r
+      // Suppress <AltResp> if any\r
+      //\r
+      StringPtr = Value;\r
+      while (*StringPtr != L'\0' && *StringPtr != L'&') {\r
+        StringPtr++;\r
+      }\r
+      *StringPtr = L'\0';\r
+\r
+      LengthStr = StrLen (Value);\r
+      Status    = EFI_SUCCESS;\r
+      if (!IsBufferStorage && IsString) {\r
+        //\r
+        // Convert Config String to Unicode String, e.g "0041004200430044" => "ABCD"\r
+        // Add string tail char L'\0' into Length\r
+        //\r
+        Length    = StorageWidth + sizeof (CHAR16);\r
+        if (Length < ((LengthStr / 4 + 1) * 2)) {\r
+          Status = EFI_BUFFER_TOO_SMALL;\r
+        } else {\r
+          StringPtr = (CHAR16 *) Dst;\r
+          ZeroMem (TemStr, sizeof (TemStr));\r
+          for (Index = 0; Index < LengthStr; Index += 4) {\r
+            StrnCpy (TemStr, Value + Index, 4);\r
+            StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr);\r
+          }\r
+          //\r
+          // Add tailing L'\0' character\r
+          //\r
+          StringPtr[Index/4] = L'\0';\r
+        }\r
       } else {\r
-        ZeroMem (TemStr, sizeof (TemStr));\r
-        for (Index = 0; Index < LengthStr; Index ++) {\r
-          TemStr[0] = Value[LengthStr - Index - 1];\r
-          DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
-          if ((Index & 1) == 0) {\r
-            Dst [Index/2] = DigitUint8;\r
-          } else {\r
-            Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);\r
+        if (StorageWidth < ((LengthStr + 1) / 2)) {\r
+          Status = EFI_BUFFER_TOO_SMALL;\r
+        } else {\r
+          ZeroMem (TemStr, sizeof (TemStr));\r
+          for (Index = 0; Index < LengthStr; Index ++) {\r
+            TemStr[0] = Value[LengthStr - Index - 1];\r
+            DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
+            if ((Index & 1) == 0) {\r
+              Dst [Index/2] = DigitUint8;\r
+            } else {\r
+              Dst [Index/2] = (UINT8) ((DigitUint8 << 4) + Dst [Index/2]);\r
+            }\r
           }\r
         }\r
       }\r
-    }\r
 \r
-    if (EFI_ERROR (Status)) {\r
-      FreePool (Result);\r
-      return Status;\r
+      if (EFI_ERROR (Status)) {\r
+        FreePool (Result);\r
+        return Status;\r
+      }\r
+    } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
+      TemBuffer = NULL;\r
+      TemBuffer = AllocateZeroPool (Storage->Size);\r
+      if (TemBuffer == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        return Status;\r
+      }\r
+      Length = Storage->Size;\r
+      Status = gRT->GetVariable (\r
+                       Storage->Name,\r
+                       &Storage->Guid,\r
+                       NULL,\r
+                       &Length,\r
+                       TemBuffer\r
+                       );\r
+      if (EFI_ERROR (Status)) {\r
+        FreePool (TemBuffer);\r
+        return Status;\r
+      }\r
+\r
+      CopyMem (Dst, TemBuffer + Question->VarStoreInfo.VarOffset, StorageWidth);\r
+\r
+      FreePool (TemBuffer);\r
     }\r
 \r
     //\r
@@ -1347,10 +1530,12 @@ GetQuestionValue (
     if (IsBufferStorage) {\r
       CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Dst, StorageWidth);\r
     } else {\r
-      SetValueByName (Storage, Question->VariableName, Value, TRUE);\r
+      SetValueByName (Storage, Question->VariableName, Value, GetSetValueWithEditBuffer);\r
     }\r
 \r
-    FreePool (Result);\r
+    if (Result != NULL) {\r
+      FreePool (Result);\r
+    }\r
   }\r
 \r
   return Status;\r
@@ -1363,8 +1548,7 @@ GetQuestionValue (
   @param  FormSet                FormSet data structure.\r
   @param  Form                   Form data structure.\r
   @param  Question               Pointer to the Question.\r
-  @param  Cached                 TRUE:  set to Edit copy FALSE: set to original\r
-                                 Storage\r
+  @param  SetValueTo             Update the question value to editbuffer , buffer or hii driver.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
 \r
@@ -1374,7 +1558,7 @@ SetQuestionValue (
   IN FORM_BROWSER_FORMSET             *FormSet,\r
   IN FORM_BROWSER_FORM                *Form,\r
   IN OUT FORM_BROWSER_STATEMENT       *Question,\r
-  IN BOOLEAN                          Cached\r
+  IN GET_SET_QUESTION_VALUE_WITH      SetValueTo\r
   )\r
 {\r
   EFI_STATUS          Status;\r
@@ -1384,7 +1568,7 @@ SetQuestionValue (
   EFI_TIME            EfiTime;\r
   UINTN               BufferLen;\r
   UINTN               StorageWidth;\r
-  FORMSET_STORAGE     *Storage;\r
+  BROWSER_STORAGE     *Storage;\r
   EFI_IFR_TYPE_VALUE  *QuestionValue;\r
   CHAR16              *ConfigResp;\r
   CHAR16              *Progress;\r
@@ -1399,6 +1583,10 @@ SetQuestionValue (
 \r
   Status = EFI_SUCCESS;\r
 \r
+  if (SetValueTo >= GetSetValueWithMax) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   //\r
   // Statement don't have storage, skip them\r
   //\r
@@ -1507,127 +1695,171 @@ SetQuestionValue (
     Src = (UINT8 *) &Question->HiiValue.Value;\r
   }\r
 \r
-  IsBufferStorage = (BOOLEAN) ((Storage->Type == EFI_HII_VARSTORE_BUFFER) ? TRUE : FALSE);\r
-  IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ?  TRUE : FALSE);\r
-  if (IsBufferStorage) {\r
-    //\r
-    // Copy to storage edit buffer\r
-    //\r
-    CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);\r
+  if (Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
+      Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
+    IsBufferStorage = TRUE;\r
   } else {\r
-    if (IsString) {\r
-      //\r
-      // Allocate enough string buffer.\r
-      //\r
-      Value = NULL;\r
-      BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16);\r
-      Value = AllocateZeroPool (BufferLen);\r
-      ASSERT (Value != NULL);\r
-      //\r
-      // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"\r
-      //\r
-      TemName = (CHAR16 *) Src;\r
-      TemString = Value;\r
-      for (; *TemName != L'\0'; TemName++) {\r
-        TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);\r
-      }\r
-    } else {\r
-      BufferLen = StorageWidth * 2 + 1;\r
-      Value = AllocateZeroPool (BufferLen * sizeof (CHAR16));\r
-      ASSERT (Value != NULL);\r
-      //\r
-      // Convert Buffer to Hex String\r
-      //\r
-      TemBuffer = Src + StorageWidth - 1;\r
-      TemString = Value;\r
-      for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) {\r
-        TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
-      }\r
-    }\r
-\r
-    Status = SetValueByName (Storage, Question->VariableName, Value, TRUE);\r
-    FreePool (Value);\r
+    IsBufferStorage = FALSE;\r
   }\r
+  IsString = (BOOLEAN) ((Question->HiiValue.Type == EFI_IFR_TYPE_STRING) ?  TRUE : FALSE);\r
 \r
-  if (!Cached) {\r
-    //\r
-    // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||\r
-    //                <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"\r
-    //\r
+  if (SetValueTo == GetSetValueWithEditBuffer || SetValueTo == GetSetValueWithBuffer) {\r
     if (IsBufferStorage) {\r
-      Length = StrLen (Question->BlockName) + 7;\r
-    } else {\r
-      Length = StrLen (Question->VariableName) + 2;\r
-    }\r
-    if (!IsBufferStorage && IsString) {\r
-      Length += (StrLen ((CHAR16 *) Src) * 4);\r
+      if (SetValueTo == GetSetValueWithEditBuffer) {\r
+        //\r
+        // Copy to storage edit buffer\r
+        //      \r
+        CopyMem (Storage->EditBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);\r
+      } else if (SetValueTo == GetSetValueWithBuffer) {\r
+        //\r
+        // Copy to storage edit buffer\r
+        //     \r
+        CopyMem (Storage->Buffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);\r
+      }\r
     } else {\r
-      Length += (StorageWidth * 2);\r
-    }\r
-    ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16));\r
-    ASSERT (ConfigResp != NULL);\r
+      if (IsString) {\r
+        //\r
+        // Allocate enough string buffer.\r
+        //\r
+        Value = NULL;\r
+        BufferLen = ((StrLen ((CHAR16 *) Src) * 4) + 1) * sizeof (CHAR16);\r
+        Value = AllocateZeroPool (BufferLen);\r
+        ASSERT (Value != NULL);\r
+        //\r
+        // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"\r
+        //\r
+        TemName = (CHAR16 *) Src;\r
+        TemString = Value;\r
+        for (; *TemName != L'\0'; TemName++) {\r
+          TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);\r
+        }\r
+      } else {\r
+        BufferLen = StorageWidth * 2 + 1;\r
+        Value = AllocateZeroPool (BufferLen * sizeof (CHAR16));\r
+        ASSERT (Value != NULL);\r
+        //\r
+        // Convert Buffer to Hex String\r
+        //\r
+        TemBuffer = Src + StorageWidth - 1;\r
+        TemString = Value;\r
+        for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) {\r
+          TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
+        }\r
+      }\r
 \r
-    StrCpy (ConfigResp, Storage->ConfigHdr);\r
-    if (IsBufferStorage) {\r
-      StrCat (ConfigResp, Question->BlockName);\r
-      StrCat (ConfigResp, L"&VALUE=");\r
-    } else {\r
-      StrCat (ConfigResp, L"&");\r
-      StrCat (ConfigResp, Question->VariableName);\r
-      StrCat (ConfigResp, L"=");\r
+      Status = SetValueByName (Storage, Question->VariableName, Value, SetValueTo);\r
+      FreePool (Value);\r
     }\r
-\r
-    Value = ConfigResp + StrLen (ConfigResp);\r
-\r
-    if (!IsBufferStorage && IsString) {\r
+  } else if (SetValueTo == GetSetValueWithHiiDriver) {\r
+    if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
       //\r
-      // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"\r
+      // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||\r
+      //                <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"\r
       //\r
-      TemName = (CHAR16 *) Src;\r
-      TemString = Value;\r
-      for (; *TemName != L'\0'; TemName++) {\r
-        TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);\r
+      if (IsBufferStorage) {\r
+        Length = StrLen (Question->BlockName) + 7;\r
+      } else {\r
+        Length = StrLen (Question->VariableName) + 2;\r
       }\r
-    } else {\r
-      //\r
-      // Convert Buffer to Hex String\r
-      //\r
-      TemBuffer = Src + StorageWidth - 1;\r
-      TemString = Value;\r
-      for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) {\r
-        TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
+      if (!IsBufferStorage && IsString) {\r
+        Length += (StrLen ((CHAR16 *) Src) * 4);\r
+      } else {\r
+        Length += (StorageWidth * 2);\r
       }\r
-    }\r
+      ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16));\r
+      ASSERT (ConfigResp != NULL);\r
 \r
-    //\r
-    // Convert to lower char.\r
-    //\r
-    for (TemString = Value; *Value != L'\0'; Value++) {\r
-      if (*Value >= L'A' && *Value <= L'Z') {\r
-        *Value = (CHAR16) (*Value - L'A' + L'a');\r
+      StrCpy (ConfigResp, Storage->ConfigHdr);\r
+      if (IsBufferStorage) {\r
+        StrCat (ConfigResp, Question->BlockName);\r
+        StrCat (ConfigResp, L"&VALUE=");\r
+      } else {\r
+        StrCat (ConfigResp, L"&");\r
+        StrCat (ConfigResp, Question->VariableName);\r
+        StrCat (ConfigResp, L"=");\r
       }\r
-    }\r
 \r
-    //\r
-    // Submit Question Value to Configuration Driver\r
-    //\r
-    if (FormSet->ConfigAccess != NULL) {\r
-      Status = FormSet->ConfigAccess->RouteConfig (\r
-                                        FormSet->ConfigAccess,\r
-                                        ConfigResp,\r
-                                        &Progress\r
-                                        );\r
-      if (EFI_ERROR (Status)) {\r
-        FreePool (ConfigResp);\r
+      Value = ConfigResp + StrLen (ConfigResp);\r
+\r
+      if (!IsBufferStorage && IsString) {\r
+        //\r
+        // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"\r
+        //\r
+        TemName = (CHAR16 *) Src;\r
+        TemString = Value;\r
+        for (; *TemName != L'\0'; TemName++) {\r
+          TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4);\r
+        }\r
+      } else {\r
+        //\r
+        // Convert Buffer to Hex String\r
+        //\r
+        TemBuffer = Src + StorageWidth - 1;\r
+        TemString = Value;\r
+        for (Index = 0; Index < StorageWidth; Index ++, TemBuffer --) {\r
+          TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
+        }\r
+      }\r
+\r
+      //\r
+      // Convert to lower char.\r
+      //\r
+      for (TemString = Value; *Value != L'\0'; Value++) {\r
+        if (*Value >= L'A' && *Value <= L'Z') {\r
+          *Value = (CHAR16) (*Value - L'A' + L'a');\r
+        }\r
+      }\r
+\r
+      //\r
+      // Submit Question Value to Configuration Driver\r
+      //\r
+      if (FormSet->ConfigAccess != NULL) {\r
+        Status = FormSet->ConfigAccess->RouteConfig (\r
+                                          FormSet->ConfigAccess,\r
+                                          ConfigResp,\r
+                                          &Progress\r
+                                          );\r
+        if (EFI_ERROR (Status)) {\r
+          FreePool (ConfigResp);\r
+          return Status;\r
+        }\r
+      }\r
+      FreePool (ConfigResp);\r
+      \r
+    } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
+      TemBuffer = NULL;\r
+      TemBuffer = AllocateZeroPool(Storage->Size);\r
+      if (TemBuffer == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
         return Status;\r
       }\r
-    }\r
-    FreePool (ConfigResp);\r
+      Length = Storage->Size;\r
+      Status = gRT->GetVariable (\r
+                       Storage->Name,\r
+                       &Storage->Guid,\r
+                       NULL,\r
+                       &Length,\r
+                       TemBuffer\r
+                       );\r
 \r
+      CopyMem (TemBuffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);\r
+      \r
+      Status = gRT->SetVariable (\r
+                       Storage->Name,\r
+                       &Storage->Guid,\r
+                       Storage->Attributes,\r
+                       Storage->Size,\r
+                       TemBuffer\r
+                       );\r
+      FreePool (TemBuffer);\r
+      if (EFI_ERROR (Status)){\r
+        return Status;\r
+      }\r
+    }\r
     //\r
-    // Synchronize shadow Buffer\r
+    // Sync storage, from editbuffer to buffer.\r
     //\r
-    SynchronizeStorage (Storage);\r
+    CopyMem (Storage->Buffer + Question->VarStoreInfo.VarOffset, Src, StorageWidth);\r
   }\r
 \r
   return Status;\r
@@ -1681,7 +1913,7 @@ ValidateQuestion (
       return Status;\r
     }\r
 \r
-    if (Expression->Result.Value.b) {\r
+    if ((Expression->Result.Type == EFI_IFR_TYPE_BOOLEAN) && Expression->Result.Value.b) {\r
       //\r
       // Condition meet, show up error message\r
       //\r
@@ -1750,58 +1982,24 @@ NoSubmitCheck (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  Restore Storage's Edit copy to Shadow copy.\r
-\r
-  @param  Storage                The Storage to be synchronized.\r
-\r
-**/\r
-VOID\r
-RestoreStorage (\r
-  IN FORMSET_STORAGE         *Storage\r
-  )\r
-{\r
-  LIST_ENTRY              *Link;\r
-  NAME_VALUE_NODE         *Node;\r
-\r
-  switch (Storage->Type) {\r
-  case EFI_HII_VARSTORE_BUFFER:\r
-    CopyMem (Storage->EditBuffer, Storage->Buffer, Storage->Size);\r
-    break;\r
-\r
-  case EFI_HII_VARSTORE_NAME_VALUE:\r
-    Link = GetFirstNode (&Storage->NameValueListHead);\r
-    while (!IsNull (&Storage->NameValueListHead, Link)) {\r
-      Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
-\r
-      if (Node->EditValue != NULL) {\r
-        FreePool (Node->EditValue);\r
-      }\r
-      Node->EditValue = AllocateCopyPool (StrSize (Node->Value), Node->Value);\r
-      ASSERT (Node->EditValue != NULL);\r
-      Link = GetNextNode (&Storage->NameValueListHead, Link);\r
-    }\r
-    break;\r
-\r
-  case EFI_HII_VARSTORE_EFI_VARIABLE:\r
-  default:\r
-    break;\r
-  }\r
-}\r
-\r
 /**\r
   Fill storage's edit copy with settings requested from Configuration Driver.\r
 \r
   @param  FormSet                FormSet data structure.\r
   @param  ConfigInfo             The config info related to this form.\r
+  @param  SyncOrRestore          Sync the buffer to editbuffer or Restore  the \r
+                                 editbuffer to buffer\r
+                                 if TRUE, copy the editbuffer to the buffer.\r
+                                 if FALSE, copy the buffer to the editbuffer.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
 \r
 **/\r
 EFI_STATUS\r
-FormRestoreStorage (\r
+SynchronizeStorageForForm (\r
   IN FORM_BROWSER_FORMSET        *FormSet,\r
-  IN FORM_BROWSER_CONFIG_REQUEST *ConfigInfo\r
+  IN FORM_BROWSER_CONFIG_REQUEST *ConfigInfo,\r
+  IN BOOLEAN                     SyncOrRestore\r
   )\r
 {\r
   EFI_STATUS              Status;\r
@@ -1810,10 +2008,12 @@ FormRestoreStorage (
   UINTN                   BufferSize;\r
   LIST_ENTRY              *Link;\r
   NAME_VALUE_NODE         *Node;\r
+  UINT8                   *Src;\r
+  UINT8                   *Dst;\r
 \r
   Status = EFI_SUCCESS;\r
   Result = NULL;\r
-  if (FormSet->ConfigAccess == NULL) {\r
+  if (FormSet->ConfigAccess == NULL && ConfigInfo->Storage->Type != EFI_HII_VARSTORE_NAME_VALUE) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -1824,12 +2024,22 @@ FormRestoreStorage (
     return EFI_SUCCESS;\r
   }\r
 \r
-  if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_BUFFER) {\r
+  if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
+      (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) {\r
     BufferSize = ConfigInfo->Storage->Size;\r
+\r
+    if (SyncOrRestore) {\r
+      Src = ConfigInfo->Storage->EditBuffer;\r
+      Dst = ConfigInfo->Storage->Buffer;\r
+    } else {\r
+      Src = ConfigInfo->Storage->Buffer;\r
+      Dst = ConfigInfo->Storage->EditBuffer;\r
+    }\r
+\r
     Status = mHiiConfigRouting->BlockToConfig(\r
                                   mHiiConfigRouting,\r
                                   ConfigInfo->ConfigRequest,\r
-                                  ConfigInfo->Storage->Buffer,\r
+                                  Src,\r
                                   BufferSize,\r
                                   &Result,\r
                                   &Progress\r
@@ -1841,28 +2051,24 @@ FormRestoreStorage (
     Status = mHiiConfigRouting->ConfigToBlock (\r
                                   mHiiConfigRouting,\r
                                   Result,\r
-                                  ConfigInfo->Storage->EditBuffer,\r
+                                  Dst,\r
                                   &BufferSize,\r
                                   &Progress\r
                                   );\r
     if (Result != NULL) {\r
       FreePool (Result);\r
     }\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
   } else if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
     Link = GetFirstNode (&ConfigInfo->Storage->NameValueListHead);\r
     while (!IsNull (&ConfigInfo->Storage->NameValueListHead, Link)) {\r
       Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
 \r
       if (StrStr (ConfigInfo->ConfigRequest, Node->Name) != NULL) {\r
-        if (Node->EditValue != NULL) {\r
-          FreePool (Node->EditValue);\r
+        if (SyncOrRestore) {\r
+          NewStringCpy (&Node->Value, Node->EditValue);\r
+        } else {\r
+          NewStringCpy (&Node->EditValue, Node->Value);\r
         }\r
-        Node->EditValue = AllocateCopyPool (StrSize (Node->Value), Node->Value);\r
-        ASSERT (Node->EditValue != NULL);\r
       }\r
 \r
       Link = GetNextNode (&ConfigInfo->Storage->NameValueListHead, Link);\r
@@ -1872,80 +2078,271 @@ FormRestoreStorage (
   return Status;\r
 }\r
 \r
+/**\r
+  When discard the question value, call the callback function with Changed type\r
+  to inform the hii driver.\r
+\r
+  @param  FormSet                FormSet data structure.\r
+  @param  Form                   Form data structure.\r
+\r
+**/\r
+VOID\r
+SendDiscardInfoToDriver (\r
+  IN FORM_BROWSER_FORMSET             *FormSet,\r
+  IN FORM_BROWSER_FORM                *Form\r
+  )\r
+{\r
+  LIST_ENTRY                  *Link;\r
+  FORM_BROWSER_STATEMENT      *Question;\r
+  EFI_STATUS                  Status;\r
+  EFI_HII_VALUE               HiiValue;\r
+  UINT8                       *BufferValue;\r
+  BOOLEAN                     ValueChanged;\r
+  EFI_IFR_TYPE_VALUE          *TypeValue;\r
+  EFI_BROWSER_ACTION_REQUEST  ActionRequest;\r
+\r
+  ValueChanged = FALSE;\r
+  BufferValue  = NULL;\r
+\r
+  if(!Form->NvUpdateRequired) {\r
+    return;\r
+  }\r
+\r
+  Link = GetFirstNode (&Form->StatementListHead);\r
+  while (!IsNull (&Form->StatementListHead, Link)) {\r
+    Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);\r
+    Link = GetNextNode (&Form->StatementListHead, Link);\r
+\r
+    if (Question->Storage == NULL || Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
+      continue;\r
+    }\r
+\r
+    if (Question->Operand == EFI_IFR_PASSWORD_OP) {\r
+      continue;\r
+    }\r
+\r
+    if (Question->BufferValue != NULL) {\r
+      BufferValue = AllocateZeroPool (Question->StorageWidth);\r
+      ASSERT (BufferValue != NULL);\r
+      CopyMem (BufferValue, Question->BufferValue, Question->StorageWidth);\r
+    } else {\r
+      HiiValue.Type = Question->HiiValue.Type;\r
+      CopyMem (&HiiValue.Value, &Question->HiiValue.Value, sizeof (EFI_IFR_TYPE_VALUE));\r
+    }\r
+\r
+    Status = GetQuestionValue (FormSet, Form, Question, GetSetValueWithBuffer);\r
+    if (EFI_ERROR (Status)) {\r
+      if (BufferValue != NULL) {\r
+        FreePool (BufferValue);\r
+        BufferValue = NULL;\r
+      }\r
+      continue;\r
+    }\r
+\r
+    if (Question->BufferValue != NULL) {\r
+      if (CompareMem (BufferValue, Question->BufferValue, Question->StorageWidth)) {\r
+        ValueChanged = TRUE;\r
+      }\r
+    } else {\r
+      if (CompareMem (&HiiValue.Value, &Question->HiiValue.Value, sizeof (EFI_IFR_TYPE_VALUE))) {\r
+        ValueChanged = TRUE;\r
+      }\r
+    }\r
+\r
+    if (BufferValue != NULL) {\r
+      FreePool (BufferValue);\r
+      BufferValue = NULL;\r
+    }\r
+\r
+    if (!ValueChanged) {\r
+      continue;\r
+    }\r
+\r
+    ValueChanged = FALSE;\r
+\r
+    if (Question->HiiValue.Type == EFI_IFR_TYPE_BUFFER) {\r
+      TypeValue = (EFI_IFR_TYPE_VALUE *) Question->BufferValue;\r
+    } else {\r
+      TypeValue = &Question->HiiValue.Value;\r
+    }\r
+\r
+    ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
+    FormSet->ConfigAccess->Callback (\r
+                             FormSet->ConfigAccess,\r
+                             EFI_BROWSER_ACTION_CHANGED,\r
+                             Question->QuestionId,\r
+                             Question->HiiValue.Type,\r
+                             TypeValue,\r
+                             &ActionRequest\r
+                             );\r
+  }\r
+}\r
+\r
+/**\r
+  Validate the FormSet. If the formset is not validate, remove it from the list.\r
+\r
+  @param  FormSet                The input FormSet which need to validate.\r
+\r
+  @retval TRUE                   The handle is validate.\r
+  @retval FALSE                  The handle is invalidate.\r
+\r
+**/\r
+BOOLEAN\r
+ValidateFormSet (\r
+  FORM_BROWSER_FORMSET    *FormSet\r
+  )\r
+{\r
+  EFI_HII_HANDLE          *HiiHandles;\r
+  UINTN                   Index;\r
+  BOOLEAN                 Find;\r
+\r
+  ASSERT (FormSet != NULL);\r
+  Find = FALSE;\r
+  //\r
+  // Get all the Hii handles\r
+  //\r
+  HiiHandles = HiiGetHiiHandles (NULL);\r
+  ASSERT (HiiHandles != NULL);\r
+\r
+  //\r
+  // Search for formset of each class type\r
+  //\r
+  for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r
+    if (HiiHandles[Index] == FormSet->HiiHandle) {\r
+      Find = TRUE;\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (!Find) {\r
+    RemoveEntryList (&FormSet->Link);\r
+    DestroyFormSet (FormSet);\r
+  }\r
+\r
+  FreePool (HiiHandles);\r
+\r
+  return Find;\r
+}\r
 \r
 /**\r
-  Discard data for form level or formset level.\r
+  Discard data based on the input setting scope (Form, FormSet or System).\r
 \r
   @param  FormSet                FormSet data structure.\r
   @param  Form                   Form data structure.\r
-  @param  SingleForm             Only discard single form or formset.\r
+  @param  SettingScope           Setting Scope for Discard action.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
+  @retval EFI_UNSUPPORTED        Unsupport SettingScope.\r
 \r
 **/\r
 EFI_STATUS\r
 DiscardForm (\r
   IN FORM_BROWSER_FORMSET             *FormSet,\r
   IN FORM_BROWSER_FORM                *Form,\r
-  IN BOOLEAN                          SingleForm\r
+  IN BROWSER_SETTING_SCOPE            SettingScope\r
   )\r
 {\r
-  LIST_ENTRY              *Link;\r
-  FORMSET_STORAGE         *Storage;\r
+  LIST_ENTRY                   *Link;\r
+  FORMSET_STORAGE              *Storage;\r
   FORM_BROWSER_CONFIG_REQUEST  *ConfigInfo;\r
+  FORM_BROWSER_FORMSET    *LocalFormSet;\r
 \r
-  if (SingleForm) {\r
-    if (Form->NvUpdateRequired) {\r
-      ConfigInfo = NULL;\r
-      Link = GetFirstNode (&Form->ConfigRequestHead);\r
-      while (!IsNull (&Form->ConfigRequestHead, Link)) {\r
-        ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link);\r
-        Link = GetNextNode (&Form->ConfigRequestHead, Link);\r
+  //\r
+  // Check the supported setting level.\r
+  //\r
+  if (SettingScope >= MaxLevel) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
-        if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
-          continue;\r
-        }\r
+  if (SettingScope == FormLevel && Form->NvUpdateRequired) {\r
+    ConfigInfo = NULL;\r
+    Link = GetFirstNode (&Form->ConfigRequestHead);\r
+    while (!IsNull (&Form->ConfigRequestHead, Link)) {\r
+      ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link);\r
+      Link = GetNextNode (&Form->ConfigRequestHead, Link);\r
 \r
-        //\r
-        // Skip if there is no RequestElement\r
-        //\r
-        if (ConfigInfo->ElementCount == 0) {\r
-          continue;\r
-        }\r
+      if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
+        continue;\r
+      }\r
 \r
-        //\r
-        // Prepare <ConfigResp>\r
-        //\r
-        FormRestoreStorage(FormSet, ConfigInfo);\r
+      //\r
+      // Skip if there is no RequestElement\r
+      //\r
+      if (ConfigInfo->ElementCount == 0) {\r
+        continue;\r
       }\r
 \r
-      Form->NvUpdateRequired = FALSE;\r
+      //\r
+      // Prepare <ConfigResp>\r
+      //\r
+      SynchronizeStorageForForm(FormSet, ConfigInfo, FALSE);\r
+\r
+      //\r
+      // Call callback with Changed type to inform the driver.\r
+      //\r
+      SendDiscardInfoToDriver (FormSet, Form);\r
     }\r
-  } else {\r
-    if (IsNvUpdateRequired(FormSet)) {\r
+\r
+    Form->NvUpdateRequired = FALSE;\r
+  } else if (SettingScope == FormSetLevel && IsNvUpdateRequired(FormSet)) {\r
+\r
+    //\r
+    // Discard Buffer storage or Name/Value storage\r
+    //\r
+    Link = GetFirstNode (&FormSet->StorageListHead);\r
+    while (!IsNull (&FormSet->StorageListHead, Link)) {\r
+      Storage = FORMSET_STORAGE_FROM_LINK (Link);\r
+      Link = GetNextNode (&FormSet->StorageListHead, Link);\r
+\r
+      if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
+        continue;\r
+      }\r
+\r
       //\r
-      // Discard Buffer storage or Name/Value storage\r
+      // Skip if there is no RequestElement\r
       //\r
-      Link = GetFirstNode (&FormSet->StorageListHead);\r
-      while (!IsNull (&FormSet->StorageListHead, Link)) {\r
-        Storage = FORMSET_STORAGE_FROM_LINK (Link);\r
-        Link = GetNextNode (&FormSet->StorageListHead, Link);\r
+      if (Storage->ElementCount == 0) {\r
+        continue;\r
+      }\r
 \r
-        if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
-          continue;\r
-        }\r
+      SynchronizeStorage(Storage->BrowserStorage, FALSE);\r
+    }\r
 \r
+    Link = GetFirstNode (&FormSet->FormListHead);\r
+    while (!IsNull (&FormSet->FormListHead, Link)) {\r
+      Form = FORM_BROWSER_FORM_FROM_LINK (Link);\r
+      Link = GetNextNode (&FormSet->FormListHead, Link);\r
+      \r
+      //\r
+      // Call callback with Changed type to inform the driver.\r
+      //\r
+      SendDiscardInfoToDriver (FormSet, Form);\r
+    }\r
+\r
+    UpdateNvInfoInForm (FormSet, FALSE);   \r
+  } else if (SettingScope == SystemLevel) {\r
+    //\r
+    // System Level Discard.\r
+    //\r
+    \r
+    //\r
+    // Discard changed value for each FormSet in the maintain list.\r
+    //\r
+    Link = GetFirstNode (&gBrowserFormSetList);\r
+    while (!IsNull (&gBrowserFormSetList, Link)) {\r
+      LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link);\r
+      Link = GetNextNode (&gBrowserFormSetList, Link);\r
+      if (!ValidateFormSet(LocalFormSet)) {\r
+        continue;\r
+      }\r
+      DiscardForm (LocalFormSet, NULL, FormSetLevel);\r
+      if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) {\r
         //\r
-        // Skip if there is no RequestElement\r
+        // Remove maintain backup list after discard except for the current using FormSet.\r
         //\r
-        if (Storage->ElementCount == 0) {\r
-          continue;\r
-        }\r
-\r
-        RestoreStorage(Storage);\r
+        RemoveEntryList (&LocalFormSet->Link);\r
+        DestroyFormSet (LocalFormSet);\r
       }\r
-\r
-      UpdateNvInfoInForm(FormSet, FALSE);   \r
     }\r
   }\r
 \r
@@ -1953,49 +2350,63 @@ DiscardForm (
 }\r
 \r
 /**\r
-  Submit data for form level or formset level.\r
+  Submit data based on the input Setting level (Form, FormSet or System).\r
 \r
   @param  FormSet                FormSet data structure.\r
   @param  Form                   Form data structure.\r
-  @param  SingleForm             whether submit for the single form or all form set.\r
+  @param  SettingScope           Setting Scope for Submit action.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
+  @retval EFI_UNSUPPORTED        Unsupport SettingScope.\r
 \r
 **/\r
 EFI_STATUS\r
 SubmitForm (\r
   IN FORM_BROWSER_FORMSET             *FormSet,\r
   IN FORM_BROWSER_FORM                *Form,\r
-  IN BOOLEAN                          SingleForm\r
+  IN BROWSER_SETTING_SCOPE            SettingScope\r
   )\r
 {\r
   EFI_STATUS              Status;\r
   LIST_ENTRY              *Link;\r
   EFI_STRING              ConfigResp;\r
   EFI_STRING              Progress;\r
-  FORMSET_STORAGE         *Storage;\r
+  BROWSER_STORAGE         *Storage;\r
+  FORMSET_STORAGE         *FormSetStorage;\r
+  UINTN                   BufferSize;\r
+  UINT8                   *TmpBuf;  \r
+  FORM_BROWSER_FORMSET    *LocalFormSet;\r
   FORM_BROWSER_CONFIG_REQUEST  *ConfigInfo;\r
 \r
+  //\r
+  // Check the supported setting level.\r
+  //\r
+  if (SettingScope >= MaxLevel) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   //\r
   // Validate the Form by NoSubmit check\r
   //\r
-  if (SingleForm) {\r
+  Status = EFI_SUCCESS;\r
+  if (SettingScope == FormLevel) {\r
     Status = NoSubmitCheck (FormSet, Form);\r
-  } else {\r
+  } else if (SettingScope == FormSetLevel) {\r
     Status = NoSubmitCheck (FormSet, NULL);\r
   }\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  if (SingleForm) {\r
+  if (SettingScope == FormLevel && Form->NvUpdateRequired) {\r
     ConfigInfo = NULL;\r
     Link = GetFirstNode (&Form->ConfigRequestHead);\r
     while (!IsNull (&Form->ConfigRequestHead, Link)) {\r
       ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_LINK (Link);\r
       Link = GetNextNode (&Form->ConfigRequestHead, Link);\r
 \r
-      if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
+      Storage = ConfigInfo->Storage;\r
+      if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
         continue;\r
       }\r
 \r
@@ -2007,43 +2418,99 @@ SubmitForm (
       }\r
 \r
       //\r
-      // Prepare <ConfigResp>\r
+      // 1. Prepare <ConfigResp>\r
       //\r
-      Status = StorageToConfigResp (ConfigInfo, &ConfigResp, TRUE);\r
+      Status = StorageToConfigResp (ConfigInfo->Storage, &ConfigResp, ConfigInfo->ConfigRequest);\r
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
 \r
       //\r
-      // Send <ConfigResp> to Configuration Driver\r
+      // 2. Set value to hii driver or efi variable.\r
       //\r
-      if (FormSet->ConfigAccess != NULL) {\r
-        Status = FormSet->ConfigAccess->RouteConfig (\r
-                                          FormSet->ConfigAccess,\r
-                                          ConfigResp,\r
-                                          &Progress\r
-                                          );\r
+      if (Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
+          Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+        //\r
+        // Send <ConfigResp> to Configuration Driver\r
+        //\r
+        if (FormSet->ConfigAccess != NULL) {\r
+          Status = FormSet->ConfigAccess->RouteConfig (\r
+                                            FormSet->ConfigAccess,\r
+                                            ConfigResp,\r
+                                            &Progress\r
+                                            );\r
+          if (EFI_ERROR (Status)) {\r
+            FreePool (ConfigResp);\r
+            return Status;\r
+          }\r
+        }\r
+      } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
+        TmpBuf = NULL;\r
+        TmpBuf = AllocateZeroPool(Storage->Size);\r
+        if (TmpBuf == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          return Status;\r
+        }\r
+\r
+        BufferSize = Storage->Size;\r
+        Status = gRT->GetVariable (\r
+                         Storage->Name,\r
+                         &Storage->Guid,\r
+                         NULL,\r
+                         &BufferSize,\r
+                         TmpBuf\r
+                         );\r
+        if (EFI_ERROR (Status)) {\r
+          FreePool (TmpBuf);\r
+          FreePool (ConfigResp);\r
+          return Status;\r
+        }\r
+        ASSERT (BufferSize == Storage->Size);      \r
+        Status = mHiiConfigRouting->ConfigToBlock (\r
+                                      mHiiConfigRouting,\r
+                                      ConfigResp,\r
+                                      TmpBuf,\r
+                                      &BufferSize,\r
+                                      &Progress\r
+                                      );\r
+        if (EFI_ERROR (Status)) {\r
+          FreePool (TmpBuf);\r
+          FreePool (ConfigResp);\r
+          return Status;\r
+        }\r
+\r
+        Status = gRT->SetVariable (\r
+                         Storage->Name,\r
+                         &Storage->Guid,\r
+                         Storage->Attributes,\r
+                         Storage->Size,\r
+                         TmpBuf\r
+                         );\r
+        FreePool (TmpBuf);\r
         if (EFI_ERROR (Status)) {\r
           FreePool (ConfigResp);\r
           return Status;\r
         }\r
       }\r
       FreePool (ConfigResp);\r
-\r
       //\r
-      // Config success, update storage shadow Buffer\r
+      // 3. Config success, update storage shadow Buffer, only update the data belong to this form.\r
       //\r
-      SynchronizeStorage (ConfigInfo->Storage);\r
+      SynchronizeStorageForForm(FormSet, ConfigInfo, TRUE);\r
     }\r
 \r
+    //\r
+    // 4. Update the NV flag.\r
+    // \r
     Form->NvUpdateRequired = FALSE;\r
-  } else {\r
+  } else if (SettingScope == FormSetLevel && IsNvUpdateRequired(FormSet)) {\r
     //\r
     // Submit Buffer storage or Name/Value storage\r
     //\r
     Link = GetFirstNode (&FormSet->StorageListHead);\r
     while (!IsNull (&FormSet->StorageListHead, Link)) {\r
-      Storage = FORMSET_STORAGE_FROM_LINK (Link);\r
+      FormSetStorage = (FORMSET_STORAGE_FROM_LINK (Link));\r
+      Storage        = FormSetStorage->BrowserStorage;\r
       Link = GetNextNode (&FormSet->StorageListHead, Link);\r
 \r
       if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
@@ -2053,41 +2520,116 @@ SubmitForm (
       //\r
       // Skip if there is no RequestElement\r
       //\r
-      if (Storage->ElementCount == 0) {\r
+      if (FormSetStorage->ElementCount == 0) {\r
         continue;\r
       }\r
 \r
       //\r
-      // Prepare <ConfigResp>\r
+      // 1. Prepare <ConfigResp>\r
       //\r
-      Status = StorageToConfigResp (Storage, &ConfigResp, FALSE);\r
+      Status = StorageToConfigResp (Storage, &ConfigResp, FormSetStorage->ConfigRequest);\r
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
 \r
-      //\r
-      // Send <ConfigResp> to Configuration Driver\r
-      //\r
-      if (FormSet->ConfigAccess != NULL) {\r
-        Status = FormSet->ConfigAccess->RouteConfig (\r
-                                          FormSet->ConfigAccess,\r
-                                          ConfigResp,\r
-                                          &Progress\r
-                                          );\r
+      if (Storage->Type == EFI_HII_VARSTORE_BUFFER || \r
+          Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+\r
+        //\r
+        // 2. Send <ConfigResp> to Configuration Driver\r
+        //\r
+        if (FormSet->ConfigAccess != NULL) {\r
+          Status = FormSet->ConfigAccess->RouteConfig (\r
+                                            FormSet->ConfigAccess,\r
+                                            ConfigResp,\r
+                                            &Progress\r
+                                            );\r
+          if (EFI_ERROR (Status)) {\r
+            FreePool (ConfigResp);\r
+            return Status;\r
+          }\r
+        }\r
+      } else if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
+        //\r
+        // 1&2. Set the edit data to the variable.\r
+        //\r
+        TmpBuf = NULL;\r
+        TmpBuf = AllocateZeroPool (Storage->Size);\r
+        if (TmpBuf == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          return Status;\r
+        }        \r
+        BufferSize = Storage->Size;\r
+        Status = gRT->GetVariable (\r
+                       Storage->Name,\r
+                       &Storage->Guid,\r
+                       NULL,\r
+                       &BufferSize,\r
+                       TmpBuf\r
+                       );\r
+        ASSERT (BufferSize == Storage->Size);      \r
+        Status = mHiiConfigRouting->ConfigToBlock (\r
+                                      mHiiConfigRouting,\r
+                                      ConfigResp,\r
+                                      TmpBuf,\r
+                                      &BufferSize,\r
+                                      &Progress\r
+                                      );\r
         if (EFI_ERROR (Status)) {\r
+          FreePool (TmpBuf);\r
           FreePool (ConfigResp);\r
           return Status;\r
         }\r
+\r
+        Status = gRT->SetVariable (\r
+                         Storage->Name,\r
+                         &Storage->Guid,\r
+                         Storage->Attributes,\r
+                         Storage->Size,\r
+                         TmpBuf\r
+                         );\r
+        if (EFI_ERROR (Status)) {\r
+          FreePool (TmpBuf);\r
+          FreePool (ConfigResp);\r
+          return Status;\r
+        }\r
+        FreePool (TmpBuf);\r
       }\r
       FreePool (ConfigResp);\r
-\r
       //\r
-      // Config success, update storage shadow Buffer\r
+      // 3. Config success, update storage shadow Buffer\r
       //\r
-      SynchronizeStorage (Storage);\r
+      SynchronizeStorage (Storage, TRUE);\r
     }\r
 \r
-    UpdateNvInfoInForm(FormSet, FALSE);\r
+    //\r
+    // 4. Update the NV flag.\r
+    // \r
+    UpdateNvInfoInForm (FormSet, FALSE);\r
+  } else if (SettingScope == SystemLevel) {\r
+    //\r
+    // System Level Save.\r
+    //\r
+\r
+    //\r
+    // Save changed value for each FormSet in the maintain list.\r
+    //\r
+    Link = GetFirstNode (&gBrowserFormSetList);\r
+    while (!IsNull (&gBrowserFormSetList, Link)) {\r
+      LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link);\r
+      Link = GetNextNode (&gBrowserFormSetList, Link);\r
+      if (!ValidateFormSet(LocalFormSet)) {\r
+        continue;\r
+      }\r
+      SubmitForm (LocalFormSet, NULL, FormSetLevel);\r
+      if (!IsHiiHandleInBrowserContext (LocalFormSet->HiiHandle)) {\r
+        //\r
+        // Remove maintain backup list after save except for the current using FormSet.\r
+        //\r
+        RemoveEntryList (&LocalFormSet->Link);\r
+        DestroyFormSet (LocalFormSet);\r
+      }\r
+    }\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -2113,7 +2655,7 @@ GetDefaultValueFromAltCfg (
   BOOLEAN             IsBufferStorage;\r
   BOOLEAN             IsString;  \r
   UINTN               Length;\r
-  FORMSET_STORAGE     *Storage;\r
+  BROWSER_STORAGE     *Storage;\r
   CHAR16              *ConfigRequest;\r
   CHAR16              *Progress;\r
   CHAR16              *Result;\r
@@ -2136,7 +2678,9 @@ GetDefaultValueFromAltCfg (
   Value         = NULL;\r
   Storage       = Question->Storage;\r
 \r
-  if ((Storage == NULL) || (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE)) {\r
+  if ((Storage == NULL) || \r
+      (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) || \r
+      (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER)) {\r
     return Status;\r
   }\r
 \r
@@ -2346,7 +2890,7 @@ GetQuestionDefault (
   EFI_BROWSER_ACTION_REQUEST      ActionRequest;\r
   INTN                            Action;\r
 \r
-  Status   = EFI_SUCCESS;\r
+  Status   = EFI_NOT_FOUND;\r
   StrValue = NULL;\r
 \r
   //\r
@@ -2414,7 +2958,19 @@ GetQuestionDefault (
             return Status;\r
           }\r
 \r
-          CopyMem (HiiValue, &Default->ValueExpression->Result, sizeof (EFI_HII_VALUE));\r
+          if (Default->ValueExpression->Result.Type == EFI_IFR_TYPE_BUFFER) {\r
+            ASSERT (HiiValue->Type == EFI_IFR_TYPE_BUFFER && Question->BufferValue != NULL);\r
+            if (Question->StorageWidth > Default->ValueExpression->Result.BufferLen) {\r
+              CopyMem (Question->HiiValue.Buffer, Default->ValueExpression->Result.Buffer, Default->ValueExpression->Result.BufferLen);\r
+              Question->HiiValue.BufferLen = Default->ValueExpression->Result.BufferLen;\r
+            } else {\r
+              CopyMem (Question->HiiValue.Buffer, Default->ValueExpression->Result.Buffer, Question->StorageWidth);\r
+              Question->HiiValue.BufferLen = Question->StorageWidth;\r
+            }\r
+            FreePool (Default->ValueExpression->Result.Buffer);\r
+          }\r
+          HiiValue->Type = Default->ValueExpression->Result.Type;\r
+          CopyMem (&HiiValue->Value, &Default->ValueExpression->Result.Value, sizeof (EFI_IFR_TYPE_VALUE));       \r
         } else {\r
           //\r
           // Default value is embedded in EFI_IFR_DEFAULT\r
@@ -2427,7 +2983,11 @@ GetQuestionDefault (
           if (StrValue == NULL) {\r
             return EFI_NOT_FOUND;\r
           }\r
-          Question->BufferValue = AllocateCopyPool (StrSize (StrValue), StrValue);\r
+          if (Question->StorageWidth > StrSize (StrValue)) {\r
+            CopyMem (Question->BufferValue, StrValue, StrSize (StrValue));\r
+          } else {\r
+            CopyMem (Question->BufferValue, StrValue, Question->StorageWidth);\r
+          }\r
         }\r
 \r
         return EFI_SUCCESS;\r
@@ -2448,6 +3008,12 @@ GetQuestionDefault (
       Link = GetFirstNode (&Question->OptionListHead);\r
       while (!IsNull (&Question->OptionListHead, Link)) {\r
         Option = QUESTION_OPTION_FROM_LINK (Link);\r
+        Link = GetNextNode (&Question->OptionListHead, Link);\r
+\r
+        if ((Option->SuppressExpression != NULL) &&\r
+            EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) {\r
+          continue;\r
+        }\r
 \r
         if (((DefaultId == EFI_HII_DEFAULT_CLASS_STANDARD) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT) != 0)) ||\r
             ((DefaultId == EFI_HII_DEFAULT_CLASS_MANUFACTURING) && ((Option->Flags & EFI_IFR_OPTION_DEFAULT_MFG) != 0))\r
@@ -2456,8 +3022,6 @@ GetQuestionDefault (
 \r
           return EFI_SUCCESS;\r
         }\r
-\r
-        Link = GetNextNode (&Question->OptionListHead, Link);\r
       }\r
     }\r
   }\r
@@ -2485,6 +3049,7 @@ GetQuestionDefault (
   //\r
   // For Questions without default\r
   //\r
+  Status = EFI_NOT_FOUND;\r
   switch (Question->Operand) {\r
   case EFI_IFR_NUMERIC_OP:\r
     //\r
@@ -2492,6 +3057,7 @@ GetQuestionDefault (
     //\r
     if ((HiiValue->Value.u64 < Question->Minimum) || (HiiValue->Value.u64 > Question->Maximum)) {\r
       HiiValue->Value.u64 = Question->Minimum;\r
+      Status = EFI_SUCCESS;\r
     }\r
     break;\r
 \r
@@ -2501,9 +3067,18 @@ GetQuestionDefault (
     //\r
     if (ValueToOption (Question, HiiValue) == NULL) {\r
       Link = GetFirstNode (&Question->OptionListHead);\r
-      if (!IsNull (&Question->OptionListHead, Link)) {\r
+      while (!IsNull (&Question->OptionListHead, Link)) {\r
         Option = QUESTION_OPTION_FROM_LINK (Link);\r
+        Link = GetNextNode (&Question->OptionListHead, Link);\r
+\r
+        if ((Option->SuppressExpression != NULL) &&\r
+            EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) {\r
+          continue;\r
+        }\r
+\r
         CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE));\r
+        Status = EFI_SUCCESS;\r
+        break;\r
       }\r
     }\r
     break;\r
@@ -2515,7 +3090,14 @@ GetQuestionDefault (
     Index = 0;\r
     Link = GetFirstNode (&Question->OptionListHead);\r
     while (!IsNull (&Question->OptionListHead, Link)) {\r
+      Status = EFI_SUCCESS;\r
       Option = QUESTION_OPTION_FROM_LINK (Link);\r
+      Link = GetNextNode (&Question->OptionListHead, Link);\r
+\r
+      if ((Option->SuppressExpression != NULL) &&\r
+          EvaluateExpressionList(Option->SuppressExpression, FALSE, NULL, NULL) != ExpressFalse) {\r
+        continue;\r
+      }\r
 \r
       SetArrayData (Question->BufferValue, Question->ValueType, Index, Option->Value.Value.u64);\r
 \r
@@ -2523,13 +3105,10 @@ GetQuestionDefault (
       if (Index >= Question->MaxContainers) {\r
         break;\r
       }\r
-\r
-      Link = GetNextNode (&Question->OptionListHead, Link);\r
     }\r
     break;\r
 \r
   default:\r
-    Status = EFI_NOT_FOUND;\r
     break;\r
   }\r
 \r
@@ -2538,65 +3117,201 @@ GetQuestionDefault (
 \r
 \r
 /**\r
-  Reset Questions in a Formset to their default value.\r
+  Reset Questions to their initial value or default value in a Form, Formset or System.\r
+\r
+  GetDefaultValueScope parameter decides which questions will reset \r
+  to its default value.\r
 \r
   @param  FormSet                FormSet data structure.\r
+  @param  Form                   Form data structure.\r
   @param  DefaultId              The Class of the default.\r
+  @param  SettingScope           Setting Scope for Default action.\r
+  @param  GetDefaultValueScope   Get default value scope.\r
+  @param  Storage                Get default value only for this storage.\r
+  @param  RetrieveValueFirst     Whether call the retrieve call back to\r
+                                 get the initial value before get default\r
+                                 value.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
+  @retval EFI_UNSUPPORTED        Unsupport SettingScope.\r
 \r
 **/\r
 EFI_STATUS\r
-ExtractFormSetDefault (\r
+ExtractDefault (\r
   IN FORM_BROWSER_FORMSET             *FormSet,\r
-  IN UINT16                           DefaultId\r
+  IN FORM_BROWSER_FORM                *Form,\r
+  IN UINT16                           DefaultId,\r
+  IN BROWSER_SETTING_SCOPE            SettingScope,\r
+  IN BROWSER_GET_DEFAULT_VALUE        GetDefaultValueScope,\r
+  IN BROWSER_STORAGE                  *Storage OPTIONAL,\r
+  IN BOOLEAN                          RetrieveValueFirst\r
   )\r
 {\r
   EFI_STATUS              Status;\r
   LIST_ENTRY              *FormLink;\r
-  LIST_ENTRY              *StatementLink;\r
+  LIST_ENTRY              *Link;\r
   FORM_BROWSER_STATEMENT  *Question;\r
-  FORM_BROWSER_FORM       *Form;\r
+  FORM_BROWSER_FORMSET    *BackUpFormSet;\r
+  FORM_BROWSER_FORMSET    *LocalFormSet;\r
+  EFI_HII_HANDLE          *HiiHandles;\r
+  UINTN                   Index;\r
+  EFI_GUID                ZeroGuid;\r
 \r
-  FormLink = GetFirstNode (&FormSet->FormListHead);\r
-  while (!IsNull (&FormSet->FormListHead, FormLink)) {\r
-    Form = FORM_BROWSER_FORM_FROM_LINK (FormLink); \r
-    \r
+  Status = EFI_SUCCESS;\r
+\r
+  //\r
+  // Check the supported setting level.\r
+  //\r
+  if (SettingScope >= MaxLevel || GetDefaultValueScope >= GetDefaultForMax) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (GetDefaultValueScope == GetDefaultForStorage && Storage == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  if (SettingScope == FormLevel) {\r
     //\r
     // Extract Form default\r
     //\r
-    StatementLink = GetFirstNode (&Form->StatementListHead);\r
-    while (!IsNull (&Form->StatementListHead, StatementLink)) {\r
-      Question = FORM_BROWSER_STATEMENT_FROM_LINK (StatementLink);\r
-      StatementLink = GetNextNode (&Form->StatementListHead, StatementLink);\r
+    Link = GetFirstNode (&Form->StatementListHead);\r
+    while (!IsNull (&Form->StatementListHead, Link)) {\r
+      Question = FORM_BROWSER_STATEMENT_FROM_LINK (Link);\r
+      Link = GetNextNode (&Form->StatementListHead, Link);\r
+\r
+      //\r
+      // If get default value only for this storage, check the storage first.\r
+      //\r
+      if ((GetDefaultValueScope == GetDefaultForStorage) && (Question->Storage != Storage)) {\r
+        continue;\r
+      }\r
+\r
+      //\r
+      // If get default value only for no storage question, just skip the question which has storage.\r
+      //\r
+      if ((GetDefaultValueScope == GetDefaultForNoStorage) && (Question->Storage != NULL)) {\r
+        continue;\r
+      }\r
 \r
       //\r
       // If Question is disabled, don't reset it to default\r
       //\r
-      if (Question->DisableExpression != NULL) {\r
-        Status = EvaluateExpression (FormSet, Form, Question->DisableExpression);\r
-        if (!EFI_ERROR (Status) && Question->DisableExpression->Result.Value.b) {\r
+      if (Question->Expression != NULL) {\r
+        if (EvaluateExpressionList(Question->Expression, TRUE, FormSet, Form) == ExpressDisable) {\r
+          continue;\r
+        }\r
+      }\r
+\r
+      if (RetrieveValueFirst) {\r
+        //\r
+        // Call the Retrieve call back to get the initial question value.\r
+        //\r
+        Status = ProcessRetrieveForQuestion(FormSet->ConfigAccess, Question);\r
+      }\r
+\r
+      //\r
+      // If not request to get the initial value or get initial value fail, then get default value.\r
+      //\r
+      if (!RetrieveValueFirst || EFI_ERROR (Status)) {\r
+        Status = GetQuestionDefault (FormSet, Form, Question, DefaultId);\r
+        if (EFI_ERROR (Status)) {\r
           continue;\r
         }\r
       }\r
 \r
       //\r
-      // Reset Question to its default value\r
+      // Synchronize Buffer storage's Edit buffer\r
       //\r
-      Status = GetQuestionDefault (FormSet, Form, Question, DefaultId);\r
+      if ((Question->Storage != NULL) &&\r
+          (Question->Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE)) {\r
+        SetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer);\r
+        //\r
+        // Update Form NV flag.\r
+        //\r
+        Form->NvUpdateRequired = TRUE;\r
+      }\r
+    }\r
+  } else if (SettingScope == FormSetLevel) {\r
+    FormLink = GetFirstNode (&FormSet->FormListHead);\r
+    while (!IsNull (&FormSet->FormListHead, FormLink)) {\r
+      Form = FORM_BROWSER_FORM_FROM_LINK (FormLink);\r
+      ExtractDefault (FormSet, Form, DefaultId, FormLevel, GetDefaultValueScope, Storage, RetrieveValueFirst);\r
+      FormLink = GetNextNode (&FormSet->FormListHead, FormLink);\r
+    }\r
+  } else if (SettingScope == SystemLevel) {\r
+    //\r
+    // Open all FormSet by locate HII packages.\r
+    // Initiliaze the maintain FormSet to store default data as back up data.\r
+    //\r
+    BackUpFormSet    = gOldFormSet;\r
+    gOldFormSet      = NULL;\r
+\r
+    //\r
+    // Get all the Hii handles\r
+    //\r
+    HiiHandles = HiiGetHiiHandles (NULL);\r
+    ASSERT (HiiHandles != NULL);\r
+\r
+    //\r
+    // Search for formset of each class type\r
+    //\r
+    for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r
+      //\r
+      // Check HiiHandles[Index] does exist in global maintain list. \r
+      //\r
+      if (GetFormSetFromHiiHandle (HiiHandles[Index]) != NULL) {\r
+        continue;\r
+      }\r
+      \r
+      //\r
+      // Initilize FormSet Setting\r
+      //\r
+      LocalFormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET));\r
+      ASSERT (LocalFormSet != NULL);\r
+      ZeroMem (&ZeroGuid, sizeof (ZeroGuid));\r
+      Status = InitializeFormSet (HiiHandles[Index], &ZeroGuid, LocalFormSet, FALSE);\r
+      if (EFI_ERROR (Status) || IsListEmpty (&LocalFormSet->FormListHead)) {\r
+        DestroyFormSet (LocalFormSet);\r
+        continue;\r
+      }\r
+      Status = InitializeCurrentSetting (LocalFormSet);\r
+      if (EFI_ERROR (Status)) {\r
+        DestroyFormSet (LocalFormSet);\r
+        continue;\r
+      }\r
+      //\r
+      // Initilize Questions' Value\r
+      //\r
+      Status = LoadFormSetConfig (NULL, LocalFormSet);\r
       if (EFI_ERROR (Status)) {\r
+        DestroyFormSet (LocalFormSet);\r
+        continue;\r
+      }\r
+\r
+      //\r
+      // Add FormSet into the maintain list.\r
+      //\r
+      InsertTailList (&gBrowserFormSetList, &LocalFormSet->Link);\r
+    }\r
+    \r
+    //\r
+    // Free resources, and restore gOldFormSet and gClassOfVfr\r
+    //\r
+    FreePool (HiiHandles);\r
+    gOldFormSet = BackUpFormSet;\r
+       \r
+    //\r
+    // Set Default Value for each FormSet in the maintain list.\r
+    //\r
+    Link = GetFirstNode (&gBrowserFormSetList);\r
+    while (!IsNull (&gBrowserFormSetList, Link)) {\r
+      LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link);\r
+      Link = GetNextNode (&gBrowserFormSetList, Link);\r
+      if (!ValidateFormSet(LocalFormSet)) {\r
         continue;\r
       }\r
-\r
-      //\r
-      // Synchronize Buffer storage's Edit buffer\r
-      //\r
-      if ((Question->Storage != NULL) &&\r
-          (Question->Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE)) {\r
-        SetQuestionValue (FormSet, Form, Question, TRUE);\r
-      }\r
+      ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel, GetDefaultValueScope, Storage, RetrieveValueFirst);\r
     }\r
-    FormLink = GetNextNode (&FormSet->FormListHead, FormLink);\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -2608,6 +3323,7 @@ ExtractFormSetDefault (
   @param  Selection              Selection contains the information about \r
                                  the Selection, form and formset to be displayed.\r
                                  Selection action may be updated in retrieve callback.\r
+                                 If Selection is NULL, only initialize Question value.\r
   @param  FormSet                FormSet data structure.\r
   @param  Form                   Form data structure.\r
 \r
@@ -2634,7 +3350,7 @@ LoadFormConfig (
     //\r
     // Initialize local copy of Value for each Question\r
     //\r
-    Status = GetQuestionValue (FormSet, Form, Question, TRUE);\r
+    Status = GetQuestionValue (FormSet, Form, Question, GetSetValueWithEditBuffer);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -2644,25 +3360,10 @@ LoadFormConfig (
     }\r
 \r
     //\r
-    // According the spec, ref opcode try to get value from call back with "retrieve" type.\r
-    //\r
-    if ((Question->Operand == EFI_IFR_REF_OP) && (FormSet->ConfigAccess != NULL)) {\r
-      Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE);\r
-      if (EFI_ERROR (Status)) {\r
-        return Status;\r
-      }\r
-    }\r
-\r
-    //\r
-    // Check whether EfiVarstore with CallBack can be got.\r
+    // Call the Retrieve call back function for all questions.\r
     //\r
-    if ((FormSet->ConfigAccess != NULL) &&\r
-        (Selection->Action != UI_ACTION_REFRESH_FORMSET) &&\r
-        (Question->QuestionId != 0) && \r
-        (Question->Storage != NULL) &&\r
-        (Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) && \r
+    if ((FormSet->ConfigAccess != NULL) && (Selection != NULL) &&\r
         ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK)) {\r
-\r
       //\r
       // Check QuestionValue does exist.\r
       //\r
@@ -2672,17 +3373,21 @@ LoadFormConfig (
       } else {\r
         BufferValue = (UINT8 *) &Question->HiiValue.Value;\r
       }\r
-      Status = gRT->GetVariable (\r
-                       Question->VariableName,\r
-                       &Question->Storage->Guid,\r
-                       NULL,\r
-                       &StorageWidth,\r
-                       BufferValue\r
-                       );\r
 \r
-      if (!EFI_ERROR (Status)) {\r
-        Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE);\r
+      //\r
+      // For efivarstore storage, initial question value first.\r
+      //\r
+      if ((Question->Storage != NULL) && (Question->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE)) {\r
+        Status = gRT->GetVariable (\r
+                         Question->VariableName,\r
+                         &Question->Storage->Guid,\r
+                         NULL,\r
+                         &StorageWidth,\r
+                         BufferValue\r
+                         );\r
       }\r
+\r
+      Status = ProcessCallBackFunction(Selection, Question, EFI_BROWSER_ACTION_RETRIEVE, TRUE);\r
     }\r
 \r
     Link = GetNextNode (&Form->StatementListHead, Link);\r
@@ -2697,6 +3402,7 @@ LoadFormConfig (
   @param  Selection              Selection contains the information about \r
                                  the Selection, form and formset to be displayed.\r
                                  Selection action may be updated in retrieve callback.\r
+                                 If Selection is NULL, only initialize Question value.\r
   @param  FormSet                FormSet data structure.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
@@ -2750,10 +3456,21 @@ LoadStorage (
   EFI_STRING  Result;\r
   CHAR16      *StrPtr;\r
 \r
-  if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
+  if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
+  if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
+    Status = gRT->GetVariable (\r
+                     Storage->BrowserStorage->Name,\r
+                     &Storage->BrowserStorage->Guid,\r
+                     NULL,\r
+                     (UINTN*)&Storage->BrowserStorage->Size,\r
+                     Storage->BrowserStorage->EditBuffer\r
+                     );\r
+    return Status;\r
+  }\r
+\r
   if (FormSet->ConfigAccess == NULL) {\r
     return EFI_NOT_FOUND;\r
   }\r
@@ -2781,67 +3498,16 @@ LoadStorage (
   //\r
   // Convert Result from <ConfigAltResp> to <ConfigResp>\r
   //\r
-  StrPtr = StrStr (Result, L"ALTCFG");\r
+  StrPtr = StrStr (Result, L"&GUID=");\r
   if (StrPtr != NULL) {\r
     *StrPtr = L'\0';\r
   }\r
 \r
-  Status = ConfigRespToStorage (Storage, Result);\r
+  Status = ConfigRespToStorage (Storage->BrowserStorage, Result);\r
   FreePool (Result);\r
   return Status;\r
 }\r
 \r
-\r
-/**\r
-  Copy uncommitted data from source Storage to destination Storage.\r
-\r
-  @param  Dst                    Target Storage for uncommitted data.\r
-  @param  Src                    Source Storage for uncommitted data.\r
-\r
-  @retval EFI_SUCCESS            The function completed successfully.\r
-  @retval EFI_INVALID_PARAMETER  Source and destination Storage is not the same type.\r
-\r
-**/\r
-EFI_STATUS\r
-CopyStorage (\r
-  IN OUT FORMSET_STORAGE     *Dst,\r
-  IN FORMSET_STORAGE         *Src\r
-  )\r
-{\r
-  LIST_ENTRY          *Link;\r
-  NAME_VALUE_NODE     *Node;\r
-\r
-  if ((Dst->Type != Src->Type) || (Dst->Size != Src->Size)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  switch (Src->Type) {\r
-  case EFI_HII_VARSTORE_BUFFER:\r
-    CopyMem (Dst->EditBuffer, Src->EditBuffer, Src->Size);\r
-    CopyMem (Dst->Buffer, Src->Buffer, Src->Size);\r
-    break;\r
-\r
-  case EFI_HII_VARSTORE_NAME_VALUE:\r
-    Link = GetFirstNode (&Src->NameValueListHead);\r
-    while (!IsNull (&Src->NameValueListHead, Link)) {\r
-      Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
-\r
-      SetValueByName (Dst, Node->Name, Node->EditValue, TRUE);\r
-      SetValueByName (Dst, Node->Name, Node->Value, FALSE);\r
-\r
-      Link = GetNextNode (&Src->NameValueListHead, Link);\r
-    }\r
-    break;\r
-\r
-  case EFI_HII_VARSTORE_EFI_VARIABLE:\r
-  default:\r
-    break;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
 /**\r
   Get current setting of Questions.\r
 \r
@@ -2865,12 +3531,9 @@ InitializeCurrentSetting (
   EFI_STATUS              Status;\r
 \r
   //\r
-  // Extract default from IFR binary\r
-  //\r
-  Status = ExtractFormSetDefault (FormSet, EFI_HII_DEFAULT_CLASS_STANDARD);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
+  // Extract default from IFR binary for no storage questions.\r
+  //  \r
+  ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForNoStorage, NULL, TRUE);\r
 \r
   //\r
   // Request current settings from Configuration Driver\r
@@ -2897,23 +3560,30 @@ InitializeCurrentSetting (
       }\r
     }\r
 \r
-    if (OldStorage == NULL) {\r
-      //\r
-      // Storage is not found in backup formset, request it from ConfigDriver\r
-      //\r
+    //\r
+    // Storage is not found in backup formset and current global storage not has other driver used,\r
+    // request it from ConfigDriver\r
+    //\r
+    if (OldStorage == NULL && Storage->BrowserStorage->ReferenceCount == 1) {\r
       Status = LoadStorage (FormSet, Storage);\r
-      //\r
-      // Now Edit Buffer is filled with default values(lower priority) and current\r
-      // settings(higher priority), sychronize it to shadow Buffer\r
-      //\r
-      if (!EFI_ERROR (Status)) {\r
-        SynchronizeStorage (Storage);\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // If get last time changed value failed, extract default from IFR binary\r
+        //\r
+        ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel, GetDefaultForStorage, Storage->BrowserStorage, TRUE);\r
+        //\r
+        // ExtractDefault will set the NV flag to TRUE, so need this function to clean the flag\r
+        // in current situation.\r
+        //\r
+        UpdateNvInfoInForm (FormSet, FALSE);\r
       }\r
-    } else {\r
+\r
       //\r
-      // Storage found in backup formset, use it\r
+      // Now Edit Buffer is filled with default values(lower priority) or current\r
+      // settings(higher priority), sychronize it to shadow Buffer\r
       //\r
-      Status = CopyStorage (Storage, OldStorage);\r
+      SynchronizeStorage (Storage->BrowserStorage, TRUE);\r
     }\r
 \r
     Link = GetNextNode (&FormSet->StorageListHead, Link);\r
@@ -2923,23 +3593,23 @@ InitializeCurrentSetting (
   // If has old formset, get the old nv update status.\r
   //\r
   if (gOldFormSet != NULL) {\r
-      Link = GetFirstNode (&FormSet->FormListHead);\r
-      while (!IsNull (&FormSet->FormListHead, Link)) {\r
-        Form = FORM_BROWSER_FORM_FROM_LINK (Link);\r
-\r
-        Link2 = GetFirstNode (&gOldFormSet->FormListHead);\r
-        while (!IsNull (&gOldFormSet->FormListHead, Link2)) {\r
-          Form2 = FORM_BROWSER_FORM_FROM_LINK (Link2);\r
+    Link = GetFirstNode (&FormSet->FormListHead);\r
+    while (!IsNull (&FormSet->FormListHead, Link)) {\r
+      Form = FORM_BROWSER_FORM_FROM_LINK (Link);\r
 \r
-          if (Form->FormId == Form2->FormId) {\r
-            Form->NvUpdateRequired = Form2->NvUpdateRequired;\r
-            break;\r
-          }\r
+      Link2 = GetFirstNode (&gOldFormSet->FormListHead);\r
+      while (!IsNull (&gOldFormSet->FormListHead, Link2)) {\r
+        Form2 = FORM_BROWSER_FORM_FROM_LINK (Link2);\r
 \r
-          Link2 = GetNextNode (&gOldFormSet->FormListHead, Link2);\r
+        if (Form->FormId == Form2->FormId) {\r
+          Form->NvUpdateRequired = Form2->NvUpdateRequired;\r
+          break;\r
         }\r
-          Link = GetNextNode (&FormSet->FormListHead, Link);\r
+\r
+        Link2 = GetNextNode (&gOldFormSet->FormListHead, Link2);\r
       }\r
+      Link = GetNextNode (&FormSet->FormListHead, Link);\r
+    }\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -2995,8 +3665,8 @@ GetIfrBinaryData (
   //\r
   // if FormSetGuid is NULL or zero GUID, return first Setup FormSet in the package list\r
   //\r
-  if (FormSetGuid == NULL || CompareGuid (FormSetGuid, &gZeroGuid)) {\r
-    ComparingGuid = &gEfiHiiPlatformSetupFormsetGuid;\r
+  if (FormSetGuid == NULL) {\r
+    ComparingGuid = &gZeroGuid;\r
   } else {\r
     ComparingGuid = FormSetGuid;\r
   }\r
@@ -3042,7 +3712,8 @@ GetIfrBinaryData (
           //\r
           // Try to compare against formset GUID\r
           //\r
-          if (CompareGuid (ComparingGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {\r
+          if (CompareGuid (FormSetGuid, &gZeroGuid) || \r
+              CompareGuid (ComparingGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {\r
             break;\r
           }\r
 \r
@@ -3089,7 +3760,7 @@ GetIfrBinaryData (
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  if (ClassGuidMatch && (FormSetGuid != NULL)) {\r
+  if (FormSetGuid != NULL) {\r
     //\r
     // Return the FormSet GUID\r
     //\r
@@ -3124,6 +3795,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
@@ -3133,7 +3805,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
@@ -3145,6 +3818,7 @@ InitializeFormSet (
     return Status;\r
   }\r
 \r
+  FormSet->Signature = FORM_BROWSER_FORMSET_SIGNATURE;\r
   FormSet->HiiHandle = Handle;\r
   CopyMem (&FormSet->Guid, FormSetGuid, sizeof (EFI_GUID));\r
 \r
@@ -3177,6 +3851,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
@@ -3195,8 +3876,11 @@ InitializeFormSet (
     }\r
   }\r
 \r
+  gFunctionKeySetting = ENABLE_FUNCTION_KEY_SETTING;\r
+\r
   if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) == FORMSET_CLASS_FRONT_PAGE) {\r
     gFrontPageHandle = FormSet->HiiHandle;\r
+    gFunctionKeySetting = NONE_FUNCTION_KEY_SETTING;\r
   }\r
 \r
   //\r
@@ -3208,20 +3892,10 @@ InitializeFormSet (
       // Update the function key setting.\r
       //\r
       gFunctionKeySetting = gFunctionKeySettingTable[Index].KeySetting;\r
-      //\r
-      // Function key prompt can not be displayed if the function key has been disabled.\r
-      //\r
-      if ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE) {\r
-        gFunctionNineString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
-      }\r
-\r
-      if ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN) {\r
-        gFunctionTenString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
-      }\r
     }\r
   }\r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 \r
@@ -3259,13 +3933,10 @@ SaveBrowserContext (
   Context->FunctionKeySetting   = gFunctionKeySetting;\r
   Context->ResetRequired        = gResetRequired;\r
   Context->Direction            = gDirection;\r
-  Context->FunctionNineString   = gFunctionNineString;\r
-  Context->FunctionTenString    = gFunctionTenString;\r
   Context->EnterString          = gEnterString;\r
   Context->EnterCommitString    = gEnterCommitString;\r
   Context->EnterEscapeString    = gEnterEscapeString;\r
   Context->EscapeString         = gEscapeString;\r
-  Context->SaveFailed           = gSaveFailed;\r
   Context->MoveHighlight        = gMoveHighlight;\r
   Context->MakeSelection        = gMakeSelection;\r
   Context->DecNumericInput      = gDecNumericInput;\r
@@ -3294,6 +3965,7 @@ SaveBrowserContext (
   Context->HelpBlockWidth       = gHelpBlockWidth;\r
   Context->OldFormSet           = gOldFormSet;\r
   Context->MenuRefreshHead      = gMenuRefreshHead;\r
+  Context->ProtocolNotFound     = gProtocolNotFound;\r
 \r
   CopyMem (&Context->ScreenDimensions, &gScreenDimensions, sizeof (gScreenDimensions));\r
   CopyMem (&Context->MenuOption, &gMenuOption, sizeof (gMenuOption));\r
@@ -3339,13 +4011,10 @@ RestoreBrowserContext (
   gFunctionKeySetting   = Context->FunctionKeySetting;\r
   gResetRequired        = Context->ResetRequired;\r
   gDirection            = Context->Direction;\r
-  gFunctionNineString   = Context->FunctionNineString;\r
-  gFunctionTenString    = Context->FunctionTenString;\r
   gEnterString          = Context->EnterString;\r
   gEnterCommitString    = Context->EnterCommitString;\r
   gEnterEscapeString    = Context->EnterEscapeString;\r
   gEscapeString         = Context->EscapeString;\r
-  gSaveFailed           = Context->SaveFailed;\r
   gMoveHighlight        = Context->MoveHighlight;\r
   gMakeSelection        = Context->MakeSelection;\r
   gDecNumericInput      = Context->DecNumericInput;\r
@@ -3374,6 +4043,7 @@ RestoreBrowserContext (
   gHelpBlockWidth       = Context->HelpBlockWidth;\r
   gOldFormSet           = Context->OldFormSet;\r
   gMenuRefreshHead      = Context->MenuRefreshHead;\r
+  gProtocolNotFound     = Context->ProtocolNotFound;\r
 \r
   CopyMem (&gScreenDimensions, &Context->ScreenDimensions, sizeof (gScreenDimensions));\r
   CopyMem (&gMenuOption, &Context->MenuOption, sizeof (gMenuOption));\r
@@ -3384,3 +4054,339 @@ RestoreBrowserContext (
   RemoveEntryList (&Context->Link);\r
   gBS->FreePool (Context);\r
 }\r
+\r
+/**\r
+  Find the matched FormSet context in the backup maintain list based on HiiHandle.\r
+  \r
+  @param Handle  The Hii Handle.\r
+  \r
+  @return the found FormSet context. If no found, NULL will return.\r
+\r
+**/\r
+FORM_BROWSER_FORMSET * \r
+GetFormSetFromHiiHandle (\r
+  EFI_HII_HANDLE Handle\r
+  )\r
+{\r
+  LIST_ENTRY           *Link;\r
+  FORM_BROWSER_FORMSET *FormSet;\r
+\r
+  Link = GetFirstNode (&gBrowserFormSetList);\r
+  while (!IsNull (&gBrowserFormSetList, Link)) {\r
+    FormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link);\r
+    Link = GetNextNode (&gBrowserFormSetList, Link);\r
+    if (!ValidateFormSet(FormSet)) {\r
+      continue;\r
+    }\r
+    if (FormSet->HiiHandle == Handle) {\r
+      return FormSet;\r
+    }\r
+  }\r
+  \r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Check whether the input HII handle is the FormSet that is being used.\r
+  \r
+  @param Handle  The Hii Handle.\r
+  \r
+  @retval TRUE   HII handle is being used.\r
+  @retval FALSE  HII handle is not being used.\r
+\r
+**/\r
+BOOLEAN\r
+IsHiiHandleInBrowserContext (\r
+  EFI_HII_HANDLE Handle\r
+  )\r
+{\r
+  LIST_ENTRY       *Link;\r
+  BROWSER_CONTEXT  *Context;\r
+\r
+  //\r
+  // HiiHandle is Current FormSet.\r
+  //\r
+  if ((gOldFormSet != NULL) && (gOldFormSet->HiiHandle == Handle)) {\r
+    return TRUE;\r
+  }\r
+\r
+  //\r
+  // Check whether HiiHandle is in BrowserContext.\r
+  //\r
+  Link = GetFirstNode (&gBrowserContextList);\r
+  while (!IsNull (&gBrowserContextList, Link)) {\r
+    Context = BROWSER_CONTEXT_FROM_LINK (Link);\r
+    if (Context->OldFormSet->HiiHandle == Handle) {\r
+      //\r
+      // HiiHandle is in BrowserContext\r
+      //\r
+      return TRUE;\r
+    }\r
+    Link = GetNextNode (&gBrowserContextList, Link);\r
+  }\r
+  \r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Find the registered HotKey based on KeyData.\r
+  \r
+  @param[in] KeyData     A pointer to a buffer that describes the keystroke\r
+                         information for the hot key.\r
+\r
+  @return The registered HotKey context. If no found, NULL will return.\r
+**/\r
+BROWSER_HOT_KEY *\r
+GetHotKeyFromRegisterList (\r
+  IN EFI_INPUT_KEY *KeyData\r
+  )\r
+{\r
+  LIST_ENTRY       *Link;\r
+  BROWSER_HOT_KEY  *HotKey;\r
+\r
+  Link = GetFirstNode (&gBrowserHotKeyList);\r
+  while (!IsNull (&gBrowserHotKeyList, Link)) {\r
+    HotKey = BROWSER_HOT_KEY_FROM_LINK (Link);\r
+    if (HotKey->KeyData->ScanCode == KeyData->ScanCode) {\r
+      return HotKey;\r
+    }\r
+    Link = GetNextNode (&gBrowserHotKeyList, Link);\r
+  }\r
+  \r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Configure what scope the hot key will impact.\r
+  All hot keys have the same scope. The mixed hot keys with the different level are not supported.\r
+  If no scope is set, the default scope will be FormSet level.\r
+  After all registered hot keys are removed, previous Scope can reset to another level.\r
+  \r
+  @param[in] Scope               Scope level to be set. \r
+  \r
+  @retval EFI_SUCCESS            Scope is set correctly.\r
+  @retval EFI_INVALID_PARAMETER  Scope is not the valid value specified in BROWSER_SETTING_SCOPE. \r
+  @retval EFI_UNSPPORTED         Scope level is different from current one that the registered hot keys have.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetScope (\r
+  IN BROWSER_SETTING_SCOPE Scope\r
+  )\r
+{\r
+  if (Scope >= MaxLevel) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // When no hot key registered in system or on the first setting,\r
+  // Scope can be set.\r
+  //\r
+  if (mBrowserScopeFirstSet || IsListEmpty (&gBrowserHotKeyList)) {\r
+    gBrowserSettingScope  = Scope;\r
+    mBrowserScopeFirstSet = FALSE;\r
+  } else if (Scope != gBrowserSettingScope) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Register the hot key with its browser action, or unregistered the hot key.\r
+  Only support hot key that is not printable character (control key, function key, etc.).\r
+  If the action value is zero, the hot key will be unregistered if it has been registered.\r
+  If the same hot key has been registered, the new action and help string will override the previous ones.\r
+  \r
+  @param[in] KeyData     A pointer to a buffer that describes the keystroke\r
+                         information for the hot key. Its type is EFI_INPUT_KEY to \r
+                         be supported by all ConsoleIn devices.\r
+  @param[in] Action      Action value that describes what action will be trigged when the hot key is pressed. \r
+  @param[in] DefaultId   Specifies the type of defaults to retrieve, which is only for DEFAULT action.\r
+  @param[in] HelpString  Help string that describes the hot key information.\r
+                         Its value may be NULL for the unregistered hot key.\r
+  \r
+  @retval EFI_SUCCESS            Hot key is registered or unregistered.\r
+  @retval EFI_INVALID_PARAMETER  KeyData is NULL or HelpString is NULL on register.\r
+  @retval EFI_NOT_FOUND          KeyData is not found to be unregistered.\r
+  @retval EFI_UNSUPPORTED        Key represents a printable character. It is conflicted with Browser.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterHotKey (\r
+  IN EFI_INPUT_KEY *KeyData,\r
+  IN UINT32        Action,\r
+  IN UINT16        DefaultId,\r
+  IN EFI_STRING    HelpString OPTIONAL\r
+  )\r
+{\r
+  BROWSER_HOT_KEY  *HotKey;\r
+\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (KeyData == NULL || KeyData->UnicodeChar != CHAR_NULL || \r
+     (Action != BROWSER_ACTION_UNREGISTER && HelpString == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Check whether the input KeyData is in BrowserHotKeyList.\r
+  //\r
+  HotKey = GetHotKeyFromRegisterList (KeyData);\r
+  \r
+  //\r
+  // Unregister HotKey\r
+  //\r
+  if (Action == BROWSER_ACTION_UNREGISTER) {\r
+    if (HotKey != NULL) {\r
+      //\r
+      // The registered HotKey is found.  \r
+      // Remove it from List, and free its resource.\r
+      //\r
+      RemoveEntryList (&HotKey->Link);\r
+      FreePool (HotKey->KeyData);\r
+      FreePool (HotKey->HelpString);\r
+      return EFI_SUCCESS;\r
+    } else {\r
+      //\r
+      // The registered HotKey is not found. \r
+      //\r
+      return EFI_NOT_FOUND;\r
+    }\r
+  }\r
+  \r
+  //\r
+  // Register HotKey into List.\r
+  //\r
+  if (HotKey == NULL) {\r
+    //\r
+    // Create new Key, and add it into List.\r
+    //\r
+    HotKey = AllocateZeroPool (sizeof (BROWSER_HOT_KEY));\r
+    ASSERT (HotKey != NULL);\r
+    HotKey->Signature = BROWSER_HOT_KEY_SIGNATURE;\r
+    HotKey->KeyData   = AllocateCopyPool (sizeof (EFI_INPUT_KEY), KeyData);\r
+    InsertTailList (&gBrowserHotKeyList, &HotKey->Link);\r
+  }\r
+\r
+  //\r
+  // Fill HotKey information.\r
+  //\r
+  HotKey->Action     = Action;\r
+  HotKey->DefaultId  = DefaultId;\r
+  if (HotKey->HelpString != NULL) {\r
+    FreePool (HotKey->HelpString);\r
+  }\r
+  HotKey->HelpString = AllocateCopyPool (StrSize (HelpString), HelpString);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Register Exit handler function. \r
+  When more than one handler function is registered, the latter one will override the previous one. \r
+  When NULL handler is specified, the previous Exit handler will be unregistered. \r
+  \r
+  @param[in] Handler      Pointer to handler function. \r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+RegiserExitHandler (\r
+  IN EXIT_HANDLER Handler\r
+  )\r
+{\r
+  ExitHandlerFunction = Handler;\r
+  return;\r
+}\r
+\r
+/**\r
+  Create reminder to let user to choose save or discard the changed browser data.\r
+  Caller can use it to actively check the changed browser data.\r
+\r
+  @retval BROWSER_NO_CHANGES       No browser data is changed.\r
+  @retval BROWSER_SAVE_CHANGES     The changed browser data is saved.\r
+  @retval BROWSER_DISCARD_CHANGES  The changed browser data is discard.\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+SaveReminder (\r
+  VOID\r
+  )\r
+{\r
+  LIST_ENTRY              *Link;\r
+  FORM_BROWSER_FORMSET    *FormSet;\r
+  BOOLEAN                 IsDataChanged;\r
+  UINT32                  DataSavedAction;\r
+  CHAR16                  *YesResponse;\r
+  CHAR16                  *NoResponse;\r
+  CHAR16                  *EmptyString;\r
+  CHAR16                  *ChangeReminderString;\r
+  CHAR16                  *SaveConfirmString;\r
+  EFI_INPUT_KEY           Key;\r
+\r
+  DataSavedAction  = BROWSER_NO_CHANGES;\r
+  IsDataChanged    = FALSE;\r
+  Link = GetFirstNode (&gBrowserFormSetList);\r
+  while (!IsNull (&gBrowserFormSetList, Link)) {\r
+    FormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link);\r
+    Link = GetNextNode (&gBrowserFormSetList, Link);\r
+    if (!ValidateFormSet(FormSet)) {\r
+      continue;\r
+    }\r
+    if (IsNvUpdateRequired (FormSet)) {\r
+      IsDataChanged = TRUE;\r
+      break;\r
+    }\r
+  }\r
+  \r
+  //\r
+  // No data is changed. No save is required. \r
+  //\r
+  if (!IsDataChanged) {\r
+    return DataSavedAction;\r
+  }\r
+  \r
+  //\r
+  // If data is changed, prompt user\r
+  //\r
+  gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+\r
+  YesResponse          = GetToken (STRING_TOKEN (ARE_YOU_SURE_YES), gHiiHandle);\r
+  ASSERT (YesResponse != NULL);\r
+  NoResponse           = GetToken (STRING_TOKEN (ARE_YOU_SURE_NO), gHiiHandle);\r
+  ASSERT (NoResponse  != NULL);\r
+  EmptyString          = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
+  ChangeReminderString = GetToken (STRING_TOKEN (CHANGE_REMINDER), gHiiHandle);\r
+  SaveConfirmString    = GetToken (STRING_TOKEN (SAVE_CONFIRM), gHiiHandle);\r
+\r
+  do {\r
+    CreateDialog (4, TRUE, 0, NULL, &Key, EmptyString, ChangeReminderString, SaveConfirmString, EmptyString);\r
+  } while\r
+  (((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse[0] | UPPER_LOWER_CASE_OFFSET)) &&\r
+   ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse[0] | UPPER_LOWER_CASE_OFFSET))\r
+  );\r
+\r
+  //\r
+  // If the user hits the YesResponse key\r
+  //\r
+  if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse[0] | UPPER_LOWER_CASE_OFFSET)) {\r
+    SubmitForm (NULL, NULL, SystemLevel);\r
+    DataSavedAction = BROWSER_SAVE_CHANGES;\r
+  } else {\r
+    DiscardForm (NULL, NULL, SystemLevel);\r
+    DataSavedAction = BROWSER_DISCARD_CHANGES;\r
+    gResetRequired  = FALSE;\r
+  }\r
+\r
+  FreePool (YesResponse);\r
+  FreePool (NoResponse);\r
+  FreePool (EmptyString);\r
+  FreePool (SaveConfirmString);\r
+  FreePool (ChangeReminderString);\r
+\r
+  return DataSavedAction;\r
+}\r