2 Platform BDS customizations.
4 Copyright (c) 2004 - 2014, 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
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.
15 #include "BdsPlatform.h"
16 #include "QemuBootOrder.h"
23 VOID
*mEfiDevPathNotifyReg
;
24 EFI_EVENT mEfiDevPathEvent
;
25 VOID
*mEmuVariableEventReg
;
26 EFI_EVENT mEmuVariableEvent
;
27 BOOLEAN mDetectVgaOnly
;
36 (EFIAPI
*PROTOCOL_INSTANCE_CALLBACK
)(
43 @param[in] Handle - Handle of PCI device instance
44 @param[in] PciIo - PCI IO protocol instance
45 @param[in] Pci - PCI Header register block
49 (EFIAPI
*VISIT_PCI_INSTANCE_CALLBACK
)(
51 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
57 // Function prototypes
61 VisitAllInstancesOfProtocol (
63 IN PROTOCOL_INSTANCE_CALLBACK CallBackFunction
,
68 VisitAllPciInstancesOfProtocol (
69 IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction
73 InstallDevicePathCallback (
78 // BDS Platform Functions
89 Platform Bds init. Incude the platform firmware vendor, revision
100 DEBUG ((EFI_D_INFO
, "PlatformBdsInit\n"));
101 InstallDevicePathCallback ();
121 EFI_SUCCESS - Connect RootBridge successfully.
122 EFI_STATUS - Connect RootBridge fail.
127 EFI_HANDLE RootHandle
;
130 // Make all the PCI_IO protocols on PCI Seg 0 show up
132 BdsLibConnectDevicePath (gPlatformRootBridges
[0]);
134 Status
= gBS
->LocateDevicePath (
135 &gEfiDevicePathProtocolGuid
,
136 &gPlatformRootBridges
[0],
139 if (EFI_ERROR (Status
)) {
143 Status
= gBS
->ConnectController (RootHandle
, NULL
, NULL
, FALSE
);
144 if (EFI_ERROR (Status
)) {
153 PrepareLpcBridgeDevicePath (
154 IN EFI_HANDLE DeviceHandle
160 Add IsaKeyboard to ConIn,
161 add IsaSerial to ConOut, ConIn, ErrOut.
166 DeviceHandle - Handle of PCIIO protocol.
170 EFI_SUCCESS - LPC bridge is added to ConOut, ConIn, and ErrOut.
171 EFI_STATUS - No LPC bridge is added.
176 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
177 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
181 Status
= gBS
->HandleProtocol (
183 &gEfiDevicePathProtocolGuid
,
186 if (EFI_ERROR (Status
)) {
189 TempDevicePath
= DevicePath
;
194 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gPnpPs2KeyboardDeviceNode
);
196 BdsLibUpdateConsoleVariable (VarConsoleInp
, DevicePath
, NULL
);
201 DevicePath
= TempDevicePath
;
202 gPnp16550ComPortDeviceNode
.UID
= 0;
204 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gPnp16550ComPortDeviceNode
);
205 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gUartDeviceNode
);
206 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gTerminalTypeDeviceNode
);
211 DevPathStr
= DevicePathToStr(DevicePath
);
212 if (DevPathStr
!= NULL
) {
215 "BdsPlatform.c+%d: COM%d DevPath: %s\n",
217 gPnp16550ComPortDeviceNode
.UID
+ 1,
220 FreePool(DevPathStr
);
223 BdsLibUpdateConsoleVariable (VarConsoleOut
, DevicePath
, NULL
);
224 BdsLibUpdateConsoleVariable (VarConsoleInp
, DevicePath
, NULL
);
225 BdsLibUpdateConsoleVariable (VarErrorOut
, DevicePath
, NULL
);
230 DevicePath
= TempDevicePath
;
231 gPnp16550ComPortDeviceNode
.UID
= 1;
233 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gPnp16550ComPortDeviceNode
);
234 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gUartDeviceNode
);
235 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gTerminalTypeDeviceNode
);
240 DevPathStr
= DevicePathToStr(DevicePath
);
241 if (DevPathStr
!= NULL
) {
244 "BdsPlatform.c+%d: COM%d DevPath: %s\n",
246 gPnp16550ComPortDeviceNode
.UID
+ 1,
249 FreePool(DevPathStr
);
252 BdsLibUpdateConsoleVariable (VarConsoleOut
, DevicePath
, NULL
);
253 BdsLibUpdateConsoleVariable (VarConsoleInp
, DevicePath
, NULL
);
254 BdsLibUpdateConsoleVariable (VarErrorOut
, DevicePath
, NULL
);
261 IN EFI_DEVICE_PATH_PROTOCOL
*PciDevicePath
,
262 OUT EFI_DEVICE_PATH_PROTOCOL
**GopDevicePath
267 EFI_HANDLE PciDeviceHandle
;
268 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
269 EFI_DEVICE_PATH_PROTOCOL
*TempPciDevicePath
;
270 UINTN GopHandleCount
;
271 EFI_HANDLE
*GopHandleBuffer
;
273 if (PciDevicePath
== NULL
|| GopDevicePath
== NULL
) {
274 return EFI_INVALID_PARAMETER
;
278 // Initialize the GopDevicePath to be PciDevicePath
280 *GopDevicePath
= PciDevicePath
;
281 TempPciDevicePath
= PciDevicePath
;
283 Status
= gBS
->LocateDevicePath (
284 &gEfiDevicePathProtocolGuid
,
288 if (EFI_ERROR (Status
)) {
293 // Try to connect this handle, so that GOP dirver could start on this
294 // device and create child handles with GraphicsOutput Protocol installed
295 // on them, then we get device paths of these child handles and select
296 // them as possible console device.
298 gBS
->ConnectController (PciDeviceHandle
, NULL
, NULL
, FALSE
);
300 Status
= gBS
->LocateHandleBuffer (
302 &gEfiGraphicsOutputProtocolGuid
,
307 if (!EFI_ERROR (Status
)) {
309 // Add all the child handles as possible Console Device
311 for (Index
= 0; Index
< GopHandleCount
; Index
++) {
312 Status
= gBS
->HandleProtocol (GopHandleBuffer
[Index
], &gEfiDevicePathProtocolGuid
, (VOID
*)&TempDevicePath
);
313 if (EFI_ERROR (Status
)) {
319 GetDevicePathSize (PciDevicePath
) - END_DEVICE_PATH_LENGTH
322 // In current implementation, we only enable one of the child handles
323 // as console device, i.e. sotre one of the child handle's device
324 // path to variable "ConOut"
325 // In futhure, we could select all child handles to be console device
328 *GopDevicePath
= TempDevicePath
;
331 // Delete the PCI device's path that added by GetPlugInPciVgaDevicePath()
332 // Add the integrity GOP device path.
334 BdsLibUpdateConsoleVariable (VarConsoleOutDev
, NULL
, PciDevicePath
);
335 BdsLibUpdateConsoleVariable (VarConsoleOutDev
, TempDevicePath
, NULL
);
338 gBS
->FreePool (GopHandleBuffer
);
345 PreparePciVgaDevicePath (
346 IN EFI_HANDLE DeviceHandle
352 Add PCI VGA to ConOut.
357 DeviceHandle - Handle of PCIIO protocol.
361 EFI_SUCCESS - PCI VGA is added to ConOut.
362 EFI_STATUS - No PCI VGA device is added.
367 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
368 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
371 GopDevicePath
= NULL
;
372 Status
= gBS
->HandleProtocol (
374 &gEfiDevicePathProtocolGuid
,
377 if (EFI_ERROR (Status
)) {
381 GetGopDevicePath (DevicePath
, &GopDevicePath
);
382 DevicePath
= GopDevicePath
;
384 BdsLibUpdateConsoleVariable (VarConsoleOut
, DevicePath
, NULL
);
390 PreparePciSerialDevicePath (
391 IN EFI_HANDLE DeviceHandle
397 Add PCI Serial to ConOut, ConIn, ErrOut.
402 DeviceHandle - Handle of PCIIO protocol.
406 EFI_SUCCESS - PCI Serial is added to ConOut, ConIn, and ErrOut.
407 EFI_STATUS - No PCI Serial device is added.
412 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
415 Status
= gBS
->HandleProtocol (
417 &gEfiDevicePathProtocolGuid
,
420 if (EFI_ERROR (Status
)) {
424 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gUartDeviceNode
);
425 DevicePath
= AppendDevicePathNode (DevicePath
, (EFI_DEVICE_PATH_PROTOCOL
*)&gTerminalTypeDeviceNode
);
427 BdsLibUpdateConsoleVariable (VarConsoleOut
, DevicePath
, NULL
);
428 BdsLibUpdateConsoleVariable (VarConsoleInp
, DevicePath
, NULL
);
429 BdsLibUpdateConsoleVariable (VarErrorOut
, DevicePath
, NULL
);
435 VisitAllInstancesOfProtocol (
437 IN PROTOCOL_INSTANCE_CALLBACK CallBackFunction
,
443 EFI_HANDLE
*HandleBuffer
;
448 // Start to check all the PciIo to find all possible device
452 Status
= gBS
->LocateHandleBuffer (
459 if (EFI_ERROR (Status
)) {
463 for (Index
= 0; Index
< HandleCount
; Index
++) {
464 Status
= gBS
->HandleProtocol (HandleBuffer
[Index
], Id
, &Instance
);
465 if (EFI_ERROR (Status
)) {
469 Status
= (*CallBackFunction
) (
476 gBS
->FreePool (HandleBuffer
);
484 VisitingAPciInstance (
485 IN EFI_HANDLE Handle
,
491 EFI_PCI_IO_PROTOCOL
*PciIo
;
494 PciIo
= (EFI_PCI_IO_PROTOCOL
*) Instance
;
497 // Check for all PCI device
499 Status
= PciIo
->Pci
.Read (
503 sizeof (Pci
) / sizeof (UINT32
),
506 if (EFI_ERROR (Status
)) {
510 return (*(VISIT_PCI_INSTANCE_CALLBACK
)(UINTN
) Context
) (
521 VisitAllPciInstances (
522 IN VISIT_PCI_INSTANCE_CALLBACK CallBackFunction
525 return VisitAllInstancesOfProtocol (
526 &gEfiPciIoProtocolGuid
,
527 VisitingAPciInstance
,
528 (VOID
*)(UINTN
) CallBackFunction
534 Do platform specific PCI Device check and add them to
535 ConOut, ConIn, ErrOut.
537 @param[in] Handle - Handle of PCI device instance
538 @param[in] PciIo - PCI IO protocol instance
539 @param[in] Pci - PCI Header register block
541 @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.
542 @retval EFI_STATUS - PCI Device check or Console variable update fail.
547 DetectAndPreparePlatformPciDevicePath (
548 IN EFI_HANDLE Handle
,
549 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
555 Status
= PciIo
->Attributes (
557 EfiPciIoAttributeOperationEnable
,
558 EFI_PCI_DEVICE_ENABLE
,
561 ASSERT_EFI_ERROR (Status
);
563 if (!mDetectVgaOnly
) {
565 // Here we decide whether it is LPC Bridge
567 if ((IS_PCI_LPC (Pci
)) ||
568 ((IS_PCI_ISA_PDECODE (Pci
)) &&
569 (Pci
->Hdr
.VendorId
== 0x8086) &&
570 (Pci
->Hdr
.DeviceId
== 0x7000)
574 // Add IsaKeyboard to ConIn,
575 // add IsaSerial to ConOut, ConIn, ErrOut
577 DEBUG ((EFI_D_INFO
, "Found LPC Bridge device\n"));
578 PrepareLpcBridgeDevicePath (Handle
);
582 // Here we decide which Serial device to enable in PCI bus
584 if (IS_PCI_16550SERIAL (Pci
)) {
586 // Add them to ConOut, ConIn, ErrOut.
588 DEBUG ((EFI_D_INFO
, "Found PCI 16550 SERIAL device\n"));
589 PreparePciSerialDevicePath (Handle
);
595 // Here we decide which VGA device to enable in PCI bus
597 if (IS_PCI_VGA (Pci
)) {
599 // Add them to ConOut.
601 DEBUG ((EFI_D_INFO
, "Found PCI VGA device\n"));
602 PreparePciVgaDevicePath (Handle
);
611 Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut
613 @param[in] DetectVgaOnly - Only detect VGA device if it's TRUE.
615 @retval EFI_SUCCESS - PCI Device check and Console variable update successfully.
616 @retval EFI_STATUS - PCI Device check or Console variable update fail.
620 DetectAndPreparePlatformPciDevicePaths (
621 BOOLEAN DetectVgaOnly
624 mDetectVgaOnly
= DetectVgaOnly
;
625 return VisitAllPciInstances (DetectAndPreparePlatformPciDevicePath
);
630 PlatformBdsConnectConsole (
631 IN BDS_CONSOLE_CONNECT_ENTRY
*PlatformConsole
637 Connect the predefined platform default console device. Always try to find
638 and enable the vga device if have.
642 PlatformConsole - Predfined platform default console device array.
646 EFI_SUCCESS - Success connect at least one ConIn and ConOut
647 device, there must have one ConOut device is
650 EFI_STATUS - Return the status of
651 BdsLibConnectAllDefaultConsoles ()
657 EFI_DEVICE_PATH_PROTOCOL
*VarConout
;
658 EFI_DEVICE_PATH_PROTOCOL
*VarConin
;
659 UINTN DevicePathSize
;
662 // Connect RootBridge
664 VarConout
= BdsLibGetVariableAndSize (
666 &gEfiGlobalVariableGuid
,
669 VarConin
= BdsLibGetVariableAndSize (
671 &gEfiGlobalVariableGuid
,
675 if (VarConout
== NULL
|| VarConin
== NULL
) {
677 // Do platform specific PCI Device check and add them to ConOut, ConIn, ErrOut
679 DetectAndPreparePlatformPciDevicePaths (FALSE
);
682 // Have chance to connect the platform default console,
683 // the platform default console is the minimue device group
684 // the platform should support
686 for (Index
= 0; PlatformConsole
[Index
].DevicePath
!= NULL
; ++Index
) {
688 // Update the console variable with the connect type
690 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_IN
) == CONSOLE_IN
) {
691 BdsLibUpdateConsoleVariable (VarConsoleInp
, PlatformConsole
[Index
].DevicePath
, NULL
);
693 if ((PlatformConsole
[Index
].ConnectType
& CONSOLE_OUT
) == CONSOLE_OUT
) {
694 BdsLibUpdateConsoleVariable (VarConsoleOut
, PlatformConsole
[Index
].DevicePath
, NULL
);
696 if ((PlatformConsole
[Index
].ConnectType
& STD_ERROR
) == STD_ERROR
) {
697 BdsLibUpdateConsoleVariable (VarErrorOut
, PlatformConsole
[Index
].DevicePath
, NULL
);
702 // Only detect VGA device and add them to ConOut
704 DetectAndPreparePlatformPciDevicePaths (TRUE
);
708 // Connect the all the default console with current cosole variable
710 Status
= BdsLibConnectAllDefaultConsoles ();
711 if (EFI_ERROR (Status
)) {
724 // Bus 0, Device 0, Function 0 - Host to PCI Bridge
726 PciWrite8 (PCI_LIB_ADDRESS (0, 0, 0, 0x3c), 0x00);
729 // Bus 0, Device 1, Function 0 - PCI to ISA Bridge
731 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x3c), 0x00);
732 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x60), 0x0b); // LNKA routing target
733 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x61), 0x0b); // LNKB routing target
734 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x62), 0x0a); // LNKC routing target
735 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 0, 0x63), 0x0a); // LNKD routing target
738 // Bus 0, Device 1, Function 1 - IDE Controller
740 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 1, 0x3c), 0x00);
741 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 1, 0x0d), 0x40);
744 // Bus 0, Device 1, Function 3 - Power Managment Controller
746 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3c), 0x09);
747 PciWrite8 (PCI_LIB_ADDRESS (0, 1, 3, 0x3d), 0x01); // INTA
750 // Bus 0, Device 2, Function 0 - Video Controller
752 PciWrite8 (PCI_LIB_ADDRESS (0, 2, 0, 0x3c), 0x00);
755 // Bus 0, Device 3, Function 0 - Network Controller
757 PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3c), 0x0a);
758 PciWrite8 (PCI_LIB_ADDRESS (0, 3, 0, 0x3d), 0x01); // INTA (-> LNKC)
761 // Bus 0, Device 5, Function 0 - RAM Memory
763 PciWrite8 (PCI_LIB_ADDRESS (0, 5, 0, 0x3c), 0x0b);
764 PciWrite8 (PCI_LIB_ADDRESS (0, 5, 0, 0x3d), 0x01); // INTA (-> LNKA)
774 // Set ACPI SCI_EN bit in PMCNTRL
776 IoOr16 ((PciRead32 (PCI_LIB_ADDRESS (0, 1, 3, 0x40)) & ~BIT0
) + 4, BIT0
);
782 ConnectRecursivelyIfPciMassStorage (
783 IN EFI_HANDLE Handle
,
784 IN EFI_PCI_IO_PROTOCOL
*Instance
,
785 IN PCI_TYPE00
*PciHeader
789 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
792 if (IS_CLASS1 (PciHeader
, PCI_CLASS_MASS_STORAGE
)) {
794 Status
= gBS
->HandleProtocol (
796 &gEfiDevicePathProtocolGuid
,
799 if (EFI_ERROR (Status
)) {
806 DevPathStr
= DevicePathToStr (DevicePath
);
807 if (DevPathStr
!= NULL
) {
810 "Found Mass Storage device: %s\n",
813 FreePool(DevPathStr
);
816 Status
= gBS
->ConnectController (Handle
, NULL
, NULL
, TRUE
);
817 if (EFI_ERROR (Status
)) {
828 This notification function is invoked when the
829 EMU Variable FVB has been changed.
831 @param Event The event that occured
832 @param Context For EFI compatiblity. Not used.
837 EmuVariablesUpdatedCallback (
842 DEBUG ((EFI_D_INFO
, "EmuVariablesUpdatedCallback\n"));
843 UpdateNvVarsOnFileSystem ();
849 VisitingFileSystemInstance (
850 IN EFI_HANDLE Handle
,
856 STATIC BOOLEAN ConnectedToFileSystem
= FALSE
;
858 if (ConnectedToFileSystem
) {
859 return EFI_ALREADY_STARTED
;
862 Status
= ConnectNvVarsToFileSystem (Handle
);
863 if (EFI_ERROR (Status
)) {
867 ConnectedToFileSystem
= TRUE
;
869 EfiCreateProtocolNotifyEvent (
870 &gEfiDevicePathProtocolGuid
,
872 EmuVariablesUpdatedCallback
,
874 &mEmuVariableEventReg
876 PcdSet64 (PcdEmuVariableEvent
, (UINT64
)(UINTN
) mEmuVariableEvent
);
883 PlatformBdsRestoreNvVarsFromHardDisk (
886 VisitAllPciInstances (ConnectRecursivelyIfPciMassStorage
);
887 VisitAllInstancesOfProtocol (
888 &gEfiSimpleFileSystemProtocolGuid
,
889 VisitingFileSystemInstance
,
897 PlatformBdsConnectSequence (
904 Connect with predeined platform connect sequence,
905 the OEM/IBV can customize with their own connect sequence.
919 DEBUG ((EFI_D_INFO
, "PlatformBdsConnectSequence\n"));
924 // Here we can get the customized platform connect sequence
925 // Notes: we can connect with new variable which record the
926 // last time boots connect device path sequence
928 while (gPlatformConnectSequence
[Index
] != NULL
) {
930 // Build the platform boot option
932 BdsLibConnectDevicePath (gPlatformConnectSequence
[Index
]);
937 // Just use the simple policy to connect all devices
941 PciInitialization ();
942 AcpiInitialization ();
945 // Clear the logo after all devices are connected.
947 gST
->ConOut
->ClearScreen (gST
->ConOut
);
951 PlatformBdsGetDriverOption (
952 IN OUT LIST_ENTRY
*BdsDriverLists
958 Load the predefined driver option, OEM/IBV can customize this
959 to load their own drivers
963 BdsDriverLists - The header of the driver option link list.
971 DEBUG ((EFI_D_INFO
, "PlatformBdsGetDriverOption\n"));
976 PlatformBdsDiagnostics (
977 IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel
,
978 IN BOOLEAN QuietBoot
,
979 IN BASEM_MEMORY_TEST BaseMemoryTest
985 Perform the platform diagnostic, such like test memory. OEM/IBV also
986 can customize this fuction to support specific platform diagnostic.
990 MemoryTestLevel - The memory test intensive level
992 QuietBoot - Indicate if need to enable the quiet boot
994 BaseMemoryTest - A pointer to BaseMemoryTest()
1004 DEBUG ((EFI_D_INFO
, "PlatformBdsDiagnostics\n"));
1007 // Here we can decide if we need to show
1008 // the diagnostics screen
1009 // Notes: this quiet boot code should be remove
1010 // from the graphic lib
1013 EnableQuietBoot (PcdGetPtr(PcdLogoFile
));
1015 // Perform system diagnostic
1017 Status
= BaseMemoryTest (MemoryTestLevel
);
1018 if (EFI_ERROR (Status
)) {
1019 DisableQuietBoot ();
1025 // Perform system diagnostic
1027 Status
= BaseMemoryTest (MemoryTestLevel
);
1033 PlatformBdsPolicyBehavior (
1034 IN OUT LIST_ENTRY
*DriverOptionList
,
1035 IN OUT LIST_ENTRY
*BootOptionList
,
1036 IN PROCESS_CAPSULES ProcessCapsules
,
1037 IN BASEM_MEMORY_TEST BaseMemoryTest
1041 Routine Description:
1043 The function will excute with as the platform policy, current policy
1044 is driven by boot mode. IBV/OEM can customize this code for their specific
1049 DriverOptionList - The header of the driver option link list
1051 BootOptionList - The header of the boot option link list
1053 ProcessCapsules - A pointer to ProcessCapsules()
1055 BaseMemoryTest - A pointer to BaseMemoryTest()
1065 EFI_EVENT UserInputDurationTime
;
1067 BDS_COMMON_OPTION
*BootOption
;
1071 EFI_BOOT_MODE BootMode
;
1073 DEBUG ((EFI_D_INFO
, "PlatformBdsPolicyBehavior\n"));
1075 ConnectRootBridge ();
1077 if (PcdGetBool (PcdOvmfFlashVariablesEnable
)) {
1078 DEBUG ((EFI_D_INFO
, "PlatformBdsPolicyBehavior: not restoring NvVars "
1079 "from disk since flash variables appear to be supported.\n"));
1082 // Try to restore variables from the hard disk early so
1083 // they can be used for the other BDS connect operations.
1085 PlatformBdsRestoreNvVarsFromHardDisk ();
1089 // Init the time out value
1091 Timeout
= PcdGet16 (PcdPlatformBootTimeOut
);
1094 // Load the driver option as the driver option list
1096 PlatformBdsGetDriverOption (DriverOptionList
);
1099 // Get current Boot Mode
1101 Status
= BdsLibGetBootMode (&BootMode
);
1102 DEBUG ((EFI_D_ERROR
, "Boot Mode:%x\n", BootMode
));
1105 // Go the different platform policy with different boot mode
1106 // Notes: this part code can be change with the table policy
1108 ASSERT (BootMode
== BOOT_WITH_FULL_CONFIGURATION
);
1110 // Connect platform console
1112 Status
= PlatformBdsConnectConsole (gPlatformConsole
);
1113 if (EFI_ERROR (Status
)) {
1115 // Here OEM/IBV can customize with defined action
1117 PlatformBdsNoConsoleAction ();
1120 // Create a 300ms duration event to ensure user has enough input time to enter Setup
1122 Status
= gBS
->CreateEvent (
1127 &UserInputDurationTime
1129 ASSERT (Status
== EFI_SUCCESS
);
1130 Status
= gBS
->SetTimer (UserInputDurationTime
, TimerRelative
, 3000000);
1131 ASSERT (Status
== EFI_SUCCESS
);
1133 // Memory test and Logo show
1135 PlatformBdsDiagnostics (IGNORE
, TRUE
, BaseMemoryTest
);
1138 // Perform some platform specific connect sequence
1140 PlatformBdsConnectSequence ();
1143 // Process QEMU's -kernel command line option
1145 TryRunningQemuKernel ();
1148 // Give one chance to enter the setup if we
1149 // have the time out
1152 //PlatformBdsEnterFrontPage (Timeout, FALSE);
1155 DEBUG ((EFI_D_INFO
, "BdsLibConnectAll\n"));
1156 BdsLibConnectAll ();
1157 BdsLibEnumerateAllBootOption (BootOptionList
);
1159 SetBootOrderFromQemu (BootOptionList
);
1161 // The BootOrder variable may have changed, reload the in-memory list with
1164 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
1167 // To give the User a chance to enter Setup here, if user set TimeOut is 0.
1168 // BDS should still give user a chance to enter Setup
1170 // Connect first boot option, and then check user input before exit
1172 for (Link
= BootOptionList
->ForwardLink
; Link
!= BootOptionList
;Link
= Link
->ForwardLink
) {
1173 BootOption
= CR (Link
, BDS_COMMON_OPTION
, Link
, BDS_LOAD_OPTION_SIGNATURE
);
1174 if (!IS_LOAD_OPTION_TYPE (BootOption
->Attribute
, LOAD_OPTION_ACTIVE
)) {
1176 // skip the header of the link list, becuase it has no boot option
1181 // Make sure the boot option device path connected, but ignore the BBS device path
1183 if (DevicePathType (BootOption
->DevicePath
) != BBS_DEVICE_PATH
) {
1184 BdsLibConnectDevicePath (BootOption
->DevicePath
);
1191 // Check whether the user input after the duration time has expired
1193 OldTpl
= EfiGetCurrentTpl();
1194 gBS
->RestoreTPL (TPL_APPLICATION
);
1195 gBS
->WaitForEvent (1, &UserInputDurationTime
, &Index
);
1196 gBS
->CloseEvent (UserInputDurationTime
);
1197 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
1198 gBS
->RaiseTPL (OldTpl
);
1200 if (!EFI_ERROR (Status
)) {
1202 // Enter Setup if user input
1205 PlatformBdsEnterFrontPage (Timeout
, FALSE
);
1213 PlatformBdsBootSuccess (
1214 IN BDS_COMMON_OPTION
*Option
1218 Routine Description:
1220 Hook point after a boot attempt succeeds. We don't expect a boot option to
1221 return, so the EFI 1.0 specification defines that you will default to an
1222 interactive mode and stop processing the BootOrder list in this case. This
1223 is alos a platform implementation and can be customized by IBV/OEM.
1227 Option - Pointer to Boot Option that succeeded to boot.
1237 DEBUG ((EFI_D_INFO
, "PlatformBdsBootSuccess\n"));
1239 // If Boot returned with EFI_SUCCESS and there is not in the boot device
1240 // select loop then we need to pop up a UI and wait for user input.
1242 TmpStr
= Option
->StatusString
;
1243 if (TmpStr
!= NULL
) {
1244 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
1251 PlatformBdsBootFail (
1252 IN BDS_COMMON_OPTION
*Option
,
1253 IN EFI_STATUS Status
,
1254 IN CHAR16
*ExitData
,
1255 IN UINTN ExitDataSize
1259 Routine Description:
1261 Hook point after a boot attempt fails.
1265 Option - Pointer to Boot Option that failed to boot.
1267 Status - Status returned from failed boot.
1269 ExitData - Exit data returned from failed boot.
1271 ExitDataSize - Exit data size returned from failed boot.
1281 DEBUG ((EFI_D_INFO
, "PlatformBdsBootFail\n"));
1284 // If Boot returned with failed status then we need to pop up a UI and wait
1287 TmpStr
= Option
->StatusString
;
1288 if (TmpStr
!= NULL
) {
1289 BdsLibOutputStrings (gST
->ConOut
, TmpStr
, Option
->Description
, L
"\n\r", NULL
);
1295 PlatformBdsNoConsoleAction (
1300 Routine Description:
1302 This function is remained for IBV/OEM to do some platform action,
1303 if there no console device can be connected.
1311 EFI_SUCCESS - Direct return success now.
1315 DEBUG ((EFI_D_INFO
, "PlatformBdsNoConsoleAction\n"));
1321 PlatformBdsLockNonUpdatableFlash (
1325 DEBUG ((EFI_D_INFO
, "PlatformBdsLockNonUpdatableFlash\n"));
1331 This notification function is invoked when an instance of the
1332 EFI_DEVICE_PATH_PROTOCOL is produced.
1334 @param Event The event that occured
1335 @param Context For EFI compatiblity. Not used.
1348 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
1349 ATAPI_DEVICE_PATH
*Atapi
;
1352 // Examine all new handles
1356 // Get the next handle
1358 BufferSize
= sizeof (Handle
);
1359 Status
= gBS
->LocateHandle (
1362 mEfiDevPathNotifyReg
,
1368 // If not found, we're done
1370 if (EFI_NOT_FOUND
== Status
) {
1374 if (EFI_ERROR (Status
)) {
1379 // Get the DevicePath protocol on that handle
1381 Status
= gBS
->HandleProtocol (Handle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevPathNode
);
1382 ASSERT_EFI_ERROR (Status
);
1384 while (!IsDevicePathEnd (DevPathNode
)) {
1386 // Find the handler to dump this device path node
1389 (DevicePathType(DevPathNode
) == MESSAGING_DEVICE_PATH
) &&
1390 (DevicePathSubType(DevPathNode
) == MSG_ATAPI_DP
)
1392 Atapi
= (ATAPI_DEVICE_PATH
*) DevPathNode
;
1398 (Atapi
->PrimarySecondary
== 1) ? 0x42: 0x40
1405 // Next device path node
1407 DevPathNode
= NextDevicePathNode (DevPathNode
);
1416 InstallDevicePathCallback (
1420 DEBUG ((EFI_D_INFO
, "Registered NotifyDevPath Event\n"));
1421 mEfiDevPathEvent
= EfiCreateProtocolNotifyEvent (
1422 &gEfiDevicePathProtocolGuid
,
1426 &mEfiDevPathNotifyReg
1431 Lock the ConsoleIn device in system table. All key
1432 presses will be ignored until the Password is typed in. The only way to
1433 disable the password is to type it in to a ConIn device.
1435 @param Password Password used to lock ConIn device.
1437 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.
1438 @retval EFI_UNSUPPORTED Password not found
1447 return EFI_UNSUPPORTED
;