2 This file implements the Graphics Output protocol for Arm platforms
4 Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/DevicePathLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/UefiRuntimeServicesTableLib.h>
20 #include <Library/MemoryAllocationLib.h>
22 #include <Guid/GlobalVariable.h>
24 #include "LcdGraphicsOutputDxe.h"
30 BOOLEAN mDisplayInitialized
= FALSE
;
32 LCD_INSTANCE mLcdTemplate
= {
33 LCD_INSTANCE_SIGNATURE
,
37 0, // HorizontalResolution
38 0, // VerticalResolution
39 PixelBltOnly
, // PixelFormat
40 { 0 }, // PixelInformation
41 0, // PixelsPerScanLine
48 0, // FrameBufferBase;
52 LcdGraphicsQueryMode
, // QueryMode
53 LcdGraphicsSetMode
, // SetMode
54 LcdGraphicsBlt
, // Blt
60 HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
,
62 (UINT8
)(sizeof (VENDOR_DEVICE_PATH
)),
63 (UINT8
)((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
66 // Hardware Device Path for Lcd
67 EFI_CALLER_ID_GUID
// Use the driver's GUID
72 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
74 sizeof (EFI_DEVICE_PATH_PROTOCOL
),
79 (EFI_EVENT
)NULL
// ExitBootServicesEvent
83 LcdInstanceContructor (
84 OUT LCD_INSTANCE
** NewInstance
87 LCD_INSTANCE
* Instance
;
89 Instance
= AllocateCopyPool (sizeof (LCD_INSTANCE
), &mLcdTemplate
);
90 if (Instance
== NULL
) {
91 return EFI_OUT_OF_RESOURCES
;
94 Instance
->Gop
.Mode
= &Instance
->Mode
;
95 Instance
->Gop
.Mode
->MaxMode
= LcdPlatformGetMaxMode ();
96 Instance
->Mode
.Info
= &Instance
->ModeInfo
;
98 *NewInstance
= Instance
;
103 // Function Definitions
108 IN LCD_INSTANCE
* Instance
111 EFI_STATUS Status
= EFI_SUCCESS
;
112 EFI_PHYSICAL_ADDRESS VramBaseAddress
;
115 Status
= LcdPlatformGetVram (&VramBaseAddress
, &VramSize
);
116 if (EFI_ERROR (Status
)) {
121 Status
= LcdInitialize (VramBaseAddress
);
122 if (EFI_ERROR (Status
)) {
123 goto EXIT_ERROR_LCD_SHUTDOWN
;
126 Status
= LcdPlatformInitializeDisplay (Instance
->Handle
);
127 if (EFI_ERROR (Status
)) {
128 goto EXIT_ERROR_LCD_SHUTDOWN
;
131 // Setup all the relevant mode information
132 Instance
->Gop
.Mode
->SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
133 Instance
->Gop
.Mode
->FrameBufferBase
= VramBaseAddress
;
135 // Set the flag before changing the mode, to avoid infinite loops
136 mDisplayInitialized
= TRUE
;
138 // All is ok, so don't deal with any errors
141 EXIT_ERROR_LCD_SHUTDOWN
:
142 DEBUG ((DEBUG_ERROR
, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status
));
152 LcdGraphicsOutputDxeInitialize (
153 IN EFI_HANDLE ImageHandle
,
154 IN EFI_SYSTEM_TABLE
*SystemTable
157 EFI_STATUS Status
= EFI_SUCCESS
;
158 LCD_INSTANCE
* Instance
;
160 Status
= LcdIdentify ();
161 if (EFI_ERROR (Status
)) {
165 Status
= LcdInstanceContructor (&Instance
);
166 if (EFI_ERROR (Status
)) {
170 // Install the Graphics Output Protocol and the Device Path
171 Status
= gBS
->InstallMultipleProtocolInterfaces (
173 &gEfiGraphicsOutputProtocolGuid
,
175 &gEfiDevicePathProtocolGuid
,
176 &Instance
->DevicePath
,
180 if (EFI_ERROR (Status
)) {
181 DEBUG ((DEBUG_ERROR
, "LcdGraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status
));
185 // Register for an ExitBootServicesEvent
186 // When ExitBootServices starts, this function will make sure that the
187 // graphics driver shuts down properly, i.e. it will free up all
188 // allocated memory and perform any necessary hardware re-configuration.
189 Status
= gBS
->CreateEvent (
190 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
192 LcdGraphicsExitBootServicesEvent
,
194 &Instance
->ExitBootServicesEvent
197 if (EFI_ERROR (Status
)) {
198 DEBUG ((DEBUG_ERROR
, "LcdGraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status
));
199 goto EXIT_ERROR_UNINSTALL_PROTOCOL
;
202 // To get here, everything must be fine, so just exit
205 EXIT_ERROR_UNINSTALL_PROTOCOL
:
206 // The following function could return an error message,
207 // however, to get here something must have gone wrong already,
208 // so preserve the original error, i.e. don't change
209 // the Status variable, even it fails to uninstall the protocol.
210 gBS
->UninstallMultipleProtocolInterfaces (
212 &gEfiGraphicsOutputProtocolGuid
,
213 &Instance
->Gop
, // Uninstall Graphics Output protocol
214 &gEfiDevicePathProtocolGuid
,
215 &Instance
->DevicePath
, // Uninstall device path
223 /** This function should be called
224 on Event: ExitBootServices
225 to free up memory, stop the driver
226 and uninstall the protocols
229 LcdGraphicsExitBootServicesEvent (
234 // By default, this PCD is FALSE. But if a platform starts a predefined OS
235 // that does not use a framebuffer then we might want to disable the display
236 // controller to avoid to display corrupted information on the screen.
237 if (FeaturePcdGet (PcdGopDisableOnExitBootServices
)) {
238 // Turn-off the Display controller
243 /** GraphicsOutput Protocol function, mapping to
244 EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode
248 LcdGraphicsQueryMode (
249 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
250 IN UINT32 ModeNumber
,
251 OUT UINTN
*SizeOfInfo
,
252 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
255 EFI_STATUS Status
= EFI_SUCCESS
;
256 LCD_INSTANCE
*Instance
;
258 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
260 // Setup the hardware if not already done
261 if (!mDisplayInitialized
) {
262 Status
= InitializeDisplay (Instance
);
263 if (EFI_ERROR (Status
)) {
269 if ((This
== NULL
) ||
271 (SizeOfInfo
== NULL
) ||
272 (ModeNumber
>= This
->Mode
->MaxMode
)) {
273 DEBUG ((DEBUG_ERROR
, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber
));
274 Status
= EFI_INVALID_PARAMETER
;
278 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
280 Status
= EFI_OUT_OF_RESOURCES
;
284 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
286 Status
= LcdPlatformQueryMode (ModeNumber
, *Info
);
287 if (EFI_ERROR (Status
)) {
295 /** GraphicsOutput Protocol function, mapping to
296 EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode
301 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
305 EFI_STATUS Status
= EFI_SUCCESS
;
306 EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour
;
307 LCD_INSTANCE
* Instance
;
310 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
312 // Setup the hardware if not already done
313 if (!mDisplayInitialized
) {
314 Status
= InitializeDisplay (Instance
);
315 if (EFI_ERROR (Status
)) {
320 // Check if this mode is supported
321 if (ModeNumber
>= This
->Mode
->MaxMode
) {
322 DEBUG ((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber
));
323 Status
= EFI_UNSUPPORTED
;
327 // Set the oscillator frequency to support the new mode
328 Status
= LcdPlatformSetMode (ModeNumber
);
329 if (EFI_ERROR (Status
)) {
330 Status
= EFI_DEVICE_ERROR
;
334 // Update the UEFI mode information
335 This
->Mode
->Mode
= ModeNumber
;
336 LcdPlatformQueryMode (ModeNumber
, &Instance
->ModeInfo
);
337 Status
= LcdPlatformGetBpp (ModeNumber
, &Bpp
);
338 if (EFI_ERROR (Status
)) {
339 DEBUG ((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status
));
342 This
->Mode
->FrameBufferSize
= Instance
->ModeInfo
.VerticalResolution
343 * Instance
->ModeInfo
.PixelsPerScanLine
344 * GetBytesPerPixel (Bpp
);
346 // Set the hardware to the new mode
347 Status
= LcdSetMode (ModeNumber
);
348 if (EFI_ERROR (Status
)) {
349 Status
= EFI_DEVICE_ERROR
;
353 // The UEFI spec requires that we now clear the visible portions of the
354 // output display to black.
356 // Set the fill colour to black
357 SetMem (&FillColour
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
359 // Fill the entire visible area with the same colour.
368 This
->Mode
->Info
->HorizontalResolution
,
369 This
->Mode
->Info
->VerticalResolution
,
383 case LCD_BITS_PER_PIXEL_24
:
386 case LCD_BITS_PER_PIXEL_16_565
:
387 case LCD_BITS_PER_PIXEL_16_555
:
388 case LCD_BITS_PER_PIXEL_12_444
:
391 case LCD_BITS_PER_PIXEL_8
:
392 case LCD_BITS_PER_PIXEL_4
:
393 case LCD_BITS_PER_PIXEL_2
:
394 case LCD_BITS_PER_PIXEL_1
: