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