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