]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
ArmPkg/PlatformBootManagerLib: connect non-discoverable USB hosts
[mirror_edk2.git] / ArmPkg / Library / PlatformBootManagerLib / PlatformBm.c
CommitLineData
c976f9cb
AB
1/** @file\r
2 Implementation for PlatformBootManagerLib library class interfaces.\r
3\r
4 Copyright (C) 2015-2016, Red Hat, Inc.\r
0f9395d7 5 Copyright (c) 2014 - 2019, ARM Ltd. All rights reserved.<BR>\r
eea668c9 6 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
c976f9cb
AB
7 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
8\r
4059386c 9 SPDX-License-Identifier: BSD-2-Clause-Patent\r
c976f9cb
AB
10\r
11**/\r
12\r
13#include <IndustryStandard/Pci22.h>\r
a43d75e1 14#include <Library/BootLogoLib.h>\r
4bbcc285 15#include <Library/CapsuleLib.h>\r
c976f9cb 16#include <Library/DevicePathLib.h>\r
4bbcc285 17#include <Library/HobLib.h>\r
c976f9cb
AB
18#include <Library/PcdLib.h>\r
19#include <Library/UefiBootManagerLib.h>\r
20#include <Library/UefiLib.h>\r
cae82316 21#include <Library/UefiRuntimeServicesTableLib.h>\r
c976f9cb 22#include <Protocol/DevicePath.h>\r
13ca0abb 23#include <Protocol/EsrtManagement.h>\r
c976f9cb
AB
24#include <Protocol/GraphicsOutput.h>\r
25#include <Protocol/LoadedImage.h>\r
0ae52d4f 26#include <Protocol/NonDiscoverableDevice.h>\r
c976f9cb
AB
27#include <Protocol/PciIo.h>\r
28#include <Protocol/PciRootBridgeIo.h>\r
1b6e7633 29#include <Protocol/PlatformBootManager.h>\r
c976f9cb 30#include <Guid/EventGroup.h>\r
0ae52d4f 31#include <Guid/NonDiscoverableDevice.h>\r
c976f9cb 32#include <Guid/TtyTerm.h>\r
6631c096 33#include <Guid/SerialPortLibVendor.h>\r
c976f9cb
AB
34\r
35#include "PlatformBm.h"\r
36\r
37#define DP_NODE_LEN(Type) { (UINT8)sizeof (Type), (UINT8)(sizeof (Type) >> 8) }\r
38\r
c976f9cb
AB
39#pragma pack (1)\r
40typedef struct {\r
41 VENDOR_DEVICE_PATH SerialDxe;\r
42 UART_DEVICE_PATH Uart;\r
43 VENDOR_DEFINED_DEVICE_PATH TermType;\r
44 EFI_DEVICE_PATH_PROTOCOL End;\r
45} PLATFORM_SERIAL_CONSOLE;\r
46#pragma pack ()\r
47\r
c976f9cb
AB
48STATIC PLATFORM_SERIAL_CONSOLE mSerialConsole = {\r
49 //\r
50 // VENDOR_DEVICE_PATH SerialDxe\r
51 //\r
52 {\r
53 { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DP_NODE_LEN (VENDOR_DEVICE_PATH) },\r
6631c096 54 EDKII_SERIAL_PORT_LIB_VENDOR_GUID\r
c976f9cb
AB
55 },\r
56\r
57 //\r
58 // UART_DEVICE_PATH Uart\r
59 //\r
60 {\r
61 { MESSAGING_DEVICE_PATH, MSG_UART_DP, DP_NODE_LEN (UART_DEVICE_PATH) },\r
62 0, // Reserved\r
63 FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate\r
64 FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits\r
65 FixedPcdGet8 (PcdUartDefaultParity), // Parity\r
66 FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits\r
67 },\r
68\r
69 //\r
70 // VENDOR_DEFINED_DEVICE_PATH TermType\r
71 //\r
72 {\r
73 {\r
74 MESSAGING_DEVICE_PATH, MSG_VENDOR_DP,\r
75 DP_NODE_LEN (VENDOR_DEFINED_DEVICE_PATH)\r
76 }\r
77 //\r
78 // Guid to be filled in dynamically\r
79 //\r
80 },\r
81\r
82 //\r
83 // EFI_DEVICE_PATH_PROTOCOL End\r
84 //\r
85 {\r
86 END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
87 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)\r
88 }\r
89};\r
90\r
91\r
92#pragma pack (1)\r
93typedef struct {\r
94 USB_CLASS_DEVICE_PATH Keyboard;\r
95 EFI_DEVICE_PATH_PROTOCOL End;\r
96} PLATFORM_USB_KEYBOARD;\r
97#pragma pack ()\r
98\r
99STATIC PLATFORM_USB_KEYBOARD mUsbKeyboard = {\r
100 //\r
101 // USB_CLASS_DEVICE_PATH Keyboard\r
102 //\r
103 {\r
104 {\r
105 MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP,\r
106 DP_NODE_LEN (USB_CLASS_DEVICE_PATH)\r
107 },\r
108 0xFFFF, // VendorId: any\r
109 0xFFFF, // ProductId: any\r
110 3, // DeviceClass: HID\r
111 1, // DeviceSubClass: boot\r
112 1 // DeviceProtocol: keyboard\r
113 },\r
114\r
115 //\r
116 // EFI_DEVICE_PATH_PROTOCOL End\r
117 //\r
118 {\r
119 END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
120 DP_NODE_LEN (EFI_DEVICE_PATH_PROTOCOL)\r
121 }\r
122};\r
123\r
124\r
125/**\r
126 Check if the handle satisfies a particular condition.\r
127\r
128 @param[in] Handle The handle to check.\r
129 @param[in] ReportText A caller-allocated string passed in for reporting\r
130 purposes. It must never be NULL.\r
131\r
132 @retval TRUE The condition is satisfied.\r
133 @retval FALSE Otherwise. This includes the case when the condition could not\r
134 be fully evaluated due to an error.\r
135**/\r
136typedef\r
137BOOLEAN\r
138(EFIAPI *FILTER_FUNCTION) (\r
139 IN EFI_HANDLE Handle,\r
140 IN CONST CHAR16 *ReportText\r
141 );\r
142\r
143\r
144/**\r
145 Process a handle.\r
146\r
147 @param[in] Handle The handle to process.\r
148 @param[in] ReportText A caller-allocated string passed in for reporting\r
149 purposes. It must never be NULL.\r
150**/\r
151typedef\r
152VOID\r
153(EFIAPI *CALLBACK_FUNCTION) (\r
154 IN EFI_HANDLE Handle,\r
155 IN CONST CHAR16 *ReportText\r
156 );\r
157\r
158/**\r
159 Locate all handles that carry the specified protocol, filter them with a\r
160 callback function, and pass each handle that passes the filter to another\r
161 callback.\r
162\r
163 @param[in] ProtocolGuid The protocol to look for.\r
164\r
165 @param[in] Filter The filter function to pass each handle to. If this\r
166 parameter is NULL, then all handles are processed.\r
167\r
168 @param[in] Process The callback function to pass each handle to that\r
169 clears the filter.\r
170**/\r
171STATIC\r
172VOID\r
173FilterAndProcess (\r
174 IN EFI_GUID *ProtocolGuid,\r
175 IN FILTER_FUNCTION Filter OPTIONAL,\r
176 IN CALLBACK_FUNCTION Process\r
177 )\r
178{\r
179 EFI_STATUS Status;\r
180 EFI_HANDLE *Handles;\r
181 UINTN NoHandles;\r
182 UINTN Idx;\r
183\r
184 Status = gBS->LocateHandleBuffer (ByProtocol, ProtocolGuid,\r
185 NULL /* SearchKey */, &NoHandles, &Handles);\r
186 if (EFI_ERROR (Status)) {\r
187 //\r
188 // This is not an error, just an informative condition.\r
189 //\r
190 DEBUG ((EFI_D_VERBOSE, "%a: %g: %r\n", __FUNCTION__, ProtocolGuid,\r
191 Status));\r
192 return;\r
193 }\r
194\r
195 ASSERT (NoHandles > 0);\r
196 for (Idx = 0; Idx < NoHandles; ++Idx) {\r
197 CHAR16 *DevicePathText;\r
198 STATIC CHAR16 Fallback[] = L"<device path unavailable>";\r
199\r
200 //\r
201 // The ConvertDevicePathToText() function handles NULL input transparently.\r
202 //\r
203 DevicePathText = ConvertDevicePathToText (\r
204 DevicePathFromHandle (Handles[Idx]),\r
205 FALSE, // DisplayOnly\r
206 FALSE // AllowShortcuts\r
207 );\r
208 if (DevicePathText == NULL) {\r
209 DevicePathText = Fallback;\r
210 }\r
211\r
212 if (Filter == NULL || Filter (Handles[Idx], DevicePathText)) {\r
213 Process (Handles[Idx], DevicePathText);\r
214 }\r
215\r
216 if (DevicePathText != Fallback) {\r
217 FreePool (DevicePathText);\r
218 }\r
219 }\r
220 gBS->FreePool (Handles);\r
221}\r
222\r
223\r
224/**\r
225 This FILTER_FUNCTION checks if a handle corresponds to a PCI display device.\r
226**/\r
227STATIC\r
228BOOLEAN\r
229EFIAPI\r
230IsPciDisplay (\r
231 IN EFI_HANDLE Handle,\r
232 IN CONST CHAR16 *ReportText\r
233 )\r
234{\r
235 EFI_STATUS Status;\r
236 EFI_PCI_IO_PROTOCOL *PciIo;\r
237 PCI_TYPE00 Pci;\r
238\r
239 Status = gBS->HandleProtocol (Handle, &gEfiPciIoProtocolGuid,\r
240 (VOID**)&PciIo);\r
241 if (EFI_ERROR (Status)) {\r
242 //\r
243 // This is not an error worth reporting.\r
244 //\r
245 return FALSE;\r
246 }\r
247\r
248 Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0 /* Offset */,\r
249 sizeof Pci / sizeof (UINT32), &Pci);\r
250 if (EFI_ERROR (Status)) {\r
251 DEBUG ((EFI_D_ERROR, "%a: %s: %r\n", __FUNCTION__, ReportText, Status));\r
252 return FALSE;\r
253 }\r
254\r
255 return IS_PCI_DISPLAY (&Pci);\r
256}\r
257\r
258\r
0ae52d4f
AB
259/**\r
260 This FILTER_FUNCTION checks if a handle corresponds to a non-discoverable\r
261 USB host controller.\r
262**/\r
263STATIC\r
264BOOLEAN\r
265EFIAPI\r
266IsUsbHost (\r
267 IN EFI_HANDLE Handle,\r
268 IN CONST CHAR16 *ReportText\r
269 )\r
270{\r
271 NON_DISCOVERABLE_DEVICE *Device;\r
272 EFI_STATUS Status;\r
273\r
274 Status = gBS->HandleProtocol (Handle,\r
275 &gEdkiiNonDiscoverableDeviceProtocolGuid,\r
276 (VOID **)&Device);\r
277 if (EFI_ERROR (Status)) {\r
278 return FALSE;\r
279 }\r
280\r
281 if (CompareGuid (Device->Type, &gEdkiiNonDiscoverableUhciDeviceGuid) ||\r
282 CompareGuid (Device->Type, &gEdkiiNonDiscoverableEhciDeviceGuid) ||\r
283 CompareGuid (Device->Type, &gEdkiiNonDiscoverableXhciDeviceGuid)) {\r
284 return TRUE;\r
285 }\r
286 return FALSE;\r
287}\r
288\r
289\r
c976f9cb
AB
290/**\r
291 This CALLBACK_FUNCTION attempts to connect a handle non-recursively, asking\r
292 the matching driver to produce all first-level child handles.\r
293**/\r
294STATIC\r
295VOID\r
296EFIAPI\r
297Connect (\r
298 IN EFI_HANDLE Handle,\r
299 IN CONST CHAR16 *ReportText\r
300 )\r
301{\r
302 EFI_STATUS Status;\r
303\r
304 Status = gBS->ConnectController (\r
305 Handle, // ControllerHandle\r
306 NULL, // DriverImageHandle\r
307 NULL, // RemainingDevicePath -- produce all children\r
308 FALSE // Recursive\r
309 );\r
310 DEBUG ((EFI_ERROR (Status) ? EFI_D_ERROR : EFI_D_VERBOSE, "%a: %s: %r\n",\r
311 __FUNCTION__, ReportText, Status));\r
312}\r
313\r
314\r
315/**\r
316 This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from the\r
317 handle, and adds it to ConOut and ErrOut.\r
318**/\r
319STATIC\r
320VOID\r
321EFIAPI\r
322AddOutput (\r
323 IN EFI_HANDLE Handle,\r
324 IN CONST CHAR16 *ReportText\r
325 )\r
326{\r
327 EFI_STATUS Status;\r
328 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
329\r
330 DevicePath = DevicePathFromHandle (Handle);\r
331 if (DevicePath == NULL) {\r
332 DEBUG ((EFI_D_ERROR, "%a: %s: handle %p: device path not found\n",\r
333 __FUNCTION__, ReportText, Handle));\r
334 return;\r
335 }\r
336\r
337 Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL);\r
338 if (EFI_ERROR (Status)) {\r
339 DEBUG ((EFI_D_ERROR, "%a: %s: adding to ConOut: %r\n", __FUNCTION__,\r
340 ReportText, Status));\r
341 return;\r
342 }\r
343\r
344 Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL);\r
345 if (EFI_ERROR (Status)) {\r
346 DEBUG ((EFI_D_ERROR, "%a: %s: adding to ErrOut: %r\n", __FUNCTION__,\r
347 ReportText, Status));\r
348 return;\r
349 }\r
350\r
351 DEBUG ((EFI_D_VERBOSE, "%a: %s: added to ConOut and ErrOut\n", __FUNCTION__,\r
352 ReportText));\r
353}\r
354\r
355STATIC\r
356VOID\r
357PlatformRegisterFvBootOption (\r
07548e17 358 CONST EFI_GUID *FileGuid,\r
c976f9cb
AB
359 CHAR16 *Description,\r
360 UINT32 Attributes\r
361 )\r
362{\r
363 EFI_STATUS Status;\r
364 INTN OptionIndex;\r
365 EFI_BOOT_MANAGER_LOAD_OPTION NewOption;\r
366 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
367 UINTN BootOptionCount;\r
368 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;\r
369 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
370 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
371\r
372 Status = gBS->HandleProtocol (\r
373 gImageHandle,\r
374 &gEfiLoadedImageProtocolGuid,\r
375 (VOID **) &LoadedImage\r
376 );\r
377 ASSERT_EFI_ERROR (Status);\r
378\r
379 EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);\r
380 DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);\r
381 ASSERT (DevicePath != NULL);\r
382 DevicePath = AppendDevicePathNode (\r
383 DevicePath,\r
384 (EFI_DEVICE_PATH_PROTOCOL *) &FileNode\r
385 );\r
386 ASSERT (DevicePath != NULL);\r
387\r
388 Status = EfiBootManagerInitializeLoadOption (\r
389 &NewOption,\r
390 LoadOptionNumberUnassigned,\r
391 LoadOptionTypeBoot,\r
392 Attributes,\r
393 Description,\r
394 DevicePath,\r
395 NULL,\r
396 0\r
397 );\r
398 ASSERT_EFI_ERROR (Status);\r
399 FreePool (DevicePath);\r
400\r
401 BootOptions = EfiBootManagerGetLoadOptions (\r
402 &BootOptionCount, LoadOptionTypeBoot\r
403 );\r
404\r
405 OptionIndex = EfiBootManagerFindLoadOption (\r
406 &NewOption, BootOptions, BootOptionCount\r
407 );\r
408\r
409 if (OptionIndex == -1) {\r
410 Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN);\r
411 ASSERT_EFI_ERROR (Status);\r
412 }\r
413 EfiBootManagerFreeLoadOption (&NewOption);\r
414 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
415}\r
416\r
417\r
1b6e7633
HZ
418STATIC\r
419VOID\r
420GetPlatformOptions (\r
421 VOID\r
422 )\r
423{\r
424 EFI_STATUS Status;\r
425 EFI_BOOT_MANAGER_LOAD_OPTION *CurrentBootOptions;\r
426 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;\r
427 EFI_INPUT_KEY *BootKeys;\r
428 PLATFORM_BOOT_MANAGER_PROTOCOL *PlatformBootManager;\r
429 UINTN CurrentBootOptionCount;\r
430 UINTN Index;\r
431 UINTN BootCount;\r
432\r
433 Status = gBS->LocateProtocol (&gPlatformBootManagerProtocolGuid, NULL,\r
434 (VOID **)&PlatformBootManager);\r
435 if (EFI_ERROR (Status)) {\r
436 return;\r
437 }\r
438 Status = PlatformBootManager->GetPlatformBootOptionsAndKeys (\r
439 &BootCount,\r
440 &BootOptions,\r
441 &BootKeys\r
442 );\r
443 if (EFI_ERROR (Status)) {\r
444 return;\r
445 }\r
446 //\r
447 // Fetch the existent boot options. If there are none, CurrentBootCount\r
448 // will be zeroed.\r
449 //\r
450 CurrentBootOptions = EfiBootManagerGetLoadOptions (\r
451 &CurrentBootOptionCount,\r
452 LoadOptionTypeBoot\r
453 );\r
454 //\r
455 // Process the platform boot options.\r
456 //\r
457 for (Index = 0; Index < BootCount; Index++) {\r
458 INTN Match;\r
459 UINTN BootOptionNumber;\r
460\r
461 //\r
462 // If there are any preexistent boot options, and the subject platform boot\r
463 // option is already among them, then don't try to add it. Just get its\r
464 // assigned boot option number so we can associate a hotkey with it. Note\r
465 // that EfiBootManagerFindLoadOption() deals fine with (CurrentBootOptions\r
466 // == NULL) if (CurrentBootCount == 0).\r
467 //\r
468 Match = EfiBootManagerFindLoadOption (\r
469 &BootOptions[Index],\r
470 CurrentBootOptions,\r
471 CurrentBootOptionCount\r
472 );\r
473 if (Match >= 0) {\r
474 BootOptionNumber = CurrentBootOptions[Match].OptionNumber;\r
475 } else {\r
476 //\r
477 // Add the platform boot options as a new one, at the end of the boot\r
478 // order. Note that if the platform provided this boot option with an\r
479 // unassigned option number, then the below function call will assign a\r
480 // number.\r
481 //\r
482 Status = EfiBootManagerAddLoadOptionVariable (\r
483 &BootOptions[Index],\r
484 MAX_UINTN\r
485 );\r
486 if (EFI_ERROR (Status)) {\r
487 DEBUG ((DEBUG_ERROR, "%a: failed to register \"%s\": %r\n",\r
488 __FUNCTION__, BootOptions[Index].Description, Status));\r
489 continue;\r
490 }\r
491 BootOptionNumber = BootOptions[Index].OptionNumber;\r
492 }\r
493\r
494 //\r
495 // Register a hotkey with the boot option, if requested.\r
496 //\r
497 if (BootKeys[Index].UnicodeChar == L'\0') {\r
498 continue;\r
499 }\r
500\r
501 Status = EfiBootManagerAddKeyOptionVariable (\r
502 NULL,\r
503 BootOptionNumber,\r
504 0,\r
2b2959dd 505 &BootKeys[Index],\r
1b6e7633
HZ
506 NULL\r
507 );\r
508 if (EFI_ERROR (Status)) {\r
509 DEBUG ((DEBUG_ERROR, "%a: failed to register hotkey for \"%s\": %r\n",\r
510 __FUNCTION__, BootOptions[Index].Description, Status));\r
511 }\r
512 }\r
513 EfiBootManagerFreeLoadOptions (CurrentBootOptions, CurrentBootOptionCount);\r
514 EfiBootManagerFreeLoadOptions (BootOptions, BootCount);\r
515 FreePool (BootKeys);\r
516}\r
517\r
c976f9cb
AB
518STATIC\r
519VOID\r
520PlatformRegisterOptionsAndKeys (\r
521 VOID\r
522 )\r
523{\r
524 EFI_STATUS Status;\r
525 EFI_INPUT_KEY Enter;\r
526 EFI_INPUT_KEY F2;\r
527 EFI_INPUT_KEY Esc;\r
528 EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
529\r
1b6e7633
HZ
530 GetPlatformOptions ();\r
531\r
c976f9cb
AB
532 //\r
533 // Register ENTER as CONTINUE key\r
534 //\r
535 Enter.ScanCode = SCAN_NULL;\r
536 Enter.UnicodeChar = CHAR_CARRIAGE_RETURN;\r
537 Status = EfiBootManagerRegisterContinueKeyOption (0, &Enter, NULL);\r
538 ASSERT_EFI_ERROR (Status);\r
539\r
540 //\r
541 // Map F2 and ESC to Boot Manager Menu\r
542 //\r
543 F2.ScanCode = SCAN_F2;\r
544 F2.UnicodeChar = CHAR_NULL;\r
545 Esc.ScanCode = SCAN_ESC;\r
546 Esc.UnicodeChar = CHAR_NULL;\r
547 Status = EfiBootManagerGetBootManagerMenu (&BootOption);\r
548 ASSERT_EFI_ERROR (Status);\r
549 Status = EfiBootManagerAddKeyOptionVariable (\r
550 NULL, (UINT16) BootOption.OptionNumber, 0, &F2, NULL\r
551 );\r
552 ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);\r
553 Status = EfiBootManagerAddKeyOptionVariable (\r
554 NULL, (UINT16) BootOption.OptionNumber, 0, &Esc, NULL\r
555 );\r
556 ASSERT (Status == EFI_SUCCESS || Status == EFI_ALREADY_STARTED);\r
557}\r
558\r
559\r
560//\r
561// BDS Platform Functions\r
562//\r
563/**\r
564 Do the platform init, can be customized by OEM/IBV\r
565 Possible things that can be done in PlatformBootManagerBeforeConsole:\r
566 > Update console variable: 1. include hot-plug devices;\r
567 > 2. Clear ConIn and add SOL for AMT\r
568 > Register new Driver#### or Boot####\r
569 > Register new Key####: e.g.: F12\r
570 > Signal ReadyToLock event\r
571 > Authentication action: 1. connect Auth devices;\r
572 > 2. Identify auto logon user.\r
573**/\r
574VOID\r
575EFIAPI\r
576PlatformBootManagerBeforeConsole (\r
577 VOID\r
578 )\r
579{\r
580 //\r
581 // Signal EndOfDxe PI Event\r
582 //\r
583 EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);\r
584\r
0f9395d7
SM
585 //\r
586 // Dispatch deferred images after EndOfDxe event.\r
587 //\r
588 EfiBootManagerDispatchDeferredImages ();\r
589\r
c976f9cb
AB
590 //\r
591 // Locate the PCI root bridges and make the PCI bus driver connect each,\r
592 // non-recursively. This will produce a number of child handles with PciIo on\r
593 // them.\r
594 //\r
595 FilterAndProcess (&gEfiPciRootBridgeIoProtocolGuid, NULL, Connect);\r
596\r
597 //\r
598 // Find all display class PCI devices (using the handles from the previous\r
599 // step), and connect them non-recursively. This should produce a number of\r
600 // child handles with GOPs on them.\r
601 //\r
602 FilterAndProcess (&gEfiPciIoProtocolGuid, IsPciDisplay, Connect);\r
603\r
604 //\r
605 // Now add the device path of all handles with GOP on them to ConOut and\r
606 // ErrOut.\r
607 //\r
608 FilterAndProcess (&gEfiGraphicsOutputProtocolGuid, NULL, AddOutput);\r
609\r
0ae52d4f
AB
610 //\r
611 // The core BDS code connects short-form USB device paths by explicitly\r
612 // looking for handles with PCI I/O installed, and checking the PCI class\r
613 // code whether it matches the one for a USB host controller. This means\r
614 // non-discoverable USB host controllers need to have the non-discoverable\r
615 // PCI driver attached first.\r
616 //\r
617 FilterAndProcess (&gEdkiiNonDiscoverableDeviceProtocolGuid, IsUsbHost, Connect);\r
618\r
c976f9cb
AB
619 //\r
620 // Add the hardcoded short-form USB keyboard device path to ConIn.\r
621 //\r
622 EfiBootManagerUpdateConsoleVariable (ConIn,\r
623 (EFI_DEVICE_PATH_PROTOCOL *)&mUsbKeyboard, NULL);\r
624\r
625 //\r
626 // Add the hardcoded serial console device path to ConIn, ConOut, ErrOut.\r
627 //\r
b1d3895f
AB
628 STATIC_ASSERT (FixedPcdGet8 (PcdDefaultTerminalType) == 4,\r
629 "PcdDefaultTerminalType must be TTYTERM");\r
7191dd3c
AB
630 STATIC_ASSERT (FixedPcdGet8 (PcdUartDefaultParity) != 0,\r
631 "PcdUartDefaultParity must be set to an actual value, not 'default'");\r
632 STATIC_ASSERT (FixedPcdGet8 (PcdUartDefaultStopBits) != 0,\r
633 "PcdUartDefaultStopBits must be set to an actual value, not 'default'");\r
b1d3895f 634\r
c976f9cb
AB
635 CopyGuid (&mSerialConsole.TermType.Guid, &gEfiTtyTermGuid);\r
636\r
637 EfiBootManagerUpdateConsoleVariable (ConIn,\r
638 (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);\r
639 EfiBootManagerUpdateConsoleVariable (ConOut,\r
640 (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);\r
641 EfiBootManagerUpdateConsoleVariable (ErrOut,\r
642 (EFI_DEVICE_PATH_PROTOCOL *)&mSerialConsole, NULL);\r
643\r
644 //\r
645 // Register platform-specific boot options and keyboard shortcuts.\r
646 //\r
647 PlatformRegisterOptionsAndKeys ();\r
648}\r
649\r
cae82316
AB
650STATIC\r
651VOID\r
652HandleCapsules (\r
653 VOID\r
654 )\r
655{\r
656 ESRT_MANAGEMENT_PROTOCOL *EsrtManagement;\r
657 EFI_PEI_HOB_POINTERS HobPointer;\r
658 EFI_CAPSULE_HEADER *CapsuleHeader;\r
659 BOOLEAN NeedReset;\r
660 EFI_STATUS Status;\r
661\r
662 DEBUG ((DEBUG_INFO, "%a: processing capsules ...\n", __FUNCTION__));\r
663\r
664 Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL,\r
665 (VOID **)&EsrtManagement);\r
666 if (!EFI_ERROR (Status)) {\r
667 EsrtManagement->SyncEsrtFmp ();\r
668 }\r
669\r
670 //\r
671 // Find all capsule images from hob\r
672 //\r
673 HobPointer.Raw = GetHobList ();\r
674 NeedReset = FALSE;\r
675 while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE,\r
676 HobPointer.Raw)) != NULL) {\r
677 CapsuleHeader = (VOID *)(UINTN)HobPointer.Capsule->BaseAddress;\r
678\r
679 Status = ProcessCapsuleImage (CapsuleHeader);\r
680 if (EFI_ERROR (Status)) {\r
681 DEBUG ((DEBUG_ERROR, "%a: failed to process capsule %p - %r\n",\r
682 __FUNCTION__, CapsuleHeader, Status));\r
683 return;\r
684 }\r
685\r
686 NeedReset = TRUE;\r
687 HobPointer.Raw = GET_NEXT_HOB (HobPointer);\r
688 }\r
689\r
690 if (NeedReset) {\r
691 DEBUG ((DEBUG_WARN, "%a: capsule update successful, resetting ...\n",\r
692 __FUNCTION__));\r
693\r
694 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
695 CpuDeadLoop();\r
696 }\r
697}\r
698\r
699\r
6c4194c9
AB
700#define VERSION_STRING_PREFIX L"Tianocore/EDK2 firmware version "\r
701\r
c976f9cb
AB
702/**\r
703 Do the platform specific action after the console is ready\r
704 Possible things that can be done in PlatformBootManagerAfterConsole:\r
705 > Console post action:\r
ff5fef14 706 > Dynamically switch output mode from 100x31 to 80x25 for certain scenario\r
c976f9cb
AB
707 > Signal console ready platform customized event\r
708 > Run diagnostics like memory testing\r
709 > Connect certain devices\r
ff5fef14 710 > Dispatch additional option roms\r
c976f9cb
AB
711 > Special boot: e.g.: USB boot, enter UI\r
712**/\r
713VOID\r
714EFIAPI\r
715PlatformBootManagerAfterConsole (\r
716 VOID\r
717 )\r
718{\r
13ca0abb 719 EFI_STATUS Status;\r
6c4194c9
AB
720 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
721 UINTN FirmwareVerLength;\r
722 UINTN PosX;\r
723 UINTN PosY;\r
724\r
725 FirmwareVerLength = StrLen (PcdGetPtr (PcdFirmwareVersionString));\r
c976f9cb
AB
726\r
727 //\r
728 // Show the splash screen.\r
729 //\r
a43d75e1
AB
730 Status = BootLogoEnableLogo ();\r
731 if (EFI_ERROR (Status)) {\r
6c4194c9 732 if (FirmwareVerLength > 0) {\r
26b99f3b 733 Print (VERSION_STRING_PREFIX L"%s\n",\r
6c4194c9
AB
734 PcdGetPtr (PcdFirmwareVersionString));\r
735 }\r
a43d75e1 736 Print (L"Press ESCAPE for boot options ");\r
6c4194c9
AB
737 } else if (FirmwareVerLength > 0) {\r
738 Status = gBS->HandleProtocol (gST->ConsoleOutHandle,\r
739 &gEfiGraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);\r
740 if (!EFI_ERROR (Status)) {\r
741 PosX = (GraphicsOutput->Mode->Info->HorizontalResolution -\r
742 (StrLen (VERSION_STRING_PREFIX) + FirmwareVerLength) *\r
743 EFI_GLYPH_WIDTH) / 2;\r
744 PosY = 0;\r
745\r
746 PrintXY (PosX, PosY, NULL, NULL, VERSION_STRING_PREFIX L"%s",\r
747 PcdGetPtr (PcdFirmwareVersionString));\r
748 }\r
a43d75e1 749 }\r
6c4194c9 750\r
c976f9cb
AB
751 //\r
752 // Connect the rest of the devices.\r
753 //\r
754 EfiBootManagerConnectAll ();\r
755\r
cae82316
AB
756 //\r
757 // On ARM, there is currently no reason to use the phased capsule\r
758 // update approach where some capsules are dispatched before EndOfDxe\r
759 // and some are dispatched after. So just handle all capsules here,\r
760 // when the console is up and we can actually give the user some\r
761 // feedback about what is going on.\r
762 //\r
763 HandleCapsules ();\r
4bbcc285 764\r
c976f9cb
AB
765 //\r
766 // Enumerate all possible boot options.\r
767 //\r
768 EfiBootManagerRefreshAllBootOption ();\r
769\r
770 //\r
771 // Register UEFI Shell\r
772 //\r
773 PlatformRegisterFvBootOption (\r
07548e17 774 &gUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE\r
c976f9cb
AB
775 );\r
776}\r
777\r
778/**\r
779 This function is called each second during the boot manager waits the\r
780 timeout.\r
781\r
782 @param TimeoutRemain The remaining timeout.\r
783**/\r
784VOID\r
785EFIAPI\r
786PlatformBootManagerWaitCallback (\r
787 UINT16 TimeoutRemain\r
788 )\r
789{\r
a43d75e1
AB
790 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Black;\r
791 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION White;\r
792 UINT16 Timeout;\r
793 EFI_STATUS Status;\r
794\r
795 Timeout = PcdGet16 (PcdPlatformBootTimeOut);\r
796\r
797 Black.Raw = 0x00000000;\r
798 White.Raw = 0x00FFFFFF;\r
799\r
800 Status = BootLogoUpdateProgress (\r
801 White.Pixel,\r
802 Black.Pixel,\r
803 L"Press ESCAPE for boot options",\r
804 White.Pixel,\r
805 (Timeout - TimeoutRemain) * 100 / Timeout,\r
806 0\r
807 );\r
808 if (EFI_ERROR (Status)) {\r
809 Print (L".");\r
810 }\r
c976f9cb 811}\r
eea668c9
RN
812\r
813/**\r
814 The function is called when no boot option could be launched,\r
815 including platform recovery options and options pointing to applications\r
816 built into firmware volumes.\r
817\r
818 If this function returns, BDS attempts to enter an infinite loop.\r
819**/\r
820VOID\r
821EFIAPI\r
822PlatformBootManagerUnableToBoot (\r
823 VOID\r
824 )\r
825{\r
826 return;\r
827}\r