]> 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 e20e030be8fbf0fba1c20855a9bf2ab3eecc70b8..b6621a93e275033a0c21edc50d306bd52537e80a 100644 (file)
@@ -18,11 +18,8 @@ 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
-EFI_GUID   MyEventGroupGuid = EFI_IFR_REFRESH_ID_OP_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
@@ -37,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
@@ -62,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
@@ -292,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
@@ -385,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
@@ -417,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
@@ -427,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
@@ -447,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
@@ -833,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
@@ -851,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
@@ -864,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
@@ -988,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
@@ -1066,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
@@ -1195,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
@@ -1224,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
@@ -1269,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
@@ -1277,7 +1282,7 @@ 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
@@ -1325,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
@@ -1370,21 +1375,14 @@ DriverCallback (
     \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
@@ -1420,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
@@ -1481,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
@@ -1492,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
@@ -1578,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
@@ -1612,7 +1619,7 @@ DriverCallback (
         PrivateData->Configuration.DynamicRefresh++;\r
       } else if (QuestionId == 0x1247 ) {\r
         StartLabel->Number       = LABEL_UPDATE3;\r
-        FormId                   = 0x05;\r
+        FormId                   = 0x06;\r
         PrivateData->Configuration.RefreshGuidCount++;\r
       }\r
 \r
@@ -1627,7 +1634,7 @@ DriverCallback (
 \r
       HiiUpdateForm (\r
         PrivateData->HiiHandle[0],  // HII handle\r
-        &mFormSetGuid,              // Formset GUID\r
+        &gDriverSampleFormSetGuid,              // Formset GUID\r
         FormId,                        // Form ID\r
         StartOpCodeHandle,          // Label for where to insert opcodes\r
         NULL                        // Insert data\r
@@ -1640,7 +1647,7 @@ DriverCallback (
       //\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
@@ -1648,18 +1655,21 @@ DriverCallback (
 \r
       if (QuestionId == 0x5678) {\r
         //\r
-        // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause\r
-        // the first statement in Form 3 be suppressed\r
+        // Update uncommitted data of Browser\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
+        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
@@ -1741,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
@@ -1798,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
@@ -1880,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
@@ -1906,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
@@ -1948,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
@@ -1978,7 +1974,44 @@ DriverSampleInit (
     ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
     ASSERT (ActionFlag);\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
@@ -1986,7 +2019,7 @@ DriverSampleInit (
         TPL_NOTIFY,\r
         DriverSampleInternalEmptyFunction,\r
         NULL,\r
-        &MyEventGroupGuid,\r
+        &gEfiIfrRefreshIdOpGuid,\r
         &mEvent\r
         );\r
   ASSERT_EFI_ERROR (Status);\r