2 This module install ACPI Boot Graphics Resource Table (BGRT).
4 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <IndustryStandard/Acpi.h>
18 #include <Protocol/AcpiTable.h>
19 #include <Protocol/GraphicsOutput.h>
20 #include <Protocol/BootLogo.h>
22 #include <Guid/EventGroup.h>
24 #include <Library/BaseLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/PcdLib.h>
30 #include <Library/SafeIntLib.h>
31 #include <Library/BmpSupportLib.h>
34 Update information of logo image drawn on screen.
36 @param This The pointer to the Boot Logo protocol instance.
37 @param BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
38 is set to NULL, it indicates that logo image is no
40 @param DestinationX X coordinate of destination for the BltBuffer.
41 @param DestinationY Y coordinate of destination for the BltBuffer.
42 @param Width Width of rectangle in BltBuffer in pixels.
43 @param Height Hight of rectangle in BltBuffer in pixels.
45 @retval EFI_SUCCESS The boot logo information was updated.
46 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
47 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
48 insufficient memory resources.
54 IN EFI_BOOT_LOGO_PROTOCOL
*This
,
55 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
56 IN UINTN DestinationX
,
57 IN UINTN DestinationY
,
63 // Boot Logo Protocol Handle
65 EFI_HANDLE mBootLogoHandle
= NULL
;
68 // Boot Logo Protocol Instance
70 EFI_BOOT_LOGO_PROTOCOL mBootLogoProtocolTemplate
= {
74 EFI_EVENT mBootGraphicsReadyToBootEvent
;
75 UINTN mBootGraphicsResourceTableKey
= 0;
76 BOOLEAN mIsLogoValid
= FALSE
;
77 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*mLogoBltBuffer
= NULL
;
81 UINTN mLogoHeight
= 0;
82 BOOLEAN mAcpiBgrtInstalled
= FALSE
;
83 BOOLEAN mAcpiBgrtStatusChanged
= FALSE
;
84 BOOLEAN mAcpiBgrtBufferChanged
= FALSE
;
87 // ACPI Boot Graphics Resource Table template
89 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE mBootGraphicsResourceTableTemplate
= {
91 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE
,
92 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
),
93 EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_REVISION
, // Revision
94 0x00, // Checksum will be updated at runtime
96 // It is expected that these values will be updated at EntryPoint.
98 {0x00}, // OEM ID is a 6 bytes long field
99 0x00, // OEM Table ID(8 bytes long)
100 0x00, // OEM Revision
102 0x00, // Creator Revision
104 EFI_ACPI_5_0_BGRT_VERSION
, // Version
105 EFI_ACPI_5_0_BGRT_STATUS_VALID
, // Status
106 EFI_ACPI_5_0_BGRT_IMAGE_TYPE_BMP
, // Image Type
113 Update information of logo image drawn on screen.
115 @param This The pointer to the Boot Logo protocol instance.
116 @param BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
117 is set to NULL, it indicates that logo image is no
118 longer on the screen.
119 @param DestinationX X coordinate of destination for the BltBuffer.
120 @param DestinationY Y coordinate of destination for the BltBuffer.
121 @param Width Width of rectangle in BltBuffer in pixels.
122 @param Height Hight of rectangle in BltBuffer in pixels.
124 @retval EFI_SUCCESS The boot logo information was updated.
125 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
126 @retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
127 insufficient memory resources.
133 IN EFI_BOOT_LOGO_PROTOCOL
*This
,
134 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer OPTIONAL
,
135 IN UINTN DestinationX
,
136 IN UINTN DestinationY
,
145 if (BltBuffer
== NULL
) {
146 mIsLogoValid
= FALSE
;
147 mAcpiBgrtStatusChanged
= TRUE
;
152 // Width and height are not allowed to be zero.
154 if (Width
== 0 || Height
== 0) {
155 return EFI_INVALID_PARAMETER
;
159 // Verify destination, width, and height do not overflow 32-bit values.
160 // The Boot Graphics Resource Table only has 32-bit fields for these values.
162 Status
= SafeUintnToUint32 (DestinationX
, &Result32
);
163 if (EFI_ERROR (Status
)) {
164 return EFI_INVALID_PARAMETER
;
166 Status
= SafeUintnToUint32 (DestinationY
, &Result32
);
167 if (EFI_ERROR (Status
)) {
168 return EFI_INVALID_PARAMETER
;
170 Status
= SafeUintnToUint32 (Width
, &Result32
);
171 if (EFI_ERROR (Status
)) {
172 return EFI_INVALID_PARAMETER
;
174 Status
= SafeUintnToUint32 (Height
, &Result32
);
175 if (EFI_ERROR (Status
)) {
176 return EFI_INVALID_PARAMETER
;
180 // Ensure the Height * Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) does
181 // not overflow UINTN
183 Status
= SafeUintnMult (
188 if (EFI_ERROR (Status
)) {
189 return EFI_UNSUPPORTED
;
191 Status
= SafeUintnMult (
193 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
),
196 if (EFI_ERROR (Status
)) {
197 return EFI_UNSUPPORTED
;
203 mAcpiBgrtBufferChanged
= TRUE
;
206 // Free old logo buffer
208 if (mLogoBltBuffer
!= NULL
) {
209 FreePool (mLogoBltBuffer
);
210 mLogoBltBuffer
= NULL
;
214 // Allocate new logo buffer
216 mLogoBltBuffer
= AllocateCopyPool (BufferSize
, BltBuffer
);
217 if (mLogoBltBuffer
== NULL
) {
218 return EFI_OUT_OF_RESOURCES
;
221 mLogoDestX
= DestinationX
;
222 mLogoDestY
= DestinationY
;
224 mLogoHeight
= Height
;
231 Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to
232 install the Boot Graphics Resource Table.
234 @param[in] Event The Event that is being processed.
235 @param[in] Context The Event Context.
240 BgrtReadyToBootEventNotify (
246 EFI_ACPI_TABLE_PROTOCOL
*AcpiTableProtocol
;
251 // Get ACPI Table protocol.
253 Status
= gBS
->LocateProtocol (
254 &gEfiAcpiTableProtocolGuid
,
256 (VOID
**) &AcpiTableProtocol
258 if (EFI_ERROR (Status
)) {
263 // Check whether Boot Graphics Resource Table is already installed.
265 if (mAcpiBgrtInstalled
) {
266 if (!mAcpiBgrtStatusChanged
&& !mAcpiBgrtBufferChanged
) {
268 // Nothing has changed
273 // If BGRT data change happens, then uninstall orignal AcpiTable first
275 Status
= AcpiTableProtocol
->UninstallAcpiTable (
277 mBootGraphicsResourceTableKey
279 if (EFI_ERROR (Status
)) {
285 // Check whether Logo exists
287 if (mLogoBltBuffer
== NULL
) {
292 if (mAcpiBgrtBufferChanged
) {
294 // Free the old BMP image buffer
296 ImageBuffer
= (UINT8
*)(UINTN
)mBootGraphicsResourceTableTemplate
.ImageAddress
;
297 if (ImageBuffer
!= NULL
) {
298 FreePool (ImageBuffer
);
302 // Convert GOP Blt buffer to BMP image. Pass in ImageBuffer set to NULL
303 // so the BMP image is allocated by TranslateGopBltToBmp().
306 Status
= TranslateGopBltToBmp (
313 if (EFI_ERROR (Status
)) {
318 // Free the logo buffer
320 FreePool (mLogoBltBuffer
);
321 mLogoBltBuffer
= NULL
;
324 // Update BMP image fields of the Boot Graphics Resource Table
326 mBootGraphicsResourceTableTemplate
.ImageAddress
= (UINT64
)(UINTN
)ImageBuffer
;
327 mBootGraphicsResourceTableTemplate
.ImageOffsetX
= (UINT32
)mLogoDestX
;
328 mBootGraphicsResourceTableTemplate
.ImageOffsetY
= (UINT32
)mLogoDestY
;
332 // Update Status field of Boot Graphics Resource Table
335 mBootGraphicsResourceTableTemplate
.Status
= EFI_ACPI_5_0_BGRT_STATUS_VALID
;
337 mBootGraphicsResourceTableTemplate
.Status
= EFI_ACPI_5_0_BGRT_STATUS_INVALID
;
341 // Update Checksum of Boot Graphics Resource Table
343 mBootGraphicsResourceTableTemplate
.Header
.Checksum
= 0;
344 mBootGraphicsResourceTableTemplate
.Header
.Checksum
=
346 (UINT8
*)&mBootGraphicsResourceTableTemplate
,
347 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
)
351 // Publish Boot Graphics Resource Table.
353 Status
= AcpiTableProtocol
->InstallAcpiTable (
355 &mBootGraphicsResourceTableTemplate
,
356 sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE
),
357 &mBootGraphicsResourceTableKey
359 if (EFI_ERROR (Status
)) {
363 mAcpiBgrtInstalled
= TRUE
;
364 mAcpiBgrtStatusChanged
= FALSE
;
365 mAcpiBgrtBufferChanged
= FALSE
;
369 The module Entry Point of the Boot Graphics Resource Table DXE driver.
371 @param[in] ImageHandle The firmware allocated handle for the EFI image.
372 @param[in] SystemTable A pointer to the EFI System Table.
374 @retval EFI_SUCCESS The entry point is executed successfully.
375 @retval Other Some error occurs when executing this entry point.
380 BootGraphicsDxeEntryPoint (
381 IN EFI_HANDLE ImageHandle
,
382 IN EFI_SYSTEM_TABLE
*SystemTable
386 EFI_ACPI_DESCRIPTION_HEADER
*Header
;
389 // Update Header fields of Boot Graphics Resource Table from PCDs
391 Header
= &mBootGraphicsResourceTableTemplate
.Header
;
392 ZeroMem (Header
->OemId
, sizeof (Header
->OemId
));
395 PcdGetPtr (PcdAcpiDefaultOemId
),
396 MIN (PcdGetSize (PcdAcpiDefaultOemId
), sizeof (Header
->OemId
))
398 WriteUnaligned64 (&Header
->OemTableId
, PcdGet64 (PcdAcpiDefaultOemTableId
));
399 Header
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
400 Header
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
401 Header
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
404 // Install Boot Logo protocol.
406 Status
= gBS
->InstallMultipleProtocolInterfaces (
408 &gEfiBootLogoProtocolGuid
,
409 &mBootLogoProtocolTemplate
,
412 ASSERT_EFI_ERROR (Status
);
415 // Register notify function to install BGRT on ReadyToBoot Event.
417 Status
= gBS
->CreateEventEx (
420 BgrtReadyToBootEventNotify
,
422 &gEfiEventReadyToBootGuid
,
423 &mBootGraphicsReadyToBootEvent
425 ASSERT_EFI_ERROR (Status
);