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