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 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <IndustryStandard/Acpi.h>
13 #include <Protocol/AcpiTable.h>
14 #include <Protocol/GraphicsOutput.h>
15 #include <Protocol/BootLogo.h>
16 #include <Protocol/BootLogo2.h>
18 #include <Guid/EventGroup.h>
20 #include <Library/BaseLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/PcdLib.h>
26 #include <Library/SafeIntLib.h>
27 #include <Library/BmpSupportLib.h>
30 Update information of logo image drawn on screen.
32 @param[in] This The pointer to the Boot Logo protocol 2 instance.
33 @param[in] BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
34 is set to NULL, it indicates that logo image is no
36 @param[in] DestinationX X coordinate of destination for the BltBuffer.
37 @param[in] DestinationY Y coordinate of destination for the BltBuffer.
38 @param[in] Width Width of rectangle in BltBuffer in pixels.
39 @param[in] Height Hight of rectangle in BltBuffer in pixels.
41 @retval EFI_SUCCESS The boot logo information was updated.
42 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
43 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
44 insufficient memory resources.
49 IN EFI_BOOT_LOGO_PROTOCOL
*This
,
50 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
51 IN UINTN DestinationX
,
52 IN UINTN DestinationY
,
58 Update information of logo image drawn on screen.
60 @param[in] This The pointer to the Boot Logo protocol 2 instance.
61 @param[in] BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
62 is set to NULL, it indicates that logo image is no
64 @param[in] DestinationX X coordinate of destination for the BltBuffer.
65 @param[in] DestinationY Y coordinate of destination for the BltBuffer.
66 @param[in] Width Width of rectangle in BltBuffer in pixels.
67 @param[in] Height Hight of rectangle in BltBuffer in pixels.
69 @retval EFI_SUCCESS The boot logo information was updated.
70 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
71 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
72 insufficient memory resources.
77 IN EDKII_BOOT_LOGO2_PROTOCOL
*This
,
78 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
79 IN UINTN DestinationX
,
80 IN UINTN DestinationY
,
86 Get the location of the boot logo on the screen.
88 @param[in] This The pointer to the Boot Logo Protocol 2 instance
89 @param[out] BltBuffer Returns pointer to the GOP BLT buffer that was
90 previously registered with SetBootLogo2(). The
91 buffer returned must not be modified or freed.
92 @param[out] DestinationX Returns the X start position of the GOP BLT buffer
93 that was previously registered with SetBootLogo2().
94 @param[out] DestinationY Returns the Y start position of the GOP BLT buffer
95 that was previously registered with SetBootLogo2().
96 @param[out] Width Returns the width of the GOP BLT buffer
97 that was previously registered with SetBootLogo2().
98 @param[out] Height Returns the height of the GOP BLT buffer
99 that was previously registered with SetBootLogo2().
101 @retval EFI_SUCCESS The location of the boot logo was returned.
102 @retval EFI_NOT_READY The boot logo has not been set.
103 @retval EFI_INVALID_PARAMETER BltBuffer is NULL.
104 @retval EFI_INVALID_PARAMETER DestinationX is NULL.
105 @retval EFI_INVALID_PARAMETER DestinationY is NULL.
106 @retval EFI_INVALID_PARAMETER Width is NULL.
107 @retval EFI_INVALID_PARAMETER Height is NULL.
112 IN EDKII_BOOT_LOGO2_PROTOCOL
*This
,
113 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
**BltBuffer
,
114 OUT UINTN
*DestinationX
,
115 OUT UINTN
*DestinationY
,
121 // Boot Logo Protocol Handle
123 EFI_HANDLE mBootLogoHandle
= NULL
;
126 // Boot Logo Protocol Instance
128 EFI_BOOT_LOGO_PROTOCOL mBootLogoProtocolTemplate
= {
133 /// Boot Logo 2 Protocol instance
135 EDKII_BOOT_LOGO2_PROTOCOL mBootLogo2ProtocolTemplate
= {
140 EFI_EVENT mBootGraphicsReadyToBootEvent
;
141 UINTN mBootGraphicsResourceTableKey
= 0;
142 BOOLEAN mIsLogoValid
= FALSE
;
143 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*mLogoBltBuffer
= NULL
;
144 UINTN mLogoDestX
= 0;
145 UINTN mLogoDestY
= 0;
146 UINTN mLogoWidth
= 0;
147 UINTN mLogoHeight
= 0;
148 BOOLEAN mAcpiBgrtInstalled
= FALSE
;
149 BOOLEAN mAcpiBgrtStatusChanged
= FALSE
;
150 BOOLEAN mAcpiBgrtBufferChanged
= FALSE
;
153 // ACPI Boot Graphics Resource Table template
155 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE mBootGraphicsResourceTableTemplate
= {
157 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE
,
158 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
),
159 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_REVISION
, // Revision
160 0x00, // Checksum will be updated at runtime
162 // It is expected that these values will be updated at EntryPoint.
164 { 0x00 }, // OEM ID is a 6 bytes long field
165 0x00, // OEM Table ID(8 bytes long)
166 0x00, // OEM Revision
168 0x00, // Creator Revision
170 EFI_ACPI_5_0_BGRT_VERSION
, // Version
171 EFI_ACPI_5_0_BGRT_STATUS_VALID
, // Status
172 EFI_ACPI_5_0_BGRT_IMAGE_TYPE_BMP
, // Image Type
179 Update information of logo image drawn on screen.
181 @param This The pointer to the Boot Logo protocol instance.
182 @param BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
183 is set to NULL, it indicates that logo image is no
184 longer on the screen.
185 @param DestinationX X coordinate of destination for the BltBuffer.
186 @param DestinationY Y coordinate of destination for the BltBuffer.
187 @param Width Width of rectangle in BltBuffer in pixels.
188 @param Height Hight of rectangle in BltBuffer in pixels.
190 @retval EFI_SUCCESS The boot logo information was updated.
191 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
192 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
193 insufficient memory resources.
199 IN EFI_BOOT_LOGO_PROTOCOL
*This
,
200 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
201 IN UINTN DestinationX
,
202 IN UINTN DestinationY
,
208 // Call same service in Boot Logo 2 Protocol
210 return SetBootLogo2 (
211 &mBootLogo2ProtocolTemplate
,
221 Update information of logo image drawn on screen.
223 @param[in] This The pointer to the Boot Logo protocol 2 instance.
224 @param[in] BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
225 is set to NULL, it indicates that logo image is no
226 longer on the screen.
227 @param[in] DestinationX X coordinate of destination for the BltBuffer.
228 @param[in] DestinationY Y coordinate of destination for the BltBuffer.
229 @param[in] Width Width of rectangle in BltBuffer in pixels.
230 @param[in] Height Hight of rectangle in BltBuffer in pixels.
232 @retval EFI_SUCCESS The boot logo information was updated.
233 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
234 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
235 insufficient memory resources.
240 IN EDKII_BOOT_LOGO2_PROTOCOL
*This
,
241 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
242 IN UINTN DestinationX
,
243 IN UINTN DestinationY
,
252 if (BltBuffer
== NULL
) {
253 mIsLogoValid
= FALSE
;
254 mAcpiBgrtStatusChanged
= TRUE
;
259 // Width and height are not allowed to be zero.
261 if ((Width
== 0) || (Height
== 0)) {
262 return EFI_INVALID_PARAMETER
;
266 // Verify destination, width, and height do not overflow 32-bit values.
267 // The Boot Graphics Resource Table only has 32-bit fields for these values.
269 Status
= SafeUintnToUint32 (DestinationX
, &Result32
);
270 if (EFI_ERROR (Status
)) {
271 return EFI_INVALID_PARAMETER
;
274 Status
= SafeUintnToUint32 (DestinationY
, &Result32
);
275 if (EFI_ERROR (Status
)) {
276 return EFI_INVALID_PARAMETER
;
279 Status
= SafeUintnToUint32 (Width
, &Result32
);
280 if (EFI_ERROR (Status
)) {
281 return EFI_INVALID_PARAMETER
;
284 Status
= SafeUintnToUint32 (Height
, &Result32
);
285 if (EFI_ERROR (Status
)) {
286 return EFI_INVALID_PARAMETER
;
290 // Ensure the Height * Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) does
291 // not overflow UINTN
293 Status
= SafeUintnMult (
298 if (EFI_ERROR (Status
)) {
299 return EFI_UNSUPPORTED
;
302 Status
= SafeUintnMult (
304 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
),
307 if (EFI_ERROR (Status
)) {
308 return EFI_UNSUPPORTED
;
314 mAcpiBgrtBufferChanged
= TRUE
;
317 // Free old logo buffer
319 if (mLogoBltBuffer
!= NULL
) {
320 FreePool (mLogoBltBuffer
);
321 mLogoBltBuffer
= NULL
;
325 // Allocate new logo buffer
327 mLogoBltBuffer
= AllocateCopyPool (BufferSize
, BltBuffer
);
328 if (mLogoBltBuffer
== NULL
) {
329 return EFI_OUT_OF_RESOURCES
;
332 mLogoDestX
= DestinationX
;
333 mLogoDestY
= DestinationY
;
335 mLogoHeight
= Height
;
342 Get the location of the boot logo on the screen.
344 @param[in] This The pointer to the Boot Logo Protocol 2 instance
345 @param[out] BltBuffer Returns pointer to the GOP BLT buffer that was
346 previously registered with SetBootLogo2(). The
347 buffer returned must not be modified or freed.
348 @param[out] DestinationX Returns the X start position of the GOP BLT buffer
349 that was previously registered with SetBootLogo2().
350 @param[out] DestinationY Returns the Y start position of the GOP BLT buffer
351 that was previously registered with SetBootLogo2().
352 @param[out] Width Returns the width of the GOP BLT buffer
353 that was previously registered with SetBootLogo2().
354 @param[out] Height Returns the height of the GOP BLT buffer
355 that was previously registered with SetBootLogo2().
357 @retval EFI_SUCCESS The location of the boot logo was returned.
358 @retval EFI_NOT_READY The boot logo has not been set.
359 @retval EFI_INVALID_PARAMETER BltBuffer is NULL.
360 @retval EFI_INVALID_PARAMETER DestinationX is NULL.
361 @retval EFI_INVALID_PARAMETER DestinationY is NULL.
362 @retval EFI_INVALID_PARAMETER Width is NULL.
363 @retval EFI_INVALID_PARAMETER Height is NULL.
368 IN EDKII_BOOT_LOGO2_PROTOCOL
*This
,
369 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
**BltBuffer
,
370 OUT UINTN
*DestinationX
,
371 OUT UINTN
*DestinationY
,
377 // If the boot logo has not been set with SetBootLogo() or SetBootLogo() was
378 // called with a NULL BltBuffer then the boot logo is not valid and
379 // EFI_NOT_READY is returned.
381 if (mLogoBltBuffer
== NULL
) {
382 DEBUG ((DEBUG_ERROR
, "Request to get boot logo location before boot logo has been set.\n"));
383 return EFI_NOT_READY
;
387 // Make sure none of the boot logo location parameters are NULL.
389 if ((BltBuffer
== NULL
) || (DestinationX
== NULL
) || (DestinationY
== NULL
) ||
390 (Width
== NULL
) || (Height
== NULL
))
392 return EFI_INVALID_PARAMETER
;
396 // Boot logo is valid. Return values from module globals.
398 *BltBuffer
= mLogoBltBuffer
;
399 *DestinationX
= mLogoDestX
;
400 *DestinationY
= mLogoDestY
;
402 *Height
= mLogoHeight
;
408 Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to
409 install the Boot Graphics Resource Table.
411 @param[in] Event The Event that is being processed.
412 @param[in] Context The Event Context.
417 BgrtReadyToBootEventNotify (
423 EFI_ACPI_TABLE_PROTOCOL
*AcpiTableProtocol
;
428 // Get ACPI Table protocol.
430 Status
= gBS
->LocateProtocol (
431 &gEfiAcpiTableProtocolGuid
,
433 (VOID
**)&AcpiTableProtocol
435 if (EFI_ERROR (Status
)) {
440 // Check whether Boot Graphics Resource Table is already installed.
442 if (mAcpiBgrtInstalled
) {
443 if (!mAcpiBgrtStatusChanged
&& !mAcpiBgrtBufferChanged
) {
445 // Nothing has changed
450 // If BGRT data change happens, then uninstall orignal AcpiTable first
452 Status
= AcpiTableProtocol
->UninstallAcpiTable (
454 mBootGraphicsResourceTableKey
456 if (EFI_ERROR (Status
)) {
462 // Check whether Logo exists
464 if (mLogoBltBuffer
== NULL
) {
469 if (mAcpiBgrtBufferChanged
) {
471 // Free the old BMP image buffer
473 ImageBuffer
= (UINT8
*)(UINTN
)mBootGraphicsResourceTableTemplate
.ImageAddress
;
474 if (ImageBuffer
!= NULL
) {
475 FreePool (ImageBuffer
);
479 // Convert GOP Blt buffer to BMP image. Pass in ImageBuffer set to NULL
480 // so the BMP image is allocated by TranslateGopBltToBmp().
483 Status
= TranslateGopBltToBmp (
490 if (EFI_ERROR (Status
)) {
495 // Free the logo buffer
497 FreePool (mLogoBltBuffer
);
498 mLogoBltBuffer
= NULL
;
501 // Update BMP image fields of the Boot Graphics Resource Table
503 mBootGraphicsResourceTableTemplate
.ImageAddress
= (UINT64
)(UINTN
)ImageBuffer
;
504 mBootGraphicsResourceTableTemplate
.ImageOffsetX
= (UINT32
)mLogoDestX
;
505 mBootGraphicsResourceTableTemplate
.ImageOffsetY
= (UINT32
)mLogoDestY
;
509 // Update Status field of Boot Graphics Resource Table
512 mBootGraphicsResourceTableTemplate
.Status
= EFI_ACPI_5_0_BGRT_STATUS_VALID
;
514 mBootGraphicsResourceTableTemplate
.Status
= EFI_ACPI_5_0_BGRT_STATUS_INVALID
;
518 // Update Checksum of Boot Graphics Resource Table
520 mBootGraphicsResourceTableTemplate
.Header
.Checksum
= 0;
521 mBootGraphicsResourceTableTemplate
.Header
.Checksum
=
523 (UINT8
*)&mBootGraphicsResourceTableTemplate
,
524 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
)
528 // Publish Boot Graphics Resource Table.
530 Status
= AcpiTableProtocol
->InstallAcpiTable (
532 &mBootGraphicsResourceTableTemplate
,
533 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
),
534 &mBootGraphicsResourceTableKey
536 if (EFI_ERROR (Status
)) {
540 mAcpiBgrtInstalled
= TRUE
;
541 mAcpiBgrtStatusChanged
= FALSE
;
542 mAcpiBgrtBufferChanged
= FALSE
;
546 The module Entry Point of the Boot Graphics Resource Table DXE driver.
548 @param[in] ImageHandle The firmware allocated handle for the EFI image.
549 @param[in] SystemTable A pointer to the EFI System Table.
551 @retval EFI_SUCCESS The entry point is executed successfully.
552 @retval Other Some error occurs when executing this entry point.
557 BootGraphicsDxeEntryPoint (
558 IN EFI_HANDLE ImageHandle
,
559 IN EFI_SYSTEM_TABLE
*SystemTable
563 EFI_ACPI_DESCRIPTION_HEADER
*Header
;
566 // Update Header fields of Boot Graphics Resource Table from PCDs
568 Header
= &mBootGraphicsResourceTableTemplate
.Header
;
569 ZeroMem (Header
->OemId
, sizeof (Header
->OemId
));
572 PcdGetPtr (PcdAcpiDefaultOemId
),
573 MIN (PcdGetSize (PcdAcpiDefaultOemId
), sizeof (Header
->OemId
))
575 WriteUnaligned64 (&Header
->OemTableId
, PcdGet64 (PcdAcpiDefaultOemTableId
));
576 Header
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
577 Header
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
578 Header
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
581 // Install Boot Logo and Boot Logo 2 Protocols.
583 Status
= gBS
->InstallMultipleProtocolInterfaces (
585 &gEfiBootLogoProtocolGuid
,
586 &mBootLogoProtocolTemplate
,
587 &gEdkiiBootLogo2ProtocolGuid
,
588 &mBootLogo2ProtocolTemplate
,
591 ASSERT_EFI_ERROR (Status
);
594 // Register notify function to install BGRT on ReadyToBoot Event.
596 Status
= gBS
->CreateEventEx (
599 BgrtReadyToBootEventNotify
,
601 &gEfiEventReadyToBootGuid
,
602 &mBootGraphicsReadyToBootEvent
604 ASSERT_EFI_ERROR (Status
);