2 Implementation for PlatformBdsLib library class interfaces.
4 Copyright (C) 2015, 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/PlatformBdsLib.h>
22 #include <Library/QemuBootOrderLib.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/GraphicsOutput.h>
25 #include <Protocol/PciIo.h>
26 #include <Protocol/PciRootBridgeIo.h>
28 #include "IntelBdsPlatform.h"
30 #define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) }
35 VENDOR_DEVICE_PATH SerialDxe
;
36 UART_DEVICE_PATH Uart
;
37 VENDOR_DEFINED_DEVICE_PATH Vt100
;
38 EFI_DEVICE_PATH_PROTOCOL End
;
39 } PLATFORM_SERIAL_CONSOLE
;
42 #define SERIAL_DXE_FILE_GUID { \
43 0xD3987D4B, 0x971A, 0x435F, \
44 { 0x8C, 0xAF, 0x49, 0x67, 0xEB, 0x62, 0x72, 0x41 } \
47 STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole
= {
49 // VENDOR_DEVICE_PATH SerialDxe
52 { HARDWARE_DEVICE_PATH
, HW_VENDOR_DP
, DP_NODE_LEN (VENDOR_DEVICE_PATH
) },
57 // UART_DEVICE_PATH Uart
60 { MESSAGING_DEVICE_PATH
, MSG_UART_DP
, DP_NODE_LEN (UART_DEVICE_PATH
) },
62 FixedPcdGet64 (PcdUartDefaultBaudRate
), // BaudRate
63 FixedPcdGet8 (PcdUartDefaultDataBits
), // DataBits
64 FixedPcdGet8 (PcdUartDefaultParity
), // Parity
65 FixedPcdGet8 (PcdUartDefaultStopBits
) // StopBits
69 // VENDOR_DEFINED_DEVICE_PATH Vt100
73 MESSAGING_DEVICE_PATH
, MSG_VENDOR_DP
,
74 DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH
)
80 // EFI_DEVICE_PATH_PROTOCOL End
83 END_DEVICE_PATH_TYPE
, END_ENTIRE_DEVICE_PATH_SUBTYPE
,
84 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL
)
91 USB_CLASS_DEVICE_PATH Keyboard
;
92 EFI_DEVICE_PATH_PROTOCOL End
;
93 } PLATFORM_USB_KEYBOARD
;
96 STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard
= {
98 // USB_CLASS_DEVICE_PATH Keyboard
102 MESSAGING_DEVICE_PATH
, MSG_USB_CLASS_DP
,
103 DP_NODE_LEN (USB_CLASS_DEVICE_PATH
)
105 0xFFFF, // VendorId: any
106 0xFFFF, // ProductId: any
107 3, // DeviceClass: HID
108 1, // DeviceSubClass: boot
109 1 // DeviceProtocol: keyboard
113 // EFI_DEVICE_PATH_PROTOCOL End
116 END_DEVICE_PATH_TYPE
, END_ENTIRE_DEVICE_PATH_SUBTYPE
,
117 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL
)
123 // BDS Platform Functions
126 Platform Bds init. Include the platform firmware vendor, revision
140 Check if the handle satisfies a particular condition.
142 @param[in] Handle The handle to check.
143 @param[in] ReportText A caller-allocated string passed in for reporting
144 purposes. It must never be NULL.
146 @retval TRUE The condition is satisfied.
147 @retval FALSE Otherwise. This includes the case when the condition could not
148 be fully evaluated due to an error.
152 (EFIAPI
*FILTER_FUNCTION
) (
153 IN EFI_HANDLE Handle
,
154 IN CONST CHAR16
*ReportText
161 @param[in] Handle The handle to process.
162 @param[in] ReportText A caller-allocated string passed in for reporting
163 purposes. It must never be NULL.
167 (EFIAPI
*CALLBACK_FUNCTION
) (
168 IN EFI_HANDLE Handle
,
169 IN CONST CHAR16
*ReportText
173 Locate all handles that carry the specified protocol, filter them with a
174 callback function, and pass each handle that passes the filter to another
177 @param[in] ProtocolGuid The protocol to look for.
179 @param[in] Filter The filter function to pass each handle to. If this
180 parameter is NULL, then all handles are processed.
182 @param[in] Process The callback function to pass each handle to that
188 IN EFI_GUID
*ProtocolGuid
,
189 IN FILTER_FUNCTION Filter OPTIONAL
,
190 IN CALLBACK_FUNCTION Process
198 Status
= gBS
->LocateHandleBuffer (ByProtocol
, ProtocolGuid
,
199 NULL
/* SearchKey */, &NoHandles
, &Handles
);
200 if (EFI_ERROR (Status
)) {
202 // This is not an error, just an informative condition.
204 DEBUG ((EFI_D_VERBOSE
, "%a: %g: %r\n", __FUNCTION__
, ProtocolGuid
,
209 ASSERT (NoHandles
> 0);
210 for (Idx
= 0; Idx
< NoHandles
; ++Idx
) {
211 CHAR16
*DevicePathText
;
212 STATIC CHAR16 Fallback
[] = L
"<device path unavailable>";
215 // The ConvertDevicePathToText() function handles NULL input transparently.
217 DevicePathText
= ConvertDevicePathToText (
218 DevicePathFromHandle (Handles
[Idx
]),
219 FALSE
, // DisplayOnly
220 FALSE
// AllowShortcuts
222 if (DevicePathText
== NULL
) {
223 DevicePathText
= Fallback
;
226 if (Filter
== NULL
|| Filter (Handles
[Idx
], DevicePathText
)) {
227 Process (Handles
[Idx
], DevicePathText
);
230 if (DevicePathText
!= Fallback
) {
231 FreePool (DevicePathText
);
234 gBS
->FreePool (Handles
);
239 This FILTER_FUNCTION checks if a handle corresponds to a PCI display device.
245 IN EFI_HANDLE Handle
,
246 IN CONST CHAR16
*ReportText
250 EFI_PCI_IO_PROTOCOL
*PciIo
;
253 Status
= gBS
->HandleProtocol (Handle
, &gEfiPciIoProtocolGuid
,
255 if (EFI_ERROR (Status
)) {
257 // This is not an error worth reporting.
262 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0 /* Offset */,
263 sizeof Pci
/ sizeof (UINT32
), &Pci
);
264 if (EFI_ERROR (Status
)) {
265 DEBUG ((EFI_D_ERROR
, "%a: %s: %r\n", __FUNCTION__
, ReportText
, Status
));
269 return IS_PCI_DISPLAY (&Pci
);
274 This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking
275 the matching driver to produce all first-level child handles.
281 IN EFI_HANDLE Handle
,
282 IN CONST CHAR16
*ReportText
287 Status
= gBS
->ConnectController (
288 Handle
, // ControllerHandle
289 NULL
, // DriverImageHandle
290 NULL
, // RemainingDevicePath -- produce all children
293 DEBUG ((EFI_ERROR (Status
) ? EFI_D_ERROR
: EFI_D_VERBOSE
, "%a: %s: %r\n",
294 __FUNCTION__
, ReportText
, Status
));
299 This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the
300 handle, and adds it to ConOut and ErrOut.
306 IN EFI_HANDLE Handle
,
307 IN CONST CHAR16
*ReportText
311 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
313 DevicePath
= DevicePathFromHandle (Handle
);
314 if (DevicePath
== NULL
) {
315 DEBUG ((EFI_D_ERROR
, "%a: %s: handle %p: device path not found\n",
316 __FUNCTION__
, ReportText
, Handle
));
320 Status
= BdsLibUpdateConsoleVariable (L
"ConOut", DevicePath
, NULL
);
321 if (EFI_ERROR (Status
)) {
322 DEBUG ((EFI_D_ERROR
, "%a: %s: adding to ConOut: %r\n", __FUNCTION__
,
323 ReportText
, Status
));
327 Status
= BdsLibUpdateConsoleVariable (L
"ErrOut", DevicePath
, NULL
);
328 if (EFI_ERROR (Status
)) {
329 DEBUG ((EFI_D_ERROR
, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__
,
330 ReportText
, Status
));
334 DEBUG ((EFI_D_VERBOSE
, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__
,
340 The function will execute with as the platform policy, current policy
341 is driven by boot mode. IBV/OEM can customize this code for their specific
344 @param DriverOptionList The header of the driver option link list
345 @param BootOptionList The header of the boot option link list
346 @param ProcessCapsules A pointer to ProcessCapsules()
347 @param BaseMemoryTest A pointer to BaseMemoryTest()
352 PlatformBdsPolicyBehavior (
353 IN LIST_ENTRY
*DriverOptionList
,
354 IN LIST_ENTRY
*BootOptionList
,
355 IN PROCESS_CAPSULES ProcessCapsules
,
356 IN BASEM_MEMORY_TEST BaseMemoryTest
360 // Locate the PCI root bridges and make the PCI bus driver connect each,
361 // non-recursively. This will produce a number of child handles with PciIo on
364 FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid
, NULL
, Connect
);
367 // Find all display class PCI devices (using the handles from the previous
368 // step), and connect them non-recursively. This should produce a number of
369 // child handles with GOPs on them.
371 FilterAndProcess (&gEfiPciIoProtocolGuid
, IsPciDisplay
, Connect
);
374 // Now add the device path of all handles with GOP on them to ConOut and
377 FilterAndProcess (&gEfiGraphicsOutputProtocolGuid
, NULL
, AddOutput
);
380 // Add the hardcoded short-form USB keyboard device path to ConIn.
382 BdsLibUpdateConsoleVariable (L
"ConIn",
383 (EFI_DEVICE_PATH_PROTOCOL
*)&mUsbKeyboard
, NULL
);
386 // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.
388 BdsLibUpdateConsoleVariable (L
"ConIn",
389 (EFI_DEVICE_PATH_PROTOCOL
*)&mSerialConsole
, NULL
);
390 BdsLibUpdateConsoleVariable (L
"ConOut",
391 (EFI_DEVICE_PATH_PROTOCOL
*)&mSerialConsole
, NULL
);
392 BdsLibUpdateConsoleVariable (L
"ErrOut",
393 (EFI_DEVICE_PATH_PROTOCOL
*)&mSerialConsole
, NULL
);
396 // Connect the consoles based on the above variables.
398 BdsLibConnectAllDefaultConsoles ();
401 // Show the splash screen.
403 EnableQuietBoot (PcdGetPtr (PcdLogoFile
));
406 // Connect the rest of the devices.
411 // Process QEMU's -kernel command line option. Note that the kernel booted
412 // this way should receive ACPI tables, which is why we connect all devices
413 // first (see above) -- PCI enumeration blocks ACPI table installation, if
414 // there is a PCI host.
416 TryRunningQemuKernel ();
418 BdsLibEnumerateAllBootOption (BootOptionList
);
419 SetBootOrderFromQemu (BootOptionList
);
421 // The BootOrder variable may have changed, reload the in-memory list with
424 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
426 PlatformBdsEnterFrontPage (GetFrontPageTimeoutFromQemu(), TRUE
);
430 Hook point after a boot attempt succeeds. We don't expect a boot option to
431 return, so the UEFI 2.0 specification defines that you will default to an
432 interactive mode and stop processing the BootOrder list in this case. This
433 is also a platform implementation and can be customized by IBV/OEM.
435 @param Option Pointer to Boot Option that succeeded to boot.
440 PlatformBdsBootSuccess (
441 IN BDS_COMMON_OPTION
*Option
447 Hook point after a boot attempt fails.
449 @param Option Pointer to Boot Option that failed to boot.
450 @param Status Status returned from failed boot.
451 @param ExitData Exit data returned from failed boot.
452 @param ExitDataSize Exit data size returned from failed boot.
457 PlatformBdsBootFail (
458 IN BDS_COMMON_OPTION
*Option
,
459 IN EFI_STATUS Status
,
461 IN UINTN ExitDataSize
467 This function locks platform flash that is not allowed to be updated during normal boot path.
468 The flash layout is platform specific.
472 PlatformBdsLockNonUpdatableFlash (