]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h
MdeModulePkg/UefiBootManagerLib: limit recursive call depth
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / InternalBm.h
CommitLineData
067ed98a
RN
1/** @file\r
2 BDS library definition, include the file and data structure\r
3\r
54127af5 4Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
5d3a9896 5(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
067ed98a
RN
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _INTERNAL_BM_H_\r
17#define _INTERNAL_BM_H_\r
18\r
19#include <PiDxe.h>\r
20\r
21#include <IndustryStandard/Pci.h>\r
22#include <IndustryStandard/PeImage.h>\r
23#include <IndustryStandard/Atapi.h>\r
24#include <IndustryStandard/Scsi.h>\r
54127af5 25#include <IndustryStandard/Nvme.h>\r
067ed98a
RN
26\r
27#include <Protocol/PciRootBridgeIo.h>\r
28#include <Protocol/BlockIo.h>\r
29#include <Protocol/LoadedImage.h>\r
30#include <Protocol/SimpleFileSystem.h>\r
31#include <Protocol/LoadFile.h>\r
32#include <Protocol/DevicePath.h>\r
33#include <Protocol/SimpleTextIn.h>\r
34#include <Protocol/SimpleTextInEx.h>\r
35#include <Protocol/SimpleTextOut.h>\r
36#include <Protocol/SimpleNetwork.h>\r
37#include <Protocol/FirmwareVolume2.h>\r
38#include <Protocol/PciIo.h>\r
39#include <Protocol/GraphicsOutput.h>\r
40#include <Protocol/UsbIo.h>\r
41#include <Protocol/DiskInfo.h>\r
54127af5 42#include <Protocol/NvmExpressPassthru.h>\r
067ed98a
RN
43#include <Protocol/IdeControllerInit.h>\r
44#include <Protocol/BootLogo.h>\r
45#include <Protocol/DriverHealth.h>\r
46#include <Protocol/FormBrowser2.h>\r
780e05ca 47#include <Protocol/VariableLock.h>\r
339ae051 48#include <Protocol/RamDisk.h>\r
b33af221 49#include <Protocol/DeferredImageLoad.h>\r
067ed98a 50\r
067ed98a
RN
51#include <Guid/MemoryTypeInformation.h>\r
52#include <Guid/FileInfo.h>\r
53#include <Guid/GlobalVariable.h>\r
067ed98a
RN
54#include <Guid/StatusCodeDataTypeVariable.h>\r
55\r
56#include <Library/PrintLib.h>\r
57#include <Library/DebugLib.h>\r
58#include <Library/BaseMemoryLib.h>\r
59#include <Library/UefiBootServicesTableLib.h>\r
60#include <Library/UefiRuntimeServicesTableLib.h>\r
61#include <Library/UefiLib.h>\r
62#include <Library/MemoryAllocationLib.h>\r
63#include <Library/DxeServicesTableLib.h>\r
64#include <Library/HobLib.h>\r
65#include <Library/BaseLib.h>\r
66#include <Library/DevicePathLib.h>\r
67#include <Library/PerformanceLib.h>\r
68#include <Library/PcdLib.h>\r
69#include <Library/PeCoffGetEntryPointLib.h>\r
70#include <Library/UefiBootManagerLib.h>\r
067ed98a
RN
71#include <Library/DxeServicesLib.h>\r
72#include <Library/ReportStatusCodeLib.h>\r
73#include <Library/CapsuleLib.h>\r
74#include <Library/PerformanceLib.h>\r
75#include <Library/HiiLib.h>\r
76\r
77#if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)\r
78 #if defined (MDE_CPU_EBC)\r
79 //\r
80 // Uefi specification only defines the default boot file name for IA32, X64\r
81 // and IPF processor, so need define boot file name for EBC architecture here.\r
82 //\r
83 #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"\r
84 #else\r
85 #error "Can not determine the default boot file name for unknown processor type!"\r
86 #endif\r
87#endif\r
88\r
89typedef enum {\r
90 BmAcpiFloppyBoot,\r
91 BmHardwareDeviceBoot,\r
92 BmMessageAtapiBoot,\r
93 BmMessageSataBoot,\r
94 BmMessageUsbBoot,\r
95 BmMessageScsiBoot,\r
067ed98a
RN
96 BmMiscBoot\r
97} BM_BOOT_TYPE;\r
98\r
99typedef\r
100CHAR16 *\r
101(* BM_GET_BOOT_DESCRIPTION) (\r
102 IN EFI_HANDLE Handle\r
103 );\r
104\r
780e05ca
RN
105//\r
106// PlatformRecovery#### is the load option with the longest name\r
107//\r
108#define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####")\r
067ed98a
RN
109extern CHAR16 *mBmLoadOptionName[];\r
110\r
72208a9a
HG
111//\r
112// Maximum number of reconnect retry to repair controller; it is to limit the\r
113// number of recursive call of BmRepairAllControllers.\r
114//\r
115#define MAX_RECONNECT_REPAIR 10\r
116\r
d95ff8e8
RN
117/**\r
118 Visitor function to be called by BmForEachVariable for each variable\r
119 in variable storage.\r
120\r
121 @param Name Variable name.\r
122 @param Guid Variable GUID.\r
123 @param Context The same context passed to BmForEachVariable.\r
124**/\r
067ed98a
RN
125typedef\r
126VOID\r
d95ff8e8 127(*BM_VARIABLE_VISITOR) (\r
067ed98a
RN
128 CHAR16 *Name,\r
129 EFI_GUID *Guid,\r
130 VOID *Context\r
131 );\r
132\r
133/**\r
134 Call Visitor function for each variable in variable storage.\r
135\r
136 @param Visitor Visitor function.\r
137 @param Context The context passed to Visitor function.\r
138**/\r
139VOID\r
d95ff8e8
RN
140BmForEachVariable (\r
141 BM_VARIABLE_VISITOR Visitor,\r
067ed98a
RN
142 VOID *Context\r
143 );\r
144\r
f41c71d2
RN
145#define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')\r
146typedef struct {\r
147 UINT32 Signature;\r
148 LIST_ENTRY Link;\r
149 EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler;\r
150} BM_BOOT_DESCRIPTION_ENTRY;\r
151\r
067ed98a
RN
152/**\r
153 Repair all the controllers according to the Driver Health status queried.\r
72208a9a
HG
154\r
155 @param ReconnectRepairCount To record the number of recursive call of\r
156 this function itself.\r
067ed98a
RN
157**/\r
158VOID\r
159BmRepairAllControllers (\r
72208a9a 160 UINTN ReconnectRepairCount\r
067ed98a
RN
161 );\r
162\r
163#define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')\r
164typedef struct {\r
165 UINT32 Signature;\r
166 LIST_ENTRY Link;\r
167\r
168 BOOLEAN IsContinue;\r
169 UINT16 BootOption;\r
170 UINT8 CodeCount;\r
171 UINT8 WaitingKey;\r
172 EFI_KEY_DATA KeyData[3];\r
173} BM_HOTKEY;\r
174\r
175#define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)\r
176\r
067ed98a
RN
177/**\r
178 Get the Option Number that wasn't used.\r
179\r
180 @param LoadOptionType Load option type.\r
181 @param FreeOptionNumber To receive the minimal free option number.\r
182\r
183 @retval EFI_SUCCESS The option number is found\r
184 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.\r
185 @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL\r
186\r
187**/\r
188EFI_STATUS\r
189BmGetFreeOptionNumber (\r
190 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,\r
191 OUT UINT16 *FreeOptionNumber\r
192 );\r
193\r
067ed98a
RN
194/**\r
195 This routine adjust the memory information for different memory type and \r
665b26ba
RN
196 save them into the variables for next boot. It resets the system when\r
197 memory information is updated and the current boot option belongs to\r
024bdafc
RN
198 boot category instead of application category. It doesn't count the\r
199 reserved memory occupied by RAM Disk.\r
665b26ba 200\r
024bdafc
RN
201 @param Boot TRUE if current boot option belongs to boot\r
202 category instead of application category.\r
067ed98a
RN
203**/\r
204VOID\r
205BmSetMemoryTypeInformationVariable (\r
3a986a35 206 IN BOOLEAN Boot\r
067ed98a
RN
207 );\r
208\r
209/**\r
210 Check whether there is a instance in BlockIoDevicePath, which contain multi device path\r
211 instances, has the same partition node with HardDriveDevicePath device path\r
212\r
213 @param BlockIoDevicePath Multi device path instances which need to check\r
214 @param HardDriveDevicePath A device path which starts with a hard drive media\r
215 device path.\r
216\r
217 @retval TRUE There is a matched device path instance.\r
218 @retval FALSE There is no matched device path instance.\r
219\r
220**/\r
221BOOLEAN\r
222BmMatchPartitionDevicePathNode (\r
223 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,\r
224 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
225 );\r
226\r
227/**\r
228 Connect the specific Usb device which match the short form device path.\r
229\r
230 @param DevicePath A short-form device path that starts with the first\r
231 element being a USB WWID or a USB Class device\r
232 path\r
233\r
234 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.\r
235 DevicePath is not a USB device path.\r
236\r
237 @return EFI_SUCCESS Success to connect USB device\r
238 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.\r
239\r
240**/\r
241EFI_STATUS\r
242BmConnectUsbShortFormDevicePath (\r
243 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
244 );\r
245\r
246/**\r
247 Stop the hotkey processing.\r
248 \r
249 @param Event Event pointer related to hotkey service. \r
250 @param Context Context pass to this function. \r
251**/\r
252VOID\r
253EFIAPI\r
254BmStopHotkeyService (\r
255 IN EFI_EVENT Event,\r
256 IN VOID *Context\r
257 );\r
258\r
259/**\r
260 Set the variable and report the error through status code upon failure.\r
261\r
262 @param VariableName A Null-terminated string that is the name of the vendor's variable.\r
263 Each VariableName is unique for each VendorGuid. VariableName must\r
264 contain 1 or more characters. If VariableName is an empty string,\r
265 then EFI_INVALID_PARAMETER is returned.\r
266 @param VendorGuid A unique identifier for the vendor.\r
267 @param Attributes Attributes bitmask to set for the variable.\r
268 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
4073f85d 269 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero\r
067ed98a
RN
270 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
271 set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
272 the variable value (the timestamp associated with the variable may be updated however \r
273 even if no new data value is provided,see the description of the \r
274 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not \r
275 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). \r
276 @param Data The contents for the variable.\r
277\r
278 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r
279 defined by the Attributes.\r
280 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the\r
281 DataSize exceeds the maximum allowed.\r
282 @retval EFI_INVALID_PARAMETER VariableName is an empty string.\r
283 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
284 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r
285 @retval EFI_WRITE_PROTECTED The variable in question is read-only.\r
286 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r
4073f85d
ZC
287 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS\r
288 being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.\r
067ed98a
RN
289\r
290 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
291**/\r
292EFI_STATUS\r
293BmSetVariableAndReportStatusCodeOnError (\r
294 IN CHAR16 *VariableName,\r
295 IN EFI_GUID *VendorGuid,\r
296 IN UINT32 Attributes,\r
297 IN UINTN DataSize,\r
298 IN VOID *Data\r
299 );\r
300\r
067ed98a
RN
301/**\r
302 Function compares a device path data structure to that of all the nodes of a\r
303 second device path instance.\r
304\r
305 @param Multi A pointer to a multi-instance device path data\r
306 structure.\r
307 @param Single A pointer to a single-instance device path data\r
308 structure.\r
309\r
310 @retval TRUE If the Single device path is contained within Multi device path.\r
311 @retval FALSE The Single device path is not match within Multi device path.\r
312\r
313**/\r
314BOOLEAN\r
315BmMatchDevicePaths (\r
316 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
317 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
318 );\r
319\r
320/**\r
321 Delete the instance in Multi which matches partly with Single instance\r
322\r
323 @param Multi A pointer to a multi-instance device path data\r
324 structure.\r
325 @param Single A pointer to a single-instance device path data\r
326 structure.\r
327\r
328 @return This function will remove the device path instances in Multi which partly\r
329 match with the Single, and return the result device path. If there is no\r
330 remaining device path as a result, this function will return NULL.\r
331\r
332**/\r
333EFI_DEVICE_PATH_PROTOCOL *\r
334BmDelPartMatchInstance (\r
335 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
336 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
337 );\r
338\r
067ed98a
RN
339/**\r
340 Print the device path info.\r
341\r
342 @param DevicePath The device path need to print.\r
343**/\r
344VOID\r
345BmPrintDp (\r
346 EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
347 );\r
348\r
418e8cd9
RN
349/**\r
350 Convert a single character to number.\r
351 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'\r
352\r
353 @param Char The input char which need to convert to int.\r
354\r
355 @return The converted 8-bit number or (UINTN) -1 if conversion failed.\r
356**/\r
357UINTN\r
358BmCharToUint (\r
359 IN CHAR16 Char\r
360 );\r
361\r
1f2e80af
RN
362/**\r
363 Return the boot description for the controller.\r
364\r
365 @param Handle Controller handle.\r
366\r
367 @return The description string.\r
368**/\r
369CHAR16 *\r
370BmGetBootDescription (\r
371 IN EFI_HANDLE Handle\r
372 );\r
373\r
374/**\r
375 Enumerate all boot option descriptions and append " 2"/" 3"/... to make\r
376 unique description.\r
377\r
378 @param BootOptions Array of boot options.\r
379 @param BootOptionCount Count of boot options.\r
380**/\r
381VOID\r
382BmMakeBootOptionDescriptionUnique (\r
383 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,\r
384 UINTN BootOptionCount\r
385 );\r
026ede49
RN
386\r
387/**\r
388 Get the file buffer from the specified Load File instance.\r
389\r
390 @param LoadFileHandle The specified Load File instance.\r
391 @param FilePath The file path which will pass to LoadFile().\r
026ede49 392\r
08eff917
RN
393 @return The full device path pointing to the load option buffer.\r
394**/\r
395EFI_DEVICE_PATH_PROTOCOL *\r
396BmExpandLoadFile (\r
397 IN EFI_HANDLE LoadFileHandle,\r
398 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
399 );\r
400\r
401/**\r
402 Return the RAM Disk device path created by LoadFile.\r
403\r
404 @param FilePath The source file path.\r
405\r
406 @return Callee-to-free RAM Disk device path\r
407**/\r
408EFI_DEVICE_PATH_PROTOCOL *\r
409BmGetRamDiskDevicePath (\r
410 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
411 );\r
412\r
413/**\r
414 Destroy the RAM Disk.\r
415\r
416 The destroy operation includes to call RamDisk.Unregister to\r
417 unregister the RAM DISK from RAM DISK driver, free the memory\r
418 allocated for the RAM Disk.\r
419\r
420 @param RamDiskDevicePath RAM Disk device path.\r
421**/\r
422VOID\r
423BmDestroyRamDisk (\r
424 IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath\r
425 );\r
426\r
427/**\r
428 Get the next possible full path pointing to the load option.\r
429\r
430 @param FilePath The device path pointing to a load option.\r
431 It could be a short-form device path.\r
432 @param FullPath The full path returned by the routine in last call.\r
433 Set to NULL in first call.\r
434\r
435 @return The next possible full path pointing to the load option.\r
436 Caller is responsible to free the memory.\r
437**/\r
438EFI_DEVICE_PATH_PROTOCOL *\r
439BmGetNextLoadOptionDevicePath (\r
440 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
441 IN EFI_DEVICE_PATH_PROTOCOL *FullPath\r
442 );\r
443\r
444/**\r
445 Return the next matched load option buffer.\r
446 The routine keeps calling BmGetNextLoadOptionDevicePath() until a valid\r
447 load option is read.\r
448\r
449 @param Type The load option type.\r
450 It's used to check whether the load option is valid.\r
451 When it's LoadOptionTypeMax, the routine only guarantees\r
452 the load option is a valid PE image but doesn't guarantee\r
453 the PE's subsystem type is valid.\r
454 @param FilePath The device path pointing to a load option.\r
455 It could be a short-form device path.\r
456 @param FullPath Return the next full device path of the load option after\r
457 short-form device path expanding.\r
458 Caller is responsible to free it.\r
459 NULL to return the first matched full device path.\r
460 @param FileSize Return the load option size.\r
461\r
462 @return The load option buffer. Caller is responsible to free the memory.\r
026ede49
RN
463**/\r
464VOID *\r
08eff917
RN
465BmGetNextLoadOptionBuffer (\r
466 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,\r
467 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
468 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
469 OUT UINTN *FileSize\r
026ede49 470 );\r
067ed98a 471#endif // _INTERNAL_BM_H_\r