]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c
MdeModulePkg/ConPlatform: Support short-form USB device path
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConPlatformDxe / ConPlatform.c
index bfa25f7be4fdee5924c216afa0c4815118db4057..27df8a4b56b6afa0b7f2b9c6b24d078e47f5ce75 100644 (file)
@@ -1,9 +1,9 @@
 /** @file\r
-  Console Platfrom DXE Driver, install Console Device Guids and update Console\r
+  Console Platform DXE Driver, install Console Device Guids and update Console\r
   Environment Variables.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <ConPlatform.h>\r
+#include "ConPlatform.h"\r
 \r
 \r
 EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextInDriverBinding = {\r
@@ -35,13 +35,15 @@ EFI_DRIVER_BINDING_PROTOCOL gConPlatformTextOutDriverBinding = {
 };\r
 \r
 /**\r
-  The user Entry Point for module ConPlatform. The user code starts with this function.\r
+  Entrypoint of this module.\r
 \r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
-  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  This function is the entrypoint of this module. It installs Driver Binding\r
+  Protocols together with Component Name Protocols.\r
+\r
+  @param  ImageHandle       The firmware allocated handle for the EFI image.\r
+  @param  SystemTable       A pointer to the EFI System Table.\r
 \r
   @retval EFI_SUCCESS       The entry point is executed successfully.\r
-  @retval other             Some error occurs when executing this entry point.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -53,9 +55,6 @@ InitializeConPlatform(
 {\r
   EFI_STATUS              Status;\r
 \r
-  //\r
-  // Install driver model protocol(s).\r
-  //\r
   Status = EfiLibInstallDriverBindingComponentName2 (\r
              ImageHandle,\r
              SystemTable,\r
@@ -76,21 +75,20 @@ InitializeConPlatform(
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-\r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 \r
 /**\r
-  Test to see if EFI Text In Protocol could be supported on the ControllerHandle. \r
+  Test to see if EFI_SIMPLE_TEXT_INPUT_PROTOCOL is supported on ControllerHandle.\r
 \r
   @param  This                Protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
   @param  RemainingDevicePath Optional parameter use to pick a specific child\r
                               device to start.\r
 \r
-  @retval EFI_SUCCESS         This driver supports this device\r
-  @retval other               This driver does not support this device\r
+  @retval EFI_SUCCESS         This driver supports this device.\r
+  @retval other               This driver does not support this device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -98,28 +96,27 @@ EFIAPI
 ConPlatformTextInDriverBindingSupported (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   ControllerHandle,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath  OPTIONAL\r
   )\r
 {\r
   return ConPlatformDriverBindingSupported (\r
-          This,\r
-          ControllerHandle,\r
-          RemainingDevicePath,\r
-          &gEfiSimpleTextInProtocolGuid\r
-          );\r
+           This,\r
+           ControllerHandle,\r
+           &gEfiSimpleTextInProtocolGuid\r
+           );\r
 }\r
 \r
 \r
 /**\r
-  Test to see if EFI Text Out Protocol could be supported on the ControllerHandle. \r
+  Test to see if EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL is supported on ControllerHandle.\r
 \r
   @param  This                Protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
   @param  RemainingDevicePath Optional parameter use to pick a specific child\r
                               device to start.\r
 \r
-  @retval EFI_SUCCESS         This driver supports this device\r
-  @retval other               This driver does not support this device\r
+  @retval EFI_SUCCESS         This driver supports this device.\r
+  @retval other               This driver does not support this device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -127,36 +124,32 @@ EFIAPI
 ConPlatformTextOutDriverBindingSupported (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   ControllerHandle,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath  OPTIONAL\r
   )\r
 {\r
   return ConPlatformDriverBindingSupported (\r
-          This,\r
-          ControllerHandle,\r
-          RemainingDevicePath,\r
-          &gEfiSimpleTextOutProtocolGuid\r
-          );\r
+           This,\r
+           ControllerHandle,\r
+           &gEfiSimpleTextOutProtocolGuid\r
+           );\r
 }\r
 \r
 \r
 /**\r
-  Test to see if specific Protocol could be supported on the ControllerHandle. \r
+  Test to see if the specified protocol is supported on ControllerHandle.\r
 \r
   @param  This                Protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
-  @param  RemainingDevicePath Optional parameter use to pick a specific child\r
-                              device to start.\r
   @param  ProtocolGuid        The specfic protocol.\r
 \r
-  @retval EFI_SUCCESS         This driver supports this device\r
-  @retval other               This driver does not support this device\r
+  @retval EFI_SUCCESS         This driver supports this device.\r
+  @retval other               This driver does not support this device.\r
 \r
 **/\r
 EFI_STATUS\r
 ConPlatformDriverBindingSupported (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   ControllerHandle,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath,\r
   IN  EFI_GUID                     *ProtocolGuid\r
   )\r
 {\r
@@ -164,8 +157,8 @@ ConPlatformDriverBindingSupported (
   VOID        *Interface;\r
 \r
   //\r
-  // Test to see if this is a physical device by checking to see if\r
-  // it has a Device Path Protocol\r
+  // Test to see if this is a physical device by checking if\r
+  // it has a Device Path Protocol.\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -179,7 +172,7 @@ ConPlatformDriverBindingSupported (
     return Status;\r
   }\r
   //\r
-  // Test to see if this device supports the specific Protocol\r
+  // Test to see if this device supports the specified Protocol.\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -194,22 +187,23 @@ ConPlatformDriverBindingSupported (
   }\r
 \r
   gBS->CloseProtocol (\r
-        ControllerHandle,\r
-        ProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        ControllerHandle\r
-        );\r
+         ControllerHandle,\r
+         ProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         ControllerHandle\r
+         );\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Start this driver on ControllerHandle by opening Simple Text In protocol,\r
+  Start this driver on the device for console input.\r
+\r
+  Start this driver on ControllerHandle by opening Simple Text Input Protocol,\r
   reading Device Path, and installing Console In Devcice GUID on ControllerHandle.\r
 \r
