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