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