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