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
;
273 Status
= SafeUintnToUint32 (DestinationY
, &Result32
);
274 if (EFI_ERROR (Status
)) {
275 return EFI_INVALID_PARAMETER
;
277 Status
= SafeUintnToUint32 (Width
, &Result32
);
278 if (EFI_ERROR (Status
)) {
279 return EFI_INVALID_PARAMETER
;
281 Status
= SafeUintnToUint32 (Height
, &Result32
);
282 if (EFI_ERROR (Status
)) {
283 return EFI_INVALID_PARAMETER
;
287 // Ensure the Height * Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) does
288 // not overflow UINTN
290 Status
= SafeUintnMult (
295 if (EFI_ERROR (Status
)) {
296 return EFI_UNSUPPORTED
;
298 Status
= SafeUintnMult (
300 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
),
303 if (EFI_ERROR (Status
)) {
304 return EFI_UNSUPPORTED
;
310 mAcpiBgrtBufferChanged
= TRUE
;
313 // Free old logo buffer
315 if (mLogoBltBuffer
!= NULL
) {
316 FreePool (mLogoBltBuffer
);
317 mLogoBltBuffer
= NULL
;
321 // Allocate new logo buffer
323 mLogoBltBuffer
= AllocateCopyPool (BufferSize
, BltBuffer
);
324 if (mLogoBltBuffer
== NULL
) {
325 return EFI_OUT_OF_RESOURCES
;
328 mLogoDestX
= DestinationX
;
329 mLogoDestY
= DestinationY
;
331 mLogoHeight
= Height
;
338 Get the location of the boot logo on the screen.
340 @param[in] This The pointer to the Boot Logo Protocol 2 instance
341 @param[out] BltBuffer Returns pointer to the GOP BLT buffer that was
342 previously registered with SetBootLogo2(). The
343 buffer returned must not be modified or freed.
344 @param[out] DestinationX Returns the X start position of the GOP BLT buffer
345 that was previously registered with SetBootLogo2().
346 @param[out] DestinationY Returns the Y start position of the GOP BLT buffer
347 that was previously registered with SetBootLogo2().
348 @param[out] Width Returns the width of the GOP BLT buffer
349 that was previously registered with SetBootLogo2().
350 @param[out] Height Returns the height of the GOP BLT buffer
351 that was previously registered with SetBootLogo2().
353 @retval EFI_SUCCESS The location of the boot logo was returned.
354 @retval EFI_NOT_READY The boot logo has not been set.
355 @retval EFI_INVALID_PARAMETER BltBuffer is NULL.
356 @retval EFI_INVALID_PARAMETER DestinationX is NULL.
357 @retval EFI_INVALID_PARAMETER DestinationY is NULL.
358 @retval EFI_INVALID_PARAMETER Width is NULL.
359 @retval EFI_INVALID_PARAMETER Height is NULL.
364 IN EDKII_BOOT_LOGO2_PROTOCOL
*This
,
365 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
**BltBuffer
,
366 OUT UINTN
*DestinationX
,
367 OUT UINTN
*DestinationY
,
373 // If the boot logo has not been set with SetBootLogo() or SetBootLogo() was
374 // called with a NULL BltBuffer then the boot logo is not valid and
375 // EFI_NOT_READY is returned.
377 if (mLogoBltBuffer
== NULL
) {
378 DEBUG ((DEBUG_ERROR
, "Request to get boot logo location before boot logo has been set.\n"));
379 return EFI_NOT_READY
;
383 // Make sure none of the boot logo location parameters are NULL.
385 if (BltBuffer
== NULL
|| DestinationX
== NULL
|| DestinationY
== NULL
||
386 Width
== NULL
|| Height
== NULL
) {
387 return EFI_INVALID_PARAMETER
;
391 // Boot logo is valid. Return values from module globals.
393 *BltBuffer
= mLogoBltBuffer
;
394 *DestinationX
= mLogoDestX
;
395 *DestinationY
= mLogoDestY
;
397 *Height
= mLogoHeight
;
403 Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to
404 install the Boot Graphics Resource Table.
406 @param[in] Event The Event that is being processed.
407 @param[in] Context The Event Context.
412 BgrtReadyToBootEventNotify (
418 EFI_ACPI_TABLE_PROTOCOL
*AcpiTableProtocol
;
423 // Get ACPI Table protocol.
425 Status
= gBS
->LocateProtocol (
426 &gEfiAcpiTableProtocolGuid
,
428 (VOID
**) &AcpiTableProtocol
430 if (EFI_ERROR (Status
)) {
435 // Check whether Boot Graphics Resource Table is already installed.
437 if (mAcpiBgrtInstalled
) {
438 if (!mAcpiBgrtStatusChanged
&& !mAcpiBgrtBufferChanged
) {
440 // Nothing has changed
445 // If BGRT data change happens, then uninstall orignal AcpiTable first
447 Status
= AcpiTableProtocol
->UninstallAcpiTable (
449 mBootGraphicsResourceTableKey
451 if (EFI_ERROR (Status
)) {
457 // Check whether Logo exists
459 if (mLogoBltBuffer
== NULL
) {
464 if (mAcpiBgrtBufferChanged
) {
466 // Free the old BMP image buffer
468 ImageBuffer
= (UINT8
*)(UINTN
)mBootGraphicsResourceTableTemplate
.ImageAddress
;
469 if (ImageBuffer
!= NULL
) {
470 FreePool (ImageBuffer
);
474 // Convert GOP Blt buffer to BMP image. Pass in ImageBuffer set to NULL
475 // so the BMP image is allocated by TranslateGopBltToBmp().
478 Status
= TranslateGopBltToBmp (
485 if (EFI_ERROR (Status
)) {
490 // Free the logo buffer
492 FreePool (mLogoBltBuffer
);
493 mLogoBltBuffer
= NULL
;
496 // Update BMP image fields of the Boot Graphics Resource Table
498 mBootGraphicsResourceTableTemplate
.ImageAddress
= (UINT64
)(UINTN
)ImageBuffer
;
499 mBootGraphicsResourceTableTemplate
.ImageOffsetX
= (UINT32
)mLogoDestX
;
500 mBootGraphicsResourceTableTemplate
.ImageOffsetY
= (UINT32
)mLogoDestY
;
504 // Update Status field of Boot Graphics Resource Table
507 mBootGraphicsResourceTableTemplate
.Status
= EFI_ACPI_5_0_BGRT_STATUS_VALID
;
509 mBootGraphicsResourceTableTemplate
.Status
= EFI_ACPI_5_0_BGRT_STATUS_INVALID
;
513 // Update Checksum of Boot Graphics Resource Table
515 mBootGraphicsResourceTableTemplate
.Header
.Checksum
= 0;
516 mBootGraphicsResourceTableTemplate
.Header
.Checksum
=
518 (UINT8
*)&mBootGraphicsResourceTableTemplate
,
519 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
)
523 // Publish Boot Graphics Resource Table.
525 Status
= AcpiTableProtocol
->InstallAcpiTable (
527 &mBootGraphicsResourceTableTemplate
,
528 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
),
529 &mBootGraphicsResourceTableKey
531 if (EFI_ERROR (Status
)) {
535 mAcpiBgrtInstalled
= TRUE
;
536 mAcpiBgrtStatusChanged
= FALSE
;
537 mAcpiBgrtBufferChanged
= FALSE
;
541 The module Entry Point of the Boot Graphics Resource Table DXE driver.
543 @param[in] ImageHandle The firmware allocated handle for the EFI image.
544 @param[in] SystemTable A pointer to the EFI System Table.
546 @retval EFI_SUCCESS The entry point is executed successfully.
547 @retval Other Some error occurs when executing this entry point.
552 BootGraphicsDxeEntryPoint (
553 IN EFI_HANDLE ImageHandle
,
554 IN EFI_SYSTEM_TABLE
*SystemTable
558 EFI_ACPI_DESCRIPTION_HEADER
*Header
;
561 // Update Header fields of Boot Graphics Resource Table from PCDs
563 Header
= &mBootGraphicsResourceTableTemplate
.Header
;
564 ZeroMem (Header
->OemId
, sizeof (Header
->OemId
));
567 PcdGetPtr (PcdAcpiDefaultOemId
),
568 MIN (PcdGetSize (PcdAcpiDefaultOemId
), sizeof (Header
->OemId
))
570 WriteUnaligned64 (&Header
->OemTableId
, PcdGet64 (PcdAcpiDefaultOemTableId
));
571 Header
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
572 Header
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
573 Header
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
576 // Install Boot Logo and Boot Logo 2 Protocols.
578 Status
= gBS
->InstallMultipleProtocolInterfaces (
580 &gEfiBootLogoProtocolGuid
,
581 &mBootLogoProtocolTemplate
,
582 &gEdkiiBootLogo2ProtocolGuid
,
583 &mBootLogo2ProtocolTemplate
,
586 ASSERT_EFI_ERROR (Status
);
589 // Register notify function to install BGRT on ReadyToBoot Event.
591 Status
= gBS
->CreateEventEx (
594 BgrtReadyToBootEventNotify
,
596 &gEfiEventReadyToBootGuid
,
597 &mBootGraphicsReadyToBootEvent
599 ASSERT_EFI_ERROR (Status
);