2 BDS library definition, include the file and data structure
4 Copyright (c) 2004 - 2015, 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>
47 #include <Guid/ZeroGuid.h>
48 #include <Guid/MemoryTypeInformation.h>
49 #include <Guid/FileInfo.h>
50 #include <Guid/GlobalVariable.h>
51 #include <Guid/Performance.h>
52 #include <Guid/StatusCodeDataTypeVariable.h>
54 #include <Library/PrintLib.h>
55 #include <Library/DebugLib.h>
56 #include <Library/BaseMemoryLib.h>
57 #include <Library/UefiBootServicesTableLib.h>
58 #include <Library/UefiRuntimeServicesTableLib.h>
59 #include <Library/UefiLib.h>
60 #include <Library/MemoryAllocationLib.h>
61 #include <Library/DxeServicesTableLib.h>
62 #include <Library/HobLib.h>
63 #include <Library/BaseLib.h>
64 #include <Library/DevicePathLib.h>
65 #include <Library/PerformanceLib.h>
66 #include <Library/PcdLib.h>
67 #include <Library/PeCoffGetEntryPointLib.h>
68 #include <Library/UefiBootManagerLib.h>
69 #include <Library/TimerLib.h>
70 #include <Library/DxeServicesLib.h>
71 #include <Library/ReportStatusCodeLib.h>
72 #include <Library/CapsuleLib.h>
73 #include <Library/PerformanceLib.h>
74 #include <Library/HiiLib.h>
76 #if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)
77 #if defined (MDE_CPU_EBC)
79 // Uefi specification only defines the default boot file name for IA32, X64
80 // and IPF processor, so need define boot file name for EBC architecture here.
82 #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"
84 #error "Can not determine the default boot file name for unknown processor type!"
102 (* BM_GET_BOOT_DESCRIPTION
) (
107 // PlatformRecovery#### is the load option with the longest name
109 #define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####")
110 extern CHAR16
*mBmLoadOptionName
[];
113 Visitor function to be called by BmForEachVariable for each variable
116 @param Name Variable name.
117 @param Guid Variable GUID.
118 @param Context The same context passed to BmForEachVariable.
122 (*BM_VARIABLE_VISITOR
) (
129 Call Visitor function for each variable in variable storage.
131 @param Visitor Visitor function.
132 @param Context The context passed to Visitor function.
136 BM_VARIABLE_VISITOR Visitor
,
140 #define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')
144 EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler
;
145 } BM_BOOT_DESCRIPTION_ENTRY
;
148 Repair all the controllers according to the Driver Health status queried.
151 BmRepairAllControllers (
155 #define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')
164 EFI_KEY_DATA KeyData
[3];
167 #define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)
170 Get the image file buffer data and buffer size by its device path.
172 @param FilePath On input, a pointer to an allocated buffer containing the device
174 On output the pointer could be NULL when the function fails to
175 load the boot option, or could point to an allocated buffer containing
176 the device path of the file.
177 It could be updated by either short-form device path expanding,
178 or default boot file path appending.
179 Caller is responsible to free it when it's non-NULL.
180 @param FileSize A pointer to the size of the file buffer.
182 @retval NULL File is NULL, or FileSize is NULL. Or, the file can't be found.
183 @retval other The file buffer. The caller is responsible to free the memory.
186 BmLoadEfiBootOption (
187 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
192 Get the Option Number that wasn't used.
194 @param LoadOptionType Load option type.
195 @param FreeOptionNumber To receive the minimal free option number.
197 @retval EFI_SUCCESS The option number is found
198 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.
199 @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL
203 BmGetFreeOptionNumber (
204 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
,
205 OUT UINT16
*FreeOptionNumber
210 Writes performance data of booting into the allocated memory.
211 OS can process these records.
213 @param Event The triggered event.
214 @param Context Context for this event.
219 BmWriteBootToOsPerformanceData (
226 Get the headers (dos, image, optional header) from an image
228 @param Device SimpleFileSystem device handle
229 @param FileName File name for the image
230 @param DosHeader Pointer to dos header
231 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
233 @retval EFI_SUCCESS Successfully get the machine type.
234 @retval EFI_NOT_FOUND The file is not found.
235 @retval EFI_LOAD_ERROR File is not a valid image file.
240 IN EFI_HANDLE Device
,
242 OUT EFI_IMAGE_DOS_HEADER
*DosHeader
,
243 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
247 This routine adjust the memory information for different memory type and
248 save them into the variables for next boot. It resets the system when
249 memory information is updated and the current boot option belongs to
250 boot category instead of application category.
252 @param Boot TRUE if current boot option belongs to boot category instead of
253 application category.
256 BmSetMemoryTypeInformationVariable (
261 Check whether there is a instance in BlockIoDevicePath, which contain multi device path
262 instances, has the same partition node with HardDriveDevicePath device path
264 @param BlockIoDevicePath Multi device path instances which need to check
265 @param HardDriveDevicePath A device path which starts with a hard drive media
268 @retval TRUE There is a matched device path instance.
269 @retval FALSE There is no matched device path instance.
273 BmMatchPartitionDevicePathNode (
274 IN EFI_DEVICE_PATH_PROTOCOL
*BlockIoDevicePath
,
275 IN HARDDRIVE_DEVICE_PATH
*HardDriveDevicePath
279 Connect the specific Usb device which match the short form device path.
281 @param DevicePath A short-form device path that starts with the first
282 element being a USB WWID or a USB Class device
285 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
286 DevicePath is not a USB device path.
288 @return EFI_SUCCESS Success to connect USB device
289 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
293 BmConnectUsbShortFormDevicePath (
294 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
298 Stop the hotkey processing.
300 @param Event Event pointer related to hotkey service.
301 @param Context Context pass to this function.
305 BmStopHotkeyService (
311 Set the variable and report the error through status code upon failure.
313 @param VariableName A Null-terminated string that is the name of the vendor's variable.
314 Each VariableName is unique for each VendorGuid. VariableName must
315 contain 1 or more characters. If VariableName is an empty string,
316 then EFI_INVALID_PARAMETER is returned.
317 @param VendorGuid A unique identifier for the vendor.
318 @param Attributes Attributes bitmask to set for the variable.
319 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
320 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
321 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
322 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
323 set, then a SetVariable() call with a DataSize of zero will not cause any change to
324 the variable value (the timestamp associated with the variable may be updated however
325 even if no new data value is provided,see the description of the
326 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
327 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
328 @param Data The contents for the variable.
330 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
331 defined by the Attributes.
332 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
333 DataSize exceeds the maximum allowed.
334 @retval EFI_INVALID_PARAMETER VariableName is an empty string.
335 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
336 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
337 @retval EFI_WRITE_PROTECTED The variable in question is read-only.
338 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
339 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
340 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
341 does NOT pass the validation check carried out by the firmware.
343 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
346 BmSetVariableAndReportStatusCodeOnError (
347 IN CHAR16
*VariableName
,
348 IN EFI_GUID
*VendorGuid
,
349 IN UINT32 Attributes
,
355 Get the load option by its device path.
357 @param FilePath The device path pointing to a load option.
358 It could be a short-form device path.
359 @param FullPath Return the full device path of the load option after
360 short-form device path expanding.
361 Caller is responsible to free it.
362 @param FileSize Return the load option size.
364 @return The load option buffer. Caller is responsible to free the memory.
367 BmGetLoadOptionBuffer (
368 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
369 OUT EFI_DEVICE_PATH_PROTOCOL
**FullPath
,
374 Return whether the PE header of the load option is valid or not.
376 @param[in] Type The load option type.
377 @param[in] FileBuffer The PE file buffer of the load option.
378 @param[in] FileSize The size of the load option file.
380 @retval TRUE The PE header of the load option is valid.
381 @retval FALSE The PE header of the load option is not valid.
384 BmIsLoadOptionPeHeaderValid (
385 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type
,
391 Function compares a device path data structure to that of all the nodes of a
392 second device path instance.
394 @param Multi A pointer to a multi-instance device path data
396 @param Single A pointer to a single-instance device path data
399 @retval TRUE If the Single device path is contained within Multi device path.
400 @retval FALSE The Single device path is not match within Multi device path.
405 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
406 IN EFI_DEVICE_PATH_PROTOCOL
*Single
410 Delete the instance in Multi which matches partly with Single instance
412 @param Multi A pointer to a multi-instance device path data
414 @param Single A pointer to a single-instance device path data
417 @return This function will remove the device path instances in Multi which partly
418 match with the Single, and return the result device path. If there is no
419 remaining device path as a result, this function will return NULL.
422 EFI_DEVICE_PATH_PROTOCOL
*
423 BmDelPartMatchInstance (
424 IN EFI_DEVICE_PATH_PROTOCOL
*Multi
,
425 IN EFI_DEVICE_PATH_PROTOCOL
*Single
429 Repair all the controllers according to the Driver Health status queried.
432 BmRepairAllControllers (
437 Print the device path info.
439 @param DevicePath The device path need to print.
443 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
447 Convert a single character to number.
448 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
450 @param Char The input char which need to convert to int.
452 @return The converted 8-bit number or (UINTN) -1 if conversion failed.
459 #endif // _INTERNAL_BM_H_