]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / PlatformDriOverrideDxe / PlatDriOverrideDxe.c
index ab8a000f1360916ae4a421974b99934f4a3e0cbf..b2ddf1020b3cb8be09cd5ba9412aeac0433b82bf 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
   This file also installs UEFI PLATFORM_DRIVER_OVERRIDE_PROTOCOL.\r
-  \r
+\r
   The main code offers a UI interface in device manager to let user configure\r
   platform override protocol to override the default algorithm for matching\r
   drivers to controllers.\r
@@ -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 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2018, 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
@@ -96,7 +96,7 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath = {
   {\r
     END_DEVICE_PATH_TYPE,\r
     END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-    { \r
+    {\r
       (UINT8) (END_DEVICE_PATH_LENGTH),\r
       (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
     }\r
@@ -104,49 +104,34 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath = {
 };\r
 \r
 /**\r
-  Converting a given device to an unicode string. \r
-  \r
-  This function will dependent on gEfiDevicePathToTextProtocolGuid, if protocol\r
-  does not installed, then return unknown device path L"?" directly.\r
-  \r
+  Converting a given device to an unicode string.\r
+\r
   @param    DevPath     Given device path instance\r
-  \r
+\r
   @return   Converted string from given device path.\r
-  @retval   L"?"  Can not locate gEfiDevicePathToTextProtocolGuid protocol for converting.\r
+  @retval   L"?" Converting failed.\r
 **/\r
 CHAR16 *\r
 DevicePathToStr (\r
   IN EFI_DEVICE_PATH_PROTOCOL     *DevPath\r
   )\r
 {\r
-  EFI_STATUS                       Status;\r
-  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;\r
-  CHAR16                           *ToText;\r
-  \r
-  if (DevPath == NULL) {\r
-    return L"";\r
-  }\r
-    \r
-  Status = gBS->LocateProtocol (\r
-                  &gEfiDevicePathToTextProtocolGuid,\r
-                  NULL,\r
-                  (VOID **) &DevPathToText\r
-                  );\r
-  if (!EFI_ERROR (Status)) {\r
-    ToText = DevPathToText->ConvertDevicePathToText (\r
-                              DevPath,\r
-                              FALSE,\r
-                              TRUE\r
-                              );\r
-    ASSERT (ToText != NULL);\r
-    return ToText;\r
+  CHAR16                          *Text;\r
+  Text = ConvertDevicePathToText (\r
+           DevPath,\r
+           FALSE,\r
+           TRUE\r
+           );\r
+  if (Text == NULL) {\r
+    Text = AllocateCopyPool (sizeof (L"?"), L"?");\r
+    ASSERT (Text != NULL);\r
   }\r
 \r
-  return L"?";\r
+  return Text;\r
 }\r
 \r
 /**\r
-  Worker function to get the driver name by ComponentName or ComponentName2 protocol \r
+  Worker function to get the driver name by ComponentName or ComponentName2 protocol\r
   according to the driver binding handle.\r
 \r
   @param  DriverBindingHandle  The Handle of DriverBinding.\r
@@ -185,7 +170,7 @@ GetComponentNameWorker (
   //\r
   // Find the best matching language.\r
   //\r
-  Language = GetEfiGlobalVariable (VariableName);\r
+  GetEfiGlobalVariable2 (VariableName, (VOID**)&Language, NULL);\r
   BestLanguage = GetBestLanguage (\r
                    ComponentName->SupportedLanguages,\r
                    (BOOLEAN) (ProtocolGuid == &gEfiComponentNameProtocolGuid),\r
@@ -212,7 +197,7 @@ GetComponentNameWorker (
 \r
 \r
 /**\r
-  Get the driver name by ComponentName or ComponentName2 protocol \r
+  Get the driver name by ComponentName or ComponentName2 protocol\r
   according to the driver binding handle\r
 \r
   @param DriverBindingHandle  The Handle of DriverBinding.\r
@@ -234,7 +219,7 @@ GetComponentName (
   DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentName2ProtocolGuid, L"PlatformLang");\r
   if (DriverName == NULL) {\r
     //\r
-    // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol. \r
+    // If we can not get driver name from Component Name 2 protocol, we can try ISO 639-2 Component Name protocol.\r
     //\r
     DriverName = GetComponentNameWorker (DriverBindingHandle, &gEfiComponentNameProtocolGuid, L"Lang");\r
   }\r
@@ -281,7 +266,7 @@ GetImageName (
     // Make sure device path node is aligned when accessing it's FV Name Guid field.\r
     //\r
     AlignedDevPathNode = AllocateCopyPool (DevicePathNodeLength(DevPathNode), DevPathNode);\r
-    \r
+\r
     //\r
     // Find the Fv File path\r
     //\r
@@ -313,9 +298,9 @@ GetImageName (
         Buffer = NULL;\r
       }\r
     }\r
-    \r
+\r
     FreePool (AlignedDevPathNode);\r
-    \r
+\r
     //\r
     // Next device path node\r
     //\r
@@ -348,6 +333,7 @@ UpdateDeviceSelectPage (
   EFI_STATUS                                Status;\r
   UINTN                                     Index;\r
   UINTN                                     DevicePathHandleCount;\r
+  UINTN                                     NewStrSize;\r
   CHAR16                                    *NewString;\r
   EFI_STRING_ID                             NewStringToken;\r
   CHAR16                                    *ControllerName;\r
@@ -358,13 +344,13 @@ UpdateDeviceSelectPage (
   VOID                                      *StartOpCodeHandle;\r
   VOID                                      *EndOpCodeHandle;\r
   EFI_IFR_GUID_LABEL                        *StartLabel;\r
-  EFI_IFR_GUID_LABEL                        *EndLabel;  \r
+  EFI_IFR_GUID_LABEL                        *EndLabel;\r
 \r
   //\r
   // Set current page form ID.\r
   //\r
-  mCurrentPage = FORM_ID_DEVICE;  \r
-  \r
+  mCurrentPage = FORM_ID_DEVICE;\r
+\r
   //\r
   // Initial the mapping database in memory\r
   //\r
@@ -440,6 +426,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
@@ -498,14 +490,15 @@ UpdateDeviceSelectPage (
     // Export the driver name string and create item in set options page\r
     //\r
     Len = StrSize (ControllerName);\r
-    NewString = AllocateZeroPool (Len + StrSize (L"--"));\r
+    NewStrSize = Len + StrSize (L"--");\r
+    NewString = AllocateZeroPool (NewStrSize);\r
     ASSERT (NewString != NULL);\r
     if (EFI_ERROR (CheckMapping (ControllerDevicePath,NULL, &mMappingDataBase, NULL, NULL))) {\r
-      StrCat (NewString, L"--");\r
+      StrCatS (NewString, NewStrSize/sizeof(CHAR16), L"--");\r
     } else {\r
-      StrCat (NewString, L"**");\r
+      StrCatS (NewString, NewStrSize/sizeof(CHAR16), L"**");\r
     }\r
-    StrCat (NewString, ControllerName);\r
+    StrCatS (NewString, NewStrSize/sizeof(CHAR16), ControllerName);\r
 \r
     NewStringToken = HiiSetString (Private->RegisteredHandle, mControllerToken[Index], NewString, NULL);\r
     ASSERT (NewStringToken != 0);\r
@@ -514,7 +507,7 @@ UpdateDeviceSelectPage (
     // Save the device path string toke for next access use\r
     //\r
     mControllerToken[Index] = NewStringToken;\r
-      \r
+\r
     HiiCreateGotoOpCode (\r
       StartOpCodeHandle,\r
       FORM_ID_DRIVER,\r
@@ -548,7 +541,7 @@ UpdateDeviceSelectPage (
   @param  ImageHandle          The Image handle\r
 \r
   @return                      Handle to Driver binding\r
-  @retval NULL                 The paramter is not valid or the driver binding handle is not found.\r
+  @retval NULL                 The parameter is not valid or the driver binding handle is not found.\r
 \r
 **/\r
 EFI_HANDLE\r
@@ -582,7 +575,7 @@ GetDriverBindingHandleFromImageHandle (
   if (EFI_ERROR (Status) || (DriverBindingHandleCount == 0)) {\r
     return NULL;\r
   }\r
-  \r
+\r
   //\r
   // Get the first Driver Binding handle which has the specific image handle.\r
   //\r
@@ -631,6 +624,7 @@ UpdateBindingDriverSelectPage (
 {\r
   EFI_STATUS                                Status;\r
   UINTN                                     Index;\r
+  UINTN                                     NewStrSize;\r
   CHAR16                                    *NewString;\r
   EFI_STRING_ID                             NewStringToken;\r
   EFI_STRING_ID                             NewStringHelpToken;\r
@@ -645,6 +639,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
@@ -713,6 +710,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
@@ -733,16 +740,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
@@ -756,7 +763,7 @@ UpdateBindingDriverSelectPage (
                         (VOID **) &LoadedImageDevicePath\r
                         );\r
     if (LoadedImageDevicePath == NULL) {\r
-      FakeNvData->DriSelection[Index] = 0x00;\r
+      mDriSelection[Index] = FALSE;\r
       continue;\r
     }\r
 \r
@@ -772,11 +779,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
@@ -810,15 +817,16 @@ UpdateBindingDriverSelectPage (
     //\r
     // First create the driver image name\r
     //\r
-    NewString = AllocateZeroPool (StrSize (DriverName));\r
-    ASSERT (NewString != NULL); \r
+    NewStrSize = StrSize (DriverName);\r
+    NewString = AllocateZeroPool (NewStrSize);\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
+    StrCatS (NewString, NewStrSize/sizeof(CHAR16), DriverName);\r
     NewStringToken = HiiSetString (Private->RegisteredHandle, mDriverImageToken[Index], NewString, NULL);\r
     ASSERT (NewStringToken != 0);\r
     mDriverImageToken[Index] = NewStringToken;\r
@@ -832,24 +840,30 @@ UpdateBindingDriverSelectPage (
     //\r
     DriverName = DevicePathToStr (LoadedImageDevicePath);\r
 \r
-    NewString = AllocateZeroPool (StrSize (DriverName));\r
-    ASSERT (NewString != NULL); \r
-    StrCat (NewString, DriverName);\r
-    NewStringHelpToken = HiiSetString (Private->RegisteredHandle, mDriverImageFilePathToken[Index], NewString, NULL);\r
+    NewStrSize = StrSize (DriverName);\r
+    NewString = AllocateZeroPool (NewStrSize);\r
+    ASSERT (NewString != NULL);\r
+    StrCatS (NewString, NewStrSize/sizeof(CHAR16), DriverName);\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
@@ -867,6 +881,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
@@ -947,7 +970,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
@@ -965,7 +988,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
@@ -1035,7 +1058,7 @@ UpdatePrioritySelectPage (
     FakeNvData->DriOrder[Index] = (UINT8) OrderNO[MinNO];\r
     TempNO[MinNO] = MAX_CHOICE_NUM + 1;\r
   }\r
-  \r
+\r
   //\r
   // Create Order List OpCode\r
   //\r
@@ -1083,7 +1106,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
@@ -1256,6 +1279,7 @@ PlatOverMngrRouteConfig (
   EFI_CALLBACK_INFO                         *Private;\r
   UINT16                                    KeyValue;\r
   PLAT_OVER_MNGR_DATA                       *FakeNvData;\r
+  EFI_STATUS                                Status;\r
 \r
   if (Configuration == NULL || Progress == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1265,7 +1289,7 @@ PlatOverMngrRouteConfig (
   if (!HiiIsConfigHdrMatch (Configuration, &gPlatformOverridesManagerGuid, mVariableName)) {\r
     return EFI_NOT_FOUND;\r
   }\r
-  \r
+\r
   *Progress = Configuration + StrLen (Configuration);\r
   Private    = EFI_CALLBACK_INFO_FROM_THIS (This);\r
   FakeNvData = &Private->FakeNvData;\r
@@ -1276,24 +1300,14 @@ PlatOverMngrRouteConfig (
     return EFI_SUCCESS;\r
   }\r
 \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
-    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
+  Status = EFI_SUCCESS;\r
 \r
   if (mCurrentPage == FORM_ID_ORDER) {\r
     KeyValue = KEY_VALUE_ORDER_SAVE_AND_EXIT;\r
-    CommintChanges (Private, KeyValue, FakeNvData);\r
+    Status = CommitChanges (Private, KeyValue, FakeNvData);\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -1351,7 +1365,7 @@ PlatOverMngrCallback (
     if (Value == NULL) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-    \r
+\r
     if (KeyValue == KEY_VALUE_DRIVER_GOTO_PREVIOUS) {\r
       UpdateDeviceSelectPage (Private, KeyValue, FakeNvData);\r
       //\r
@@ -1363,7 +1377,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
@@ -1397,30 +1411,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
@@ -1482,7 +1500,7 @@ GetDriver (
 \r
     Status = InitOverridesMapping (&mMappingDataBase);\r
     if (EFI_ERROR (Status)){\r
-      DEBUG ((DEBUG_ERROR, "The status to Get Platform Driver Override Variable is %r\n", Status));\r
+      DEBUG ((DEBUG_INFO, "The status to Get Platform Driver Override Variable is %r\n", Status));\r
       InitializeListHead (&mMappingDataBase);\r
       return EFI_NOT_FOUND;\r
     }\r
@@ -1508,14 +1526,14 @@ GetDriver (
   This driver doesn't support this API.\r
 \r
   @param  This                  A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r
-                                PROTOCOL instance.                            \r
+                                PROTOCOL instance.\r
   @param  ControllerHandle      The device handle of the controller to check if a driver override\r
-                                exists.                                                          \r
+                                exists.\r
   @param  DriverImagePath       On input, a pointer to the previous driver device path returned by\r
                                 GetDriverPath(). On output, a pointer to the next driver\r
                                 device path. Passing in a pointer to NULL, will return the first\r
                                 driver device path for ControllerHandle.\r
-  \r
+\r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
@@ -1532,18 +1550,18 @@ GetDriverPath (
 \r
 /**\r
   Used to associate a driver image handle with a device path that was returned on a prior call to the\r
-  GetDriverPath() service. This driver image handle will then be available through the               \r
+  GetDriverPath() service. This driver image handle will then be available through the\r
   GetDriver() service. This driver doesn't support this API.\r
 \r
   @param  This                  A pointer to the EFI_PLATFORM_DRIVER_OVERRIDE_\r
-                                PROTOCOL instance.                            \r
-  @param  ControllerHandle      The device handle of the controller.                                                             \r
+                                PROTOCOL instance.\r
+  @param  ControllerHandle      The device handle of the controller.\r
   @param  DriverImagePath       A pointer to the driver device path that was returned in a prior\r
-                                call to GetDriverPath().                                                                        \r
+                                call to GetDriverPath().\r
   @param  DriverImageHandle     The driver image handle that was returned by LoadImage()\r
-                                when the driver specified by DriverImagePath was loaded \r
-                                into memory. \r
-  \r
+                                when the driver specified by DriverImagePath was loaded\r
+                                into memory.\r
+\r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
@@ -1559,7 +1577,7 @@ DriverLoaded (
 }\r
 \r
 /**\r
-  The driver Entry Point. The funciton will export a disk device class formset and\r
+  The driver Entry Point. The function will export a disk device class formset and\r
   its callback function to hii database.\r
 \r
   @param  ImageHandle    The firmware allocated handle for the EFI image.\r
@@ -1579,7 +1597,7 @@ PlatDriOverrideDxeInit (
   EFI_STATUS                  Status;\r
   EFI_FORM_BROWSER2_PROTOCOL  *FormBrowser2;\r
   VOID                        *Instance;\r
-  \r
+\r
   //\r
   // There should only be one Form Configuration protocol\r
   //\r
@@ -1608,7 +1626,7 @@ PlatDriOverrideDxeInit (
   if (!EFI_ERROR (Status)) {\r
     return EFI_ALREADY_STARTED;\r
   }\r
-  \r
+\r
   mCallerImageHandle = ImageHandle;\r
   mCallbackInfo = AllocateZeroPool (sizeof (EFI_CALLBACK_INFO));\r
   if (mCallbackInfo == NULL) {\r
@@ -1622,6 +1640,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
@@ -1655,28 +1686,12 @@ 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
+\r
   return EFI_SUCCESS;\r
 \r
 Finish:\r
@@ -1719,5 +1734,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