2 This file implements the Graphics Output protocol for Arm platforms
4 Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseMemoryLib.h>
11 #include <Library/DevicePathLib.h>
12 #include <Library/UefiBootServicesTableLib.h>
13 #include <Library/UefiRuntimeServicesTableLib.h>
14 #include <Library/MemoryAllocationLib.h>
16 #include <Guid/GlobalVariable.h>
18 #include "LcdGraphicsOutputDxe.h"
24 BOOLEAN mDisplayInitialized
= FALSE
;
26 LCD_INSTANCE mLcdTemplate
= {
27 LCD_INSTANCE_SIGNATURE
,
31 0, // HorizontalResolution
32 0, // VerticalResolution
33 PixelBltOnly
, // PixelFormat
34 { 0 }, // PixelInformation
35 0, // PixelsPerScanLine
42 0, // FrameBufferBase;
46 LcdGraphicsQueryMode
, // QueryMode
47 LcdGraphicsSetMode
, // SetMode
48 LcdGraphicsBlt
, // Blt
54 HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
,
56 (UINT8
)(sizeof (VENDOR_DEVICE_PATH
)),
57 (UINT8
)((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
60 // Hardware Device Path for Lcd
61 EFI_CALLER_ID_GUID
// Use the driver's GUID
66 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
68 sizeof (EFI_DEVICE_PATH_PROTOCOL
),
73 (EFI_EVENT
)NULL
// ExitBootServicesEvent
77 LcdInstanceContructor (
78 OUT LCD_INSTANCE
** NewInstance
81 LCD_INSTANCE
* Instance
;
83 Instance
= AllocateCopyPool (sizeof (LCD_INSTANCE
), &mLcdTemplate
);
84 if (Instance
== NULL
) {
85 return EFI_OUT_OF_RESOURCES
;
88 Instance
->Gop
.Mode
= &Instance
->Mode
;
89 Instance
->Gop
.Mode
->MaxMode
= LcdPlatformGetMaxMode ();
90 Instance
->Mode
.Info
= &Instance
->ModeInfo
;
92 *NewInstance
= Instance
;
97 // Function Definitions
102 IN LCD_INSTANCE
* Instance
105 EFI_STATUS Status
= EFI_SUCCESS
;
106 EFI_PHYSICAL_ADDRESS VramBaseAddress
;
109 Status
= LcdPlatformGetVram (&VramBaseAddress
, &VramSize
);
110 if (EFI_ERROR (Status
)) {
115 Status
= LcdInitialize (VramBaseAddress
);
116 if (EFI_ERROR (Status
)) {
117 goto EXIT_ERROR_LCD_SHUTDOWN
;
120 Status
= LcdPlatformInitializeDisplay (Instance
->Handle
);
121 if (EFI_ERROR (Status
)) {
122 goto EXIT_ERROR_LCD_SHUTDOWN
;
125 // Setup all the relevant mode information
126 Instance
->Gop
.Mode
->SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
127 Instance
->Gop
.Mode
->FrameBufferBase
= VramBaseAddress
;
129 // Set the flag before changing the mode, to avoid infinite loops
130 mDisplayInitialized
= TRUE
;
132 // All is ok, so don't deal with any errors
135 EXIT_ERROR_LCD_SHUTDOWN
:
136 DEBUG ((DEBUG_ERROR
, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status
));
146 LcdGraphicsOutputDxeInitialize (
147 IN EFI_HANDLE ImageHandle
,
148 IN EFI_SYSTEM_TABLE
*SystemTable
151 EFI_STATUS Status
= EFI_SUCCESS
;
152 LCD_INSTANCE
* Instance
;
154 Status
= LcdIdentify ();
155 if (EFI_ERROR (Status
)) {
159 Status
= LcdInstanceContructor (&Instance
);
160 if (EFI_ERROR (Status
)) {
164 // Install the Graphics Output Protocol and the Device Path
165 Status
= gBS
->InstallMultipleProtocolInterfaces (
167 &gEfiGraphicsOutputProtocolGuid
,
169 &gEfiDevicePathProtocolGuid
,
170 &Instance
->DevicePath
,
174 if (EFI_ERROR (Status
)) {
175 DEBUG ((DEBUG_ERROR
, "LcdGraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status
));
179 // Register for an ExitBootServicesEvent
180 // When ExitBootServices starts, this function will make sure that the
181 // graphics driver shuts down properly, i.e. it will free up all
182 // allocated memory and perform any necessary hardware re-configuration.
183 Status
= gBS
->CreateEvent (
184 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
186 LcdGraphicsExitBootServicesEvent
,
188 &Instance
->ExitBootServicesEvent
191 if (EFI_ERROR (Status
)) {
192 DEBUG ((DEBUG_ERROR
, "LcdGraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status
));
193 goto EXIT_ERROR_UNINSTALL_PROTOCOL
;
196 // To get here, everything must be fine, so just exit
199 EXIT_ERROR_UNINSTALL_PROTOCOL
:
200 // The following function could return an error message,
201 // however, to get here something must have gone wrong already,
202 // so preserve the original error, i.e. don't change
203 // the Status variable, even it fails to uninstall the protocol.
204 gBS
->UninstallMultipleProtocolInterfaces (
206 &gEfiGraphicsOutputProtocolGuid
,
207 &Instance
->Gop
, // Uninstall Graphics Output protocol
208 &gEfiDevicePathProtocolGuid
,
209 &Instance
->DevicePath
, // Uninstall device path
217 /** This function should be called
218 on Event: ExitBootServices
219 to free up memory, stop the driver
220 and uninstall the protocols
223 LcdGraphicsExitBootServicesEvent (
228 // By default, this PCD is FALSE. But if a platform starts a predefined OS
229 // that does not use a framebuffer then we might want to disable the display
230 // controller to avoid to display corrupted information on the screen.
231 if (FeaturePcdGet (PcdGopDisableOnExitBootServices
)) {
232 // Turn-off the Display controller
237 /** GraphicsOutput Protocol function, mapping to
238 EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode
242 LcdGraphicsQueryMode (
243 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
244 IN UINT32 ModeNumber
,
245 OUT UINTN
*SizeOfInfo
,
246 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
249 EFI_STATUS Status
= EFI_SUCCESS
;
250 LCD_INSTANCE
*Instance
;
252 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
254 // Setup the hardware if not already done
255 if (!mDisplayInitialized
) {
256 Status
= InitializeDisplay (Instance
);
257 if (EFI_ERROR (Status
)) {
263 if ((This
== NULL
) ||
265 (SizeOfInfo
== NULL
) ||
266 (ModeNumber
>= This
->Mode
->MaxMode
)) {
267 DEBUG ((DEBUG_ERROR
, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber
));
268 Status
= EFI_INVALID_PARAMETER
;
272 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
274 Status
= EFI_OUT_OF_RESOURCES
;
278 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
280 Status
= LcdPlatformQueryMode (ModeNumber
, *Info
);
281 if (EFI_ERROR (Status
)) {
289 /** GraphicsOutput Protocol function, mapping to
290 EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode
295 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
299 EFI_STATUS Status
= EFI_SUCCESS
;
300 EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour
;
301 LCD_INSTANCE
* Instance
;
304 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
306 // Setup the hardware if not already done
307 if (!mDisplayInitialized
) {
308 Status
= InitializeDisplay (Instance
);
309 if (EFI_ERROR (Status
)) {
314 // Check if this mode is supported
315 if (ModeNumber
>= This
->Mode
->MaxMode
) {
316 DEBUG ((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber
));
317 Status
= EFI_UNSUPPORTED
;
321 // Set the oscillator frequency to support the new mode
322 Status
= LcdPlatformSetMode (ModeNumber
);
323 if (EFI_ERROR (Status
)) {
324 Status
= EFI_DEVICE_ERROR
;
328 // Update the UEFI mode information
329 This
->Mode
->Mode
= ModeNumber
;
330 LcdPlatformQueryMode (ModeNumber
, &Instance
->ModeInfo
);
331 Status
= LcdPlatformGetBpp (ModeNumber
, &Bpp
);
332 if (EFI_ERROR (Status
)) {
333 DEBUG ((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status
));
336 This
->Mode
->FrameBufferSize
= Instance
->ModeInfo
.VerticalResolution
337 * Instance
->ModeInfo
.PixelsPerScanLine
338 * GetBytesPerPixel (Bpp
);
340 // Set the hardware to the new mode
341 Status
= LcdSetMode (ModeNumber
);
342 if (EFI_ERROR (Status
)) {
343 Status
= EFI_DEVICE_ERROR
;
347 // The UEFI spec requires that we now clear the visible portions of the
348 // output display to black.
350 // Set the fill colour to black
351 SetMem (&FillColour
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
353 // Fill the entire visible area with the same colour.
362 This
->Mode
->Info
->HorizontalResolution
,
363 This
->Mode
->Info
->VerticalResolution
,
377 case LCD_BITS_PER_PIXEL_24
:
380 case LCD_BITS_PER_PIXEL_16_565
:
381 case LCD_BITS_PER_PIXEL_16_555
:
382 case LCD_BITS_PER_PIXEL_12_444
:
385 case LCD_BITS_PER_PIXEL_8
:
386 case LCD_BITS_PER_PIXEL_4
:
387 case LCD_BITS_PER_PIXEL_2
:
388 case LCD_BITS_PER_PIXEL_1
: