2 BDS library definition, include the file and data structure
4 Copyright (c) 2004 - 2016, 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
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.
16 #ifndef _INTERNAL_BM_H_
17 #define _INTERNAL_BM_H_
21 #include <IndustryStandard/Pci.h>
22 #include <IndustryStandard/PeImage.h>
23 #include <IndustryStandard/Atapi.h>
24 #include <IndustryStandard/Scsi.h>
26 #include <Protocol/PciRootBridgeIo.h>
27 #include <Protocol/BlockIo.h>
28 #include <Protocol/LoadedImage.h>
29 #include <Protocol/SimpleFileSystem.h>
30 #include <Protocol/LoadFile.h>
31 #include <Protocol/DevicePath.h>
32 #include <Protocol/SimpleTextIn.h>
33 #include <Protocol/SimpleTextInEx.h>
34 #include <Protocol/SimpleTextOut.h>
35 #include <Protocol/SimpleNetwork.h>
36 #include <Protocol/FirmwareVolume2.h>
37 #include <Protocol/PciIo.h>
38 #include <Protocol/GraphicsOutput.h>
39 #include <Protocol/UsbIo.h>
40 #include <Protocol/DiskInfo.h>
41 #include <Protocol/IdeControllerInit.h>
42 #include <Protocol/BootLogo.h>
43 #include <Protocol/DriverHealth.h>
44 #include <Protocol/FormBrowser2.h>
45 #include <Protocol/VariableLock.h>
46 #include <Protocol/RamDisk.h>
48 #include <Guid/ZeroGuid.h>
49 #include <Guid/MemoryTypeInformation.h>
50 #include <Guid/FileInfo.h>
51 #include <Guid/GlobalVariable.h>
52 #include <Guid/Performance.h>
53 #include <Guid/StatusCodeDataTypeVariable.h>
55 #include <Library/PrintLib.h>
56 #include <Library/DebugLib.h>
57 #include <Library/BaseMemoryLib.h>
58 #include <Library/UefiBootServicesTableLib.h>
59 #include <Library/UefiRuntimeServicesTableLib.h>
60 #include <Library/UefiLib.h>
61 #include <Library/MemoryAllocationLib.h>
62 #include <Library/DxeServicesTableLib.h>
63 #include <Library/HobLib.h>
64 #include <Library/BaseLib.h>
65 #include <Library/DevicePathLib.h>
66 #include <Library/PerformanceLib.h>
67 #include <Library/PcdLib.h>
68 #include <Library/PeCoffGetEntryPointLib.h>
69 #include <Library/UefiBootManagerLib.h>
70 #include <Library/TimerLib.h>
71 #include <Library/DxeServicesLib.h>
72 #include <Library/ReportStatusCodeLib.h>
73 #include <Library/CapsuleLib.h>
74 #include <Library/PerformanceLib.h>
75 #include <Library/HiiLib.h>
77 #if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)
78 #if defined (MDE_CPU_EBC)
80 // Uefi specification only defines the default boot file name for IA32, X64
81 // and IPF processor, so need define boot file name for EBC architecture here.
83 #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"
85 #error "Can not determine the default boot file name for unknown processor type!"
101 (* BM_GET_BOOT_DESCRIPTION
) (
106 // PlatformRecovery#### is the load option with the longest name
108 #define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####")
109 extern CHAR16
*mBmLoadOptionName
[];
112 Visitor function to be called by BmForEachVariable for each variable
115 @param Name Variable name.
116 @param Guid Variable GUID.
117 @param Context The same context passed to BmForEachVariable.
121 (*BM_VARIABLE_VISITOR
) (
128 Call Visitor function for each variable in variable storage.
130 @param Visitor Visitor function.
131 @param Context The context passed to Visitor function.
135 BM_VARIABLE_VISITOR Visitor
,
139 #define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')
143 EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler
;
144 } BM_BOOT_DESCRIPTION_ENTRY
;
147 Repair all the controllers according to the Driver Health status queried.
150 BmRepairAllControllers (
154 #define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')
163 EFI_KEY_DATA KeyData
[3];
166 #define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)
169 Get the Option Number that wasn't used.
171 @param LoadOptionType Load option type.
172 @param FreeOptionNumber To receive the minimal free option number.
174 @retval EFI_SUCCESS The option number is found
175 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.
176 @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL
180 BmGetFreeOptionNumber (
181 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
,
182 OUT UINT16
*FreeOptionNumber
187 Writes performance data of booting into the allocated memory.
188 OS can process these records.
190 @param Event The triggered event.
191 @param Context Context for this event.
196 BmWriteBootToOsPerformanceData (
202 This routine adjust the memory information for different memory type and
203 save them into the variables for next boot. It resets the system when
204 memory information is updated and the current boot option belongs to
205 boot category instead of application category.
207 @param Boot TRUE if current boot option belongs to boot category instead of
208 application category.
211 BmSetMemoryTypeInformationVariable (
216 Check whether there is a instance in BlockIoDevicePath, which contain multi device path
217 instances, has the same partition node with HardDriveDevicePath device path
219 @param BlockIoDevicePath Multi device path instances which need to check
220 @param HardDriveDevicePath A device path which starts with a hard drive media
223 @retval TRUE There is a matched device path instance.
224 @retval FALSE There is no matched device path instance.
228 BmMatchPartitionDevicePathNode (
229 IN EFI_DEVICE_PATH_PROTOCOL
*BlockIoDevicePath
,
230 IN HARDDRIVE_DEVICE_PATH
*HardDriveDevicePath
234 Connect the specific Usb device which match the short form device path.
236 @param DevicePath A short-form device path that starts with the first
237 element being a USB WWID or a USB Class device
240 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
241 DevicePath is not a USB device path.
243 @return EFI_SUCCESS Success to connect USB device
244 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
248 BmConnectUsbShortFormDevicePath (
249 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
253 Stop the hotkey processing.
255 @param Event Event pointer related to hotkey service.
256 @param Context Context pass to this function.
260 BmStopHotkeyService (
266 Set the variable and report the error through status code upon failure.
268 @param VariableName A Null-terminated string that is the name of the vendor's variable.
269 Each VariableName is unique for each VendorGuid. VariableName must
270 contain 1 or more characters. If VariableName is an empty string,
271 then EFI_INVALID_PARAMETER is returned.
272 @param VendorGuid A unique identifier for the vendor.
273 @param Attributes Attributes bitmask to set for the variable.
274 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
275 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
276 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
277 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
278 set, then a SetVariable() call with a DataSize of zero will not cause any change to
279 the variable value (the timestamp associated with the variable may be updated however
280 even if no new data value is provided,see the description of the
281 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
282 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
283 @param Data The contents for the variable.
285 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
286 defined by the Attributes.
287 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
288 DataSize exceeds the maximum allowed.
289 @retval EFI_INVALID_PARAMETER VariableName is an empty string.
290 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
291 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
292 @retval EFI_WRITE_PROTECTED The variable in question is read-only.
293 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
294 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
295 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
296 does NOT pass the validation check carried out by the firmware.
298 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
301 BmSetVariableAndReportStatusCodeOnError (
302 IN CHAR16
*VariableName
,
303 IN EFI_GUID
*VendorGuid
,
304 IN UINT32 Attributes
,
310 Get the load option by its device path.
312 @param FilePath The device path pointing to a load option.
313 It could be a short-form device path.
314 @param FullPath Return the full device path of the load option after
315 short-form device path expanding.
316 Caller is responsible to free it.
317 @param FileSize Return the load option size.
319 @return The load option buffer. Caller is responsible to free the memory.
322 BmGetLoadOptionBuffer (
323 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
324 OUT EFI_DEVICE_PATH_PROTOCOL
**FullPath
,
329 Return whether the PE header of the load option is valid or not.
331 @param[in] Type The load option type.
332 @param[in] FileBuffer The PE file buffer of the load option.
333 @param[in] FileSize The size of the load option file.
335 @retval TRUE The PE header of the load option is valid.
336 @retval FALSE The PE header of the load option is not valid.
339 BmIsLoadOptionPeHeaderValid (
340 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type
,
346 Function compares a device path data structure to that of all the nodes of a
347 second device path instance.
349 @param Multi A pointer to a multi-instance device path data
351 @param Single A pointer to a single-instance device path data
354 @retval TRUE If the Single device path is contained within Multi device path.
355 @retval FALSE The Single device path is not match within Multi device path.
360 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
361 IN EFI_DEVICE_PATH_PROTOCOL
*Single
365 Delete the instance in Multi which matches partly with Single instance
367 @param Multi A pointer to a multi-instance device path data
369 @param Single A pointer to a single-instance device path data
372 @return This function will remove the device path instances in Multi which partly
373 match with the Single, and return the result device path. If there is no
374 remaining device path as a result, this function will return NULL.
377 EFI_DEVICE_PATH_PROTOCOL
*
378 BmDelPartMatchInstance (
379 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
380 IN EFI_DEVICE_PATH_PROTOCOL
*Single
384 Repair all the controllers according to the Driver Health status queried.
387 BmRepairAllControllers (
392 Print the device path info.
394 @param DevicePath The device path need to print.
398 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
402 Convert a single character to number.
403 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
405 @param Char The input char which need to convert to int.
407 @return The converted 8-bit number or (UINTN) -1 if conversion failed.
415 Return the boot description for the controller.
417 @param Handle Controller handle.
419 @return The description string.
422 BmGetBootDescription (
427 Enumerate all boot option descriptions and append " 2"/" 3"/... to make
430 @param BootOptions Array of boot options.
431 @param BootOptionCount Count of boot options.
434 BmMakeBootOptionDescriptionUnique (
435 EFI_BOOT_MANAGER_LOAD_OPTION
*BootOptions
,
436 UINTN BootOptionCount
440 Get the file buffer from the specified Load File instance.
442 @param LoadFileHandle The specified Load File instance.
443 @param FilePath The file path which will pass to LoadFile().
444 @param FullPath Return the full device path pointing to the load option.
445 @param FileSize Return the size of the load option.
447 @return The load option buffer or NULL if fails.
450 BmGetFileBufferFromLoadFile (
451 EFI_HANDLE LoadFileHandle
,
452 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
453 OUT EFI_DEVICE_PATH_PROTOCOL
**FullPath
,
456 #endif // _INTERNAL_BM_H_