]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Include/Library/UefiBootManagerLib.h
MdeModulePkg: Add match2 opcode support in SetupBrowserDxe and sample code in DriverS...
[mirror_edk2.git] / MdeModulePkg / Include / Library / UefiBootManagerLib.h
1 /** @file
2 Provide Boot Manager related library APIs.
3
4 Copyright (c) 2011 - 2015, 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
9
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.
12
13 **/
14
15
16 #ifndef _UEFI_BOOT_MANAGER_LIB_H_
17 #define _UEFI_BOOT_MANAGER_LIB_H_
18
19 #include <Protocol/DriverHealth.h>
20 #include <Library/SortLib.h>
21
22 //
23 // Boot Manager load option library functions.
24 //
25
26 //
27 // Load Option Type
28 //
29 typedef enum {
30 LoadOptionTypeBoot,
31 LoadOptionTypeDriver,
32 LoadOptionTypeMax
33 } EFI_BOOT_MANAGER_LOAD_OPTION_TYPE;
34
35 typedef enum {
36 LoadOptionNumberMax = 0x10000,
37 LoadOptionNumberUnassigned = LoadOptionNumberMax
38 } EFI_BOOT_MANAGER_LOAD_OPTION_NUMBER;
39
40 //
41 // Common structure definition for DriverOption and BootOption
42 //
43 typedef struct {
44 //
45 // Data read from UEFI NV variables
46 //
47 UINTN OptionNumber; // #### numerical value, could be LoadOptionNumberUnassigned
48 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType; // LoadOptionTypeBoot or LoadOptionTypeDriver
49 UINT32 Attributes; // Load Option Attributes
50 CHAR16 *Description; // Load Option Description
51 EFI_DEVICE_PATH_PROTOCOL *FilePath; // Load Option Device Path
52 UINT8 *OptionalData; // Load Option optional data to pass into image
53 UINT32 OptionalDataSize; // Load Option size of OptionalData
54
55 //
56 // Used at runtime
57 //
58 EFI_STATUS Status; // Status returned from boot attempt gBS->StartImage ()
59 CHAR16 *ExitData; // Exit data returned from gBS->StartImage ()
60 UINTN ExitDataSize; // Size of ExitData
61 } EFI_BOOT_MANAGER_LOAD_OPTION;
62
63 /**
64 Returns an array of load options based on the EFI variable
65 L"BootOrder"/L"DriverOrder" and the L"Boot####"/L"Driver####" variables impled by it.
66 #### is the hex value of the UINT16 in each BootOrder/DriverOrder entry.
67
68 @param LoadOptionCount Returns number of entries in the array.
69 @param LoadOptionType The type of the load option.
70
71 @retval NULL No load options exist.
72 @retval !NULL Array of load option entries.
73
74 **/
75 EFI_BOOT_MANAGER_LOAD_OPTION *
76 EFIAPI
77 EfiBootManagerGetLoadOptions (
78 OUT UINTN *LoadOptionCount,
79 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
80 );
81
82 /**
83 Free an array of load options returned from EfiBootManagerGetLoadOptions().
84
85 @param LoadOptions Pointer to the array of load options to free.
86 @param LoadOptionCount Number of array entries in LoadOptions.
87
88 @return EFI_SUCCESS LoadOptions was freed.
89 @return EFI_INVALID_PARAMETER LoadOptions is NULL.
90 **/
91 EFI_STATUS
92 EFIAPI
93 EfiBootManagerFreeLoadOptions (
94 IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOptions,
95 IN UINTN LoadOptionCount
96 );
97
98 /**
99 Initialize a load option.
100
101 @param Option Pointer to the load option to be initialized.
102 @param OptionNumber Option number of the load option.
103 @param OptionType Type of the load option.
104 @param Attributes Attributes of the load option.
105 @param Description Description of the load option.
106 @param FilePath Device path of the load option.
107 @param OptionalData Optional data of the load option.
108 @param OptionalDataSize Size of the optional data of the load option.
109
110 @retval EFI_SUCCESS The load option was initialized successfully.
111 @retval EFI_INVALID_PARAMETER Option, Description or FilePath is NULL.
112 **/
113 EFI_STATUS
114 EFIAPI
115 EfiBootManagerInitializeLoadOption (
116 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option,
117 IN UINTN OptionNumber,
118 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType,
119 IN UINT32 Attributes,
120 IN CHAR16 *Description,
121 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
122 IN UINT8 *OptionalData,
123 IN UINT32 OptionalDataSize
124 );
125
126 /**
127 Free a load option created by EfiBootManagerInitializeLoadOption()
128 or EfiBootManagerVariableToLoadOption().
129
130 @param LoadOption Pointer to the load option to free.
131 CONCERN: Check Boot#### instead of BootOrder, optimize, spec clarify
132 @return EFI_SUCCESS LoadOption was freed.
133 @return EFI_INVALID_PARAMETER LoadOption is NULL.
134
135 **/
136 EFI_STATUS
137 EFIAPI
138 EfiBootManagerFreeLoadOption (
139 IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption
140 );
141
142 /**
143 Initialize the load option from the VariableName.
144
145 @param VariableName EFI Variable name which could be Boot#### or
146 Driver####
147 @param LoadOption Pointer to the load option to be initialized
148
149 @retval EFI_SUCCESS The option was created
150 @retval EFI_INVALID_PARAMETER VariableName or LoadOption is NULL.
151 @retval EFI_NOT_FOUND The variable specified by VariableName cannot be found.
152 **/
153 EFI_STATUS
154 EFIAPI
155 EfiBootManagerVariableToLoadOption (
156 IN CHAR16 *VariableName,
157 IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption
158 );
159
160 /**
161 Create the Boot#### or Driver#### variable from the load option.
162
163 @param LoadOption Pointer to the load option.
164
165 @retval EFI_SUCCESS The variable was created.
166 @retval Others Error status returned by RT->SetVariable.
167 **/
168 EFI_STATUS
169 EFIAPI
170 EfiBootManagerLoadOptionToVariable (
171 IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption
172 );
173
174 /**
175 This function will update the Boot####/Driver#### and the BootOrder/DriverOrder
176 to add a new load option.
177
178 @param Option Pointer to load option to add.
179 @param Position Position of the new load option to put in the BootOrder/DriverOrder.
180
181 @retval EFI_SUCCESS The load option has been successfully added.
182 @retval Others Error status returned by RT->SetVariable.
183 **/
184 EFI_STATUS
185 EFIAPI
186 EfiBootManagerAddLoadOptionVariable (
187 IN EFI_BOOT_MANAGER_LOAD_OPTION *Option,
188 IN UINTN Position
189 );
190
191 /**
192 Delete the load option according to the OptionNumber and OptionType.
193
194 Only the BootOrder/DriverOrder is updated to remove the reference of the OptionNumber.
195
196 @param OptionNumber Option number of the load option.
197 @param OptionType Type of the load option.
198
199 @retval EFI_NOT_FOUND The load option cannot be found.
200 @retval EFI_SUCCESS The load option was deleted.
201 **/
202 EFI_STATUS
203 EFIAPI
204 EfiBootManagerDeleteLoadOptionVariable (
205 IN UINTN OptionNumber,
206 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
207 );
208
209 /**
210 Sort the load options. The DriverOrder/BootOrder variables will be re-created to
211 reflect the new order.
212
213 @param OptionType The type of the load option.
214 @param Comparator The comparator function pointer.
215 **/
216 VOID
217 EFIAPI
218 EfiBootManagerSortLoadOptionVariable (
219 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType,
220 IN SORT_COMPARE CompareFunction
221 );
222
223 //
224 // Boot Manager hot key library functions.
225 //
226
227 #pragma pack(1)
228 ///
229 /// EFI Key Option.
230 ///
231 typedef struct {
232 ///
233 /// Specifies options about how the key will be processed.
234 ///
235 EFI_BOOT_KEY_DATA KeyData;
236 ///
237 /// The CRC-32 which should match the CRC-32 of the entire EFI_LOAD_OPTION to
238 /// which BootOption refers. If the CRC-32s do not match this value, then this key
239 /// option is ignored.
240 ///
241 UINT32 BootOptionCrc;
242 ///
243 /// The Boot#### option which will be invoked if this key is pressed and the boot option
244 /// is active (LOAD_OPTION_ACTIVE is set).
245 ///
246 UINT16 BootOption;
247 ///
248 /// The key codes to compare against those returned by the
249 /// EFI_SIMPLE_TEXT_INPUT and EFI_SIMPLE_TEXT_INPUT_EX protocols.
250 /// The number of key codes (0-3) is specified by the EFI_KEY_CODE_COUNT field in KeyOptions.
251 ///
252 EFI_INPUT_KEY Keys[3];
253 UINT16 OptionNumber;
254 } EFI_BOOT_MANAGER_KEY_OPTION;
255 #pragma pack()
256
257 /**
258 Start the hot key service so that the key press can trigger the boot option.
259
260 @param HotkeyTriggered Return the waitable event and it will be signaled
261 when a valid hot key is pressed.
262
263 @retval EFI_SUCCESS The hot key service is started.
264 **/
265 EFI_STATUS
266 EFIAPI
267 EfiBootManagerStartHotkeyService (
268 IN EFI_EVENT *HotkeyTriggered
269 );
270
271 //
272 // Modifier for EfiBootManagerAddKeyOptionVariable and EfiBootManagerDeleteKeyOptionVariable
273 //
274 #define EFI_BOOT_MANAGER_SHIFT_PRESSED 0x00000001
275 #define EFI_BOOT_MANAGER_CONTROL_PRESSED 0x00000002
276 #define EFI_BOOT_MANAGER_ALT_PRESSED 0x00000004
277 #define EFI_BOOT_MANAGER_LOGO_PRESSED 0x00000008
278 #define EFI_BOOT_MANAGER_MENU_KEY_PRESSED 0x00000010
279 #define EFI_BOOT_MANAGER_SYS_REQ_PRESSED 0x00000020
280
281 /**
282 Add the key option.
283 It adds the key option variable and the key option takes affect immediately.
284
285 @param AddedOption Return the added key option.
286 @param BootOptionNumber The boot option number for the key option.
287 @param Modifier Key shift state.
288 @param ... Parameter list of pointer of EFI_INPUT_KEY.
289
290 @retval EFI_SUCCESS The key option is added.
291 @retval EFI_ALREADY_STARTED The hot key is already used by certain key option.
292 **/
293 EFI_STATUS
294 EFIAPI
295 EfiBootManagerAddKeyOptionVariable (
296 OUT EFI_BOOT_MANAGER_KEY_OPTION *AddedOption, OPTIONAL
297 IN UINT16 BootOptionNumber,
298 IN UINT32 Modifier,
299 ...
300 );
301
302 /**
303 Delete the Key Option variable and unregister the hot key
304
305 @param DeletedOption Return the deleted key options.
306 @param Modifier Key shift state.
307 @param ... Parameter list of pointer of EFI_INPUT_KEY.
308
309 @retval EFI_SUCCESS The key option is deleted.
310 @retval EFI_NOT_FOUND The key option cannot be found.
311 **/
312 EFI_STATUS
313 EFIAPI
314 EfiBootManagerDeleteKeyOptionVariable (
315 IN EFI_BOOT_MANAGER_KEY_OPTION *DeletedOption, OPTIONAL
316 IN UINT32 Modifier,
317 ...
318 );
319
320 /**
321 Register the key option to exit the waiting of the Boot Manager timeout.
322 Platform should ensure that the continue key option isn't conflict with
323 other boot key options.
324
325 @param Modifier Key shift state.
326 @param ... Parameter list of pointer of EFI_INPUT_KEY.
327
328 @retval EFI_SUCCESS Successfully register the continue key option.
329 @retval EFI_ALREADY_STARTED The continue key option is already registered.
330 **/
331 EFI_STATUS
332 EFIAPI
333 EfiBootManagerRegisterContinueKeyOption (
334 IN UINT32 Modifier,
335 ...
336 );
337
338 /**
339 Try to boot the boot option triggered by hot key.
340 **/
341 VOID
342 EFIAPI
343 EfiBootManagerHotkeyBoot (
344 VOID
345 );
346 //
347 // Boot Manager boot library functions.
348 //
349
350 /**
351 The function creates boot options for all possible bootable medias in the following order:
352 1. Removable BlockIo - The boot option only points to the removable media
353 device, like USB key, DVD, Floppy etc.
354 2. Fixed BlockIo - The boot option only points to a Fixed blockIo device,
355 like HardDisk.
356 3. Non-BlockIo SimpleFileSystem - The boot option points to a device supporting
357 SimpleFileSystem Protocol, but not supporting BlockIo
358 protocol.
359 4. LoadFile - The boot option points to the media supporting
360 LoadFile protocol.
361 Reference: UEFI Spec chapter 3.3 Boot Option Variables Default Boot Behavior
362
363 The function won't delete the boot option not added by itself.
364 **/
365 VOID
366 EFIAPI
367 EfiBootManagerRefreshAllBootOption (
368 VOID
369 );
370
371 /**
372 Attempt to boot the EFI boot option. This routine sets L"BootCurent" and
373 signals the EFI ready to boot event. If the device path for the option starts
374 with a BBS device path a legacy boot is attempted. Short form device paths are
375 also supported via this rountine. A device path starting with
376 MEDIA_HARDDRIVE_DP, MSG_USB_WWID_DP, MSG_USB_CLASS_DP gets expaned out
377 to find the first device that matches. If the BootOption Device Path
378 fails the removable media boot algorithm is attempted (\EFI\BOOTIA32.EFI,
379 \EFI\BOOTX64.EFI,... only one file type is tried per processor type)
380
381 @param BootOption Boot Option to try and boot.
382 On return, BootOption->Status contains the boot status:
383 EFI_SUCCESS BootOption was booted
384 EFI_UNSUPPORTED BootOption isn't supported.
385 EFI_NOT_FOUND The BootOption was not found on the system
386 Others BootOption failed with this error status
387
388 **/
389 VOID
390 EFIAPI
391 EfiBootManagerBoot (
392 IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
393 );
394
395 /**
396 Return the Boot Manager Menu.
397
398 @param BootOption Return the Boot Manager Menu.
399
400 @retval EFI_SUCCESS The Boot Manager Menu is successfully returned.
401 @retval EFI_NOT_FOUND The Boot Manager Menu is not found.
402 **/
403 EFI_STATUS
404 EFIAPI
405 EfiBootManagerGetBootManagerMenu (
406 EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
407 );
408
409 /**
410 The function enumerates all the legacy boot options, creates them and
411 registers them in the BootOrder variable.
412 **/
413 typedef
414 VOID
415 (EFIAPI *EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION) (
416 VOID
417 );
418
419 /**
420 The function boots a legacy boot option.
421 **/
422 typedef
423 VOID
424 (EFIAPI *EFI_BOOT_MANAGER_LEGACY_BOOT) (
425 IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
426 );
427
428 /**
429 The function registers the legacy boot support capabilities.
430
431 @param RefreshLegacyBootOption The function pointer to create all the legacy boot options.
432 @param LegacyBoot The function pointer to boot the legacy boot option.
433 **/
434 VOID
435 EFIAPI
436 EfiBootManagerRegisterLegacyBootSupport (
437 EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION RefreshLegacyBootOption,
438 EFI_BOOT_MANAGER_LEGACY_BOOT LegacyBoot
439 );
440
441
442 //
443 // Boot Manager connect and disconnect library functions
444 //
445
446 /**
447 This function will connect all the system driver to controller
448 first, and then special connect the default console, this make
449 sure all the system controller available and the platform default
450 console connected.
451 **/
452 VOID
453 EFIAPI
454 EfiBootManagerConnectAll (
455 VOID
456 );
457
458 /**
459 This function will create all handles associate with every device
460 path node. If the handle associate with one device path node can not
461 be created successfully, then still give one chance to do the dispatch,
462 which load the missing drivers if possible.
463
464 @param DevicePathToConnect The device path which will be connected, it CANNOT be
465 a multi-instance device path
466 @param MatchingHandle Return the controller handle closest to the DevicePathToConnect
467
468 @retval EFI_INVALID_PARAMETER DevicePathToConnect is NULL.
469 @retval EFI_NOT_FOUND Failed to create all handles associate with every device path node.
470 @retval EFI_SUCCESS Successful to create all handles associate with every device path node.
471
472 **/
473 EFI_STATUS
474 EFIAPI
475 EfiBootManagerConnectDevicePath (
476 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect,
477 OUT EFI_HANDLE *MatchingHandle OPTIONAL
478 );
479
480 /**
481 This function will disconnect all current system handles.
482
483 gBS->DisconnectController() is invoked for each handle exists in system handle buffer.
484 If handle is a bus type handle, all childrens also are disconnected recursively by
485 gBS->DisconnectController().
486 **/
487 VOID
488 EFIAPI
489 EfiBootManagerDisconnectAll (
490 VOID
491 );
492
493
494 //
495 // Boot Manager console library functions
496 //
497
498 typedef enum {
499 ConIn,
500 ConOut,
501 ErrOut,
502 ConInDev,
503 ConOutDev,
504 ErrOutDev,
505 ConsoleTypeMax
506 } CONSOLE_TYPE;
507
508 /**
509 This function will connect all the console devices base on the console
510 device variable ConIn, ConOut and ErrOut.
511 **/
512 VOID
513 EFIAPI
514 EfiBootManagerConnectAllDefaultConsoles (
515 VOID
516 );
517
518 /**
519 This function updates the console variable based on ConVarName. It can
520 add or remove one specific console device path from the variable
521
522 @param ConsoleType ConIn, ConOut, ErrOut, ConInDev, ConOutDev or ErrOutDev.
523 @param CustomizedConDevicePath The console device path to be added to
524 the console variable. Cannot be multi-instance.
525 @param ExclusiveDevicePath The console device path to be removed
526 from the console variable. Cannot be multi-instance.
527
528 @retval EFI_UNSUPPORTED The added device path is the same as a removed one.
529 @retval EFI_SUCCESS Successfully added or removed the device path from the
530 console variable.
531
532 **/
533 EFI_STATUS
534 EFIAPI
535 EfiBootManagerUpdateConsoleVariable (
536 IN CONSOLE_TYPE ConsoleType,
537 IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,
538 IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath
539 );
540
541 /**
542 Connect the console device base on the variable ConVarName, if
543 device path of the ConVarName is multi-instance device path, if
544 anyone of the instances is connected success, then this function
545 will return success.
546
547 @param ConsoleType ConIn, ConOut or ErrOut.
548
549 @retval EFI_NOT_FOUND There is not any console devices connected
550 success
551 @retval EFI_SUCCESS Success connect any one instance of the console
552 device path base on the variable ConVarName.
553
554 **/
555 EFI_STATUS
556 EFIAPI
557 EfiBootManagerConnectConsoleVariable (
558 IN CONSOLE_TYPE ConsoleType
559 );
560
561 /**
562 Query all the children of VideoController and return the device paths of all the
563 children that support GraphicsOutput protocol.
564
565 @param VideoController PCI handle of video controller.
566
567 @return Device paths of all the children that support GraphicsOutput protocol.
568 **/
569 EFI_DEVICE_PATH_PROTOCOL *
570 EFIAPI
571 EfiBootManagerGetGopDevicePath (
572 IN EFI_HANDLE VideoController
573 );
574
575 /**
576 Connect the platform active active video controller.
577
578 @param VideoController PCI handle of video controller.
579
580 @retval EFI_NOT_FOUND There is no active video controller.
581 @retval EFI_SUCCESS The video controller is connected.
582 **/
583 EFI_STATUS
584 EFIAPI
585 EfiBootManagerConnectVideoController (
586 EFI_HANDLE VideoController OPTIONAL
587 );
588
589 //
590 // Boot Manager driver health library functions.
591 //
592
593 typedef struct {
594 EFI_DRIVER_HEALTH_PROTOCOL *DriverHealth;
595
596 ///
597 /// Driver relative handles
598 ///
599 EFI_HANDLE DriverHealthHandle;
600 EFI_HANDLE ControllerHandle;
601 EFI_HANDLE ChildHandle;
602
603 ///
604 /// Driver health messages of the specify Driver
605 ///
606 EFI_DRIVER_HEALTH_HII_MESSAGE *MessageList;
607
608 ///
609 /// HII relative handles
610 ///
611 EFI_HII_HANDLE HiiHandle;
612
613 ///
614 /// Driver Health status
615 ///
616 EFI_DRIVER_HEALTH_STATUS HealthStatus;
617 } EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO;
618
619 /**
620 Return all the Driver Health information.
621
622 When the cumulative health status of all the controllers managed by the
623 driver who produces the EFI_DRIVER_HEALTH_PROTOCOL is healthy, only one
624 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry is created for such
625 EFI_DRIVER_HEALTH_PROTOCOL instance.
626 Otherwise, every controller creates one EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO
627 entry. Additionally every child controller creates one
628 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO entry if the driver is a bus driver.
629
630 @param Count Return the count of the Driver Health information.
631
632 @retval NULL No Driver Health information is returned.
633 @retval !NULL Pointer to the Driver Health information array.
634 **/
635 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO *
636 EFIAPI
637 EfiBootManagerGetDriverHealthInfo (
638 UINTN *Count
639 );
640
641 /**
642 Free the Driver Health information array.
643
644 @param DriverHealthInfo Pointer to array of the Driver Health information.
645 @param Count Count of the array.
646
647 @retval EFI_SUCCESS The array is freed.
648 @retval EFI_INVALID_PARAMETER The array is NULL.
649 **/
650 EFI_STATUS
651 EFIAPI
652 EfiBootManagerFreeDriverHealthInfo (
653 EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO *DriverHealthInfo,
654 UINTN Count
655 );
656
657 #endif