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