]> 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 44282b1f9f78517d44fbedcb2f6c1b548096b86c..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
@@ -49,16 +49,15 @@ GRAPHICS_CONSOLE_MODE_DATA mGraphicsConsoleModeData[] = {
   {100, 31},\r
   //\r
   // New modes can be added here.\r
-  // The last 2 entries are specific for PcdConOutRow x PcdConOutColumn and full screen mode.\r
+  // The last entry is specific for full screen mode.\r
   //\r
-  {0, 0},\r
   {0, 0}\r
 };\r
 \r
 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
@@ -252,12 +251,7 @@ InitializeGraphicsConsoleTextMode (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  //\r
-  // Add PcdConOutColumn and PcdConOutRow to the last second entry.\r
-  //\r
   Count = sizeof (mGraphicsConsoleModeData) / sizeof (GRAPHICS_CONSOLE_MODE_DATA);\r
-  mGraphicsConsoleModeData[Count - 2].Columns = (UINTN) PcdGet32 (PcdConOutColumn);\r
-  mGraphicsConsoleModeData[Count - 2].Rows    = (UINTN) PcdGet32 (PcdConOutRow);\r
 \r
   //\r
   // Compute the maximum number of text Rows and Columns that this current graphics mode can support.\r
@@ -266,6 +260,11 @@ InitializeGraphicsConsoleTextMode (
   MaxColumns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
   MaxRows    = VerticalResolution / EFI_GLYPH_HEIGHT;\r
 \r
+  //\r
+  // According to UEFI spec, all output devices support at least 80x25 text mode.\r
+  //\r
+  ASSERT ((MaxColumns >= 80) && (MaxRows >= 25));\r
+\r
   //\r
   // Add full screen mode to the last entry.\r
   //\r
@@ -290,19 +289,8 @@ InitializeGraphicsConsoleTextMode (
   //\r
   ValidCount = 0;  \r
 \r
-  if ((MaxColumns >= 80) && (MaxRows >= 25)) {\r
-    //\r
-    // 80x25 can be supported.\r
-    //\r
-    NewModeBuffer[ValidCount].Columns = 80;\r
-    NewModeBuffer[ValidCount].Rows    = 25;\r
-  } else {\r
-    //\r
-    // 80x25 cannot be supported, set PCD defined mode.\r
-    //\r
-    NewModeBuffer[ValidCount].Columns = (UINTN) PcdGet32 (PcdConOutColumn);\r
-    NewModeBuffer[ValidCount].Rows    = (UINTN) PcdGet32 (PcdConOutRow);\r
-  }  \r
+  NewModeBuffer[ValidCount].Columns       = 80;\r
+  NewModeBuffer[ValidCount].Rows          = 25;\r
   NewModeBuffer[ValidCount].GopWidth      = HorizontalResolution;\r
   NewModeBuffer[ValidCount].GopHeight     = VerticalResolution;\r
   NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
@@ -465,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
@@ -509,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
@@ -545,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
@@ -571,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
@@ -770,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
@@ -806,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
@@ -874,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
@@ -928,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
@@ -1311,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
@@ -1320,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
@@ -1363,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
@@ -1490,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
@@ -1539,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
@@ -1621,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
@@ -1662,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
@@ -1673,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
@@ -2013,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