]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
Global variables have been moved backward ahead of functions.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
index 1e1bd0edd4f1c6bd0ca7b7022536738ced9019c1..f925daa975bd935c7b4e2c622f15f9620663a3d6 100644 (file)
@@ -1,10 +1,5 @@
 /** @file\r
   This is the main routine for initializing the Graphics Console support routines.\r
-Remaining Tasks\r
-  Add all standard Glyphs from UEFI 2.0 Specification\r
-  Implement optimal automatic Mode creation algorithm\r
-  Solve palette issues for mixed graphics and text\r
-  When does this protocol reset the palette?\r
 \r
 Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
 All rights reserved. This program and the accompanying materials\r
@@ -19,37 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "GraphicsConsole.h"\r
 \r
-EFI_STATUS\r
-GetTextColors (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
-  OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Foreground,\r
-  OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Background\r
-  );\r
-\r
-EFI_STATUS\r
-DrawUnicodeWeightAtCursorN (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
-  IN  CHAR16                           *UnicodeWeight,\r
-  IN  UINTN                            Count\r
-  );\r
-\r
-EFI_STATUS\r
-EraseCursor (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
-  );\r
-\r
-EFI_STATUS\r
-CheckModeSupported (\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput,\r
-  IN  UINT32  HorizontalResolution,\r
-  IN  UINT32  VerticalResolution,\r
-  OUT UINT32  *CurrentModeNumber\r
-  );\r
 \r
 //\r
-// Globals\r
+// Graphics Console Devcie Private Data template\r
 //\r
-GRAPHICS_CONSOLE_DEV        mGraphicsConsoleDevTemplate = {\r
+GRAPHICS_CONSOLE_DEV    mGraphicsConsoleDevTemplate = {\r
   GRAPHICS_CONSOLE_DEV_SIGNATURE,\r
   (EFI_GRAPHICS_OUTPUT_PROTOCOL *) NULL,\r
   (EFI_UGA_DRAW_PROTOCOL *) NULL,\r
@@ -87,11 +56,11 @@ EFI_HII_DATABASE_PROTOCOL   *mHiiDatabase;
 EFI_HII_FONT_PROTOCOL       *mHiiFont;\r
 BOOLEAN                     mFirstAccessFlag = TRUE;\r
 \r
-STATIC EFI_GUID             mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, 0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad};\r
+EFI_GUID             mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};\r
 \r
-STATIC CHAR16               mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
+CHAR16               mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
 \r
-STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL        mEfiColors[16] = {\r
+EFI_GRAPHICS_OUTPUT_BLT_PIXEL        mEfiColors[16] = {\r
   //\r
   // B     G     R\r
   //\r
@@ -113,13 +82,13 @@ STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL        mEfiColors[16] = {
   {0xff, 0xff, 0xff, 0x00}  // WHITE\r
 };\r
 \r
-STATIC EFI_NARROW_GLYPH     mCursorGlyph = {\r
+EFI_NARROW_GLYPH     mCursorGlyph = {\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
 };\r
 \r
-STATIC CHAR16       SpaceStr[] = { NARROW_CHAR, ' ', 0 };\r
+CHAR16       SpaceStr[] = { NARROW_CHAR, ' ', 0 };\r
 \r
 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = {\r
   GraphicsConsoleControllerDriverSupported,\r
@@ -130,6 +99,100 @@ EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = {
   NULL\r
 };\r
 \r
+/**\r
+  Gets Graphics Console devcie's foreground color and background color.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  Foreground            Returned text foreground color.\r
+  @param  Background            Returned text background color.\r
+\r
+  @retval EFI_SUCCESS           It returned always.\r
+\r
+**/\r
+EFI_STATUS\r
+GetTextColors (\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
+  OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Foreground,\r
+  OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Background\r
+  );\r
+\r
+/**\r
+  Draw Unicode string on the Graphice Console device's screen.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  UnicodeWeight         One Unicode string to be displayed.\r
+  @param  Count                 The count of Unicode string.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  If no memory resource to use.\r
+  @retval EFI_UNSUPPORTED       If no Graphics Output protocol and UGA Draw\r
+                                protocol exist.\r
+  @retval EFI_SUCCESS           Drawing Unicode string implemented successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+DrawUnicodeWeightAtCursorN (\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
+  IN  CHAR16                           *UnicodeWeight,\r
+  IN  UINTN                            Count\r
+  );\r
+\r
+/**\r
+  Erase the cursor on the screen.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           The cursor is erased successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EraseCursor (\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
+  );\r
+\r
+/**\r
+  Check if the current specific mode supported the user defined resolution\r
+  for the Graphice Console devcie based on Graphics Output Protocol.\r
+\r
+  If yes, set the graphic devcice's current mode to this specific mode.\r
+  \r
+  @param  GraphicsOutput        Graphics Output Protocol instance pointer.\r
+  @param  HorizontalResolution  User defined horizontal resolution\r
+  @param  VerticalResolution    User defined vertical resolution.\r
+  @param  CurrentModeNumber     Current specific mode to be check.\r
+\r
+  @retval EFI_SUCCESS       The mode is supported.\r
+  @retval EFI_UNSUPPORTED   The specific mode is out of range of graphics \r
+                            devcie supported.\r
+  @retval other             The specific mode does not support user defined \r
+                            resolution or failed to set the current mode to the \r
+                            specific mode on graphics device.\r
+\r
+**/\r
+EFI_STATUS\r
+CheckModeSupported (\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput,\r
+  IN  UINT32  HorizontalResolution,\r
+  IN  UINT32  VerticalResolution,\r
+  OUT UINT32  *CurrentModeNumber\r
+  );\r
+\r
+\r
+/**\r
+  Test to see if Graphics Console could be supported on the Controller.\r
+\r
+  Graphics Console could be supported if Graphics Output Protocol or UGA Draw\r
+  Protocol exists on the Controller. (UGA Draw Protocol could be skipped\r
+  if PcdUgaConsumeSupport is set to FALSE.)\r
+\r
+  @param  This                Protocol instance pointer.\r
+  @param  Controller          Handle of device to test.\r
+  @param  RemainingDevicePath Optional parameter use to pick a specific child\r
+                              device to start.\r
+\r
+  @retval EFI_SUCCESS         This driver supports this device.\r
+  @retval other               This driver does not support this device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 GraphicsConsoleControllerDriverSupported (\r
@@ -227,16 +290,17 @@ Error:
 \r
 \r
 /**\r
-  Start the controller.\r
-\r
-  @param  This                  A pointer to the EFI_DRIVER_BINDING_PROTOCOL\r
-                                instance.\r
-  @param  Controller            The handle of the controller to start.\r
-  @param  RemainingDevicePath   A pointer to the remaining portion of a devcie\r
-                                path.\r
-\r
-  @retval EFI_SUCCESS           Return successfully.\r
-  @retval EFI_OUT_OF_RESOURCES  Out of resources.\r
+  Start this driver on Controller by opening Graphics Output protocol or \r
+  UGA Draw protocol, and installing Simple Text Out protocol on Controller.\r
+  (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)\r
+  \r
+  @param  This                 Protocol instance pointer.\r
+  @param  Controller           Handle of device to bind driver to\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          This driver is added to Controller.\r
+  @retval other                This driver does not support this device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -322,7 +386,7 @@ GraphicsConsoleControllerDriverStart (
     SimplifiedFont->NumberOfNarrowGlyphs = (UINT16) (NarrowFontSize / sizeof (EFI_NARROW_GLYPH));\r
 \r
     Location = (UINT8 *) (&SimplifiedFont->NumberOfWideGlyphs + 1);\r
-    CopyMem (Location, UsStdNarrowGlyphData, NarrowFontSize);\r
+    CopyMem (Location, gUsStdNarrowGlyphData, NarrowFontSize);\r
 \r
     //\r
     // Add this simplified font package to a package list then install it.\r
@@ -330,8 +394,8 @@ GraphicsConsoleControllerDriverStart (
     PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package);\r
     Status = mHiiDatabase->NewPackageList (mHiiDatabase, PackageList, NULL, &(Private->HiiHandle));\r
     ASSERT_EFI_ERROR (Status);\r
-    SafeFreePool (PackageList);\r
-    SafeFreePool (Package);\r
+    FreePool (PackageList);\r
+    FreePool (Package);\r
 \r
     mFirstAccessFlag = FALSE;\r
   }\r
@@ -441,22 +505,22 @@ GraphicsConsoleControllerDriverStart (
   // 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].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
+  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].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
+    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
@@ -464,13 +528,13 @@ GraphicsConsoleControllerDriverStart (
   // 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].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
+    Private->ModeData[MaxMode].DeltaX        = 0;\r
+    Private->ModeData[MaxMode].DeltaY        = 0;\r
     MaxMode++;\r
   }\r
 \r
@@ -478,11 +542,11 @@ GraphicsConsoleControllerDriverStart (
   // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)\r
   //\r
   if (Columns >= 100 && Rows >= 31) {\r
-    Private->ModeData[MaxMode].GopWidth   = HorizontalResolution;\r
-    Private->ModeData[MaxMode].GopHeight  = VerticalResolution;\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
+    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
 \r
@@ -490,13 +554,13 @@ GraphicsConsoleControllerDriverStart (
   // 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].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
+    Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution % EFI_GLYPH_WIDTH) >> 1;\r
+    Private->ModeData[MaxMode].DeltaY        = (VerticalResolution % EFI_GLYPH_HEIGHT) >> 1;\r
     MaxMode++;\r
   }\r
 \r
@@ -530,7 +594,7 @@ GraphicsConsoleControllerDriverStart (
 Error:\r
   if (EFI_ERROR (Status)) {\r
     //\r
-    // Close the GOP or UGA IO Protocol\r
+    // Close the GOP and UGA Draw Protocol\r
     //\r
     if (Private->GraphicsOutput != NULL) {\r
       gBS->CloseProtocol (\r
@@ -562,6 +626,24 @@ Error:
   return Status;\r
 }\r
 \r
+/**\r
+  Stop this driver on Controller by removing Simple Text Out protocol \r
+  and closing the Graphics Output Protocol or UGA Draw protocol on Controller.\r
+  (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)\r
+  \r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  Controller        Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed Controller.\r
+  @retval EFI_NOT_STARTED   Simple Text Out protocol could not be found the \r
+                            Controller.\r
+  @retval other             This driver was not removed from this device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 GraphicsConsoleControllerDriverStop (\r
@@ -635,12 +717,31 @@ GraphicsConsoleControllerDriverStop (
   return Status;\r
 }\r
 \r
+/**\r
+  Check if the current specific mode supported the user defined resolution\r
+  for the Graphice Console devcie based on Graphics Output Protocol.\r
+\r
+  If yes, set the graphic devcice's current mode to this specific mode.\r
+  \r
+  @param  GraphicsOutput        Graphics Output Protocol instance pointer.\r
+  @param  HorizontalResolution  User defined horizontal resolution\r
+  @param  VerticalResolution    User defined vertical resolution.\r
+  @param  CurrentModeNumber     Current specific mode to be check.\r
+\r
+  @retval EFI_SUCCESS       The mode is supported.\r
+  @retval EFI_UNSUPPORTED   The specific mode is out of range of graphics \r
+                            devcie supported.\r
+  @retval other             The specific mode does not support user defined \r
+                            resolution or failed to set the current mode to the \r
+                            specific mode on graphics device.\r
+\r
+**/\r
 EFI_STATUS\r
 CheckModeSupported (\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput,\r
-  IN  UINT32  HorizontalResolution,\r
-  IN  UINT32  VerticalResolution,\r
-  OUT UINT32  *CurrentModeNumber\r
+  IN  UINT32                    HorizontalResolution,\r
+  IN  UINT32                    VerticalResolution,\r
+  OUT UINT32                    *CurrentModeNumber\r
   )\r
 {\r
   UINT32     ModeNumber;\r
@@ -680,9 +781,12 @@ CheckModeSupported (
 \r
 \r
 /**\r
-  Locate HII protocols for future usage.\r
-\r
+  Locate HII Database protocol and HII Font protocol.\r
 \r
+  @retval  EFI_SUCCESS     HII Database protocol and HII Font protocol \r
+                           are located successfully.\r
+  @return  other           Failed to locate HII Database protocol or \r
+                           HII Font protocol.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -734,20 +838,21 @@ EfiLocateHiiProtocol (
 //\r
 \r
 /**\r
+  Reset the text output device hardware and optionaly run diagnostics.\r
+  \r
   Implements SIMPLE_TEXT_OUTPUT.Reset().\r
   If ExtendeVerification is TRUE, then perform dependent Graphics Console\r
   device reset, and set display mode to mode 0.\r
   If ExtendedVerification is FALSE, only set display mode to mode 0.\r
 \r
-  @param  This                  Indicates the calling context.\r
+  @param  This                  Protocol instance pointer.\r
   @param  ExtendedVerification  Indicates that the driver may perform a more\r
                                 exhaustive verification operation of the device\r
                                 during reset.\r
 \r
-  @return EFI_SUCCESS\r
-  @return The reset operation succeeds.\r
-  @return EFI_DEVICE_ERROR\r
-  @return The Graphics Console is not functioning correctly\r
+  @retval EFI_SUCCESS          The text output device was reset.\r
+  @retval EFI_DEVICE_ERROR     The text output device is not functioning correctly and\r
+                               could not be reset.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -763,21 +868,25 @@ GraphicsConsoleConOutReset (
 \r
 \r
 /**\r
-  Implements SIMPLE_TEXT_OUTPUT.OutputString().\r
+  Write a Unicode string to the output device.\r
+\r
+  Implements SIMPLE_TEXT_OUTPUT.OutputString(). \r
   The Unicode string will be converted to Glyphs and will be\r
   sent to the Graphics Console.\r
 \r
-  @param  This                  Indicates the calling context.\r
-  @param  WString               The Null-terminated Unicode string to be displayed\r
-                                on the Graphics Console.\r
+  @param  This                    Protocol instance pointer.\r
+  @param  WString                 The NULL-terminated Unicode string to be displayed\r
+                                  on the output device(s). All output devices must\r
+                                  also support the Unicode drawing defined in this file.\r
 \r
-  @return EFI_SUCCESS\r
-  @return The string is output successfully.\r
-  @return EFI_DEVICE_ERROR\r
-  @return The Graphics Console failed to send the string out.\r
-  @return EFI_WARN_UNKNOWN_GLYPH\r
-  @return Indicates that some of the characters in the Unicode string could not\r
-  @return be rendered and are skipped.\r
+  @retval EFI_SUCCESS             The string was output to the device.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error while attempting to output\r
+                                  the text.\r
+  @retval EFI_UNSUPPORTED         The output device's mode is not currently in a\r
+                                  defined text mode.\r
+  @retval EFI_WARN_UNKNOWN_GLYPH  This warning code indicates that some of the\r
+                                  characters in the Unicode string could not be\r
+                                  rendered and were skipped.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1055,21 +1164,23 @@ GraphicsConsoleConOutOutputString (
 \r
 }\r
 \r
-\r
 /**\r
-  Implements SIMPLE_TEXT_OUTPUT.TestString().\r
-  If one of the characters in the *Wstring is\r
-  neither valid valid Unicode drawing characters,\r
-  not ASCII code, then this function will return\r
-  EFI_UNSUPPORTED.\r
+  Verifies that all characters in a Unicode string can be output to the \r
+  target device.\r
+\r
+  Implements SIMPLE_TEXT_OUTPUT.QueryMode().\r
+  If one of the characters in the *Wstring is neither valid valid Unicode\r
+  drawing characters, not ASCII code, then this function will return\r
+  EFI_UNSUPPORTED\r
 \r
-  @param  This                  Indicates the calling context.\r
-  @param  WString               The Null-terminated Unicode string to be tested.\r
+  @param  This    Protocol instance pointer.\r
+  @param  WString The NULL-terminated Unicode string to be examined for the output\r
+                  device(s).\r
 \r
-  @return EFI_SUCCESS\r
-  @return The Graphics Console is capable of rendering the output string.\r
-  @return EFI_UNSUPPORTED\r
-  @return Some of the characters in the Unicode string cannot be rendered.\r
+  @retval EFI_SUCCESS      The device(s) are capable of rendering the output string.\r
+  @retval EFI_UNSUPPORTED  Some of the characters in the Unicode string cannot be\r
+                           rendered by one or more of the output devices mapped\r
+                           by the EFI handle.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1095,8 +1206,10 @@ GraphicsConsoleConOutTestString (
                          &Blt,\r
                          NULL\r
                          );\r
-    SafeFreePool (Blt);\r
-    Blt = NULL;\r
+    if (Blt != NULL) {\r
+      FreePool (Blt);\r
+      Blt = NULL;\r
+    }\r
     Count++;\r
 \r
     if (EFI_ERROR (Status)) {\r
@@ -1109,21 +1222,20 @@ GraphicsConsoleConOutTestString (
 \r
 \r
 /**\r
+  Returns information for an available text mode that the output device(s)\r
+  supports\r
+\r
   Implements SIMPLE_TEXT_OUTPUT.QueryMode().\r
-  It returnes information for an available text mode\r
-  that the Graphics Console supports.\r
-  In this driver,we only support text mode 80x25, which is\r
-  defined as mode 0.\r
+  It returnes information for an available text mode that the Graphics Console supports.\r
+  In this driver,we only support text mode 80x25, which is defined as mode 0.\r
 \r
-  @param  This                  Indicates the calling context.\r
+  @param  This                  Protocol instance pointer.\r
   @param  ModeNumber            The mode number to return information on.\r
   @param  Columns               The returned columns of the requested mode.\r
   @param  Rows                  The returned rows of the requested mode.\r
 \r
-  @return EFI_SUCCESS\r
-  @return The requested mode information is returned.\r
-  @return EFI_UNSUPPORTED\r
-  @return The mode number is not valid.\r
+  @retval EFI_SUCCESS           The requested mode information is returned.\r
+  @retval EFI_UNSUPPORTED       The mode number is not valid.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1164,19 +1276,18 @@ Done:
 \r
 \r
 /**\r
+  Sets the output device(s) to a specified mode.\r
+  \r
   Implements SIMPLE_TEXT_OUTPUT.SetMode().\r
-  Set the Graphics Console to a specified mode.\r
-  In this driver, we only support mode 0.\r
+  Set the Graphics Console to a specified mode. In this driver, we only support mode 0.\r
 \r
-  @param  This                  Indicates the calling context.\r
+  @param  This                  Protocol instance pointer.\r
   @param  ModeNumber            The text mode to set.\r
 \r
-  @return EFI_SUCCESS\r
-  @return The requested text mode is set.\r
-  @return EFI_DEVICE_ERROR\r
-  @return The requested text mode cannot be set because of Graphics Console device error.\r
-  @return EFI_UNSUPPORTED\r
-  @return The text mode number is not valid.\r
+  @retval EFI_SUCCESS           The requested text mode is set.\r
+  @retval EFI_DEVICE_ERROR      The requested text mode cannot be set because of \r
+                                Graphics Console device error.\r
+  @retval EFI_UNSUPPORTED       The text mode number is not valid.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1360,15 +1471,19 @@ Done:
 \r
 \r
 /**\r
+  Sets the background and foreground colors for the OutputString () and\r
+  ClearScreen () functions.\r
+\r
   Implements SIMPLE_TEXT_OUTPUT.SetAttribute().\r
 \r
-  @param  This                  Indicates the calling context.\r
-  @param  Attribute             The attribute to set. Only bit0..6 are valid, all\r
-                                other bits are undefined and must be zero.\r
+  @param  This                  Protocol instance pointer.\r
+  @param  Attribute             The attribute to set. Bits 0..3 are the foreground\r
+                                color, and bits 4..6 are the background color. \r
+                                All other bits are undefined and must be zero.\r
 \r
-  @return EFI_SUCCESS           The requested attribute is set.\r
-  @return EFI_DEVICE_ERROR      The requested attribute cannot be set due to Graphics Console port error.\r
-  @return EFI_UNSUPPORTED       The attribute requested is not defined by EFI spec.\r
+  @retval EFI_SUCCESS           The requested attribute is set.\r
+  @retval EFI_DEVICE_ERROR      The requested attribute cannot be set due to Graphics Console port error.\r
+  @retval EFI_UNSUPPORTED       The attribute requested is not defined.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1403,18 +1518,16 @@ GraphicsConsoleConOutSetAttribute (
 \r
 \r
 /**\r
+  Clears the output device(s) display to the currently selected background \r
+  color.\r
+\r
   Implements SIMPLE_TEXT_OUTPUT.ClearScreen().\r
-  It clears the Graphics Console's display to the\r
-  currently selected background color.\r
 \r
-  @param  This                  Indicates the calling context.\r
+  @param  This                  Protocol instance pointer.\r
 \r
-  @return EFI_SUCCESS\r
-  @return The operation completed successfully.\r
-  @return EFI_DEVICE_ERROR\r
-  @return The Graphics Console cannot be cleared due to Graphics Console device error.\r
-  @return EFI_UNSUPPORTED\r
-  @return The Graphics Console is not in a valid text mode.\r
+  @retval  EFI_SUCCESS      The operation completed successfully.\r
+  @retval  EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
+  @retval  EFI_UNSUPPORTED  The output device is not in a valid text mode.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1482,19 +1595,22 @@ GraphicsConsoleConOutClearScreen (
 \r
 \r
 /**\r
+  Sets the current coordinates of the cursor position.\r
+\r
   Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().\r
 \r
-  @param  This                  Indicates the calling context.\r
-  @param  Column                The row to set cursor to.\r
-  @param  Row                   The column to set cursor to.\r
+  @param  This        Protocol instance pointer.\r
+  @param  Column      The position to set the cursor to. Must be greater than or\r
+                      equal to zero and less than the number of columns and rows\r
+                      by QueryMode ().\r
+  @param  Row         The position to set the cursor to. Must be greater than or\r
+                      equal to zero and less than the number of columns and rows\r
+                      by QueryMode ().\r
 \r
-  @return EFI_SUCCESS\r
-  @return The operation completed successfully.\r
-  @return EFI_DEVICE_ERROR\r
-  @return The request fails due to Graphics Console device error.\r
-  @return EFI_UNSUPPORTED\r
-  @return The Graphics Console is not in a valid text mode, or the cursor position\r
-  @return is invalid for current mode.\r
+  @retval EFI_SUCCESS      The operation completed successfully.\r
+  @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
+  @retval EFI_UNSUPPORTED  The output device is not in a valid text mode, or the\r
+                           cursor position is invalid for the current mode.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1522,7 +1638,7 @@ GraphicsConsoleConOutSetCursorPosition (
     goto Done;\r
   }\r
 \r
-  if (((INT32) Column == This->Mode->CursorColumn) && ((INT32) Row == This->Mode->CursorRow)) {\r
+  if ((This->Mode->CursorColumn == (INT32) Column) && (This->Mode->CursorRow == (INT32) Row)) {\r
     Status = EFI_SUCCESS;\r
     goto Done;\r
   }\r
@@ -1542,17 +1658,15 @@ Done:
 \r
 \r
 /**\r
+  Makes the cursor visible or invisible.\r
+\r
   Implements SIMPLE_TEXT_OUTPUT.EnableCursor().\r
-  In this driver, the cursor cannot be hidden.\r
 \r
-  @param  This                  Indicates the calling context.\r
+  @param  This                  Protocol instance pointer.\r
   @param  Visible               If TRUE, the cursor is set to be visible, If FALSE,\r
                                 the cursor is set to be invisible.\r
 \r
-  @return EFI_SUCCESS\r
-  @return The request is valid.\r
-  @return EFI_UNSUPPORTED\r
-  @return The Graphics Console does not support a hidden cursor.\r
+  @retval EFI_SUCCESS           The operation completed successfully.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1576,6 +1690,16 @@ GraphicsConsoleConOutEnableCursor (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Gets Graphics Console devcie's foreground color and background color.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  Foreground            Returned text foreground color.\r
+  @param  Background            Returned text background color.\r
+\r
+  @retval EFI_SUCCESS           It returned always.\r
+\r
+**/\r
 EFI_STATUS\r
 GetTextColors (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
@@ -1593,11 +1717,24 @@ GetTextColors (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Draw Unicode string on the Graphice Console device's screen.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  UnicodeWeight         One Unicode string to be displayed.\r
+  @param  Count                 The count of Unicode string.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  If no memory resource to use.\r
+  @retval EFI_UNSUPPORTED       If no Graphics Output protocol and UGA Draw\r
+                                protocol exist.\r
+  @retval EFI_SUCCESS           Drawing Unicode string implemented successfully.\r
+\r
+**/\r
 EFI_STATUS\r
 DrawUnicodeWeightAtCursorN (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
-  IN  CHAR16                        *UnicodeWeight,\r
-  IN  UINTN                         Count\r
+  IN  CHAR16                           *UnicodeWeight,\r
+  IN  UINTN                            Count\r
   )\r
 {\r
   EFI_STATUS                        Status;\r
@@ -1620,20 +1757,29 @@ DrawUnicodeWeightAtCursorN (
 \r
   String = AllocateCopyPool ((Count + 1) * sizeof (CHAR16), UnicodeWeight);\r
   if (String == NULL) {\r
-    SafeFreePool (Blt);\r
+    FreePool (Blt);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  *(String + Count) = 0;\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
   if (FontInfo == NULL) {\r
-    SafeFreePool (Blt);\r
-    SafeFreePool (String);\r
+    FreePool (Blt);\r
+    FreePool (String);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+  //\r
+  // Get current foreground and background colors.\r
+  //\r
   GetTextColors (This, &FontInfo->ForegroundColor, &FontInfo->BackgroundColor);\r
 \r
   if (Private->GraphicsOutput != NULL) {\r
+    //\r
+    // If Graphcis Output protocol exists, using HII Font protocol to draw. \r
+    //\r
     Blt->Image.Screen = Private->GraphicsOutput;\r
 \r
     Status = mHiiFont->StringToImage (\r
@@ -1650,14 +1796,18 @@ DrawUnicodeWeightAtCursorN (
                          );\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
 \r
     UgaDraw = Private->UgaDraw;\r
 \r
     Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
     if (Blt->Image.Bitmap == NULL) {\r
-      SafeFreePool (Blt);\r
-      SafeFreePool (String);\r
+      FreePool (Blt);\r
+      FreePool (String);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
@@ -1700,19 +1850,32 @@ DrawUnicodeWeightAtCursorN (
                           );\r
     }\r
 \r
-    SafeFreePool (RowInfoArray);\r
-    SafeFreePool (Blt->Image.Bitmap);\r
+    FreePool (RowInfoArray);\r
+    FreePool (Blt->Image.Bitmap);\r
   } else {\r
     Status = EFI_UNSUPPORTED;\r
   }\r
 \r
-  SafeFreePool (Blt);\r
-  SafeFreePool (String);\r
-  SafeFreePool (FontInfo);\r
+  if (Blt != NULL) {\r
+    FreePool (Blt);\r
+  }\r
+  if (String != NULL) {\r
+    FreePool (String);\r
+  }\r
+  if (FontInfo != NULL) {\r
+    FreePool (FontInfo);\r
+  }\r
   return Status;\r
 }\r
 \r
+/**\r
+  Erase the cursor on the screen.\r
+\r
+  @param  This                  Protocol instance pointer.\r
 \r
+  @retval EFI_SUCCESS           The cursor is erased successfully.\r
+\r
+**/\r
 EFI_STATUS\r
 EraseCursor (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
@@ -1741,7 +1904,7 @@ EraseCursor (
   UgaDraw = Private->UgaDraw;\r
 \r
   //\r
-  // BUGBUG - we need to think about what to do with wide and narrow character deletions.\r
+  // In this driver, only narrow character was supported.\r
   //\r
   //\r
   // Blt a character to the screen\r