3 Copyright (c) 2011, 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
)),
68 (UINT8
) ((sizeof(VENDOR_DEVICE_PATH
)) >> 8),
70 // Hardware Device Path for Lcd
71 EFI_CALLER_ID_GUID
// Use the driver's GUID
76 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
77 sizeof(EFI_DEVICE_PATH_PROTOCOL
),
81 (EFI_EVENT
) NULL
// ExitBootServicesEvent
85 LcdInstanceContructor (
86 OUT LCD_INSTANCE
** NewInstance
89 LCD_INSTANCE
* Instance
;
91 Instance
= AllocateCopyPool (sizeof(LCD_INSTANCE
), &mLcdTemplate
);
92 if (Instance
== NULL
) {
93 return EFI_OUT_OF_RESOURCES
;
96 Instance
->Gop
.Mode
= &Instance
->Mode
;
97 Instance
->Gop
.Mode
->MaxMode
= LcdPlatformGetMaxMode ();
98 Instance
->Mode
.Info
= &Instance
->ModeInfo
;
100 *NewInstance
= Instance
;
105 // Function Definitions
110 IN LCD_INSTANCE
* Instance
113 EFI_STATUS Status
= EFI_SUCCESS
;
114 EFI_PHYSICAL_ADDRESS VramBaseAddress
;
117 Status
= LcdPlatformGetVram (&VramBaseAddress
, &VramSize
);
118 if (EFI_ERROR(Status
)) {
123 Status
= LcdInitialize (VramBaseAddress
);
124 if (EFI_ERROR(Status
)) {
125 goto EXIT_ERROR_LCD_SHUTDOWN
;
128 Status
= LcdPlatformInitializeDisplay (Instance
->Handle
);
129 if (EFI_ERROR(Status
)) {
130 goto EXIT_ERROR_LCD_SHUTDOWN
;
133 // Setup all the relevant mode information
134 Instance
->Gop
.Mode
->SizeOfInfo
= sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
135 Instance
->Gop
.Mode
->FrameBufferBase
= VramBaseAddress
;
137 // Set the flag before changing the mode, to avoid infinite loops
138 mDisplayInitialized
= TRUE
;
140 // All is ok, so don't deal with any errors
143 EXIT_ERROR_LCD_SHUTDOWN
:
144 DEBUG((DEBUG_ERROR
, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status
));
153 LcdGraphicsOutputDxeInitialize (
154 IN EFI_HANDLE ImageHandle
,
155 IN EFI_SYSTEM_TABLE
*SystemTable
158 EFI_STATUS Status
= EFI_SUCCESS
;
159 LCD_INSTANCE
* Instance
;
161 Status
= LcdInstanceContructor (&Instance
);
162 if (EFI_ERROR(Status
)) {
166 // Install the Graphics Output Protocol and the Device Path
167 Status
= gBS
->InstallMultipleProtocolInterfaces(
169 &gEfiGraphicsOutputProtocolGuid
, &Instance
->Gop
,
170 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
,
174 if (EFI_ERROR(Status
)) {
175 DEBUG((DEBUG_ERROR
, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status
));
179 // Register for an ExitBootServicesEvent
180 // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,
181 // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.
182 Status
= gBS
->CreateEvent (
183 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
185 LcdGraphicsExitBootServicesEvent
, NULL
,
186 &Instance
->ExitBootServicesEvent
189 if (EFI_ERROR(Status
)) {
190 DEBUG((DEBUG_ERROR
, "GraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status
));
191 goto EXIT_ERROR_UNINSTALL_PROTOCOL
;
194 // To get here, everything must be fine, so just exit
197 EXIT_ERROR_UNINSTALL_PROTOCOL
:
198 /* The following function could return an error message,
199 * however, to get here something must have gone wrong already,
200 * so preserve the original error, i.e. don't change
201 * the Status variable, even it fails to uninstall the protocol.
203 gBS
->UninstallMultipleProtocolInterfaces (
205 &gEfiGraphicsOutputProtocolGuid
, &Instance
->Gop
, // Uninstall Graphics Output protocol
206 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
, // Uninstall device path
215 /***************************************
216 * This function should be called
217 * on Event: ExitBootServices
218 * to free up memory, stop the driver
219 * and uninstall the protocols
220 ***************************************/
222 LcdGraphicsExitBootServicesEvent (
227 // By default, this PCD is FALSE. But if a platform starts a predefined OS that
228 // does not use a framebuffer then we might want to disable the display controller
229 // to avoid to display corrupted information on the screen.
230 if (FeaturePcdGet (PcdGopDisableOnExitBootServices
)) {
231 // Turn-off the Display controller
236 /***************************************
237 * GraphicsOutput Protocol function, mapping to
238 * EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode
239 ***************************************/
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
) || (Info
== NULL
) || (SizeOfInfo
== NULL
) || (ModeNumber
>= This
->Mode
->MaxMode
) ) {
264 DEBUG((DEBUG_ERROR
, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber
));
265 Status
= EFI_INVALID_PARAMETER
;
269 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
271 Status
= EFI_OUT_OF_RESOURCES
;
275 *SizeOfInfo
= sizeof( EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
277 Status
= LcdPlatformQueryMode (ModeNumber
,*Info
);
278 if (EFI_ERROR(Status
)) {
286 /***************************************
287 * GraphicsOutput Protocol function, mapping to
288 * EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode
289 ***************************************/
293 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
297 EFI_STATUS Status
= EFI_SUCCESS
;
298 EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour
;
299 LCD_INSTANCE
* Instance
;
302 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
304 // Setup the hardware if not already done
305 if(!mDisplayInitialized
) {
306 Status
= InitializeDisplay (Instance
);
307 if (EFI_ERROR(Status
)) {
312 // Check if this mode is supported
313 if( ModeNumber
>= This
->Mode
->MaxMode
) {
314 DEBUG((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber
));
315 Status
= EFI_UNSUPPORTED
;
319 // Set the oscillator frequency to support the new mode
320 Status
= LcdPlatformSetMode (ModeNumber
);
321 if (EFI_ERROR(Status
)) {
322 Status
= EFI_DEVICE_ERROR
;
326 // Update the UEFI mode information
327 This
->Mode
->Mode
= ModeNumber
;
328 LcdPlatformQueryMode (ModeNumber
,&Instance
->ModeInfo
);
329 Status
= LcdPlatformGetBpp(ModeNumber
, &Bpp
);
330 if (EFI_ERROR(Status
)) {
331 DEBUG ((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status
));
334 This
->Mode
->FrameBufferSize
= Instance
->ModeInfo
.VerticalResolution
335 * Instance
->ModeInfo
.PixelsPerScanLine
336 * GetBytesPerPixel(Bpp
);
338 // Set the hardware to the new mode
339 Status
= LcdSetMode (ModeNumber
);
340 if (EFI_ERROR(Status
)) {
341 Status
= EFI_DEVICE_ERROR
;
345 // The UEFI spec requires that we now clear the visible portions of the output display to black.
347 // Set the fill colour to black
348 SetMem (&FillColour
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
350 // Fill the entire visible area with the same colour.
359 This
->Mode
->Info
->HorizontalResolution
,
360 This
->Mode
->Info
->VerticalResolution
,
373 case LCD_BITS_PER_PIXEL_24
:
376 case LCD_BITS_PER_PIXEL_16_565
:
377 case LCD_BITS_PER_PIXEL_16_555
:
378 case LCD_BITS_PER_PIXEL_12_444
:
381 case LCD_BITS_PER_PIXEL_8
:
382 case LCD_BITS_PER_PIXEL_4
:
383 case LCD_BITS_PER_PIXEL_2
:
384 case LCD_BITS_PER_PIXEL_1
: