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