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/PcdLib.h>
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"
26 /**********************************************************************
28 * This file implements the Graphics Output protocol on ArmVersatileExpress
29 * using the Lcd controller
31 **********************************************************************/
37 BOOLEAN mDisplayInitialized
= FALSE
;
39 LCD_INSTANCE mLcdTemplate
= {
40 LCD_INSTANCE_SIGNATURE
,
44 0, // HorizontalResolution
45 0, // VerticalResolution
46 PixelBltOnly
, // PixelFormat
47 0, // PixelInformation
48 0, // PixelsPerScanLine
55 0, // FrameBufferBase;
59 LcdGraphicsQueryMode
, // QueryMode
60 LcdGraphicsSetMode
, // SetMode
61 LcdGraphicsBlt
, // Blt
67 HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
,
68 (UINT8
) (sizeof(VENDOR_DEVICE_PATH
)),
69 (UINT8
) ((sizeof(VENDOR_DEVICE_PATH
)) >> 8),
71 // Hardware Device Path for Lcd
72 EFI_CALLER_ID_GUID
// Use the driver's GUID
77 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
78 sizeof(EFI_DEVICE_PATH_PROTOCOL
),
82 (EFI_EVENT
) NULL
// ExitBootServicesEvent
86 LcdInstanceContructor (
87 OUT LCD_INSTANCE
** NewInstance
90 LCD_INSTANCE
* Instance
;
92 Instance
= AllocateCopyPool (sizeof(LCD_INSTANCE
), &mLcdTemplate
);
93 if (Instance
== NULL
) {
94 return EFI_OUT_OF_RESOURCES
;
97 Instance
->Gop
.Mode
= &Instance
->Mode
;
98 Instance
->Gop
.Mode
->MaxMode
= LcdPlatformGetMaxMode ();
99 Instance
->Mode
.Info
= &Instance
->ModeInfo
;
101 *NewInstance
= Instance
;
106 // Function Definitions
111 IN LCD_INSTANCE
* Instance
114 EFI_STATUS Status
= EFI_SUCCESS
;
115 EFI_PHYSICAL_ADDRESS VramBaseAddress
;
118 Status
= LcdPlatformGetVram (&VramBaseAddress
, &VramSize
);
119 if (EFI_ERROR(Status
)) {
124 Status
= LcdInitialize (VramBaseAddress
);
125 if (EFI_ERROR(Status
)) {
126 goto EXIT_ERROR_LCD_SHUTDOWN
;
129 Status
= LcdPlatformInitializeDisplay ();
130 if (EFI_ERROR(Status
)) {
131 goto EXIT_ERROR_LCD_SHUTDOWN
;
134 // Setup all the relevant mode information
135 Instance
->Gop
.Mode
->SizeOfInfo
= sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
136 Instance
->Gop
.Mode
->FrameBufferBase
= VramBaseAddress
;
137 Instance
->Gop
.Mode
->FrameBufferSize
= VramSize
;
139 // Set the flag before changing the mode, to avoid infinite loops
140 mDisplayInitialized
= TRUE
;
142 // All is ok, so don't deal with any errors
145 EXIT_ERROR_LCD_SHUTDOWN
:
146 DEBUG((DEBUG_ERROR
, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status
));
155 LcdGraphicsOutputDxeInitialize (
156 IN EFI_HANDLE ImageHandle
,
157 IN EFI_SYSTEM_TABLE
*SystemTable
160 EFI_STATUS Status
= EFI_SUCCESS
;
161 LCD_INSTANCE
* Instance
;
163 Status
= LcdInstanceContructor (&Instance
);
164 if (EFI_ERROR(Status
)) {
168 // Install the Graphics Output Protocol and the Device Path
169 Status
= gBS
->InstallMultipleProtocolInterfaces(
171 &gEfiGraphicsOutputProtocolGuid
, &Instance
->Gop
,
172 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
,
176 if (EFI_ERROR(Status
)) {
177 DEBUG((DEBUG_ERROR
, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status
));
181 // Register for an ExitBootServicesEvent
182 // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,
183 // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.
184 Status
= gBS
->CreateEvent (
185 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
187 LcdGraphicsExitBootServicesEvent
, NULL
,
188 &Instance
->ExitBootServicesEvent
191 if (EFI_ERROR(Status
)) {
192 DEBUG((DEBUG_ERROR
, "GraphicsOutputDxeInitialize: 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.
205 gBS
->UninstallMultipleProtocolInterfaces (
207 &gEfiGraphicsOutputProtocolGuid
, &Instance
->Gop
, // Uninstall Graphics Output protocol
208 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
, // Uninstall device path
217 /***************************************
218 * This function should be called
219 * on Event: ExitBootServices
220 * to free up memory, stop the driver
221 * and uninstall the protocols
222 ***************************************/
224 LcdGraphicsExitBootServicesEvent (
232 /***************************************
233 * GraphicsOutput Protocol function, mapping to
234 * EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode
235 ***************************************/
238 LcdGraphicsQueryMode (
239 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
240 IN UINT32 ModeNumber
,
241 OUT UINTN
*SizeOfInfo
,
242 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
245 EFI_STATUS Status
= EFI_SUCCESS
;
246 LCD_INSTANCE
*Instance
;
248 Instance
= LCD_INSTANCE_FROM_GOP_THIS(This
);
250 // Setup the hardware if not already done
251 if( !mDisplayInitialized
) {
252 Status
= InitializeDisplay(Instance
);
253 if (EFI_ERROR(Status
)) {
259 if ( (This
== NULL
) || (Info
== NULL
) || (SizeOfInfo
== NULL
) || (ModeNumber
>= This
->Mode
->MaxMode
) ) {
260 DEBUG((DEBUG_ERROR
, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber
));
261 Status
= EFI_INVALID_PARAMETER
;
265 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
267 Status
= EFI_OUT_OF_RESOURCES
;
271 *SizeOfInfo
= sizeof( EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
273 Status
= LcdPlatformQueryMode (ModeNumber
,*Info
);
274 if (EFI_ERROR(Status
)) {
282 /***************************************
283 * GraphicsOutput Protocol function, mapping to
284 * EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode
285 ***************************************/
289 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
293 EFI_STATUS Status
= EFI_SUCCESS
;
294 EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour
;
295 LCD_INSTANCE
* Instance
;
297 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
299 // Setup the hardware if not already done
300 if(!mDisplayInitialized
) {
301 Status
= InitializeDisplay (Instance
);
302 if (EFI_ERROR(Status
)) {
307 // Check if this mode is supported
308 if( ModeNumber
>= This
->Mode
->MaxMode
) {
309 DEBUG((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber
));
310 Status
= EFI_UNSUPPORTED
;
314 // Set the oscillator frequency to support the new mode
315 Status
= LcdPlatformSetMode (ModeNumber
);
316 if (EFI_ERROR(Status
)) {
317 Status
= EFI_DEVICE_ERROR
;
321 // Update the UEFI mode information
322 This
->Mode
->Mode
= ModeNumber
;
323 LcdPlatformQueryMode (ModeNumber
,&Instance
->ModeInfo
);
325 // Set the hardware to the new mode
326 Status
= LcdSetMode (ModeNumber
);
327 if (EFI_ERROR(Status
)) {
328 Status
= EFI_DEVICE_ERROR
;
332 // The UEFI spec requires that we now clear the visible portions of the output display to black.
334 // Set the fill colour to black
335 SetMem (&FillColour
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
337 // Fill the entire visible area with the same colour.
346 This
->Mode
->Info
->HorizontalResolution
,
347 This
->Mode
->Info
->VerticalResolution
,
360 case LCD_BITS_PER_PIXEL_24
:
363 case LCD_BITS_PER_PIXEL_16_565
:
364 case LCD_BITS_PER_PIXEL_16_555
:
365 case LCD_BITS_PER_PIXEL_12_444
:
368 case LCD_BITS_PER_PIXEL_8
:
369 case LCD_BITS_PER_PIXEL_4
:
370 case LCD_BITS_PER_PIXEL_2
:
371 case LCD_BITS_PER_PIXEL_1
: