]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
Per UEFI spec, on CallBack action EFI_BROWSER_ACTION_CHANGING, the return value of...
[mirror_edk2.git] / MdeModulePkg / Universal / DriverSampleDxe / DriverSample.c
index 9f78db28542c9533884db5a2c043118936feadfa..e7c1202ecfd7eacc68b2ce22a9627c356e428c2b 100644 (file)
@@ -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
@@ -517,7 +662,6 @@ AppendAltCfgString (
   )\r
 {\r
   EFI_STRING                          StringPtr;\r
-  EFI_STRING                          TmpPtr;\r
   UINTN                               Length;\r
   UINT8                               *TmpBuffer;\r
   UINTN                               Offset;\r
@@ -538,11 +682,6 @@ AppendAltCfgString (
   }\r
 \r
   while (*StringPtr != 0 && StrnCmp (StringPtr, L"OFFSET=", StrLen (L"OFFSET=")) == 0) {\r
-    //\r
-    // Back up the header of one <BlockName>\r
-    //\r
-    TmpPtr = StringPtr;\r
-\r
     StringPtr += StrLen (L"OFFSET=");\r
     //\r
     // Get Offset\r
@@ -679,7 +818,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
@@ -697,7 +836,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
@@ -710,10 +849,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
@@ -834,7 +980,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
@@ -912,17 +1058,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
@@ -1041,7 +1195,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
@@ -1070,7 +1224,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
@@ -1115,7 +1269,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
@@ -1123,7 +1276,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
@@ -1131,6 +1285,7 @@ DriverCallback (
   }\r
 \r
 \r
+  FormId = 0;\r
   Status = EFI_SUCCESS;\r
   PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
 \r
@@ -1169,7 +1324,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
@@ -1177,6 +1332,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
@@ -1199,26 +1359,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
@@ -1254,6 +1412,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
@@ -1315,7 +1482,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
@@ -1326,14 +1493,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
@@ -1412,7 +1579,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
@@ -1424,6 +1591,7 @@ DriverCallback (
       break;\r
 \r
     case 0x5678:\r
+    case 0x1247:\r
       //\r
       // We will reach here once the Question is refreshed\r
       //\r
@@ -1439,7 +1607,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
@@ -1452,8 +1628,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
@@ -1463,70 +1639,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
-      break;\r
-\r
-    case 0x1237:\r
-      //\r
-      // User press "Exit now", request Browser to exit\r
-      //\r
-      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
-      break;\r
-\r
-    case 0x1238:\r
-      //\r
-      // User press "Save now", request Browser to save the uncommitted data.\r
-      //\r
-      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
-      break;\r
-\r
-    case 0x1241:\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
-      //\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
+      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 0x2000:\r
@@ -1563,27 +1701,63 @@ 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
   }\r
   break;\r
 \r
+  case EFI_BROWSER_ACTION_CHANGED:\r
+    switch (QuestionId) {\r
+      case 0x1237:\r
+        //\r
+        // User press "Exit now", request Browser to exit\r
+        //\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
+        break;\r
+      \r
+      case 0x1238:\r
+        //\r
+        // User press "Save now", request Browser to save the uncommitted data.\r
+        //\r
+        *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
+      default:\r
+      break;\r
+    }\r
+  break;\r
+\r
   default:\r
     Status = EFI_UNSUPPORTED;\r
     break;\r
@@ -1620,6 +1794,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
@@ -1702,7 +1877,7 @@ DriverSampleInit (
   // Publish our HII data\r
   //\r
   HiiHandle[0] = HiiAddPackages (\r
-                   &mFormSetGuid,\r
+                   &gDriverSampleFormSetGuid,\r
                    DriverHandle[0],\r
                    DriverSampleStrings,\r
                    VfrBin,\r
@@ -1728,7 +1903,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,6 +1916,14 @@ DriverSampleInit (
 \r
   PrivateData->HiiHandle[1] = HiiHandle[1];\r
 \r
+  //\r
+  // Update the device path string.\r
+  //\r
+  if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), (EFI_STRING) &mHiiVendorDevicePath0, NULL) == 0) {\r
+    DriverSampleUnload (ImageHandle);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  \r
   //\r
   // Very simple example of how one would update a string that is already\r
   // in the HII database\r
@@ -1770,18 +1953,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
@@ -1800,10 +1983,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
@@ -1891,5 +2119,7 @@ DriverSampleUnload (
   FreePool (PrivateData);\r
   PrivateData = NULL;\r
 \r
+  gBS->CloseEvent (mEvent);\r
+\r
   return EFI_SUCCESS;\r
 }\r