]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c
Locate the config route protocol before install the config access protocol to fix...
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriOverrideDxe / PlatDriOverrideDxe.c
index 0f0da166ad9984dda31826cbf54112dfe02afbc3..7027e9697e842478980db596e5bb7db0d6f3980b 100644 (file)
@@ -13,7 +13,7 @@
   4. It save all the mapping info in NV variables which will be consumed\r
      by platform override protocol driver to publish the platform override protocol.\r
 \r
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2015, 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
@@ -70,16 +70,16 @@ EFI_HANDLE                   *mDevicePathHandleBuffer;
 EFI_HANDLE                   *mDriverImageHandleBuffer;\r
 \r
 INTN                         mSelectedCtrIndex;\r
-EFI_STRING_ID                mControllerToken[MAX_CHOICE_NUM];\r
+EFI_STRING_ID                *mControllerToken;\r
 UINTN                        mDriverImageHandleCount;\r
-EFI_STRING_ID                mDriverImageToken[MAX_CHOICE_NUM];\r
-EFI_STRING_ID                mDriverImageFilePathToken[MAX_CHOICE_NUM];\r
-EFI_LOADED_IMAGE_PROTOCOL    *mDriverImageProtocol[MAX_CHOICE_NUM];\r
-EFI_DEVICE_PATH_PROTOCOL     *mControllerDevicePathProtocol[MAX_CHOICE_NUM];\r
+EFI_STRING_ID                *mDriverImageToken;\r
+EFI_DEVICE_PATH_PROTOCOL     **mControllerDevicePathProtocol;\r
 UINTN                        mSelectedDriverImageNum;\r
 UINTN                        mLastSavedDriverImageNum;\r
 UINT16                       mCurrentPage;\r
 EFI_CALLBACK_INFO           *mCallbackInfo;\r
