]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/Console/VgaClassDxe/VgaClass.c
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / Console / VgaClassDxe / VgaClass.c
index 71e0360da8561b7a15f2969f37ef3ac3f57c5093..a9da74c7920eeb8161abbbfc682de0b711108a9c 100644 (file)
@@ -1,14 +1,14 @@
-/**@file\r
-  This driver produces a VGA console.\r
-\r
-Copyright (c) 2006, Intel Corporation                                                         \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
+/** @file\r
+  VGA Class Driver that managers VGA devices and produces Simple Text Output Protocol.\r
+\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
@@ -26,52 +26,10 @@ EFI_DRIVER_BINDING_PROTOCOL gVgaClassDriverBinding = {
   NULL\r
 };\r
 \r
-/**\r
-  The user Entry Point for module VgaClass. The user code starts with this function.\r
-\r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
-  @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \r
-  @retval EFI_SUCCESS       The entry point is executed successfully.\r
-  @retval other             Some error occurs when executing this entry point.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InitializeVgaClass(\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE     *SystemTable\r
-  )\r
-{\r
-  EFI_STATUS              Status;\r
-\r
-  //\r
-  // Install driver model protocol(s).\r
-  //\r
-  Status = EfiLibInstallDriverBindingComponentName2 (\r
-             ImageHandle,\r
-             SystemTable,\r
-             &gVgaClassDriverBinding,\r
-             ImageHandle,\r
-             &gVgaClassComponentName,\r
-             &gVgaClassComponentName2\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-\r
-  return Status;\r
-}\r
-\r
 //\r
 // Local variables\r
 //\r
-static CHAR16               CrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
-\r
-typedef struct {\r
-  CHAR16  Unicode;\r
-  CHAR8   PcAnsi;\r
-  CHAR8   Ascii;\r
-} UNICODE_TO_CHAR;\r
+CHAR16               CrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
 \r
 //\r
 // This list is used to define the valid extend chars.\r
@@ -79,7 +37,7 @@ typedef struct {
 // ASCII. The ASCII mapping we just made up.\r
 //\r
 //\r
-STATIC UNICODE_TO_CHAR  UnicodeToPcAnsiOrAscii[] = {\r
+UNICODE_TO_CHAR  UnicodeToPcAnsiOrAscii[] = {\r
   {\r
     BOXDRAW_HORIZONTAL,\r
     0xc4,\r
@@ -344,58 +302,220 @@ STATIC UNICODE_TO_CHAR  UnicodeToPcAnsiOrAscii[] = {
   }\r
 };\r
 \r
-//\r
-// Private worker functions\r
-//\r
-STATIC\r
+/**\r
+  Entrypoint of this VGA Class Driver.\r
+\r
+  This function is the entrypoint of this VGA Class Driver. It installs Driver Binding\r
+  Protocols together with Component Name Protocols.\r
+\r
+  @param  ImageHandle       The firmware allocated handle for the EFI image.\r
+  @param  SystemTable       A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeVgaClass(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gVgaClassDriverBinding,\r
+             ImageHandle,\r
+             &gVgaClassComponentName,\r
+             &gVgaClassComponentName2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Internal worker function to program CRTC register via PCI I/O Protocol.\r
+\r
+  @param VgaClassDev  device instance object\r
+  @param Address      Address of register to write\r
+  @param Data         Data to write to register.\r
+\r
+**/\r
+VOID\r
+WriteCrtc (\r
+  IN  VGA_CLASS_DEV  *VgaClassDev,\r
+  IN  UINT16         Address,\r
+  IN  UINT8          Data\r
+  )\r
+{\r
+  VgaClassDev->PciIo->Io.Write (\r
+                           VgaClassDev->PciIo,\r
+                           EfiPciIoWidthUint8,\r
+                           VgaClassDev->VgaMiniPort->CrtcAddressRegisterBar,\r
+                           VgaClassDev->VgaMiniPort->CrtcAddressRegisterOffset,\r
+                           1,\r
+                           &Address\r
+                           );\r
+\r
+  VgaClassDev->PciIo->Io.Write (\r
+                           VgaClassDev->PciIo,\r
+                           EfiPciIoWidthUint8,\r
+                           VgaClassDev->VgaMiniPort->CrtcDataRegisterBar,\r
+                           VgaClassDev->VgaMiniPort->CrtcDataRegisterOffset,\r
+                           1,\r
+                           &Data\r
+                           );\r
+}\r
+\r
+/**\r
+  Internal worker function to set cursor's position to VgaClass device\r
+\r
+  @param  VgaClassDev   Private data structure for device instance.\r
+  @param  Column        Colomn of position to set cursor to.\r
+  @param  Row           Row of position to set cursor to.\r
+  @param  MaxColumn     Max value of column.\r
+\r
+**/\r
 VOID\r
 SetVideoCursorPosition (\r
   IN  VGA_CLASS_DEV  *VgaClassDev,\r
   IN  UINTN          Column,\r
   IN  UINTN          Row,\r
   IN  UINTN          MaxColumn\r
-  );\r
+  )\r
+{\r
+  Column    = Column & 0xff;\r
+  Row       = Row & 0xff;\r
+  MaxColumn = MaxColumn & 0xff;\r
 \r
-STATIC\r
-VOID\r
-WriteCrtc (\r
-  IN  VGA_CLASS_DEV  *VgaClassDev,\r
-  IN  UINT16         Address,\r
-  IN  UINT8          Data\r
-  );\r
+  WriteCrtc (\r
+    VgaClassDev,\r
+    CRTC_CURSOR_LOCATION_HIGH,\r
+    (UINT8) ((Row * MaxColumn + Column) >> 8)\r
+    );\r
+  WriteCrtc (\r
+    VgaClassDev,\r
+    CRTC_CURSOR_LOCATION_LOW,\r
+    (UINT8) ((Row * MaxColumn + Column) & 0xff)\r
+    );\r
+}\r
+\r
+/**\r
+  Internal worker function to detect if a Unicode char is for Box Drawing text graphics.\r
+\r
+  @param  Graphic  Unicode char to test.\r
+  @param  PcAnsi   Pointer to PCANSI equivalent of Graphic for output.\r
+                   If NULL, then PCANSI value is not returned.\r
+  @param  Ascii    Pointer to ASCII equivalent of Graphic for output.\r
+                   If NULL, then ASCII value is not returned.\r
+\r
+  @retval TRUE     Gpaphic is a supported Unicode Box Drawing character.\r
+  @retval FALSE    Gpaphic is not a supported Unicode Box Drawing character.\r
 \r
-STATIC\r
+**/\r
 BOOLEAN\r
 LibIsValidTextGraphics (\r
   IN  CHAR16  Graphic,\r
   OUT CHAR8   *PcAnsi, OPTIONAL\r
   OUT CHAR8   *Ascii OPTIONAL\r
-  );\r
+  )\r
+{\r
+  UNICODE_TO_CHAR *Table;\r
+\r
+  //\r
+  // Unicode drawing code charts are all in the 0x25xx range, arrows are 0x21xx.\r
+  // So first filter out values not in these 2 ranges.\r
+  //\r
+  if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) {\r
+    return FALSE;\r
+  }\r
 \r
-STATIC\r
+  //\r
+  // Search UnicodeToPcAnsiOrAscii table for matching entry.\r
+  //\r
+  for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) {\r
+    if (Graphic == Table->Unicode) {\r
+      if (PcAnsi != NULL) {\r
+        *PcAnsi = Table->PcAnsi;\r
+      }\r
+\r
+      if (Ascii != NULL) {\r
+        *Ascii = Table->Ascii;\r
+      }\r
+\r
+      return TRUE;\r
+    }\r
+  }\r
+\r
+  //\r
+  // If value is not found in UnicodeToPcAnsiOrAscii table, then return FALSE.\r
+  //\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Internal worker function to check whether input value is an ASCII char.\r
+\r
+  @param  Char     Character to check.\r
+\r
+  @retval TRUE     Input value is an ASCII char.\r
+  @retval FALSE    Input value is not an ASCII char.\r
+\r
+**/\r
 BOOLEAN\r
 IsValidAscii (\r
-  IN  CHAR16  Ascii\r
-  );\r
+  IN  CHAR16  Char\r
+  )\r
+{\r
+  if ((Char >= 0x20) && (Char <= 0x7f)) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
 \r
-STATIC\r
+/**\r
+  Internal worker function to check whether input value is a unicode control char.\r
+\r
+  @param  Char    Character to check.\r
+\r
+  @retval TRUE     Input value is a unicode control char.\r
+  @retval FALSE    Input value is not a unicode control char.\r
+\r
+**/\r
 BOOLEAN\r
 IsValidEfiCntlChar (\r
-  IN  CHAR16  c\r
-  );\r
+  IN  CHAR16  Char\r
+  )\r
+{\r
+  if (Char == CHAR_NULL || Char == CHAR_BACKSPACE || Char == CHAR_LINEFEED || Char == CHAR_CARRIAGE_RETURN) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
 \r
 /**\r
-  Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
-  than contains a VgaMiniPort and PciIo protocol can be supported.\r
+  Tests to see if this driver supports a given controller.\r
+\r
+  This function implments EFI_DRIVER_BINDING_PROTOCOL.Supported().\r
+  It Checks if this driver supports the controller specified. Any Controller\r
+  with VgaMiniPort Protocol and Pci I/O protocol can be supported.\r
 \r
-  @param  This                Protocol instance pointer.\r
+  @param  This                A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
   @param  ControllerHandle    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 EFI_ALREADY_STARTED This driver is already running on this device\r
-  @retval other               This driver does not support this device\r
+  @retval EFI_SUCCESS         This driver supports this device.\r
+  @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
+  @retval EFI_UNSUPPORTED     This driver does not support this device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -403,19 +523,18 @@ EFIAPI
 VgaClassDriverBindingSupported (\r
   IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN EFI_HANDLE                   Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
-  EFI_VGA_MINI_PORT_PROTOCOL  *VgaMiniPort;\r
 \r
   //\r
-  // Open the IO Abstraction(s) needed to perform the supported test\r
+  // Checks if Abstraction(s) needed to perform the supported test\r
   //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiVgaMiniPortProtocolGuid,\r
-                  (VOID **) &VgaMiniPort,\r
+                  NULL,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
@@ -442,18 +561,19 @@ VgaClassDriverBindingSupported (
 }\r
 \r
 /**\r
-  Start this driver on ControllerHandle by opening a PciIo and VgaMiniPort\r
-  protocol, creating VGA_CLASS_DEV device and install gEfiSimpleTextOutProtocolGuid\r
-  finnally.\r
+  Starts the device controller.\r
+\r
+  This function implments EFI_DRIVER_BINDING_PROTOCOL.Start().\r
+  It starts the device specified by Controller with the driver based on PCI I/O Protocol\r
+  and VgaMiniPort Protocol. It creates context for device instance and install EFI_SIMPLE_TEXT_OUT_PROTOCOL.\r
 \r
-  @param  This                 Protocol instance pointer.\r
+  @param  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
   @param  ControllerHandle     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 ControllerHandle\r
-  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
-  @retval other                This driver does not support this device\r
+  @retval EFI_SUCCESS          The device was started.\r
+  @retval other                Fail to start the device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -461,7 +581,7 @@ EFIAPI
 VgaClassDriverBindingStart (\r
   IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN EFI_HANDLE                   Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -488,7 +608,7 @@ VgaClassDriverBindingStart (
     );\r
 \r
   //\r
-  // Open the IO Abstraction(s) needed\r
+  // Open the PCI I/O Protocol\r
   //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
@@ -501,7 +621,9 @@ VgaClassDriverBindingStart (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-\r
+  //\r
+  // Open the VGA Mini Port Protocol\r
+  //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiVgaMiniPortProtocolGuid,\r
@@ -516,49 +638,37 @@ VgaClassDriverBindingStart (
   //\r
   // Allocate the private device structure\r
   //\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  sizeof (VGA_CLASS_DEV),\r
-                  (VOID **) &VgaClassPrivate\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    gBS->CloseProtocol (\r
-          Controller,\r
-          &gEfiVgaMiniPortProtocolGuid,\r
-          This->DriverBindingHandle,\r
-          Controller\r
-          );\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  ZeroMem (VgaClassPrivate, sizeof (VGA_CLASS_DEV));\r
+  VgaClassPrivate = AllocateZeroPool (sizeof (VGA_CLASS_DEV));\r
+  ASSERT (VgaClassPrivate != NULL);\r
 \r
   //\r
   // Initialize the private device structure\r
   //\r
-  VgaClassPrivate->Signature                        = VGA_CLASS_DEV_SIGNATURE;\r
-  VgaClassPrivate->Handle = Controller;\r
+  VgaClassPrivate->Signature   = VGA_CLASS_DEV_SIGNATURE;\r
+  VgaClassPrivate->Handle      = Controller;\r
   VgaClassPrivate->VgaMiniPort = VgaMiniPort;\r
-  VgaClassPrivate->PciIo = PciIo;\r
+  VgaClassPrivate->PciIo       = PciIo;\r
 \r
-  VgaClassPrivate->SimpleTextOut.Reset = VgaClassReset;\r
-  VgaClassPrivate->SimpleTextOut.OutputString = VgaClassOutputString;\r
-  VgaClassPrivate->SimpleTextOut.TestString = VgaClassTestString;\r
-  VgaClassPrivate->SimpleTextOut.ClearScreen = VgaClassClearScreen;\r
-  VgaClassPrivate->SimpleTextOut.SetAttribute = VgaClassSetAttribute;\r
+  VgaClassPrivate->SimpleTextOut.Reset             = VgaClassReset;\r
+  VgaClassPrivate->SimpleTextOut.OutputString      = VgaClassOutputString;\r
+  VgaClassPrivate->SimpleTextOut.TestString        = VgaClassTestString;\r
+  VgaClassPrivate->SimpleTextOut.ClearScreen       = VgaClassClearScreen;\r
+  VgaClassPrivate->SimpleTextOut.SetAttribute      = VgaClassSetAttribute;\r
   VgaClassPrivate->SimpleTextOut.SetCursorPosition = VgaClassSetCursorPosition;\r
-  VgaClassPrivate->SimpleTextOut.EnableCursor = VgaClassEnableCursor;\r
-  VgaClassPrivate->SimpleTextOut.QueryMode = VgaClassQueryMode;\r
-  VgaClassPrivate->SimpleTextOut.SetMode = VgaClassSetMode;\r
+  VgaClassPrivate->SimpleTextOut.EnableCursor      = VgaClassEnableCursor;\r
+  VgaClassPrivate->SimpleTextOut.QueryMode         = VgaClassQueryMode;\r
+  VgaClassPrivate->SimpleTextOut.SetMode           = VgaClassSetMode;\r
 \r
-  VgaClassPrivate->SimpleTextOut.Mode = &VgaClassPrivate->SimpleTextOutputMode;\r
-  VgaClassPrivate->SimpleTextOutputMode.MaxMode = VgaMiniPort->MaxMode;\r
-  VgaClassPrivate->DevicePath = DevicePath;\r
+  VgaClassPrivate->SimpleTextOut.Mode              = &VgaClassPrivate->SimpleTextOutputMode;\r
+  VgaClassPrivate->SimpleTextOutputMode.MaxMode    = VgaMiniPort->MaxMode;\r
+  VgaClassPrivate->DevicePath                      = DevicePath;\r
 \r
+  //\r
+  // Initialize the VGA device.\r
+  //\r
   Status = VgaClassPrivate->SimpleTextOut.SetAttribute (\r
                                             &VgaClassPrivate->SimpleTextOut,\r
-                                            EFI_TEXT_ATTR (EFI_WHITE,\r
-    EFI_BLACK)\r
+                                            EFI_TEXT_ATTR (EFI_WHITE, EFI_BLACK)\r
                                             );\r
   if (EFI_ERROR (Status)) {\r
     goto ErrorExit;\r
@@ -601,14 +711,16 @@ ErrorExit:
 }\r
 \r
 /**\r
-  Stop this driver on ControllerHandle. Support stoping any child handles\r
+  Starts the device controller.\r
+\r
+  This function implments EFI_DRIVER_BINDING_PROTOCOL.Stop().\r
+  It stops this driver on Controller. Support stopping any child handles\r
   created by this driver.\r
 \r
-  @param  This              Protocol instance pointer.\r
-  @param  ControllerHandle  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
+  @param  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param  ControllerHandle  A handle to the device being stopped.\r
+  @param  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
+  @param  ChildHandleBuffer An array of child handles to be freed.\r
 \r
   @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
   @retval other             This driver was not removed from this device\r
@@ -620,7 +732,7 @@ VgaClassDriverBindingStop (
   IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
   IN  EFI_HANDLE                      Controller,\r
   IN  UINTN                           NumberOfChildren,\r
-  IN  EFI_HANDLE                      *ChildHandleBuffer\r
+  IN  EFI_HANDLE                      *ChildHandleBuffer OPTIONAL\r
   )\r
 {\r
   EFI_STATUS                    Status;\r
@@ -662,34 +774,43 @@ VgaClassDriverBindingStop (
   // Release PCI I/O and VGA Mini Port Protocols on the controller handle.\r
   //\r
   gBS->CloseProtocol (\r
-        Controller,\r
-        &gEfiPciIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Controller\r
-        );\r
+         Controller,\r
+         &gEfiPciIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
 \r
   gBS->CloseProtocol (\r
-        Controller,\r
-        &gEfiVgaMiniPortProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Controller\r
-        );\r
+         Controller,\r
+         &gEfiVgaMiniPortProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
 \r
-  gBS->FreePool (VgaClassPrivate);\r
+  FreePool (VgaClassPrivate);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Reset VgaClass device and clear output.\r
-  \r
-  @param This                 Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.\r
-  @param ExtendedVerification Whether need additional judgement\r
+  Resets the text output device hardware.\r
+\r
+  This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().\r
+  It resets the text output device hardware. The cursor position is set to (0, 0),\r
+  and the screen is cleared to the default background color for the output device.\r
+\r
+  @param  This                 Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
+  @param  ExtendedVerification Indicates that the driver may perform a more exhaustive\r
+                               verification operation of the device during reset.\r
+\r
+  @retval EFI_SUCCESS          The text output device was reset.\r
+  @retval EFI_DEVICE_ERROR     The text output device is not functioning correctly and could not be reset.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 VgaClassReset (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL        *This,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL     *This,\r
   IN  BOOLEAN                             ExtendedVerification\r
   )\r
 {\r
@@ -715,16 +836,27 @@ VgaClassReset (
 }\r
 \r
 /**\r
-  Output a string to VgaClass device.\r
-  \r
-  @param This                 Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.\r
-  @param WString              wide chars.\r
+  Writes a Unicode string to the output device.\r
+\r
+  This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().\r
+  It writes a Unicode string to the output device. This is the most basic output mechanism\r
+  on an output device.\r
+\r
+  @param  This                   Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
+  @param  String                 The Null-terminated Unicode string to be displayed on the output device(s).\r
+\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 the text.\r
+  @retval EFI_UNSUPPORTED        The output device's mode is not currently in a defined text mode.\r
+  @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the characters in\r
+                                 the Unicode string could not be rendered and were skipped.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 VgaClassOutputString (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
-  IN  CHAR16                          *WString\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
+  IN  CHAR16                          *String\r
   )\r
 {\r
   EFI_STATUS                  Status;\r
@@ -736,22 +868,24 @@ VgaClassOutputString (
   CHAR8                       GraphicChar;\r
 \r
   VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
-\r
   Mode        = This->Mode;\r
 \r
   Status = This->QueryMode (\r
-                  This,\r
-                  Mode->Mode,\r
-                  &MaxColumn,\r
-                  &MaxRow\r
-                  );\r
+                   This,\r
+                   Mode->Mode,\r
+                   &MaxColumn,\r
+                   &MaxRow\r
+                   );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  for (; *WString != CHAR_NULL; WString++) {\r
+  //\r
+  // Parse each character of the string to output\r
+  //\r
+  for (; *String != CHAR_NULL; String++) {\r
 \r
-    switch (*WString) {\r
+    switch (*String) {\r
     case CHAR_BACKSPACE:\r
       if (Mode->CursorColumn > 0) {\r
         Mode->CursorColumn--;\r
@@ -799,14 +933,14 @@ VgaClassOutputString (
       break;\r
 \r
     default:\r
-      if (!LibIsValidTextGraphics (*WString, &GraphicChar, NULL)) {\r
+      if (!LibIsValidTextGraphics (*String, &GraphicChar, NULL)) {\r
         //\r
-        // Just convert to ASCII\r
+        // If this character is not ,Box Drawing text graphics, then convert it to ASCII.\r
         //\r
-        GraphicChar = (CHAR8) *WString;\r
+        GraphicChar = (CHAR8) *String;\r
         if (!IsValidAscii (GraphicChar)) {\r
           //\r
-          // Keep the API from supporting PCANSI Graphics chars\r
+          // If not valid ASCII char, convert it to "?"\r
           //\r
           GraphicChar = '?';\r
         }\r
@@ -842,38 +976,50 @@ VgaClassOutputString (
 }\r
 \r
 /**\r
-  Detects if a Unicode char is for Box Drawing text graphics.\r
-  \r
-  @param This     Pointer of EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r
-  @param WString  Unicode chars\r
-  \r
-  @return if a Unicode char is for Box Drawing text graphics.\r
+  Verifies that all characters in a Unicode string can be output to the target device.\r
+\r
+  This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().\r
+  It verifies that all characters in a Unicode string can be output to the target device.\r
+\r
+  @param  This                   Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
+  @param  String                 The Null-terminated Unicode string to be examined for the output device(s).\r
+\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 rendered by\r
+                                 one or more of the output devices mapped by the EFI handle.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 VgaClassTestString (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
-  IN  CHAR16                          *WString\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
+  IN  CHAR16                          *String\r
   )\r
 {\r
-  while (*WString != 0x0000) {\r
-    if (!(IsValidAscii (*WString) || IsValidEfiCntlChar (*WString) || LibIsValidTextGraphics (*WString, NULL, NULL))) {\r
+  while (*String != CHAR_NULL) {\r
+    if (!(IsValidAscii (*String) || IsValidEfiCntlChar (*String) || LibIsValidTextGraphics (*String, NULL, NULL))) {\r
       return EFI_UNSUPPORTED;\r
     }\r
 \r
-    WString++;\r
+    String++;\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Clear Screen via VgaClass device\r
-  \r
-  @param This     Pointer of EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL \r
-  \r
-  @retval EFI_SUCESS Success to clear screen\r
-  @retval Others     Wrong displaying mode.\r
+  Clears the output device(s) display to the currently selected background color.\r
+\r
+  This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().\r
+  The ClearScreen() function clears the output device(s) display to the currently\r
+  selected background color. The cursor position is set to (0, 0).\r
+\r
+  @param  This                   Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
+\r
+  @retval EFI_SUCESS             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
 EFIAPI\r
@@ -890,11 +1036,11 @@ VgaClassClearScreen (
   VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
 \r
   Status = This->QueryMode (\r
-                  This,\r
-                  This->Mode->Mode,\r
-                  &MaxColumn,\r
-                  &MaxRow\r
-                  );\r
+                   This,\r
+                   This->Mode->Mode,\r
+                   &MaxColumn,\r
+                   &MaxRow\r
+                   );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -916,18 +1062,27 @@ VgaClassClearScreen (
 }\r
 \r
 /**\r
-  Set displaying mode's attribute\r
-  \r
-  @param This      Pointer of EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL \r
-  @param Attribute Mode's attribute\r
-  \r
-  @param EFI_SUCCESS      Success to set attribute\r
-  @param EFI_UNSUPPORTED  Wrong mode's attribute wanted to be set\r
+  Sets the background and foreground colors for theOutputString() and ClearScreen() functions.\r
+\r
+  This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().\r
+  It sets the background and foreground colors for the OutputString() and ClearScreen() functions.\r
+  The color mask can be set even when the device is in an invalid text mode.\r
+  Devices supporting a different number of text colors are required to emulate the above colors\r
+  to the best of the device's capabilities.\r
+\r
+  @param  This                   Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
+  @param  Attribute              The attribute to set.\r
+                                 Bits 0..3 are the foreground color,\r
+                                 and bits 4..6 are the background color.\r
+\r
+  @retval EFI_SUCCESS            The requested attributes were set.\r
+  @retval EFI_DEVICE_ERROR       The device had an error and could not complete the request.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 VgaClassSetAttribute (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
   IN  UINTN                           Attribute\r
   )\r
 {\r
@@ -940,19 +1095,26 @@ VgaClassSetAttribute (
 }\r
 \r
 /**\r
-  Set cursor position.\r
-  \r
-  @param This      Pointer of EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL \r
-  @param Column    Column of new cursor position.\r
-  @param Row       Row of new cursor position.\r
-  \r
-  @retval EFI_SUCCESS Sucess to set cursor's position.\r
-  @retval Others      Wrong current displaying mode.\r
+  Sets the current coordinates of the cursor position.\r
+\r
+  This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().\r
+  It sets the current coordinates of the cursor position.\r
+  The upper left corner of the screen is defined as coordinate (0, 0).\r
+\r
+  @param  This                   Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
+  @param  Column                 Column of position to set the cursor to.\r
+  @param  Row                    Row of position to set the cursor to.\r
+\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 cursor\r
+                                 position is invalid for the current mode.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 VgaClassSetCursorPosition (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
   IN  UINTN                           Column,\r
   IN  UINTN                           Row\r
   )\r
@@ -965,11 +1127,11 @@ VgaClassSetCursorPosition (
   VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
 \r
   Status = This->QueryMode (\r
-                  This,\r
-                  This->Mode->Mode,\r
-                  &MaxColumn,\r
-                  &MaxRow\r
-                  );\r
+                   This,\r
+                   This->Mode->Mode,\r
+                   &MaxColumn,\r
+                   &MaxRow\r
+                   );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -987,17 +1149,25 @@ VgaClassSetCursorPosition (
 }\r
 \r
 /**\r
-  Enable cursor to display or not.\r
-  \r
-  @param This      Pointer of EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL \r
-  @param Visible   Display cursor or not.\r
-  \r
-  @retval EFI_SUCESS Success to display the cursor or not.\r
+  Makes the cursor visible or invisible.\r
+\r
+  This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.EnableCursor().\r
+  It makes the cursor visible or invisible.\r
+\r
+  @param  This                   Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
+  @param  Visible                If TRUE, the cursor is set to be visible.\r
+                                 If FALSE, the cursor is set to be invisible.\r
+\r
+  @retval EFI_SUCESS             The operation completed successfully.\r
+  @retval EFI_DEVICE_ERROR       The device had an error and could not complete the request or the\r
+                                 device does not support changing the cursor mode.\r
+  @retval EFI_UNSUPPORTED        The output device does not support visibility control of the cursor.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 VgaClassEnableCursor (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
   IN  BOOLEAN                         Visible\r
   )\r
 {\r
@@ -1005,16 +1175,18 @@ VgaClassEnableCursor (
 \r
   VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
   if (Visible) {\r
-    switch (This->Mode->Mode) {\r
-    case 1:\r
+    if (This->Mode->Mode == 1) {\r
+      //\r
+      // 80 * 50\r
+      //\r
       WriteCrtc (VgaClassDev, CRTC_CURSOR_START, 0x06);\r
       WriteCrtc (VgaClassDev, CRTC_CURSOR_END, 0x07);\r
-      break;\r
-\r
-    default:\r
+    } else {\r
+      //\r
+      // 80 * 25\r
+      //\r
       WriteCrtc (VgaClassDev, CRTC_CURSOR_START, 0x0e);\r
       WriteCrtc (VgaClassDev, CRTC_CURSOR_END, 0x0f);\r
-      break;\r
     }\r
   } else {\r
     WriteCrtc (VgaClassDev, CRTC_CURSOR_START, 0x20);\r
@@ -1025,23 +1197,27 @@ VgaClassEnableCursor (
 }\r
 \r
 /**\r
-  Query colum and row according displaying mode number\r
-  The mode:\r
-  0: 80 * 25\r
-  1: 80 * 50\r
-  \r
-  @param This       Pointer of EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r
-  @param ModeNumber Mode number\r
-  @param Columns    return the columen in current mode number\r
-  @param Rows       return the row in current mode number.\r
-  \r
-  @return EFI_SUCCESS     Sucess to get columns and rows according to mode number\r
-  @return EFI_UNSUPPORTED Unsupported mode number\r
+  Returns information for an available text mode that the output device(s) supports.\r
+\r
+  This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().\r
+  It returns information for an available text mode that the output device(s) supports.\r
+  It is required that all output devices support at least 80x25 text mode. This mode is defined to be mode 0.\r
+  If the output devices support 80x50, that is defined to be mode 1.\r
+\r
+  @param  This                   Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
+  @param  ModeNumber             The mode number to return information on.\r
+  @param  Columns                Columen in current mode number\r
+  @param  Rows                   Row in current mode number.\r
+\r
+  @retval EFI_SUCCESS            The requested mode information was returned.\r
+  @retval EFI_DEVICE_ERROR       The device had an error and could not complete the request.\r
+  @retval EFI_UNSUPPORTED        The mode number was not valid.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 VgaClassQueryMode (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
   IN  UINTN                           ModeNumber,\r
   OUT UINTN                           *Columns,\r
   OUT UINTN                           *Rows\r
@@ -1074,22 +1250,28 @@ VgaClassQueryMode (
 }\r
 \r
 /**\r
-  Set displaying mode number\r
-  \r
-  @param This       Pointer of EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r
-  @param ModeNumber mode number\r
-  \r
-  @retval EFI_UNSUPPORTED Unsupported mode number in parameter\r
-  @retval EFI_SUCCESS     Success to set the mode number.\r
+  Sets the output device(s) to a specified mode.\r
+\r
+  This function implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().\r
+  It sets the output device(s) to the requested mode.\r
+  On success the device is in the geometry for the requested mode,\r
+  and the device has been cleared to the current background color with the cursor at (0,0).\r
+\r
+  @param  This                   Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
+  @param  ModeNumber             The text mode to set.\r
+\r
+  @retval EFI_SUCCESS            The requested text mode was set.\r
+  @retval EFI_DEVICE_ERROR       The device had an error and could not complete the request.\r
+  @retval EFI_UNSUPPORTED        The mode number was not valid.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 VgaClassSetMode (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
   IN  UINTN                           ModeNumber\r
   )\r
 {\r
-  EFI_STATUS    Status;\r
   VGA_CLASS_DEV *VgaClassDev;\r
 \r
   VgaClassDev = VGA_CLASS_DEV_FROM_THIS (This);\r
@@ -1102,158 +1284,5 @@ VgaClassSetMode (
 \r
   This->Mode->Mode  = (INT32) ModeNumber;\r
 \r
-  Status            = VgaClassDev->VgaMiniPort->SetMode (VgaClassDev->VgaMiniPort, ModeNumber);\r
-\r
-  return Status;\r
+  return VgaClassDev->VgaMiniPort->SetMode (VgaClassDev->VgaMiniPort, ModeNumber);\r
 }\r
-\r
-/**\r
-  Set logic cursor's position to VgaClass device\r
-  \r
-  @param VgaClassDev device instance object\r
-  @param Column      cursor logic position.\r
-  @param Row         cursor logic position.\r
-  @param MaxColumn   max logic column\r
-  \r
-**/\r
-STATIC\r
-VOID\r
-SetVideoCursorPosition (\r
-  IN  VGA_CLASS_DEV  *VgaClassDev,\r
-  IN  UINTN          Column,\r
-  IN  UINTN          Row,\r
-  IN  UINTN          MaxColumn\r
-  )\r
-{\r
-  Column    = Column & 0xff;\r
-  Row       = Row & 0xff;\r
-  MaxColumn = MaxColumn & 0xff;\r
-  WriteCrtc (\r
-    VgaClassDev,\r
-    CRTC_CURSOR_LOCATION_HIGH,\r
-    (UINT8) ((Row * MaxColumn + Column) >> 8)\r
-    );\r
-  WriteCrtc (\r
-    VgaClassDev,\r
-    CRTC_CURSOR_LOCATION_LOW,\r
-    (UINT8) ((Row * MaxColumn + Column) & 0xff)\r
-    );\r
-}\r
-\r
-/**\r
-  Program CRTC register via PCI IO.\r
-  \r
-  @param VgaClassDev  device instance object\r
-  @param Address      address\r
-  @param Data         data\r
-**/\r
-STATIC\r
-VOID\r
-WriteCrtc (\r
-  IN  VGA_CLASS_DEV  *VgaClassDev,\r
-  IN  UINT16         Address,\r
-  IN  UINT8          Data\r
-  )\r
-{\r
-  VgaClassDev->PciIo->Io.Write (\r
-                          VgaClassDev->PciIo,\r
-                          EfiPciIoWidthUint8,\r
-                          VgaClassDev->VgaMiniPort->CrtcAddressRegisterBar,\r
-                          VgaClassDev->VgaMiniPort->CrtcAddressRegisterOffset,\r
-                          1,\r
-                          &Address\r
-                          );\r
-\r
-  VgaClassDev->PciIo->Io.Write (\r
-                          VgaClassDev->PciIo,\r
-                          EfiPciIoWidthUint8,\r
-                          VgaClassDev->VgaMiniPort->CrtcDataRegisterBar,\r
-                          VgaClassDev->VgaMiniPort->CrtcDataRegisterOffset,\r
-                          1,\r
-                          &Data\r
-                          );\r
-}\r
-\r
-/**\r
-  Detects if a Unicode char is for Box Drawing text graphics.\r
-\r
-  @param Grphic   Unicode char to test.\r
-  @param PcAnsi   Optional pointer to return PCANSI equivalent of Graphic.\r
-  @param Asci     Optional pointer to return Ascii equivalent of Graphic.\r
-\r
-  @return TRUE if Gpaphic is a supported Unicode Box Drawing character.\r
-\r
-**/\r
-STATIC\r
-BOOLEAN\r
-LibIsValidTextGraphics (\r
-  IN  CHAR16  Graphic,\r
-  OUT CHAR8   *PcAnsi, OPTIONAL\r
-  OUT CHAR8   *Ascii OPTIONAL\r
-  )\r
-{\r
-  UNICODE_TO_CHAR *Table;\r
-\r
-  if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) {\r
-    //\r
-    // Unicode drawing code charts are all in the 0x25xx range,\r
-    //  arrows are 0x21xx\r
-    //\r
-    return FALSE;\r
-  }\r
-\r
-  for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) {\r
-    if (Graphic == Table->Unicode) {\r
-      if (PcAnsi) {\r
-        *PcAnsi = Table->PcAnsi;\r
-      }\r
-\r
-      if (Ascii) {\r
-        *Ascii = Table->Ascii;\r
-      }\r
-\r
-      return TRUE;\r
-    }\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
-/**\r
-  Judge whether is an ASCII char.\r
-  \r
-  @param Ascii character\r
-  @return whether is an ASCII char.\r
-**/\r
-STATIC\r
-BOOLEAN\r
-IsValidAscii (\r
-  IN  CHAR16  Ascii\r
-  )\r
-{\r
-  if ((Ascii >= 0x20) && (Ascii <= 0x7f)) {\r
-    return TRUE;\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
-/**\r
-  Judge whether is diplaying control character.\r
-  \r
-  @param c character\r
-  @return whether is diplaying control character.\r
-**/\r
-STATIC\r
-BOOLEAN\r
-IsValidEfiCntlChar (\r
-  IN  CHAR16  c\r
-  )\r
-{\r
-  if (c == CHAR_NULL || c == CHAR_BACKSPACE || c == CHAR_LINEFEED || c == CHAR_CARRIAGE_RETURN) {\r
-    return TRUE;\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r