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