+BOOLEAN                     *mDriSelection;\r
+UINTN                        mMaxDeviceCount;\r
 \r
 HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath = {\r
   {\r
@@ -425,6 +425,12 @@ UpdateDeviceSelectPage (
     return EFI_SUCCESS;\r
   }\r
 \r
+  mMaxDeviceCount = DevicePathHandleCount;\r
+  mControllerDevicePathProtocol = AllocateZeroPool (DevicePathHandleCount * sizeof (EFI_DEVICE_PATH_PROTOCOL *));\r
+  ASSERT (mControllerDevicePathProtocol != NULL);\r
+  mControllerToken = AllocateZeroPool (DevicePathHandleCount * sizeof (EFI_STRING_ID));\r
+  ASSERT (mControllerToken != NULL);\r
+\r
   for (Index = 0; Index < DevicePathHandleCount; Index++) {\r
     if (FakeNvData->PciDeviceFilter == 0x01) {\r
       //\r
@@ -630,6 +636,9 @@ UpdateBindingDriverSelectPage (
   VOID                                      *EndOpCodeHandle;\r
   EFI_IFR_GUID_LABEL                        *StartLabel;\r
   EFI_IFR_GUID_LABEL                        *EndLabel;\r
+  EFI_LOADED_IMAGE_PROTOCOL                 **DriverImageProtocol;\r
+  EFI_STRING_ID                             *DriverImageFilePathToken;\r
+  UINT8                                     CheckFlags;\r
 \r
   //\r
   // If user select a controller item in the first page  the following code will be run.\r
@@ -698,6 +707,16 @@ UpdateBindingDriverSelectPage (
     return EFI_NOT_FOUND;\r
   }\r
 \r
+  mDriverImageToken = AllocateZeroPool (DriverImageHandleCount * sizeof (EFI_STRING_ID));\r
+  ASSERT (mDriverImageToken != NULL);\r
+  mDriSelection = AllocateZeroPool (DriverImageHandleCount * sizeof (BOOLEAN));\r
+  ASSERT (mDriSelection != NULL);\r
+\r
+  DriverImageProtocol = AllocateZeroPool (DriverImageHandleCount * sizeof (EFI_LOADED_IMAGE_PROTOCOL *));\r
+  ASSERT (DriverImageProtocol != NULL);\r
+  DriverImageFilePathToken = AllocateZeroPool (DriverImageHandleCount * sizeof (EFI_STRING_ID));\r
+  ASSERT (DriverImageFilePathToken != NULL);\r
+\r
   mDriverImageHandleCount = DriverImageHandleCount;\r
   for (Index = 0; Index < DriverImageHandleCount; Index++) {\r
     //\r
@@ -718,16 +737,16 @@ UpdateBindingDriverSelectPage (
                     EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                     );\r
     if (EFI_ERROR (Status)) {\r
-      FakeNvData->DriSelection[Index] = 0x00;\r
+      mDriSelection[Index] = FALSE;\r
       continue;\r
     }\r
-    mDriverImageProtocol[Index] = LoadedImage;\r
+    DriverImageProtocol[Index] = LoadedImage;\r
     //\r
     // Find its related driver binding protocol\r
     //\r
     DriverBindingHandle = GetDriverBindingHandleFromImageHandle (mDriverImageHandleBuffer[Index]);\r
     if (DriverBindingHandle == NULL) {\r
-      FakeNvData->DriSelection[Index] = 0x00;\r
+      mDriSelection[Index] = FALSE;\r
       continue;\r
     }\r
 \r
@@ -741,7 +760,7 @@ UpdateBindingDriverSelectPage (
                         (VOID **) &LoadedImageDevicePath\r
                         );\r
     if (LoadedImageDevicePath == NULL) {\r
-      FakeNvData->DriSelection[Index] = 0x00;\r
+      mDriSelection[Index] = FALSE;\r
       continue;\r
     }\r
 \r
@@ -757,11 +776,11 @@ UpdateBindingDriverSelectPage (
                          (VOID **) &BusSpecificDriverOverride\r
                          );\r
         if (EFI_ERROR (Status) || BusSpecificDriverOverride == NULL) {\r
-          FakeNvData->DriSelection[Index] = 0x00;\r
+          mDriSelection[Index] = FALSE;\r
           continue;\r
         }\r
       } else {\r
-        FakeNvData->DriSelection[Index] = 0x00;\r
+        mDriSelection[Index] = FALSE;\r
         continue;\r
       }\r
     }\r
@@ -798,9 +817,9 @@ UpdateBindingDriverSelectPage (
     NewString = AllocateZeroPool (StrSize (DriverName));\r
     ASSERT (NewString != NULL); \r
     if (EFI_ERROR (CheckMapping (mControllerDevicePathProtocol[mSelectedCtrIndex], LoadedImageDevicePath, &mMappingDataBase, NULL, NULL))) {\r
-      FakeNvData->DriSelection[Index] = 0x00;\r
+      mDriSelection[Index] = FALSE;\r
     } else {\r
-      FakeNvData->DriSelection[Index] = 0x01;\r
+      mDriSelection[Index] = TRUE;\r
       mLastSavedDriverImageNum++;\r
     }\r
     StrCat (NewString, DriverName);\r
@@ -820,21 +839,26 @@ UpdateBindingDriverSelectPage (
     NewString = AllocateZeroPool (StrSize (DriverName));\r
     ASSERT (NewString != NULL); \r
     StrCat (NewString, DriverName);\r
-    NewStringHelpToken = HiiSetString (Private->RegisteredHandle, mDriverImageFilePathToken[Index], NewString, NULL);\r
+    NewStringHelpToken = HiiSetString (Private->RegisteredHandle, DriverImageFilePathToken[Index], NewString, NULL);\r
     ASSERT (NewStringHelpToken != 0);\r
-    mDriverImageFilePathToken[Index] = NewStringHelpToken;\r
+    DriverImageFilePathToken[Index] = NewStringHelpToken;\r
     FreePool (NewString);\r
     FreePool (DriverName);\r
 \r
+    CheckFlags        = 0;\r
+    if (mDriSelection[Index]) {\r
+      CheckFlags |= EFI_IFR_CHECKBOX_DEFAULT;\r
+    }\r
+\r
     HiiCreateCheckBoxOpCode (\r
       StartOpCodeHandle,\r
-      (UINT16) (DRIVER_SELECTION_QUESTION_ID + Index),\r
-      VARSTORE_ID_PLAT_OVER_MNGR,\r
-      (UINT16) (DRIVER_SELECTION_VAR_OFFSET + Index),\r
-      NewStringToken,\r
-      NewStringHelpToken,\r
+      (UINT16) (KEY_VALUE_DRIVER_OFFSET + Index),\r
       0,\r
       0,\r
+      NewStringToken,\r
+      NewStringHelpToken,\r
+      EFI_IFR_FLAG_CALLBACK,\r
+      CheckFlags,\r
       NULL\r
       );\r
   }\r
@@ -852,6 +876,15 @@ UpdateBindingDriverSelectPage (
 \r
   HiiFreeOpCodeHandle (StartOpCodeHandle);\r
   HiiFreeOpCodeHandle (EndOpCodeHandle);\r
+\r
+  if (DriverImageProtocol != NULL) {\r
+    FreePool (DriverImageProtocol);\r
+  }\r
+\r
+  if (DriverImageFilePathToken != NULL) {\r
+    FreePool (DriverImageFilePathToken);\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -932,7 +965,7 @@ UpdatePrioritySelectPage (
   //\r
   SelectedDriverImageNum = 0;\r
   for (Index = 0; Index < mDriverImageHandleCount; Index++) {\r
-    if (FakeNvData->DriSelection[Index] != 0) {\r
+    if (mDriSelection[Index]) {\r
       SelectedDriverImageNum ++;\r
     }\r
   }\r
@@ -950,7 +983,7 @@ UpdatePrioritySelectPage (
   //\r
   SelectedDriverImageNum = 0;\r
   for (Index = 0; Index < mDriverImageHandleCount; Index++) {\r
-    if (FakeNvData->DriSelection[Index] != 0) {\r
+    if (mDriSelection[Index]) {\r
       //\r
       // Use the NO. in driver binding buffer as value, will use it later\r
       //\r
@@ -1068,7 +1101,7 @@ UpdatePrioritySelectPage (
 \r
 **/\r
 EFI_STATUS\r
-CommintChanges (\r
+CommitChanges (\r
   IN EFI_CALLBACK_INFO                *Private,\r
   IN UINT16                           KeyValue,\r
   IN PLAT_OVER_MNGR_DATA              *FakeNvData\r
@@ -1263,21 +1296,10 @@ PlatOverMngrRouteConfig (
   }\r
 \r
   Status = EFI_SUCCESS;\r
-  if (mCurrentPage == FORM_ID_DRIVER) {\r
-    KeyValue = KEY_VALUE_DRIVER_GOTO_ORDER;\r
-    UpdatePrioritySelectPage (Private, KeyValue, FakeNvData);\r
-    KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;\r
-    Status = CommintChanges (Private, KeyValue, FakeNvData);\r
-    //\r
-    // Since UpdatePrioritySelectPage will change mCurrentPage,\r
-    // should ensure the mCurrentPage still indicate the second page here\r
-    //\r
-    mCurrentPage = FORM_ID_DRIVER;\r
-  }\r
 \r
   if (mCurrentPage == FORM_ID_ORDER) {\r
     KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;\r
-    Status = CommintChanges (Private, KeyValue, FakeNvData);\r
+    Status = CommitChanges (Private, KeyValue, FakeNvData);\r
   }\r
 \r
   return Status;\r
@@ -1350,7 +1372,7 @@ PlatOverMngrCallback (
       }\r
     }\r
 \r
-    if (((KeyValue >= KEY_VALUE_DEVICE_OFFSET) && (KeyValue < KEY_VALUE_DEVICE_MAX)) || (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS)) {\r
+    if (((KeyValue >= KEY_VALUE_DEVICE_OFFSET) && (KeyValue < KEY_VALUE_DEVICE_OFFSET + mMaxDeviceCount)) || (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS)) {\r
       if (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS) {\r
         KeyValue = (EFI_QUESTION_ID) (mSelectedCtrIndex + KEY_VALUE_DEVICE_OFFSET);\r
       }\r
@@ -1384,30 +1406,34 @@ PlatOverMngrCallback (
       UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r
     }\r
   } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
-    switch (KeyValue) {\r
-    case KEY_VALUE_DEVICE_REFRESH:\r
-    case KEY_VALUE_DEVICE_FILTER:\r
-      UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r
-      //\r
-      // Update page title string\r
-      //\r
-      NewStringToken = STRING_TOKEN (STR_TITLE);\r
-      if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path", NULL) == 0) {\r
-        ASSERT (FALSE);\r
-      }\r
-    break;\r
-    \r
-    case KEY_VALUE_ORDER_SAVE_AND_EXIT:\r
-      Status = CommintChanges (Private, KeyValue, FakeNvData);\r
-      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
-      if (EFI_ERROR (Status)) {\r
-        CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Single Override Info too large, Saving Error!", NULL);\r
-        return EFI_DEVICE_ERROR;\r
-      }\r
-    break;\r
+    if ((KeyValue >= KEY_VALUE_DRIVER_OFFSET) && (KeyValue < KEY_VALUE_DRIVER_OFFSET + mDriverImageHandleCount)) {\r
+      mDriSelection[KeyValue - KEY_VALUE_DRIVER_OFFSET] = Value->b;\r
+    } else {\r
+      switch (KeyValue) {\r
+      case KEY_VALUE_DEVICE_REFRESH:\r
+      case KEY_VALUE_DEVICE_FILTER:\r
+        UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r
+        //\r
+        // Update page title string\r
+        //\r
+        NewStringToken = STRING_TOKEN (STR_TITLE);\r
+        if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path", NULL) == 0) {\r
+          ASSERT (FALSE);\r
+        }\r
+      break;\r
+      \r
+      case KEY_VALUE_ORDER_SAVE_AND_EXIT:\r
+        Status = CommitChanges (Private, KeyValue, FakeNvData);\r
+        *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
+        if (EFI_ERROR (Status)) {\r
+          CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Single Override Info too large, Saving Error!", NULL);\r
+          return EFI_DEVICE_ERROR;\r
+        }\r
+      break;\r
 \r
-    default:\r
-    break;\r
+      default:\r
+      break;\r
+      }\r
     }\r
   }\r
 \r
@@ -1609,6 +1635,19 @@ PlatDriOverrideDxeInit (
   mCallbackInfo->PlatformDriverOverride.GetDriver      = GetDriver;\r
   mCallbackInfo->PlatformDriverOverride.GetDriverPath  = GetDriverPath;\r
   mCallbackInfo->PlatformDriverOverride.DriverLoaded   = DriverLoaded;\r
+\r
+  //\r
+  // Locate ConfigRouting protocol\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiHiiConfigRoutingProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &mCallbackInfo->HiiConfigRouting\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Finish;\r
+  }\r
+\r
   //\r
   // Install Device Path Protocol and Config Access protocol to driver handle\r
   // Install Platform Driver Override Protocol to driver handle\r
@@ -1642,27 +1681,11 @@ PlatDriOverrideDxeInit (
     goto Finish;\r
   }\r
 \r
-  //\r
-  // Locate ConfigRouting protocol\r
-  //\r
-  Status = gBS->LocateProtocol (\r
-                  &gEfiHiiConfigRoutingProtocolGuid,\r
-                  NULL,\r
-                  (VOID **) &mCallbackInfo->HiiConfigRouting\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    goto Finish;\r
-  }\r
-\r
   //\r
   // Clear all the globle variable\r
   //\r
   mDriverImageHandleCount = 0;\r
   mCurrentPage = 0;\r
-  ZeroMem (mDriverImageToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));\r
-  ZeroMem (mDriverImageFilePathToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));\r
-  ZeroMem (mControllerToken, MAX_CHOICE_NUM * sizeof (EFI_STRING_ID));\r
-  ZeroMem (mDriverImageProtocol, MAX_CHOICE_NUM * sizeof (EFI_LOADED_IMAGE_PROTOCOL *));\r
   \r
   return EFI_SUCCESS;\r
 \r
@@ -1706,5 +1729,17 @@ PlatDriOverrideDxeUnload (
 \r
   FreePool (mCallbackInfo);\r
 \r
+  if (mControllerToken != NULL) {\r
+    FreePool (mControllerToken);\r
+  }\r
+\r
+  if (mControllerDevicePathProtocol != NULL) {\r
+    FreePool (mControllerDevicePathProtocol);\r
+  }\r
+\r
+  if (mDriverImageToken != NULL) {\r
+    FreePool (mDriverImageToken);\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r