]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h
MdeModulePkg UsbBusPei: Fix wrong buffer length used to read hub desc
[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 // Maximum number of reconnect retry to repair controller; it is to limit the
113 // number of recursive call of BmRepairAllControllers.
114 //
115 #define MAX_RECONNECT_REPAIR 10
116
117 /**
118 Visitor function to be called by BmForEachVariable for each variable
119 in variable storage.
120
121 @param Name Variable name.
122 @param Guid Variable GUID.
123 @param Context The same context passed to BmForEachVariable.
124 **/
125 typedef
126 VOID
127 (*BM_VARIABLE_VISITOR) (
128 CHAR16 *Name,
129 EFI_GUID *Guid,
130 VOID *Context
131 );
132
133 /**
134 Call Visitor function for each variable in variable storage.
135
136 @param Visitor Visitor function.
137 @param Context The context passed to Visitor function.
138 **/
139 VOID
140 BmForEachVariable (
141 BM_VARIABLE_VISITOR Visitor,
142 VOID *Context
143 );
144
145 #define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')
146 typedef struct {
147 UINT32 Signature;
148 LIST_ENTRY Link;
149 EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler;
150 } BM_BOOT_DESCRIPTION_ENTRY;
151
152 /**
153 Repair all the controllers according to the Driver Health status queried.
154
155 @param ReconnectRepairCount To record the number of recursive call of
156 this function itself.
157 **/
158 VOID
159 BmRepairAllControllers (
160 UINTN ReconnectRepairCount
161 );
162
163 #define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')
164 typedef struct {
165 UINT32 Signature;
166 LIST_ENTRY Link;
167
168 BOOLEAN IsContinue;
169 UINT16 BootOption;
170 UINT8 CodeCount;
171 UINT8 WaitingKey;
172 EFI_KEY_DATA KeyData[3];
173 } BM_HOTKEY;
174
175 #define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)
176
177 /**
178 Get the Option Number that wasn't used.
179
180 @param LoadOptionType Load option type.
181 @param FreeOptionNumber To receive the minimal free option number.
182
183 @retval EFI_SUCCESS The option number is found
184 @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.
185 @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL
186
187 **/
188 EFI_STATUS
189 BmGetFreeOptionNumber (
190 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,
191 OUT UINT16 *FreeOptionNumber
192 );
193
194 /**
195 This routine adjust the memory information for different memory type and
196 save them into the variables for next boot. It resets the system when
197 memory information is updated and the current boot option belongs to
198 boot category instead of application category. It doesn't count the
199 reserved memory occupied by RAM Disk.
200
201 @param Boot TRUE if current boot option belongs to boot
202 category instead of application category.
203 **/
204 VOID
205 BmSetMemoryTypeInformationVariable (
206 IN BOOLEAN Boot
207 );
208
209 /**
210 Check whether there is a instance in BlockIoDevicePath, which contain multi device path
211 instances, has the same partition node with HardDriveDevicePath device path
212
213 @param BlockIoDevicePath Multi device path instances which need to check
214 @param HardDriveDevicePath A device path which starts with a hard drive media
215 device path.
216
217 @retval TRUE There is a matched device path instance.
218 @retval FALSE There is no matched device path instance.
219
220 **/
221 BOOLEAN
222 BmMatchPartitionDevicePathNode (
223 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,
224 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath
225 );
226
227 /**
228 Connect the specific Usb device which match the short form device path.
229
230 @param DevicePath A short-form device path that starts with the first
231 element being a USB WWID or a USB Class device
232 path
233
234 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
235 DevicePath is not a USB device path.
236
237 @return EFI_SUCCESS Success to connect USB device
238 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
239
240 **/
241 EFI_STATUS
242 BmConnectUsbShortFormDevicePath (
243 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
244 );
245
246 /**
247 Stop the hotkey processing.
248
249 @param Event Event pointer related to hotkey service.
250 @param Context Context pass to this function.
251 **/
252 VOID
253 EFIAPI
254 BmStopHotkeyService (
255 IN EFI_EVENT Event,
256 IN VOID *Context
257 );
258
259 /**
260 Set the variable and report the error through status code upon failure.
261
262 @param VariableName A Null-terminated string that is the name of the vendor's variable.
263 Each VariableName is unique for each VendorGuid. VariableName must
264 contain 1 or more characters. If VariableName is an empty string,
265 then EFI_INVALID_PARAMETER is returned.
266 @param VendorGuid A unique identifier for the vendor.
267 @param Attributes Attributes bitmask to set for the variable.
268 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
269 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
270 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
271 set, then a SetVariable() call with a DataSize of zero will not cause any change to
272 the variable value (the timestamp associated with the variable may be updated however
273 even if no new data value is provided,see the description of the
274 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
275 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
276 @param Data The contents for the variable.
277
278 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
279 defined by the Attributes.
280 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
281 DataSize exceeds the maximum allowed.
282 @retval EFI_INVALID_PARAMETER VariableName is an empty string.
283 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
284 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
285 @retval EFI_WRITE_PROTECTED The variable in question is read-only.
286 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
287 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS
288 being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.
289
290 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
291 **/
292 EFI_STATUS
293 BmSetVariableAndReportStatusCodeOnError (
294 IN CHAR16 *VariableName,
295 IN EFI_GUID *VendorGuid,
296 IN UINT32 Attributes,
297 IN UINTN DataSize,
298 IN VOID *Data
299 );
300
301 /**
302 Function compares a device path data structure to that of all the nodes of a
303 second device path instance.
304
305 @param Multi A pointer to a multi-instance device path data
306 structure.
307 @param Single A pointer to a single-instance device path data
308 structure.
309
310 @retval TRUE If the Single device path is contained within Multi device path.
311 @retval FALSE The Single device path is not match within Multi device path.
312
313 **/
314 BOOLEAN
315 BmMatchDevicePaths (
316 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
317 IN EFI_DEVICE_PATH_PROTOCOL *Single
318 );
319
320 /**
321 Delete the instance in Multi which matches partly with Single instance
322
323 @param Multi A pointer to a multi-instance device path data
324 structure.
325 @param Single A pointer to a single-instance device path data
326 structure.
327
328 @return This function will remove the device path instances in Multi which partly
329 match with the Single, and return the result device path. If there is no
330 remaining device path as a result, this function will return NULL.
331
332 **/
333 EFI_DEVICE_PATH_PROTOCOL *
334 BmDelPartMatchInstance (
335 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
336 IN EFI_DEVICE_PATH_PROTOCOL *Single
337 );
338
339 /**
340 Print the device path info.
341
342 @param DevicePath The device path need to print.
343 **/
344 VOID
345 BmPrintDp (
346 EFI_DEVICE_PATH_PROTOCOL *DevicePath
347 );
348
349 /**
350 Convert a single character to number.
351 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
352
353 @param Char The input char which need to convert to int.
354
355 @return The converted 8-bit number or (UINTN) -1 if conversion failed.
356 **/
357 UINTN
358 BmCharToUint (
359 IN CHAR16 Char
360 );
361
362 /**
363 Return the boot description for the controller.
364
365 @param Handle Controller handle.
366
367 @return The description string.
368 **/
369 CHAR16 *
370 BmGetBootDescription (
371 IN EFI_HANDLE Handle
372 );
373
374 /**
375 Enumerate all boot option descriptions and append " 2"/" 3"/... to make
376 unique description.
377
378 @param BootOptions Array of boot options.
379 @param BootOptionCount Count of boot options.
380 **/
381 VOID
382 BmMakeBootOptionDescriptionUnique (
383 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,
384 UINTN BootOptionCount
385 );
386
387 /**
388 Get the file buffer from the specified Load File instance.
389
390 @param LoadFileHandle The specified Load File instance.
391 @param FilePath The file path which will pass to LoadFile().
392
393 @return The full device path pointing to the load option buffer.
394 **/
395 EFI_DEVICE_PATH_PROTOCOL *
396 BmExpandLoadFile (
397 IN EFI_HANDLE LoadFileHandle,
398 IN EFI_DEVICE_PATH_PROTOCOL *FilePath
399 );
400
401 /**
402 Return the RAM Disk device path created by LoadFile.
403
404 @param FilePath The source file path.
405
406 @return Callee-to-free RAM Disk device path
407 **/
408 EFI_DEVICE_PATH_PROTOCOL *
409 BmGetRamDiskDevicePath (
410 IN EFI_DEVICE_PATH_PROTOCOL *FilePath
411 );
412
413 /**
414 Destroy the RAM Disk.
415
416 The destroy operation includes to call RamDisk.Unregister to
417 unregister the RAM DISK from RAM DISK driver, free the memory
418 allocated for the RAM Disk.
419
420 @param RamDiskDevicePath RAM Disk device path.
421 **/
422 VOID
423 BmDestroyRamDisk (
424 IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath
425 );
426
427 /**
428 Get the next possible full path pointing to the load option.
429
430 @param FilePath The device path pointing to a load option.
431 It could be a short-form device path.
432 @param FullPath The full path returned by the routine in last call.
433 Set to NULL in first call.
434
435 @return The next possible full path pointing to the load option.
436 Caller is responsible to free the memory.
437 **/
438 EFI_DEVICE_PATH_PROTOCOL *
439 BmGetNextLoadOptionDevicePath (
440 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
441 IN EFI_DEVICE_PATH_PROTOCOL *FullPath
442 );
443
444 /**
445 Return the next matched load option buffer.
446 The routine keeps calling BmGetNextLoadOptionDevicePath() until a valid
447 load option is read.
448
449 @param Type The load option type.
450 It's used to check whether the load option is valid.
451 When it's LoadOptionTypeMax, the routine only guarantees
452 the load option is a valid PE image but doesn't guarantee
453 the PE's subsystem type is valid.
454 @param FilePath The device path pointing to a load option.
455 It could be a short-form device path.
456 @param FullPath Return the next full device path of the load option after
457 short-form device path expanding.
458 Caller is responsible to free it.
459 NULL to return the first matched full device path.
460 @param FileSize Return the load option size.
461
462 @return The load option buffer. Caller is responsible to free the memory.
463 **/
464 VOID *
465 BmGetNextLoadOptionBuffer (
466 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,
467 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
468 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,
469 OUT UINTN *FileSize
470 );
471 #endif // _INTERNAL_BM_H_