]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
Add BootlogoOnly feature in BDS for BGRT
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsConsole.c
index 42b0a23769e40ac694c54c31a6b1a3ad0d77918c..4fca0f3b12e076bf36f6dc962964ced518e994b6 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   BDS Lib functions which contain all the code to connect console device\r
 \r
-Copyright (c) 2004 - 2009, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -13,7 +13,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "InternalBdsLib.h"\r
-#include "Bmp.h"\r
+#include <IndustryStandard/Bmp.h>\r
+\r
 \r
 /**\r
   Check if we need to save the EFI variable with "ConVarName" as name\r
@@ -196,6 +197,7 @@ BdsLibUpdateConsoleVariable (
   IN  EFI_DEVICE_PATH_PROTOCOL  *ExclusiveDevicePath\r
   )\r
 {\r
+  EFI_STATUS                Status;\r
   EFI_DEVICE_PATH_PROTOCOL  *VarConsole;\r
   UINTN                     DevicePathSize;\r
   EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
@@ -272,13 +274,18 @@ BdsLibUpdateConsoleVariable (
   //\r
   // Finally, Update the variable of the default console by NewDevicePath\r
   //\r
-  gRT->SetVariable (\r
-        ConVarName,\r
-        &gEfiGlobalVariableGuid,\r
-        Attributes,\r
-        GetDevicePathSize (NewDevicePath),\r
-        NewDevicePath\r
-        );\r
+  DevicePathSize = GetDevicePathSize (NewDevicePath);\r
+  Status = gRT->SetVariable (\r
+                  ConVarName,\r
+                  &gEfiGlobalVariableGuid,\r
+                  Attributes,\r
+                  DevicePathSize,\r
+                  NewDevicePath\r
+                  );\r
+  if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   if (VarConsole == NewDevicePath) {\r
     if (VarConsole != NULL) {\r
@@ -293,7 +300,7 @@ BdsLibUpdateConsoleVariable (
     }\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 \r
 }\r
 \r
@@ -361,16 +368,32 @@ BdsLibConnectConsoleVariable (
 \r
     SetDevicePathEndNode (Next);\r
     //\r
-    // Connect the instance device path\r
+    // Connect the USB console\r
+    // USB console device path is a short-form device path that \r
+    //  starts with the first element being a USB WWID\r
+    //  or a USB Class device path\r
     //\r
-    Status = BdsLibConnectDevicePath (Instance);\r
-    if (EFI_ERROR (Status)) {\r
+    if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&\r
+       ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)\r
+       || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)\r
+       )) {\r
+      Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance);\r
+      if (!EFI_ERROR (Status)) {\r
+        DeviceExist = TRUE;\r
+      }\r
+    } else {\r
       //\r
-      // Delete the instance from the console varialbe\r
+      // Connect the instance device path\r
       //\r
-      BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);\r
-    } else {\r
-      DeviceExist = TRUE;\r
+      Status = BdsLibConnectDevicePath (Instance);\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // Delete the instance from the console varialbe\r
+        //\r
+        BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);\r
+      } else {\r
+        DeviceExist = TRUE;\r
+      }\r
     }\r
     FreePool(Instance);\r
   } while (CopyOfDevicePath != NULL);\r
@@ -764,6 +787,17 @@ EnableQuietBoot (
   UINT32                        ColorDepth;\r
   UINT32                        RefreshRate;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
+  EFI_BOOT_LOGO_PROTOCOL        *BootLogo;\r
+  UINTN                         NumberOfLogos;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LogoBlt;\r
+  UINTN                         LogoDestX;\r
+  UINTN                         LogoDestY;\r
+  UINTN                         LogoHeight;\r
+  UINTN                         LogoWidth;\r
+  UINTN                         NewDestX;\r
+  UINTN                         NewDestY;\r
+  UINTN                         NewHeight;\r
+  UINTN                         NewWidth;\r
 \r
   UgaDraw = NULL;\r
   //\r
@@ -781,6 +815,12 @@ EnableQuietBoot (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  //\r
+  // Try to open Boot Logo Protocol.\r
+  //\r
+  BootLogo = NULL;\r
+  gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);\r
+\r
   //\r
   // Erase Cursor from screen\r
   //\r
@@ -802,6 +842,16 @@ EnableQuietBoot (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  Blt = NULL;\r
+  NumberOfLogos = 0;\r
+  LogoDestX = 0;\r
+  LogoDestY = 0;\r
+  LogoHeight = 0;\r
+  LogoWidth = 0;\r
+  NewDestX = 0;\r
+  NewDestY = 0;\r
+  NewHeight = 0;\r
+  NewWidth = 0;\r
   Instance = 0;\r
   while (1) {\r
     ImageData = NULL;\r
@@ -822,7 +872,7 @@ EnableQuietBoot (
                           &CoordinateY\r
                           );\r
       if (EFI_ERROR (Status)) {\r
-        return Status;\r
+        goto Done;\r
       }\r
 \r
       //\r
@@ -845,9 +895,16 @@ EnableQuietBoot (
 \r
       CoordinateX = 0;\r
       CoordinateY = 0;\r
-      Attribute   = EfiBadgingDisplayAttributeCenter;\r
+      if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {\r
+        Attribute   = EfiBadgingDisplayAttributeCenter;\r
+      } else {\r
+        Attribute   = EfiBadgingDisplayAttributeCustomized;\r
+      } \r
     }\r
 \r
+    if (Blt != NULL) {\r
+      FreePool (Blt);\r
+    }\r
     Blt = NULL;\r
     Status = ConvertBmpToGopBlt (\r
               ImageData,\r
@@ -916,6 +973,11 @@ EnableQuietBoot (
       DestY = (SizeOfY - Height) / 2;\r
       break;\r
 \r
+    case EfiBadgingDisplayAttributeCustomized:\r
+      DestX = (SizeOfX - Width) / 2;\r
+      DestY = ((SizeOfY * 382) / 1000) - Height / 2;\r
+      break;\r
+\r
     default:\r
       DestX = CoordinateX;\r
       DestY = CoordinateY;\r
@@ -950,20 +1012,116 @@ EnableQuietBoot (
                             Width * sizeof (EFI_UGA_PIXEL)\r
                             );\r
       } else {\r
-      Status = EFI_UNSUPPORTED;\r
+        Status = EFI_UNSUPPORTED;\r
+      }\r
+\r
+      //\r
+      // Report displayed Logo information.\r
+      //\r
+      if (!EFI_ERROR (Status)) {\r
+        NumberOfLogos++;\r
+\r
+        if (LogoWidth == 0) {\r
+          //\r
+          // The first Logo.\r
+          //\r
+          LogoDestX = (UINTN) DestX;\r
+          LogoDestY = (UINTN) DestY;\r
+          LogoWidth = Width;\r
+          LogoHeight = Height;\r
+        } else {\r
+          //\r
+          // Merge new logo with old one.\r
+          //\r
+          NewDestX = MIN ((UINTN) DestX, LogoDestX);\r
+          NewDestY = MIN ((UINTN) DestY, LogoDestY);\r
+          NewWidth = MAX ((UINTN) DestX + Width, LogoDestX + LogoWidth) - NewDestX;\r
+          NewHeight = MAX ((UINTN) DestY + Height, LogoDestY + LogoHeight) - NewDestY;\r
+\r
+          LogoDestX = NewDestX;\r
+          LogoDestY = NewDestY;\r
+          LogoWidth = NewWidth;\r
+          LogoHeight = NewHeight;\r
+        }\r
       }\r
     }\r
 \r
     FreePool (ImageData);\r
 \r
+    if (Badging == NULL) {\r
+      break;\r
+    }\r
+  }\r
+\r
+Done:\r
+  if (BootLogo == NULL || NumberOfLogos == 0) {\r
+    //\r
+    // No logo displayed.\r
+    //\r
     if (Blt != NULL) {\r
       FreePool (Blt);\r
     }\r
 \r
-    if (Badging == NULL) {\r
-      break;\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Advertise displayed Logo information.\r
+  //\r
+  if (NumberOfLogos == 1) {\r
+    //\r
+    // Only one logo displayed, use its Blt buffer directly for BootLogo protocol.\r
+    //\r
+    LogoBlt = Blt;\r
+    Status = EFI_SUCCESS;\r
+  } else {\r
+    //\r
+    // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation. \r
+    //\r
+    if (Blt != NULL) {\r
+      FreePool (Blt);\r
+    }\r
+\r
+    LogoBlt = AllocateZeroPool (LogoWidth * LogoHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+    if (LogoBlt == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
+\r
+    if (GraphicsOutput != NULL) {\r
+      Status = GraphicsOutput->Blt (\r
+                          GraphicsOutput,\r
+                          LogoBlt,\r
+                          EfiBltVideoToBltBuffer,\r
+                          LogoDestX,\r
+                          LogoDestY,\r
+                          0,\r
+                          0,\r
+                          LogoWidth,\r
+                          LogoHeight,\r
+                          LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                          );\r
+    } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+      Status = UgaDraw->Blt (\r
+                          UgaDraw,\r
+                          (EFI_UGA_PIXEL *) LogoBlt,\r
+                          EfiUgaVideoToBltBuffer,\r
+                          LogoDestX,\r
+                          LogoDestY,\r
+                          0,\r
+                          0,\r
+                          LogoWidth,\r
+                          LogoHeight,\r
+                          LogoWidth * sizeof (EFI_UGA_PIXEL)\r
+                          );\r
+    } else {\r
+      Status = EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight);\r
   }\r
+  FreePool (LogoBlt);\r
 \r
   return Status;\r
 }\r