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