]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h
MdeModulePkg/UefiBootManagerLib: Expose *GetLoadOptionBuffer() API
[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 #include <Protocol/RamDisk.h>
47
48 #include <Guid/ZeroGuid.h>
49 #include <Guid/MemoryTypeInformation.h>
50 #include <Guid/FileInfo.h>
51 #include <Guid/GlobalVariable.h>
52 #include <Guid/Performance.h>
53 #include <Guid/StatusCodeDataTypeVariable.h>
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/TimerLib.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
187 Writes performance data of booting into the allocated memory.
188 OS can process these records.
189
190 @param Event The triggered event.
191 @param Context Context for this event.
192
193 **/
194 VOID
195 EFIAPI
196 BmWriteBootToOsPerformanceData (
197 IN EFI_EVENT Event,
198 IN VOID *Context
199 );
200
201 /**
202 This routine adjust the memory information for different memory type and
203 save them into the variables for next boot. It resets the system when
204 memory information is updated and the current boot option belongs to
205 boot category instead of application category. It doesn't count the
206 reserved memory occupied by RAM Disk.
207
208 @param Boot TRUE if current boot option belongs to boot
209 category instead of application category.
210 @param RamDiskSizeInPages Reserved memory size in pages occupied by
211 RAM Disk.
212 **/
213 VOID
214 BmSetMemoryTypeInformationVariable (
215 IN BOOLEAN Boot,
216 IN UINTN RamDiskSizeInPages
217 );
218
219 /**
220 Check whether there is a instance in BlockIoDevicePath, which contain multi device path
221 instances, has the same partition node with HardDriveDevicePath device path
222
223 @param BlockIoDevicePath Multi device path instances which need to check
224 @param HardDriveDevicePath A device path which starts with a hard drive media
225 device path.
226
227 @retval TRUE There is a matched device path instance.
228 @retval FALSE There is no matched device path instance.
229
230 **/
231 BOOLEAN
232 BmMatchPartitionDevicePathNode (
233 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,
234 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath
235 );
236
237 /**
238 Connect the specific Usb device which match the short form device path.
239
240 @param DevicePath A short-form device path that starts with the first
241 element being a USB WWID or a USB Class device
242 path
243
244 @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
245 DevicePath is not a USB device path.
246
247 @return EFI_SUCCESS Success to connect USB device
248 @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
249
250 **/
251 EFI_STATUS
252 BmConnectUsbShortFormDevicePath (
253 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
254 );
255
256 /**
257 Stop the hotkey processing.
258
259 @param Event Event pointer related to hotkey service.
260 @param Context Context pass to this function.
261 **/
262 VOID
263 EFIAPI
264 BmStopHotkeyService (
265 IN EFI_EVENT Event,
266 IN VOID *Context
267 );
268
269 /**
270 Set the variable and report the error through status code upon failure.
271
272 @param VariableName A Null-terminated string that is the name of the vendor's variable.
273 Each VariableName is unique for each VendorGuid. VariableName must
274 contain 1 or more characters. If VariableName is an empty string,
275 then EFI_INVALID_PARAMETER is returned.
276 @param VendorGuid A unique identifier for the vendor.
277 @param Attributes Attributes bitmask to set for the variable.
278 @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
279 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
280 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
281 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
282 set, then a SetVariable() call with a DataSize of zero will not cause any change to
283 the variable value (the timestamp associated with the variable may be updated however
284 even if no new data value is provided,see the description of the
285 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
286 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
287 @param Data The contents for the variable.
288
289 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
290 defined by the Attributes.
291 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
292 DataSize exceeds the maximum allowed.
293 @retval EFI_INVALID_PARAMETER VariableName is an empty string.
294 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
295 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
296 @retval EFI_WRITE_PROTECTED The variable in question is read-only.
297 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
298 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
299 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
300 does NOT pass the validation check carried out by the firmware.
301
302 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
303 **/
304 EFI_STATUS
305 BmSetVariableAndReportStatusCodeOnError (
306 IN CHAR16 *VariableName,
307 IN EFI_GUID *VendorGuid,
308 IN UINT32 Attributes,
309 IN UINTN DataSize,
310 IN VOID *Data
311 );
312
313 /**
314 Return whether the PE header of the load option is valid or not.
315
316 @param[in] Type The load option type.
317 @param[in] FileBuffer The PE file buffer of the load option.
318 @param[in] FileSize The size of the load option file.
319
320 @retval TRUE The PE header of the load option is valid.
321 @retval FALSE The PE header of the load option is not valid.
322 **/
323 BOOLEAN
324 BmIsLoadOptionPeHeaderValid (
325 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,
326 IN VOID *FileBuffer,
327 IN UINTN FileSize
328 );
329
330 /**
331 Function compares a device path data structure to that of all the nodes of a
332 second device path instance.
333
334 @param Multi A pointer to a multi-instance device path data
335 structure.
336 @param Single A pointer to a single-instance device path data
337 structure.
338
339 @retval TRUE If the Single device path is contained within Multi device path.
340 @retval FALSE The Single device path is not match within Multi device path.
341
342 **/
343 BOOLEAN
344 BmMatchDevicePaths (
345 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
346 IN EFI_DEVICE_PATH_PROTOCOL *Single
347 );
348
349 /**
350 Delete the instance in Multi which matches partly with Single instance
351
352 @param Multi A pointer to a multi-instance device path data
353 structure.
354 @param Single A pointer to a single-instance device path data
355 structure.
356
357 @return This function will remove the device path instances in Multi which partly
358 match with the Single, and return the result device path. If there is no
359 remaining device path as a result, this function will return NULL.
360
361 **/
362 EFI_DEVICE_PATH_PROTOCOL *
363 BmDelPartMatchInstance (
364 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
365 IN EFI_DEVICE_PATH_PROTOCOL *Single
366 );
367
368 /**
369 Repair all the controllers according to the Driver Health status queried.
370 **/
371 VOID
372 BmRepairAllControllers (
373 VOID
374 );
375
376 /**
377 Print the device path info.
378
379 @param DevicePath The device path need to print.
380 **/
381 VOID
382 BmPrintDp (
383 EFI_DEVICE_PATH_PROTOCOL *DevicePath
384 );
385
386 /**
387 Convert a single character to number.
388 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
389
390 @param Char The input char which need to convert to int.
391
392 @return The converted 8-bit number or (UINTN) -1 if conversion failed.
393 **/
394 UINTN
395 BmCharToUint (
396 IN CHAR16 Char
397 );
398
399 /**
400 Return the boot description for the controller.
401
402 @param Handle Controller handle.
403
404 @return The description string.
405 **/
406 CHAR16 *
407 BmGetBootDescription (
408 IN EFI_HANDLE Handle
409 );
410
411 /**
412 Enumerate all boot option descriptions and append " 2"/" 3"/... to make
413 unique description.
414
415 @param BootOptions Array of boot options.
416 @param BootOptionCount Count of boot options.
417 **/
418 VOID
419 BmMakeBootOptionDescriptionUnique (
420 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,
421 UINTN BootOptionCount
422 );
423
424 /**
425 Get the file buffer from the specified Load File instance.
426
427 @param LoadFileHandle The specified Load File instance.
428 @param FilePath The file path which will pass to LoadFile().
429 @param FullPath Return the full device path pointing to the load option.
430 @param FileSize Return the size of the load option.
431
432 @return The load option buffer or NULL if fails.
433 **/
434 VOID *
435 BmGetFileBufferFromLoadFile (
436 EFI_HANDLE LoadFileHandle,
437 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
438 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,
439 OUT UINTN *FileSize
440 );
441 #endif // _INTERNAL_BM_H_