]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
index 4de8009bdfefd5d132b927871c7ac656f1299ce2..b895dafedeaab9516df3fae3f50a21d27ce003c6 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   This is the main routine for initializing the Graphics Console support routines.\r
 \r
 /** @file\r
   This is the main routine for initializing the Graphics Console support routines.\r
 \r
-Copyright (c) 2006 - 2009 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
+Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
 **/\r
 \r
@@ -17,10 +11,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //\r
 // Graphics Console Device Private Data template\r
 //\r
 //\r
 // Graphics Console Device Private Data template\r
 //\r
-GRAPHICS_CONSOLE_DEV    mGraphicsConsoleDevTemplate = {\r
+GRAPHICS_CONSOLE_DEV  mGraphicsConsoleDevTemplate = {\r
   GRAPHICS_CONSOLE_DEV_SIGNATURE,\r
   GRAPHICS_CONSOLE_DEV_SIGNATURE,\r
-  (EFI_GRAPHICS_OUTPUT_PROTOCOL *) NULL,\r
-  (EFI_UGA_DRAW_PROTOCOL *) NULL,\r
+  (EFI_GRAPHICS_OUTPUT_PROTOCOL *)NULL,\r
+  (EFI_UGA_DRAW_PROTOCOL *)NULL,\r
   {\r
     GraphicsConsoleConOutReset,\r
     GraphicsConsoleConOutOutputString,\r
   {\r
     GraphicsConsoleConOutReset,\r
     GraphicsConsoleConOutOutputString,\r
@@ -31,65 +25,74 @@ GRAPHICS_CONSOLE_DEV    mGraphicsConsoleDevTemplate = {
     GraphicsConsoleConOutClearScreen,\r
     GraphicsConsoleConOutSetCursorPosition,\r
     GraphicsConsoleConOutEnableCursor,\r
     GraphicsConsoleConOutClearScreen,\r
     GraphicsConsoleConOutSetCursorPosition,\r
     GraphicsConsoleConOutEnableCursor,\r
-    (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL\r
+    (EFI_SIMPLE_TEXT_OUTPUT_MODE *)NULL\r
   },\r
   {\r
     0,\r
   },\r
   {\r
     0,\r
-    0,\r
-    EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK),\r
+    -1,\r
+    EFI_TEXT_ATTR (EFI_LIGHTGRAY,          EFI_BLACK),\r
     0,\r
     0,\r
     0,\r
     0,\r
-    TRUE\r
-  },\r
-  {\r
-    { 80, 25, 0, 0, 0, 0 },  // Mode 0\r
-    { 80, 50, 0, 0, 0, 0 },  // Mode 1\r
-    { 100,31, 0, 0, 0, 0 },  // Mode 2\r
-    {  0,  0, 0, 0, 0, 0 }   // Mode 3\r
+    FALSE\r
   },\r
   },\r
-  (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL\r
+  (GRAPHICS_CONSOLE_MODE_DATA *)NULL,\r
+  (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)NULL\r
 };\r
 \r
 };\r
 \r
-EFI_HII_DATABASE_PROTOCOL   *mHiiDatabase;\r
-EFI_HII_FONT_PROTOCOL       *mHiiFont;\r
-EFI_HII_HANDLE              mHiiHandle;\r
-EFI_EVENT                   mHiiRegistration;\r
+GRAPHICS_CONSOLE_MODE_DATA  mGraphicsConsoleModeData[] = {\r
+  { 100, 31 },  //  800 x 600\r
+  { 128, 40 },  // 1024 x 768\r
+  { 160, 42 },  // 1280 x 800\r
+  { 240, 56 },  // 1920 x 1080\r
+  //\r
+  // New modes can be added here.\r
+  // The last entry is specific for full screen mode.\r
+  //\r
+  { 0,   0  }\r
+};\r
+\r
+EFI_HII_DATABASE_PROTOCOL  *mHiiDatabase;\r
+EFI_HII_FONT_PROTOCOL      *mHiiFont;\r
+EFI_HII_HANDLE             mHiiHandle;\r
+VOID                       *mHiiRegistration;\r
 \r
 \r
-EFI_GUID             mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};\r
+EFI_GUID  mFontPackageListGuid = {\r
+  0xf5f219d3, 0x7006, 0x4648, { 0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad }\r
+};\r
 \r
 \r
-CHAR16               mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
+CHAR16  mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
 \r
 \r
-EFI_GRAPHICS_OUTPUT_BLT_PIXEL        mEfiColors[16] = {\r
+EFI_GRAPHICS_OUTPUT_BLT_PIXEL  mGraphicsEfiColors[16] = {\r
   //\r
   // B    G    R   reserved\r
   //\r
   //\r
   // B    G    R   reserved\r
   //\r
-  {0x00, 0x00, 0x00, 0x00},  // BLACK\r
-  {0x98, 0x00, 0x00, 0x00},  // LIGHTBLUE\r
-  {0x00, 0x98, 0x00, 0x00},  // LIGHGREEN\r
-  {0x98, 0x98, 0x00, 0x00},  // LIGHCYAN\r
-  {0x00, 0x00, 0x98, 0x00},  // LIGHRED\r
-  {0x98, 0x00, 0x98, 0x00},  // MAGENTA\r
-  {0x00, 0x98, 0x98, 0x00},  // BROWN\r
-  {0x98, 0x98, 0x98, 0x00},  // LIGHTGRAY\r
-  {0x30, 0x30, 0x30, 0x00},  // DARKGRAY - BRIGHT BLACK\r
-  {0xff, 0x00, 0x00, 0x00},  // BLUE\r
-  {0x00, 0xff, 0x00, 0x00},  // LIME\r
-  {0xff, 0xff, 0x00, 0x00},  // CYAN\r
-  {0x00, 0x00, 0xff, 0x00},  // RED\r
-  {0xff, 0x00, 0xff, 0x00},  // FUCHSIA\r
-  {0x00, 0xff, 0xff, 0x00},  // YELLOW\r
-  {0xff, 0xff, 0xff, 0x00}   // WHITE\r
+  { 0x00, 0x00, 0x00, 0x00 },  // BLACK\r
+  { 0x98, 0x00, 0x00, 0x00 },  // LIGHTBLUE\r
+  { 0x00, 0x98, 0x00, 0x00 },  // LIGHGREEN\r
+  { 0x98, 0x98, 0x00, 0x00 },  // LIGHCYAN\r
+  { 0x00, 0x00, 0x98, 0x00 },  // LIGHRED\r
+  { 0x98, 0x00, 0x98, 0x00 },  // MAGENTA\r
+  { 0x00, 0x98, 0x98, 0x00 },  // BROWN\r
+  { 0x98, 0x98, 0x98, 0x00 },  // LIGHTGRAY\r
+  { 0x30, 0x30, 0x30, 0x00 },  // DARKGRAY - BRIGHT BLACK\r
+  { 0xff, 0x00, 0x00, 0x00 },  // BLUE\r
+  { 0x00, 0xff, 0x00, 0x00 },  // LIME\r
+  { 0xff, 0xff, 0x00, 0x00 },  // CYAN\r
+  { 0x00, 0x00, 0xff, 0x00 },  // RED\r
+  { 0xff, 0x00, 0xff, 0x00 },  // FUCHSIA\r
+  { 0x00, 0xff, 0xff, 0x00 },  // YELLOW\r
+  { 0xff, 0xff, 0xff, 0x00 }   // WHITE\r
 };\r
 \r
 };\r
 \r
-EFI_NARROW_GLYPH     mCursorGlyph = {\r
+EFI_NARROW_GLYPH  mCursorGlyph = {\r
   0x0000,\r
   0x00,\r
   0x0000,\r
   0x00,\r
-  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }\r
+  { 0x00,0x00,  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }\r
 };\r
 \r
 };\r
 \r
-CHAR16       SpaceStr[] = { NARROW_CHAR, ' ', 0 };\r
+CHAR16  SpaceStr[] = { NARROW_CHAR, ' ', 0 };\r
 \r
 \r
-EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = {\r
+EFI_DRIVER_BINDING_PROTOCOL  gGraphicsConsoleDriverBinding = {\r
   GraphicsConsoleControllerDriverSupported,\r
   GraphicsConsoleControllerDriverStart,\r
   GraphicsConsoleControllerDriverStop,\r
   GraphicsConsoleControllerDriverSupported,\r
   GraphicsConsoleControllerDriverStart,\r
   GraphicsConsoleControllerDriverStop,\r
@@ -117,15 +120,15 @@ EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = {
 EFI_STATUS\r
 EFIAPI\r
 GraphicsConsoleControllerDriverSupported (\r
 EFI_STATUS\r
 EFIAPI\r
 GraphicsConsoleControllerDriverSupported (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
-  IN EFI_HANDLE                     Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                   Status;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL        *UgaDraw;\r
-  EFI_DEVICE_PATH_PROTOCOL     *DevicePath;\r
+  EFI_STATUS                    Status;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
+  EFI_UGA_DRAW_PROTOCOL         *UgaDraw;\r
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
 \r
   GraphicsOutput = NULL;\r
   UgaDraw        = NULL;\r
 \r
   GraphicsOutput = NULL;\r
   UgaDraw        = NULL;\r
@@ -135,7 +138,7 @@ GraphicsConsoleControllerDriverSupported (
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiGraphicsOutputProtocolGuid,\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiGraphicsOutputProtocolGuid,\r
-                  (VOID **) &GraphicsOutput,\r
+                  (VOID **)&GraphicsOutput,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -148,12 +151,13 @@ GraphicsConsoleControllerDriverSupported (
     Status = gBS->OpenProtocol (\r
                     Controller,\r
                     &gEfiUgaDrawProtocolGuid,\r
     Status = gBS->OpenProtocol (\r
                     Controller,\r
                     &gEfiUgaDrawProtocolGuid,\r
-                    (VOID **) &UgaDraw,\r
+                    (VOID **)&UgaDraw,\r
                     This->DriverBindingHandle,\r
                     Controller,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     );\r
   }\r
                     This->DriverBindingHandle,\r
                     Controller,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     );\r
   }\r
+\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -166,18 +170,18 @@ GraphicsConsoleControllerDriverSupported (
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiDevicePathProtocolGuid,\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiDevicePathProtocolGuid,\r
-                  (VOID **) &DevicePath,\r
+                  (VOID **)&DevicePath,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
   if (!EFI_ERROR (Status)) {\r
     gBS->CloseProtocol (\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
   if (!EFI_ERROR (Status)) {\r
     gBS->CloseProtocol (\r
-          Controller,\r
-          &gEfiDevicePathProtocolGuid,\r
-          This->DriverBindingHandle,\r
-          Controller\r
-          );\r
+           Controller,\r
+           &gEfiDevicePathProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
   } else {\r
     goto Error;\r
   }\r
   } else {\r
     goto Error;\r
   }\r
@@ -193,22 +197,176 @@ GraphicsConsoleControllerDriverSupported (
 Error:\r
   if (GraphicsOutput != NULL) {\r
     gBS->CloseProtocol (\r
 Error:\r
   if (GraphicsOutput != NULL) {\r
     gBS->CloseProtocol (\r
-          Controller,\r
-          &gEfiGraphicsOutputProtocolGuid,\r
-          This->DriverBindingHandle,\r
-          Controller\r
-          );\r
+           Controller,\r
+           &gEfiGraphicsOutputProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     gBS->CloseProtocol (\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     gBS->CloseProtocol (\r
-          Controller,\r
-          &gEfiUgaDrawProtocolGuid,\r
-          This->DriverBindingHandle,\r
-          Controller\r
-          );\r
+           Controller,\r
+           &gEfiUgaDrawProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
   }\r
   }\r
+\r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
+/**\r
+  Initialize all the text modes which the graphics console supports.\r
+\r
+  It returns information for available text modes that the graphics can support.\r
+\r
+  @param[in]  HorizontalResolution     The size of video screen in pixels in the X dimension.\r
+  @param[in]  VerticalResolution       The size of video screen in pixels in the Y dimension.\r
+  @param[in]  GopModeNumber            The graphics mode number which graphics console is based on.\r
+  @param[out] TextModeCount            The total number of text modes that graphics console supports.\r
+  @param[out] TextModeData             The buffer to the text modes column and row information.\r
+                                       Caller is responsible to free it when it's non-NULL.\r
+\r
+  @retval EFI_SUCCESS                  The supporting mode information is returned.\r
+  @retval EFI_INVALID_PARAMETER        The parameters are invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+InitializeGraphicsConsoleTextMode (\r
+  IN UINT32                       HorizontalResolution,\r
+  IN UINT32                       VerticalResolution,\r
+  IN UINT32                       GopModeNumber,\r
+  OUT UINTN                       *TextModeCount,\r
+  OUT GRAPHICS_CONSOLE_MODE_DATA  **TextModeData\r
+  )\r
+{\r
+  UINTN                       Index;\r
+  UINTN                       Count;\r
+  GRAPHICS_CONSOLE_MODE_DATA  *ModeBuffer;\r
+  GRAPHICS_CONSOLE_MODE_DATA  *NewModeBuffer;\r
+  UINTN                       ValidCount;\r
+  UINTN                       ValidIndex;\r
+  UINTN                       MaxColumns;\r
+  UINTN                       MaxRows;\r
+\r
+  if ((TextModeCount == NULL) || (TextModeData == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Count = sizeof (mGraphicsConsoleModeData) / sizeof (GRAPHICS_CONSOLE_MODE_DATA);\r
+\r
+  //\r
+  // Compute the maximum number of text Rows and Columns that this current graphics mode can support.\r
+  // To make graphics console work well, MaxColumns and MaxRows should not be zero.\r
+  //\r
+  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
+  mGraphicsConsoleModeData[Count - 1].Columns = MaxColumns;\r
+  mGraphicsConsoleModeData[Count - 1].Rows    = MaxRows;\r
+\r
+  //\r
+  // Get defined mode buffer pointer.\r
+  //\r
+  ModeBuffer = mGraphicsConsoleModeData;\r
+\r
+  //\r
+  // Here we make sure that the final mode exposed does not include the duplicated modes,\r
+  // and does not include the invalid modes which exceed the max column and row.\r
+  // Reserve 2 modes for 80x25, 80x50 of graphics console.\r
+  //\r
+  NewModeBuffer = AllocateZeroPool (sizeof (GRAPHICS_CONSOLE_MODE_DATA) * (Count + 2));\r
+  ASSERT (NewModeBuffer != NULL);\r
+\r
+  //\r
+  // Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec.\r
+  //\r
+  ValidCount = 0;\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
+  NewModeBuffer[ValidCount].DeltaX        = (HorizontalResolution - (NewModeBuffer[ValidCount].Columns * EFI_GLYPH_WIDTH)) >> 1;\r
+  NewModeBuffer[ValidCount].DeltaY        = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1;\r
+  ValidCount++;\r
+\r
+  if ((MaxColumns >= 80) && (MaxRows >= 50)) {\r
+    NewModeBuffer[ValidCount].Columns = 80;\r
+    NewModeBuffer[ValidCount].Rows    = 50;\r
+    NewModeBuffer[ValidCount].DeltaX  = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
+    NewModeBuffer[ValidCount].DeltaY  = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;\r
+  }\r
+\r
+  NewModeBuffer[ValidCount].GopWidth      = HorizontalResolution;\r
+  NewModeBuffer[ValidCount].GopHeight     = VerticalResolution;\r
+  NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
+  ValidCount++;\r
+\r
+  //\r
+  // Start from mode 2 to put the valid mode other than 80x25 and 80x50 in the output mode buffer.\r
+  //\r
+  for (Index = 0; Index < Count; Index++) {\r
+    if ((ModeBuffer[Index].Columns == 0) || (ModeBuffer[Index].Rows == 0) ||\r
+        (ModeBuffer[Index].Columns > MaxColumns) || (ModeBuffer[Index].Rows > MaxRows))\r
+    {\r
+      //\r
+      // Skip the pre-defined mode which is invalid or exceeds the max column and row.\r
+      //\r
+      continue;\r
+    }\r
+\r
+    for (ValidIndex = 0; ValidIndex < ValidCount; ValidIndex++) {\r
+      if ((ModeBuffer[Index].Columns == NewModeBuffer[ValidIndex].Columns) &&\r
+          (ModeBuffer[Index].Rows == NewModeBuffer[ValidIndex].Rows))\r
+      {\r
+        //\r
+        // Skip the duplicated mode.\r
+        //\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (ValidIndex == ValidCount) {\r
+      NewModeBuffer[ValidCount].Columns       = ModeBuffer[Index].Columns;\r
+      NewModeBuffer[ValidCount].Rows          = ModeBuffer[Index].Rows;\r
+      NewModeBuffer[ValidCount].GopWidth      = HorizontalResolution;\r
+      NewModeBuffer[ValidCount].GopHeight     = VerticalResolution;\r
+      NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
+      NewModeBuffer[ValidCount].DeltaX        = (HorizontalResolution - (NewModeBuffer[ValidCount].Columns * EFI_GLYPH_WIDTH)) >> 1;\r
+      NewModeBuffer[ValidCount].DeltaY        = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1;\r
+      ValidCount++;\r
+    }\r
+  }\r
+\r
+  DEBUG_CODE_BEGIN ();\r
+  for (Index = 0; Index < ValidCount; Index++) {\r
+    DEBUG ((\r
+      DEBUG_INFO,\r
+      "Graphics - Mode %d, Column = %d, Row = %d\n",\r
+      Index,\r
+      NewModeBuffer[Index].Columns,\r
+      NewModeBuffer[Index].Rows\r
+      ));\r
+  }\r
+\r
+  DEBUG_CODE_END ();\r
+\r
+  //\r
+  // Return valid mode count and mode information buffer.\r
+  //\r
+  *TextModeCount = ValidCount;\r
+  *TextModeData  = NewModeBuffer;\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   Start this driver on Controller by opening Graphics Output protocol or\r
 \r
 /**\r
   Start this driver on Controller by opening Graphics Output protocol or\r
@@ -227,22 +385,30 @@ Error:
 EFI_STATUS\r
 EFIAPI\r
 GraphicsConsoleControllerDriverStart (\r
 EFI_STATUS\r
 EFIAPI\r
 GraphicsConsoleControllerDriverStart (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
-  IN EFI_HANDLE                     Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                           Status;\r
-  GRAPHICS_CONSOLE_DEV                 *Private;\r
-  UINT32                               HorizontalResolution;\r
-  UINT32                               VerticalResolution;\r
-  UINT32                               ColorDepth;\r
-  UINT32                               RefreshRate;\r
-  UINTN                                MaxMode;\r
-  UINTN                                Columns;\r
-  UINTN                                Rows;\r
-  UINT32                               ModeNumber;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE    *Mode;\r
+  EFI_STATUS                            Status;\r
+  GRAPHICS_CONSOLE_DEV                  *Private;\r
+  UINT32                                HorizontalResolution;\r
+  UINT32                                VerticalResolution;\r
+  UINT32                                ColorDepth;\r
+  UINT32                                RefreshRate;\r
+  UINT32                                ModeIndex;\r
+  UINTN                                 MaxMode;\r
+  UINT32                                ModeNumber;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE     *Mode;\r
+  UINTN                                 SizeOfInfo;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info;\r
+  INT32                                 PreferMode;\r
+  INT32                                 Index;\r
+  UINTN                                 Column;\r
+  UINTN                                 Row;\r
+  UINTN                                 DefaultColumn;\r
+  UINTN                                 DefaultRow;\r
+\r
   ModeNumber = 0;\r
 \r
   //\r
   ModeNumber = 0;\r
 \r
   //\r
@@ -261,17 +427,17 @@ GraphicsConsoleControllerDriverStart (
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiGraphicsOutputProtocolGuid,\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiGraphicsOutputProtocolGuid,\r
-                  (VOID **) &Private->GraphicsOutput,\r
+                  (VOID **)&Private->GraphicsOutput,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
 \r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
 \r
-  if (EFI_ERROR(Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+  if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     Status = gBS->OpenProtocol (\r
                     Controller,\r
                     &gEfiUgaDrawProtocolGuid,\r
     Status = gBS->OpenProtocol (\r
                     Controller,\r
                     &gEfiUgaDrawProtocolGuid,\r
-                    (VOID **) &Private->UgaDraw,\r
+                    (VOID **)&Private->UgaDraw,\r
                     This->DriverBindingHandle,\r
                     Controller,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
                     This->DriverBindingHandle,\r
                     Controller,\r
                     EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -282,12 +448,8 @@ GraphicsConsoleControllerDriverStart (
     goto Error;\r
   }\r
 \r
     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
 \r
   if (Private->GraphicsOutput != NULL) {\r
     //\r
@@ -295,176 +457,173 @@ 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
     // 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
+    if ((HorizontalResolution == 0x0) || (VerticalResolution == 0x0)) {\r
       //\r
       //\r
-      // Update default mode to current mode\r
+      // Find the highest resolution which GOP supports.\r
       //\r
       //\r
-      HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;\r
-      VerticalResolution   = CURRENT_VERTICAL_RESOLUTION;\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->HorizontalResolution == HorizontalResolution) && (Info->VerticalResolution > VerticalResolution)))\r
+          {\r
+            HorizontalResolution = Info->HorizontalResolution;\r
+            VerticalResolution   = Info->VerticalResolution;\r
+            ModeNumber           = ModeIndex;\r
+          }\r
+\r
+          FreePool (Info);\r
+        }\r
+      }\r
+\r
+      if ((HorizontalResolution == 0x0) || (VerticalResolution == 0x0)) {\r
+        Status = EFI_UNSUPPORTED;\r
+        goto Error;\r
+      }\r
     } else {\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
       //\r
       Status = CheckModeSupported (\r
-                   Private->GraphicsOutput,\r
-                   800,\r
-                   600,\r
-                   &ModeNumber\r
-                   );\r
+                 Private->GraphicsOutput,\r
+                 HorizontalResolution,\r
+                 VerticalResolution,\r
+                 &ModeNumber\r
+                 );\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec\r
+        //\r
+        HorizontalResolution = 800;\r
+        VerticalResolution   = 600;\r
+        Status               = CheckModeSupported (\r
+                                 Private->GraphicsOutput,\r
+                                 HorizontalResolution,\r
+                                 VerticalResolution,\r
+                                 &ModeNumber\r
+                                 );\r
+        Mode = Private->GraphicsOutput->Mode;\r
+        if (EFI_ERROR (Status) && (Mode->MaxMode != 0)) {\r
+          //\r
+          // If set default mode failed or device doesn'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
 \r
     }\r
 \r
-    Mode = Private->GraphicsOutput->Mode;\r
-\r
-    if (EFI_ERROR (Status) || (Mode->MaxMode != 0)) {\r
+    if (EFI_ERROR (Status) || (ModeNumber != Private->GraphicsOutput->Mode->Mode)) {\r
       //\r
       //\r
-      // Set default mode failed or device don't support default mode, then get the current mode information\r
+      // Current graphics mode is not set or is not set to the mode which we have found,\r
+      // set the new graphic mode.\r
       //\r
       //\r
-      HorizontalResolution = Mode->Info->HorizontalResolution;\r
-      VerticalResolution = Mode->Info->VerticalResolution;\r
-      ModeNumber = Mode->Mode;\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
     //\r
     }\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // At first try to set user-defined resolution\r
     //\r
-    ColorDepth            = 32;\r
-    RefreshRate           = 60;\r
-    Status = Private->UgaDraw->SetMode (\r
-                                Private->UgaDraw,\r
-                                CURRENT_HORIZONTAL_RESOLUTION,\r
-                                CURRENT_VERTICAL_RESOLUTION,\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
+    ColorDepth  = 32;\r
+    RefreshRate = 60;\r
+    Status      = Private->UgaDraw->SetMode (\r
+                                      Private->UgaDraw,\r
+                                      HorizontalResolution,\r
+                                      VerticalResolution,\r
+                                      ColorDepth,\r
+                                      RefreshRate\r
+                                      );\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
       //\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
-                                  ColorDepth,\r
-                                  RefreshRate\r
-                                  );\r
+                                   Private->UgaDraw,\r
+                                   800,\r
+                                   600,\r
+                                   ColorDepth,\r
+                                   RefreshRate\r
+                                   );\r
       if (EFI_ERROR (Status)) {\r
         Status = Private->UgaDraw->GetMode (\r
       if (EFI_ERROR (Status)) {\r
         Status = Private->UgaDraw->GetMode (\r
-                                    Private->UgaDraw,\r
-                                    &HorizontalResolution,\r
-                                    &VerticalResolution,\r
-                                    &ColorDepth,\r
-                                    &RefreshRate\r
-                                    );\r
+                                     Private->UgaDraw,\r
+                                     &HorizontalResolution,\r
+                                     &VerticalResolution,\r
+                                     &ColorDepth,\r
+                                     &RefreshRate\r
+                                     );\r
         if (EFI_ERROR (Status)) {\r
           goto Error;\r
         }\r
       }\r
         if (EFI_ERROR (Status)) {\r
           goto Error;\r
         }\r
       }\r
-    } else {\r
-      Status = EFI_UNSUPPORTED;\r
-      goto Error;\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
-  //\r
-  // Compute the maximum number of text Rows and Columns that this current graphics mode can support\r
-  //\r
-  Columns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
-  Rows    = VerticalResolution / EFI_GLYPH_HEIGHT;\r
-\r
-  //\r
-  // See if the mode is too small to support the required 80x25 text mode\r
-  //\r
-  if (Columns < 80 || Rows < 25) {\r
-    goto Error;\r
-  }\r
-  //\r
-  // Add Mode #0 that must be 80x25\r
-  //\r
-  MaxMode = 0;\r
-  Private->ModeData[MaxMode].GopWidth      = HorizontalResolution;\r
-  Private->ModeData[MaxMode].GopHeight     = VerticalResolution;\r
-  Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
-  Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
-  Private->ModeData[MaxMode].DeltaY        = (VerticalResolution - (25 * EFI_GLYPH_HEIGHT)) >> 1;\r
-  MaxMode++;\r
-\r
-  //\r
-  // If it is possible to support Mode #1 - 80x50, than add it as an active mode\r
-  //\r
-  if (Rows >= 50) {\r
-    Private->ModeData[MaxMode].GopWidth      = HorizontalResolution;\r
-    Private->ModeData[MaxMode].GopHeight     = VerticalResolution;\r
-    Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
-    Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
-    Private->ModeData[MaxMode].DeltaY        = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;\r
-    MaxMode++;\r
-  }\r
-\r
-  //\r
-  // If it is not to support Mode #1 - 80x50, then skip it\r
-  //\r
-  if (MaxMode < 2) {\r
-    Private->ModeData[MaxMode].Columns       = 0;\r
-    Private->ModeData[MaxMode].Rows          = 0;\r
-    Private->ModeData[MaxMode].GopWidth      = HorizontalResolution;\r
-    Private->ModeData[MaxMode].GopHeight     = VerticalResolution;\r
-    Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
-    Private->ModeData[MaxMode].DeltaX        = 0;\r
-    Private->ModeData[MaxMode].DeltaY        = 0;\r
-    MaxMode++;\r
-  }\r
+  DEBUG ((DEBUG_INFO, "GraphicsConsole video resolution %d x %d\n", HorizontalResolution, VerticalResolution));\r
 \r
   //\r
 \r
   //\r
-  // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)\r
+  // Initialize the mode which GraphicsConsole supports.\r
   //\r
   //\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
-    Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution - (100 * EFI_GLYPH_WIDTH)) >> 1;\r
-    Private->ModeData[MaxMode].DeltaY        = (VerticalResolution - (31 * EFI_GLYPH_HEIGHT)) >> 1;\r
-    MaxMode++;\r
-  }\r
+  Status = InitializeGraphicsConsoleTextMode (\r
+             HorizontalResolution,\r
+             VerticalResolution,\r
+             ModeNumber,\r
+             &MaxMode,\r
+             &Private->ModeData\r
+             );\r
 \r
 \r
-  //\r
-  // Add Mode #3 that uses the entire display for user-defined mode\r
-  //\r
-  if (HorizontalResolution > 800 && VerticalResolution > 600) {\r
-    Private->ModeData[MaxMode].Columns       = HorizontalResolution/EFI_GLYPH_WIDTH;\r
-    Private->ModeData[MaxMode].Rows          = VerticalResolution/EFI_GLYPH_HEIGHT;\r
-    Private->ModeData[MaxMode].GopWidth      = HorizontalResolution;\r
-    Private->ModeData[MaxMode].GopHeight     = VerticalResolution;\r
-    Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
-    Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution % EFI_GLYPH_WIDTH) >> 1;\r
-    Private->ModeData[MaxMode].DeltaY        = (VerticalResolution % EFI_GLYPH_HEIGHT) >> 1;\r
-    MaxMode++;\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
   }\r
 \r
   //\r
   // Update the maximum number of modes\r
   //\r
   }\r
 \r
   //\r
   // Update the maximum number of modes\r
   //\r
-  Private->SimpleTextOutputMode.MaxMode = (INT32) MaxMode;\r
+  Private->SimpleTextOutputMode.MaxMode = (INT32)MaxMode;\r
 \r
   //\r
 \r
   //\r
-  // Determine the number of text modes that this protocol can support\r
+  // Initialize the Mode of graphics console devices\r
   //\r
   //\r
-  Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);\r
-  if (EFI_ERROR (Status)) {\r
-    goto Error;\r
+  PreferMode    = -1;\r
+  DefaultColumn = PcdGet32 (PcdConOutColumn);\r
+  DefaultRow    = PcdGet32 (PcdConOutRow);\r
+  Column        = 0;\r
+  Row           = 0;\r
+  for (Index = 0; Index < (INT32)MaxMode; Index++) {\r
+    if ((DefaultColumn != 0) && (DefaultRow != 0)) {\r
+      if ((Private->ModeData[Index].Columns == DefaultColumn) &&\r
+          (Private->ModeData[Index].Rows == DefaultRow))\r
+      {\r
+        PreferMode = Index;\r
+        break;\r
+      }\r
+    } else {\r
+      if ((Private->ModeData[Index].Columns > Column) &&\r
+          (Private->ModeData[Index].Rows > Row))\r
+      {\r
+        Column     = Private->ModeData[Index].Columns;\r
+        Row        = Private->ModeData[Index].Rows;\r
+        PreferMode = Index;\r
+      }\r
+    }\r
   }\r
 \r
   }\r
 \r
-  DEBUG_CODE_BEGIN ();\r
-    GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");\r
-  DEBUG_CODE_END ();\r
+  Private->SimpleTextOutput.Mode->Mode = (INT32)PreferMode;\r
+  DEBUG ((DEBUG_INFO, "Graphics Console Started, Mode: %d\n", PreferMode));\r
 \r
   //\r
   // Install protocol interfaces for the Graphics Console device.\r
 \r
   //\r
   // Install protocol interfaces for the Graphics Console device.\r
@@ -501,6 +660,10 @@ Error:
       FreePool (Private->LineBuffer);\r
     }\r
 \r
       FreePool (Private->LineBuffer);\r
     }\r
 \r
+    if (Private->ModeData != NULL) {\r
+      FreePool (Private->ModeData);\r
+    }\r
+\r
     //\r
     // Free private data\r
     //\r
     //\r
     // Free private data\r
     //\r
@@ -531,10 +694,10 @@ Error:
 EFI_STATUS\r
 EFIAPI\r
 GraphicsConsoleControllerDriverStop (\r
 EFI_STATUS\r
 EFIAPI\r
 GraphicsConsoleControllerDriverStop (\r
-  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
-  IN  EFI_HANDLE                    Controller,\r
-  IN  UINTN                         NumberOfChildren,\r
-  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Controller,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
   )\r
 {\r
   EFI_STATUS                       Status;\r
   )\r
 {\r
   EFI_STATUS                       Status;\r
@@ -544,7 +707,7 @@ GraphicsConsoleControllerDriverStop (
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiSimpleTextOutProtocolGuid,\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiSimpleTextOutProtocolGuid,\r
-                  (VOID **) &SimpleTextOutput,\r
+                  (VOID **)&SimpleTextOutput,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
@@ -567,24 +730,28 @@ GraphicsConsoleControllerDriverStop (
     //\r
     if (Private->GraphicsOutput != NULL) {\r
       gBS->CloseProtocol (\r
     //\r
     if (Private->GraphicsOutput != NULL) {\r
       gBS->CloseProtocol (\r
-            Controller,\r
-            &gEfiGraphicsOutputProtocolGuid,\r
-            This->DriverBindingHandle,\r
-            Controller\r
-            );\r
+             Controller,\r
+             &gEfiGraphicsOutputProtocolGuid,\r
+             This->DriverBindingHandle,\r
+             Controller\r
+             );\r
     } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
       gBS->CloseProtocol (\r
     } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
       gBS->CloseProtocol (\r
-            Controller,\r
-            &gEfiUgaDrawProtocolGuid,\r
-            This->DriverBindingHandle,\r
-            Controller\r
-            );\r
+             Controller,\r
+             &gEfiUgaDrawProtocolGuid,\r
+             This->DriverBindingHandle,\r
+             Controller\r
+             );\r
     }\r
 \r
     if (Private->LineBuffer != NULL) {\r
       FreePool (Private->LineBuffer);\r
     }\r
 \r
     }\r
 \r
     if (Private->LineBuffer != NULL) {\r
       FreePool (Private->LineBuffer);\r
     }\r
 \r
+    if (Private->ModeData != NULL) {\r
+      FreePool (Private->ModeData);\r
+    }\r
+\r
     //\r
     // Free our instance data\r
     //\r
     //\r
     // Free our instance data\r
     //\r
@@ -598,7 +765,7 @@ GraphicsConsoleControllerDriverStop (
   Check if the current specific mode supported the user defined resolution\r
   for the Graphics Console device based on Graphics Output Protocol.\r
 \r
   Check if the current specific mode supported the user defined resolution\r
   for the Graphics Console device based on Graphics Output Protocol.\r
 \r
-  If yes, set the graphic devcice's current mode to this specific mode.\r
+  If yes, set the graphic device's current mode to this specific mode.\r
 \r
   @param  GraphicsOutput        Graphics Output Protocol instance pointer.\r
   @param  HorizontalResolution  User defined horizontal resolution\r
 \r
   @param  GraphicsOutput        Graphics Output Protocol instance pointer.\r
   @param  HorizontalResolution  User defined horizontal resolution\r
@@ -621,31 +788,43 @@ CheckModeSupported (
   OUT UINT32                    *CurrentModeNumber\r
   )\r
 {\r
   OUT UINT32                    *CurrentModeNumber\r
   )\r
 {\r
-  UINT32     ModeNumber;\r
-  EFI_STATUS Status;\r
-  UINTN      SizeOfInfo;\r
-  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
-  UINT32     MaxMode;\r
+  UINT32                                ModeNumber;\r
+  EFI_STATUS                            Status;\r
+  UINTN                                 SizeOfInfo;\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info;\r
+  UINT32                                MaxMode;\r
 \r
   Status  = EFI_SUCCESS;\r
   MaxMode = GraphicsOutput->Mode->MaxMode;\r
 \r
   for (ModeNumber = 0; ModeNumber < MaxMode; ModeNumber++) {\r
     Status = GraphicsOutput->QueryMode (\r
 \r
   Status  = EFI_SUCCESS;\r
   MaxMode = GraphicsOutput->Mode->MaxMode;\r
 \r
   for (ModeNumber = 0; ModeNumber < MaxMode; ModeNumber++) {\r
     Status = GraphicsOutput->QueryMode (\r
-                       GraphicsOutput,\r
-                       ModeNumber,\r
-                       &SizeOfInfo,\r
-                       &Info\r
-                       );\r
+                               GraphicsOutput,\r
+                               ModeNumber,\r
+                               &SizeOfInfo,\r
+                               &Info\r
+                               );\r
     if (!EFI_ERROR (Status)) {\r
       if ((Info->HorizontalResolution == HorizontalResolution) &&\r
     if (!EFI_ERROR (Status)) {\r
       if ((Info->HorizontalResolution == HorizontalResolution) &&\r
-          (Info->VerticalResolution == VerticalResolution)) {\r
-        Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);\r
-        if (!EFI_ERROR (Status)) {\r
+          (Info->VerticalResolution == VerticalResolution))\r
+      {\r
+        if ((GraphicsOutput->Mode->Info->HorizontalResolution == HorizontalResolution) &&\r
+            (GraphicsOutput->Mode->Info->VerticalResolution == VerticalResolution))\r
+        {\r
+          //\r
+          // If video device has been set to this mode, we do not need to SetMode again\r
+          //\r
           FreePool (Info);\r
           break;\r
           FreePool (Info);\r
           break;\r
+        } else {\r
+          Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);\r
+          if (!EFI_ERROR (Status)) {\r
+            FreePool (Info);\r
+            break;\r
+          }\r
         }\r
       }\r
         }\r
       }\r
+\r
       FreePool (Info);\r
     }\r
   }\r
       FreePool (Info);\r
     }\r
   }\r
@@ -658,7 +837,6 @@ CheckModeSupported (
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Locate HII Database protocol and HII Font protocol.\r
 \r
 /**\r
   Locate HII Database protocol and HII Font protocol.\r
 \r
@@ -673,42 +851,14 @@ EfiLocateHiiProtocol (
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
-  EFI_HANDLE  Handle;\r
-  UINTN       Size;\r
   EFI_STATUS  Status;\r
 \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
+  Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&mHiiDatabase);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\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
-  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
   return Status;\r
 }\r
 \r
@@ -720,7 +870,7 @@ EfiLocateHiiProtocol (
   Reset the text output device hardware and optionally run diagnostics.\r
 \r
   Implements SIMPLE_TEXT_OUTPUT.Reset().\r
   Reset the text output device hardware and optionally run diagnostics.\r
 \r
   Implements SIMPLE_TEXT_OUTPUT.Reset().\r
-  If ExtendeVerification is TRUE, then perform dependent Graphics Console\r
+  If ExtendedVerification 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
   device reset, and set display mode to mode 0.\r
   If ExtendedVerification is FALSE, only set display mode to mode 0.\r
 \r
@@ -741,10 +891,16 @@ GraphicsConsoleConOutReset (
   IN  BOOLEAN                          ExtendedVerification\r
   )\r
 {\r
   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
-}\r
+  EFI_STATUS  Status;\r
 \r
 \r
+  Status = This->SetMode (This, 0);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));\r
+  return Status;\r
+}\r
 \r
 /**\r
   Write a Unicode string to the output device.\r
 \r
 /**\r
   Write a Unicode string to the output device.\r
@@ -775,25 +931,32 @@ GraphicsConsoleConOutOutputString (
   IN  CHAR16                           *WString\r
   )\r
 {\r
   IN  CHAR16                           *WString\r
   )\r
 {\r
-  GRAPHICS_CONSOLE_DEV  *Private;\r
+  GRAPHICS_CONSOLE_DEV           *Private;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL   *GraphicsOutput;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL   *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
-  INTN                  Mode;\r
-  UINTN                 MaxColumn;\r
-  UINTN                 MaxRow;\r
-  UINTN                 Width;\r
-  UINTN                 Height;\r
-  UINTN                 Delta;\r
-  EFI_STATUS            Status;\r
-  BOOLEAN               Warning;\r
+  EFI_UGA_DRAW_PROTOCOL          *UgaDraw;\r
+  INTN                           Mode;\r
+  UINTN                          MaxColumn;\r
+  UINTN                          MaxRow;\r
+  UINTN                          Width;\r
+  UINTN                          Height;\r
+  UINTN                          Delta;\r
+  EFI_STATUS                     Status;\r
+  BOOLEAN                        Warning;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Foreground;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Background;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Foreground;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Background;\r
-  UINTN                 DeltaX;\r
-  UINTN                 DeltaY;\r
-  UINTN                 Count;\r
-  UINTN                 Index;\r
-  INT32                 OriginAttribute;\r
-  EFI_TPL               OldTpl;\r
+  UINTN                          DeltaX;\r
+  UINTN                          DeltaY;\r
+  UINTN                          Count;\r
+  UINTN                          Index;\r
+  INT32                          OriginAttribute;\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
 \r
   Status = EFI_SUCCESS;\r
 \r
@@ -801,15 +964,15 @@ GraphicsConsoleConOutOutputString (
   //\r
   // Current mode\r
   //\r
   //\r
   // Current mode\r
   //\r
-  Mode      = This->Mode->Mode;\r
-  Private   = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
+  Mode           = This->Mode->Mode;\r
+  Private        = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
   GraphicsOutput = Private->GraphicsOutput;\r
   GraphicsOutput = Private->GraphicsOutput;\r
-  UgaDraw   = Private->UgaDraw;\r
+  UgaDraw        = Private->UgaDraw;\r
 \r
   MaxColumn = Private->ModeData[Mode].Columns;\r
   MaxRow    = Private->ModeData[Mode].Rows;\r
 \r
   MaxColumn = Private->ModeData[Mode].Columns;\r
   MaxRow    = Private->ModeData[Mode].Rows;\r
-  DeltaX    = Private->ModeData[Mode].DeltaX;\r
-  DeltaY    = Private->ModeData[Mode].DeltaY;\r
+  DeltaX    = (UINTN)Private->ModeData[Mode].DeltaX;\r
+  DeltaY    = (UINTN)Private->ModeData[Mode].DeltaY;\r
   Width     = MaxColumn * EFI_GLYPH_WIDTH;\r
   Height    = (MaxRow - 1) * EFI_GLYPH_HEIGHT;\r
   Delta     = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
   Width     = MaxColumn * EFI_GLYPH_WIDTH;\r
   Height    = (MaxRow - 1) * EFI_GLYPH_HEIGHT;\r
   Delta     = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
@@ -819,7 +982,7 @@ GraphicsConsoleConOutOutputString (
   //\r
   GetTextColors (This, &Foreground, &Background);\r
 \r
   //\r
   GetTextColors (This, &Foreground, &Background);\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   Warning = FALSE;\r
 \r
 \r
   Warning = FALSE;\r
 \r
@@ -829,19 +992,18 @@ GraphicsConsoleConOutOutputString (
   OriginAttribute = This->Mode->Attribute;\r
 \r
   while (*WString != L'\0') {\r
   OriginAttribute = This->Mode->Attribute;\r
 \r
   while (*WString != L'\0') {\r
-\r
     if (*WString == CHAR_BACKSPACE) {\r
       //\r
       // If the cursor is at the left edge of the display, then move the cursor\r
       // one row up.\r
       //\r
     if (*WString == CHAR_BACKSPACE) {\r
       //\r
       // If the cursor is at the left edge of the display, then move the cursor\r
       // one row up.\r
       //\r
-      if (This->Mode->CursorColumn == 0 && This->Mode->CursorRow > 0) {\r
+      if ((This->Mode->CursorColumn == 0) && (This->Mode->CursorRow > 0)) {\r
         This->Mode->CursorRow--;\r
         This->Mode->CursorRow--;\r
-        This->Mode->CursorColumn = (INT32) (MaxColumn - 1);\r
+        This->Mode->CursorColumn = (INT32)(MaxColumn - 1);\r
         This->OutputString (This, SpaceStr);\r
         This->OutputString (This, SpaceStr);\r
-        EraseCursor (This);\r
+        FlushCursor (This);\r
         This->Mode->CursorRow--;\r
         This->Mode->CursorRow--;\r
-        This->Mode->CursorColumn = (INT32) (MaxColumn - 1);\r
+        This->Mode->CursorColumn = (INT32)(MaxColumn - 1);\r
       } else if (This->Mode->CursorColumn > 0) {\r
         //\r
         // If the cursor is not at the left edge of the display, then move the cursor\r
       } else if (This->Mode->CursorColumn > 0) {\r
         //\r
         // If the cursor is not at the left edge of the display, then move the cursor\r
@@ -849,107 +1011,100 @@ GraphicsConsoleConOutOutputString (
         //\r
         This->Mode->CursorColumn--;\r
         This->OutputString (This, SpaceStr);\r
         //\r
         This->Mode->CursorColumn--;\r
         This->OutputString (This, SpaceStr);\r
-        EraseCursor (This);\r
+        FlushCursor (This);\r
         This->Mode->CursorColumn--;\r
       }\r
 \r
       WString++;\r
         This->Mode->CursorColumn--;\r
       }\r
 \r
       WString++;\r
-\r
     } else if (*WString == CHAR_LINEFEED) {\r
       //\r
       // If the cursor is at the bottom of the display, then scroll the display one\r
       // row, and do not update the cursor position. Otherwise, move the cursor\r
       // down one row.\r
       //\r
     } else if (*WString == CHAR_LINEFEED) {\r
       //\r
       // If the cursor is at the bottom of the display, then scroll the display one\r
       // row, and do not update the cursor position. Otherwise, move the cursor\r
       // down one row.\r
       //\r
-      if (This->Mode->CursorRow == (INT32) (MaxRow - 1)) {\r
+      if (This->Mode->CursorRow == (INT32)(MaxRow - 1)) {\r
         if (GraphicsOutput != NULL) {\r
           //\r
           // Scroll Screen Up One Row\r
           //\r
           GraphicsOutput->Blt (\r
         if (GraphicsOutput != NULL) {\r
           //\r
           // Scroll Screen Up One Row\r
           //\r
           GraphicsOutput->Blt (\r
-                    GraphicsOutput,\r
-                    NULL,\r
-                    EfiBltVideoToVideo,\r
-                    DeltaX,\r
-                    DeltaY + EFI_GLYPH_HEIGHT,\r
-                    DeltaX,\r
-                    DeltaY,\r
-                    Width,\r
-                    Height,\r
-                    Delta\r
-                    );\r
+                            GraphicsOutput,\r
+                            NULL,\r
+                            EfiBltVideoToVideo,\r
+                            DeltaX,\r
+                            DeltaY + EFI_GLYPH_HEIGHT,\r
+                            DeltaX,\r
+                            DeltaY,\r
+                            Width,\r
+                            Height,\r
+                            Delta\r
+                            );\r
 \r
           //\r
           // Print Blank Line at last line\r
           //\r
           GraphicsOutput->Blt (\r
 \r
           //\r
           // Print Blank Line at last line\r
           //\r
           GraphicsOutput->Blt (\r
-                    GraphicsOutput,\r
-                    &Background,\r
-                    EfiBltVideoFill,\r
-                    0,\r
-                    0,\r
-                    DeltaX,\r
-                    DeltaY + Height,\r
-                    Width,\r
-                    EFI_GLYPH_HEIGHT,\r
-                    Delta\r
-                    );\r
+                            GraphicsOutput,\r
+                            &Background,\r
+                            EfiBltVideoFill,\r
+                            0,\r
+                            0,\r
+                            DeltaX,\r
+                            DeltaY + Height,\r
+                            Width,\r
+                            EFI_GLYPH_HEIGHT,\r
+                            Delta\r
+                            );\r
         } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
           //\r
           // Scroll Screen Up One Row\r
           //\r
           UgaDraw->Blt (\r
         } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
           //\r
           // Scroll Screen Up One Row\r
           //\r
           UgaDraw->Blt (\r
-                    UgaDraw,\r
-                    NULL,\r
-                    EfiUgaVideoToVideo,\r
-                    DeltaX,\r
-                    DeltaY + EFI_GLYPH_HEIGHT,\r
-                    DeltaX,\r
-                    DeltaY,\r
-                    Width,\r
-                    Height,\r
-                    Delta\r
-                    );\r
+                     UgaDraw,\r
+                     NULL,\r
+                     EfiUgaVideoToVideo,\r
+                     DeltaX,\r
+                     DeltaY + EFI_GLYPH_HEIGHT,\r
+                     DeltaX,\r
+                     DeltaY,\r
+                     Width,\r
+                     Height,\r
+                     Delta\r
+                     );\r
 \r
           //\r
           // Print Blank Line at last line\r
           //\r
           UgaDraw->Blt (\r
 \r
           //\r
           // Print Blank Line at last line\r
           //\r
           UgaDraw->Blt (\r
-                    UgaDraw,\r
-                    (EFI_UGA_PIXEL *) (UINTN) &Background,\r
-                    EfiUgaVideoFill,\r
-                    0,\r
-                    0,\r
-                    DeltaX,\r
-                    DeltaY + Height,\r
-                    Width,\r
-                    EFI_GLYPH_HEIGHT,\r
-                    Delta\r
-                    );\r
+                     UgaDraw,\r
+                     (EFI_UGA_PIXEL *)(UINTN)&Background,\r
+                     EfiUgaVideoFill,\r
+                     0,\r
+                     0,\r
+                     DeltaX,\r
+                     DeltaY + Height,\r
+                     Width,\r
+                     EFI_GLYPH_HEIGHT,\r
+                     Delta\r
+                     );\r
         }\r
       } else {\r
         This->Mode->CursorRow++;\r
       }\r
 \r
       WString++;\r
         }\r
       } else {\r
         This->Mode->CursorRow++;\r
       }\r
 \r
       WString++;\r
-\r
     } else if (*WString == CHAR_CARRIAGE_RETURN) {\r
       //\r
       // Move the cursor to the beginning of the current row.\r
       //\r
       This->Mode->CursorColumn = 0;\r
       WString++;\r
     } else if (*WString == CHAR_CARRIAGE_RETURN) {\r
       //\r
       // Move the cursor to the beginning of the current row.\r
       //\r
       This->Mode->CursorColumn = 0;\r
       WString++;\r
-\r
     } else if (*WString == WIDE_CHAR) {\r
     } else if (*WString == WIDE_CHAR) {\r
-\r
       This->Mode->Attribute |= EFI_WIDE_ATTRIBUTE;\r
       WString++;\r
       This->Mode->Attribute |= EFI_WIDE_ATTRIBUTE;\r
       WString++;\r
-\r
     } else if (*WString == NARROW_CHAR) {\r
     } else if (*WString == NARROW_CHAR) {\r
-\r
-      This->Mode->Attribute &= (~ (UINT32) EFI_WIDE_ATTRIBUTE);\r
+      This->Mode->Attribute &= (~(UINT32)EFI_WIDE_ATTRIBUTE);\r
       WString++;\r
       WString++;\r
-\r
     } else {\r
       //\r
       // Print the character at the current cursor position and move the cursor\r
     } else {\r
       //\r
       // Print the character at the current cursor position and move the cursor\r
@@ -965,14 +1120,16 @@ GraphicsConsoleConOutOutputString (
       // Count is used to determine how many characters are used regardless of their attributes\r
       //\r
       for (Count = 0, Index = 0; (This->Mode->CursorColumn + Index) < MaxColumn; Count++, Index++) {\r
       // Count is used to determine how many characters are used regardless of their attributes\r
       //\r
       for (Count = 0, Index = 0; (This->Mode->CursorColumn + Index) < MaxColumn; Count++, Index++) {\r
-        if (WString[Count] == CHAR_NULL ||\r
-            WString[Count] == CHAR_BACKSPACE ||\r
-            WString[Count] == CHAR_LINEFEED ||\r
-            WString[Count] == CHAR_CARRIAGE_RETURN ||\r
-            WString[Count] == WIDE_CHAR ||\r
-            WString[Count] == NARROW_CHAR) {\r
+        if ((WString[Count] == CHAR_NULL) ||\r
+            (WString[Count] == CHAR_BACKSPACE) ||\r
+            (WString[Count] == CHAR_LINEFEED) ||\r
+            (WString[Count] == CHAR_CARRIAGE_RETURN) ||\r
+            (WString[Count] == WIDE_CHAR) ||\r
+            (WString[Count] == NARROW_CHAR))\r
+        {\r
           break;\r
         }\r
           break;\r
         }\r
+\r
         //\r
         // Is the wide attribute on?\r
         //\r
         //\r
         // Is the wide attribute on?\r
         //\r
@@ -997,27 +1154,28 @@ GraphicsConsoleConOutOutputString (
       if (EFI_ERROR (Status)) {\r
         Warning = TRUE;\r
       }\r
       if (EFI_ERROR (Status)) {\r
         Warning = TRUE;\r
       }\r
+\r
       //\r
       // At the end of line, output carriage return and line feed\r
       //\r
       //\r
       // At the end of line, output carriage return and line feed\r
       //\r
-      WString += Count;\r
-      This->Mode->CursorColumn += (INT32) Index;\r
-      if (This->Mode->CursorColumn > (INT32) MaxColumn) {\r
+      WString                  += Count;\r
+      This->Mode->CursorColumn += (INT32)Index;\r
+      if (This->Mode->CursorColumn > (INT32)MaxColumn) {\r
         This->Mode->CursorColumn -= 2;\r
         This->OutputString (This, SpaceStr);\r
       }\r
 \r
         This->Mode->CursorColumn -= 2;\r
         This->OutputString (This, SpaceStr);\r
       }\r
 \r
-      if (This->Mode->CursorColumn >= (INT32) MaxColumn) {\r
-        EraseCursor (This);\r
+      if (This->Mode->CursorColumn >= (INT32)MaxColumn) {\r
+        FlushCursor (This);\r
         This->OutputString (This, mCrLfString);\r
         This->OutputString (This, mCrLfString);\r
-        EraseCursor (This);\r
+        FlushCursor (This);\r
       }\r
     }\r
   }\r
 \r
   This->Mode->Attribute = OriginAttribute;\r
 \r
       }\r
     }\r
   }\r
 \r
   This->Mode->Attribute = OriginAttribute;\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   if (Warning) {\r
     Status = EFI_WARN_UNKNOWN_GLYPH;\r
 \r
   if (Warning) {\r
     Status = EFI_WARN_UNKNOWN_GLYPH;\r
@@ -1025,7 +1183,6 @@ GraphicsConsoleConOutOutputString (
 \r
   gBS->RestoreTPL (OldTpl);\r
   return Status;\r
 \r
   gBS->RestoreTPL (OldTpl);\r
   return Status;\r
-\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -1054,10 +1211,10 @@ GraphicsConsoleConOutTestString (
   IN  CHAR16                           *WString\r
   )\r
 {\r
   IN  CHAR16                           *WString\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  UINT16                Count;\r
+  EFI_STATUS  Status;\r
+  UINT16      Count;\r
 \r
 \r
-  EFI_IMAGE_OUTPUT      *Blt;\r
+  EFI_IMAGE_OUTPUT  *Blt;\r
 \r
   Blt   = NULL;\r
   Count = 0;\r
 \r
   Blt   = NULL;\r
   Count = 0;\r
@@ -1074,6 +1231,7 @@ GraphicsConsoleConOutTestString (
       FreePool (Blt);\r
       Blt = NULL;\r
     }\r
       FreePool (Blt);\r
       Blt = NULL;\r
     }\r
+\r
     Count++;\r
 \r
     if (EFI_ERROR (Status)) {\r
     Count++;\r
 \r
     if (EFI_ERROR (Status)) {\r
@@ -1084,7 +1242,6 @@ GraphicsConsoleConOutTestString (
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Returns information for an available text mode that the output device(s)\r
   supports\r
 /**\r
   Returns information for an available text mode that the output device(s)\r
   supports\r
@@ -1115,22 +1272,21 @@ GraphicsConsoleConOutQueryMode (
   EFI_STATUS            Status;\r
   EFI_TPL               OldTpl;\r
 \r
   EFI_STATUS            Status;\r
   EFI_TPL               OldTpl;\r
 \r
-  if (ModeNumber >= (UINTN) This->Mode->MaxMode) {\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
     return EFI_UNSUPPORTED;\r
   }\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
   Status = EFI_SUCCESS;\r
 \r
-  Private   = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
+  Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
 \r
 \r
-  *Columns  = Private->ModeData[ModeNumber].Columns;\r
-  *Rows     = Private->ModeData[ModeNumber].Rows;\r
+  *Columns = Private->ModeData[ModeNumber].Columns;\r
+  *Rows    = Private->ModeData[ModeNumber].Rows;\r
 \r
 \r
-  if (*Columns <= 0 && *Rows <= 0) {\r
+  if ((*Columns <= 0) || (*Rows <= 0)) {\r
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
-\r
   }\r
 \r
 Done:\r
   }\r
 \r
 Done:\r
@@ -1138,7 +1294,6 @@ Done:
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Sets the output device(s) to a specified mode.\r
 \r
 /**\r
   Sets the output device(s) to a specified mode.\r
 \r
@@ -1161,80 +1316,78 @@ GraphicsConsoleConOutSetMode (
   IN  UINTN                            ModeNumber\r
   )\r
 {\r
   IN  UINTN                            ModeNumber\r
   )\r
 {\r
-  EFI_STATUS                      Status;\r
-  GRAPHICS_CONSOLE_DEV            *Private;\r
-  GRAPHICS_CONSOLE_MODE_DATA      *ModeData;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL   *NewLineBuffer;\r
-  UINT32                          HorizontalResolution;\r
-  UINT32                          VerticalResolution;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL    *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL           *UgaDraw;\r
-  UINT32                          ColorDepth;\r
-  UINT32                          RefreshRate;\r
-  EFI_TPL                         OldTpl;\r
+  EFI_STATUS                     Status;\r
+  GRAPHICS_CONSOLE_DEV           *Private;\r
+  GRAPHICS_CONSOLE_MODE_DATA     *ModeData;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *NewLineBuffer;\r
+  UINT32                         HorizontalResolution;\r
+  UINT32                         VerticalResolution;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL   *GraphicsOutput;\r
+  EFI_UGA_DRAW_PROTOCOL          *UgaDraw;\r
+  UINT32                         ColorDepth;\r
+  UINT32                         RefreshRate;\r
+  EFI_TPL                        OldTpl;\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  Private   = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
+  Private        = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
   GraphicsOutput = Private->GraphicsOutput;\r
   GraphicsOutput = Private->GraphicsOutput;\r
-  UgaDraw   = Private->UgaDraw;\r
-  ModeData  = &(Private->ModeData[ModeNumber]);\r
-\r
-  if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
-    Status = EFI_UNSUPPORTED;\r
-    goto Done;\r
-  }\r
+  UgaDraw        = Private->UgaDraw;\r
 \r
   //\r
   // Make sure the requested mode number is supported\r
   //\r
 \r
   //\r
   // Make sure the requested mode number is supported\r
   //\r
-  if (ModeNumber >= (UINTN) This->Mode->MaxMode) {\r
+  if (ModeNumber >= (UINTN)This->Mode->MaxMode) {\r
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
   }\r
 \r
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
   }\r
 \r
-  if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
+  ModeData = &(Private->ModeData[ModeNumber]);\r
+\r
+  if ((ModeData->Columns <= 0) && (ModeData->Rows <= 0)) {\r
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
   }\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
 \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
   // 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
     //\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
+    if ((INT32)ModeNumber == This->Mode->Mode) {\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
       Status = EFI_SUCCESS;\r
       goto Done;\r
     }\r
+\r
     //\r
     // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,\r
     // so erase the cursor, and free the LineBuffer for the current mode\r
     //\r
     //\r
     // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,\r
     // so erase the cursor, and free the LineBuffer for the current mode\r
     //\r
-    EraseCursor (This);\r
+    FlushCursor (This);\r
 \r
     FreePool (Private->LineBuffer);\r
   }\r
 \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
   //\r
   // Assign the current line buffer to the newly allocated line buffer\r
   //\r
@@ -1257,17 +1410,17 @@ GraphicsConsoleConOutSetMode (
       // The current graphics mode is correct, so simply clear the entire display\r
       //\r
       Status = GraphicsOutput->Blt (\r
       // The current graphics mode is correct, so simply clear the entire display\r
       //\r
       Status = GraphicsOutput->Blt (\r
-                          GraphicsOutput,\r
-                          &mEfiColors[0],\r
-                          EfiBltVideoFill,\r
-                          0,\r
-                          0,\r
-                          0,\r
-                          0,\r
-                          ModeData->GopWidth,\r
-                          ModeData->GopHeight,\r
-                          0\r
-                          );\r
+                                 GraphicsOutput,\r
+                                 &mGraphicsEfiColors[0],\r
+                                 EfiBltVideoFill,\r
+                                 0,\r
+                                 0,\r
+                                 0,\r
+                                 0,\r
+                                 ModeData->GopWidth,\r
+                                 ModeData->GopHeight,\r
+                                 0\r
+                                 );\r
     }\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     }\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
@@ -1280,7 +1433,7 @@ GraphicsConsoleConOutSetMode (
                         &ColorDepth,\r
                         &RefreshRate\r
                         );\r
                         &ColorDepth,\r
                         &RefreshRate\r
                         );\r
-    if (EFI_ERROR (Status) || HorizontalResolution != ModeData->GopWidth || VerticalResolution != ModeData->GopHeight) {\r
+    if (EFI_ERROR (Status) || (HorizontalResolution != ModeData->GopWidth) || (VerticalResolution != ModeData->GopHeight)) {\r
       //\r
       // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode\r
       //\r
       //\r
       // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode\r
       //\r
@@ -1303,7 +1456,7 @@ GraphicsConsoleConOutSetMode (
       //\r
       Status = UgaDraw->Blt (\r
                           UgaDraw,\r
       //\r
       Status = UgaDraw->Blt (\r
                           UgaDraw,\r
-                          (EFI_UGA_PIXEL *) (UINTN) &mEfiColors[0],\r
+                          (EFI_UGA_PIXEL *)(UINTN)&mGraphicsEfiColors[0],\r
                           EfiUgaVideoFill,\r
                           0,\r
                           0,\r
                           EfiUgaVideoFill,\r
                           0,\r
                           0,\r
@@ -1319,12 +1472,15 @@ GraphicsConsoleConOutSetMode (
   //\r
   // The new mode is valid, so commit the mode change\r
   //\r
   //\r
   // The new mode is valid, so commit the mode change\r
   //\r
-  This->Mode->Mode = (INT32) ModeNumber;\r
+  This->Mode->Mode = (INT32)ModeNumber;\r
 \r
   //\r
 \r
   //\r
-  // Move the text cursor to the upper left hand corner of the display and enable it\r
+  // Move the text cursor to the upper left hand corner of the display and flush it\r
   //\r
   //\r
-  This->SetCursorPosition (This, 0, 0);\r
+  This->Mode->CursorColumn = 0;\r
+  This->Mode->CursorRow    = 0;\r
+\r
+  FlushCursor (This);\r
 \r
   Status = EFI_SUCCESS;\r
 \r
 \r
   Status = EFI_SUCCESS;\r
 \r
@@ -1333,7 +1489,6 @@ Done:
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Sets the background and foreground colors for the OutputString () and\r
   ClearScreen () functions.\r
 /**\r
   Sets the background and foreground colors for the OutputString () and\r
   ClearScreen () functions.\r
@@ -1357,30 +1512,29 @@ GraphicsConsoleConOutSetAttribute (
   IN  UINTN                            Attribute\r
   )\r
 {\r
   IN  UINTN                            Attribute\r
   )\r
 {\r
-  EFI_TPL               OldTpl;\r
+  EFI_TPL  OldTpl;\r
 \r
 \r
-  if ((Attribute | 0xFF) != 0xFF) {\r
+  if ((Attribute | 0x7F) != 0x7F) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  if ((INT32) Attribute == This->Mode->Attribute) {\r
+  if ((INT32)Attribute == This->Mode->Attribute) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
     return EFI_SUCCESS;\r
   }\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
 \r
-  This->Mode->Attribute = (INT32) Attribute;\r
+  This->Mode->Attribute = (INT32)Attribute;\r
 \r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 \r
   gBS->RestoreTPL (OldTpl);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Clears the output device(s) display to the currently selected background\r
   color.\r
 /**\r
   Clears the output device(s) display to the currently selected background\r
   color.\r
@@ -1400,40 +1554,47 @@ GraphicsConsoleConOutClearScreen (
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
   )\r
 {\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  GRAPHICS_CONSOLE_DEV          *Private;\r
-  GRAPHICS_CONSOLE_MODE_DATA    *ModeData;\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
-  EFI_TPL                       OldTpl;\r
+  EFI_STATUS                     Status;\r
+  GRAPHICS_CONSOLE_DEV           *Private;\r
+  GRAPHICS_CONSOLE_MODE_DATA     *ModeData;\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
+  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
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  Private   = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
+  Private        = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
   GraphicsOutput = Private->GraphicsOutput;\r
   GraphicsOutput = Private->GraphicsOutput;\r
-  UgaDraw   = Private->UgaDraw;\r
-  ModeData  = &(Private->ModeData[This->Mode->Mode]);\r
+  UgaDraw        = Private->UgaDraw;\r
+  ModeData       = &(Private->ModeData[This->Mode->Mode]);\r
 \r
   GetTextColors (This, &Foreground, &Background);\r
   if (GraphicsOutput != NULL) {\r
     Status = GraphicsOutput->Blt (\r
 \r
   GetTextColors (This, &Foreground, &Background);\r
   if (GraphicsOutput != NULL) {\r
     Status = GraphicsOutput->Blt (\r
-                        GraphicsOutput,\r
-                        &Background,\r
-                        EfiBltVideoFill,\r
-                        0,\r
-                        0,\r
-                        0,\r
-                        0,\r
-                        ModeData->GopWidth,\r
-                        ModeData->GopHeight,\r
-                        0\r
-                        );\r
+                               GraphicsOutput,\r
+                               &Background,\r
+                               EfiBltVideoFill,\r
+                               0,\r
+                               0,\r
+                               0,\r
+                               0,\r
+                               ModeData->GopWidth,\r
+                               ModeData->GopHeight,\r
+                               0\r
+                               );\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     Status = UgaDraw->Blt (\r
                         UgaDraw,\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     Status = UgaDraw->Blt (\r
                         UgaDraw,\r
-                        (EFI_UGA_PIXEL *) (UINTN) &Background,\r
+                        (EFI_UGA_PIXEL *)(UINTN)&Background,\r
                         EfiUgaVideoFill,\r
                         0,\r
                         0,\r
                         EfiUgaVideoFill,\r
                         0,\r
                         0,\r
@@ -1447,17 +1608,16 @@ GraphicsConsoleConOutClearScreen (
     Status = EFI_UNSUPPORTED;\r
   }\r
 \r
     Status = EFI_UNSUPPORTED;\r
   }\r
 \r
-  This->Mode->CursorColumn  = 0;\r
-  This->Mode->CursorRow     = 0;\r
+  This->Mode->CursorColumn = 0;\r
+  This->Mode->CursorRow    = 0;\r
 \r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
 \r
   return Status;\r
 }\r
 \r
 \r
   gBS->RestoreTPL (OldTpl);\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Sets the current coordinates of the cursor position.\r
 \r
 /**\r
   Sets the current coordinates of the cursor position.\r
 \r
@@ -1490,29 +1650,36 @@ GraphicsConsoleConOutSetCursorPosition (
   EFI_STATUS                  Status;\r
   EFI_TPL                     OldTpl;\r
 \r
   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
 \r
   Status = EFI_SUCCESS;\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  Private   = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
-  ModeData  = &(Private->ModeData[This->Mode->Mode]);\r
+  Private  = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
+  ModeData = &(Private->ModeData[This->Mode->Mode]);\r
 \r
   if ((Column >= ModeData->Columns) || (Row >= ModeData->Rows)) {\r
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
   }\r
 \r
 \r
   if ((Column >= ModeData->Columns) || (Row >= ModeData->Rows)) {\r
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
   }\r
 \r
-  if ((This->Mode->CursorColumn == (INT32) Column) && (This->Mode->CursorRow == (INT32) Row)) {\r
+  if ((This->Mode->CursorColumn == (INT32)Column) && (This->Mode->CursorRow == (INT32)Row)) {\r
     Status = EFI_SUCCESS;\r
     goto Done;\r
   }\r
 \r
     Status = EFI_SUCCESS;\r
     goto Done;\r
   }\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
 \r
-  This->Mode->CursorColumn  = (INT32) Column;\r
-  This->Mode->CursorRow     = (INT32) Row;\r
+  This->Mode->CursorColumn = (INT32)Column;\r
+  This->Mode->CursorRow    = (INT32)Row;\r
 \r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
 Done:\r
   gBS->RestoreTPL (OldTpl);\r
 \r
 Done:\r
   gBS->RestoreTPL (OldTpl);\r
@@ -1520,7 +1687,6 @@ Done:
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Makes the cursor visible or invisible.\r
 \r
 /**\r
   Makes the cursor visible or invisible.\r
 \r
@@ -1531,6 +1697,8 @@ Done:
                                 the cursor is set to be invisible.\r
 \r
   @retval EFI_SUCCESS           The operation completed successfully.\r
                                 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
 \r
 **/\r
 EFI_STATUS\r
@@ -1540,22 +1708,29 @@ GraphicsConsoleConOutEnableCursor (
   IN  BOOLEAN                          Visible\r
   )\r
 {\r
   IN  BOOLEAN                          Visible\r
   )\r
 {\r
-  EFI_TPL               OldTpl;\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
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   This->Mode->CursorVisible = Visible;\r
 \r
 \r
   This->Mode->CursorVisible = Visible;\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
 \r
   gBS->RestoreTPL (OldTpl);\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Gets Graphics Console devcie's foreground color and background color.\r
+  Gets Graphics Console device's foreground color and background color.\r
 \r
   @param  This                  Protocol instance pointer.\r
   @param  Foreground            Returned text foreground color.\r
 \r
   @param  This                  Protocol instance pointer.\r
   @param  Foreground            Returned text foreground color.\r
@@ -1573,10 +1748,10 @@ GetTextColors (
 {\r
   INTN  Attribute;\r
 \r
 {\r
   INTN  Attribute;\r
 \r
-  Attribute   = This->Mode->Attribute & 0x7F;\r
+  Attribute = This->Mode->Attribute & 0x7F;\r
 \r
 \r
-  *Foreground = mEfiColors[Attribute & 0x0f];\r
-  *Background = mEfiColors[Attribute >> 4];\r
+  *Foreground = mGraphicsEfiColors[Attribute & 0x0f];\r
+  *Background = mGraphicsEfiColors[Attribute >> 4];\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -1601,40 +1776,42 @@ DrawUnicodeWeightAtCursorN (
   IN  UINTN                            Count\r
   )\r
 {\r
   IN  UINTN                            Count\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
-  GRAPHICS_CONSOLE_DEV              *Private;\r
-  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
+  EFI_STATUS             Status;\r
+  GRAPHICS_CONSOLE_DEV   *Private;\r
+  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
   Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
-  Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
+  Blt     = (EFI_IMAGE_OUTPUT *)AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
   if (Blt == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
   if (Blt == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  Blt->Width        = (UINT16) (Private->ModeData[This->Mode->Mode].GopWidth);\r
-  Blt->Height       = (UINT16) (Private->ModeData[This->Mode->Mode].GopHeight);\r
+  Blt->Width  = (UINT16)(Private->ModeData[This->Mode->Mode].GopWidth);\r
+  Blt->Height = (UINT16)(Private->ModeData[This->Mode->Mode].GopHeight);\r
 \r
   String = AllocateCopyPool ((Count + 1) * sizeof (CHAR16), UnicodeWeight);\r
   if (String == NULL) {\r
     FreePool (Blt);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
   String = AllocateCopyPool ((Count + 1) * sizeof (CHAR16), UnicodeWeight);\r
   if (String == NULL) {\r
     FreePool (Blt);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+\r
   //\r
   // Set the end character\r
   //\r
   *(String + Count) = L'\0';\r
 \r
   //\r
   // Set the end character\r
   //\r
   *(String + Count) = L'\0';\r
 \r
-  FontInfo = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO));\r
+  FontInfo = (EFI_FONT_DISPLAY_INFO *)AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO));\r
   if (FontInfo == NULL) {\r
     FreePool (Blt);\r
     FreePool (String);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   if (FontInfo == NULL) {\r
     FreePool (Blt);\r
     FreePool (String);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+\r
   //\r
   // Get current foreground and background colors.\r
   //\r
   //\r
   // Get current foreground and background colors.\r
   //\r
@@ -1648,7 +1825,7 @@ DrawUnicodeWeightAtCursorN (
 \r
     Status = mHiiFont->StringToImage (\r
                          mHiiFont,\r
 \r
     Status = mHiiFont->StringToImage (\r
                          mHiiFont,\r
-                         EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN,\r
+                         EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN | EFI_HII_IGNORE_LINE_BREAK,\r
                          String,\r
                          FontInfo,\r
                          &Blt,\r
                          String,\r
                          FontInfo,\r
                          &Blt,\r
@@ -1658,13 +1835,12 @@ DrawUnicodeWeightAtCursorN (
                          NULL,\r
                          NULL\r
                          );\r
                          NULL,\r
                          NULL\r
                          );\r
-\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,\r
     // using UGA Draw protocol to draw.\r
     //\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,\r
     // using UGA Draw protocol to draw.\r
     //\r
-    ASSERT (Private->UgaDraw!= NULL);\r
+    ASSERT (Private->UgaDraw != NULL);\r
 \r
     UgaDraw = Private->UgaDraw;\r
 \r
 \r
     UgaDraw = Private->UgaDraw;\r
 \r
@@ -1681,17 +1857,17 @@ DrawUnicodeWeightAtCursorN (
     //  we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.\r
     //\r
     Status = mHiiFont->StringToImage (\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 * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
-                          This->Mode->CursorRow * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
-                          &RowInfoArray,\r
-                          &RowInfoArraySize,\r
-                          NULL\r
-                          );\r
+                         mHiiFont,\r
+                         EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK,\r
+                         String,\r
+                         FontInfo,\r
+                         &Blt,\r
+                         This->Mode->CursorColumn * EFI_GLYPH_WIDTH + Private->ModeData[This->Mode->Mode].DeltaX,\r
+                         This->Mode->CursorRow * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
+                         &RowInfoArray,\r
+                         &RowInfoArraySize,\r
+                         NULL\r
+                         );\r
 \r
     if (!EFI_ERROR (Status)) {\r
       //\r
 \r
     if (!EFI_ERROR (Status)) {\r
       //\r
@@ -1702,7 +1878,7 @@ DrawUnicodeWeightAtCursorN (
 \r
       Status = UgaDraw->Blt (\r
                           UgaDraw,\r
 \r
       Status = UgaDraw->Blt (\r
                           UgaDraw,\r
-                          (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r
+                          (EFI_UGA_PIXEL *)Blt->Image.Bitmap,\r
                           EfiUgaBltBufferToVideo,\r
                           This->Mode->CursorColumn * EFI_GLYPH_WIDTH  + Private->ModeData[This->Mode->Mode].DeltaX,\r
                           (This->Mode->CursorRow) * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
                           EfiUgaBltBufferToVideo,\r
                           This->Mode->CursorColumn * EFI_GLYPH_WIDTH  + Private->ModeData[This->Mode->Mode].DeltaX,\r
                           (This->Mode->CursorRow) * EFI_GLYPH_HEIGHT + Private->ModeData[This->Mode->Mode].DeltaY,\r
@@ -1723,17 +1899,25 @@ DrawUnicodeWeightAtCursorN (
   if (Blt != NULL) {\r
     FreePool (Blt);\r
   }\r
   if (Blt != NULL) {\r
     FreePool (Blt);\r
   }\r
+\r
   if (String != NULL) {\r
     FreePool (String);\r
   }\r
   if (String != NULL) {\r
     FreePool (String);\r
   }\r
+\r
   if (FontInfo != NULL) {\r
     FreePool (FontInfo);\r
   }\r
   if (FontInfo != NULL) {\r
     FreePool (FontInfo);\r
   }\r
+\r
   return Status;\r
 }\r
 \r
 /**\r
   return Status;\r
 }\r
 \r
 /**\r
-  Erase the cursor on the screen.\r
+  Flush the cursor on the screen.\r
+\r
+  If CursorVisible is FALSE, nothing to do and return directly.\r
+  If CursorVisible is TRUE,\r
+     i) If the cursor shows on screen, it will be erased.\r
+    ii) If the cursor does not show on screen, it will be shown.\r
 \r
   @param  This                  Protocol instance pointer.\r
 \r
 \r
   @param  This                  Protocol instance pointer.\r
 \r
@@ -1741,21 +1925,21 @@ DrawUnicodeWeightAtCursorN (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EraseCursor (\r
+FlushCursor (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
   )\r
 {\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
   )\r
 {\r
-  GRAPHICS_CONSOLE_DEV                *Private;\r
-  EFI_SIMPLE_TEXT_OUTPUT_MODE         *CurrentMode;\r
-  INTN                                GlyphX;\r
-  INTN                                GlyphY;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL        *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL               *UgaDraw;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar[EFI_GLYPH_HEIGHT][EFI_GLYPH_WIDTH];\r
-  UINTN                               PosX;\r
-  UINTN                               PosY;\r
+  GRAPHICS_CONSOLE_DEV                 *Private;\r
+  EFI_SIMPLE_TEXT_OUTPUT_MODE          *CurrentMode;\r
+  INTN                                 GlyphX;\r
+  INTN                                 GlyphY;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL         *GraphicsOutput;\r
+  EFI_UGA_DRAW_PROTOCOL                *UgaDraw;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  Foreground;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  Background;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION  BltChar[EFI_GLYPH_HEIGHT][EFI_GLYPH_WIDTH];\r
+  UINTN                                PosX;\r
+  UINTN                                PosY;\r
 \r
   CurrentMode = This->Mode;\r
 \r
 \r
   CurrentMode = This->Mode;\r
 \r
@@ -1763,9 +1947,9 @@ EraseCursor (
     return EFI_SUCCESS;\r
   }\r
 \r
     return EFI_SUCCESS;\r
   }\r
 \r
-  Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
+  Private        = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);\r
   GraphicsOutput = Private->GraphicsOutput;\r
   GraphicsOutput = Private->GraphicsOutput;\r
-  UgaDraw = Private->UgaDraw;\r
+  UgaDraw        = Private->UgaDraw;\r
 \r
   //\r
   // In this driver, only narrow character was supported.\r
 \r
   //\r
   // In this driver, only narrow character was supported.\r
@@ -1773,34 +1957,34 @@ EraseCursor (
   //\r
   // Blt a character to the screen\r
   //\r
   //\r
   // Blt a character to the screen\r
   //\r
-  GlyphX  = (CurrentMode->CursorColumn * EFI_GLYPH_WIDTH) + Private->ModeData[CurrentMode->Mode].DeltaX;\r
-  GlyphY  = (CurrentMode->CursorRow * EFI_GLYPH_HEIGHT) + Private->ModeData[CurrentMode->Mode].DeltaY;\r
+  GlyphX = (CurrentMode->CursorColumn * EFI_GLYPH_WIDTH) + Private->ModeData[CurrentMode->Mode].DeltaX;\r
+  GlyphY = (CurrentMode->CursorRow * EFI_GLYPH_HEIGHT) + Private->ModeData[CurrentMode->Mode].DeltaY;\r
   if (GraphicsOutput != NULL) {\r
     GraphicsOutput->Blt (\r
   if (GraphicsOutput != NULL) {\r
     GraphicsOutput->Blt (\r
-              GraphicsOutput,\r
-              (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,\r
-              EfiBltVideoToBltBuffer,\r
-              GlyphX,\r
-              GlyphY,\r
-              0,\r
-              0,\r
-              EFI_GLYPH_WIDTH,\r
-              EFI_GLYPH_HEIGHT,\r
-              EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
-              );\r
+                      GraphicsOutput,\r
+                      (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)BltChar,\r
+                      EfiBltVideoToBltBuffer,\r
+                      GlyphX,\r
+                      GlyphY,\r
+                      0,\r
+                      0,\r
+                      EFI_GLYPH_WIDTH,\r
+                      EFI_GLYPH_HEIGHT,\r
+                      EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                      );\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     UgaDraw->Blt (\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     UgaDraw->Blt (\r
-              UgaDraw,\r
-              (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
-              EfiUgaVideoToBltBuffer,\r
-              GlyphX,\r
-              GlyphY,\r
-              0,\r
-              0,\r
-              EFI_GLYPH_WIDTH,\r
-              EFI_GLYPH_HEIGHT,\r
-              EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
-              );\r
+               UgaDraw,\r
+               (EFI_UGA_PIXEL *)(UINTN)BltChar,\r
+               EfiUgaVideoToBltBuffer,\r
+               GlyphX,\r
+               GlyphY,\r
+               0,\r
+               0,\r
+               EFI_GLYPH_WIDTH,\r
+               EFI_GLYPH_HEIGHT,\r
+               EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
+               );\r
   }\r
 \r
   GetTextColors (This, &Foreground.Pixel, &Background.Pixel);\r
   }\r
 \r
   GetTextColors (This, &Foreground.Pixel, &Background.Pixel);\r
@@ -1818,49 +2002,56 @@ EraseCursor (
 \r
   if (GraphicsOutput != NULL) {\r
     GraphicsOutput->Blt (\r
 \r
   if (GraphicsOutput != NULL) {\r
     GraphicsOutput->Blt (\r
-              GraphicsOutput,\r
-              (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltChar,\r
-              EfiBltBufferToVideo,\r
-              0,\r
-              0,\r
-              GlyphX,\r
-              GlyphY,\r
-              EFI_GLYPH_WIDTH,\r
-              EFI_GLYPH_HEIGHT,\r
-              EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
-              );\r
+                      GraphicsOutput,\r
+                      (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)BltChar,\r
+                      EfiBltBufferToVideo,\r
+                      0,\r
+                      0,\r
+                      GlyphX,\r
+                      GlyphY,\r
+                      EFI_GLYPH_WIDTH,\r
+                      EFI_GLYPH_HEIGHT,\r
+                      EFI_GLYPH_WIDTH * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                      );\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     UgaDraw->Blt (\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     UgaDraw->Blt (\r
-              UgaDraw,\r
-              (EFI_UGA_PIXEL *) (UINTN) BltChar,\r
-              EfiUgaBltBufferToVideo,\r
-              0,\r
-              0,\r
-              GlyphX,\r
-              GlyphY,\r
-              EFI_GLYPH_WIDTH,\r
-              EFI_GLYPH_HEIGHT,\r
-              EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
-              );\r
+               UgaDraw,\r
+               (EFI_UGA_PIXEL *)(UINTN)BltChar,\r
+               EfiUgaBltBufferToVideo,\r
+               0,\r
+               0,\r
+               GlyphX,\r
+               GlyphY,\r
+               EFI_GLYPH_WIDTH,\r
+               EFI_GLYPH_HEIGHT,\r
+               EFI_GLYPH_WIDTH * sizeof (EFI_UGA_PIXEL)\r
+               );\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  HII Database Protocol notification event handler.\r
+\r
+  Register font package when HII Database Protocol has been installed.\r
+\r
+  @param[in] Event    Event whose notification function is being invoked.\r
+  @param[in] Context  Pointer to the notification function's context.\r
+**/\r
 VOID\r
 EFIAPI\r
 RegisterFontPackage (\r
 VOID\r
 EFIAPI\r
 RegisterFontPackage (\r
-  IN  EFI_EVENT       Event,\r
-  IN  VOID            *Context\r
+  IN  EFI_EVENT  Event,\r
+  IN  VOID       *Context\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                           Status;\r
-  EFI_HII_SIMPLE_FONT_PACKAGE_HDR      *SimplifiedFont;\r
-  UINT32                               PackageLength;\r
-  EFI_HII_PACKAGE_LIST_HEADER          *PackageList;\r
-  UINT8                                *Package;\r
-  UINT8                                *Location;\r
-  EFI_HII_DATABASE_PROTOCOL            *HiiDatabase;\r
+  EFI_STATUS                       Status;\r
+  EFI_HII_SIMPLE_FONT_PACKAGE_HDR  *SimplifiedFont;\r
+  UINT32                           PackageLength;\r
+  UINT8                            *Package;\r
+  UINT8                            *Location;\r
+  EFI_HII_DATABASE_PROTOCOL        *HiiDatabase;\r
 \r
   //\r
   // Locate HII Database Protocol\r
 \r
   //\r
   // Locate HII Database Protocol\r
@@ -1868,12 +2059,14 @@ RegisterFontPackage (
   Status = gBS->LocateProtocol (\r
                   &gEfiHiiDatabaseProtocolGuid,\r
                   NULL,\r
   Status = gBS->LocateProtocol (\r
                   &gEfiHiiDatabaseProtocolGuid,\r
                   NULL,\r
-                  (VOID **) &HiiDatabase\r
+                  (VOID **)&HiiDatabase\r
                   );\r
                   );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
 \r
   //\r
 \r
   //\r
-  // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only.\r
+  // Add 4 bytes to the header for entire length for HiiAddPackages use only.\r
   //\r
   //    +--------------------------------+ <-- Package\r
   //    |                                |\r
   //\r
   //    +--------------------------------+ <-- Package\r
   //    |                                |\r
@@ -1889,26 +2082,29 @@ RegisterFontPackage (
   //    |                                |\r
   //    +--------------------------------+\r
 \r
   //    |                                |\r
   //    +--------------------------------+\r
 \r
-  PackageLength   = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + mNarrowFontSize + 4;\r
-  Package = AllocateZeroPool (PackageLength);\r
+  PackageLength = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + mNarrowFontSize + 4;\r
+  Package       = AllocateZeroPool (PackageLength);\r
   ASSERT (Package != NULL);\r
 \r
   ASSERT (Package != NULL);\r
 \r
-  WriteUnaligned32((UINT32 *) Package,PackageLength);\r
-  SimplifiedFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR *) (Package + 4);\r
-  SimplifiedFont->Header.Length        = (UINT32) (PackageLength - 4);\r
+  WriteUnaligned32 ((UINT32 *)Package, PackageLength);\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->Header.Type          = EFI_HII_PACKAGE_SIMPLE_FONTS;\r
-  SimplifiedFont->NumberOfNarrowGlyphs = (UINT16) (mNarrowFontSize / sizeof (EFI_NARROW_GLYPH));\r
+  SimplifiedFont->NumberOfNarrowGlyphs = (UINT16)(mNarrowFontSize / sizeof (EFI_NARROW_GLYPH));\r
 \r
 \r
-  Location = (UINT8 *) (&SimplifiedFont->NumberOfWideGlyphs + 1);\r
+  Location = (UINT8 *)(&SimplifiedFont->NumberOfWideGlyphs + 1);\r
   CopyMem (Location, gUsStdNarrowGlyphData, mNarrowFontSize);\r
 \r
   //\r
   // Add this simplified font package to a package list then install it.\r
   //\r
   CopyMem (Location, gUsStdNarrowGlyphData, mNarrowFontSize);\r
 \r
   //\r
   // Add this simplified font package to a package list then install it.\r
   //\r
-  PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package);\r
-  Status = HiiDatabase->NewPackageList (HiiDatabase, PackageList, NULL, &mHiiHandle);\r
-  ASSERT_EFI_ERROR (Status);\r
-  FreePool (PackageList);\r
+  mHiiHandle = HiiAddPackages (\r
+                 &mFontPackageListGuid,\r
+                 NULL,\r
+                 Package,\r
+                 NULL\r
+                 );\r
+  ASSERT (mHiiHandle != NULL);\r
   FreePool (Package);\r
 }\r
 \r
   FreePool (Package);\r
 }\r
 \r
@@ -1925,15 +2121,15 @@ RegisterFontPackage (
 EFI_STATUS\r
 EFIAPI\r
 InitializeGraphicsConsole (\r
 EFI_STATUS\r
 EFIAPI\r
 InitializeGraphicsConsole (\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS              Status;\r
+  EFI_STATUS  Status;\r
 \r
   //\r
   // Register notify function on HII Database Protocol to add font package.\r
 \r
   //\r
   // Register notify function on HII Database Protocol to add font package.\r
-  // \r
+  //\r
   EfiCreateProtocolNotifyEvent (\r
     &gEfiHiiDatabaseProtocolGuid,\r
     TPL_CALLBACK,\r
   EfiCreateProtocolNotifyEvent (\r
     &gEfiHiiDatabaseProtocolGuid,\r
     TPL_CALLBACK,\r
@@ -1957,5 +2153,3 @@ InitializeGraphicsConsole (
 \r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
-\r
-\r