]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Include/Library/GenericBdsLib.h
Sync in bug fix from EDK I:
[mirror_edk2.git] / MdeModulePkg / Include / Library / GenericBdsLib.h
CommitLineData
83d26a81 1/** @file\r
5f597758 2 Generic BDS library definition, include the data structure and function.\r
93e3992d 3\r
83d26a81 4Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
93e3992d 9\r
83d26a81 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
93e3992d 12\r
83d26a81 13**/\r
93e3992d 14\r
15#ifndef _GENERIC_BDS_LIB_H_\r
16#define _GENERIC_BDS_LIB_H_\r
17\r
93e3992d 18#include <Protocol/HiiDatabase.h>\r
19#include <IndustryStandard/PeImage.h>\r
20\r
21\r
22extern EFI_HANDLE mBdsImageHandle;\r
23\r
24//\r
25// Constants which are variable names used to access variables\r
26//\r
5f597758 27#define VAR_LEGACY_DEV_ORDER L"LegacyDevOrder"\r
93e3992d 28\r
29//\r
30// Data structures and defines\r
31//\r
32#define FRONT_PAGE_QUESTION_ID 0x0000\r
33#define FRONT_PAGE_DATA_WIDTH 0x01\r
34\r
35//\r
36// ConnectType\r
37//\r
38#define CONSOLE_OUT 0x00000001\r
39#define STD_ERROR 0x00000002\r
40#define CONSOLE_IN 0x00000004\r
41#define CONSOLE_ALL (CONSOLE_OUT | CONSOLE_IN | STD_ERROR)\r
42\r
43//\r
44// Load Option Attributes defined in EFI Specification\r
45//\r
46#define LOAD_OPTION_ACTIVE 0x00000001\r
47#define LOAD_OPTION_FORCE_RECONNECT 0x00000002\r
48\r
93e3992d 49#define LOAD_OPTION_HIDDEN 0x00000008\r
50#define LOAD_OPTION_CATEGORY 0x00001F00\r
51\r
52#define LOAD_OPTION_CATEGORY_BOOT 0x00000000\r
53#define LOAD_OPTION_CATEGORY_APP 0x00000100\r
54\r
55#define EFI_BOOT_OPTION_SUPPORT_KEY 0x00000001\r
56#define EFI_BOOT_OPTION_SUPPORT_APP 0x00000002\r
93e3992d 57\r
58#define IS_LOAD_OPTION_TYPE(_c, _Mask) (BOOLEAN) (((_c) & (_Mask)) != 0)\r
59\r
60//\r
61// Define Maxmim characters that will be accepted\r
62//\r
63#define MAX_CHAR 480\r
64#define MAX_CHAR_SIZE (MAX_CHAR * 2)\r
65\r
66#define MIN_ALIGNMENT_SIZE 4\r
67#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0)\r
68\r
69//\r
70// Define maximum characters for boot option variable "BootXXXX"\r
71//\r
72#define BOOT_OPTION_MAX_CHAR 10\r
73\r
74//\r
75// This data structure is the part of BDS_CONNECT_ENTRY that we can hard code.\r
76//\r
77#define BDS_LOAD_OPTION_SIGNATURE EFI_SIGNATURE_32 ('B', 'd', 'C', 'O')\r
78\r
79typedef struct {\r
80\r
81 UINTN Signature;\r
82 LIST_ENTRY Link;\r
83\r
84 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
85\r
86 CHAR16 *OptionName;\r
87 UINTN OptionNumber;\r
88 UINT16 BootCurrent;\r
89 UINT32 Attribute;\r
90 CHAR16 *Description;\r
91 VOID *LoadOptions;\r
92 UINT32 LoadOptionsSize;\r
93 CHAR16 *StatusString;\r
94\r
95} BDS_COMMON_OPTION;\r
96\r
97typedef struct {\r
98 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
99 UINTN ConnectType;\r
100} BDS_CONSOLE_CONNECT_ENTRY;\r
101\r
102//\r
103// Lib Functions\r
104//\r
105\r
106//\r
5f597758 107// Bds boot related lib functions\r
93e3992d 108//\r
83d26a81 109/**\r
5f597758 110 Boot from the UEFI spec defined "BootNext" variable.\r
93e3992d 111\r
83d26a81 112**/\r
93e3992d 113VOID\r
83d26a81 114EFIAPI\r
93e3992d 115BdsLibBootNext (\r
116 VOID\r
117 );\r
118\r
83d26a81 119/**\r
5f597758 120 Process the boot option follow the UEFI specification and\r
83d26a81 121 special treat the legacy boot option with BBS_DEVICE_PATH.\r
122\r
123 @param Option The boot option need to be processed\r
124 @param DevicePath The device path which describe where to load the\r
125 boot image or the legcy BBS device path to boot\r
126 the legacy OS\r
5f597758
LG
127 @param ExitDataSize The size of exit data.\r
128 @param ExitData Data returned when Boot image failed.\r
83d26a81 129\r
5f597758 130 @retval EFI_SUCCESS Boot from the input boot option successfully.\r
83d26a81 131 @retval EFI_NOT_FOUND If the Device Path is not found in the system\r
132\r
133**/\r
93e3992d 134EFI_STATUS\r
83d26a81 135EFIAPI\r
93e3992d 136BdsLibBootViaBootOption (\r
137 IN BDS_COMMON_OPTION * Option,\r
138 IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,\r
139 OUT UINTN *ExitDataSize,\r
140 OUT CHAR16 **ExitData OPTIONAL\r
141 );\r
142\r
83d26a81 143\r
144/**\r
145 This function will enumerate all possible boot device in the system,\r
146 it will only excute once of every boot.\r
147\r
148 @param BdsBootOptionList The header of the link list which indexed all\r
149 current boot options\r
150\r
151 @retval EFI_SUCCESS Finished all the boot device enumerate and create\r
152 the boot option base on that boot device\r
153\r
154**/\r
93e3992d 155EFI_STATUS\r
83d26a81 156EFIAPI\r
93e3992d 157BdsLibEnumerateAllBootOption (\r
83d26a81 158 IN OUT LIST_ENTRY *BdsBootOptionList\r
93e3992d 159 );\r
160\r
83d26a81 161/**\r
162 Build the boot option with the handle parsed in\r
163\r
164 @param Handle The handle which present the device path to create\r
165 boot option\r
166 @param BdsBootOptionList The header of the link list which indexed all\r
167 current boot options\r
5f597758 168 @param String The description of the boot option.\r
83d26a81 169\r
170**/\r
93e3992d 171VOID\r
83d26a81 172EFIAPI\r
93e3992d 173BdsLibBuildOptionFromHandle (\r
83d26a81 174 IN EFI_HANDLE Handle,\r
175 IN LIST_ENTRY *BdsBootOptionList,\r
176 IN CHAR16 *String\r
93e3992d 177 );\r
178\r
83d26a81 179\r
180/**\r
5f597758 181 Build the on flash shell boot option with the handle parsed in.\r
83d26a81 182\r
183 @param Handle The handle which present the device path to create\r
184 on flash shell boot option\r
185 @param BdsBootOptionList The header of the link list which indexed all\r
186 current boot options\r
187\r
83d26a81 188**/\r
93e3992d 189VOID\r
83d26a81 190EFIAPI\r
93e3992d 191BdsLibBuildOptionFromShell (\r
83d26a81 192 IN EFI_HANDLE Handle,\r
193 IN OUT LIST_ENTRY *BdsBootOptionList\r
93e3992d 194 );\r
195\r
196//\r
197// Bds misc lib functions\r
198//\r
83d26a81 199/**\r
200 Return the default value for system Timeout variable.\r
201\r
202 @return Timeout value.\r
203\r
204**/\r
93e3992d 205UINT16\r
83d26a81 206EFIAPI\r
93e3992d 207BdsLibGetTimeout (\r
208 VOID\r
209 );\r
210\r
83d26a81 211/**\r
212 Get boot mode by looking up configuration table and parsing HOB list\r
213\r
214 @param BootMode Boot mode from PEI handoff HOB.\r
215\r
216 @retval EFI_SUCCESS Successfully get boot mode\r
217\r
218**/\r
93e3992d 219EFI_STATUS\r
83d26a81 220EFIAPI\r
93e3992d 221BdsLibGetBootMode (\r
222 OUT EFI_BOOT_MODE *BootMode\r
223 );\r
224\r
83d26a81 225\r
226/**\r
227 The function will go through the driver optoin link list, load and start\r
228 every driver the driver optoin device path point to.\r
229\r
230 @param BdsDriverLists The header of the current driver option link list\r
231\r
232**/\r
93e3992d 233VOID\r
83d26a81 234EFIAPI\r
93e3992d 235BdsLibLoadDrivers (\r
83d26a81 236 IN LIST_ENTRY *BdsDriverLists\r
93e3992d 237 );\r
238\r
83d26a81 239\r
240/**\r
241 Process BootOrder, or DriverOrder variables, by calling\r
242 BdsLibVariableToOption () for each UINT16 in the variables.\r
243\r
244 @param BdsCommonOptionList The header of the option list base on variable\r
245 VariableName\r
246 @param VariableName EFI Variable name indicate the BootOrder or\r
247 DriverOrder\r
248\r
249 @retval EFI_SUCCESS Success create the boot option or driver option\r
250 list\r
251 @retval EFI_OUT_OF_RESOURCES Failed to get the boot option or driver option list\r
252\r
253**/\r
93e3992d 254EFI_STATUS\r
83d26a81 255EFIAPI\r
93e3992d 256BdsLibBuildOptionFromVar (\r
83d26a81 257 IN LIST_ENTRY *BdsCommonOptionList,\r
258 IN CHAR16 *VariableName\r
93e3992d 259 );\r
260\r
83d26a81 261/**\r
262 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated\r
263 buffer, and the size of the buffer. If failure return NULL.\r
264\r
265 @param Name String part of EFI variable name\r
266 @param VendorGuid GUID part of EFI variable name\r
267 @param VariableSize Returns the size of the EFI variable that was read\r
268\r
5f597758
LG
269 @return Dynamically allocated memory that contains a copy of the EFI variable\r
270 Caller is responsible freeing the buffer.\r
83d26a81 271 @retval NULL Variable was not read\r
272\r
273**/\r
274VOID *\r
275EFIAPI\r
93e3992d 276BdsLibGetVariableAndSize (\r
277 IN CHAR16 *Name,\r
278 IN EFI_GUID *VendorGuid,\r
279 OUT UINTN *VariableSize\r
280 );\r
281\r
83d26a81 282\r
283/**\r
284 This function prints a series of strings.\r
285\r
286 @param ConOut Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r
287 @param ... A variable argument list containing series of\r
288 strings, the last string must be NULL.\r
289\r
290 @retval EFI_SUCCESS Success print out the string using ConOut.\r
291 @retval EFI_STATUS Return the status of the ConOut->OutputString ().\r
292\r
293**/\r
93e3992d 294EFI_STATUS\r
83d26a81 295EFIAPI\r
93e3992d 296BdsLibOutputStrings (\r
297 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut,\r
298 ...\r
299 );\r
300\r
83d26a81 301/**\r
302 Build the boot#### or driver#### option from the VariableName, the\r
5f597758 303 build boot#### or driver#### will also be linked to BdsCommonOptionList.\r
83d26a81 304\r
305 @param BdsCommonOptionList The header of the boot#### or driver#### option\r
306 link list\r
307 @param VariableName EFI Variable name indicate if it is boot#### or\r
308 driver####\r
309\r
310 @retval BDS_COMMON_OPTION Get the option just been created\r
311 @retval NULL Failed to get the new option\r
312\r
313**/\r
314BDS_COMMON_OPTION *\r
315EFIAPI\r
93e3992d 316BdsLibVariableToOption (\r
83d26a81 317 IN OUT LIST_ENTRY *BdsCommonOptionList,\r
318 IN CHAR16 *VariableName\r
93e3992d 319 );\r
320\r
83d26a81 321/**\r
322 This function will register the new boot#### or driver#### option base on\r
323 the VariableName. The new registered boot#### or driver#### will be linked\r
324 to BdsOptionList and also update to the VariableName. After the boot#### or\r
325 driver#### updated, the BootOrder or DriverOrder will also be updated.\r
326\r
327 @param BdsOptionList The header of the boot#### or driver#### link list\r
328 @param DevicePath The device path which the boot#### or driver####\r
329 option present\r
330 @param String The description of the boot#### or driver####\r
331 @param VariableName Indicate if the boot#### or driver#### option\r
332\r
333 @retval EFI_SUCCESS The boot#### or driver#### have been success\r
334 registered\r
335 @retval EFI_STATUS Return the status of gRT->SetVariable ().\r
336\r
337**/\r
93e3992d 338EFI_STATUS\r
83d26a81 339EFIAPI\r
93e3992d 340BdsLibRegisterNewOption (\r
83d26a81 341 IN LIST_ENTRY *BdsOptionList,\r
93e3992d 342 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
343 IN CHAR16 *String,\r
344 IN CHAR16 *VariableName\r
345 );\r
346\r
347//\r
348// Bds connect or disconnect driver lib funcion\r
349//\r
83d26a81 350/**\r
351 Connects all drivers to all controllers.\r
352 This function make sure all the current system driver will manage\r
353 the correspoinding controllers if have. And at the same time, make\r
354 sure all the system controllers have driver to manage it if have.\r
355\r
356**/\r
93e3992d 357VOID\r
83d26a81 358EFIAPI\r
93e3992d 359BdsLibConnectAllDriversToAllControllers (\r
360 VOID\r
361 );\r
362\r
83d26a81 363/**\r
364 This function will connect all the system driver to controller\r
365 first, and then special connect the default console, this make\r
366 sure all the system controller avialbe and the platform default\r
367 console connected.\r
368\r
369**/\r
93e3992d 370VOID\r
83d26a81 371EFIAPI\r
93e3992d 372BdsLibConnectAll (\r
373 VOID\r
374 );\r
375\r
83d26a81 376/**\r
377 This function will create all handles associate with every device\r
378 path node. If the handle associate with one device path node can not\r
379 be created success, then still give one chance to do the dispatch,\r
380 which load the missing drivers if possible.\r
381\r
382 @param DevicePathToConnect The device path which will be connected, it can be\r
383 a multi-instance device path\r
384\r
385 @retval EFI_SUCCESS All handles associate with every device path node\r
386 have been created\r
387 @retval EFI_OUT_OF_RESOURCES There is no resource to create new handles\r
388 @retval EFI_NOT_FOUND Create the handle associate with one device path\r
389 node failed\r
390\r
391**/\r
93e3992d 392EFI_STATUS\r
83d26a81 393EFIAPI\r
93e3992d 394BdsLibConnectDevicePath (\r
395 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect\r
396 );\r
397\r
83d26a81 398/**\r
399 This function will connect all current system handles recursively. The\r
400 connection will finish until every handle's child handle created if it have.\r
401\r
402 @retval EFI_SUCCESS All handles and it's child handle have been\r
403 connected\r
404 @retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().\r
405\r
406**/\r
93e3992d 407EFI_STATUS\r
83d26a81 408EFIAPI\r
93e3992d 409BdsLibConnectAllEfi (\r
410 VOID\r
411 );\r
412\r
83d26a81 413\r
414/**\r
415 This function will disconnect all current system handles. The disconnection\r
416 will finish until every handle have been disconnected.\r
417\r
418 @retval EFI_SUCCESS All handles have been disconnected\r
419 @retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().\r
420\r
421**/\r
93e3992d 422EFI_STATUS\r
83d26a81 423EFIAPI\r
93e3992d 424BdsLibDisconnectAllEfi (\r
425 VOID\r
426 );\r
427\r
428//\r
5f597758 429// Bds console related lib functions\r
93e3992d 430//\r
83d26a81 431/**\r
432 This function will search every simpletxt devive in current system,\r
433 and make every simpletxt device as pertantial console device.\r
434\r
435**/\r
93e3992d 436VOID\r
83d26a81 437EFIAPI\r
93e3992d 438BdsLibConnectAllConsoles (\r
439 VOID\r
440 );\r
441\r
83d26a81 442\r
443/**\r
444 This function will connect console device base on the console\r
445 device variable ConIn, ConOut and ErrOut.\r
446\r
447 @retval EFI_SUCCESS At least one of the ConIn and ConOut device have\r
448 been connected success.\r
5f597758 449 @retval EFI_STATUS Return the status of BdsLibConnectConsoleVariable ().\r
83d26a81 450\r
451**/\r
93e3992d 452EFI_STATUS\r
83d26a81 453EFIAPI\r
93e3992d 454BdsLibConnectAllDefaultConsoles (\r
455 VOID\r
456 );\r
457\r
83d26a81 458/**\r
459 This function update console variable based on ConVarName, it can\r
460 add or remove one specific console device path from the variable\r
461\r
462 @param ConVarName Console related variable name, ConIn, ConOut,\r
463 ErrOut.\r
464 @param CustomizedConDevicePath The console device path which will be added to\r
465 the console variable ConVarName, this parameter\r
466 can not be multi-instance.\r
467 @param ExclusiveDevicePath The console device path which will be removed\r
468 from the console variable ConVarName, this\r
469 parameter can not be multi-instance.\r
470\r
5f597758 471 @retval EFI_UNSUPPORTED The added device path is same to the removed one.\r
83d26a81 472 @retval EFI_SUCCESS Success add or remove the device path from the\r
473 console variable.\r
474\r
475**/\r
93e3992d 476EFI_STATUS\r
83d26a81 477EFIAPI\r
93e3992d 478BdsLibUpdateConsoleVariable (\r
479 IN CHAR16 *ConVarName,\r
480 IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,\r
481 IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath\r
482 );\r
483\r
83d26a81 484/**\r
485 Connect the console device base on the variable ConVarName, if\r
486 device path of the ConVarName is multi-instance device path, if\r
487 anyone of the instances is connected success, then this function\r
488 will return success.\r
489\r
490 @param ConVarName Console related variable name, ConIn, ConOut,\r
491 ErrOut.\r
492\r
493 @retval EFI_NOT_FOUND There is not any console devices connected\r
494 success\r
495 @retval EFI_SUCCESS Success connect any one instance of the console\r
496 device path base on the variable ConVarName.\r
497\r
498**/\r
93e3992d 499EFI_STATUS\r
83d26a81 500EFIAPI\r
93e3992d 501BdsLibConnectConsoleVariable (\r
502 IN CHAR16 *ConVarName\r
503 );\r
504\r
505//\r
5f597758 506// Bds device path related lib functions\r
93e3992d 507//\r
83d26a81 508/**\r
509 Function unpacks a device path data structure so that all the nodes\r
510 of a device path are naturally aligned.\r
511\r
512 @param DevPath A pointer to a device path data structure\r
513\r
514 @return If the memory for the device path is successfully allocated, then a\r
515 pointer to the new device path is returned. Otherwise, NULL is returned.\r
516\r
517**/\r
518EFI_DEVICE_PATH_PROTOCOL *\r
519EFIAPI\r
93e3992d 520BdsLibUnpackDevicePath (\r
521 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
522 );\r
523\r
83d26a81 524/**\r
525 Delete the instance in Multi which matches partly with Single instance\r
526\r
527 @param Multi A pointer to a multi-instance device path data\r
528 structure.\r
529 @param Single A pointer to a single-instance device path data\r
530 structure.\r
531\r
532 @return This function will remove the device path instances in Multi which partly\r
533 match with the Single, and return the result device path. If there is no\r
534 remaining device path as a result, this function will return NULL.\r
535\r
536**/\r
93e3992d 537EFI_DEVICE_PATH_PROTOCOL *\r
83d26a81 538EFIAPI\r
93e3992d 539BdsLibDelPartMatchInstance (\r
540 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
541 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
542 );\r
543\r
83d26a81 544/**\r
545 Function compares a device path data structure to that of all the nodes of a\r
546 second device path instance.\r
547\r
548 @param Multi A pointer to a multi-instance device path data\r
549 structure.\r
550 @param Single A pointer to a single-instance device path data\r
551 structure.\r
552\r
5f597758
LG
553 @retval TRUE If the Single device path is contained within Multi device path.\r
554 @retval FALSE The Single device path is not match within Multi device path.\r
83d26a81 555\r
556**/\r
93e3992d 557BOOLEAN\r
83d26a81 558EFIAPI\r
93e3992d 559BdsLibMatchDevicePaths (\r
560 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
561 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
562 );\r
563\r
83d26a81 564/**\r
565 This function converts an input device structure to a Unicode string.\r
566\r
567 @param DevPath A pointer to the device path structure.\r
568\r
569 @return A new allocated Unicode string that represents the device path.\r
570\r
571**/\r
572CHAR16 *\r
573EFIAPI\r
93e3992d 574DevicePathToStr (\r
83d26a81 575 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
93e3992d 576 );\r
577\r
93e3992d 578\r
579//\r
580// Internal definitions\r
581//\r
582typedef struct {\r
583 CHAR16 *str;\r
584 UINTN len;\r
585 UINTN maxlen;\r
586} POOL_PRINT;\r
587\r
588typedef struct {\r
589 UINT8 Type;\r
590 UINT8 SubType;\r
591 VOID (*Function) (POOL_PRINT *, VOID *);\r
592} DEVICE_PATH_STRING_TABLE;\r
593\r
594extern EFI_GUID mEfiDevicePathMessagingUartFlowControlGuid;\r
595\r
596typedef struct {\r
597 EFI_DEVICE_PATH_PROTOCOL Header;\r
598 EFI_GUID Guid;\r
599 UINT8 VendorDefinedData[1];\r
600} VENDOR_DEVICE_PATH_WITH_DATA;\r
601\r
93e3992d 602\r
603extern EFI_GUID mEfiDevicePathMessagingSASGuid;\r
604\r
605typedef struct {\r
606 EFI_DEVICE_PATH_PROTOCOL Header;\r
607 UINT16 NetworkProtocol;\r
608 UINT16 LoginOption;\r
609 UINT64 Lun;\r
610 UINT16 TargetPortalGroupTag;\r
611 CHAR16 iSCSITargetName[1];\r
612} ISCSI_DEVICE_PATH_WITH_NAME;\r
613\r
93e3992d 614\r
93e3992d 615//\r
616// Notes: EFI 64 shadow all option rom\r
617//\r
618#if defined (MDE_CPU_IPF)\r
619#define EFI64_SHADOW_ALL_LEGACY_ROM() ShadowAllOptionRom ();\r
93e3992d 620#else\r
621#define EFI64_SHADOW_ALL_LEGACY_ROM()\r
622#endif\r
623\r
5f597758
LG
624/**\r
625 Shadow all Legacy OptionRom. \r
626\r
627**/\r
628VOID\r
629EFIAPI\r
630ShadowAllOptionRom (\r
631 VOID\r
632 );\r
633\r
93e3992d 634//\r
635// BBS support macros and functions\r
636//\r
637\r
638#if defined(MDE_CPU_IA32) || defined(MDE_CPU_X64)\r
639#define REFRESH_LEGACY_BOOT_OPTIONS \\r
640 BdsDeleteAllInvalidLegacyBootOptions ();\\r
641 BdsAddNonExistingLegacyBootOptions (); \\r
642 BdsUpdateLegacyDevOrder ()\r
643#else\r
644#define REFRESH_LEGACY_BOOT_OPTIONS\r
645#endif\r
646\r
5f597758
LG
647/**\r
648 Delete all the invalid legacy boot options.\r
649\r
650 @retval EFI_SUCCESS All invalide legacy boot options are deleted.\r
651 @retval EFI_OUT_OF_RESOURCES Fail to allocate necessary memory.\r
652 @retval EFI_NOT_FOUND Fail to retrive variable of boot order.\r
653\r
654**/\r
93e3992d 655EFI_STATUS\r
5f597758 656EFIAPI\r
93e3992d 657BdsDeleteAllInvalidLegacyBootOptions (\r
658 VOID\r
659 );\r
660\r
5f597758
LG
661/**\r
662\r
663 Add the legacy boot options from BBS table if they do not exist.\r
664\r
665 @retval EFI_SUCCESS The boot options are added successfully \r
666 or they are already in boot options.\r
667\r
668**/\r
93e3992d 669EFI_STATUS\r
5f597758 670EFIAPI\r
93e3992d 671BdsAddNonExistingLegacyBootOptions (\r
672 VOID\r
673 );\r
674\r
5f597758
LG
675/**\r
676\r
677 Add the legacy boot devices from BBS table into \r
678 the legacy device boot order.\r
679\r
680 @retval EFI_SUCCESS The boot devices are added successfully.\r
681\r
682**/\r
93e3992d 683EFI_STATUS\r
5f597758 684EFIAPI\r
93e3992d 685BdsUpdateLegacyDevOrder (\r
686 VOID\r
687 );\r
688\r
5f597758
LG
689/**\r
690\r
691 Set the boot priority for BBS entries based on boot option entry and boot order.\r
692\r
693 @param Entry The boot option is to be checked for refresh BBS table.\r
694 \r
695 @retval EFI_SUCCESS The boot priority for BBS entries is refreshed successfully.\r
696\r
697**/\r
93e3992d 698EFI_STATUS\r
5f597758 699EFIAPI\r
93e3992d 700BdsRefreshBbsTableForBoot (\r
701 IN BDS_COMMON_OPTION *Entry\r
702 );\r
703\r
5f597758
LG
704/**\r
705\r
706 Delete boot option specified by OptionNumber and adjust the boot order.\r
707\r
708 @param OptionNumber The boot option to be deleted.\r
709 @param BootOrder Boot order list to be adjusted by remove this boot option.\r
710 @param BootOrderSize The size of Boot order list will be modified.\r
711 \r
712 @retval EFI_SUCCESS The boot option is deleted successfully.\r
713\r
714**/\r
93e3992d 715EFI_STATUS\r
5f597758 716EFIAPI\r
93e3992d 717BdsDeleteBootOption (\r
718 IN UINTN OptionNumber,\r
719 IN OUT UINT16 *BootOrder,\r
720 IN OUT UINTN *BootOrderSize\r
721 );\r
722\r
723//\r
724//The interface functions relate with Setup Browser Reset Reminder feature\r
725//\r
83d26a81 726/**\r
727 Enable the setup browser reset reminder feature.\r
728 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.\r
729\r
730**/\r
93e3992d 731VOID\r
83d26a81 732EFIAPI\r
93e3992d 733EnableResetReminderFeature (\r
734 VOID\r
735 );\r
736\r
83d26a81 737/**\r
738 Disable the setup browser reset reminder feature.\r
739 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.\r
740\r
741**/\r
93e3992d 742VOID\r
83d26a81 743EFIAPI\r
93e3992d 744DisableResetReminderFeature (\r
745 VOID\r
746 );\r
747\r
83d26a81 748/**\r
749 Record the info that a reset is required.\r
750 A module boolean variable is used to record whether a reset is required.\r
751\r
752**/\r
93e3992d 753VOID\r
83d26a81 754EFIAPI\r
93e3992d 755EnableResetRequired (\r
756 VOID\r
757 );\r
758\r
83d26a81 759\r
760/**\r
761 Record the info that no reset is required.\r
762 A module boolean variable is used to record whether a reset is required.\r
763\r
764**/\r
93e3992d 765VOID\r
83d26a81 766EFIAPI\r
93e3992d 767DisableResetRequired (\r
768 VOID\r
769 );\r
770\r
83d26a81 771/**\r
772 Check whether platform policy enable the reset reminder feature. The default is enabled.\r
773\r
774**/\r
93e3992d 775BOOLEAN\r
83d26a81 776EFIAPI\r
93e3992d 777IsResetReminderFeatureEnable (\r
778 VOID\r
779 );\r
780\r
83d26a81 781/**\r
782 Check if user changed any option setting which needs a system reset to be effective.\r
783\r
784**/\r
93e3992d 785BOOLEAN\r
83d26a81 786EFIAPI\r
93e3992d 787IsResetRequired (\r
788 VOID\r
789 );\r
790\r
83d26a81 791/**\r
792 Check whether a reset is needed, and finish the reset reminder feature.\r
793 If a reset is needed, Popup a menu to notice user, and finish the feature\r
794 according to the user selection.\r
795\r
796**/\r
93e3992d 797VOID\r
83d26a81 798EFIAPI\r
93e3992d 799SetupResetReminder (\r
800 VOID\r
801 );\r
802\r
83d26a81 803\r
804/**\r
805 Get the headers (dos, image, optional header) from an image\r
806\r
807 @param Device SimpleFileSystem device handle\r
808 @param FileName File name for the image\r
809 @param DosHeader Pointer to dos header\r
5f597758 810 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.\r
83d26a81 811\r
812 @retval EFI_SUCCESS Successfully get the machine type.\r
813 @retval EFI_NOT_FOUND The file is not found.\r
814 @retval EFI_LOAD_ERROR File is not a valid image file.\r
815\r
816**/\r
93e3992d 817EFI_STATUS\r
83d26a81 818EFIAPI\r
93e3992d 819BdsLibGetImageHeader (\r
820 IN EFI_HANDLE Device,\r
821 IN CHAR16 *FileName,\r
822 OUT EFI_IMAGE_DOS_HEADER *DosHeader,\r
823 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr\r
93e3992d 824 );\r
83d26a81 825\r
93e3992d 826//\r
827// Define the boot type which to classify the boot option type\r
828// Different boot option type could have different boot behavior\r
829// Use their device path node (Type + SubType) as type value\r
830// The boot type here can be added according to requirement\r
831//\r
832//\r
833// ACPI boot type. For ACPI device, cannot use sub-type to distinguish device, so hardcode their value\r
834//\r
835#define BDS_EFI_ACPI_FLOPPY_BOOT 0x0201\r
836//\r
837// Message boot type\r
838// If a device path of boot option only point to a message node, the boot option is message boot type\r
839//\r
840#define BDS_EFI_MESSAGE_ATAPI_BOOT 0x0301 // Type 03; Sub-Type 01\r
841#define BDS_EFI_MESSAGE_SCSI_BOOT 0x0302 // Type 03; Sub-Type 02\r
842#define BDS_EFI_MESSAGE_USB_DEVICE_BOOT 0x0305 // Type 03; Sub-Type 05\r
843#define BDS_EFI_MESSAGE_MISC_BOOT 0x03FF\r
844//\r
845// Media boot type\r
846// If a device path of boot option contain a media node, the boot option is media boot type\r
847//\r
848#define BDS_EFI_MEDIA_HD_BOOT 0x0401 // Type 04; Sub-Type 01\r
849#define BDS_EFI_MEDIA_CDROM_BOOT 0x0402 // Type 04; Sub-Type 02\r
850//\r
851// BBS boot type\r
852// If a device path of boot option contain a BBS node, the boot option is BBS boot type\r
853//\r
854#define BDS_LEGACY_BBS_BOOT 0x0501 // Type 05; Sub-Type 01\r
855\r
856#define BDS_EFI_UNSUPPORT 0xFFFF\r
857\r
858//\r
859// USB host controller Programming Interface.\r
860//\r
861#define PCI_CLASSC_PI_UHCI 0x00\r
862#define PCI_CLASSC_PI_EHCI 0x20\r
863\r
83d26a81 864/**\r
865 Check whether there is a instance in BlockIoDevicePath, which contain multi device path\r
866 instances, has the same partition node with HardDriveDevicePath device path\r
867\r
868 @param BlockIoDevicePath Multi device path instances which need to check\r
869 @param HardDriveDevicePath A device path which starts with a hard drive media\r
870 device path.\r
871\r
5f597758
LG
872 @retval TRUE There is a matched device path instance.\r
873 @retval FALSE There is no matched device path instance.\r
83d26a81 874\r
875**/\r
93e3992d 876BOOLEAN\r
83d26a81 877EFIAPI\r
93e3992d 878MatchPartitionDevicePathNode (\r
879 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,\r
880 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
881 );\r
83d26a81 882\r
883\r
884/**\r
885 Expand a device path that starts with a hard drive media device path node to be a\r
886 full device path that includes the full hardware path to the device. We need\r
887 to do this so it can be booted. As an optimizaiton the front match (the part point\r
888 to the partition node. E.g. ACPI() /PCI()/ATA()/Partition() ) is saved in a variable\r
889 so a connect all is not required on every boot. All successful history device path\r
890 which point to partition node (the front part) will be saved.\r
891\r
892 @param HardDriveDevicePath EFI Device Path to boot, if it starts with a hard\r
893 drive media device path.\r
894 @return A Pointer to the full device path or NULL if a valid Hard Drive devic path\r
895 cannot be found.\r
896\r
897**/\r
93e3992d 898EFI_DEVICE_PATH_PROTOCOL *\r
83d26a81 899EFIAPI\r
93e3992d 900BdsExpandPartitionPartialDevicePathToFull (\r
901 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
902 );\r
903 \r
83d26a81 904/**\r
905 Return the bootable media handle.\r
906 First, check the device is connected\r
907 Second, check whether the device path point to a device which support SimpleFileSystemProtocol,\r
908 Third, detect the the default boot file in the Media, and return the removable Media handle.\r
909\r
910 @param DevicePath Device Path to a bootable device\r
911\r
83d26a81 912 @retval NULL The media on the DevicePath is not bootable\r
913\r
914**/\r
93e3992d 915EFI_HANDLE\r
83d26a81 916EFIAPI\r
93e3992d 917BdsLibGetBootableHandle (\r
918 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
919 );\r
920 \r
83d26a81 921\r
922/**\r
923 Check whether the Device path in a boot option point to a valide bootable device,\r
924 And if CheckMedia is true, check the device is ready to boot now.\r
925\r
5f597758
LG
926 @param DevPath the Device path in a boot option\r
927 @param CheckMedia if true, check the device is ready to boot now.\r
83d26a81 928\r
5f597758
LG
929 @retval TRUE the Device path is valide\r
930 @retval FALSE the Device path is invalide .\r
83d26a81 931\r
932**/\r
93e3992d 933BOOLEAN\r
83d26a81 934EFIAPI\r
93e3992d 935BdsLibIsValidEFIBootOptDevicePath (\r
936 IN EFI_DEVICE_PATH_PROTOCOL *DevPath,\r
937 IN BOOLEAN CheckMedia\r
938 );\r
939 \r
83d26a81 940/**\r
5f597758 941 For a bootable Device path, return its boot type.\r
83d26a81 942\r
943 @param DevicePath The bootable device Path to check\r
944\r
945 @retval BDS_EFI_MEDIA_HD_BOOT If the device path contains any media deviec path node, it is media boot type\r
946 For the floppy node, handle it as media node\r
947 @retval BDS_EFI_MEDIA_CDROM_BOOT If the device path contains any media deviec path node, it is media boot type\r
948 For the floppy node, handle it as media node\r
949 @retval BDS_EFI_ACPI_FLOPPY_BOOT If the device path contains any media deviec path node, it is media boot type\r
950 For the floppy node, handle it as media node\r
951 @retval BDS_EFI_MESSAGE_ATAPI_BOOT If the device path not contains any media deviec path node, and\r
952 its last device path node point to a message device path node, it is\r
953 \r
954 @retval BDS_EFI_MESSAGE_SCSI_BOOT If the device path not contains any media deviec path node, and\r
955 its last device path node point to a message device path node, it is\r
956 @retval BDS_EFI_MESSAGE_USB_DEVICE_BOOT If the device path not contains any media deviec path node, and\r
957 its last device path node point to a message device path node, it is\r
958 @retval BDS_EFI_MESSAGE_MISC_BOOT If the device path not contains any media deviec path node, and\r
959 its last device path node point to a message device path node, it is\r
960 @retval BDS_LEGACY_BBS_BOOT Legacy boot type\r
961 @retval BDS_EFI_UNSUPPORT An EFI Removable BlockIO device path not point to a media and message devie, \r
962\r
963**/\r
93e3992d 964UINT32\r
83d26a81 965EFIAPI\r
93e3992d 966BdsGetBootTypeFromDevicePath (\r
967 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
968 );\r
83d26a81 969\r
970\r
971/**\r
5f597758
LG
972 This routine register a function to adjust the different type memory page number\r
973 just before booting and save the updated info into the variable for next boot to use.\r
83d26a81 974\r
975**/\r
93e3992d 976VOID\r
977EFIAPI\r
978BdsLibSaveMemoryTypeInformation (\r
83d26a81 979 VOID\r
93e3992d 980 );\r
981 \r
83d26a81 982\r
983/**\r
984 According to a file guild, check a Fv file device path is valid. If it is invalid,\r
985 try to return the valid device path.\r
986 FV address maybe changes for memory layout adjust from time to time, use this funciton\r
987 could promise the Fv file device path is right.\r
988\r
989 @param DevicePath on input, the Fv file device path need to check on\r
990 output, the updated valid Fv file device path\r
991 @param FileGuid the Fv file guild\r
992\r
993 @retval EFI_INVALID_PARAMETER the input DevicePath or FileGuid is invalid\r
994 parameter\r
995 @retval EFI_UNSUPPORTED the input DevicePath does not contain Fv file\r
996 guild at all\r
997 @retval EFI_ALREADY_STARTED the input DevicePath has pointed to Fv file, it is\r
998 valid\r
999 @retval EFI_SUCCESS has successfully updated the invalid DevicePath,\r
1000 and return the updated device path in DevicePath\r
1001\r
1002**/\r
93e3992d 1003EFI_STATUS\r
1004EFIAPI\r
1005BdsLibUpdateFvFileDevicePath (\r
1006 IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,\r
1007 IN EFI_GUID *FileGuid\r
1008 );\r
1009\r
83d26a81 1010\r
1011/**\r
1012 Connect the specific Usb device which match the short form device path,\r
1013 and whose bus is determined by Host Controller (Uhci or Ehci)\r
1014\r
1015 @param HostControllerPI Uhci (0x00) or Ehci (0x20) or Both uhci and ehci\r
1016 (0xFF)\r
1017 @param RemainingDevicePath a short-form device path that starts with the first\r
5f597758 1018 element being a USB WWID or a USB Class device\r
83d26a81 1019 path\r
1020\r
5f597758
LG
1021 @retval EFI_SUCCESS The specific Usb device is connected successfully.\r
1022 @retval EFI_INVALID_PARAMETER Invalid HostControllerPi (not 0x00, 0x20 or 0xFF) \r
1023 or RemainingDevicePath is not the USB class device path.\r
1024 @retval EFI_NOT_FOUND The device specified by device path is not found.\r
83d26a81 1025\r
1026**/\r
93e3992d 1027EFI_STATUS\r
83d26a81 1028EFIAPI\r
1029BdsLibConnectUsbDevByShortFormDP(\r
25ca163d 1030 IN UINT8 HostControllerPI,\r
93e3992d 1031 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
1032 );\r
1033 \r
93e3992d 1034\r
1035//\r
1036// The implementation of this function is provided by Platform code.\r
1037//\r
83d26a81 1038/**\r
5f597758 1039 Convert Vendor device path to device name.\r
83d26a81 1040\r
1041 @param Str The buffer store device name\r
1042 @param DevPath Pointer to vendor device path\r
1043\r
83d26a81 1044**/\r
93e3992d 1045VOID\r
83d26a81 1046EFIAPI\r
93e3992d 1047DevPathVendor (\r
1048 IN OUT POOL_PRINT *Str,\r
1049 IN VOID *DevPath\r
ed66e1bc 1050 );\r
93e3992d 1051\r
83d26a81 1052/**\r
1053 Concatenates a formatted unicode string to allocated pool.\r
1054 The caller must free the resulting buffer.\r
1055\r
5f597758 1056 @param Str Tracks the allocated pool, size in use, and amount of pool allocated.\r
83d26a81 1057 @param fmt The format string\r
5f597758 1058 @param ... The data will be printed.\r
83d26a81 1059\r
1060 @return Allocated buffer with the formatted string printed in it.\r
5f597758
LG
1061 The caller must free the allocated buffer.\r
1062 The buffer allocation is not packed.\r
83d26a81 1063\r
1064**/\r
93e3992d 1065CHAR16 *\r
83d26a81 1066EFIAPI\r
93e3992d 1067CatPrint (\r
1068 IN OUT POOL_PRINT *Str,\r
1069 IN CHAR16 *fmt,\r
1070 ...\r
ed66e1bc 1071 );\r
d1d249a7 1072#endif\r
1073\r