3 Copyright (c) 2011-2018, 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 /** This file implements the Graphics Output protocol on ArmVersatileExpress
26 using the Lcd controller
34 BOOLEAN mDisplayInitialized
= FALSE
;
36 LCD_INSTANCE mLcdTemplate
= {
37 LCD_INSTANCE_SIGNATURE
,
41 0, // HorizontalResolution
42 0, // VerticalResolution
43 PixelBltOnly
, // PixelFormat
44 { 0 }, // PixelInformation
45 0, // PixelsPerScanLine
52 0, // FrameBufferBase;
56 LcdGraphicsQueryMode
, // QueryMode
57 LcdGraphicsSetMode
, // SetMode
58 LcdGraphicsBlt
, // Blt
64 HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
,
66 (UINT8
)(sizeof (VENDOR_DEVICE_PATH
)),
67 (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
,
78 sizeof (EFI_DEVICE_PATH_PROTOCOL
),
83 (EFI_EVENT
)NULL
// ExitBootServicesEvent
87 LcdInstanceContructor (
88 OUT LCD_INSTANCE
** NewInstance
91 LCD_INSTANCE
* Instance
;
93 Instance
= AllocateCopyPool (sizeof (LCD_INSTANCE
), &mLcdTemplate
);
94 if (Instance
== NULL
) {
95 return EFI_OUT_OF_RESOURCES
;
98 Instance
->Gop
.Mode
= &Instance
->Mode
;
99 Instance
->Gop
.Mode
->MaxMode
= LcdPlatformGetMaxMode ();
100 Instance
->Mode
.Info
= &Instance
->ModeInfo
;
102 *NewInstance
= Instance
;
107 // Function Definitions
112 IN LCD_INSTANCE
* Instance
115 EFI_STATUS Status
= EFI_SUCCESS
;
116 EFI_PHYSICAL_ADDRESS VramBaseAddress
;
119 Status
= LcdPlatformGetVram (&VramBaseAddress
, &VramSize
);
120 if (EFI_ERROR (Status
)) {
125 Status
= LcdInitialize (VramBaseAddress
);
126 if (EFI_ERROR (Status
)) {
127 goto EXIT_ERROR_LCD_SHUTDOWN
;
130 Status
= LcdPlatformInitializeDisplay (Instance
->Handle
);
131 if (EFI_ERROR (Status
)) {
132 goto EXIT_ERROR_LCD_SHUTDOWN
;
135 // Setup all the relevant mode information
136 Instance
->Gop
.Mode
->SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
137 Instance
->Gop
.Mode
->FrameBufferBase
= VramBaseAddress
;
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
));
156 LcdGraphicsOutputDxeInitialize (
157 IN EFI_HANDLE ImageHandle
,
158 IN EFI_SYSTEM_TABLE
*SystemTable
161 EFI_STATUS Status
= EFI_SUCCESS
;
162 LCD_INSTANCE
* Instance
;
164 Status
= LcdIdentify ();
165 if (EFI_ERROR (Status
)) {
169 Status
= LcdInstanceContructor (&Instance
);
170 if (EFI_ERROR (Status
)) {
174 // Install the Graphics Output Protocol and the Device Path
175 Status
= gBS
->InstallMultipleProtocolInterfaces (
177 &gEfiGraphicsOutputProtocolGuid
,
179 &gEfiDevicePathProtocolGuid
,
180 &Instance
->DevicePath
,
184 if (EFI_ERROR (Status
)) {
185 DEBUG ((DEBUG_ERROR
, "LcdGraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status
));
189 // Register for an ExitBootServicesEvent
190 // When ExitBootServices starts, this function will make sure that the
191 // graphics driver shuts down properly, i.e. it will free up all
192 // allocated memory and perform any necessary hardware re-configuration.
193 Status
= gBS
->CreateEvent (
194 EVT_SIGNAL_EXIT_BOOT_SERVICES
,
196 LcdGraphicsExitBootServicesEvent
,
198 &Instance
->ExitBootServicesEvent
201 if (EFI_ERROR (Status
)) {
202 DEBUG ((DEBUG_ERROR
, "LcdGraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status
));
203 goto EXIT_ERROR_UNINSTALL_PROTOCOL
;
206 // To get here, everything must be fine, so just exit
209 EXIT_ERROR_UNINSTALL_PROTOCOL
:
210 // The following function could return an error message,
211 // however, to get here something must have gone wrong already,
212 // so preserve the original error, i.e. don't change
213 // the Status variable, even it fails to uninstall the protocol.
214 gBS
->UninstallMultipleProtocolInterfaces (
216 &gEfiGraphicsOutputProtocolGuid
,
217 &Instance
->Gop
, // Uninstall Graphics Output protocol
218 &gEfiDevicePathProtocolGuid
,
219 &Instance
->DevicePath
, // Uninstall device path
227 /** This function should be called
228 on Event: ExitBootServices
229 to free up memory, stop the driver
230 and uninstall the protocols
233 LcdGraphicsExitBootServicesEvent (
238 // By default, this PCD is FALSE. But if a platform starts a predefined OS
239 // that does not use a framebuffer then we might want to disable the display
240 // controller to avoid to display corrupted information on the screen.
241 if (FeaturePcdGet (PcdGopDisableOnExitBootServices
)) {
242 // Turn-off the Display controller
247 /** GraphicsOutput Protocol function, mapping to
248 EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode
252 LcdGraphicsQueryMode (
253 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
254 IN UINT32 ModeNumber
,
255 OUT UINTN
*SizeOfInfo
,
256 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
259 EFI_STATUS Status
= EFI_SUCCESS
;
260 LCD_INSTANCE
*Instance
;
262 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
264 // Setup the hardware if not already done
265 if (!mDisplayInitialized
) {
266 Status
= InitializeDisplay (Instance
);
267 if (EFI_ERROR (Status
)) {
273 if ((This
== NULL
) ||
275 (SizeOfInfo
== NULL
) ||
276 (ModeNumber
>= This
->Mode
->MaxMode
)) {
277 DEBUG ((DEBUG_ERROR
, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber
));
278 Status
= EFI_INVALID_PARAMETER
;
282 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
284 Status
= EFI_OUT_OF_RESOURCES
;
288 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
290 Status
= LcdPlatformQueryMode (ModeNumber
, *Info
);
291 if (EFI_ERROR (Status
)) {
299 /** GraphicsOutput Protocol function, mapping to
300 EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode
305 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
309 EFI_STATUS Status
= EFI_SUCCESS
;
310 EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour
;
311 LCD_INSTANCE
* Instance
;
314 Instance
= LCD_INSTANCE_FROM_GOP_THIS (This
);
316 // Setup the hardware if not already done
317 if (!mDisplayInitialized
) {
318 Status
= InitializeDisplay (Instance
);
319 if (EFI_ERROR (Status
)) {
324 // Check if this mode is supported
325 if (ModeNumber
>= This
->Mode
->MaxMode
) {
326 DEBUG ((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber
));
327 Status
= EFI_UNSUPPORTED
;
331 // Set the oscillator frequency to support the new mode
332 Status
= LcdPlatformSetMode (ModeNumber
);
333 if (EFI_ERROR (Status
)) {
334 Status
= EFI_DEVICE_ERROR
;
338 // Update the UEFI mode information
339 This
->Mode
->Mode
= ModeNumber
;
340 LcdPlatformQueryMode (ModeNumber
, &Instance
->ModeInfo
);
341 Status
= LcdPlatformGetBpp (ModeNumber
, &Bpp
);
342 if (EFI_ERROR (Status
)) {
343 DEBUG ((DEBUG_ERROR
, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status
));
346 This
->Mode
->FrameBufferSize
= Instance
->ModeInfo
.VerticalResolution
347 * Instance
->ModeInfo
.PixelsPerScanLine
348 * GetBytesPerPixel (Bpp
);
350 // Set the hardware to the new mode
351 Status
= LcdSetMode (ModeNumber
);
352 if (EFI_ERROR (Status
)) {
353 Status
= EFI_DEVICE_ERROR
;
357 // The UEFI spec requires that we now clear the visible portions of the
358 // output display to black.
360 // Set the fill colour to black
361 SetMem (&FillColour
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
363 // Fill the entire visible area with the same colour.
372 This
->Mode
->Info
->HorizontalResolution
,
373 This
->Mode
->Info
->VerticalResolution
,
387 case LCD_BITS_PER_PIXEL_24
:
390 case LCD_BITS_PER_PIXEL_16_565
:
391 case LCD_BITS_PER_PIXEL_16_555
:
392 case LCD_BITS_PER_PIXEL_12_444
:
395 case LCD_BITS_PER_PIXEL_8
:
396 case LCD_BITS_PER_PIXEL_4
:
397 case LCD_BITS_PER_PIXEL_2
:
398 case LCD_BITS_PER_PIXEL_1
: