3 Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/DevicePathLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/UefiRuntimeServicesTableLib.h>
19 #include <Library/MemoryAllocationLib.h>
21 #include <Guid/GlobalVariable.h>
23 #include "LcdGraphicsOutputDxe.h"
25 /**********************************************************************
27 * This file implements the Graphics Output protocol on ArmVersatileExpress
28 * using the Lcd controller
30 **********************************************************************/
36 BOOLEAN mDisplayInitialized
= FALSE
;
38 LCD_INSTANCE mLcdTemplate
= {
39 LCD_INSTANCE_SIGNATURE
,
43 0, // HorizontalResolution
44 0, // VerticalResolution
45 PixelBltOnly
, // PixelFormat
46 { 0 }, // PixelInformation
47 0, // PixelsPerScanLine
54 0, // FrameBufferBase;
58 LcdGraphicsQueryMode
, // QueryMode
59 LcdGraphicsSetMode
, // SetMode
60 LcdGraphicsBlt
, // Blt
66 HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
,
67 { (UINT8
) (sizeof(VENDOR_DEVICE_PATH
)), (UINT8
) ((sizeof(VENDOR_DEVICE_PATH
)) >> 8) },
69 // Hardware Device Path for Lcd
70 EFI_CALLER_ID_GUID
// Use the driver's GUID
75 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
76 { sizeof(EFI_DEVICE_PATH_PROTOCOL
), 0 }
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
));
151 LcdGraphicsOutputDxeInitialize (
152 IN EFI_HANDLE ImageHandle
,
153 IN EFI_SYSTEM_TABLE
*SystemTable
156 EFI_STATUS Status
= EFI_SUCCESS
;
157 LCD_INSTANCE
* Instance
;
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
, &Instance
->Gop
,
168 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
,
172 if (EFI_ERROR(Status
)) {
173 DEBUG((DEBUG_ERROR
, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status
));
177 // Register for an ExitBootServicesEvent
178 // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,
179 // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.
180 Status
= gBS
->CreateEvent (
181 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
183 LcdGraphicsExitBootServicesEvent
, NULL
,
184 &Instance
->ExitBootServicesEvent
187 if (EFI_ERROR(Status
)) {
188 DEBUG((DEBUG_ERROR
, "GraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status
));
189 goto EXIT_ERROR_UNINSTALL_PROTOCOL
;
192 // To get here, everything must be fine, so just exit
195 EXIT_ERROR_UNINSTALL_PROTOCOL
:
196 /* The following function could return an error message,
197 * however, to get here something must have gone wrong already,
198 * so preserve the original error, i.e. don't change
199 * the Status variable, even it fails to uninstall the protocol.
201 gBS
->UninstallMultipleProtocolInterfaces (
203 &gEfiGraphicsOutputProtocolGuid
, &Instance
->Gop
, // Uninstall Graphics Output protocol
204 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
, // Uninstall device path
213 /***************************************
214 * This function should be called
215 * on Event: ExitBootServices
216 * to free up memory, stop the driver
217 * and uninstall the protocols
218 ***************************************/
220 LcdGraphicsExitBootServicesEvent (
225 // By default, this PCD is FALSE. But if a platform starts a predefined OS that
226 // does not use a framebuffer then we might want to disable the display controller
227 // to avoid to display corrupted information on the screen.
228 if (FeaturePcdGet (PcdGopDisableOnExitBootServices
)) {
229 // Turn-off the Display controller
234 /***************************************
235 * GraphicsOutput Protocol function, mapping to
236 * EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode
237 ***************************************/
240 LcdGraphicsQueryMode (
241 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
242 IN UINT32 ModeNumber
,
243 OUT UINTN
*SizeOfInfo
,
244 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
247 EFI_STATUS Status
= EFI_SUCCESS
;
248 LCD_INSTANCE
*Instance
;
250 Instance
= LCD_INSTANCE_FROM_GOP_THIS(This
);
252 // Setup the hardware if not already done
253 if( !mDisplayInitialized
) {
254 Status
= InitializeDisplay(Instance
);
255 if (EFI_ERROR(Status
)) {
261 if ( (This
== NULL
) || (Info
== NULL
) || (SizeOfInfo
== NULL
) || (ModeNumber
>= This
->Mode
->MaxMode
) ) {
262 DEBUG((DEBUG_ERROR
, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber
));
263 Status
= EFI_INVALID_PARAMETER
;
267 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
269 Status
= EFI_OUT_OF_RESOURCES
;
273 *SizeOfInfo
= sizeof( EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
275 Status
= LcdPlatformQueryMode (ModeNumber
,*Info
);
276 if (EFI_ERROR(Status
)) {
284 /***************************************
285 * GraphicsOutput Protocol function, mapping to
286 * EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode
287 ***************************************/
291 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
295 EFI_STATUS Status
= EFI_SUCCESS
;
296 EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour
;
297 LCD_INSTANCE
* Instance
;
300 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
302 // Setup the hardware if not already done
303 if(!mDisplayInitialized
) {
304 Status
= InitializeDisplay (Instance
);
305 if (EFI_ERROR(Status
)) {
310 // Check if this mode is supported
311 if( ModeNumber
>= This
->Mode
->MaxMode
) {
312 DEBUG((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber
));
313 Status
= EFI_UNSUPPORTED
;
317 // Set the oscillator frequency to support the new mode
318 Status
= LcdPlatformSetMode (ModeNumber
);
319 if (EFI_ERROR(Status
)) {
320 Status
= EFI_DEVICE_ERROR
;
324 // Update the UEFI mode information
325 This
->Mode
->Mode
= ModeNumber
;
326 LcdPlatformQueryMode (ModeNumber
,&Instance
->ModeInfo
);
327 Status
= LcdPlatformGetBpp(ModeNumber
, &Bpp
);
328 if (EFI_ERROR(Status
)) {
329 DEBUG ((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status
));
332 This
->Mode
->FrameBufferSize
= Instance
->ModeInfo
.VerticalResolution
333 * Instance
->ModeInfo
.PixelsPerScanLine
334 * GetBytesPerPixel(Bpp
);
336 // Set the hardware to the new mode
337 Status
= LcdSetMode (ModeNumber
);
338 if (EFI_ERROR(Status
)) {
339 Status
= EFI_DEVICE_ERROR
;
343 // The UEFI spec requires that we now clear the visible portions of the output display to black.
345 // Set the fill colour to black
346 SetMem (&FillColour
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
348 // Fill the entire visible area with the same colour.
357 This
->Mode
->Info
->HorizontalResolution
,
358 This
->Mode
->Info
->VerticalResolution
,
371 case LCD_BITS_PER_PIXEL_24
:
374 case LCD_BITS_PER_PIXEL_16_565
:
375 case LCD_BITS_PER_PIXEL_16_555
:
376 case LCD_BITS_PER_PIXEL_12_444
:
379 case LCD_BITS_PER_PIXEL_8
:
380 case LCD_BITS_PER_PIXEL_4
:
381 case LCD_BITS_PER_PIXEL_2
:
382 case LCD_BITS_PER_PIXEL_1
: