]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h
MdeModulePkg: Make the BmFindLoadOption function public
[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 - 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
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
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
46 #include <Guid/ZeroGuid.h>
47 #include <Guid/MemoryTypeInformation.h>
48 #include <Guid/FileInfo.h>
49 #include <Guid/GlobalVariable.h>
50 #include <Guid/Performance.h>
51 #include <Guid/StatusCodeDataTypeVariable.h>
52
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/TimerLib.h>
69 #include <Library/DxeServicesLib.h>
70 #include <Library/ReportStatusCodeLib.h>
71 #include <Library/CapsuleLib.h>
72 #include <Library/PerformanceLib.h>
73 #include <Library/HiiLib.h>
74
75 #if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)
76 #if defined (MDE_CPU_EBC)
77 //
78 // Uefi specification only defines the default boot file name for IA32, X64
79 // and IPF processor, so need define boot file name for EBC architecture here.
80 //
81 #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"
82 #else
83 #error "Can not determine the default boot file name for unknown processor type!"
84 #endif
85 #endif
86
87 typedef enum {
88 BmAcpiFloppyBoot,
89 BmHardwareDeviceBoot,
90 BmMessageAtapiBoot,
91 BmMessageSataBoot,
92 BmMessageUsbBoot,
93 BmMessageScsiBoot,
94 BmMessageNetworkBoot,
95 BmMessageHttpBoot,
96 BmMiscBoot
97 } BM_BOOT_TYPE;
98
99 typedef
100 CHAR16 *
101 (* BM_GET_BOOT_DESCRIPTION) (
102 IN EFI_HANDLE Handle
103 );
104
105 #define BM_OPTION_NAME_LEN sizeof ("SysPrep####")
106 extern CHAR16 *mBmLoadOptionName[];
107
108 typedef
109 VOID
110 (*VARIABLE_VISITOR) (
111 CHAR16 *Name,
112 EFI_GUID *Guid,
113 VOID *Context
114 );
115
116 /**
117 Call Visitor function for each variable in variable storage.
118
119 @param Visitor Visitor function.
120 @param Context The context passed to Visitor function.
121 **/
122 VOID
123 ForEachVariable (
124 VARIABLE_VISITOR Visitor,
125 VOID *Context
126 );
127
128 #define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')
129 typedef struct {
130 UINT32 Signature;
131 LIST_ENTRY Link;
132 EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler;
133 } BM_BOOT_DESCRIPTION_ENTRY;
134
135 /**
136 Repair all the controllers according to the Driver Health status queried.
137 **/
138 VOID
139 BmRepairAllControllers (
140 VOID
141 );
142
143 #define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')
144 typedef struct {
145 UINT32 Signature;
146 LIST_ENTRY Link;
147
148 BOOLEAN IsContinue;
149 UINT16 BootOption;
150 UINT8 CodeCount;
151 UINT8 WaitingKey;
152 EFI_KEY_DATA KeyData[3];
153 } BM_HOTKEY;
154
155 #define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)
156
157 /**
158 Get the image file buffer data and buffer size by its device path.
159
160 @param FilePath On input, a pointer to an allocated buffer containing the device
161 path of the file.
162 On output the pointer could be NULL when the function fails to
163 load the boot option, or could point to an allocated buffer containing
164 the device path of the file.
165 It could be updated by either short-form device path expanding,
166 or default boot file path appending.
167 Caller is responsible to free it when it's non-NULL.
168 @param FileSize A pointer to the size of the file buffer.
169
170 @retval NULL File is NULL, or FileSize is NULL. Or, the file can't be found.
171 @retval other The file buffer. The caller is responsible to free the memory.
172 **/
173 VOID *
174 BmLoadEfiBootOption (
175 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
176 OUT UINTN *FileSize
177 );
178
179 /**
180 Get the Option Number that wasn't used.
181
182 @param LoadOptionType Load option type.
183 @param FreeOptionNumber To receive the minimal free option number.
184
185 @retval EFI_SUCCESS The option number is found
186 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.
187 @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL
188
189 **/
190 EFI_STATUS
191 BmGetFreeOptionNumber (
192 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,
193 OUT UINT16 *FreeOptionNumber
194 );
195
196 /**
197
198 Writes performance data of booting into the allocated memory.
199 OS can process these records.
200
201 @param Event The triggered event.
202 @param Context Context for this event.
203
204 **/
205 VOID
206 EFIAPI
207 BmWriteBootToOsPerformanceData (
208 IN EFI_EVENT Event,
209 IN VOID *Context
210 );
211
212
213 /**
214 Get the headers (dos, image, optional header) from an image
215
216 @param Device SimpleFileSystem device handle
217 @param FileName File name for the image
218 @param DosHeader Pointer to dos header
219 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
220
221 @retval EFI_SUCCESS Successfully get the machine type.
222 @retval EFI_NOT_FOUND The file is not found.
223 @retval EFI_LOAD_ERROR File is not a valid image file.
224
225 **/
226 EFI_STATUS
227 BmGetImageHeader (
228 IN EFI_HANDLE Device,
229 IN CHAR16 *FileName,
230 OUT EFI_IMAGE_DOS_HEADER *DosHeader,
231 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
232 );
233
234 /**
235 This routine adjust the memory information for different memory type and
236 save them into the variables for next boot.
237 **/
238 VOID
239 BmSetMemoryTypeInformationVariable (
240 VOID
241 );
242
243 /**
244 Check whether there is a instance in BlockIoDevicePath, which contain multi device path
245 instances, has the same partition node with HardDriveDevicePath device path
246
247 @param BlockIoDevicePath Multi device path instances which need to check
248 @param HardDriveDevicePath A device path which starts with a hard drive media
249 device path.
250
251 @retval TRUE There is a matched device path instance.
252 @retval FALSE There is no matched device path instance.
253
254 **/
255 BOOLEAN
256 BmMatchPartitionDevicePathNode (
257 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,
258 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath
259 );
260
261 /**
262 Connect the specific Usb device which match the short form device path.
263
264 @param DevicePath A short-form device path that starts with the first
265 element being a USB WWID or a USB Class device
266 path
267
268 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
269 DevicePath is not a USB device path.
270
271 @return EFI_SUCCESS Success to connect USB device
272 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
273
274 **/
275 EFI_STATUS
276 BmConnectUsbShortFormDevicePath (
277 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
278 );
279
280 /**
281 Stop the hotkey processing.
282
283 @param Event Event pointer related to hotkey service.
284 @param Context Context pass to this function.
285 **/
286 VOID
287 EFIAPI
288 BmStopHotkeyService (
289 IN EFI_EVENT Event,
290 IN VOID *Context
291 );
292
293 /**
294 Set the variable and report the error through status code upon failure.
295
296 @param VariableName A Null-terminated string that is the name of the vendor's variable.
297 Each VariableName is unique for each VendorGuid. VariableName must
298 contain 1 or more characters. If VariableName is an empty string,
299 then EFI_INVALID_PARAMETER is returned.
300 @param VendorGuid A unique identifier for the vendor.
301 @param Attributes Attributes bitmask to set for the variable.
302 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
303 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
304 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
305 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
306 set, then a SetVariable() call with a DataSize of zero will not cause any change to
307 the variable value (the timestamp associated with the variable may be updated however
308 even if no new data value is provided,see the description of the
309 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
310 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
311 @param Data The contents for the variable.
312
313 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
314 defined by the Attributes.
315 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
316 DataSize exceeds the maximum allowed.
317 @retval EFI_INVALID_PARAMETER VariableName is an empty string.
318 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
319 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
320 @retval EFI_WRITE_PROTECTED The variable in question is read-only.
321 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
322 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
323 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
324 does NOT pass the validation check carried out by the firmware.
325
326 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
327 **/
328 EFI_STATUS
329 BmSetVariableAndReportStatusCodeOnError (
330 IN CHAR16 *VariableName,
331 IN EFI_GUID *VendorGuid,
332 IN UINT32 Attributes,
333 IN UINTN DataSize,
334 IN VOID *Data
335 );
336
337 /**
338 Get the load option by its device path.
339
340 @param FilePath The device path pointing to a load option.
341 It could be a short-form device path.
342 @param FullPath Return the full device path of the load option after
343 short-form device path expanding.
344 Caller is responsible to free it.
345 @param FileSize Return the load option size.
346
347 @return The load option buffer. Caller is responsible to free the memory.
348 **/
349 VOID *
350 BmGetLoadOptionBuffer (
351 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
352 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,
353 OUT UINTN *FileSize
354 );
355
356 /**
357 Return whether the PE header of the load option is valid or not.
358
359 @param[in] Type The load option type.
360 @param[in] FileBuffer The PE file buffer of the load option.
361 @param[in] FileSize The size of the load option file.
362
363 @retval TRUE The PE header of the load option is valid.
364 @retval FALSE The PE header of the load option is not valid.
365 **/
366 BOOLEAN
367 BmIsLoadOptionPeHeaderValid (
368 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,
369 IN VOID *FileBuffer,
370 IN UINTN FileSize
371 );
372
373 /**
374 Function compares a device path data structure to that of all the nodes of a
375 second device path instance.
376
377 @param Multi A pointer to a multi-instance device path data
378 structure.
379 @param Single A pointer to a single-instance device path data
380 structure.
381
382 @retval TRUE If the Single device path is contained within Multi device path.
383 @retval FALSE The Single device path is not match within Multi device path.
384
385 **/
386 BOOLEAN
387 BmMatchDevicePaths (
388 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
389 IN EFI_DEVICE_PATH_PROTOCOL *Single
390 );
391
392 /**
393 Delete the instance in Multi which matches partly with Single instance
394
395 @param Multi A pointer to a multi-instance device path data
396 structure.
397 @param Single A pointer to a single-instance device path data
398 structure.
399
400 @return This function will remove the device path instances in Multi which partly
401 match with the Single, and return the result device path. If there is no
402 remaining device path as a result, this function will return NULL.
403
404 **/
405 EFI_DEVICE_PATH_PROTOCOL *
406 BmDelPartMatchInstance (
407 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
408 IN EFI_DEVICE_PATH_PROTOCOL *Single
409 );
410
411 /**
412 Repair all the controllers according to the Driver Health status queried.
413 **/
414 VOID
415 BmRepairAllControllers (
416 VOID
417 );
418
419 /**
420 Print the device path info.
421
422 @param DevicePath The device path need to print.
423 **/
424 VOID
425 BmPrintDp (
426 EFI_DEVICE_PATH_PROTOCOL *DevicePath
427 );
428
429 #endif // _INTERNAL_BM_H_