]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
Use the correct length to copy KeyData.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConSplitterDxe / ConSplitter.c
index 9b0fe2fed4ce2c42e177b32911f60f926a6d58a4..d4f480943b216a1a20f2d344ecbd05deb7a57e8d 100644 (file)
@@ -16,8 +16,8 @@
   never removed. Such design ensures sytem function well during none console\r
   device situation.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -107,18 +107,18 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA  mConIn = {
 // Uga Draw Protocol Private Data template\r
 //\r
 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UGA_DRAW_PROTOCOL mUgaDrawProtocolTemplate = {\r
-  ConSpliterUgaDrawGetMode,\r
-  ConSpliterUgaDrawSetMode,\r
-  ConSpliterUgaDrawBlt\r
+  ConSplitterUgaDrawGetMode,\r
+  ConSplitterUgaDrawSetMode,\r
+  ConSplitterUgaDrawBlt\r
 };\r
 \r
 //\r
 // Graphics Output Protocol Private Data template\r
 //\r
 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_PROTOCOL mGraphicsOutputProtocolTemplate = {\r
-  ConSpliterGraphicsOutputQueryMode,\r
-  ConSpliterGraphicsOutputSetMode,\r
-  ConSpliterGraphicsOutputBlt,\r
+  ConSplitterGraphicsOutputQueryMode,\r
+  ConSplitterGraphicsOutputSetMode,\r
+  ConSplitterGraphicsOutputBlt,\r
   NULL\r
 };\r
 \r
@@ -379,23 +379,11 @@ ConSplitterDriverEntry(
           FeaturePcdGet (PcdConOutUgaSupport));\r
 \r
   //\r
-  // The driver creates virtual handles for ConIn, ConOut, and StdErr.\r
+  // The driver creates virtual handles for ConIn, ConOut.\r
   // The virtual handles will always exist even if no console exist in the\r
   // system. This is need to support hotplug devices like USB.\r
   //\r
   //\r
-  // Create virtual device handle for StdErr Splitter\r
-  //\r
-  Status = ConSplitterTextOutConstructor (&mStdErr);\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                    &mStdErr.VirtualHandle,\r
-                    &gEfiSimpleTextOutProtocolGuid,\r
-                    &mStdErr.TextOut,\r
-                    NULL\r
-                    );\r
-  }\r
-  //\r
   // Create virtual device handle for ConIn Splitter\r
   //\r
   Status = ConSplitterTextInConstructor (&mConIn);\r
@@ -683,7 +671,7 @@ ConSplitterTextOutConstructor (
     //\r
     // Setup the UgaDraw to 800 x 600 x 32 bits per pixel, 60Hz.\r
     //\r
-    ConSpliterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);\r
+    ConSplitterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);\r
   }\r
   if (FeaturePcdGet (PcdConOutGopSupport)) {\r
     //\r
@@ -971,7 +959,7 @@ ConSplitterStart (
   }\r
 \r
   //\r
-  // Create virtual handle and open DeviceGuid on the virtul handle.\r
+  // Open the Parent Handle for the child.\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -1327,6 +1315,27 @@ ConSplitterStdErrDriverBindingStart (
   EFI_STATUS                       Status;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *TextOut;\r
 \r
+  if (mStdErr.CurrentNumberOfConsoles == 0) {\r
+    //\r
+    // Construct console output devices' private data\r
+    //\r
+    Status = ConSplitterTextOutConstructor (&mStdErr);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Create virtual device handle for StdErr Splitter\r
+      //\r
+      Status = gBS->InstallMultipleProtocolInterfaces (\r
+                      &mStdErr.VirtualHandle,\r
+                      &gEfiSimpleTextOutProtocolGuid,\r
+                      &mStdErr.TextOut,\r
+                      NULL\r
+                      );\r
+    }\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
   //\r
   // Start ConSplitter on ControllerHandle, and create the virtual\r
   // agrogated console device on first call Start for a StandardError handle.\r
@@ -1715,6 +1724,8 @@ ConSplitterStdErrDriverBindingStop (
   }\r
 \r
   if (mStdErr.CurrentNumberOfConsoles == 0) {\r
+    mStdErr.VirtualHandle     = NULL;\r
+\r
     gST->StandardErrorHandle  = NULL;\r
     gST->StdErr               = NULL;\r
     //\r
@@ -1726,6 +1737,16 @@ ConSplitterStdErrDriverBindingStop (
           gST->Hdr.HeaderSize,\r
           &gST->Hdr.CRC32\r
           );\r
+\r
+    //\r
+    // Uninstall Simple Text Output protocol from StdErr Handle.\r
+    //\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+           mStdErr.VirtualHandle,\r
+           &gEfiSimpleTextOutProtocolGuid,\r
+           &mStdErr.TextOut,\r
+           NULL\r
+           );\r
   }\r
 \r
   return Status;\r
