]>
Commit | Line | Data |
---|---|---|
1e57a462 | 1 | /** @file\r |
4257dfaa | 2 | This file implements the Graphics Output protocol for Arm platforms\r |
1e57a462 | 3 | \r |
eb97f138 | 4 | Copyright (c) 2011 - 2020, Arm Limited. All rights reserved.<BR>\r |
f4dfad05 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
1e57a462 | 6 | \r |
b1b69d26 | 7 | **/\r |
1e57a462 | 8 | \r |
9 | #include <PiDxe.h>\r | |
10 | #include <Library/BaseMemoryLib.h>\r | |
11 | #include <Library/DevicePathLib.h>\r | |
12 | #include <Library/UefiBootServicesTableLib.h>\r | |
13 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
14 | #include <Library/MemoryAllocationLib.h>\r | |
15 | \r | |
16 | #include <Guid/GlobalVariable.h>\r | |
17 | \r | |
18 | #include "LcdGraphicsOutputDxe.h"\r | |
19 | \r | |
1e57a462 | 20 | //\r |
21 | // Global variables\r | |
22 | //\r | |
23 | \r | |
40b0b23e | 24 | BOOLEAN mDisplayInitialized = FALSE;\r |
1e57a462 | 25 | \r |
40b0b23e | 26 | LCD_INSTANCE mLcdTemplate = {\r |
1e57a462 | 27 | LCD_INSTANCE_SIGNATURE,\r |
40b0b23e MK |
28 | NULL, // Handle\r |
29 | { // ModeInfo\r | |
30 | 0, // Version\r | |
31 | 0, // HorizontalResolution\r | |
32 | 0, // VerticalResolution\r | |
1e57a462 | 33 | PixelBltOnly, // PixelFormat\r |
40b0b23e MK |
34 | { 0 }, // PixelInformation\r |
35 | 0, // PixelsPerScanLine\r | |
1e57a462 | 36 | },\r |
37 | {\r | |
40b0b23e MK |
38 | 0, // MaxMode;\r |
39 | 0, // Mode;\r | |
1e57a462 | 40 | NULL, // Info;\r |
40b0b23e MK |
41 | 0, // SizeOfInfo;\r |
42 | 0, // FrameBufferBase;\r | |
43 | 0 // FrameBufferSize;\r | |
1e57a462 | 44 | },\r |
40b0b23e MK |
45 | { // Gop\r |
46 | LcdGraphicsQueryMode, // QueryMode\r | |
47 | LcdGraphicsSetMode, // SetMode\r | |
48 | LcdGraphicsBlt, // Blt\r | |
49 | NULL // *Mode\r | |
1e57a462 | 50 | },\r |
51 | { // DevicePath\r | |
52 | {\r | |
53 | {\r | |
40b0b23e | 54 | HARDWARE_DEVICE_PATH, HW_VENDOR_DP,\r |
b1b69d26 GP |
55 | {\r |
56 | (UINT8)(sizeof (VENDOR_DEVICE_PATH)),\r | |
57 | (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r | |
58 | },\r | |
1e57a462 | 59 | },\r |
60 | // Hardware Device Path for Lcd\r | |
61 | EFI_CALLER_ID_GUID // Use the driver's GUID\r | |
62 | },\r | |
63 | \r | |
64 | {\r | |
65 | END_DEVICE_PATH_TYPE,\r | |
66 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
b1b69d26 GP |
67 | {\r |
68 | sizeof (EFI_DEVICE_PATH_PROTOCOL),\r | |
69 | 0\r | |
70 | }\r | |
1e57a462 | 71 | }\r |
72 | },\r | |
b1b69d26 | 73 | (EFI_EVENT)NULL // ExitBootServicesEvent\r |
1e57a462 | 74 | };\r |
75 | \r | |
76 | EFI_STATUS\r | |
77 | LcdInstanceContructor (\r | |
40b0b23e | 78 | OUT LCD_INSTANCE **NewInstance\r |
1e57a462 | 79 | )\r |
80 | {\r | |
40b0b23e | 81 | LCD_INSTANCE *Instance;\r |
1e57a462 | 82 | \r |
b1b69d26 | 83 | Instance = AllocateCopyPool (sizeof (LCD_INSTANCE), &mLcdTemplate);\r |
1e57a462 | 84 | if (Instance == NULL) {\r |
85 | return EFI_OUT_OF_RESOURCES;\r | |
86 | }\r | |
87 | \r | |
88 | Instance->Gop.Mode = &Instance->Mode;\r | |
89 | Instance->Gop.Mode->MaxMode = LcdPlatformGetMaxMode ();\r | |
90 | Instance->Mode.Info = &Instance->ModeInfo;\r | |
91 | \r | |
92 | *NewInstance = Instance;\r | |
93 | return EFI_SUCCESS;\r | |
94 | }\r | |
95 | \r | |
96 | //\r | |
97 | // Function Definitions\r | |
98 | //\r | |
99 | \r | |
100 | EFI_STATUS\r | |
101 | InitializeDisplay (\r | |
40b0b23e | 102 | IN LCD_INSTANCE *Instance\r |
1e57a462 | 103 | )\r |
104 | {\r | |
40b0b23e MK |
105 | EFI_STATUS Status;\r |
106 | EFI_PHYSICAL_ADDRESS VramBaseAddress;\r | |
107 | UINTN VramSize;\r | |
1e57a462 | 108 | \r |
109 | Status = LcdPlatformGetVram (&VramBaseAddress, &VramSize);\r | |
b1b69d26 | 110 | if (EFI_ERROR (Status)) {\r |
1e57a462 | 111 | return Status;\r |
112 | }\r | |
113 | \r | |
114 | // Setup the LCD\r | |
115 | Status = LcdInitialize (VramBaseAddress);\r | |
b1b69d26 | 116 | if (EFI_ERROR (Status)) {\r |
1e57a462 | 117 | goto EXIT_ERROR_LCD_SHUTDOWN;\r |
118 | }\r | |
119 | \r | |
120 | Status = LcdPlatformInitializeDisplay (Instance->Handle);\r | |
b1b69d26 | 121 | if (EFI_ERROR (Status)) {\r |
1e57a462 | 122 | goto EXIT_ERROR_LCD_SHUTDOWN;\r |
123 | }\r | |
124 | \r | |
125 | // Setup all the relevant mode information\r | |
b1b69d26 | 126 | Instance->Gop.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r |
1e57a462 | 127 | Instance->Gop.Mode->FrameBufferBase = VramBaseAddress;\r |
1e57a462 | 128 | \r |
129 | // Set the flag before changing the mode, to avoid infinite loops\r | |
130 | mDisplayInitialized = TRUE;\r | |
131 | \r | |
132 | // All is ok, so don't deal with any errors\r | |
133 | goto EXIT;\r | |
134 | \r | |
135 | EXIT_ERROR_LCD_SHUTDOWN:\r | |
b1b69d26 GP |
136 | DEBUG ((DEBUG_ERROR, "InitializeDisplay: ERROR - Can not initialise the display. Exit Status=%r\n", Status));\r |
137 | \r | |
1e57a462 | 138 | LcdShutdown ();\r |
139 | \r | |
140 | EXIT:\r | |
141 | return Status;\r | |
142 | }\r | |
143 | \r | |
144 | EFI_STATUS\r | |
145 | EFIAPI\r | |
146 | LcdGraphicsOutputDxeInitialize (\r | |
40b0b23e MK |
147 | IN EFI_HANDLE ImageHandle,\r |
148 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1e57a462 | 149 | )\r |
150 | {\r | |
40b0b23e MK |
151 | EFI_STATUS Status;\r |
152 | LCD_INSTANCE *Instance;\r | |
1e57a462 | 153 | \r |
9dc94d98 | 154 | Status = LcdIdentify ();\r |
b1b69d26 | 155 | if (EFI_ERROR (Status)) {\r |
9dc94d98 AB |
156 | goto EXIT;\r |
157 | }\r | |
158 | \r | |
1e57a462 | 159 | Status = LcdInstanceContructor (&Instance);\r |
b1b69d26 | 160 | if (EFI_ERROR (Status)) {\r |
1e57a462 | 161 | goto EXIT;\r |
162 | }\r | |
163 | \r | |
91c38d4e | 164 | // Install the Graphics Output Protocol and the Device Path\r |
b1b69d26 GP |
165 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
166 | &Instance->Handle,\r | |
167 | &gEfiGraphicsOutputProtocolGuid,\r | |
168 | &Instance->Gop,\r | |
169 | &gEfiDevicePathProtocolGuid,\r | |
170 | &Instance->DevicePath,\r | |
171 | NULL\r | |
172 | );\r | |
173 | \r | |
174 | if (EFI_ERROR (Status)) {\r | |
175 | DEBUG ((DEBUG_ERROR, "LcdGraphicsOutputDxeInitialize: Can not install the protocol. Exit Status=%r\n", Status));\r | |
91c38d4e RC |
176 | goto EXIT;\r |
177 | }\r | |
178 | \r | |
179 | // Register for an ExitBootServicesEvent\r | |
b1b69d26 GP |
180 | // When ExitBootServices starts, this function will make sure that the\r |
181 | // graphics driver shuts down properly, i.e. it will free up all\r | |
182 | // allocated memory and perform any necessary hardware re-configuration.\r | |
91c38d4e | 183 | Status = gBS->CreateEvent (\r |
b1b69d26 GP |
184 | EVT_SIGNAL_EXIT_BOOT_SERVICES,\r |
185 | TPL_NOTIFY,\r | |
186 | LcdGraphicsExitBootServicesEvent,\r | |
187 | NULL,\r | |
188 | &Instance->ExitBootServicesEvent\r | |
189 | );\r | |
190 | \r | |
191 | if (EFI_ERROR (Status)) {\r | |
192 | DEBUG ((DEBUG_ERROR, "LcdGraphicsOutputDxeInitialize: Can not install the ExitBootServicesEvent handler. Exit Status=%r\n", Status));\r | |
91c38d4e RC |
193 | goto EXIT_ERROR_UNINSTALL_PROTOCOL;\r |
194 | }\r | |
195 | \r | |
196 | // To get here, everything must be fine, so just exit\r | |
197 | goto EXIT;\r | |
1e57a462 | 198 | \r |
199 | EXIT_ERROR_UNINSTALL_PROTOCOL:\r | |
b1b69d26 GP |
200 | // The following function could return an error message,\r |
201 | // however, to get here something must have gone wrong already,\r | |
202 | // so preserve the original error, i.e. don't change\r | |
203 | // the Status variable, even it fails to uninstall the protocol.\r | |
91c38d4e | 204 | gBS->UninstallMultipleProtocolInterfaces (\r |
b1b69d26 GP |
205 | Instance->Handle,\r |
206 | &gEfiGraphicsOutputProtocolGuid,\r | |
207 | &Instance->Gop, // Uninstall Graphics Output protocol\r | |
208 | &gEfiDevicePathProtocolGuid,\r | |
209 | &Instance->DevicePath, // Uninstall device path\r | |
210 | NULL\r | |
211 | );\r | |
1e57a462 | 212 | \r |
213 | EXIT:\r | |
91c38d4e | 214 | return Status;\r |
1e57a462 | 215 | }\r |
216 | \r | |
b1b69d26 GP |
217 | /** This function should be called\r |
218 | on Event: ExitBootServices\r | |
219 | to free up memory, stop the driver\r | |
220 | and uninstall the protocols\r | |
221 | **/\r | |
1e57a462 | 222 | VOID\r |
223 | LcdGraphicsExitBootServicesEvent (\r | |
224 | IN EFI_EVENT Event,\r | |
225 | IN VOID *Context\r | |
226 | )\r | |
227 | {\r | |
b1b69d26 GP |
228 | // By default, this PCD is FALSE. But if a platform starts a predefined OS\r |
229 | // that does not use a framebuffer then we might want to disable the display\r | |
230 | // controller to avoid to display corrupted information on the screen.\r | |
d8c4bb9a OM |
231 | if (FeaturePcdGet (PcdGopDisableOnExitBootServices)) {\r |
232 | // Turn-off the Display controller\r | |
233 | LcdShutdown ();\r | |
234 | }\r | |
1e57a462 | 235 | }\r |
236 | \r | |
b1b69d26 GP |
237 | /** GraphicsOutput Protocol function, mapping to\r |
238 | EFI_GRAPHICS_OUTPUT_PROTOCOL.QueryMode\r | |
239 | **/\r | |
1e57a462 | 240 | EFI_STATUS\r |
241 | EFIAPI\r | |
242 | LcdGraphicsQueryMode (\r | |
40b0b23e MK |
243 | IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,\r |
244 | IN UINT32 ModeNumber,\r | |
245 | OUT UINTN *SizeOfInfo,\r | |
246 | OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info\r | |
91c38d4e | 247 | )\r |
1e57a462 | 248 | {\r |
40b0b23e MK |
249 | EFI_STATUS Status;\r |
250 | LCD_INSTANCE *Instance;\r | |
1e57a462 | 251 | \r |
b1b69d26 | 252 | Instance = LCD_INSTANCE_FROM_GOP_THIS (This);\r |
1e57a462 | 253 | \r |
254 | // Setup the hardware if not already done\r | |
b1b69d26 GP |
255 | if (!mDisplayInitialized) {\r |
256 | Status = InitializeDisplay (Instance);\r | |
257 | if (EFI_ERROR (Status)) {\r | |
1e57a462 | 258 | goto EXIT;\r |
259 | }\r | |
260 | }\r | |
261 | \r | |
91c38d4e | 262 | // Error checking\r |
b1b69d26 GP |
263 | if ((This == NULL) ||\r |
264 | (Info == NULL) ||\r | |
265 | (SizeOfInfo == NULL) ||\r | |
40b0b23e MK |
266 | (ModeNumber >= This->Mode->MaxMode))\r |
267 | {\r | |
b1b69d26 | 268 | DEBUG ((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber));\r |
91c38d4e RC |
269 | Status = EFI_INVALID_PARAMETER;\r |
270 | goto EXIT;\r | |
271 | }\r | |
1e57a462 | 272 | \r |
91c38d4e | 273 | *Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));\r |
1e57a462 | 274 | if (*Info == NULL) {\r |
275 | Status = EFI_OUT_OF_RESOURCES;\r | |
276 | goto EXIT;\r | |
277 | }\r | |
278 | \r | |
b1b69d26 | 279 | *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);\r |
1e57a462 | 280 | \r |
b1b69d26 GP |
281 | Status = LcdPlatformQueryMode (ModeNumber, *Info);\r |
282 | if (EFI_ERROR (Status)) {\r | |
283 | FreePool (*Info);\r | |
1e57a462 | 284 | }\r |
285 | \r | |
286 | EXIT:\r | |
91c38d4e | 287 | return Status;\r |
1e57a462 | 288 | }\r |
289 | \r | |
b1b69d26 GP |
290 | /** GraphicsOutput Protocol function, mapping to\r |
291 | EFI_GRAPHICS_OUTPUT_PROTOCOL.SetMode\r | |
292 | **/\r | |
1e57a462 | 293 | EFI_STATUS\r |
294 | EFIAPI\r | |
295 | LcdGraphicsSetMode (\r | |
40b0b23e MK |
296 | IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,\r |
297 | IN UINT32 ModeNumber\r | |
91c38d4e | 298 | )\r |
1e57a462 | 299 | {\r |
40b0b23e MK |
300 | EFI_STATUS Status;\r |
301 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour;\r | |
302 | LCD_INSTANCE *Instance;\r | |
303 | LCD_BPP Bpp;\r | |
1e57a462 | 304 | \r |
91c38d4e | 305 | Instance = LCD_INSTANCE_FROM_GOP_THIS (This);\r |
1e57a462 | 306 | \r |
307 | // Setup the hardware if not already done\r | |
b1b69d26 | 308 | if (!mDisplayInitialized) {\r |
1e57a462 | 309 | Status = InitializeDisplay (Instance);\r |
b1b69d26 | 310 | if (EFI_ERROR (Status)) {\r |
1e57a462 | 311 | goto EXIT;\r |
312 | }\r | |
313 | }\r | |
314 | \r | |
315 | // Check if this mode is supported\r | |
b1b69d26 GP |
316 | if (ModeNumber >= This->Mode->MaxMode) {\r |
317 | DEBUG ((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Unsupported mode number %d .\n", ModeNumber));\r | |
1e57a462 | 318 | Status = EFI_UNSUPPORTED;\r |
319 | goto EXIT;\r | |
320 | }\r | |
321 | \r | |
91c38d4e | 322 | // Set the oscillator frequency to support the new mode\r |
1e57a462 | 323 | Status = LcdPlatformSetMode (ModeNumber);\r |
b1b69d26 | 324 | if (EFI_ERROR (Status)) {\r |
1e57a462 | 325 | Status = EFI_DEVICE_ERROR;\r |
326 | goto EXIT;\r | |
327 | }\r | |
328 | \r | |
91c38d4e RC |
329 | // Update the UEFI mode information\r |
330 | This->Mode->Mode = ModeNumber;\r | |
b1b69d26 GP |
331 | LcdPlatformQueryMode (ModeNumber, &Instance->ModeInfo);\r |
332 | Status = LcdPlatformGetBpp (ModeNumber, &Bpp);\r | |
333 | if (EFI_ERROR (Status)) {\r | |
91c38d4e RC |
334 | DEBUG ((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status));\r |
335 | goto EXIT;\r | |
336 | }\r | |
40b0b23e | 337 | \r |
91c38d4e | 338 | This->Mode->FrameBufferSize = Instance->ModeInfo.VerticalResolution\r |
40b0b23e MK |
339 | * Instance->ModeInfo.PixelsPerScanLine\r |
340 | * GetBytesPerPixel (Bpp);\r | |
1e57a462 | 341 | \r |
342 | // Set the hardware to the new mode\r | |
91c38d4e | 343 | Status = LcdSetMode (ModeNumber);\r |
b1b69d26 | 344 | if (EFI_ERROR (Status)) {\r |
1e57a462 | 345 | Status = EFI_DEVICE_ERROR;\r |
346 | goto EXIT;\r | |
347 | }\r | |
348 | \r | |
b1b69d26 GP |
349 | // The UEFI spec requires that we now clear the visible portions of the\r |
350 | // output display to black.\r | |
1e57a462 | 351 | \r |
352 | // Set the fill colour to black\r | |
353 | SetMem (&FillColour, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r | |
354 | \r | |
355 | // Fill the entire visible area with the same colour.\r | |
356 | Status = This->Blt (\r | |
40b0b23e MK |
357 | This,\r |
358 | &FillColour,\r | |
359 | EfiBltVideoFill,\r | |
360 | 0,\r | |
361 | 0,\r | |
362 | 0,\r | |
363 | 0,\r | |
364 | This->Mode->Info->HorizontalResolution,\r | |
365 | This->Mode->Info->VerticalResolution,\r | |
366 | 0\r | |
367 | );\r | |
1e57a462 | 368 | \r |
369 | EXIT:\r | |
91c38d4e | 370 | return Status;\r |
1e57a462 | 371 | }\r |
372 | \r | |
373 | UINTN\r | |
374 | GetBytesPerPixel (\r | |
40b0b23e | 375 | IN LCD_BPP Bpp\r |
1e57a462 | 376 | )\r |
377 | {\r | |
b1b69d26 | 378 | switch (Bpp) {\r |
40b0b23e MK |
379 | case LcdBitsPerPixel_24:\r |
380 | return 4;\r | |
381 | \r | |
382 | case LcdBitsPerPixel_16_565:\r | |
383 | case LcdBitsPerPixel_16_555:\r | |
384 | case LcdBitsPerPixel_12_444:\r | |
385 | return 2;\r | |
386 | \r | |
387 | case LcdBitsPerPixel_8:\r | |
388 | case LcdBitsPerPixel_4:\r | |
389 | case LcdBitsPerPixel_2:\r | |
390 | case LcdBitsPerPixel_1:\r | |
391 | return 1;\r | |
392 | \r | |
393 | default:\r | |
394 | return 0;\r | |
1e57a462 | 395 | }\r |
396 | }\r |