]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h
MdeModulePkg: Add Platform recovery support
[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
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
169/**\r
170 Get the image file buffer data and buffer size by its device path. \r
171\r
172 @param FilePath On input, a pointer to an allocated buffer containing the device\r
173 path of the file.\r
174 On output the pointer could be NULL when the function fails to\r
175 load the boot option, or could point to an allocated buffer containing\r
176 the device path of the file.\r
177 It could be updated by either short-form device path expanding,\r
178 or default boot file path appending.\r
179 Caller is responsible to free it when it's non-NULL.\r
180 @param FileSize A pointer to the size of the file buffer.\r
181\r
182 @retval NULL File is NULL, or FileSize is NULL. Or, the file can't be found.\r
183 @retval other The file buffer. The caller is responsible to free the memory.\r
184**/\r
185VOID *\r
186BmLoadEfiBootOption (\r
187 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
188 OUT UINTN *FileSize\r
189 );\r
190\r
191/**\r
192 Get the Option Number that wasn't used.\r
193\r
194 @param LoadOptionType Load option type.\r
195 @param FreeOptionNumber To receive the minimal free option number.\r
196\r
197 @retval EFI_SUCCESS The option number is found\r
198 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.\r
199 @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL\r
200\r
201**/\r
202EFI_STATUS\r
203BmGetFreeOptionNumber (\r
204 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,\r
205 OUT UINT16 *FreeOptionNumber\r
206 );\r
207\r
208/**\r
209\r
210 Writes performance data of booting into the allocated memory.\r
211 OS can process these records.\r
212\r
213 @param Event The triggered event.\r
214 @param Context Context for this event.\r
215\r
216**/\r
217VOID\r
218EFIAPI\r
219BmWriteBootToOsPerformanceData (\r
220 IN EFI_EVENT Event,\r
221 IN VOID *Context\r
222 );\r
223\r
224\r
225/**\r
226 Get the headers (dos, image, optional header) from an image\r
227\r
228 @param Device SimpleFileSystem device handle\r
229 @param FileName File name for the image\r
230 @param DosHeader Pointer to dos header\r
231 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.\r
232\r
233 @retval EFI_SUCCESS Successfully get the machine type.\r
234 @retval EFI_NOT_FOUND The file is not found.\r
235 @retval EFI_LOAD_ERROR File is not a valid image file.\r
236\r
237**/\r
238EFI_STATUS\r
239BmGetImageHeader (\r
240 IN EFI_HANDLE Device,\r
241 IN CHAR16 *FileName,\r
242 OUT EFI_IMAGE_DOS_HEADER *DosHeader,\r
243 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr\r
244 );\r
245\r
246/**\r
247 This routine adjust the memory information for different memory type and \r
248 save them into the variables for next boot.\r
249**/\r
250VOID\r
251BmSetMemoryTypeInformationVariable (\r
252 VOID\r
253 );\r
254\r
255/**\r
256 Check whether there is a instance in BlockIoDevicePath, which contain multi device path\r
257 instances, has the same partition node with HardDriveDevicePath device path\r
258\r
259 @param BlockIoDevicePath Multi device path instances which need to check\r
260 @param HardDriveDevicePath A device path which starts with a hard drive media\r
261 device path.\r
262\r
263 @retval TRUE There is a matched device path instance.\r
264 @retval FALSE There is no matched device path instance.\r
265\r
266**/\r
267BOOLEAN\r
268BmMatchPartitionDevicePathNode (\r
269 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,\r
270 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
271 );\r
272\r
273/**\r
274 Connect the specific Usb device which match the short form device path.\r
275\r
276 @param DevicePath A short-form device path that starts with the first\r
277 element being a USB WWID or a USB Class device\r
278 path\r
279\r
280 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.\r
281 DevicePath is not a USB device path.\r
282\r
283 @return EFI_SUCCESS Success to connect USB device\r
284 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.\r
285\r
286**/\r
287EFI_STATUS\r
288BmConnectUsbShortFormDevicePath (\r
289 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
290 );\r
291\r
292/**\r
293 Stop the hotkey processing.\r
294 \r
295 @param Event Event pointer related to hotkey service. \r
296 @param Context Context pass to this function. \r
297**/\r
298VOID\r
299EFIAPI\r
300BmStopHotkeyService (\r
301 IN EFI_EVENT Event,\r
302 IN VOID *Context\r
303 );\r
304\r
305/**\r
306 Set the variable and report the error through status code upon failure.\r
307\r
308 @param VariableName A Null-terminated string that is the name of the vendor's variable.\r
309 Each VariableName is unique for each VendorGuid. VariableName must\r
310 contain 1 or more characters. If VariableName is an empty string,\r
311 then EFI_INVALID_PARAMETER is returned.\r
312 @param VendorGuid A unique identifier for the vendor.\r
313 @param Attributes Attributes bitmask to set for the variable.\r
314 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
315 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
316 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
317 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
318 set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
319 the variable value (the timestamp associated with the variable may be updated however \r
320 even if no new data value is provided,see the description of the \r
321 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not \r
322 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). \r
323 @param Data The contents for the variable.\r
324\r
325 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r
326 defined by the Attributes.\r
327 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the\r
328 DataSize exceeds the maximum allowed.\r
329 @retval EFI_INVALID_PARAMETER VariableName is an empty string.\r
330 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
331 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r
332 @retval EFI_WRITE_PROTECTED The variable in question is read-only.\r
333 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r
334 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
335 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
336 does NOT pass the validation check carried out by the firmware.\r
337\r
338 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
339**/\r
340EFI_STATUS\r
341BmSetVariableAndReportStatusCodeOnError (\r
342 IN CHAR16 *VariableName,\r
343 IN EFI_GUID *VendorGuid,\r
344 IN UINT32 Attributes,\r
345 IN UINTN DataSize,\r
346 IN VOID *Data\r
347 );\r
348\r
349/**\r
350 Get the load option by its device path.\r
351\r
352 @param FilePath The device path pointing to a load option.\r
353 It could be a short-form device path.\r
354 @param FullPath Return the full device path of the load option after\r
355 short-form device path expanding.\r
356 Caller is responsible to free it.\r
357 @param FileSize Return the load option size.\r
358\r
359 @return The load option buffer. Caller is responsible to free the memory.\r
360**/\r
361VOID *\r
362BmGetLoadOptionBuffer (\r
363 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
364 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
365 OUT UINTN *FileSize\r
366 );\r
367\r
368/**\r
369 Return whether the PE header of the load option is valid or not.\r
370\r
371 @param[in] Type The load option type.\r
372 @param[in] FileBuffer The PE file buffer of the load option.\r
373 @param[in] FileSize The size of the load option file.\r
374\r
375 @retval TRUE The PE header of the load option is valid.\r
376 @retval FALSE The PE header of the load option is not valid.\r
377**/\r
378BOOLEAN\r
379BmIsLoadOptionPeHeaderValid (\r
380 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,\r
381 IN VOID *FileBuffer,\r
382 IN UINTN FileSize\r
383 );\r
384\r
385/**\r
386 Function compares a device path data structure to that of all the nodes of a\r
387 second device path instance.\r
388\r
389 @param Multi A pointer to a multi-instance device path data\r
390 structure.\r
391 @param Single A pointer to a single-instance device path data\r
392 structure.\r
393\r
394 @retval TRUE If the Single device path is contained within Multi device path.\r
395 @retval FALSE The Single device path is not match within Multi device path.\r
396\r
397**/\r
398BOOLEAN\r
399BmMatchDevicePaths (\r
400 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
401 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
402 );\r
403\r
404/**\r
405 Delete the instance in Multi which matches partly with Single instance\r
406\r
407 @param Multi A pointer to a multi-instance device path data\r
408 structure.\r
409 @param Single A pointer to a single-instance device path data\r
410 structure.\r
411\r
412 @return This function will remove the device path instances in Multi which partly\r
413 match with the Single, and return the result device path. If there is no\r
414 remaining device path as a result, this function will return NULL.\r
415\r
416**/\r
417EFI_DEVICE_PATH_PROTOCOL *\r
418BmDelPartMatchInstance (\r
419 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
420 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
421 );\r
422\r
067ed98a
RN
423/**\r
424 Repair all the controllers according to the Driver Health status queried.\r
425**/\r
426VOID\r
427BmRepairAllControllers (\r
428 VOID\r
429 );\r
430\r
431/**\r
432 Print the device path info.\r
433\r
434 @param DevicePath The device path need to print.\r
435**/\r
436VOID\r
437BmPrintDp (\r
438 EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
439 );\r
440\r
418e8cd9
RN
441/**\r
442 Convert a single character to number.\r
443 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'\r
444\r
445 @param Char The input char which need to convert to int.\r
446\r
447 @return The converted 8-bit number or (UINTN) -1 if conversion failed.\r
448**/\r
449UINTN\r
450BmCharToUint (\r
451 IN CHAR16 Char\r
452 );\r
453\r
067ed98a 454#endif // _INTERNAL_BM_H_\r