TianoCore EDK2 master
Loading...
Searching...
No Matches
PlatformBm.c
Go to the documentation of this file.
1
14#include <Library/BootLogoLib.h>
16#include <Library/PcdLib.h>
22#include <Protocol/DevicePath.h>
25#include <Protocol/PciIo.h>
28#include <Guid/EventGroup.h>
29#include <Guid/GlobalVariable.h>
33
34#include "PlatformBm.h"
35
36#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) }
37
38#pragma pack (1)
39typedef struct {
40 VENDOR_DEVICE_PATH SerialDxe;
45#pragma pack ()
46
47STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {
48 //
49 // VENDOR_DEVICE_PATH SerialDxe
50 //
51 {
53 EDKII_SERIAL_PORT_LIB_VENDOR_GUID
54 },
55
56 //
57 // UART_DEVICE_PATH Uart
58 //
59 {
61 0, // Reserved
62 FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate
63 FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits
64 FixedPcdGet8 (PcdUartDefaultParity), // Parity
65 FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits
66 },
67
68 //
69 // VENDOR_DEFINED_DEVICE_PATH TermType
70 //
71 {
72 {
73 MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,
74 DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH)
75 }
76 //
77 // Guid to be filled in dynamically
78 //
79 },
80
81 //
82 // EFI_DEVICE_PATH_PROTOCOL End
83 //
84 {
85 END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
86 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
87 }
88};
89
90#pragma pack (1)
91typedef struct {
92 USB_CLASS_DEVICE_PATH Keyboard;
95#pragma pack ()
96
97STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {
98 //
99 // USB_CLASS_DEVICE_PATH Keyboard
100 //
101 {
102 {
104 DP_NODE_LEN (USB_CLASS_DEVICE_PATH)
105 },
106 0xFFFF, // VendorId: any
107 0xFFFF, // ProductId: any
108 3, // DeviceClass: HID
109 1, // DeviceSubClass: boot
110 1 // DeviceProtocol: keyboard
111 },
112
113 //
114 // EFI_DEVICE_PATH_PROTOCOL End
115 //
116 {
117 END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
118 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)
119 }
120};
121
133typedef
134BOOLEAN
135(EFIAPI *FILTER_FUNCTION)(
136 IN EFI_HANDLE Handle,
137 IN CONST CHAR16 *ReportText
138 );
139
147typedef
149(EFIAPI *CALLBACK_FUNCTION)(
150 IN EFI_HANDLE Handle,
151 IN CONST CHAR16 *ReportText
152 );
153
167STATIC
168VOID
170 IN EFI_GUID *ProtocolGuid,
171 IN FILTER_FUNCTION Filter OPTIONAL,
172 IN CALLBACK_FUNCTION Process
173 )
174{
175 EFI_STATUS Status;
176 EFI_HANDLE *Handles;
177 UINTN NoHandles;
178 UINTN Idx;
179
180 Status = gBS->LocateHandleBuffer (
182 ProtocolGuid,
183 NULL /* SearchKey */,
184 &NoHandles,
185 &Handles
186 );
187 if (EFI_ERROR (Status)) {
188 //
189 // This is not an error, just an informative condition.
190 //
191 DEBUG ((
192 DEBUG_VERBOSE,
193 "%a: %g: %r\n",
194 __func__,
195 ProtocolGuid,
196 Status
197 ));
198 return;
199 }
200
201 ASSERT (NoHandles > 0);
202 for (Idx = 0; Idx < NoHandles; ++Idx) {
203 CHAR16 *DevicePathText;
204 STATIC CHAR16 Fallback[] = L"<device path unavailable>";
205
206 //
207 // The ConvertDevicePathToText() function handles NULL input transparently.
208 //
209 DevicePathText = ConvertDevicePathToText (
210 DevicePathFromHandle (Handles[Idx]),
211 FALSE, // DisplayOnly
212 FALSE // AllowShortcuts
213 );
214 if (DevicePathText == NULL) {
215 DevicePathText = Fallback;
216 }
217
218 if ((Filter == NULL) || Filter (Handles[Idx], DevicePathText)) {
219 Process (Handles[Idx], DevicePathText);
220 }
221
222 if (DevicePathText != Fallback) {
223 FreePool (DevicePathText);
224 }
225 }
226
227 gBS->FreePool (Handles);
228}
229
233STATIC
234BOOLEAN
235EFIAPI
237 IN EFI_HANDLE Handle,
238 IN CONST CHAR16 *ReportText
239 )
240{
241 EFI_STATUS Status;
242 EFI_PCI_IO_PROTOCOL *PciIo;
243 PCI_TYPE00 Pci;
244
245 Status = gBS->HandleProtocol (
246 Handle,
247 &gEfiPciIoProtocolGuid,
248 (VOID **)&PciIo
249 );
250 if (EFI_ERROR (Status)) {
251 //
252 // This is not an error worth reporting.
253 //
254 return FALSE;
255 }
256
257 Status = PciIo->Pci.Read (
258 PciIo,
259 EfiPciIoWidthUint32,
260 0 /* Offset */,
261 sizeof Pci / sizeof (UINT32),
262 &Pci
263 );
264 if (EFI_ERROR (Status)) {
265 DEBUG ((DEBUG_ERROR, "%a: %s: %r\n", __func__, ReportText, Status));
266 return FALSE;
267 }
268
269 return IS_PCI_DISPLAY (&Pci);
270}
271
276STATIC
277BOOLEAN
278EFIAPI
280 IN EFI_HANDLE Handle,
281 IN CONST CHAR16 *ReportText,
282 IN UINT16 VirtIoDeviceId
283 )
284{
285 EFI_STATUS Status;
287
288 Status = gBS->HandleProtocol (
289 Handle,
290 &gVirtioDeviceProtocolGuid,
291 (VOID **)&VirtIo
292 );
293 if (EFI_ERROR (Status)) {
294 return FALSE;
295 }
296
297 return (BOOLEAN)(VirtIo->SubSystemDeviceId ==
298 VirtIoDeviceId);
299}
300
305STATIC
306BOOLEAN
307EFIAPI
309 IN EFI_HANDLE Handle,
310 IN CONST CHAR16 *ReportText
311 )
312{
313 return IsVirtio (Handle, ReportText, VIRTIO_SUBSYSTEM_ENTROPY_SOURCE);
314}
315
320STATIC
321BOOLEAN
322EFIAPI
324 IN EFI_HANDLE Handle,
325 IN CONST CHAR16 *ReportText
326 )
327{
328 return IsVirtio (Handle, ReportText, VIRTIO_SUBSYSTEM_CONSOLE);
329}
330
335STATIC
336BOOLEAN
337EFIAPI
339 IN EFI_HANDLE Handle,
340 IN CONST CHAR16 *ReportText,
341 IN UINT16 VirtIoDeviceId
342 )
343{
344 EFI_STATUS Status;
345 EFI_PCI_IO_PROTOCOL *PciIo;
346 UINT16 VendorId;
347 UINT16 DeviceId;
348 UINT8 RevisionId;
349 BOOLEAN Virtio10;
350 UINT16 SubsystemId;
351
352 Status = gBS->HandleProtocol (
353 Handle,
354 &gEfiPciIoProtocolGuid,
355 (VOID **)&PciIo
356 );
357 if (EFI_ERROR (Status)) {
358 return FALSE;
359 }
360
361 //
362 // Read and check VendorId.
363 //
364 Status = PciIo->Pci.Read (
365 PciIo,
366 EfiPciIoWidthUint16,
367 PCI_VENDOR_ID_OFFSET,
368 1,
369 &VendorId
370 );
371 if (EFI_ERROR (Status)) {
372 goto PciError;
373 }
374
375 if (VendorId != VIRTIO_VENDOR_ID) {
376 return FALSE;
377 }
378
379 //
380 // Read DeviceId and RevisionId.
381 //
382 Status = PciIo->Pci.Read (
383 PciIo,
384 EfiPciIoWidthUint16,
385 PCI_DEVICE_ID_OFFSET,
386 1,
387 &DeviceId
388 );
389 if (EFI_ERROR (Status)) {
390 goto PciError;
391 }
392
393 Status = PciIo->Pci.Read (
394 PciIo,
395 EfiPciIoWidthUint8,
396 PCI_REVISION_ID_OFFSET,
397 1,
398 &RevisionId
399 );
400 if (EFI_ERROR (Status)) {
401 goto PciError;
402 }
403
404 //
405 // From DeviceId and RevisionId, determine whether the device is a
406 // modern-only Virtio 1.0 device. In case of Virtio 1.0, DeviceId can
407 // immediately be restricted to VirtIoDeviceId, and
408 // SubsystemId will only play a sanity-check role. Otherwise, DeviceId can
409 // only be sanity-checked, and SubsystemId will decide.
410 //
411 if ((DeviceId == 0x1040 + VirtIoDeviceId) &&
412 (RevisionId >= 0x01))
413 {
414 Virtio10 = TRUE;
415 } else if ((DeviceId >= 0x1000) && (DeviceId <= 0x103F) && (RevisionId == 0x00)) {
416 Virtio10 = FALSE;
417 } else {
418 return FALSE;
419 }
420
421 //
422 // Read and check SubsystemId as dictated by Virtio10.
423 //
424 Status = PciIo->Pci.Read (
425 PciIo,
426 EfiPciIoWidthUint16,
427 PCI_SUBSYSTEM_ID_OFFSET,
428 1,
429 &SubsystemId
430 );
431 if (EFI_ERROR (Status)) {
432 goto PciError;
433 }
434
435 if (Virtio10 && (SubsystemId >= 0x40)) {
436 return TRUE;
437 }
438
439 if (!Virtio10 && (SubsystemId == VirtIoDeviceId)) {
440 return TRUE;
441 }
442
443 return FALSE;
444
445PciError:
446 DEBUG ((DEBUG_ERROR, "%a: %s: %r\n", __func__, ReportText, Status));
447 return FALSE;
448}
449
454STATIC
455BOOLEAN
456EFIAPI
458 IN EFI_HANDLE Handle,
459 IN CONST CHAR16 *ReportText
460 )
461{
462 return IsVirtioPci (Handle, ReportText, VIRTIO_SUBSYSTEM_ENTROPY_SOURCE);
463}
464
469STATIC
470BOOLEAN
471EFIAPI
473 IN EFI_HANDLE Handle,
474 IN CONST CHAR16 *ReportText
475 )
476{
477 return IsVirtioPci (Handle, ReportText, VIRTIO_SUBSYSTEM_CONSOLE);
478}
479
484STATIC
485VOID
486EFIAPI
488 IN EFI_HANDLE Handle,
489 IN CONST CHAR16 *ReportText
490 )
491{
492 EFI_STATUS Status;
493
494 Status = gBS->ConnectController (
495 Handle, // ControllerHandle
496 NULL, // DriverImageHandle
497 NULL, // RemainingDevicePath -- produce all children
498 FALSE // Recursive
499 );
500 DEBUG ((
501 EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE,
502 "%a: %s: %r\n",
503 __func__,
504 ReportText,
505 Status
506 ));
507}
508
513STATIC
514VOID
515EFIAPI
517 IN EFI_HANDLE Handle,
518 IN CONST CHAR16 *ReportText
519 )
520{
521 EFI_STATUS Status;
522 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
523
524 DevicePath = DevicePathFromHandle (Handle);
525 if (DevicePath == NULL) {
526 DEBUG ((
527 DEBUG_ERROR,
528 "%a: %s: handle %p: device path not found\n",
529 __func__,
530 ReportText,
531 Handle
532 ));
533 return;
534 }
535
536 Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);
537 if (EFI_ERROR (Status)) {
538 DEBUG ((
539 DEBUG_ERROR,
540 "%a: %s: adding to ConOut: %r\n",
541 __func__,
542 ReportText,
543 Status
544 ));
545 return;
546 }
547
548 Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);
549 if (EFI_ERROR (Status)) {
550 DEBUG ((
551 DEBUG_ERROR,
552 "%a: %s: adding to ErrOut: %r\n",
553 __func__,
554 ReportText,
555 Status
556 ));
557 return;
558 }
559
560 DEBUG ((
561 DEBUG_VERBOSE,
562 "%a: %s: added to ConOut and ErrOut\n",
563 __func__,
564 ReportText
565 ));
566}
567
573STATIC
574VOID
575EFIAPI
577 IN EFI_HANDLE Handle,
578 IN CONST CHAR16 *ReportText
579 )
580{
581 STATIC CONST ACPI_HID_DEVICE_PATH SerialNode = {
582 {
584 ACPI_DP,
585 {
586 (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)),
587 (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)
588 },
589 },
590 EISA_PNP_ID (0x0501),
591 0
592 };
593
594 STATIC CONST UART_DEVICE_PATH UartNode = {
595 {
598 {
599 (UINT8)(sizeof (UART_DEVICE_PATH)),
600 (UINT8)((sizeof (UART_DEVICE_PATH)) >> 8)
601 },
602 },
603 0,
604 115200,
605 8,
606 1,
607 1
608 };
609
610 STATIC VENDOR_DEVICE_PATH TerminalNode = {
611 {
613 MSG_VENDOR_DP,
614 {
615 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
616 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
617 },
618 },
619 // copy from PcdTerminalTypeGuidBuffer
620 };
621
622 EFI_STATUS Status;
623 EFI_DEVICE_PATH_PROTOCOL *DevicePath, *OldDevicePath;
624
625 DevicePath = DevicePathFromHandle (Handle);
626
627 if (DevicePath == NULL) {
628 DEBUG ((
629 DEBUG_ERROR,
630 "%a: %s: handle %p: device path not found\n",
631 __func__,
632 ReportText,
633 Handle
634 ));
635 return;
636 }
637
638 CopyGuid (
639 &TerminalNode.Guid,
640 PcdGetPtr (PcdTerminalTypeGuidBuffer)
641 );
642
643 DevicePath = AppendDevicePathNode (
644 DevicePath,
645 &SerialNode.Header
646 );
647
648 OldDevicePath = DevicePath;
649 DevicePath = AppendDevicePathNode (
650 DevicePath,
651 &UartNode.Header
652 );
653 FreePool (OldDevicePath);
654
655 OldDevicePath = DevicePath;
656 DevicePath = AppendDevicePathNode (
657 DevicePath,
658 &TerminalNode.Header
659 );
660 FreePool (OldDevicePath);
661
662 Status = EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL);
663 if (EFI_ERROR (Status)) {
664 DEBUG ((
665 DEBUG_ERROR,
666 "%a: %s: adding to ConIn: %r\n",
667 __func__,
668 ReportText,
669 Status
670 ));
671 return;
672 }
673
674 Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);
675 if (EFI_ERROR (Status)) {
676 DEBUG ((
677 DEBUG_ERROR,
678
679 "%a: %s: adding to ConOut: %r\n",
680 __func__,
681 ReportText,
682 Status
683 ));
684 return;
685 }
686
687 Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);
688 if (EFI_ERROR (Status)) {
689 DEBUG ((
690 DEBUG_ERROR,
691 "%a: %s: adding to ErrOut: %r\n",
692 __func__,
693 ReportText,
694 Status
695 ));
696 return;
697 }
698
699 FreePool (DevicePath);
700
701 DEBUG ((
702 DEBUG_VERBOSE,
703 "%a: %s: added to ConIn, ConOut and ErrOut\n",
704 __func__,
705 ReportText
706 ));
707}
708
709STATIC
710VOID
711PlatformRegisterOptionsAndKeys (
712 VOID
713 )
714{
715 EFI_STATUS Status;
716 EFI_INPUT_KEY Enter;
717 EFI_INPUT_KEY F2;
718 EFI_INPUT_KEY Esc;
720
721 //
722 // Register ENTER as CONTINUE key
723 //
724 Enter.ScanCode = SCAN_NULL;
725 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;
726 Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);
727 ASSERT_EFI_ERROR (Status);
728
729 //
730 // Map F2 and ESC to Boot Manager Menu
731 //
732 F2.ScanCode = SCAN_F2;
733 F2.UnicodeChar = CHAR_NULL;
734 Esc.ScanCode = SCAN_ESC;
735 Esc.UnicodeChar = CHAR_NULL;
736 Status = EfiBootManagerGetBootManagerMenu (&BootOption);
737 ASSERT_EFI_ERROR (Status);
739 NULL,
740 (UINT16)BootOption.OptionNumber,
741 0,
742 &F2,
743 NULL
744 );
745 ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);
747 NULL,
748 (UINT16)BootOption.OptionNumber,
749 0,
750 &Esc,
751 NULL
752 );
753 ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);
754}
755
756//
757// BDS Platform Functions
758//
759
771VOID
772EFIAPI
774 VOID
775 )
776{
777 UINT16 FrontPageTimeout;
778 RETURN_STATUS PcdStatus;
779 EFI_STATUS Status;
780 BOOLEAN FirmwareSetupEnabled;
781
782 //
783 // Signal EndOfDxe PI Event
784 //
785 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);
786
787 //
788 // Disable the TPM 2 platform hierarchy
789 //
791
792 //
793 // Dispatch deferred images after EndOfDxe event.
794 //
796
797 //
798 // Locate the PCI root bridges and make the PCI bus driver connect each,
799 // non-recursively. This will produce a number of child handles with PciIo on
800 // them.
801 //
802 FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid, NULL, Connect);
803
804 //
805 // Signal the ACPI platform driver that it can download QEMU ACPI tables.
806 //
807 EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);
808
809 //
810 // Find all display class PCI devices (using the handles from the previous
811 // step), and connect them non-recursively. This should produce a number of
812 // child handles with GOPs on them.
813 //
814 FilterAndProcess (&gEfiPciIoProtocolGuid, IsPciDisplay, Connect);
815
816 //
817 // Now add the device path of all handles with GOP on them to ConOut and
818 // ErrOut.
819 //
820 FilterAndProcess (&gEfiGraphicsOutputProtocolGuid, NULL, AddOutput);
821
822 //
823 // Add the hardcoded short-form USB keyboard device path to ConIn.
824 //
826 ConIn,
827 (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard,
828 NULL
829 );
830
831 //
832 // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.
833 //
834 CopyGuid (
835 &mSerialConsole.TermType.Guid,
836 PcdGetPtr (PcdTerminalTypeGuidBuffer)
837 );
839 ConIn,
840 (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole,
841 NULL
842 );
844 ConOut,
845 (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole,
846 NULL
847 );
849 ErrOut,
850 (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole,
851 NULL
852 );
853
854 //
855 // Set the front page timeout from the QEMU configuration.
856 //
857 FrontPageTimeout = GetFrontPageTimeoutFromQemu ();
858 PcdStatus = PcdSet16S (PcdPlatformBootTimeOut, FrontPageTimeout);
859 ASSERT_RETURN_ERROR (PcdStatus);
860 //
861 // Reflect the PCD in the standard Timeout variable.
862 //
863 Status = gRT->SetVariable (
865 &gEfiGlobalVariableGuid,
867 EFI_VARIABLE_BOOTSERVICE_ACCESS |
868 EFI_VARIABLE_RUNTIME_ACCESS),
869 sizeof FrontPageTimeout,
870 &FrontPageTimeout
871 );
872 DEBUG ((
873 EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE,
874 "%a: SetVariable(%s, %u): %r\n",
875 __func__,
877 FrontPageTimeout,
878 Status
879 ));
880
881 Status = QemuFwCfgParseBool (
882 "opt/org.tianocore/FirmwareSetupSupport",
883 &FirmwareSetupEnabled
884 );
885
886 if (RETURN_ERROR (Status)) {
887 FirmwareSetupEnabled = TRUE;
888 }
889
891 &gUiAppFileGuid,
892 L"EFI Firmware Setup",
893 LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_APP,
894 FirmwareSetupEnabled
895 );
896
897 //
898 // Register platform-specific boot options and keyboard shortcuts.
899 //
900 PlatformRegisterOptionsAndKeys ();
901
902 //
903 // At this point, VIRTIO_DEVICE_PROTOCOL instances exist only for Virtio MMIO
904 // transports. Install EFI_RNG_PROTOCOL instances on Virtio MMIO RNG devices.
905 //
906 FilterAndProcess (&gVirtioDeviceProtocolGuid, IsVirtioRng, Connect);
907
908 //
909 // Install both VIRTIO_DEVICE_PROTOCOL and (dependent) EFI_RNG_PROTOCOL
910 // instances on Virtio PCI RNG devices.
911 //
912 FilterAndProcess (&gEfiPciIoProtocolGuid, IsVirtioPciRng, Connect);
913
914 //
915 // Register Virtio serial devices as console.
916 //
917 FilterAndProcess (&gVirtioDeviceProtocolGuid, IsVirtioSerial, SetupVirtioSerial);
918 FilterAndProcess (&gEfiPciIoProtocolGuid, IsVirtioPciSerial, SetupVirtioSerial);
919}
920
924STATIC
925VOID
927 VOID
928 )
929{
930 EFI_STATUS Status;
931 EFI_HANDLE Handle;
932 UINTN Size;
933 VOID *MemoryAttributeProtocol;
934
935 Size = sizeof (Handle);
936 Status = gBS->LocateHandle (
938 &gEfiMemoryAttributeProtocolGuid,
939 NULL,
940 &Size,
941 &Handle
942 );
943
944 if (EFI_ERROR (Status)) {
945 ASSERT (Status == EFI_NOT_FOUND);
946 return;
947 }
948
949 Status = gBS->HandleProtocol (
950 Handle,
951 &gEfiMemoryAttributeProtocolGuid,
952 &MemoryAttributeProtocol
953 );
954 ASSERT_EFI_ERROR (Status);
955
956 Status = gBS->UninstallProtocolInterface (
957 Handle,
958 &gEfiMemoryAttributeProtocolGuid,
959 MemoryAttributeProtocol
960 );
961 ASSERT_EFI_ERROR (Status);
962}
963
975VOID
976EFIAPI
978 VOID
979 )
980{
981 RETURN_STATUS Status;
982 BOOLEAN Uninstall;
983 BOOLEAN ShellEnabled;
984
985 //
986 // Show the splash screen.
987 //
989
990 //
991 // Work around shim's terminally broken use of the EFI memory attributes
992 // protocol, by uninstalling it if requested on the QEMU command line.
993 //
994 // E.g.,
995 // -fw_cfg opt/org.tianocore/UninstallMemAttrProtocol,string=y
996 //
997 Uninstall = FixedPcdGetBool (PcdUninstallMemAttrProtocol);
998 QemuFwCfgParseBool ("opt/org.tianocore/UninstallMemAttrProtocol", &Uninstall);
999 DEBUG ((
1000 DEBUG_WARN,
1001 "%a: %auninstalling EFI memory protocol\n",
1002 __func__,
1003 Uninstall ? "" : "not "
1004 ));
1005 if (Uninstall) {
1007 }
1008
1009 Status = QemuFwCfgParseBool (
1010 "opt/org.tianocore/EFIShellSupport",
1011 &ShellEnabled
1012 );
1013
1014 if (RETURN_ERROR (Status)) {
1015 ShellEnabled = TRUE;
1016 }
1017
1018 //
1019 // Process QEMU's -kernel command line option. The kernel booted this way
1020 // will receive ACPI tables: in PlatformBootManagerBeforeConsole(), we
1021 // connected any and all PCI root bridges, and then signaled the ACPI
1022 // platform driver.
1023 //
1025
1026 //
1027 // Connect the purported boot devices.
1028 //
1029 Status = ConnectDevicesFromQemu ();
1030 if (RETURN_ERROR (Status)) {
1031 //
1032 // Connect the rest of the devices.
1033 //
1035 }
1036
1037 //
1038 // Enumerate all possible boot options, then filter and reorder them based on
1039 // the QEMU configuration.
1040 //
1042
1043 //
1044 // Register UEFI Shell
1045 //
1047 &gUefiShellFileGuid,
1048 L"EFI Internal Shell",
1049 LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_APP,
1050 ShellEnabled
1051 );
1052
1055
1057}
1058
1065VOID
1066EFIAPI
1068 UINT16 TimeoutRemain
1069 )
1070{
1073 UINT16 TimeoutInitial;
1074
1075 TimeoutInitial = PcdGet16 (PcdPlatformBootTimeOut);
1076
1077 //
1078 // If PcdPlatformBootTimeOut is set to zero, then we consider
1079 // that no progress update should be enacted.
1080 //
1081 if (TimeoutInitial == 0) {
1082 return;
1083 }
1084
1085 Black.Raw = 0x00000000;
1086 White.Raw = 0x00FFFFFF;
1087
1089 White.Pixel,
1090 Black.Pixel,
1091 L"Start boot option",
1092 White.Pixel,
1093 (TimeoutInitial - TimeoutRemain) * 100 / TimeoutInitial,
1094 0
1095 );
1096}
1097
1105VOID
1106EFIAPI
1108 VOID
1109 )
1110{
1111 EFI_STATUS Status;
1112 EFI_INPUT_KEY Key;
1113 EFI_BOOT_MANAGER_LOAD_OPTION BootManagerMenu;
1114 UINTN Index;
1115
1116 //
1117 // BootManagerMenu doesn't contain the correct information when return status
1118 // is EFI_NOT_FOUND.
1119 //
1120 Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);
1121 if (EFI_ERROR (Status)) {
1122 return;
1123 }
1124
1125 //
1126 // Normally BdsDxe does not print anything to the system console, but this is
1127 // a last resort -- the end-user will likely not see any DEBUG messages
1128 // logged in this situation.
1129 //
1130 // AsciiPrint() will NULL-check gST->ConOut internally. We check gST->ConIn
1131 // here to see if it makes sense to request and wait for a keypress.
1132 //
1133 if (gST->ConIn != NULL) {
1134 AsciiPrint (
1135 "%a: No bootable option or device was found.\n"
1136 "%a: Press any key to enter the Boot Manager Menu.\n",
1137 gEfiCallerBaseName,
1138 gEfiCallerBaseName
1139 );
1140 Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);
1141 ASSERT_EFI_ERROR (Status);
1142 ASSERT (Index == 0);
1143
1144 //
1145 // Drain any queued keys.
1146 //
1147 while (!EFI_ERROR (gST->ConIn->ReadKeyStroke (gST->ConIn, &Key))) {
1148 //
1149 // just throw away Key
1150 //
1151 }
1152 }
1153
1154 for ( ; ;) {
1155 EfiBootManagerBoot (&BootManagerMenu);
1156 }
1157}
UINT64 UINTN
VOID EFIAPI PlatformBootManagerBeforeConsole(VOID)
Definition: PlatformBm.c:714
VOID EFIAPI PlatformBootManagerWaitCallback(UINT16 TimeoutRemain)
Definition: PlatformBm.c:1075
VOID(EFIAPI * CALLBACK_FUNCTION)(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:153
STATIC VOID EFIAPI Connect(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:317
VOID EFIAPI PlatformBootManagerUnableToBoot(VOID)
Definition: PlatformBm.c:1111
VOID EFIAPI PlatformBootManagerAfterConsole(VOID)
Definition: PlatformBm.c:995
STATIC VOID EFIAPI AddOutput(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:346
STATIC BOOLEAN EFIAPI IsPciDisplay(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:240
BOOLEAN(EFIAPI * FILTER_FUNCTION)(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:139
STATIC VOID FilterAndProcess(IN EFI_GUID *ProtocolGuid, IN FILTER_FUNCTION Filter OPTIONAL, IN CALLBACK_FUNCTION Process)
Definition: PlatformBm.c:173
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
EFI_STATUS EFIAPI BootLogoUpdateProgress(IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground, IN CHAR16 *Title, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor, IN UINTN Progress, IN UINTN PreviousValue)
Definition: BootLogoLib.c:348
EFI_STATUS EFIAPI BootLogoEnableLogo(VOID)
Definition: BootLogoLib.c:33
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define HW_VENDOR_DP
Definition: DevicePath.h:133
#define ACPI_DEVICE_PATH
Definition: DevicePath.h:190
#define ACPI_DP
Definition: DevicePath.h:195
#define MSG_UART_DP
Definition: DevicePath.h:692
#define MSG_USB_CLASS_DP
Definition: DevicePath.h:434
#define MESSAGING_DEVICE_PATH
Definition: DevicePath.h:321
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DevicePathFromHandle(IN EFI_HANDLE Handle)
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define EFI_TIME_OUT_VARIABLE_NAME
STATIC VOID PlatformRegisterFvBootOption(CONST EFI_GUID *FileGuid, CHAR16 *Description, UINT32 Attributes)
Definition: LinuxBootBm.c:40
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define RETURN_ERROR(StatusCode)
Definition: Base.h:1061
#define VOID
Definition: Base.h:269
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:463
#define ASSERT_RETURN_ERROR(StatusParameter)
Definition: DebugLib.h:494
#define DEBUG(Expression)
Definition: DebugLib.h:435
STATIC BOOLEAN EFIAPI IsVirtio(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText, IN UINT16 VirtIoDeviceId)
Definition: PlatformBm.c:279
STATIC BOOLEAN EFIAPI IsVirtioPci(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText, IN UINT16 VirtIoDeviceId)
Definition: PlatformBm.c:338
STATIC BOOLEAN EFIAPI IsVirtioPciSerial(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:472
STATIC VOID EFIAPI SetupVirtioSerial(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:576
STATIC BOOLEAN EFIAPI IsVirtioRng(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:308
STATIC BOOLEAN EFIAPI IsVirtioPciRng(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:457
STATIC BOOLEAN EFIAPI IsVirtioSerial(IN EFI_HANDLE Handle, IN CONST CHAR16 *ReportText)
Definition: PlatformBm.c:323
STATIC VOID UninstallEfiMemoryAttributesProtocol(VOID)
Definition: PlatformBm.c:926
#define PcdGet16(TokenName)
Definition: PcdLib.h:349
#define FixedPcdGet64(TokenName)
Definition: PcdLib.h:106
#define FixedPcdGetBool(TokenName)
Definition: PcdLib.h:120
#define FixedPcdGet8(TokenName)
Definition: PcdLib.h:64
#define PcdSet16S(TokenName, Value)
Definition: PcdLib.h:483
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
#define IS_PCI_DISPLAY(_p)
Definition: Pci22.h:349
VOID EFIAPI ConfigureTpmPlatformHierarchy()
EFI_STATUS EFIAPI PlatformBmPrintScRegisterHandler(VOID)
VOID RemoveStaleFvFileOptions(VOID)
EFI_STATUS TryRunningQemuKernel(VOID)
Definition: QemuKernel.c:17
RETURN_STATUS EFIAPI SetBootOrderFromQemu(VOID)
RETURN_STATUS EFIAPI ConnectDevicesFromQemu(VOID)
UINT16 EFIAPI GetFrontPageTimeoutFromQemu(VOID)
RETURN_STATUS EFIAPI QemuFwCfgParseBool(IN CONST CHAR8 *FileName, OUT BOOLEAN *Value)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI EfiBootManagerDispatchDeferredImages(VOID)
Definition: BmMisc.c:428
VOID EFIAPI EfiBootManagerBoot(IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption)
Definition: BmBoot.c:1894
EFI_STATUS EFIAPI EfiBootManagerRegisterContinueKeyOption(IN UINT32 Modifier,...)
Definition: BmHotkey.c:813
EFI_STATUS EFIAPI EfiBootManagerUpdateConsoleVariable(IN CONSOLE_TYPE ConsoleType, IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath, IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath)
Definition: BmConsole.c:418
VOID EFIAPI EfiBootManagerRefreshAllBootOption(VOID)
Definition: BmBoot.c:2436
VOID EFIAPI EfiBootManagerConnectAll(VOID)
Definition: BmConnect.c:67
EFI_STATUS EFIAPI EfiBootManagerGetBootManagerMenu(EFI_BOOT_MANAGER_LOAD_OPTION *BootOption)
Definition: BmBoot.c:2656
EFI_STATUS EFIAPI EfiBootManagerAddKeyOptionVariable(OUT EFI_BOOT_MANAGER_KEY_OPTION *AddedOption OPTIONAL, IN UINT16 BootOptionNumber, IN UINT32 Modifier,...)
Definition: BmHotkey.c:972
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
UINTN EFIAPI AsciiPrint(IN CONST CHAR8 *Format,...)
Definition: UefiLibPrint.c:250
EFI_STATUS EFIAPI EfiEventGroupSignal(IN CONST EFI_GUID *EventGroup)
Definition: UefiLib.c:310
#define EFI_VARIABLE_NON_VOLATILE
@ ByProtocol
Definition: UefiSpec.h:1528
EFI_PCI_IO_PROTOCOL_CONFIG Read
Definition: PciIo.h:232
EFI_SIMPLE_TEXT_INPUT_PROTOCOL * ConIn
Definition: UefiSpec.h:2066
Definition: Base.h:213