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