]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Csm/BiosThunk/VideoDxe/BiosVideo.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / Csm / BiosThunk / VideoDxe / BiosVideo.c
index 24d945b2eb74f9101dcd348062332019ad1bcd0c..35a4a24f340421ecaa8499d085b3d6d95a36dd6f 100644 (file)
@@ -12,7 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 //\r
 // EFI Driver Binding Protocol Instance\r
 //\r
-EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding = {\r
+EFI_DRIVER_BINDING_PROTOCOL  gBiosVideoDriverBinding = {\r
   BiosVideoDriverBindingSupported,\r
   BiosVideoDriverBindingStart,\r
   BiosVideoDriverBindingStop,\r
@@ -24,17 +24,17 @@ EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding = {
 //\r
 // Global lookup tables for VGA graphics modes\r
 //\r
-UINT8                          mVgaLeftMaskTable[]   = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };\r
+UINT8  mVgaLeftMaskTable[] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01 };\r
 \r
-UINT8                          mVgaRightMaskTable[]  = { 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };\r
+UINT8  mVgaRightMaskTable[] = { 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff };\r
 \r
-UINT8                          mVgaBitMaskTable[]    = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };\r
+UINT8  mVgaBitMaskTable[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };\r
 \r
 //\r
 // Save controller attributes during first start\r
 //\r
-UINT64                         mOriginalPciAttributes;\r
-BOOLEAN                        mPciAttributesSaved = FALSE;\r
+UINT64   mOriginalPciAttributes;\r
+BOOLEAN  mPciAttributesSaved = FALSE;\r
 \r
 EFI_GRAPHICS_OUTPUT_BLT_PIXEL  mVgaColorToGraphicsOutputColor[] = {\r
   { 0x00, 0x00, 0x00, 0x00 },\r
@@ -58,33 +58,33 @@ EFI_GRAPHICS_OUTPUT_BLT_PIXEL  mVgaColorToGraphicsOutputColor[] = {
 //\r
 // Standard timing defined by VESA EDID\r
 //\r
-VESA_BIOS_EXTENSIONS_EDID_TIMING mEstablishedEdidTiming[] = {\r
+VESA_BIOS_EXTENSIONS_EDID_TIMING  mEstablishedEdidTiming[] = {\r
   //\r
   // Established Timing I\r
   //\r
-  {800, 600, 60},\r
-  {800, 600, 56},\r
-  {640, 480, 75},\r
-  {640, 480, 72},\r
-  {640, 480, 67},\r
-  {640, 480, 60},\r
-  {720, 400, 88},\r
-  {720, 400, 70},\r
+  { 800,  600,  60 },\r
+  { 800,  600,  56 },\r
+  { 640,  480,  75 },\r
+  { 640,  480,  72 },\r
+  { 640,  480,  67 },\r
+  { 640,  480,  60 },\r
+  { 720,  400,  88 },\r
+  { 720,  400,  70 },\r
   //\r
   // Established Timing II\r
   //\r
-  {1280, 1024, 75},\r
-  {1024,  768, 75},\r
-  {1024,  768, 70},\r
-  {1024,  768, 60},\r
-  {1024,  768, 87},\r
-  {832,   624, 75},\r
-  {800,   600, 75},\r
-  {800,   600, 72},\r
+  { 1280, 1024, 75 },\r
+  { 1024, 768,  75 },\r
+  { 1024, 768,  70 },\r
+  { 1024, 768,  60 },\r
+  { 1024, 768,  87 },\r
+  { 832,  624,  75 },\r
+  { 800,  600,  75 },\r
+  { 800,  600,  72 },\r
   //\r
   // Established Timing III\r
   //\r
-  {1152, 870, 75}\r
+  { 1152, 870,  75 }\r
 };\r
 \r
 /**\r
@@ -117,7 +117,7 @@ BiosVideoDriverBindingSupported (
   //\r
   // See if the Legacy BIOS Protocol is available\r
   //\r
-  Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r
+  Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **)&LegacyBios);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -128,7 +128,7 @@ BiosVideoDriverBindingSupported (
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiPciIoProtocolGuid,\r
-                  (VOID **) &PciIo,\r
+                  (VOID **)&PciIo,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -154,6 +154,7 @@ BiosVideoDriverBindingSupported (
       return EFI_ALREADY_STARTED;\r
     }\r
   }\r
+\r
   //\r
   // See if this is a PCI Graphics Controller by looking at the Command register and\r
   // Class Code Register\r
@@ -171,15 +172,14 @@ BiosVideoDriverBindingSupported (
   }\r
 \r
   Status = EFI_UNSUPPORTED;\r
-  if (Pci.Hdr.ClassCode[2] == 0x03 || (Pci.Hdr.ClassCode[2] == 0x00 && Pci.Hdr.ClassCode[1] == 0x01)) {\r
-\r
+  if ((Pci.Hdr.ClassCode[2] == 0x03) || ((Pci.Hdr.ClassCode[2] == 0x00) && (Pci.Hdr.ClassCode[1] == 0x01))) {\r
     Status = EFI_SUCCESS;\r
     //\r
     // If this is a graphics controller,\r
     // go further check RemainingDevicePath validation\r
     //\r
     if (RemainingDevicePath != NULL) {\r
-      Node = (EFI_DEV_PATH *) RemainingDevicePath;\r
+      Node = (EFI_DEV_PATH *)RemainingDevicePath;\r
       //\r
       // Check if RemainingDevicePath is the End of Device Path Node,\r
       // if yes, return EFI_SUCCESS\r
@@ -189,9 +189,10 @@ BiosVideoDriverBindingSupported (
         // If RemainingDevicePath isn't the End of Device Path Node,\r
         // check its validation\r
         //\r
-        if (Node->DevPath.Type != ACPI_DEVICE_PATH ||\r
-            Node->DevPath.SubType != ACPI_ADR_DP ||\r
-            DevicePathNodeLength(&Node->DevPath) < sizeof(ACPI_ADR_DEVICE_PATH)) {\r
+        if ((Node->DevPath.Type != ACPI_DEVICE_PATH) ||\r
+            (Node->DevPath.SubType != ACPI_ADR_DP) ||\r
+            (DevicePathNodeLength (&Node->DevPath) < sizeof (ACPI_ADR_DEVICE_PATH)))\r
+        {\r
           Status = EFI_UNSUPPORTED;\r
         }\r
       }\r
@@ -209,7 +210,6 @@ Done:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Install Graphics Output Protocol onto VGA device handles.\r
 \r
@@ -246,7 +246,7 @@ BiosVideoDriverBindingStart (
   //\r
   // See if the Legacy BIOS Protocol is available\r
   //\r
-  Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r
+  Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **)&LegacyBios);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -257,7 +257,7 @@ BiosVideoDriverBindingStart (
   Status = gBS->HandleProtocol (\r
                   Controller,\r
                   &gEfiDevicePathProtocolGuid,\r
-                  (VOID **) &ParentDevicePath\r
+                  (VOID **)&ParentDevicePath\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -269,7 +269,7 @@ BiosVideoDriverBindingStart (
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiPciIoProtocolGuid,\r
-                  (VOID **) &PciIo,\r
+                  (VOID **)&PciIo,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -292,6 +292,7 @@ BiosVideoDriverBindingStart (
     if (EFI_ERROR (Status)) {\r
       goto Done;\r
     }\r
+\r
     mPciAttributesSaved = TRUE;\r
   }\r
 \r
@@ -309,7 +310,7 @@ BiosVideoDriverBindingStart (
   }\r
 \r
   Supports &= (UINT64)(EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16);\r
-  if (Supports == 0 || Supports == (EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) {\r
+  if ((Supports == 0) || (Supports == (EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16))) {\r
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
   }\r
@@ -323,11 +324,11 @@ BiosVideoDriverBindingStart (
   // Enable the device and make sure VGA cycles are being forwarded to this VGA device\r
   //\r
   Status = PciIo->Attributes (\r
-             PciIo,\r
-             EfiPciIoAttributeOperationEnable,\r
-             EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | Supports,\r
-             NULL\r
-             );\r
+                    PciIo,\r
+                    EfiPciIoAttributeOperationEnable,\r
+                    EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | Supports,\r
+                    NULL\r
+                    );\r
   if (EFI_ERROR (Status)) {\r
     REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
       EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
@@ -336,6 +337,7 @@ BiosVideoDriverBindingStart (
       );\r
     goto Done;\r
   }\r
+\r
   //\r
   // Check to see if there is a legacy option ROM image associated with this PCI device\r
   //\r
@@ -349,6 +351,7 @@ BiosVideoDriverBindingStart (
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
   }\r
+\r
   //\r
   // Post the legacy option ROM if it is available.\r
   //\r
@@ -378,7 +381,8 @@ BiosVideoDriverBindingStart (
 \r
   if (RemainingDevicePath != NULL) {\r
     if (IsDevicePathEnd (RemainingDevicePath) &&\r
-        (FeaturePcdGet (PcdBiosVideoCheckVbeEnable) || FeaturePcdGet (PcdBiosVideoCheckVgaEnable))) {\r
+        (FeaturePcdGet (PcdBiosVideoCheckVbeEnable) || FeaturePcdGet (PcdBiosVideoCheckVgaEnable)))\r
+    {\r
       //\r
       // If RemainingDevicePath is the End of Device Path Node,\r
       // don't create any child device and return EFI_SUCCESS\r
@@ -418,13 +422,14 @@ Done:
         // Restore original PCI attributes\r
         //\r
         PciIo->Attributes (\r
-                        PciIo,\r
-                        EfiPciIoAttributeOperationSet,\r
-                        mOriginalPciAttributes,\r
-                        NULL\r
-                        );\r
+                 PciIo,\r
+                 EfiPciIoAttributeOperationSet,\r
+                 mOriginalPciAttributes,\r
+                 NULL\r
+                 );\r
       }\r
     }\r
+\r
     //\r
     // Release PCI I/O Protocols on the controller handle.\r
     //\r
@@ -439,7 +444,6 @@ Done:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Stop.\r
 \r
@@ -455,16 +459,16 @@ Done:
 EFI_STATUS\r
 EFIAPI\r
 BiosVideoDriverBindingStop (\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
-  BOOLEAN                      AllChildrenStopped;\r
-  UINTN                        Index;\r
-  EFI_PCI_IO_PROTOCOL          *PciIo;\r
+  EFI_STATUS           Status;\r
+  BOOLEAN              AllChildrenStopped;\r
+  UINTN                Index;\r
+  EFI_PCI_IO_PROTOCOL  *PciIo;\r
 \r
   AllChildrenStopped = TRUE;\r
 \r
@@ -499,7 +503,7 @@ BiosVideoDriverBindingStop (
       Status = gBS->HandleProtocol (\r
                       Controller,\r
                       &gEfiPciIoProtocolGuid,\r
-                      (VOID **) &PciIo\r
+                      (VOID **)&PciIo\r
                       );\r
       ASSERT_EFI_ERROR (Status);\r
 \r
@@ -516,11 +520,9 @@ BiosVideoDriverBindingStop (
     }\r
   }\r
 \r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Install child handles if the Handle supports MBR format.\r
 \r
@@ -545,18 +547,18 @@ BiosVideoChildHandleInstall (
   IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS               Status;\r
-  BIOS_VIDEO_DEV           *BiosVideoPrivate;\r
-  PCI_TYPE00               Pci;\r
-  ACPI_ADR_DEVICE_PATH     AcpiDeviceNode;\r
-  BOOLEAN                  ProtocolInstalled;\r
+  EFI_STATUS            Status;\r
+  BIOS_VIDEO_DEV        *BiosVideoPrivate;\r
+  PCI_TYPE00            Pci;\r
+  ACPI_ADR_DEVICE_PATH  AcpiDeviceNode;\r
+  BOOLEAN               ProtocolInstalled;\r
 \r
   //\r
   // Allocate the private device structure for video device\r
   //\r
-  BiosVideoPrivate = (BIOS_VIDEO_DEV *) AllocateZeroPool (\r
-                                          sizeof (BIOS_VIDEO_DEV)\r
-                                          );\r
+  BiosVideoPrivate = (BIOS_VIDEO_DEV *)AllocateZeroPool (\r
+                                         sizeof (BIOS_VIDEO_DEV)\r
+                                         );\r
   if (NULL == BiosVideoPrivate) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -566,12 +568,12 @@ BiosVideoChildHandleInstall (
   // See if this is a VGA compatible controller or not\r
   //\r
   Status = ParentPciIo->Pci.Read (\r
-                          ParentPciIo,\r
-                          EfiPciIoWidthUint32,\r
-                          0,\r
-                          sizeof (Pci) / sizeof (UINT32),\r
-                          &Pci\r
-                          );\r
+                              ParentPciIo,\r
+                              EfiPciIoWidthUint32,\r
+                              0,\r
+                              sizeof (Pci) / sizeof (UINT32),\r
+                              &Pci\r
+                              );\r
   if (EFI_ERROR (Status)) {\r
     REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
       EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
@@ -580,16 +582,17 @@ BiosVideoChildHandleInstall (
       );\r
     goto Done;\r
   }\r
+\r
   BiosVideoPrivate->VgaCompatible = FALSE;\r
-  if (Pci.Hdr.ClassCode[2] == 0x00 && Pci.Hdr.ClassCode[1] == 0x01) {\r
+  if ((Pci.Hdr.ClassCode[2] == 0x00) && (Pci.Hdr.ClassCode[1] == 0x01)) {\r
     BiosVideoPrivate->VgaCompatible = TRUE;\r
   }\r
 \r
-  if (Pci.Hdr.ClassCode[2] == 0x03 && Pci.Hdr.ClassCode[1] == 0x00 && Pci.Hdr.ClassCode[0] == 0x00) {\r
+  if ((Pci.Hdr.ClassCode[2] == 0x03) && (Pci.Hdr.ClassCode[1] == 0x00) && (Pci.Hdr.ClassCode[0] == 0x00)) {\r
     BiosVideoPrivate->VgaCompatible = TRUE;\r
   }\r
 \r
- if (PcdGetBool (PcdBiosVideoSetTextVgaModeEnable)) {\r
 if (PcdGetBool (PcdBiosVideoSetTextVgaModeEnable)) {\r
     //\r
     // Create EXIT_BOOT_SERIVES Event\r
     //\r
@@ -626,21 +629,20 @@ BiosVideoChildHandleInstall (
   BiosVideoPrivate->GraphicsOutput.QueryMode = BiosVideoGraphicsOutputQueryMode;\r
   BiosVideoPrivate->GraphicsOutput.SetMode   = BiosVideoGraphicsOutputSetMode;\r
 \r
-\r
   //\r
   // Allocate buffer for Graphics Output Protocol mode information\r
   //\r
-  BiosVideoPrivate->GraphicsOutput.Mode = (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *) AllocatePool (\r
-                                             sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE)\r
-                                             );\r
+  BiosVideoPrivate->GraphicsOutput.Mode = (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *)AllocatePool (\r
+                                                                                 sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE)\r
+                                                                                 );\r
   if (NULL == BiosVideoPrivate->GraphicsOutput.Mode) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
-  BiosVideoPrivate->GraphicsOutput.Mode->Info = (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) AllocatePool (\r
-                                             sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION)\r
-                                             );\r
+  BiosVideoPrivate->GraphicsOutput.Mode->Info = (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *)AllocatePool (\r
+                                                                                          sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION)\r
+                                                                                          );\r
   if (NULL ==  BiosVideoPrivate->GraphicsOutput.Mode->Info) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -657,14 +659,14 @@ BiosVideoChildHandleInstall (
   if ((RemainingDevicePath == NULL) || (!IsDevicePathEnd (RemainingDevicePath))) {\r
     if (RemainingDevicePath == NULL) {\r
       ZeroMem (&AcpiDeviceNode, sizeof (ACPI_ADR_DEVICE_PATH));\r
-      AcpiDeviceNode.Header.Type = ACPI_DEVICE_PATH;\r
+      AcpiDeviceNode.Header.Type    = ACPI_DEVICE_PATH;\r
       AcpiDeviceNode.Header.SubType = ACPI_ADR_DP;\r
-      AcpiDeviceNode.ADR = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0);\r
+      AcpiDeviceNode.ADR            = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0);\r
       SetDevicePathNodeLength (&AcpiDeviceNode.Header, sizeof (ACPI_ADR_DEVICE_PATH));\r
 \r
       BiosVideoPrivate->GopDevicePath = AppendDevicePathNode (\r
                                           ParentDevicePath,\r
-                                          (EFI_DEVICE_PATH_PROTOCOL *) &AcpiDeviceNode\r
+                                          (EFI_DEVICE_PATH_PROTOCOL *)&AcpiDeviceNode\r
                                           );\r
     } else {\r
       BiosVideoPrivate->GopDevicePath = AppendDevicePathNode (ParentDevicePath, RemainingDevicePath);\r
@@ -674,12 +676,12 @@ BiosVideoChildHandleInstall (
     // Creat child handle and device path protocol firstly\r
     //\r
     BiosVideoPrivate->Handle = NULL;\r
-    Status = gBS->InstallMultipleProtocolInterfaces (\r
-                    &BiosVideoPrivate->Handle,\r
-                    &gEfiDevicePathProtocolGuid,\r
-                    BiosVideoPrivate->GopDevicePath,\r
-                    NULL\r
-                    );\r
+    Status                   = gBS->InstallMultipleProtocolInterfaces (\r
+                                      &BiosVideoPrivate->Handle,\r
+                                      &gEfiDevicePathProtocolGuid,\r
+                                      BiosVideoPrivate->GopDevicePath,\r
+                                      NULL\r
+                                      );\r
     if (EFI_ERROR (Status)) {\r
       goto Done;\r
     }\r
@@ -704,7 +706,7 @@ BiosVideoChildHandleInstall (
   //\r
   // When check for VBE, PCI I/O protocol is needed, so use parent's protocol interface temporally\r
   //\r
-  BiosVideoPrivate->PciIo                 = ParentPciIo;\r
+  BiosVideoPrivate->PciIo = ParentPciIo;\r
 \r
   //\r
   // Check for VESA BIOS Extensions for modes that are compatible with Graphics Output\r
@@ -715,6 +717,7 @@ BiosVideoChildHandleInstall (
   } else {\r
     Status = EFI_UNSUPPORTED;\r
   }\r
+\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // The VESA BIOS Extensions are not compatible with Graphics Output, so check for support\r
@@ -740,6 +743,7 @@ BiosVideoChildHandleInstall (
           FreePool (BiosVideoPrivate->GraphicsOutput.Mode->Info);\r
           BiosVideoPrivate->GraphicsOutput.Mode->Info = NULL;\r
         }\r
+\r
         FreePool (BiosVideoPrivate->GraphicsOutput.Mode);\r
         BiosVideoPrivate->GraphicsOutput.Mode = NULL;\r
       }\r
@@ -781,7 +785,7 @@ BiosVideoChildHandleInstall (
       Status = gBS->OpenProtocol (\r
                       ParentHandle,\r
                       &gEfiPciIoProtocolGuid,\r
-                      (VOID **) &BiosVideoPrivate->PciIo,\r
+                      (VOID **)&BiosVideoPrivate->PciIo,\r
                       This->DriverBindingHandle,\r
                       BiosVideoPrivate->Handle,\r
                       EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
@@ -789,6 +793,7 @@ BiosVideoChildHandleInstall (
       if (EFI_ERROR (Status)) {\r
         goto Done;\r
       }\r
+\r
       ProtocolInstalled = TRUE;\r
     }\r
   }\r
@@ -810,6 +815,7 @@ Done:
     if ((BiosVideoPrivate != NULL) && (BiosVideoPrivate->ExitBootServicesEvent != NULL)) {\r
       gBS->CloseEvent (BiosVideoPrivate->ExitBootServicesEvent);\r
     }\r
+\r
     //\r
     // Free private data structure\r
     //\r
@@ -819,7 +825,6 @@ Done:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Deregister an video child handle and free resources.\r
 \r
@@ -832,17 +837,17 @@ Done:
 **/\r
 EFI_STATUS\r
 BiosVideoChildHandleUninstall (\r
-  EFI_DRIVER_BINDING_PROTOCOL    *This,\r
-  EFI_HANDLE                     Controller,\r
-  EFI_HANDLE                     Handle\r
+  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  EFI_HANDLE                   Controller,\r
+  EFI_HANDLE                   Handle\r
   )\r
 {\r
-  EFI_STATUS                   Status;\r
-  EFI_IA32_REGISTER_SET        Regs;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
-  EFI_VGA_MINI_PORT_PROTOCOL   *VgaMiniPort;\r
-  BIOS_VIDEO_DEV               *BiosVideoPrivate;\r
-  EFI_PCI_IO_PROTOCOL          *PciIo;\r
+  EFI_STATUS                    Status;\r
+  EFI_IA32_REGISTER_SET         Regs;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
+  EFI_VGA_MINI_PORT_PROTOCOL    *VgaMiniPort;\r
+  BIOS_VIDEO_DEV                *BiosVideoPrivate;\r
+  EFI_PCI_IO_PROTOCOL           *PciIo;\r
 \r
   BiosVideoPrivate = NULL;\r
   GraphicsOutput   = NULL;\r
@@ -852,24 +857,24 @@ BiosVideoChildHandleUninstall (
   Status = gBS->OpenProtocol (\r
                   Handle,\r
                   &gEfiGraphicsOutputProtocolGuid,\r
-                  (VOID **) &GraphicsOutput,\r
+                  (VOID **)&GraphicsOutput,\r
                   This->DriverBindingHandle,\r
                   Handle,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (!EFI_ERROR (Status)) {\r
-      BiosVideoPrivate = BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS (GraphicsOutput);\r
+    BiosVideoPrivate = BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS (GraphicsOutput);\r
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
     Status = gBS->OpenProtocol (\r
-                   Handle,\r
-                   &gEfiVgaMiniPortProtocolGuid,\r
-                   (VOID **) &VgaMiniPort,\r
-                   This->DriverBindingHandle,\r
-                   Handle,\r
-                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                   );\r
+                    Handle,\r
+                    &gEfiVgaMiniPortProtocolGuid,\r
+                    (VOID **)&VgaMiniPort,\r
+                    This->DriverBindingHandle,\r
+                    Handle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
     if (!EFI_ERROR (Status)) {\r
       BiosVideoPrivate = BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS (VgaMiniPort);\r
     }\r
@@ -918,6 +923,7 @@ BiosVideoChildHandleUninstall (
                     NULL\r
                     );\r
   }\r
+\r
   if (!BiosVideoPrivate->ProduceGraphicsOutput) {\r
     Status = gBS->UninstallMultipleProtocolInterfaces (\r
                     Controller,\r
@@ -931,7 +937,7 @@ BiosVideoChildHandleUninstall (
     gBS->OpenProtocol (\r
            Controller,\r
            &gEfiPciIoProtocolGuid,\r
-           (VOID **) &PciIo,\r
+           (VOID **)&PciIo,\r
            This->DriverBindingHandle,\r
            Handle,\r
            EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
@@ -954,7 +960,6 @@ BiosVideoChildHandleUninstall (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Release resource for biso video instance.\r
 \r
@@ -967,7 +972,7 @@ BiosVideoDeviceReleaseResource (
   )\r
 {\r
   if (BiosVideoPrivate == NULL) {\r
-    return ;\r
+    return;\r
   }\r
 \r
   //\r
@@ -980,24 +985,28 @@ BiosVideoDeviceReleaseResource (
   if (BiosVideoPrivate->VgaFrameBuffer != NULL) {\r
     FreePool (BiosVideoPrivate->VgaFrameBuffer);\r
   }\r
+\r
   //\r
   // Free VBE Frame Buffer\r
   //\r
   if (BiosVideoPrivate->VbeFrameBuffer != NULL) {\r
     FreePool (BiosVideoPrivate->VbeFrameBuffer);\r
   }\r
+\r
   //\r
   // Free line buffer\r
   //\r
   if (BiosVideoPrivate->LineBuffer != NULL) {\r
     FreePool (BiosVideoPrivate->LineBuffer);\r
   }\r
+\r
   //\r
   // Free mode data\r
   //\r
   if (BiosVideoPrivate->ModeData != NULL) {\r
     FreePool (BiosVideoPrivate->ModeData);\r
   }\r
+\r
   //\r
   // Free memory allocated below 1MB\r
   //\r
@@ -1014,18 +1023,21 @@ BiosVideoDeviceReleaseResource (
   //\r
   if (BiosVideoPrivate->GraphicsOutput.Mode != NULL) {\r
     if (BiosVideoPrivate->GraphicsOutput.Mode->Info != NULL) {\r
-        FreePool (BiosVideoPrivate->GraphicsOutput.Mode->Info);\r
-        BiosVideoPrivate->GraphicsOutput.Mode->Info = NULL;\r
+      FreePool (BiosVideoPrivate->GraphicsOutput.Mode->Info);\r
+      BiosVideoPrivate->GraphicsOutput.Mode->Info = NULL;\r
     }\r
+\r
     FreePool (BiosVideoPrivate->GraphicsOutput.Mode);\r
     BiosVideoPrivate->GraphicsOutput.Mode = NULL;\r
   }\r
+\r
   //\r
   // Free EDID discovered protocol occupied resource\r
   //\r
   if (BiosVideoPrivate->EdidDiscovered.Edid != NULL) {\r
     FreePool (BiosVideoPrivate->EdidDiscovered.Edid);\r
   }\r
+\r
   //\r
   // Free EDID active protocol occupied resource\r
   //\r
@@ -1033,16 +1045,15 @@ BiosVideoDeviceReleaseResource (
     FreePool (BiosVideoPrivate->EdidActive.Edid);\r
   }\r
 \r
-  if (BiosVideoPrivate->GopDevicePath!= NULL) {\r
+  if (BiosVideoPrivate->GopDevicePath != NULL) {\r
     FreePool (BiosVideoPrivate->GopDevicePath);\r
   }\r
 \r
   FreePool (BiosVideoPrivate);\r
 \r
-  return ;\r
+  return;\r
 }\r
 \r
-\r
 /**\r
   Generate a search key for a specified timing data.\r
 \r
@@ -1053,10 +1064,10 @@ BiosVideoDeviceReleaseResource (
 **/\r
 UINT32\r
 CalculateEdidKey (\r
-  VESA_BIOS_EXTENSIONS_EDID_TIMING       *EdidTiming\r
+  VESA_BIOS_EXTENSIONS_EDID_TIMING  *EdidTiming\r
   )\r
 {\r
-  UINT32 Key;\r
+  UINT32  Key;\r
 \r
   //\r
   // Be sure no conflicts for all standard timing defined by VESA.\r
@@ -1065,7 +1076,6 @@ CalculateEdidKey (
   return Key;\r
 }\r
 \r
-\r
 /**\r
   Parse the Established Timing and Standard Timing in EDID data block.\r
 \r
@@ -1078,31 +1088,32 @@ CalculateEdidKey (
 **/\r
 BOOLEAN\r
 ParseEdidData (\r
-  UINT8                                      *EdidBuffer,\r
-  VESA_BIOS_EXTENSIONS_VALID_EDID_TIMING     *ValidEdidTiming\r
+  UINT8                                   *EdidBuffer,\r
+  VESA_BIOS_EXTENSIONS_VALID_EDID_TIMING  *ValidEdidTiming\r
   )\r
 {\r
-  UINT8  CheckSum;\r
-  UINT32 Index;\r
-  UINT32 ValidNumber;\r
-  UINT32 TimingBits;\r
-  UINT8  *BufferIndex;\r
-  UINT16 HorizontalResolution;\r
-  UINT16 VerticalResolution;\r
-  UINT8  AspectRatio;\r
-  UINT8  RefreshRate;\r
-  VESA_BIOS_EXTENSIONS_EDID_TIMING     TempTiming;\r
-  VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *EdidDataBlock;\r
+  UINT8                                 CheckSum;\r
+  UINT32                                Index;\r
+  UINT32                                ValidNumber;\r
+  UINT32                                TimingBits;\r
+  UINT8                                 *BufferIndex;\r
+  UINT16                                HorizontalResolution;\r
+  UINT16                                VerticalResolution;\r
+  UINT8                                 AspectRatio;\r
+  UINT8                                 RefreshRate;\r
+  VESA_BIOS_EXTENSIONS_EDID_TIMING      TempTiming;\r
+  VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK  *EdidDataBlock;\r
 \r
-  EdidDataBlock = (VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *) EdidBuffer;\r
+  EdidDataBlock = (VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *)EdidBuffer;\r
 \r
   //\r
   // Check the checksum of EDID data\r
   //\r
   CheckSum = 0;\r
-  for (Index = 0; Index < VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE; Index ++) {\r
-    CheckSum = (UINT8) (CheckSum + EdidBuffer[Index]);\r
+  for (Index = 0; Index < VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE; Index++) {\r
+    CheckSum = (UINT8)(CheckSum + EdidBuffer[Index]);\r
   }\r
+\r
   if (CheckSum != 0) {\r
     return FALSE;\r
   }\r
@@ -1113,20 +1124,26 @@ ParseEdidData (
   if ((EdidDataBlock->EstablishedTimings[0] != 0) ||\r
       (EdidDataBlock->EstablishedTimings[1] != 0) ||\r
       (EdidDataBlock->EstablishedTimings[2] != 0)\r
-      ) {\r
+      )\r
+  {\r
     //\r
     // Established timing data\r
     //\r
     TimingBits = EdidDataBlock->EstablishedTimings[0] |\r
                  (EdidDataBlock->EstablishedTimings[1] << 8) |\r
-                 ((EdidDataBlock->EstablishedTimings[2] & 0x80) << 9) ;\r
-    for (Index = 0; Index < VESA_BIOS_EXTENSIONS_EDID_ESTABLISHED_TIMING_MAX_NUMBER; Index ++) {\r
+                 ((EdidDataBlock->EstablishedTimings[2] & 0x80) << 9);\r
+    for (Index = 0; Index < VESA_BIOS_EXTENSIONS_EDID_ESTABLISHED_TIMING_MAX_NUMBER; Index++) {\r
       if ((TimingBits & 0x1) != 0) {\r
-        DEBUG ((DEBUG_INFO, "Established Timing: %d x %d\n",\r
-        mEstablishedEdidTiming[Index].HorizontalResolution, mEstablishedEdidTiming[Index].VerticalResolution));\r
+        DEBUG ((\r
+          DEBUG_INFO,\r
+          "Established Timing: %d x %d\n",\r
+          mEstablishedEdidTiming[Index].HorizontalResolution,\r
+          mEstablishedEdidTiming[Index].VerticalResolution\r
+          ));\r
         ValidEdidTiming->Key[ValidNumber] = CalculateEdidKey (&mEstablishedEdidTiming[Index]);\r
-        ValidNumber ++;\r
+        ValidNumber++;\r
       }\r
+\r
       TimingBits = TimingBits >> 1;\r
     }\r
   }\r
@@ -1135,42 +1152,44 @@ ParseEdidData (
   // Parse the standard timing data\r
   //\r
   BufferIndex = &EdidDataBlock->StandardTimingIdentification[0];\r
-  for (Index = 0; Index < 8; Index ++) {\r
+  for (Index = 0; Index < 8; Index++) {\r
     //\r
     // Check if this is a valid Standard Timing entry\r
     // VESA documents unused fields should be set to 01h\r
     //\r
-    if ((BufferIndex[0] != 0x1) && (BufferIndex[1] != 0x1)){\r
+    if ((BufferIndex[0] != 0x1) && (BufferIndex[1] != 0x1)) {\r
       //\r
       // A valid Standard Timing\r
       //\r
-      HorizontalResolution = (UINT16) (BufferIndex[0] * 8 + 248);\r
-      AspectRatio = (UINT8) (BufferIndex[1] >> 6);\r
+      HorizontalResolution = (UINT16)(BufferIndex[0] * 8 + 248);\r
+      AspectRatio          = (UINT8)(BufferIndex[1] >> 6);\r
       switch (AspectRatio) {\r
         case 0:\r
-          VerticalResolution = (UINT16) (HorizontalResolution / 16 * 10);\r
+          VerticalResolution = (UINT16)(HorizontalResolution / 16 * 10);\r
           break;\r
         case 1:\r
-          VerticalResolution = (UINT16) (HorizontalResolution / 4 * 3);\r
+          VerticalResolution = (UINT16)(HorizontalResolution / 4 * 3);\r
           break;\r
         case 2:\r
-          VerticalResolution = (UINT16) (HorizontalResolution / 5 * 4);\r
+          VerticalResolution = (UINT16)(HorizontalResolution / 5 * 4);\r
           break;\r
         case 3:\r
-          VerticalResolution = (UINT16) (HorizontalResolution / 16 * 9);\r
+          VerticalResolution = (UINT16)(HorizontalResolution / 16 * 9);\r
           break;\r
         default:\r
-          VerticalResolution = (UINT16) (HorizontalResolution / 4 * 3);\r
+          VerticalResolution = (UINT16)(HorizontalResolution / 4 * 3);\r
           break;\r
       }\r
-      RefreshRate = (UINT8) ((BufferIndex[1] & 0x1f) + 60);\r
+\r
+      RefreshRate = (UINT8)((BufferIndex[1] & 0x1f) + 60);\r
       DEBUG ((DEBUG_INFO, "Standard Timing: %d x %d\n", HorizontalResolution, VerticalResolution));\r
-      TempTiming.HorizontalResolution = HorizontalResolution;\r
-      TempTiming.VerticalResolution = VerticalResolution;\r
-      TempTiming.RefreshRate = RefreshRate;\r
+      TempTiming.HorizontalResolution   = HorizontalResolution;\r
+      TempTiming.VerticalResolution     = VerticalResolution;\r
+      TempTiming.RefreshRate            = RefreshRate;\r
       ValidEdidTiming->Key[ValidNumber] = CalculateEdidKey (&TempTiming);\r
-      ValidNumber ++;\r
+      ValidNumber++;\r
     }\r
+\r
     BufferIndex += 2;\r
   }\r
 \r
@@ -1178,7 +1197,7 @@ ParseEdidData (
   // Parse the Detailed Timing data\r
   //\r
   BufferIndex = &EdidDataBlock->DetailedTimingDescriptions[0];\r
-  for (Index = 0; Index < 4; Index ++, BufferIndex += VESA_BIOS_EXTENSIONS_DETAILED_TIMING_EACH_DESCRIPTOR_SIZE) {\r
+  for (Index = 0; Index < 4; Index++, BufferIndex += VESA_BIOS_EXTENSIONS_DETAILED_TIMING_EACH_DESCRIPTOR_SIZE) {\r
     if ((BufferIndex[0] == 0x0) && (BufferIndex[1] == 0x0)) {\r
       //\r
       // Check if this is a valid Detailed Timing Descriptor\r
@@ -1186,22 +1205,27 @@ ParseEdidData (
       //\r
       continue;\r
     }\r
+\r
     //\r
     // Calculate Horizontal and Vertical resolution\r
     //\r
     TempTiming.HorizontalResolution = ((UINT16)(BufferIndex[4] & 0xF0) << 4) | (BufferIndex[2]);\r
-    TempTiming.VerticalResolution = ((UINT16)(BufferIndex[7] & 0xF0) << 4) | (BufferIndex[5]);\r
-    DEBUG ((DEBUG_INFO, "Detailed Timing %d: %d x %d\n",\r
-            Index, TempTiming.HorizontalResolution, TempTiming.VerticalResolution));\r
+    TempTiming.VerticalResolution   = ((UINT16)(BufferIndex[7] & 0xF0) << 4) | (BufferIndex[5]);\r
+    DEBUG ((\r
+      DEBUG_INFO,\r
+      "Detailed Timing %d: %d x %d\n",\r
+      Index,\r
+      TempTiming.HorizontalResolution,\r
+      TempTiming.VerticalResolution\r
+      ));\r
     ValidEdidTiming->Key[ValidNumber] = CalculateEdidKey (&TempTiming);\r
-    ValidNumber ++;\r
+    ValidNumber++;\r
   }\r
 \r
   ValidEdidTiming->ValidNumber = ValidNumber;\r
   return TRUE;\r
 }\r
 \r
-\r
 /**\r
   Search a specified Timing in all the valid EDID timings.\r
 \r
@@ -1214,16 +1238,16 @@ ParseEdidData (
 **/\r
 BOOLEAN\r
 SearchEdidTiming (\r
-  VESA_BIOS_EXTENSIONS_VALID_EDID_TIMING *ValidEdidTiming,\r
-  VESA_BIOS_EXTENSIONS_EDID_TIMING       *EdidTiming\r
+  VESA_BIOS_EXTENSIONS_VALID_EDID_TIMING  *ValidEdidTiming,\r
+  VESA_BIOS_EXTENSIONS_EDID_TIMING        *EdidTiming\r
   )\r
 {\r
-  UINT32 Index;\r
-  UINT32 Key;\r
+  UINT32  Index;\r
+  UINT32  Key;\r
 \r
   Key = CalculateEdidKey (EdidTiming);\r
 \r
-  for (Index = 0; Index < ValidEdidTiming->ValidNumber; Index ++) {\r
+  for (Index = 0; Index < ValidEdidTiming->ValidNumber; Index++) {\r
     if (Key == ValidEdidTiming->Key[Index]) {\r
       return TRUE;\r
     }\r
@@ -1281,34 +1305,34 @@ BiosVideoCheckForVbe (
   IN OUT BIOS_VIDEO_DEV  *BiosVideoPrivate\r
   )\r
 {\r
-  EFI_STATUS                             Status;\r
-  EFI_IA32_REGISTER_SET                  Regs;\r
-  UINT16                                 *ModeNumberPtr;\r
-  UINT16                                 VbeModeNumber;\r
-  BOOLEAN                                ModeFound;\r
-  BOOLEAN                                EdidFound;\r
-  BIOS_VIDEO_MODE_DATA                   *ModeBuffer;\r
-  BIOS_VIDEO_MODE_DATA                   *CurrentModeData;\r
-  UINTN                                  PreferMode;\r
-  UINTN                                  ModeNumber;\r
-  VESA_BIOS_EXTENSIONS_EDID_TIMING       Timing;\r
-  VESA_BIOS_EXTENSIONS_VALID_EDID_TIMING ValidEdidTiming;\r
-  EFI_EDID_OVERRIDE_PROTOCOL             *EdidOverride;\r
-  UINT32                                 EdidAttributes;\r
-  BOOLEAN                                EdidOverrideFound;\r
-  UINTN                                  EdidOverrideDataSize;\r
-  UINT8                                  *EdidOverrideDataBlock;\r
-  UINTN                                  EdidActiveDataSize;\r
-  UINT8                                  *EdidActiveDataBlock;\r
-  UINT32                                 HighestHorizontalResolution;\r
-  UINT32                                 HighestVerticalResolution;\r
-  UINTN                                  HighestResolutionMode;\r
-\r
-  EdidFound             = TRUE;\r
-  EdidOverrideFound     = FALSE;\r
-  EdidOverrideDataBlock = NULL;\r
-  EdidActiveDataSize    = 0;\r
-  EdidActiveDataBlock   = NULL;\r
+  EFI_STATUS                              Status;\r
+  EFI_IA32_REGISTER_SET                   Regs;\r
+  UINT16                                  *ModeNumberPtr;\r
+  UINT16                                  VbeModeNumber;\r
+  BOOLEAN                                 ModeFound;\r
+  BOOLEAN                                 EdidFound;\r
+  BIOS_VIDEO_MODE_DATA                    *ModeBuffer;\r
+  BIOS_VIDEO_MODE_DATA                    *CurrentModeData;\r
+  UINTN                                   PreferMode;\r
+  UINTN                                   ModeNumber;\r
+  VESA_BIOS_EXTENSIONS_EDID_TIMING        Timing;\r
+  VESA_BIOS_EXTENSIONS_VALID_EDID_TIMING  ValidEdidTiming;\r
+  EFI_EDID_OVERRIDE_PROTOCOL              *EdidOverride;\r
+  UINT32                                  EdidAttributes;\r
+  BOOLEAN                                 EdidOverrideFound;\r
+  UINTN                                   EdidOverrideDataSize;\r
+  UINT8                                   *EdidOverrideDataBlock;\r
+  UINTN                                   EdidActiveDataSize;\r
+  UINT8                                   *EdidActiveDataBlock;\r
+  UINT32                                  HighestHorizontalResolution;\r
+  UINT32                                  HighestVerticalResolution;\r
+  UINTN                                   HighestResolutionMode;\r
+\r
+  EdidFound                   = TRUE;\r
+  EdidOverrideFound           = FALSE;\r
+  EdidOverrideDataBlock       = NULL;\r
+  EdidActiveDataSize          = 0;\r
+  EdidActiveDataBlock         = NULL;\r
   HighestHorizontalResolution = 0;\r
   HighestVerticalResolution   = 0;\r
   HighestResolutionMode       = 0;\r
@@ -1340,12 +1364,12 @@ BiosVideoCheckForVbe (
   //\r
   // Fill in the VBE related data structures\r
   //\r
-  BiosVideoPrivate->VbeInformationBlock = (VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *) (UINTN) (BiosVideoPrivate->PagesBelow1MB);\r
-  BiosVideoPrivate->VbeModeInformationBlock = (VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *) (BiosVideoPrivate->VbeInformationBlock + 1);\r
-  BiosVideoPrivate->VbeEdidDataBlock = (VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *) (BiosVideoPrivate->VbeModeInformationBlock + 1);\r
-  BiosVideoPrivate->VbeCrtcInformationBlock = (VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK *) (BiosVideoPrivate->VbeEdidDataBlock + 1);\r
-  BiosVideoPrivate->VbeSaveRestorePages   = 0;\r
-  BiosVideoPrivate->VbeSaveRestoreBuffer  = 0;\r
+  BiosVideoPrivate->VbeInformationBlock     = (VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *)(UINTN)(BiosVideoPrivate->PagesBelow1MB);\r
+  BiosVideoPrivate->VbeModeInformationBlock = (VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *)(BiosVideoPrivate->VbeInformationBlock + 1);\r
+  BiosVideoPrivate->VbeEdidDataBlock        = (VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *)(BiosVideoPrivate->VbeModeInformationBlock + 1);\r
+  BiosVideoPrivate->VbeCrtcInformationBlock = (VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK *)(BiosVideoPrivate->VbeEdidDataBlock + 1);\r
+  BiosVideoPrivate->VbeSaveRestorePages     = 0;\r
+  BiosVideoPrivate->VbeSaveRestoreBuffer    = 0;\r
 \r
   //\r
   // Test to see if the Video Adapter is compliant with VBE 3.0\r
@@ -1353,9 +1377,9 @@ BiosVideoCheckForVbe (
   gBS->SetMem (&Regs, sizeof (Regs), 0);\r
   Regs.X.AX = VESA_BIOS_EXTENSIONS_RETURN_CONTROLLER_INFORMATION;\r
   gBS->SetMem (BiosVideoPrivate->VbeInformationBlock, sizeof (VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK), 0);\r
-  BiosVideoPrivate->VbeInformationBlock->VESASignature  = VESA_BIOS_EXTENSIONS_VBE2_SIGNATURE;\r
-  Regs.X.ES = EFI_SEGMENT ((UINTN) BiosVideoPrivate->VbeInformationBlock);\r
-  Regs.X.DI = EFI_OFFSET ((UINTN) BiosVideoPrivate->VbeInformationBlock);\r
+  BiosVideoPrivate->VbeInformationBlock->VESASignature = VESA_BIOS_EXTENSIONS_VBE2_SIGNATURE;\r
+  Regs.X.ES                                            = EFI_SEGMENT ((UINTN)BiosVideoPrivate->VbeInformationBlock);\r
+  Regs.X.DI                                            = EFI_OFFSET ((UINTN)BiosVideoPrivate->VbeInformationBlock);\r
 \r
   BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
 \r
@@ -1367,12 +1391,14 @@ BiosVideoCheckForVbe (
   if (Regs.X.AX != VESA_BIOS_EXTENSIONS_STATUS_SUCCESS) {\r
     return Status;\r
   }\r
+\r
   //\r
   // Check for 'VESA' signature\r
   //\r
   if (BiosVideoPrivate->VbeInformationBlock->VESASignature != VESA_BIOS_EXTENSIONS_VESA_SIGNATURE) {\r
     return Status;\r
   }\r
+\r
   //\r
   // Check to see if this is VBE 2.0 or higher\r
   //\r
@@ -1388,10 +1414,10 @@ BiosVideoCheckForVbe (
   // Find EDID Override protocol firstly, this protocol is installed by platform if needed.\r
   //\r
   Status = gBS->LocateProtocol (\r
-                   &gEfiEdidOverrideProtocolGuid,\r
-                   NULL,\r
-                   (VOID **) &EdidOverride\r
-                   );\r
+                  &gEfiEdidOverrideProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&EdidOverride\r
+                  );\r
   if (!EFI_ERROR (Status)) {\r
     //\r
     // Allocate double size of VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE to avoid overflow\r
@@ -1407,11 +1433,12 @@ BiosVideoCheckForVbe (
                              BiosVideoPrivate->Handle,\r
                              &EdidAttributes,\r
                              &EdidOverrideDataSize,\r
-                             (UINT8 **) &EdidOverrideDataBlock\r
+                             (UINT8 **)&EdidOverrideDataBlock\r
                              );\r
     if (!EFI_ERROR (Status)  &&\r
-         EdidAttributes == 0 &&\r
-         EdidOverrideDataSize != 0) {\r
+        (EdidAttributes == 0) &&\r
+        (EdidOverrideDataSize != 0))\r
+    {\r
       //\r
       // Succeeded to get EDID Override Data\r
       //\r
@@ -1419,7 +1446,7 @@ BiosVideoCheckForVbe (
     }\r
   }\r
 \r
-  if (!EdidOverrideFound || EdidAttributes == EFI_EDID_OVERRIDE_DONT_OVERRIDE) {\r
+  if (!EdidOverrideFound || (EdidAttributes == EFI_EDID_OVERRIDE_DONT_OVERRIDE)) {\r
     //\r
     // If EDID Override data doesn't exist or EFI_EDID_OVERRIDE_DONT_OVERRIDE returned,\r
     // read EDID information through INT10 call\r
@@ -1430,8 +1457,8 @@ BiosVideoCheckForVbe (
     Regs.X.BX = 1;\r
     Regs.X.CX = 0;\r
     Regs.X.DX = 0;\r
-    Regs.X.ES = EFI_SEGMENT ((UINTN) BiosVideoPrivate->VbeEdidDataBlock);\r
-    Regs.X.DI = EFI_OFFSET  ((UINTN) BiosVideoPrivate->VbeEdidDataBlock);\r
+    Regs.X.ES = EFI_SEGMENT ((UINTN)BiosVideoPrivate->VbeEdidDataBlock);\r
+    Regs.X.DI = EFI_OFFSET ((UINTN)BiosVideoPrivate->VbeEdidDataBlock);\r
 \r
     BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
     //\r
@@ -1442,13 +1469,13 @@ BiosVideoCheckForVbe (
       // Set EDID Discovered Data\r
       //\r
       BiosVideoPrivate->EdidDiscovered.SizeOfEdid = VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE;\r
-       BiosVideoPrivate->EdidDiscovered.Edid = (UINT8 *) AllocateCopyPool (\r
-                                                          VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE,\r
-                                                          BiosVideoPrivate->VbeEdidDataBlock\r
-                                                           );\r
+      BiosVideoPrivate->EdidDiscovered.Edid       = (UINT8 *)AllocateCopyPool (\r
+                                                               VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE,\r
+                                                               BiosVideoPrivate->VbeEdidDataBlock\r
+                                                               );\r
 \r
       if (NULL == BiosVideoPrivate->EdidDiscovered.Edid) {\r
-         Status = EFI_OUT_OF_RESOURCES;\r
+        Status = EFI_OUT_OF_RESOURCES;\r
         goto Done;\r
       }\r
 \r
@@ -1462,41 +1489,41 @@ BiosVideoCheckForVbe (
   } else if (EdidOverrideFound) {\r
     EdidActiveDataSize  = EdidOverrideDataSize;\r
     EdidActiveDataBlock = EdidOverrideDataBlock;\r
-    EdidFound = TRUE;\r
-   }\r
+    EdidFound           = TRUE;\r
+  }\r
 \r
-   if (EdidFound) {\r
+  if (EdidFound) {\r
     //\r
     // Parse EDID data structure to retrieve modes supported by monitor\r
     //\r
-    if (ParseEdidData ((UINT8 *) EdidActiveDataBlock, &ValidEdidTiming)) {\r
+    if (ParseEdidData ((UINT8 *)EdidActiveDataBlock, &ValidEdidTiming)) {\r
       //\r
       // Copy EDID Override Data to EDID Active Data\r
       //\r
-      BiosVideoPrivate->EdidActive.SizeOfEdid = (UINT32) EdidActiveDataSize;\r
-      BiosVideoPrivate->EdidActive.Edid = (UINT8 *) AllocateCopyPool (\r
-                                                      EdidActiveDataSize,\r
-                                                      EdidActiveDataBlock\r
-                                                      );\r
+      BiosVideoPrivate->EdidActive.SizeOfEdid = (UINT32)EdidActiveDataSize;\r
+      BiosVideoPrivate->EdidActive.Edid       = (UINT8 *)AllocateCopyPool (\r
+                                                           EdidActiveDataSize,\r
+                                                           EdidActiveDataBlock\r
+                                                           );\r
       if (NULL ==  BiosVideoPrivate->EdidActive.Edid) {\r
-         Status = EFI_OUT_OF_RESOURCES;\r
+        Status = EFI_OUT_OF_RESOURCES;\r
         goto Done;\r
       }\r
     }\r
   } else {\r
     BiosVideoPrivate->EdidActive.SizeOfEdid = 0;\r
-    BiosVideoPrivate->EdidActive.Edid = NULL;\r
-    EdidFound = FALSE;\r
+    BiosVideoPrivate->EdidActive.Edid       = NULL;\r
+    EdidFound                               = FALSE;\r
   }\r
 \r
   //\r
   // Walk through the mode list to see if there is at least one mode the is compatible with the EDID mode\r
   //\r
   ModeNumberPtr = (UINT16 *)\r
-    (\r
-      (((UINTN) BiosVideoPrivate->VbeInformationBlock->VideoModePtr & 0xffff0000) >> 12) |\r
-        ((UINTN) BiosVideoPrivate->VbeInformationBlock->VideoModePtr & 0x0000ffff)\r
-    );\r
+                  (\r
+                   (((UINTN)BiosVideoPrivate->VbeInformationBlock->VideoModePtr & 0xffff0000) >> 12) |\r
+                   ((UINTN)BiosVideoPrivate->VbeInformationBlock->VideoModePtr & 0x0000ffff)\r
+                  );\r
 \r
   PreferMode = 0;\r
   ModeNumber = 0;\r
@@ -1506,13 +1533,15 @@ BiosVideoCheckForVbe (
   //\r
   for (VbeModeNumber = ReadUnaligned16 (ModeNumberPtr);\r
        VbeModeNumber != VESA_BIOS_EXTENSIONS_END_OF_MODE_LIST;\r
-       VbeModeNumber = ReadUnaligned16 (++ModeNumberPtr)) {\r
+       VbeModeNumber = ReadUnaligned16 (++ModeNumberPtr))\r
+  {\r
     //\r
     // Make sure this is a mode number defined by the VESA VBE specification.  If it isn'tm then skip this mode number.\r
     //\r
     if ((VbeModeNumber & VESA_BIOS_EXTENSIONS_MODE_NUMBER_VESA) == 0) {\r
       continue;\r
     }\r
+\r
     //\r
     // Get the information about the mode\r
     //\r
@@ -1520,8 +1549,8 @@ BiosVideoCheckForVbe (
     Regs.X.AX = VESA_BIOS_EXTENSIONS_RETURN_MODE_INFORMATION;\r
     Regs.X.CX = VbeModeNumber;\r
     gBS->SetMem (BiosVideoPrivate->VbeModeInformationBlock, sizeof (VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK), 0);\r
-    Regs.X.ES = EFI_SEGMENT ((UINTN) BiosVideoPrivate->VbeModeInformationBlock);\r
-    Regs.X.DI = EFI_OFFSET ((UINTN) BiosVideoPrivate->VbeModeInformationBlock);\r
+    Regs.X.ES = EFI_SEGMENT ((UINTN)BiosVideoPrivate->VbeModeInformationBlock);\r
+    Regs.X.DI = EFI_OFFSET ((UINTN)BiosVideoPrivate->VbeModeInformationBlock);\r
 \r
     BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
 \r
@@ -1531,24 +1560,28 @@ BiosVideoCheckForVbe (
     if (Regs.X.AX != VESA_BIOS_EXTENSIONS_STATUS_SUCCESS) {\r
       continue;\r
     }\r
+\r
     //\r
     // See if the mode supports color.  If it doesn't then try the next mode.\r
     //\r
     if ((BiosVideoPrivate->VbeModeInformationBlock->ModeAttributes & VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_COLOR) == 0) {\r
       continue;\r
     }\r
+\r
     //\r
     // See if the mode supports graphics.  If it doesn't then try the next mode.\r
     //\r
     if ((BiosVideoPrivate->VbeModeInformationBlock->ModeAttributes & VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_GRAPHICS) == 0) {\r
       continue;\r
     }\r
+\r
     //\r
     // See if the mode supports a linear frame buffer.  If it doesn't then try the next mode.\r
     //\r
     if ((BiosVideoPrivate->VbeModeInformationBlock->ModeAttributes & VESA_BIOS_EXTENSIONS_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER) == 0) {\r
       continue;\r
     }\r
+\r
     //\r
     // See if the mode supports 32 bit color.  If it doesn't then try the next mode.\r
     // 32 bit mode can be implemented by 24 Bits Per Pixels. Also make sure the\r
@@ -1565,6 +1598,7 @@ BiosVideoCheckForVbe (
     if ((BiosVideoPrivate->VbeModeInformationBlock->BitsPerPixel % 8) != 0) {\r
       continue;\r
     }\r
+\r
     //\r
     // See if the physical base pointer for the linear mode is valid.  If it isn't then try the next mode.\r
     //\r
@@ -1572,25 +1606,31 @@ BiosVideoCheckForVbe (
       continue;\r
     }\r
 \r
-    DEBUG ((DEBUG_INFO, "Video Controller Mode 0x%x: %d x %d\n",\r
-            VbeModeNumber, BiosVideoPrivate->VbeModeInformationBlock->XResolution, BiosVideoPrivate->VbeModeInformationBlock->YResolution));\r
+    DEBUG ((\r
+      DEBUG_INFO,\r
+      "Video Controller Mode 0x%x: %d x %d\n",\r
+      VbeModeNumber,\r
+      BiosVideoPrivate->VbeModeInformationBlock->XResolution,\r
+      BiosVideoPrivate->VbeModeInformationBlock->YResolution\r
+      ));\r
 \r
     if (EdidFound && (ValidEdidTiming.ValidNumber > 0)) {\r
       //\r
       // EDID exist, check whether this mode match with any mode in EDID\r
       //\r
       Timing.HorizontalResolution = BiosVideoPrivate->VbeModeInformationBlock->XResolution;\r
-      Timing.VerticalResolution = BiosVideoPrivate->VbeModeInformationBlock->YResolution;\r
+      Timing.VerticalResolution   = BiosVideoPrivate->VbeModeInformationBlock->YResolution;\r
       if (!SearchEdidTiming (&ValidEdidTiming, &Timing)) {\r
         //\r
         // When EDID comes from INT10 call, EDID does not include 800x600, 640x480 and 1024x768,\r
         // but INT10 can support these modes, we add them into GOP mode.\r
         //\r
         if ((BiosVideoPrivate->EdidDiscovered.SizeOfEdid != 0) &&\r
-            !((Timing.HorizontalResolution) == 1024 && (Timing.VerticalResolution == 768)) &&\r
-            !((Timing.HorizontalResolution) == 800 && (Timing.VerticalResolution == 600)) &&\r
-            !((Timing.HorizontalResolution) == 640 && (Timing.VerticalResolution == 480))) {\r
-        continue;\r
+            !(((Timing.HorizontalResolution) == 1024) && (Timing.VerticalResolution == 768)) &&\r
+            !(((Timing.HorizontalResolution) == 800) && (Timing.VerticalResolution == 600)) &&\r
+            !(((Timing.HorizontalResolution) == 640) && (Timing.VerticalResolution == 480)))\r
+        {\r
+          continue;\r
         }\r
       }\r
     }\r
@@ -1600,20 +1640,25 @@ BiosVideoCheckForVbe (
     //\r
     ModeFound = FALSE;\r
 \r
-    if (BiosVideoPrivate->VbeModeInformationBlock->XResolution == 1024 &&\r
-        BiosVideoPrivate->VbeModeInformationBlock->YResolution == 768\r
-        ) {\r
+    if ((BiosVideoPrivate->VbeModeInformationBlock->XResolution == 1024) &&\r
+        (BiosVideoPrivate->VbeModeInformationBlock->YResolution == 768)\r
+        )\r
+    {\r
       ModeFound = TRUE;\r
     }\r
-    if (BiosVideoPrivate->VbeModeInformationBlock->XResolution == 800 &&\r
-        BiosVideoPrivate->VbeModeInformationBlock->YResolution == 600\r
-        ) {\r
-      ModeFound = TRUE;\r
+\r
+    if ((BiosVideoPrivate->VbeModeInformationBlock->XResolution == 800) &&\r
+        (BiosVideoPrivate->VbeModeInformationBlock->YResolution == 600)\r
+        )\r
+    {\r
+      ModeFound  = TRUE;\r
       PreferMode = ModeNumber;\r
     }\r
-    if (BiosVideoPrivate->VbeModeInformationBlock->XResolution == 640 &&\r
-        BiosVideoPrivate->VbeModeInformationBlock->YResolution == 480\r
-        ) {\r
+\r
+    if ((BiosVideoPrivate->VbeModeInformationBlock->XResolution == 640) &&\r
+        (BiosVideoPrivate->VbeModeInformationBlock->YResolution == 480)\r
+        )\r
+    {\r
       ModeFound = TRUE;\r
     }\r
 \r
@@ -1629,19 +1674,20 @@ BiosVideoCheckForVbe (
     //\r
     if ((BiosVideoPrivate->VbeModeInformationBlock->XResolution > HighestHorizontalResolution) ||\r
         ((BiosVideoPrivate->VbeModeInformationBlock->XResolution == HighestHorizontalResolution) &&\r
-         (BiosVideoPrivate->VbeModeInformationBlock->YResolution > HighestVerticalResolution))) {\r
+         (BiosVideoPrivate->VbeModeInformationBlock->YResolution > HighestVerticalResolution)))\r
+    {\r
       HighestHorizontalResolution = BiosVideoPrivate->VbeModeInformationBlock->XResolution;\r
-      HighestVerticalResolution = BiosVideoPrivate->VbeModeInformationBlock->YResolution;\r
-      HighestResolutionMode = ModeNumber;\r
+      HighestVerticalResolution   = BiosVideoPrivate->VbeModeInformationBlock->YResolution;\r
+      HighestResolutionMode       = ModeNumber;\r
     }\r
 \r
     //\r
     // Add mode to the list of available modes\r
     //\r
-    ModeNumber ++;\r
-    ModeBuffer = (BIOS_VIDEO_MODE_DATA *) AllocatePool (\r
-                                            ModeNumber * sizeof (BIOS_VIDEO_MODE_DATA)\r
-                                            );\r
+    ModeNumber++;\r
+    ModeBuffer = (BIOS_VIDEO_MODE_DATA *)AllocatePool (\r
+                                           ModeNumber * sizeof (BIOS_VIDEO_MODE_DATA)\r
+                                           );\r
     if (NULL == ModeBuffer) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
@@ -1659,33 +1705,34 @@ BiosVideoCheckForVbe (
       FreePool (BiosVideoPrivate->ModeData);\r
     }\r
 \r
-    CurrentModeData = &ModeBuffer[ModeNumber - 1];\r
+    CurrentModeData                = &ModeBuffer[ModeNumber - 1];\r
     CurrentModeData->VbeModeNumber = VbeModeNumber;\r
     if (BiosVideoPrivate->VbeInformationBlock->VESAVersion >= VESA_BIOS_EXTENSIONS_VERSION_3_0) {\r
-      CurrentModeData->BytesPerScanLine = BiosVideoPrivate->VbeModeInformationBlock->LinBytesPerScanLine;\r
-      CurrentModeData->Red.Position = BiosVideoPrivate->VbeModeInformationBlock->LinRedFieldPosition;\r
-      CurrentModeData->Red.Mask = (UINT8) ((1 << BiosVideoPrivate->VbeModeInformationBlock->LinRedMaskSize) - 1);\r
-      CurrentModeData->Blue.Position = BiosVideoPrivate->VbeModeInformationBlock->LinBlueFieldPosition;\r
-      CurrentModeData->Blue.Mask = (UINT8) ((1 << BiosVideoPrivate->VbeModeInformationBlock->LinBlueMaskSize) - 1);\r
-      CurrentModeData->Green.Position = BiosVideoPrivate->VbeModeInformationBlock->LinGreenFieldPosition;\r
-      CurrentModeData->Green.Mask = (UINT8) ((1 << BiosVideoPrivate->VbeModeInformationBlock->LinGreenMaskSize) - 1);\r
+      CurrentModeData->BytesPerScanLine  = BiosVideoPrivate->VbeModeInformationBlock->LinBytesPerScanLine;\r
+      CurrentModeData->Red.Position      = BiosVideoPrivate->VbeModeInformationBlock->LinRedFieldPosition;\r
+      CurrentModeData->Red.Mask          = (UINT8)((1 << BiosVideoPrivate->VbeModeInformationBlock->LinRedMaskSize) - 1);\r
+      CurrentModeData->Blue.Position     = BiosVideoPrivate->VbeModeInformationBlock->LinBlueFieldPosition;\r
+      CurrentModeData->Blue.Mask         = (UINT8)((1 << BiosVideoPrivate->VbeModeInformationBlock->LinBlueMaskSize) - 1);\r
+      CurrentModeData->Green.Position    = BiosVideoPrivate->VbeModeInformationBlock->LinGreenFieldPosition;\r
+      CurrentModeData->Green.Mask        = (UINT8)((1 << BiosVideoPrivate->VbeModeInformationBlock->LinGreenMaskSize) - 1);\r
       CurrentModeData->Reserved.Position = BiosVideoPrivate->VbeModeInformationBlock->LinRsvdFieldPosition;\r
-      CurrentModeData->Reserved.Mask = (UINT8) ((1 << BiosVideoPrivate->VbeModeInformationBlock->LinRsvdMaskSize) - 1);\r
+      CurrentModeData->Reserved.Mask     = (UINT8)((1 << BiosVideoPrivate->VbeModeInformationBlock->LinRsvdMaskSize) - 1);\r
     } else {\r
-      CurrentModeData->BytesPerScanLine = BiosVideoPrivate->VbeModeInformationBlock->BytesPerScanLine;\r
-      CurrentModeData->Red.Position = BiosVideoPrivate->VbeModeInformationBlock->RedFieldPosition;\r
-      CurrentModeData->Red.Mask = (UINT8) ((1 << BiosVideoPrivate->VbeModeInformationBlock->RedMaskSize) - 1);\r
-      CurrentModeData->Blue.Position = BiosVideoPrivate->VbeModeInformationBlock->BlueFieldPosition;\r
-      CurrentModeData->Blue.Mask = (UINT8) ((1 << BiosVideoPrivate->VbeModeInformationBlock->BlueMaskSize) - 1);\r
-      CurrentModeData->Green.Position = BiosVideoPrivate->VbeModeInformationBlock->GreenFieldPosition;\r
-      CurrentModeData->Green.Mask = (UINT8) ((1 << BiosVideoPrivate->VbeModeInformationBlock->GreenMaskSize) - 1);\r
+      CurrentModeData->BytesPerScanLine  = BiosVideoPrivate->VbeModeInformationBlock->BytesPerScanLine;\r
+      CurrentModeData->Red.Position      = BiosVideoPrivate->VbeModeInformationBlock->RedFieldPosition;\r
+      CurrentModeData->Red.Mask          = (UINT8)((1 << BiosVideoPrivate->VbeModeInformationBlock->RedMaskSize) - 1);\r
+      CurrentModeData->Blue.Position     = BiosVideoPrivate->VbeModeInformationBlock->BlueFieldPosition;\r
+      CurrentModeData->Blue.Mask         = (UINT8)((1 << BiosVideoPrivate->VbeModeInformationBlock->BlueMaskSize) - 1);\r
+      CurrentModeData->Green.Position    = BiosVideoPrivate->VbeModeInformationBlock->GreenFieldPosition;\r
+      CurrentModeData->Green.Mask        = (UINT8)((1 << BiosVideoPrivate->VbeModeInformationBlock->GreenMaskSize) - 1);\r
       CurrentModeData->Reserved.Position = BiosVideoPrivate->VbeModeInformationBlock->RsvdFieldPosition;\r
-      CurrentModeData->Reserved.Mask = (UINT8) ((1 << BiosVideoPrivate->VbeModeInformationBlock->RsvdMaskSize) - 1);\r
+      CurrentModeData->Reserved.Mask     = (UINT8)((1 << BiosVideoPrivate->VbeModeInformationBlock->RsvdMaskSize) - 1);\r
     }\r
 \r
     CurrentModeData->PixelFormat = PixelBitMask;\r
     if ((BiosVideoPrivate->VbeModeInformationBlock->BitsPerPixel == 32) &&\r
-        (CurrentModeData->Red.Mask == 0xff) && (CurrentModeData->Green.Mask == 0xff) && (CurrentModeData->Blue.Mask == 0xff)) {\r
+        (CurrentModeData->Red.Mask == 0xff) && (CurrentModeData->Green.Mask == 0xff) && (CurrentModeData->Blue.Mask == 0xff))\r
+    {\r
       if ((CurrentModeData->Red.Position == 0) && (CurrentModeData->Green.Position == 8) && (CurrentModeData->Blue.Position == 16)) {\r
         CurrentModeData->PixelFormat = PixelRedGreenBlueReserved8BitPerColor;\r
       } else if ((CurrentModeData->Blue.Position == 0) && (CurrentModeData->Green.Position == 8) && (CurrentModeData->Red.Position == 16)) {\r
@@ -1693,16 +1740,16 @@ BiosVideoCheckForVbe (
       }\r
     }\r
 \r
-    CurrentModeData->PixelBitMask.RedMask = ((UINT32) CurrentModeData->Red.Mask) << CurrentModeData->Red.Position;\r
-    CurrentModeData->PixelBitMask.GreenMask = ((UINT32) CurrentModeData->Green.Mask) << CurrentModeData->Green.Position;\r
-    CurrentModeData->PixelBitMask.BlueMask = ((UINT32) CurrentModeData->Blue.Mask) << CurrentModeData->Blue.Position;\r
-    CurrentModeData->PixelBitMask.ReservedMask = ((UINT32) CurrentModeData->Reserved.Mask) << CurrentModeData->Reserved.Position;\r
+    CurrentModeData->PixelBitMask.RedMask      = ((UINT32)CurrentModeData->Red.Mask) << CurrentModeData->Red.Position;\r
+    CurrentModeData->PixelBitMask.GreenMask    = ((UINT32)CurrentModeData->Green.Mask) << CurrentModeData->Green.Position;\r
+    CurrentModeData->PixelBitMask.BlueMask     = ((UINT32)CurrentModeData->Blue.Mask) << CurrentModeData->Blue.Position;\r
+    CurrentModeData->PixelBitMask.ReservedMask = ((UINT32)CurrentModeData->Reserved.Mask) << CurrentModeData->Reserved.Position;\r
 \r
-    CurrentModeData->LinearFrameBuffer = (VOID *) (UINTN)BiosVideoPrivate->VbeModeInformationBlock->PhysBasePtr;\r
+    CurrentModeData->LinearFrameBuffer    = (VOID *)(UINTN)BiosVideoPrivate->VbeModeInformationBlock->PhysBasePtr;\r
     CurrentModeData->HorizontalResolution = BiosVideoPrivate->VbeModeInformationBlock->XResolution;\r
-    CurrentModeData->VerticalResolution = BiosVideoPrivate->VbeModeInformationBlock->YResolution;\r
+    CurrentModeData->VerticalResolution   = BiosVideoPrivate->VbeModeInformationBlock->YResolution;\r
 \r
-    CurrentModeData->BitsPerPixel  = BiosVideoPrivate->VbeModeInformationBlock->BitsPerPixel;\r
+    CurrentModeData->BitsPerPixel    = BiosVideoPrivate->VbeModeInformationBlock->BitsPerPixel;\r
     CurrentModeData->FrameBufferSize = CurrentModeData->BytesPerScanLine * CurrentModeData->VerticalResolution;\r
     //\r
     // Make sure the FrameBufferSize does not exceed the max available frame buffer size reported by VEB.\r
@@ -1711,6 +1758,7 @@ BiosVideoCheckForVbe (
 \r
     BiosVideoPrivate->ModeData = ModeBuffer;\r
   }\r
+\r
   //\r
   // Check to see if we found any modes that are compatible with GRAPHICS OUTPUT\r
   //\r
@@ -1722,9 +1770,9 @@ BiosVideoCheckForVbe (
   //\r
   // Assign Gop's Blt function\r
   //\r
-  BiosVideoPrivate->GraphicsOutput.Blt     = BiosVideoGraphicsOutputVbeBlt;\r
+  BiosVideoPrivate->GraphicsOutput.Blt = BiosVideoGraphicsOutputVbeBlt;\r
 \r
-  BiosVideoPrivate->GraphicsOutput.Mode->MaxMode = (UINT32) ModeNumber;\r
+  BiosVideoPrivate->GraphicsOutput.Mode->MaxMode = (UINT32)ModeNumber;\r
   //\r
   // Current mode is unknow till now, set it to an invalid mode.\r
   //\r
@@ -1737,22 +1785,28 @@ BiosVideoCheckForVbe (
     DEBUG_CODE (\r
       BIOS_VIDEO_MODE_DATA    *ModeData;\r
       ModeData = &BiosVideoPrivate->ModeData[HighestResolutionMode];\r
-      DEBUG ((DEBUG_INFO, "BiosVideo set highest resolution %d x %d\n",\r
-              ModeData->HorizontalResolution, ModeData->VerticalResolution));\r
-    );\r
+      DEBUG ((\r
+        DEBUG_INFO,\r
+        "BiosVideo set highest resolution %d x %d\n",\r
+        ModeData->HorizontalResolution,\r
+        ModeData->VerticalResolution\r
+        ));\r
+      );\r
     PreferMode = HighestResolutionMode;\r
   }\r
-  Status = BiosVideoGraphicsOutputSetMode (&BiosVideoPrivate->GraphicsOutput, (UINT32) PreferMode);\r
+\r
+  Status = BiosVideoGraphicsOutputSetMode (&BiosVideoPrivate->GraphicsOutput, (UINT32)PreferMode);\r
   if (EFI_ERROR (Status)) {\r
-    for (PreferMode = 0; PreferMode < ModeNumber; PreferMode ++) {\r
+    for (PreferMode = 0; PreferMode < ModeNumber; PreferMode++) {\r
       Status = BiosVideoGraphicsOutputSetMode (\r
-                &BiosVideoPrivate->GraphicsOutput,\r
-                (UINT32) PreferMode\r
-                );\r
+                 &BiosVideoPrivate->GraphicsOutput,\r
+                 (UINT32)PreferMode\r
+                 );\r
       if (!EFI_ERROR (Status)) {\r
         break;\r
       }\r
     }\r
+\r
     if (PreferMode == ModeNumber) {\r
       //\r
       // None mode is set successfully.\r
@@ -1768,9 +1822,10 @@ Done:
   if (EFI_ERROR (Status)) {\r
     if (BiosVideoPrivate->ModeData != NULL) {\r
       FreePool (BiosVideoPrivate->ModeData);\r
-      BiosVideoPrivate->ModeData  = NULL;\r
-      BiosVideoPrivate->MaxMode   = 0;\r
+      BiosVideoPrivate->ModeData = NULL;\r
+      BiosVideoPrivate->MaxMode  = 0;\r
     }\r
+\r
     if (EdidOverrideDataBlock != NULL) {\r
       FreePool (EdidOverrideDataBlock);\r
     }\r
@@ -1779,7 +1834,6 @@ Done:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Check for VGA device.\r
 \r
@@ -1801,7 +1855,7 @@ BiosVideoCheckForVga (
   //\r
   // Assign Gop's Blt function\r
   //\r
-  BiosVideoPrivate->GraphicsOutput.Blt     = BiosVideoGraphicsOutputVgaBlt;\r
+  BiosVideoPrivate->GraphicsOutput.Blt = BiosVideoGraphicsOutputVgaBlt;\r
 \r
   //\r
   // Add mode to the list of available modes\r
@@ -1810,23 +1864,23 @@ BiosVideoCheckForVga (
   ASSERT (BiosVideoPrivate->GraphicsOutput.Mode != NULL);\r
   BiosVideoPrivate->GraphicsOutput.Mode->MaxMode = 1;\r
 \r
-  ModeBuffer = (BIOS_VIDEO_MODE_DATA *) AllocatePool (\r
-                                          sizeof (BIOS_VIDEO_MODE_DATA)\r
-                                          );\r
+  ModeBuffer = (BIOS_VIDEO_MODE_DATA *)AllocatePool (\r
+                                         sizeof (BIOS_VIDEO_MODE_DATA)\r
+                                         );\r
   if (NULL == ModeBuffer) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
-  ModeBuffer->VbeModeNumber         = 0x0012;\r
-  ModeBuffer->BytesPerScanLine      = 640;\r
-  ModeBuffer->LinearFrameBuffer     = (VOID *) (UINTN) (0xa0000);\r
-  ModeBuffer->HorizontalResolution  = 640;\r
-  ModeBuffer->VerticalResolution    = 480;\r
-  ModeBuffer->PixelFormat           = PixelBltOnly;\r
-  ModeBuffer->BitsPerPixel          = 8;\r
-  ModeBuffer->ColorDepth            = 32;\r
-  ModeBuffer->RefreshRate           = 60;\r
+  ModeBuffer->VbeModeNumber        = 0x0012;\r
+  ModeBuffer->BytesPerScanLine     = 640;\r
+  ModeBuffer->LinearFrameBuffer    = (VOID *)(UINTN)(0xa0000);\r
+  ModeBuffer->HorizontalResolution = 640;\r
+  ModeBuffer->VerticalResolution   = 480;\r
+  ModeBuffer->PixelFormat          = PixelBltOnly;\r
+  ModeBuffer->BitsPerPixel         = 8;\r
+  ModeBuffer->ColorDepth           = 32;\r
+  ModeBuffer->RefreshRate          = 60;\r
 \r
   BiosVideoPrivate->ModeData = ModeBuffer;\r
 \r
@@ -1834,7 +1888,7 @@ BiosVideoCheckForVga (
   // Test to see if the Video Adapter support the 640x480 16 color mode\r
   //\r
   BiosVideoPrivate->GraphicsOutput.Mode->Mode = GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER;\r
-  Status = BiosVideoGraphicsOutputSetMode (&BiosVideoPrivate->GraphicsOutput, 0);\r
+  Status                                      = BiosVideoGraphicsOutputSetMode (&BiosVideoPrivate->GraphicsOutput, 0);\r
 \r
 Done:\r
   //\r
@@ -1845,15 +1899,18 @@ Done:
       FreePool (BiosVideoPrivate->ModeData);\r
       BiosVideoPrivate->ModeData = NULL;\r
     }\r
+\r
     if (BiosVideoPrivate->GraphicsOutput.Mode != NULL) {\r
       if (BiosVideoPrivate->GraphicsOutput.Mode->Info != NULL) {\r
         FreePool (BiosVideoPrivate->GraphicsOutput.Mode->Info);\r
         BiosVideoPrivate->GraphicsOutput.Mode->Info = NULL;\r
       }\r
+\r
       FreePool (BiosVideoPrivate->GraphicsOutput.Mode);\r
       BiosVideoPrivate->GraphicsOutput.Mode = NULL;\r
     }\r
   }\r
+\r
   return Status;\r
 }\r
 \r
@@ -1901,11 +1958,11 @@ BiosVideoGraphicsOutputQueryMode (
     return EFI_NOT_STARTED;\r
   }\r
 \r
-  if (This == NULL || Info == NULL || SizeOfInfo == NULL || ModeNumber >= This->Mode->MaxMode) {\r
+  if ((This == NULL) || (Info == NULL) || (SizeOfInfo == NULL) || (ModeNumber >= This->Mode->MaxMode)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  *Info = (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) AllocatePool (\r
+  *Info = (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *)AllocatePool (\r
                                                     sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION)\r
                                                     );\r
   if (NULL == *Info) {\r
@@ -1914,12 +1971,12 @@ BiosVideoGraphicsOutputQueryMode (
 \r
   *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
 \r
-  ModeData = &BiosVideoPrivate->ModeData[ModeNumber];\r
-  (*Info)->Version = 0;\r
+  ModeData                      = &BiosVideoPrivate->ModeData[ModeNumber];\r
+  (*Info)->Version              = 0;\r
   (*Info)->HorizontalResolution = ModeData->HorizontalResolution;\r
   (*Info)->VerticalResolution   = ModeData->VerticalResolution;\r
-  (*Info)->PixelFormat = ModeData->PixelFormat;\r
-  CopyMem (&((*Info)->PixelInformation), &(ModeData->PixelBitMask), sizeof(ModeData->PixelBitMask));\r
+  (*Info)->PixelFormat          = ModeData->PixelFormat;\r
+  CopyMem (&((*Info)->PixelInformation), &(ModeData->PixelBitMask), sizeof (ModeData->PixelBitMask));\r
 \r
   (*Info)->PixelsPerScanLine =  (ModeData->BytesPerScanLine * 8) / ModeData->BitsPerPixel;\r
 \r
@@ -1941,13 +1998,13 @@ BiosVideoGraphicsOutputQueryMode (
 **/\r
 EFI_STATUS\r
 BiosVideoSetModeWorker (\r
-  IN  BIOS_VIDEO_DEV               *BiosVideoPrivate,\r
-  IN  BIOS_VIDEO_MODE_DATA         *ModeData,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
+  IN  BIOS_VIDEO_DEV            *BiosVideoPrivate,\r
+  IN  BIOS_VIDEO_MODE_DATA      *ModeData,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
   )\r
 {\r
-  EFI_STATUS              Status;\r
-  EFI_IA32_REGISTER_SET   Regs;\r
+  EFI_STATUS             Status;\r
+  EFI_IA32_REGISTER_SET  Regs;\r
 \r
   if (BiosVideoPrivate->LineBuffer != NULL) {\r
     FreePool (BiosVideoPrivate->LineBuffer);\r
@@ -1961,12 +2018,13 @@ BiosVideoSetModeWorker (
     FreePool (BiosVideoPrivate->VbeFrameBuffer);\r
   }\r
 \r
-  BiosVideoPrivate->LineBuffer = (UINT8 *) AllocatePool (\r
-                                             ModeData->BytesPerScanLine\r
-                                             );\r
+  BiosVideoPrivate->LineBuffer = (UINT8 *)AllocatePool (\r
+                                            ModeData->BytesPerScanLine\r
+                                            );\r
   if (NULL == BiosVideoPrivate->LineBuffer) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+\r
   //\r
   // Clear all registers\r
   //\r
@@ -1976,35 +2034,36 @@ BiosVideoSetModeWorker (
     //\r
     // Allocate a working buffer for BLT operations to the VGA frame buffer\r
     //\r
-    BiosVideoPrivate->VgaFrameBuffer = (UINT8 *) AllocatePool (4 * 480 * 80);\r
+    BiosVideoPrivate->VgaFrameBuffer = (UINT8 *)AllocatePool (4 * 480 * 80);\r
     if (NULL == BiosVideoPrivate->VgaFrameBuffer) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
+\r
     //\r
     // Set VGA Mode\r
     //\r
     Regs.X.AX = ModeData->VbeModeNumber;\r
     BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
-\r
   } else {\r
     //\r
     // Allocate a working buffer for BLT operations to the VBE frame buffer\r
     //\r
     BiosVideoPrivate->VbeFrameBuffer =\r
-      (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) AllocatePool (\r
-                                          ModeData->BytesPerScanLine * ModeData->VerticalResolution\r
-                                          );\r
+      (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)AllocatePool (\r
+                                         ModeData->BytesPerScanLine * ModeData->VerticalResolution\r
+                                         );\r
     if (NULL == BiosVideoPrivate->VbeFrameBuffer) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
+\r
     //\r
     // Set VBE mode\r
     //\r
     Regs.X.AX = VESA_BIOS_EXTENSIONS_SET_MODE;\r
-    Regs.X.BX = (UINT16) (ModeData->VbeModeNumber | VESA_BIOS_EXTENSIONS_MODE_NUMBER_LINEAR_FRAME_BUFFER);\r
+    Regs.X.BX = (UINT16)(ModeData->VbeModeNumber | VESA_BIOS_EXTENSIONS_MODE_NUMBER_LINEAR_FRAME_BUFFER);\r
     ZeroMem (BiosVideoPrivate->VbeCrtcInformationBlock, sizeof (VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK));\r
-    Regs.X.ES = EFI_SEGMENT ((UINTN) BiosVideoPrivate->VbeCrtcInformationBlock);\r
-    Regs.X.DI = EFI_OFFSET ((UINTN) BiosVideoPrivate->VbeCrtcInformationBlock);\r
+    Regs.X.ES = EFI_SEGMENT ((UINTN)BiosVideoPrivate->VbeCrtcInformationBlock);\r
+    Regs.X.DI = EFI_OFFSET ((UINTN)BiosVideoPrivate->VbeCrtcInformationBlock);\r
     BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
 \r
     //\r
@@ -2018,6 +2077,7 @@ BiosVideoSetModeWorker (
         );\r
       return EFI_DEVICE_ERROR;\r
     }\r
+\r
     //\r
     // Initialize the state of the VbeFrameBuffer\r
     //\r
@@ -2025,7 +2085,7 @@ BiosVideoSetModeWorker (
                                             BiosVideoPrivate->PciIo,\r
                                             EfiPciIoWidthUint32,\r
                                             EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                                            (UINT64) (UINTN) ModeData->LinearFrameBuffer,\r
+                                            (UINT64)(UINTN)ModeData->LinearFrameBuffer,\r
                                             (ModeData->BytesPerScanLine * ModeData->VerticalResolution) >> 2,\r
                                             BiosVideoPrivate->VbeFrameBuffer\r
                                             );\r
@@ -2052,14 +2112,14 @@ BiosVideoSetModeWorker (
 EFI_STATUS\r
 EFIAPI\r
 BiosVideoGraphicsOutputSetMode (\r
-  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL This,\r
-  IN  UINT32                       ModeNumber\r
+  IN  EFI_GRAPHICS_OUTPUT_PROTOCOL  *This,\r
+  IN  UINT32                        ModeNumber\r
   )\r
 {\r
-  EFI_STATUS              Status;\r
-  BIOS_VIDEO_DEV          *BiosVideoPrivate;\r
-  BIOS_VIDEO_MODE_DATA    *ModeData;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
+  EFI_STATUS                     Status;\r
+  BIOS_VIDEO_DEV                 *BiosVideoPrivate;\r
+  BIOS_VIDEO_MODE_DATA           *ModeData;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Background;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2079,17 +2139,17 @@ BiosVideoGraphicsOutputSetMode (
     //\r
     ZeroMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
     BiosVideoGraphicsOutputVbeBlt (\r
-                        This,\r
-                        &Background,\r
-                        EfiBltVideoFill,\r
-                        0,\r
-                        0,\r
-                        0,\r
-                        0,\r
-                        ModeData->HorizontalResolution,\r
-                        ModeData->VerticalResolution,\r
-                        0\r
-    );\r
+      This,\r
+      &Background,\r
+      EfiBltVideoFill,\r
+      0,\r
+      0,\r
+      0,\r
+      0,\r
+      ModeData->HorizontalResolution,\r
+      ModeData->VerticalResolution,\r
+      0\r
+      );\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -2098,16 +2158,16 @@ BiosVideoGraphicsOutputSetMode (
     return Status;\r
   }\r
 \r
-  This->Mode->Mode = ModeNumber;\r
-  This->Mode->Info->Version = 0;\r
+  This->Mode->Mode                       = ModeNumber;\r
+  This->Mode->Info->Version              = 0;\r
   This->Mode->Info->HorizontalResolution = ModeData->HorizontalResolution;\r
-  This->Mode->Info->VerticalResolution = ModeData->VerticalResolution;\r
-  This->Mode->Info->PixelFormat = ModeData->PixelFormat;\r
+  This->Mode->Info->VerticalResolution   = ModeData->VerticalResolution;\r
+  This->Mode->Info->PixelFormat          = ModeData->PixelFormat;\r
   CopyMem (&(This->Mode->Info->PixelInformation), &(ModeData->PixelBitMask), sizeof (ModeData->PixelBitMask));\r
   This->Mode->Info->PixelsPerScanLine =  (ModeData->BytesPerScanLine * 8) / ModeData->BitsPerPixel;\r
-  This->Mode->SizeOfInfo = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
-  This->Mode->FrameBufferSize = ModeData->FrameBufferSize;\r
-  This->Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) ModeData->LinearFrameBuffer;\r
+  This->Mode->SizeOfInfo              = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+  This->Mode->FrameBufferSize         = ModeData->FrameBufferSize;\r
+  This->Mode->FrameBufferBase         = (EFI_PHYSICAL_ADDRESS)(UINTN)ModeData->LinearFrameBuffer;\r
 \r
   BiosVideoPrivate->HardwareNeedsStarting = FALSE;\r
 \r
@@ -2129,36 +2189,36 @@ BiosVideoGraphicsOutputSetMode (
 **/\r
 VOID\r
 CopyVideoBuffer (\r
-  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
-  IN  UINT8                 *VbeBuffer,\r
-  IN  VOID                  *MemAddress,\r
-  IN  UINTN                 DestinationX,\r
-  IN  UINTN                 DestinationY,\r
-  IN  UINTN                 TotalBytes,\r
-  IN  UINT32                VbePixelWidth,\r
-  IN  UINTN                 BytesPerScanLine\r
+  IN  EFI_PCI_IO_PROTOCOL  *PciIo,\r
+  IN  UINT8                *VbeBuffer,\r
+  IN  VOID                 *MemAddress,\r
+  IN  UINTN                DestinationX,\r
+  IN  UINTN                DestinationY,\r
+  IN  UINTN                TotalBytes,\r
+  IN  UINT32               VbePixelWidth,\r
+  IN  UINTN                BytesPerScanLine\r
   )\r
 {\r
-  UINTN                 FrameBufferAddr;\r
-  UINTN                 CopyBlockNum;\r
-  UINTN                 RemainingBytes;\r
-  UINTN                 UnalignedBytes;\r
-  EFI_STATUS            Status;\r
+  UINTN       FrameBufferAddr;\r
+  UINTN       CopyBlockNum;\r
+  UINTN       RemainingBytes;\r
+  UINTN       UnalignedBytes;\r
+  EFI_STATUS  Status;\r
 \r
-  FrameBufferAddr = (UINTN) MemAddress + (DestinationY * BytesPerScanLine) + DestinationX * VbePixelWidth;\r
+  FrameBufferAddr = (UINTN)MemAddress + (DestinationY * BytesPerScanLine) + DestinationX * VbePixelWidth;\r
 \r
   //\r
   // If TotalBytes is less than 4 bytes, only start byte copy.\r
   //\r
   if (TotalBytes < 4) {\r
     Status = PciIo->Mem.Write (\r
-                     PciIo,\r
-                     EfiPciIoWidthUint8,\r
-                     EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                     (UINT64) FrameBufferAddr,\r
-                     TotalBytes,\r
-                     VbeBuffer\r
-                     );\r
+                          PciIo,\r
+                          EfiPciIoWidthUint8,\r
+                          EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                          (UINT64)FrameBufferAddr,\r
+                          TotalBytes,\r
+                          VbeBuffer\r
+                          );\r
     ASSERT_EFI_ERROR (Status);\r
     return;\r
   }\r
@@ -2166,17 +2226,17 @@ CopyVideoBuffer (
   //\r
   // If VbeBuffer is not 4-byte aligned, start byte copy.\r
   //\r
-  UnalignedBytes  = (4 - ((UINTN) VbeBuffer & 0x3)) & 0x3;\r
+  UnalignedBytes = (4 - ((UINTN)VbeBuffer & 0x3)) & 0x3;\r
 \r
   if (UnalignedBytes != 0) {\r
     Status = PciIo->Mem.Write (\r
-                     PciIo,\r
-                     EfiPciIoWidthUint8,\r
-                     EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                     (UINT64) FrameBufferAddr,\r
-                     UnalignedBytes,\r
-                     VbeBuffer\r
-                     );\r
+                          PciIo,\r
+                          EfiPciIoWidthUint8,\r
+                          EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                          (UINT64)FrameBufferAddr,\r
+                          UnalignedBytes,\r
+                          VbeBuffer\r
+                          );\r
     ASSERT_EFI_ERROR (Status);\r
     FrameBufferAddr += UnalignedBytes;\r
     VbeBuffer       += UnalignedBytes;\r
@@ -2193,27 +2253,27 @@ CopyVideoBuffer (
   //\r
   if (CopyBlockNum != 0) {\r
     Status = PciIo->Mem.Write (\r
-                    PciIo,\r
-                    EfiPciIoWidthUint32,\r
-                    EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                    (UINT64) FrameBufferAddr,\r
-                    CopyBlockNum,\r
-                    VbeBuffer\r
-                    );\r
+                          PciIo,\r
+                          EfiPciIoWidthUint32,\r
+                          EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                          (UINT64)FrameBufferAddr,\r
+                          CopyBlockNum,\r
+                          VbeBuffer\r
+                          );\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
   if (RemainingBytes != 0) {\r
     FrameBufferAddr += (CopyBlockNum << 2);\r
     VbeBuffer       += (CopyBlockNum << 2);\r
-    Status = PciIo->Mem.Write (\r
-                    PciIo,\r
-                    EfiPciIoWidthUint8,\r
-                    EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                    (UINT64) FrameBufferAddr,\r
-                    RemainingBytes,\r
-                    VbeBuffer\r
-                    );\r
+    Status           = PciIo->Mem.Write (\r
+                                    PciIo,\r
+                                    EfiPciIoWidthUint8,\r
+                                    EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                                    (UINT64)FrameBufferAddr,\r
+                                    RemainingBytes,\r
+                                    VbeBuffer\r
+                                    );\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
 }\r
@@ -2278,22 +2338,23 @@ BiosVideoVbeBltWorker (
   UINT32                         Pixel;\r
   UINTN                          TotalBytes;\r
 \r
-  PciIo             = BiosVideoPrivate->PciIo;\r
+  PciIo = BiosVideoPrivate->PciIo;\r
 \r
-  VbeFrameBuffer    = BiosVideoPrivate->VbeFrameBuffer;\r
-  MemAddress        = Mode->LinearFrameBuffer;\r
-  BytesPerScanLine  = Mode->BytesPerScanLine;\r
-  VbePixelWidth     = Mode->BitsPerPixel / 8;\r
-  BltUint8          = (UINT8 *) BltBuffer;\r
-  TotalBytes        = Width * VbePixelWidth;\r
+  VbeFrameBuffer   = BiosVideoPrivate->VbeFrameBuffer;\r
+  MemAddress       = Mode->LinearFrameBuffer;\r
+  BytesPerScanLine = Mode->BytesPerScanLine;\r
+  VbePixelWidth    = Mode->BitsPerPixel / 8;\r
+  BltUint8         = (UINT8 *)BltBuffer;\r
+  TotalBytes       = Width * VbePixelWidth;\r
 \r
-  if (((UINTN) BltOperation) >= EfiGraphicsOutputBltOperationMax) {\r
+  if (((UINTN)BltOperation) >= EfiGraphicsOutputBltOperationMax) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (Width == 0 || Height == 0) {\r
+  if ((Width == 0) || (Height == 0)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+\r
   //\r
   // We need to fill the Virtual Screen buffer with the blt data.\r
   // The virtual screen is upside down, as the first row is the bootom row of\r
@@ -2322,6 +2383,7 @@ BiosVideoVbeBltWorker (
       return EFI_INVALID_PARAMETER;\r
     }\r
   }\r
+\r
   //\r
   // If Delta is zero, then the entire BltBuffer is being used, so Delta\r
   // is the number of bytes in each row of BltBuffer.  Since BltBuffer is Width pixels size,\r
@@ -2330,6 +2392,7 @@ BiosVideoVbeBltWorker (
   if (Delta == 0) {\r
     Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
   }\r
+\r
   //\r
   // We have to raise to TPL Notify, so we make an atomic write the frame buffer.\r
   // We would not want a timer based event (Cursor, ...) to come in while we are\r
@@ -2338,148 +2401,151 @@ BiosVideoVbeBltWorker (
   OriginalTPL = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
   switch (BltOperation) {\r
-  case EfiBltVideoToBltBuffer:\r
-    for (SrcY = SourceY, DstY = DestinationY; DstY < (Height + DestinationY); SrcY++, DstY++) {\r
-      Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) (BltUint8 + DstY * Delta + DestinationX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
-      //\r
-      // Shuffle the packed bytes in the hardware buffer to match EFI_GRAPHICS_OUTPUT_BLT_PIXEL\r
-      //\r
-      VbeBuffer = ((UINT8 *) VbeFrameBuffer + (SrcY * BytesPerScanLine + SourceX * VbePixelWidth));\r
-      for (DstX = DestinationX; DstX < (Width + DestinationX); DstX++) {\r
-        Pixel         = VbeBuffer[0] | VbeBuffer[1] << 8 | VbeBuffer[2] << 16 | VbeBuffer[3] << 24;\r
-        Blt->Red      = (UINT8) ((Pixel >> Mode->Red.Position) & Mode->Red.Mask);\r
-        Blt->Blue     = (UINT8) ((Pixel >> Mode->Blue.Position) & Mode->Blue.Mask);\r
-        Blt->Green    = (UINT8) ((Pixel >> Mode->Green.Position) & Mode->Green.Mask);\r
-        Blt->Reserved = 0;\r
-        Blt++;\r
-        VbeBuffer += VbePixelWidth;\r
+    case EfiBltVideoToBltBuffer:\r
+      for (SrcY = SourceY, DstY = DestinationY; DstY < (Height + DestinationY); SrcY++, DstY++) {\r
+        Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)(BltUint8 + DstY * Delta + DestinationX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+        //\r
+        // Shuffle the packed bytes in the hardware buffer to match EFI_GRAPHICS_OUTPUT_BLT_PIXEL\r
+        //\r
+        VbeBuffer = ((UINT8 *)VbeFrameBuffer + (SrcY * BytesPerScanLine + SourceX * VbePixelWidth));\r
+        for (DstX = DestinationX; DstX < (Width + DestinationX); DstX++) {\r
+          Pixel         = VbeBuffer[0] | VbeBuffer[1] << 8 | VbeBuffer[2] << 16 | VbeBuffer[3] << 24;\r
+          Blt->Red      = (UINT8)((Pixel >> Mode->Red.Position) & Mode->Red.Mask);\r
+          Blt->Blue     = (UINT8)((Pixel >> Mode->Blue.Position) & Mode->Blue.Mask);\r
+          Blt->Green    = (UINT8)((Pixel >> Mode->Green.Position) & Mode->Green.Mask);\r
+          Blt->Reserved = 0;\r
+          Blt++;\r
+          VbeBuffer += VbePixelWidth;\r
+        }\r
       }\r
 \r
-    }\r
-    break;\r
+      break;\r
 \r
-  case EfiBltVideoToVideo:\r
-    for (Index = 0; Index < Height; Index++) {\r
-      if (DestinationY <= SourceY) {\r
-        SrcY  = SourceY + Index;\r
-        DstY  = DestinationY + Index;\r
-      } else {\r
-        SrcY  = SourceY + Height - Index - 1;\r
-        DstY  = DestinationY + Height - Index - 1;\r
-      }\r
+    case EfiBltVideoToVideo:\r
+      for (Index = 0; Index < Height; Index++) {\r
+        if (DestinationY <= SourceY) {\r
+          SrcY = SourceY + Index;\r
+          DstY = DestinationY + Index;\r
+        } else {\r
+          SrcY = SourceY + Height - Index - 1;\r
+          DstY = DestinationY + Height - Index - 1;\r
+        }\r
 \r
-      VbeBuffer   = ((UINT8 *) VbeFrameBuffer + DstY * BytesPerScanLine + DestinationX * VbePixelWidth);\r
-      VbeBuffer1  = ((UINT8 *) VbeFrameBuffer + SrcY * BytesPerScanLine + SourceX * VbePixelWidth);\r
+        VbeBuffer  = ((UINT8 *)VbeFrameBuffer + DstY * BytesPerScanLine + DestinationX * VbePixelWidth);\r
+        VbeBuffer1 = ((UINT8 *)VbeFrameBuffer + SrcY * BytesPerScanLine + SourceX * VbePixelWidth);\r
 \r
-      gBS->CopyMem (\r
-            VbeBuffer,\r
-            VbeBuffer1,\r
-            TotalBytes\r
-            );\r
+        gBS->CopyMem (\r
+               VbeBuffer,\r
+               VbeBuffer1,\r
+               TotalBytes\r
+               );\r
+\r
+        //\r
+        // Update physical frame buffer.\r
+        //\r
+        CopyVideoBuffer (\r
+          PciIo,\r
+          VbeBuffer,\r
+          MemAddress,\r
+          DestinationX,\r
+          DstY,\r
+          TotalBytes,\r
+          VbePixelWidth,\r
+          BytesPerScanLine\r
+          );\r
+      }\r
+\r
+      break;\r
 \r
+    case EfiBltVideoFill:\r
+      VbeBuffer = (UINT8 *)((UINTN)VbeFrameBuffer + (DestinationY * BytesPerScanLine) + DestinationX * VbePixelWidth);\r
+      Blt       = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)BltUint8;\r
       //\r
-      // Update physical frame buffer.\r
+      // Shuffle the RGB fields in EFI_GRAPHICS_OUTPUT_BLT_PIXEL to match the hardware buffer\r
       //\r
-      CopyVideoBuffer (\r
-        PciIo,\r
-        VbeBuffer,\r
-        MemAddress,\r
-        DestinationX,\r
-        DstY,\r
-        TotalBytes,\r
-        VbePixelWidth,\r
-        BytesPerScanLine\r
-        );\r
-    }\r
-    break;\r
+      Pixel = ((Blt->Red & Mode->Red.Mask) << Mode->Red.Position) |\r
+              (\r
+               (Blt->Green & Mode->Green.Mask) <<\r
+               Mode->Green.Position\r
+              ) |\r
+              ((Blt->Blue & Mode->Blue.Mask) << Mode->Blue.Position);\r
+\r
+      for (Index = 0; Index < Width; Index++) {\r
+        gBS->CopyMem (\r
+               VbeBuffer,\r
+               &Pixel,\r
+               VbePixelWidth\r
+               );\r
+        VbeBuffer += VbePixelWidth;\r
+      }\r
 \r
-  case EfiBltVideoFill:\r
-    VbeBuffer = (UINT8 *) ((UINTN) VbeFrameBuffer + (DestinationY * BytesPerScanLine) + DestinationX * VbePixelWidth);\r
-    Blt       = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltUint8;\r
-    //\r
-    // Shuffle the RGB fields in EFI_GRAPHICS_OUTPUT_BLT_PIXEL to match the hardware buffer\r
-    //\r
-    Pixel = ((Blt->Red & Mode->Red.Mask) << Mode->Red.Position) |\r
-      (\r
-        (Blt->Green & Mode->Green.Mask) <<\r
-        Mode->Green.Position\r
-      ) |\r
-          ((Blt->Blue & Mode->Blue.Mask) << Mode->Blue.Position);\r
+      VbeBuffer = (UINT8 *)((UINTN)VbeFrameBuffer + (DestinationY * BytesPerScanLine) + DestinationX * VbePixelWidth);\r
+      for (DstY = DestinationY + 1; DstY < (Height + DestinationY); DstY++) {\r
+        gBS->CopyMem (\r
+               (VOID *)((UINTN)VbeFrameBuffer + (DstY * BytesPerScanLine) + DestinationX * VbePixelWidth),\r
+               VbeBuffer,\r
+               TotalBytes\r
+               );\r
+      }\r
 \r
-    for (Index = 0; Index < Width; Index++) {\r
-      gBS->CopyMem (\r
-            VbeBuffer,\r
-            &Pixel,\r
-            VbePixelWidth\r
-            );\r
-      VbeBuffer += VbePixelWidth;\r
-    }\r
+      for (DstY = DestinationY; DstY < (Height + DestinationY); DstY++) {\r
+        //\r
+        // Update physical frame buffer.\r
+        //\r
+        CopyVideoBuffer (\r
+          PciIo,\r
+          VbeBuffer,\r
+          MemAddress,\r
+          DestinationX,\r
+          DstY,\r
+          TotalBytes,\r
+          VbePixelWidth,\r
+          BytesPerScanLine\r
+          );\r
+      }\r
 \r
-    VbeBuffer = (UINT8 *) ((UINTN) VbeFrameBuffer + (DestinationY * BytesPerScanLine) + DestinationX * VbePixelWidth);\r
-    for (DstY = DestinationY + 1; DstY < (Height + DestinationY); DstY++) {\r
-      gBS->CopyMem (\r
-            (VOID *) ((UINTN) VbeFrameBuffer + (DstY * BytesPerScanLine) + DestinationX * VbePixelWidth),\r
-            VbeBuffer,\r
-            TotalBytes\r
-            );\r
-    }\r
+      break;\r
 \r
-    for (DstY = DestinationY; DstY < (Height + DestinationY); DstY++) {\r
-      //\r
-      // Update physical frame buffer.\r
-      //\r
-      CopyVideoBuffer (\r
-        PciIo,\r
-        VbeBuffer,\r
-        MemAddress,\r
-        DestinationX,\r
-        DstY,\r
-        TotalBytes,\r
-        VbePixelWidth,\r
-        BytesPerScanLine\r
-        );\r
-    }\r
-    break;\r
+    case EfiBltBufferToVideo:\r
+      for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {\r
+        Blt       = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)(BltUint8 + (SrcY * Delta) + (SourceX) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+        VbeBuffer = ((UINT8 *)VbeFrameBuffer + (DstY * BytesPerScanLine + DestinationX * VbePixelWidth));\r
+        for (DstX = DestinationX; DstX < (Width + DestinationX); DstX++) {\r
+          //\r
+          // Shuffle the RGB fields in EFI_GRAPHICS_OUTPUT_BLT_PIXEL to match the hardware buffer\r
+          //\r
+          Pixel = ((Blt->Red & Mode->Red.Mask) << Mode->Red.Position) |\r
+                  ((Blt->Green & Mode->Green.Mask) << Mode->Green.Position) |\r
+                  ((Blt->Blue & Mode->Blue.Mask) << Mode->Blue.Position);\r
+          gBS->CopyMem (\r
+                 VbeBuffer,\r
+                 &Pixel,\r
+                 VbePixelWidth\r
+                 );\r
+          Blt++;\r
+          VbeBuffer += VbePixelWidth;\r
+        }\r
+\r
+        VbeBuffer = ((UINT8 *)VbeFrameBuffer + (DstY * BytesPerScanLine + DestinationX * VbePixelWidth));\r
 \r
-  case EfiBltBufferToVideo:\r
-    for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {\r
-      Blt       = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) (BltUint8 + (SrcY * Delta) + (SourceX) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
-      VbeBuffer = ((UINT8 *) VbeFrameBuffer + (DstY * BytesPerScanLine + DestinationX * VbePixelWidth));\r
-      for (DstX = DestinationX; DstX < (Width + DestinationX); DstX++) {\r
         //\r
-        // Shuffle the RGB fields in EFI_GRAPHICS_OUTPUT_BLT_PIXEL to match the hardware buffer\r
+        // Update physical frame buffer.\r
         //\r
-        Pixel = ((Blt->Red & Mode->Red.Mask) << Mode->Red.Position) |\r
-          ((Blt->Green & Mode->Green.Mask) << Mode->Green.Position) |\r
-            ((Blt->Blue & Mode->Blue.Mask) << Mode->Blue.Position);\r
-        gBS->CopyMem (\r
-              VbeBuffer,\r
-              &Pixel,\r
-              VbePixelWidth\r
-              );\r
-        Blt++;\r
-        VbeBuffer += VbePixelWidth;\r
+        CopyVideoBuffer (\r
+          PciIo,\r
+          VbeBuffer,\r
+          MemAddress,\r
+          DestinationX,\r
+          DstY,\r
+          TotalBytes,\r
+          VbePixelWidth,\r
+          BytesPerScanLine\r
+          );\r
       }\r
 \r
-      VbeBuffer = ((UINT8 *) VbeFrameBuffer + (DstY * BytesPerScanLine + DestinationX * VbePixelWidth));\r
+      break;\r
 \r
-      //\r
-      // Update physical frame buffer.\r
-      //\r
-      CopyVideoBuffer (\r
-        PciIo,\r
-        VbeBuffer,\r
-        MemAddress,\r
-        DestinationX,\r
-        DstY,\r
-        TotalBytes,\r
-        VbePixelWidth,\r
-        BytesPerScanLine\r
-        );\r
-    }\r
-    break;\r
-\r
-    default: ;\r
+    default:;\r
   }\r
 \r
   gBS->RestoreTPL (OriginalTPL);\r
@@ -2529,15 +2595,15 @@ BiosVideoGraphicsOutputVbeBlt (
   IN  UINTN                              Delta\r
   )\r
 {\r
-  BIOS_VIDEO_DEV                 *BiosVideoPrivate;\r
-  BIOS_VIDEO_MODE_DATA           *Mode;\r
+  BIOS_VIDEO_DEV        *BiosVideoPrivate;\r
+  BIOS_VIDEO_MODE_DATA  *Mode;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  BiosVideoPrivate  = BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS (This);\r
-  Mode              = &BiosVideoPrivate->ModeData[This->Mode->Mode];\r
+  BiosVideoPrivate = BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS (This);\r
+  Mode             = &BiosVideoPrivate->ModeData[This->Mode->Mode];\r
 \r
   return BiosVideoVbeBltWorker (\r
            BiosVideoPrivate,\r
@@ -2583,7 +2649,6 @@ WriteGraphicsController (
               );\r
 }\r
 \r
-\r
 /**\r
   Read the four bit plane of VGA frame buffer.\r
 \r
@@ -2606,11 +2671,11 @@ VgaReadBitPlanes (
   UINTN                Height\r
   )\r
 {\r
-  UINTN BitPlane;\r
-  UINTN Rows;\r
-  UINTN FrameBufferOffset;\r
-  UINT8 *Source;\r
-  UINT8 *Destination;\r
+  UINTN  BitPlane;\r
+  UINTN  Rows;\r
+  UINTN  FrameBufferOffset;\r
+  UINT8  *Source;\r
+  UINT8  *Destination;\r
 \r
   //\r
   // Program the Mode Register Write mode 0, Read mode 0\r
@@ -2624,7 +2689,8 @@ VgaReadBitPlanes (
   for (BitPlane = 0, FrameBufferOffset = 0;\r
        BitPlane < VGA_NUMBER_OF_BIT_PLANES;\r
        BitPlane++, FrameBufferOffset += VGA_BYTES_PER_BIT_PLANE\r
-      ) {\r
+       )\r
+  {\r
     //\r
     // Program the Read Map Select Register to select the correct bit plane\r
     //\r
@@ -2639,18 +2705,17 @@ VgaReadBitPlanes (
 \r
     for (Rows = 0; Rows < Height; Rows++, Source += VGA_BYTES_PER_SCAN_LINE, Destination += VGA_BYTES_PER_SCAN_LINE) {\r
       PciIo->Mem.Read (\r
-                  PciIo,\r
-                  EfiPciIoWidthUint8,\r
-                  EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                  (UINT64) (UINTN) Source,\r
-                  WidthInBytes,\r
-                  (VOID *) Destination\r
-                  );\r
+                   PciIo,\r
+                   EfiPciIoWidthUint8,\r
+                   EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                   (UINT64)(UINTN)Source,\r
+                   WidthInBytes,\r
+                   (VOID *)Destination\r
+                   );\r
     }\r
   }\r
 }\r
 \r
-\r
 /**\r
   Internal routine to convert VGA color to Grahpics Output color.\r
 \r
@@ -2670,12 +2735,12 @@ VgaConvertToGraphicsOutputColor (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *BltBuffer\r
   )\r
 {\r
-  UINTN Mask;\r
-  UINTN Bit;\r
-  UINTN Color;\r
+  UINTN  Mask;\r
+  UINTN  Bit;\r
+  UINTN  Color;\r
 \r
   MemoryBuffer += ((CoordinateY << 6) + (CoordinateY << 4) + (CoordinateX >> 3));\r
-  Mask = mVgaBitMaskTable[CoordinateX & 0x07];\r
+  Mask          = mVgaBitMaskTable[CoordinateX & 0x07];\r
   for (Bit = 0x01, Color = 0; Bit < 0x10; Bit <<= 1, MemoryBuffer += VGA_BYTES_PER_BIT_PLANE) {\r
     if ((*MemoryBuffer & Mask) != 0) {\r
       Color |= Bit;\r
@@ -2695,12 +2760,12 @@ VgaConvertToGraphicsOutputColor (
 **/\r
 UINT8\r
 VgaConvertColor (\r
-  IN  EFI_GRAPHICS_OUTPUT_BLT_PIXEL          *BltBuffer\r
+  IN  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *BltBuffer\r
   )\r
 {\r
-  UINT8 Color;\r
+  UINT8  Color;\r
 \r
-  Color = (UINT8) ((BltBuffer->Blue >> 7) | ((BltBuffer->Green >> 6) & 0x02) | ((BltBuffer->Red >> 5) & 0x04));\r
+  Color = (UINT8)((BltBuffer->Blue >> 7) | ((BltBuffer->Green >> 6) & 0x02) | ((BltBuffer->Red >> 5) & 0x04));\r
   if ((BltBuffer->Red + BltBuffer->Green + BltBuffer->Blue) > 0x180) {\r
     Color |= 0x08;\r
   }\r
@@ -2708,7 +2773,6 @@ VgaConvertColor (
   return Color;\r
 }\r
 \r
-\r
 /**\r
   Grahpics Output protocol instance to block transfer for VGA device.\r
 \r
@@ -2751,51 +2815,51 @@ BiosVideoGraphicsOutputVgaBlt (
   IN  UINTN                              Delta\r
   )\r
 {\r
-  BIOS_VIDEO_DEV      *BiosVideoPrivate;\r
-  EFI_TPL             OriginalTPL;\r
-  UINT8               *MemAddress;\r
-  UINTN               BytesPerScanLine;\r
-  UINTN               Bit;\r
-  UINTN               Index;\r
-  UINTN               Index1;\r
-  UINTN               StartAddress;\r
-  UINTN               Bytes;\r
-  UINTN               Offset;\r
-  UINT8               LeftMask;\r
-  UINT8               RightMask;\r
-  UINTN               Address;\r
-  UINTN               AddressFix;\r
-  UINT8               *Address1;\r
-  UINT8               *SourceAddress;\r
-  UINT8               *DestinationAddress;\r
-  EFI_PCI_IO_PROTOCOL *PciIo;\r
-  UINT8               Data;\r
-  UINT8               PixelColor;\r
-  UINT8               *VgaFrameBuffer;\r
-  UINTN               SourceOffset;\r
-  UINTN               SourceWidth;\r
-  UINTN               Rows;\r
-  UINTN               Columns;\r
-  UINTN               CoordinateX;\r
-  UINTN               CoordinateY;\r
-  UINTN               CurrentMode;\r
-\r
-  if (This == NULL || ((UINTN) BltOperation) >= EfiGraphicsOutputBltOperationMax) {\r
+  BIOS_VIDEO_DEV       *BiosVideoPrivate;\r
+  EFI_TPL              OriginalTPL;\r
+  UINT8                *MemAddress;\r
+  UINTN                BytesPerScanLine;\r
+  UINTN                Bit;\r
+  UINTN                Index;\r
+  UINTN                Index1;\r
+  UINTN                StartAddress;\r
+  UINTN                Bytes;\r
+  UINTN                Offset;\r
+  UINT8                LeftMask;\r
+  UINT8                RightMask;\r
+  UINTN                Address;\r
+  UINTN                AddressFix;\r
+  UINT8                *Address1;\r
+  UINT8                *SourceAddress;\r
+  UINT8                *DestinationAddress;\r
+  EFI_PCI_IO_PROTOCOL  *PciIo;\r
+  UINT8                Data;\r
+  UINT8                PixelColor;\r
+  UINT8                *VgaFrameBuffer;\r
+  UINTN                SourceOffset;\r
+  UINTN                SourceWidth;\r
+  UINTN                Rows;\r
+  UINTN                Columns;\r
+  UINTN                CoordinateX;\r
+  UINTN                CoordinateY;\r
+  UINTN                CurrentMode;\r
+\r
+  if ((This == NULL) || (((UINTN)BltOperation) >= EfiGraphicsOutputBltOperationMax)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  BiosVideoPrivate  = BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS (This);\r
-\r
-  CurrentMode = This->Mode->Mode;\r
-  PciIo             = BiosVideoPrivate->PciIo;\r
-  MemAddress        = BiosVideoPrivate->ModeData[CurrentMode].LinearFrameBuffer;\r
-  BytesPerScanLine  = BiosVideoPrivate->ModeData[CurrentMode].BytesPerScanLine >> 3;\r
-  VgaFrameBuffer    = BiosVideoPrivate->VgaFrameBuffer;\r
+  BiosVideoPrivate = BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS (This);\r
 \r
+  CurrentMode      = This->Mode->Mode;\r
+  PciIo            = BiosVideoPrivate->PciIo;\r
+  MemAddress       = BiosVideoPrivate->ModeData[CurrentMode].LinearFrameBuffer;\r
+  BytesPerScanLine = BiosVideoPrivate->ModeData[CurrentMode].BytesPerScanLine >> 3;\r
+  VgaFrameBuffer   = BiosVideoPrivate->VgaFrameBuffer;\r
 \r
-  if (Width == 0 || Height == 0) {\r
+  if ((Width == 0) || (Height == 0)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+\r
   //\r
   // We need to fill the Virtual Screen buffer with the blt data.\r
   // The virtual screen is upside down, as the first row is the bootom row of\r
@@ -2824,6 +2888,7 @@ BiosVideoGraphicsOutputVgaBlt (
       return EFI_INVALID_PARAMETER;\r
     }\r
   }\r
+\r
   //\r
   // If Delta is zero, then the entire BltBuffer is being used, so Delta\r
   // is the number of bytes in each row of BltBuffer.  Since BltBuffer is Width pixels size,\r
@@ -2832,6 +2897,7 @@ BiosVideoGraphicsOutputVgaBlt (
   if (Delta == 0) {\r
     Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
   }\r
+\r
   //\r
   // We have to raise to TPL Notify, so we make an atomic write the frame buffer.\r
   // We would not want a timer based event (Cursor, ...) to come in while we are\r
@@ -2843,67 +2909,10 @@ BiosVideoGraphicsOutputVgaBlt (
   // Compute some values we need for VGA\r
   //\r
   switch (BltOperation) {\r
-  case EfiBltVideoToBltBuffer:\r
-\r
-    SourceOffset  = (SourceY << 6) + (SourceY << 4) + (SourceX >> 3);\r
-    SourceWidth   = ((SourceX + Width - 1) >> 3) - (SourceX >> 3) + 1;\r
-\r
-    //\r
-    // Read all the pixels in the 4 bit planes into a memory buffer that looks like the VGA buffer\r
-    //\r
-    VgaReadBitPlanes (\r
-      PciIo,\r
-      MemAddress + SourceOffset,\r
-      VgaFrameBuffer + SourceOffset,\r
-      SourceWidth,\r
-      Height\r
-      );\r
-\r
-    //\r
-    // Convert VGA Bit Planes to a Graphics Output 32-bit color value\r
-    //\r
-    BltBuffer += (DestinationY * (Delta >> 2) + DestinationX);\r
-    for (Rows = 0, CoordinateY = SourceY; Rows < Height; Rows++, CoordinateY++, BltBuffer += (Delta >> 2)) {\r
-      for (Columns = 0, CoordinateX = SourceX; Columns < Width; Columns++, CoordinateX++, BltBuffer++) {\r
-        VgaConvertToGraphicsOutputColor (VgaFrameBuffer, CoordinateX, CoordinateY, BltBuffer);\r
-      }\r
-\r
-      BltBuffer -= Width;\r
-    }\r
+    case EfiBltVideoToBltBuffer:\r
 \r
-    break;\r
-\r
-  case EfiBltVideoToVideo:\r
-    //\r
-    // Check for an aligned Video to Video operation\r
-    //\r
-    if ((SourceX & 0x07) == 0x00 && (DestinationX & 0x07) == 0x00 && (Width & 0x07) == 0x00) {\r
-      //\r
-      // Program the Mode Register Write mode 1, Read mode 0\r
-      //\r
-      WriteGraphicsController (\r
-        PciIo,\r
-        VGA_GRAPHICS_CONTROLLER_MODE_REGISTER,\r
-        VGA_GRAPHICS_CONTROLLER_READ_MODE_0 | VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1\r
-        );\r
-\r
-      SourceAddress       = (UINT8 *) (MemAddress + (SourceY << 6) + (SourceY << 4) + (SourceX >> 3));\r
-      DestinationAddress  = (UINT8 *) (MemAddress + (DestinationY << 6) + (DestinationY << 4) + (DestinationX >> 3));\r
-      Bytes               = Width >> 3;\r
-      for (Index = 0, Offset = 0; Index < Height; Index++, Offset += BytesPerScanLine) {\r
-        PciIo->CopyMem (\r
-                PciIo,\r
-                EfiPciIoWidthUint8,\r
-                EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                (UINT64) (UINTN) (DestinationAddress + Offset),\r
-                EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                (UINT64) (UINTN) (SourceAddress + Offset),\r
-                Bytes\r
-                );\r
-      }\r
-    } else {\r
-      SourceOffset  = (SourceY << 6) + (SourceY << 4) + (SourceX >> 3);\r
-      SourceWidth   = ((SourceX + Width - 1) >> 3) - (SourceX >> 3) + 1;\r
+      SourceOffset = (SourceY << 6) + (SourceY << 4) + (SourceX >> 3);\r
+      SourceWidth  = ((SourceX + Width - 1) >> 3) - (SourceX >> 3) + 1;\r
 \r
       //\r
       // Read all the pixels in the 4 bit planes into a memory buffer that looks like the VGA buffer\r
@@ -2915,218 +2924,277 @@ BiosVideoGraphicsOutputVgaBlt (
         SourceWidth,\r
         Height\r
         );\r
-    }\r
 \r
-    break;\r
-\r
-  case EfiBltVideoFill:\r
-    StartAddress  = (UINTN) (MemAddress + (DestinationY << 6) + (DestinationY << 4) + (DestinationX >> 3));\r
-    Bytes         = ((DestinationX + Width - 1) >> 3) - (DestinationX >> 3);\r
-    LeftMask      = mVgaLeftMaskTable[DestinationX & 0x07];\r
-    RightMask     = mVgaRightMaskTable[(DestinationX + Width - 1) & 0x07];\r
-    if (Bytes == 0) {\r
-      LeftMask = (UINT8) (LeftMask & RightMask);\r
-      RightMask = 0;\r
-    }\r
-\r
-    if (LeftMask == 0xff) {\r
-      StartAddress--;\r
-      Bytes++;\r
-      LeftMask = 0;\r
-    }\r
-\r
-    if (RightMask == 0xff) {\r
-      Bytes++;\r
-      RightMask = 0;\r
-    }\r
-\r
-    PixelColor = VgaConvertColor (BltBuffer);\r
+      //\r
+      // Convert VGA Bit Planes to a Graphics Output 32-bit color value\r
+      //\r
+      BltBuffer += (DestinationY * (Delta >> 2) + DestinationX);\r
+      for (Rows = 0, CoordinateY = SourceY; Rows < Height; Rows++, CoordinateY++, BltBuffer += (Delta >> 2)) {\r
+        for (Columns = 0, CoordinateX = SourceX; Columns < Width; Columns++, CoordinateX++, BltBuffer++) {\r
+          VgaConvertToGraphicsOutputColor (VgaFrameBuffer, CoordinateX, CoordinateY, BltBuffer);\r
+        }\r
 \r
-    //\r
-    // Program the Mode Register Write mode 2, Read mode 0\r
-    //\r
-    WriteGraphicsController (\r
-      PciIo,\r
-      VGA_GRAPHICS_CONTROLLER_MODE_REGISTER,\r
-      VGA_GRAPHICS_CONTROLLER_READ_MODE_0 | VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2\r
-      );\r
+        BltBuffer -= Width;\r
+      }\r
 \r
-    //\r
-    // Program the Data Rotate/Function Select Register to replace\r
-    //\r
-    WriteGraphicsController (\r
-      PciIo,\r
-      VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER,\r
-      VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE\r
-      );\r
+      break;\r
 \r
-    if (LeftMask != 0) {\r
+    case EfiBltVideoToVideo:\r
       //\r
-      // Program the BitMask register with the Left column mask\r
+      // Check for an aligned Video to Video operation\r
       //\r
-      WriteGraphicsController (\r
-        PciIo,\r
-        VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER,\r
-        LeftMask\r
-        );\r
-\r
-      for (Index = 0, Address = StartAddress; Index < Height; Index++, Address += BytesPerScanLine) {\r
+      if (((SourceX & 0x07) == 0x00) && ((DestinationX & 0x07) == 0x00) && ((Width & 0x07) == 0x00)) {\r
         //\r
-        // Read data from the bit planes into the latches\r
+        // Program the Mode Register Write mode 1, Read mode 0\r
         //\r
-        PciIo->Mem.Read (\r
-                    PciIo,\r
-                    EfiPciIoWidthUint8,\r
-                    EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                    (UINT64) (UINTN) Address,\r
-                    1,\r
-                    &Data\r
-                    );\r
+        WriteGraphicsController (\r
+          PciIo,\r
+          VGA_GRAPHICS_CONTROLLER_MODE_REGISTER,\r
+          VGA_GRAPHICS_CONTROLLER_READ_MODE_0 | VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1\r
+          );\r
+\r
+        SourceAddress      = (UINT8 *)(MemAddress + (SourceY << 6) + (SourceY << 4) + (SourceX >> 3));\r
+        DestinationAddress = (UINT8 *)(MemAddress + (DestinationY << 6) + (DestinationY << 4) + (DestinationX >> 3));\r
+        Bytes              = Width >> 3;\r
+        for (Index = 0, Offset = 0; Index < Height; Index++, Offset += BytesPerScanLine) {\r
+          PciIo->CopyMem (\r
+                   PciIo,\r
+                   EfiPciIoWidthUint8,\r
+                   EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                   (UINT64)(UINTN)(DestinationAddress + Offset),\r
+                   EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                   (UINT64)(UINTN)(SourceAddress + Offset),\r
+                   Bytes\r
+                   );\r
+        }\r
+      } else {\r
+        SourceOffset = (SourceY << 6) + (SourceY << 4) + (SourceX >> 3);\r
+        SourceWidth  = ((SourceX + Width - 1) >> 3) - (SourceX >> 3) + 1;\r
+\r
         //\r
-        // Write the lower 4 bits of PixelColor to the bit planes in the pixels enabled by BitMask\r
+        // Read all the pixels in the 4 bit planes into a memory buffer that looks like the VGA buffer\r
         //\r
-        PciIo->Mem.Write (\r
-                    PciIo,\r
-                    EfiPciIoWidthUint8,\r
-                    EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                    (UINT64) (UINTN) Address,\r
-                    1,\r
-                    &PixelColor\r
-                    );\r
+        VgaReadBitPlanes (\r
+          PciIo,\r
+          MemAddress + SourceOffset,\r
+          VgaFrameBuffer + SourceOffset,\r
+          SourceWidth,\r
+          Height\r
+          );\r
       }\r
-    }\r
 \r
-    if (Bytes > 1) {\r
+      break;\r
+\r
+    case EfiBltVideoFill:\r
+      StartAddress = (UINTN)(MemAddress + (DestinationY << 6) + (DestinationY << 4) + (DestinationX >> 3));\r
+      Bytes        = ((DestinationX + Width - 1) >> 3) - (DestinationX >> 3);\r
+      LeftMask     = mVgaLeftMaskTable[DestinationX & 0x07];\r
+      RightMask    = mVgaRightMaskTable[(DestinationX + Width - 1) & 0x07];\r
+      if (Bytes == 0) {\r
+        LeftMask  = (UINT8)(LeftMask & RightMask);\r
+        RightMask = 0;\r
+      }\r
+\r
+      if (LeftMask == 0xff) {\r
+        StartAddress--;\r
+        Bytes++;\r
+        LeftMask = 0;\r
+      }\r
+\r
+      if (RightMask == 0xff) {\r
+        Bytes++;\r
+        RightMask = 0;\r
+      }\r
+\r
+      PixelColor = VgaConvertColor (BltBuffer);\r
+\r
       //\r
-      // Program the BitMask register with the middle column mask of 0xff\r
+      // Program the Mode Register Write mode 2, Read mode 0\r
       //\r
       WriteGraphicsController (\r
         PciIo,\r
-        VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER,\r
-        0xff\r
+        VGA_GRAPHICS_CONTROLLER_MODE_REGISTER,\r
+        VGA_GRAPHICS_CONTROLLER_READ_MODE_0 | VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2\r
         );\r
 \r
-      for (Index = 0, Address = StartAddress + 1; Index < Height; Index++, Address += BytesPerScanLine) {\r
-        PciIo->Mem.Write (\r
-                    PciIo,\r
-                    EfiPciIoWidthFillUint8,\r
-                    EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                    (UINT64) (UINTN) Address,\r
-                    Bytes - 1,\r
-                    &PixelColor\r
-                    );\r
-      }\r
-    }\r
-\r
-    if (RightMask != 0) {\r
       //\r
-      // Program the BitMask register with the Right column mask\r
+      // Program the Data Rotate/Function Select Register to replace\r
       //\r
       WriteGraphicsController (\r
         PciIo,\r
-        VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER,\r
-        RightMask\r
+        VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER,\r
+        VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE\r
         );\r
 \r
-      for (Index = 0, Address = StartAddress + Bytes; Index < Height; Index++, Address += BytesPerScanLine) {\r
-        //\r
-        // Read data from the bit planes into the latches\r
-        //\r
-        PciIo->Mem.Read (\r
-                    PciIo,\r
-                    EfiPciIoWidthUint8,\r
-                    EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                    (UINT64) (UINTN) Address,\r
-                    1,\r
-                    &Data\r
-                    );\r
+      if (LeftMask != 0) {\r
         //\r
-        // Write the lower 4 bits of PixelColor to the bit planes in the pixels enabled by BitMask\r
+        // Program the BitMask register with the Left column mask\r
         //\r
-        PciIo->Mem.Write (\r
-                    PciIo,\r
-                    EfiPciIoWidthUint8,\r
-                    EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                    (UINT64) (UINTN) Address,\r
-                    1,\r
-                    &PixelColor\r
-                    );\r
-      }\r
-    }\r
-    break;\r
-\r
-  case EfiBltBufferToVideo:\r
-    StartAddress  = (UINTN) (MemAddress + (DestinationY << 6) + (DestinationY << 4) + (DestinationX >> 3));\r
-    LeftMask      = mVgaBitMaskTable[DestinationX & 0x07];\r
+        WriteGraphicsController (\r
+          PciIo,\r
+          VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER,\r
+          LeftMask\r
+          );\r
 \r
-    //\r
-    // Program the Mode Register Write mode 2, Read mode 0\r
-    //\r
-    WriteGraphicsController (\r
-      PciIo,\r
-      VGA_GRAPHICS_CONTROLLER_MODE_REGISTER,\r
-      VGA_GRAPHICS_CONTROLLER_READ_MODE_0 | VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2\r
-      );\r
+        for (Index = 0, Address = StartAddress; Index < Height; Index++, Address += BytesPerScanLine) {\r
+          //\r
+          // Read data from the bit planes into the latches\r
+          //\r
+          PciIo->Mem.Read (\r
+                       PciIo,\r
+                       EfiPciIoWidthUint8,\r
+                       EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                       (UINT64)(UINTN)Address,\r
+                       1,\r
+                       &Data\r
+                       );\r
+          //\r
+          // Write the lower 4 bits of PixelColor to the bit planes in the pixels enabled by BitMask\r
+          //\r
+          PciIo->Mem.Write (\r
+                       PciIo,\r
+                       EfiPciIoWidthUint8,\r
+                       EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                       (UINT64)(UINTN)Address,\r
+                       1,\r
+                       &PixelColor\r
+                       );\r
+        }\r
+      }\r
 \r
-    //\r
-    // Program the Data Rotate/Function Select Register to replace\r
-    //\r
-    WriteGraphicsController (\r
-      PciIo,\r
-      VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER,\r
-      VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE\r
-      );\r
+      if (Bytes > 1) {\r
+        //\r
+        // Program the BitMask register with the middle column mask of 0xff\r
+        //\r
+        WriteGraphicsController (\r
+          PciIo,\r
+          VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER,\r
+          0xff\r
+          );\r
 \r
-    for (Index = 0, Address = StartAddress; Index < Height; Index++, Address += BytesPerScanLine) {\r
-      for (Index1 = 0; Index1 < Width; Index1++) {\r
-        BiosVideoPrivate->LineBuffer[Index1] = VgaConvertColor (&BltBuffer[(SourceY + Index) * (Delta >> 2) + SourceX + Index1]);\r
+        for (Index = 0, Address = StartAddress + 1; Index < Height; Index++, Address += BytesPerScanLine) {\r
+          PciIo->Mem.Write (\r
+                       PciIo,\r
+                       EfiPciIoWidthFillUint8,\r
+                       EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                       (UINT64)(UINTN)Address,\r
+                       Bytes - 1,\r
+                       &PixelColor\r
+                       );\r
+        }\r
       }\r
-      AddressFix = Address;\r
 \r
-      for (Bit = 0; Bit < 8; Bit++) {\r
+      if (RightMask != 0) {\r
         //\r
-        // Program the BitMask register with the Left column mask\r
+        // Program the BitMask register with the Right column mask\r
         //\r
         WriteGraphicsController (\r
           PciIo,\r
           VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER,\r
-          LeftMask\r
+          RightMask\r
           );\r
 \r
-        for (Index1 = Bit, Address1 = (UINT8 *) AddressFix; Index1 < Width; Index1 += 8, Address1++) {\r
+        for (Index = 0, Address = StartAddress + Bytes; Index < Height; Index++, Address += BytesPerScanLine) {\r
           //\r
           // Read data from the bit planes into the latches\r
           //\r
           PciIo->Mem.Read (\r
-                      PciIo,\r
-                      EfiPciIoWidthUint8,\r
-                      EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                      (UINT64) (UINTN) Address1,\r
-                      1,\r
-                      &Data\r
-                      );\r
-\r
+                       PciIo,\r
+                       EfiPciIoWidthUint8,\r
+                       EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                       (UINT64)(UINTN)Address,\r
+                       1,\r
+                       &Data\r
+                       );\r
+          //\r
+          // Write the lower 4 bits of PixelColor to the bit planes in the pixels enabled by BitMask\r
+          //\r
           PciIo->Mem.Write (\r
-                      PciIo,\r
-                      EfiPciIoWidthUint8,\r
-                      EFI_PCI_IO_PASS_THROUGH_BAR,\r
-                      (UINT64) (UINTN) Address1,\r
-                      1,\r
-                      &BiosVideoPrivate->LineBuffer[Index1]\r
-                      );\r
+                       PciIo,\r
+                       EfiPciIoWidthUint8,\r
+                       EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                       (UINT64)(UINTN)Address,\r
+                       1,\r
+                       &PixelColor\r
+                       );\r
         }\r
+      }\r
+\r
+      break;\r
+\r
+    case EfiBltBufferToVideo:\r
+      StartAddress = (UINTN)(MemAddress + (DestinationY << 6) + (DestinationY << 4) + (DestinationX >> 3));\r
+      LeftMask     = mVgaBitMaskTable[DestinationX & 0x07];\r
+\r
+      //\r
+      // Program the Mode Register Write mode 2, Read mode 0\r
+      //\r
+      WriteGraphicsController (\r
+        PciIo,\r
+        VGA_GRAPHICS_CONTROLLER_MODE_REGISTER,\r
+        VGA_GRAPHICS_CONTROLLER_READ_MODE_0 | VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2\r
+        );\r
+\r
+      //\r
+      // Program the Data Rotate/Function Select Register to replace\r
+      //\r
+      WriteGraphicsController (\r
+        PciIo,\r
+        VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER,\r
+        VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE\r
+        );\r
 \r
-        LeftMask = (UINT8) (LeftMask >> 1);\r
-        if (LeftMask == 0) {\r
-          LeftMask = 0x80;\r
-          AddressFix++;\r
+      for (Index = 0, Address = StartAddress; Index < Height; Index++, Address += BytesPerScanLine) {\r
+        for (Index1 = 0; Index1 < Width; Index1++) {\r
+          BiosVideoPrivate->LineBuffer[Index1] = VgaConvertColor (&BltBuffer[(SourceY + Index) * (Delta >> 2) + SourceX + Index1]);\r
+        }\r
+\r
+        AddressFix = Address;\r
+\r
+        for (Bit = 0; Bit < 8; Bit++) {\r
+          //\r
+          // Program the BitMask register with the Left column mask\r
+          //\r
+          WriteGraphicsController (\r
+            PciIo,\r
+            VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER,\r
+            LeftMask\r
+            );\r
+\r
+          for (Index1 = Bit, Address1 = (UINT8 *)AddressFix; Index1 < Width; Index1 += 8, Address1++) {\r
+            //\r
+            // Read data from the bit planes into the latches\r
+            //\r
+            PciIo->Mem.Read (\r
+                         PciIo,\r
+                         EfiPciIoWidthUint8,\r
+                         EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                         (UINT64)(UINTN)Address1,\r
+                         1,\r
+                         &Data\r
+                         );\r
+\r
+            PciIo->Mem.Write (\r
+                         PciIo,\r
+                         EfiPciIoWidthUint8,\r
+                         EFI_PCI_IO_PASS_THROUGH_BAR,\r
+                         (UINT64)(UINTN)Address1,\r
+                         1,\r
+                         &BiosVideoPrivate->LineBuffer[Index1]\r
+                         );\r
+          }\r
+\r
+          LeftMask = (UINT8)(LeftMask >> 1);\r
+          if (LeftMask == 0) {\r
+            LeftMask = 0x80;\r
+            AddressFix++;\r
+          }\r
         }\r
       }\r
-    }\r
 \r
-    break;\r
+      break;\r
 \r
-    default: ;\r
+    default:;\r
   }\r
 \r
   gBS->RestoreTPL (OriginalTPL);\r
@@ -3155,8 +3223,8 @@ BiosVideoVgaMiniPortSetMode (
   IN  UINTN                       ModeNumber\r
   )\r
 {\r
-  BIOS_VIDEO_DEV        *BiosVideoPrivate;\r
-  EFI_IA32_REGISTER_SET Regs;\r
+  BIOS_VIDEO_DEV         *BiosVideoPrivate;\r
+  EFI_IA32_REGISTER_SET  Regs;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -3168,41 +3236,42 @@ BiosVideoVgaMiniPortSetMode (
   if (ModeNumber >= This->MaxMode) {\r
     return EFI_UNSUPPORTED;\r
   }\r
+\r
   //\r
   // Get the device structure for this device\r
   //\r
   BiosVideoPrivate = BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS (This);\r
 \r
   switch (ModeNumber) {\r
-  case 0:\r
-    //\r
-    // Set the 80x25 Text VGA Mode\r
-    //\r
-    Regs.H.AH = 0x00;\r
-    Regs.H.AL = 0x83;\r
-    BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
+    case 0:\r
+      //\r
+      // Set the 80x25 Text VGA Mode\r
+      //\r
+      Regs.H.AH = 0x00;\r
+      Regs.H.AL = 0x83;\r
+      BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
 \r
-    Regs.H.AH = 0x11;\r
-    Regs.H.AL = 0x14;\r
-    Regs.H.BL = 0;\r
-    BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
-    break;\r
+      Regs.H.AH = 0x11;\r
+      Regs.H.AL = 0x14;\r
+      Regs.H.BL = 0;\r
+      BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
+      break;\r
 \r
-  case 1:\r
-    //\r
-    // Set the 80x50 Text VGA Mode\r
-    //\r
-    Regs.H.AH = 0x00;\r
-    Regs.H.AL = 0x83;\r
-    BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
-    Regs.H.AH = 0x11;\r
-    Regs.H.AL = 0x12;\r
-    Regs.H.BL = 0;\r
-    BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
-    break;\r
+    case 1:\r
+      //\r
+      // Set the 80x50 Text VGA Mode\r
+      //\r
+      Regs.H.AH = 0x00;\r
+      Regs.H.AL = 0x83;\r
+      BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
+      Regs.H.AH = 0x11;\r
+      Regs.H.AL = 0x12;\r
+      Regs.H.BL = 0;\r
+      BiosVideoPrivate->LegacyBios->Int86 (BiosVideoPrivate->LegacyBios, 0x10, &Regs);\r
+      break;\r
 \r
-  default:\r
-    return EFI_UNSUPPORTED;\r
+    default:\r
+      return EFI_UNSUPPORTED;\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -3218,14 +3287,14 @@ BiosVideoVgaMiniPortSetMode (
 VOID\r
 EFIAPI\r
 BiosVideoNotifyExitBootServices (\r
-  IN  EFI_EVENT Event,\r
-  IN  VOID      *Context\r
+  IN  EFI_EVENT  Event,\r
+  IN  VOID       *Context\r
   )\r
 {\r
   BIOS_VIDEO_DEV         *BiosVideoPrivate;\r
   EFI_IA32_REGISTER_SET  Regs;\r
 \r
-  BiosVideoPrivate  = (BIOS_VIDEO_DEV *)Context;\r
+  BiosVideoPrivate = (BIOS_VIDEO_DEV *)Context;\r
 \r
   //\r
   // Set the 80x25 Text VGA Mode\r
@@ -3256,9 +3325,9 @@ BiosVideoNotifyExitBootServices (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-BiosVideoEntryPoint(\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE     *SystemTable\r
+BiosVideoEntryPoint (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
   EFI_STATUS  Status;\r