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