]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
Clean up the private GUID definition in module Level.
[mirror_edk2.git] / MdeModulePkg / Universal / DriverSampleDxe / DriverSample.c
index 83e669b9da5da5a114129a38e192d2eb56090c12..b6621a93e275033a0c21edc50d306bd52537e80a 100644 (file)
@@ -2,7 +2,7 @@
 This is an example of how a driver might export data to the HII protocol to be\r
 later utilized by the Setup Protocol\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2011, 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
@@ -18,12 +18,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #define DISPLAY_ONLY_MY_ITEM  0x0002\r
 \r
-EFI_GUID   mFormSetGuid = FORMSET_GUID;\r
-EFI_GUID   mInventoryGuid = INVENTORY_GUID;\r
-\r
 CHAR16     VariableName[] = L"MyIfrNVData";\r
+CHAR16     MyEfiVar[] = L"MyEfiVar";\r
 EFI_HANDLE                      DriverHandle[2] = {NULL, NULL};\r
 DRIVER_SAMPLE_PRIVATE_DATA      *PrivateData = NULL;\r
+EFI_EVENT                       mEvent;\r
 \r
 HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath0 = {\r
   {\r
@@ -35,10 +34,7 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath0 = {
         (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
       }\r
     },\r
-    //\r
-    // {C153B68D-EBFC-488e-B110-662867745B87}\r
-    //\r
-    { 0xc153b68d, 0xebfc, 0x488e, { 0xb1, 0x10, 0x66, 0x28, 0x67, 0x74, 0x5b, 0x87 } }\r
+    DRIVER_SAMPLE_FORMSET_GUID\r
   },\r
   {\r
     END_DEVICE_PATH_TYPE,\r
@@ -60,10 +56,7 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath1 = {
         (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
       }\r
     },\r
-    //\r
-    // {06F37F07-0C48-40e9-8436-0A08A0BB76B0}\r
-    //\r
-    { 0x6f37f07, 0xc48, 0x40e9, { 0x84, 0x36, 0xa, 0x8, 0xa0, 0xbb, 0x76, 0xb0 } }\r
+    DRIVER_SAMPLE_INVENTORY_GUID\r
   },\r
   {\r
     END_DEVICE_PATH_TYPE,\r
@@ -75,6 +68,158 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath1 = {
   }\r
 };\r
 \r
+/**\r
+  Add empty function for event process function.\r
+\r
+  @param Event    The Event need to be process\r
+  @param Context  The context of the event.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+DriverSampleInternalEmptyFunction (\r
+  IN  EFI_EVENT Event,\r
+  IN  VOID      *Context\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Notification function for keystrokes.\r
+\r
+  @param[in] KeyData    The key that was pressed.\r
+\r
+  @retval EFI_SUCCESS   The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+NotificationFunction(\r
+  IN EFI_KEY_DATA *KeyData\r
+  )\r
+{\r
+  gBS->SignalEvent (mEvent);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Function to start monitoring for CTRL-C using SimpleTextInputEx. \r
+\r
+  @retval EFI_SUCCESS           The feature is enabled.\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough mnemory available.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalStartMonitor(\r
+  VOID\r
+  )\r
+{\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
+  EFI_KEY_DATA                      KeyData;\r
+  EFI_STATUS                        Status;\r
+  EFI_HANDLE                        *Handles;\r
+  UINTN                             HandleCount;\r
+  UINTN                             HandleIndex;\r
+  EFI_HANDLE                        NotifyHandle;\r
+\r
+  Status = gBS->LocateHandleBuffer (\r
+              ByProtocol,\r
+              &gEfiSimpleTextInputExProtocolGuid,\r
+              NULL,\r
+              &HandleCount,\r
+              &Handles\r
+              );\r
+  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
+    Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    KeyData.KeyState.KeyToggleState = 0;\r
+    KeyData.Key.ScanCode            = 0;\r
+    KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
+    KeyData.Key.UnicodeChar         = L'c';\r
+\r
+    Status = SimpleEx->RegisterKeyNotify(\r
+      SimpleEx,\r
+      &KeyData,\r
+      NotificationFunction,\r
+      &NotifyHandle);\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+    \r
+    KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
+    Status = SimpleEx->RegisterKeyNotify(\r
+      SimpleEx,\r
+      &KeyData,\r
+      NotificationFunction,\r
+      &NotifyHandle);\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Function to stop monitoring for CTRL-C using SimpleTextInputEx.  \r
+\r
+  @retval EFI_SUCCESS           The feature is enabled.\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough mnemory available.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalStopMonitor(\r
+  VOID\r
+  )\r
+{\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
+  EFI_STATUS                        Status;\r
+  EFI_HANDLE                        *Handles;\r
+  EFI_KEY_DATA                      KeyData;  \r
+  UINTN                             HandleCount;\r
+  UINTN                             HandleIndex;\r
+  EFI_HANDLE                        NotifyHandle;\r
+\r
+  Status = gBS->LocateHandleBuffer (\r
+                ByProtocol,\r
+                &gEfiSimpleTextInputExProtocolGuid,\r
+                NULL,\r
+                &HandleCount,\r
+                &Handles\r
+                );\r
+  for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
+    Status = gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleTextInputExProtocolGuid, (VOID **) &SimpleEx);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    KeyData.KeyState.KeyToggleState = 0;\r
+    KeyData.Key.ScanCode            = 0;\r
+    KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
+    KeyData.Key.UnicodeChar         = L'c';\r
+\r
+    Status = SimpleEx->RegisterKeyNotify(\r
+      SimpleEx,\r
+      &KeyData,\r
+      NotificationFunction,\r
+      &NotifyHandle);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);\r
+    }\r
+\r
+    KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
+    Status = SimpleEx->RegisterKeyNotify(\r
+      SimpleEx,\r
+      &KeyData,\r
+      NotificationFunction,\r
+      &NotifyHandle);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = SimpleEx->UnregisterKeyNotify (SimpleEx, NotifyHandle);\r
+    }\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
 /**\r
   Encode the password using a simple algorithm.\r
 \r
@@ -138,7 +283,7 @@ ValidatePassword (
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
   Status = gRT->GetVariable (\r
                   VariableName,\r
-                  &mFormSetGuid,\r
+                  &gDriverSampleFormSetGuid,\r
                   NULL,\r
                   &BufferSize,\r
                   &PrivateData->Configuration\r
@@ -231,7 +376,7 @@ SetPassword (
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
   Status = gRT->GetVariable (\r
                   VariableName,\r
-                  &mFormSetGuid,\r
+                  &gDriverSampleFormSetGuid,\r
                   NULL,\r
                   &BufferSize,\r
                   &PrivateData->Configuration\r
@@ -263,7 +408,7 @@ SetPassword (
   //\r
   Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));\r
   ASSERT (Configuration != NULL);\r
-  if (HiiGetBrowserData (&mFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
+  if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
     //\r
     // Update password's clear text in the screen\r
     //\r
@@ -273,7 +418,7 @@ SetPassword (
     // Update uncommitted data of Browser\r
     //\r
     HiiSetBrowserData (\r
-       &mFormSetGuid,\r
+       &gDriverSampleFormSetGuid,\r
        VariableName,\r
        sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
        (UINT8 *) Configuration,\r
@@ -293,7 +438,7 @@ SetPassword (
   EncodePassword (Password, StrLen (Password) * 2);\r
   Status = gRT->SetVariable(\r
                   VariableName,\r
-                  &mFormSetGuid,\r
+                  &gDriverSampleFormSetGuid,\r
                   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                   sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                   &PrivateData->Configuration\r
@@ -444,10 +589,11 @@ CreateAltCfgString (
   EFI_STRING TmpStr;\r
   UINTN      NewLen;\r
 \r
+  NewLen = StrLen (Result);\r
   //\r
   // String Len = ConfigResp + AltConfig + AltConfig + 1("\0")\r
   //\r
-  NewLen = (StrLen (Result) + ((1 + StrLen (ConfigHdr) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16);\r
+  NewLen = (NewLen + ((1 + StrLen (ConfigHdr) + 8 + 4) + (8 + 4 + 7 + 4 + 7 + 4)) * 2 + 1) * sizeof (CHAR16);\r
   StringPtr = AllocateZeroPool (NewLen);\r
   if (StringPtr == NULL) {\r
     return NULL;\r
@@ -586,7 +732,7 @@ AppendAltCfgString (
     StringPtr += StrLen (L"&VALUE=");\r
 \r
     //\r
-    // Get Width\r
+    // Get Value\r
     //\r
     Status = GetValueOfNumber (StringPtr, &TmpBuffer, &Length);\r
     if (EFI_ERROR (Status)) {\r
@@ -678,7 +824,7 @@ ExtractConfig (
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
   Status = gRT->GetVariable (\r
             VariableName,\r
-            &mFormSetGuid,\r
+            &gDriverSampleFormSetGuid,\r
             NULL,\r
             &BufferSize,\r
             &PrivateData->Configuration\r
@@ -696,7 +842,7 @@ ExtractConfig (
     // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
     // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
     //\r
-    ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
+    ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
     Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
     ConfigRequest = AllocateZeroPool (Size);\r
     ASSERT (ConfigRequest != NULL);\r
@@ -709,10 +855,17 @@ ExtractConfig (
     // Check routing data in <ConfigHdr>.\r
     // Note: if only one Storage is used, then this checking could be skipped.\r
     //\r
-    if (!HiiIsConfigHdrMatch (Request, &mFormSetGuid, NULL)) {\r
+    if (!HiiIsConfigHdrMatch (Request, &gDriverSampleFormSetGuid, NULL)) {\r
       return EFI_NOT_FOUND;\r
     }\r
     //\r
+    // Check whether request for EFI Varstore. EFI varstore get data\r
+    // through hii database, not support in this path.\r
+    //\r
+    if (HiiIsConfigHdrMatch(Request, &gDriverSampleFormSetGuid, MyEfiVar)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    //\r
     // Set Request to the unified request string.\r
     //\r
     ConfigRequest = Request;\r
@@ -833,7 +986,7 @@ ExtractConfig (
                                   Progress\r
                                   );\r
     if (!EFI_ERROR (Status)) {\r
-      ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
+      ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
       AppendAltCfgString(Results, ConfigRequestHdr);\r
     }\r
   }\r
@@ -911,17 +1064,25 @@ RouteConfig (
   // Check routing data in <ConfigHdr>.\r
   // Note: if only one Storage is used, then this checking could be skipped.\r
   //\r
-  if (!HiiIsConfigHdrMatch (Configuration, &mFormSetGuid, NULL)) {\r
+  if (!HiiIsConfigHdrMatch (Configuration, &gDriverSampleFormSetGuid, NULL)) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
+  //\r
+  // Check whether request for EFI Varstore. EFI varstore get data\r
+  // through hii database, not support in this path.\r
+  //\r
+  if (HiiIsConfigHdrMatch(Configuration, &gDriverSampleFormSetGuid, MyEfiVar)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   //\r
   // Get Buffer Storage data from EFI variable\r
   //\r
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
   Status = gRT->GetVariable (\r
             VariableName,\r
-            &mFormSetGuid,\r
+            &gDriverSampleFormSetGuid,\r
             NULL,\r
             &BufferSize,\r
             &PrivateData->Configuration\r
@@ -1040,7 +1201,7 @@ RouteConfig (
     //\r
     Status = gRT->SetVariable(\r
       VariableName,\r
-      &mFormSetGuid,\r
+      &gDriverSampleFormSetGuid,\r
       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
       sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
       &PrivateData->Configuration\r
@@ -1069,7 +1230,7 @@ RouteConfig (
   //\r
   Status = gRT->SetVariable(\r
                   VariableName,\r
-                  &mFormSetGuid,\r
+                  &gDriverSampleFormSetGuid,\r
                   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                   sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                   &PrivateData->Configuration\r
@@ -1114,7 +1275,6 @@ DriverCallback (
 {\r
   DRIVER_SAMPLE_PRIVATE_DATA      *PrivateData;\r
   EFI_STATUS                      Status;\r
-  UINT8                           MyVar;\r
   VOID                            *StartOpCodeHandle;\r
   VOID                            *OptionsOpCodeHandle;\r
   EFI_IFR_GUID_LABEL              *StartLabel;\r
@@ -1122,7 +1282,8 @@ DriverCallback (
   EFI_IFR_GUID_LABEL              *EndLabel;\r
   EFI_INPUT_KEY                   Key;\r
   DRIVER_SAMPLE_CONFIGURATION     *Configuration;\r
-  UINTN                           MyVarSize;\r
+  MY_EFI_VARSTORE_DATA            *EfiData;\r
+  EFI_FORM_ID                     FormId;\r
   \r
   if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))||\r
     (ActionRequest == NULL)) {\r
@@ -1130,6 +1291,7 @@ DriverCallback (
   }\r
 \r
 \r
+  FormId = 0;\r
   Status = EFI_SUCCESS;\r
   PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
 \r
@@ -1168,7 +1330,7 @@ DriverCallback (
 \r
         HiiUpdateForm (\r
           PrivateData->HiiHandle[0],  // HII handle\r
-          &mFormSetGuid,              // Formset GUID\r
+          &gDriverSampleFormSetGuid,  // Formset GUID\r
           0x3,                        // Form ID\r
           StartOpCodeHandle,          // Label for where to insert opcodes\r
           NULL                        // Insert data\r
@@ -1176,6 +1338,11 @@ DriverCallback (
 \r
         HiiFreeOpCodeHandle (StartOpCodeHandle);\r
       }\r
+\r
+      if (QuestionId == 0x1247) {\r
+        Status = InternalStartMonitor ();\r
+        ASSERT_EFI_ERROR (Status);\r
+      }\r
     }\r
     break;\r
 \r
@@ -1198,26 +1365,24 @@ DriverCallback (
             );\r
         } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
       }\r
+\r
+      if (QuestionId == 0x1247) {\r
+        Status = InternalStopMonitor ();\r
+        ASSERT_EFI_ERROR (Status);\r
+      }\r
     }\r
     break;\r
     \r
   case EFI_BROWSER_ACTION_RETRIEVE:\r
     {\r
-      if (QuestionId == 0x1111) {\r
-        //\r
-        // EfiVarstore question takes sample action (print value as debug information) \r
-        // after read/write question.\r
-        //\r
-        MyVarSize = 1;\r
-        Status = gRT->GetVariable(\r
-                        L"MyVar",\r
-                        &mFormSetGuid,\r
-                        NULL,\r
-                        &MyVarSize,\r
-                        &MyVar\r
-                        );\r
-        ASSERT_EFI_ERROR (Status);\r
-        DEBUG ((DEBUG_INFO, "EfiVarstore question: Tall value is %d with value width %d\n", MyVar, MyVarSize));\r
+      if (QuestionId == 0x1248) {\r
+        {\r
+          if (Type != EFI_IFR_TYPE_REF) {\r
+            return EFI_INVALID_PARAMETER;\r
+          }\r
+        \r
+          Value->ref.FormId = 0x3;\r
+        }\r
       }\r
     }\r
     break;\r
@@ -1253,6 +1418,15 @@ DriverCallback (
   case EFI_BROWSER_ACTION_CHANGING:\r
   {\r
     switch (QuestionId) {\r
+    case 0x1249:\r
+      {\r
+        if (Type != EFI_IFR_TYPE_REF) {\r
+          return EFI_INVALID_PARAMETER;\r
+        }\r
+\r
+        Value->ref.FormId = 0x1234;\r
+      }\r
+    break;\r
     case 0x1234:\r
       //\r
       // Initialize the container for dynamic opcodes\r
@@ -1314,7 +1488,7 @@ DriverCallback (
       PrivateData->Configuration.DynamicOneof = 2;\r
       Status = gRT->SetVariable(\r
                       VariableName,\r
-                      &mFormSetGuid,\r
+                      &gDriverSampleFormSetGuid,\r
                       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                       sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                       &PrivateData->Configuration\r
@@ -1325,14 +1499,14 @@ DriverCallback (
       //\r
       Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));\r
       ASSERT (Configuration != NULL);\r
-      if (HiiGetBrowserData (&mFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
+      if (HiiGetBrowserData (&gDriverSampleFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration)) {\r
         Configuration->DynamicOneof = 2;\r
 \r
         //\r
         // Update uncommitted data of Browser\r
         //\r
         HiiSetBrowserData (\r
-          &mFormSetGuid,\r
+          &gDriverSampleFormSetGuid,\r
           VariableName,\r
           sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
           (UINT8 *) Configuration,\r
@@ -1411,7 +1585,7 @@ DriverCallback (
 \r
       HiiUpdateForm (\r
         PrivateData->HiiHandle[0],  // HII handle\r
-        &mFormSetGuid,              // Formset GUID\r
+        &gDriverSampleFormSetGuid,  // Formset GUID\r
         0x1234,                     // Form ID\r
         StartOpCodeHandle,          // Label for where to insert opcodes\r
         EndOpCodeHandle             // Replace data\r
@@ -1423,6 +1597,7 @@ DriverCallback (
       break;\r
 \r
     case 0x5678:\r
+    case 0x1247:\r
       //\r
       // We will reach here once the Question is refreshed\r
       //\r
@@ -1438,7 +1613,15 @@ DriverCallback (
       //\r
       StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
       StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
-      StartLabel->Number       = LABEL_UPDATE2;\r
+      if (QuestionId == 0x5678) {\r
+        StartLabel->Number       = LABEL_UPDATE2;\r
+        FormId                   = 0x03;\r
+        PrivateData->Configuration.DynamicRefresh++;\r
+      } else if (QuestionId == 0x1247 ) {\r
+        StartLabel->Number       = LABEL_UPDATE3;\r
+        FormId                   = 0x06;\r
+        PrivateData->Configuration.RefreshGuidCount++;\r
+      }\r
 \r
       HiiCreateActionOpCode (\r
         StartOpCodeHandle,                // Container for dynamic created opcodes\r
@@ -1451,8 +1634,8 @@ DriverCallback (
 \r
       HiiUpdateForm (\r
         PrivateData->HiiHandle[0],  // HII handle\r
-        &mFormSetGuid,              // Formset GUID\r
-        0x3,                        // Form ID\r
+        &gDriverSampleFormSetGuid,              // Formset GUID\r
+        FormId,                        // Form ID\r
         StartOpCodeHandle,          // Label for where to insert opcodes\r
         NULL                        // Insert data\r
         );\r
@@ -1462,28 +1645,32 @@ DriverCallback (
       //\r
       // Refresh the Question value\r
       //\r
-      PrivateData->Configuration.DynamicRefresh++;\r
       Status = gRT->SetVariable(\r
                       VariableName,\r
-                      &mFormSetGuid,\r
+                      &gDriverSampleFormSetGuid,\r
                       EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                       sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                       &PrivateData->Configuration\r
                       );\r
 \r
-      //\r
-      // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause\r
-      // the first statement in Form 3 be suppressed\r
-      //\r
-      MyVarSize = 1;\r
-      MyVar = 111;\r
-      Status = gRT->SetVariable(\r
-                      L"MyVar",\r
-                      &mFormSetGuid,\r
-                      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                      MyVarSize,\r
-                      &MyVar\r
-                      );\r
+      if (QuestionId == 0x5678) {\r
+        //\r
+        // Update uncommitted data of Browser\r
+        //\r
+        EfiData = AllocateZeroPool (sizeof (MY_EFI_VARSTORE_DATA));\r
+        ASSERT (EfiData != NULL);\r
+        if (HiiGetBrowserData (&gDriverSampleFormSetGuid, MyEfiVar, sizeof (MY_EFI_VARSTORE_DATA), (UINT8 *) EfiData)) {\r
+          EfiData->Field8 = 111;\r
+          HiiSetBrowserData (\r
+            &gDriverSampleFormSetGuid,\r
+            MyEfiVar,\r
+            sizeof (MY_EFI_VARSTORE_DATA),\r
+            (UINT8 *) EfiData,\r
+            NULL\r
+            );\r
+        }\r
+        FreePool (EfiData);\r
+      }\r
       break;\r
 \r
     case 0x1237:\r
@@ -1500,6 +1687,36 @@ DriverCallback (
       *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
       break;\r
 \r
+    case 0x1241:\r
+    case 0x1246:\r
+      //\r
+      // User press "Submit current form and Exit now", request Browser to submit current form and exit\r
+      //\r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;\r
+      break;\r
+\r
+    case 0x1242:\r
+      //\r
+      // User press "Discard current form now", request Browser to discard the uncommitted data.\r
+      //\r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD;\r
+      break;\r
+\r
+    case 0x1243:\r
+      //\r
+      // User press "Submit current form now", request Browser to save the uncommitted data.\r
+      //\r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
+      break;\r
+\r
+    case 0x1244:\r
+    case 0x1245:\r
+      //\r
+      // User press "Discard current form and Exit now", request Browser to discard the uncommitted data and exit.\r
+      //\r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;\r
+      break;\r
+\r
     case 0x2000:\r
       //\r
       // Only used to update the state.\r
@@ -1534,21 +1751,6 @@ DriverCallback (
 \r
       break;\r
 \r
-    case 0x1111:\r
-      //\r
-      // EfiVarstore question takes sample action (print value as debug information) \r
-      // after read/write question.\r
-      //\r
-      MyVarSize = 1;\r
-      Status = gRT->GetVariable(\r
-                      L"MyVar",\r
-                      &mFormSetGuid,\r
-                      NULL,\r
-                      &MyVarSize,\r
-                      &MyVar\r
-                      );\r
-      ASSERT_EFI_ERROR (Status);\r
-      DEBUG ((DEBUG_INFO, "EfiVarstore question: Tall value is %d with value width %d\n", MyVar, MyVarSize));\r
     default:\r
       break;\r
     }\r
@@ -1591,6 +1793,7 @@ DriverSampleInit (
   DRIVER_SAMPLE_CONFIGURATION     *Configuration;\r
   BOOLEAN                         ActionFlag;\r
   EFI_STRING                      ConfigRequestHdr;\r
+  MY_EFI_VARSTORE_DATA            *VarStoreConfig;\r
 \r
   //\r
   // Initialize the local variables.\r
@@ -1673,7 +1876,7 @@ DriverSampleInit (
   // Publish our HII data\r
   //\r
   HiiHandle[0] = HiiAddPackages (\r
-                   &mFormSetGuid,\r
+                   &gDriverSampleFormSetGuid,\r
                    DriverHandle[0],\r
                    DriverSampleStrings,\r
                    VfrBin,\r
@@ -1699,7 +1902,7 @@ DriverSampleInit (
   PrivateData->DriverHandle[1] = DriverHandle[1];\r
 \r
   HiiHandle[1] = HiiAddPackages (\r
-                   &mInventoryGuid,\r
+                   &gDriverSampleInventoryGuid,\r
                    DriverHandle[1],\r
                    DriverSampleStrings,\r
                    InventoryBin,\r
@@ -1741,18 +1944,18 @@ DriverSampleInit (
   //\r
   // Try to read NV config EFI variable first\r
   //\r
-  ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, DriverHandle[0]);\r
+  ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, VariableName, DriverHandle[0]);\r
   ASSERT (ConfigRequestHdr != NULL);\r
 \r
   BufferSize = sizeof (DRIVER_SAMPLE_CONFIGURATION);\r
-  Status = gRT->GetVariable (VariableName, &mFormSetGuid, NULL, &BufferSize, Configuration);\r
+  Status = gRT->GetVariable (VariableName, &gDriverSampleFormSetGuid, NULL, &BufferSize, Configuration);\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // Store zero data Buffer Storage to EFI variable\r
     //\r
     Status = gRT->SetVariable(\r
                     VariableName,\r
-                    &mFormSetGuid,\r
+                    &gDriverSampleFormSetGuid,\r
                     EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
                     sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                     Configuration\r
@@ -1771,10 +1974,55 @@ DriverSampleInit (
     ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
     ASSERT (ActionFlag);\r
   }\r
-\r
   FreePool (ConfigRequestHdr);\r
 \r
+  //\r
+  // Initialize efi varstore configuration data\r
+  //\r
+  VarStoreConfig = &PrivateData->VarStoreConfig;\r
+  ZeroMem (VarStoreConfig, sizeof (MY_EFI_VARSTORE_DATA));\r
+\r
+  ConfigRequestHdr = HiiConstructConfigHdr (&gDriverSampleFormSetGuid, MyEfiVar, DriverHandle[0]);\r
+  ASSERT (ConfigRequestHdr != NULL);\r
+\r
+  BufferSize = sizeof (MY_EFI_VARSTORE_DATA);\r
+  Status = gRT->GetVariable (MyEfiVar, &gDriverSampleFormSetGuid, NULL, &BufferSize, VarStoreConfig);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Store zero data to EFI variable Storage.\r
+    //\r
+    Status = gRT->SetVariable(\r
+                    MyEfiVar,\r
+                    &gDriverSampleFormSetGuid,\r
+                    EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    sizeof (MY_EFI_VARSTORE_DATA),\r
+                    VarStoreConfig\r
+                    );\r
+    ASSERT (Status == EFI_SUCCESS);\r
+    //\r
+    // EFI variable for NV config doesn't exit, we should build this variable\r
+    // based on default values stored in IFR\r
+    //\r
+    ActionFlag = HiiSetToDefaults (ConfigRequestHdr, EFI_HII_DEFAULT_CLASS_STANDARD);\r
+    ASSERT (ActionFlag);\r
+  } else {\r
+    //\r
+    // EFI variable does exist and Validate Current Setting\r
+    //\r
+    ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
+    ASSERT (ActionFlag);\r
+  }\r
+  FreePool (ConfigRequestHdr);\r
 \r
+  Status = gBS->CreateEventEx (\r
+        EVT_NOTIFY_SIGNAL, \r
+        TPL_NOTIFY,\r
+        DriverSampleInternalEmptyFunction,\r
+        NULL,\r
+        &gEfiIfrRefreshIdOpGuid,\r
+        &mEvent\r
+        );\r
+  ASSERT_EFI_ERROR (Status);\r
   //\r
   // In default, this driver is built into Flash device image,\r
   // the following code doesn't run.\r
@@ -1862,5 +2110,7 @@ DriverSampleUnload (
   FreePool (PrivateData);\r
   PrivateData = NULL;\r
 \r
+  gBS->CloseEvent (mEvent);\r
+\r
   return EFI_SUCCESS;\r
 }\r