1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
|
/** @file
This module install ACPI Boot Graphics Resource Table (BGRT).
Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2016, Microsoft Corporation<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <IndustryStandard/Acpi.h>
#include <Protocol/AcpiTable.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/BootLogo.h>
#include <Protocol/BootLogo2.h>
#include <Guid/EventGroup.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <Library/SafeIntLib.h>
#include <Library/BmpSupportLib.h>
/**
Update information of logo image drawn on screen.
@param[in] This The pointer to the Boot Logo protocol 2 instance.
@param[in] BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
is set to NULL, it indicates that logo image is no
longer on the screen.
@param[in] DestinationX X coordinate of destination for the BltBuffer.
@param[in] DestinationY Y coordinate of destination for the BltBuffer.
@param[in] Width Width of rectangle in BltBuffer in pixels.
@param[in] Height Hight of rectangle in BltBuffer in pixels.
@retval EFI_SUCCESS The boot logo information was updated.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
insufficient memory resources.
**/
EFI_STATUS
EFIAPI
SetBootLogo (
IN EFI_BOOT_LOGO_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height
);
/**
Update information of logo image drawn on screen.
@param[in] This The pointer to the Boot Logo protocol 2 instance.
@param[in] BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
is set to NULL, it indicates that logo image is no
longer on the screen.
@param[in] DestinationX X coordinate of destination for the BltBuffer.
@param[in] DestinationY Y coordinate of destination for the BltBuffer.
@param[in] Width Width of rectangle in BltBuffer in pixels.
@param[in] Height Hight of rectangle in BltBuffer in pixels.
@retval EFI_SUCCESS The boot logo information was updated.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
insufficient memory resources.
**/
EFI_STATUS
EFIAPI
SetBootLogo2 (
IN EDKII_BOOT_LOGO2_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height
);
/**
Get the location of the boot logo on the screen.
@param[in] This The pointer to the Boot Logo Protocol 2 instance
@param[out] BltBuffer Returns pointer to the GOP BLT buffer that was
previously registered with SetBootLogo2(). The
buffer returned must not be modified or freed.
@param[out] DestinationX Returns the X start position of the GOP BLT buffer
that was previously registered with SetBootLogo2().
@param[out] DestinationY Returns the Y start position of the GOP BLT buffer
that was previously registered with SetBootLogo2().
@param[out] Width Returns the width of the GOP BLT buffer
that was previously registered with SetBootLogo2().
@param[out] Height Returns the height of the GOP BLT buffer
that was previously registered with SetBootLogo2().
@retval EFI_SUCCESS The location of the boot logo was returned.
@retval EFI_NOT_READY The boot logo has not been set.
@retval EFI_INVALID_PARAMETER BltBuffer is NULL.
@retval EFI_INVALID_PARAMETER DestinationX is NULL.
@retval EFI_INVALID_PARAMETER DestinationY is NULL.
@retval EFI_INVALID_PARAMETER Width is NULL.
@retval EFI_INVALID_PARAMETER Height is NULL.
**/
EFI_STATUS
EFIAPI
GetBootLogo2 (
IN EDKII_BOOT_LOGO2_PROTOCOL *This,
OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **BltBuffer,
OUT UINTN *DestinationX,
OUT UINTN *DestinationY,
OUT UINTN *Width,
OUT UINTN *Height
);
//
// Boot Logo Protocol Handle
//
EFI_HANDLE mBootLogoHandle = NULL;
//
// Boot Logo Protocol Instance
//
EFI_BOOT_LOGO_PROTOCOL mBootLogoProtocolTemplate = {
SetBootLogo
};
///
/// Boot Logo 2 Protocol instance
///
EDKII_BOOT_LOGO2_PROTOCOL mBootLogo2ProtocolTemplate = {
SetBootLogo2,
GetBootLogo2
};
EFI_EVENT mBootGraphicsReadyToBootEvent;
UINTN mBootGraphicsResourceTableKey = 0;
BOOLEAN mIsLogoValid = FALSE;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *mLogoBltBuffer = NULL;
UINTN mLogoDestX = 0;
UINTN mLogoDestY = 0;
UINTN mLogoWidth = 0;
UINTN mLogoHeight = 0;
BOOLEAN mAcpiBgrtInstalled = FALSE;
BOOLEAN mAcpiBgrtStatusChanged = FALSE;
BOOLEAN mAcpiBgrtBufferChanged = FALSE;
//
// ACPI Boot Graphics Resource Table template
//
EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE mBootGraphicsResourceTableTemplate = {
{
EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE,
sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE),
EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE_REVISION, // Revision
0x00, // Checksum will be updated at runtime
//
// It is expected that these values will be updated at EntryPoint.
//
{0x00}, // OEM ID is a 6 bytes long field
0x00, // OEM Table ID(8 bytes long)
0x00, // OEM Revision
0x00, // Creator ID
0x00, // Creator Revision
},
EFI_ACPI_5_0_BGRT_VERSION, // Version
EFI_ACPI_5_0_BGRT_STATUS_VALID, // Status
EFI_ACPI_5_0_BGRT_IMAGE_TYPE_BMP, // Image Type
0, // Image Address
0, // Image Offset X
0 // Image Offset Y
};
/**
Update information of logo image drawn on screen.
@param This The pointer to the Boot Logo protocol instance.
@param BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
is set to NULL, it indicates that logo image is no
longer on the screen.
@param DestinationX X coordinate of destination for the BltBuffer.
@param DestinationY Y coordinate of destination for the BltBuffer.
@param Width Width of rectangle in BltBuffer in pixels.
@param Height Hight of rectangle in BltBuffer in pixels.
@retval EFI_SUCCESS The boot logo information was updated.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
insufficient memory resources.
**/
EFI_STATUS
EFIAPI
SetBootLogo (
IN EFI_BOOT_LOGO_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height
)
{
//
// Call same service in Boot Logo 2 Protocol
//
return SetBootLogo2 (
&mBootLogo2ProtocolTemplate,
BltBuffer,
DestinationX,
DestinationY,
Width,
Height
);
}
/**
Update information of logo image drawn on screen.
@param[in] This The pointer to the Boot Logo protocol 2 instance.
@param[in] BltBuffer The BLT buffer for logo drawn on screen. If BltBuffer
is set to NULL, it indicates that logo image is no
longer on the screen.
@param[in] DestinationX X coordinate of destination for the BltBuffer.
@param[in] DestinationY Y coordinate of destination for the BltBuffer.
@param[in] Width Width of rectangle in BltBuffer in pixels.
@param[in] Height Hight of rectangle in BltBuffer in pixels.
@retval EFI_SUCCESS The boot logo information was updated.
@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
@retval EFI_OUT_OF_RESOURCES The logo information was not updated due to
insufficient memory resources.
**/
EFI_STATUS
EFIAPI
SetBootLogo2 (
IN EDKII_BOOT_LOGO2_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height
)
{
EFI_STATUS Status;
UINTN BufferSize;
UINT32 Result32;
if (BltBuffer == NULL) {
mIsLogoValid = FALSE;
mAcpiBgrtStatusChanged = TRUE;
return EFI_SUCCESS;
}
//
// Width and height are not allowed to be zero.
//
if (Width == 0 || Height == 0) {
return EFI_INVALID_PARAMETER;
}
//
// Verify destination, width, and height do not overflow 32-bit values.
// The Boot Graphics Resource Table only has 32-bit fields for these values.
//
Status = SafeUintnToUint32 (DestinationX, &Result32);
if (EFI_ERROR (Status)) {
return EFI_INVALID_PARAMETER;
}
Status = SafeUintnToUint32 (DestinationY, &Result32);
if (EFI_ERROR (Status)) {
return EFI_INVALID_PARAMETER;
}
Status = SafeUintnToUint32 (Width, &Result32);
if (EFI_ERROR (Status)) {
return EFI_INVALID_PARAMETER;
}
Status = SafeUintnToUint32 (Height, &Result32);
if (EFI_ERROR (Status)) {
return EFI_INVALID_PARAMETER;
}
//
// Ensure the Height * Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) does
// not overflow UINTN
//
Status = SafeUintnMult (
Width,
Height,
&BufferSize
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
Status = SafeUintnMult (
BufferSize,
sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL),
&BufferSize
);
if (EFI_ERROR (Status)) {
return EFI_UNSUPPORTED;
}
//
// Update state
//
mAcpiBgrtBufferChanged = TRUE;
//
// Free old logo buffer
//
if (mLogoBltBuffer != NULL) {
FreePool (mLogoBltBuffer);
mLogoBltBuffer = NULL;
}
//
// Allocate new logo buffer
//
mLogoBltBuffer = AllocateCopyPool (BufferSize, BltBuffer);
if (mLogoBltBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
mLogoDestX = DestinationX;
mLogoDestY = DestinationY;
mLogoWidth = Width;
mLogoHeight = Height;
mIsLogoValid = TRUE;
return EFI_SUCCESS;
}
/**
Get the location of the boot logo on the screen.
@param[in] This The pointer to the Boot Logo Protocol 2 instance
@param[out] BltBuffer Returns pointer to the GOP BLT buffer that was
previously registered with SetBootLogo2(). The
buffer returned must not be modified or freed.
@param[out] DestinationX Returns the X start position of the GOP BLT buffer
that was previously registered with SetBootLogo2().
@param[out] DestinationY Returns the Y start position of the GOP BLT buffer
that was previously registered with SetBootLogo2().
@param[out] Width Returns the width of the GOP BLT buffer
that was previously registered with SetBootLogo2().
@param[out] Height Returns the height of the GOP BLT buffer
that was previously registered with SetBootLogo2().
@retval EFI_SUCCESS The location of the boot logo was returned.
@retval EFI_NOT_READY The boot logo has not been set.
@retval EFI_INVALID_PARAMETER BltBuffer is NULL.
@retval EFI_INVALID_PARAMETER DestinationX is NULL.
@retval EFI_INVALID_PARAMETER DestinationY is NULL.
@retval EFI_INVALID_PARAMETER Width is NULL.
@retval EFI_INVALID_PARAMETER Height is NULL.
**/
EFI_STATUS
EFIAPI
GetBootLogo2 (
IN EDKII_BOOT_LOGO2_PROTOCOL *This,
OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **BltBuffer,
OUT UINTN *DestinationX,
OUT UINTN *DestinationY,
OUT UINTN *Width,
OUT UINTN *Height
)
{
//
// If the boot logo has not been set with SetBootLogo() or SetBootLogo() was
// called with a NULL BltBuffer then the boot logo is not valid and
// EFI_NOT_READY is returned.
//
if (mLogoBltBuffer == NULL) {
DEBUG ((DEBUG_ERROR, "Request to get boot logo location before boot logo has been set.\n"));
return EFI_NOT_READY;
}
//
// Make sure none of the boot logo location parameters are NULL.
//
if (BltBuffer == NULL || DestinationX == NULL || DestinationY == NULL ||
Width == NULL || Height == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Boot logo is valid. Return values from module globals.
//
*BltBuffer = mLogoBltBuffer;
*DestinationX = mLogoDestX;
*DestinationY = mLogoDestY;
*Width = mLogoWidth;
*Height = mLogoHeight;
return EFI_SUCCESS;
}
/**
Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to
install the Boot Graphics Resource Table.
@param[in] Event The Event that is being processed.
@param[in] Context The Event Context.
**/
VOID
EFIAPI
BgrtReadyToBootEventNotify (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
VOID *ImageBuffer;
UINT32 BmpSize;
//
// Get ACPI Table protocol.
//
Status = gBS->LocateProtocol (
&gEfiAcpiTableProtocolGuid,
NULL,
(VOID **) &AcpiTableProtocol
);
if (EFI_ERROR (Status)) {
return;
}
//
// Check whether Boot Graphics Resource Table is already installed.
//
if (mAcpiBgrtInstalled) {
if (!mAcpiBgrtStatusChanged && !mAcpiBgrtBufferChanged) {
//
// Nothing has changed
//
return;
} else {
//
// If BGRT data change happens, then uninstall orignal AcpiTable first
//
Status = AcpiTableProtocol->UninstallAcpiTable (
AcpiTableProtocol,
mBootGraphicsResourceTableKey
);
if (EFI_ERROR (Status)) {
return;
}
}
} else {
//
// Check whether Logo exists
//
if (mLogoBltBuffer == NULL) {
return;
}
}
if (mAcpiBgrtBufferChanged) {
//
// Free the old BMP image buffer
//
ImageBuffer = (UINT8 *)(UINTN)mBootGraphicsResourceTableTemplate.ImageAddress;
if (ImageBuffer != NULL) {
FreePool (ImageBuffer);
}
//
// Convert GOP Blt buffer to BMP image. Pass in ImageBuffer set to NULL
// so the BMP image is allocated by TranslateGopBltToBmp().
//
ImageBuffer = NULL;
Status = TranslateGopBltToBmp (
mLogoBltBuffer,
(UINT32)mLogoHeight,
(UINT32)mLogoWidth,
&ImageBuffer,
&BmpSize
);
if (EFI_ERROR (Status)) {
return;
}
//
// Free the logo buffer
//
FreePool (mLogoBltBuffer);
mLogoBltBuffer = NULL;
//
// Update BMP image fields of the Boot Graphics Resource Table
//
mBootGraphicsResourceTableTemplate.ImageAddress = (UINT64)(UINTN)ImageBuffer;
mBootGraphicsResourceTableTemplate.ImageOffsetX = (UINT32)mLogoDestX;
mBootGraphicsResourceTableTemplate.ImageOffsetY = (UINT32)mLogoDestY;
}
//
// Update Status field of Boot Graphics Resource Table
//
if (mIsLogoValid) {
mBootGraphicsResourceTableTemplate.Status = EFI_ACPI_5_0_BGRT_STATUS_VALID;
} else {
mBootGraphicsResourceTableTemplate.Status = EFI_ACPI_5_0_BGRT_STATUS_INVALID;
}
//
// Update Checksum of Boot Graphics Resource Table
//
mBootGraphicsResourceTableTemplate.Header.Checksum = 0;
mBootGraphicsResourceTableTemplate.Header.Checksum =
CalculateCheckSum8 (
(UINT8 *)&mBootGraphicsResourceTableTemplate,
sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE)
);
//
// Publish Boot Graphics Resource Table.
//
Status = AcpiTableProtocol->InstallAcpiTable (
AcpiTableProtocol,
&mBootGraphicsResourceTableTemplate,
sizeof (EFI_ACPI_5_0_BOOT_GRAPHICS_RESOURCE_TABLE),
&mBootGraphicsResourceTableKey
);
if (EFI_ERROR (Status)) {
return;
}
mAcpiBgrtInstalled = TRUE;
mAcpiBgrtStatusChanged = FALSE;
mAcpiBgrtBufferChanged = FALSE;
}
/**
The module Entry Point of the Boot Graphics Resource Table DXE driver.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval Other Some error occurs when executing this entry point.
**/
EFI_STATUS
EFIAPI
BootGraphicsDxeEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
EFI_ACPI_DESCRIPTION_HEADER *Header;
//
// Update Header fields of Boot Graphics Resource Table from PCDs
//
Header = &mBootGraphicsResourceTableTemplate.Header;
ZeroMem (Header->OemId, sizeof (Header->OemId));
CopyMem (
Header->OemId,
PcdGetPtr (PcdAcpiDefaultOemId),
MIN (PcdGetSize (PcdAcpiDefaultOemId), sizeof (Header->OemId))
);
WriteUnaligned64 (&Header->OemTableId, PcdGet64 (PcdAcpiDefaultOemTableId));
Header->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
Header->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
Header->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
//
// Install Boot Logo and Boot Logo 2 Protocols.
//
Status = gBS->InstallMultipleProtocolInterfaces (
&mBootLogoHandle,
&gEfiBootLogoProtocolGuid,
&mBootLogoProtocolTemplate,
&gEdkiiBootLogo2ProtocolGuid,
&mBootLogo2ProtocolTemplate,
NULL
);
ASSERT_EFI_ERROR (Status);
//
// Register notify function to install BGRT on ReadyToBoot Event.
//
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
BgrtReadyToBootEventNotify,
NULL,
&gEfiEventReadyToBootGuid,
&mBootGraphicsReadyToBootEvent
);
ASSERT_EFI_ERROR (Status);
return Status;
}
|