]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / InternalBm.h
... / ...
CommitLineData
1/** @file\r
2 BDS library definition, include the file and data structure\r
3\r
4Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.\r
5Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
6(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
7SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10\r
11#ifndef _INTERNAL_BM_H_\r
12#define _INTERNAL_BM_H_\r
13\r
14#include <PiDxe.h>\r
15\r
16#include <IndustryStandard/Pci.h>\r
17#include <IndustryStandard/PeImage.h>\r
18#include <IndustryStandard/Atapi.h>\r
19#include <IndustryStandard/Scsi.h>\r
20#include <IndustryStandard/Nvme.h>\r
21\r
22#include <Protocol/PciRootBridgeIo.h>\r
23#include <Protocol/BlockIo.h>\r
24#include <Protocol/LoadedImage.h>\r
25#include <Protocol/SimpleFileSystem.h>\r
26#include <Protocol/LoadFile.h>\r
27#include <Protocol/DevicePath.h>\r
28#include <Protocol/SimpleTextIn.h>\r
29#include <Protocol/SimpleTextInEx.h>\r
30#include <Protocol/SimpleTextOut.h>\r
31#include <Protocol/SimpleNetwork.h>\r
32#include <Protocol/FirmwareVolume2.h>\r
33#include <Protocol/PciIo.h>\r
34#include <Protocol/GraphicsOutput.h>\r
35#include <Protocol/UsbIo.h>\r
36#include <Protocol/DiskInfo.h>\r
37#include <Protocol/NvmExpressPassthru.h>\r
38#include <Protocol/IdeControllerInit.h>\r
39#include <Protocol/BootLogo.h>\r
40#include <Protocol/DriverHealth.h>\r
41#include <Protocol/FormBrowser2.h>\r
42#include <Protocol/RamDisk.h>\r
43#include <Protocol/DeferredImageLoad.h>\r
44#include <Protocol/PlatformBootManager.h>\r
45\r
46#include <Guid/MemoryTypeInformation.h>\r
47#include <Guid/FileInfo.h>\r
48#include <Guid/GlobalVariable.h>\r
49#include <Guid/StatusCodeDataTypeId.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/DxeServicesLib.h>\r
68#include <Library/ReportStatusCodeLib.h>\r
69#include <Library/CapsuleLib.h>\r
70#include <Library/PerformanceLib.h>\r
71#include <Library/HiiLib.h>\r
72\r
73#if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)\r
74 #if defined (MDE_CPU_EBC)\r
75//\r
76// Uefi specification only defines the default boot file name for IA32, X64\r
77// and IPF processor, so need define boot file name for EBC architecture here.\r
78//\r
79#define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"\r
80 #else\r
81 #error "Can not determine the default boot file name for unknown processor type!"\r
82 #endif\r
83#endif\r
84\r
85typedef enum {\r
86 BmAcpiFloppyBoot,\r
87 BmHardwareDeviceBoot,\r
88 BmMessageAtapiBoot,\r
89 BmMessageSataBoot,\r
90 BmMessageUsbBoot,\r
91 BmMessageScsiBoot,\r
92 BmMiscBoot\r
93} BM_BOOT_TYPE;\r
94\r
95typedef\r
96CHAR16 *\r
97(*BM_GET_BOOT_DESCRIPTION) (\r
98 IN EFI_HANDLE Handle\r
99 );\r
100\r
101//\r
102// PlatformRecovery#### is the load option with the longest name\r
103//\r
104#define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####")\r
105extern CHAR16 *mBmLoadOptionName[];\r
106\r
107//\r
108// Maximum number of reconnect retry to repair controller; it is to limit the\r
109// number of recursive call of BmRepairAllControllers.\r
110//\r
111#define MAX_RECONNECT_REPAIR 10\r
112\r
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
121typedef\r
122VOID\r
123(*BM_VARIABLE_VISITOR) (\r
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
136BmForEachVariable (\r
137 BM_VARIABLE_VISITOR Visitor,\r
138 VOID *Context\r
139 );\r
140\r
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
148/**\r
149 Repair all the controllers according to the Driver Health status queried.\r
150\r
151 @param ReconnectRepairCount To record the number of recursive call of\r
152 this function itself.\r
153**/\r
154VOID\r
155BmRepairAllControllers (\r
156 UINTN ReconnectRepairCount\r
157 );\r
158\r
159#define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')\r
160typedef struct {\r
161 UINT32 Signature;\r
162 LIST_ENTRY Link;\r
163\r
164 BOOLEAN IsContinue;\r
165 UINT16 BootOption;\r
166 UINT8 CodeCount;\r
167 UINT8 WaitingKey;\r
168 EFI_KEY_DATA KeyData[3];\r
169} BM_HOTKEY;\r
170\r
171#define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)\r
172\r
173/**\r
174 Get the Option Number that wasn't used.\r
175\r
176 @param LoadOptionType Load option type.\r
177 @param FreeOptionNumber To receive the minimal free option number.\r
178\r
179 @retval EFI_SUCCESS The option number is found\r
180 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.\r
181 @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL\r
182\r
183**/\r
184EFI_STATUS\r
185BmGetFreeOptionNumber (\r
186 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,\r
187 OUT UINT16 *FreeOptionNumber\r
188 );\r
189\r
190/**\r
191 This routine adjust the memory information for different memory type and\r
192 save them into the variables for next boot. It resets the system when\r
193 memory information is updated and the current boot option belongs to\r
194 boot category instead of application category. It doesn't count the\r
195 reserved memory occupied by RAM Disk.\r
196\r
197 @param Boot TRUE if current boot option belongs to boot\r
198 category instead of application category.\r
199**/\r
200VOID\r
201BmSetMemoryTypeInformationVariable (\r
202 IN BOOLEAN Boot\r
203 );\r
204\r
205/**\r
206 Check whether there is a instance in BlockIoDevicePath, which contain multi device path\r
207 instances, has the same partition node with HardDriveDevicePath device path\r
208\r
209 @param BlockIoDevicePath Multi device path instances which need to check\r
210 @param HardDriveDevicePath A device path which starts with a hard drive media\r
211 device path.\r
212\r
213 @retval TRUE There is a matched device path instance.\r
214 @retval FALSE There is no matched device path instance.\r
215\r
216**/\r
217BOOLEAN\r
218BmMatchPartitionDevicePathNode (\r
219 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,\r
220 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
221 );\r
222\r
223/**\r
224 Connect the specific Usb device which match the short form device path.\r
225\r
226 @param DevicePath A short-form device path that starts with the first\r
227 element being a USB WWID or a USB Class device\r
228 path\r
229\r
230 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.\r
231 DevicePath is not a USB device path.\r
232\r
233 @return EFI_SUCCESS Success to connect USB device\r
234 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.\r
235\r
236**/\r
237EFI_STATUS\r
238BmConnectUsbShortFormDevicePath (\r
239 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
240 );\r
241\r
242/**\r
243 Stop the hotkey processing.\r
244\r
245 @param Event Event pointer related to hotkey service.\r
246 @param Context Context pass to this function.\r
247**/\r
248VOID\r
249EFIAPI\r
250BmStopHotkeyService (\r
251 IN EFI_EVENT Event,\r
252 IN VOID *Context\r
253 );\r
254\r
255/**\r
256 Set the variable and report the error through status code upon failure.\r
257\r
258 @param VariableName A Null-terminated string that is the name of the vendor's variable.\r
259 Each VariableName is unique for each VendorGuid. VariableName must\r
260 contain 1 or more characters. If VariableName is an empty string,\r
261 then EFI_INVALID_PARAMETER is returned.\r
262 @param VendorGuid A unique identifier for the vendor.\r
263 @param Attributes Attributes bitmask to set for the variable.\r
264 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,\r
265 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero\r
266 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is\r
267 set, then a SetVariable() call with a DataSize of zero will not cause any change to\r
268 the variable value (the timestamp associated with the variable may be updated however\r
269 even if no new data value is provided,see the description of the\r
270 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not\r
271 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).\r
272 @param Data The contents for the variable.\r
273\r
274 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r
275 defined by the Attributes.\r
276 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the\r
277 DataSize exceeds the maximum allowed.\r
278 @retval EFI_INVALID_PARAMETER VariableName is an empty string.\r
279 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
280 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r
281 @retval EFI_WRITE_PROTECTED The variable in question is read-only.\r
282 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r
283 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS\r
284 being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.\r
285\r
286 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
287**/\r
288EFI_STATUS\r
289BmSetVariableAndReportStatusCodeOnError (\r
290 IN CHAR16 *VariableName,\r
291 IN EFI_GUID *VendorGuid,\r
292 IN UINT32 Attributes,\r
293 IN UINTN DataSize,\r
294 IN VOID *Data\r
295 );\r
296\r
297/**\r
298 Function compares a device path data structure to that of all the nodes of a\r
299 second device path instance.\r
300\r
301 @param Multi A pointer to a multi-instance device path data\r
302 structure.\r
303 @param Single A pointer to a single-instance device path data\r
304 structure.\r
305\r
306 @retval TRUE If the Single device path is contained within Multi device path.\r
307 @retval FALSE The Single device path is not match within Multi device path.\r
308\r
309**/\r
310BOOLEAN\r
311BmMatchDevicePaths (\r
312 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
313 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
314 );\r
315\r
316/**\r
317 Delete the instance in Multi which matches partly with Single instance\r
318\r
319 @param Multi A pointer to a multi-instance device path data\r
320 structure.\r
321 @param Single A pointer to a single-instance device path data\r
322 structure.\r
323\r
324 @return This function will remove the device path instances in Multi which partly\r
325 match with the Single, and return the result device path. If there is no\r
326 remaining device path as a result, this function will return NULL.\r
327\r
328**/\r
329EFI_DEVICE_PATH_PROTOCOL *\r
330BmDelPartMatchInstance (\r
331 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
332 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
333 );\r
334\r
335/**\r
336 Print the device path info.\r
337\r
338 @param DevicePath The device path need to print.\r
339**/\r
340VOID\r
341BmPrintDp (\r
342 EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
343 );\r
344\r
345/**\r
346 Convert a single character to number.\r
347 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'\r
348\r
349 @param Char The input char which need to convert to int.\r
350\r
351 @return The converted 8-bit number or (UINTN) -1 if conversion failed.\r
352**/\r
353UINTN\r
354BmCharToUint (\r
355 IN CHAR16 Char\r
356 );\r
357\r
358/**\r
359 Return the boot description for the controller.\r
360\r
361 @param Handle Controller handle.\r
362\r
363 @return The description string.\r
364**/\r
365CHAR16 *\r
366BmGetBootDescription (\r
367 IN EFI_HANDLE Handle\r
368 );\r
369\r
370/**\r
371 Enumerate all boot option descriptions and append " 2"/" 3"/... to make\r
372 unique description.\r
373\r
374 @param BootOptions Array of boot options.\r
375 @param BootOptionCount Count of boot options.\r
376**/\r
377VOID\r
378BmMakeBootOptionDescriptionUnique (\r
379 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,\r
380 UINTN BootOptionCount\r
381 );\r
382\r
383/**\r
384 Get the file buffer from the specified Load File instance.\r
385\r
386 @param LoadFileHandle The specified Load File instance.\r
387 @param FilePath The file path which will pass to LoadFile().\r
388\r
389 @return The full device path pointing to the load option buffer.\r
390**/\r
391EFI_DEVICE_PATH_PROTOCOL *\r
392BmExpandLoadFile (\r
393 IN EFI_HANDLE LoadFileHandle,\r
394 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
395 );\r
396\r
397/**\r
398 Return the RAM Disk device path created by LoadFile.\r
399\r
400 @param FilePath The source file path.\r
401\r
402 @return Callee-to-free RAM Disk device path\r
403**/\r
404EFI_DEVICE_PATH_PROTOCOL *\r
405BmGetRamDiskDevicePath (\r
406 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
407 );\r
408\r
409/**\r
410 Destroy the RAM Disk.\r
411\r
412 The destroy operation includes to call RamDisk.Unregister to\r
413 unregister the RAM DISK from RAM DISK driver, free the memory\r
414 allocated for the RAM Disk.\r
415\r
416 @param RamDiskDevicePath RAM Disk device path.\r
417**/\r
418VOID\r
419BmDestroyRamDisk (\r
420 IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath\r
421 );\r
422\r
423/**\r
424 Get the next possible full path pointing to the load option.\r
425\r
426 @param FilePath The device path pointing to a load option.\r
427 It could be a short-form device path.\r
428 @param FullPath The full path returned by the routine in last call.\r
429 Set to NULL in first call.\r
430\r
431 @return The next possible full path pointing to the load option.\r
432 Caller is responsible to free the memory.\r
433**/\r
434EFI_DEVICE_PATH_PROTOCOL *\r
435BmGetNextLoadOptionDevicePath (\r
436 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
437 IN EFI_DEVICE_PATH_PROTOCOL *FullPath\r
438 );\r
439\r
440/**\r
441 Return the next matched load option buffer.\r
442 The routine keeps calling BmGetNextLoadOptionDevicePath() until a valid\r
443 load option is read.\r
444\r
445 @param Type The load option type.\r
446 It's used to check whether the load option is valid.\r
447 When it's LoadOptionTypeMax, the routine only guarantees\r
448 the load option is a valid PE image but doesn't guarantee\r
449 the PE's subsystem type is valid.\r
450 @param FilePath The device path pointing to a load option.\r
451 It could be a short-form device path.\r
452 @param FullPath Return the next full device path of the load option after\r
453 short-form device path expanding.\r
454 Caller is responsible to free it.\r
455 NULL to return the first matched full device path.\r
456 @param FileSize Return the load option size.\r
457\r
458 @return The load option buffer. Caller is responsible to free the memory.\r
459**/\r
460VOID *\r
461BmGetNextLoadOptionBuffer (\r
462 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,\r
463 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
464 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
465 OUT UINTN *FileSize\r
466 );\r
467\r
468#endif // _INTERNAL_BM_H_\r