]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
Remove hard code video resolution in C code and use PCD PcdVideoHorizontalResolution...
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
index bb279f985027e1cdc5c37b485b11ea604cce86da..553a8146346076d50480e5e9bd351664c64242bd 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 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2011, 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
@@ -239,13 +239,17 @@ GraphicsConsoleControllerDriverStart (
   UINT32                               VerticalResolution;\r
   UINT32                               ColorDepth;\r
   UINT32                               RefreshRate;\r
-  UINT                               ModeIndex;\r
+  UINT32                               ModeIndex;\r
   UINTN                                MaxMode;\r
-  UINTN                                Columns;\r
-  UINTN                                Rows;\r
+  UINTN                                MaxColumns;\r
+  UINTN                                MaxRows;\r
   UINT32                               ModeNumber;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE    *Mode;\r
   GRAPHICS_CONSOLE_MODE_DATA           *ModeData;\r
+  UINTN                                SizeOfInfo;  \r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
+  BOOLEAN                              TextModeFound;\r
+  \r
   ModeNumber = 0;\r
 \r
   //\r
@@ -285,12 +289,8 @@ GraphicsConsoleControllerDriverStart (
     goto Error;\r
   }\r
 \r
-  //\r
-  // If the current mode information can not be retrieved, then attempt to set the default mode\r
-  // of 800x600, 32 bit color, 60 Hz refresh.\r
-  //\r
-  HorizontalResolution  = 800;\r
-  VerticalResolution    = 600;\r
+  HorizontalResolution  = PcdGet32 (PcdVideoHorizontalResolution);\r
+  VerticalResolution    = PcdGet32 (PcdVideoVerticalResolution);\r
 \r
   if (Private->GraphicsOutput != NULL) {\r
     //\r
@@ -298,39 +298,63 @@ GraphicsConsoleControllerDriverStart (
     // for the user-defined mode; if there are multiple video devices,\r
     // graphic console driver will set all the video devices to the same mode.\r
     //\r
-    Status = CheckModeSupported (\r
-                 Private->GraphicsOutput,\r
-                 CURRENT_HORIZONTAL_RESOLUTION,\r
-                 CURRENT_VERTICAL_RESOLUTION,\r
-                 &ModeNumber\r
-                 );\r
-    if (!EFI_ERROR(Status)) {\r
-      //\r
-      // Update default mode to current mode\r
+    if ((HorizontalResolution == 0x0) || (VerticalResolution == 0x0)) {\r
       //\r
-      HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;\r
-      VerticalResolution   = CURRENT_VERTICAL_RESOLUTION;\r
+      // Find the highest resolution which GOP supports.\r
+      //    \r
+      MaxMode = Private->GraphicsOutput->Mode->MaxMode;\r
+      \r
+      for (ModeIndex = 0; ModeIndex < MaxMode; ModeIndex++) {\r
+        Status = Private->GraphicsOutput->QueryMode (\r
+                           Private->GraphicsOutput,\r
+                           ModeIndex,\r
+                           &SizeOfInfo,\r
+                           &Info\r
+                           );\r
+        if (!EFI_ERROR (Status)) {\r
+          if ((Info->HorizontalResolution >= HorizontalResolution) &&\r
+              (Info->VerticalResolution >= VerticalResolution)) {\r
+            HorizontalResolution = Info->HorizontalResolution;\r
+            VerticalResolution   = Info->VerticalResolution;\r
+            ModeNumber           = ModeIndex;\r
+          }\r
+          FreePool (Info);\r
+        }\r
+      }\r
+      if ((HorizontalResolution == 0x0) || (VerticalResolution == 0x0)) {\r
+        Status = EFI_UNSUPPORTED;\r
+        goto Error;\r
+      }\r
     } else {\r
       //\r
-      // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec\r
+      // Use user-defined resolution\r
       //\r
       Status = CheckModeSupported (\r
                    Private->GraphicsOutput,\r
-                   800,\r
-                   600,\r
+                   HorizontalResolution,\r
+                   VerticalResolution,\r
                    &ModeNumber\r
                    );\r
-    }\r
-\r
-    Mode = Private->GraphicsOutput->Mode;\r
-\r
-    if (EFI_ERROR (Status) || (Mode->MaxMode != 0)) {\r
-      //\r
-      // Set default mode failed or device don't support default mode, then get the current mode information\r
-      //\r
-      HorizontalResolution = Mode->Info->HorizontalResolution;\r
-      VerticalResolution = Mode->Info->VerticalResolution;\r
-      ModeNumber = Mode->Mode;\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec\r
+        //\r
+        Status = CheckModeSupported (\r
+                     Private->GraphicsOutput,\r
+                     800,\r
+                     600,\r
+                     &ModeNumber\r
+                     );\r
+        Mode = Private->GraphicsOutput->Mode;\r
+        if (EFI_ERROR (Status) && Mode->MaxMode != 0) {\r
+          //\r
+          // Set default mode failed or device don't support default mode, then get the current mode information\r
+          //\r
+          HorizontalResolution = Mode->Info->HorizontalResolution;\r
+          VerticalResolution = Mode->Info->VerticalResolution;\r
+          ModeNumber = Mode->Mode;\r
+        }\r
+      }\r
     }\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
@@ -340,22 +364,19 @@ GraphicsConsoleControllerDriverStart (
     RefreshRate           = 60;\r
     Status = Private->UgaDraw->SetMode (\r
                                 Private->UgaDraw,\r
-                                CURRENT_HORIZONTAL_RESOLUTION,\r
-                                CURRENT_VERTICAL_RESOLUTION,\r
+                                HorizontalResolution,\r
+                                VerticalResolution,\r
                                 ColorDepth,\r
                                 RefreshRate\r
                                 );\r
-    if (!EFI_ERROR (Status)) {\r
-      HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;\r
-      VerticalResolution   = CURRENT_VERTICAL_RESOLUTION;\r
-    } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    if (EFI_ERROR (Status)) {\r
       //\r
       // Try to set 800*600 which is required by UEFI/EFI spec\r
       //\r
       Status = Private->UgaDraw->SetMode (\r
                                   Private->UgaDraw,\r
-                                  HorizontalResolution,\r
-                                  VerticalResolution,\r
+                                  800,\r
+                                  600,\r
                                   ColorDepth,\r
                                   RefreshRate\r
                                   );\r
@@ -378,50 +399,67 @@ GraphicsConsoleControllerDriverStart (
   }\r
 \r
   //\r
-  // Add Mode #3 that uses the entire display for user-defined mode\r
+  // Include the existing pre-defined 80x25, 80x50 and 100x31 \r
+  // in mGraphicsConsoleDevTemplate.\r
   //\r
-  Private->ModeData[3].Columns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
-  Private->ModeData[3].Rows    = VerticalResolution / EFI_GLYPH_HEIGHT;\r
+  MaxMode = 3;\r
 \r
   //\r
-  // Add Mode #4 that uses the PCD values\r
+  // Compute the maximum number of text Rows and Columns that this current graphics mode can support\r
   //\r
-  Private->ModeData[4].Columns = (UINTN) PcdGet32 (PcdConOutColumn);\r
-  Private->ModeData[4].Rows    = (UINTN) PcdGet32 (PcdConOutRow);\r
+  MaxColumns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
+  MaxRows    = VerticalResolution / EFI_GLYPH_HEIGHT;\r
 \r
   //\r
-  // Compute the maximum number of text Rows and Columns that this current graphics mode can support\r
+  // Add Mode #3 that uses the entire display for user-defined mode\r
+  //\r
+  Private->ModeData[MaxMode].Columns = MaxColumns;\r
+  Private->ModeData[MaxMode].Rows    = MaxRows;\r
+  MaxMode++;\r
+\r
+  //\r
+  // Add Mode #4 that uses the PCD values\r
   //\r
-  Columns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
-  Rows    = VerticalResolution / EFI_GLYPH_HEIGHT;\r
+  Private->ModeData[MaxMode].Columns = (UINTN) PcdGet32 (PcdConOutColumn);\r
+  Private->ModeData[MaxMode].Rows    = (UINTN) PcdGet32 (PcdConOutRow);  \r
+  if ((Private->ModeData[MaxMode].Columns != 0) && (Private->ModeData[MaxMode].Rows != 0)) {\r
+    MaxMode++;\r
+  }\r
 \r
   //\r
   // Here we make sure that mode 0 is valid\r
   //\r
-  if (Columns < Private->ModeData[0].Columns ||\r
-      Rows < Private->ModeData[0].Rows) {\r
+  if (MaxColumns < Private->ModeData[0].Columns ||\r
+      MaxRows < Private->ModeData[0].Rows) {\r
     //\r
     // 80x25 cannot be supported.\r
     //\r
-    // Fallback to using the PcdConOutColumn and PcdConOutRow\r
-    // for mode 0.  If the PCDs are also to large, then mode 0\r
-    // will be shrunk to fit as needed.\r
+    if ((Private->ModeData[4].Columns != 0) && (Private->ModeData[4].Rows != 0)) {\r
+    //\r
+    // Fallback to using the Mode 4 for mode 0 if PcdConOutColumn and PcdConOutRow\r
+    // are not 0. If the PCDs are also too large, then mode 0\r
+    // will be shrunk to fit as needed. If the PCDs are all 0,\r
+    // then mode 0 will be the entire display.\r
     //\r
-    Private->ModeData[0].Columns = MIN (Private->ModeData[4].Columns, Columns);\r
-    Private->ModeData[0].Rows    = MIN (Private->ModeData[4].Rows, Rows);\r
+      Private->ModeData[0].Columns = MIN (Private->ModeData[4].Columns, MaxColumns);\r
+      Private->ModeData[0].Rows    = MIN (Private->ModeData[4].Rows, MaxRows);\r
+    } else {\r
+      Private->ModeData[0].Columns = MaxColumns;\r
+      Private->ModeData[0].Rows    = MaxRows;\r
+    }\r
   }\r
-\r
-  MaxMode = 0;\r
+  \r
+  TextModeFound = FALSE;\r
   for (ModeIndex = 0; ModeIndex < GRAPHICS_MAX_MODE; ModeIndex++) {\r
     ModeData = &Private->ModeData[ModeIndex];\r
     ModeData->GopWidth      = HorizontalResolution;\r
     ModeData->GopHeight     = VerticalResolution;\r
     ModeData->GopModeNumber = ModeNumber;\r
-    if (Columns >= ModeData->Columns &&\r
-        Rows >= ModeData->Rows) {\r
+    if ((ModeData->Columns != 0) && (ModeData->Rows != 0) &&\r
+        (MaxColumns >= ModeData->Columns) && (MaxRows >= ModeData->Rows)) {\r
       ModeData->DeltaX        = (HorizontalResolution - (ModeData->Columns * EFI_GLYPH_WIDTH)) >> 1;\r
       ModeData->DeltaY        = (VerticalResolution - (ModeData->Rows * EFI_GLYPH_HEIGHT)) >> 1;\r
-      MaxMode = ModeIndex + 1;\r
+      TextModeFound = TRUE;\r
     } else {\r
       ModeData->Columns       = 0;\r
       ModeData->Rows          = 0;\r
@@ -433,7 +471,8 @@ GraphicsConsoleControllerDriverStart (
   //\r
   // See if the resolution was too small to support any text modes\r
   //\r
-  if (MaxMode == 0) {\r
+  if (!TextModeFound) {\r
+    Status = EFI_UNSUPPORTED;\r
     goto Error;\r
   }\r
 \r