2 Implementation for PlatformBootManagerLib library class interfaces.
4 Copyright (C) 2015-2016, Red Hat, Inc.
5 Copyright (c) 2014, ARM Ltd. All rights reserved.<BR>
6 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <IndustryStandard/Pci22.h>
19 #include <Library/DevicePathLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/QemuBootOrderLib.h>
22 #include <Protocol/DevicePath.h>
23 #include <Protocol/GraphicsOutput.h>
24 #include <Protocol/PciIo.h>
25 #include <Protocol/PciRootBridgeIo.h>
26 #include <Guid/EventGroup.h>
27 #include <Guid/RootBridgesConnectedEventGroup.h>
29 #include "PlatformBm.h"
31 #define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) }
36 VENDOR_DEVICE_PATH SerialDxe
;
37 UART_DEVICE_PATH Uart
;
38 VENDOR_DEFINED_DEVICE_PATH TermType
;
39 EFI_DEVICE_PATH_PROTOCOL End
;
40 } PLATFORM_SERIAL_CONSOLE
;
43 #define SERIAL_DXE_FILE_GUID { \
44 0xD3987D4B, 0x971A, 0x435F, \
45 { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \
48 STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole
= {
50 // VENDOR_DEVICE_PATH SerialDxe
53 { HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
, DP_NODE_LEN (VENDOR_DEVICE_PATH
) },
58 // UART_DEVICE_PATH Uart
61 { MESSAGING_DEVICE_PATH
, MSG_UART_DP
, DP_NODE_LEN (UART_DEVICE_PATH
) },
63 FixedPcdGet64 (PcdUartDefaultBaudRate
), // BaudRate
64 FixedPcdGet8 (PcdUartDefaultDataBits
), // DataBits
65 FixedPcdGet8 (PcdUartDefaultParity
), // Parity
66 FixedPcdGet8 (PcdUartDefaultStopBits
) // StopBits
70 // VENDOR_DEFINED_DEVICE_PATH TermType
74 MESSAGING_DEVICE_PATH
, MSG_VENDOR_DP
,
75 DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH
)
78 // Guid to be filled in dynamically
83 // EFI_DEVICE_PATH_PROTOCOL End
86 END_DEVICE_PATH_TYPE
, END_ENTIRE_DEVICE_PATH_SUBTYPE
,
87 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL
)
94 USB_CLASS_DEVICE_PATH Keyboard
;
95 EFI_DEVICE_PATH_PROTOCOL End
;
96 } PLATFORM_USB_KEYBOARD
;
99 STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard
= {
101 // USB_CLASS_DEVICE_PATH Keyboard
105 MESSAGING_DEVICE_PATH
, MSG_USB_CLASS_DP
,
106 DP_NODE_LEN (USB_CLASS_DEVICE_PATH
)
108 0xFFFF, // VendorId: any
109 0xFFFF, // ProductId: any
110 3, // DeviceClass: HID
111 1, // DeviceSubClass: boot
112 1 // DeviceProtocol: keyboard
116 // EFI_DEVICE_PATH_PROTOCOL End
119 END_DEVICE_PATH_TYPE
, END_ENTIRE_DEVICE_PATH_SUBTYPE
,
120 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL
)
125 // BDS Platform Functions
128 Do the platform init, can be customized by OEM/IBV
129 Possible things that can be done in PlatformBootManagerBeforeConsole:
130 > Update console variable: 1. include hot-plug devices;
131 > 2. Clear ConIn and add SOL for AMT
132 > Register new Driver#### or Boot####
133 > Register new Key####: e.g.: F12
134 > Signal ReadyToLock event
135 > Authentication action: 1. connect Auth devices;
136 > 2. Identify auto logon user.
140 PlatformBootManagerBeforeConsole (
145 // Signal EndOfDxe PI Event
147 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid
);
152 Check if the handle satisfies a particular condition.
154 @param[in] Handle The handle to check.
155 @param[in] ReportText A caller-allocated string passed in for reporting
156 purposes. It must never be NULL.
158 @retval TRUE The condition is satisfied.
159 @retval FALSE Otherwise. This includes the case when the condition could not
160 be fully evaluated due to an error.
164 (EFIAPI
*FILTER_FUNCTION
) (
165 IN EFI_HANDLE Handle
,
166 IN CONST CHAR16
*ReportText
173 @param[in] Handle The handle to process.
174 @param[in] ReportText A caller-allocated string passed in for reporting
175 purposes. It must never be NULL.
179 (EFIAPI
*CALLBACK_FUNCTION
) (
180 IN EFI_HANDLE Handle
,
181 IN CONST CHAR16
*ReportText
185 Locate all handles that carry the specified protocol, filter them with a
186 callback function, and pass each handle that passes the filter to another
189 @param[in] ProtocolGuid The protocol to look for.
191 @param[in] Filter The filter function to pass each handle to. If this
192 parameter is NULL, then all handles are processed.
194 @param[in] Process The callback function to pass each handle to that
200 IN EFI_GUID
*ProtocolGuid
,
201 IN FILTER_FUNCTION Filter OPTIONAL
,
202 IN CALLBACK_FUNCTION Process
210 Status
= gBS
->LocateHandleBuffer (ByProtocol
, ProtocolGuid
,
211 NULL
/* SearchKey */, &NoHandles
, &Handles
);
212 if (EFI_ERROR (Status
)) {
214 // This is not an error, just an informative condition.
216 DEBUG ((EFI_D_VERBOSE
, "%a: %g: %r\n", __FUNCTION__
, ProtocolGuid
,
221 ASSERT (NoHandles
> 0);
222 for (Idx
= 0; Idx
< NoHandles
; ++Idx
) {
223 CHAR16
*DevicePathText
;
224 STATIC CHAR16 Fallback
[] = L
"<device path unavailable>";
227 // The ConvertDevicePathToText() function handles NULL input transparently.
229 DevicePathText
= ConvertDevicePathToText (
230 DevicePathFromHandle (Handles
[Idx
]),
231 FALSE
, // DisplayOnly
232 FALSE
// AllowShortcuts
234 if (DevicePathText
== NULL
) {
235 DevicePathText
= Fallback
;
238 if (Filter
== NULL
|| Filter (Handles
[Idx
], DevicePathText
)) {
239 Process (Handles
[Idx
], DevicePathText
);
242 if (DevicePathText
!= Fallback
) {
243 FreePool (DevicePathText
);
246 gBS
->FreePool (Handles
);
251 This FILTER_FUNCTION checks if a handle corresponds to a PCI display device.
257 IN EFI_HANDLE Handle
,
258 IN CONST CHAR16
*ReportText
262 EFI_PCI_IO_PROTOCOL
*PciIo
;
265 Status
= gBS
->HandleProtocol (Handle
, &gEfiPciIoProtocolGuid
,
267 if (EFI_ERROR (Status
)) {
269 // This is not an error worth reporting.
274 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0 /* Offset */,
275 sizeof Pci
/ sizeof (UINT32
), &Pci
);
276 if (EFI_ERROR (Status
)) {
277 DEBUG ((EFI_D_ERROR
, "%a: %s: %r\n", __FUNCTION__
, ReportText
, Status
));
281 return IS_PCI_DISPLAY (&Pci
);
286 This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking
287 the matching driver to produce all first-level child handles.
293 IN EFI_HANDLE Handle
,
294 IN CONST CHAR16
*ReportText
299 Status
= gBS
->ConnectController (
300 Handle
, // ControllerHandle
301 NULL
, // DriverImageHandle
302 NULL
, // RemainingDevicePath -- produce all children
305 DEBUG ((EFI_ERROR (Status
) ? EFI_D_ERROR
: EFI_D_VERBOSE
, "%a: %s: %r\n",
306 __FUNCTION__
, ReportText
, Status
));
311 This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the
312 handle, and adds it to ConOut and ErrOut.
318 IN EFI_HANDLE Handle
,
319 IN CONST CHAR16
*ReportText
323 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
325 DevicePath
= DevicePathFromHandle (Handle
);
326 if (DevicePath
== NULL
) {
327 DEBUG ((EFI_D_ERROR
, "%a: %s: handle %p: device path not found\n",
328 __FUNCTION__
, ReportText
, Handle
));
332 Status
= BdsLibUpdateConsoleVariable (L
"ConOut", DevicePath
, NULL
);
333 if (EFI_ERROR (Status
)) {
334 DEBUG ((EFI_D_ERROR
, "%a: %s: adding to ConOut: %r\n", __FUNCTION__
,
335 ReportText
, Status
));
339 Status
= BdsLibUpdateConsoleVariable (L
"ErrOut", DevicePath
, NULL
);
340 if (EFI_ERROR (Status
)) {
341 DEBUG ((EFI_D_ERROR
, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__
,
342 ReportText
, Status
));
346 DEBUG ((EFI_D_VERBOSE
, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__
,
352 Do the platform specific action after the console is ready
353 Possible things that can be done in PlatformBootManagerAfterConsole:
354 > Console post action:
355 > Dynamically switch output mode from 100x31 to 80x25 for certain senarino
356 > Signal console ready platform customized event
357 > Run diagnostics like memory testing
358 > Connect certain devices
359 > Dispatch aditional option roms
360 > Special boot: e.g.: USB boot, enter UI
364 PlatformBootManagerAfterConsole (
369 // Locate the PCI root bridges and make the PCI bus driver connect each,
370 // non-recursively. This will produce a number of child handles with PciIo on
373 FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid
, NULL
, Connect
);
376 // Signal the ACPI platform driver that it can download QEMU ACPI tables.
378 EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid
);
381 // Find all display class PCI devices (using the handles from the previous
382 // step), and connect them non-recursively. This should produce a number of
383 // child handles with GOPs on them.
385 FilterAndProcess (&gEfiPciIoProtocolGuid
, IsPciDisplay
, Connect
);
388 // Now add the device path of all handles with GOP on them to ConOut and
391 FilterAndProcess (&gEfiGraphicsOutputProtocolGuid
, NULL
, AddOutput
);
394 // Add the hardcoded short-form USB keyboard device path to ConIn.
396 BdsLibUpdateConsoleVariable (L
"ConIn",
397 (EFI_DEVICE_PATH_PROTOCOL
*)&mUsbKeyboard
, NULL
);
400 // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.
402 CopyGuid (&mSerialConsole
.TermType
.Guid
,
403 PcdGetPtr (PcdTerminalTypeGuidBuffer
));
404 BdsLibUpdateConsoleVariable (L
"ConIn",
405 (EFI_DEVICE_PATH_PROTOCOL
*)&mSerialConsole
, NULL
);
406 BdsLibUpdateConsoleVariable (L
"ConOut",
407 (EFI_DEVICE_PATH_PROTOCOL
*)&mSerialConsole
, NULL
);
408 BdsLibUpdateConsoleVariable (L
"ErrOut",
409 (EFI_DEVICE_PATH_PROTOCOL
*)&mSerialConsole
, NULL
);
412 // Connect the consoles based on the above variables.
414 BdsLibConnectAllDefaultConsoles ();
417 // Show the splash screen.
419 EnableQuietBoot (PcdGetPtr (PcdLogoFile
));
422 // Connect the rest of the devices.
427 // Process QEMU's -kernel command line option. Note that the kernel booted
428 // this way should receive ACPI tables, which is why we connect all devices
429 // first (see above) -- PCI enumeration blocks ACPI table installation, if
430 // there is a PCI host.
432 TryRunningQemuKernel ();
434 BdsLibEnumerateAllBootOption (BootOptionList
);
435 SetBootOrderFromQemu (BootOptionList
);
437 // The BootOrder variable may have changed, reload the in-memory list with
440 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
442 PlatformBdsEnterFrontPage (GetFrontPageTimeoutFromQemu(), TRUE
);
446 Hook point after a boot attempt succeeds. We don't expect a boot option to
447 return, so the UEFI 2.0 specification defines that you will default to an
448 interactive mode and stop processing the BootOrder list in this case. This
449 is also a platform implementation and can be customized by IBV/OEM.
451 @param Option Pointer to Boot Option that succeeded to boot.
456 PlatformBdsBootSuccess (
457 IN BDS_COMMON_OPTION
*Option
463 Hook point after a boot attempt fails.
465 @param Option Pointer to Boot Option that failed to boot.
466 @param Status Status returned from failed boot.
467 @param ExitData Exit data returned from failed boot.
468 @param ExitDataSize Exit data size returned from failed boot.
473 PlatformBdsBootFail (
474 IN BDS_COMMON_OPTION
*Option
,
475 IN EFI_STATUS Status
,
477 IN UINTN ExitDataSize
483 This function locks platform flash that is not allowed to be updated during normal boot path.
484 The flash layout is platform specific.
488 PlatformBdsLockNonUpdatableFlash (
496 This function is called each second during the boot manager waits the
499 @param TimeoutRemain The remaining timeout.
503 PlatformBootManagerWaitCallback (