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