@@ -1749,8 +1770,8 @@ ConSplitterStdErrDriverBindingStop (
 **/\r
 EFI_STATUS\r
 ConSplitterGrowBuffer (\r
-  IN  UINTN                           SizeOfCount,\r
-  IN  UINTN                           *Count,\r
+  IN      UINTN                       SizeOfCount,\r
+  IN OUT  UINTN                       *Count,\r
   IN OUT  VOID                        **Buffer\r
   )\r
 {\r
@@ -2609,6 +2630,7 @@ ConSplitterAddGraphicsOutputMode (
 \r
   Index        = 0;\r
   CurrentIndex = 0;\r
+  Status       = EFI_SUCCESS;\r
 \r
   if (Private->CurrentNumberOfUgaDraw != 0) {\r
     //\r
@@ -2630,7 +2652,7 @@ ConSplitterAddGraphicsOutputMode (
         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
@@ -2813,21 +2835,48 @@ Done:
   // regardless whether the console is in EfiConsoleControlScreenGraphics or EfiConsoleControlScreenText mode\r
   //\r
   Private->HardwareNeedsStarting = TRUE;\r
-  //\r
-  // Current mode number may need update now, so set it to an invalid mode number\r
-  //\r
-  CurrentGraphicsOutputMode->Mode = 0xffff;\r
-  //\r
-  // Graphics console can ensure all GOP devices have the same mode which can be taken as current mode.\r
-  //\r
-  Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) CurrentIndex);\r
-  if (EFI_ERROR(Status)) {\r
+  \r
+  Mode = &Private->GraphicsOutputModeBuffer[CurrentIndex];\r
+  if ((GraphicsOutput != NULL) &&\r
+      (Mode->HorizontalResolution == CurrentGraphicsOutputMode->Info->HorizontalResolution) &&\r
+      (Mode->VerticalResolution == CurrentGraphicsOutputMode->Info->VerticalResolution)) {\r
+    CurrentGraphicsOutputMode->Mode = (UINT32) CurrentIndex;\r
+    if ((Mode->HorizontalResolution != GraphicsOutput->Mode->Info->HorizontalResolution) ||\r
+        (Mode->VerticalResolution != GraphicsOutput->Mode->Info->VerticalResolution)) {\r
+      //\r
+      // If all existing video device has been set to common mode, only set new GOP device to\r
+      // the common mode\r
+      //\r
+      for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex ++) {\r
+        Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);\r
+        if (EFI_ERROR (Status)) {\r
+          return Status;\r
+        }\r
+        if ((Info->HorizontalResolution == Mode->HorizontalResolution) && (Info->VerticalResolution == Mode->VerticalResolution)) {\r
+          FreePool (Info);\r
+          break;\r
+        }\r
+        FreePool (Info);\r
+      }\r
+      Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32) NumberIndex);\r
+    }\r
+  } else {\r
+    //\r
+    // Current mode number may need update now, so set it to an invalid mode number\r
+    //\r
+    CurrentGraphicsOutputMode->Mode = 0xffff;\r
     //\r
-    // If user defined mode is not valid for display device, set to the default mode 800x600.\r
+    // Graphics console can ensure all GOP devices have the same mode which can be taken as current mode.\r
     //\r
-    (Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;\r
-    (Private->GraphicsOutputModeBuffer[0]).VerticalResolution   = 600;\r
-    Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);\r
+    Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) CurrentIndex);\r
+    if (EFI_ERROR(Status)) {\r
+      //\r
+      // If user defined mode is not valid for display device, set to the default mode 800x600.\r
+      //\r
+      (Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;\r
+      (Private->GraphicsOutputModeBuffer[0]).VerticalResolution   = 600;\r
+      Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);\r
+    }\r
   }\r
 \r
   return Status;\r
@@ -2891,7 +2940,7 @@ ConsplitterSetConsoleOutMode (
     //\r
     Status = TextOut->SetMode (TextOut, BaseMode);\r
     ASSERT(!EFI_ERROR(Status));\r
-    \r
+\r
     PcdSet32 (PcdConOutColumn, 80);\r
     PcdSet32 (PcdConOutRow, 25);\r
   }\r
