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