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