2 This module install ACPI Boot Graphics Resource Table (BGRT).
4 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2016, Microsoft Corporation<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <IndustryStandard/Acpi.h>
19 #include <Protocol/AcpiTable.h>
20 #include <Protocol/GraphicsOutput.h>
21 #include <Protocol/BootLogo.h>
22 #include <Protocol/BootLogo2.h>
24 #include <Guid/EventGroup.h>
26 #include <Library/BaseLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/PcdLib.h>
32 #include <Library/SafeIntLib.h>
33 #include <Library/BmpSupportLib.h>
36 Update information of logo image drawn on screen.
38 @param[in] This The pointer to the Boot Logo protocol 2 instance.
39 @param[in] BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
40 is set to NULL, it indicates that logo image is no
42 @param[in] DestinationX X coordinate of destination for the BltBuffer.
43 @param[in] DestinationY Y coordinate of destination for the BltBuffer.
44 @param[in] Width Width of rectangle in BltBuffer in pixels.
45 @param[in] Height Hight of rectangle in BltBuffer in pixels.
47 @retval EFI_SUCCESS The boot logo information was updated.
48 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
49 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
50 insufficient memory resources.
55 IN EFI_BOOT_LOGO_PROTOCOL
*This
,
56 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
57 IN UINTN DestinationX
,
58 IN UINTN DestinationY
,
64 Update information of logo image drawn on screen.
66 @param[in] This The pointer to the Boot Logo protocol 2 instance.
67 @param[in] BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
68 is set to NULL, it indicates that logo image is no
70 @param[in] DestinationX X coordinate of destination for the BltBuffer.
71 @param[in] DestinationY Y coordinate of destination for the BltBuffer.
72 @param[in] Width Width of rectangle in BltBuffer in pixels.
73 @param[in] Height Hight of rectangle in BltBuffer in pixels.
75 @retval EFI_SUCCESS The boot logo information was updated.
76 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
77 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
78 insufficient memory resources.
83 IN EDKII_BOOT_LOGO2_PROTOCOL
*This
,
84 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
85 IN UINTN DestinationX
,
86 IN UINTN DestinationY
,
92 Get the location of the boot logo on the screen.
94 @param[in] This The pointer to the Boot Logo Protocol 2 instance
95 @param[out] BltBuffer Returns pointer to the GOP BLT buffer that was
96 previously registered with SetBootLogo2(). The
97 buffer returned must not be modified or freed.
98 @param[out] DestinationX Returns the X start position of the GOP BLT buffer
99 that was previously registered with SetBootLogo2().
100 @param[out] DestinationY Returns the Y start position of the GOP BLT buffer
101 that was previously registered with SetBootLogo2().
102 @param[out] Width Returns the width of the GOP BLT buffer
103 that was previously registered with SetBootLogo2().
104 @param[out] Height Returns the height of the GOP BLT buffer
105 that was previously registered with SetBootLogo2().
107 @retval EFI_SUCCESS The location of the boot logo was returned.
108 @retval EFI_NOT_READY The boot logo has not been set.
109 @retval EFI_INVALID_PARAMETER BltBuffer is NULL.
110 @retval EFI_INVALID_PARAMETER DestinationX is NULL.
111 @retval EFI_INVALID_PARAMETER DestinationY is NULL.
112 @retval EFI_INVALID_PARAMETER Width is NULL.
113 @retval EFI_INVALID_PARAMETER Height is NULL.
118 IN EDKII_BOOT_LOGO2_PROTOCOL
*This
,
119 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
**BltBuffer
,
120 OUT UINTN
*DestinationX
,
121 OUT UINTN
*DestinationY
,
127 // Boot Logo Protocol Handle
129 EFI_HANDLE mBootLogoHandle
= NULL
;
132 // Boot Logo Protocol Instance
134 EFI_BOOT_LOGO_PROTOCOL mBootLogoProtocolTemplate
= {
139 /// Boot Logo 2 Protocol instance
141 EDKII_BOOT_LOGO2_PROTOCOL mBootLogo2ProtocolTemplate
= {
146 EFI_EVENT mBootGraphicsReadyToBootEvent
;
147 UINTN mBootGraphicsResourceTableKey
= 0;
148 BOOLEAN mIsLogoValid
= FALSE
;
149 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*mLogoBltBuffer
= NULL
;
150 UINTN mLogoDestX
= 0;
151 UINTN mLogoDestY
= 0;
152 UINTN mLogoWidth
= 0;
153 UINTN mLogoHeight
= 0;
154 BOOLEAN mAcpiBgrtInstalled
= FALSE
;
155 BOOLEAN mAcpiBgrtStatusChanged
= FALSE
;
156 BOOLEAN mAcpiBgrtBufferChanged
= FALSE
;
159 // ACPI Boot Graphics Resource Table template
161 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE mBootGraphicsResourceTableTemplate
= {
163 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE
,
164 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
),
165 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_REVISION
, // Revision
166 0x00, // Checksum will be updated at runtime
168 // It is expected that these values will be updated at EntryPoint.
170 {0x00}, // OEM ID is a 6 bytes long field
171 0x00, // OEM Table ID(8 bytes long)
172 0x00, // OEM Revision
174 0x00, // Creator Revision
176 EFI_ACPI_5_0_BGRT_VERSION
, // Version
177 EFI_ACPI_5_0_BGRT_STATUS_VALID
, // Status
178 EFI_ACPI_5_0_BGRT_IMAGE_TYPE_BMP
, // Image Type
185 Update information of logo image drawn on screen.
187 @param This The pointer to the Boot Logo protocol instance.
188 @param BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
189 is set to NULL, it indicates that logo image is no
190 longer on the screen.
191 @param DestinationX X coordinate of destination for the BltBuffer.
192 @param DestinationY Y coordinate of destination for the BltBuffer.
193 @param Width Width of rectangle in BltBuffer in pixels.
194 @param Height Hight of rectangle in BltBuffer in pixels.
196 @retval EFI_SUCCESS The boot logo information was updated.
197 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
198 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
199 insufficient memory resources.
205 IN EFI_BOOT_LOGO_PROTOCOL
*This
,
206 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
207 IN UINTN DestinationX
,
208 IN UINTN DestinationY
,
214 // Call same service in Boot Logo 2 Protocol
216 return SetBootLogo2 (
217 &mBootLogo2ProtocolTemplate
,
227 Update information of logo image drawn on screen.
229 @param[in] This The pointer to the Boot Logo protocol 2 instance.
230 @param[in] BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
231 is set to NULL, it indicates that logo image is no
232 longer on the screen.
233 @param[in] DestinationX X coordinate of destination for the BltBuffer.
234 @param[in] DestinationY Y coordinate of destination for the BltBuffer.
235 @param[in] Width Width of rectangle in BltBuffer in pixels.
236 @param[in] Height Hight of rectangle in BltBuffer in pixels.
238 @retval EFI_SUCCESS The boot logo information was updated.
239 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
240 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
241 insufficient memory resources.
246 IN EDKII_BOOT_LOGO2_PROTOCOL
*This
,
247 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
248 IN UINTN DestinationX
,
249 IN UINTN DestinationY
,
258 if (BltBuffer
== NULL
) {
259 mIsLogoValid
= FALSE
;
260 mAcpiBgrtStatusChanged
= TRUE
;
265 // Width and height are not allowed to be zero.
267 if (Width
== 0 || Height
== 0) {
268 return EFI_INVALID_PARAMETER
;
272 // Verify destination, width, and height do not overflow 32-bit values.
273 // The Boot Graphics Resource Table only has 32-bit fields for these values.
275 Status
= SafeUintnToUint32 (DestinationX
, &Result32
);
276 if (EFI_ERROR (Status
)) {
277 return EFI_INVALID_PARAMETER
;
279 Status
= SafeUintnToUint32 (DestinationY
, &Result32
);
280 if (EFI_ERROR (Status
)) {
281 return EFI_INVALID_PARAMETER
;
283 Status
= SafeUintnToUint32 (Width
, &Result32
);
284 if (EFI_ERROR (Status
)) {
285 return EFI_INVALID_PARAMETER
;
287 Status
= SafeUintnToUint32 (Height
, &Result32
);
288 if (EFI_ERROR (Status
)) {
289 return EFI_INVALID_PARAMETER
;
293 // Ensure the Height * Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) does
294 // not overflow UINTN
296 Status
= SafeUintnMult (
301 if (EFI_ERROR (Status
)) {
302 return EFI_UNSUPPORTED
;
304 Status
= SafeUintnMult (
306 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
),
309 if (EFI_ERROR (Status
)) {
310 return EFI_UNSUPPORTED
;
316 mAcpiBgrtBufferChanged
= TRUE
;
319 // Free old logo buffer
321 if (mLogoBltBuffer
!= NULL
) {
322 FreePool (mLogoBltBuffer
);
323 mLogoBltBuffer
= NULL
;
327 // Allocate new logo buffer
329 mLogoBltBuffer
= AllocateCopyPool (BufferSize
, BltBuffer
);
330 if (mLogoBltBuffer
== NULL
) {
331 return EFI_OUT_OF_RESOURCES
;
334 mLogoDestX
= DestinationX
;
335 mLogoDestY
= DestinationY
;
337 mLogoHeight
= Height
;
344 Get the location of the boot logo on the screen.
346 @param[in] This The pointer to the Boot Logo Protocol 2 instance
347 @param[out] BltBuffer Returns pointer to the GOP BLT buffer that was
348 previously registered with SetBootLogo2(). The
349 buffer returned must not be modified or freed.
350 @param[out] DestinationX Returns the X start position of the GOP BLT buffer
351 that was previously registered with SetBootLogo2().
352 @param[out] DestinationY Returns the Y start position of the GOP BLT buffer
353 that was previously registered with SetBootLogo2().
354 @param[out] Width Returns the width of the GOP BLT buffer
355 that was previously registered with SetBootLogo2().
356 @param[out] Height Returns the height of the GOP BLT buffer
357 that was previously registered with SetBootLogo2().
359 @retval EFI_SUCCESS The location of the boot logo was returned.
360 @retval EFI_NOT_READY The boot logo has not been set.
361 @retval EFI_INVALID_PARAMETER BltBuffer is NULL.
362 @retval EFI_INVALID_PARAMETER DestinationX is NULL.
363 @retval EFI_INVALID_PARAMETER DestinationY is NULL.
364 @retval EFI_INVALID_PARAMETER Width is NULL.
365 @retval EFI_INVALID_PARAMETER Height is NULL.
370 IN EDKII_BOOT_LOGO2_PROTOCOL
*This
,
371 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
**BltBuffer
,
372 OUT UINTN
*DestinationX
,
373 OUT UINTN
*DestinationY
,
379 // If the boot logo has not been set with SetBootLogo() or SetBootLogo() was
380 // called with a NULL BltBuffer then the boot logo is not valid and
381 // EFI_NOT_READY is returned.
383 if (mLogoBltBuffer
== NULL
) {
384 DEBUG ((DEBUG_ERROR
, "Request to get boot logo location before boot logo has been set.\n"));
385 return EFI_NOT_READY
;
389 // Make sure none of the boot logo location parameters are NULL.
391 if (BltBuffer
== NULL
|| DestinationX
== NULL
|| DestinationY
== NULL
||
392 Width
== NULL
|| Height
== NULL
) {
393 return EFI_INVALID_PARAMETER
;
397 // Boot logo is valid. Return values from module globals.
399 *BltBuffer
= mLogoBltBuffer
;
400 *DestinationX
= mLogoDestX
;
401 *DestinationY
= mLogoDestY
;
403 *Height
= mLogoHeight
;
409 Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to
410 install the Boot Graphics Resource Table.
412 @param[in] Event The Event that is being processed.
413 @param[in] Context The Event Context.
418 BgrtReadyToBootEventNotify (
424 EFI_ACPI_TABLE_PROTOCOL
*AcpiTableProtocol
;
429 // Get ACPI Table protocol.
431 Status
= gBS
->LocateProtocol (
432 &gEfiAcpiTableProtocolGuid
,
434 (VOID
**) &AcpiTableProtocol
436 if (EFI_ERROR (Status
)) {
441 // Check whether Boot Graphics Resource Table is already installed.
443 if (mAcpiBgrtInstalled
) {
444 if (!mAcpiBgrtStatusChanged
&& !mAcpiBgrtBufferChanged
) {
446 // Nothing has changed
451 // If BGRT data change happens, then uninstall orignal AcpiTable first
453 Status
= AcpiTableProtocol
->UninstallAcpiTable (
455 mBootGraphicsResourceTableKey
457 if (EFI_ERROR (Status
)) {
463 // Check whether Logo exists
465 if (mLogoBltBuffer
== NULL
) {
470 if (mAcpiBgrtBufferChanged
) {
472 // Free the old BMP image buffer
474 ImageBuffer
= (UINT8
*)(UINTN
)mBootGraphicsResourceTableTemplate
.ImageAddress
;
475 if (ImageBuffer
!= NULL
) {
476 FreePool (ImageBuffer
);
480 // Convert GOP Blt buffer to BMP image. Pass in ImageBuffer set to NULL
481 // so the BMP image is allocated by TranslateGopBltToBmp().
484 Status
= TranslateGopBltToBmp (
491 if (EFI_ERROR (Status
)) {
496 // Free the logo buffer
498 FreePool (mLogoBltBuffer
);
499 mLogoBltBuffer
= NULL
;
502 // Update BMP image fields of the Boot Graphics Resource Table
504 mBootGraphicsResourceTableTemplate
.ImageAddress
= (UINT64
)(UINTN
)ImageBuffer
;
505 mBootGraphicsResourceTableTemplate
.ImageOffsetX
= (UINT32
)mLogoDestX
;
506 mBootGraphicsResourceTableTemplate
.ImageOffsetY
= (UINT32
)mLogoDestY
;
510 // Update Status field of Boot Graphics Resource Table
513 mBootGraphicsResourceTableTemplate
.Status
= EFI_ACPI_5_0_BGRT_STATUS_VALID
;
515 mBootGraphicsResourceTableTemplate
.Status
= EFI_ACPI_5_0_BGRT_STATUS_INVALID
;
519 // Update Checksum of Boot Graphics Resource Table
521 mBootGraphicsResourceTableTemplate
.Header
.Checksum
= 0;
522 mBootGraphicsResourceTableTemplate
.Header
.Checksum
=
524 (UINT8
*)&mBootGraphicsResourceTableTemplate
,
525 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
)
529 // Publish Boot Graphics Resource Table.
531 Status
= AcpiTableProtocol
->InstallAcpiTable (
533 &mBootGraphicsResourceTableTemplate
,
534 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
),
535 &mBootGraphicsResourceTableKey
537 if (EFI_ERROR (Status
)) {
541 mAcpiBgrtInstalled
= TRUE
;
542 mAcpiBgrtStatusChanged
= FALSE
;
543 mAcpiBgrtBufferChanged
= FALSE
;
547 The module Entry Point of the Boot Graphics Resource Table DXE driver.
549 @param[in] ImageHandle The firmware allocated handle for the EFI image.
550 @param[in] SystemTable A pointer to the EFI System Table.
552 @retval EFI_SUCCESS The entry point is executed successfully.
553 @retval Other Some error occurs when executing this entry point.
558 BootGraphicsDxeEntryPoint (
559 IN EFI_HANDLE ImageHandle
,
560 IN EFI_SYSTEM_TABLE
*SystemTable
564 EFI_ACPI_DESCRIPTION_HEADER
*Header
;
567 // Update Header fields of Boot Graphics Resource Table from PCDs
569 Header
= &mBootGraphicsResourceTableTemplate
.Header
;
570 ZeroMem (Header
->OemId
, sizeof (Header
->OemId
));
573 PcdGetPtr (PcdAcpiDefaultOemId
),
574 MIN (PcdGetSize (PcdAcpiDefaultOemId
), sizeof (Header
->OemId
))
576 WriteUnaligned64 (&Header
->OemTableId
, PcdGet64 (PcdAcpiDefaultOemTableId
));
577 Header
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
578 Header
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
579 Header
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
582 // Install Boot Logo and Boot Logo 2 Protocols.
584 Status
= gBS
->InstallMultipleProtocolInterfaces (
586 &gEfiBootLogoProtocolGuid
,
587 &mBootLogoProtocolTemplate
,
588 &gEdkiiBootLogo2ProtocolGuid
,
589 &mBootLogo2ProtocolTemplate
,
592 ASSERT_EFI_ERROR (Status
);
595 // Register notify function to install BGRT on ReadyToBoot Event.
597 Status
= gBS
->CreateEventEx (
600 BgrtReadyToBootEventNotify
,
602 &gEfiEventReadyToBootGuid
,
603 &mBootGraphicsReadyToBootEvent
605 ASSERT_EFI_ERROR (Status
);