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