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