]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
add some error check and return.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
index ff4b0c209a0792428ec699a2e0175b86d56694c2..2cf2f3e64d6b10c729419f6026798f5ee37d66d0 100644 (file)
@@ -5,15 +5,15 @@ Remaining Tasks
   Implement optimal automatic Mode creation algorithm\r
   Solve palette issues for mixed graphics and text\r
   When does this protocol reset the palette?\r
-    \r
+\r
 Copyright (c) 2006 - 2007 Intel Corporation. <BR>\r
-All rights reserved. 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
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+All rights reserved. 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
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
@@ -86,17 +86,12 @@ GRAPHICS_CONSOLE_DEV        mGraphicsConsoleDevTemplate = {
   (EFI_HII_HANDLE ) 0\r
 };\r
 \r
-#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
 EFI_HII_DATABASE_PROTOCOL   *mHiiDatabase;\r
 EFI_HII_FONT_PROTOCOL       *mHiiFont;\r
 BOOLEAN                     mFirstAccessFlag = TRUE;\r
 \r
 STATIC EFI_GUID             mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, 0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad};\r
 \r
-#else\r
-EFI_HII_PROTOCOL            *mHii;\r
-#endif\r
-\r
 static CHAR16               mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
 \r
 static EFI_GRAPHICS_OUTPUT_BLT_PIXEL        mEfiColors[16] = {\r
@@ -144,12 +139,13 @@ GraphicsConsoleControllerDriverSupported (
   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
+  EFI_STATUS                   Status;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL     *UgaDraw;\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_UGA_DRAW_PROTOCOL        *UgaDraw;\r
+  EFI_DEVICE_PATH_PROTOCOL     *DevicePath;\r
 \r
-  UgaDraw = NULL;\r
+  GraphicsOutput = NULL;\r
+  UgaDraw        = NULL;\r
   //\r
   // Open the IO Abstraction(s) needed to perform the supported test\r
   //\r
@@ -161,9 +157,8 @@ GraphicsConsoleControllerDriverSupported (
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
-  \r
-  if (EFI_ERROR (Status)) {\r
-    GraphicsOutput = NULL;\r
+\r
+  if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // Open Graphics Output Protocol failed, try to open UGA Draw Protocol\r
     //\r
@@ -175,9 +170,9 @@ GraphicsConsoleControllerDriverSupported (
                     Controller,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
   }\r
 \r
   //\r
@@ -220,7 +215,7 @@ Error:
           This->DriverBindingHandle,\r
           Controller\r
           );\r
-  } else {\r
+  } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     gBS->CloseProtocol (\r
           Controller,\r
           &gEfiUgaDrawProtocolGuid,\r
@@ -268,6 +263,11 @@ GraphicsConsoleControllerDriverStart (
   UINTN                                Columns;\r
   UINTN                                Rows;\r
   UINT32                               ModeNumber;\r
+  EFI_HII_SIMPLE_FONT_PACKAGE_HDR      *SimplifiedFont;\r
+  UINTN                                PackageLength;\r
+  EFI_HII_PACKAGE_LIST_HEADER          *PackageList;\r
+  UINT8                                *Package;\r
+  UINT8                                *Location;\r
 \r
   ModeNumber = 0;\r
 \r
@@ -292,9 +292,8 @@ GraphicsConsoleControllerDriverStart (
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
-  if (EFI_ERROR(Status)) {\r
-    Private->GraphicsOutput = NULL;\r
 \r
+  if (EFI_ERROR(Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     Status = gBS->OpenProtocol (\r
                     Controller,\r
                     &gEfiUgaDrawProtocolGuid,\r
@@ -303,41 +302,44 @@ GraphicsConsoleControllerDriverStart (
                     Controller,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     );\r
-    if (EFI_ERROR (Status)) {\r
-      goto Error;\r
-    }\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
   }\r
 \r
   NarrowFontSize  = ReturnNarrowFontSize ();\r
 \r
-#if 1\r
   if (mFirstAccessFlag) {\r
-    HiiLibAddFontPackageToHiiDatabase (NarrowFontSize, (UINT8 *) UsStdNarrowGlyphData, &mFontPackageListGuid, &(Private->HiiHandle));\r
-    mFirstAccessFlag = FALSE;\r
-  }\r
-#else\r
-  FontPack        = AllocateZeroPool (sizeof (EFI_HII_FONT_PACK) + NarrowFontSize);\r
-  ASSERT (FontPack);\r
-\r
-  FontPack->Header.Length         = (UINT32) (sizeof (EFI_HII_FONT_PACK) + NarrowFontSize);\r
-  FontPack->Header.Type           = EFI_HII_FONT;\r
-  FontPack->NumberOfNarrowGlyphs  = (UINT16) (NarrowFontSize / sizeof (EFI_NARROW_GLYPH));\r
+    //\r
+    // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only.\r
+    // Looks ugly. Might be updated when font tool is ready.\r
+    //\r
+    PackageLength   = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + NarrowFontSize + 4;\r
+    Package = AllocateZeroPool (PackageLength);\r
+    if (Package == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (Package, &PackageLength, 4);\r
+    SimplifiedFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR*) (Package + 4);\r
+    SimplifiedFont->Header.Length        = (UINT32) (PackageLength - 4);\r
+    SimplifiedFont->Header.Type          = EFI_HII_PACKAGE_SIMPLE_FONTS;\r
+    SimplifiedFont->NumberOfNarrowGlyphs = (UINT16) (NarrowFontSize / sizeof (EFI_NARROW_GLYPH));\r
 \r
-  Location                        = (UINT8 *) (&FontPack->NumberOfWideGlyphs + sizeof (UINT8));\r
-  CopyMem (Location, UsStdNarrowGlyphData, NarrowFontSize);\r
+    Location = (UINT8 *) (&SimplifiedFont->NumberOfWideGlyphs + 1);\r
+    CopyMem (Location, UsStdNarrowGlyphData, NarrowFontSize);\r
 \r
-  //\r
-  // Register our Fonts into the global database\r
-  //\r
-  Package = PreparePackages (1, NULL, FontPack);\r
-  mHii->NewPack (mHii, Package, &(Private->HiiHandle));\r
-  FreePool (Package);\r
+    //\r
+    // Add this simplified font package to a package list then install it.\r
+    //\r
+    PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package);\r
+    Status = mHiiDatabase->NewPackageList (mHiiDatabase, PackageList, NULL, &(Private->HiiHandle));\r
+    ASSERT_EFI_ERROR (Status);\r
+    SafeFreePool (PackageList);\r
+    SafeFreePool (Package);\r
 \r
-  //\r
-  // Free the font database\r
-  //\r
-  FreePool (FontPack);\r
-#endif\r
+    mFirstAccessFlag = FALSE;\r
+  }\r
   //\r
   // If the current mode information can not be retrieved, then attemp to set the default mode\r
   // of 800x600, 32 bit colot, 60 Hz refresh.\r
@@ -347,13 +349,13 @@ GraphicsConsoleControllerDriverStart (
 \r
   if (Private->GraphicsOutput != NULL) {\r
     //\r
-    // The console is build on top of Graphics Output Protocol, find the mode number \r
+    // The console is build on top of Graphics Output Protocol, find the mode number\r
     // 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
+                 Private->GraphicsOutput,\r
+                 CURRENT_HORIZONTAL_RESOLUTION,\r
                  CURRENT_VERTICAL_RESOLUTION,\r
                  &ModeNumber\r
                  );\r
@@ -368,9 +370,9 @@ GraphicsConsoleControllerDriverStart (
       // 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
+                   Private->GraphicsOutput,\r
+                   800,\r
+                   600,\r
                    &ModeNumber\r
                    );\r
     }\r
@@ -383,7 +385,7 @@ GraphicsConsoleControllerDriverStart (
       VerticalResolution = Private->GraphicsOutput->Mode->Info->VerticalResolution;\r
       ModeNumber = Private->GraphicsOutput->Mode->Mode;\r
     }\r
-  } else {\r
+  } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // At first try to set user-defined resolution\r
     //\r
@@ -399,7 +401,7 @@ GraphicsConsoleControllerDriverStart (
     if (!EFI_ERROR (Status)) {\r
       HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;\r
       VerticalResolution   = CURRENT_VERTICAL_RESOLUTION;\r
-    } else {\r
+    } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
       //\r
       // Try to set 800*600 which is required by UEFI/EFI spec\r
       //\r
@@ -422,6 +424,9 @@ GraphicsConsoleControllerDriverStart (
           goto Error;\r
         }\r
       }\r
+    } else {\r
+      Status = EFI_UNSUPPORTED;\r
+      goto Error;\r
     }\r
   }\r
 \r
@@ -473,11 +478,11 @@ GraphicsConsoleControllerDriverStart (
     Private->ModeData[MaxMode].DeltaY     = 0;\r
     MaxMode++;\r
   }\r
-  \r
+\r
   //\r
   // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)\r
   //\r
-  if (Columns >= 100 && Rows >= 31) {  \r
+  if (Columns >= 100 && Rows >= 31) {\r
     Private->ModeData[MaxMode].GopWidth   = HorizontalResolution;\r
     Private->ModeData[MaxMode].GopHeight  = VerticalResolution;\r
     Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
@@ -491,7 +496,7 @@ GraphicsConsoleControllerDriverStart (
   //\r
   if (HorizontalResolution > 800 && VerticalResolution > 600) {\r
     Private->ModeData[MaxMode].Columns    = HorizontalResolution/GLYPH_WIDTH;\r
-    Private->ModeData[MaxMode].Rows       = VerticalResolution/GLYPH_HEIGHT;    \r
+    Private->ModeData[MaxMode].Rows       = VerticalResolution/GLYPH_HEIGHT;\r
     Private->ModeData[MaxMode].GopWidth   = HorizontalResolution;\r
     Private->ModeData[MaxMode].GopHeight  = VerticalResolution;\r
     Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
@@ -499,7 +504,7 @@ GraphicsConsoleControllerDriverStart (
     Private->ModeData[MaxMode].DeltaY     = (VerticalResolution % GLYPH_HEIGHT) >> 1;\r
     MaxMode++;\r
   }\r
-    \r
+\r
   //\r
   // Update the maximum number of modes\r
   //\r
@@ -539,7 +544,7 @@ Error:
             This->DriverBindingHandle,\r
             Controller\r
             );\r
-    } else {\r
+    } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
       gBS->CloseProtocol (\r
             Controller,\r
             &gEfiUgaDrawProtocolGuid,\r
@@ -606,7 +611,7 @@ GraphicsConsoleControllerDriverStop (
             This->DriverBindingHandle,\r
             Controller\r
             );\r
-    } else {\r
+    } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
       gBS->CloseProtocol (\r
             Controller,\r
             &gEfiUgaDrawProtocolGuid,\r
@@ -618,12 +623,10 @@ GraphicsConsoleControllerDriverStop (
     //\r
     // Remove the font pack\r
     //\r
-#if 1\r
-    HiiLibRemovePackages (Private->HiiHandle);\r
-    mFirstAccessFlag = TRUE;\r
-#else    \r
-    mHii->RemovePack (mHii, Private->HiiHandle);\r
-#endif\r
+    if (Private->HiiHandle != NULL) {\r
+      HiiLibRemovePackages (Private->HiiHandle);\r
+      mFirstAccessFlag = TRUE;\r
+    }\r
 \r
     //\r
     // Free our instance data\r
@@ -647,11 +650,11 @@ CheckModeSupported (
 {\r
   UINT32     ModeNumber;\r
   EFI_STATUS Status;\r
-  UINTN      SizeOfInfo;  \r
+  UINTN      SizeOfInfo;\r
   EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
-    \r
+\r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   for (ModeNumber = 0; ModeNumber < GraphicsOutput->Mode->MaxMode; ModeNumber++) {\r
     Status = GraphicsOutput->QueryMode (\r
                        GraphicsOutput,\r
@@ -671,13 +674,13 @@ CheckModeSupported (
       gBS->FreePool (Info);\r
     }\r
   }\r
-  \r
+\r
   if (ModeNumber == GraphicsOutput->Mode->MaxMode) {\r
     Status = EFI_UNSUPPORTED;\r
   }\r
-  \r
+\r
   *CurrentModeNumber = ModeNumber;\r
-  return Status; \r
+  return Status;\r
 }\r
 \r
 EFI_STATUS\r
@@ -699,8 +702,6 @@ EfiLocateHiiProtocol (
   UINTN       Size;\r
   EFI_STATUS  Status;\r
 \r
-#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
-\r
   //\r
   // There should only be one - so buffer size is this\r
   //\r
@@ -734,33 +735,6 @@ EfiLocateHiiProtocol (
                   (VOID **) &mHiiFont\r
                   );\r
   return Status;\r
-#else\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
-                  &gEfiHiiProtocolGuid,\r
-                  NULL,\r
-                  &Size,\r
-                  &Handle\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = gBS->HandleProtocol (\r
-                  Handle,\r
-                  &gEfiHiiProtocolGuid,\r
-                  &mHii\r
-                  );\r
-\r
-  return Status;\r
-#endif\r
 }\r
 \r
 //\r
@@ -774,27 +748,27 @@ GraphicsConsoleConOutReset (
   )\r
 /*++\r
   Routine Description:\r
-  \r
+\r
     Implements SIMPLE_TEXT_OUTPUT.Reset().\r
-    If ExtendeVerification is TRUE, then perform dependent Graphics Console \r
+    If ExtendeVerification is TRUE, then perform dependent Graphics Console\r
     device reset, and set display mode to mode 0.\r
     If ExtendedVerification is FALSE, only set display mode to mode 0.\r
-  \r
+\r
   Arguments:\r
-  \r
+\r
     This - Indicates the calling context.\r
-    \r
+\r
     ExtendedVerification - Indicates that the driver may perform a more exhaustive\r
                            verification operation of the device during reset.\r
-        \r
+\r
   Returns:\r
-  \r
+\r
     EFI_SUCCESS\r
-       The reset operation succeeds.   \r
-    \r
+       The reset operation succeeds.\r
+\r
     EFI_DEVICE_ERROR\r
-      The Graphics Console is not functioning correctly \r
-                \r
+      The Graphics Console is not functioning correctly\r
+\r
 --*/\r
 {\r
   This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));\r
@@ -809,31 +783,31 @@ GraphicsConsoleConOutOutputString (
   )\r
 /*++\r
   Routine Description:\r
-  \r
+\r
     Implements SIMPLE_TEXT_OUTPUT.OutputString().\r
-    The Unicode string will be converted to Glyphs and will be \r
+    The Unicode string will be converted to Glyphs and will be\r
     sent to the Graphics Console.\r
-    \r
-  \r
+\r
+\r
   Arguments:\r
-  \r
+\r
     This - Indicates the calling context.\r
-    \r
-    WString - The Null-terminated Unicode string to be displayed on \r
+\r
+    WString - The Null-terminated Unicode string to be displayed on\r
               the Graphics Console.\r
-        \r
+\r
   Returns:\r
-  \r
+\r
     EFI_SUCCESS\r
-       The string is output successfully.   \r
-    \r
+       The string is output successfully.\r
+\r
     EFI_DEVICE_ERROR\r
       The Graphics Console failed to send the string out.\r
-      \r
+\r
     EFI_WARN_UNKNOWN_GLYPH\r
-      Indicates that some of the characters in the Unicode string could not \r
-      be rendered and are skipped.          \r
-                \r
+      Indicates that some of the characters in the Unicode string could not\r
+      be rendered and are skipped.\r
+\r
 --*/\r
 {\r
   GRAPHICS_CONSOLE_DEV  *Private;\r
@@ -956,7 +930,7 @@ GraphicsConsoleConOutOutputString (
                     GLYPH_HEIGHT,\r
                     Delta\r
                     );\r
-        } else {\r
+        } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
           //\r
           // Scroll Screen Up One Row\r
           //\r
@@ -1113,45 +1087,38 @@ GraphicsConsoleConOutTestString (
   )\r
 /*++\r
   Routine Description:\r
-  \r
+\r
     Implements SIMPLE_TEXT_OUTPUT.TestString().\r
     If one of the characters in the *Wstring is\r
     neither valid valid Unicode drawing characters,\r
     not ASCII code, then this function will return\r
     EFI_UNSUPPORTED.\r
-        \r
-  \r
+\r
+\r
   Arguments:\r
-  \r
+\r
     This - Indicates the calling context.\r
-    \r
+\r
     WString - The Null-terminated Unicode string to be tested.\r
-        \r
+\r
   Returns:\r
-  \r
+\r
     EFI_SUCCESS\r
-       The Graphics Console is capable of rendering the output string. \r
-    \r
+       The Graphics Console is capable of rendering the output string.\r
+\r
     EFI_UNSUPPORTED\r
-      Some of the characters in the Unicode string cannot be rendered.      \r
-                \r
+      Some of the characters in the Unicode string cannot be rendered.\r
+\r
 --*/\r
 {\r
   EFI_STATUS            Status;\r
   UINT16                Count;\r
 \r
-#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
   EFI_IMAGE_OUTPUT      *Blt = NULL;\r
-#else\r
-  UINT16                GlyphWidth;\r
-  UINT32                GlyphStatus = 0;\r
-  GLYPH_UNION           *Glyph;  \r
-#endif\r
 \r
   Count = 0;\r
 \r
   while (WString[Count] != 0) {\r
-#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
     Status = mHiiFont->GetGlyph (\r
                          mHiiFont,\r
                          WString[Count],\r
@@ -1162,16 +1129,7 @@ GraphicsConsoleConOutTestString (
     SafeFreePool (Blt);\r
     Blt = NULL;\r
     Count++;\r
-#else\r
-    Status = mHii->GetGlyph (\r
-                    mHii,\r
-                    WString,\r
-                    &Count,\r
-                    (UINT8 **) &Glyph,\r
-                    &GlyphWidth,\r
-                    &GlyphStatus\r
-                    );\r
-#endif\r
+\r
     if (EFI_ERROR (Status)) {\r
       return EFI_UNSUPPORTED;\r
     }\r
@@ -1190,45 +1148,45 @@ GraphicsConsoleConOutQueryMode (
   )\r
 /*++\r
   Routine Description:\r
-  \r
+\r
     Implements SIMPLE_TEXT_OUTPUT.QueryMode().\r
     It returnes information for an available text mode\r
     that the Graphics Console supports.\r
     In this driver,we only support text mode 80x25, which is\r
     defined as mode 0.\r
-        \r
-  \r
+\r
+\r
   Arguments:\r
-  \r
+\r
     This - Indicates the calling context.\r
-    \r
+\r
     ModeNumber - The mode number to return information on.\r
-        \r
+\r
     Columns - The returned columns of the requested mode.\r
-        \r
-    Rows - The returned rows of the requested mode.                \r
-        \r
+\r
+    Rows - The returned rows of the requested mode.\r
+\r
   Returns:\r
-  \r
+\r
     EFI_SUCCESS\r
-      The requested mode information is returned. \r
-    \r
+      The requested mode information is returned.\r
+\r
     EFI_UNSUPPORTED\r
-      The mode number is not valid.   \r
-                \r
+      The mode number is not valid.\r
+\r
 --*/\r
 {\r
   GRAPHICS_CONSOLE_DEV  *Private;\r
   EFI_STATUS            Status;\r
   EFI_TPL               OldTpl;\r
-       \r
+\r
   if (ModeNumber >= (UINTN) This->Mode->MaxMode) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   Private   = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
 \r
   *Columns  = Private->ModeData[ModeNumber].Columns;\r
@@ -1253,28 +1211,28 @@ GraphicsConsoleConOutSetMode (
   )\r
 /*++\r
   Routine Description:\r
-  \r
+\r
     Implements SIMPLE_TEXT_OUTPUT.SetMode().\r
     Set the Graphics Console to a specified mode.\r
-    In this driver, we only support mode 0.        \r
-  \r
+    In this driver, we only support mode 0.\r
+\r
   Arguments:\r
-  \r
+\r
     This - Indicates the calling context.\r
-    \r
+\r
     ModeNumber - The text mode to set.\r
-        \r
+\r
   Returns:\r
-  \r
+\r
     EFI_SUCCESS\r
        The requested text mode is set.\r
-       \r
+\r
     EFI_DEVICE_ERROR\r
       The requested text mode cannot be set because of Graphics Console device error.\r
-    \r
+\r
     EFI_UNSUPPORTED\r
-      The text mode number is not valid.       \r
-                \r
+      The text mode number is not valid.\r
+\r
 --*/\r
 {\r
   EFI_STATUS                      Status;\r
@@ -1385,7 +1343,7 @@ GraphicsConsoleConOutSetMode (
                           0\r
                           );\r
     }\r
-  } else {\r
+  } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // Get the current UGA Draw mode information\r
     //\r
@@ -1457,31 +1415,31 @@ GraphicsConsoleConOutSetAttribute (
   )\r
 /*++\r
   Routine Description:\r
-  \r
-    Implements SIMPLE_TEXT_OUTPUT.SetAttribute().       \r
-  \r
+\r
+    Implements SIMPLE_TEXT_OUTPUT.SetAttribute().\r
+\r
   Arguments:\r
-  \r
+\r
     This - Indicates the calling context.\r
-    \r
+\r
     Attrubute - The attribute to set. Only bit0..6 are valid, all other bits\r
                 are undefined and must be zero.\r
-        \r
+\r
   Returns:\r
-  \r
+\r
     EFI_SUCCESS\r
-      The requested attribute is set. \r
-       \r
+      The requested attribute is set.\r
+\r
     EFI_DEVICE_ERROR\r
       The requested attribute cannot be set due to Graphics Console port error.\r
-          \r
+\r
     EFI_UNSUPPORTED\r
-      The attribute requested is not defined by EFI spec.   \r
-                \r
+      The attribute requested is not defined by EFI spec.\r
+\r
 --*/\r
 {\r
   EFI_TPL               OldTpl;\r
-  \r
+\r
   if ((Attribute | 0xFF) != 0xFF) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -1510,27 +1468,27 @@ GraphicsConsoleConOutClearScreen (
   )\r
 /*++\r
   Routine Description:\r
-  \r
+\r
     Implements SIMPLE_TEXT_OUTPUT.ClearScreen().\r
-    It clears the Graphics Console's display to the \r
+    It clears the Graphics Console's display to the\r
     currently selected background color.\r
-        \r
-  \r
+\r
+\r
   Arguments:\r
-  \r
+\r
     This - Indicates the calling context.\r
 \r
   Returns:\r
-  \r
+\r
     EFI_SUCCESS\r
       The operation completed successfully.\r
-       \r
+\r
     EFI_DEVICE_ERROR\r
-      The Graphics Console cannot be cleared due to Graphics Console device error.        \r
-    \r
+      The Graphics Console cannot be cleared due to Graphics Console device error.\r
+\r
     EFI_UNSUPPORTED\r
-      The Graphics Console is not in a valid text mode.       \r
-                \r
+      The Graphics Console is not in a valid text mode.\r
+\r
 --*/\r
 {\r
   EFI_STATUS                    Status;\r
@@ -1563,7 +1521,7 @@ GraphicsConsoleConOutClearScreen (
                         ModeData->GopHeight,\r
                         0\r
                         );\r
-  } else {\r
+  } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     Status = UgaDraw->Blt (\r
                         UgaDraw,\r
                         (EFI_UGA_PIXEL *) (UINTN) &Background,\r
@@ -1576,6 +1534,8 @@ GraphicsConsoleConOutClearScreen (
                         ModeData->GopHeight,\r
                         0\r
                         );\r
+  } else {\r
+    Status = EFI_UNSUPPORTED;\r
   }\r
 \r
   This->Mode->CursorColumn  = 0;\r
@@ -1597,29 +1557,29 @@ GraphicsConsoleConOutSetCursorPosition (
   )\r
 /*++\r
   Routine Description:\r
-  \r
-    Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().          \r
-  \r
+\r
+    Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().\r
+\r
   Arguments:\r
-  \r
+\r
     This - Indicates the calling context.\r
-        \r
+\r
     Column - The row to set cursor to.\r
-        \r
-    Row - The column to set cursor to.                \r
+\r
+    Row - The column to set cursor to.\r
 \r
   Returns:\r
-  \r
+\r
     EFI_SUCCESS\r
       The operation completed successfully.\r
-       \r
+\r
     EFI_DEVICE_ERROR\r
-      The request fails due to Graphics Console device error.        \r
-    \r
+      The request fails due to Graphics Console device error.\r
+\r
     EFI_UNSUPPORTED\r
       The Graphics Console is not in a valid text mode, or the cursor position\r
-      is invalid for current mode.     \r
-                \r
+      is invalid for current mode.\r
+\r
 --*/\r
 {\r
   GRAPHICS_CONSOLE_DEV        *Private;\r
@@ -1665,31 +1625,31 @@ GraphicsConsoleConOutEnableCursor (
   )\r
 /*++\r
   Routine Description:\r
-  \r
+\r
     Implements SIMPLE_TEXT_OUTPUT.EnableCursor().\r
-    In this driver, the cursor cannot be hidden.        \r
-  \r
+    In this driver, the cursor cannot be hidden.\r
+\r
   Arguments:\r
-  \r
+\r
     This - Indicates the calling context.\r
-        \r
+\r
     Visible - If TRUE, the cursor is set to be visible,\r
-              If FALSE, the cursor is set to be invisible.        \r
+              If FALSE, the cursor is set to be invisible.\r
 \r
   Returns:\r
-  \r
+\r
     EFI_SUCCESS\r
       The request is valid.\r
-       \r
+\r
     EFI_UNSUPPORTED\r
-      The Graphics Console does not support a hidden cursor.   \r
-                \r
+      The Graphics Console does not support a hidden cursor.\r
+\r
 --*/\r
 {\r
   EFI_TPL               OldTpl;\r
-  \r
+\r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
-    \r
+\r
   EraseCursor (This);\r
 \r
   This->Mode->CursorVisible = Visible;\r
@@ -1718,7 +1678,6 @@ GetTextColors (
   return EFI_SUCCESS;\r
 }\r
 \r
-#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
 EFI_STATUS\r
 DrawUnicodeWeightAtCursorN (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
@@ -1731,13 +1690,11 @@ DrawUnicodeWeightAtCursorN (
   EFI_IMAGE_OUTPUT                  *Blt;\r
   EFI_STRING                        String;\r
   EFI_FONT_DISPLAY_INFO             *FontInfo;\r
+  EFI_UGA_DRAW_PROTOCOL             *UgaDraw;\r
+  EFI_HII_ROW_INFO                  *RowInfoArray;\r
+  UINTN                             RowInfoArraySize;\r
 \r
   Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
-  //\r
-  // GOP protocol is required in UEFI mode.\r
-  //\r
-  ASSERT (Private->GraphicsOutput != NULL);\r
-\r
   Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
   if (Blt == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -1745,7 +1702,6 @@ DrawUnicodeWeightAtCursorN (
 \r
   Blt->Width        = (UINT16) (Private->ModeData[This->Mode->Mode].GopWidth);\r
   Blt->Height       = (UINT16) (Private->ModeData[This->Mode->Mode].GopHeight);\r
-  Blt->Image.Screen = Private->GraphicsOutput;\r
 \r
   String = AllocateCopyPool ((Count + 1) * sizeof (CHAR16), UnicodeWeight);\r
   if (String == NULL) {\r
@@ -1762,166 +1718,85 @@ DrawUnicodeWeightAtCursorN (
   }\r
   GetTextColors (This, &FontInfo->ForegroundColor, &FontInfo->BackgroundColor);\r
 \r
-  Status = mHiiFont->StringToImage (\r
-                       mHiiFont,\r
-                       EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN,\r
-                       String,\r
-                       FontInfo,\r
-                       &Blt,\r
-                       This->Mode->CursorColumn * GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
-                       This->Mode->CursorRow * GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
-                       NULL,\r
-                       NULL,\r
-                       NULL\r
-                       );\r
-\r
-  SafeFreePool (Blt);\r
-  SafeFreePool (String);\r
-  SafeFreePool (FontInfo);\r
-  return Status;\r
-}\r
-#else\r
-STATIC\r
-EFI_STATUS\r
-DrawUnicodeWeightAtCursorN (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
-  IN  CHAR16                           *UnicodeWeight,\r
-  IN  UINTN                            Count\r
-  )\r
-{\r
-  GRAPHICS_CONSOLE_DEV  *Private;\r
-  EFI_STATUS            Status;\r
-  EFI_STATUS            ReturnStatus;\r
-  GLYPH_UNION           *Glyph;\r
-  GLYPH_UNION           GlyphData;\r
-  INTN                  GlyphX;\r
-  INTN                  GlyphY;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
-  UINTN                 Index;\r
-  UINTN                 ArrayIndex;\r
-  UINTN                 Counts;\r
-  UINT16                GlyphWidth;\r
-  UINT32                GlyphStatus;\r
-\r
-  Private       = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
+  if (Private->GraphicsOutput != NULL) {\r
+    Blt->Image.Screen = Private->GraphicsOutput;\r
 \r
-  ReturnStatus  = EFI_SUCCESS;\r
-  GlyphStatus   = 0;\r
-  GlyphWidth    = 0x08;\r
+    Status = mHiiFont->StringToImage (\r
+                         mHiiFont,\r
+                         EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN,\r
+                         String,\r
+                         FontInfo,\r
+                         &Blt,\r
+                         This->Mode->CursorColumn * GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
+                         This->Mode->CursorRow * GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
+                         NULL,\r
+                         NULL,\r
+                         NULL\r
+                         );\r
 \r
-  GetTextColors (This, &Foreground, &Background);\r
+  } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    ASSERT (Private->UgaDraw!= NULL);\r
 \r
-  Index       = 0;\r
-  ArrayIndex  = 0;\r
-  while (Index < Count) {\r
-    if (This->Mode->Attribute & EFI_WIDE_ATTRIBUTE) {\r
-      GlyphStatus = WIDE_CHAR;\r
-    } else {\r
-      GlyphStatus = NARROW_CHAR;\r
-    }\r
+    UgaDraw = Private->UgaDraw;\r
 \r
-    Status = mHii->GetGlyph (\r
-                    mHii,\r
-                    UnicodeWeight,\r
-                    (UINT16 *) &Index,\r
-                    (UINT8 **) &Glyph,\r
-                    &GlyphWidth,\r
-                    &GlyphStatus\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      ReturnStatus = Status;\r
+    Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+    if (Blt->Image.Bitmap == NULL) {\r
+      SafeFreePool (Blt);\r
+      SafeFreePool (String);\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
-    Counts = 0;\r
-\r
-    CopyMem (&GlyphData, Glyph, sizeof (GLYPH_UNION));\r
+    RowInfoArray = NULL;\r
+    //\r
+    //  StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,\r
+    //  we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.\r
+    //\r
+    Status = mHiiFont->StringToImage (\r
+                          mHiiFont,\r
+                          EFI_HII_IGNORE_IF_NO_GLYPH,\r
+                          String,\r
+                          FontInfo,\r
+                          &Blt,\r
+                          This->Mode->CursorColumn * GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
+                          This->Mode->CursorRow * GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
+                          &RowInfoArray,\r
+                          &RowInfoArraySize,\r
+                          NULL\r
+                          );\r
 \r
-    do {\r
+    if (!EFI_ERROR (Status)) {\r
       //\r
-      // We are creating the second half of the wide character's BLT buffer\r
+      // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will\r
+      // always be 1. ASSERT here to make sure.\r
       //\r
-      if (GlyphWidth == 0x10 && Counts == 1) {\r
-        CopyMem (&GlyphData.NarrowGlyph.GlyphCol1, &Glyph->WideGlyph.GlyphCol2, sizeof (Glyph->WideGlyph.GlyphCol2));\r
-      }\r
-\r
-      Counts++;\r
-\r
-      if (GlyphWidth == 0x10) {\r
-        mHii->GlyphToBlt (\r
-                mHii,\r
-                (UINT8 *) &GlyphData,\r
-                Foreground,\r
-                Background,\r
-                Count * 2,\r
-                GLYPH_WIDTH,\r
-                GLYPH_HEIGHT,\r
-                &Private->LineBuffer[ArrayIndex * GLYPH_WIDTH]\r
-                );\r
-      } else {\r
-        mHii->GlyphToBlt (\r
-                mHii,\r
-                (UINT8 *) &GlyphData,\r
-                Foreground,\r
-                Background,\r
-                Count,\r
-                GLYPH_WIDTH,\r
-                GLYPH_HEIGHT,\r
-                &Private->LineBuffer[ArrayIndex * GLYPH_WIDTH]\r
-                );\r
-      }\r
+      ASSERT (RowInfoArraySize == 1);\r
 \r
-      ArrayIndex++;\r
-\r
-    } while (Counts < 2 && GlyphWidth == 0x10);\r
+      Status = UgaDraw->Blt (\r
+                          UgaDraw,\r
+                          (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r
+                          EfiUgaBltBufferToVideo,\r
+                          This->Mode->CursorColumn * GLYPH_WIDTH  + Private->ModeData[This->Mode->Mode].DeltaX,\r
+                          (This->Mode->CursorRow) * GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
+                          This->Mode->CursorColumn * GLYPH_WIDTH  + Private->ModeData[This->Mode->Mode].DeltaX,\r
+                          (This->Mode->CursorRow) * GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
+                          RowInfoArray[0].LineWidth,\r
+                          RowInfoArray[0].LineHeight,\r
+                          Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                          );\r
+    }\r
 \r
-  }\r
-  //\r
-  // If we are printing Wide characters, treat the BLT as if it is twice as many characters\r
-  //\r
-  if (GlyphWidth == 0x10) {\r
-    Count = Count * 2;\r
-  }\r
-  //\r
-  // Blt a character to the screen\r
-  //\r
-  GlyphX  = This->Mode->CursorColumn * GLYPH_WIDTH;\r
-  GlyphY  = This->Mode->CursorRow * GLYPH_HEIGHT;\r
-  GraphicsOutput = Private->GraphicsOutput;\r
-  UgaDraw = Private->UgaDraw;\r
-  if (GraphicsOutput != NULL) {\r
-    GraphicsOutput->Blt (\r
-              GraphicsOutput,\r
-              Private->LineBuffer,\r
-              EfiBltBufferToVideo,\r
-              0,\r
-              0,\r
-              GlyphX + Private->ModeData[This->Mode->Mode].DeltaX,\r
-              GlyphY + Private->ModeData[This->Mode->Mode].DeltaY,\r
-              GLYPH_WIDTH * Count,\r
-              GLYPH_HEIGHT,\r
-              GLYPH_WIDTH * Count * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
-              );\r
+    SafeFreePool (RowInfoArray);\r
+    SafeFreePool (Blt->Image.Bitmap);\r
   } else {\r
-    UgaDraw->Blt (\r
-              UgaDraw,\r
-              (EFI_UGA_PIXEL *) (UINTN) Private->LineBuffer,\r
-              EfiUgaBltBufferToVideo,\r
-              0,\r
-              0,\r
-              GlyphX + Private->ModeData[This->Mode->Mode].DeltaX,\r
-              GlyphY + Private->ModeData[This->Mode->Mode].DeltaY,\r
-              GLYPH_WIDTH * Count,\r
-              GLYPH_HEIGHT,\r
-              GLYPH_WIDTH * Count * sizeof (EFI_UGA_PIXEL)\r
-              );\r
+    Status = EFI_UNSUPPORTED;\r
   }\r
 \r
-  return ReturnStatus;\r
+  SafeFreePool (Blt);\r
+  SafeFreePool (String);\r
+  SafeFreePool (FontInfo);\r
+  return Status;\r
 }\r
-#endif\r
+\r
 \r
 STATIC\r
 EFI_STATUS\r
@@ -1972,7 +1847,7 @@ EraseCursor (
               GLYPH_HEIGHT,\r
               GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
               );\r
-  } else {\r
+  } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     UgaDraw->Blt (\r
               UgaDraw,\r
               (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
@@ -2013,7 +1888,7 @@ EraseCursor (
               GLYPH_HEIGHT,\r
               GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
               );\r
-  } else {\r
+  } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     UgaDraw->Blt (\r
               UgaDraw,\r
               (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
@@ -2034,9 +1909,9 @@ EraseCursor (
 /**\r
   The user Entry Point for module GraphicsConsole. The user code starts with this function.\r
 \r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
   @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \r
+\r
   @retval EFI_SUCCESS       The entry point is executed successfully.\r
   @retval other             Some error occurs when executing this entry point.\r
 \r
@@ -2067,3 +1942,4 @@ InitializeGraphicsConsole (
   return Status;\r
 }\r
 \r
+\r