-  If this devcie is not one hot-plug devce, append its device path into the \r
-  console environment variables ConInDev.\r
-  \r
+  Append its device path into the console environment variables ConInDev.\r
+\r
   @param  This                 Protocol instance pointer.\r
   @param  ControllerHandle     Handle of device to bind driver to\r
   @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
@@ -217,7 +211,7 @@ ConPlatformDriverBindingSupported (
 \r
   @retval EFI_SUCCESS          This driver is added to ControllerHandle\r
   @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
-  @retval other                This driver does not support this device\r
+  @retval other                This driver does not support this device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -228,9 +222,10 @@ ConPlatformTextInDriverBindingStart (
   IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                  Status;\r
-  EFI_DEVICE_PATH_PROTOCOL    *DevicePath;\r
+  EFI_STATUS                     Status;\r
+  EFI_DEVICE_PATH_PROTOCOL       *DevicePath;\r
   EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;\r
+  BOOLEAN                        IsInConInVariable;\r
 \r
   //\r
   // Get the Device Path Protocol so the environment variables can be updated\r
@@ -247,7 +242,7 @@ ConPlatformTextInDriverBindingStart (
     return Status;\r
   }\r
   //\r
-  // Open the Simple Input Protocol BY_DRIVER\r
+  // Open the Simple Text Input Protocol BY_DRIVER\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -261,66 +256,59 @@ ConPlatformTextInDriverBindingStart (
     return Status;\r
   }\r
   //\r
-  // Check the device handle, if it is a hot plug device,\r
-  // do not put the device path into ConInDev, and install\r
-  // gEfiConsoleInDeviceGuid to the device handle directly.\r
-  // The policy is, make hot plug device plug in and play immediately.\r
+  // Check if the device path is in ConIn Variable\r
+  //\r
+  IsInConInVariable = FALSE;\r
+  Status = ConPlatformUpdateDeviceVariable (\r
+             L"ConIn",\r
+             DevicePath,\r
+             Check\r
+             );\r
+  if (!EFI_ERROR (Status)) {\r
+    IsInConInVariable = TRUE;\r
+  }\r
+\r
+  //\r
+  // Append the device path to the ConInDev environment variable\r
+  //\r
+  ConPlatformUpdateDeviceVariable (\r
+    L"ConInDev",\r
+    DevicePath,\r
+    Append\r
+    );\r
+\r
+  //\r
+  // If the device path is an instance in the ConIn environment variable,\r
+  // then install EfiConsoleInDeviceGuid onto ControllerHandle\r
   //\r
-  if (IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
+  if (IsInConInVariable) {\r
     gBS->InstallMultipleProtocolInterfaces (\r
-          &ControllerHandle,\r
-          &gEfiConsoleInDeviceGuid,\r
-          NULL,\r
-          NULL\r
-          );\r
+           &ControllerHandle,\r
+           &gEfiConsoleInDeviceGuid,\r
+           NULL,\r
+           NULL\r
+           );\r
   } else {\r
-    //\r
-    // Append the device path to the ConInDev environment variable\r
-    //\r
-    ConPlatformUpdateDeviceVariable (\r
-      L"ConInDev",\r
-      DevicePath,\r
-      APPEND\r
-      );\r
-\r
-    //\r
-    // If the device path is an instance in the ConIn environment variable,\r
-    // then install EfiConsoleInDeviceGuid onto ControllerHandle\r
-    //\r
-    Status = ConPlatformUpdateDeviceVariable (\r
-              L"ConIn",\r
-              DevicePath,\r
-              CHECK\r
-              );\r
-\r
-    if (!EFI_ERROR (Status)) {\r
-      gBS->InstallMultipleProtocolInterfaces (\r
-            &ControllerHandle,\r
-            &gEfiConsoleInDeviceGuid,\r
-            NULL,\r
-            NULL\r
-            );\r
-    } else {\r
-      gBS->CloseProtocol (\r
-            ControllerHandle,\r
-            &gEfiSimpleTextInProtocolGuid,\r
-            This->DriverBindingHandle,\r
-            ControllerHandle\r
-            );\r
-    }\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           &gEfiSimpleTextInProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Start this driver on ControllerHandle by opening Simple Text Out protocol,\r
+  Start this driver on the device for console output and standard error output.\r
+\r
+  Start this driver on ControllerHandle by opening Simple Text Output Protocol,\r
   reading Device Path, and installing Console Out Devcic GUID, Standard Error\r
   Device GUID on ControllerHandle.\r
 \r
-  If this devcie is not one hot-plug devce, append its device path into the \r
-  console environment variables ConOutDev, StdErrDev.\r
-  \r
+  Append its device path into the console environment variables ConOutDev, ErrOutDev.\r
+\r
   @param  This                 Protocol instance pointer.\r
   @param  ControllerHandle     Handle of device to bind driver to\r
   @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
@@ -339,10 +327,12 @@ ConPlatformTextOutDriverBindingStart (
   IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
+  EFI_STATUS                       Status;\r
+  EFI_DEVICE_PATH_PROTOCOL         *DevicePath;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
-  BOOLEAN                       NeedClose;\r
+  BOOLEAN                          NeedClose;\r
+  BOOLEAN                          IsInConOutVariable;\r
+  BOOLEAN                          IsInErrOutVariable;\r
 \r
   NeedClose = TRUE;\r
 \r
@@ -375,90 +365,90 @@ ConPlatformTextOutDriverBindingStart (
     return Status;\r
   }\r
   //\r
-  // Check the device handle, if it is a hot plug device,\r
-  // do not put the device path into ConOutDev and StdErrDev,\r
-  // and install gEfiConsoleOutDeviceGuid to the device handle directly.\r
-  // The policy is, make hot plug device plug in and play immediately.\r
+  // Check if the device path is in ConOut & ErrOut Variable\r
   //\r
-  if (IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
-    gBS->InstallMultipleProtocolInterfaces (\r
-          &ControllerHandle,\r
-          &gEfiConsoleOutDeviceGuid,\r
-          NULL,\r
-          NULL\r
-          );\r
-  } else {\r
-    //\r
-    // Append the device path to the ConOutDev environment variable\r
-    //\r
+  IsInConOutVariable = FALSE;\r
+  Status = ConPlatformUpdateDeviceVariable (\r
+             L"ConOut",\r
+             DevicePath,\r
+             Check\r
+             );\r
+  if (!EFI_ERROR (Status)) {\r
+    IsInConOutVariable = TRUE;\r
+  }\r
+\r
+  IsInErrOutVariable = FALSE;\r
+  Status = ConPlatformUpdateDeviceVariable (\r
+             L"ErrOut",\r
+             DevicePath,\r
+             Check\r
+             );\r
+  if (!EFI_ERROR (Status)) {\r
+    IsInErrOutVariable = TRUE;\r
+  }\r
+\r
+  //\r
+  // Append the device path to the ConOutDev and ErrOutDev environment variable.\r
+  // For GOP device path, append the sibling device path as well.\r
+  //\r
+  if (!ConPlatformUpdateGopCandidate (DevicePath)) {\r
     ConPlatformUpdateDeviceVariable (\r
       L"ConOutDev",\r
       DevicePath,\r
-      APPEND\r
+      Append\r
       );\r
     //\r
-    // Append the device path to the StdErrDev environment variable\r
+    // Then append the device path to the ErrOutDev environment variable\r
     //\r
     ConPlatformUpdateDeviceVariable (\r
       L"ErrOutDev",\r
       DevicePath,\r
-      APPEND\r
+      Append\r
       );\r
+  }\r
 \r
-    //\r
-    // If the device path is an instance in the ConOut environment variable,\r
-    // then install EfiConsoleOutDeviceGuid onto ControllerHandle\r
-    //\r
-    Status = ConPlatformUpdateDeviceVariable (\r
-              L"ConOut",\r
-              DevicePath,\r
-              CHECK\r
-              );\r
-\r
-    if (!EFI_ERROR (Status)) {\r
-      NeedClose = FALSE;\r
-      Status = gBS->InstallMultipleProtocolInterfaces (\r
-                      &ControllerHandle,\r
-                      &gEfiConsoleOutDeviceGuid,\r
-                      NULL,\r
-                      NULL\r
-                      );\r
-    }\r
-    //\r
-    // If the device path is an instance in the StdErr environment variable,\r
-    // then install EfiStandardErrorDeviceGuid onto ControllerHandle\r
-    //\r
-    Status = ConPlatformUpdateDeviceVariable (\r
-              L"ErrOut",\r
-              DevicePath,\r
-              CHECK\r
-              );\r
-    if (!EFI_ERROR (Status)) {\r
-      NeedClose = FALSE;\r
-      gBS->InstallMultipleProtocolInterfaces (\r
-            &ControllerHandle,\r
-            &gEfiStandardErrorDeviceGuid,\r
-            NULL,\r
-            NULL\r
-            );\r
-    }\r
+  //\r
+  // If the device path is an instance in the ConOut environment variable,\r
+  // then install EfiConsoleOutDeviceGuid onto ControllerHandle\r
+  //\r
+  if (IsInConOutVariable) {\r
+    NeedClose = FALSE;\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &ControllerHandle,\r
+                    &gEfiConsoleOutDeviceGuid,\r
+                    NULL,\r
+                    NULL\r
+                    );\r
+  }\r
+  //\r
+  // If the device path is an instance in the ErrOut environment variable,\r
+  // then install EfiStandardErrorDeviceGuid onto ControllerHandle\r
+  //\r
+  if (IsInErrOutVariable) {\r
+    NeedClose = FALSE;\r
+    gBS->InstallMultipleProtocolInterfaces (\r
+           &ControllerHandle,\r
+           &gEfiStandardErrorDeviceGuid,\r
+           NULL,\r
+           NULL\r
+           );\r
+  }\r
 \r
-    if (NeedClose) {\r
-      gBS->CloseProtocol (\r
-            ControllerHandle,\r
-            &gEfiSimpleTextOutProtocolGuid,\r
-            This->DriverBindingHandle,\r
-            ControllerHandle\r
-            );\r
-    }\r
+  if (NeedClose) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           &gEfiSimpleTextOutProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Stop this driver on ControllerHandle by removing Console In Devcice GUID \r
-  and closing the Simple Text In protocol on ControllerHandle.\r
+  Stop this driver on ControllerHandle by removing Console In Devcice GUID\r
+  and closing the Simple Text Input protocol on ControllerHandle.\r
 \r
   @param  This              Protocol instance pointer.\r
   @param  ControllerHandle  Handle of device to stop driver on\r
@@ -483,32 +473,30 @@ ConPlatformTextInDriverBindingStop (
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
 \r
   //\r
-  // hot plug device is not included into the console associated variables,\r
-  // so no need to check variable for those hot plug devices.\r
+  // Get the Device Path Protocol firstly\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &DevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  //\r
+  // If there is device path on ControllerHandle\r
   //\r
-  if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
+  if (!EFI_ERROR (Status)) {\r
     //\r
-    // Get the Device Path Protocol so the environment variables can be updated\r
+    // Remove DevicePath from ConInDev if exists.\r
     //\r
-    Status = gBS->OpenProtocol (\r
-                    ControllerHandle,\r
-                    &gEfiDevicePathProtocolGuid,\r
-                    (VOID **) &DevicePath,\r
-                    This->DriverBindingHandle,\r
-                    ControllerHandle,\r
-                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                    );\r
-    if (!EFI_ERROR (Status)) {\r
-      //\r
-      // Remove DevicePath from ConInDev\r
-      //\r
-      ConPlatformUpdateDeviceVariable (\r
-        L"ConInDev",\r
-        DevicePath,\r
-        DELETE\r
-        );\r
-    }\r
+    ConPlatformUpdateDeviceVariable (\r
+      L"ConInDev",\r
+      DevicePath,\r
+      Delete\r
+      );\r
   }\r
+\r
   //\r
   // Uninstall the Console Device GUIDs from Controller Handle\r
   //\r
@@ -519,22 +507,22 @@ ConPlatformTextInDriverBindingStop (
     );\r
 \r
   //\r
-  // Close the Simple Input Protocol\r
+  // Close the Simple Text Input Protocol\r
   //\r
   gBS->CloseProtocol (\r
-        ControllerHandle,\r
-        &gEfiSimpleTextInProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        ControllerHandle\r
-        );\r
+         ControllerHandle,\r
+         &gEfiSimpleTextInProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         ControllerHandle\r
+         );\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 \r
 /**\r
-  Stop this driver on ControllerHandle by removing Console Out Devcice GUID \r
-  and closing the Simple Text Out protocol on ControllerHandle.\r
+  Stop this driver on ControllerHandle by removing Console Out Devcice GUID\r
+  and closing the Simple Text Output protocol on ControllerHandle.\r
 \r
   @param  This              Protocol instance pointer.\r
   @param  ControllerHandle  Handle of device to stop driver on\r
@@ -559,37 +547,32 @@ ConPlatformTextOutDriverBindingStop (
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
 \r
   //\r
-  // hot plug device is not included into the console associated variables,\r
-  // so no need to check variable for those hot plug devices.\r
+  // Get the Device Path Protocol firstly\r
   //\r
-  if (!IsHotPlugDevice (This->DriverBindingHandle, ControllerHandle)) {\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &DevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
     //\r
-    // Get the Device Path Protocol so the environment variables can be updated\r
+    // Remove DevicePath from ConOutDev and ErrOutDev if exists.\r
     //\r
-    Status = gBS->OpenProtocol (\r
-                    ControllerHandle,\r
-                    &gEfiDevicePathProtocolGuid,\r
-                    (VOID **) &DevicePath,\r
-                    This->DriverBindingHandle,\r
-                    ControllerHandle,\r
-                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                    );\r
-    if (!EFI_ERROR (Status)) {\r
-      //\r
-      // Remove DevicePath from ConOutDev, and StdErrDev\r
-      //\r
-      ConPlatformUpdateDeviceVariable (\r
-        L"ConOutDev",\r
-        DevicePath,\r
-        DELETE\r
-        );\r
-      ConPlatformUpdateDeviceVariable (\r
-        L"ErrOutDev",\r
-        DevicePath,\r
-        DELETE\r
-        );\r
-    }\r
+    ConPlatformUpdateDeviceVariable (\r
+      L"ConOutDev",\r
+      DevicePath,\r
+      Delete\r
+      );\r
+    ConPlatformUpdateDeviceVariable (\r
+      L"ErrOutDev",\r
+      DevicePath,\r
+      Delete\r
+      );\r
   }\r
+\r
   //\r
   // Uninstall the Console Device GUIDs from Controller Handle\r
   //\r
@@ -620,13 +603,11 @@ ConPlatformTextOutDriverBindingStop (
 \r
 \r
 /**\r
-  Unstall the specific protocol.\r
+  Uninstall the specified protocol.\r
 \r
   @param This            Protocol instance pointer.\r
-  @param Handle          Handle of device to unstall protocol on.\r
-  @param ProtocolGuid    The specific protocol need to be uninstalled.\r
-\r
-  @return None.\r
+  @param Handle          Handle of device to uninstall protocol on.\r
+  @param ProtocolGuid    The specified protocol need to be uninstalled.\r
 \r
 **/\r
 VOID\r
@@ -649,26 +630,28 @@ ConPlatformUnInstallProtocol (
 \r
   if (!EFI_ERROR (Status)) {\r
     gBS->UninstallMultipleProtocolInterfaces (\r
-          Handle,\r
-          ProtocolGuid,\r
-          NULL,\r
-          NULL\r
-          );\r
+           Handle,\r
+           ProtocolGuid,\r
+           NULL,\r
+           NULL\r
+           );\r
   }\r
 \r
   return ;\r
 }\r
 \r
 /**\r
-  Read the EFI variable (Name) and return a dynamically allocated\r
-  buffer, and the size of the buffer. On failure return NULL.\r
+  Get the necessary size of buffer and read the variable.\r
 \r
+  First get the necessary size of buffer. Then read the\r
+  EFI variable (Name) and return a dynamically allocated\r
+  buffer. On failure return NULL.\r
 \r
   @param  Name             String part of EFI variable name\r
 \r
   @return Dynamically allocated memory that contains a copy of the EFI variable.\r
-          Caller is repsoncible freeing the buffer.\r
-          NULL - Variable was not read\r
+          Caller is repsoncible freeing the buffer. Return NULL means Variable\r
+          was not read.\r
 \r
 **/\r
 VOID *\r
@@ -684,7 +667,7 @@ ConPlatformGetVariable (
   Buffer      = NULL;\r
 \r
   //\r
-  // Test to see if the variable exists.  If it doesn't reuturn NULL\r
+  // Test to see if the variable exists.  If it doesn't, return NULL.\r
   //\r
   Status = gRT->GetVariable (\r
                   Name,\r
@@ -714,6 +697,9 @@ ConPlatformGetVariable (
                     );\r
     if (EFI_ERROR (Status)) {\r
       FreePool (Buffer);\r
+      //\r
+      // To make sure Buffer is NULL if any error occurs.\r
+      //\r
       Buffer = NULL;\r
     }\r
   }\r
@@ -721,11 +707,328 @@ ConPlatformGetVariable (
   return Buffer;\r
 }\r
 \r
+/**\r
+  Function returns TRUE when the two input device paths point to the two\r
+  GOP child handles that have the same parent.\r
+\r
+  @param Left    A pointer to a device path data structure.\r
+  @param Right   A pointer to a device path data structure.\r
+\r
+  @retval TRUE  Left and Right share the same parent.\r
+  @retval FALSE Left and Right don't share the same parent or either of them is not\r
+                a GOP device path.\r
+**/\r
+BOOLEAN\r
+IsGopSibling (\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *Left,\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *Right\r
+  )\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL  *NodeLeft;\r
+  EFI_DEVICE_PATH_PROTOCOL  *NodeRight;\r
+\r
+  for (NodeLeft = Left; !IsDevicePathEndType (NodeLeft); NodeLeft = NextDevicePathNode (NodeLeft)) {\r
+    if ((DevicePathType (NodeLeft) == ACPI_DEVICE_PATH && DevicePathSubType (NodeLeft) == ACPI_ADR_DP) ||\r
+        (DevicePathType (NodeLeft) == HARDWARE_DEVICE_PATH && DevicePathSubType (NodeLeft) == HW_CONTROLLER_DP &&\r
+         DevicePathType (NextDevicePathNode (NodeLeft)) == ACPI_DEVICE_PATH && DevicePathSubType (NextDevicePathNode (NodeLeft)) == ACPI_ADR_DP)) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (IsDevicePathEndType (NodeLeft)) {\r
+    return FALSE;\r
+  }\r
+\r
+  for (NodeRight = Right; !IsDevicePathEndType (NodeRight); NodeRight = NextDevicePathNode (NodeRight)) {\r
+    if ((DevicePathType (NodeRight) == ACPI_DEVICE_PATH && DevicePathSubType (NodeRight) == ACPI_ADR_DP) ||\r
+        (DevicePathType (NodeRight) == HARDWARE_DEVICE_PATH && DevicePathSubType (NodeRight) == HW_CONTROLLER_DP &&\r
+         DevicePathType (NextDevicePathNode (NodeRight)) == ACPI_DEVICE_PATH && DevicePathSubType (NextDevicePathNode (NodeRight)) == ACPI_ADR_DP)) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (IsDevicePathEndType (NodeRight)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (((UINTN) NodeLeft - (UINTN) Left) != ((UINTN) NodeRight - (UINTN) Right)) {\r
+    return FALSE;\r
+  }\r
+\r
+  return (BOOLEAN) (CompareMem (Left, Right, (UINTN) NodeLeft - (UINTN) Left) == 0);\r
+}\r
+\r
+/**\r
+  Check whether a USB device match the specified USB Class device path. This\r
+  function follows "Load Option Processing" behavior in UEFI specification.\r
+\r
+  @param UsbIo       USB I/O protocol associated with the USB device.\r
+  @param UsbClass    The USB Class device path to match.\r
+\r
+  @retval TRUE       The USB device match the USB Class device path.\r
+  @retval FALSE      The USB device does not match the USB Class device path.\r
+\r
+**/\r
+BOOLEAN\r
+MatchUsbClass (\r
+  IN EFI_USB_IO_PROTOCOL        *UsbIo,\r
+  IN USB_CLASS_DEVICE_PATH      *UsbClass\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_USB_DEVICE_DESCRIPTOR     DevDesc;\r
+  EFI_USB_INTERFACE_DESCRIPTOR  IfDesc;\r
+  UINT8                         DeviceClass;\r
+  UINT8                         DeviceSubClass;\r
+  UINT8                         DeviceProtocol;\r
+\r
+  if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||\r
+      (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP)){\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check Vendor Id and Product Id.\r
+  //\r
+  Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if ((UsbClass->VendorId != 0xffff) &&\r
+      (UsbClass->VendorId != DevDesc.IdVendor)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if ((UsbClass->ProductId != 0xffff) &&\r
+      (UsbClass->ProductId != DevDesc.IdProduct)) {\r
+    return FALSE;\r
+  }\r
+\r
+  DeviceClass    = DevDesc.DeviceClass;\r
+  DeviceSubClass = DevDesc.DeviceSubClass;\r
+  DeviceProtocol = DevDesc.DeviceProtocol;\r
+  if (DeviceClass == 0) {\r
+    //\r
+    // If Class in Device Descriptor is set to 0, use the Class, SubClass and\r
+    // Protocol in Interface Descriptor instead.\r
+    //\r
+    Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);\r
+    if (EFI_ERROR (Status)) {\r
+      return FALSE;\r
+    }\r
+\r
+    DeviceClass    = IfDesc.InterfaceClass;\r
+    DeviceSubClass = IfDesc.InterfaceSubClass;\r
+    DeviceProtocol = IfDesc.InterfaceProtocol;\r
+  }\r
+\r
+  //\r
+  // Check Class, SubClass and Protocol.\r
+  //\r
+  if ((UsbClass->DeviceClass != 0xff) &&\r
+      (UsbClass->DeviceClass != DeviceClass)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if ((UsbClass->DeviceSubClass != 0xff) &&\r
+      (UsbClass->DeviceSubClass != DeviceSubClass)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if ((UsbClass->DeviceProtocol != 0xff) &&\r
+      (UsbClass->DeviceProtocol != DeviceProtocol)) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+/**\r
+  Check whether a USB device match the specified USB WWID device path. This\r
+  function follows "Load Option Processing" behavior in UEFI specification.\r
+\r
+  @param UsbIo       USB I/O protocol associated with the USB device.\r
+  @param UsbWwid     The USB WWID device path to match.\r
+\r
+  @retval TRUE       The USB device match the USB WWID device path.\r
+  @retval FALSE      The USB device does not match the USB WWID device path.\r
+\r
+**/\r
+BOOLEAN\r
+MatchUsbWwid (\r
+  IN EFI_USB_IO_PROTOCOL        *UsbIo,\r
+  IN USB_WWID_DEVICE_PATH       *UsbWwid\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  EFI_USB_DEVICE_DESCRIPTOR    DevDesc;\r
+  EFI_USB_INTERFACE_DESCRIPTOR IfDesc;\r
+  UINT16                       *LangIdTable;\r
+  UINT16                       TableSize;\r
+  UINT16                       Index;\r
+  CHAR16                       *CompareStr;\r
+  UINTN                        CompareLen;\r
+  CHAR16                       *SerialNumberStr;\r
+  UINTN                        Length;\r
+\r
+  if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||\r
+      (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check Vendor Id and Product Id.\r
+  //\r
+  Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+  if ((DevDesc.IdVendor != UsbWwid->VendorId) ||\r
+      (DevDesc.IdProduct != UsbWwid->ProductId)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check Interface Number.\r
+  //\r
+  Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+  if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check Serial Number.\r
+  //\r
+  if (DevDesc.StrSerialNumber == 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Get all supported languages.\r
+  //\r
+  TableSize = 0;\r
+  LangIdTable = NULL;\r
+  Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable, &TableSize);\r
+  if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.\r
+  //\r
+  CompareStr = (CHAR16 *) (UINTN) (UsbWwid + 1);\r
+  CompareLen = (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);\r
+  if (CompareStr[CompareLen - 1] == L'\0') {\r
+    CompareLen--;\r
+  }\r
+\r
+  //\r
+  // Compare serial number in each supported language.\r
+  //\r
+  for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {\r
+    SerialNumberStr = NULL;\r
+    Status = UsbIo->UsbGetStringDescriptor (\r
+                      UsbIo,\r
+                      LangIdTable[Index],\r
+                      DevDesc.StrSerialNumber,\r
+                      &SerialNumberStr\r
+                      );\r
+    if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {\r
+      continue;\r
+    }\r
+\r
+    Length = StrLen (SerialNumberStr);\r
+    if ((Length >= CompareLen) &&\r
+        (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {\r
+      FreePool (SerialNumberStr);\r
+      return TRUE;\r
+    }\r
+\r
+    FreePool (SerialNumberStr);\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Compare whether a full console device path matches a USB shortform device path.\r
+\r
+  @param[in] FullPath      Full console device path.\r
+  @param[in] ShortformPath Short-form device path. Short-form device node may in the beginning or in the middle.\r
+\r
+  @retval TRUE  The full console device path matches the short-form device path.\r
+  @retval FALSE The full console device path doesn't match the short-form device path.\r
+**/\r
+BOOLEAN\r
+MatchUsbShortformDevicePath (\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *FullPath,\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *ShortformPath\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ShortformNode;\r
+  UINTN                     ParentDevicePathSize;\r
+  EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath;\r
+  EFI_USB_IO_PROTOCOL       *UsbIo;\r
+  EFI_HANDLE                Handle;\r
+\r
+  for ( ShortformNode = ShortformPath\r
+      ; !IsDevicePathEnd (ShortformNode)\r
+      ; ShortformNode = NextDevicePathNode (ShortformNode)\r
+      ) {\r
+    if ((DevicePathType (ShortformNode) == MESSAGING_DEVICE_PATH) &&\r
+        ((DevicePathSubType (ShortformNode) == MSG_USB_CLASS_DP) ||\r
+         (DevicePathSubType (ShortformNode) == MSG_USB_WWID_DP))\r
+        ) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Skip further compare when it's not a shortform device path.\r
+  //\r
+  if (IsDevicePathEnd (ShortformNode)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Compare the parent device path when the ShortformPath doesn't start with short-form node.\r
+  //\r
+  ParentDevicePathSize = (UINTN) ShortformNode - (UINTN) ShortformPath;\r
+  RemainingDevicePath  = FullPath;\r
+  Status               = gBS->LocateDevicePath (&gEfiUsbIoProtocolGuid, &RemainingDevicePath, &Handle);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+  if (ParentDevicePathSize != 0) {\r
+    if ((ParentDevicePathSize > (UINTN) RemainingDevicePath - (UINTN) FullPath) ||\r
+        (CompareMem (FullPath, ShortformPath, ParentDevicePathSize) != 0)) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Compar the USB layer.\r
+  //\r
+  Status = gBS->HandleProtocol(\r
+                  Handle,\r
+                  &gEfiUsbIoProtocolGuid,\r
+                  (VOID **) &UsbIo\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return MatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *)ShortformNode) ||\r
+         MatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *)ShortformNode);\r
+}\r
+\r
 /**\r
   Function compares a device path data structure to that of all the nodes of a\r
   second device path instance.\r
 \r
-\r
   @param Multi           A pointer to a multi-instance device path data structure.\r
   @param Single          A pointer to a single-instance device path data structure.\r
   @param NewDevicePath   If Delete is TRUE, this parameter must not be null, and it\r
@@ -735,20 +1038,24 @@ ConPlatformGetVariable (
                          If FALSE, the routine just check whether Single matches\r
                          with any instance in Multi.\r
 \r
-  @return The function returns EFI_SUCCESS if the Single is contained within Multi.\r
-          Otherwise, EFI_NOT_FOUND is returned.\r
+  @retval EFI_SUCCESS           If the Single is contained within Multi.\r
+  @retval EFI_NOT_FOUND         If the Single is not contained within Multi.\r
+  @retval EFI_INVALID_PARAMETER Multi is NULL.\r
+  @retval EFI_INVALID_PARAMETER Single is NULL.\r
+  @retval EFI_INVALID_PARAMETER NewDevicePath is NULL when Delete is TRUE.\r
 \r
 **/\r
 EFI_STATUS\r
 ConPlatformMatchDevicePaths (\r
   IN  EFI_DEVICE_PATH_PROTOCOL  *Multi,\r
   IN  EFI_DEVICE_PATH_PROTOCOL  *Single,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath OPTIONAL,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath OPTIONAL,\r
   IN  BOOLEAN                   Delete\r
   )\r
 {\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath1;\r
+  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath2;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevicePathInst;\r
   UINTN                     Size;\r
 \r
@@ -756,31 +1063,50 @@ ConPlatformMatchDevicePaths (
   // The passed in DevicePath should not be NULL\r
   //\r
   if ((Multi == NULL) || (Single == NULL)) {\r
-    return EFI_NOT_FOUND;\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
+\r
   //\r
-  // if performing Delete operation, the NewDevicePath must not be NULL.\r
+  // If performing Delete operation, the NewDevicePath must not be NULL.\r
   //\r
-  TempDevicePath  = NULL;\r
+  if (Delete) {\r
+    if (NewDevicePath == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+\r
+  TempDevicePath1 = NULL;\r
 \r
   DevicePath      = Multi;\r
   DevicePathInst  = GetNextDevicePathInstance (&DevicePath, &Size);\r
 \r
   //\r
-  // search for the match of 'Single' in 'Multi'\r
+  // Search for the match of 'Single' in 'Multi'\r
   //\r
   while (DevicePathInst != NULL) {\r
-    if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
+    if ((CompareMem (Single, DevicePathInst, Size) == 0) ||\r
+      IsGopSibling (Single, DevicePathInst) || MatchUsbShortformDevicePath (Single, DevicePathInst)) {\r
       if (!Delete) {\r
+        //\r
+        // If Delete is FALSE, return EFI_SUCCESS if Single is found in Multi.\r
+        //\r
         FreePool (DevicePathInst);\r
         return EFI_SUCCESS;\r
       }\r
     } else {\r
       if (Delete) {\r
-        TempDevicePath = AppendDevicePathInstance (\r
-                            NULL,\r
+        //\r
+        // If the node of Multi does not match Single, then added it back to the result.\r
+        // That is, the node matching Single will be dropped and deleted from result.\r
+        //\r
+        TempDevicePath2 = AppendDevicePathInstance (\r
+                            TempDevicePath1,\r
                             DevicePathInst\r
                             );\r
+        if (TempDevicePath1 != NULL) {\r
+          FreePool (TempDevicePath1);\r
+        }\r
+        TempDevicePath1 = TempDevicePath2;\r
       }\r
     }\r
 \r
@@ -789,7 +1115,10 @@ ConPlatformMatchDevicePaths (
   }\r
 \r
   if (Delete) {\r
-    *NewDevicePath = TempDevicePath;\r
+    //\r
+    // Return the new device path data structure with specified node deleted.\r
+    //\r
+    *NewDevicePath = TempDevicePath1;\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -797,12 +1126,12 @@ ConPlatformMatchDevicePaths (
 }\r
 \r
 /**\r
-  Update console devicein console environment variables. \r
+  Update console environment variables.\r
 \r
   @param  VariableName    Console environment variables, ConOutDev, ConInDev\r
-                          StdErrDev, ConIn or ConOut.\r
+                          ErrOutDev, ConIn ,ConOut or ErrOut.\r
   @param  DevicePath      Console devcie's device path.\r
-  @param  Operation       Variable operations, such as APPEND or DELETE.\r
+  @param  Operation       Variable operations, including APPEND, CHECK and DELETE.\r
 \r
   @retval EFI_SUCCESS           Variable operates successfully.\r
   @retval EFI_OUT_OF_RESOURCES  If variable cannot be appended.\r
@@ -830,18 +1159,22 @@ ConPlatformUpdateDeviceVariable (
   //\r
   VariableDevicePath = ConPlatformGetVariable (VariableName);\r
 \r
-  if (Operation != DELETE) {\r
-\r
+  if (Operation != Delete) {\r
+    //\r
+    // Match specified DevicePath in Console Variable.\r
+    //\r
     Status = ConPlatformMatchDevicePaths (\r
-              VariableDevicePath,\r
-              DevicePath,\r
-              NULL,\r
-              FALSE\r
-              );\r
+               VariableDevicePath,\r
+               DevicePath,\r
+               NULL,\r
+               FALSE\r
+               );\r
 \r
-    if ((Operation == CHECK) || (!EFI_ERROR (Status))) {\r
+    if ((Operation == Check) || (!EFI_ERROR (Status))) {\r
       //\r
-      // The device path is already in the variable\r
+      // Branch here includes 2 cases:\r
+      // 1. Operation is CHECK, simply return Status.\r
+      // 2. Operation is APPEND, and device path already exists in variable, also return.\r
       //\r
       if (VariableDevicePath != NULL) {\r
         FreePool (VariableDevicePath);\r
@@ -850,8 +1183,7 @@ ConPlatformUpdateDeviceVariable (
       return Status;\r
     }\r
     //\r
-    // The device path is not in variable. Append DevicePath to the\r
-    // environment variable that is a multi-instance device path.\r
+    // We reach here to append a device path that does not exist in variable.\r
     //\r
     Status = EFI_SUCCESS;\r
     NewVariableDevicePath = AppendDevicePathInstance (\r
@@ -864,15 +1196,15 @@ ConPlatformUpdateDeviceVariable (
 \r
   } else {\r
     //\r
-    // Remove DevicePath from the environment variable that\r
+    // We reach here to remove DevicePath from the environment variable that\r
     // is a multi-instance device path.\r
     //\r
     Status = ConPlatformMatchDevicePaths (\r
-              VariableDevicePath,\r
-              DevicePath,\r
-              &NewVariableDevicePath,\r
-              TRUE\r
-              );\r
+               VariableDevicePath,\r
+               DevicePath,\r
+               &NewVariableDevicePath,\r
+               TRUE\r
+               );\r
   }\r
 \r
   if (VariableDevicePath != NULL) {\r
@@ -884,6 +1216,9 @@ ConPlatformUpdateDeviceVariable (
   }\r
 \r
   if (NewVariableDevicePath != NULL) {\r
+    //\r
+    // Update Console Environment Variable.\r
+    //\r
     Status = gRT->SetVariable (\r
                     VariableName,\r
                     &gEfiGlobalVariableGuid,\r
@@ -899,37 +1234,44 @@ ConPlatformUpdateDeviceVariable (
 }\r
 \r
 /**\r
-  Check if the device is one hot-plug supported.\r
+  Update ConOutDev and ErrOutDev variables to add the device path of\r
+  GOP controller itself and the sibling controllers.\r
 \r
-  @param  DriverBindingHandle   Protocol instance pointer.\r
-  @param  ControllerHandle      Handle of device to check.\r
+  @param  DevicePath            Pointer to device's device path.\r
 \r
-  @retval TRUE                  The devcie is a hot-plug device\r
-  @retval FALSE                 The devcie is not a hot-plug device.\r
+  @retval TRUE                  The devcie is a GOP device.\r
+  @retval FALSE                 The devcie is not a GOP device.\r
 \r
 **/\r
 BOOLEAN\r
-IsHotPlugDevice (\r
-  EFI_HANDLE    DriverBindingHandle,\r
-  EFI_HANDLE    ControllerHandle\r
+ConPlatformUpdateGopCandidate (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL    *DevicePath\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS                           Status;\r
+  EFI_HANDLE                           PciHandle;\r
+  EFI_HANDLE                           GopHandle;\r
+  EFI_DEVICE_PATH_PROTOCOL             *TempDevicePath;\r
 \r
   //\r
-  // HotPlugDeviceGuid indicates ControllerHandle stands for a hot plug device.\r
+  // Check whether it's a GOP device.\r
   //\r
-  Status = gBS->OpenProtocol (\r
-                  ControllerHandle,\r
-                  &gEfiHotPlugDeviceGuid,\r
-                  NULL,\r
-                  DriverBindingHandle,\r
-                  ControllerHandle,\r
-                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
-                  );\r
+  TempDevicePath = DevicePath;\r
+  Status = gBS->LocateDevicePath (&gEfiGraphicsOutputProtocolGuid, &TempDevicePath, &GopHandle);\r
   if (EFI_ERROR (Status)) {\r
     return FALSE;\r
   }\r
-\r
+  //\r
+  // Get the parent PciIo handle in order to find all the children\r
+  //\r
+  Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &DevicePath, &PciHandle);\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+  TempDevicePath = EfiBootManagerGetGopDevicePath (PciHandle);\r
+  if (TempDevicePath != NULL) {\r
+    ConPlatformUpdateDeviceVariable (L"ConOutDev", TempDevicePath, Append);\r
+    ConPlatformUpdateDeviceVariable (L"ErrOutDev", TempDevicePath, Append);\r
+  }\r
   return TRUE;\r
 }\r