]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/LcdGraphicsOutputDxe.c
ArmPlatformPkg: Tidy Lcd code: Coding standard
[mirror_edk2.git] / ArmPlatformPkg / Drivers / LcdGraphicsOutputDxe / LcdGraphicsOutputDxe.c
index b721061fc1df5695092e8c71da97ae0b9af46b3f..905eb26ee01b5037dfbaf3c054a62593837c8b5f 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
- Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>\r
+ Copyright (c) 2011-2018, ARM Ltd. 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
@@ -9,7 +9,7 @@
  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
- **/\r
+**/\r
 \r
 #include <PiDxe.h>\r
 #include <Library/BaseMemoryLib.h>\r
 \r
 #include "LcdGraphicsOutputDxe.h"\r
 \r
-/**********************************************************************\r
- *\r
- *  This file implements the Graphics Output protocol on ArmVersatileExpress\r
- *  using the Lcd controller\r
- *\r
- **********************************************************************/\r
+/** This file implements the Graphics Output protocol on ArmVersatileExpress\r
+  using the Lcd controller\r
+\r
+**/\r
 \r
 //\r
 // Global variables\r
@@ -64,7 +62,10 @@ LCD_INSTANCE mLcdTemplate = {
     {\r
       {\r
         HARDWARE_DEVICE_PATH, HW_VENDOR_DP,\r
-        { (UINT8) (sizeof(VENDOR_DEVICE_PATH)), (UINT8) ((sizeof(VENDOR_DEVICE_PATH)) >> 8) },\r
+        {\r
+          (UINT8)(sizeof (VENDOR_DEVICE_PATH)),\r
+          (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
+        },\r
       },\r
       // Hardware Device Path for Lcd\r
       EFI_CALLER_ID_GUID // Use the driver's GUID\r
@@ -73,10 +74,13 @@ LCD_INSTANCE mLcdTemplate = {
     {\r
       END_DEVICE_PATH_TYPE,\r
       END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-      { sizeof(EFI_DEVICE_PATH_PROTOCOL), 0 }\r
+      {\r
+        sizeof (EFI_DEVICE_PATH_PROTOCOL),\r
+        0\r
+      }\r
     }\r
   },\r
-  (EFI_EVENT) NULL // ExitBootServicesEvent\r
+  (EFI_EVENT)NULL // ExitBootServicesEvent\r
 };\r
 \r
 EFI_STATUS\r
@@ -86,7 +90,7 @@ LcdInstanceContructor (
 {\r
   LCD_INSTANCE* Instance;\r
 \r
-  Instance = AllocateCopyPool (sizeof(LCD_INSTANCE), &mLcdTemplate);\r
+  Instance = AllocateCopyPool (sizeof (LCD_INSTANCE), &mLcdTemplate);\r
   if (Instance == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -113,23 +117,23 @@ InitializeDisplay (
   UINTN                  VramSize;\r
 \r
   Status = LcdPlatformGetVram (&VramBaseAddress, &VramSize);\r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
   // Setup the LCD\r
   Status = LcdInitialize (VramBaseAddress);\r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     goto EXIT_ERROR_LCD_SHUTDOWN;\r
   }\r
 \r
   Status = LcdPlatformInitializeDisplay (Instance->Handle);\r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     goto EXIT_ERROR_LCD_SHUTDOWN;\r
   }\r
 \r
   // Setup all the relevant mode information\r
-  Instance->Gop.Mode->SizeOfInfo      = sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+  Instance->Gop.Mode->SizeOfInfo      = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
   Instance->Gop.Mode->FrameBufferBase = VramBaseAddress;\r
 \r
   // Set the flag before changing the mode, to avoid infinite loops\r
@@ -139,7 +143,8 @@ InitializeDisplay (
   goto EXIT;\r
 \r
 EXIT_ERROR_LCD_SHUTDOWN:\r
-  DEBUG((DEBUG_ERROR, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status));\r
+  DEBUG ((DEBUG_ERROR, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status));\r
+\r
   LcdShutdown ();\r
 \r
 EXIT:\r
@@ -157,40 +162,44 @@ LcdGraphicsOutputDxeInitialize (
   LCD_INSTANCE* Instance;\r
 \r
   Status = LcdIdentify ();\r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     goto EXIT;\r
   }\r
 \r
   Status = LcdInstanceContructor (&Instance);\r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     goto EXIT;\r
   }\r
 \r
   // Install the Graphics Output Protocol and the Device Path\r
-  Status = gBS->InstallMultipleProtocolInterfaces(\r
-            &Instance->Handle,\r
-            &gEfiGraphicsOutputProtocolGuid, &Instance->Gop,\r
-            &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,\r
-            NULL\r
-            );\r
-\r
-  if (EFI_ERROR(Status)) {\r
-    DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status));\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Instance->Handle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  &Instance->Gop,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  &Instance->DevicePath,\r
+                  NULL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "LcdGraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status));\r
     goto EXIT;\r
   }\r
 \r
   // Register for an ExitBootServicesEvent\r
-  // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,\r
-  // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.\r
+  // When ExitBootServices starts, this function will make sure that the\r
+  // graphics driver shuts down properly, i.e. it will free up all\r
+  // allocated memory and perform any necessary hardware re-configuration.\r
   Status = gBS->CreateEvent (\r
-            EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
-            TPL_NOTIFY,\r
-            LcdGraphicsExitBootServicesEvent, NULL,\r
-            &Instance->ExitBootServicesEvent\r
-            );\r
-\r
-  if (EFI_ERROR(Status)) {\r
-    DEBUG((DEBUG_ERROR, "GraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status));\r
+                  EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
+                  TPL_NOTIFY,\r
+                  LcdGraphicsExitBootServicesEvent,\r
+                  NULL,\r
+                  &Instance->ExitBootServicesEvent\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "LcdGraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status));\r
     goto EXIT_ERROR_UNINSTALL_PROTOCOL;\r
   }\r
 \r
@@ -198,48 +207,46 @@ LcdGraphicsOutputDxeInitialize (
   goto EXIT;\r
 \r
 EXIT_ERROR_UNINSTALL_PROTOCOL:\r
-  /* The following function could return an error message,\r
-   * however, to get here something must have gone wrong already,\r
-   * so preserve the original error, i.e. don't change\r
-   * the Status variable, even it fails to uninstall the protocol.\r
-   */\r
+  // The following function could return an error message,\r
+  // however, to get here something must have gone wrong already,\r
+  // so preserve the original error, i.e. don't change\r
+  // the Status variable, even it fails to uninstall the protocol.\r
   gBS->UninstallMultipleProtocolInterfaces (\r
-    Instance->Handle,\r
-    &gEfiGraphicsOutputProtocolGuid, &Instance->Gop, // Uninstall Graphics Output protocol\r
-    &gEfiDevicePathProtocolGuid,     &Instance->DevicePath,     // Uninstall device path\r
-    NULL\r
-    );\r
+         Instance->Handle,\r
+         &gEfiGraphicsOutputProtocolGuid,\r
+         &Instance->Gop, // Uninstall Graphics Output protocol\r
+         &gEfiDevicePathProtocolGuid,\r
+         &Instance->DevicePath,     // Uninstall device path\r
+         NULL\r
+         );\r
 \r
 EXIT:\r
   return Status;\r
-\r
 }\r
 \r
-/***************************************\r
- * This function should be called\r
- * on Event: ExitBootServices\r
- * to free up memory, stop the driver\r
- * and uninstall the protocols\r
- ***************************************/\r
+/** This function should be called\r
+  on Event: ExitBootServices\r
+  to free up memory, stop the driver\r
+  and uninstall the protocols\r
+**/\r
 VOID\r
 LcdGraphicsExitBootServicesEvent (\r
   IN EFI_EVENT  Event,\r
   IN VOID       *Context\r
   )\r
 {\r
-  // By default, this PCD is FALSE. But if a platform starts a predefined OS that\r
-  // does not use a framebuffer then we might want to disable the display controller\r
-  // to avoid to display corrupted information on the screen.\r
+  // By default, this PCD is FALSE. But if a platform starts a predefined OS\r
+  // that does not use a framebuffer then we might want to disable the display\r
+  // controller to avoid to display corrupted information on the screen.\r
   if (FeaturePcdGet (PcdGopDisableOnExitBootServices)) {\r
     // Turn-off the Display controller\r
     LcdShutdown ();\r
   }\r
 }\r
 \r
-/***************************************\r
- * GraphicsOutput Protocol function, mapping to\r
- * EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode\r
- ***************************************/\r
+/** GraphicsOutput Protocol function, mapping to\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 LcdGraphicsQueryMode (\r
@@ -252,19 +259,22 @@ LcdGraphicsQueryMode (
   EFI_STATUS Status = EFI_SUCCESS;\r
   LCD_INSTANCE *Instance;\r
 \r
-  Instance = LCD_INSTANCE_FROM_GOP_THIS(This);\r
+  Instance = LCD_INSTANCE_FROM_GOP_THIS (This);\r
 \r
   // Setup the hardware if not already done\r
-  if( !mDisplayInitialized ) {\r
-    Status = InitializeDisplay(Instance);\r
-    if (EFI_ERROR(Status)) {\r
+  if (!mDisplayInitialized) {\r
+    Status = InitializeDisplay (Instance);\r
+    if (EFI_ERROR (Status)) {\r
       goto EXIT;\r
     }\r
   }\r
 \r
   // Error checking\r
-  if ( (This == NULL) || (Info == NULL) || (SizeOfInfo == NULL) || (ModeNumber >= This->Mode->MaxMode) ) {\r
-    DEBUG((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber ));\r
+  if ((This == NULL) ||\r
+      (Info == NULL) ||\r
+      (SizeOfInfo == NULL) ||\r
+      (ModeNumber >= This->Mode->MaxMode)) {\r
+    DEBUG ((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber));\r
     Status = EFI_INVALID_PARAMETER;\r
     goto EXIT;\r
   }\r
@@ -275,21 +285,20 @@ LcdGraphicsQueryMode (
     goto EXIT;\r
   }\r
 \r
-  *SizeOfInfo = sizeofEFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
+  *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r
 \r
-  Status = LcdPlatformQueryMode (ModeNumber,*Info);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool(*Info);\r
+  Status = LcdPlatformQueryMode (ModeNumber, *Info);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (*Info);\r
   }\r
 \r
 EXIT:\r
   return Status;\r
 }\r
 \r
-/***************************************\r
- * GraphicsOutput Protocol function, mapping to\r
- * EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode\r
- ***************************************/\r
+/** GraphicsOutput Protocol function, mapping to\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 LcdGraphicsSetMode (\r
@@ -305,47 +314,48 @@ LcdGraphicsSetMode (
   Instance = LCD_INSTANCE_FROM_GOP_THIS (This);\r
 \r
   // Setup the hardware if not already done\r
-  if(!mDisplayInitialized) {\r
+  if (!mDisplayInitialized) {\r
     Status = InitializeDisplay (Instance);\r
-    if (EFI_ERROR(Status)) {\r
+    if (EFI_ERROR (Status)) {\r
       goto EXIT;\r
     }\r
   }\r
 \r
   // Check if this mode is supported\r
-  if( ModeNumber >= This->Mode->MaxMode ) {\r
-    DEBUG((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber ));\r
+  if (ModeNumber >= This->Mode->MaxMode) {\r
+    DEBUG ((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber));\r
     Status = EFI_UNSUPPORTED;\r
     goto EXIT;\r
   }\r
 \r
   // Set the oscillator frequency to support the new mode\r
   Status = LcdPlatformSetMode (ModeNumber);\r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     Status = EFI_DEVICE_ERROR;\r
     goto EXIT;\r
   }\r
 \r
   // Update the UEFI mode information\r
   This->Mode->Mode = ModeNumber;\r
-  LcdPlatformQueryMode (ModeNumber,&Instance->ModeInfo);\r
-  Status = LcdPlatformGetBpp(ModeNumber, &Bpp);\r
-  if (EFI_ERROR(Status)) {\r
+  LcdPlatformQueryMode (ModeNumber, &Instance->ModeInfo);\r
+  Status = LcdPlatformGetBpp (ModeNumber, &Bpp);\r
+  if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status));\r
     goto EXIT;\r
   }\r
   This->Mode->FrameBufferSize =  Instance->ModeInfo.VerticalResolution\r
-                               * Instance->ModeInfo.PixelsPerScanLine\r
-                               * GetBytesPerPixel(Bpp);\r
+                                 * Instance->ModeInfo.PixelsPerScanLine\r
+                                 * GetBytesPerPixel (Bpp);\r
 \r
   // Set the hardware to the new mode\r
   Status = LcdSetMode (ModeNumber);\r
-  if (EFI_ERROR(Status)) {\r
+  if (EFI_ERROR (Status)) {\r
     Status = EFI_DEVICE_ERROR;\r
     goto EXIT;\r
   }\r
 \r
-  // The UEFI spec requires that we now clear the visible portions of the output display to black.\r
+  // The UEFI spec requires that we now clear the visible portions of the\r
+  // output display to black.\r
 \r
   // Set the fill colour to black\r
   SetMem (&FillColour, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r
@@ -361,7 +371,8 @@ LcdGraphicsSetMode (
       0,\r
       This->Mode->Info->HorizontalResolution,\r
       This->Mode->Info->VerticalResolution,\r
-      0);\r
+      0\r
+      );\r
 \r
 EXIT:\r
   return Status;\r
@@ -372,7 +383,7 @@ GetBytesPerPixel (
   IN  LCD_BPP       Bpp\r
   )\r
 {\r
-  switch(Bpp) {\r
+  switch (Bpp) {\r
   case LCD_BITS_PER_PIXEL_24:\r
     return 4;\r
 \r