]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
Update code logic to let BDS UI can shows more than one formsets in one HiiHandle.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / DeviceMngr / DeviceManager.c
index 14e71e3e52b803fb6913a7c992aa2457c27c0783..6a76c33f267dda4359897c8f1a5a3c4439d9db86 100644 (file)
@@ -208,8 +208,10 @@ InitializeDeviceManager (
 \r
   @param Handle          The HII handle.\r
   @param SetupClassGuid  The class guid specifies which form set will be displayed.\r
+  @param SkipCount       Skip some formsets which has processed before.\r
   @param FormSetTitle    Formset title string.\r
   @param FormSetHelp     Formset help string.\r
+  @param FormSetGuid     Return the formset guid for this formset.\r
 \r
   @retval  TRUE          The formset for given HII handle will be displayed.\r
   @return  FALSE         The formset for given HII handle will not be displayed.\r
@@ -219,8 +221,10 @@ BOOLEAN
 ExtractDisplayedHiiFormFromHiiHandle (\r
   IN      EFI_HII_HANDLE      Handle,\r
   IN      EFI_GUID            *SetupClassGuid,\r
+  IN      UINTN               SkipCount,\r
   OUT     EFI_STRING_ID       *FormSetTitle,\r
-  OUT     EFI_STRING_ID       *FormSetHelp\r
+  OUT     EFI_STRING_ID       *FormSetHelp,\r
+  OUT     EFI_GUID            **FormSetGuid\r
   )\r
 {\r
   EFI_STATUS                   Status;\r
@@ -286,8 +290,14 @@ ExtractDisplayedHiiFormFromHiiHandle (
       Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);\r
       while (Offset2 < PackageHeader.Length) {\r
         OpCodeData = Package + Offset2;\r
+        Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
 \r
         if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) {\r
+          if (SkipCount != 0) {\r
+            SkipCount --;\r
+            continue;\r
+          }\r
+\r
           if (((EFI_IFR_OP_HEADER *) OpCodeData)->Length > OFFSET_OF (EFI_IFR_FORM_SET, Flags)) {\r
             //\r
             // Find FormSet OpCode\r
@@ -298,6 +308,8 @@ ExtractDisplayedHiiFormFromHiiHandle (
               if (CompareGuid (SetupClassGuid, ClassGuid)) {\r
                 CopyMem (FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID));\r
                 CopyMem (FormSetHelp, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID));\r
+                *FormSetGuid = AllocateCopyPool (sizeof (EFI_GUID), &((EFI_IFR_FORM_SET *) OpCodeData)->Guid);\r
+                ASSERT (*FormSetGuid != NULL);\r
                 FreePool (HiiPackageList);\r
                 return TRUE;\r
               }\r
@@ -306,15 +318,12 @@ ExtractDisplayedHiiFormFromHiiHandle (
            } else {\r
              CopyMem (FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID));\r
              CopyMem (FormSetHelp, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID));\r
+             *FormSetGuid = AllocateCopyPool (sizeof (EFI_GUID), &((EFI_IFR_FORM_SET *) OpCodeData)->Guid);\r
+             ASSERT (*FormSetGuid != NULL);\r
              FreePool (HiiPackageList);\r
              return TRUE;\r
           }\r
         }\r
-        \r
-        //\r
-        // Go to next opcode\r
-        //\r
-        Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
       }\r
     }\r
     \r
@@ -699,6 +708,71 @@ Done:
   return IsNeedAdd; \r
 }\r
 \r
