]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
MdeModulePkg: Fix parameter verification for SetAttribute
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
index 2419b7c4a8dcc777e1e2d189a974aa01fccfd2a4..037fb5adaa22fe1199593c57e00eac366b49e335 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This is the main routine for initializing the Graphics Console support routines.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -35,7 +35,7 @@ GRAPHICS_CONSOLE_DEV    mGraphicsConsoleDevTemplate = {
   },\r
   {\r
     0,\r
-    0,\r
+    -1,\r
     EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK),\r
     0,\r
     0,\r
@@ -57,7 +57,7 @@ GRAPHICS_CONSOLE_MODE_DATA mGraphicsConsoleModeData[] = {
 EFI_HII_DATABASE_PROTOCOL   *mHiiDatabase;\r
 EFI_HII_FONT_PROTOCOL       *mHiiFont;\r
 EFI_HII_HANDLE              mHiiHandle;\r
-EFI_EVENT                   mHiiRegistration;\r
+VOID                        *mHiiRegistration;\r
 \r
 EFI_GUID             mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};\r
 \r
@@ -453,8 +453,8 @@ GraphicsConsoleControllerDriverStart (
                            &Info\r
                            );\r
         if (!EFI_ERROR (Status)) {\r
-          if ((Info->HorizontalResolution >= HorizontalResolution) &&\r
-              (Info->VerticalResolution >= VerticalResolution)) {\r
+          if ((Info->HorizontalResolution > HorizontalResolution) ||\r
+              ((Info->HorizontalResolution == HorizontalResolution) && (Info->VerticalResolution > VerticalResolution))) {\r
             HorizontalResolution = Info->HorizontalResolution;\r
             VerticalResolution   = Info->VerticalResolution;\r
             ModeNumber           = ModeIndex;\r
@@ -497,6 +497,19 @@ GraphicsConsoleControllerDriverStart (
         }\r
       }\r
     }\r
+    if (ModeNumber != Private->GraphicsOutput->Mode->Mode) {\r
+      //\r
+      // Current graphics mode is not set or is not set to the mode which we has found,\r
+      // set the new graphic mode.\r
+      //\r
+      Status = Private->GraphicsOutput->SetMode (Private->GraphicsOutput, ModeNumber);\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // The mode set operation failed\r
+        //\r
+        goto Error;\r
+      }\r
+    }\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // At first try to set user-defined resolution\r
@@ -533,12 +546,11 @@ GraphicsConsoleControllerDriverStart (
           goto Error;\r
         }\r
       }\r
-    } else {\r
-      Status = EFI_UNSUPPORTED;\r
-      goto Error;\r
     }\r
   }\r
 \r
+  DEBUG ((EFI_D_INFO, "GraphicsConsole video resolution %d x %d\n", HorizontalResolution, VerticalResolution));\r
+\r
   //\r
   // Initialize the mode which GraphicsConsole supports.\r
   //\r
@@ -559,16 +571,15 @@ GraphicsConsoleControllerDriverStart (
   //\r
   Private->SimpleTextOutputMode.MaxMode = (INT32) MaxMode;\r
 \r
-  //\r
-  // Determine the number of text modes that this protocol can support\r
-  //\r
-  Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);\r
-  if (EFI_ERROR (Status)) {\r
-    goto Error;\r
-  }\r
-\r
   DEBUG_CODE_BEGIN ();\r
-    GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");\r
+    Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);\r
+    if (EFI_ERROR (Status)) {\r
+      goto Error;\r
+    }\r
+    Status = GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");\r
+    if (EFI_ERROR (Status)) {\r
+      goto Error;\r
+    }  \r
   DEBUG_CODE_END ();\r
 \r
   //\r
@@ -758,6 +769,7 @@ CheckModeSupported (
           //\r
           // If video device has been set to this mode, we do not need to SetMode again\r
           //\r
+          FreePool (Info);\r
           break;\r
         } else {\r
           Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);\r
@@ -794,42 +806,14 @@ EfiLocateHiiProtocol (
   VOID\r
   )\r
 {\r
-  EFI_HANDLE  Handle;\r
-  UINTN       Size;\r
   EFI_STATUS  Status;\r
 \r
-  //\r
-  // There should only be one - so buffer size is this\r
-  //\r
-  Size = sizeof (EFI_HANDLE);\r
-\r
-  Status = gBS->LocateHandle (\r
-                  ByProtocol,\r
-                  &gEfiHiiDatabaseProtocolGuid,\r
-                  NULL,\r
-                  &Size,\r
-                  (VOID **) &Handle\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = gBS->HandleProtocol (\r
-                  Handle,\r
-                  &gEfiHiiDatabaseProtocolGuid,\r
-                  (VOID **) &mHiiDatabase\r
-                  );\r
-\r
+  Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &mHiiDatabase);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  Status = gBS->HandleProtocol (\r
-                  Handle,\r
-                  &gEfiHiiFontProtocolGuid,\r
-                  (VOID **) &mHiiFont\r
-                  );\r
+  Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &mHiiFont);\r
   return Status;\r
 }\r
 \r
