]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/GenericBdsLib/BdsConsole.c
Synchronize GenericBdsLib library class's header file to library instance.
[mirror_edk2.git] / MdeModulePkg / Library / GenericBdsLib / BdsConsole.c
1 /** @file
2 BDS Lib functions which contain all the code to connect console device
3
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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 Check if we need to save the EFI variable with "ConVarName" as name
19 as NV type
20
21 @param ConVarName The name of the EFI variable.
22
23 @retval TRUE Set the EFI variabel as NV type.
24 @retval FALSE EFI variabel as NV type can be set NonNV.
25 **/
26 BOOLEAN
27 IsNvNeed (
28 IN CHAR16 *ConVarName
29 )
30 {
31 CHAR16 *Ptr;
32
33 Ptr = ConVarName;
34
35 //
36 // If the variable includes "Dev" at last, we consider
37 // it does not support NV attribute.
38 //
39 while (*Ptr != L'\0') {
40 Ptr++;
41 }
42
43 if ((*(Ptr - 3) == 'D') && (*(Ptr - 2) == 'e') && (*(Ptr - 1) == 'v')) {
44 return FALSE;
45 } else {
46 return TRUE;
47 }
48 }
49
50 /**
51 This function update console variable based on ConVarName, it can
52 add or remove one specific console device path from the variable
53
54 @param ConVarName Console related variable name, ConIn, ConOut,
55 ErrOut.
56 @param CustomizedConDevicePath The console device path which will be added to
57 the console variable ConVarName, this parameter
58 can not be multi-instance.
59 @param ExclusiveDevicePath The console device path which will be removed
60 from the console variable ConVarName, this
61 parameter can not be multi-instance.
62
63 @retval EFI_UNSUPPORTED The added device path is same to the removed one.
64 @retval EFI_SUCCESS Success add or remove the device path from the
65 console variable.
66
67 **/
68 EFI_STATUS
69 EFIAPI
70 BdsLibUpdateConsoleVariable (
71 IN CHAR16 *ConVarName,
72 IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,
73 IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath
74 )
75 {
76 EFI_DEVICE_PATH_PROTOCOL *VarConsole;
77 UINTN DevicePathSize;
78 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
79 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
80 UINT32 Attributes;
81
82 VarConsole = NULL;
83 DevicePathSize = 0;
84
85 //
86 // Notes: check the device path point, here should check
87 // with compare memory
88 //
89 if (CustomizedConDevicePath == ExclusiveDevicePath) {
90 return EFI_UNSUPPORTED;
91 }
92 //
93 // Delete the ExclusiveDevicePath from current default console
94 //
95 VarConsole = BdsLibGetVariableAndSize (
96 ConVarName,
97 &gEfiGlobalVariableGuid,
98 &DevicePathSize
99 );
100
101 //
102 // Initialize NewDevicePath
103 //
104 NewDevicePath = VarConsole;
105
106 //
107 // If ExclusiveDevicePath is even the part of the instance in VarConsole, delete it.
108 // In the end, NewDevicePath is the final device path.
109 //
110 if (ExclusiveDevicePath != NULL && VarConsole != NULL) {
111 NewDevicePath = BdsLibDelPartMatchInstance (VarConsole, ExclusiveDevicePath);
112 }
113 //
114 // Try to append customized device path to NewDevicePath.
115 //
116 if (CustomizedConDevicePath != NULL) {
117 if (!BdsLibMatchDevicePaths (NewDevicePath, CustomizedConDevicePath)) {
118 //
119 // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it.
120 //
121 NewDevicePath = BdsLibDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath);
122 //
123 // In the first check, the default console variable will be _ModuleEntryPoint,
124 // just append current customized device path
125 //
126 TempNewDevicePath = NewDevicePath;
127 NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath);
128 if (TempNewDevicePath != NULL) {
129 FreePool(TempNewDevicePath);
130 }
131 }
132 }
133
134 //
135 // The attribute for ConInDev, ConOutDev and ErrOutDev does not include NV.
136 //
137 if (IsNvNeed(ConVarName)) {
138 //
139 // ConVarName has NV attribute.
140 //
141 Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
142 } else {
143 //
144 // ConVarName does not have NV attribute.
145 //
146 Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
147 }
148
149 //
150 // Finally, Update the variable of the default console by NewDevicePath
151 //
152 gRT->SetVariable (
153 ConVarName,
154 &gEfiGlobalVariableGuid,
155 Attributes,
156 GetDevicePathSize (NewDevicePath),
157 NewDevicePath
158 );
159
160 if (VarConsole == NewDevicePath) {
161 if (VarConsole != NULL) {
162 FreePool(VarConsole);
163 }
164 } else {
165 if (VarConsole != NULL) {
166 FreePool(VarConsole);
167 }
168 if (NewDevicePath != NULL) {
169 FreePool(NewDevicePath);
170 }
171 }
172
173 return EFI_SUCCESS;
174
175 }
176
177
178 /**
179 Connect the console device base on the variable ConVarName, if
180 device path of the ConVarName is multi-instance device path, if
181 anyone of the instances is connected success, then this function
182 will return success.
183
184 @param ConVarName Console related variable name, ConIn, ConOut,
185 ErrOut.
186
187 @retval EFI_NOT_FOUND There is not any console devices connected
188 success
189 @retval EFI_SUCCESS Success connect any one instance of the console
190 device path base on the variable ConVarName.
191
192 **/
193 EFI_STATUS
194 EFIAPI
195 BdsLibConnectConsoleVariable (
196 IN CHAR16 *ConVarName
197 )
198 {
199 EFI_STATUS Status;
200 EFI_DEVICE_PATH_PROTOCOL *StartDevicePath;
201 UINTN VariableSize;
202 EFI_DEVICE_PATH_PROTOCOL *Instance;
203 EFI_DEVICE_PATH_PROTOCOL *Next;
204 EFI_DEVICE_PATH_PROTOCOL *CopyOfDevicePath;
205 UINTN Size;
206 BOOLEAN DeviceExist;
207
208 Status = EFI_SUCCESS;
209 DeviceExist = FALSE;
210
211 //
212 // Check if the console variable exist
213 //
214 StartDevicePath = BdsLibGetVariableAndSize (
215 ConVarName,
216 &gEfiGlobalVariableGuid,
217 &VariableSize
218 );
219 if (StartDevicePath == NULL) {
220 return EFI_UNSUPPORTED;
221 }
222
223 CopyOfDevicePath = StartDevicePath;
224 do {
225 //
226 // Check every instance of the console variable
227 //
228 Instance = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);
229 Next = Instance;
230 while (!IsDevicePathEndType (Next)) {
231 Next = NextDevicePathNode (Next);
232 }
233
234 SetDevicePathEndNode (Next);
235 //
236 // Check USB1.1 console
237 //
238 if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&
239 ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)
240 || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)
241 )) {
242 //
243 // Check the Usb console in Usb2.0 bus firstly, then Usb1.1 bus
244 //
245 Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_EHCI, Instance);
246 if (!EFI_ERROR (Status)) {
247 DeviceExist = TRUE;
248 }
249
250 Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_UHCI, Instance);
251 if (!EFI_ERROR (Status)) {
252 DeviceExist = TRUE;
253 }
254 } else {
255 //
256 // Connect the instance device path
257 //
258 Status = BdsLibConnectDevicePath (Instance);
259 if (EFI_ERROR (Status)) {
260 //
261 // Delete the instance from the console varialbe
262 //
263 BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);
264 } else {
265 DeviceExist = TRUE;
266 }
267 }
268 FreePool(Instance);
269 } while (CopyOfDevicePath != NULL);
270
271 FreePool (StartDevicePath);
272
273 if (!DeviceExist) {
274 return EFI_NOT_FOUND;
275 }
276
277 return EFI_SUCCESS;
278 }
279
280
281 /**
282 This function will search every simpletxt devive in current system,
283 and make every simpletxt device as pertantial console device.
284
285 **/
286 VOID
287 EFIAPI
288 BdsLibConnectAllConsoles (
289 VOID
290 )
291 {
292 UINTN Index;
293 EFI_DEVICE_PATH_PROTOCOL *ConDevicePath;
294 UINTN HandleCount;
295 EFI_HANDLE *HandleBuffer;
296
297 Index = 0;
298 HandleCount = 0;
299 HandleBuffer = NULL;
300 ConDevicePath = NULL;
301
302 //
303 // Update all the console varables
304 //
305 gBS->LocateHandleBuffer (
306 ByProtocol,
307 &gEfiSimpleTextInProtocolGuid,
308 NULL,
309 &HandleCount,
310 &HandleBuffer
311 );
312
313 for (Index = 0; Index < HandleCount; Index++) {
314 gBS->HandleProtocol (
315 HandleBuffer[Index],
316 &gEfiDevicePathProtocolGuid,
317 (VOID **) &ConDevicePath
318 );
319 BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);
320 }
321
322 if (HandleBuffer != NULL) {
323 FreePool(HandleBuffer);
324 HandleBuffer = NULL;
325 }
326
327 gBS->LocateHandleBuffer (
328 ByProtocol,
329 &gEfiSimpleTextOutProtocolGuid,
330 NULL,
331 &HandleCount,
332 &HandleBuffer
333 );
334 for (Index = 0; Index < HandleCount; Index++) {
335 gBS->HandleProtocol (
336 HandleBuffer[Index],
337 &gEfiDevicePathProtocolGuid,
338 (VOID **) &ConDevicePath
339 );
340 BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL);
341 BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);
342 }
343
344 if (HandleBuffer != NULL) {
345 FreePool(HandleBuffer);
346 }
347
348 //
349 // Connect all console variables
350 //
351 BdsLibConnectAllDefaultConsoles ();
352
353 }
354
355 /**
356 This function will connect console device base on the console
357 device variable ConIn, ConOut and ErrOut.
358
359 @retval EFI_SUCCESS At least one of the ConIn and ConOut device have
360 been connected success.
361 @retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().
362
363 **/
364 EFI_STATUS
365 EFIAPI
366 BdsLibConnectAllDefaultConsoles (
367 VOID
368 )
369 {
370 EFI_STATUS Status;
371
372 //
373 // Connect all default console variables
374 //
375
376 //
377 // It seems impossible not to have any ConOut device on platform,
378 // so we check the status here.
379 //
380 Status = BdsLibConnectConsoleVariable (L"ConOut");
381 if (EFI_ERROR (Status)) {
382 return Status;
383 }
384
385 //
386 // Insert the performance probe for Console Out
387 //
388 PERF_START (NULL, "ConOut", "BDS", 1);
389 PERF_END (NULL, "ConOut", "BDS", 0);
390
391 //
392 // Because possibly the platform is legacy free, in such case,
393 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
394 // so we need not check the status.
395 //
396 BdsLibConnectConsoleVariable (L"ConIn");
397
398 //
399 // The _ModuleEntryPoint err out var is legal.
400 //
401 BdsLibConnectConsoleVariable (L"ErrOut");
402
403 return EFI_SUCCESS;
404
405 }
406
407 /**
408 Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer
409 is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt
410 buffer is passed in it will be used if it is big enough.
411
412 @param BmpImage Pointer to BMP file
413 @param BmpImageSize Number of bytes in BmpImage
414 @param GopBlt Buffer containing GOP version of BmpImage.
415 @param GopBltSize Size of GopBlt in bytes.
416 @param PixelHeight Height of GopBlt/BmpImage in pixels
417 @param PixelWidth Width of GopBlt/BmpImage in pixels
418
419 @retval EFI_SUCCESS GopBlt and GopBltSize are returned.
420 @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image
421 @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough.
422 GopBltSize will contain the required size.
423 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate.
424
425 **/
426 EFI_STATUS
427 ConvertBmpToGopBlt (
428 IN VOID *BmpImage,
429 IN UINTN BmpImageSize,
430 IN OUT VOID **GopBlt,
431 IN OUT UINTN *GopBltSize,
432 OUT UINTN *PixelHeight,
433 OUT UINTN *PixelWidth
434 )
435 {
436 UINT8 *Image;
437 UINT8 *ImageHeader;
438 BMP_IMAGE_HEADER *BmpHeader;
439 BMP_COLOR_MAP *BmpColorMap;
440 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
441 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
442 UINTN BltBufferSize;
443 UINTN Index;
444 UINTN Height;
445 UINTN Width;
446 UINTN ImageIndex;
447 BOOLEAN IsAllocated;
448
449 BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;
450
451 if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {
452 return EFI_UNSUPPORTED;
453 }
454
455 //
456 // Doesn't support compress.
457 //
458 if (BmpHeader->CompressionType != 0) {
459 return EFI_UNSUPPORTED;
460 }
461
462 //
463 // Calculate Color Map offset in the image.
464 //
465 Image = BmpImage;
466 BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));
467
468 //
469 // Calculate graphics image data address in the image
470 //
471 Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;
472 ImageHeader = Image;
473
474 //
475 // Calculate the BltBuffer needed size.
476 //
477 BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
478 IsAllocated = FALSE;
479 if (*GopBlt == NULL) {
480 //
481 // GopBlt is not allocated by caller.
482 //
483 *GopBltSize = BltBufferSize;
484 *GopBlt = AllocatePool (*GopBltSize);
485 IsAllocated = TRUE;
486 if (*GopBlt == NULL) {
487 return EFI_OUT_OF_RESOURCES;
488 }
489 } else {
490 //
491 // GopBlt has been allocated by caller.
492 //
493 if (*GopBltSize < BltBufferSize) {
494 *GopBltSize = BltBufferSize;
495 return EFI_BUFFER_TOO_SMALL;
496 }
497 }
498
499 *PixelWidth = BmpHeader->PixelWidth;
500 *PixelHeight = BmpHeader->PixelHeight;
501
502 //
503 // Convert image from BMP to Blt buffer format
504 //
505 BltBuffer = *GopBlt;
506 for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {
507 Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];
508 for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {
509 switch (BmpHeader->BitPerPixel) {
510 case 1:
511 //
512 // Convert 1-bit (2 colors) BMP to 24-bit color
513 //
514 for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {
515 Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;
516 Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;
517 Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;
518 Blt++;
519 Width++;
520 }
521
522 Blt --;
523 Width --;
524 break;
525
526 case 4:
527 //
528 // Convert 4-bit (16 colors) BMP Palette to 24-bit color
529 //
530 Index = (*Image) >> 4;
531 Blt->Red = BmpColorMap[Index].Red;
532 Blt->Green = BmpColorMap[Index].Green;
533 Blt->Blue = BmpColorMap[Index].Blue;
534 if (Width < (BmpHeader->PixelWidth - 1)) {
535 Blt++;
536 Width++;
537 Index = (*Image) & 0x0f;
538 Blt->Red = BmpColorMap[Index].Red;
539 Blt->Green = BmpColorMap[Index].Green;
540 Blt->Blue = BmpColorMap[Index].Blue;
541 }
542 break;
543
544 case 8:
545 //
546 // Convert 8-bit (256 colors) BMP Palette to 24-bit color
547 //
548 Blt->Red = BmpColorMap[*Image].Red;
549 Blt->Green = BmpColorMap[*Image].Green;
550 Blt->Blue = BmpColorMap[*Image].Blue;
551 break;
552
553 case 24:
554 //
555 // It is 24-bit BMP.
556 //
557 Blt->Blue = *Image++;
558 Blt->Green = *Image++;
559 Blt->Red = *Image;
560 break;
561
562 default:
563 //
564 // Other bit format BMP is not supported.
565 //
566 if (IsAllocated) {
567 FreePool (*GopBlt);
568 *GopBlt = NULL;
569 }
570 return EFI_UNSUPPORTED;
571 break;
572 };
573
574 }
575
576 ImageIndex = (UINTN) (Image - ImageHeader);
577 if ((ImageIndex % 4) != 0) {
578 //
579 // Bmp Image starts each row on a 32-bit boundary!
580 //
581 Image = Image + (4 - (ImageIndex % 4));
582 }
583 }
584
585 return EFI_SUCCESS;
586 }
587
588
589 /**
590 Use Console Control Protocol to lock the Console In Spliter virtual handle.
591 This is the ConInHandle and ConIn handle in the EFI system table. All key
592 presses will be ignored until the Password is typed in. The only way to
593 disable the password is to type it in to a ConIn device.
594
595 @param Password Password used to lock ConIn device.
596
597 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
598 @retval EFI_UNSUPPORTED Password not found
599
600 **/
601 EFI_STATUS
602 EFIAPI
603 LockKeyboards (
604 IN CHAR16 *Password
605 )
606 {
607 EFI_STATUS Status;
608 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
609
610 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
611 if (EFI_ERROR (Status)) {
612 return EFI_UNSUPPORTED;
613 }
614
615 Status = ConsoleControl->LockStdIn (ConsoleControl, Password);
616 return Status;
617 }
618
619
620 /**
621 Use Console Control to turn off UGA based Simple Text Out consoles from going
622 to the UGA device. Put up LogoFile on every UGA device that is a console
623
624 @param[in] LogoFile File name of logo to display on the center of the screen.
625
626 @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed.
627 @retval EFI_UNSUPPORTED Logo not found
628
629 **/
630 EFI_STATUS
631 EFIAPI
632 EnableQuietBoot (
633 IN EFI_GUID *LogoFile
634 )
635 {
636 EFI_STATUS Status;
637 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
638 EFI_OEM_BADGING_PROTOCOL *Badging;
639 UINT32 SizeOfX;
640 UINT32 SizeOfY;
641 INTN DestX;
642 INTN DestY;
643 UINT8 *ImageData;
644 UINTN ImageSize;
645 UINTN BltSize;
646 UINT32 Instance;
647 EFI_BADGING_FORMAT Format;
648 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;
649 UINTN CoordinateX;
650 UINTN CoordinateY;
651 UINTN Height;
652 UINTN Width;
653 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
654 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
655 UINT32 ColorDepth;
656 UINT32 RefreshRate;
657 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
658
659 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
660 if (EFI_ERROR (Status)) {
661 return EFI_UNSUPPORTED;
662 }
663
664 UgaDraw = NULL;
665 //
666 // Try to open GOP first
667 //
668 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);
669 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
670 GraphicsOutput = NULL;
671 //
672 // Open GOP failed, try to open UGA
673 //
674 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);
675 }
676 if (EFI_ERROR (Status)) {
677 return EFI_UNSUPPORTED;
678 }
679
680 Badging = NULL;
681 Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);
682
683 //
684 // Set console control to graphics mode.
685 //
686 Status = ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);
687 if (EFI_ERROR (Status)) {
688 return EFI_UNSUPPORTED;
689 }
690
691 if (GraphicsOutput != NULL) {
692 SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
693 SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
694 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
695 Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
696 if (EFI_ERROR (Status)) {
697 return EFI_UNSUPPORTED;
698 }
699 } else {
700 return EFI_UNSUPPORTED;
701 }
702
703 Instance = 0;
704 while (1) {
705 ImageData = NULL;
706 ImageSize = 0;
707
708 if (Badging != NULL) {
709 //
710 // Get image from OEMBadging protocol.
711 //
712 Status = Badging->GetImage (
713 Badging,
714 &Instance,
715 &Format,
716 &ImageData,
717 &ImageSize,
718 &Attribute,
719 &CoordinateX,
720 &CoordinateY
721 );
722 if (EFI_ERROR (Status)) {
723 return Status;
724 }
725
726 //
727 // Currently only support BMP format.
728 //
729 if (Format != EfiBadgingFormatBMP) {
730 if (ImageData != NULL) {
731 FreePool (ImageData);
732 }
733 continue;
734 }
735 } else {
736 //
737 // Get the specified image from FV.
738 //
739 Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize);
740 if (EFI_ERROR (Status)) {
741 return EFI_UNSUPPORTED;
742 }
743
744 CoordinateX = 0;
745 CoordinateY = 0;
746 Attribute = EfiBadgingDisplayAttributeCenter;
747 }
748
749 Blt = NULL;
750 Status = ConvertBmpToGopBlt (
751 ImageData,
752 ImageSize,
753 (VOID **) &Blt,
754 &BltSize,
755 &Height,
756 &Width
757 );
758 if (EFI_ERROR (Status)) {
759 if (ImageData != NULL) {
760 FreePool (ImageData);
761 }
762 if (Badging == NULL) {
763 return Status;
764 } else {
765 continue;
766 }
767 }
768
769 //
770 // Caculate the display position according to Attribute.
771 //
772 switch (Attribute) {
773 case EfiBadgingDisplayAttributeLeftTop:
774 DestX = CoordinateX;
775 DestY = CoordinateY;
776 break;
777
778 case EfiBadgingDisplayAttributeCenterTop:
779 DestX = (SizeOfX - Width) / 2;
780 DestY = CoordinateY;
781 break;
782
783 case EfiBadgingDisplayAttributeRightTop:
784 DestX = (SizeOfX - Width - CoordinateX);
785 DestY = CoordinateY;;
786 break;
787
788 case EfiBadgingDisplayAttributeCenterRight:
789 DestX = (SizeOfX - Width - CoordinateX);
790 DestY = (SizeOfY - Height) / 2;
791 break;
792
793 case EfiBadgingDisplayAttributeRightBottom:
794 DestX = (SizeOfX - Width - CoordinateX);
795 DestY = (SizeOfY - Height - CoordinateY);
796 break;
797
798 case EfiBadgingDisplayAttributeCenterBottom:
799 DestX = (SizeOfX - Width) / 2;
800 DestY = (SizeOfY - Height - CoordinateY);
801 break;
802
803 case EfiBadgingDisplayAttributeLeftBottom:
804 DestX = CoordinateX;
805 DestY = (SizeOfY - Height - CoordinateY);
806 break;
807
808 case EfiBadgingDisplayAttributeCenterLeft:
809 DestX = CoordinateX;
810 DestY = (SizeOfY - Height) / 2;
811 break;
812
813 case EfiBadgingDisplayAttributeCenter:
814 DestX = (SizeOfX - Width) / 2;
815 DestY = (SizeOfY - Height) / 2;
816 break;
817
818 default:
819 DestX = CoordinateX;
820 DestY = CoordinateY;
821 break;
822 }
823
824 if ((DestX >= 0) && (DestY >= 0)) {
825 if (GraphicsOutput != NULL) {
826 Status = GraphicsOutput->Blt (
827 GraphicsOutput,
828 Blt,
829 EfiBltBufferToVideo,
830 0,
831 0,
832 (UINTN) DestX,
833 (UINTN) DestY,
834 Width,
835 Height,
836 Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
837 );
838 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
839 Status = UgaDraw->Blt (
840 UgaDraw,
841 (EFI_UGA_PIXEL *) Blt,
842 EfiUgaBltBufferToVideo,
843 0,
844 0,
845 (UINTN) DestX,
846 (UINTN) DestY,
847 Width,
848 Height,
849 Width * sizeof (EFI_UGA_PIXEL)
850 );
851 } else {
852 Status = EFI_UNSUPPORTED;
853 }
854 }
855
856 if (ImageData != NULL) {
857 FreePool (ImageData);
858 }
859 if (Blt != NULL) {
860 FreePool (Blt);
861 }
862
863 if (Badging == NULL) {
864 break;
865 }
866 }
867
868 return Status;
869 }
870
871 /**
872 Use Console Control to turn on UGA based Simple Text Out consoles. The UGA
873 Simple Text Out screens will now be synced up with all non UGA output devices
874
875 @retval EFI_SUCCESS UGA devices are back in text mode and synced up.
876
877 **/
878 EFI_STATUS
879 EFIAPI
880 DisableQuietBoot (
881 VOID
882 )
883 {
884 EFI_STATUS Status;
885 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
886
887 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
888 if (EFI_ERROR (Status)) {
889 return EFI_UNSUPPORTED;
890 }
891
892 //
893 // Set console control to text mode.
894 //
895 return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);
896 }
897