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