+/**\r
+  Get HiiHandle total number.\r
+\r
+  @param   HiiHandles              The input HiiHandle array.\r
+\r
+  @retval  the Hiihandle count.\r
+\r
+**/\r
+UINTN\r
+GetHiiHandleCount (\r
+  IN EFI_HII_HANDLE              *HiiHandles\r
+  )\r
+{\r
+  UINTN  Index;\r
+\r
+  for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r
+  }\r
+\r
+  return Index;\r
+}\r
+\r
+/**\r
+  Insert the new HiiHandle + FormsetGuid at the NewPair[InsertOffset].\r
+\r
+  @param   HiiHandles              The input HiiHandle array.\r
+  @param   GuidLists               The input form set guid lists.\r
+  @param   ArrayCount              The input array count, new array will be arraycount + 1 size.\r
+  @param   Offset                  The current used HiiHandle's Offset. \r
+  @param   FormSetGuid             The new found formset guid.\r
+\r
+**/\r
+VOID\r
+AdjustArrayData (\r
+  IN OUT EFI_HII_HANDLE              **HiiHandles,\r
+  IN OUT EFI_GUID                    ***GuidLists,\r
+  IN     UINTN                       ArrayCount,\r
+  IN     UINTN                       Offset,\r
+  IN     EFI_GUID                    *FormSetGuid\r
+  )\r
+{\r
+  EFI_HII_HANDLE              *NewHiiHandles;\r
+  EFI_GUID                    **NewGuidLists;\r
+\r
+  //\r
+  // +2 means include the new HiiHandle and the last empty NULL pointer.\r
+  //\r
+  NewHiiHandles = AllocateZeroPool ((ArrayCount + 2) * sizeof (EFI_HII_HANDLE));\r
+  ASSERT (NewHiiHandles != NULL);\r
+\r
+  CopyMem (NewHiiHandles, *HiiHandles, Offset * sizeof (EFI_HII_HANDLE));\r
+  NewHiiHandles[Offset] = NewHiiHandles[Offset - 1];\r
+  CopyMem (NewHiiHandles + Offset + 1, *HiiHandles + Offset, (ArrayCount - Offset) * sizeof (EFI_HII_HANDLE));\r
+\r
+  NewGuidLists = AllocateZeroPool ((ArrayCount + 2) * sizeof (EFI_GUID *));\r
+  ASSERT (NewGuidLists != NULL);\r
+\r
+  CopyMem (NewGuidLists, *GuidLists, Offset * sizeof (EFI_GUID *));\r
+  NewGuidLists[Offset] = FormSetGuid;\r
+\r
+  FreePool (*HiiHandles);\r
+  *HiiHandles = NewHiiHandles;\r
+  FreePool (*GuidLists);\r
+  *GuidLists = NewGuidLists;\r
+}\r
+\r
 /**\r
   Call the browser and display the device manager to allow user\r
   to configure the platform.\r
@@ -736,7 +810,12 @@ CallDeviceManager (
   UINTN                       AddItemCount;\r
   UINTN                       NewStringLen;\r
   EFI_STRING                  NewStringTitle;\r
+  EFI_GUID                    **GuidLists;\r
+  UINTN                       HandleNum;\r
+  UINTN                       SkipCount;\r
+  EFI_GUID                    *FormSetGuid;\r
 \r
+  GuidLists     = NULL;\r
   HiiHandles    = NULL;\r
   Status        = EFI_SUCCESS;\r
   gCallbackKey  = 0;\r
@@ -744,6 +823,8 @@ CallDeviceManager (
   DriverHealthHandles = NULL;\r
   AddNetworkMenu = FALSE;\r
   AddItemCount   = 0;\r
+  SkipCount      = 0;\r
+  FormSetGuid    = NULL;\r
 \r
   //\r
   // Connect all prior to entering the platform setup menu.\r
@@ -825,6 +906,10 @@ CallDeviceManager (
   HiiHandles = HiiGetHiiHandles (NULL);\r
   ASSERT (HiiHandles != NULL);\r
 \r
+  HandleNum = GetHiiHandleCount (HiiHandles);\r
+  GuidLists = AllocateZeroPool ((HandleNum + 1) * sizeof (EFI_GUID *));\r
+  ASSERT (GuidLists != NULL);\r
+\r
   //\r
   // Search for formset of each class type\r
   //\r
@@ -836,10 +921,21 @@ CallDeviceManager (
     //\r
     ASSERT(Index < MAX_KEY_SECTION_LEN);\r
 \r
-    if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, &FormSetTitle, &FormSetHelp)) {\r
+    if (!ExtractDisplayedHiiFormFromHiiHandle (HiiHandles[Index], &gEfiHiiPlatformSetupFormsetGuid, SkipCount, &FormSetTitle, &FormSetHelp, &FormSetGuid)) {\r
+      SkipCount = 0;\r
       continue;\r
     }\r
 \r
+    //\r
+    // One HiiHandle has more than one formset can be shown, \r
+    // Insert a new pair of HiiHandle + Guid to the HiiHandles and GuidLists list.\r
+    // \r
+    if (SkipCount > 0) {\r
+      AdjustArrayData (&HiiHandles, &GuidLists, HandleNum, Index + 1, FormSetGuid);\r
+      HandleNum ++;\r
+      Index ++;\r
+    }\r
+\r
     String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL);\r
     if (String == NULL) {\r
       String = HiiGetString (HiiHandle, STR_MISSING_STRING, NULL);\r
@@ -919,6 +1015,12 @@ CallDeviceManager (
           );\r
       }\r
     }\r
+\r
+    //\r
+    // Try to find more formset in this HiiHandle.\r
+    //\r
+    SkipCount++;\r
+    Index--;\r
   }\r
 \r
   Status = gBS->LocateHandleBuffer (\r
@@ -994,7 +1096,7 @@ CallDeviceManager (
                              gFormBrowser2,\r
                              &HiiHandles[gCallbackKey - DEVICE_KEY_OFFSET],\r
                              1,\r
-                             NULL,\r
+                             GuidLists[gCallbackKey - DEVICE_KEY_OFFSET],\r
                              0,\r
                              NULL,\r
                              &ActionRequest\r
@@ -1062,6 +1164,13 @@ Done:
   HiiFreeOpCodeHandle (EndOpCodeHandle);\r
   FreePool (HiiHandles);\r
 \r
+  for (Index = 0; Index < HandleNum; Index++) {\r
+    if (GuidLists[Index] != NULL) {\r
+      FreePool (GuidLists[Index]);\r
+    }\r
+  }\r
+  FreePool (GuidLists);\r
+\r
   return Status;\r
 }\r
 \r