@@ -2930,6 +2979,7 @@ ConSplitterTextOutAddDevice (
   TEXT_OUT_AND_GOP_DATA                *TextAndGop;\r
   UINTN                                SizeOfInfo;\r
   EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
+  EFI_STATUS                           DeviceStatus;\r
 \r
   Status                = EFI_SUCCESS;\r
   CurrentNumOfConsoles  = Private->CurrentNumberOfConsoles;\r
@@ -2982,22 +3032,17 @@ ConSplitterTextOutAddDevice (
   MaxMode     = Private->TextOutMode.MaxMode;\r
   ASSERT (MaxMode >= 1);\r
 \r
+  DeviceStatus = EFI_DEVICE_ERROR;\r
   if (FeaturePcdGet (PcdConOutGopSupport)) {\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
+      DeviceStatus = ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);\r
     }\r
   }\r
 \r
   if (FeaturePcdGet (PcdConOutUgaSupport)) {\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
@@ -3021,26 +3066,33 @@ ConSplitterTextOutAddDevice (
                     &UgaColorDepth,\r
                     &UgaRefreshRate\r
                     );\r
+      if (!EFI_ERROR (Status) && EFI_ERROR (DeviceStatus)) {\r
+        //\r
+        // if GetMode is successfully and UGA device hasn't been set, set it\r
+        //\r
+        Status = ConSplitterUgaDrawSetMode (\r
+                    &Private->UgaDraw,\r
+                    UgaHorizontalResolution,\r
+                    UgaVerticalResolution,\r
+                    UgaColorDepth,\r
+                    UgaRefreshRate\r
+                    );\r
+      }\r
+      //\r
+      // If GetMode/SetMode is failed, set to 800x600 mode\r
+      //\r
+      if(EFI_ERROR (Status)) {\r
+        Status = ConSplitterUgaDrawSetMode (\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
-  //\r
-  // If ConOut, then set the mode to Mode #0 which us 80 x 25\r
-  //\r
-  Private->TextOut.SetMode (&Private->TextOut, 0);\r
-\r
   //\r
   // After adding new console device, all existing console devices should be\r
   // synced to the current shared mode.\r
@@ -3597,7 +3649,7 @@ ConSplitterTextInRegisterKeyNotify (
   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
+  CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));\r
 \r
   //\r
   // Return the wrong status of registering key notify of\r
@@ -3636,7 +3688,6 @@ ConSplitterTextInRegisterKeyNotify (
   @retval EFI_SUCCESS              The notification function was unregistered\r
                                    successfully.\r
   @retval EFI_INVALID_PARAMETER    The NotificationHandle is invalid.\r
-  @retval EFI_NOT_FOUND            Can not find the matching entry in database.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -3658,8 +3709,8 @@ ConSplitterTextInUnregisterKeyNotify (
 \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
@@ -3690,8 +3741,10 @@ ConSplitterTextInUnregisterKeyNotify (
     }\r
   }\r
 \r
-  return EFI_NOT_FOUND;\r
-\r
+  //\r
+  // NotificationHandle is not found in database\r
+  //\r
+  return EFI_INVALID_PARAMETER;\r
 }\r
 \r
 \r
@@ -4145,15 +4198,11 @@ ConSplitterTextOutOutputString (
   Private         = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   BackSpaceCount  = 0;\r
-  for (TargetString = WString; *TargetString != L'\0'; TargetString++) {\r
-    if (*TargetString == L'a' && *(TargetString + 1) == L'b' && *(TargetString + 2) == L'c') {\r
-;//       CpuBreakpoint ();\r
-    }\r
 \r
+  for (TargetString = WString; *TargetString != L'\0'; TargetString++) {\r
     if (*TargetString == CHAR_BACKSPACE) {\r
       BackSpaceCount++;\r
     }\r
-\r
   }\r
 \r
   if (BackSpaceCount == 0) {\r
@@ -4359,14 +4408,6 @@ ConSplitterTextOutSetMode (
                                                     Private->TextOutList[Index].TextOut,\r
                                                     TextOutModeMap[Index]\r
                                                     );\r
-    //\r
-    // If this console device is based on a GOP or UGA device, then sync up the bitmap from\r
-    // the GOP/UGA splitter and reclear the text portion of the display in the new mode.\r
-    //\r
-    if ((Private->TextOutList[Index].GraphicsOutput != NULL) || (Private->TextOutList[Index].UgaDraw != NULL)) {\r
-      Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);\r
-    }\r
-\r
     if (EFI_ERROR (Status)) {\r
       ReturnStatus = Status;\r
     }\r