@@ -862,8 +846,13 @@ GraphicsConsoleConOutReset (
   IN  BOOLEAN                          ExtendedVerification\r
   )\r
 {\r
-  This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));\r
-  return This->SetMode (This, 0);\r
+  EFI_STATUS    Status;\r
+  Status = This->SetMode (This, 0);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  Status = This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));\r
+  return Status;\r
 }\r
 \r
 \r
@@ -916,8 +905,15 @@ GraphicsConsoleConOutOutputString (
   INT32                 OriginAttribute;\r
   EFI_TPL               OldTpl;\r
 \r
-  Status = EFI_SUCCESS;\r
+  if (This->Mode->Mode == -1) {\r
+    //\r
+    // If current mode is not valid, return error.\r
+    //\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
+  Status = EFI_SUCCESS;\r
+  \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
   //\r
   // Current mode\r
@@ -1299,7 +1295,6 @@ GraphicsConsoleConOutSetMode (
   Private   = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
   GraphicsOutput = Private->GraphicsOutput;\r
   UgaDraw   = Private->UgaDraw;\r
-  ModeData  = &(Private->ModeData[ModeNumber]);\r
 \r
   //\r
   // Make sure the requested mode number is supported\r
@@ -1308,38 +1303,26 @@ GraphicsConsoleConOutSetMode (
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
   }\r
+  \r
+  ModeData  = &(Private->ModeData[ModeNumber]);\r
 \r
   if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
   }\r
-  //\r
-  // Attempt to allocate a line buffer for the requested mode number\r
-  //\r
-  NewLineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ModeData->Columns * EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT);\r
 \r
-  if (NewLineBuffer == NULL) {\r
-    //\r
-    // The new line buffer could not be allocated, so return an error.\r
-    // No changes to the state of the current console have been made, so the current console is still valid\r
-    //\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto Done;\r
-  }\r
   //\r
   // If the mode has been set at least one other time, then LineBuffer will not be NULL\r
   //\r
   if (Private->LineBuffer != NULL) {\r
-    //\r
-    // Clear the current text window on the current graphics console\r
-    //\r
-    This->ClearScreen (This);\r
-\r
     //\r
     // If the new mode is the same as the old mode, then just return EFI_SUCCESS\r
     //\r
     if ((INT32) ModeNumber == This->Mode->Mode) {\r
-      FreePool (NewLineBuffer);\r
+      //\r
+      // Clear the current text window on the current graphics console\r
+      //\r
+      This->ClearScreen (This);\r
       Status = EFI_SUCCESS;\r
       goto Done;\r
     }\r
@@ -1351,6 +1334,21 @@ GraphicsConsoleConOutSetMode (
 \r
     FreePool (Private->LineBuffer);\r
   }\r
+\r
+  //\r
+  // Attempt to allocate a line buffer for the requested mode number\r
+  //\r
+  NewLineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ModeData->Columns * EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT);\r
+\r
+  if (NewLineBuffer == NULL) {\r
+    //\r
+    // The new line buffer could not be allocated, so return an error.\r
+    // No changes to the state of the current console have been made, so the current console is still valid\r
+    //\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Done;\r
+  }\r
+\r
   //\r
   // Assign the current line buffer to the newly allocated line buffer\r
   //\r
@@ -1478,7 +1476,14 @@ GraphicsConsoleConOutSetAttribute (
 {\r
   EFI_TPL               OldTpl;\r
 \r
-  if ((Attribute | 0xFF) != 0xFF) {\r
+  if ((Attribute | 0x7F) != 0x7F) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (This->Mode->Mode == -1) {\r
+    //\r
+    // If current mode is not valid, return error.\r
+    //\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -1527,6 +1532,13 @@ GraphicsConsoleConOutClearScreen (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
   EFI_TPL                       OldTpl;\r
+  \r
+  if (This->Mode->Mode == -1) {\r
+    //\r
+    // If current mode is not valid, return error.\r
+    //\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
@@ -1609,6 +1621,13 @@ GraphicsConsoleConOutSetCursorPosition (
   EFI_STATUS                  Status;\r
   EFI_TPL                     OldTpl;\r
 \r
+  if (This->Mode->Mode == -1) {\r
+    //\r
+    // If current mode is not valid, return error.\r
+    //\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   Status = EFI_SUCCESS;\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
@@ -1650,6 +1669,8 @@ Done:
                                 the cursor is set to be invisible.\r
 \r
   @retval EFI_SUCCESS           The operation completed successfully.\r
+  @retval EFI_UNSUPPORTED       The output device's mode is not currently in a\r
+                                defined text mode.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1661,6 +1682,13 @@ GraphicsConsoleConOutEnableCursor (
 {\r
   EFI_TPL               OldTpl;\r
 \r
+  if (This->Mode->Mode == -1) {\r
+    //\r
+    // If current mode is not valid, return error.\r
+    //\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
   FlushCursor (This);\r
@@ -2001,7 +2029,9 @@ RegisterFontPackage (
                   NULL,\r
                   (VOID **) &HiiDatabase\r
                   );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
 \r
   //\r
   // Add 4 bytes to the header for entire length for HiiAddPackages use only.\r