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