]>
Commit | Line | Data |
---|---|---|
1d112229 RN |
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 | This program and the accompanying materials | |
6 | are licensed and made available under the terms and conditions of the BSD License | |
7 | which accompanies this distribution. The full text of the license may be found at | |
8 | http://opensource.org/licenses/bsd-license.php | |
9 | ||
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
11 | WITHOUT 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 | ||
86 | typedef enum { | |
87 | BmAcpiFloppyBoot, | |
88 | BmHardwareDeviceBoot, | |
89 | BmMessageAtapiBoot, | |
90 | BmMessageSataBoot, | |
91 | BmMessageUsbBoot, | |
92 | BmMessageScsiBoot, | |
93 | BmMessageNetworkBoot, | |
94 | BmMiscBoot | |
95 | } BM_BOOT_TYPE; | |
96 | ||
97 | typedef | |
98 | CHAR16 * | |
99 | (* BM_GET_BOOT_DESCRIPTION) ( | |
100 | IN EFI_HANDLE Handle | |
101 | ); | |
102 | ||
103 | #define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k') | |
104 | typedef struct { | |
105 | UINT32 Signature; | |
106 | LIST_ENTRY Link; | |
107 | ||
108 | BOOLEAN IsContinue; | |
109 | UINT16 BootOption; | |
110 | UINT8 CodeCount; | |
111 | UINT8 WaitingKey; | |
112 | EFI_KEY_DATA KeyData[3]; | |
113 | } BM_HOTKEY; | |
114 | ||
115 | #define BM_HOTKEY_FROM_LINK(a) CR (a, BM_HOTKEY, Link, BM_HOTKEY_SIGNATURE) | |
116 | ||
117 | /** | |
118 | Get the image file buffer data and buffer size by its device path. | |
119 | ||
120 | @param FilePath On input, a pointer to an allocated buffer containing the device | |
121 | path of the file. | |
122 | On output the pointer could be NULL when the function fails to | |
123 | load the boot option, or could point to an allocated buffer containing | |
124 | the device path of the file. | |
125 | It could be updated by either short-form device path expanding, | |
126 | or default boot file path appending. | |
127 | Caller is responsible to free it when it's non-NULL. | |
128 | @param FileSize A pointer to the size of the file buffer. | |
129 | ||
130 | @retval NULL File is NULL, or FileSize is NULL. Or, the file can't be found. | |
131 | @retval other The file buffer. The caller is responsible to free the memory. | |
132 | **/ | |
133 | VOID * | |
134 | BmLoadEfiBootOption ( | |
135 | IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, | |
136 | OUT UINTN *FileSize | |
137 | ); | |
138 | ||
139 | /** | |
140 | Get the Option Number that wasn't used. | |
141 | ||
142 | @param OrderVariableName Could be L"BootOrder" or L"DriverOrder". | |
143 | @param FreeOptionNumber To receive the minimal free option number. | |
144 | ||
145 | @retval EFI_SUCCESS The option number is found | |
146 | @retval EFI_OUT_OF_RESOURCES There is no free option number that can be used. | |
147 | @retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL | |
148 | ||
149 | **/ | |
150 | EFI_STATUS | |
151 | BmGetFreeOptionNumber ( | |
152 | IN CHAR16 *OrderVariableName, | |
153 | OUT UINT16 *FreeOptionNumber | |
154 | ); | |
155 | ||
156 | /** | |
157 | ||
158 | Writes performance data of booting into the allocated memory. | |
159 | OS can process these records. | |
160 | ||
161 | @param Event The triggered event. | |
162 | @param Context Context for this event. | |
163 | ||
164 | **/ | |
165 | VOID | |
166 | EFIAPI | |
167 | BmWriteBootToOsPerformanceData ( | |
168 | IN EFI_EVENT Event, | |
169 | IN VOID *Context | |
170 | ); | |
171 | ||
172 | ||
173 | /** | |
174 | Get the headers (dos, image, optional header) from an image | |
175 | ||
176 | @param Device SimpleFileSystem device handle | |
177 | @param FileName File name for the image | |
178 | @param DosHeader Pointer to dos header | |
179 | @param Hdr The buffer in which to return the PE32, PE32+, or TE header. | |
180 | ||
181 | @retval EFI_SUCCESS Successfully get the machine type. | |
182 | @retval EFI_NOT_FOUND The file is not found. | |
183 | @retval EFI_LOAD_ERROR File is not a valid image file. | |
184 | ||
185 | **/ | |
186 | EFI_STATUS | |
187 | BmGetImageHeader ( | |
188 | IN EFI_HANDLE Device, | |
189 | IN CHAR16 *FileName, | |
190 | OUT EFI_IMAGE_DOS_HEADER *DosHeader, | |
191 | OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr | |
192 | ); | |
193 | ||
194 | /** | |
195 | This routine adjust the memory information for different memory type and | |
196 | save them into the variables for next boot. | |
197 | **/ | |
198 | VOID | |
199 | BmSetMemoryTypeInformationVariable ( | |
200 | VOID | |
201 | ); | |
202 | ||
203 | /** | |
204 | Check whether there is a instance in BlockIoDevicePath, which contain multi device path | |
205 | instances, has the same partition node with HardDriveDevicePath device path | |
206 | ||
207 | @param BlockIoDevicePath Multi device path instances which need to check | |
208 | @param HardDriveDevicePath A device path which starts with a hard drive media | |
209 | device path. | |
210 | ||
211 | @retval TRUE There is a matched device path instance. | |
212 | @retval FALSE There is no matched device path instance. | |
213 | ||
214 | **/ | |
215 | BOOLEAN | |
216 | BmMatchPartitionDevicePathNode ( | |
217 | IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath, | |
218 | IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath | |
219 | ); | |
220 | ||
221 | /** | |
222 | Connect the specific Usb device which match the short form device path. | |
223 | ||
224 | @param DevicePath A short-form device path that starts with the first | |
225 | element being a USB WWID or a USB Class device | |
226 | path | |
227 | ||
228 | @return EFI_INVALID_PARAMETER DevicePath is NULL pointer. | |
229 | DevicePath is not a USB device path. | |
230 | ||
231 | @return EFI_SUCCESS Success to connect USB device | |
232 | @return EFI_NOT_FOUND Fail to find handle for USB controller to connect. | |
233 | ||
234 | **/ | |
235 | EFI_STATUS | |
236 | BmConnectUsbShortFormDevicePath ( | |
237 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath | |
238 | ); | |
239 | ||
240 | /** | |
241 | Stop the hotkey processing. | |
242 | ||
243 | @param Event Event pointer related to hotkey service. | |
244 | @param Context Context pass to this function. | |
245 | **/ | |
246 | VOID | |
247 | EFIAPI | |
248 | BmStopHotkeyService ( | |
249 | IN EFI_EVENT Event, | |
250 | IN VOID *Context | |
251 | ); | |
252 | ||
253 | /** | |
254 | Set the variable and report the error through status code upon failure. | |
255 | ||
256 | @param VariableName A Null-terminated string that is the name of the vendor's variable. | |
257 | Each VariableName is unique for each VendorGuid. VariableName must | |
258 | contain 1 or more characters. If VariableName is an empty string, | |
259 | then EFI_INVALID_PARAMETER is returned. | |
260 | @param VendorGuid A unique identifier for the vendor. | |
261 | @param Attributes Attributes bitmask to set for the variable. | |
262 | @param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, | |
263 | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or | |
264 | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero | |
265 | causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is | |
266 | set, then a SetVariable() call with a DataSize of zero will not cause any change to | |
267 | the variable value (the timestamp associated with the variable may be updated however | |
268 | even if no new data value is provided,see the description of the | |
269 | EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not | |
270 | be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). | |
271 | @param Data The contents for the variable. | |
272 | ||
273 | @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as | |
274 | defined by the Attributes. | |
275 | @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the | |
276 | DataSize exceeds the maximum allowed. | |
277 | @retval EFI_INVALID_PARAMETER VariableName is an empty string. | |
278 | @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data. | |
279 | @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error. | |
280 | @retval EFI_WRITE_PROTECTED The variable in question is read-only. | |
281 | @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted. | |
282 | @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | |
283 | or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo | |
284 | does NOT pass the validation check carried out by the firmware. | |
285 | ||
286 | @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found. | |
287 | **/ | |
288 | EFI_STATUS | |
289 | BmSetVariableAndReportStatusCodeOnError ( | |
290 | IN CHAR16 *VariableName, | |
291 | IN EFI_GUID *VendorGuid, | |
292 | IN UINT32 Attributes, | |
293 | IN UINTN DataSize, | |
294 | IN VOID *Data | |
295 | ); | |
296 | ||
297 | /** | |
298 | Function compares a device path data structure to that of all the nodes of a | |
299 | second device path instance. | |
300 | ||
301 | @param Multi A pointer to a multi-instance device path data | |
302 | structure. | |
303 | @param Single A pointer to a single-instance device path data | |
304 | structure. | |
305 | ||
306 | @retval TRUE If the Single device path is contained within Multi device path. | |
307 | @retval FALSE The Single device path is not match within Multi device path. | |
308 | ||
309 | **/ | |
310 | BOOLEAN | |
311 | BmMatchDevicePaths ( | |
312 | IN EFI_DEVICE_PATH_PROTOCOL *Multi, | |
313 | IN EFI_DEVICE_PATH_PROTOCOL *Single | |
314 | ); | |
315 | ||
316 | /** | |
317 | Delete the instance in Multi which matches partly with Single instance | |
318 | ||
319 | @param Multi A pointer to a multi-instance device path data | |
320 | structure. | |
321 | @param Single A pointer to a single-instance device path data | |
322 | structure. | |
323 | ||
324 | @return This function will remove the device path instances in Multi which partly | |
325 | match with the Single, and return the result device path. If there is no | |
326 | remaining device path as a result, this function will return NULL. | |
327 | ||
328 | **/ | |
329 | EFI_DEVICE_PATH_PROTOCOL * | |
330 | BmDelPartMatchInstance ( | |
331 | IN EFI_DEVICE_PATH_PROTOCOL *Multi, | |
332 | IN EFI_DEVICE_PATH_PROTOCOL *Single | |
333 | ); | |
334 | ||
335 | ||
336 | /** | |
337 | Return the index of the load option in the load option array. | |
338 | ||
339 | The function consider two load options are equal when the | |
340 | OptionType, Attributes, Description, FilePath and OptionalData are equal. | |
341 | ||
342 | @param Key Pointer to the load option to be found. | |
343 | @param Array Pointer to the array of load options to be found. | |
344 | @param Count Number of entries in the Array. | |
345 | ||
346 | @retval -1 Key wasn't found in the Array. | |
347 | @retval 0 ~ Count-1 The index of the Key in the Array. | |
348 | **/ | |
349 | INTN | |
350 | BmFindLoadOption ( | |
351 | IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key, | |
352 | IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array, | |
353 | IN UINTN Count | |
354 | ); | |
355 | ||
356 | /** | |
357 | Repair all the controllers according to the Driver Health status queried. | |
358 | **/ | |
359 | VOID | |
360 | BmRepairAllControllers ( | |
361 | VOID | |
362 | ); | |
363 | ||
364 | #endif // _INTERNAL_BM_H_ |