]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConSplitterDxe / ConSplitter.c
index bfd50bd59d127d9644f453588e1a60e2df7ac4aa..dacef61d45d59118961e6b160b99150574c15508 100644 (file)
@@ -1,4 +1,4 @@
-/**@file\r
+/** @file\r
   Console Splitter Driver. Any Handle that attatched\r
   EFI_CONSOLE_IDENTIFIER_PROTOCOL can be bound by this driver.\r
 \r
@@ -16,7 +16,7 @@
   The virtual handle are added on driver entry and never removed.\r
   Such design ensures sytem function well during none console device situation.\r
 \r
-Copyright (c) 2006 - 2007 Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
 All rights reserved. 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
@@ -30,9 +30,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "ConSplitter.h"\r
 \r
 //\r
-// Global Variables\r
+// Template for Text In Splitter\r
 //\r
-STATIC TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {\r
+TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
   (EFI_HANDLE) NULL,\r
   {\r
@@ -43,6 +43,21 @@ STATIC TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
   0,\r
   (EFI_SIMPLE_TEXT_INPUT_PROTOCOL **) NULL,\r
   0,\r
+  {\r
+    ConSplitterTextInResetEx,\r
+    ConSplitterTextInReadKeyStrokeEx,\r
+    (EFI_EVENT) NULL,\r
+    ConSplitterTextInSetState,\r
+    ConSplitterTextInRegisterKeyNotify,\r
+    ConSplitterTextInUnregisterKeyNotify\r
+  },\r
+  0,\r
+  (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL **) NULL,\r
+  0,\r
+  {\r
+    (LIST_ENTRY *) NULL,\r
+    (LIST_ENTRY *) NULL\r
+  },\r
 \r
   {\r
     ConSplitterSimplePointerReset,\r
@@ -61,6 +76,27 @@ STATIC TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
   (EFI_SIMPLE_POINTER_PROTOCOL **) NULL,\r
   0,\r
 \r
+  {\r
+    ConSplitterAbsolutePointerReset,\r
+    ConSplitterAbsolutePointerGetState,\r
+    (EFI_EVENT) NULL,\r
+    (EFI_ABSOLUTE_POINTER_MODE *) NULL\r
+  },\r
+\r
+  {\r
+    0,       //AbsoluteMinX\r
+    0,       //AbsoluteMinY\r
+    0,       //AbsoluteMinZ\r
+    0x10000, //AbsoluteMaxX\r
+    0x10000, //AbsoluteMaxY\r
+    0x10000, //AbsoluteMaxZ\r
+    0        //Attributes\r
+  },\r
+  0,\r
+  (EFI_ABSOLUTE_POINTER_PROTOCOL **) NULL,\r
+  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
@@ -81,7 +117,29 @@ STATIC TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
   FALSE\r
 };\r
 \r
-STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {\r
+//\r
+// Template for Uga Draw Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UGA_DRAW_PROTOCOL mUgaDrawProtocolTemplate = {\r
+  ConSpliterUgaDrawGetMode,\r
+  ConSpliterUgaDrawSetMode,\r
+  ConSpliterUgaDrawBlt\r
+};\r
+\r
+//\r
+// Template for Graphics Output Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_PROTOCOL mGraphicsOutputProtocolTemplate = {\r
+  ConSpliterGraphicsOutputQueryMode,\r
+  ConSpliterGraphicsOutputSetMode,\r
+  ConSpliterGraphicsOutputBlt,\r
+  NULL\r
+};\r
+\r
+//\r
+// Template for Text Out Splitter\r
+//\r
+TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
   (EFI_HANDLE) NULL,\r
   {\r
@@ -105,13 +163,24 @@ STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {
     FALSE,\r
   },\r
   {\r
-    ConSpliterGraphicsOutputQueryMode,\r
-    ConSpliterGraphicsOutputSetMode,\r
-    ConSpliterGraphicsOutputBlt,\r
+    NULL,\r
+    NULL,\r
+    NULL\r
+  },\r
+  0,\r
+  0,\r
+  0,\r
+  0,\r
+  (EFI_UGA_PIXEL *) NULL,\r
+  {\r
+    NULL,\r
+    NULL,\r
+    NULL,\r
     NULL\r
   },\r
   (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,\r
-  (TEXT_OUT_GOP_MODE *) NULL,\r
+  (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) NULL,\r
+  0,\r
   0,\r
   TRUE,\r
   {\r
@@ -134,7 +203,10 @@ STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {
   (INT32 *) NULL\r
 };\r
 \r
-STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {\r
+//\r
+// Template for Standard Error Text Out Splitter\r
+//\r
+TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
   (EFI_HANDLE) NULL,\r
   {\r
@@ -158,13 +230,24 @@ STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {
     FALSE,\r
   },\r
   {\r
-    ConSpliterGraphicsOutputQueryMode,\r
-    ConSpliterGraphicsOutputSetMode,\r
-    ConSpliterGraphicsOutputBlt,\r
+    NULL,\r
+    NULL,\r
+    NULL\r
+  },\r
+  0,\r
+  0,\r
+  0,\r
+  0,\r
+  (EFI_UGA_PIXEL *) NULL,\r
+  {\r
+    NULL,\r
+    NULL,\r
+    NULL,\r
     NULL\r
   },\r
   (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,\r
-  (TEXT_OUT_GOP_MODE *) NULL,\r
+  (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) NULL,\r
+  0,\r
   0,\r
   TRUE,\r
   {\r
@@ -187,6 +270,9 @@ STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {
   (INT32 *) NULL\r
 };\r
 \r
+//\r
+// Driver binding instance for Console Input Device\r
+//\r
 EFI_DRIVER_BINDING_PROTOCOL           gConSplitterConInDriverBinding = {\r
   ConSplitterConInDriverBindingSupported,\r
   ConSplitterConInDriverBindingStart,\r
@@ -196,6 +282,9 @@ EFI_DRIVER_BINDING_PROTOCOL           gConSplitterConInDriverBinding = {
   NULL\r
 };\r
 \r
+//\r
+// Driver binding instance for Simple Pointer protocol\r
+//\r
 EFI_DRIVER_BINDING_PROTOCOL           gConSplitterSimplePointerDriverBinding = {\r
   ConSplitterSimplePointerDriverBindingSupported,\r
   ConSplitterSimplePointerDriverBindingStart,\r
@@ -205,6 +294,21 @@ EFI_DRIVER_BINDING_PROTOCOL           gConSplitterSimplePointerDriverBinding = {
   NULL\r
 };\r
 \r
+//\r
+// Driver binding instance for Absolute Pointer protocol\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL           gConSplitterAbsolutePointerDriverBinding = {\r
+  ConSplitterAbsolutePointerDriverBindingSupported,\r
+  ConSplitterAbsolutePointerDriverBindingStart,\r
+  ConSplitterAbsolutePointerDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+//\r
+// Driver binding instance for Console Out device\r
+//\r
 EFI_DRIVER_BINDING_PROTOCOL           gConSplitterConOutDriverBinding = {\r
   ConSplitterConOutDriverBindingSupported,\r
   ConSplitterConOutDriverBindingStart,\r
@@ -214,6 +318,9 @@ EFI_DRIVER_BINDING_PROTOCOL           gConSplitterConOutDriverBinding = {
   NULL\r
 };\r
 \r
+//\r
+// Driver binding instance for Standard Error device\r
+//\r
 EFI_DRIVER_BINDING_PROTOCOL           gConSplitterStdErrDriverBinding = {\r
   ConSplitterStdErrDriverBindingSupported,\r
   ConSplitterStdErrDriverBindingStart,\r
@@ -226,16 +333,21 @@ EFI_DRIVER_BINDING_PROTOCOL           gConSplitterStdErrDriverBinding = {
 /**\r
   The user Entry Point for module ConSplitter. The user code starts with this function.\r
 \r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \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
+  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
   @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \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
 EFIAPI\r
-InitializeConSplitter(\r
+ConSplitterDriverEntry(\r
   IN EFI_HANDLE           ImageHandle,\r
   IN EFI_SYSTEM_TABLE     *SystemTable\r
   )\r
@@ -265,6 +377,16 @@ InitializeConSplitter(
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gConSplitterAbsolutePointerDriverBinding,\r
+             NULL,\r
+             &gConSplitterAbsolutePointerComponentName,\r
+             &gConSplitterAbsolutePointerComponentName2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   Status = EfiLibInstallDriverBindingComponentName2 (\r
              ImageHandle,\r
              SystemTable,\r
@@ -286,37 +408,8 @@ InitializeConSplitter(
   ASSERT_EFI_ERROR (Status);\r
 \r
 \r
-  //\r
-  // Call the original Entry Point\r
-  //\r
-  Status = ConSplitterDriverEntry (ImageHandle, SystemTable);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-ConSplitterDriverEntry (\r
-  IN EFI_HANDLE                       ImageHandle,\r
-  IN EFI_SYSTEM_TABLE                 *SystemTable\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-  Intialize a virtual console device to act as an agrigator of physical console\r
-  devices.\r
-\r
-Arguments:\r
-  ImageHandle - (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
-  SystemTable - (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
-Returns:\r
-  EFI_SUCCESS\r
-\r
---*/\r
-{\r
-  EFI_STATUS  Status;\r
-\r
+  ASSERT (FeaturePcdGet (PcdConOutGopSupport) ||\r
+          FeaturePcdGet (PcdConOutUgaSupport));\r
   //\r
   // The driver creates virtual handles for ConIn, ConOut, and StdErr.\r
   // The virtual handles will always exist even if no console exist in the\r
@@ -345,8 +438,12 @@ Returns:
                     &mConIn.VirtualHandle,\r
                     &gEfiSimpleTextInProtocolGuid,\r
                     &mConIn.TextIn,\r
+                    &gEfiSimpleTextInputExProtocolGuid,\r
+                    &mConIn.TextInEx,\r
                     &gEfiSimplePointerProtocolGuid,\r
                     &mConIn.SimplePointer,\r
+                    &gEfiAbsolutePointerProtocolGuid,\r
+                    &mConIn.AbsolutePointer,\r
                     &gEfiPrimaryConsoleInDeviceGuid,\r
                     NULL,\r
                     NULL\r
@@ -364,21 +461,58 @@ Returns:
   //\r
   Status = ConSplitterTextOutConstructor (&mConOut);\r
   if (!EFI_ERROR (Status)) {\r
-    //\r
-    // In UEFI mode, Graphics Output Protocol is installed on virtual handle.\r
-    //\r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                    &mConOut.VirtualHandle,\r
-                    &gEfiSimpleTextOutProtocolGuid,\r
-                    &mConOut.TextOut,\r
-                    &gEfiGraphicsOutputProtocolGuid,\r
-                    &mConOut.GraphicsOutput,\r
-                    &gEfiConsoleControlProtocolGuid,\r
-                    &mConOut.ConsoleControl,\r
-                    &gEfiPrimaryConsoleOutDeviceGuid,\r
-                    NULL,\r
-                    NULL\r
-                    );\r
+    if (!FeaturePcdGet (PcdConOutGopSupport)) {\r
+      //\r
+      // In EFI mode, UGA Draw protocol is installed\r
+      //\r
+      Status = gBS->InstallMultipleProtocolInterfaces (\r
+                      &mConOut.VirtualHandle,\r
+                      &gEfiSimpleTextOutProtocolGuid,\r
+                      &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
+      //\r
+      // In UEFI mode, Graphics Output Protocol is installed on virtual handle.\r
+      //\r
+      Status = gBS->InstallMultipleProtocolInterfaces (\r
+                      &mConOut.VirtualHandle,\r
+                      &gEfiSimpleTextOutProtocolGuid,\r
+                      &mConOut.TextOut,\r
+                      &gEfiGraphicsOutputProtocolGuid,\r
+                      &mConOut.GraphicsOutput,\r
+                      &gEfiConsoleControlProtocolGuid,\r
+                      &mConOut.ConsoleControl,\r
+                      &gEfiPrimaryConsoleOutDeviceGuid,\r
+                      NULL,\r
+                      NULL\r
+                      );\r
+    } else {\r
+      //\r
+      // In EFI and UEFI comptible mode, Graphics Output Protocol and UGA are\r
+      // installed on virtual handle.\r
+      //\r
+      Status = gBS->InstallMultipleProtocolInterfaces (\r
+                      &mConOut.VirtualHandle,\r
+                      &gEfiSimpleTextOutProtocolGuid,\r
+                      &mConOut.TextOut,\r
+                      &gEfiGraphicsOutputProtocolGuid,\r
+                      &mConOut.GraphicsOutput,\r
+                      &gEfiUgaDrawProtocolGuid,\r
+                      &mConOut.UgaDraw,\r
+                      &gEfiConsoleControlProtocolGuid,\r
+                      &mConOut.ConsoleControl,\r
+                      &gEfiPrimaryConsoleOutDeviceGuid,\r
+                      NULL,\r
+                      NULL\r
+                      );\r
+    }\r
 \r
     if (!EFI_ERROR (Status)) {\r
       //\r
@@ -400,26 +534,25 @@ Returns:
         );\r
 \r
   return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-ConSplitterTextInConstructor (\r
-  TEXT_IN_SPLITTER_PRIVATE_DATA       *ConInPrivate\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
+}\r
 \r
-  Construct the ConSplitter.\r
 \r
-Arguments:\r
+/**\r
+  Construct console input devices' private data.\r
 \r
-  ConInPrivate    - A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA structure.\r
+  @param  ConInPrivate             A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA\r
+                                   structure.\r
 \r
-Returns:\r
-  EFI_OUT_OF_RESOURCES - Out of resources.\r
+  @retval EFI_OUT_OF_RESOURCES     Out of resources.\r
+  @retval EFI_SUCCESS              Text Input Devcie's private data has been constructed.\r
+  @retval other                    Failed to construct private data.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+ConSplitterTextInConstructor (\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA       *ConInPrivate\r
+  )\r
 {\r
   EFI_STATUS  Status;\r
 \r
@@ -455,6 +588,52 @@ Returns:
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Buffer for Simple Text Input Ex Protocol\r
+  //\r
+  Status = ConSplitterGrowBuffer (\r
+             sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),\r
+             &ConInPrivate->TextInExListCount,\r
+             (VOID **) &ConInPrivate->TextInExList\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  ConSplitterTextInWaitForKey,\r
+                  ConInPrivate,\r
+                  &ConInPrivate->TextInEx.WaitForKeyEx\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  InitializeListHead (&ConInPrivate->NotifyList);\r
+\r
+  //\r
+  // Allocate Buffer and Create Event for Absolute Pointer and Simple Pointer Protocols\r
+  //\r
+  ConInPrivate->AbsolutePointer.Mode = &ConInPrivate->AbsolutePointerMode;\r
+\r
+  Status = ConSplitterGrowBuffer (\r
+            sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),\r
+            &ConInPrivate->AbsolutePointerListCount,\r
+            (VOID **) &ConInPrivate->AbsolutePointerList\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = gBS->CreateEvent (\r
+            EVT_NOTIFY_WAIT,\r
+            TPL_NOTIFY,\r
+            ConSplitterAbsolutePointerWaitForInput,\r
+            ConInPrivate,\r
+            &ConInPrivate->AbsolutePointer.WaitForInput\r
+        );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   ConInPrivate->SimplePointer.Mode = &ConInPrivate->SimplePointerMode;\r
 \r
   Status = ConSplitterGrowBuffer (\r
@@ -477,18 +656,46 @@ Returns:
   return Status;\r
 }\r
 \r
+/**\r
+  Construct console output devices' private data.\r
+\r
+  @param  ConOutPrivate            A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA\r
+                                   structure.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES     Out of resources.\r
+  @retval EFI_SUCCESS              Text Input Devcie's private data has been constructed.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterTextOutConstructor (\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA      *ConOutPrivate\r
   )\r
 {\r
   EFI_STATUS  Status;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info;\r
+\r
+  //\r
+  // Copy protocols template\r
+  //\r
+  if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
+    CopyMem (&ConOutPrivate->UgaDraw, &mUgaDrawProtocolTemplate, sizeof (EFI_UGA_DRAW_PROTOCOL));\r
+  }\r
+\r
+  if (FeaturePcdGet (PcdConOutGopSupport)) {\r
+    CopyMem (&ConOutPrivate->GraphicsOutput, &mGraphicsOutputProtocolTemplate, sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL));\r
+  }\r
 \r
   //\r
   // Initilize console output splitter's private data.\r
   //\r
   ConOutPrivate->TextOut.Mode = &ConOutPrivate->TextOutMode;\r
 \r
+  //\r
+  // When new console device is added, the new mode will be set later,\r
+  // so put current mode back to init state.\r
+  //\r
+  ConOutPrivate->TextOutMode.Mode = 0xFF;\r
+\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (TEXT_OUT_AND_GOP_DATA),\r
             &ConOutPrivate->TextOutListCount,\r
@@ -513,68 +720,74 @@ ConSplitterTextOutConstructor (
   ConOutPrivate->TextOutQueryData[0].Rows     = 25;\r
   DevNullTextOutSetMode (ConOutPrivate, 0);\r
 \r
-  //\r
-  // Setup resource for mode information in Graphics Output Protocol interface\r
-  //\r
-  if ((ConOutPrivate->GraphicsOutput.Mode = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE))) == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  if ((ConOutPrivate->GraphicsOutput.Mode->Info = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  //\r
-  // Setup the DevNullGraphicsOutput to 800 x 600 x 32 bits per pixel\r
-  //\r
-  if ((ConOutPrivate->GraphicsOutputModeBuffer = AllocateZeroPool (sizeof (TEXT_OUT_GOP_MODE))) == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+  if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
+    //\r
+    // Setup the DevNullUgaDraw to 800 x 600 x 32 bits per pixel\r
+    //\r
+    ConSpliterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);\r
   }\r
-  ConOutPrivate->GraphicsOutputModeBuffer[0].HorizontalResolution = 800;\r
-  ConOutPrivate->GraphicsOutputModeBuffer[0].VerticalResolution = 600;\r
+  if (FeaturePcdGet (PcdConOutGopSupport)) {\r
+    //\r
+    // Setup resource for mode information in Graphics Output Protocol interface\r
+    //\r
+    if ((ConOutPrivate->GraphicsOutput.Mode = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE))) == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    if ((ConOutPrivate->GraphicsOutput.Mode->Info = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    //\r
+    // Setup the DevNullGraphicsOutput to 800 x 600 x 32 bits per pixel\r
+    // DevNull will be updated to user-defined mode after driver has started.\r
+    //\r
+    if ((ConOutPrivate->GraphicsOutputModeBuffer = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Info = &ConOutPrivate->GraphicsOutputModeBuffer[0];\r
+    Info->Version = 0;\r
+    Info->HorizontalResolution = 800;\r
+    Info->VerticalResolution = 600;\r
+    Info->PixelFormat = PixelBltOnly;\r
+    Info->PixelsPerScanLine = 800;\r
+    CopyMem (ConOutPrivate->GraphicsOutput.Mode->Info, Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
+    ConOutPrivate->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
 \r
-  //\r
-  // Initialize the following items, theset items remain unchanged in GraphicsOutput->SetMode()\r
-  //  GraphicsOutputMode->Info->Version, GraphicsOutputMode->Info->PixelFormat\r
-  //  GraphicsOutputMode->SizeOfInfo, GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize\r
-  //\r
-  ConOutPrivate->GraphicsOutput.Mode->Info->Version = 0;\r
-  ConOutPrivate->GraphicsOutput.Mode->Info->PixelFormat = PixelBltOnly;\r
-  ConOutPrivate->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
-  ConOutPrivate->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;\r
-  ConOutPrivate->GraphicsOutput.Mode->FrameBufferSize = 0;\r
+    //\r
+    // Initialize the following items, theset items remain unchanged in GraphicsOutput->SetMode()\r
+    // GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize\r
+    //\r
+    ConOutPrivate->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;\r
+    ConOutPrivate->GraphicsOutput.Mode->FrameBufferSize = 0;\r
 \r
-  ConOutPrivate->GraphicsOutput.Mode->MaxMode = 1;\r
-  //\r
-  // Initial current mode to unknow state, and then set to mode 0\r
-  //\r
-  ConOutPrivate->GraphicsOutput.Mode->Mode = 0xffff;\r
-  ConOutPrivate->GraphicsOutput.SetMode (&ConOutPrivate->GraphicsOutput, 0);\r
+    ConOutPrivate->GraphicsOutput.Mode->MaxMode = 1;\r
+    //\r
+    // Initial current mode to unknown state, and then set to mode 0\r
+    //\r
+    ConOutPrivate->GraphicsOutput.Mode->Mode = 0xffff;\r
+    ConOutPrivate->GraphicsOutput.SetMode (&ConOutPrivate->GraphicsOutput, 0);\r
+  }\r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Test to see if the specified protocol could be supported on the ControllerHandle. \r
+\r
+  @param  This                Protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test.\r
+  @param  Guid                The specified protocol guid.\r
+\r
+  @retval EFI_SUCCESS         The specified protocol is supported on this device.\r
+  @retval other               The specified protocol is not supported on this device.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterSupported (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_GUID                        *Guid\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Generic Supported Check\r
-\r
-Arguments:\r
-  This              - Pointer to protocol.\r
-  ControllerHandle  - Controller Handle.\r
-  Guid              - Guid.\r
-\r
-Returns:\r
-\r
-  EFI_UNSUPPORTED - unsupported.\r
-  EFI_SUCCESS     - operation is OK.\r
-\r
---*/\r
 {\r
   EFI_STATUS  Status;\r
   VOID        *Instance;\r
@@ -619,6 +832,18 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Test to see if Console In Device could be supported on the 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
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterConInDriverBindingSupported (\r
@@ -626,21 +851,6 @@ ConSplitterConInDriverBindingSupported (
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Console In Supported Check\r
-\r
-Arguments:\r
-  This              - Pointer to protocol.\r
-  ControllerHandle  - Controller handle.\r
-  RemainingDevicePath  - Remaining device path.\r
-\r
-Returns:\r
-\r
-  EFI_STATUS\r
-\r
---*/\r
 {\r
   return ConSplitterSupported (\r
           This,\r
@@ -649,6 +859,18 @@ Returns:
           );\r
 }\r
 \r
+/**\r
+  Test to see if Simple Pointer protocol could be supported on the 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
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterSimplePointerDriverBindingSupported (\r
@@ -656,21 +878,6 @@ ConSplitterSimplePointerDriverBindingSupported (
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Standard Error Supported Check\r
-\r
-Arguments:\r
-  This              - Pointer to protocol.\r
-  ControllerHandle  - Controller handle.\r
-  RemainingDevicePath  - Remaining device path.\r
-\r
-Returns:\r
-\r
-  EFI_STATUS\r
-\r
---*/\r
 {\r
   return ConSplitterSupported (\r
           This,\r
@@ -679,28 +886,54 @@ Returns:
           );\r
 }\r
 \r
+\r
+/**\r
+  Test to see if Absolute Pointer protocol could be supported on the 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
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
-ConSplitterConOutDriverBindingSupported (\r
+ConSplitterAbsolutePointerDriverBindingSupported (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
-/*++\r
+{\r
+  return ConSplitterSupported (\r
+          This,\r
+          ControllerHandle,\r
+          &gEfiAbsolutePointerProtocolGuid\r
+          );\r
+}\r
 \r
-Routine Description:\r
-  Console Out Supported Check\r
 \r
-Arguments:\r
-  This              - Pointer to protocol.\r
-  ControllerHandle  - Controller handle.\r
-  RemainingDevicePath  - Remaining device path.\r
+/**\r
+  Test to see if Console Out Device could be supported on the ControllerHandle. \r
 \r
-Returns:\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
-  EFI_STATUS\r
+  @retval EFI_SUCCESS         This driver supports this device.\r
+  @retval other               This driver does not support this device.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConOutDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
 {\r
   return ConSplitterSupported (\r
           This,\r
@@ -709,6 +942,18 @@ Returns:
           );\r
 }\r
 \r
+/**\r
+  Test to see if Standard Error Device could be supported on the 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
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterStdErrDriverBindingSupported (\r
@@ -716,21 +961,6 @@ ConSplitterStdErrDriverBindingSupported (
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Standard Error Supported Check\r
-\r
-Arguments:\r
-  This              - Pointer to protocol.\r
-  ControllerHandle  - Controller handle.\r
-  RemainingDevicePath  - Remaining device path.\r
-\r
-Returns:\r
-\r
-  EFI_STATUS\r
-\r
---*/\r
 {\r
   return ConSplitterSupported (\r
           This,\r
@@ -739,36 +969,39 @@ Returns:
           );\r
 }\r
 \r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
+\r
+/**\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
+  @param  This                      Protocol instance pointer.\r
+  @param  ControllerHandle          Handle of device.\r
+  @param  ConSplitterVirtualHandle  Console virtual Handle.\r
+  @param  DeviceGuid                The specified Console Device, such as ConInDev,\r
+                                    ConOutDev.\r
+  @param  InterfaceGuid             The specified protocol to be opened.\r
+  @param  Interface                 Protocol interface returned.\r
+\r
+  @retval EFI_SUCCESS               This driver supports this device.\r
+  @retval other                     Failed to open the specified Console Device Guid\r
+                                    or specified protocol.\r
+\r
+**/\r
+EFI_STATUS\r
 ConSplitterStart (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_HANDLE                      ConSplitterVirtualHandle,\r
   IN  EFI_GUID                        *DeviceGuid,\r
   IN  EFI_GUID                        *InterfaceGuid,\r
-  IN  VOID                            **Interface\r
+  OUT VOID                            **Interface\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Start ConSplitter on ControllerHandle, and create the virtual\r
-  agrogated console device on first call Start for a SimpleTextIn handle.\r
-\r
-Arguments:\r
-  (Standard DriverBinding Protocol Start() function)\r
-\r
-Returns:\r
-  EFI_ERROR if a SimpleTextIn protocol is not started.\r
-\r
---*/\r
 {\r
   EFI_STATUS  Status;\r
   VOID        *Instance;\r
 \r
   //\r
-  // Check to see whether the handle has the ConsoleInDevice GUID on it\r
+  // Check to see whether the ControllerHandle has the InterfaceGuid on it.\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -804,6 +1037,19 @@ Returns:
                 );\r
 }\r
 \r
+\r
+/**\r
+  Start Console In Consplitter on device handle. \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
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          Console In Consplitter is added to ControllerHandle.\r
+  @retval other                Console In Consplitter does not support this device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterConInDriverBindingStart (\r
@@ -811,26 +1057,10 @@ ConSplitterConInDriverBindingStart (
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Start ConSplitter on ControllerHandle, and create the virtual\r
-  agrogated console device on first call Start for a SimpleTextIn handle.\r
-\r
-Arguments:\r
-  This              - Pointer to protocol.\r
-  ControllerHandle  - Controller handle.\r
-  RemainingDevicePath  - Remaining device path.\r
-\r
-Returns:\r
-\r
-  EFI_STATUS\r
-  EFI_ERROR if a SimpleTextIn protocol is not started.\r
-\r
---*/\r
 {\r
-  EFI_STATUS                     Status;\r
-  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;\r
+  EFI_STATUS                          Status;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL      *TextIn;\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL   *TextInEx;\r
 \r
   //\r
   // Start ConSplitter on ControllerHandle, and create the virtual\r
@@ -848,9 +1078,46 @@ Returns:
     return Status;\r
   }\r
 \r
-  return ConSplitterTextInAddDevice (&mConIn, TextIn);\r
+  //\r
+  // Add this device into Text In devices list.\r
+  //\r
+  Status = ConSplitterTextInAddDevice (&mConIn, TextIn);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleTextInputExProtocolGuid,\r
+                  (VOID **) &TextInEx,\r
+                  This->DriverBindingHandle,\r
+                  mConIn.VirtualHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // If Simple Text Input Ex protocol exists,\r
+    // add this device into Text In Ex devices list.\r
+    //\r
+    Status = ConSplitterTextInExAddDevice (&mConIn, TextInEx);\r
+  }\r
+\r
+  return Status;\r
 }\r
 \r
+\r
+/**\r
+  Start Simple Pointer Consplitter on device handle. \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
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          Simple Pointer Consplitter is added to ControllerHandle.\r
+  @retval other                Simple Pointer Consplitter does not support this device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterSimplePointerDriverBindingStart (\r
@@ -858,26 +1125,14 @@ ConSplitterSimplePointerDriverBindingStart (
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Start ConSplitter on ControllerHandle, and create the virtual\r
-  agrogated console device on first call Start for a SimpleTextIn handle.\r
-\r
-Arguments:\r
-  This              - Pointer to protocol.\r
-  ControllerHandle  - Controller handle.\r
-  RemainingDevicePath  - Remaining device path.\r
-\r
-Returns:\r
-\r
-  EFI_ERROR if a SimpleTextIn protocol is not started.\r
-\r
---*/\r
 {\r
   EFI_STATUS                  Status;\r
   EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;\r
 \r
+  //\r
+  // Start ConSplitter on ControllerHandle, and create the virtual\r
+  // agrogated console device on first call Start for a SimplePointer handle.\r
+  //\r
   Status = ConSplitterStart (\r
             This,\r
             ControllerHandle,\r
@@ -890,37 +1145,89 @@ Returns:
     return Status;\r
   }\r
 \r
+  //\r
+  // Add this devcie into Simple Pointer devices list.\r
+  //\r
   return ConSplitterSimplePointerAddDevice (&mConIn, SimplePointer);\r
 }\r
 \r
+\r
+/**\r
+  Start Absolute Pointer Consplitter on device handle. \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
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          Absolute Pointer Consplitter is added to ControllerHandle.\r
+  @retval other                Absolute Pointer Consplitter does not support this device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
-ConSplitterConOutDriverBindingStart (\r
+ConSplitterAbsolutePointerDriverBindingStart (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
-/*++\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_ABSOLUTE_POINTER_PROTOCOL     *AbsolutePointer;\r
+\r
+  //\r
+  // Start ConSplitter on ControllerHandle, and create the virtual\r
+  // agrogated console device on first call Start for a AbsolutePointer handle.\r
+  //\r
+  Status = ConSplitterStart (\r
+             This,\r
+             ControllerHandle,\r
+             mConIn.VirtualHandle,\r
+             &gEfiAbsolutePointerProtocolGuid,\r
+             &gEfiAbsolutePointerProtocolGuid,\r
+             (VOID **) &AbsolutePointer\r
+             );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Add this devcie into Absolute Pointer devices list.\r
+  //\r
+  return ConSplitterAbsolutePointerAddDevice (&mConIn, AbsolutePointer);\r
+}\r
 \r
-Routine Description:\r
-  Start ConSplitter on ControllerHandle, and create the virtual\r
-  agrogated console device on first call Start for a SimpleTextIn handle.\r
 \r
-Arguments:\r
-  This              - Pointer to protocol.\r
-  ControllerHandle  - Controller handle.\r
-  RemainingDevicePath  - Remaining device path.\r
+/**\r
+  Start Console Out Consplitter on device handle. \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
+                               device to start.\r
 \r
-Returns:\r
-  EFI_ERROR if a SimpleTextIn protocol is not started.\r
+  @retval EFI_SUCCESS          Console Out Consplitter is added to ControllerHandle.\r
+  @retval other                Console Out Consplitter does not support this device.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConOutDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  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
 \r
+  //\r
+  // Start ConSplitter on ControllerHandle, and create the virtual\r
+  // agrogated console device on first call Start for a ConsoleOut handle.\r
+  //\r
   Status = ConSplitterStart (\r
             This,\r
             ControllerHandle,\r
@@ -932,6 +1239,9 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
+  GraphicsOutput = NULL;\r
+  UgaDraw        = NULL;\r
   //\r
   // Try to Open Graphics Output protocol\r
   //\r
@@ -943,23 +1253,27 @@ Returns:
                   mConOut.VirtualHandle,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
-  if (EFI_ERROR (Status)) {\r
-    GraphicsOutput = NULL;\r
+\r
+  if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    //\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
   }\r
+\r
   //\r
-  // Open UGA_DRAW protocol\r
+  // When new console device is added, the new mode will be set later,\r
+  // so put current mode back to init state.\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
-  if (EFI_ERROR (Status)) {\r
-    UgaDraw = NULL;\r
-  }\r
+  mConOut.TextOutMode.Mode = 0xFF;\r
+\r
   //\r
   // If both ConOut and StdErr incorporate the same Text Out device,\r
   // their MaxMode and QueryData should be the intersection of both.\r
@@ -967,9 +1281,36 @@ Returns:
   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
+    //\r
+    // Match the UGA mode data of ConOut with the current mode\r
+    //\r
+    if (UgaDraw != NULL) {\r
+      UgaDraw->GetMode (\r
+                 UgaDraw,\r
+                 &mConOut.UgaHorizontalResolution,\r
+                 &mConOut.UgaVerticalResolution,\r
+                 &mConOut.UgaColorDepth,\r
+                 &mConOut.UgaRefreshRate\r
+                 );\r
+    }\r
+  }\r
   return Status;\r
 }\r
 \r
+\r
+/**\r
+  Start Standard Error Consplitter on device handle. \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
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          Standard Error Consplitter is added to ControllerHandle.\r
+  @retval other                Standard Error Consplitter does not support this device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterStdErrDriverBindingStart (\r
@@ -977,25 +1318,14 @@ ConSplitterStdErrDriverBindingStart (
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Start ConSplitter on ControllerHandle, and create the virtual\r
-  agrogated console device on first call Start for a SimpleTextIn handle.\r
-\r
-Arguments:\r
-  This              - Pointer to protocol.\r
-  ControllerHandle  - Controller handle.\r
-  RemainingDevicePath  - Remaining device path.\r
-\r
-Returns:\r
-  EFI_ERROR if a SimpleTextIn protocol is not started.\r
-\r
---*/\r
 {\r
   EFI_STATUS                       Status;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
 \r
+  //\r
+  // Start ConSplitter on ControllerHandle, and create the virtual\r
+  // agrogated console device on first call Start for a StandardError handle.\r
+  //\r
   Status = ConSplitterStart (\r
             This,\r
             ControllerHandle,\r
@@ -1007,6 +1337,13 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
+  //\r
+  // When new console device is added, the new mode will be set later,\r
+  // so put current mode back to init state.\r
+  //\r
+  mStdErr.TextOutMode.Mode = 0xFF;\r
+\r
   //\r
   // If both ConOut and StdErr incorporate the same Text Out device,\r
   // their MaxMode and QueryData should be the intersection of both.\r
@@ -1034,9 +1371,24 @@ Returns:
   return Status;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Stop ConSplitter on device handle by closing Console Device Guid on device handle \r
+  and the console virtual handle.\r
+  \r
+  @param  This                      Protocol instance pointer.\r
+  @param  ControllerHandle          Handle of device.\r
+  @param  ConSplitterVirtualHandle  Console virtual Handle.\r
+  @param  DeviceGuid                The specified Console Device, such as ConInDev,\r
+                                    ConOutDev.\r
+  @param  InterfaceGuid             The specified protocol to be opened.\r
+  @param  Interface                 Protocol interface returned.\r
+\r
+  @retval EFI_SUCCESS               Stop ConSplitter on ControllerHandle successfully.\r
+  @retval other                     Failed to Stop ConSplitter on ControllerHandle.\r
+\r
+**/\r
 EFI_STATUS\r
-EFIAPI\r
 ConSplitterStop (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
   IN  EFI_HANDLE                      ControllerHandle,\r
@@ -1045,18 +1397,6 @@ ConSplitterStop (
   IN  EFI_GUID                        *InterfaceGuid,\r
   IN  VOID                            **Interface\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-  (Standard DriverBinding Protocol Stop() function)\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
   EFI_STATUS  Status;\r
 \r
@@ -1080,6 +1420,7 @@ Returns:
         This->DriverBindingHandle,\r
         ConSplitterVirtualHandle\r
         );\r
+\r
   gBS->CloseProtocol (\r
         ControllerHandle,\r
         DeviceGuid,\r
@@ -1090,6 +1431,20 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Stop Console In ConSplitter on ControllerHandle by closing Console In Devcice GUID.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterConInDriverBindingStop (\r
@@ -1098,26 +1453,37 @@ ConSplitterConInDriverBindingStop (
   IN  UINTN                           NumberOfChildren,\r
   IN  EFI_HANDLE                      *ChildHandleBuffer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-  (Standard DriverBinding Protocol Stop() function)\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
-  EFI_STATUS                     Status;\r
-  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;\r
+  EFI_STATUS                        Status;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL    *TextIn;\r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx;\r
 \r
   if (NumberOfChildren == 0) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleTextInputExProtocolGuid,\r
+                  (VOID **) &TextInEx,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // If Simple Text Input Ex protocol exists,\r
+    // remove device from Text Input Ex devices list.\r
+    //  \r
+    Status = ConSplitterTextInExDeleteDevice (&mConIn, TextInEx);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Close Simple Text In protocol on controller handle and virtual handle.\r
+  //\r
   Status = ConSplitterStop (\r
             This,\r
             ControllerHandle,\r
@@ -1129,12 +1495,28 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
   //\r
-  // Delete this console input device's data structures.\r
-  //\r
+  // Remove device from Text Input devices list.\r
+  // \r
   return ConSplitterTextInDeleteDevice (&mConIn, TextIn);\r
 }\r
 \r
+\r
+/**\r
+  Stop Simple Pointer protocol ConSplitter on ControllerHandle by closing\r
+  Simple Pointer protocol.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterSimplePointerDriverBindingStop (\r
@@ -1143,18 +1525,6 @@ ConSplitterSimplePointerDriverBindingStop (
   IN  UINTN                           NumberOfChildren,\r
   IN  EFI_HANDLE                      *ChildHandleBuffer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-  (Standard DriverBinding Protocol Stop() function)\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
   EFI_STATUS                  Status;\r
   EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;\r
@@ -1163,6 +1533,9 @@ Returns:
     return EFI_SUCCESS;\r
   }\r
 \r
+  //\r
+  // Close Simple Pointer protocol on controller handle and virtual handle.\r
+  //\r
   Status = ConSplitterStop (\r
             This,\r
             ControllerHandle,\r
@@ -1174,32 +1547,87 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
   //\r
-  // Delete this console input device's data structures.\r
+  // Remove this device from Simple Pointer device list.\r
   //\r
   return ConSplitterSimplePointerDeleteDevice (&mConIn, SimplePointer);\r
 }\r
 \r
+\r
+/**\r
+  Stop Absolute Pointer protocol ConSplitter on ControllerHandle by closing\r
+  Absolute Pointer protocol.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
-ConSplitterConOutDriverBindingStop (\r
+ConSplitterAbsolutePointerDriverBindingStop (\r
   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  UINTN                           NumberOfChildren,\r
   IN  EFI_HANDLE                      *ChildHandleBuffer\r
   )\r
-/*++\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_ABSOLUTE_POINTER_PROTOCOL     *AbsolutePointer;\r
+\r
+  if (NumberOfChildren == 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Close Absolute Pointer protocol on controller handle and virtual handle.\r
+  //\r
+  Status = ConSplitterStop (\r
+             This,\r
+             ControllerHandle,\r
+             mConIn.VirtualHandle,\r
+             &gEfiAbsolutePointerProtocolGuid,\r
+             &gEfiAbsolutePointerProtocolGuid,\r
+             (VOID **) &AbsolutePointer\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Remove this device from Absolute Pointer device list.\r
+  //\r
+  return ConSplitterAbsolutePointerDeleteDevice (&mConIn, AbsolutePointer);\r
+}\r
 \r
-Routine Description:\r
 \r
-Arguments:\r
-  (Standard DriverBinding Protocol Stop() function)\r
+/**\r
+  Stop Console Out ConSplitter on device handle by closing Console Out Devcice GUID.\r
 \r
-Returns:\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
 \r
-  None\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterConOutDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      ControllerHandle,\r
+  IN  UINTN                           NumberOfChildren,\r
+  IN  EFI_HANDLE                      *ChildHandleBuffer\r
+  )\r
 {\r
   EFI_STATUS                       Status;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
@@ -1208,6 +1636,9 @@ Returns:
     return EFI_SUCCESS;\r
   }\r
 \r
+  //\r
+  // Close Absolute Pointer protocol on controller handle and virtual handle.\r
+  //\r
   Status = ConSplitterStop (\r
             This,\r
             ControllerHandle,\r
@@ -1221,11 +1652,25 @@ Returns:
   }\r
 \r
   //\r
-  // Delete this console output device's data structures.\r
+  // Remove this device from Text Out device list.\r
   //\r
   return ConSplitterTextOutDeleteDevice (&mConOut, TextOut);\r
 }\r
 \r
+\r
+/**\r
+  Stop Standard Error ConSplitter on ControllerHandle by closing Standard Error GUID.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterStdErrDriverBindingStop (\r
@@ -1234,18 +1679,6 @@ ConSplitterStdErrDriverBindingStop (
   IN  UINTN                           NumberOfChildren,\r
   IN  EFI_HANDLE                      *ChildHandleBuffer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-  (Standard DriverBinding Protocol Stop() function)\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - Complete successfully.\r
-\r
---*/\r
 {\r
   EFI_STATUS                       Status;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
@@ -1254,6 +1687,9 @@ Returns:
     return EFI_SUCCESS;\r
   }\r
 \r
+  //\r
+  // Close Standard Error Device on controller handle and virtual handle.\r
+  //\r
   Status = ConSplitterStop (\r
             This,\r
             ControllerHandle,\r
@@ -1290,33 +1726,28 @@ Returns:
   return Status;\r
 }\r
 \r
-EFI_STATUS\r
-ConSplitterGrowBuffer (\r
-  IN  UINTN                           SizeOfCount,\r
-  IN  UINTN                           *Count,\r
-  IN OUT  VOID                        **Buffer\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
+/**\r
   Take the passed in Buffer of size SizeOfCount and grow the buffer\r
   by MAX (CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT, MaxGrow) * SizeOfCount\r
   bytes. Copy the current data in Buffer to the new version of Buffer\r
   and free the old version of buffer.\r
 \r
+  @param  SizeOfCount              Size of element in array\r
+  @param  Count                    Current number of elements in array\r
+  @param  Buffer                   Bigger version of passed in Buffer with all the\r
+                                   data\r
 \r
-Arguments:\r
-  SizeOfCount - Size of element in array\r
-  Count       - Current number of elements in array\r
-  Buffer      - Bigger version of passed in Buffer with all the data\r
-\r
-Returns:\r
-  EFI_SUCCESS - Buffer size has grown\r
-  EFI_OUT_OF_RESOURCES - Could not grow the buffer size\r
+  @retval EFI_SUCCESS              Buffer size has grown\r
+  @retval EFI_OUT_OF_RESOURCES     Could not grow the buffer size.\r
 \r
-  None\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+ConSplitterGrowBuffer (\r
+  IN  UINTN                           SizeOfCount,\r
+  IN  UINTN                           *Count,\r
+  IN OUT  VOID                        **Buffer\r
+  )\r
 {\r
   UINTN NewSize;\r
   UINTN OldSize;\r
@@ -1347,25 +1778,24 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Add Text Input Device in Consplitter Text Input list.\r
+\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  TextIn                   Simple Text Input protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Text Input Device added successfully.\r
+  @retval EFI_OUT_OF_RESOURCES     Could not grow the buffer size.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterTextInAddDevice (\r
   IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *TextIn\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS\r
-  EFI_OUT_OF_RESOURCES\r
-\r
---*/\r
-{\r
-  EFI_STATUS  Status;\r
+{\r
+  EFI_STATUS  Status;\r
 \r
   //\r
   // If the Text In List is full, enlarge it by calling growbuffer().\r
@@ -1394,23 +1824,22 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Remove Simple Text Device in Consplitter Absolute Pointer list.\r
+\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  TextIn                   Simple Text protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Simple Text Device removed successfully.\r
+  @retval EFI_NOT_FOUND            No Simple Text Device found.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterTextInDeleteDevice (\r
   IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *TextIn\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS\r
-  EFI_NOT_FOUND\r
-\r
---*/\r
 {\r
   UINTN Index;\r
   //\r
@@ -1431,23 +1860,102 @@ Returns:
   return EFI_NOT_FOUND;\r
 }\r
 \r
+/**\r
+  Add Text Input Ex Device in Consplitter Text Input Ex list.\r
+\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  TextInEx                 Simple Text Ex Input protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Text Input Ex Device added successfully.\r
+  @retval EFI_OUT_OF_RESOURCES     Could not grow the buffer size.\r
+\r
+**/\r
 EFI_STATUS\r
-ConSplitterSimplePointerAddDevice (\r
-  IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
-  IN  EFI_SIMPLE_POINTER_PROTOCOL     *SimplePointer\r
+ConSplitterTextInExAddDevice (\r
+  IN  TEXT_IN_SPLITTER_PRIVATE_DATA         *Private,\r
+  IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL     *TextInEx\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // If the TextInEx List is full, enlarge it by calling growbuffer().\r
+  //\r
+  if (Private->CurrentNumberOfExConsoles >= Private->TextInExListCount) {\r
+    Status = ConSplitterGrowBuffer (\r
+              sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),\r
+              &Private->TextInExListCount,\r
+              (VOID **) &Private->TextInExList\r
+              );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+  //\r
+  // Add the new text-in device data structure into the Text In List.\r
+  //\r
+  Private->TextInExList[Private->CurrentNumberOfExConsoles] = TextInEx;\r
+  Private->CurrentNumberOfExConsoles++;\r
+\r
+  //\r
+  // Extra CheckEvent added to reduce the double CheckEvent() in UI.c\r
+  //\r
+  gBS->CheckEvent (TextInEx->WaitForKeyEx);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Remove Simple Text Ex Device in Consplitter Absolute Pointer list.\r
+\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  TextInEx                 Simple Text Ex protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Simple Text Ex Device removed successfully.\r
+  @retval EFI_NOT_FOUND            No Simple Text Ex Device found.\r
+\r
+**/\r
+EFI_STATUS\r
+ConSplitterTextInExDeleteDevice (\r
+  IN  TEXT_IN_SPLITTER_PRIVATE_DATA         *Private,\r
+  IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL     *TextInEx\r
   )\r
-/*++\r
+{\r
+  UINTN Index;\r
+  //\r
+  // Remove the specified text-in device data structure from the Text In List,\r
+  // and rearrange the remaining data structures in the Text In List.\r
+  //\r
+  for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
+    if (Private->TextInExList[Index] == TextInEx) {\r
+      for (Index = Index; Index < Private->CurrentNumberOfExConsoles - 1; Index++) {\r
+        Private->TextInExList[Index] = Private->TextInExList[Index + 1];\r
+      }\r
+\r
+      Private->CurrentNumberOfExConsoles--;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
 \r
-Routine Description:\r
 \r
-Arguments:\r
+/**\r
+  Add Simple Pointer Device in Consplitter Simple Pointer list.\r
 \r
-Returns:\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  SimplePointer            Simple Pointer protocol pointer.\r
 \r
-  EFI_OUT_OF_RESOURCES\r
-  EFI_SUCCESS\r
+  @retval EFI_SUCCESS              Simple Pointer Device added successfully.\r
+  @retval EFI_OUT_OF_RESOURCES     Could not grow the buffer size.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+ConSplitterSimplePointerAddDevice (\r
+  IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
+  IN  EFI_SIMPLE_POINTER_PROTOCOL     *SimplePointer\r
+  )\r
 {\r
   EFI_STATUS  Status;\r
 \r
@@ -1472,22 +1980,22 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Remove Simple Pointer Device in Consplitter Absolute Pointer list.\r
+\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  SimplePointer            Simple Pointer protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Simple Pointer Device removed successfully.\r
+  @retval EFI_NOT_FOUND            No Simple Pointer Device found.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterSimplePointerDeleteDevice (\r
   IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
   IN  EFI_SIMPLE_POINTER_PROTOCOL     *SimplePointer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
   UINTN Index;\r
   //\r
@@ -1508,22 +2016,95 @@ Returns:
   return EFI_NOT_FOUND;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Add Absolute Pointer Device in Consplitter Absolute Pointer list.\r
+\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  AbsolutePointer          Absolute Pointer protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Absolute Pointer Device added successfully.\r
+  @retval EFI_OUT_OF_RESOURCES     Could not grow the buffer size.\r
+\r
+**/\r
 EFI_STATUS\r
-ConSplitterGrowMapTable (\r
-  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private\r
+ConSplitterAbsolutePointerAddDevice (\r
+  IN  TEXT_IN_SPLITTER_PRIVATE_DATA     *Private,\r
+  IN  EFI_ABSOLUTE_POINTER_PROTOCOL     *AbsolutePointer\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // If the Absolute Pointer List is full, enlarge it by calling growbuffer().\r
+  //\r
+  if (Private->CurrentNumberOfAbsolutePointers >= Private->AbsolutePointerListCount) {\r
+    Status = ConSplitterGrowBuffer (\r
+              sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),\r
+              &Private->AbsolutePointerListCount,\r
+              (VOID **) &Private->AbsolutePointerList\r
+              );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+  //\r
+  // Add the new text-in device data structure into the Text In List.\r
+  //\r
+  Private->AbsolutePointerList[Private->CurrentNumberOfAbsolutePointers] = AbsolutePointer;\r
+  Private->CurrentNumberOfAbsolutePointers++;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Remove Absolute Pointer Device in Consplitter Absolute Pointer list.\r
+\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  AbsolutePointer          Absolute Pointer protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Absolute Pointer Device removed successfully.\r
+  @retval EFI_NOT_FOUND            No Absolute Pointer Device found.\r
+\r
+**/\r
+EFI_STATUS\r
+ConSplitterAbsolutePointerDeleteDevice (\r
+  IN  TEXT_IN_SPLITTER_PRIVATE_DATA     *Private,\r
+  IN  EFI_ABSOLUTE_POINTER_PROTOCOL     *AbsolutePointer\r
   )\r
-/*++\r
+{\r
+  UINTN Index;\r
+  //\r
+  // Remove the specified text-in device data structure from the Text In List,\r
+  // and rearrange the remaining data structures in the Text In List.\r
+  //\r
+  for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {\r
+    if (Private->AbsolutePointerList[Index] == AbsolutePointer) {\r
+      for (Index = Index; Index < Private->CurrentNumberOfAbsolutePointers - 1; Index++) {\r
+        Private->AbsolutePointerList[Index] = Private->AbsolutePointerList[Index + 1];\r
+      }\r
+\r
+      Private->CurrentNumberOfAbsolutePointers--;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
 \r
-Routine Description:\r
+  return EFI_NOT_FOUND;\r
+}\r
 \r
-Arguments:\r
+/**\r
+  Reallocate Text Out mode map.\r
 \r
-Returns:\r
+  @param  Private                  Consplitter Text Out pointer.\r
 \r
-  None\r
+  @retval EFI_SUCCESS              Buffer size has grown\r
+  @retval EFI_OUT_OF_RESOURCES     Could not grow the buffer size.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+ConSplitterGrowMapTable (\r
+  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private\r
+  )\r
 {\r
   UINTN Size;\r
   UINTN NewSize;\r
@@ -1585,23 +2166,22 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Add 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
+  @retval EFI_SUCCESS           Device added successfully.\r
+  @retval EFI_OUT_OF_RESOURCES  Could not grow the buffer size.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterAddOutputMode (\r
   IN  TEXT_OUT_SPLITTER_PRIVATE_DATA     *Private,\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *TextOut\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
   EFI_STATUS  Status;\r
   INT32       MaxMode;\r
@@ -1639,12 +2219,20 @@ Returns:
   Mode  = 0;\r
   Index = 0;\r
   while (Mode < MaxMode) {\r
-    TextOut->QueryMode (\r
-              TextOut,\r
-              Mode,\r
-              &Private->TextOutQueryData[Mode].Columns,\r
-              &Private->TextOutQueryData[Mode].Rows\r
-              );\r
+    Status = TextOut->QueryMode (\r
+                  TextOut,\r
+                  Mode,\r
+                  &Private->TextOutQueryData[Mode].Columns,\r
+                  &Private->TextOutQueryData[Mode].Rows\r
+                  );\r
+    //\r
+    // If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData\r
+    // is clear to 0x0.\r
+    //\r
+    if ((EFI_ERROR(Status)) && (Mode == 1)) {\r
+      Private->TextOutQueryData[Mode].Columns = 0;\r
+      Private->TextOutQueryData[Mode].Rows = 0;\r
+    }\r
     Private->TextOutModeMap[Index] = Mode;\r
     Mode++;\r
     Index += Private->TextOutListCount;\r
@@ -1653,7 +2241,24 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+/**\r
+  Reconstruct TextOutModeMap to get intersection of modes\r
+\r
+  This routine reconstruct TextOutModeMap to get the intersection\r
+  of modes for all console out devices. Because EFI/UEFI spec require\r
+  mode 0 is 80x25, mode 1 is 80x50, this routine will not check the\r
+  intersection for mode 0 and mode 1.\r
+\r
+  @param TextOutModeMap  Current text out mode map, begin with the mode 80x25\r
+  @param NewlyAddedMap   New text out mode map, begin with the mode 80x25\r
+  @param MapStepSize     Mode step size for one console device\r
+  @param NewMapStepSize  Mode step size for one console device\r
+  @param MaxMode         Current max text mode\r
+  @param CurrentMode     Current text mode\r
+\r
+  @retval None\r
+\r
+**/\r
 VOID\r
 ConSplitterGetIntersection (\r
   IN  INT32                           *TextOutModeMap,\r
@@ -1670,9 +2275,16 @@ ConSplitterGetIntersection (
   INT32 CurrentMaxMode;\r
   INT32 Mode;\r
 \r
-  Index           = 0;\r
-  CurrentMapEntry = TextOutModeMap;\r
-  NextMapEntry    = TextOutModeMap;\r
+  //\r
+  // According to EFI/UEFI spec, mode 0 and mode 1 have been reserved\r
+  // for 80x25 and 80x50 in Simple Text Out protocol, so don't make intersection\r
+  // for mode 0 and mode 1, mode number starts from 2.\r
+  //\r
+  Index           = 2;\r
+  CurrentMapEntry = &TextOutModeMap[MapStepSize * 2];\r
+  NextMapEntry    = &TextOutModeMap[MapStepSize * 2];\r
+  NewlyAddedMap   = &NewlyAddedMap[NewMapStepSize * 2];\r
+\r
   CurrentMaxMode  = *MaxMode;\r
   Mode            = *CurrentMode;\r
 \r
@@ -1706,34 +2318,33 @@ ConSplitterGetIntersection (
   return ;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Add 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
+  @return None\r
+\r
+**/\r
 VOID\r
 ConSplitterSyncOutputMode (\r
   IN  TEXT_OUT_SPLITTER_PRIVATE_DATA     *Private,\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *TextOut\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-  Private - Private data structure.\r
-  TextOut - Text Out Protocol.\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
   INT32                         CurrentMaxMode;\r
   INT32                         Mode;\r
   INT32                         Index;\r
   INT32                         *TextOutModeMap;\r
   INT32                         *MapTable;\r
+  INT32                         QueryMode;\r
   TEXT_OUT_SPLITTER_QUERY_DATA  *TextOutQueryData;\r
   UINTN                         Rows;\r
   UINTN                         Columns;\r
   UINTN                         StepSize;\r
+  EFI_STATUS                    Status;\r
 \r
   //\r
   // Must make sure that current mode won't change even if mode number changes\r
@@ -1749,14 +2360,23 @@ Returns:
   Mode      = 0;\r
   MapTable  = TextOutModeMap + Private->CurrentNumberOfConsoles;\r
   while (Mode < TextOut->Mode->MaxMode) {\r
-    TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);\r
-\r
+    Status = TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);\r
+    if (EFI_ERROR(Status)) {\r
+      if (Mode == 1) {\r
+        MapTable[StepSize] = Mode;\r
+        TextOutQueryData[Mode].Columns = 0;\r
+        TextOutQueryData[Mode].Rows = 0;\r
+      }\r
+      Mode++;\r
+      continue;\r
+    }\r
     //\r
-    // Search the QueryData database to see if they intersects\r
+    // Search the intersection map and QueryData database to see if they intersects\r
     //\r
     Index = 0;\r
     while (Index < CurrentMaxMode) {\r
-      if ((TextOutQueryData[Index].Rows == Rows) && (TextOutQueryData[Index].Columns == Columns)) {\r
+      QueryMode = *(TextOutModeMap + Index * StepSize);\r
+      if ((TextOutQueryData[QueryMode].Rows == Rows) && (TextOutQueryData[QueryMode].Columns == Columns)) {\r
         MapTable[Index * StepSize] = Mode;\r
         break;\r
       }\r
@@ -1782,23 +2402,18 @@ Returns:
   return ;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Sync output device between ConOut and StdErr output.\r
+\r
+  @retval EFI_SUCCESS              Sync implemented successfully.\r
+  @retval EFI_OUT_OF_RESOURCES     Could not grow the buffer size.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterGetIntersectionBetweenConOutAndStrErr (\r
   VOID\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\r
-  EFI_OUT_OF_RESOURCES\r
-\r
---*/\r
 {\r
   UINTN                         ConOutNumOfConsoles;\r
   UINTN                         StdErrNumOfConsoles;\r
@@ -1806,10 +2421,14 @@ Returns:
   TEXT_OUT_AND_GOP_DATA         *StdErrTextOutList;\r
   UINTN                         Indexi;\r
   UINTN                         Indexj;\r
-  UINTN                         Rows;\r
-  UINTN                         Columns;\r
+  UINTN                         ConOutRows;\r
+  UINTN                         ConOutColumns;\r
+  UINTN                         StdErrRows;\r
+  UINTN                         StdErrColumns;\r
   INT32                         ConOutMaxMode;\r
   INT32                         StdErrMaxMode;\r
+  INT32                         ConOutMode;\r
+  INT32                         StdErrMode;\r
   INT32                         Mode;\r
   INT32                         Index;\r
   INT32                         *ConOutModeMap;\r
@@ -1818,6 +2437,8 @@ Returns:
   INT32                         *StdErrMapTable;\r
   TEXT_OUT_SPLITTER_QUERY_DATA  *ConOutQueryData;\r
   TEXT_OUT_SPLITTER_QUERY_DATA  *StdErrQueryData;\r
+  UINTN                         ConOutStepSize;\r
+  UINTN                         StdErrStepSize;\r
   BOOLEAN                       FoundTheSameTextOut;\r
   UINTN                         ConOutMapTableSize;\r
   UINTN                         StdErrMapTableSize;\r
@@ -1853,10 +2474,12 @@ Returns:
   //\r
   ConOutMaxMode     = mConOut.TextOutMode.MaxMode;\r
   ConOutModeMap     = mConOut.TextOutModeMap;\r
+  ConOutStepSize    = mConOut.TextOutListCount;\r
   ConOutQueryData   = mConOut.TextOutQueryData;\r
 \r
   StdErrMaxMode     = mStdErr.TextOutMode.MaxMode;\r
   StdErrModeMap     = mStdErr.TextOutModeMap;\r
+  StdErrStepSize    = mStdErr.TextOutListCount;\r
   StdErrQueryData   = mStdErr.TextOutQueryData;\r
 \r
   //\r
@@ -1885,13 +2508,17 @@ Returns:
   Mode = 0;\r
   while (Mode < ConOutMaxMode) {\r
     //\r
-    // Search the other's QueryData database to see if they intersect\r
+    // Search the intersection map and QueryData database to see if they intersect\r
     //\r
-    Index   = 0;\r
-    Rows    = ConOutQueryData[Mode].Rows;\r
-    Columns = ConOutQueryData[Mode].Columns;\r
+    Index = 0;\r
+    ConOutMode    = *(ConOutModeMap + Mode * ConOutStepSize);\r
+    ConOutRows    = ConOutQueryData[ConOutMode].Rows;\r
+    ConOutColumns = ConOutQueryData[ConOutMode].Columns;\r
     while (Index < StdErrMaxMode) {\r
-      if ((StdErrQueryData[Index].Rows == Rows) && (StdErrQueryData[Index].Columns == Columns)) {\r
+      StdErrMode    = *(StdErrModeMap + Index * StdErrStepSize);\r
+      StdErrRows    = StdErrQueryData[StdErrMode].Rows;\r
+      StdErrColumns = StdErrQueryData[StdErrMode].Columns;\r
+      if ((StdErrRows == ConOutRows) && (StdErrColumns == ConOutColumns)) {\r
         ConOutMapTable[Mode]  = 1;\r
         StdErrMapTable[Index] = 1;\r
         break;\r
@@ -1936,35 +2563,41 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Add GOP or UGA output mode into Consplitter Text Out list.\r
+\r
+  @param  Private               Text Out Splitter pointer.\r
+  @param  GraphicsOutput        Graphics Output protocol pointer.\r
+  @param  UgaDraw               UGA Draw protocol pointer.\r
+\r
+  @retval EFI_SUCCESS           Output mode added successfully.\r
+  @retval other                 Failed to add output mode.\r
+\r
+**/\r
 EFI_STATUS\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
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
   EFI_STATUS                           Status;\r
   UINTN                                Index;\r
-  TEXT_OUT_GOP_MODE                    *Mode;\r
+  UINTN                                CurrentIndex;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode;\r
   UINTN                                SizeOfInfo;\r
   EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE    *CurrentGraphicsOutputMode;\r
-  TEXT_OUT_GOP_MODE                    *ModeBuffer;\r
-  TEXT_OUT_GOP_MODE                    *MatchedMode;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeBuffer;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *MatchedMode;\r
   UINTN                                NumberIndex;\r
   BOOLEAN                              Match;\r
+  BOOLEAN                              AlreadyExist;\r
+  UINT32                               UgaHorizontalResolution;\r
+  UINT32                               UgaVerticalResolution;\r
+  UINT32                               UgaColorDepth;\r
+  UINT32                               UgaRefreshRate;\r
 \r
   if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {\r
     return EFI_UNSUPPORTED;\r
@@ -1972,6 +2605,18 @@ Returns:
 \r
   CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;\r
 \r
+  Index        = 0;\r
+  CurrentIndex = 0;\r
+\r
+  if (Private->CurrentNumberOfUgaDraw != 0) {\r
+    //\r
+    // If any UGA device has already been added, then there is no need to\r
+    // calculate intersection of display mode of different GOP/UGA device,\r
+    // since only one display mode will be exported (i.e. user-defined mode)\r
+    //\r
+    goto Done;\r
+  }\r
+\r
   if (GraphicsOutput != NULL) {\r
     if (Private->CurrentNumberOfGraphicsOutput == 0) {\r
         //\r
@@ -1987,7 +2632,7 @@ Returns:
         //\r
         // Allocate resource for the private mode buffer\r
         //\r
-        ModeBuffer = AllocatePool (sizeof (TEXT_OUT_GOP_MODE) * GraphicsOutput->Mode->MaxMode);\r
+        ModeBuffer = AllocatePool (GraphicsOutput->Mode->SizeOfInfo * GraphicsOutput->Mode->MaxMode);\r
         if (ModeBuffer == NULL) {\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
@@ -2003,8 +2648,7 @@ Returns:
           if (EFI_ERROR (Status)) {\r
             return Status;\r
           }\r
-          Mode->HorizontalResolution = Info->HorizontalResolution;\r
-          Mode->VerticalResolution = Info->VerticalResolution;\r
+          CopyMem (Mode, Info, SizeOfInfo);\r
           Mode++;\r
           FreePool (Info);\r
         }\r
@@ -2012,7 +2656,7 @@ Returns:
       //\r
       // Check intersection of display mode\r
       //\r
-      ModeBuffer = AllocatePool (sizeof (TEXT_OUT_GOP_MODE) * CurrentGraphicsOutputMode->MaxMode);\r
+      ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * CurrentGraphicsOutputMode->MaxMode);\r
       if (ModeBuffer == NULL) {\r
         return EFI_OUT_OF_RESOURCES;\r
       }\r
@@ -2028,7 +2672,7 @@ Returns:
             return Status;\r
           }\r
           if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&\r
-              (Info->VerticalResolution == Mode->VerticalResolution)){\r
+              (Info->VerticalResolution == Mode->VerticalResolution)) {\r
             Match = TRUE;\r
             FreePool (Info);\r
             break;\r
@@ -2037,8 +2681,28 @@ Returns:
         }\r
 \r
         if (Match) {\r
-          CopyMem (MatchedMode, Mode, sizeof (TEXT_OUT_GOP_MODE));\r
-          MatchedMode++;\r
+          AlreadyExist = FALSE;\r
+\r
+          for (Info = ModeBuffer; Info < MatchedMode; Info++) {\r
+            if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&\r
+                (Info->VerticalResolution == Mode->VerticalResolution)) {\r
+              AlreadyExist = TRUE;\r
+              break;\r
+            }\r
+          }\r
+\r
+          if (!AlreadyExist) {\r
+            CopyMem (MatchedMode, Mode, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
+\r
+            //\r
+            // Physical frame buffer is no longer available, change PixelFormat to PixelBltOnly\r
+            //\r
+            MatchedMode->Version = 0;\r
+            MatchedMode->PixelFormat = PixelBltOnly;\r
+            ZeroMem (&MatchedMode->PixelInformation, sizeof (EFI_PIXEL_BITMASK));\r
+\r
+            MatchedMode++;\r
+          }\r
         }\r
 \r
         Mode++;\r
@@ -2053,61 +2717,80 @@ Returns:
       //\r
       // Physical frame buffer is no longer available when there are more than one physical GOP devices\r
       //\r
-      CurrentGraphicsOutputMode->MaxMode = (UINT32) (((UINTN) MatchedMode - (UINTN) ModeBuffer) / sizeof (TEXT_OUT_GOP_MODE));\r
+      CurrentGraphicsOutputMode->MaxMode = (UINT32) (((UINTN) MatchedMode - (UINTN) ModeBuffer) / sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
       CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;\r
       ZeroMem (&CurrentGraphicsOutputMode->Info->PixelInformation, sizeof (EFI_PIXEL_BITMASK));\r
       CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
-      CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;\r
+      CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;\r
       CurrentGraphicsOutputMode->FrameBufferSize = 0;\r
     }\r
 \r
     //\r
-    // Select a prefered Display mode 800x600\r
+    // Graphics console driver can ensure the same mode for all GOP devices\r
     //\r
     for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {\r
       Mode = &Private->GraphicsOutputModeBuffer[Index];\r
-      if ((Mode->HorizontalResolution == 800) && (Mode->VerticalResolution == 600)) {\r
+      if ((Mode->HorizontalResolution == GraphicsOutput->Mode->Info->HorizontalResolution) &&\r
+         (Mode->VerticalResolution == GraphicsOutput->Mode->Info->VerticalResolution)) {\r
+        CurrentIndex = Index;\r
         break;\r
       }\r
     }\r
-    //\r
-    // Prefered mode is not found, set to mode 0\r
-    //\r
     if (Index >= CurrentGraphicsOutputMode->MaxMode) {\r
-      Index = 0;\r
+      //\r
+      // if user defined mode is not found, set to default mode 800x600\r
+      //\r
+      for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {\r
+        Mode = &Private->GraphicsOutputModeBuffer[Index];\r
+        if ((Mode->HorizontalResolution == 800) && (Mode->VerticalResolution == 600)) {\r
+          CurrentIndex = Index;\r
+          break;\r
+        }\r
+      }\r
     }\r
-\r
-    //\r
-    // Current mode number may need update now, so set it to an invalide mode number\r
-    //\r
-    CurrentGraphicsOutputMode->Mode = 0xffff;\r
-  } else {\r
+  }\r
+  if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
-    // For UGA device, it's inconvenient to retrieve all the supported display modes.\r
-    // To simplify the implementation, only add one resolution(800x600, 32bit color depth) as defined in UEFI spec\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
     //\r
+    UgaDraw->GetMode (\r
+               UgaDraw,\r
+               &UgaHorizontalResolution,\r
+               &UgaVerticalResolution,\r
+               &UgaColorDepth,\r
+               &UgaRefreshRate\r
+               );\r
+\r
     CurrentGraphicsOutputMode->MaxMode = 1;\r
-    CurrentGraphicsOutputMode->Info->Version = 0;\r
-    CurrentGraphicsOutputMode->Info->HorizontalResolution = 800;\r
-    CurrentGraphicsOutputMode->Info->VerticalResolution = 600;\r
-    CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;\r
-    CurrentGraphicsOutputMode->Info->PixelsPerScanLine = 800;\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
-    CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;\r
+    CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;\r
     CurrentGraphicsOutputMode->FrameBufferSize = 0;\r
 \r
     //\r
     // Update the private mode buffer\r
     //\r
-    ModeBuffer = &Private->GraphicsOutputModeBuffer[0];\r
-    ModeBuffer->HorizontalResolution = 800;\r
-    ModeBuffer->VerticalResolution   = 600;\r
+    CopyMem (&Private->GraphicsOutputModeBuffer[0], Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
 \r
     //\r
-    // Current mode is unknow now, set it to an invalid mode number 0xffff\r
+    // Only mode 0 is available to be set\r
     //\r
-    CurrentGraphicsOutputMode->Mode = 0xffff;\r
-    Index = 0;\r
+    CurrentIndex = 0;\r
+  }\r
+\r
+Done:\r
+\r
+  if (GraphicsOutput != NULL) {\r
+    Private->CurrentNumberOfGraphicsOutput++;\r
+  }\r
+  if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    Private->CurrentNumberOfUgaDraw++;\r
   }\r
 \r
   //\r
@@ -2115,37 +2798,156 @@ Returns:
   // regardless whether the console is in EfiConsoleControlScreenGraphics or EfiConsoleControlScreenText mode\r
   //\r
   Private->HardwareNeedsStarting = TRUE;\r
-  Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) Index);\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
 \r
-  Private->CurrentNumberOfGraphicsOutput++;\r
+  //\r
+  // If user defined mode is not valid for UGA, set to the default mode 800x600.\r
+  //\r
+  if (EFI_ERROR(Status)) {\r
+    (Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;\r
+    (Private->GraphicsOutputModeBuffer[0]).VerticalResolution   = 600;\r
+    Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);\r
+  }\r
 \r
   return Status;\r
 }\r
 \r
-EFI_STATUS\r
-ConSplitterTextOutAddDevice (\r
-  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA     *Private,\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *TextOut,\r
-  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL       *GraphicsOutput,\r
-  IN  EFI_UGA_DRAW_PROTOCOL              *UgaDraw\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
 \r
-Arguments:\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
 \r
-Returns:\r
+  @param  Private            Consplitter Text Out pointer.\r
 \r
-  None\r
+  @return None\r
 \r
---*/\r
+**/\r
+VOID\r
+ConsplitterSetConsoleOutMode (\r
+  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private\r
+  )\r
 {\r
-  EFI_STATUS            Status;\r
-  UINTN                 CurrentNumOfConsoles;\r
-  INT32                 CurrentMode;\r
-  INT32                 MaxMode;\r
-  TEXT_OUT_AND_GOP_DATA *TextAndGop;\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
+  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
+\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
+  //\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
+      }\r
+      if (Col == 80 && Row == 25) {\r
+        BaseMode = Mode;\r
+      }\r
+    }\r
+  }\r
+\r
+  Status = TextOut->SetMode (TextOut, PreferMode);\r
+\r
+  //\r
+  // if current mode setting is failed, default 80x25 mode will be set.\r
+  //\r
+  if (EFI_ERROR(Status)) {\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
+  }\r
+\r
+  gBS->FreePool (ModeInfo);\r
+}\r
+\r
+\r
+/**\r
+  Add Text Output Device in Consplitter Text Output list.\r
+\r
+  @param  Private                  Text Out Splitter pointer.\r
+  @param  TextOut                  Simple Text Output protocol pointer.\r
+  @param  GraphicsOutput           Graphics Output protocol pointer.\r
+  @param  UgaDraw                  UGA Draw protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Text Output Device added successfully.\r
+  @retval EFI_OUT_OF_RESOURCES     Could not grow the buffer size.\r
+\r
+**/\r
+EFI_STATUS\r
+ConSplitterTextOutAddDevice (\r
+  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA     *Private,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *TextOut,\r
+  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL       *GraphicsOutput,\r
+  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
 \r
   Status                = EFI_SUCCESS;\r
   CurrentNumOfConsoles  = Private->CurrentNumberOfConsoles;\r
@@ -2179,12 +2981,12 @@ Returns:
 \r
   if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {\r
     //\r
-    // If No UGA device then use the ConOut device\r
+    // If No GOP/UGA device then use the ConOut device\r
     //\r
     TextAndGop->TextOutEnabled = TRUE;\r
   } else {\r
     //\r
-    // If UGA device use ConOut device only used if UGA screen is in Text mode\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
@@ -2211,20 +3013,61 @@ Returns:
   MaxMode     = Private->TextOutMode.MaxMode;\r
   ASSERT (MaxMode >= 1);\r
 \r
-  if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {\r
-    ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);\r
+  //\r
+  // Update DevNull mode according to current video device\r
+  //\r
+  if (FeaturePcdGet (PcdConOutGopSupport)) {\r
+    if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {\r
+      ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);\r
+    }\r
+  }\r
+  if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
+    if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+      Status = UgaDraw->GetMode (\r
+                    UgaDraw,\r
+                    &UgaHorizontalResolution,\r
+                    &UgaVerticalResolution,\r
+                    &UgaColorDepth,\r
+                    &UgaRefreshRate\r
+                    );\r
+      if (!EFI_ERROR (Status)) {\r
+        Status = ConSpliterUgaDrawSetMode (\r
+                    &Private->UgaDraw,\r
+                    UgaHorizontalResolution,\r
+                    UgaVerticalResolution,\r
+                    UgaColorDepth,\r
+                    UgaRefreshRate\r
+                    );\r
+      }\r
+      //\r
+      // If GetMode/SetMode is failed, set to 800x600 mode\r
+      //\r
+      if(EFI_ERROR (Status)) {\r
+        Status = ConSpliterUgaDrawSetMode (\r
+                    &Private->UgaDraw,\r
+                    800,\r
+                    600,\r
+                    32,\r
+                    60\r
+                    );\r
+      }\r
+    }\r
   }\r
 \r
   if (Private->ConsoleOutputMode == EfiConsoleControlScreenGraphics && GraphicsOutput != NULL) {\r
     //\r
-    // We just added a new UGA device in graphics mode\r
+    // We just added a new GOP or UGA device in graphics mode\r
     //\r
-    DevNullGopSync (Private, GraphicsOutput, UgaDraw);\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
-    DevNullSyncGopStdOut (Private);\r
+    DevNullSyncStdOut (Private);\r
   } else {\r
     //\r
     // If ConOut, then set the mode to Mode #0 which us 80 x 25\r
@@ -2232,25 +3075,31 @@ Returns:
     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
+  //\r
+  ConsplitterSetConsoleOutMode (Private);\r
+\r
   return Status;\r
 }\r
 \r
+\r
+/**\r
+  Remove Text Out Device in Consplitter Text Out list.\r
+\r
+  @param  Private                  Text Out Splitter pointer.\r
+  @param  TextOut                  Simple Text Output Pointer protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Text Out Device removed successfully.\r
+  @retval EFI_NOT_FOUND            No Text Out Device found.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterTextOutDeleteDevice (\r
   IN  TEXT_OUT_SPLITTER_PRIVATE_DATA     *Private,\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *TextOut\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
   INT32                 Index;\r
   UINTN                 CurrentNumOfConsoles;\r
@@ -2268,6 +3117,12 @@ Returns:
     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
       break;\r
     }\r
 \r
@@ -2329,30 +3184,25 @@ Returns:
 \r
   return Status;\r
 }\r
-//\r
-// ConSplitter TextIn member functions\r
-//\r
+\r
+\r
+/**\r
+  Reset the input device and optionaly run diagnostics\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  ExtendedVerification     Driver may perform diagnostics on reset.\r
+\r
+  @retval EFI_SUCCESS              The device was reset.\r
+  @retval EFI_DEVICE_ERROR         The device is not functioning properly and could\r
+                                   not be reset.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextInReset (\r
   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
   IN  BOOLEAN                         ExtendedVerification\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Reset the input device and optionaly run diagnostics\r
-\r
-  Arguments:\r
-    This                 - Protocol instance pointer.\r
-    ExtendedVerification - Driver may perform diagnostics on reset.\r
-\r
-  Returns:\r
-    EFI_SUCCESS           - The device was reset.\r
-    EFI_DEVICE_ERROR      - The device is not functioning properly and could\r
-                            not be reset.\r
-\r
---*/\r
 {\r
   EFI_STATUS                    Status;\r
   EFI_STATUS                    ReturnStatus;\r
@@ -2379,29 +3229,26 @@ ConSplitterTextInReset (
   return ReturnStatus;\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
+\r
+  @param  Private                  Protocol instance pointer.\r
+  @param  Key                      Driver may perform diagnostics on reset.\r
+\r
+  @retval EFI_SUCCESS              The keystroke information was returned.\r
+  @retval EFI_NOT_READY            There was no keystroke data availiable.\r
+  @retval EFI_DEVICE_ERROR         The keydtroke information was not returned due\r
+                                   to hardware errors.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextInPrivateReadKeyStroke (\r
   IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
   OUT EFI_INPUT_KEY                   *Key\r
   )\r
-/*++\r
-\r
-  Routine Description:\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
-\r
-  Arguments:\r
-    This   - Protocol instance pointer.\r
-    Key    - Driver may perform diagnostics on reset.\r
-\r
-  Returns:\r
-    EFI_SUCCESS       - The keystroke information was returned.\r
-    EFI_NOT_READY     - There was no keystroke data availiable.\r
-    EFI_DEVICE_ERROR  - The keydtroke information was not returned due to\r
-                        hardware errors.\r
-\r
---*/\r
 {\r
   EFI_STATUS    Status;\r
   UINTN         Index;\r
@@ -2429,49 +3276,45 @@ ConSplitterTextInPrivateReadKeyStroke (
   return EFI_NOT_READY;\r
 }\r
 \r
-BOOLEAN\r
-ConSpliterConssoleControlStdInLocked (\r
-  VOID\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
+/**\r
   Return TRUE if StdIn is locked. The ConIn device on the virtual handle is\r
   the only device locked.\r
 \r
-Arguments:\r
   NONE\r
 \r
-Returns:\r
-  TRUE  - StdIn locked\r
-  FALSE - StdIn working normally\r
+  @retval TRUE                     StdIn locked\r
+  @retval FALSE                    StdIn working normally\r
 \r
---*/\r
+**/\r
+BOOLEAN\r
+ConSpliterConssoleControlStdInLocked (\r
+  VOID\r
+  )\r
 {\r
   return mConIn.PasswordEnabled;\r
 }\r
 \r
-VOID\r
-EFIAPI\r
-ConSpliterConsoleControlLockStdInEvent (\r
-  IN  EFI_EVENT                       Event,\r
-  IN  VOID                            *Context\r
-  )\r
-/*++\r
 \r
-Routine Description:\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
-Arguments:\r
-  (Standard EFI_EVENT_NOTIFY)\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
-Returns:\r
-  None\r
+  @return None\r
 \r
---*/\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
@@ -2508,7 +3351,7 @@ Returns:
           BackSpaceString[0]  = CHAR_BACKSPACE;\r
           BackSpaceString[1]  = 0;\r
 \r
-          SpaceString[0]      = ' ';\r
+          SpaceString[0]      = L' ';\r
           SpaceString[1]      = 0;\r
 \r
           ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);\r
@@ -2535,27 +3378,26 @@ Returns:
   } while (!EFI_ERROR (Status));\r
 }\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-ConSpliterConsoleControlLockStdIn (\r
-  IN  EFI_CONSOLE_CONTROL_PROTOCOL    *This,\r
-  IN  CHAR16                          *Password\r
-  )\r
-/*++\r
 \r
-Routine Description:\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
-Arguments:\r
+  @param  This                     Console Control protocol pointer.\r
+  @param  Password                 The password input.\r
 \r
-Returns:\r
-  EFI_SUCCESS           - Lock the StdIn device\r
-  EFI_INVALID_PARAMETER - Password is NULL\r
-  EFI_OUT_OF_RESOURCES  - Buffer allocation to store the password fails\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
+**/\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
@@ -2578,30 +3420,27 @@ Returns:
   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
+\r
+  @retval EFI_SUCCESS              The keystroke information was returned.\r
+  @retval EFI_NOT_READY            There was no keystroke data availiable.\r
+  @retval EFI_DEVICE_ERROR         The keydtroke information was not returned due\r
+                                   to hardware errors.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextInReadKeyStroke (\r
   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
   OUT EFI_INPUT_KEY                   *Key\r
   )\r
-/*++\r
-\r
-  Routine Description:\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
-  Arguments:\r
-    This   - Protocol instance pointer.\r
-    Key    - Driver may perform diagnostics on reset.\r
-\r
-  Returns:\r
-    EFI_SUCCESS       - The keystroke information was returned.\r
-    EFI_NOT_READY     - There was no keystroke data availiable.\r
-    EFI_DEVICE_ERROR  - The keydtroke information was not returned due to\r
-                        hardware errors.\r
-\r
---*/\r
 {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
 \r
@@ -2618,29 +3457,26 @@ ConSplitterTextInReadKeyStroke (
   return ConSplitterTextInPrivateReadKeyStroke (Private, Key);\r
 }\r
 \r
-VOID\r
-EFIAPI\r
-ConSplitterTextInWaitForKey (\r
-  IN  EFI_EVENT                       Event,\r
-  IN  VOID                            *Context\r
-  )\r
-/*++\r
 \r
-Routine Description:\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
 \r
-Arguments:\r
-  Event   - The Event assoicated with callback.\r
-  Context - Context registered when Event was created.\r
+  @param  Event                    The Event assoicated with callback.\r
+  @param  Context                  Context registered when Event was created.\r
 \r
-Returns:\r
-  None\r
+  @return None\r
 \r
---*/\r
+**/\r
+VOID\r
+EFIAPI\r
+ConSplitterTextInWaitForKey (\r
+  IN  EFI_EVENT                       Event,\r
+  IN  VOID                            *Context\r
+  )\r
 {\r
   EFI_STATUS                    Status;\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
@@ -2673,27 +3509,436 @@ Returns:
   }\r
 }\r
 \r
+\r
+\r
+/**\r
+  Test if the key has been registered on input device.\r
+\r
+  @param  RegsiteredData           A pointer to a buffer that is filled in with the\r
+                                   keystroke state data for the key that was\r
+                                   registered.\r
+  @param  InputData                A pointer to a buffer that is filled in with the\r
+                                   keystroke state data for the key that was\r
+                                   pressed.\r
+\r
+  @retval TRUE                     Key be pressed matches a registered key.\r
+  @retval FLASE                    Match failed.\r
+\r
+**/\r
+BOOLEAN\r
+IsKeyRegistered (\r
+  IN EFI_KEY_DATA  *RegsiteredData,\r
+  IN EFI_KEY_DATA  *InputData\r
+  )\r
+{\r
+  ASSERT (RegsiteredData != NULL && InputData != NULL);\r
+\r
+  if ((RegsiteredData->Key.ScanCode    != InputData->Key.ScanCode) ||\r
+      (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.\r
+  //\r
+  if (RegsiteredData->KeyState.KeyShiftState != 0 &&\r
+      RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {\r
+    return FALSE;\r
+  }\r
+  if (RegsiteredData->KeyState.KeyToggleState != 0 &&\r
+      RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+\r
+}\r
+\r
+\r
+/**\r
+  Reset the input device and optionaly run diagnostics\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  ExtendedVerification     Driver may perform diagnostics on reset.\r
+\r
+  @retval EFI_SUCCESS              The device was reset.\r
+  @retval EFI_DEVICE_ERROR         The device is not functioning properly and could\r
+                                   not be reset.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterTextInResetEx (\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
+  IN BOOLEAN                            ExtendedVerification\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_STATUS                    ReturnStatus;\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
+  UINTN                         Index;\r
+\r
+  Private                       = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Private->KeyEventSignalState  = FALSE;\r
+\r
+  //\r
+  // return the worst status met\r
+  //\r
+  for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
+    Status = Private->TextInExList[Index]->Reset (\r
+                                             Private->TextInExList[Index],\r
+                                             ExtendedVerification\r
+                                             );\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
+    }\r
+  }\r
+\r
+  return ReturnStatus;\r
+\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
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  KeyData                  A pointer to a buffer that is filled in with the\r
+                                   keystroke state data for the key that was\r
+                                   pressed.\r
+\r
+  @retval EFI_SUCCESS              The keystroke information was returned.\r
+  @retval EFI_NOT_READY            There was no keystroke data availiable.\r
+  @retval EFI_DEVICE_ERROR         The keystroke information was not returned due\r
+                                   to hardware errors.\r
+  @retval EFI_INVALID_PARAMETER    KeyData is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterTextInReadKeyStrokeEx (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
+  OUT EFI_KEY_DATA                      *KeyData\r
+  )\r
+{\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
+  EFI_STATUS                    Status;\r
+  UINTN                         Index;\r
+  EFI_KEY_DATA                  CurrentKeyData;\r
+\r
+\r
+  if (KeyData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\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
+  KeyData->Key.UnicodeChar  = 0;\r
+  KeyData->Key.ScanCode     = SCAN_NULL;\r
+\r
+  //\r
+  // if no physical console input device exists, return EFI_NOT_READY;\r
+  // if any physical console input device has key input,\r
+  // return the key and EFI_SUCCESS.\r
+  //\r
+  for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
+    Status = Private->TextInExList[Index]->ReadKeyStrokeEx (\r
+                                          Private->TextInExList[Index],\r
+                                          &CurrentKeyData\r
+                                          );\r
+    if (!EFI_ERROR (Status)) {\r
+      CopyMem (KeyData, &CurrentKeyData, sizeof (CurrentKeyData));\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_READY;\r
+}\r
+\r
+\r
+/**\r
+  Set certain state for the input device.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  KeyToggleState           A pointer to the EFI_KEY_TOGGLE_STATE to set the\r
+                                   state for the input device.\r
+\r
+  @retval EFI_SUCCESS              The device state was set successfully.\r
+  @retval EFI_DEVICE_ERROR         The device is not functioning correctly and\r
+                                   could not have the setting adjusted.\r
+  @retval EFI_UNSUPPORTED          The device does not have the ability to set its\r
+                                   state.\r
+  @retval EFI_INVALID_PARAMETER    KeyToggleState is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterTextInSetState (\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
+  IN EFI_KEY_TOGGLE_STATE               *KeyToggleState\r
+  )\r
+{\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
+  EFI_STATUS                    Status;\r
+  UINTN                         Index;\r
+\r
+  if (KeyToggleState == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  // if no physical console input device exists, return EFI_SUCCESS;\r
+  // otherwise return the status of setting state of physical console input device\r
+  //\r
+  for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
+    Status = Private->TextInExList[Index]->SetState (\r
+                                             Private->TextInExList[Index],\r
+                                             KeyToggleState\r
+                                             );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r
+\r
+\r
+/**\r
+  Register a notification function for a particular keystroke for the input device.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  KeyData                  A pointer to a buffer that is filled in with the\r
+                                   keystroke information data for the key that was\r
+                                   pressed.\r
+  @param  KeyNotificationFunction  Points to the function to be called when the key\r
+                                   sequence is typed specified by KeyData.\r
+  @param  NotifyHandle             Points to the unique handle assigned to the\r
+                                   registered notification.\r
+\r
+  @retval EFI_SUCCESS              The notification function was registered\r
+                                   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
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterTextInRegisterKeyNotify (\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
+  IN EFI_KEY_DATA                       *KeyData,\r
+  IN EFI_KEY_NOTIFY_FUNCTION            KeyNotificationFunction,\r
+  OUT EFI_HANDLE                        *NotifyHandle\r
+  )\r
+{\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
+  EFI_STATUS                    Status;\r
+  UINTN                         Index;\r
+  TEXT_IN_EX_SPLITTER_NOTIFY    *NewNotify;\r
+  LIST_ENTRY                    *Link;\r
+  TEXT_IN_EX_SPLITTER_NOTIFY    *CurrentNotify;\r
+\r
+\r
+  if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  // if no physical console input device exists,\r
+  // return EFI_SUCCESS directly.\r
+  //\r
+  if (Private->CurrentNumberOfExConsoles <= 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.\r
+  //\r
+  for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {\r
+    CurrentNotify = CR (\r
+                      Link,\r
+                      TEXT_IN_EX_SPLITTER_NOTIFY,\r
+                      NotifyEntry,\r
+                      TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE\r
+                      );\r
+    if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {\r
+      if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {\r
+        *NotifyHandle = CurrentNotify->NotifyHandle;\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Allocate resource to save the notification function\r
+  //\r
+  NewNotify = (TEXT_IN_EX_SPLITTER_NOTIFY *) AllocateZeroPool (sizeof (TEXT_IN_EX_SPLITTER_NOTIFY));\r
+  if (NewNotify == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  NewNotify->NotifyHandleList = (EFI_HANDLE *) AllocateZeroPool (sizeof (EFI_HANDLE) * Private->CurrentNumberOfExConsoles);\r
+  if (NewNotify->NotifyHandleList == NULL) {\r
+    gBS->FreePool (NewNotify);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  NewNotify->Signature         = TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE;\r
+  NewNotify->KeyNotificationFn = KeyNotificationFunction;\r
+  CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));\r
+\r
+  //\r
+  // Return the wrong status of registering key notify of\r
+  // physical console input device if meet problems\r
+  //\r
+  for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
+    Status = Private->TextInExList[Index]->RegisterKeyNotify (\r
+                                             Private->TextInExList[Index],\r
+                                             KeyData,\r
+                                             KeyNotificationFunction,\r
+                                             &NewNotify->NotifyHandleList[Index]\r
+                                             );\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->FreePool (NewNotify->NotifyHandleList);\r
+      gBS->FreePool (NewNotify);\r
+      return Status;\r
+    }\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
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r
+\r
+\r
+/**\r
+  Remove a registered notification function from a particular keystroke.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  NotificationHandle       The handle of the notification function being\r
+                                   unregistered.\r
+\r
+  @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
+EFIAPI\r
+ConSplitterTextInUnregisterKeyNotify (\r
+  IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
+  IN EFI_HANDLE                         NotificationHandle\r
+  )\r
+{\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
+  EFI_STATUS                    Status;\r
+  UINTN                         Index;\r
+  TEXT_IN_EX_SPLITTER_NOTIFY    *CurrentNotify;\r
+  LIST_ENTRY                    *Link;\r
+\r
+  if (NotificationHandle == NULL) {\r
+    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
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  // if no physical console input device exists,\r
+  // return EFI_SUCCESS directly.\r
+  //\r
+  if (Private->CurrentNumberOfExConsoles <= 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {\r
+    CurrentNotify = CR (Link, TEXT_IN_EX_SPLITTER_NOTIFY, NotifyEntry, TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE);\r
+    if (CurrentNotify->NotifyHandle == NotificationHandle) {\r
+      for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
+        Status = Private->TextInExList[Index]->UnregisterKeyNotify (\r
+                                                 Private->TextInExList[Index],\r
+                                                 CurrentNotify->NotifyHandleList[Index]\r
+                                                 );\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\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
+      gBS->FreePool (CurrentNotify->NotifyHandleList);\r
+      gBS->FreePool (CurrentNotify);\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+\r
+}\r
+\r
+\r
+/**\r
+  Reset the input device and optionaly run diagnostics\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  ExtendedVerification     Driver may perform diagnostics on reset.\r
+\r
+  @retval EFI_SUCCESS              The device was reset.\r
+  @retval EFI_DEVICE_ERROR         The device is not functioning properly and could\r
+                                   not be reset.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterSimplePointerReset (\r
   IN  EFI_SIMPLE_POINTER_PROTOCOL     *This,\r
   IN  BOOLEAN                         ExtendedVerification\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Reset the input device and optionaly run diagnostics\r
-\r
-  Arguments:\r
-    This                 - Protocol instance pointer.\r
-    ExtendedVerification - Driver may perform diagnostics on reset.\r
-\r
-  Returns:\r
-    EFI_SUCCESS           - The device was reset.\r
-    EFI_DEVICE_ERROR      - The device is not functioning properly and could\r
-                            not be reset.\r
-\r
---*/\r
 {\r
   EFI_STATUS                    Status;\r
   EFI_STATUS                    ReturnStatus;\r
@@ -2723,30 +3968,26 @@ ConSplitterSimplePointerReset (
   return ReturnStatus;\r
 }\r
 \r
-STATIC\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
+\r
+  @param  Private                  Protocol instance pointer.\r
+  @param  State                    The state information of simple pointer device.\r
+\r
+  @retval EFI_SUCCESS              The keystroke information was returned.\r
+  @retval EFI_NOT_READY            There was no keystroke data availiable.\r
+  @retval EFI_DEVICE_ERROR         The keydtroke information was not returned due\r
+                                   to hardware errors.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterSimplePointerPrivateGetState (\r
   IN  TEXT_IN_SPLITTER_PRIVATE_DATA   *Private,\r
   IN OUT EFI_SIMPLE_POINTER_STATE     *State\r
   )\r
-/*++\r
-\r
-  Routine Description:\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
-\r
-  Arguments:\r
-    This   - Protocol instance pointer.\r
-    State  -\r
-\r
-  Returns:\r
-    EFI_SUCCESS       - The keystroke information was returned.\r
-    EFI_NOT_READY     - There was no keystroke data availiable.\r
-    EFI_DEVICE_ERROR  - The keydtroke information was not returned due to\r
-                        hardware errors.\r
-\r
---*/\r
 {\r
   EFI_STATUS                Status;\r
   EFI_STATUS                ReturnStatus;\r
@@ -2803,30 +4044,27 @@ ConSplitterSimplePointerPrivateGetState (
   return ReturnStatus;\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                     A pointer to protocol instance.\r
+  @param  State                    A pointer to state information on the pointer device\r
+\r
+  @retval EFI_SUCCESS              The keystroke information was returned in State.\r
+  @retval EFI_NOT_READY            There was no keystroke data availiable.\r
+  @retval EFI_DEVICE_ERROR         The keydtroke information was not returned due\r
+                                   to hardware errors.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterSimplePointerGetState (\r
   IN  EFI_SIMPLE_POINTER_PROTOCOL     *This,\r
   IN OUT EFI_SIMPLE_POINTER_STATE     *State\r
   )\r
-/*++\r
-\r
-  Routine Description:\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
-  Arguments:\r
-    This   - Protocol instance pointer.\r
-    State  -\r
-\r
-  Returns:\r
-    EFI_SUCCESS       - The keystroke information was returned.\r
-    EFI_NOT_READY     - There was no keystroke data availiable.\r
-    EFI_DEVICE_ERROR  - The keydtroke information was not returned due to\r
-                        hardware errors.\r
-\r
---*/\r
 {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
 \r
@@ -2843,29 +4081,26 @@ ConSplitterSimplePointerGetState (
   return ConSplitterSimplePointerPrivateGetState (Private, State);\r
 }\r
 \r
-VOID\r
-EFIAPI\r
-ConSplitterSimplePointerWaitForInput (\r
-  IN  EFI_EVENT                       Event,\r
-  IN  VOID                            *Context\r
-  )\r
-/*++\r
 \r
-Routine Description:\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
 \r
-Arguments:\r
-  Event   - The Event assoicated with callback.\r
-  Context - Context registered when Event was created.\r
+  @param  Event                    The Event assoicated with callback.\r
+  @param  Context                  Context registered when Event was created.\r
 \r
-Returns:\r
-  None\r
+  @return None\r
 \r
---*/\r
+**/\r
+VOID\r
+EFIAPI\r
+ConSplitterSimplePointerWaitForInput (\r
+  IN  EFI_EVENT                       Event,\r
+  IN  VOID                            *Context\r
+  )\r
 {\r
   EFI_STATUS                    Status;\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
@@ -2898,28 +4133,206 @@ Returns:
   }\r
 }\r
 \r
+/**\r
+  Resets the pointer device hardware.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  ExtendedVerification     Driver may perform diagnostics on reset.\r
+\r
+  @retval EFI_SUCCESS              The device was reset.\r
+  @retval EFI_DEVICE_ERROR         The device is not functioning correctly and\r
+                                   could not be reset.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
-ConSplitterTextOutReset (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
-  IN  BOOLEAN                            ExtendedVerification\r
+ConSplitterAbsolutePointerReset (\r
+  IN EFI_ABSOLUTE_POINTER_PROTOCOL   *This,\r
+  IN BOOLEAN                         ExtendedVerification\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_STATUS                    ReturnStatus;\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
+  UINTN                         Index;\r
+\r
+  Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);\r
+\r
+  Private->AbsoluteInputEventSignalState = FALSE;\r
+\r
+  if (Private->CurrentNumberOfAbsolutePointers == 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // return the worst status met\r
+  //\r
+  for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {\r
+    Status = Private->AbsolutePointerList[Index]->Reset (\r
+                                                    Private->AbsolutePointerList[Index],\r
+                                                    ExtendedVerification\r
+                                                    );\r
+    if (EFI_ERROR (Status)) {\r
+      ReturnStatus = Status;\r
+    }\r
+  }\r
+\r
+  return ReturnStatus;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves the current state of a pointer device.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  State                    A pointer to the state information on the\r
+                                   pointer device.\r
+\r
+  @retval EFI_SUCCESS              The state of the pointer device was returned in\r
+                                   State..\r
+  @retval EFI_NOT_READY            The state of the pointer device has not changed\r
+                                   since the last call to GetState().\r
+  @retval EFI_DEVICE_ERROR         A device error occurred while attempting to\r
+                                   retrieve the pointer device's current state.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterAbsolutePointerGetState (\r
+  IN EFI_ABSOLUTE_POINTER_PROTOCOL   *This,\r
+  IN OUT EFI_ABSOLUTE_POINTER_STATE  *State\r
+  )\r
+{\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
+  EFI_STATUS                    Status;\r
+  EFI_STATUS                    ReturnStatus;\r
+  UINTN                         Index;\r
+  EFI_ABSOLUTE_POINTER_STATE    CurrentState;\r
+\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
+  State->CurrentX                        = 0;\r
+  State->CurrentY                        = 0;\r
+  State->CurrentZ                        = 0;\r
+  State->ActiveButtons                   = 0;\r
+\r
+  //\r
+  // if no physical pointer device exists, return EFI_NOT_READY;\r
+  // if any physical pointer device has changed state,\r
+  // return the state and EFI_SUCCESS.\r
+  //\r
+  ReturnStatus = EFI_NOT_READY;\r
+  for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {\r
+\r
+    Status = Private->AbsolutePointerList[Index]->GetState (\r
+                                                    Private->AbsolutePointerList[Index],\r
+                                                    &CurrentState\r
+                                                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      if (ReturnStatus == EFI_NOT_READY) {\r
+        ReturnStatus = EFI_SUCCESS;\r
+      }\r
+\r
+      State->ActiveButtons = CurrentState.ActiveButtons;\r
+\r
+      if (!(Private->AbsolutePointerMode.AbsoluteMinX == 0 && Private->AbsolutePointerMode.AbsoluteMaxX == 0)) {\r
+        State->CurrentX = CurrentState.CurrentX;\r
+      }\r
+      if (!(Private->AbsolutePointerMode.AbsoluteMinY == 0 && Private->AbsolutePointerMode.AbsoluteMaxY == 0)) {\r
+        State->CurrentY = CurrentState.CurrentY;\r
+      }\r
+      if (!(Private->AbsolutePointerMode.AbsoluteMinZ == 0 && Private->AbsolutePointerMode.AbsoluteMaxZ == 0)) {\r
+        State->CurrentZ = CurrentState.CurrentZ;\r
+      }\r
+\r
+    } else if (Status == EFI_DEVICE_ERROR) {\r
+      ReturnStatus = EFI_DEVICE_ERROR;\r
+    }\r
+  }\r
+\r
+  return ReturnStatus;\r
+}\r
+\r
+\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
+\r
+  @param  Event                    The Event assoicated with callback.\r
+  @param  Context                  Context registered when Event was created.\r
+\r
+  @return None\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+ConSplitterAbsolutePointerWaitForInput (\r
+  IN  EFI_EVENT                       Event,\r
+  IN  VOID                            *Context\r
   )\r
-/*++\r
+{\r
+  EFI_STATUS                    Status;\r
+  TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
+  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
+  // and not cleared by Reset() or GetState(), signal it\r
+  //\r
+  if (Private->AbsoluteInputEventSignalState) {\r
+    gBS->SignalEvent (Event);\r
+    return ;\r
+  }\r
+  //\r
+  // if any physical console input device has key input, signal the event.\r
+  //\r
+  for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {\r
+    Status = gBS->CheckEvent (Private->AbsolutePointerList[Index]->WaitForInput);\r
+    if (!EFI_ERROR (Status)) {\r
+      gBS->SignalEvent (Event);\r
+      Private->AbsoluteInputEventSignalState = TRUE;\r
+    }\r
+  }\r
+}\r
+\r
 \r
-  Routine Description:\r
-    Reset the text output device hardware and optionaly run diagnostics\r
+/**\r
+  Reset the text output device hardware and optionaly run diagnostics\r
 \r
-  Arguments:\r
-    This                 - Protocol instance pointer.\r
-    ExtendedVerification - Driver may perform more exhaustive verfication\r
-                           operation of the device during reset.\r
+  @param  This                     Protocol instance pointer.\r
+  @param  ExtendedVerification     Driver may perform more exhaustive verfication\r
+                                   operation of the device during reset.\r
 \r
-  Returns:\r
-    EFI_SUCCESS       - The text output device was reset.\r
-    EFI_DEVICE_ERROR  - The text output device is not functioning correctly and\r
-                        could not be reset.\r
+  @retval EFI_SUCCESS              The text output device was reset.\r
+  @retval EFI_DEVICE_ERROR         The text output device is not functioning\r
+                                   correctly and could not be reset.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ConSplitterTextOutReset (\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
+  IN  BOOLEAN                            ExtendedVerification\r
+  )\r
 {\r
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
@@ -2945,7 +4358,7 @@ ConSplitterTextOutReset (
     }\r
   }\r
 \r
-  This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));\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
@@ -2955,34 +4368,32 @@ ConSplitterTextOutReset (
   return ReturnStatus;\r
 }\r
 \r
+\r
+/**\r
+  Write a Unicode string to the output device.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  WString                  The NULL-terminated Unicode string to be\r
+                                   displayed on the output device(s). All output\r
+                                   devices must also support the Unicode drawing\r
+                                   defined in this file.\r
+\r
+  @retval EFI_SUCCESS              The string was output to the device.\r
+  @retval EFI_DEVICE_ERROR         The device reported an error while attempting to\r
+                                   output the text.\r
+  @retval EFI_UNSUPPORTED          The output device's mode is not currently in a\r
+                                   defined text mode.\r
+  @retval EFI_WARN_UNKNOWN_GLYPH   This warning code indicates that some of the\r
+                                   characters in the Unicode string could not be\r
+                                   rendered and were skipped.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextOutOutputString (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
   IN  CHAR16                             *WString\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Write a Unicode string to the output device.\r
-\r
-  Arguments:\r
-    This    - Protocol instance pointer.\r
-    String  - The NULL-terminated Unicode string to be displayed on the output\r
-              device(s). All output devices must also support the Unicode\r
-              drawing defined in this file.\r
-\r
-  Returns:\r
-    EFI_SUCCESS       - The string was output to the device.\r
-    EFI_DEVICE_ERROR  - The device reported an error while attempting to output\r
-                         the text.\r
-    EFI_UNSUPPORTED        - The output device's mode is not currently in a\r
-                              defined text mode.\r
-    EFI_WARN_UNKNOWN_GLYPH - This warning code indicates that some of the\r
-                              characters in the Unicode string could not be\r
-                              rendered and were skipped.\r
-\r
---*/\r
 {\r
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
@@ -2996,7 +4407,7 @@ ConSplitterTextOutOutputString (
   Private         = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   BackSpaceCount  = 0;\r
-  for (TargetString = WString; *TargetString; TargetString++) {\r
+  for (TargetString = WString; *TargetString != L'\0'; TargetString++) {\r
     if (*TargetString == CHAR_BACKSPACE) {\r
       BackSpaceCount++;\r
     }\r
@@ -3030,37 +4441,35 @@ ConSplitterTextOutOutputString (
     }\r
   }\r
 \r
-  if (BackSpaceCount) {\r
+  if (BackSpaceCount > 0) {\r
     FreePool (TargetString);\r
   }\r
 \r
   return ReturnStatus;\r
 }\r
 \r
+\r
+/**\r
+  Verifies that all characters in a Unicode string can be output to the\r
+  target device.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  WString                  The NULL-terminated Unicode string to be\r
+                                   examined for the output device(s).\r
+\r
+  @retval EFI_SUCCESS              The device(s) are capable of rendering the\r
+                                   output string.\r
+  @retval EFI_UNSUPPORTED          Some of the characters in the Unicode string\r
+                                   cannot be rendered by one or more of the output\r
+                                   devices mapped by the EFI handle.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextOutTestString (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
   IN  CHAR16                             *WString\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Verifies that all characters in a Unicode string can be output to the\r
-    target device.\r
-\r
-  Arguments:\r
-    This    - Protocol instance pointer.\r
-    String  - The NULL-terminated Unicode string to be examined for the output\r
-               device(s).\r
-\r
-  Returns:\r
-    EFI_SUCCESS     - The device(s) are capable of rendering the output string.\r
-    EFI_UNSUPPORTED - Some of the characters in the Unicode string cannot be\r
-                       rendered by one or more of the output devices mapped\r
-                       by the EFI handle.\r
-\r
---*/\r
 {\r
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
@@ -3091,6 +4500,24 @@ ConSplitterTextOutTestString (
   return ReturnStatus;\r
 }\r
 \r
+\r
+/**\r
+  Returns information for an available text mode that the output device(s)\r
+  supports.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  ModeNumber               The mode number to return information on.\r
+  @param  Columns                  Returns the columns of the text output device\r
+                                   for the requested ModeNumber.\r
+  @param  Rows                     Returns the rows of the text output device\r
+                                   for the requested ModeNumber.\r
+\r
+  @retval EFI_SUCCESS              The requested mode information was returned.\r
+  @retval EFI_DEVICE_ERROR         The device had an error and could not complete\r
+                                   the request.\r
+  @retval EFI_UNSUPPORTED          The mode number was not valid.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextOutQueryMode (\r
@@ -3099,27 +4526,10 @@ ConSplitterTextOutQueryMode (
   OUT UINTN                              *Columns,\r
   OUT UINTN                              *Rows\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Returns information for an available text mode that the output device(s)\r
-    supports.\r
-\r
-  Arguments:\r
-    This       - Protocol instance pointer.\r
-    ModeNumber - The mode number to return information on.\r
-    Columns, Rows - Returns the geometry of the text output device for the\r
-                    requested ModeNumber.\r
-\r
-  Returns:\r
-    EFI_SUCCESS      - The requested mode information was returned.\r
-    EFI_DEVICE_ERROR - The device had an error and could not\r
-                       complete the request.\r
-    EFI_UNSUPPORTED - The mode number was not valid.\r
-\r
---*/\r
 {\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
+  UINTN                           CurrentMode;\r
+  INT32                           *TextOutModeMap;\r
 \r
   Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
 \r
@@ -3135,8 +4545,18 @@ ConSplitterTextOutQueryMode (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  *Columns  = Private->TextOutQueryData[ModeNumber].Columns;\r
-  *Rows     = Private->TextOutQueryData[ModeNumber].Rows;\r
+  //\r
+  // We get the available mode from mode intersection map if it's available\r
+  //\r
+  if (Private->TextOutModeMap != NULL) {\r
+    TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;\r
+    CurrentMode    = (UINTN)(*TextOutModeMap);\r
+    *Columns       = Private->TextOutQueryData[CurrentMode].Columns;\r
+    *Rows          = Private->TextOutQueryData[CurrentMode].Rows;\r
+  } else {\r
+    *Columns  = Private->TextOutQueryData[ModeNumber].Columns;\r
+    *Rows     = Private->TextOutQueryData[ModeNumber].Rows;\r
+  }\r
 \r
   if (*Columns <= 0 && *Rows <= 0) {\r
     return EFI_UNSUPPORTED;\r
@@ -3146,28 +4566,25 @@ ConSplitterTextOutQueryMode (
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Sets the output device(s) to a specified mode.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  ModeNumber               The mode number to set.\r
+\r
+  @retval EFI_SUCCESS              The requested text mode was set.\r
+  @retval EFI_DEVICE_ERROR         The device had an error and could not complete\r
+                                   the request.\r
+  @retval EFI_UNSUPPORTED          The mode number was not valid.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextOutSetMode (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
   IN  UINTN                              ModeNumber\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Sets the output device(s) to a specified mode.\r
-\r
-  Arguments:\r
-    This       - Protocol instance pointer.\r
-    ModeNumber - The mode number to set.\r
-\r
-  Returns:\r
-    EFI_SUCCESS      - The requested text mode was set.\r
-    EFI_DEVICE_ERROR - The device had an error and\r
-                       could not complete the request.\r
-    EFI_UNSUPPORTED - The mode number was not valid.\r
-\r
---*/\r
 {\r
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
@@ -3206,8 +4623,8 @@ ConSplitterTextOutSetMode (
                                                       TextOutModeMap[Index]\r
                                                       );\r
       //\r
-      // If this console device is based on a UGA device, then sync up the bitmap from\r
-      // the UGA splitter and reclear the text portion of the display in the new mode.\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
@@ -3229,31 +4646,30 @@ ConSplitterTextOutSetMode (
   return ReturnStatus;\r
 }\r
 \r
+\r
+/**\r
+  Sets the background and foreground colors for the OutputString () and\r
+  ClearScreen () functions.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  Attribute                The attribute to set. Bits 0..3 are the\r
+                                   foreground color, and bits 4..6 are the\r
+                                   background color. All other bits are undefined\r
+                                   and must be zero. The valid Attributes are\r
+                                   defined in this file.\r
+\r
+  @retval EFI_SUCCESS              The attribute was set.\r
+  @retval EFI_DEVICE_ERROR         The device had an error and could not complete\r
+                                   the request.\r
+  @retval EFI_UNSUPPORTED          The attribute requested is not defined.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextOutSetAttribute (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
   IN  UINTN                              Attribute\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Sets the background and foreground colors for the OutputString () and\r
-    ClearScreen () functions.\r
-\r
-  Arguments:\r
-    This      - Protocol instance pointer.\r
-    Attribute - The attribute to set. Bits 0..3 are the foreground color, and\r
-                bits 4..6 are the background color. All other bits are undefined\r
-                and must be zero. The valid Attributes are defined in this file.\r
-\r
-  Returns:\r
-    EFI_SUCCESS      - The attribute was set.\r
-    EFI_DEVICE_ERROR - The device had an error and\r
-                       could not complete the request.\r
-    EFI_UNSUPPORTED - The attribute requested is not defined.\r
-\r
---*/\r
 {\r
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
@@ -3290,27 +4706,24 @@ ConSplitterTextOutSetAttribute (
   return ReturnStatus;\r
 }\r
 \r
+\r
+/**\r
+  Clears the output device(s) display to the currently selected background\r
+  color.\r
+\r
+  @param  This                     Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS              The operation completed successfully.\r
+  @retval EFI_DEVICE_ERROR         The device had an error and could not complete\r
+                                   the request.\r
+  @retval EFI_UNSUPPORTED          The output device is not in a valid text mode.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextOutClearScreen (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Clears the output device(s) display to the currently selected background\r
-    color.\r
-\r
-  Arguments:\r
-    This      - Protocol instance pointer.\r
-\r
-  Returns:\r
-    EFI_SUCCESS      - The operation completed successfully.\r
-    EFI_DEVICE_ERROR - The device had an error and\r
-                       could not complete the request.\r
-    EFI_UNSUPPORTED - The output device is not in a valid text mode.\r
-\r
---*/\r
 {\r
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
@@ -3340,6 +4753,26 @@ ConSplitterTextOutClearScreen (
   return ReturnStatus;\r
 }\r
 \r
+\r
+/**\r
+  Sets the current coordinates of the cursor position\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  Column                   The column position to set the cursor to. Must be\r
+                                   greater than or equal to zero and less than the\r
+                                   number of columns by QueryMode ().\r
+  @param  Row                      The row position to set the cursor to. Must be\r
+                                   greater than or equal to zero and less than the\r
+                                   number of rows by QueryMode ().\r
+\r
+  @retval EFI_SUCCESS              The operation completed successfully.\r
+  @retval EFI_DEVICE_ERROR         The device had an error and could not complete\r
+                                   the request.\r
+  @retval EFI_UNSUPPORTED          The output device is not in a valid text mode,\r
+                                   or the cursor position is invalid for the\r
+                                   current mode.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextOutSetCursorPosition (\r
@@ -3347,25 +4780,6 @@ ConSplitterTextOutSetCursorPosition (
   IN  UINTN                              Column,\r
   IN  UINTN                              Row\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Sets the current coordinates of the cursor position\r
-\r
-  Arguments:\r
-    This        - Protocol instance pointer.\r
-    Column, Row - the position to set the cursor to. Must be greater than or\r
-                  equal to zero and less than the number of columns and rows\r
-                  by QueryMode ().\r
-\r
-  Returns:\r
-    EFI_SUCCESS      - The operation completed successfully.\r
-    EFI_DEVICE_ERROR - The device had an error and\r
-                       could not complete the request.\r
-    EFI_UNSUPPORTED - The output device is not in a valid text mode, or the\r
-                       cursor position is invalid for the current mode.\r
-\r
---*/\r
 {\r
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
@@ -3373,11 +4787,26 @@ ConSplitterTextOutSetCursorPosition (
   EFI_STATUS                      ReturnStatus;\r
   UINTN                           MaxColumn;\r
   UINTN                           MaxRow;\r
+  INT32                           *TextOutModeMap;\r
+  INT32                           ModeNumber;\r
+  INT32                           CurrentMode;\r
 \r
   Private   = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
+  TextOutModeMap  = NULL;\r
+  ModeNumber      = Private->TextOutMode.Mode;\r
 \r
-  MaxColumn = Private->TextOutQueryData[Private->TextOutMode.Mode].Columns;\r
-  MaxRow    = Private->TextOutQueryData[Private->TextOutMode.Mode].Rows;\r
+  //\r
+  // Get current MaxColumn and MaxRow from intersection map\r
+  //\r
+  if (Private->TextOutModeMap != NULL) {\r
+    TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;\r
+    CurrentMode    = *TextOutModeMap;\r
+  } else {\r
+    CurrentMode = ModeNumber;\r
+  }\r
+\r
+  MaxColumn = Private->TextOutQueryData[CurrentMode].Columns;\r
+  MaxRow    = Private->TextOutQueryData[CurrentMode].Rows;\r
 \r
   if (Column >= MaxColumn || Row >= MaxRow) {\r
     return EFI_UNSUPPORTED;\r
@@ -3404,30 +4833,27 @@ ConSplitterTextOutSetCursorPosition (
   return ReturnStatus;\r
 }\r
 \r
+\r
+/**\r
+  Makes the cursor visible or invisible\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  Visible                  If TRUE, the cursor is set to be visible. If\r
+                                   FALSE, the cursor is set to be invisible.\r
+\r
+  @retval EFI_SUCCESS              The operation completed successfully.\r
+  @retval EFI_DEVICE_ERROR         The device had an error and could not complete\r
+                                   the request, or the device does not support\r
+                                   changing the cursor mode.\r
+  @retval EFI_UNSUPPORTED          The output device is not in a valid text mode.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextOutEnableCursor (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
   IN  BOOLEAN                            Visible\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Makes the cursor visible or invisible\r
-\r
-  Arguments:\r
-    This    - Protocol instance pointer.\r
-    Visible - If TRUE, the cursor is set to be visible. If FALSE, the cursor is\r
-              set to be invisible.\r
-\r
-  Returns:\r
-    EFI_SUCCESS      - The operation completed successfully.\r
-    EFI_DEVICE_ERROR - The device had an error and could not complete the\r
-                        request, or the device does not support changing\r
-                        the cursor mode.\r
-    EFI_UNSUPPORTED - The output device is not in a valid text mode.\r
-\r
---*/\r
 {\r
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
@@ -3456,3 +4882,4 @@ ConSplitterTextOutEnableCursor (
 \r
   return ReturnStatus;\r
 }\r
+\r