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