]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
1. retried PrimaryConsoleInDeviceGuid, PrimaryConsoleOutDeviceGuid and PrimaryStandar...
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConSplitterDxe / ConSplitter.c
index a6fecb8772b7f97cc8b836381ac9e14672597910..04ea719e59b121c3f7e5b3d54c184b6e03d53de8 100644 (file)
@@ -1,6 +1,7 @@
-/**@file\r
-  Console Splitter Driver. Any Handle that attatched\r
-  EFI_CONSOLE_IDENTIFIER_PROTOCOL can be bound by this driver.\r
+/** @file\r
+  Console Splitter Driver. Any Handle that attatched console I/O protocols\r
+  (Console In device, Console Out device, Console Error device, Simple Pointer\r
+  protocol, Absolute Pointer protocol) can be bound by this driver.\r
 \r
   So far it works like any other driver by opening a SimpleTextIn and/or\r
   SimpleTextOut protocol with EFI_OPEN_PROTOCOL_BY_DRIVER attributes. The big\r
@@ -8,15 +9,14 @@
   handle, or construct a child handle like a standard device or bus driver.\r
   This driver produces three virtual handles as children, one for console input\r
   splitter, one for console output splitter and one for error output splitter.\r
-  EFI_CONSOLE_SPLIT_PROTOCOL will be attatched onto each virtual handle to\r
-  identify the splitter type.\r
+  These 3 virtual handles would be installed on gST.\r
 \r
-  Each virtual handle, that supports both the EFI_CONSOLE_SPLIT_PROTOCOL\r
-  and Console I/O protocol, will be produced in the driver entry point.\r
-  The virtual handle are added on driver entry and never removed.\r
-  Such design ensures sytem function well during none console device situation.\r
+  Each virtual handle, that supports the Console I/O protocol, will be produced\r
+  in the driver entry point. The virtual handle are added on driver entry and\r
+  never removed. Such design ensures sytem function well during none console\r
+  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
+// Text In Splitter Private Data template\r
 //\r
-STATIC TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
   (EFI_HANDLE) NULL,\r
   {\r
@@ -55,8 +55,8 @@ STATIC TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
   (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL **) NULL,\r
   0,\r
   {\r
-    (struct _LIST_ENTRY     *) NULL,\r
-    (struct _LIST_ENTRY     *) NULL\r
+    (LIST_ENTRY *) NULL,\r
+    (LIST_ENTRY *) NULL\r
   },\r
 \r
   {\r
@@ -84,13 +84,13 @@ STATIC TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
   },\r
 \r
   {\r
-    0,       //AbsoluteMinX\r
-    0,       //AbsoluteMinY\r
-    0,       //AbsoluteMinZ\r
-    0x10000, //AbsoluteMaxX\r
-    0x10000, //AbsoluteMaxY\r
-    0x10000, //AbsoluteMaxZ\r
-    0        //Attributes\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
@@ -117,20 +117,31 @@ STATIC TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
   FALSE\r
 };\r
 \r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UGA_DRAW_PROTOCOL gUgaDrawProtocolTemplate = {\r
+\r
+//\r
+// Uga Draw Protocol Private Data template\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UGA_DRAW_PROTOCOL mUgaDrawProtocolTemplate = {\r
   ConSpliterUgaDrawGetMode,\r
   ConSpliterUgaDrawSetMode,\r
   ConSpliterUgaDrawBlt\r
 };\r
 \r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_PROTOCOL gGraphicsOutputProtocolTemplate = {\r
+//\r
+// Graphics Output Protocol Private Data template\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_PROTOCOL mGraphicsOutputProtocolTemplate = {\r
   ConSpliterGraphicsOutputQueryMode,\r
   ConSpliterGraphicsOutputSetMode,\r
   ConSpliterGraphicsOutputBlt,\r
   NULL\r
 };\r
 \r
-STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {\r
+\r
+//\r
+// Text Out Splitter Private Data template\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
   (EFI_HANDLE) NULL,\r
   {\r
@@ -194,7 +205,10 @@ STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {
   (INT32 *) NULL\r
 };\r
 \r
-STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {\r
+//\r
+// Standard Error Text Out Splitter Data Template\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,\r
   (EFI_HANDLE) NULL,\r
   {\r
@@ -258,6 +272,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
@@ -267,47 +284,61 @@ EFI_DRIVER_BINDING_PROTOCOL           gConSplitterConInDriverBinding = {
   NULL\r
 };\r
 \r
-EFI_DRIVER_BINDING_PROTOCOL           gConSplitterSimplePointerDriverBinding = {\r
-  ConSplitterSimplePointerDriverBindingSupported,\r
-  ConSplitterSimplePointerDriverBindingStart,\r
-  ConSplitterSimplePointerDriverBindingStop,\r
+//\r
+// Driver binding instance for Console Out device\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL           gConSplitterConOutDriverBinding = {\r
+  ConSplitterConOutDriverBindingSupported,\r
+  ConSplitterConOutDriverBindingStart,\r
+  ConSplitterConOutDriverBindingStop,\r
   0xa,\r
   NULL,\r
   NULL\r
 };\r
 \r
 //\r
-// Driver binding instance for Absolute Pointer protocol\r
+// Driver binding instance for Standard Error device\r
 //\r
-EFI_DRIVER_BINDING_PROTOCOL           gConSplitterAbsolutePointerDriverBinding = {\r
-  ConSplitterAbsolutePointerDriverBindingSupported,\r
-  ConSplitterAbsolutePointerDriverBindingStart,\r
-  ConSplitterAbsolutePointerDriverBindingStop,\r
+EFI_DRIVER_BINDING_PROTOCOL           gConSplitterStdErrDriverBinding = {\r
+  ConSplitterStdErrDriverBindingSupported,\r
+  ConSplitterStdErrDriverBindingStart,\r
+  ConSplitterStdErrDriverBindingStop,\r
   0xa,\r
   NULL,\r
   NULL\r
 };\r
 \r
-EFI_DRIVER_BINDING_PROTOCOL           gConSplitterConOutDriverBinding = {\r
-  ConSplitterConOutDriverBindingSupported,\r
-  ConSplitterConOutDriverBindingStart,\r
-  ConSplitterConOutDriverBindingStop,\r
+//\r
+// Driver binding instance for Simple Pointer protocol\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL           gConSplitterSimplePointerDriverBinding = {\r
+  ConSplitterSimplePointerDriverBindingSupported,\r
+  ConSplitterSimplePointerDriverBindingStart,\r
+  ConSplitterSimplePointerDriverBindingStop,\r
   0xa,\r
   NULL,\r
   NULL\r
 };\r
 \r
-EFI_DRIVER_BINDING_PROTOCOL           gConSplitterStdErrDriverBinding = {\r
-  ConSplitterStdErrDriverBindingSupported,\r
-  ConSplitterStdErrDriverBindingStart,\r
-  ConSplitterStdErrDriverBindingStop,\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
-  The user Entry Point for module ConSplitter. The user code starts with this function.\r
+  The Entry Point for module ConSplitter. The user code starts with this function.\r
+\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
@@ -318,7 +349,7 @@ EFI_DRIVER_BINDING_PROTOCOL           gConSplitterStdErrDriverBinding = {
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-InitializeConSplitter(\r
+ConSplitterDriverEntry(\r
   IN EFI_HANDLE           ImageHandle,\r
   IN EFI_SYSTEM_TABLE     *SystemTable\r
   )\r
@@ -378,40 +409,12 @@ InitializeConSplitter(
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-\r
   //\r
-  // Call the original Entry Point\r
+  // Either Graphics Output protocol or UGA Draw protocol must be supported.\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
   //\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
@@ -426,8 +429,6 @@ Returns:
                     &mStdErr.VirtualHandle,\r
                     &gEfiSimpleTextOutProtocolGuid,\r
                     &mStdErr.TextOut,\r
-                    &gEfiPrimaryStandardErrorDeviceGuid,\r
-                    NULL,\r
                     NULL\r
                     );\r
   }\r
@@ -446,13 +447,12 @@ Returns:
                     &mConIn.SimplePointer,\r
                     &gEfiAbsolutePointerProtocolGuid,\r
                     &mConIn.AbsolutePointer,\r
-                    &gEfiPrimaryConsoleInDeviceGuid,\r
-                    NULL,\r
                     NULL\r
                     );\r
     if (!EFI_ERROR (Status)) {\r
       //\r
       // Update the EFI System Table with new virtual console\r
+      // and update the pointer to Simple Text Input protocol.\r
       //\r
       gST->ConsoleInHandle  = mConIn.VirtualHandle;\r
       gST->ConIn            = &mConIn.TextIn;\r
@@ -465,7 +465,8 @@ Returns:
   if (!EFI_ERROR (Status)) {\r
     if (!FeaturePcdGet (PcdConOutGopSupport)) {\r
       //\r
-      // In EFI mode, UGA Draw protocol is installed\r
+      // If Graphics Outpurt protocol not supported, UGA Draw protocol is installed\r
+      // on the virtual handle.\r
       //\r
       Status = gBS->InstallMultipleProtocolInterfaces (\r
                       &mConOut.VirtualHandle,\r
@@ -475,13 +476,12 @@ Returns:
                       &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
+      // If UGA Draw protocol not supported, Graphics Output Protocol is installed\r
+      // on virtual handle.\r
       //\r
       Status = gBS->InstallMultipleProtocolInterfaces (\r
                       &mConOut.VirtualHandle,\r
@@ -491,14 +491,12 @@ Returns:
                       &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
+      // Boot Graphics Output protocol and UGA Draw protocol are supported,\r
+      // both they will be installed on virtual handle.\r
       //\r
       Status = gBS->InstallMultipleProtocolInterfaces (\r
                       &mConOut.VirtualHandle,\r
@@ -510,8 +508,6 @@ Returns:
                       &mConOut.UgaDraw,\r
                       &gEfiConsoleControlProtocolGuid,\r
                       &mConOut.ConsoleControl,\r
-                      &gEfiPrimaryConsoleOutDeviceGuid,\r
-                      NULL,\r
                       NULL\r
                       );\r
     }\r
@@ -519,6 +515,7 @@ Returns:
     if (!EFI_ERROR (Status)) {\r
       //\r
       // Update the EFI System Table with new virtual console\r
+      // and Update the pointer to Text Output protocol.\r
       //\r
       gST->ConsoleOutHandle = mConOut.VirtualHandle;\r
       gST->ConOut           = &mConOut.TextOut;\r
@@ -536,31 +533,29 @@ Returns:
         );\r
 \r
   return EFI_SUCCESS;\r
+\r
 }\r
 \r
+/**\r
+  Construct console input devices' private data.\r
+\r
+  @param  ConInPrivate             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
+  @retval other                    Failed to construct private data.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterTextInConstructor (\r
   TEXT_IN_SPLITTER_PRIVATE_DATA       *ConInPrivate\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Construct the ConSplitter.\r
-\r
-Arguments:\r
-\r
-  ConInPrivate    - A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA structure.\r
-\r
-Returns:\r
-  EFI_OUT_OF_RESOURCES - Out of resources.\r
-\r
---*/\r
 {\r
   EFI_STATUS  Status;\r
 \r
   //\r
-  // Initilize console input splitter's private data.\r
+  // Allocate buffer for Simple Text Input device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),\r
@@ -581,7 +576,9 @@ Returns:
                   &ConInPrivate->LockEvent\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-\r
+  //\r
+  // Create Event to wait for a key\r
+  //\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
                   TPL_NOTIFY,\r
@@ -592,7 +589,7 @@ Returns:
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Buffer for Simple Text Input Ex Protocol\r
+  // Allocate buffer for Simple Text Input Ex device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
              sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),\r
@@ -602,7 +599,9 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-\r
+  //\r
+  // Create Event to wait for a key Ex\r
+  //\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
                   TPL_NOTIFY,\r
@@ -614,11 +613,10 @@ Returns:
 \r
   InitializeListHead (&ConInPrivate->NotifyList);\r
 \r
+  ConInPrivate->AbsolutePointer.Mode = &ConInPrivate->AbsolutePointerMode;\r
   //\r
-  // Allocate Buffer and Create Event for Absolute Pointer and Simple Pointer Protocols\r
+  // Allocate buffer for Absolute Pointer device\r
   //\r
-  ConInPrivate->AbsolutePointer.Mode = &ConInPrivate->AbsolutePointerMode;\r
-\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),\r
             &ConInPrivate->AbsolutePointerListCount,\r
@@ -627,7 +625,9 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-\r
+  //\r
+  // Create Event to wait for device input for Absolute pointer device\r
+  //\r
   Status = gBS->CreateEvent (\r
             EVT_NOTIFY_WAIT,\r
             TPL_NOTIFY,\r
@@ -638,7 +638,9 @@ Returns:
   ASSERT_EFI_ERROR (Status);\r
 \r
   ConInPrivate->SimplePointer.Mode = &ConInPrivate->SimplePointerMode;\r
-\r
+  //\r
+  // Allocate buffer for Simple Pointer device\r
+  //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),\r
             &ConInPrivate->PointerListCount,\r
@@ -647,7 +649,9 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-\r
+  //\r
+  // Create Event to wait for device input for Simple pointer device\r
+  //\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
                   TPL_NOTIFY,\r
@@ -659,6 +663,16 @@ Returns:
   return Status;\r
 }\r
 \r
+/**\r
+  Construct console output devices' private data.\r
+\r
+  @param  ConOutPrivate            A pointer to the TEXT_OUT_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
@@ -671,11 +685,10 @@ ConSplitterTextOutConstructor (
   // Copy protocols template\r
   //\r
   if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
-    CopyMem (&ConOutPrivate->UgaDraw, &gUgaDrawProtocolTemplate, sizeof (EFI_UGA_DRAW_PROTOCOL));\r
+    CopyMem (&ConOutPrivate->UgaDraw, &mUgaDrawProtocolTemplate, sizeof (EFI_UGA_DRAW_PROTOCOL));\r
   }\r
-\r
   if (FeaturePcdGet (PcdConOutGopSupport)) {\r
-    CopyMem (&ConOutPrivate->GraphicsOutput, &gGraphicsOutputProtocolTemplate, sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL));\r
+    CopyMem (&ConOutPrivate->GraphicsOutput, &mGraphicsOutputProtocolTemplate, sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL));\r
   }\r
 \r
   //\r
@@ -688,7 +701,9 @@ ConSplitterTextOutConstructor (
   // so put current mode back to init state.\r
   //\r
   ConOutPrivate->TextOutMode.Mode = 0xFF;\r
-\r
+  //\r
+  // Allocate buffer for Console Out device\r
+  //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (TEXT_OUT_AND_GOP_DATA),\r
             &ConOutPrivate->TextOutListCount,\r
@@ -697,7 +712,9 @@ ConSplitterTextOutConstructor (
   if (EFI_ERROR (Status)) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-\r
+  //\r
+  // Allocate buffer for Text Out query data\r
+  //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),\r
             &ConOutPrivate->TextOutQueryDataCount,\r
@@ -706,6 +723,7 @@ ConSplitterTextOutConstructor (
   if (EFI_ERROR (Status)) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+\r
   //\r
   // Setup the DevNullTextOut console to 80 x 25\r
   //\r
@@ -715,7 +733,7 @@ ConSplitterTextOutConstructor (
 \r
   if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
     //\r
-    // Setup the DevNullUgaDraw to 800 x 600 x 32 bits per pixel\r
+    // Setup the DevNullUgaDraw to 800 x 600 x 32 bits per pixel, 60Hz.\r
     //\r
     ConSpliterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);\r
   }\r
@@ -754,38 +772,34 @@ ConSplitterTextOutConstructor (
 \r
     ConOutPrivate->GraphicsOutput.Mode->MaxMode = 1;\r
     //\r
-    // Initial current mode to unknow state, and then set to mode 0\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 specified device.\r
+\r
+  @param  This                Driver Binding protocol pointer.\r
+  @param  ControllerHandle    Handle of device to test.\r
+  @param  Guid                The specified protocol.\r
+\r
+  @retval EFI_SUCCESS         The specified protocol is supported on this device.\r
+  @retval EFI_UNSUPPORTED     The specified protocol attempts to be installed on virtul handle.\r
+  @retval other               Failed to open specified protocol 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
@@ -793,19 +807,15 @@ Returns:
   //\r
   // Make sure the Console Splitter does not attempt to attach to itself\r
   //\r
-  if (ControllerHandle == mConIn.VirtualHandle) {\r
+  if (ControllerHandle == mConIn.VirtualHandle  ||\r
+      ControllerHandle == mConOut.VirtualHandle ||\r
+      ControllerHandle == mStdErr.VirtualHandle\r
+      ) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  if (ControllerHandle == mConOut.VirtualHandle) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  if (ControllerHandle == mStdErr.VirtualHandle) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
   //\r
-  // Check to see whether the handle has the ConsoleInDevice GUID on it\r
+  // Check to see whether the specific protocol could be opened BY_DRIVER\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -830,6 +840,18 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Test to see if Console In Device could be supported on the Controller.\r
+\r
+  @param  This                Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test.\r
+  @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
@@ -837,21 +859,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
@@ -860,6 +867,18 @@ Returns:
           );\r
 }\r
 \r
+/**\r
+  Test to see if Simple Pointer protocol could be supported on the Controller.\r
+\r
+  @param  This                Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test.\r
+  @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
@@ -867,21 +886,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
@@ -890,6 +894,18 @@ Returns:
           );\r
 }\r
 \r
+/**\r
+  Test to see if Absolute Pointer protocol could be supported on the Controller.\r
+\r
+  @param  This                Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test.\r
+  @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
 ConSplitterAbsolutePointerDriverBindingSupported (\r
@@ -897,21 +913,6 @@ ConSplitterAbsolutePointerDriverBindingSupported (
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-  Absolute Pointer 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
@@ -920,6 +921,19 @@ Returns:
           );\r
 }\r
 \r
+\r
+/**\r
+  Test to see if Console Out Device could be supported on the Controller.\r
+\r
+  @param  This                Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test.\r
+  @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
@@ -927,21 +941,6 @@ ConSplitterConOutDriverBindingSupported (
   IN  EFI_HANDLE                      ControllerHandle,\r
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\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
-Returns:\r
-\r
-  EFI_STATUS\r
-\r
---*/\r
 {\r
   return ConSplitterSupported (\r
           This,\r
@@ -950,6 +949,18 @@ Returns:
           );\r
 }\r
 \r
+/**\r
+  Test to see if Standard Error Device could be supported on the Controller.\r
+\r
+  @param  This                Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test.\r
+  @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
@@ -957,21 +968,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
@@ -980,36 +976,39 @@ Returns:
           );\r
 }\r
 \r
-STATIC\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                      Driver Binding 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
-EFIAPI\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 DeviceGuid on it.\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -1023,6 +1022,9 @@ Returns:
     return Status;\r
   }\r
 \r
+  //\r
+  // Create virtual handle and open DeviceGuid on the virtul handle.\r
+  //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
                   DeviceGuid,\r
@@ -1032,10 +1034,13 @@ Returns:
                   EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Err;\r
   }\r
 \r
-  return gBS->OpenProtocol (\r
+  //\r
+  // Open InterfaceGuid on the virtul handle.\r
+  //\r
+  Status =  gBS->OpenProtocol (\r
                 ControllerHandle,\r
                 InterfaceGuid,\r
                 Interface,\r
@@ -1043,8 +1048,48 @@ Returns:
                 ConSplitterVirtualHandle,\r
                 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                 );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // close the DeviceGuid on ConSplitter VirtualHandle.\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        DeviceGuid,\r
+        This->DriverBindingHandle,\r
+        ConSplitterVirtualHandle\r
+        );\r
+\r
+Err:\r
+  //\r
+  // close the DeviceGuid on ControllerHandle.\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        DeviceGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return Status;\r
 }\r
 \r
+\r
+/**\r
+  Start Console In Consplitter on device handle.\r
+\r
+  @param  This                 Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to.\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               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
@@ -1052,27 +1097,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_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx;\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
@@ -1090,6 +1118,9 @@ Returns:
     return Status;\r
   }\r
 \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
@@ -1103,15 +1134,30 @@ Returns:
                   mConIn.VirtualHandle,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\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
-  Status = ConSplitterTextInExAddDevice (&mConIn, TextInEx);\r
-\r
   return Status;\r
 }\r
 \r
+\r
+/**\r
+  Start Simple Pointer Consplitter on device handle.\r
+\r
+  @param  This                 Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to.\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               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
@@ -1119,26 +1165,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
@@ -1151,9 +1185,25 @@ 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                 Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to.\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               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
 ConSplitterAbsolutePointerDriverBindingStart (\r
@@ -1161,26 +1211,14 @@ ConSplitterAbsolutePointerDriverBindingStart (
   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 ConIn 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 AbsolutePointer protocol is not started.\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
@@ -1194,9 +1232,25 @@ Returns:
     return Status;\r
   }\r
 \r
+  //\r
+  // Add this devcie into Absolute Pointer devices list.\r
+  //\r
   return ConSplitterAbsolutePointerAddDevice (&mConIn, AbsolutePointer);\r
 }\r
 \r
+\r
+/**\r
+  Start Console Out Consplitter on device handle.\r
+\r
+  @param  This                 Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to.\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               device to start.\r
+\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
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterConOutDriverBindingStart (\r
@@ -1204,27 +1258,18 @@ ConSplitterConOutDriverBindingStart (
   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
-  EFI_GRAPHICS_OUTPUT_PROTOCOL     *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL            *UgaDraw;\r
+  EFI_STATUS                           Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL      *TextOut;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL         *GraphicsOutput;\r
+  EFI_UGA_DRAW_PROTOCOL                *UgaDraw;\r
+  UINTN                                SizeOfInfo;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
 \r
+  //\r
+  // Start ConSplitter on ControllerHandle, and create the virtual\r
+  // agrogated console device on first call Start for a ConsoleOut handle.\r
+  //\r
   Status = ConSplitterStart (\r
             This,\r
             ControllerHandle,\r
@@ -1253,16 +1298,16 @@ Returns:
 \r
   if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
-    // Open UGA_DRAW protocol\r
+    // Open UGA DRAW protocol\r
     //\r
-    Status = gBS->OpenProtocol (\r
-                    ControllerHandle,\r
-                    &gEfiUgaDrawProtocolGuid,\r
-                    (VOID **) &UgaDraw,\r
-                    This->DriverBindingHandle,\r
-                    mConOut.VirtualHandle,\r
-                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                    );\r
+    gBS->OpenProtocol (\r
+           ControllerHandle,\r
+           &gEfiUgaDrawProtocolGuid,\r
+           (VOID **) &UgaDraw,\r
+           This->DriverBindingHandle,\r
+           mConOut.VirtualHandle,\r
+           EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+           );\r
   }\r
 \r
   //\r
@@ -1278,12 +1323,26 @@ 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
+  if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
     //\r
-    // Match the UGA mode data of ConOut with the current mode\r
+    // Get the UGA mode data of ConOut from the current mode\r
     //\r
-    if (UgaDraw != NULL) {\r
-      UgaDraw->GetMode (\r
+    if (GraphicsOutput != NULL) {\r
+      Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+      ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
+\r
+      mConOut.UgaHorizontalResolution = Info->HorizontalResolution;\r
+      mConOut.UgaVerticalResolution   = Info->VerticalResolution;\r
+      mConOut.UgaColorDepth           = 32;\r
+      mConOut.UgaRefreshRate          = 60;\r
+\r
+      FreePool (Info);\r
+\r
+    } else if (UgaDraw != NULL  && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+      Status = UgaDraw->GetMode (\r
                  UgaDraw,\r
                  &mConOut.UgaHorizontalResolution,\r
                  &mConOut.UgaVerticalResolution,\r
@@ -1292,9 +1351,23 @@ Returns:
                  );\r
     }\r
   }\r
+\r
   return Status;\r
 }\r
 \r
+\r
+/**\r
+  Start Standard Error Consplitter on device handle.\r
+\r
+  @param  This                 Driver Binding protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to.\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               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
@@ -1302,25 +1375,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
@@ -1366,9 +1428,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
@@ -1377,18 +1454,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
@@ -1412,6 +1477,7 @@ Returns:
         This->DriverBindingHandle,\r
         ConSplitterVirtualHandle\r
         );\r
+\r
   gBS->CloseProtocol (\r
         ControllerHandle,\r
         DeviceGuid,\r
@@ -1422,6 +1488,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              Driver Binding 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
@@ -1430,23 +1510,11 @@ 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
-\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
@@ -1459,16 +1527,20 @@ Returns:
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = ConSplitterTextInExDeleteDevice (&mConIn, TextInEx);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\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
+  //\r
+  // Close Simple Text In protocol on controller handle and virtual handle.\r
+  //\r
   Status = ConSplitterStop (\r
             This,\r
             ControllerHandle,\r
@@ -1480,12 +1552,28 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
   //\r
-  // Delete this console input device's data structures.\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              Driver Binding 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
@@ -1494,18 +1582,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
@@ -1514,6 +1590,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
@@ -1525,12 +1604,28 @@ 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              Driver Binding 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
 ConSplitterAbsolutePointerDriverBindingStop (\r
@@ -1539,18 +1634,6 @@ ConSplitterAbsolutePointerDriverBindingStop (
   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_ABSOLUTE_POINTER_PROTOCOL     *AbsolutePointer;\r
@@ -1559,6 +1642,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
@@ -1570,12 +1656,27 @@ 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 Absolute Pointer device list.\r
   //\r
   return ConSplitterAbsolutePointerDeleteDevice (&mConIn, AbsolutePointer);\r
 }\r
 \r
+\r
+/**\r
+  Stop Console Out ConSplitter on device handle by closing Console Out Devcice GUID.\r
+\r
+  @param  This              Driver Binding 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
@@ -1584,18 +1685,6 @@ ConSplitterConOutDriverBindingStop (
   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_OUTPUT_PROTOCOL  *TextOut;\r
@@ -1604,6 +1693,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
@@ -1617,11 +1709,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              Driver Binding 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
@@ -1630,18 +1736,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
@@ -1650,6 +1744,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
@@ -1686,36 +1783,29 @@ 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
-\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
+ConSplitterGrowBuffer (\r
+  IN  UINTN                           SizeOfCount,\r
+  IN  UINTN                           *Count,\r
+  IN OUT  VOID                        **Buffer\r
+  )\r
 {\r
-  UINTN NewSize;\r
-  UINTN OldSize;\r
   VOID  *Ptr;\r
 \r
   //\r
@@ -1723,48 +1813,40 @@ Returns:
   // copy the old buffer's content to the new-size buffer,\r
   // then free the old buffer.\r
   //\r
-  OldSize = *Count * SizeOfCount;\r
   *Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;\r
-  NewSize = *Count * SizeOfCount;\r
-\r
-  Ptr     = AllocateZeroPool (NewSize);\r
+  Ptr = ReallocatePool (\r
+          SizeOfCount * ((*Count) - CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT),\r
+          SizeOfCount * (*Count),\r
+          *Buffer\r
+          );\r
   if (Ptr == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+  *Buffer = Ptr;\r
+  return EFI_SUCCESS;\r
+}\r
 \r
-  CopyMem (Ptr, *Buffer, OldSize);\r
 \r
-  if (*Buffer != NULL) {\r
-    FreePool (*Buffer);\r
-  }\r
+/**\r
+  Add Text Input Device in Consplitter Text Input list.\r
 \r
-  *Buffer = Ptr;\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  TextIn                   Simple Text Input protocol pointer.\r
 \r
-  return EFI_SUCCESS;\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
   //\r
-  // If the Text In List is full, enlarge it by calling growbuffer().\r
+  // If the Text In List is full, enlarge it by calling ConSplitterGrowBuffer().\r
   //\r
   if (Private->CurrentNumberOfConsoles >= Private->TextInListCount) {\r
     Status = ConSplitterGrowBuffer (\r
@@ -1783,30 +1865,29 @@ Returns:
   Private->CurrentNumberOfConsoles++;\r
 \r
   //\r
-  // Extra CheckEvent added to reduce the double CheckEvent() in UI.c\r
+  // Extra CheckEvent added to reduce the double CheckEvent().\r
   //\r
   gBS->CheckEvent (TextIn->WaitForKey);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Remove Text Input Device from Consplitter Text Input 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
@@ -1827,6 +1908,16 @@ 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 Input 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
 ConSplitterTextInExAddDevice (\r
   IN  TEXT_IN_SPLITTER_PRIVATE_DATA         *Private,\r
@@ -1836,7 +1927,7 @@ ConSplitterTextInExAddDevice (
   EFI_STATUS  Status;\r
 \r
   //\r
-  // If the TextInEx List is full, enlarge it by calling growbuffer().\r
+  // If the Text Input Ex List is full, enlarge it by calling ConSplitterGrowBuffer().\r
   //\r
   if (Private->CurrentNumberOfExConsoles >= Private->TextInExListCount) {\r
     Status = ConSplitterGrowBuffer (\r
@@ -1849,19 +1940,29 @@ ConSplitterTextInExAddDevice (
     }\r
   }\r
   //\r
-  // Add the new text-in device data structure into the Text In List.\r
+  // Add the new text-in device data structure into the Text Input Ex 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
+  // Extra CheckEvent added to reduce the double CheckEvent().\r
   //\r
   gBS->CheckEvent (TextInEx->WaitForKeyEx);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Remove Text Ex Device from Consplitter Text Input Ex list.\r
+\r
+  @param  Private                  Text In Splitter pointer.\r
+  @param  TextInEx                 Simple Text Ex protocol pointer.\r
+\r
+  @retval EFI_SUCCESS              Simple Text Input Ex Device removed successfully.\r
+  @retval EFI_NOT_FOUND            No Simple Text Input Ex Device found.\r
+\r
+**/\r
 EFI_STATUS\r
 ConSplitterTextInExDeleteDevice (\r
   IN  TEXT_IN_SPLITTER_PRIVATE_DATA         *Private,\r
@@ -1870,7 +1971,7 @@ ConSplitterTextInExDeleteDevice (
 {\r
   UINTN Index;\r
   //\r
-  // Remove the specified text-in device data structure from the Text In List,\r
+  // Remove the specified text-in device data structure from the Text Input Ex List,\r
   // and rearrange the remaining data structures in the Text In List.\r
   //\r
   for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
@@ -1887,28 +1988,27 @@ ConSplitterTextInExDeleteDevice (
   return EFI_NOT_FOUND;\r
 }\r
 \r
+\r
+/**\r
+  Add Simple Pointer Device in Consplitter Simple 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 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
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  EFI_OUT_OF_RESOURCES\r
-  EFI_SUCCESS\r
-\r
---*/\r
 {\r
   EFI_STATUS  Status;\r
 \r
   //\r
-  // If the Text In List is full, enlarge it by calling growbuffer().\r
+  // If the Simple Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().\r
   //\r
   if (Private->CurrentNumberOfPointers >= Private->PointerListCount) {\r
     Status = ConSplitterGrowBuffer (\r
@@ -1921,33 +2021,34 @@ Returns:
     }\r
   }\r
   //\r
-  // Add the new text-in device data structure into the Text In List.\r
+  // Add the new text-in device data structure into the Simple Pointer List.\r
   //\r
   Private->PointerList[Private->CurrentNumberOfPointers] = SimplePointer;\r
   Private->CurrentNumberOfPointers++;\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Remove Simple Pointer Device from Consplitter Simple 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
-  // Remove the specified text-in device data structure from the Text In List,\r
+  // Remove the specified text-in device data structure from the Simple Pointer List,\r
   // and rearrange the remaining data structures in the Text In List.\r
   //\r
   for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {\r
@@ -1964,28 +2065,27 @@ Returns:
   return EFI_NOT_FOUND;\r
 }\r
 \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
 ConSplitterAbsolutePointerAddDevice (\r
   IN  TEXT_IN_SPLITTER_PRIVATE_DATA     *Private,\r
   IN  EFI_ABSOLUTE_POINTER_PROTOCOL     *AbsolutePointer\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  EFI_OUT_OF_RESOURCES\r
-  EFI_SUCCESS\r
-\r
---*/\r
 {\r
   EFI_STATUS  Status;\r
 \r
   //\r
-  // If the Absolute Pointer List is full, enlarge it by calling growbuffer().\r
+  // If the Absolute Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().\r
   //\r
   if (Private->CurrentNumberOfAbsolutePointers >= Private->AbsolutePointerListCount) {\r
     Status = ConSplitterGrowBuffer (\r
@@ -1998,34 +2098,35 @@ Returns:
     }\r
   }\r
   //\r
-  // Add the new text-in device data structure into the Text In List.\r
+  // Add the new text-in device data structure into the Absolute Pointer List.\r
   //\r
   Private->AbsolutePointerList[Private->CurrentNumberOfAbsolutePointers] = AbsolutePointer;\r
   Private->CurrentNumberOfAbsolutePointers++;\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Remove Absolute Pointer Device from 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
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
-  None\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
+  // Remove the specified text-in device data structure from the Absolute Pointer List,\r
+  // and rearrange the remaining data structures from the Absolute Pointer List.\r
   //\r
   for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {\r
     if (Private->AbsolutePointerList[Index] == AbsolutePointer) {\r
@@ -2041,22 +2142,21 @@ Returns:
   return EFI_NOT_FOUND;\r
 }\r
 \r
-STATIC\r
-EFI_STATUS\r
-ConSplitterGrowMapTable (\r
-  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
+  Reallocate Text Out mode map.\r
 \r
-Arguments:\r
+  Allocate new buffer and copy original buffer into the new buffer.\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
@@ -2068,9 +2168,12 @@ Returns:
 \r
   NewSize           = Private->TextOutListCount * sizeof (INT32);\r
   OldTextOutModeMap = Private->TextOutModeMap;\r
-  TotalSize         = NewSize * Private->TextOutQueryDataCount;\r
+  TotalSize         = NewSize * (Private->TextOutQueryDataCount);\r
 \r
-  TextOutModeMap    = AllocateZeroPool (TotalSize);\r
+  //\r
+  // Allocate new buffer for Text Out List.\r
+  //\r
+  TextOutModeMap    = AllocatePool (TotalSize);\r
   if (TextOutModeMap == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -2118,23 +2221,22 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Add new 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
@@ -2195,37 +2297,35 @@ Returns:
 }\r
 \r
 /**\r
-  Reconstruct TextOutModeMap to get intersection of modes\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
-  @parm TextOutModeMap  Current text out mode map, begin with the mode 80x25\r
-  @parm NewlyAddedMap   New text out mode map, begin with the mode 80x25\r
-  @parm MapStepSize     Mode step size for one console device\r
-  @parm NewMapStepSize  Mode step size for one console device\r
-  @parm MaxMode         Current max text mode\r
-  @parm CurrentMode     Current text mode\r
-\r
-  @retval None\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  New Mode step size for one console device\r
+  @param MaxMode         IN: Current max text mode, OUT: Updated max text mode.\r
+  @param CurrentMode     IN: Current text mode,     OUT: Updated current text mode.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 ConSplitterGetIntersection (\r
-  IN  INT32                           *TextOutModeMap,\r
-  IN  INT32                           *NewlyAddedMap,\r
-  IN  UINTN                           MapStepSize,\r
-  IN  UINTN                           NewMapStepSize,\r
-  OUT INT32                           *MaxMode,\r
-  OUT INT32                           *CurrentMode\r
+  IN     INT32                        *TextOutModeMap,\r
+  IN     INT32                        *NewlyAddedMap,\r
+  IN     UINTN                        MapStepSize,\r
+  IN     UINTN                        NewMapStepSize,\r
+  IN OUT INT32                        *MaxMode,\r
+  IN OUT INT32                        *CurrentMode\r
   )\r
 {\r
   INT32 Index;\r
   INT32 *CurrentMapEntry;\r
   INT32 *NextMapEntry;\r
+  INT32 *NewMapEntry;\r
   INT32 CurrentMaxMode;\r
   INT32 Mode;\r
 \r
@@ -2236,14 +2336,14 @@ ConSplitterGetIntersection (
   //\r
   Index           = 2;\r
   CurrentMapEntry = &TextOutModeMap[MapStepSize * 2];\r
-  NextMapEntry    = &TextOutModeMap[MapStepSize * 2];\r
-  NewlyAddedMap   = &NewlyAddedMap[NewMapStepSize * 2];\r
+  NextMapEntry    = CurrentMapEntry;\r
+  NewMapEntry     = &NewlyAddedMap[NewMapStepSize * 2];\r
 \r
   CurrentMaxMode  = *MaxMode;\r
   Mode            = *CurrentMode;\r
 \r
   while (Index < CurrentMaxMode) {\r
-    if (*NewlyAddedMap == -1) {\r
+    if (*NewMapEntry == -1) {\r
       //\r
       // This mode is not supported any more. Remove it. Special care\r
       // must be taken as this remove will also affect current mode;\r
@@ -2263,7 +2363,7 @@ ConSplitterGetIntersection (
     }\r
 \r
     CurrentMapEntry += MapStepSize;\r
-    NewlyAddedMap += NewMapStepSize;\r
+    NewMapEntry     += NewMapStepSize;\r
     Index++;\r
   }\r
 \r
@@ -2272,24 +2372,18 @@ ConSplitterGetIntersection (
   return ;\r
 }\r
 \r
-STATIC\r
+/**\r
+  Sync the device's output mode to console splitter's mode list.\r
+\r
+  @param  Private               Text Out Splitter pointer.\r
+  @param  TextOut               Simple Text Output protocol pointer.\r
+\r
+**/\r
 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
@@ -2318,8 +2412,13 @@ Returns:
   MapTable  = TextOutModeMap + Private->CurrentNumberOfConsoles;\r
   while (Mode < TextOut->Mode->MaxMode) {\r
     Status = TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);\r
+\r
     if (EFI_ERROR(Status)) {\r
       if (Mode == 1) {\r
+        //\r
+        // If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData\r
+        // is clear to 0x0.\r
+        //\r
         MapTable[StepSize] = Mode;\r
         TextOutQueryData[Mode].Columns = 0;\r
         TextOutQueryData[Mode].Rows = 0;\r
@@ -2337,10 +2436,8 @@ Returns:
         MapTable[Index * StepSize] = Mode;\r
         break;\r
       }\r
-\r
       Index++;\r
     }\r
-\r
     Mode++;\r
   }\r
   //\r
@@ -2359,23 +2456,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
-  EFI_SUCCESS\r
-  EFI_OUT_OF_RESOURCES\r
-\r
---*/\r
 {\r
   UINTN                         ConOutNumOfConsoles;\r
   UINTN                         StdErrNumOfConsoles;\r
@@ -2503,6 +2595,7 @@ Returns:
     &(mConOut.TextOutMode.MaxMode),\r
     &(mConOut.TextOutMode.Mode)\r
     );\r
+\r
   if (mConOut.TextOutMode.Mode < 0) {\r
     mConOut.TextOut.SetMode (&(mConOut.TextOut), 0);\r
   }\r
@@ -2515,6 +2608,7 @@ Returns:
     &(mStdErr.TextOutMode.MaxMode),\r
     &(mStdErr.TextOutMode.Mode)\r
     );\r
+\r
   if (mStdErr.TextOutMode.Mode < 0) {\r
     mStdErr.TextOut.SetMode (&(mStdErr.TextOut), 0);\r
   }\r
@@ -2525,24 +2619,24 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-STATIC\r
+\r
+/**\r
+  Add Grahpics Output modes into Consplitter Text Out list.\r
+\r
+  @param  Private               Text Out Splitter pointer.\r
+  @param  GraphicsOutput        Graphics Output protocol pointer.\r
+  @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
@@ -2561,9 +2655,7 @@ Returns:
   UINT32                               UgaColorDepth;\r
   UINT32                               UgaRefreshRate;\r
 \r
-  if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  ASSERT (GraphicsOutput != NULL || UgaDraw != NULL);\r
 \r
   CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;\r
 \r
@@ -2590,11 +2682,11 @@ Returns:
         CurrentGraphicsOutputMode->SizeOfInfo = GraphicsOutput->Mode->SizeOfInfo;\r
         CurrentGraphicsOutputMode->FrameBufferBase = GraphicsOutput->Mode->FrameBufferBase;\r
         CurrentGraphicsOutputMode->FrameBufferSize = GraphicsOutput->Mode->FrameBufferSize;\r
-\r
+  \r
         //\r
         // Allocate resource for the private mode buffer\r
         //\r
-        ModeBuffer = AllocatePool (GraphicsOutput->Mode->SizeOfInfo * GraphicsOutput->Mode->MaxMode);\r
+        ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * GraphicsOutput->Mode->MaxMode);\r
         if (ModeBuffer == NULL) {\r
           return EFI_OUT_OF_RESOURCES;\r
         }\r
@@ -2606,10 +2698,14 @@ Returns:
         //\r
         Mode = ModeBuffer;\r
         for (Index = 0; Index < GraphicsOutput->Mode->MaxMode; Index++) {\r
+          //\r
+          // The Info buffer would be allocated by callee\r
+          //\r
           Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) Index, &SizeOfInfo, &Info);\r
           if (EFI_ERROR (Status)) {\r
             return Status;\r
           }\r
+          ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
           CopyMem (Mode, Info, SizeOfInfo);\r
           Mode++;\r
           FreePool (Info);\r
@@ -2629,12 +2725,19 @@ Returns:
         Match = FALSE;\r
 \r
         for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {\r
+          //\r
+          // The Info buffer would be allocated by callee\r
+          //\r
           Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);\r
           if (EFI_ERROR (Status)) {\r
             return Status;\r
           }\r
           if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&\r
               (Info->VerticalResolution == Mode->VerticalResolution)) {\r
+            //\r
+            // If GOP device supports one mode in current mode buffer,\r
+            // it will be added into matched mode buffer\r
+            //\r
             Match = TRUE;\r
             FreePool (Info);\r
             break;\r
@@ -2645,6 +2748,9 @@ Returns:
         if (Match) {\r
           AlreadyExist = FALSE;\r
 \r
+          //\r
+          // Check if GOP mode has been in the mode buffer, ModeBuffer = MatchedMode at begin.\r
+          //\r
           for (Info = ModeBuffer; Info < MatchedMode; Info++) {\r
             if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&\r
                 (Info->VerticalResolution == Mode->VerticalResolution)) {\r
@@ -2710,8 +2816,7 @@ Returns:
         }\r
       }\r
     }\r
-  }\r
-  if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+  } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // Graphics console driver can ensure the same mode for all GOP devices\r
     // so we can get the current mode from this video device\r
@@ -2727,11 +2832,11 @@ Returns:
     CurrentGraphicsOutputMode->MaxMode = 1;\r
     Info = CurrentGraphicsOutputMode->Info;\r
     Info->Version = 0;\r
-    Info->HorizontalResolution = UgaHorizontalResolution;\r
-    Info->VerticalResolution = UgaVerticalResolution;\r
-    Info->PixelFormat = PixelBltOnly;\r
-    Info->PixelsPerScanLine = UgaHorizontalResolution;\r
-    CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+    Info->HorizontalResolution                 = UgaHorizontalResolution;\r
+    Info->VerticalResolution                   = UgaVerticalResolution;\r
+    Info->PixelFormat                          = PixelBltOnly;\r
+    Info->PixelsPerScanLine                    = UgaHorizontalResolution;\r
+    CurrentGraphicsOutputMode->SizeOfInfo      = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
     CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;\r
     CurrentGraphicsOutputMode->FrameBufferSize = 0;\r
 \r
@@ -2768,11 +2873,10 @@ Done:
   // 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
-  //\r
-  // If user defined mode is not valid for UGA, set to the default mode 800x600.\r
-  //\r
   if (EFI_ERROR(Status)) {\r
+    //\r
+    // If user defined mode is not valid for display device, set to the default mode 800x600.\r
+    //\r
     (Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;\r
     (Private->GraphicsOutputModeBuffer[0]).VerticalResolution   = 600;\r
     Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);\r
@@ -2781,76 +2885,46 @@ Done:
   return Status;\r
 }\r
 \r
-VOID\r
-ConsplitterSetConsoleOutMode (\r
-  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
+  Set the current console out mode.\r
 \r
   This routine will get the current console mode information (column, row)\r
   from ConsoleOutMode variable and set it; if the variable does not exist,\r
   set to user defined console mode.\r
 \r
-Arguments:\r
-\r
-  None\r
+  @param  Private            Consplitter Text Out pointer.\r
 \r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
+**/\r
+VOID\r
+ConsplitterSetConsoleOutMode (\r
+  IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private\r
+  )\r
 {\r
-  UINTN                         Col;\r
-  UINTN                         Row;\r
-  UINTN                         Mode;\r
-  UINTN                         PreferMode;\r
-  UINTN                         BaseMode;\r
-  UINTN                         ModeInfoSize;\r
-  UINTN                         MaxMode;\r
-  EFI_STATUS                    Status;\r
-  CONSOLE_OUT_MODE              *ModeInfo;\r
+  UINTN                            Col;\r
+  UINTN                            Row;\r
+  UINTN                            Mode;\r
+  UINTN                            PreferMode;\r
+  UINTN                            BaseMode;\r
+  UINTN                            MaxMode;\r
+  EFI_STATUS                       Status;\r
+  CONSOLE_OUT_MODE                 ModeInfo;\r
   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
+  ModeInfo.Column = PcdGet32 (PcdConOutColumn);\r
+  ModeInfo.Row    = PcdGet32 (PcdConOutRow);\r
 \r
   //\r
-  // Set to the default mode 80 x 25 required by EFI/UEFI spec;\r
-  // user can also define other valid default console mode here.\r
+  // To find the prefer mode and basic mode from Text Out mode list\r
   //\r
-  if (EFI_ERROR(Status)) {\r
-    ModeInfo->Column = 80;\r
-    ModeInfo->Row    = 25;\r
-    Status = gRT->SetVariable (\r
-                    VarConOutMode,\r
-                    &gEfiGenericPlatformVariableGuid,\r
-                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-                    sizeof (CONSOLE_OUT_MODE),\r
-                    ModeInfo\r
-                    );\r
-  }\r
-\r
   for (Mode = 0; Mode < MaxMode; Mode++) {\r
     Status = TextOut->QueryMode (TextOut, Mode, &Col, &Row);\r
     if (!EFI_ERROR(Status)) {\r
-      if (Col == ModeInfo->Column && Row == ModeInfo->Row) {\r
+      if (Col == ModeInfo.Column && Row == ModeInfo.Row) {\r
         PreferMode = Mode;\r
       }\r
       if (Col == 80 && Row == 25) {\r
@@ -2859,34 +2933,37 @@ Returns:
     }\r
   }\r
 \r
-  Status = TextOut->SetMode (TextOut, PreferMode);\r
-\r
   //\r
-  // if current mode setting is failed, default 80x25 mode will be set.\r
+  // Set prefer mode to Text Out devices.\r
   //\r
+  Status = TextOut->SetMode (TextOut, PreferMode);\r
   if (EFI_ERROR(Status)) {\r
-    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
+    // if current mode setting is failed, default 80x25 mode will be set.\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
+    Status = TextOut->SetMode (TextOut, BaseMode);\r
+    ASSERT(!EFI_ERROR(Status));\r
+    \r
+    PcdSet32 (PcdConOutColumn, 80);\r
+    PcdSet32 (PcdConOutRow, 25);\r
   }\r
 \r
-  gBS->FreePool (ModeInfo);\r
+  return ;\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
@@ -2894,33 +2971,24 @@ ConSplitterTextOutAddDevice (
   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                 CurrentNumOfConsoles;\r
-  INT32                 CurrentMode;\r
-  INT32                 MaxMode;\r
-  UINT32                UgaHorizontalResolution;\r
-  UINT32                UgaVerticalResolution;\r
-  UINT32                UgaColorDepth;\r
-  UINT32                UgaRefreshRate;\r
-  TEXT_OUT_AND_GOP_DATA *TextAndGop;\r
+  EFI_STATUS                           Status;\r
+  UINTN                                CurrentNumOfConsoles;\r
+  INT32                                CurrentMode;\r
+  INT32                                MaxMode;\r
+  UINT32                               UgaHorizontalResolution;\r
+  UINT32                               UgaVerticalResolution;\r
+  UINT32                               UgaColorDepth;\r
+  UINT32                               UgaRefreshRate;\r
+  TEXT_OUT_AND_GOP_DATA                *TextAndGop;\r
+  UINTN                                SizeOfInfo;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
 \r
   Status                = EFI_SUCCESS;\r
   CurrentNumOfConsoles  = Private->CurrentNumberOfConsoles;\r
 \r
   //\r
-  // If the Text Out List is full, enlarge it by calling growbuffer().\r
+  // If the Text Out List is full, enlarge it by calling ConSplitterGrowBuffer().\r
   //\r
   while (CurrentNumOfConsoles >= Private->TextOutListCount) {\r
     Status = ConSplitterGrowBuffer (\r
@@ -2942,9 +3010,9 @@ Returns:
 \r
   TextAndGop          = &Private->TextOutList[CurrentNumOfConsoles];\r
 \r
-  TextAndGop->TextOut = TextOut;\r
+  TextAndGop->TextOut        = TextOut;\r
   TextAndGop->GraphicsOutput = GraphicsOutput;\r
-  TextAndGop->UgaDraw = UgaDraw;\r
+  TextAndGop->UgaDraw        = UgaDraw;\r
 \r
   if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {\r
     //\r
@@ -2980,16 +3048,38 @@ Returns:
   MaxMode     = Private->TextOutMode.MaxMode;\r
   ASSERT (MaxMode >= 1);\r
 \r
-  //\r
-  // Update DevNull mode according to current video device\r
-  //\r
   if (FeaturePcdGet (PcdConOutGopSupport)) {\r
-    if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {\r
+    //\r
+    // If GOP is produced by Consplitter, this device display mode will be added into Graphics Ouput modes.\r
+    //\r
+    if ((GraphicsOutput != NULL) || (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport))) {\r
       ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);\r
     }\r
   }\r
+\r
   if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
-    if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    UgaHorizontalResolution = 800;\r
+    UgaVerticalResolution   = 600;\r
+    UgaColorDepth           = 32;\r
+    UgaRefreshRate          = 60;\r
+\r
+    Status = EFI_DEVICE_ERROR;\r
+    //\r
+    // If UGA is produced by Consplitter\r
+    //\r
+    if (GraphicsOutput != NULL) {\r
+      Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+      ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
+\r
+      UgaHorizontalResolution = Info->HorizontalResolution;\r
+      UgaVerticalResolution   = Info->VerticalResolution;\r
+\r
+      FreePool (Info);\r
+\r
+    } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
       Status = UgaDraw->GetMode (\r
                     UgaDraw,\r
                     &UgaHorizontalResolution,\r
@@ -2997,28 +3087,19 @@ Returns:
                     &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
+    //  Set UGA Draw mode,\r
+    //  if GetMode is failed, set to 800x600 mode\r
+    //\r
+    Status = ConSpliterUgaDrawSetMode (\r
+                &Private->UgaDraw,\r
+                UgaHorizontalResolution,\r
+                UgaVerticalResolution,\r
+                UgaColorDepth,\r
+                UgaRefreshRate\r
+                );\r
   }\r
 \r
   if (Private->ConsoleOutputMode == EfiConsoleControlScreenGraphics && GraphicsOutput != NULL) {\r
@@ -3026,8 +3107,14 @@ Returns:
     // We just added a new GOP or UGA device in graphics mode\r
     //\r
     if (FeaturePcdGet (PcdConOutGopSupport)) {\r
+      //\r
+      // Sync display output on new device based on GOP settings.\r
+      //\r
       DevNullGopSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);\r
     } else if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
+      //\r
+      // Sync display output on new device based on UGA settings.\r
+      //\r
       DevNullUgaSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);\r
     }\r
   } else if ((CurrentMode >= 0) && ((GraphicsOutput != NULL) || (UgaDraw != NULL)) && (CurrentMode < Private->TextOutMode.MaxMode)) {\r
@@ -3051,22 +3138,22 @@ Returns:
   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
@@ -3151,30 +3238,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
@@ -3201,29 +3283,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
@@ -3251,49 +3330,41 @@ 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
+\r
+/**\r
+  Record and check key sequence on StdIn.\r
+\r
+  This timer event will fire when StdIn is locked. It will record the key sequence\r
+  on StdIn and also check to see if it matches the password. Any error in the\r
+  password will cause the check to reset. As long as a mConIn.PasswordEnabled is\r
+  TRUE, the StdIn splitter will not report any input.\r
+\r
+  @param  Event                  The Event this notify function registered to.\r
+  @param  Context                Pointer to the context data registerd to the\r
+                                 Event.\r
+**/\r
 VOID\r
 EFIAPI\r
 ConSpliterConsoleControlLockStdInEvent (\r
   IN  EFI_EVENT                       Event,\r
   IN  VOID                            *Context\r
   )\r
-/*++\r
-\r
-Routine Description:\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
-\r
-Returns:\r
-  None\r
-\r
---*/\r
 {\r
   EFI_STATUS    Status;\r
   EFI_INPUT_KEY Key;\r
@@ -3304,11 +3375,14 @@ Returns:
     Status = ConSplitterTextInPrivateReadKeyStroke (&mConIn, &Key);\r
     if (!EFI_ERROR (Status)) {\r
       //\r
-      // if it's an ENTER, match password\r
+      // If key read successfully\r
       //\r
       if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN) && (Key.ScanCode == SCAN_NULL)) {\r
+        //\r
+        // If it's an ENTER, match password\r
+        //\r
         mConIn.PwdAttempt[mConIn.PwdIndex] = CHAR_NULL;\r
-        if (StrCmp (mConIn.Password, mConIn.PwdAttempt)) {\r
+        if (StrCmp (mConIn.Password, mConIn.PwdAttempt) != 0) {\r
           //\r
           // Password not match\r
           //\r
@@ -3330,7 +3404,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
@@ -3341,7 +3415,8 @@ Returns:
         }\r
       } else if ((Key.ScanCode == SCAN_NULL) && (Key.UnicodeChar >= 32)) {\r
         //\r
-        // If it's not an ENTER, neigher a function key, nor a CTRL-X or ALT-X, record the input\r
+        // If it's not an ENTER, neigher a function key, nor a CTRL-X or ALT-X, record the input,\r
+        // value 32 stands for a Blank Space key.\r
         //\r
         if (mConIn.PwdIndex < (MAX_STD_IN_PASSWORD - 1)) {\r
           if (mConIn.PwdIndex == 0) {\r
@@ -3357,27 +3432,25 @@ Returns:
   } while (!EFI_ERROR (Status));\r
 }\r
 \r
+\r
+/**\r
+  If Password is NULL or the Password is too big, then return an error. If the\r
+  Password is valid, then store the password, lock StdIn and arm the periodic timer.\r
+\r
+  @param  This                     Console Control protocol pointer.\r
+  @param  Password                 The password input.\r
+\r
+  @retval EFI_SUCCESS              Lock the StdIn device.\r
+  @retval EFI_INVALID_PARAMETER    Password is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES     Buffer allocation to store the password fails.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSpliterConsoleControlLockStdIn (\r
   IN  EFI_CONSOLE_CONTROL_PROTOCOL    *This,\r
   IN  CHAR16                          *Password\r
   )\r
-/*++\r
-\r
-Routine Description:\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
-\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
-\r
---*/\r
 {\r
   if (Password == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -3395,35 +3468,35 @@ Returns:
   StrCpy (mConIn.Password, Password);\r
   mConIn.PasswordEnabled  = TRUE;\r
   mConIn.PwdIndex         = 0;\r
-  gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, (10000 * 25));\r
+  //\r
+  // Lock Timer Periodic is 25ms.\r
+  //\r
+  gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, 10000 * 25);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+/**\r
+  Reads the next keystroke from the input device. The WaitForKey Event can\r
+  be used to test for existance of a keystroke via WaitForEvent () call.\r
+  If the ConIn is password locked make it look like no keystroke is availible\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  Key                      Driver may perform diagnostics on reset.\r
+\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
@@ -3440,35 +3513,32 @@ 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
-  This event agregates all the events of the ConIn devices in the spliter.\r
+/**\r
+  This event aggregates all the events of the ConIn devices in the spliter.\r
+\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
-\r
-Returns:\r
-  None\r
+  @param  Event                    The Event assoicated with callback.\r
+  @param  Context                  Context registered when Event was created.\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
   UINTN                         Index;\r
 \r
   Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;\r
+\r
   if (Private->PasswordEnabled) {\r
     //\r
     // If StdIn Locked return not ready\r
@@ -3476,15 +3546,16 @@ Returns:
     return ;\r
   }\r
 \r
-  //\r
-  // if KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()\r
-  //\r
   if (Private->KeyEventSignalState) {\r
+    //\r
+    // If KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()\r
+    //\r
     gBS->SignalEvent (Event);\r
     return ;\r
   }\r
+\r
   //\r
-  // if any physical console input device has key input, signal the event.\r
+  // If any physical console input device has key input, signal the event.\r
   //\r
   for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {\r
     Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);\r
@@ -3496,28 +3567,26 @@ Returns:
 }\r
 \r
 \r
-STATIC\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
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-  RegsiteredData    - A pointer to a buffer that is filled in with the keystroke\r
-                      state data for the key that was registered.\r
-  InputData         - A pointer to a buffer that is filled in with the keystroke\r
-                      state data for the key that was pressed.\r
-\r
-Returns:\r
-  TRUE              - Key be pressed matches a registered key.\r
-  FLASE             - Match failed.\r
-\r
---*/\r
 {\r
   ASSERT (RegsiteredData != NULL && InputData != NULL);\r
 \r
@@ -3542,31 +3611,24 @@ Returns:
 \r
 }\r
 \r
-//\r
-// Simple Text Input Ex protocol functions\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
-\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
@@ -3594,31 +3656,29 @@ ConSplitterTextInResetEx (
 \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
-\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
-    KeyData    - A pointer to a buffer that is filled in with the keystroke\r
-                 state data for the key that was pressed.\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 keystroke information was not returned due to\r
-                            hardware errors.\r
-    EFI_INVALID_PARAMETER - KeyData is NULL.\r
-\r
---*/\r
 {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
   EFI_STATUS                    Status;\r
@@ -3662,30 +3722,28 @@ ConSplitterTextInReadKeyStrokeEx (
   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
-\r
-  Routine Description:\r
-    Set certain state for the input device.\r
-\r
-  Arguments:\r
-    This                  - Protocol instance pointer.\r
-    KeyToggleState        - A pointer to the EFI_KEY_TOGGLE_STATE to set the\r
-                            state for the input device.\r
-\r
-  Returns:\r
-    EFI_SUCCESS           - The device state was set successfully.\r
-    EFI_DEVICE_ERROR      - The device is not functioning correctly and could\r
-                            not have the setting adjusted.\r
-    EFI_UNSUPPORTED       - The device does not have the ability to set its state.\r
-    EFI_INVALID_PARAMETER - KeyToggleState is NULL.\r
-\r
---*/\r
 {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
   EFI_STATUS                    Status;\r
@@ -3715,6 +3773,26 @@ ConSplitterTextInSetState (
 \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 KeyNotificationFunction or NotifyHandle is NULL.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextInRegisterKeyNotify (\r
@@ -3723,25 +3801,6 @@ ConSplitterTextInRegisterKeyNotify (
   IN EFI_KEY_NOTIFY_FUNCTION            KeyNotificationFunction,\r
   OUT EFI_HANDLE                        *NotifyHandle\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Register a notification function for a particular keystroke for the input device.\r
-\r
-  Arguments:\r
-    This                    - Protocol instance pointer.\r
-    KeyData                 - A pointer to a buffer that is filled in with the keystroke\r
-                              information data for the key that was pressed.\r
-    KeyNotificationFunction - Points to the function to be called when the key\r
-                              sequence is typed specified by KeyData.\r
-    NotifyHandle            - Points to the unique handle assigned to the registered notification.\r
-\r
-  Returns:\r
-    EFI_SUCCESS             - The notification function was registered successfully.\r
-    EFI_OUT_OF_RESOURCES    - Unable to allocate resources for necesssary data structures.\r
-    EFI_INVALID_PARAMETER   - KeyData or NotifyHandle is NULL.\r
-\r
---*/\r
 {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
   EFI_STATUS                    Status;\r
@@ -3758,7 +3817,7 @@ ConSplitterTextInRegisterKeyNotify (
   Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   //\r
-  // if no physical console input device exists,\r
+  // If no physical console input device exists,\r
   // return EFI_SUCCESS directly.\r
   //\r
   if (Private->CurrentNumberOfExConsoles <= 0) {\r
@@ -3769,12 +3828,7 @@ ConSplitterTextInRegisterKeyNotify (
   // 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
+    CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);\r
     if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {\r
       if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {\r
         *NotifyHandle = CurrentNotify->NotifyHandle;\r
@@ -3797,6 +3851,7 @@ ConSplitterTextInRegisterKeyNotify (
   }\r
   NewNotify->Signature         = TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE;\r
   NewNotify->KeyNotificationFn = KeyNotificationFunction;\r
+  NewNotify->NotifyHandle      = (EFI_HANDLE) NewNotify;\r
   CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));\r
 \r
   //\r
@@ -3817,17 +3872,6 @@ ConSplitterTextInRegisterKeyNotify (
     }\r
   }\r
 \r
-  //\r
-  // Use gSimpleTextInExNotifyGuid to get a valid EFI_HANDLE\r
-  //\r
-  Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &NewNotify->NotifyHandle,\r
-                  &gSimpleTextInExNotifyGuid,\r
-                  NULL,\r
-                  NULL\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   InsertTailList (&mConIn.NotifyList, &NewNotify->NotifyEntry);\r
 \r
   *NotifyHandle                = NewNotify->NotifyHandle;\r
@@ -3836,27 +3880,26 @@ ConSplitterTextInRegisterKeyNotify (
 \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
-\r
-  Routine Description:\r
-    Remove a registered notification function from a particular keystroke.\r
-\r
-  Arguments:\r
-    This                    - Protocol instance pointer.\r
-    NotificationHandle      - The handle of the notification function being unregistered.\r
-\r
-  Returns:\r
-    EFI_SUCCESS             - The notification function was unregistered successfully.\r
-    EFI_INVALID_PARAMETER   - The NotificationHandle is invalid.\r
-    EFI_NOT_FOUND           - Can not find the matching entry in database.\r
-\r
---*/\r
 {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
   EFI_STATUS                    Status;\r
@@ -3868,18 +3911,10 @@ ConSplitterTextInUnregisterKeyNotify (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Status = gBS->OpenProtocol (\r
-                  NotificationHandle,\r
-                  &gSimpleTextInExNotifyGuid,\r
-                  NULL,\r
-                  NULL,\r
-                  NULL,\r
-                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
+  if (((TEXT_IN_EX_SPLITTER_NOTIFY *) NotificationHandle)->Signature != TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE) {\r
     return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
+  } \r
+  \r
   Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   //\r
@@ -3891,7 +3926,7 @@ ConSplitterTextInUnregisterKeyNotify (
   }\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
+    CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);\r
     if (CurrentNotify->NotifyHandle == NotificationHandle) {\r
       for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {\r
         Status = Private->TextInExList[Index]->UnregisterKeyNotify (\r
@@ -3903,13 +3938,7 @@ ConSplitterTextInUnregisterKeyNotify (
         }\r
       }\r
       RemoveEntryList (&CurrentNotify->NotifyEntry);\r
-      Status = gBS->UninstallMultipleProtocolInterfaces (\r
-                      CurrentNotify->NotifyHandle,\r
-                      &gSimpleTextInExNotifyGuid,\r
-                      NULL,\r
-                      NULL\r
-                      );\r
-      ASSERT_EFI_ERROR (Status);\r
+\r
       gBS->FreePool (CurrentNotify->NotifyHandleList);\r
       gBS->FreePool (CurrentNotify);\r
       return EFI_SUCCESS;\r
@@ -3920,27 +3949,24 @@ ConSplitterTextInUnregisterKeyNotify (
 \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
@@ -3970,30 +3996,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
@@ -4050,30 +4072,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
@@ -4090,29 +4109,24 @@ 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
-\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
@@ -4145,31 +4159,23 @@ Returns:
   }\r
 }\r
 \r
-//\r
-// Absolute Pointer Protocol functions\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
 ConSplitterAbsolutePointerReset (\r
   IN EFI_ABSOLUTE_POINTER_PROTOCOL   *This,\r
   IN BOOLEAN                         ExtendedVerification\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Resets the pointer device hardware.\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 correctly and could\r
-                            not be reset.\r
-\r
---*/\r
 {\r
   EFI_STATUS                    Status;\r
   EFI_STATUS                    ReturnStatus;\r
@@ -4199,28 +4205,28 @@ ConSplitterAbsolutePointerReset (
   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
-\r
-  Routine Description:\r
-    Retrieves the current state of a pointer device.\r
-\r
-  Arguments:\r
-    This                  - Protocol instance pointer.\r
-    State                 - A pointer to the state information on the pointer device.\r
-\r
-  Returns:\r
-    EFI_SUCCESS           - The state of the pointer device was returned in State..\r
-    EFI_NOT_READY         - The state of the pointer device has not changed since the last call to\r
-                            GetState().\r
-    EFI_DEVICE_ERROR      - A device error occurred while attempting to retrieve the pointer\r
-                            device's current state.\r
---*/\r
 {\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
   EFI_STATUS                    Status;\r
@@ -4281,29 +4287,24 @@ ConSplitterAbsolutePointerGetState (
   return ReturnStatus;\r
 }\r
 \r
-VOID\r
-EFIAPI\r
-ConSplitterAbsolutePointerWaitForInput (\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 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
-Arguments:\r
-  Event   - The Event assoicated with callback.\r
-  Context - Context registered when Event was created.\r
-\r
-Returns:\r
-  None\r
+  @param  Event                    The Event assoicated with callback.\r
+  @param  Context                  Context registered when Event was created.\r
 \r
---*/\r
+**/\r
+VOID\r
+EFIAPI\r
+ConSplitterAbsolutePointerWaitForInput (\r
+  IN  EFI_EVENT                       Event,\r
+  IN  VOID                            *Context\r
+  )\r
 {\r
   EFI_STATUS                    Status;\r
   TEXT_IN_SPLITTER_PRIVATE_DATA *Private;\r
@@ -4337,28 +4338,25 @@ Returns:
   }\r
 }\r
 \r
+\r
+/**\r
+  Reset the text output device hardware and optionaly run diagnostics\r
+\r
+  @param  This                     Protocol instance pointer.\r
+  @param  ExtendedVerification     Driver may perform more exhaustive verfication\r
+                                   operation of the device during reset.\r
+\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
 EFI_STATUS\r
 EFIAPI\r
 ConSplitterTextOutReset (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
   IN  BOOLEAN                            ExtendedVerification\r
   )\r
-/*++\r
-\r
-  Routine Description:\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
-\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
-\r
---*/\r
 {\r
   EFI_STATUS                      Status;\r
   TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private;\r
@@ -4384,7 +4382,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
@@ -4394,34 +4392,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
@@ -4435,7 +4431,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
@@ -4446,6 +4442,8 @@ ConSplitterTextOutOutputString (
     TargetString = WString;\r
   } else {\r
     TargetString = AllocatePool (sizeof (CHAR16) * (StrLen (WString) + BackSpaceCount + 1));\r
+    ASSERT (TargetString != NULL);\r
+\r
     StrCpy (TargetString, WString);\r
   }\r
   //\r
@@ -4469,37 +4467,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
@@ -4530,6 +4526,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
@@ -4538,25 +4552,6 @@ 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
@@ -4597,28 +4592,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
@@ -4680,31 +4672,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
@@ -4741,27 +4732,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
@@ -4791,6 +4779,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
@@ -4798,25 +4806,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
@@ -4870,30 +4859,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