2 BDS library definition, include the file and data structure
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
11 #ifndef _INTERNAL_BM_H_
12 #define _INTERNAL_BM_H_
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>
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>
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>
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>
73 #if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)
74 #if defined (MDE_CPU_EBC)
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.
79 #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"
81 #error "Can not determine the default boot file name for unknown processor type!"
97 (*BM_GET_BOOT_DESCRIPTION
) (
102 // PlatformRecovery#### is the load option with the longest name
104 #define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####")
105 extern CHAR16
*mBmLoadOptionName
[];
108 // Maximum number of reconnect retry to repair controller; it is to limit the
109 // number of recursive call of BmRepairAllControllers.
111 #define MAX_RECONNECT_REPAIR 10
114 Visitor function to be called by BmForEachVariable for each variable
117 @param Name Variable name.
118 @param Guid Variable GUID.
119 @param Context The same context passed to BmForEachVariable.
123 (*BM_VARIABLE_VISITOR
) (
130 Call Visitor function for each variable in variable storage.
132 @param Visitor Visitor function.
133 @param Context The context passed to Visitor function.
137 BM_VARIABLE_VISITOR Visitor
,
141 #define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')
145 EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler
;
146 } BM_BOOT_DESCRIPTION_ENTRY
;
149 Repair all the controllers according to the Driver Health status queried.
151 @param ReconnectRepairCount To record the number of recursive call of
152 this function itself.
155 BmRepairAllControllers (
156 UINTN ReconnectRepairCount
159 #define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')
168 EFI_KEY_DATA KeyData
[3];
171 #define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)
174 Get the Option Number that wasn't used.
176 @param LoadOptionType Load option type.
177 @param FreeOptionNumber To receive the minimal free option number.
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
185 BmGetFreeOptionNumber (
186 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
,
187 OUT UINT16
*FreeOptionNumber
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.
197 @param Boot TRUE if current boot option belongs to boot
198 category instead of application category.
201 BmSetMemoryTypeInformationVariable (
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
209 @param BlockIoDevicePath Multi device path instances which need to check
210 @param HardDriveDevicePath A device path which starts with a hard drive media
213 @retval TRUE There is a matched device path instance.
214 @retval FALSE There is no matched device path instance.
218 BmMatchPartitionDevicePathNode (
219 IN EFI_DEVICE_PATH_PROTOCOL
*BlockIoDevicePath
,
220 IN HARDDRIVE_DEVICE_PATH
*HardDriveDevicePath
224 Connect the specific Usb device which match the short form device path.
226 @param DevicePath A short-form device path that starts with the first
227 element being a USB WWID or a USB Class device
230 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
231 DevicePath is not a USB device path.
233 @return EFI_SUCCESS Success to connect USB device
234 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
238 BmConnectUsbShortFormDevicePath (
239 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
243 Stop the hotkey processing.
245 @param Event Event pointer related to hotkey service.
246 @param Context Context pass to this function.
250 BmStopHotkeyService (
256 Set the variable and report the error through status code upon failure.
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.
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.
286 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
289 BmSetVariableAndReportStatusCodeOnError (
290 IN CHAR16
*VariableName
,
291 IN EFI_GUID
*VendorGuid
,
292 IN UINT32 Attributes
,
298 Function compares a device path data structure to that of all the nodes of a
299 second device path instance.
301 @param Multi A pointer to a multi-instance device path data
303 @param Single A pointer to a single-instance device path data
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.
312 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
313 IN EFI_DEVICE_PATH_PROTOCOL
*Single
317 Delete the instance in Multi which matches partly with Single instance
319 @param Multi A pointer to a multi-instance device path data
321 @param Single A pointer to a single-instance device path data
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.
329 EFI_DEVICE_PATH_PROTOCOL
*
330 BmDelPartMatchInstance (
331 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
332 IN EFI_DEVICE_PATH_PROTOCOL
*Single
336 Print the device path info.
338 @param DevicePath The device path need to print.
342 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
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'
349 @param Char The input char which need to convert to int.
351 @return The converted 8-bit number or (UINTN) -1 if conversion failed.
359 Return the boot description for the controller.
361 @param Handle Controller handle.
363 @return The description string.
366 BmGetBootDescription (
371 Enumerate all boot option descriptions and append " 2"/" 3"/... to make
374 @param BootOptions Array of boot options.
375 @param BootOptionCount Count of boot options.
378 BmMakeBootOptionDescriptionUnique (
379 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
,
380 UINTN BootOptionCount
384 Get the file buffer from the specified Load File instance.
386 @param LoadFileHandle The specified Load File instance.
387 @param FilePath The file path which will pass to LoadFile().
389 @return The full device path pointing to the load option buffer.
391 EFI_DEVICE_PATH_PROTOCOL
*
393 IN EFI_HANDLE LoadFileHandle
,
394 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
398 Return the RAM Disk device path created by LoadFile.
400 @param FilePath The source file path.
402 @return Callee-to-free RAM Disk device path
404 EFI_DEVICE_PATH_PROTOCOL
*
405 BmGetRamDiskDevicePath (
406 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
410 Destroy the RAM Disk.
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.
416 @param RamDiskDevicePath RAM Disk device path.
420 IN EFI_DEVICE_PATH_PROTOCOL
*RamDiskDevicePath
424 Get the next possible full path pointing to the load option.
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.
431 @return The next possible full path pointing to the load option.
432 Caller is responsible to free the memory.
434 EFI_DEVICE_PATH_PROTOCOL
*
435 BmGetNextLoadOptionDevicePath (
436 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
437 IN EFI_DEVICE_PATH_PROTOCOL
*FullPath
441 Return the next matched load option buffer.
442 The routine keeps calling BmGetNextLoadOptionDevicePath() until a valid
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.
458 @return The load option buffer. Caller is responsible to free the memory.
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
,
468 #endif // _INTERNAL_BM_H_