]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
Update the code to follow the spec when evaluate the expression.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Setup.c
index fa721f6d1622ef9d91c517650291e02421e32175..d4f3fa01d61f19286a8d82bd677bab1f2bf20dfa 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 - 2012, 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,6 +20,12 @@ SETUP_DRIVER_PRIVATE_DATA  mPrivateData = {
   {\r
     SendForm,\r
     BrowserCallback\r
+  },\r
+  {\r
+    SetScope,\r
+    RegisterHotKey,\r
+    RegiserExitHandler,\r
+    SaveReminder\r
   }\r
 };\r
 \r
@@ -29,6 +35,8 @@ EFI_HII_CONFIG_ROUTING_PROTOCOL   *mHiiConfigRouting;
 \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
 \r
 BANNER_DATA           *gBannerData;\r
 EFI_HII_HANDLE        gFrontPageHandle;\r
@@ -38,17 +46,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
@@ -84,7 +96,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 +226,28 @@ 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
   // 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 +282,7 @@ SendForm (
             SCROLL_ARROW_HEIGHT *\r
             2 +\r
             FRONT_PAGE_HEADER_HEIGHT +\r
-            FOOTER_HEIGHT +\r
+            gFooterHeight +\r
             1\r
           )\r
         ) {\r
@@ -275,7 +303,7 @@ SendForm (
   //\r
   InitializeBrowserStrings ();\r
 \r
-  gFunctionKeySetting = DEFAULT_FUNCTION_KEY_SETTING;\r
+  gFunctionKeySetting = ENABLE_FUNCTION_KEY_SETTING;\r
 \r
   //\r
   // Ensure we are in Text mode\r
@@ -290,10 +318,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 +329,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 +357,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
@@ -431,7 +470,8 @@ BrowserCallback (
       Link = GetNextNode (&FormSet->StorageListHead, Link);\r
 \r
       if (CompareGuid (&Storage->Guid, (EFI_GUID *) VariableGuid)) {\r
-        if (Storage->Type == EFI_HII_VARSTORE_BUFFER) {\r
+        if (Storage->Type == EFI_HII_VARSTORE_BUFFER ||\r
+            Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
           //\r
           // Buffer storage require both GUID and Name\r
           //\r
@@ -516,6 +556,65 @@ BrowserCallback (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Notify function will remove the formset in the maintain list \r
+  once this formset is removed.\r
+  \r
+  Functions which are registered to receive notification of\r
+  database events have this prototype. The actual event is encoded\r
+  in NotifyType. The following table describes how PackageType,\r
+  PackageGuid, Handle, and Package are used for each of the\r
+  notification types.\r
+\r
+  @param PackageType  Package type of the notification.\r
+\r
+  @param PackageGuid  If PackageType is\r
+                      EFI_HII_PACKAGE_TYPE_GUID, then this is\r
+                      the pointer to the GUID from the Guid\r
+                      field of EFI_HII_PACKAGE_GUID_HEADER.\r
+                      Otherwise, it must be NULL.\r
+\r
+  @param Package  Points to the package referred to by the\r
+                  notification Handle The handle of the package\r
+                  list which contains the specified package.\r
+\r
+  @param Handle       The HII handle.\r
+\r
+  @param NotifyType   The type of change concerning the\r
+                      database. See\r
+                      EFI_HII_DATABASE_NOTIFY_TYPE.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FormsetRemoveNotify (\r
+  IN UINT8                              PackageType,\r
+  IN CONST EFI_GUID                     *PackageGuid,\r
+  IN CONST EFI_HII_PACKAGE_HEADER       *Package,\r
+  IN EFI_HII_HANDLE                     Handle,\r
+  IN EFI_HII_DATABASE_NOTIFY_TYPE       NotifyType\r
+  )\r
+{\r
+  FORM_BROWSER_FORMSET *FormSet;\r
+\r
+  //\r
+  // Ignore the update for current using formset, which is handled by another notify function.\r
+  //\r
+  if (IsHiiHandleInBrowserContext (Handle)) {\r
+    return EFI_SUCCESS;\r
+  }\r
+  \r
+  //\r
+  // Remove the backup FormSet data when the Form Package is removed.\r
+  //\r
+  FormSet = GetFormSetFromHiiHandle (Handle);\r
+  if (FormSet != NULL) {\r
+    RemoveEntryList (&FormSet->Link);\r
+    DestroyFormSet (FormSet);\r
+  }\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   Initialize Setup Browser driver.\r
@@ -535,6 +634,9 @@ InitializeSetup (
   )\r
 {\r
   EFI_STATUS                  Status;\r
+  EFI_HANDLE                  NotifyHandle;\r
+  EFI_INPUT_KEY               DefaultHotKey;\r
+  EFI_STRING                  HelpString;\r
 \r
   //\r
   // Locate required Hii relative protocols\r
@@ -576,6 +678,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 +698,47 @@ 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
+  //\r
+  // Register notify for Form package remove\r
+  //\r
+  Status = mHiiDatabase->RegisterPackageNotify (\r
+                           mHiiDatabase,\r
+                           EFI_HII_PACKAGE_FORMS,\r
+                           NULL,\r
+                           FormsetRemoveNotify,\r
+                           EFI_HII_DATABASE_NOTIFY_REMOVE_PACK,\r
+                           &NotifyHandle\r
+                           );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return Status;\r
 }\r
 \r
@@ -727,14 +877,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 FORMSET_STORAGE         *Storage,\r
+  IN BOOLEAN                 SyncOrRestore\r
   )\r
 {\r
   LIST_ENTRY              *Link;\r
@@ -742,7 +897,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 +910,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
@@ -894,6 +1058,7 @@ StorageToConfigResp (
 \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
@@ -959,6 +1124,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
@@ -1050,8 +1216,11 @@ 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
   //\r
   // Statement don't have storage, skip them\r
@@ -1066,7 +1235,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 +1257,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,7 +1366,12 @@ 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 (IsBufferStorage) {\r
@@ -1230,115 +1429,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
@@ -1350,7 +1581,9 @@ GetQuestionValue (
       SetValueByName (Storage, Question->VariableName, Value, TRUE);\r
     }\r
 \r
-    FreePool (Result);\r
+    if (Result != NULL) {\r
+      FreePool (Result);\r
+    }\r
   }\r
 \r
   return Status;\r
@@ -1507,7 +1740,12 @@ SetQuestionValue (
     Src = (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 (IsBufferStorage) {\r
     //\r
@@ -1550,84 +1788,115 @@ SetQuestionValue (
   }\r
 \r
   if (!Cached) {\r
-    //\r
-    // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||\r
-    //                <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"\r
-    //\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
-    } else {\r
-      Length += (StorageWidth * 2);\r
-    }\r
-    ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16));\r
-    ASSERT (ConfigResp != NULL);\r
+    if (Storage->Type == EFI_HII_VARSTORE_BUFFER || Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+      //\r
+      // <ConfigResp> ::= <ConfigHdr> + <BlockName> + "&VALUE=" + "<HexCh>StorageWidth * 2" ||\r
+      //                <ConfigHdr> + "&" + <VariableName> + "=" + "<string>"\r
+      //\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
+      } else {\r
+        Length += (StorageWidth * 2);\r
+      }\r
+      ConfigResp = AllocateZeroPool ((StrLen (Storage->ConfigHdr) + Length + 1) * sizeof (CHAR16));\r
+      ASSERT (ConfigResp != NULL);\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
-    }\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
-    Value = ConfigResp + StrLen (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
-    if (!IsBufferStorage && IsString) {\r
       //\r
-      // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044"\r
+      // Convert to lower char.\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
+      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
-    } else {\r
+\r
       //\r
-      // Convert Buffer to Hex String\r
+      // Submit Question Value to Configuration Driver\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 (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
-    }\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
+      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
+      Length = Storage->Size;\r
+      Status = gRT->GetVariable (\r
+                       Storage->Name,\r
+                       &Storage->Guid,\r
+                       NULL,\r
+                       &Length,\r
+                       TemBuffer\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
+      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
-    FreePool (ConfigResp);\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 +1950,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 +2019,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 +2045,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 +2061,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 +2088,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
@@ -1874,78 +2117,104 @@ FormRestoreStorage (
 \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
-        if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
-          continue;\r
-        }\r
+  //\r
+  // Check the supported setting level.\r
+  //\r
+  if (SettingScope >= MaxLevel) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
-        //\r
-        // Skip if there is no RequestElement\r
-        //\r
-        if (ConfigInfo->ElementCount == 0) {\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
-        // Prepare <ConfigResp>\r
-        //\r
-        FormRestoreStorage(FormSet, ConfigInfo);\r
+      if (ConfigInfo->Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {\r
+        continue;\r
+      }\r
+\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
-  } else {\r
-    if (IsNvUpdateRequired(FormSet)) {\r
+\r
+    Form->NvUpdateRequired = FALSE;\r
+  } else if (SettingScope == FormSetLevel && IsNvUpdateRequired(FormSet)) {\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->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, FALSE);\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
+      DiscardForm (LocalFormSet, NULL, FormSetLevel);\r
+      Link = GetNextNode (&gBrowserFormSetList, Link);\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,20 +2222,21 @@ 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
@@ -1974,28 +2244,40 @@ SubmitForm (
   EFI_STRING              ConfigResp;\r
   EFI_STRING              Progress;\r
   FORMSET_STORAGE         *Storage;\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,7 +2289,7 @@ SubmitForm (
       }\r
 \r
       //\r
-      // Prepare <ConfigResp>\r
+      // 1. Prepare <ConfigResp>\r
       //\r
       Status = StorageToConfigResp (ConfigInfo, &ConfigResp, TRUE);\r
       if (EFI_ERROR (Status)) {\r
@@ -2015,29 +2297,84 @@ SubmitForm (
       }\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
@@ -2058,36 +2395,108 @@ SubmitForm (
       }\r
 \r
       //\r
-      // Prepare <ConfigResp>\r
+      // 1. Prepare <ConfigResp>\r
       //\r
       Status = StorageToConfigResp (Storage, &ConfigResp, FALSE);\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
+      SubmitForm (LocalFormSet, NULL, FormSetLevel);\r
+      Link = GetNextNode (&gBrowserFormSetList, Link);\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
@@ -2136,7 +2545,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 +2757,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 +2825,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 +2850,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
@@ -2485,6 +2912,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 +2920,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
@@ -2504,6 +2933,7 @@ GetQuestionDefault (
       if (!IsNull (&Question->OptionListHead, Link)) {\r
         Option = QUESTION_OPTION_FROM_LINK (Link);\r
         CopyMem (HiiValue, &Option->Value, sizeof (EFI_HII_VALUE));\r
+        Status = EFI_SUCCESS;\r
       }\r
     }\r
     break;\r
@@ -2515,6 +2945,7 @@ 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
 \r
       SetArrayData (Question->BufferValue, Question->ValueType, Index, Option->Value.Value.u64);\r
@@ -2529,7 +2960,6 @@ GetQuestionDefault (
     break;\r
 \r
   default:\r
-    Status = EFI_NOT_FOUND;\r
     break;\r
   }\r
 \r
@@ -2538,55 +2968,157 @@ GetQuestionDefault (
 \r
 \r
 /**\r
-  Reset Questions in a Form to their default value.\r
+  Reset Questions to their default value in a Form, Formset or System.\r
 \r
   @param  FormSet                FormSet data structure.\r
-  @param  Form                   The Form which to be reset.\r
+  @param  Form                   Form data structure.\r
   @param  DefaultId              The Class of the default.\r
+  @param  SettingScope           Setting Scope for Default action.\r
 \r
   @retval EFI_SUCCESS            The function completed successfully.\r
+  @retval EFI_UNSUPPORTED        Unsupport SettingScope.\r
 \r
 **/\r
 EFI_STATUS\r
-ExtractFormDefault (\r
+ExtractDefault (\r
   IN FORM_BROWSER_FORMSET             *FormSet,\r
   IN FORM_BROWSER_FORM                *Form,\r
-  IN UINT16                           DefaultId\r
+  IN UINT16                           DefaultId,\r
+  IN BROWSER_SETTING_SCOPE            SettingScope\r
   )\r
 {\r
   EFI_STATUS              Status;\r
+  LIST_ENTRY              *FormLink;\r
   LIST_ENTRY              *Link;\r
   FORM_BROWSER_STATEMENT  *Question;\r
+  FORM_BROWSER_FORMSET    *BackUpFormSet;\r
+  FORM_BROWSER_FORMSET    *LocalFormSet;\r
+  EFI_HII_HANDLE          *HiiHandles;\r
+  UINTN                   Index;\r
+  EFI_GUID                ZeroGuid;\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
+  //\r
+  // Check the supported setting level.\r
+  //\r
+  if (SettingScope >= MaxLevel) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  if (SettingScope == FormLevel) {\r
     //\r
-    // If Question is disabled, don't reset it to default\r
+    // Extract Form 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
+    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 Question is disabled, don't reset it to default\r
+      //\r
+      if (Question->Expression != NULL) {\r
+        if (EvaluateExpressionList(Question->Expression, TRUE, FormSet, Form) == ExpressDisable) {\r
+          continue;\r
+        }\r
+      }\r
+  \r
+      //\r
+      // Reset Question to its default value\r
+      //\r
+      Status = GetQuestionDefault (FormSet, Form, Question, DefaultId);\r
+      if (EFI_ERROR (Status)) {\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
+        // 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);\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
-    // Reset Question to its default value\r
+    // Get all the Hii handles\r
     //\r
-    Status = GetQuestionDefault (FormSet, Form, Question, DefaultId);\r
-    if (EFI_ERROR (Status)) {\r
-      continue;\r
-    }\r
+    HiiHandles = HiiGetHiiHandles (NULL);\r
+    ASSERT (HiiHandles != NULL);\r
 \r
     //\r
-    // Synchronize Buffer storage's Edit buffer\r
+    // Search for formset of each class type\r
     //\r
-    if ((Question->Storage != NULL) &&\r
-        (Question->Storage->Type != EFI_HII_VARSTORE_EFI_VARIABLE)) {\r
-      SetQuestionValue (FormSet, Form, Question, TRUE);\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
+      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
+      ExtractDefault (LocalFormSet, NULL, DefaultId, FormSetLevel);\r
+      Link = GetNextNode (&gBrowserFormSetList, Link);\r
     }\r
   }\r
 \r
@@ -2599,6 +3131,7 @@ ExtractFormDefault (
   @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,10 +3167,21 @@ LoadFormConfig (
       HiiSetString (FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);\r
     }\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) && (Selection != 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
     //\r
     if ((FormSet->ConfigAccess != NULL) &&\r
+        (Selection != NULL) &&\r
         (Selection->Action != UI_ACTION_REFRESH_FORMSET) &&\r
         (Question->QuestionId != 0) && \r
         (Question->Storage != NULL) &&\r
@@ -2678,6 +3222,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
@@ -2735,6 +3280,17 @@ LoadStorage (
     return EFI_SUCCESS;\r
   }\r
 \r
+  if (Storage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {\r
+    Status = gRT->GetVariable (\r
+                     Storage->Name,\r
+                     &Storage->Guid,\r
+                     NULL,\r
+                     (UINTN*)&Storage->Size,\r
+                     Storage->EditBuffer\r
+                     );\r
+    return Status;\r
+  }\r
+\r
   if (FormSet->ConfigAccess == NULL) {\r
     return EFI_NOT_FOUND;\r
   }\r
@@ -2798,6 +3354,7 @@ CopyStorage (
 \r
   switch (Src->Type) {\r
   case EFI_HII_VARSTORE_BUFFER:\r
+  case EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER:\r
     CopyMem (Dst->EditBuffer, Src->EditBuffer, Src->Size);\r
     CopyMem (Dst->Buffer, Src->Buffer, Src->Size);\r
     break;\r
@@ -2848,14 +3405,8 @@ InitializeCurrentSetting (
   //\r
   // Extract default from IFR binary\r
   //\r
-  Link = GetFirstNode (&FormSet->FormListHead);\r
-  while (!IsNull (&FormSet->FormListHead, Link)) {\r
-    Form = FORM_BROWSER_FORM_FROM_LINK (Link);\r
-\r
-    Status = ExtractFormDefault (FormSet, Form, EFI_HII_DEFAULT_CLASS_STANDARD);\r
-\r
-    Link = GetNextNode (&FormSet->FormListHead, Link);\r
-  }\r
+  ExtractDefault (FormSet, NULL, EFI_HII_DEFAULT_CLASS_STANDARD, FormSetLevel);\r
+  UpdateNvInfoInForm (FormSet, FALSE);\r
 \r
   //\r
   // Request current settings from Configuration Driver\r
@@ -2892,7 +3443,7 @@ InitializeCurrentSetting (
       // settings(higher priority), sychronize it to shadow Buffer\r
       //\r
       if (!EFI_ERROR (Status)) {\r
-        SynchronizeStorage (Storage);\r
+        SynchronizeStorage (Storage, TRUE);\r
       }\r
     } else {\r
       //\r
@@ -2980,8 +3531,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
@@ -3027,7 +3578,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
@@ -3074,7 +3626,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
@@ -3109,6 +3661,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
@@ -3118,7 +3671,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
@@ -3130,6 +3684,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
@@ -3162,6 +3717,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
@@ -3182,6 +3744,7 @@ InitializeFormSet (
 \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
@@ -3193,20 +3756,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
@@ -3244,13 +3797,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
@@ -3324,13 +3874,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
@@ -3369,3 +3916,333 @@ 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
+    if (FormSet->HiiHandle == Handle) {\r
+      return FormSet;\r
+    }\r
+    Link = GetNextNode (&gBrowserFormSetList, Link);\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
+    if (IsNvUpdateRequired (FormSet)) {\r
+      IsDataChanged = TRUE;\r
+      break;\r
+    }\r
+    Link = GetNextNode (&gBrowserFormSetList, Link);\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