]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
Keep StdErr same logic initialization with ConOut, e.g. initialize gST->StandardError...
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConSplitterDxe / ConSplitter.c
index 234f733bd63b00d9e16ef069ee15a19fd743bb28..ab42b924dd55f8a163d9ca0fafe1f9c131a4362b 100644 (file)
   These 3 virtual handles would be installed on gST.\r
 \r
   Each virtual handle, that supports the Console I/O protocol, will be produced\r
-  in the driver entry point. The virtual handle are added on driver entry and \r
-  never removed. Such design ensures sytem function well during none console \r
+  in the driver entry point. The virtual handle are added on driver entry and\r
+  never removed. Such design ensures sytem function well during none console\r
   device situation.\r
 \r
-Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2012, 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
@@ -35,6 +35,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
   (EFI_HANDLE) NULL,\r
+\r
   {\r
     ConSplitterTextInReset,\r
     ConSplitterTextInReadKeyStroke,\r
@@ -43,6 +44,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
   0,\r
   (EFI_SIMPLE_TEXT_INPUT_PROTOCOL **) NULL,\r
   0,\r
+\r
   {\r
     ConSplitterTextInResetEx,\r
     ConSplitterTextInReadKeyStrokeEx,\r
@@ -82,7 +84,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
     (EFI_EVENT) NULL,\r
     (EFI_ABSOLUTE_POINTER_MODE *) NULL\r
   },\r
-\r
   {\r
     0,       // AbsoluteMinX\r
     0,       // AbsoluteMinY\r
@@ -97,22 +98,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
   0,\r
   FALSE,\r
 \r
-  FALSE,\r
-  {\r
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
-  },\r
-  0,\r
-  {\r
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
-  },\r
-  (EFI_EVENT) NULL,\r
-\r
   FALSE,\r
   FALSE\r
 };\r
@@ -122,18 +107,18 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
 // Uga Draw Protocol Private Data template\r
 //\r
 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UGA_DRAW_PROTOCOL mUgaDrawProtocolTemplate = {\r
-  ConSpliterUgaDrawGetMode,\r
-  ConSpliterUgaDrawSetMode,\r
-  ConSpliterUgaDrawBlt\r
+  ConSplitterUgaDrawGetMode,\r
+  ConSplitterUgaDrawSetMode,\r
+  ConSplitterUgaDrawBlt\r
 };\r
 \r
 //\r
 // Graphics Output Protocol Private Data template\r
 //\r
 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_PROTOCOL mGraphicsOutputProtocolTemplate = {\r
-  ConSpliterGraphicsOutputQueryMode,\r
-  ConSpliterGraphicsOutputSetMode,\r
-  ConSpliterGraphicsOutputBlt,\r
+  ConSplitterGraphicsOutputQueryMode,\r
+  ConSplitterGraphicsOutputSetMode,\r
+  ConSplitterGraphicsOutputBlt,\r
   NULL\r
 };\r
 \r
@@ -164,6 +149,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {
     0,\r
     FALSE,\r
   },\r
+\r
   {\r
     NULL,\r
     NULL,\r
@@ -173,35 +159,22 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {
   0,\r
   0,\r
   0,\r
-  (EFI_UGA_PIXEL *) NULL,\r
+\r
   {\r
     NULL,\r
     NULL,\r
     NULL,\r
     NULL\r
   },\r
-  (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,\r
   (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) NULL,\r
   0,\r
   0,\r
-  TRUE,\r
-  {\r
-    ConSpliterConsoleControlGetMode,\r
-    ConSpliterConsoleControlSetMode,\r
-    ConSpliterConsoleControlLockStdIn\r
-  },\r
 \r
   0,\r
   (TEXT_OUT_AND_GOP_DATA *) NULL,\r
   0,\r
   (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,\r
   0,\r
-  (INT32 *) NULL,\r
-\r
-  EfiConsoleControlScreenText,\r
-  0,\r
-  0,\r
-  (CHAR16 *) NULL,\r
   (INT32 *) NULL\r
 };\r
 \r
@@ -231,6 +204,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {
     0,\r
     FALSE,\r
   },\r
+\r
   {\r
     NULL,\r
     NULL,\r
@@ -240,35 +214,22 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {
   0,\r
   0,\r
   0,\r
-  (EFI_UGA_PIXEL *) NULL,\r
+\r
   {\r
     NULL,\r
     NULL,\r
     NULL,\r
     NULL\r
   },\r
-  (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,\r
   (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) NULL,\r
   0,\r
   0,\r
-  TRUE,\r
-  {\r
-    ConSpliterConsoleControlGetMode,\r
-    ConSpliterConsoleControlSetMode,\r
-    ConSpliterConsoleControlLockStdIn\r
-  },\r
 \r
   0,\r
   (TEXT_OUT_AND_GOP_DATA *) NULL,\r
   0,\r
   (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,\r
   0,\r
-  (INT32 *) NULL,\r
-\r
-  EfiConsoleControlScreenText,\r
-  0,\r
-  0,\r
-  (CHAR16 *) NULL,\r
   (INT32 *) NULL\r
 };\r
 \r
@@ -337,7 +298,7 @@ EFI_DRIVER_BINDING_PROTOCOL           gConSplitterAbsolutePointerDriverBinding =
 \r
   Installs driver module protocols and. Creates virtual device handles for ConIn,\r
   ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,\r
-  Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers. \r
+  Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.\r
   Installs Graphics Output protocol and/or UGA Draw protocol if needed.\r
 \r
   @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
@@ -410,31 +371,17 @@ ConSplitterDriverEntry(
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // One of Either Graphics Output protocol and UGA Draw protocol must be supported.\r
+  // Either Graphics Output protocol or UGA Draw protocol must be supported.\r
   //\r
   ASSERT (FeaturePcdGet (PcdConOutGopSupport) ||\r
           FeaturePcdGet (PcdConOutUgaSupport));\r
 \r
   //\r
-  // The driver creates virtual handles for ConIn, ConOut, and StdErr.\r
+  // The driver creates virtual handles for ConIn, ConOut, StdErr.\r
   // The virtual handles will always exist even if no console exist in the\r
   // system. This is need to support hotplug devices like USB.\r
   //\r
   //\r
-  // Create virtual device handle for StdErr Splitter\r
-  //\r
-  Status = ConSplitterTextOutConstructor (&mStdErr);\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                    &mStdErr.VirtualHandle,\r
-                    &gEfiSimpleTextOutProtocolGuid,\r
-                    &mStdErr.TextOut,\r
-                    &gEfiPrimaryStandardErrorDeviceGuid,\r
-                    NULL,\r
-                    NULL\r
-                    );\r
-  }\r
-  //\r
   // Create virtual device handle for ConIn Splitter\r
   //\r
   Status = ConSplitterTextInConstructor (&mConIn);\r
@@ -449,8 +396,6 @@ ConSplitterDriverEntry(
                     &mConIn.SimplePointer,\r
                     &gEfiAbsolutePointerProtocolGuid,\r
                     &mConIn.AbsolutePointer,\r
-                    &gEfiPrimaryConsoleInDeviceGuid,\r
-                    NULL,\r
                     NULL\r
                     );\r
     if (!EFI_ERROR (Status)) {\r
@@ -469,7 +414,7 @@ ConSplitterDriverEntry(
   if (!EFI_ERROR (Status)) {\r
     if (!FeaturePcdGet (PcdConOutGopSupport)) {\r
       //\r
-      // If Graphics Outpurt protocol not supported, UGA Draw protocol is installed \r
+      // If Graphics Outpurt protocol not supported, UGA Draw protocol is installed\r
       // on the virtual handle.\r
       //\r
       Status = gBS->InstallMultipleProtocolInterfaces (\r
@@ -478,10 +423,6 @@ ConSplitterDriverEntry(
                       &mConOut.TextOut,\r
                       &gEfiUgaDrawProtocolGuid,\r
                       &mConOut.UgaDraw,\r
-                      &gEfiConsoleControlProtocolGuid,\r
-                      &mConOut.ConsoleControl,\r
-                      &gEfiPrimaryConsoleOutDeviceGuid,\r
-                      NULL,\r
                       NULL\r
                       );\r
     } else if (!FeaturePcdGet (PcdConOutUgaSupport)) {\r
@@ -495,10 +436,6 @@ ConSplitterDriverEntry(
                       &mConOut.TextOut,\r
                       &gEfiGraphicsOutputProtocolGuid,\r
                       &mConOut.GraphicsOutput,\r
-                      &gEfiConsoleControlProtocolGuid,\r
-                      &mConOut.ConsoleControl,\r
-                      &gEfiPrimaryConsoleOutDeviceGuid,\r
-                      NULL,\r
                       NULL\r
                       );\r
     } else {\r
@@ -514,10 +451,6 @@ ConSplitterDriverEntry(
                       &mConOut.GraphicsOutput,\r
                       &gEfiUgaDrawProtocolGuid,\r
                       &mConOut.UgaDraw,\r
-                      &gEfiConsoleControlProtocolGuid,\r
-                      &mConOut.ConsoleControl,\r
-                      &gEfiPrimaryConsoleOutDeviceGuid,\r
-                      NULL,\r
                       NULL\r
                       );\r
     }\r
@@ -532,6 +465,28 @@ ConSplitterDriverEntry(
     }\r
 \r
   }\r
+\r
+  //\r
+  // Create virtual device handle for StdErr Splitter\r
+  //\r
+  Status = ConSplitterTextOutConstructor (&mStdErr);\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &mStdErr.VirtualHandle,\r
+                    &gEfiSimpleTextOutProtocolGuid,\r
+                    &mStdErr.TextOut,\r
+                    NULL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {  \r
+      //\r
+      // Update the EFI System Table with new virtual console\r
+      // and update the pointer to Text Output protocol.\r
+      //\r
+      gST->StandardErrorHandle  = mStdErr.VirtualHandle;\r
+      gST->StdErr               = &mStdErr.TextOut;\r
+    }\r
+  }\r
+  \r
   //\r
   // Update the CRC32 in the EFI System Table header\r
   //\r
@@ -565,7 +520,7 @@ ConSplitterTextInConstructor (
   EFI_STATUS  Status;\r
 \r
   //\r
-  // Allocate buffer for Simple Text Input device  \r
+  // Allocate buffer for Simple Text Input device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),\r
@@ -575,19 +530,9 @@ ConSplitterTextInConstructor (
   if (EFI_ERROR (Status)) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+\r
   //\r
-  // Create Event to support locking StdIn Device\r
-  //\r
-  Status = gBS->CreateEvent (\r
-                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
-                  TPL_CALLBACK,\r
-                  ConSpliterConsoleControlLockStdInEvent,\r
-                  NULL,\r
-                  &ConInPrivate->LockEvent\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-  //\r
-  // Create Event to wait for a key \r
+  // Create Event to wait for a key\r
   //\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
@@ -599,7 +544,7 @@ ConSplitterTextInConstructor (
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Allocate buffer for Simple Text Input Ex device  \r
+  // Allocate buffer for Simple Text Input Ex device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
              sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),\r
@@ -625,7 +570,7 @@ ConSplitterTextInConstructor (
 \r
   ConInPrivate->AbsolutePointer.Mode = &ConInPrivate->AbsolutePointerMode;\r
   //\r
-  // Allocate buffer for Absolute Pointer device  \r
+  // Allocate buffer for Absolute Pointer device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),\r
@@ -649,7 +594,7 @@ ConSplitterTextInConstructor (
 \r
   ConInPrivate->SimplePointer.Mode = &ConInPrivate->SimplePointerMode;\r
   //\r
-  // Allocate buffer for Simple Pointer device  \r
+  // Allocate buffer for Simple Pointer device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),\r
@@ -712,7 +657,7 @@ ConSplitterTextOutConstructor (
   //\r
   ConOutPrivate->TextOutMode.Mode = 0xFF;\r
   //\r
-  // Allocate buffer for Console Out device  \r
+  // Allocate buffer for Console Out device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (TEXT_OUT_AND_GOP_DATA),\r
@@ -735,17 +680,18 @@ ConSplitterTextOutConstructor (
   }\r
 \r
   //\r
-  // Setup the DevNullTextOut console to 80 x 25\r
+  // Setup the default console to 80 x 25 and mode to 0\r
   //\r
   ConOutPrivate->TextOutQueryData[0].Columns  = 80;\r
   ConOutPrivate->TextOutQueryData[0].Rows     = 25;\r
-  DevNullTextOutSetMode (ConOutPrivate, 0);\r
+  TextOutSetMode (ConOutPrivate, 0);\r
+\r
 \r
   if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
     //\r
-    // Setup the DevNullUgaDraw to 800 x 600 x 32 bits per pixel, 60Hz.\r
+    // Setup the UgaDraw to 800 x 600 x 32 bits per pixel, 60Hz.\r
     //\r
-    ConSpliterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);\r
+    ConSplitterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);\r
   }\r
   if (FeaturePcdGet (PcdConOutGopSupport)) {\r
     //\r
@@ -793,7 +739,7 @@ ConSplitterTextOutConstructor (
 \r
 \r
 /**\r
-  Test to see if the specified protocol could be supported on the specified device. \r
+  Test to see if the specified protocol could be supported on the specified device.\r
 \r
   @param  This                Driver Binding protocol pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -819,7 +765,7 @@ ConSplitterSupported (
   //\r
   if (ControllerHandle == mConIn.VirtualHandle  ||\r
       ControllerHandle == mConOut.VirtualHandle ||\r
-      ControllerHandle == mStdErr.VirtualHandle \r
+      ControllerHandle == mStdErr.VirtualHandle\r
       ) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -851,7 +797,7 @@ ConSplitterSupported (
 }\r
 \r
 /**\r
-  Test to see if Console In Device could be supported on the Controller. \r
+  Test to see if Console In Device could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -878,7 +824,7 @@ ConSplitterConInDriverBindingSupported (
 }\r
 \r
 /**\r
-  Test to see if Simple Pointer protocol could be supported on the Controller. \r
+  Test to see if Simple Pointer protocol could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -905,7 +851,7 @@ ConSplitterSimplePointerDriverBindingSupported (
 }\r
 \r
 /**\r
-  Test to see if Absolute Pointer protocol could be supported on the Controller. \r
+  Test to see if Absolute Pointer protocol could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -933,7 +879,7 @@ ConSplitterAbsolutePointerDriverBindingSupported (
 \r
 \r
 /**\r
-  Test to see if Console Out Device could be supported on the Controller. \r
+  Test to see if Console Out Device could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -960,7 +906,7 @@ ConSplitterConOutDriverBindingSupported (
 }\r
 \r
 /**\r
-  Test to see if Standard Error Device could be supported on the Controller. \r
+  Test to see if Standard Error Device could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -988,9 +934,9 @@ ConSplitterStdErrDriverBindingSupported (
 \r
 \r
 /**\r
-  Start ConSplitter on devcie handle by opening Console Device Guid on device handle \r
+  Start ConSplitter on devcie handle by opening Console Device Guid on device handle\r
   and the console virtual handle. And Get the console interface on controller handle.\r
-  \r
+\r
   @param  This                      Driver Binding protocol instance pointer.\r
   @param  ControllerHandle          Handle of device.\r
   @param  ConSplitterVirtualHandle  Console virtual Handle.\r
@@ -1031,9 +977,9 @@ ConSplitterStart (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
\r
+\r
   //\r
-  // Create virtual handle and open DeviceGuid on the virtul handle.\r
+  // Open the Parent Handle for the child.\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -1089,8 +1035,8 @@ Err:
 \r
 \r
 /**\r
-  Start Console In Consplitter on device handle. \r
-  \r
+  Start Console In Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding 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
@@ -1157,8 +1103,8 @@ ConSplitterConInDriverBindingStart (
 \r
 \r
 /**\r
-  Start Simple Pointer Consplitter on device handle. \r
-  \r
+  Start Simple Pointer Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding 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
@@ -1203,8 +1149,8 @@ ConSplitterSimplePointerDriverBindingStart (
 \r
 \r
 /**\r
-  Start Absolute Pointer Consplitter on device handle. \r
-  \r
+  Start Absolute Pointer Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding 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
@@ -1250,8 +1196,8 @@ ConSplitterAbsolutePointerDriverBindingStart (
 \r
 \r
 /**\r
-  Start Console Out Consplitter on device handle. \r
-  \r
+  Start Console Out Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding 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
@@ -1269,10 +1215,12 @@ ConSplitterConOutDriverBindingStart (
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                       Status;\r
-  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL     *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL            *UgaDraw;\r
+  EFI_STATUS                           Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL      *TextOut;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL         *GraphicsOutput;\r
+  EFI_UGA_DRAW_PROTOCOL                *UgaDraw;\r
+  UINTN                                SizeOfInfo;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
 \r
   //\r
   // Start ConSplitter on ControllerHandle, and create the virtual\r
@@ -1308,14 +1256,14 @@ ConSplitterConOutDriverBindingStart (
     //\r
     // Open UGA DRAW protocol\r
     //\r
-    Status = gBS->OpenProtocol (\r
-                    ControllerHandle,\r
-                    &gEfiUgaDrawProtocolGuid,\r
-                    (VOID **) &UgaDraw,\r
-                    This->DriverBindingHandle,\r
-                    mConOut.VirtualHandle,\r
-                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                    );\r
+    gBS->OpenProtocol (\r
+           ControllerHandle,\r
+           &gEfiUgaDrawProtocolGuid,\r
+           (VOID **) &UgaDraw,\r
+           This->DriverBindingHandle,\r
+           mConOut.VirtualHandle,\r
+           EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+           );\r
   }\r
 \r
   //\r
@@ -1331,12 +1279,26 @@ ConSplitterConOutDriverBindingStart (
   Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput, UgaDraw);\r
   ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
 \r
-  if (FeaturePcdGet (PcdConOutUgaSupport) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+  if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
     //\r
-    // Match the UGA mode data of ConOut with the current mode\r
+    // Get the UGA mode data of ConOut from the current mode\r
     //\r
-    if (UgaDraw != NULL) {\r
-      UgaDraw->GetMode (\r
+    if (GraphicsOutput != NULL) {\r
+      Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+      ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
+\r
+      mConOut.UgaHorizontalResolution = Info->HorizontalResolution;\r
+      mConOut.UgaVerticalResolution   = Info->VerticalResolution;\r
+      mConOut.UgaColorDepth           = 32;\r
+      mConOut.UgaRefreshRate          = 60;\r
+\r
+      FreePool (Info);\r
+\r
+    } else if (UgaDraw != NULL  && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+      Status = UgaDraw->GetMode (\r
                  UgaDraw,\r
                  &mConOut.UgaHorizontalResolution,\r
                  &mConOut.UgaVerticalResolution,\r
@@ -1345,13 +1307,14 @@ ConSplitterConOutDriverBindingStart (
                  );\r
     }\r
   }\r
+\r
   return Status;\r
 }\r
 \r
 \r
 /**\r
-  Start Standard Error Consplitter on device handle. \r
-  \r
+  Start Standard Error Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding 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
@@ -1404,28 +1367,14 @@ ConSplitterStdErrDriverBindingStart (
     return Status;\r
   }\r
 \r
-  if (mStdErr.CurrentNumberOfConsoles == 1) {\r
-    gST->StandardErrorHandle  = mStdErr.VirtualHandle;\r
-    gST->StdErr               = &mStdErr.TextOut;\r
-    //\r
-    // Update the CRC32 in the EFI System Table header\r
-    //\r
-    gST->Hdr.CRC32 = 0;\r
-    gBS->CalculateCrc32 (\r
-          (UINT8 *) &gST->Hdr,\r
-          gST->Hdr.HeaderSize,\r
-          &gST->Hdr.CRC32\r
-          );\r
-  }\r
-\r
   return Status;\r
 }\r
 \r
 \r
 /**\r
-  Stop ConSplitter on device handle by closing Console Device Guid on device handle \r
+  Stop ConSplitter on device handle by closing Console Device Guid on device handle\r
   and the console virtual handle.\r
-  \r
+\r
   @param  This                      Protocol instance pointer.\r
   @param  ControllerHandle          Handle of device.\r
   @param  ConSplitterVirtualHandle  Console virtual Handle.\r
@@ -1524,7 +1473,7 @@ ConSplitterConInDriverBindingStop (
     //\r
     // If Simple Text Input Ex protocol exists,\r
     // remove device from Text Input Ex devices list.\r
-    //  \r
+    //\r
     Status = ConSplitterTextInExDeleteDevice (&mConIn, TextInEx);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
@@ -1548,7 +1497,7 @@ ConSplitterConInDriverBindingStop (
 \r
   //\r
   // Remove device from Text Input devices list.\r
-  // \r
+  //\r
   return ConSplitterTextInDeleteDevice (&mConIn, TextIn);\r
 }\r
 \r
@@ -1754,26 +1703,7 @@ ConSplitterStdErrDriverBindingStop (
   //\r
   // Delete this console error out device's data structures.\r
   //\r
-  Status = ConSplitterTextOutDeleteDevice (&mStdErr, TextOut);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  if (mStdErr.CurrentNumberOfConsoles == 0) {\r
-    gST->StandardErrorHandle  = NULL;\r
-    gST->StdErr               = NULL;\r
-    //\r
-    // Update the CRC32 in the EFI System Table header\r
-    //\r
-    gST->Hdr.CRC32 = 0;\r
-    gBS->CalculateCrc32 (\r
-          (UINT8 *) &gST->Hdr,\r
-          gST->Hdr.HeaderSize,\r
-          &gST->Hdr.CRC32\r
-          );\r
-  }\r
-\r
-  return Status;\r
+  return ConSplitterTextOutDeleteDevice (&mStdErr, TextOut);\r
 }\r
 \r
 \r
@@ -1794,8 +1724,8 @@ ConSplitterStdErrDriverBindingStop (
 **/\r
 EFI_STATUS\r
 ConSplitterGrowBuffer (\r
-  IN  UINTN                           SizeOfCount,\r
-  IN  UINTN                           *Count,\r
+  IN      UINTN                       SizeOfCount,\r
+  IN OUT  UINTN                       *Count,\r
   IN OUT  VOID                        **Buffer\r
   )\r
 {\r
@@ -1808,7 +1738,7 @@ ConSplitterGrowBuffer (
   //\r
   *Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;\r
   Ptr = ReallocatePool (\r
-          SizeOfCount * ((*Count) - CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT), \r
+          SizeOfCount * ((*Count) - CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT),\r
           SizeOfCount * (*Count),\r
           *Buffer\r
           );\r
@@ -1889,7 +1819,7 @@ ConSplitterTextInDeleteDevice (
   //\r
   for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {\r
     if (Private->TextInList[Index] == TextIn) {\r
-      for (Index = Index; Index < Private->CurrentNumberOfConsoles - 1; Index++) {\r
+      for (; Index < Private->CurrentNumberOfConsoles - 1; Index++) {\r
         Private->TextInList[Index] = Private->TextInList[Index + 1];\r
       }\r
 \r
@@ -1969,7 +1899,7 @@ ConSplitterTextInExDeleteDevice (
   //\r
   for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
     if (Private->TextInExList[Index] == TextInEx) {\r
-      for (Index = Index; Index < Private->CurrentNumberOfExConsoles - 1; Index++) {\r
+      for (; Index < Private->CurrentNumberOfExConsoles - 1; Index++) {\r
         Private->TextInExList[Index] = Private->TextInExList[Index + 1];\r
       }\r
 \r
@@ -2046,7 +1976,7 @@ ConSplitterSimplePointerDeleteDevice (
   //\r
   for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {\r
     if (Private->PointerList[Index] == SimplePointer) {\r
-      for (Index = Index; Index < Private->CurrentNumberOfPointers - 1; Index++) {\r
+      for (; Index < Private->CurrentNumberOfPointers - 1; Index++) {\r
         Private->PointerList[Index] = Private->PointerList[Index + 1];\r
       }\r
 \r
@@ -2123,7 +2053,7 @@ ConSplitterAbsolutePointerDeleteDevice (
   //\r
   for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {\r
     if (Private->AbsolutePointerList[Index] == AbsolutePointer) {\r
-      for (Index = Index; Index < Private->CurrentNumberOfAbsolutePointers - 1; Index++) {\r
+      for (; Index < Private->CurrentNumberOfAbsolutePointers - 1; Index++) {\r
         Private->AbsolutePointerList[Index] = Private->AbsolutePointerList[Index + 1];\r
       }\r
 \r
@@ -2220,7 +2150,7 @@ ConSplitterGrowMapTable (
 \r
   @param  Private               Text Out Splitter pointer\r
   @param  TextOut               Simple Text Output protocol pointer.\r
-  \r
+\r
   @retval EFI_SUCCESS           Device added successfully.\r
   @retval EFI_OUT_OF_RESOURCES  Could not grow the buffer size.\r
 \r
@@ -2366,11 +2296,11 @@ ConSplitterGetIntersection (
 }\r
 \r
 /**\r
-  Add the device's output mode to console splitter's mode list.\r
+  Sync the device's output mode to console splitter's mode list.\r
 \r
   @param  Private               Text Out Splitter pointer.\r
   @param  TextOut               Simple Text Output protocol pointer.\r
-  \r
+\r
 **/\r
 VOID\r
 ConSplitterSyncOutputMode (\r
@@ -2614,7 +2544,7 @@ ConSplitterGetIntersectionBetweenConOutAndStrErr (
 \r
 \r
 /**\r
-  Add display (GOP or UGA) output modes into Consplitter Text Out list.\r
+  Add Grahpics Output modes into Consplitter Text Out list.\r
 \r
   @param  Private               Text Out Splitter pointer.\r
   @param  GraphicsOutput        Graphics Output protocol pointer.\r
@@ -2625,7 +2555,7 @@ ConSplitterGetIntersectionBetweenConOutAndStrErr (
 \r
 **/\r
 EFI_STATUS\r
-ConSplitterAddDisplayOutputMode (\r
+ConSplitterAddGraphicsOutputMode (\r
   IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private,\r
   IN  EFI_GRAPHICS_OUTPUT_PROTOCOL    *GraphicsOutput,\r
   IN  EFI_UGA_DRAW_PROTOCOL           *UgaDraw\r
@@ -2648,14 +2578,13 @@ ConSplitterAddDisplayOutputMode (
   UINT32                               UgaColorDepth;\r
   UINT32                               UgaRefreshRate;\r
 \r
-  if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  ASSERT (GraphicsOutput != NULL || UgaDraw != NULL);\r
 \r
   CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;\r
 \r
   Index        = 0;\r
   CurrentIndex = 0;\r
+  Status       = EFI_SUCCESS;\r
 \r
   if (Private->CurrentNumberOfUgaDraw != 0) {\r
     //\r
@@ -2730,7 +2659,7 @@ ConSplitterAddDisplayOutputMode (
           if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&\r
               (Info->VerticalResolution == Mode->VerticalResolution)) {\r
             //\r
-            // If GOP device supports one mode in current mode buffer, \r
+            // If GOP device supports one mode in current mode buffer,\r
             // it will be added into matched mode buffer\r
             //\r
             Match = TRUE;\r
@@ -2742,7 +2671,7 @@ ConSplitterAddDisplayOutputMode (
 \r
         if (Match) {\r
           AlreadyExist = FALSE;\r
-          \r
+\r
           //\r
           // Check if GOP mode has been in the mode buffer, ModeBuffer = MatchedMode at begin.\r
           //\r
@@ -2811,8 +2740,7 @@ ConSplitterAddDisplayOutputMode (
         }\r
       }\r
     }\r
-  }\r
-  if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+  } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // Graphics console driver can ensure the same mode for all GOP devices\r
     // so we can get the current mode from this video device\r
@@ -2828,11 +2756,11 @@ ConSplitterAddDisplayOutputMode (
     CurrentGraphicsOutputMode->MaxMode = 1;\r
     Info = CurrentGraphicsOutputMode->Info;\r
     Info->Version = 0;\r
-    Info->HorizontalResolution = UgaHorizontalResolution;\r
-    Info->VerticalResolution = UgaVerticalResolution;\r
-    Info->PixelFormat = PixelBltOnly;\r
-    Info->PixelsPerScanLine = UgaHorizontalResolution;\r
-    CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+    Info->HorizontalResolution                 = UgaHorizontalResolution;\r
+    Info->VerticalResolution                   = UgaVerticalResolution;\r
+    Info->PixelFormat                          = PixelBltOnly;\r
+    Info->PixelsPerScanLine                    = UgaHorizontalResolution;\r
+    CurrentGraphicsOutputMode->SizeOfInfo      = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
     CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;\r
     CurrentGraphicsOutputMode->FrameBufferSize = 0;\r
 \r
@@ -2858,31 +2786,57 @@ Done:
 \r
   //\r
   // Force GraphicsOutput mode to be set,\r
-  // regardless whether the console is in EfiConsoleControlScreenGraphics or EfiConsoleControlScreenText mode\r
   //\r
-  Private->HardwareNeedsStarting = TRUE;\r
-  //\r
-  // Current mode number may need update now, so set it to an invalid mode number\r
-  //\r
-  CurrentGraphicsOutputMode->Mode = 0xffff;\r
-  //\r
-  // Graphics console can ensure all GOP devices have the same mode which can be taken as current mode.\r
-  //\r
-  Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) CurrentIndex);\r
-  if (EFI_ERROR(Status)) {\r
+  \r
+  Mode = &Private->GraphicsOutputModeBuffer[CurrentIndex];\r
+  if ((GraphicsOutput != NULL) &&\r
+      (Mode->HorizontalResolution == CurrentGraphicsOutputMode->Info->HorizontalResolution) &&\r
+      (Mode->VerticalResolution == CurrentGraphicsOutputMode->Info->VerticalResolution)) {\r
+    CurrentGraphicsOutputMode->Mode = (UINT32) CurrentIndex;\r
+    if ((Mode->HorizontalResolution != GraphicsOutput->Mode->Info->HorizontalResolution) ||\r
+        (Mode->VerticalResolution != GraphicsOutput->Mode->Info->VerticalResolution)) {\r
+      //\r
+      // If all existing video device has been set to common mode, only set new GOP device to\r
+      // the common mode\r
+      //\r
+      for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex ++) {\r
+        Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\r
+        if ((Info->HorizontalResolution == Mode->HorizontalResolution) && (Info->VerticalResolution == Mode->VerticalResolution)) {\r
+          FreePool (Info);\r
+          break;\r
+        }\r
+        FreePool (Info);\r
+      }\r
+      Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32) NumberIndex);\r
+    }\r
+  } else {\r
     //\r
-    // If user defined mode is not valid for display device, set to the default mode 800x600.\r
+    // Current mode number may need update now, so set it to an invalid mode number\r
     //\r
-    (Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;\r
-    (Private->GraphicsOutputModeBuffer[0]).VerticalResolution   = 600;\r
-    Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);\r
+    CurrentGraphicsOutputMode->Mode = 0xffff;\r
+    //\r
+    // Graphics console can ensure all GOP devices have the same mode which can be taken as current mode.\r
+    //\r
+    Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) CurrentIndex);\r
+    if (EFI_ERROR(Status)) {\r
+      //\r
+      // If user defined mode is not valid for display device, set to the default mode 800x600.\r
+      //\r
+      (Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;\r
+      (Private->GraphicsOutputModeBuffer[0]).VerticalResolution   = 600;\r
+      Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);\r
+    }\r
   }\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
+  Set the current console out mode.\r
+\r
   This routine will get the current console mode information (column, row)\r
   from ConsoleOutMode variable and set it; if the variable does not exist,\r
   set to user defined console mode.\r
@@ -2895,55 +2849,50 @@ ConsplitterSetConsoleOutMode (
   IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private\r
   )\r
 {\r
-  UINTN                         Col;\r
-  UINTN                         Row;\r
-  UINTN                         Mode;\r
-  UINTN                         PreferMode;\r
-  UINTN                         BaseMode;\r
-  UINTN                         ModeInfoSize;\r
-  UINTN                         MaxMode;\r
-  EFI_STATUS                    Status;\r
-  CONSOLE_OUT_MODE              *ModeInfo;\r
+  UINTN                            Col;\r
+  UINTN                            Row;\r
+  UINTN                            Mode;\r
+  UINTN                            PreferMode;\r
+  UINTN                            BaseMode;\r
+  UINTN                            MaxMode;\r
+  EFI_STATUS                       Status;\r
+  CONSOLE_OUT_MODE                 ModeInfo;\r
+  CONSOLE_OUT_MODE                 MaxModeInfo;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
 \r
   PreferMode   = 0xFF;\r
   BaseMode     = 0xFF;\r
   TextOut      = &Private->TextOut;\r
   MaxMode      = (UINTN) (TextOut->Mode->MaxMode);\r
-  ModeInfoSize = sizeof (CONSOLE_OUT_MODE);\r
-\r
-  ModeInfo = AllocateZeroPool (sizeof(CONSOLE_OUT_MODE));\r
-  ASSERT(ModeInfo != NULL);\r
 \r
-  Status = gRT->GetVariable (\r
-                   VARCONOUTMODE,\r
-                   &gEfiGenericPlatformVariableGuid,\r
-                   NULL,\r
-                   &ModeInfoSize,\r
-                   ModeInfo\r
-                   );\r
+  MaxModeInfo.Column = 0;\r
+  MaxModeInfo.Row    = 0; \r
+  ModeInfo.Column    = PcdGet32 (PcdConOutColumn);\r
+  ModeInfo.Row       = PcdGet32 (PcdConOutRow);\r
 \r
   //\r
-  // Set to the default mode 80 x 25 required by EFI/UEFI spec;\r
-  // user can also define other valid default console mode here.\r
+  // To find the prefer mode and basic mode from Text Out mode list\r
   //\r
-  if (EFI_ERROR(Status)) {\r
-    ModeInfo->Column = 80;\r
-    ModeInfo->Row    = 25;\r
-    Status = gRT->SetVariable (\r
-                    VARCONOUTMODE,\r
-                    &gEfiGenericPlatformVariableGuid,\r
-                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-                    sizeof (CONSOLE_OUT_MODE),\r
-                    ModeInfo\r
-                    );\r
-  }\r
-\r
   for (Mode = 0; Mode < MaxMode; Mode++) {\r
     Status = TextOut->QueryMode (TextOut, Mode, &Col, &Row);\r
     if (!EFI_ERROR(Status)) {\r
-      if (Col == ModeInfo->Column && Row == ModeInfo->Row) {\r
-        PreferMode = Mode;\r
+      if ((ModeInfo.Column != 0) && (ModeInfo.Row != 0)) {\r
+        //\r
+        // Use user defined column and row\r
+        //\r
+        if (Col == ModeInfo.Column && Row == ModeInfo.Row) {\r
+          PreferMode = Mode;\r
+        }\r
+      } else {\r
+        //\r
+        // If user sets PcdConOutColumn or PcdConOutRow to 0,\r
+        // find and set the highest text mode.\r
+        //\r
+        if ((Col >= MaxModeInfo.Column) && (Row >= MaxModeInfo.Row)) {\r
+          MaxModeInfo.Column  = Col;\r
+          MaxModeInfo.Row     = Row;\r
+          PreferMode          = Mode;\r
+        }\r
       }\r
       if (Col == 80 && Row == 25) {\r
         BaseMode = Mode;\r
@@ -2951,31 +2900,22 @@ ConsplitterSetConsoleOutMode (
     }\r
   }\r
 \r
-  Status = TextOut->SetMode (TextOut, PreferMode);\r
-\r
   //\r
-  // if current mode setting is failed, default 80x25 mode will be set.\r
+  // Set prefer mode to Text Out devices.\r
   //\r
+  Status = TextOut->SetMode (TextOut, PreferMode);\r
   if (EFI_ERROR(Status)) {\r
+    //\r
+    // if current mode setting is failed, default 80x25 mode will be set.\r
+    //\r
     Status = TextOut->SetMode (TextOut, BaseMode);\r
     ASSERT(!EFI_ERROR(Status));\r
 \r
-    ModeInfo->Column = 80;\r
-    ModeInfo->Row    = 25;\r
-\r
-    //\r
-    // Update ConOutMode variable\r
-    //\r
-    Status = gRT->SetVariable (\r
-                    VARCONOUTMODE,\r
-                    &gEfiGenericPlatformVariableGuid,\r
-                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-                    sizeof (CONSOLE_OUT_MODE),\r
-                    ModeInfo\r
-                    );\r
+    PcdSet32 (PcdConOutColumn, 80);\r
+    PcdSet32 (PcdConOutRow, 25);\r
   }\r
 \r
-  gBS->FreePool (ModeInfo);\r
+  return ;\r
 }\r
 \r
 \r
@@ -2999,15 +2939,17 @@ ConSplitterTextOutAddDevice (
   IN  EFI_UGA_DRAW_PROTOCOL              *UgaDraw\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  UINTN                 CurrentNumOfConsoles;\r
-  INT32                 CurrentMode;\r
-  INT32                 MaxMode;\r
-  UINT32                UgaHorizontalResolution;\r
-  UINT32                UgaVerticalResolution;\r
-  UINT32                UgaColorDepth;\r
-  UINT32                UgaRefreshRate;\r
-  TEXT_OUT_AND_GOP_DATA *TextAndGop;\r
+  EFI_STATUS                           Status;\r
+  UINTN                                CurrentNumOfConsoles;\r
+  INT32                                MaxMode;\r
+  UINT32                               UgaHorizontalResolution;\r
+  UINT32                               UgaVerticalResolution;\r
+  UINT32                               UgaColorDepth;\r
+  UINT32                               UgaRefreshRate;\r
+  TEXT_OUT_AND_GOP_DATA                *TextAndGop;\r
+  UINTN                                SizeOfInfo;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
+  EFI_STATUS                           DeviceStatus;\r
 \r
   Status                = EFI_SUCCESS;\r
   CurrentNumOfConsoles  = Private->CurrentNumberOfConsoles;\r
@@ -3035,21 +2977,9 @@ ConSplitterTextOutAddDevice (
 \r
   TextAndGop          = &Private->TextOutList[CurrentNumOfConsoles];\r
 \r
-  TextAndGop->TextOut = TextOut;\r
+  TextAndGop->TextOut        = TextOut;\r
   TextAndGop->GraphicsOutput = GraphicsOutput;\r
-  TextAndGop->UgaDraw = UgaDraw;\r
-\r
-  if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {\r
-    //\r
-    // If No GOP/UGA device then use the ConOut device\r
-    //\r
-    TextAndGop->TextOutEnabled = TRUE;\r
-  } else {\r
-    //\r
-    // If GOP/UGA device use ConOut device only used if screen is in Text mode\r
-    //\r
-    TextAndGop->TextOutEnabled = (BOOLEAN) (Private->ConsoleOutputMode == EfiConsoleControlScreenText);\r
-  }\r
+  TextAndGop->UgaDraw        = UgaDraw;\r
 \r
   if (CurrentNumOfConsoles == 0) {\r
     //\r
@@ -3069,20 +2999,36 @@ ConSplitterTextOutAddDevice (
   //\r
   ConSplitterGetIntersectionBetweenConOutAndStrErr ();\r
 \r
-  CurrentMode = Private->TextOutMode.Mode;\r
   MaxMode     = Private->TextOutMode.MaxMode;\r
   ASSERT (MaxMode >= 1);\r
 \r
-  //\r
-  // Update DevNull mode according to current video device\r
-  //\r
+  DeviceStatus = EFI_DEVICE_ERROR;\r
   if (FeaturePcdGet (PcdConOutGopSupport)) {\r
-    if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {\r
-      ConSplitterAddDisplayOutputMode (Private, GraphicsOutput, UgaDraw);\r
+    //\r
+    // If GOP is produced by Consplitter, this device display mode will be added into Graphics Ouput modes.\r
+    //\r
+    if ((GraphicsOutput != NULL) || (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport))) {\r
+      DeviceStatus = ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);\r
     }\r
   }\r
+\r
   if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
-    if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    //\r
+    // If UGA is produced by Consplitter\r
+    //\r
+    if (GraphicsOutput != NULL) {\r
+      Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+      ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
+\r
+      UgaHorizontalResolution = Info->HorizontalResolution;\r
+      UgaVerticalResolution   = Info->VerticalResolution;\r
+\r
+      FreePool (Info);\r
+\r
+    } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
       Status = UgaDraw->GetMode (\r
                     UgaDraw,\r
                     &UgaHorizontalResolution,\r
@@ -3090,8 +3036,11 @@ ConSplitterTextOutAddDevice (
                     &UgaColorDepth,\r
                     &UgaRefreshRate\r
                     );\r
-      if (!EFI_ERROR (Status)) {\r
-        Status = ConSpliterUgaDrawSetMode (\r
+      if (!EFI_ERROR (Status) && EFI_ERROR (DeviceStatus)) {\r
+        //\r
+        // if GetMode is successfully and UGA device hasn't been set, set it\r
+        //\r
+        Status = ConSplitterUgaDrawSetMode (\r
                     &Private->UgaDraw,\r
                     UgaHorizontalResolution,\r
                     UgaVerticalResolution,\r
@@ -3103,7 +3052,7 @@ ConSplitterTextOutAddDevice (
       // If GetMode/SetMode is failed, set to 800x600 mode\r
       //\r
       if(EFI_ERROR (Status)) {\r
-        Status = ConSpliterUgaDrawSetMode (\r
+        Status = ConSplitterUgaDrawSetMode (\r
                     &Private->UgaDraw,\r
                     800,\r
                     600,\r
@@ -3114,27 +3063,6 @@ ConSplitterTextOutAddDevice (
     }\r
   }\r
 \r
-  if (Private->ConsoleOutputMode == EfiConsoleControlScreenGraphics && GraphicsOutput != NULL) {\r
-    //\r
-    // We just added a new GOP or UGA device in graphics mode\r
-    //\r
-    if (FeaturePcdGet (PcdConOutGopSupport)) {\r
-      DevNullGopSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);\r
-    } else if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
-      DevNullUgaSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);\r
-    }\r
-  } else if ((CurrentMode >= 0) && ((GraphicsOutput != NULL) || (UgaDraw != NULL)) && (CurrentMode < Private->TextOutMode.MaxMode)) {\r
-    //\r
-    // The new console supports the same mode of the current console so sync up\r
-    //\r
-    DevNullSyncStdOut (Private);\r
-  } else {\r
-    //\r
-    // If ConOut, then set the mode to Mode #0 which us 80 x 25\r
-    //\r
-    Private->TextOut.SetMode (&Private->TextOut, 0);\r
-  }\r
-\r
   //\r
   // After adding new console device, all existing console devices should be\r
   // synced to the current shared mode.\r
@@ -3175,14 +3103,14 @@ ConSplitterTextOutDeleteDevice (
   TextOutList           = Private->TextOutList;\r
   while (Index >= 0) {\r
     if (TextOutList->TextOut == TextOut) {\r
-      CopyMem (TextOutList, TextOutList + 1, sizeof (TEXT_OUT_AND_GOP_DATA) * Index);\r
-      CurrentNumOfConsoles--;\r
       if (TextOutList->UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
         Private->CurrentNumberOfUgaDraw--;\r
       }\r
       if (TextOutList->GraphicsOutput != NULL) {\r
         Private->CurrentNumberOfGraphicsOutput--;\r
       }\r
+      CopyMem (TextOutList, TextOutList + 1, sizeof (TEXT_OUT_AND_GOP_DATA) * Index);\r
+      CurrentNumOfConsoles--;\r
       break;\r
     }\r
 \r
@@ -3198,13 +3126,13 @@ ConSplitterTextOutDeleteDevice (
 \r
   if (CurrentNumOfConsoles == 0) {\r
     //\r
-    // If the number of consoles is zero clear the Dev NULL device\r
+    // If the number of consoles is zero, reset all parameters\r
     //\r
     Private->CurrentNumberOfConsoles      = 0;\r
     Private->TextOutMode.MaxMode          = 1;\r
     Private->TextOutQueryData[0].Columns  = 80;\r
     Private->TextOutQueryData[0].Rows     = 25;\r
-    DevNullTextOutSetMode (Private, 0);\r
+    TextOutSetMode (Private, 0);\r
 \r
     return EFI_SUCCESS;\r
   }\r
@@ -3336,149 +3264,10 @@ ConSplitterTextInPrivateReadKeyStroke (
   return EFI_NOT_READY;\r
 }\r
 \r
-/**\r
-  Return TRUE if StdIn is locked. The ConIn device on the virtual handle is\r
-  the only device locked.\r
-\r
-  @retval TRUE                     StdIn locked\r
-  @retval FALSE                    StdIn working normally\r
-\r
-**/\r
-BOOLEAN\r
-ConSpliterConssoleControlStdInLocked (\r
-  VOID\r
-  )\r
-{\r
-  return mConIn.PasswordEnabled;\r
-}\r
-\r
-\r
-/**\r
-  This timer event will fire when StdIn is locked. It will check the key\r
-  sequence on StdIn to see if it matches the password. Any error in the\r
-  password will cause the check to reset. As long a mConIn.PasswordEnabled is\r
-  TRUE the StdIn splitter will not report any input.\r
-\r
-  @param  Event                  The Event this notify function registered to.\r
-  @param  Context                Pointer to the context data registerd to the\r
-                                 Event.\r
-**/\r
-VOID\r
-EFIAPI\r
-ConSpliterConsoleControlLockStdInEvent (\r
-  IN  EFI_EVENT                       Event,\r
-  IN  VOID                            *Context\r
-  )\r
-{\r
-  EFI_STATUS    Status;\r
-  EFI_INPUT_KEY Key;\r
-  CHAR16        BackSpaceString[2];\r
-  CHAR16        SpaceString[2];\r
-\r
-  do {\r
-    Status = ConSplitterTextInPrivateReadKeyStroke (&mConIn, &Key);\r
-    if (!EFI_ERROR (Status)) {\r
-      //\r
-      // if it's an ENTER, match password\r
-      //\r
-      if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN) && (Key.ScanCode == SCAN_NULL)) {\r
-        mConIn.PwdAttempt[mConIn.PwdIndex] = CHAR_NULL;\r
-        if (StrCmp (mConIn.Password, mConIn.PwdAttempt)) {\r
-          //\r
-          // Password not match\r
-          //\r
-          ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\rPassword not correct\n\r");\r
-          mConIn.PwdIndex = 0;\r
-        } else {\r
-          //\r
-          // Key matches password sequence\r
-          //\r
-          gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, 0);\r
-          mConIn.PasswordEnabled  = FALSE;\r
-          Status                  = EFI_NOT_READY;\r
-        }\r
-      } else if ((Key.UnicodeChar == CHAR_BACKSPACE) && (Key.ScanCode == SCAN_NULL)) {\r
-        //\r
-        // BackSpace met\r
-        //\r
-        if (mConIn.PwdIndex > 0) {\r
-          BackSpaceString[0]  = CHAR_BACKSPACE;\r
-          BackSpaceString[1]  = 0;\r
-\r
-          SpaceString[0]      = L' ';\r
-          SpaceString[1]      = 0;\r
-\r
-          ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);\r
-          ConSplitterTextOutOutputString (&mConOut.TextOut, SpaceString);\r
-          ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);\r
-\r
-          mConIn.PwdIndex--;\r
-        }\r
-      } else if ((Key.ScanCode == SCAN_NULL) && (Key.UnicodeChar >= 32)) {\r
-        //\r
-        // If it's not an ENTER, neigher a function key, nor a CTRL-X or ALT-X, record the input\r
-        //\r
-        if (mConIn.PwdIndex < (MAX_STD_IN_PASSWORD - 1)) {\r
-          if (mConIn.PwdIndex == 0) {\r
-            ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\r");\r
-          }\r
-\r
-          ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"*");\r
-          mConIn.PwdAttempt[mConIn.PwdIndex] = Key.UnicodeChar;\r
-          mConIn.PwdIndex++;\r
-        }\r
-      }\r
-    }\r
-  } while (!EFI_ERROR (Status));\r
-}\r
-\r
-\r
-/**\r
-  If Password is NULL unlock the password state variable and set the event\r
-  timer. If the Password is too big return an error. If the Password is valid\r
-  Copy the Password and enable state variable and then arm the periodic timer\r
-\r
-  @param  This                     Console Control protocol pointer.\r
-  @param  Password                 The password input.\r
-\r
-  @retval EFI_SUCCESS              Lock the StdIn device\r
-  @retval EFI_INVALID_PARAMETER    Password is NULL\r
-  @retval EFI_OUT_OF_RESOURCES     Buffer allocation to store the password fails\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ConSpliterConsoleControlLockStdIn (\r
-  IN  EFI_CONSOLE_CONTROL_PROTOCOL    *This,\r
-  IN  CHAR16                          *Password\r
-  )\r
-{\r
-  if (Password == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (StrLen (Password) >= MAX_STD_IN_PASSWORD) {\r
-    //\r
-    // Currently have a max password size\r
-    //\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  //\r
-  // Save the password, initialize state variables and arm event timer\r
-  //\r
-  StrCpy (mConIn.Password, Password);\r
-  mConIn.PasswordEnabled  = TRUE;\r
-  mConIn.PwdIndex         = 0;\r
-  gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, (10000 * 25));\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
 \r
 /**\r
   Reads the next keystroke from the input device. The WaitForKey Event can\r
   be used to test for existance of a keystroke via WaitForEvent () call.\r
-  If the ConIn is password locked make it look like no keystroke is availible\r
 \r
   @param  This                     Protocol instance pointer.\r
   @param  Key                      Driver may perform diagnostics on reset.\r
@@ -3499,12 +3288,6 @@ ConSplitterTextInReadKeyStroke (
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
 \r
   Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
-  if (Private->PasswordEnabled) {\r
-    //\r
-    // If StdIn Locked return not ready\r
-    //\r
-    return EFI_NOT_READY;\r
-  }\r
 \r
   Private->KeyEventSignalState = FALSE;\r
 \r
@@ -3513,8 +3296,8 @@ ConSplitterTextInReadKeyStroke (
 \r
 \r
 /**\r
-  This event agregates all the events of the ConIn devices in the spliter.\r
-  If the ConIn is password locked then return.\r
+  This event aggregates all the events of the ConIn devices in the spliter.\r
+\r
   If any events of physical ConIn devices are signaled, signal the ConIn\r
   spliter event. This will cause the calling code to call\r
   ConSplitterTextInReadKeyStroke ().\r
@@ -3535,22 +3318,17 @@ ConSplitterTextInWaitForKey (
   UINTN                         Index;\r
 \r
   Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;\r
-  if (Private->PasswordEnabled) {\r
-    //\r
-    // If StdIn Locked return not ready\r
-    //\r
-    return ;\r
-  }\r
 \r
-  //\r
-  // if KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()\r
-  //\r
   if (Private->KeyEventSignalState) {\r
+    //\r
+    // If KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()\r
+    //\r
     gBS->SignalEvent (Event);\r
     return ;\r
   }\r
+\r
   //\r
-  // if any physical console input device has key input, signal the event.\r
+  // If any physical console input device has key input, signal the event.\r
   //\r
   for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {\r
     Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);\r
@@ -3686,12 +3464,6 @@ ConSplitterTextInReadKeyStrokeEx (
   }\r
 \r
   Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
-  if (Private->PasswordEnabled) {\r
-    //\r
-    // If StdIn Locked return not ready\r
-    //\r
-    return EFI_NOT_READY;\r
-  }\r
 \r
   Private->KeyEventSignalState = FALSE;\r
 \r
@@ -3785,7 +3557,7 @@ ConSplitterTextInSetState (
                                    successfully.\r
   @retval EFI_OUT_OF_RESOURCES     Unable to allocate resources for necesssary data\r
                                    structures.\r
-  @retval EFI_INVALID_PARAMETER    KeyData or NotifyHandle is NULL.\r
+  @retval EFI_INVALID_PARAMETER    KeyData or KeyNotificationFunction or NotifyHandle is NULL.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3812,7 +3584,7 @@ ConSplitterTextInRegisterKeyNotify (
   Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   //\r
-  // if no physical console input device exists,\r
+  // If no physical console input device exists,\r
   // return EFI_SUCCESS directly.\r
   //\r
   if (Private->CurrentNumberOfExConsoles <= 0) {\r
@@ -3846,7 +3618,8 @@ ConSplitterTextInRegisterKeyNotify (
   }\r
   NewNotify->Signature         = TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE;\r
   NewNotify->KeyNotificationFn = KeyNotificationFunction;\r
-  CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));\r
+  NewNotify->NotifyHandle      = (EFI_HANDLE) NewNotify;\r
+  CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));\r
 \r
   //\r
   // Return the wrong status of registering key notify of\r
@@ -3866,17 +3639,6 @@ ConSplitterTextInRegisterKeyNotify (
     }\r
   }\r
 \r
-  //\r
-  // Use gSimpleTextInExNotifyGuid to get a valid EFI_HANDLE\r
-  //\r
-  Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &NewNotify->NotifyHandle,\r
-                  &gSimpleTextInExNotifyGuid,\r
-                  NULL,\r
-                  NULL\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   InsertTailList (&mConIn.NotifyList, &NewNotify->NotifyEntry);\r
 \r
   *NotifyHandle                = NewNotify->NotifyHandle;\r
@@ -3896,7 +3658,6 @@ ConSplitterTextInRegisterKeyNotify (
   @retval EFI_SUCCESS              The notification function was unregistered\r
                                    successfully.\r
   @retval EFI_INVALID_PARAMETER    The NotificationHandle is invalid.\r
-  @retval EFI_NOT_FOUND            Can not find the matching entry in database.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3916,15 +3677,7 @@ ConSplitterTextInUnregisterKeyNotify (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Status = gBS->OpenProtocol (\r
-                  NotificationHandle,\r
-                  &gSimpleTextInExNotifyGuid,\r
-                  NULL,\r
-                  NULL,\r
-                  NULL,\r
-                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
+  if (((TEXT_IN_EX_SPLITTER_NOTIFY *) NotificationHandle)->Signature != TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -3951,21 +3704,17 @@ ConSplitterTextInUnregisterKeyNotify (
         }\r
       }\r
       RemoveEntryList (&CurrentNotify->NotifyEntry);\r
-      Status = gBS->UninstallMultipleProtocolInterfaces (\r
-                      CurrentNotify->NotifyHandle,\r
-                      &gSimpleTextInExNotifyGuid,\r
-                      NULL,\r
-                      NULL\r
-                      );\r
-      ASSERT_EFI_ERROR (Status);\r
+\r
       gBS->FreePool (CurrentNotify->NotifyHandleList);\r
       gBS->FreePool (CurrentNotify);\r
       return EFI_SUCCESS;\r
     }\r
   }\r
 \r
-  return EFI_NOT_FOUND;\r
-\r
+  //\r
+  // NotificationHandle is not found in database\r
+  //\r
+  return EFI_INVALID_PARAMETER;\r
 }\r
 \r
 \r
@@ -4095,7 +3844,6 @@ ConSplitterSimplePointerPrivateGetState (
 /**\r
   Reads the next keystroke from the input device. The WaitForKey Event can\r
   be used to test for existance of a keystroke via WaitForEvent () call.\r
-  If the ConIn is password locked make it look like no keystroke is availible\r
 \r
   @param  This                     A pointer to protocol instance.\r
   @param  State                    A pointer to state information on the pointer device\r
@@ -4116,12 +3864,6 @@ ConSplitterSimplePointerGetState (
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
 \r
   Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);\r
-  if (Private->PasswordEnabled) {\r
-    //\r
-    // If StdIn Locked return not ready\r
-    //\r
-    return EFI_NOT_READY;\r
-  }\r
 \r
   Private->InputEventSignalState = FALSE;\r
 \r
@@ -4131,7 +3873,6 @@ ConSplitterSimplePointerGetState (
 \r
 /**\r
   This event agregates all the events of the ConIn devices in the spliter.\r
-  If the ConIn is password locked then return.\r
   If any events of physical ConIn devices are signaled, signal the ConIn\r
   spliter event. This will cause the calling code to call\r
   ConSplitterTextInReadKeyStroke ().\r
@@ -4152,12 +3893,6 @@ ConSplitterSimplePointerWaitForInput (
   UINTN                         Index;\r
 \r
   Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;\r
-  if (Private->PasswordEnabled) {\r
-    //\r
-    // If StdIn Locked return not ready\r
-    //\r
-    return ;\r
-  }\r
 \r
   //\r
   // if InputEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()\r
@@ -4255,12 +3990,6 @@ ConSplitterAbsolutePointerGetState (
 \r
 \r
   Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);\r
-  if (Private->PasswordEnabled) {\r
-    //\r
-    // If StdIn Locked return not ready\r
-    //\r
-    return EFI_NOT_READY;\r
-  }\r
 \r
   Private->AbsoluteInputEventSignalState = FALSE;\r
 \r
@@ -4309,7 +4038,6 @@ ConSplitterAbsolutePointerGetState (
 \r
 /**\r
   This event agregates all the events of the pointer devices in the splitter.\r
-  If the ConIn is password locked then return.\r
   If any events of physical pointer devices are signaled, signal the pointer\r
   splitter event. This will cause the calling code to call\r
   ConSplitterAbsolutePointerGetState ().\r
@@ -4330,12 +4058,6 @@ ConSplitterAbsolutePointerWaitForInput (
   UINTN                         Index;\r
 \r
   Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;\r
-  if (Private->PasswordEnabled) {\r
-    //\r
-    // If StdIn Locked return not ready\r
-    //\r
-    return ;\r
-  }\r
 \r
   //\r
   // if AbsoluteInputEventSignalState is flagged before,\r
@@ -4388,25 +4110,21 @@ ConSplitterTextOutReset (
   // return the worst status met\r
   //\r
   for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {\r
-\r
-    if (Private->TextOutList[Index].TextOutEnabled) {\r
-\r
-      Status = Private->TextOutList[Index].TextOut->Reset (\r
-                                                      Private->TextOutList[Index].TextOut,\r
-                                                      ExtendedVerification\r
-                                                      );\r
-      if (EFI_ERROR (Status)) {\r
-        ReturnStatus = Status;\r
-      }\r
+    Status = Private->TextOutList[Index].TextOut->Reset (\r
+                                                    Private->TextOutList[Index].TextOut,\r
+                                                    ExtendedVerification\r
+                                                    );\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
     }\r
   }\r
 \r
   This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BLACK));\r
 \r
-  Status = DevNullTextOutSetMode (Private, 0);\r
-  if (EFI_ERROR (Status)) {\r
-    ReturnStatus = Status;\r
-  }\r
+  //\r
+  // reset all mode parameters\r
+  //\r
+  TextOutSetMode (Private, 0);\r
 \r
   return ReturnStatus;\r
 }\r
@@ -4441,51 +4159,74 @@ ConSplitterTextOutOutputString (
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
   UINTN                           Index;\r
-  UINTN                           BackSpaceCount;\r
   EFI_STATUS                      ReturnStatus;\r
-  CHAR16                          *TargetString;\r
+  UINTN                           MaxColumn;\r
+  UINTN                           MaxRow;\r
 \r
   This->SetAttribute (This, This->Mode->Attribute);\r
 \r
   Private         = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
 \r
-  BackSpaceCount  = 0;\r
-  for (TargetString = WString; *TargetString != L'\0'; TargetString++) {\r
-    if (*TargetString == CHAR_BACKSPACE) {\r
-      BackSpaceCount++;\r
-    }\r
-\r
-  }\r
-\r
-  if (BackSpaceCount == 0) {\r
-    TargetString = WString;\r
-  } else {\r
-    TargetString = AllocatePool (sizeof (CHAR16) * (StrLen (WString) + BackSpaceCount + 1));\r
-    StrCpy (TargetString, WString);\r
-  }\r
   //\r
   // return the worst status met\r
   //\r
-  Status = DevNullTextOutOutputString (Private, TargetString);\r
-  if (EFI_ERROR (Status)) {\r
-    ReturnStatus = Status;\r
-  }\r
-\r
   for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {\r
-\r
-    if (Private->TextOutList[Index].TextOutEnabled) {\r
-      Status = Private->TextOutList[Index].TextOut->OutputString (\r
-                                                      Private->TextOutList[Index].TextOut,\r
-                                                      TargetString\r
-                                                      );\r
-      if (EFI_ERROR (Status)) {\r
-        ReturnStatus = Status;\r
-      }\r
+    Status = Private->TextOutList[Index].TextOut->OutputString (\r
+                                                    Private->TextOutList[Index].TextOut,\r
+                                                    WString\r
+                                                    );\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
     }\r
   }\r
 \r
-  if (BackSpaceCount > 0) {\r
-    FreePool (TargetString);\r
+  if (Private->CurrentNumberOfConsoles > 0) {\r
+    Private->TextOutMode.CursorColumn = Private->TextOutList[0].TextOut->Mode->CursorColumn;\r
+    Private->TextOutMode.CursorRow    = Private->TextOutList[0].TextOut->Mode->CursorRow;\r
+  } else {\r
+    //\r
+    // When there is no real console devices in system, \r
+    // update cursor position for the virtual device in consplitter.\r
+    //\r
+    Private->TextOut.QueryMode (\r
+                       &Private->TextOut,\r
+                       Private->TextOutMode.Mode,\r
+                       &MaxColumn,\r
+                       &MaxRow\r
+                       );    \r
+    for (; *WString != CHAR_NULL; WString++) {\r
+      switch (*WString) {\r
+      case CHAR_BACKSPACE:\r
+        if (Private->TextOutMode.CursorColumn == 0 && Private->TextOutMode.CursorRow > 0) {\r
+          Private->TextOutMode.CursorRow--;\r
+          Private->TextOutMode.CursorColumn = (INT32) (MaxColumn - 1);          \r
+        } else if (Private->TextOutMode.CursorColumn > 0) {\r
+          Private->TextOutMode.CursorColumn--;\r
+        }\r
+        break;\r
+      \r
+      case CHAR_LINEFEED:\r
+        if (Private->TextOutMode.CursorRow < (INT32) (MaxRow - 1)) {\r
+          Private->TextOutMode.CursorRow++;\r
+        }\r
+        break;\r
+      \r
+      case CHAR_CARRIAGE_RETURN:\r
+        Private->TextOutMode.CursorColumn = 0;\r
+        break;\r
+      \r
+      default:\r
+        if (Private->TextOutMode.CursorColumn < (INT32) (MaxColumn - 1)) {\r
+          Private->TextOutMode.CursorColumn++;\r
+        } else {\r
+          Private->TextOutMode.CursorColumn = 0;\r
+          if (Private->TextOutMode.CursorRow < (INT32) (MaxRow - 1)) {\r
+            Private->TextOutMode.CursorRow++;\r
+          }\r
+        }\r
+        break;\r
+      }\r
+    }\r
   }\r
 \r
   return ReturnStatus;\r
@@ -4525,14 +4266,12 @@ ConSplitterTextOutTestString (
   // return the worst status met\r
   //\r
   for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {\r
-    if (Private->TextOutList[Index].TextOutEnabled) {\r
-      Status = Private->TextOutList[Index].TextOut->TestString (\r
-                                                      Private->TextOutList[Index].TextOut,\r
-                                                      WString\r
-                                                      );\r
-      if (EFI_ERROR (Status)) {\r
-        ReturnStatus = Status;\r
-      }\r
+    Status = Private->TextOutList[Index].TextOut->TestString (\r
+                                                    Private->TextOutList[Index].TextOut,\r
+                                                    WString\r
+                                                    );\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
     }\r
   }\r
   //\r
@@ -4659,32 +4398,19 @@ ConSplitterTextOutSetMode (
   //\r
   TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;\r
   for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {\r
-\r
-    if (Private->TextOutList[Index].TextOutEnabled) {\r
-      Status = Private->TextOutList[Index].TextOut->SetMode (\r
-                                                      Private->TextOutList[Index].TextOut,\r
-                                                      TextOutModeMap[Index]\r
-                                                      );\r
-      //\r
-      // If this console device is based on a GOP or UGA device, then sync up the bitmap from\r
-      // the GOP/UGA splitter and reclear the text portion of the display in the new mode.\r
-      //\r
-      if ((Private->TextOutList[Index].GraphicsOutput != NULL) || (Private->TextOutList[Index].UgaDraw != NULL)) {\r
-        Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);\r
-      }\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        ReturnStatus = Status;\r
-      }\r
+    Status = Private->TextOutList[Index].TextOut->SetMode (\r
+                                                    Private->TextOutList[Index].TextOut,\r
+                                                    TextOutModeMap[Index]\r
+                                                    );\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
     }\r
   }\r
+\r
   //\r
-  // The DevNull Console will support any possible mode as it allocates memory\r
+  // Set mode parameter to specified mode number\r
   //\r
-  Status = DevNullTextOutSetMode (Private, ModeNumber);\r
-  if (EFI_ERROR (Status)) {\r
-    ReturnStatus = Status;\r
-  }\r
+  TextOutSetMode (Private, ModeNumber);\r
 \r
   return ReturnStatus;\r
 }\r
@@ -4732,15 +4458,12 @@ ConSplitterTextOutSetAttribute (
   // return the worst status met\r
   //\r
   for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {\r
-\r
-    if (Private->TextOutList[Index].TextOutEnabled) {\r
-      Status = Private->TextOutList[Index].TextOut->SetAttribute (\r
-                                                      Private->TextOutList[Index].TextOut,\r
-                                                      Attribute\r
-                                                      );\r
-      if (EFI_ERROR (Status)) {\r
-        ReturnStatus = Status;\r
-      }\r
+    Status = Private->TextOutList[Index].TextOut->SetAttribute (\r
+                                                    Private->TextOutList[Index].TextOut,\r
+                                                    Attribute\r
+                                                    );\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
     }\r
   }\r
 \r
@@ -4779,19 +4502,20 @@ ConSplitterTextOutClearScreen (
   // return the worst status met\r
   //\r
   for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {\r
-\r
-    if (Private->TextOutList[Index].TextOutEnabled) {\r
-      Status = Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);\r
-      if (EFI_ERROR (Status)) {\r
-        ReturnStatus = Status;\r
-      }\r
+    Status = Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
     }\r
   }\r
 \r
-  Status = DevNullTextOutClearScreen (Private);\r
-  if (EFI_ERROR (Status)) {\r
-    ReturnStatus = Status;\r
-  }\r
+  //\r
+  // No need to do extra check here as whether (Column, Row) is valid has\r
+  // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should\r
+  // always be supported.\r
+  //\r
+  Private->TextOutMode.CursorColumn = 0;\r
+  Private->TextOutMode.CursorRow    = 0;\r
+  Private->TextOutMode.CursorVisible = TRUE;\r
 \r
   return ReturnStatus;\r
 }\r
@@ -4858,20 +4582,23 @@ ConSplitterTextOutSetCursorPosition (
   // return the worst status met\r
   //\r
   for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {\r
-\r
-    if (Private->TextOutList[Index].TextOutEnabled) {\r
-      Status = Private->TextOutList[Index].TextOut->SetCursorPosition (\r
-                                                      Private->TextOutList[Index].TextOut,\r
-                                                      Column,\r
-                                                      Row\r
-                                                      );\r
-      if (EFI_ERROR (Status)) {\r
-        ReturnStatus = Status;\r
-      }\r
+    Status = Private->TextOutList[Index].TextOut->SetCursorPosition (\r
+                                                    Private->TextOutList[Index].TextOut,\r
+                                                    Column,\r
+                                                    Row\r
+                                                    );\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
     }\r
   }\r
 \r
-  DevNullTextOutSetCursorPosition (Private, Column, Row);\r
+  //\r
+  // No need to do extra check here as whether (Column, Row) is valid has\r
+  // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should\r
+  // always be supported.\r
+  //\r
+  Private->TextOutMode.CursorColumn = (INT32) Column;\r
+  Private->TextOutMode.CursorRow    = (INT32) Row;\r
 \r
   return ReturnStatus;\r
 }\r
@@ -4909,19 +4636,16 @@ ConSplitterTextOutEnableCursor (
   // return the worst status met\r
   //\r
   for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {\r
-\r
-    if (Private->TextOutList[Index].TextOutEnabled) {\r
-      Status = Private->TextOutList[Index].TextOut->EnableCursor (\r
-                                                      Private->TextOutList[Index].TextOut,\r
-                                                      Visible\r
-                                                      );\r
-      if (EFI_ERROR (Status)) {\r
-        ReturnStatus = Status;\r
-      }\r
+    Status = Private->TextOutList[Index].TextOut->EnableCursor (\r
+                                                    Private->TextOutList[Index].TextOut,\r
+                                                    Visible\r
+                                                    );\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
     }\r
   }\r
 \r
-  DevNullTextOutEnableCursor (Private, Visible);\r
+  Private->TextOutMode.CursorVisible = Visible;\r
 \r
   return ReturnStatus;\r
 }\r