]>
Commit | Line | Data |
---|---|---|
067ed98a RN |
1 | /** @file\r |
2 | BDS library definition, include the file and data structure\r | |
3 | \r | |
d1102dba | 4 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r |
5d3a9896 | 5 | (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r |
9d510e61 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
067ed98a RN |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | #ifndef _INTERNAL_BM_H_\r | |
11 | #define _INTERNAL_BM_H_\r | |
12 | \r | |
13 | #include <PiDxe.h>\r | |
14 | \r | |
15 | #include <IndustryStandard/Pci.h>\r | |
16 | #include <IndustryStandard/PeImage.h>\r | |
17 | #include <IndustryStandard/Atapi.h>\r | |
18 | #include <IndustryStandard/Scsi.h>\r | |
54127af5 | 19 | #include <IndustryStandard/Nvme.h>\r |
067ed98a RN |
20 | \r |
21 | #include <Protocol/PciRootBridgeIo.h>\r | |
22 | #include <Protocol/BlockIo.h>\r | |
23 | #include <Protocol/LoadedImage.h>\r | |
24 | #include <Protocol/SimpleFileSystem.h>\r | |
25 | #include <Protocol/LoadFile.h>\r | |
26 | #include <Protocol/DevicePath.h>\r | |
27 | #include <Protocol/SimpleTextIn.h>\r | |
28 | #include <Protocol/SimpleTextInEx.h>\r | |
29 | #include <Protocol/SimpleTextOut.h>\r | |
30 | #include <Protocol/SimpleNetwork.h>\r | |
31 | #include <Protocol/FirmwareVolume2.h>\r | |
32 | #include <Protocol/PciIo.h>\r | |
33 | #include <Protocol/GraphicsOutput.h>\r | |
34 | #include <Protocol/UsbIo.h>\r | |
35 | #include <Protocol/DiskInfo.h>\r | |
54127af5 | 36 | #include <Protocol/NvmExpressPassthru.h>\r |
067ed98a RN |
37 | #include <Protocol/IdeControllerInit.h>\r |
38 | #include <Protocol/BootLogo.h>\r | |
39 | #include <Protocol/DriverHealth.h>\r | |
40 | #include <Protocol/FormBrowser2.h>\r | |
780e05ca | 41 | #include <Protocol/VariableLock.h>\r |
339ae051 | 42 | #include <Protocol/RamDisk.h>\r |
b33af221 | 43 | #include <Protocol/DeferredImageLoad.h>\r |
067ed98a | 44 | \r |
067ed98a RN |
45 | #include <Guid/MemoryTypeInformation.h>\r |
46 | #include <Guid/FileInfo.h>\r | |
47 | #include <Guid/GlobalVariable.h>\r | |
5cc67962 | 48 | #include <Guid/StatusCodeDataTypeId.h>\r |
067ed98a RN |
49 | #include <Guid/StatusCodeDataTypeVariable.h>\r |
50 | \r | |
51 | #include <Library/PrintLib.h>\r | |
52 | #include <Library/DebugLib.h>\r | |
53 | #include <Library/BaseMemoryLib.h>\r | |
54 | #include <Library/UefiBootServicesTableLib.h>\r | |
55 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
56 | #include <Library/UefiLib.h>\r | |
57 | #include <Library/MemoryAllocationLib.h>\r | |
58 | #include <Library/DxeServicesTableLib.h>\r | |
59 | #include <Library/HobLib.h>\r | |
60 | #include <Library/BaseLib.h>\r | |
61 | #include <Library/DevicePathLib.h>\r | |
62 | #include <Library/PerformanceLib.h>\r | |
63 | #include <Library/PcdLib.h>\r | |
64 | #include <Library/PeCoffGetEntryPointLib.h>\r | |
65 | #include <Library/UefiBootManagerLib.h>\r | |
067ed98a RN |
66 | #include <Library/DxeServicesLib.h>\r |
67 | #include <Library/ReportStatusCodeLib.h>\r | |
68 | #include <Library/CapsuleLib.h>\r | |
69 | #include <Library/PerformanceLib.h>\r | |
70 | #include <Library/HiiLib.h>\r | |
71 | \r | |
72 | #if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)\r | |
73 | #if defined (MDE_CPU_EBC)\r | |
74 | //\r | |
75 | // Uefi specification only defines the default boot file name for IA32, X64\r | |
76 | // and IPF processor, so need define boot file name for EBC architecture here.\r | |
77 | //\r | |
78 | #define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"\r | |
79 | #else\r | |
80 | #error "Can not determine the default boot file name for unknown processor type!"\r | |
81 | #endif\r | |
82 | #endif\r | |
83 | \r | |
84 | typedef enum {\r | |
85 | BmAcpiFloppyBoot,\r | |
86 | BmHardwareDeviceBoot,\r | |
87 | BmMessageAtapiBoot,\r | |
88 | BmMessageSataBoot,\r | |
89 | BmMessageUsbBoot,\r | |
90 | BmMessageScsiBoot,\r | |
067ed98a RN |
91 | BmMiscBoot\r |
92 | } BM_BOOT_TYPE;\r | |
93 | \r | |
94 | typedef\r | |
95 | CHAR16 *\r | |
96 | (* BM_GET_BOOT_DESCRIPTION) (\r | |
97 | IN EFI_HANDLE Handle\r | |
98 | );\r | |
99 | \r | |
780e05ca RN |
100 | //\r |
101 | // PlatformRecovery#### is the load option with the longest name\r | |
102 | //\r | |
103 | #define BM_OPTION_NAME_LEN sizeof ("PlatformRecovery####")\r | |
067ed98a RN |
104 | extern CHAR16 *mBmLoadOptionName[];\r |
105 | \r | |
72208a9a HG |
106 | //\r |
107 | // Maximum number of reconnect retry to repair controller; it is to limit the\r | |
108 | // number of recursive call of BmRepairAllControllers.\r | |
109 | //\r | |
110 | #define MAX_RECONNECT_REPAIR 10\r | |
111 | \r | |
d95ff8e8 RN |
112 | /**\r |
113 | Visitor function to be called by BmForEachVariable for each variable\r | |
114 | in variable storage.\r | |
115 | \r | |
116 | @param Name Variable name.\r | |
117 | @param Guid Variable GUID.\r | |
118 | @param Context The same context passed to BmForEachVariable.\r | |
119 | **/\r | |
067ed98a RN |
120 | typedef\r |
121 | VOID\r | |
d95ff8e8 | 122 | (*BM_VARIABLE_VISITOR) (\r |
067ed98a RN |
123 | CHAR16 *Name,\r |
124 | EFI_GUID *Guid,\r | |
125 | VOID *Context\r | |
126 | );\r | |
127 | \r | |
128 | /**\r | |
129 | Call Visitor function for each variable in variable storage.\r | |
130 | \r | |
131 | @param Visitor Visitor function.\r | |
132 | @param Context The context passed to Visitor function.\r | |
133 | **/\r | |
134 | VOID\r | |
d95ff8e8 RN |
135 | BmForEachVariable (\r |
136 | BM_VARIABLE_VISITOR Visitor,\r | |
067ed98a RN |
137 | VOID *Context\r |
138 | );\r | |
139 | \r | |
f41c71d2 RN |
140 | #define BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE SIGNATURE_32 ('b', 'm', 'd', 'h')\r |
141 | typedef struct {\r | |
142 | UINT32 Signature;\r | |
143 | LIST_ENTRY Link;\r | |
144 | EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler;\r | |
145 | } BM_BOOT_DESCRIPTION_ENTRY;\r | |
146 | \r | |
067ed98a RN |
147 | /**\r |
148 | Repair all the controllers according to the Driver Health status queried.\r | |
72208a9a HG |
149 | \r |
150 | @param ReconnectRepairCount To record the number of recursive call of\r | |
151 | this function itself.\r | |
067ed98a RN |
152 | **/\r |
153 | VOID\r | |
154 | BmRepairAllControllers (\r | |
72208a9a | 155 | UINTN ReconnectRepairCount\r |
067ed98a RN |
156 | );\r |
157 | \r | |
158 | #define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')\r | |
159 | typedef struct {\r | |
160 | UINT32 Signature;\r | |
161 | LIST_ENTRY Link;\r | |
162 | \r | |
163 | BOOLEAN IsContinue;\r | |
164 | UINT16 BootOption;\r | |
165 | UINT8 CodeCount;\r | |
166 | UINT8 WaitingKey;\r | |
167 | EFI_KEY_DATA KeyData[3];\r | |
168 | } BM_HOTKEY;\r | |
169 | \r | |
170 | #define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE)\r | |
171 | \r | |
067ed98a RN |
172 | /**\r |
173 | Get the Option Number that wasn't used.\r | |
174 | \r | |
175 | @param LoadOptionType Load option type.\r | |
176 | @param FreeOptionNumber To receive the minimal free option number.\r | |
177 | \r | |
178 | @retval EFI_SUCCESS The option number is found\r | |
179 | @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.\r | |
180 | @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL\r | |
181 | \r | |
182 | **/\r | |
183 | EFI_STATUS\r | |
184 | BmGetFreeOptionNumber (\r | |
185 | IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,\r | |
186 | OUT UINT16 *FreeOptionNumber\r | |
187 | );\r | |
188 | \r | |
067ed98a | 189 | /**\r |
d1102dba | 190 | This routine adjust the memory information for different memory type and\r |
665b26ba RN |
191 | save them into the variables for next boot. It resets the system when\r |
192 | memory information is updated and the current boot option belongs to\r | |
024bdafc RN |
193 | boot category instead of application category. It doesn't count the\r |
194 | reserved memory occupied by RAM Disk.\r | |
665b26ba | 195 | \r |
024bdafc RN |
196 | @param Boot TRUE if current boot option belongs to boot\r |
197 | category instead of application category.\r | |
067ed98a RN |
198 | **/\r |
199 | VOID\r | |
200 | BmSetMemoryTypeInformationVariable (\r | |
3a986a35 | 201 | IN BOOLEAN Boot\r |
067ed98a RN |
202 | );\r |
203 | \r | |
204 | /**\r | |
205 | Check whether there is a instance in BlockIoDevicePath, which contain multi device path\r | |
206 | instances, has the same partition node with HardDriveDevicePath device path\r | |
207 | \r | |
208 | @param BlockIoDevicePath Multi device path instances which need to check\r | |
209 | @param HardDriveDevicePath A device path which starts with a hard drive media\r | |
210 | device path.\r | |
211 | \r | |
212 | @retval TRUE There is a matched device path instance.\r | |
213 | @retval FALSE There is no matched device path instance.\r | |
214 | \r | |
215 | **/\r | |
216 | BOOLEAN\r | |
217 | BmMatchPartitionDevicePathNode (\r | |
218 | IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,\r | |
219 | IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r | |
220 | );\r | |
221 | \r | |
222 | /**\r | |
223 | Connect the specific Usb device which match the short form device path.\r | |
224 | \r | |
225 | @param DevicePath A short-form device path that starts with the first\r | |
226 | element being a USB WWID or a USB Class device\r | |
227 | path\r | |
228 | \r | |
229 | @return EFI_INVALID_PARAMETER DevicePath is NULL pointer.\r | |
230 | DevicePath is not a USB device path.\r | |
231 | \r | |
232 | @return EFI_SUCCESS Success to connect USB device\r | |
233 | @return EFI_NOT_FOUND Fail to find handle for USB controller to connect.\r | |
234 | \r | |
235 | **/\r | |
236 | EFI_STATUS\r | |
237 | BmConnectUsbShortFormDevicePath (\r | |
238 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
239 | );\r | |
240 | \r | |
241 | /**\r | |
242 | Stop the hotkey processing.\r | |
d1102dba LG |
243 | \r |
244 | @param Event Event pointer related to hotkey service.\r | |
245 | @param Context Context pass to this function.\r | |
067ed98a RN |
246 | **/\r |
247 | VOID\r | |
248 | EFIAPI\r | |
249 | BmStopHotkeyService (\r | |
250 | IN EFI_EVENT Event,\r | |
251 | IN VOID *Context\r | |
252 | );\r | |
253 | \r | |
254 | /**\r | |
255 | Set the variable and report the error through status code upon failure.\r | |
256 | \r | |
257 | @param VariableName A Null-terminated string that is the name of the vendor's variable.\r | |
258 | Each VariableName is unique for each VendorGuid. VariableName must\r | |
259 | contain 1 or more characters. If VariableName is an empty string,\r | |
260 | then EFI_INVALID_PARAMETER is returned.\r | |
261 | @param VendorGuid A unique identifier for the vendor.\r | |
262 | @param Attributes Attributes bitmask to set for the variable.\r | |
d1102dba | 263 | @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,\r |
4073f85d | 264 | or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero\r |
d1102dba LG |
265 | causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is\r |
266 | set, then a SetVariable() call with a DataSize of zero will not cause any change to\r | |
267 | the variable value (the timestamp associated with the variable may be updated however\r | |
268 | even if no new data value is provided,see the description of the\r | |
269 | EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not\r | |
270 | be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).\r | |
067ed98a RN |
271 | @param Data The contents for the variable.\r |
272 | \r | |
273 | @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r | |
274 | defined by the Attributes.\r | |
275 | @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the\r | |
276 | DataSize exceeds the maximum allowed.\r | |
277 | @retval EFI_INVALID_PARAMETER VariableName is an empty string.\r | |
278 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r | |
279 | @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r | |
280 | @retval EFI_WRITE_PROTECTED The variable in question is read-only.\r | |
281 | @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r | |
4073f85d ZC |
282 | @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS\r |
283 | being set, but the AuthInfo does NOT pass the validation check carried out by the firmware.\r | |
067ed98a RN |
284 | \r |
285 | @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r | |
286 | **/\r | |
287 | EFI_STATUS\r | |
288 | BmSetVariableAndReportStatusCodeOnError (\r | |
289 | IN CHAR16 *VariableName,\r | |
290 | IN EFI_GUID *VendorGuid,\r | |
291 | IN UINT32 Attributes,\r | |
292 | IN UINTN DataSize,\r | |
293 | IN VOID *Data\r | |
294 | );\r | |
295 | \r | |
067ed98a RN |
296 | /**\r |
297 | Function compares a device path data structure to that of all the nodes of a\r | |
298 | second device path instance.\r | |
299 | \r | |
300 | @param Multi A pointer to a multi-instance device path data\r | |
301 | structure.\r | |
302 | @param Single A pointer to a single-instance device path data\r | |
303 | structure.\r | |
304 | \r | |
305 | @retval TRUE If the Single device path is contained within Multi device path.\r | |
306 | @retval FALSE The Single device path is not match within Multi device path.\r | |
307 | \r | |
308 | **/\r | |
309 | BOOLEAN\r | |
310 | BmMatchDevicePaths (\r | |
311 | IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r | |
312 | IN EFI_DEVICE_PATH_PROTOCOL *Single\r | |
313 | );\r | |
314 | \r | |
315 | /**\r | |
316 | Delete the instance in Multi which matches partly with Single instance\r | |
317 | \r | |
318 | @param Multi A pointer to a multi-instance device path data\r | |
319 | structure.\r | |
320 | @param Single A pointer to a single-instance device path data\r | |
321 | structure.\r | |
322 | \r | |
323 | @return This function will remove the device path instances in Multi which partly\r | |
324 | match with the Single, and return the result device path. If there is no\r | |
325 | remaining device path as a result, this function will return NULL.\r | |
326 | \r | |
327 | **/\r | |
328 | EFI_DEVICE_PATH_PROTOCOL *\r | |
329 | BmDelPartMatchInstance (\r | |
330 | IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r | |
331 | IN EFI_DEVICE_PATH_PROTOCOL *Single\r | |
332 | );\r | |
333 | \r | |
067ed98a RN |
334 | /**\r |
335 | Print the device path info.\r | |
336 | \r | |
337 | @param DevicePath The device path need to print.\r | |
338 | **/\r | |
339 | VOID\r | |
340 | BmPrintDp (\r | |
341 | EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
342 | );\r | |
343 | \r | |
418e8cd9 RN |
344 | /**\r |
345 | Convert a single character to number.\r | |
346 | It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'\r | |
347 | \r | |
348 | @param Char The input char which need to convert to int.\r | |
349 | \r | |
350 | @return The converted 8-bit number or (UINTN) -1 if conversion failed.\r | |
351 | **/\r | |
352 | UINTN\r | |
353 | BmCharToUint (\r | |
354 | IN CHAR16 Char\r | |
355 | );\r | |
356 | \r | |
1f2e80af RN |
357 | /**\r |
358 | Return the boot description for the controller.\r | |
359 | \r | |
360 | @param Handle Controller handle.\r | |
361 | \r | |
362 | @return The description string.\r | |
363 | **/\r | |
364 | CHAR16 *\r | |
365 | BmGetBootDescription (\r | |
366 | IN EFI_HANDLE Handle\r | |
367 | );\r | |
368 | \r | |
369 | /**\r | |
370 | Enumerate all boot option descriptions and append " 2"/" 3"/... to make\r | |
371 | unique description.\r | |
372 | \r | |
373 | @param BootOptions Array of boot options.\r | |
374 | @param BootOptionCount Count of boot options.\r | |
375 | **/\r | |
376 | VOID\r | |
377 | BmMakeBootOptionDescriptionUnique (\r | |
378 | EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,\r | |
379 | UINTN BootOptionCount\r | |
380 | );\r | |
026ede49 RN |
381 | \r |
382 | /**\r | |
383 | Get the file buffer from the specified Load File instance.\r | |
384 | \r | |
385 | @param LoadFileHandle The specified Load File instance.\r | |
386 | @param FilePath The file path which will pass to LoadFile().\r | |
026ede49 | 387 | \r |
08eff917 RN |
388 | @return The full device path pointing to the load option buffer.\r |
389 | **/\r | |
390 | EFI_DEVICE_PATH_PROTOCOL *\r | |
391 | BmExpandLoadFile (\r | |
392 | IN EFI_HANDLE LoadFileHandle,\r | |
393 | IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r | |
394 | );\r | |
395 | \r | |
396 | /**\r | |
397 | Return the RAM Disk device path created by LoadFile.\r | |
398 | \r | |
399 | @param FilePath The source file path.\r | |
400 | \r | |
401 | @return Callee-to-free RAM Disk device path\r | |
402 | **/\r | |
403 | EFI_DEVICE_PATH_PROTOCOL *\r | |
404 | BmGetRamDiskDevicePath (\r | |
405 | IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r | |
406 | );\r | |
407 | \r | |
408 | /**\r | |
409 | Destroy the RAM Disk.\r | |
410 | \r | |
411 | The destroy operation includes to call RamDisk.Unregister to\r | |
412 | unregister the RAM DISK from RAM DISK driver, free the memory\r | |
413 | allocated for the RAM Disk.\r | |
414 | \r | |
415 | @param RamDiskDevicePath RAM Disk device path.\r | |
416 | **/\r | |
417 | VOID\r | |
418 | BmDestroyRamDisk (\r | |
419 | IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath\r | |
420 | );\r | |
421 | \r | |
422 | /**\r | |
423 | Get the next possible full path pointing to the load option.\r | |
424 | \r | |
425 | @param FilePath The device path pointing to a load option.\r | |
426 | It could be a short-form device path.\r | |
427 | @param FullPath The full path returned by the routine in last call.\r | |
428 | Set to NULL in first call.\r | |
429 | \r | |
430 | @return The next possible full path pointing to the load option.\r | |
431 | Caller is responsible to free the memory.\r | |
432 | **/\r | |
433 | EFI_DEVICE_PATH_PROTOCOL *\r | |
434 | BmGetNextLoadOptionDevicePath (\r | |
435 | IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r | |
436 | IN EFI_DEVICE_PATH_PROTOCOL *FullPath\r | |
437 | );\r | |
438 | \r | |
439 | /**\r | |
440 | Return the next matched load option buffer.\r | |
441 | The routine keeps calling BmGetNextLoadOptionDevicePath() until a valid\r | |
442 | load option is read.\r | |
443 | \r | |
444 | @param Type The load option type.\r | |
445 | It's used to check whether the load option is valid.\r | |
446 | When it's LoadOptionTypeMax, the routine only guarantees\r | |
447 | the load option is a valid PE image but doesn't guarantee\r | |
448 | the PE's subsystem type is valid.\r | |
449 | @param FilePath The device path pointing to a load option.\r | |
450 | It could be a short-form device path.\r | |
451 | @param FullPath Return the next full device path of the load option after\r | |
452 | short-form device path expanding.\r | |
453 | Caller is responsible to free it.\r | |
454 | NULL to return the first matched full device path.\r | |
455 | @param FileSize Return the load option size.\r | |
456 | \r | |
457 | @return The load option buffer. Caller is responsible to free the memory.\r | |
026ede49 RN |
458 | **/\r |
459 | VOID *\r | |
08eff917 RN |
460 | BmGetNextLoadOptionBuffer (\r |
461 | IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,\r | |
462 | IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r | |
463 | OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r | |
464 | OUT UINTN *FileSize\r | |
026ede49 | 465 | );\r |
067ed98a | 466 | #endif // _INTERNAL_BM_H_\r |