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