VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h@ 99404

Last change on this file since 99404 was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 15.3 KB
Line 
1/** @file
2 BDS library definition, include the file and data structure
3
4Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
5Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
6(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
7SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#ifndef _INTERNAL_BM_H_
12#define _INTERNAL_BM_H_
13
14#include <PiDxe.h>
15
16#include <IndustryStandard/Pci.h>
17#include <IndustryStandard/PeImage.h>
18#include <IndustryStandard/Atapi.h>
19#include <IndustryStandard/Scsi.h>
20#include <IndustryStandard/Nvme.h>
21
22#include <Protocol/PciRootBridgeIo.h>
23#include <Protocol/BlockIo.h>
24#include <Protocol/LoadedImage.h>
25#include <Protocol/SimpleFileSystem.h>
26#include <Protocol/LoadFile.h>
27#include <Protocol/DevicePath.h>
28#include <Protocol/SimpleTextIn.h>
29#include <Protocol/SimpleTextInEx.h>
30#include <Protocol/SimpleTextOut.h>
31#include <Protocol/SimpleNetwork.h>
32#include <Protocol/FirmwareVolume2.h>
33#include <Protocol/PciIo.h>
34#include <Protocol/GraphicsOutput.h>
35#include <Protocol/UsbIo.h>
36#include <Protocol/DiskInfo.h>
37#include <Protocol/NvmExpressPassthru.h>
38#include <Protocol/IdeControllerInit.h>
39#include <Protocol/BootLogo.h>
40#include <Protocol/DriverHealth.h>
41#include <Protocol/FormBrowser2.h>
42#include <Protocol/RamDisk.h>
43#include <Protocol/DeferredImageLoad.h>
44#include <Protocol/PlatformBootManager.h>
45
46#include <Guid/MemoryTypeInformation.h>
47#include <Guid/FileInfo.h>
48#include <Guid/GlobalVariable.h>
49#include <Guid/StatusCodeDataTypeId.h>
50#include <Guid/StatusCodeDataTypeVariable.h>
51#ifdef VBOX
52#include <Guid/VBoxFsBlessedFileInfo.h>
53#endif
54
55#include <Library/PrintLib.h>
56#include <Library/DebugLib.h>
57#include <Library/BaseMemoryLib.h>
58#include <Library/UefiBootServicesTableLib.h>
59#include <Library/UefiRuntimeServicesTableLib.h>
60#include <Library/UefiLib.h>
61#include <Library/MemoryAllocationLib.h>
62#include <Library/DxeServicesTableLib.h>
63#include <Library/HobLib.h>
64#include <Library/BaseLib.h>
65#include <Library/DevicePathLib.h>
66#include <Library/PerformanceLib.h>
67#include <Library/PcdLib.h>
68#include <Library/PeCoffGetEntryPointLib.h>
69#include <Library/UefiBootManagerLib.h>
70#include <Library/DxeServicesLib.h>
71#include <Library/ReportStatusCodeLib.h>
72#include <Library/CapsuleLib.h>
73#include <Library/PerformanceLib.h>
74#include <Library/HiiLib.h>
75
76#if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)
77 #if defined (MDE_CPU_EBC)
78//
79// Uefi specification only defines the default boot file name for IA32, X64
80// and IPF processor, so need define boot file name for EBC architecture here.
81//
82#define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"
83 #else
84 #error "Can not determine the default boot file name for unknown processor type!"
85 #endif
86#endif
87
88typedef enum {
89 BmAcpiFloppyBoot,
90 BmHardwareDeviceBoot,
91 BmMessageAtapiBoot,
92 BmMessageSataBoot,
93 BmMessageUsbBoot,
94 BmMessageScsiBoot,
95 BmMiscBoot
96} BM_BOOT_TYPE;
97
98typedef
99CHAR16 *
100(*BM_GET_BOOT_DESCRIPTION) (
101 IN EFI_HANDLE Handle
102 );
103
104//
105// PlatformRecovery#### is the load option with the longest name
106//
107#define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####")
108extern CHAR16 *mBmLoadOptionName[];
109
110//
111// Maximum number of reconnect retry to repair controller; it is to limit the
112// number of recursive call of BmRepairAllControllers.
113//
114#define MAX_RECONNECT_REPAIR 10
115
116/**
117 Visitor function to be called by BmForEachVariable for each variable
118 in variable storage.
119
120 @param Name Variable name.
121 @param Guid Variable GUID.
122 @param Context The same context passed to BmForEachVariable.
123**/
124typedef
125VOID
126(*BM_VARIABLE_VISITOR) (
127 CHAR16 *Name,
128 EFI_GUID *Guid,
129 VOID *Context
130 );
131
132/**
133 Call Visitor function for each variable in variable storage.
134
135 @param Visitor Visitor function.
136 @param Context The context passed to Visitor function.
137**/
138VOID
139BmForEachVariable (
140 BM_VARIABLE_VISITOR Visitor,
141 VOID *Context
142 );
143
144#define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')
145typedef struct {
146 UINT32 Signature;
147 LIST_ENTRY Link;
148 EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler;
149} BM_BOOT_DESCRIPTION_ENTRY;
150
151/**
152 Repair all the controllers according to the Driver Health status queried.
153
154 @param ReconnectRepairCount To record the number of recursive call of
155 this function itself.
156**/
157VOID
158BmRepairAllControllers (
159 UINTN ReconnectRepairCount
160 );
161
162#define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')
163typedef struct {
164 UINT32 Signature;
165 LIST_ENTRY Link;
166
167 BOOLEAN IsContinue;
168 UINT16 BootOption;
169 UINT8 CodeCount;
170 UINT8 WaitingKey;
171 EFI_KEY_DATA KeyData[3];
172} BM_HOTKEY;
173
174#define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)
175
176/**
177 Get the Option Number that wasn't used.
178
179 @param LoadOptionType Load option type.
180 @param FreeOptionNumber To receive the minimal free option number.
181
182 @retval EFI_SUCCESS The option number is found
183 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.
184 @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL
185
186**/
187EFI_STATUS
188BmGetFreeOptionNumber (
189 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,
190 OUT UINT16 *FreeOptionNumber
191 );
192
193/**
194 This routine adjust the memory information for different memory type and
195 save them into the variables for next boot. It resets the system when
196 memory information is updated and the current boot option belongs to
197 boot category instead of application category. It doesn't count the
198 reserved memory occupied by RAM Disk.
199
200 @param Boot TRUE if current boot option belongs to boot
201 category instead of application category.
202**/
203VOID
204BmSetMemoryTypeInformationVariable (
205 IN BOOLEAN Boot
206 );
207
208/**
209 Check whether there is a instance in BlockIoDevicePath, which contain multi device path
210 instances, has the same partition node with HardDriveDevicePath device path
211
212 @param BlockIoDevicePath Multi device path instances which need to check
213 @param HardDriveDevicePath A device path which starts with a hard drive media
214 device path.
215
216 @retval TRUE There is a matched device path instance.
217 @retval FALSE There is no matched device path instance.
218
219**/
220BOOLEAN
221BmMatchPartitionDevicePathNode (
222 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,
223 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath
224 );
225
226/**
227 Connect the specific Usb device which match the short form device path.
228
229 @param DevicePath A short-form device path that starts with the first
230 element being a USB WWID or a USB Class device
231 path
232
233 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
234 DevicePath is not a USB device path.
235
236 @return EFI_SUCCESS Success to connect USB device
237 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
238
239**/
240EFI_STATUS
241BmConnectUsbShortFormDevicePath (
242 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
243 );
244
245/**
246 Stop the hotkey processing.
247
248 @param Event Event pointer related to hotkey service.
249 @param Context Context pass to this function.
250**/
251VOID
252EFIAPI
253BmStopHotkeyService (
254 IN EFI_EVENT Event,
255 IN VOID *Context
256 );
257
258/**
259 Set the variable and report the error through status code upon failure.
260
261 @param VariableName A Null-terminated string that is the name of the vendor's variable.
262 Each VariableName is unique for each VendorGuid. VariableName must
263 contain 1 or more characters. If VariableName is an empty string,
264 then EFI_INVALID_PARAMETER is returned.
265 @param VendorGuid A unique identifier for the vendor.
266 @param Attributes Attributes bitmask to set for the variable.
267 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
268 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
269 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
270 set, then a SetVariable() call with a DataSize of zero will not cause any change to
271 the variable value (the timestamp associated with the variable may be updated however
272 even if no new data value is provided,see the description of the
273 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
274 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
275 @param Data The contents for the variable.
276
277 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
278 defined by the Attributes.
279 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
280 DataSize exceeds the maximum allowed.
281 @retval EFI_INVALID_PARAMETER VariableName is an empty string.
282 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
283 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
284 @retval EFI_WRITE_PROTECTED The variable in question is read-only.
285 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
286 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS
287 being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.
288
289 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
290**/
291EFI_STATUS
292BmSetVariableAndReportStatusCodeOnError (
293 IN CHAR16 *VariableName,
294 IN EFI_GUID *VendorGuid,
295 IN UINT32 Attributes,
296 IN UINTN DataSize,
297 IN VOID *Data
298 );
299
300/**
301 Function compares a device path data structure to that of all the nodes of a
302 second device path instance.
303
304 @param Multi A pointer to a multi-instance device path data
305 structure.
306 @param Single A pointer to a single-instance device path data
307 structure.
308
309 @retval TRUE If the Single device path is contained within Multi device path.
310 @retval FALSE The Single device path is not match within Multi device path.
311
312**/
313BOOLEAN
314BmMatchDevicePaths (
315 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
316 IN EFI_DEVICE_PATH_PROTOCOL *Single
317 );
318
319/**
320 Delete the instance in Multi which matches partly with Single instance
321
322 @param Multi A pointer to a multi-instance device path data
323 structure.
324 @param Single A pointer to a single-instance device path data
325 structure.
326
327 @return This function will remove the device path instances in Multi which partly
328 match with the Single, and return the result device path. If there is no
329 remaining device path as a result, this function will return NULL.
330
331**/
332EFI_DEVICE_PATH_PROTOCOL *
333BmDelPartMatchInstance (
334 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
335 IN EFI_DEVICE_PATH_PROTOCOL *Single
336 );
337
338/**
339 Print the device path info.
340
341 @param DevicePath The device path need to print.
342**/
343VOID
344BmPrintDp (
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**/
356UINTN
357BmCharToUint (
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**/
368CHAR16 *
369BmGetBootDescription (
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**/
380VOID
381BmMakeBootOptionDescriptionUnique (
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**/
394EFI_DEVICE_PATH_PROTOCOL *
395BmExpandLoadFile (
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**/
407EFI_DEVICE_PATH_PROTOCOL *
408BmGetRamDiskDevicePath (
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**/
421VOID
422BmDestroyRamDisk (
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**/
437EFI_DEVICE_PATH_PROTOCOL *
438BmGetNextLoadOptionDevicePath (
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**/
463VOID *
464BmGetNextLoadOptionBuffer (
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
471#endif // _INTERNAL_BM_H_
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette