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>
27 #include <Guid/EventGroup.h>
29 #include "IntelBdsPlatform.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 Vt100
;
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 Vt100
74 MESSAGING_DEVICE_PATH
, MSG_VENDOR_DP
,
75 DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH
)
81 // EFI_DEVICE_PATH_PROTOCOL End
84 END_DEVICE_PATH_TYPE
, END_ENTIRE_DEVICE_PATH_SUBTYPE
,
85 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL
)
92 USB_CLASS_DEVICE_PATH Keyboard
;
93 EFI_DEVICE_PATH_PROTOCOL End
;
94 } PLATFORM_USB_KEYBOARD
;
97 STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard
= {
99 // USB_CLASS_DEVICE_PATH Keyboard
103 MESSAGING_DEVICE_PATH
, MSG_USB_CLASS_DP
,
104 DP_NODE_LEN (USB_CLASS_DEVICE_PATH
)
106 0xFFFF, // VendorId: any
107 0xFFFF, // ProductId: any
108 3, // DeviceClass: HID
109 1, // DeviceSubClass: boot
110 1 // DeviceProtocol: keyboard
114 // EFI_DEVICE_PATH_PROTOCOL End
117 END_DEVICE_PATH_TYPE
, END_ENTIRE_DEVICE_PATH_SUBTYPE
,
118 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL
)
123 An empty function to pass error checking of CreateEventEx ().
125 @param Event Event whose notification function is being invoked.
126 @param Context Pointer to the notification function's context,
127 which is implementation-dependent.
133 EmptyCallbackFunction (
141 // BDS Platform Functions
144 Platform Bds init. Include the platform firmware vendor, revision
154 EFI_EVENT EndOfDxeEvent
;
158 // Signal EndOfDxe PI Event
160 Status
= gBS
->CreateEventEx (
163 EmptyCallbackFunction
,
165 &gEfiEndOfDxeEventGroupGuid
,
168 if (!EFI_ERROR (Status
)) {
169 gBS
->SignalEvent (EndOfDxeEvent
);
170 gBS
->CloseEvent (EndOfDxeEvent
);
176 Check if the handle satisfies a particular condition.
178 @param[in] Handle The handle to check.
179 @param[in] ReportText A caller-allocated string passed in for reporting
180 purposes. It must never be NULL.
182 @retval TRUE The condition is satisfied.
183 @retval FALSE Otherwise. This includes the case when the condition could not
184 be fully evaluated due to an error.
188 (EFIAPI
*FILTER_FUNCTION
) (
189 IN EFI_HANDLE Handle
,
190 IN CONST CHAR16
*ReportText
197 @param[in] Handle The handle to process.
198 @param[in] ReportText A caller-allocated string passed in for reporting
199 purposes. It must never be NULL.
203 (EFIAPI
*CALLBACK_FUNCTION
) (
204 IN EFI_HANDLE Handle
,
205 IN CONST CHAR16
*ReportText
209 Locate all handles that carry the specified protocol, filter them with a
210 callback function, and pass each handle that passes the filter to another
213 @param[in] ProtocolGuid The protocol to look for.
215 @param[in] Filter The filter function to pass each handle to. If this
216 parameter is NULL, then all handles are processed.
218 @param[in] Process The callback function to pass each handle to that
224 IN EFI_GUID
*ProtocolGuid
,
225 IN FILTER_FUNCTION Filter OPTIONAL
,
226 IN CALLBACK_FUNCTION Process
234 Status
= gBS
->LocateHandleBuffer (ByProtocol
, ProtocolGuid
,
235 NULL
/* SearchKey */, &NoHandles
, &Handles
);
236 if (EFI_ERROR (Status
)) {
238 // This is not an error, just an informative condition.
240 DEBUG ((EFI_D_VERBOSE
, "%a: %g: %r\n", __FUNCTION__
, ProtocolGuid
,
245 ASSERT (NoHandles
> 0);
246 for (Idx
= 0; Idx
< NoHandles
; ++Idx
) {
247 CHAR16
*DevicePathText
;
248 STATIC CHAR16 Fallback
[] = L
"<device path unavailable>";
251 // The ConvertDevicePathToText() function handles NULL input transparently.
253 DevicePathText
= ConvertDevicePathToText (
254 DevicePathFromHandle (Handles
[Idx
]),
255 FALSE
, // DisplayOnly
256 FALSE
// AllowShortcuts
258 if (DevicePathText
== NULL
) {
259 DevicePathText
= Fallback
;
262 if (Filter
== NULL
|| Filter (Handles
[Idx
], DevicePathText
)) {
263 Process (Handles
[Idx
], DevicePathText
);
266 if (DevicePathText
!= Fallback
) {
267 FreePool (DevicePathText
);
270 gBS
->FreePool (Handles
);
275 This FILTER_FUNCTION checks if a handle corresponds to a PCI display device.
281 IN EFI_HANDLE Handle
,
282 IN CONST CHAR16
*ReportText
286 EFI_PCI_IO_PROTOCOL
*PciIo
;
289 Status
= gBS
->HandleProtocol (Handle
, &gEfiPciIoProtocolGuid
,
291 if (EFI_ERROR (Status
)) {
293 // This is not an error worth reporting.
298 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0 /* Offset */,
299 sizeof Pci
/ sizeof (UINT32
), &Pci
);
300 if (EFI_ERROR (Status
)) {
301 DEBUG ((EFI_D_ERROR
, "%a: %s: %r\n", __FUNCTION__
, ReportText
, Status
));
305 return IS_PCI_DISPLAY (&Pci
);
310 This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking
311 the matching driver to produce all first-level child handles.
317 IN EFI_HANDLE Handle
,
318 IN CONST CHAR16
*ReportText
323 Status
= gBS
->ConnectController (
324 Handle
, // ControllerHandle
325 NULL
, // DriverImageHandle
326 NULL
, // RemainingDevicePath -- produce all children
329 DEBUG ((EFI_ERROR (Status
) ? EFI_D_ERROR
: EFI_D_VERBOSE
, "%a: %s: %r\n",
330 __FUNCTION__
, ReportText
, Status
));
335 This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the
336 handle, and adds it to ConOut and ErrOut.
342 IN EFI_HANDLE Handle
,
343 IN CONST CHAR16
*ReportText
347 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
349 DevicePath
= DevicePathFromHandle (Handle
);
350 if (DevicePath
== NULL
) {
351 DEBUG ((EFI_D_ERROR
, "%a: %s: handle %p: device path not found\n",
352 __FUNCTION__
, ReportText
, Handle
));
356 Status
= BdsLibUpdateConsoleVariable (L
"ConOut", DevicePath
, NULL
);
357 if (EFI_ERROR (Status
)) {
358 DEBUG ((EFI_D_ERROR
, "%a: %s: adding to ConOut: %r\n", __FUNCTION__
,
359 ReportText
, Status
));
363 Status
= BdsLibUpdateConsoleVariable (L
"ErrOut", DevicePath
, NULL
);
364 if (EFI_ERROR (Status
)) {
365 DEBUG ((EFI_D_ERROR
, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__
,
366 ReportText
, Status
));
370 DEBUG ((EFI_D_VERBOSE
, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__
,
376 The function will execute with as the platform policy, current policy
377 is driven by boot mode. IBV/OEM can customize this code for their specific
380 @param DriverOptionList The header of the driver option link list
381 @param BootOptionList The header of the boot option link list
382 @param ProcessCapsules A pointer to ProcessCapsules()
383 @param BaseMemoryTest A pointer to BaseMemoryTest()
388 PlatformBdsPolicyBehavior (
389 IN LIST_ENTRY
*DriverOptionList
,
390 IN LIST_ENTRY
*BootOptionList
,
391 IN PROCESS_CAPSULES ProcessCapsules
,
392 IN BASEM_MEMORY_TEST BaseMemoryTest
396 // Locate the PCI root bridges and make the PCI bus driver connect each,
397 // non-recursively. This will produce a number of child handles with PciIo on
400 FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid
, NULL
, Connect
);
403 // Find all display class PCI devices (using the handles from the previous
404 // step), and connect them non-recursively. This should produce a number of
405 // child handles with GOPs on them.
407 FilterAndProcess (&gEfiPciIoProtocolGuid
, IsPciDisplay
, Connect
);
410 // Now add the device path of all handles with GOP on them to ConOut and
413 FilterAndProcess (&gEfiGraphicsOutputProtocolGuid
, NULL
, AddOutput
);
416 // Add the hardcoded short-form USB keyboard device path to ConIn.
418 BdsLibUpdateConsoleVariable (L
"ConIn",
419 (EFI_DEVICE_PATH_PROTOCOL
*)&mUsbKeyboard
, NULL
);
422 // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.
424 BdsLibUpdateConsoleVariable (L
"ConIn",
425 (EFI_DEVICE_PATH_PROTOCOL
*)&mSerialConsole
, NULL
);
426 BdsLibUpdateConsoleVariable (L
"ConOut",
427 (EFI_DEVICE_PATH_PROTOCOL
*)&mSerialConsole
, NULL
);
428 BdsLibUpdateConsoleVariable (L
"ErrOut",
429 (EFI_DEVICE_PATH_PROTOCOL
*)&mSerialConsole
, NULL
);
432 // Connect the consoles based on the above variables.
434 BdsLibConnectAllDefaultConsoles ();
437 // Show the splash screen.
439 EnableQuietBoot (PcdGetPtr (PcdLogoFile
));
442 // Connect the rest of the devices.
447 // Process QEMU's -kernel command line option. Note that the kernel booted
448 // this way should receive ACPI tables, which is why we connect all devices
449 // first (see above) -- PCI enumeration blocks ACPI table installation, if
450 // there is a PCI host.
452 TryRunningQemuKernel ();
454 BdsLibEnumerateAllBootOption (BootOptionList
);
455 SetBootOrderFromQemu (BootOptionList
);
457 // The BootOrder variable may have changed, reload the in-memory list with
460 BdsLibBuildOptionFromVar (BootOptionList
, L
"BootOrder");
462 PlatformBdsEnterFrontPage (GetFrontPageTimeoutFromQemu(), TRUE
);
466 Hook point after a boot attempt succeeds. We don't expect a boot option to
467 return, so the UEFI 2.0 specification defines that you will default to an
468 interactive mode and stop processing the BootOrder list in this case. This
469 is also a platform implementation and can be customized by IBV/OEM.
471 @param Option Pointer to Boot Option that succeeded to boot.
476 PlatformBdsBootSuccess (
477 IN BDS_COMMON_OPTION
*Option
483 Hook point after a boot attempt fails.
485 @param Option Pointer to Boot Option that failed to boot.
486 @param Status Status returned from failed boot.
487 @param ExitData Exit data returned from failed boot.
488 @param ExitDataSize Exit data size returned from failed boot.
493 PlatformBdsBootFail (
494 IN BDS_COMMON_OPTION
*Option
,
495 IN EFI_STATUS Status
,
497 IN UINTN ExitDataSize
503 This function locks platform flash that is not allowed to be updated during normal boot path.
504 The flash layout is platform specific.
508 PlatformBdsLockNonUpdatableFlash (