]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/Override/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
Vlv2TbltDevicePkg/Override/GenericBdsLib: Use BmpSupportLib
[mirror_edk2.git] / Vlv2TbltDevicePkg / Override / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsConsole.c
1 /** @file
2 BDS Lib functions which contain all the code to connect console device
3
4 Copyright (c) 2004 - 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
9
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.
12
13 **/
14
15 #include "InternalBdsLib.h"
16
17
18 /**
19 Check if we need to save the EFI variable with "ConVarName" as name
20 as NV type
21 If ConVarName is NULL, then ASSERT().
22
23 @param ConVarName The name of the EFI variable.
24
25 @retval TRUE Set the EFI variable as NV type.
26 @retval FALSE EFI variable as NV type can be set NonNV.
27 **/
28 BOOLEAN
29 IsNvNeed (
30 IN CHAR16 *ConVarName
31 )
32 {
33 CHAR16 *Ptr;
34
35 ASSERT (ConVarName != NULL);
36
37 Ptr = ConVarName;
38
39 //
40 // If the variable includes "Dev" at last, we consider
41 // it does not support NV attribute.
42 //
43 while (*Ptr != L'\0') {
44 Ptr++;
45 }
46
47 if (((INTN)((UINTN)Ptr - (UINTN)ConVarName) / sizeof (CHAR16)) <= 3) {
48 return TRUE;
49 }
50
51 if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) {
52 return FALSE;
53 } else {
54 return TRUE;
55 }
56 }
57
58 /**
59 Fill console handle in System Table if there are no valid console handle in.
60
61 Firstly, check the validation of console handle in System Table. If it is invalid,
62 update it by the first console device handle from EFI console variable.
63
64 @param VarName The name of the EFI console variable.
65 @param ConsoleGuid Specified Console protocol GUID.
66 @param ConsoleHandle On IN, console handle in System Table to be checked.
67 On OUT, new console handle in system table.
68 @param ProtocolInterface On IN, console protocol on console handle in System Table to be checked.
69 On OUT, new console protocol on new console handle in system table.
70
71 @retval TRUE System Table has been updated.
72 @retval FALSE System Table hasn't been updated.
73
74 **/
75 BOOLEAN
76 UpdateSystemTableConsole (
77 IN CHAR16 *VarName,
78 IN EFI_GUID *ConsoleGuid,
79 IN OUT EFI_HANDLE *ConsoleHandle,
80 IN OUT VOID **ProtocolInterface
81 )
82 {
83 EFI_STATUS Status;
84 UINTN DevicePathSize;
85 EFI_DEVICE_PATH_PROTOCOL *FullDevicePath;
86 EFI_DEVICE_PATH_PROTOCOL *VarConsole;
87 EFI_DEVICE_PATH_PROTOCOL *Instance;
88 VOID *Interface;
89 EFI_HANDLE NewHandle;
90 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
91
92 ASSERT (VarName != NULL);
93 ASSERT (ConsoleHandle != NULL);
94 ASSERT (ConsoleGuid != NULL);
95 ASSERT (ProtocolInterface != NULL);
96
97 if (*ConsoleHandle != NULL) {
98 Status = gBS->HandleProtocol (
99 *ConsoleHandle,
100 ConsoleGuid,
101 &Interface
102 );
103 if (Status == EFI_SUCCESS && Interface == *ProtocolInterface) {
104 //
105 // If ConsoleHandle is valid and console protocol on this handle also
106 // also matched, just return.
107 //
108 return FALSE;
109 }
110 }
111
112 //
113 // Get all possible consoles device path from EFI variable
114 //
115 VarConsole = BdsLibGetVariableAndSize (
116 VarName,
117 &gEfiGlobalVariableGuid,
118 &DevicePathSize
119 );
120 if (VarConsole == NULL) {
121 //
122 // If there is no any console device, just return.
123 //
124 return FALSE;
125 }
126
127 FullDevicePath = VarConsole;
128
129 do {
130 //
131 // Check every instance of the console variable
132 //
133 Instance = GetNextDevicePathInstance (&VarConsole, &DevicePathSize);
134 if (Instance == NULL) {
135 FreePool (FullDevicePath);
136 ASSERT (FALSE);
137 }
138
139 //
140 // Find console device handle by device path instance
141 //
142 Status = gBS->LocateDevicePath (
143 ConsoleGuid,
144 &Instance,
145 &NewHandle
146 );
147 if (!EFI_ERROR (Status)) {
148 //
149 // Get the console protocol on this console device handle
150 //
151 Status = gBS->HandleProtocol (
152 NewHandle,
153 ConsoleGuid,
154 &Interface
155 );
156 if (!EFI_ERROR (Status)) {
157 //
158 // Update new console handle in System Table.
159 //
160 *ConsoleHandle = NewHandle;
161 *ProtocolInterface = Interface;
162 if (CompareGuid (ConsoleGuid, &gEfiSimpleTextOutProtocolGuid)) {
163 //
164 // If it is console out device, set console mode 80x25 if current mode is invalid.
165 //
166 TextOut = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *) Interface;
167 if (TextOut->Mode->Mode == -1) {
168 TextOut->SetMode (TextOut, 0);
169 }
170 }
171 return TRUE;
172 }
173 }
174
175 } while (Instance != NULL);
176
177 //
178 // No any available console devcie found.
179 //
180 return FALSE;
181 }
182
183 /**
184 This function update console variable based on ConVarName, it can
185 add or remove one specific console device path from the variable
186
187 @param ConVarName Console related variable name, ConIn, ConOut,
188 ErrOut.
189 @param CustomizedConDevicePath The console device path which will be added to
190 the console variable ConVarName, this parameter
191 can not be multi-instance.
192 @param ExclusiveDevicePath The console device path which will be removed
193 from the console variable ConVarName, this
194 parameter can not be multi-instance.
195
196 @retval EFI_UNSUPPORTED The added device path is same to the removed one.
197 @retval EFI_SUCCESS Success add or remove the device path from the
198 console variable.
199
200 **/
201 EFI_STATUS
202 EFIAPI
203 BdsLibUpdateConsoleVariable (
204 IN CHAR16 *ConVarName,
205 IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,
206 IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath
207 )
208 {
209 EFI_STATUS Status;
210 EFI_DEVICE_PATH_PROTOCOL *VarConsole;
211 UINTN DevicePathSize;
212 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
213 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
214 UINT32 Attributes;
215
216 VarConsole = NULL;
217 DevicePathSize = 0;
218
219 //
220 // Notes: check the device path point, here should check
221 // with compare memory
222 //
223 if (CustomizedConDevicePath == ExclusiveDevicePath) {
224 return EFI_UNSUPPORTED;
225 }
226 //
227 // Delete the ExclusiveDevicePath from current default console
228 //
229 VarConsole = BdsLibGetVariableAndSize (
230 ConVarName,
231 &gEfiGlobalVariableGuid,
232 &DevicePathSize
233 );
234
235 //
236 // Initialize NewDevicePath
237 //
238 NewDevicePath = VarConsole;
239
240 //
241 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
242 // In the end, NewDevicePath is the final device path.
243 //
244 if (ExclusiveDevicePath != NULL && VarConsole != NULL) {
245 NewDevicePath = BdsLibDelPartMatchInstance (VarConsole, ExclusiveDevicePath);
246 }
247 //
248 // Try to append customized device path to NewDevicePath.
249 //
250 if (CustomizedConDevicePath != NULL) {
251 if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) {
252 //
253 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
254 //
255 NewDevicePath = BdsLibDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath);
256 //
257 // In the first check, the default console variable will be _ModuleEntryPoint,
258 // just append current customized device path
259 //
260 TempNewDevicePath = NewDevicePath;
261 NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath);
262 if (TempNewDevicePath != NULL) {
263 FreePool(TempNewDevicePath);
264 }
265 }
266 }
267
268 //
269 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
270 //
271 if (IsNvNeed(ConVarName)) {
272 //
273 // ConVarName has NV attribute.
274 //
275 Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
276 } else {
277 //
278 // ConVarName does not have NV attribute.
279 //
280 Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
281 }
282
283 //
284 // Finally, Update the variable of the default console by NewDevicePath
285 //
286 DevicePathSize = GetDevicePathSize (NewDevicePath);
287 Status = SetVariableAndReportStatusCodeOnError (
288 ConVarName,
289 &gEfiGlobalVariableGuid,
290 Attributes,
291 DevicePathSize,
292 NewDevicePath
293 );
294 if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {
295 Status = EFI_SUCCESS;
296 }
297
298 if (VarConsole == NewDevicePath) {
299 if (VarConsole != NULL) {
300 FreePool(VarConsole);
301 }
302 } else {
303 if (VarConsole != NULL) {
304 FreePool(VarConsole);
305 }
306 if (NewDevicePath != NULL) {
307 FreePool(NewDevicePath);
308 }
309 }
310
311 return Status;
312
313 }
314
315
316 /**
317 Connect the console device base on the variable ConVarName, if
318 device path of the ConVarName is multi-instance device path and
319 anyone of the instances is connected success, then this function
320 will return success.
321 If the handle associate with one device path node can not
322 be created successfully, then still give chance to do the dispatch,
323 which load the missing drivers if possible..
324
325 @param ConVarName Console related variable name, ConIn, ConOut,
326 ErrOut.
327
328 @retval EFI_NOT_FOUND There is not any console devices connected
329 success
330 @retval EFI_SUCCESS Success connect any one instance of the console
331 device path base on the variable ConVarName.
332
333 **/
334 EFI_STATUS
335 EFIAPI
336 BdsLibConnectConsoleVariable (
337 IN CHAR16 *ConVarName
338 )
339 {
340 EFI_STATUS Status;
341 EFI_DEVICE_PATH_PROTOCOL *StartDevicePath;
342 UINTN VariableSize;
343 EFI_DEVICE_PATH_PROTOCOL *Instance;
344 EFI_DEVICE_PATH_PROTOCOL *Next;
345 EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath;
346 UINTN Size;
347 BOOLEAN DeviceExist;
348
349 Status = EFI_SUCCESS;
350 DeviceExist = FALSE;
351
352 //
353 // Check if the console variable exist
354 //
355 StartDevicePath = BdsLibGetVariableAndSize (
356 ConVarName,
357 &gEfiGlobalVariableGuid,
358 &VariableSize
359 );
360 if (StartDevicePath == NULL) {
361 return EFI_UNSUPPORTED;
362 }
363
364 CopyOfDevicePath = StartDevicePath;
365 do {
366 //
367 // Check every instance of the console variable
368 //
369 Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);
370 if (Instance == NULL) {
371 FreePool (StartDevicePath);
372 return EFI_UNSUPPORTED;
373 }
374
375 Next = Instance;
376 while (!IsDevicePathEndType (Next)) {
377 Next = NextDevicePathNode (Next);
378 }
379
380 SetDevicePathEndNode (Next);
381 //
382 // Connect the USB console
383 // USB console device path is a short-form device path that
384 // starts with the first element being a USB WWID
385 // or a USB Class device path
386 //
387 if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&
388 ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)
389 || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)
390 )) {
391 Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance);
392 if (!EFI_ERROR (Status)) {
393 DeviceExist = TRUE;
394 }
395 } else {
396 //
397 // Connect the instance device path
398 //
399 Status = BdsLibConnectDevicePath (Instance);
400
401 if (EFI_ERROR (Status)) {
402 //
403 // Delete the instance from the console varialbe
404 //
405 BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);
406 } else {
407 DeviceExist = TRUE;
408 }
409 }
410 FreePool(Instance);
411 } while (CopyOfDevicePath != NULL);
412
413 FreePool (StartDevicePath);
414
415 if (!DeviceExist) {
416 return EFI_NOT_FOUND;
417 }
418
419 return EFI_SUCCESS;
420 }
421
422 /**
423 This function will search every simpletext device in current system,
424 and make every simpletext device as pertantial console device.
425
426 **/
427 VOID
428 EFIAPI
429 BdsLibConnectAllConsoles (
430 VOID
431 )
432 {
433 UINTN Index;
434 EFI_DEVICE_PATH_PROTOCOL *ConDevicePath;
435 UINTN HandleCount;
436 EFI_HANDLE *HandleBuffer;
437
438 Index = 0;
439 HandleCount = 0;
440 HandleBuffer = NULL;
441 ConDevicePath = NULL;
442
443 //
444 // Update all the console variables
445 //
446 gBS->LocateHandleBuffer (
447 ByProtocol,
448 &gEfiSimpleTextInProtocolGuid,
449 NULL,
450 &HandleCount,
451 &HandleBuffer
452 );
453
454 for (Index = 0; Index < HandleCount; Index++) {
455 gBS->HandleProtocol (
456 HandleBuffer[Index],
457 &gEfiDevicePathProtocolGuid,
458 (VOID **) &ConDevicePath
459 );
460 BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);
461 }
462
463 if (HandleBuffer != NULL) {
464 FreePool(HandleBuffer);
465 HandleBuffer = NULL;
466 }
467
468 gBS->LocateHandleBuffer (
469 ByProtocol,
470 &gEfiSimpleTextOutProtocolGuid,
471 NULL,
472 &HandleCount,
473 &HandleBuffer
474 );
475 for (Index = 0; Index < HandleCount; Index++) {
476 gBS->HandleProtocol (
477 HandleBuffer[Index],
478 &gEfiDevicePathProtocolGuid,
479 (VOID **) &ConDevicePath
480 );
481 BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL);
482 BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);
483 }
484
485 if (HandleBuffer != NULL) {
486 FreePool(HandleBuffer);
487 }
488
489 //
490 // Connect all console variables
491 //
492 BdsLibConnectAllDefaultConsoles ();
493
494 }
495
496 /**
497 This function will connect console device base on the console
498 device variable ConIn, ConOut and ErrOut.
499
500 @retval EFI_SUCCESS At least one of the ConIn and ConOut device have
501 been connected success.
502 @retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().
503
504 **/
505 EFI_STATUS
506 EFIAPI
507 BdsLibConnectAllDefaultConsoles (
508 VOID
509 )
510 {
511 EFI_STATUS Status;
512 BOOLEAN SystemTableUpdated;
513
514 //
515 // Connect all default console variables
516 //
517
518 //
519 // It seems impossible not to have any ConOut device on platform,
520 // so we check the status here.
521 //
522 Status = BdsLibConnectConsoleVariable (L"ConOut");
523 if (EFI_ERROR (Status)) {
524 return Status;
525 }
526
527 //
528 // Insert the performance probe for Console Out
529 //
530 PERF_START (NULL, "ConOut", "BDS", 1);
531 PERF_END (NULL, "ConOut", "BDS", 0);
532
533 //
534 // Because possibly the platform is legacy free, in such case,
535 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
536 // so we need not check the status.
537 //
538 BdsLibConnectConsoleVariable (L"ConIn");
539
540 //
541 // The _ModuleEntryPoint err out var is legal.
542 //
543 BdsLibConnectConsoleVariable (L"ErrOut");
544
545 SystemTableUpdated = FALSE;
546 //
547 // Fill console handles in System Table if no console device assignd.
548 //
549 if (UpdateSystemTableConsole (L"ConIn", &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **) &gST->ConIn)) {
550 SystemTableUpdated = TRUE;
551 }
552 if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {
553 SystemTableUpdated = TRUE;
554 }
555 if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) {
556 SystemTableUpdated = TRUE;
557 }
558
559 if (SystemTableUpdated) {
560 //
561 // Update the CRC32 in the EFI System Table header
562 //
563 gST->Hdr.CRC32 = 0;
564 gBS->CalculateCrc32 (
565 (UINT8 *) &gST->Hdr,
566 gST->Hdr.HeaderSize,
567 &gST->Hdr.CRC32
568 );
569 }
570
571 return EFI_SUCCESS;
572
573 }
574
575 /**
576 This function will connect console device except ConIn base on the console
577 device variable ConOut and ErrOut.
578
579 @retval EFI_SUCCESS At least one of the ConOut device have
580 been connected success.
581 @retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().
582
583 **/
584 EFI_STATUS
585 EFIAPI
586 BdsLibConnectAllDefaultConsolesWithOutConIn (
587 VOID
588 )
589 {
590 EFI_STATUS Status;
591 BOOLEAN SystemTableUpdated;
592
593 //
594 // Connect all default console variables except ConIn
595 //
596
597 //
598 // It seems impossible not to have any ConOut device on platform,
599 // so we check the status here.
600 //
601 Status = BdsLibConnectConsoleVariable (L"ConOut");
602 if (EFI_ERROR (Status)) {
603 return Status;
604 }
605
606 //
607 // Insert the performance probe for Console Out
608 //
609 PERF_START (NULL, "ConOut", "BDS", 1);
610 PERF_END (NULL, "ConOut", "BDS", 0);
611
612 //
613 // The _ModuleEntryPoint err out var is legal.
614 //
615 BdsLibConnectConsoleVariable (L"ErrOut");
616
617 SystemTableUpdated = FALSE;
618 //
619 // Fill console handles in System Table if no console device assignd.
620 //
621 if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {
622 SystemTableUpdated = TRUE;
623 }
624 if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) {
625 SystemTableUpdated = TRUE;
626 }
627
628 if (SystemTableUpdated) {
629 //
630 // Update the CRC32 in the EFI System Table header
631 //
632 gST->Hdr.CRC32 = 0;
633 gBS->CalculateCrc32 (
634 (UINT8 *) &gST->Hdr,
635 gST->Hdr.HeaderSize,
636 &gST->Hdr.CRC32
637 );
638 }
639
640 return EFI_SUCCESS;
641
642 }
643
644 /**
645 Use SystemTable Conout to stop video based Simple Text Out consoles from going
646 to the video device. Put up LogoFile on every video device that is a console.
647
648 @param[in] LogoFile File name of logo to display on the center of the screen.
649
650 @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed.
651 @retval EFI_UNSUPPORTED Logo not found
652
653 **/
654 EFI_STATUS
655 EFIAPI
656 EnableQuietBoot (
657 IN EFI_GUID *LogoFile
658 )
659 {
660 EFI_STATUS Status;
661 EFI_OEM_BADGING_PROTOCOL *Badging;
662 UINT32 SizeOfX;
663 UINT32 SizeOfY;
664 INTN DestX;
665 INTN DestY;
666 UINT8 *ImageData;
667 UINTN ImageSize;
668 UINTN BltSize;
669 UINT32 Instance;
670 EFI_BADGING_FORMAT Format;
671 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;
672 UINTN CoordinateX;
673 UINTN CoordinateY;
674 UINTN Height;
675 UINTN Width;
676 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
677 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
678 UINT32 ColorDepth;
679 UINT32 RefreshRate;
680 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
681 EFI_BOOT_LOGO_PROTOCOL *BootLogo;
682 UINTN NumberOfLogos;
683 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LogoBlt;
684 UINTN LogoDestX;
685 UINTN LogoDestY;
686 UINTN LogoHeight;
687 UINTN LogoWidth;
688 UINTN NewDestX;
689 UINTN NewDestY;
690 UINTN NewHeight;
691 UINTN NewWidth;
692 UINT64 BufferSize;
693
694 UgaDraw = NULL;
695 //
696 // Try to open GOP first
697 //
698 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);
699 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
700 GraphicsOutput = NULL;
701 //
702 // Open GOP failed, try to open UGA
703 //
704 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);
705 }
706 if (EFI_ERROR (Status)) {
707 return EFI_UNSUPPORTED;
708 }
709
710 //
711 // Try to open Boot Logo Protocol.
712 //
713 BootLogo = NULL;
714 gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);
715
716 //
717 // Erase Cursor from screen
718 //
719 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
720
721 Badging = NULL;
722 Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);
723
724 if (GraphicsOutput != NULL) {
725 SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
726 SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
727
728 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
729 Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
730 if (EFI_ERROR (Status)) {
731 return EFI_UNSUPPORTED;
732 }
733 } else {
734 return EFI_UNSUPPORTED;
735 }
736
737 Blt = NULL;
738 NumberOfLogos = 0;
739 LogoDestX = 0;
740 LogoDestY = 0;
741 LogoHeight = 0;
742 LogoWidth = 0;
743 NewDestX = 0;
744 NewDestY = 0;
745 NewHeight = 0;
746 NewWidth = 0;
747 Instance = 0;
748 while (1) {
749 ImageData = NULL;
750 ImageSize = 0;
751
752 if (Badging != NULL) {
753 //
754 // Get image from OEMBadging protocol.
755 //
756 Status = Badging->GetImage (
757 Badging,
758 &Instance,
759 &Format,
760 &ImageData,
761 &ImageSize,
762 &Attribute,
763 &CoordinateX,
764 &CoordinateY
765 );
766 if (EFI_ERROR (Status)) {
767 goto Done;
768 }
769
770 //
771 // Currently only support BMP format.
772 //
773 if (Format != EfiBadgingFormatBMP) {
774 if (ImageData != NULL) {
775 FreePool (ImageData);
776 }
777 continue;
778 }
779 } else {
780 //
781 // Get the specified image from FV.
782 //
783 Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize);
784 if (EFI_ERROR (Status)) {
785 return EFI_UNSUPPORTED;
786 }
787
788 CoordinateX = 0;
789 CoordinateY = 0;
790 if (!FeaturePcdGet(PcdBootlogoOnlyEnable)) {
791 Attribute = EfiBadgingDisplayAttributeCenter;
792 } else {
793 Attribute = EfiBadgingDisplayAttributeCustomized;
794 }
795 }
796
797 if (Blt != NULL) {
798 FreePool (Blt);
799 }
800 Blt = NULL;
801 Status = TranslateBmpToGopBlt (
802 ImageData,
803 ImageSize,
804 &Blt,
805 &BltSize,
806 &Height,
807 &Width
808 );
809 if (EFI_ERROR (Status)) {
810 FreePool (ImageData);
811
812 if (Badging == NULL) {
813 return Status;
814 } else {
815 continue;
816 }
817 }
818
819 //
820 // Calculate the display position according to Attribute.
821 //
822 switch (Attribute) {
823 case EfiBadgingDisplayAttributeLeftTop:
824 DestX = CoordinateX;
825 DestY = CoordinateY;
826 break;
827
828 case EfiBadgingDisplayAttributeCenterTop:
829 DestX = (SizeOfX - Width) / 2;
830 DestY = CoordinateY;
831 break;
832
833 case EfiBadgingDisplayAttributeRightTop:
834 DestX = (SizeOfX - Width - CoordinateX);
835 DestY = CoordinateY;;
836 break;
837
838 case EfiBadgingDisplayAttributeCenterRight:
839 DestX = (SizeOfX - Width - CoordinateX);
840 DestY = (SizeOfY - Height) / 2;
841 break;
842
843 case EfiBadgingDisplayAttributeRightBottom:
844 DestX = (SizeOfX - Width - CoordinateX);
845 DestY = (SizeOfY - Height - CoordinateY);
846 break;
847
848 case EfiBadgingDisplayAttributeCenterBottom:
849 DestX = (SizeOfX - Width) / 2;
850 DestY = (SizeOfY - Height - CoordinateY);
851 break;
852
853 case EfiBadgingDisplayAttributeLeftBottom:
854 DestX = CoordinateX;
855 DestY = (SizeOfY - Height - CoordinateY);
856 break;
857
858 case EfiBadgingDisplayAttributeCenterLeft:
859 DestX = CoordinateX;
860 DestY = (SizeOfY - Height) / 2;
861 break;
862
863 case EfiBadgingDisplayAttributeCenter:
864 DestX = (SizeOfX - Width) / 2;
865 DestY = (SizeOfY - Height) / 2;
866 break;
867
868 case EfiBadgingDisplayAttributeCustomized:
869 DestX = (SizeOfX - Width) / 2;
870 DestY = ((SizeOfY * 382) / 1000) - Height / 2;
871 break;
872
873 default:
874 DestX = CoordinateX;
875 DestY = CoordinateY;
876 break;
877 }
878
879 if ((DestX >= 0) && (DestY >= 0)) {
880 if (GraphicsOutput != NULL) {
881 Status = GraphicsOutput->Blt (
882 GraphicsOutput,
883 Blt,
884 EfiBltBufferToVideo,
885 0,
886 0,
887 (UINTN) DestX,
888 (UINTN) DestY,
889 Width,
890 Height,
891 Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
892 );
893 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
894 Status = UgaDraw->Blt (
895 UgaDraw,
896 (EFI_UGA_PIXEL *) Blt,
897 EfiUgaBltBufferToVideo,
898 0,
899 0,
900 (UINTN) DestX,
901 (UINTN) DestY,
902 Width,
903 Height,
904 Width * sizeof (EFI_UGA_PIXEL)
905 );
906 } else {
907 Status = EFI_UNSUPPORTED;
908 }
909
910 //
911 // Report displayed Logo information.
912 //
913 if (!EFI_ERROR (Status)) {
914 NumberOfLogos++;
915
916 if (LogoWidth == 0) {
917 //
918 // The first Logo.
919 //
920 LogoDestX = (UINTN) DestX;
921 LogoDestY = (UINTN) DestY;
922 LogoWidth = Width;
923 LogoHeight = Height;
924 } else {
925 //
926 // Merge new logo with old one.
927 //
928 NewDestX = MIN ((UINTN) DestX, LogoDestX);
929 NewDestY = MIN ((UINTN) DestY, LogoDestY);
930 NewWidth = MAX ((UINTN) DestX + Width, LogoDestX + LogoWidth) - NewDestX;
931 NewHeight = MAX ((UINTN) DestY + Height, LogoDestY + LogoHeight) - NewDestY;
932
933 LogoDestX = NewDestX;
934 LogoDestY = NewDestY;
935 LogoWidth = NewWidth;
936 LogoHeight = NewHeight;
937 }
938 }
939 }
940
941 FreePool (ImageData);
942
943 if (Badging == NULL) {
944 break;
945 }
946 }
947
948 Done:
949 if (BootLogo == NULL || NumberOfLogos == 0) {
950 //
951 // No logo displayed.
952 //
953 if (Blt != NULL) {
954 FreePool (Blt);
955 }
956
957 return Status;
958 }
959
960 //
961 // Advertise displayed Logo information.
962 //
963 if (NumberOfLogos == 1) {
964 //
965 // Only one logo displayed, use its Blt buffer directly for BootLogo protocol.
966 //
967 LogoBlt = Blt;
968 Status = EFI_SUCCESS;
969 } else {
970 //
971 // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation.
972 //
973 if (Blt != NULL) {
974 FreePool (Blt);
975 }
976
977 //
978 // Ensure the LogoHeight * LogoWidth doesn't overflow
979 //
980 if (LogoHeight > DivU64x64Remainder ((UINTN) ~0, LogoWidth, NULL)) {
981 return EFI_UNSUPPORTED;
982 }
983 BufferSize = MultU64x64 (LogoWidth, LogoHeight);
984
985 //
986 // Ensure the BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
987 //
988 if (BufferSize > DivU64x32 ((UINTN) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
989 return EFI_UNSUPPORTED;
990 }
991
992 LogoBlt = AllocateZeroPool ((UINTN)BufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
993 if (LogoBlt == NULL) {
994 return EFI_OUT_OF_RESOURCES;
995 }
996
997 if (GraphicsOutput != NULL) {
998 Status = GraphicsOutput->Blt (
999 GraphicsOutput,
1000 LogoBlt,
1001 EfiBltVideoToBltBuffer,
1002 LogoDestX,
1003 LogoDestY,
1004 0,
1005 0,
1006 LogoWidth,
1007 LogoHeight,
1008 LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1009 );
1010 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
1011 Status = UgaDraw->Blt (
1012 UgaDraw,
1013 (EFI_UGA_PIXEL *) LogoBlt,
1014 EfiUgaVideoToBltBuffer,
1015 LogoDestX,
1016 LogoDestY,
1017 0,
1018 0,
1019 LogoWidth,
1020 LogoHeight,
1021 LogoWidth * sizeof (EFI_UGA_PIXEL)
1022 );
1023 } else {
1024 Status = EFI_UNSUPPORTED;
1025 }
1026 }
1027
1028 if (!EFI_ERROR (Status)) {
1029 BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight);
1030 }
1031 FreePool (LogoBlt);
1032
1033 return Status;
1034 }
1035
1036 /**
1037 Use SystemTable Conout to turn on video based Simple Text Out consoles. The
1038 Simple Text Out screens will now be synced up with all non video output devices
1039
1040 @retval EFI_SUCCESS UGA devices are back in text mode and synced up.
1041
1042 **/
1043 EFI_STATUS
1044 EFIAPI
1045 DisableQuietBoot (
1046 VOID
1047 )
1048 {
1049
1050 //
1051 // Enable Cursor on Screen
1052 //
1053 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
1054 return EFI_SUCCESS;
1055 }
1056