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