]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
012fe5be047037adf0cf543758f8a3ff2c250759
[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 // Check USB1.1 console
365 //
366 if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&
367 ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)
368 || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)
369 )) {
370 //
371 // Check the Usb console in Usb2.0 bus firstly, then Usb1.1 bus
372 //
373 Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_EHCI, Instance);
374 if (!EFI_ERROR (Status)) {
375 DeviceExist = TRUE;
376 }
377
378 Status = BdsLibConnectUsbDevByShortFormDP (PCI_CLASSC_PI_UHCI, Instance);
379 if (!EFI_ERROR (Status)) {
380 DeviceExist = TRUE;
381 }
382 } else {
383 //
384 // Connect the instance device path
385 //
386 Status = BdsLibConnectDevicePath (Instance);
387 if (EFI_ERROR (Status)) {
388 //
389 // Delete the instance from the console varialbe
390 //
391 BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);
392 } else {
393 DeviceExist = TRUE;
394 }
395 }
396 FreePool(Instance);
397 } while (CopyOfDevicePath != NULL);
398
399 FreePool (StartDevicePath);
400
401 if (!DeviceExist) {
402 return EFI_NOT_FOUND;
403 }
404
405 return EFI_SUCCESS;
406 }
407
408
409 /**
410 This function will search every simpletext device in current system,
411 and make every simpletext device as pertantial console device.
412
413 **/
414 VOID
415 EFIAPI
416 BdsLibConnectAllConsoles (
417 VOID
418 )
419 {
420 UINTN Index;
421 EFI_DEVICE_PATH_PROTOCOL *ConDevicePath;
422 UINTN HandleCount;
423 EFI_HANDLE *HandleBuffer;
424
425 Index = 0;
426 HandleCount = 0;
427 HandleBuffer = NULL;
428 ConDevicePath = NULL;
429
430 //
431 // Update all the console variables
432 //
433 gBS->LocateHandleBuffer (
434 ByProtocol,
435 &gEfiSimpleTextInProtocolGuid,
436 NULL,
437 &HandleCount,
438 &HandleBuffer
439 );
440
441 for (Index = 0; Index < HandleCount; Index++) {
442 gBS->HandleProtocol (
443 HandleBuffer[Index],
444 &gEfiDevicePathProtocolGuid,
445 (VOID **) &ConDevicePath
446 );
447 BdsLibUpdateConsoleVariable (L"ConIn", ConDevicePath, NULL);
448 }
449
450 if (HandleBuffer != NULL) {
451 FreePool(HandleBuffer);
452 HandleBuffer = NULL;
453 }
454
455 gBS->LocateHandleBuffer (
456 ByProtocol,
457 &gEfiSimpleTextOutProtocolGuid,
458 NULL,
459 &HandleCount,
460 &HandleBuffer
461 );
462 for (Index = 0; Index < HandleCount; Index++) {
463 gBS->HandleProtocol (
464 HandleBuffer[Index],
465 &gEfiDevicePathProtocolGuid,
466 (VOID **) &ConDevicePath
467 );
468 BdsLibUpdateConsoleVariable (L"ConOut", ConDevicePath, NULL);
469 BdsLibUpdateConsoleVariable (L"ErrOut", ConDevicePath, NULL);
470 }
471
472 if (HandleBuffer != NULL) {
473 FreePool(HandleBuffer);
474 }
475
476 //
477 // Connect all console variables
478 //
479 BdsLibConnectAllDefaultConsoles ();
480
481 }
482
483 /**
484 This function will connect console device base on the console
485 device variable ConIn, ConOut and ErrOut.
486
487 @retval EFI_SUCCESS At least one of the ConIn and ConOut device have
488 been connected success.
489 @retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().
490
491 **/
492 EFI_STATUS
493 EFIAPI
494 BdsLibConnectAllDefaultConsoles (
495 VOID
496 )
497 {
498 EFI_STATUS Status;
499 BOOLEAN SystemTableUpdated;
500
501 //
502 // Connect all default console variables
503 //
504
505 //
506 // It seems impossible not to have any ConOut device on platform,
507 // so we check the status here.
508 //
509 Status = BdsLibConnectConsoleVariable (L"ConOut");
510 if (EFI_ERROR (Status)) {
511 return Status;
512 }
513
514 //
515 // Insert the performance probe for Console Out
516 //
517 PERF_START (NULL, "ConOut", "BDS", 1);
518 PERF_END (NULL, "ConOut", "BDS", 0);
519
520 //
521 // Because possibly the platform is legacy free, in such case,
522 // ConIn devices (Serial Port and PS2 Keyboard ) does not exist,
523 // so we need not check the status.
524 //
525 BdsLibConnectConsoleVariable (L"ConIn");
526
527 //
528 // The _ModuleEntryPoint err out var is legal.
529 //
530 BdsLibConnectConsoleVariable (L"ErrOut");
531
532 SystemTableUpdated = FALSE;
533 //
534 // Fill console handles in System Table if no console device assignd.
535 //
536 if (UpdateSystemTableConsole (L"ConIn", &gEfiSimpleTextInProtocolGuid, &gST->ConsoleInHandle, (VOID **) &gST->ConIn)) {
537 SystemTableUpdated = TRUE;
538 }
539 if (UpdateSystemTableConsole (L"ConOut", &gEfiSimpleTextOutProtocolGuid, &gST->ConsoleOutHandle, (VOID **) &gST->ConOut)) {
540 SystemTableUpdated = TRUE;
541 }
542 if (UpdateSystemTableConsole (L"ErrOut", &gEfiSimpleTextOutProtocolGuid, &gST->StandardErrorHandle, (VOID **) &gST->StdErr)) {
543 SystemTableUpdated = TRUE;
544 }
545
546 if (SystemTableUpdated) {
547 //
548 // Update the CRC32 in the EFI System Table header
549 //
550 gST->Hdr.CRC32 = 0;
551 gBS->CalculateCrc32 (
552 (UINT8 *) &gST->Hdr,
553 gST->Hdr.HeaderSize,
554 &gST->Hdr.CRC32
555 );
556 }
557
558 return EFI_SUCCESS;
559
560 }
561
562 /**
563 Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer
564 is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt
565 buffer is passed in it will be used if it is big enough.
566
567 @param BmpImage Pointer to BMP file
568 @param BmpImageSize Number of bytes in BmpImage
569 @param GopBlt Buffer containing GOP version of BmpImage.
570 @param GopBltSize Size of GopBlt in bytes.
571 @param PixelHeight Height of GopBlt/BmpImage in pixels
572 @param PixelWidth Width of GopBlt/BmpImage in pixels
573
574 @retval EFI_SUCCESS GopBlt and GopBltSize are returned.
575 @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image
576 @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough.
577 GopBltSize will contain the required size.
578 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate.
579
580 **/
581 EFI_STATUS
582 ConvertBmpToGopBlt (
583 IN VOID *BmpImage,
584 IN UINTN BmpImageSize,
585 IN OUT VOID **GopBlt,
586 IN OUT UINTN *GopBltSize,
587 OUT UINTN *PixelHeight,
588 OUT UINTN *PixelWidth
589 )
590 {
591 UINT8 *Image;
592 UINT8 *ImageHeader;
593 BMP_IMAGE_HEADER *BmpHeader;
594 BMP_COLOR_MAP *BmpColorMap;
595 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
596 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
597 UINT64 BltBufferSize;
598 UINTN Index;
599 UINTN Height;
600 UINTN Width;
601 UINTN ImageIndex;
602 BOOLEAN IsAllocated;
603
604 BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;
605
606 if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {
607 return EFI_UNSUPPORTED;
608 }
609
610 //
611 // Doesn't support compress.
612 //
613 if (BmpHeader->CompressionType != 0) {
614 return EFI_UNSUPPORTED;
615 }
616
617 //
618 // Calculate Color Map offset in the image.
619 //
620 Image = BmpImage;
621 BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));
622
623 //
624 // Calculate graphics image data address in the image
625 //
626 Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;
627 ImageHeader = Image;
628
629 //
630 // Calculate the BltBuffer needed size.
631 //
632 BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
633 if (BltBufferSize >= SIZE_4GB) {
634 //
635 // If the BMP resolution is too large
636 //
637 return EFI_UNSUPPORTED;
638 }
639
640 IsAllocated = FALSE;
641 if (*GopBlt == NULL) {
642 //
643 // GopBlt is not allocated by caller.
644 //
645 *GopBltSize = (UINTN) BltBufferSize;
646 *GopBlt = AllocatePool (*GopBltSize);
647 IsAllocated = TRUE;
648 if (*GopBlt == NULL) {
649 return EFI_OUT_OF_RESOURCES;
650 }
651 } else {
652 //
653 // GopBlt has been allocated by caller.
654 //
655 if (*GopBltSize < (UINTN) BltBufferSize) {
656 *GopBltSize = (UINTN) BltBufferSize;
657 return EFI_BUFFER_TOO_SMALL;
658 }
659 }
660
661 *PixelWidth = BmpHeader->PixelWidth;
662 *PixelHeight = BmpHeader->PixelHeight;
663
664 //
665 // Convert image from BMP to Blt buffer format
666 //
667 BltBuffer = *GopBlt;
668 for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {
669 Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];
670 for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {
671 switch (BmpHeader->BitPerPixel) {
672 case 1:
673 //
674 // Convert 1-bit (2 colors) BMP to 24-bit color
675 //
676 for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {
677 Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;
678 Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;
679 Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;
680 Blt++;
681 Width++;
682 }
683
684 Blt--;
685 Width--;
686 break;
687
688 case 4:
689 //
690 // Convert 4-bit (16 colors) BMP Palette to 24-bit color
691 //
692 Index = (*Image) >> 4;
693 Blt->Red = BmpColorMap[Index].Red;
694 Blt->Green = BmpColorMap[Index].Green;
695 Blt->Blue = BmpColorMap[Index].Blue;
696 if (Width < (BmpHeader->PixelWidth - 1)) {
697 Blt++;
698 Width++;
699 Index = (*Image) & 0x0f;
700 Blt->Red = BmpColorMap[Index].Red;
701 Blt->Green = BmpColorMap[Index].Green;
702 Blt->Blue = BmpColorMap[Index].Blue;
703 }
704 break;
705
706 case 8:
707 //
708 // Convert 8-bit (256 colors) BMP Palette to 24-bit color
709 //
710 Blt->Red = BmpColorMap[*Image].Red;
711 Blt->Green = BmpColorMap[*Image].Green;
712 Blt->Blue = BmpColorMap[*Image].Blue;
713 break;
714
715 case 24:
716 //
717 // It is 24-bit BMP.
718 //
719 Blt->Blue = *Image++;
720 Blt->Green = *Image++;
721 Blt->Red = *Image;
722 break;
723
724 default:
725 //
726 // Other bit format BMP is not supported.
727 //
728 if (IsAllocated) {
729 FreePool (*GopBlt);
730 *GopBlt = NULL;
731 }
732 return EFI_UNSUPPORTED;
733 break;
734 };
735
736 }
737
738 ImageIndex = (UINTN) (Image - ImageHeader);
739 if ((ImageIndex % 4) != 0) {
740 //
741 // Bmp Image starts each row on a 32-bit boundary!
742 //
743 Image = Image + (4 - (ImageIndex % 4));
744 }
745 }
746
747 return EFI_SUCCESS;
748 }
749
750 /**
751 Use SystemTable Conout to stop video based Simple Text Out consoles from going
752 to the video device. Put up LogoFile on every video device that is a console.
753
754 @param[in] LogoFile File name of logo to display on the center of the screen.
755
756 @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed.
757 @retval EFI_UNSUPPORTED Logo not found
758
759 **/
760 EFI_STATUS
761 EFIAPI
762 EnableQuietBoot (
763 IN EFI_GUID *LogoFile
764 )
765 {
766 EFI_STATUS Status;
767 EFI_OEM_BADGING_PROTOCOL *Badging;
768 UINT32 SizeOfX;
769 UINT32 SizeOfY;
770 INTN DestX;
771 INTN DestY;
772 UINT8 *ImageData;
773 UINTN ImageSize;
774 UINTN BltSize;
775 UINT32 Instance;
776 EFI_BADGING_FORMAT Format;
777 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;
778 UINTN CoordinateX;
779 UINTN CoordinateY;
780 UINTN Height;
781 UINTN Width;
782 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
783 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
784 UINT32 ColorDepth;
785 UINT32 RefreshRate;
786 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
787
788 UgaDraw = NULL;
789 //
790 // Try to open GOP first
791 //
792 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);
793 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
794 GraphicsOutput = NULL;
795 //
796 // Open GOP failed, try to open UGA
797 //
798 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);
799 }
800 if (EFI_ERROR (Status)) {
801 return EFI_UNSUPPORTED;
802 }
803
804 //
805 // Erase Cursor from screen
806 //
807 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
808
809 Badging = NULL;
810 Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);
811
812 if (GraphicsOutput != NULL) {
813 SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
814 SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
815
816 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
817 Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
818 if (EFI_ERROR (Status)) {
819 return EFI_UNSUPPORTED;
820 }
821 } else {
822 return EFI_UNSUPPORTED;
823 }
824
825 Instance = 0;
826 while (1) {
827 ImageData = NULL;
828 ImageSize = 0;
829
830 if (Badging != NULL) {
831 //
832 // Get image from OEMBadging protocol.
833 //
834 Status = Badging->GetImage (
835 Badging,
836 &Instance,
837 &Format,
838 &ImageData,
839 &ImageSize,
840 &Attribute,
841 &CoordinateX,
842 &CoordinateY
843 );
844 if (EFI_ERROR (Status)) {
845 return Status;
846 }
847
848 //
849 // Currently only support BMP format.
850 //
851 if (Format != EfiBadgingFormatBMP) {
852 if (ImageData != NULL) {
853 FreePool (ImageData);
854 }
855 continue;
856 }
857 } else {
858 //
859 // Get the specified image from FV.
860 //
861 Status = GetSectionFromAnyFv (LogoFile, EFI_SECTION_RAW, 0, (VOID **) &ImageData, &ImageSize);
862 if (EFI_ERROR (Status)) {
863 return EFI_UNSUPPORTED;
864 }
865
866 CoordinateX = 0;
867 CoordinateY = 0;
868 Attribute = EfiBadgingDisplayAttributeCenter;
869 }
870
871 Blt = NULL;
872 Status = ConvertBmpToGopBlt (
873 ImageData,
874 ImageSize,
875 (VOID **) &Blt,
876 &BltSize,
877 &Height,
878 &Width
879 );
880 if (EFI_ERROR (Status)) {
881 FreePool (ImageData);
882
883 if (Badging == NULL) {
884 return Status;
885 } else {
886 continue;
887 }
888 }
889
890 //
891 // Calculate the display position according to Attribute.
892 //
893 switch (Attribute) {
894 case EfiBadgingDisplayAttributeLeftTop:
895 DestX = CoordinateX;
896 DestY = CoordinateY;
897 break;
898
899 case EfiBadgingDisplayAttributeCenterTop:
900 DestX = (SizeOfX - Width) / 2;
901 DestY = CoordinateY;
902 break;
903
904 case EfiBadgingDisplayAttributeRightTop:
905 DestX = (SizeOfX - Width - CoordinateX);
906 DestY = CoordinateY;;
907 break;
908
909 case EfiBadgingDisplayAttributeCenterRight:
910 DestX = (SizeOfX - Width - CoordinateX);
911 DestY = (SizeOfY - Height) / 2;
912 break;
913
914 case EfiBadgingDisplayAttributeRightBottom:
915 DestX = (SizeOfX - Width - CoordinateX);
916 DestY = (SizeOfY - Height - CoordinateY);
917 break;
918
919 case EfiBadgingDisplayAttributeCenterBottom:
920 DestX = (SizeOfX - Width) / 2;
921 DestY = (SizeOfY - Height - CoordinateY);
922 break;
923
924 case EfiBadgingDisplayAttributeLeftBottom:
925 DestX = CoordinateX;
926 DestY = (SizeOfY - Height - CoordinateY);
927 break;
928
929 case EfiBadgingDisplayAttributeCenterLeft:
930 DestX = CoordinateX;
931 DestY = (SizeOfY - Height) / 2;
932 break;
933
934 case EfiBadgingDisplayAttributeCenter:
935 DestX = (SizeOfX - Width) / 2;
936 DestY = (SizeOfY - Height) / 2;
937 break;
938
939 default:
940 DestX = CoordinateX;
941 DestY = CoordinateY;
942 break;
943 }
944
945 if ((DestX >= 0) && (DestY >= 0)) {
946 if (GraphicsOutput != NULL) {
947 Status = GraphicsOutput->Blt (
948 GraphicsOutput,
949 Blt,
950 EfiBltBufferToVideo,
951 0,
952 0,
953 (UINTN) DestX,
954 (UINTN) DestY,
955 Width,
956 Height,
957 Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
958 );
959 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
960 Status = UgaDraw->Blt (
961 UgaDraw,
962 (EFI_UGA_PIXEL *) Blt,
963 EfiUgaBltBufferToVideo,
964 0,
965 0,
966 (UINTN) DestX,
967 (UINTN) DestY,
968 Width,
969 Height,
970 Width * sizeof (EFI_UGA_PIXEL)
971 );
972 } else {
973 Status = EFI_UNSUPPORTED;
974 }
975 }
976
977 FreePool (ImageData);
978
979 if (Blt != NULL) {
980 FreePool (Blt);
981 }
982
983 if (Badging == NULL) {
984 break;
985 }
986 }
987
988 return Status;
989 }
990
991 /**
992 Use SystemTable Conout to turn on video based Simple Text Out consoles. The
993 Simple Text Out screens will now be synced up with all non video output devices
994
995 @retval EFI_SUCCESS UGA devices are back in text mode and synced up.
996
997 **/
998 EFI_STATUS
999 EFIAPI
1000 DisableQuietBoot (
1001 VOID
1002 )
1003 {
1004
1005 //
1006 // Enable Cursor on Screen
1007 //
1008 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
1009 return EFI_SUCCESS;
1010 }
1011