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/DebugLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DevicePathLib.h>
19 #include <Library/UefiBootServicesTableLib.h>
20 #include <Library/UefiRuntimeServicesTableLib.h>
21 #include <Library/MemoryAllocationLib.h>
23 #include <Guid/GlobalVariable.h>
25 #include <ArmPlatform.h>
26 #include "LcdGraphicsOutputDxe.h"
28 /**********************************************************************
30 * This file implements the Graphics Output protocol on ArmVersatileExpress
31 * using the Lcd controller
33 **********************************************************************/
39 BOOLEAN mDisplayInitialized
= FALSE
;
41 LCD_INSTANCE mLcdTemplate
= {
42 LCD_INSTANCE_SIGNATURE
,
46 0, // HorizontalResolution
47 0, // VerticalResolution
48 PixelBltOnly
, // PixelFormat
49 0, // PixelInformation
50 0, // PixelsPerScanLine
57 0, // FrameBufferBase;
61 LcdGraphicsQueryMode
, // QueryMode
62 LcdGraphicsSetMode
, // SetMode
63 LcdGraphicsBlt
, // Blt
69 HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
,
70 (UINT8
) (sizeof(VENDOR_DEVICE_PATH
)),
71 (UINT8
) ((sizeof(VENDOR_DEVICE_PATH
)) >> 8),
73 // Hardware Device Path for Lcd
74 EFI_CALLER_ID_GUID
// Use the driver's GUID
79 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
80 sizeof(EFI_DEVICE_PATH_PROTOCOL
),
84 (EFI_EVENT
) NULL
// ExitBootServicesEvent
88 LcdInstanceContructor (
89 OUT LCD_INSTANCE
** NewInstance
92 LCD_INSTANCE
* Instance
;
94 Instance
= AllocateCopyPool (sizeof(LCD_INSTANCE
), &mLcdTemplate
);
95 if (Instance
== NULL
) {
96 return EFI_OUT_OF_RESOURCES
;
99 Instance
->Gop
.Mode
= &Instance
->Mode
;
100 Instance
->Gop
.Mode
->MaxMode
= LcdPlatformGetMaxMode ();
101 Instance
->Mode
.Info
= &Instance
->ModeInfo
;
103 *NewInstance
= Instance
;
108 // Function Definitions
113 IN LCD_INSTANCE
* Instance
116 EFI_STATUS Status
= EFI_SUCCESS
;
117 EFI_PHYSICAL_ADDRESS VramBaseAddress
;
120 Status
= LcdPlatformGetVram (&VramBaseAddress
, &VramSize
);
121 if (EFI_ERROR(Status
)) {
126 Status
= LcdInitialize (VramBaseAddress
);
127 if (EFI_ERROR(Status
)) {
128 goto EXIT_ERROR_LCD_SHUTDOWN
;
131 Status
= LcdPlatformInitializeDisplay ();
132 if (EFI_ERROR(Status
)) {
133 goto EXIT_ERROR_LCD_SHUTDOWN
;
136 // Setup all the relevant mode information
137 Instance
->Gop
.Mode
->SizeOfInfo
= sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
138 Instance
->Gop
.Mode
->FrameBufferBase
= VramBaseAddress
;
139 Instance
->Gop
.Mode
->FrameBufferSize
= VramSize
;
141 // Set the flag before changing the mode, to avoid infinite loops
142 mDisplayInitialized
= TRUE
;
144 // All is ok, so don't deal with any errors
147 EXIT_ERROR_LCD_SHUTDOWN
:
148 DEBUG((DEBUG_ERROR
, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status
));
157 LcdGraphicsOutputDxeInitialize (
158 IN EFI_HANDLE ImageHandle
,
159 IN EFI_SYSTEM_TABLE
*SystemTable
162 EFI_STATUS Status
= EFI_SUCCESS
;
163 LCD_INSTANCE
* Instance
;
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
, &Instance
->Gop
,
174 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
,
178 if (EFI_ERROR(Status
)) {
179 DEBUG((DEBUG_ERROR
, "GraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status
));
183 // Register for an ExitBootServicesEvent
184 // When ExitBootServices starts, this function here will make sure that the graphics driver will shut down properly,
185 // i.e. it will free up all allocated memory and perform any necessary hardware re-configuration.
186 Status
= gBS
->CreateEvent (
187 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
189 LcdGraphicsExitBootServicesEvent
, NULL
,
190 &Instance
->ExitBootServicesEvent
193 if (EFI_ERROR(Status
)) {
194 DEBUG((DEBUG_ERROR
, "GraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status
));
195 goto EXIT_ERROR_UNINSTALL_PROTOCOL
;
198 // To get here, everything must be fine, so just exit
201 EXIT_ERROR_UNINSTALL_PROTOCOL
:
202 /* The following function could return an error message,
203 * however, to get here something must have gone wrong already,
204 * so preserve the original error, i.e. don't change
205 * the Status variable, even it fails to uninstall the protocol.
207 gBS
->UninstallMultipleProtocolInterfaces (
209 &gEfiGraphicsOutputProtocolGuid
, &Instance
->Gop
, // Uninstall Graphics Output protocol
210 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
, // Uninstall device path
219 /***************************************
220 * This function should be called
221 * on Event: ExitBootServices
222 * to free up memory, stop the driver
223 * and uninstall the protocols
224 ***************************************/
226 LcdGraphicsExitBootServicesEvent (
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
;
299 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
301 // Setup the hardware if not already done
302 if(!mDisplayInitialized
) {
303 Status
= InitializeDisplay (Instance
);
304 if (EFI_ERROR(Status
)) {
309 // Check if this mode is supported
310 if( ModeNumber
>= This
->Mode
->MaxMode
) {
311 DEBUG((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber
));
312 Status
= EFI_UNSUPPORTED
;
316 // Set the oscillator frequency to support the new mode
317 Status
= LcdPlatformSetMode (ModeNumber
);
318 if (EFI_ERROR(Status
)) {
319 Status
= EFI_DEVICE_ERROR
;
323 // Update the UEFI mode information
324 This
->Mode
->Mode
= ModeNumber
;
325 LcdPlatformQueryMode (ModeNumber
,&Instance
->ModeInfo
);
327 // Set the hardware to the new mode
328 Status
= LcdSetMode (ModeNumber
);
329 if (EFI_ERROR(Status
)) {
330 Status
= EFI_DEVICE_ERROR
;
334 // The UEFI spec requires that we now clear the visible portions of the output display to black.
336 // Set the fill colour to black
337 SetMem (&FillColour
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
339 // Fill the entire visible area with the same colour.
348 This
->Mode
->Info
->HorizontalResolution
,
349 This
->Mode
->Info
->VerticalResolution
,
362 case LCD_BITS_PER_PIXEL_24
:
365 case LCD_BITS_PER_PIXEL_16_565
:
366 case LCD_BITS_PER_PIXEL_16_555
:
367 case LCD_BITS_PER_PIXEL_12_444
:
370 case LCD_BITS_PER_PIXEL_8
:
371 case LCD_BITS_PER_PIXEL_4
:
372 case LCD_BITS_PER_PIXEL_2
:
373 case LCD_BITS_PER_PIXEL_1
: