]> 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 b61f7bdc280bc5e689bf816ea80081cf659189c6..04ea719e59b121c3f7e5b3d54c184b6e03d53de8 100644 (file)
@@ -12,8 +12,8 @@
   These 3 virtual handles would be installed on gST.\r
 \r
   Each virtual handle, that supports the Console I/O protocol, will be produced\r
-  in the driver entry point. The virtual handle are added on driver entry and \r
-  never removed. Such design ensures sytem function well during none console \r
+  in the driver entry point. The virtual handle are added on driver entry and\r
+  never removed. Such design ensures sytem function well during none console\r
   device situation.\r
 \r
 Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
@@ -337,7 +337,7 @@ EFI_DRIVER_BINDING_PROTOCOL           gConSplitterAbsolutePointerDriverBinding =
 \r
   Installs driver module protocols and. Creates virtual device handles for ConIn,\r
   ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,\r
-  Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers. \r
+  Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.\r
   Installs Graphics Output protocol and/or UGA Draw protocol if needed.\r
 \r
   @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
@@ -410,7 +410,7 @@ ConSplitterDriverEntry(
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // One of Either Graphics Output protocol and UGA Draw protocol must be supported.\r
+  // Either Graphics Output protocol or UGA Draw protocol must be supported.\r
   //\r
   ASSERT (FeaturePcdGet (PcdConOutGopSupport) ||\r
           FeaturePcdGet (PcdConOutUgaSupport));\r
@@ -429,8 +429,6 @@ ConSplitterDriverEntry(
                     &mStdErr.VirtualHandle,\r
                     &gEfiSimpleTextOutProtocolGuid,\r
                     &mStdErr.TextOut,\r
-                    &gEfiPrimaryStandardErrorDeviceGuid,\r
-                    NULL,\r
                     NULL\r
                     );\r
   }\r
@@ -449,8 +447,6 @@ ConSplitterDriverEntry(
                     &mConIn.SimplePointer,\r
                     &gEfiAbsolutePointerProtocolGuid,\r
                     &mConIn.AbsolutePointer,\r
-                    &gEfiPrimaryConsoleInDeviceGuid,\r
-                    NULL,\r
                     NULL\r
                     );\r
     if (!EFI_ERROR (Status)) {\r
@@ -469,7 +465,7 @@ ConSplitterDriverEntry(
   if (!EFI_ERROR (Status)) {\r
     if (!FeaturePcdGet (PcdConOutGopSupport)) {\r
       //\r
-      // If Graphics Outpurt protocol not supported, UGA Draw protocol is installed \r
+      // If Graphics Outpurt protocol not supported, UGA Draw protocol is installed\r
       // on the virtual handle.\r
       //\r
       Status = gBS->InstallMultipleProtocolInterfaces (\r
@@ -480,8 +476,6 @@ ConSplitterDriverEntry(
                       &mConOut.UgaDraw,\r
                       &gEfiConsoleControlProtocolGuid,\r
                       &mConOut.ConsoleControl,\r
-                      &gEfiPrimaryConsoleOutDeviceGuid,\r
-                      NULL,\r
                       NULL\r
                       );\r
     } else if (!FeaturePcdGet (PcdConOutUgaSupport)) {\r
@@ -497,8 +491,6 @@ ConSplitterDriverEntry(
                       &mConOut.GraphicsOutput,\r
                       &gEfiConsoleControlProtocolGuid,\r
                       &mConOut.ConsoleControl,\r
-                      &gEfiPrimaryConsoleOutDeviceGuid,\r
-                      NULL,\r
                       NULL\r
                       );\r
     } else {\r
@@ -516,8 +508,6 @@ ConSplitterDriverEntry(
                       &mConOut.UgaDraw,\r
                       &gEfiConsoleControlProtocolGuid,\r
                       &mConOut.ConsoleControl,\r
-                      &gEfiPrimaryConsoleOutDeviceGuid,\r
-                      NULL,\r
                       NULL\r
                       );\r
     }\r
@@ -565,7 +555,7 @@ ConSplitterTextInConstructor (
   EFI_STATUS  Status;\r
 \r
   //\r
-  // Allocate buffer for Simple Text Input device  \r
+  // Allocate buffer for Simple Text Input device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),\r
@@ -587,7 +577,7 @@ ConSplitterTextInConstructor (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
   //\r
-  // Create Event to wait for a key \r
+  // Create Event to wait for a key\r
   //\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
@@ -599,7 +589,7 @@ ConSplitterTextInConstructor (
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Allocate buffer for Simple Text Input Ex device  \r
+  // Allocate buffer for Simple Text Input Ex device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
              sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),\r
@@ -625,7 +615,7 @@ ConSplitterTextInConstructor (
 \r
   ConInPrivate->AbsolutePointer.Mode = &ConInPrivate->AbsolutePointerMode;\r
   //\r
-  // Allocate buffer for Absolute Pointer device  \r
+  // Allocate buffer for Absolute Pointer device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),\r
@@ -649,7 +639,7 @@ ConSplitterTextInConstructor (
 \r
   ConInPrivate->SimplePointer.Mode = &ConInPrivate->SimplePointerMode;\r
   //\r
-  // Allocate buffer for Simple Pointer device  \r
+  // Allocate buffer for Simple Pointer device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),\r
@@ -712,7 +702,7 @@ ConSplitterTextOutConstructor (
   //\r
   ConOutPrivate->TextOutMode.Mode = 0xFF;\r
   //\r
-  // Allocate buffer for Console Out device  \r
+  // Allocate buffer for Console Out device\r
   //\r
   Status = ConSplitterGrowBuffer (\r
             sizeof (TEXT_OUT_AND_GOP_DATA),\r
@@ -793,7 +783,7 @@ ConSplitterTextOutConstructor (
 \r
 \r
 /**\r
-  Test to see if the specified protocol could be supported on the specified device. \r
+  Test to see if the specified protocol could be supported on the specified device.\r
 \r
   @param  This                Driver Binding protocol pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -819,7 +809,7 @@ ConSplitterSupported (
   //\r
   if (ControllerHandle == mConIn.VirtualHandle  ||\r
       ControllerHandle == mConOut.VirtualHandle ||\r
-      ControllerHandle == mStdErr.VirtualHandle \r
+      ControllerHandle == mStdErr.VirtualHandle\r
       ) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -851,7 +841,7 @@ ConSplitterSupported (
 }\r
 \r
 /**\r
-  Test to see if Console In Device could be supported on the Controller. \r
+  Test to see if Console In Device could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -878,7 +868,7 @@ ConSplitterConInDriverBindingSupported (
 }\r
 \r
 /**\r
-  Test to see if Simple Pointer protocol could be supported on the Controller. \r
+  Test to see if Simple Pointer protocol could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -905,7 +895,7 @@ ConSplitterSimplePointerDriverBindingSupported (
 }\r
 \r
 /**\r
-  Test to see if Absolute Pointer protocol could be supported on the Controller. \r
+  Test to see if Absolute Pointer protocol could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -933,7 +923,7 @@ ConSplitterAbsolutePointerDriverBindingSupported (
 \r
 \r
 /**\r
-  Test to see if Console Out Device could be supported on the Controller. \r
+  Test to see if Console Out Device could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -960,7 +950,7 @@ ConSplitterConOutDriverBindingSupported (
 }\r
 \r
 /**\r
-  Test to see if Standard Error Device could be supported on the Controller. \r
+  Test to see if Standard Error Device could be supported on the Controller.\r
 \r
   @param  This                Driver Binding protocol instance pointer.\r
   @param  ControllerHandle    Handle of device to test.\r
@@ -988,9 +978,9 @@ ConSplitterStdErrDriverBindingSupported (
 \r
 \r
 /**\r
-  Start ConSplitter on devcie handle by opening Console Device Guid on device handle \r
+  Start ConSplitter on devcie handle by opening Console Device Guid on device handle\r
   and the console virtual handle. And Get the console interface on controller handle.\r
-  \r
+\r
   @param  This                      Driver Binding protocol instance pointer.\r
   @param  ControllerHandle          Handle of device.\r
   @param  ConSplitterVirtualHandle  Console virtual Handle.\r
@@ -1031,7 +1021,7 @@ ConSplitterStart (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
\r
+\r
   //\r
   // Create virtual handle and open DeviceGuid on the virtul handle.\r
   //\r
@@ -1089,8 +1079,8 @@ Err:
 \r
 \r
 /**\r
-  Start Console In Consplitter on device handle. \r
-  \r
+  Start Console In Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding protocol instance pointer.\r
   @param  ControllerHandle     Handle of device to bind driver to.\r
   @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
@@ -1157,8 +1147,8 @@ ConSplitterConInDriverBindingStart (
 \r
 \r
 /**\r
-  Start Simple Pointer Consplitter on device handle. \r
-  \r
+  Start Simple Pointer Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding protocol instance pointer.\r
   @param  ControllerHandle     Handle of device to bind driver to.\r
   @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
@@ -1203,8 +1193,8 @@ ConSplitterSimplePointerDriverBindingStart (
 \r
 \r
 /**\r
-  Start Absolute Pointer Consplitter on device handle. \r
-  \r
+  Start Absolute Pointer Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding protocol instance pointer.\r
   @param  ControllerHandle     Handle of device to bind driver to.\r
   @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
@@ -1250,8 +1240,8 @@ ConSplitterAbsolutePointerDriverBindingStart (
 \r
 \r
 /**\r
-  Start Console Out Consplitter on device handle. \r
-  \r
+  Start Console Out Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding protocol instance pointer.\r
   @param  ControllerHandle     Handle of device to bind driver to.\r
   @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
@@ -1269,10 +1259,12 @@ ConSplitterConOutDriverBindingStart (
   IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                       Status;\r
-  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL     *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL            *UgaDraw;\r
+  EFI_STATUS                           Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL      *TextOut;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL         *GraphicsOutput;\r
+  EFI_UGA_DRAW_PROTOCOL                *UgaDraw;\r
+  UINTN                                SizeOfInfo;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
 \r
   //\r
   // Start ConSplitter on ControllerHandle, and create the virtual\r
@@ -1308,14 +1300,14 @@ ConSplitterConOutDriverBindingStart (
     //\r
     // Open UGA DRAW protocol\r
     //\r
-    Status = gBS->OpenProtocol (\r
-                    ControllerHandle,\r
-                    &gEfiUgaDrawProtocolGuid,\r
-                    (VOID **) &UgaDraw,\r
-                    This->DriverBindingHandle,\r
-                    mConOut.VirtualHandle,\r
-                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                    );\r
+    gBS->OpenProtocol (\r
+           ControllerHandle,\r
+           &gEfiUgaDrawProtocolGuid,\r
+           (VOID **) &UgaDraw,\r
+           This->DriverBindingHandle,\r
+           mConOut.VirtualHandle,\r
+           EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+           );\r
   }\r
 \r
   //\r
@@ -1331,12 +1323,26 @@ ConSplitterConOutDriverBindingStart (
   Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput, UgaDraw);\r
   ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
 \r
-  if (FeaturePcdGet (PcdConOutUgaSupport) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+  if (FeaturePcdGet (PcdConOutUgaSupport)) {\r
     //\r
-    // Match the UGA mode data of ConOut with the current mode\r
+    // Get the UGA mode data of ConOut from the current mode\r
     //\r
-    if (UgaDraw != NULL) {\r
-      UgaDraw->GetMode (\r
+    if (GraphicsOutput != NULL) {\r
+      Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+      ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r
+\r
+      mConOut.UgaHorizontalResolution = Info->HorizontalResolution;\r
+      mConOut.UgaVerticalResolution   = Info->VerticalResolution;\r
+      mConOut.UgaColorDepth           = 32;\r
+      mConOut.UgaRefreshRate          = 60;\r
+\r
+      FreePool (Info);\r
+\r
+    } else if (UgaDraw != NULL  && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+      Status = UgaDraw->GetMode (\r
                  UgaDraw,\r
                  &mConOut.UgaHorizontalResolution,\r
                  &mConOut.UgaVerticalResolution,\r
@@ -1345,13 +1351,14 @@ ConSplitterConOutDriverBindingStart (
                  );\r
     }\r
   }\r
+\r
   return Status;\r
 }\r
 \r
 \r
 /**\r
-  Start Standard Error Consplitter on device handle. \r
-  \r
+  Start Standard Error Consplitter on device handle.\r
+\r
   @param  This                 Driver Binding protocol instance pointer.\r
   @param  ControllerHandle     Handle of device to bind driver to.\r
   @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
@@ -1423,9 +1430,9 @@ ConSplitterStdErrDriverBindingStart (
 \r
 \r
 /**\r
-  Stop ConSplitter on device handle by closing Console Device Guid on device handle \r
+  Stop ConSplitter on device handle by closing Console Device Guid on device handle\r
   and the console virtual handle.\r
-  \r
+\r
   @param  This                      Protocol instance pointer.\r
   @param  ControllerHandle          Handle of device.\r
   @param  ConSplitterVirtualHandle  Console virtual Handle.\r
@@ -1524,7 +1531,7 @@ ConSplitterConInDriverBindingStop (
     //\r
     // If Simple Text Input Ex protocol exists,\r
     // remove device from Text Input Ex devices list.\r
-    //  \r
+    //\r
     Status = ConSplitterTextInExDeleteDevice (&mConIn, TextInEx);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
@@ -1548,7 +1555,7 @@ ConSplitterConInDriverBindingStop (
 \r
   //\r
   // Remove device from Text Input devices list.\r
-  // \r
+  //\r
   return ConSplitterTextInDeleteDevice (&mConIn, TextIn);\r
 }\r
 \r
@@ -1808,7 +1815,7 @@ ConSplitterGrowBuffer (
   //\r
   *Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;\r
   Ptr = ReallocatePool (\r
-          SizeOfCount * ((*Count) - CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT), \r
+          SizeOfCount * ((*Count) - CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT),\r
           SizeOfCount * (*Count),\r
           *Buffer\r
           );\r
@@ -2220,7 +2227,7 @@ ConSplitterGrowMapTable (
 \r
   @param  Private               Text Out Splitter pointer\r
   @param  TextOut               Simple Text Output protocol pointer.\r
-  \r
+\r
   @retval EFI_SUCCESS           Device added successfully.\r
   @retval EFI_OUT_OF_RESOURCES  Could not grow the buffer size.\r
 \r
@@ -2366,11 +2373,11 @@ ConSplitterGetIntersection (
 }\r
 \r
 /**\r
-  Add the device's output mode to console splitter's mode list.\r
+  Sync the device's output mode to console splitter's mode list.\r
 \r
   @param  Private               Text Out Splitter pointer.\r
   @param  TextOut               Simple Text Output protocol pointer.\r
-  \r
+\r
 **/\r
 VOID\r
 ConSplitterSyncOutputMode (\r
@@ -2614,7 +2621,7 @@ ConSplitterGetIntersectionBetweenConOutAndStrErr (
 \r
 \r
 /**\r
-  Add display (GOP or UGA) output modes into Consplitter Text Out list.\r
+  Add Grahpics Output modes into Consplitter Text Out list.\r
 \r
   @param  Private               Text Out Splitter pointer.\r
   @param  GraphicsOutput        Graphics Output protocol pointer.\r
@@ -2625,7 +2632,7 @@ ConSplitterGetIntersectionBetweenConOutAndStrErr (
 \r
 **/\r
 EFI_STATUS\r
-ConSplitterAddDisplayOutputMode (\r
+ConSplitterAddGraphicsOutputMode (\r
   IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private,\r
   IN  EFI_GRAPHICS_OUTPUT_PROTOCOL    *GraphicsOutput,\r
   IN  EFI_UGA_DRAW_PROTOCOL           *UgaDraw\r
@@ -2648,9 +2655,7 @@ ConSplitterAddDisplayOutputMode (
   UINT32                               UgaColorDepth;\r
   UINT32                               UgaRefreshRate;\r
 \r
-  if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  ASSERT (GraphicsOutput != NULL || UgaDraw != NULL);\r
 \r
   CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;\r
 \r
@@ -2677,7 +2682,7 @@ ConSplitterAddDisplayOutputMode (
         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
@@ -2730,7 +2735,7 @@ ConSplitterAddDisplayOutputMode (
           if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&\r
               (Info->VerticalResolution == Mode->VerticalResolution)) {\r
             //\r
-            // If GOP device supports one mode in current mode buffer, \r
+            // If GOP device supports one mode in current mode buffer,\r
             // it will be added into matched mode buffer\r
             //\r
             Match = TRUE;\r
@@ -2742,7 +2747,7 @@ ConSplitterAddDisplayOutputMode (
 \r
         if (Match) {\r
           AlreadyExist = FALSE;\r
-          \r
+\r
           //\r
           // Check if GOP mode has been in the mode buffer, ModeBuffer = MatchedMode at begin.\r
           //\r
@@ -2811,8 +2816,7 @@ ConSplitterAddDisplayOutputMode (
         }\r
       }\r
     }\r
-  }\r
-  if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+  } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // Graphics console driver can ensure the same mode for all GOP devices\r
     // so we can get the current mode from this video device\r
@@ -2828,11 +2832,11 @@ ConSplitterAddDisplayOutputMode (
     CurrentGraphicsOutputMode->MaxMode = 1;\r
     Info = CurrentGraphicsOutputMode->Info;\r
     Info->Version = 0;\r
-    Info->HorizontalResolution = UgaHorizontalResolution;\r
-    Info->VerticalResolution = UgaVerticalResolution;\r
-    Info->PixelFormat = PixelBltOnly;\r
-    Info->PixelsPerScanLine = UgaHorizontalResolution;\r
-    CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+    Info->HorizontalResolution                 = UgaHorizontalResolution;\r
+    Info->VerticalResolution                   = UgaVerticalResolution;\r
+    Info->PixelFormat                          = PixelBltOnly;\r
+    Info->PixelsPerScanLine                    = UgaHorizontalResolution;\r
+    CurrentGraphicsOutputMode->SizeOfInfo      = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
     CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;\r
     CurrentGraphicsOutputMode->FrameBufferSize = 0;\r
 \r
@@ -2881,8 +2885,9 @@ Done:
   return Status;\r
 }\r
 \r
-\r
 /**\r
+  Set the current console out mode.\r
+\r
   This routine will get the current console mode information (column, row)\r
   from ConsoleOutMode variable and set it; if the variable does not exist,\r
   set to user defined console mode.\r
@@ -2895,54 +2900,31 @@ ConsplitterSetConsoleOutMode (
   IN  TEXT_OUT_SPLITTER_PRIVATE_DATA  *Private\r
   )\r
 {\r
-  UINTN                         Col;\r
-  UINTN                         Row;\r
-  UINTN                         Mode;\r
-  UINTN                         PreferMode;\r
-  UINTN                         BaseMode;\r
-  UINTN                         ModeInfoSize;\r
-  UINTN                         MaxMode;\r
-  EFI_STATUS                    Status;\r
-  CONSOLE_OUT_MODE              *ModeInfo;\r
+  UINTN                            Col;\r
+  UINTN                            Row;\r
+  UINTN                            Mode;\r
+  UINTN                            PreferMode;\r
+  UINTN                            BaseMode;\r
+  UINTN                            MaxMode;\r
+  EFI_STATUS                       Status;\r
+  CONSOLE_OUT_MODE                 ModeInfo;\r
   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
@@ -2951,31 +2933,22 @@ ConsplitterSetConsoleOutMode (
     }\r
   }\r
 \r
-  Status = TextOut->SetMode (TextOut, PreferMode);\r
-\r
   //\r
-  // if current mode setting is failed, default 80x25 mode will be set.\r
+  // Set prefer mode to Text Out devices.\r
   //\r
+  Status = TextOut->SetMode (TextOut, PreferMode);\r
   if (EFI_ERROR(Status)) {\r
-    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
@@ -2999,15 +2972,17 @@ ConSplitterTextOutAddDevice (
   IN  EFI_UGA_DRAW_PROTOCOL              *UgaDraw\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  UINTN                 CurrentNumOfConsoles;\r
-  INT32                 CurrentMode;\r
-  INT32                 MaxMode;\r
-  UINT32                UgaHorizontalResolution;\r
-  UINT32                UgaVerticalResolution;\r
-  UINT32                UgaColorDepth;\r
-  UINT32                UgaRefreshRate;\r
-  TEXT_OUT_AND_GOP_DATA *TextAndGop;\r
+  EFI_STATUS                           Status;\r
+  UINTN                                CurrentNumOfConsoles;\r
+  INT32                                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
@@ -3035,9 +3010,9 @@ ConSplitterTextOutAddDevice (
 \r
   TextAndGop          = &Private->TextOutList[CurrentNumOfConsoles];\r
 \r
-  TextAndGop->TextOut = TextOut;\r
+  TextAndGop->TextOut        = TextOut;\r
   TextAndGop->GraphicsOutput = GraphicsOutput;\r
-  TextAndGop->UgaDraw = UgaDraw;\r
+  TextAndGop->UgaDraw        = UgaDraw;\r
 \r
   if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {\r
     //\r
@@ -3073,16 +3048,38 @@ ConSplitterTextOutAddDevice (
   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
-      ConSplitterAddDisplayOutputMode (Private, GraphicsOutput, UgaDraw);\r
+    //\r
+    // If GOP is produced by Consplitter, this device display mode will be added into Graphics Ouput modes.\r
+    //\r
+    if ((GraphicsOutput != NULL) || (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport))) {\r
+      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
@@ -3090,28 +3087,19 @@ ConSplitterTextOutAddDevice (
                     &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
@@ -3119,8 +3107,14 @@ ConSplitterTextOutAddDevice (
     // 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
@@ -3354,10 +3348,12 @@ ConSpliterConssoleControlStdInLocked (
 \r
 \r
 /**\r
-  This timer event will fire when StdIn is locked. It will check the key\r
-  sequence on StdIn to see if it matches the password. Any error in the\r
-  password will cause the check to reset. As long a mConIn.PasswordEnabled is\r
-  TRUE the StdIn splitter will not report any input.\r
+  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
@@ -3379,11 +3375,14 @@ ConSpliterConsoleControlLockStdInEvent (
     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
@@ -3416,7 +3415,8 @@ ConSpliterConsoleControlLockStdInEvent (
         }\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
@@ -3434,15 +3434,15 @@ ConSpliterConsoleControlLockStdInEvent (
 \r
 \r
 /**\r
-  If Password is NULL or the Password is too big, then return an error. If the \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
+  @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
@@ -3468,7 +3468,10 @@ ConSpliterConsoleControlLockStdIn (
   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
@@ -3512,7 +3515,8 @@ ConSplitterTextInReadKeyStroke (
 \r
 \r
 /**\r
-  This event agregates all the events of the ConIn devices in the spliter.\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
@@ -3534,6 +3538,7 @@ ConSplitterTextInWaitForKey (
   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
@@ -3541,15 +3546,16 @@ ConSplitterTextInWaitForKey (
     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
@@ -3784,7 +3790,7 @@ ConSplitterTextInSetState (
                                    successfully.\r
   @retval EFI_OUT_OF_RESOURCES     Unable to allocate resources for necesssary data\r
                                    structures.\r
-  @retval EFI_INVALID_PARAMETER    KeyData or NotifyHandle is NULL.\r
+  @retval EFI_INVALID_PARAMETER    KeyData or KeyNotificationFunction or NotifyHandle is NULL.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3811,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
@@ -3845,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
@@ -3865,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
@@ -3915,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
@@ -3950,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
@@ -4460,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