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/VariableLock.h>
43 #include <Protocol/RamDisk.h>
44 #include <Protocol/DeferredImageLoad.h>
45 #include <Protocol/PlatformBootManager.h>
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>
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>
74 #if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)
75 #if defined (MDE_CPU_EBC)
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.
80 #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"
82 #error "Can not determine the default boot file name for unknown processor type!"
98 (* BM_GET_BOOT_DESCRIPTION
) (
103 // PlatformRecovery#### is the load option with the longest name
105 #define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####")
106 extern CHAR16
*mBmLoadOptionName
[];
109 // Maximum number of reconnect retry to repair controller; it is to limit the
110 // number of recursive call of BmRepairAllControllers.
112 #define MAX_RECONNECT_REPAIR 10
115 Visitor function to be called by BmForEachVariable for each variable
118 @param Name Variable name.
119 @param Guid Variable GUID.
120 @param Context The same context passed to BmForEachVariable.
124 (*BM_VARIABLE_VISITOR
) (
131 Call Visitor function for each variable in variable storage.
133 @param Visitor Visitor function.
134 @param Context The context passed to Visitor function.
138 BM_VARIABLE_VISITOR Visitor
,
142 #define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')
146 EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler
;
147 } BM_BOOT_DESCRIPTION_ENTRY
;
150 Repair all the controllers according to the Driver Health status queried.
152 @param ReconnectRepairCount To record the number of recursive call of
153 this function itself.
156 BmRepairAllControllers (
157 UINTN ReconnectRepairCount
160 #define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')
169 EFI_KEY_DATA KeyData
[3];
172 #define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)
175 Get the Option Number that wasn't used.
177 @param LoadOptionType Load option type.
178 @param FreeOptionNumber To receive the minimal free option number.
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
186 BmGetFreeOptionNumber (
187 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
,
188 OUT UINT16
*FreeOptionNumber
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.
198 @param Boot TRUE if current boot option belongs to boot
199 category instead of application category.
202 BmSetMemoryTypeInformationVariable (
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
210 @param BlockIoDevicePath Multi device path instances which need to check
211 @param HardDriveDevicePath A device path which starts with a hard drive media
214 @retval TRUE There is a matched device path instance.
215 @retval FALSE There is no matched device path instance.
219 BmMatchPartitionDevicePathNode (
220 IN EFI_DEVICE_PATH_PROTOCOL
*BlockIoDevicePath
,
221 IN HARDDRIVE_DEVICE_PATH
*HardDriveDevicePath
225 Connect the specific Usb device which match the short form device path.
227 @param DevicePath A short-form device path that starts with the first
228 element being a USB WWID or a USB Class device
231 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
232 DevicePath is not a USB device path.
234 @return EFI_SUCCESS Success to connect USB device
235 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
239 BmConnectUsbShortFormDevicePath (
240 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
244 Stop the hotkey processing.
246 @param Event Event pointer related to hotkey service.
247 @param Context Context pass to this function.
251 BmStopHotkeyService (
257 Set the variable and report the error through status code upon failure.
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.
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.
287 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
290 BmSetVariableAndReportStatusCodeOnError (
291 IN CHAR16
*VariableName
,
292 IN EFI_GUID
*VendorGuid
,
293 IN UINT32 Attributes
,
299 Function compares a device path data structure to that of all the nodes of a
300 second device path instance.
302 @param Multi A pointer to a multi-instance device path data
304 @param Single A pointer to a single-instance device path data
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.
313 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
314 IN EFI_DEVICE_PATH_PROTOCOL
*Single
318 Delete the instance in Multi which matches partly with Single instance
320 @param Multi A pointer to a multi-instance device path data
322 @param Single A pointer to a single-instance device path data
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.
330 EFI_DEVICE_PATH_PROTOCOL
*
331 BmDelPartMatchInstance (
332 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
333 IN EFI_DEVICE_PATH_PROTOCOL
*Single
337 Print the device path info.
339 @param DevicePath The device path need to print.
343 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
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'
350 @param Char The input char which need to convert to int.
352 @return The converted 8-bit number or (UINTN) -1 if conversion failed.
360 Return the boot description for the controller.
362 @param Handle Controller handle.
364 @return The description string.
367 BmGetBootDescription (
372 Enumerate all boot option descriptions and append " 2"/" 3"/... to make
375 @param BootOptions Array of boot options.
376 @param BootOptionCount Count of boot options.
379 BmMakeBootOptionDescriptionUnique (
380 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
,
381 UINTN BootOptionCount
385 Get the file buffer from the specified Load File instance.
387 @param LoadFileHandle The specified Load File instance.
388 @param FilePath The file path which will pass to LoadFile().
390 @return The full device path pointing to the load option buffer.
392 EFI_DEVICE_PATH_PROTOCOL
*
394 IN EFI_HANDLE LoadFileHandle
,
395 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
399 Return the RAM Disk device path created by LoadFile.
401 @param FilePath The source file path.
403 @return Callee-to-free RAM Disk device path
405 EFI_DEVICE_PATH_PROTOCOL
*
406 BmGetRamDiskDevicePath (
407 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
411 Destroy the RAM Disk.
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.
417 @param RamDiskDevicePath RAM Disk device path.
421 IN EFI_DEVICE_PATH_PROTOCOL
*RamDiskDevicePath
425 Get the next possible full path pointing to the load option.
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.
432 @return The next possible full path pointing to the load option.
433 Caller is responsible to free the memory.
435 EFI_DEVICE_PATH_PROTOCOL
*
436 BmGetNextLoadOptionDevicePath (
437 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
438 IN EFI_DEVICE_PATH_PROTOCOL
*FullPath
442 Return the next matched load option buffer.
443 The routine keeps calling BmGetNextLoadOptionDevicePath() until a valid
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.
459 @return The load option buffer. Caller is responsible to free the memory.
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
,
468 #endif // _INTERNAL_BM_H_