]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Provides interface to advanced shell functionality for parsing both handle and protocol database.\r | |
3 | \r | |
4 | Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "UefiHandleParsingLib.h"\r | |
16 | \r | |
17 | \r | |
18 | STATIC CONST EFI_GUID mHandleParsingHiiGuid = \\r | |
19 | { \\r | |
20 | 0xb8969637, 0x81de, 0x43af, { 0xbc, 0x9a, 0x24, 0xd9, 0x89, 0x13, 0xf2, 0xf6 } \\r | |
21 | };\r | |
22 | EFI_HANDLE mHandleParsingHiiHandle;\r | |
23 | HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};\r | |
24 | \r | |
25 | /**\r | |
26 | Constructor for the library.\r | |
27 | \r | |
28 | @param[in] ImageHandle Ignored.\r | |
29 | @param[in] SystemTable Ignored.\r | |
30 | \r | |
31 | @retval EFI_SUCCESS The operation was successful.\r | |
32 | **/\r | |
33 | EFI_STATUS\r | |
34 | EFIAPI\r | |
35 | HandleParsingLibConstructor (\r | |
36 | IN EFI_HANDLE ImageHandle,\r | |
37 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
38 | )\r | |
39 | {\r | |
40 | mHandleParsingHiiHandle = HiiAddPackages (&mHandleParsingHiiGuid, gImageHandle, UefiHandleParsingLibStrings, NULL);\r | |
41 | if (mHandleParsingHiiHandle == NULL) {\r | |
42 | return (EFI_DEVICE_ERROR);\r | |
43 | }\r | |
44 | \r | |
45 | return (EFI_SUCCESS);\r | |
46 | }\r | |
47 | \r | |
48 | /**\r | |
49 | Destructor for the library. free any resources.\r | |
50 | \r | |
51 | @param[in] ImageHandle Ignored.\r | |
52 | @param[in] SystemTable Ignored.\r | |
53 | \r | |
54 | @retval EFI_SUCCESS The operation was successful.\r | |
55 | **/\r | |
56 | EFI_STATUS\r | |
57 | EFIAPI\r | |
58 | HandleParsingLibDestructor (\r | |
59 | IN EFI_HANDLE ImageHandle,\r | |
60 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
61 | )\r | |
62 | {\r | |
63 | if (mHandleParsingHiiHandle != NULL) {\r | |
64 | HiiRemovePackages(mHandleParsingHiiHandle);\r | |
65 | }\r | |
66 | return (EFI_SUCCESS);\r | |
67 | }\r | |
68 | \r | |
69 | /*\r | |
70 | CHAR16*\r | |
71 | EFIAPI\r | |
72 | LoadedImageProtocolDumpInformation(\r | |
73 | IN CONST EFI_HANDLE TheHandle,\r | |
74 | IN CONST BOOLEAN Verbose\r | |
75 | )\r | |
76 | {\r | |
77 | EFI_LOADED_IMAGE_PROTOCOL *Image;\r | |
78 | EFI_STATUS Status;\r | |
79 | EFI_DEVICE_PATH_PROTOCOL *DevPath;\r | |
80 | EFI_DEVICE_PATH_PROTOCOL *DevPathNode;\r | |
81 | VOID *Buffer;\r | |
82 | UINTN BufferSize;\r | |
83 | UINT32 AuthenticationStatus;\r | |
84 | EFI_GUID *NameGuid;\r | |
85 | EFI_FIRMWARE_VOLUME_PROTOCOL *FV;\r | |
86 | EFI_FIRMWARE_VOLUME2_PROTOCOL *FV2;\r | |
87 | \r | |
88 | FV = NULL;\r | |
89 | FV2 = NULL;\r | |
90 | Buffer = NULL;\r | |
91 | BufferSize = 0;\r | |
92 | \r | |
93 | Status = HandleProtocol (\r | |
94 | TheHandle,\r | |
95 | &gEfiLoadedImageProtocolGuid,\r | |
96 | &Image);\r | |
97 | ASSERT_EFI_ERROR(Status);\r | |
98 | \r | |
99 | DevPath = UnpackDevicePath (Image->FilePath);\r | |
100 | \r | |
101 | if (DevPath == NULL) {\r | |
102 | return NULL;\r | |
103 | }\r | |
104 | \r | |
105 | DevPathNode = DevPath;\r | |
106 | \r | |
107 | while (!IsDevicePathEnd (DevPathNode)) {\r | |
108 | //\r | |
109 | // Find the Fv File path\r | |
110 | //\r | |
111 | NameGuid = GetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)DevPathNode);\r | |
112 | if (NameGuid != NULL) {\r | |
113 | Status = BS->HandleProtocol (\r | |
114 | Image->DeviceHandle,\r | |
115 | &gEfiFirmwareVolumeProtocolGuid,\r | |
116 | &FV\r | |
117 | );\r | |
118 | if (!EFI_ERROR (Status)) {\r | |
119 | Status = FV->ReadSection (\r | |
120 | FV,\r | |
121 | NameGuid,\r | |
122 | EFI_SECTION_USER_INTERFACE,\r | |
123 | 0,\r | |
124 | &Buffer,\r | |
125 | &BufferSize,\r | |
126 | &AuthenticationStatus\r | |
127 | );\r | |
128 | if (!EFI_ERROR (Status)) {\r | |
129 | break;\r | |
130 | }\r | |
131 | \r | |
132 | Buffer = NULL;\r | |
133 | } else {\r | |
134 | Status = BS->HandleProtocol (\r | |
135 | Image->DeviceHandle,\r | |
136 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
137 | &FV2\r | |
138 | );\r | |
139 | if (!EFI_ERROR (Status)) {\r | |
140 | Status = FV2->ReadSection (\r | |
141 | FV2,\r | |
142 | NameGuid,\r | |
143 | EFI_SECTION_USER_INTERFACE,\r | |
144 | 0,\r | |
145 | &Buffer,\r | |
146 | &BufferSize,\r | |
147 | &AuthenticationStatus\r | |
148 | );\r | |
149 | if (!EFI_ERROR (Status)) {\r | |
150 | break;\r | |
151 | }\r | |
152 | \r | |
153 | Buffer = NULL;\r | |
154 | }\r | |
155 | }\r | |
156 | }\r | |
157 | //\r | |
158 | // Next device path node\r | |
159 | //\r | |
160 | DevPathNode = NextDevicePathNode (DevPathNode);\r | |
161 | }\r | |
162 | \r | |
163 | FreePool (DevPath);\r | |
164 | return Buffer;\r | |
165 | }\r | |
166 | */\r | |
167 | \r | |
168 | /**\r | |
169 | Function to dump information about SimpleTextOut.\r | |
170 | \r | |
171 | This will allocate the return buffer from boot services pool.\r | |
172 | \r | |
173 | @param[in] TheHandle The handle that has SimpleTextOut installed.\r | |
174 | @param[in] Verbose TRUE for additional information, FALSE otherwise.\r | |
175 | \r | |
176 | @retval A poitner to a string containing the information.\r | |
177 | **/\r | |
178 | CHAR16*\r | |
179 | EFIAPI\r | |
180 | TxtOutProtocolDumpInformation(\r | |
181 | IN CONST EFI_HANDLE TheHandle,\r | |
182 | IN CONST BOOLEAN Verbose\r | |
183 | )\r | |
184 | {\r | |
185 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Dev;\r | |
186 | INTN Index;\r | |
187 | UINTN Col;\r | |
188 | UINTN Row;\r | |
189 | EFI_STATUS Status;\r | |
190 | CHAR16 *RetVal;\r | |
191 | UINTN Size;\r | |
192 | CHAR16 *Temp;\r | |
193 | UINTN NewSize;\r | |
194 | \r | |
195 | if (!Verbose) {\r | |
196 | return (NULL);\r | |
197 | }\r | |
198 | \r | |
199 | RetVal = NULL;\r | |
200 | Size = 0;\r | |
201 | \r | |
202 | Status = gBS->HandleProtocol(\r | |
203 | TheHandle,\r | |
204 | &gEfiSimpleTextOutProtocolGuid,\r | |
205 | (VOID**)&Dev);\r | |
206 | \r | |
207 | ASSERT_EFI_ERROR(Status);\r | |
208 | ASSERT (Dev != NULL && Dev->Mode != NULL);\r | |
209 | \r | |
210 | Size = (Dev->Mode->MaxMode + 1) * 80;\r | |
211 | RetVal = AllocateZeroPool(Size);\r | |
212 | \r | |
213 | Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER), NULL);\r | |
214 | UnicodeSPrint(RetVal, Size, Temp, Dev, Dev->Mode->Attribute);\r | |
215 | FreePool(Temp);\r | |
216 | \r | |
217 | //\r | |
218 | // Dump TextOut Info\r | |
219 | //\r | |
220 | Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE), NULL);\r | |
221 | for (Index = 0; Index < Dev->Mode->MaxMode; Index++) {\r | |
222 | Status = Dev->QueryMode (Dev, Index, &Col, &Row);\r | |
223 | NewSize = Size - StrSize(RetVal);\r | |
224 | UnicodeSPrint(\r | |
225 | RetVal + StrLen(RetVal),\r | |
226 | NewSize,\r | |
227 | Temp,\r | |
228 | Index == Dev->Mode->Mode ? L'*' : L' ',\r | |
229 | Index,\r | |
230 | !EFI_ERROR(Status)?Col:-1,\r | |
231 | !EFI_ERROR(Status)?Row:-1\r | |
232 | );\r | |
233 | }\r | |
234 | FreePool(Temp);\r | |
235 | return (RetVal);\r | |
236 | }\r | |
237 | \r | |
238 | STATIC CONST UINTN VersionStringSize = 60;\r | |
239 | \r | |
240 | /**\r | |
241 | Function to dump information about EfiDriverSupportedEfiVersion protocol.\r | |
242 | \r | |
243 | This will allocate the return buffer from boot services pool.\r | |
244 | \r | |
245 | @param[in] TheHandle The handle that has the protocol installed.\r | |
246 | @param[in] Verbose TRUE for additional information, FALSE otherwise.\r | |
247 | \r | |
248 | @retval A poitner to a string containing the information.\r | |
249 | **/\r | |
250 | CHAR16*\r | |
251 | EFIAPI\r | |
252 | DriverEfiVersionProtocolDumpInformation(\r | |
253 | IN CONST EFI_HANDLE TheHandle,\r | |
254 | IN CONST BOOLEAN Verbose\r | |
255 | )\r | |
256 | {\r | |
257 | EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL *DriverEfiVersion;\r | |
258 | EFI_STATUS Status;\r | |
259 | CHAR16 *RetVal;\r | |
260 | \r | |
261 | Status = gBS->HandleProtocol(\r | |
262 | TheHandle,\r | |
263 | &gEfiDriverSupportedEfiVersionProtocolGuid,\r | |
264 | (VOID**)&DriverEfiVersion);\r | |
265 | \r | |
266 | ASSERT_EFI_ERROR(Status);\r | |
267 | \r | |
268 | RetVal = AllocateZeroPool(VersionStringSize);\r | |
269 | ASSERT(RetVal != NULL);\r | |
270 | UnicodeSPrint(RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion);\r | |
271 | return (RetVal);\r | |
272 | }\r | |
273 | \r | |
274 | /**\r | |
275 | Function to dump information about DevicePath protocol.\r | |
276 | \r | |
277 | This will allocate the return buffer from boot services pool.\r | |
278 | \r | |
279 | @param[in] TheHandle The handle that has the protocol installed.\r | |
280 | @param[in] Verbose TRUE for additional information, FALSE otherwise.\r | |
281 | \r | |
282 | @retval A poitner to a string containing the information.\r | |
283 | **/\r | |
284 | CHAR16*\r | |
285 | EFIAPI\r | |
286 | DevicePathProtocolDumpInformation(\r | |
287 | IN CONST EFI_HANDLE TheHandle,\r | |
288 | IN CONST BOOLEAN Verbose\r | |
289 | )\r | |
290 | {\r | |
291 | EFI_DEVICE_PATH_PROTOCOL *DevPath;\r | |
292 | CHAR16 *Temp;\r | |
293 | CHAR16 *Temp2;\r | |
294 | EFI_STATUS Status;\r | |
295 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;\r | |
296 | Temp = NULL;\r | |
297 | \r | |
298 | Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID**)&DevPathToText);\r | |
299 | if (!EFI_ERROR(Status)) {\r | |
300 | Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
301 | if (!EFI_ERROR(Status)) {\r | |
302 | //\r | |
303 | // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)\r | |
304 | //\r | |
305 | Temp = DevPathToText->ConvertDevicePathToText(DevPath, TRUE, TRUE);\r | |
306 | gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);\r | |
307 | }\r | |
308 | }\r | |
309 | if (!Verbose && Temp != NULL && StrLen(Temp) > 30) {\r | |
310 | Temp2 = NULL;\r | |
311 | Temp2 = StrnCatGrow(&Temp2, NULL, Temp+(StrLen(Temp) - 30), 30);\r | |
312 | FreePool(Temp);\r | |
313 | Temp = Temp2;\r | |
314 | }\r | |
315 | return (Temp);\r | |
316 | }\r | |
317 | \r | |
318 | //\r | |
319 | // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg\r | |
320 | //\r | |
321 | #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \\r | |
322 | { \\r | |
323 | 0x58c518b1, 0x76f3, 0x11d4, 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \\r | |
324 | }\r | |
325 | \r | |
326 | #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \\r | |
327 | { \\r | |
328 | 0x96eb4ad6, 0xa32a, 0x11d4, 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \\r | |
329 | }\r | |
330 | \r | |
331 | #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \\r | |
332 | { \\r | |
333 | 0xc95a93d, 0xa006, 0x11d4, 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \\r | |
334 | }\r | |
335 | STATIC CONST EFI_GUID WinNtThunkProtocolGuid = LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID;\r | |
336 | STATIC CONST EFI_GUID WinNtIoProtocolGuid = LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID;\r | |
337 | STATIC CONST EFI_GUID WinNtSerialPortGuid = LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID;\r | |
338 | \r | |
339 | STATIC CONST PROTOCOL_INFO_BLOCK mGuidStringListNT[] = {\r | |
340 | {STRING_TOKEN(STR_WINNT_THUNK), (EFI_GUID*)&WinNtThunkProtocolGuid, NULL},\r | |
341 | {STRING_TOKEN(STR_WINNT_DRIVER_IO), (EFI_GUID*)&WinNtIoProtocolGuid, NULL},\r | |
342 | {STRING_TOKEN(STR_WINNT_SERIAL_PORT), (EFI_GUID*)&WinNtSerialPortGuid, NULL},\r | |
343 | {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},\r | |
344 | };\r | |
345 | \r | |
346 | STATIC CONST PROTOCOL_INFO_BLOCK mGuidStringList[] = {\r | |
347 | {STRING_TOKEN(STR_LOADED_IMAGE), &gEfiLoadedImageProtocolGuid, NULL},\r | |
348 | {STRING_TOKEN(STR_DEVICE_PATH), &gEfiDevicePathProtocolGuid, DevicePathProtocolDumpInformation},\r | |
349 | {STRING_TOKEN(STR_IMAGE_PATH), &gEfiLoadedImageDevicePathProtocolGuid, DevicePathProtocolDumpInformation},\r | |
350 | {STRING_TOKEN(STR_DEVICE_PATH_UTIL), &gEfiDevicePathUtilitiesProtocolGuid, NULL},\r | |
351 | {STRING_TOKEN(STR_DEVICE_PATH_TXT), &gEfiDevicePathToTextProtocolGuid, NULL},\r | |
352 | {STRING_TOKEN(STR_DEVICE_PATH_FTXT), &gEfiDevicePathFromTextProtocolGuid, NULL},\r | |
353 | {STRING_TOKEN(STR_DEVICE_PATH_PC), &gEfiPcAnsiGuid, NULL},\r | |
354 | {STRING_TOKEN(STR_DEVICE_PATH_VT100), &gEfiVT100Guid, NULL},\r | |
355 | {STRING_TOKEN(STR_DEVICE_PATH_VT100P), &gEfiVT100PlusGuid, NULL},\r | |
356 | {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8), &gEfiVTUTF8Guid, NULL},\r | |
357 | {STRING_TOKEN(STR_DRIVER_BINDING), &gEfiDriverBindingProtocolGuid, NULL},\r | |
358 | {STRING_TOKEN(STR_PLATFORM_OVERRIDE), &gEfiPlatformDriverOverrideProtocolGuid, NULL},\r | |
359 | {STRING_TOKEN(STR_BUS_OVERRIDE), &gEfiBusSpecificDriverOverrideProtocolGuid, NULL},\r | |
360 | {STRING_TOKEN(STR_DRIVER_DIAG), &gEfiDriverDiagnosticsProtocolGuid, NULL},\r | |
361 | {STRING_TOKEN(STR_DRIVER_DIAG2), &gEfiDriverDiagnostics2ProtocolGuid, NULL},\r | |
362 | {STRING_TOKEN(STR_DRIVER_CN), &gEfiComponentNameProtocolGuid, NULL},\r | |
363 | {STRING_TOKEN(STR_DRIVER_CN2), &gEfiComponentName2ProtocolGuid, NULL},\r | |
364 | {STRING_TOKEN(STR_PLAT_DRV_CFG), &gEfiPlatformToDriverConfigurationProtocolGuid, NULL},\r | |
365 | {STRING_TOKEN(STR_DRIVER_VERSION), &gEfiDriverSupportedEfiVersionProtocolGuid, DriverEfiVersionProtocolDumpInformation},\r | |
366 | {STRING_TOKEN(STR_TXT_IN), &gEfiSimpleTextInProtocolGuid, NULL},\r | |
367 | {STRING_TOKEN(STR_TXT_IN_EX), &gEfiSimpleTextInputExProtocolGuid, NULL},\r | |
368 | {STRING_TOKEN(STR_TXT_OUT), &gEfiSimpleTextOutProtocolGuid, TxtOutProtocolDumpInformation},\r | |
369 | {STRING_TOKEN(STR_SIM_POINTER), &gEfiSimplePointerProtocolGuid, NULL},\r | |
370 | {STRING_TOKEN(STR_ABS_POINTER), &gEfiAbsolutePointerProtocolGuid, NULL},\r | |
371 | {STRING_TOKEN(STR_SERIAL_IO), &gEfiSerialIoProtocolGuid, NULL},\r | |
372 | {STRING_TOKEN(STR_GRAPHICS_OUTPUT), &gEfiGraphicsOutputProtocolGuid, NULL},\r | |
373 | {STRING_TOKEN(STR_EDID_DISCOVERED), &gEfiEdidDiscoveredProtocolGuid, NULL},\r | |
374 | {STRING_TOKEN(STR_EDID_ACTIVE), &gEfiEdidActiveProtocolGuid, NULL},\r | |
375 | {STRING_TOKEN(STR_EDID_OVERRIDE), &gEfiEdidOverrideProtocolGuid, NULL},\r | |
376 | {STRING_TOKEN(STR_CON_IN), &gEfiConsoleInDeviceGuid, NULL},\r | |
377 | {STRING_TOKEN(STR_CON_OUT), &gEfiConsoleOutDeviceGuid, NULL},\r | |
378 | {STRING_TOKEN(STR_STD_ERR), &gEfiStandardErrorDeviceGuid, NULL},\r | |
379 | {STRING_TOKEN(STR_LOAD_FILE), &gEfiLoadFileProtocolGuid, NULL},\r | |
380 | {STRING_TOKEN(STR_LOAD_FILE2), &gEfiLoadFile2ProtocolGuid, NULL},\r | |
381 | {STRING_TOKEN(STR_SIMPLE_FILE_SYS), &gEfiSimpleFileSystemProtocolGuid, NULL},\r | |
382 | {STRING_TOKEN(STR_FILE_INFO), &gEfiFileInfoGuid, NULL},\r | |
383 | {STRING_TOKEN(STR_FILE_SYS_INFO), &gEfiFileSystemInfoGuid, NULL},\r | |
384 | {STRING_TOKEN(STR_TAPE_IO), &gEfiTapeIoProtocolGuid, NULL},\r | |
385 | {STRING_TOKEN(STR_DISK_IO), &gEfiDiskIoProtocolGuid, NULL},\r | |
386 | {STRING_TOKEN(STR_BLK_IO), &gEfiBlockIoProtocolGuid, NULL},\r | |
387 | {STRING_TOKEN(STR_UC), &gEfiUnicodeCollationProtocolGuid, NULL},\r | |
388 | {STRING_TOKEN(STR_UC2), &gEfiUnicodeCollation2ProtocolGuid, NULL},\r | |
389 | {STRING_TOKEN(STR_PCIRB_IO), &gEfiPciRootBridgeIoProtocolGuid, NULL},\r | |
390 | {STRING_TOKEN(STR_PCI_IO), &gEfiPciIoProtocolGuid, NULL},\r | |
391 | {STRING_TOKEN(STR_SCSI_PT), &gEfiScsiPassThruProtocolGuid, NULL},\r | |
392 | {STRING_TOKEN(STR_SCSI_IO), &gEfiScsiIoProtocolGuid, NULL},\r | |
393 | {STRING_TOKEN(STR_SCSI_PT_EXT), &gEfiExtScsiPassThruProtocolGuid, NULL},\r | |
394 | {STRING_TOKEN(STR_ISCSI), &gEfiIScsiInitiatorNameProtocolGuid, NULL},\r | |
395 | {STRING_TOKEN(STR_USB_IO), &gEfiUsbIoProtocolGuid, NULL},\r | |
396 | {STRING_TOKEN(STR_USB_HC), &gEfiUsbHcProtocolGuid, NULL},\r | |
397 | {STRING_TOKEN(STR_USB_HC2), &gEfiUsb2HcProtocolGuid, NULL},\r | |
398 | {STRING_TOKEN(STR_DEBUG_SUPPORT), &gEfiDebugSupportProtocolGuid, NULL},\r | |
399 | {STRING_TOKEN(STR_DEBUG_PORT), &gEfiDebugPortProtocolGuid, NULL},\r | |
400 | {STRING_TOKEN(STR_DECOMPRESS), &gEfiDecompressProtocolGuid, NULL},\r | |
401 | {STRING_TOKEN(STR_ACPI_TABLE), &gEfiAcpiTableProtocolGuid, NULL},\r | |
402 | {STRING_TOKEN(STR_EBC_INTERPRETER), &gEfiEbcProtocolGuid, NULL},\r | |
403 | {STRING_TOKEN(STR_SNP), &gEfiSimpleNetworkProtocolGuid, NULL},\r | |
404 | {STRING_TOKEN(STR_NII), &gEfiNetworkInterfaceIdentifierProtocolGuid, NULL},\r | |
405 | {STRING_TOKEN(STR_NII_31), &gEfiNetworkInterfaceIdentifierProtocolGuid_31, NULL},\r | |
406 | {STRING_TOKEN(STR_PXE_BC), &gEfiPxeBaseCodeProtocolGuid, NULL},\r | |
407 | {STRING_TOKEN(STR_PXE_CB), &gEfiPxeBaseCodeCallbackProtocolGuid, NULL},\r | |
408 | {STRING_TOKEN(STR_BIS), &gEfiBisProtocolGuid, NULL},\r | |
409 | {STRING_TOKEN(STR_MNP_SB), &gEfiManagedNetworkServiceBindingProtocolGuid, NULL},\r | |
410 | {STRING_TOKEN(STR_MNP), &gEfiManagedNetworkProtocolGuid, NULL},\r | |
411 | {STRING_TOKEN(STR_ARP_SB), &gEfiArpServiceBindingProtocolGuid, NULL},\r | |
412 | {STRING_TOKEN(STR_ARP), &gEfiArpProtocolGuid, NULL},\r | |
413 | {STRING_TOKEN(STR_DHCPV4_SB), &gEfiDhcp4ServiceBindingProtocolGuid, NULL},\r | |
414 | {STRING_TOKEN(STR_DHCPV4), &gEfiDhcp4ProtocolGuid, NULL},\r | |
415 | {STRING_TOKEN(STR_TCPV4_SB), &gEfiTcp4ServiceBindingProtocolGuid, NULL},\r | |
416 | {STRING_TOKEN(STR_TCPV4), &gEfiTcp4ProtocolGuid, NULL},\r | |
417 | {STRING_TOKEN(STR_IPV4_SB), &gEfiIp4ServiceBindingProtocolGuid, NULL},\r | |
418 | {STRING_TOKEN(STR_IPV4), &gEfiIp4ProtocolGuid, NULL},\r | |
419 | {STRING_TOKEN(STR_IPV4_CFG), &gEfiIp4ConfigProtocolGuid, NULL},\r | |
420 | {STRING_TOKEN(STR_SHELL_PARAMETERS), &gEfiShellParametersProtocolGuid, NULL},\r | |
421 | {STRING_TOKEN(STR_SHELL), &gEfiShellProtocolGuid, NULL},\r | |
422 | {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE), &gEfiGlobalVariableGuid, NULL},\r | |
423 | {STRING_TOKEN(STR_UDPV4_SB), &gEfiUdp4ServiceBindingProtocolGuid, NULL},\r | |
424 | {STRING_TOKEN(STR_UDPV4), &gEfiUdp4ProtocolGuid, NULL},\r | |
425 | {STRING_TOKEN(STR_MTFTPV4_SB), &gEfiMtftp4ServiceBindingProtocolGuid, NULL},\r | |
426 | {STRING_TOKEN(STR_MTFTPV4), &gEfiMtftp4ProtocolGuid, NULL},\r | |
427 | {STRING_TOKEN(STR_AUTH_INFO), &gEfiAuthenticationInfoProtocolGuid, NULL},\r | |
428 | {STRING_TOKEN(STR_HASH_SB), &gEfiHashServiceBindingProtocolGuid, NULL},\r | |
429 | {STRING_TOKEN(STR_HASH), &gEfiHashProtocolGuid, NULL},\r | |
430 | {STRING_TOKEN(STR_HII_FONT), &gEfiHiiFontProtocolGuid, NULL},\r | |
431 | {STRING_TOKEN(STR_HII_STRING), &gEfiHiiStringProtocolGuid, NULL},\r | |
432 | {STRING_TOKEN(STR_HII_IMAGE), &gEfiHiiImageProtocolGuid, NULL},\r | |
433 | {STRING_TOKEN(STR_HII_DATABASE), &gEfiHiiDatabaseProtocolGuid, NULL},\r | |
434 | {STRING_TOKEN(STR_HII_CONFIG_ROUT), &gEfiHiiConfigRoutingProtocolGuid, NULL},\r | |
435 | {STRING_TOKEN(STR_HII_CONFIG_ACC), &gEfiHiiConfigAccessProtocolGuid, NULL},\r | |
436 | {STRING_TOKEN(STR_HII_FORM_BROWSER2), &gEfiFormBrowser2ProtocolGuid, NULL},\r | |
437 | {STRING_TOKEN(STR_SHELL_INTERFACE), &gEfiShellInterfaceGuid, NULL},\r | |
438 | {STRING_TOKEN(STR_SHELL_ENV2), &gEfiShellEnvironment2Guid, NULL},\r | |
439 | {STRING_TOKEN(STR_SHELL_ENV), &gEfiShellEnvironment2Guid, NULL},\r | |
440 | {STRING_TOKEN(STR_DEVICE_IO), &gEfiDeviceIoProtocolGuid, NULL},\r | |
441 | {STRING_TOKEN(STR_UGA_DRAW), &gEfiUgaDrawProtocolGuid, NULL},\r | |
442 | {STRING_TOKEN(STR_UGA_IO), &gEfiUgaIoProtocolGuid, NULL},\r | |
443 | {STRING_TOKEN(STR_ESP), &gEfiPartTypeSystemPartGuid, NULL},\r | |
444 | {STRING_TOKEN(STR_GPT_NBR), &gEfiPartTypeLegacyMbrGuid, NULL},\r | |
445 | {STRING_TOKEN(STR_DRIVER_CONFIG), &gEfiDriverConfigurationProtocolGuid, NULL},\r | |
446 | {STRING_TOKEN(STR_DRIVER_CONFIG2), &gEfiDriverConfiguration2ProtocolGuid, NULL},\r | |
447 | {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},\r | |
448 | };\r | |
449 | \r | |
450 | /**\r | |
451 | Function to get the node for a protocol or struct from it's GUID.\r | |
452 | \r | |
453 | if Guid is NULL, then ASSERT.\r | |
454 | \r | |
455 | @param[in] Guid The GUID to look for the name of.\r | |
456 | \r | |
457 | @return The node.\r | |
458 | **/\r | |
459 | CONST PROTOCOL_INFO_BLOCK *\r | |
460 | EFIAPI\r | |
461 | InternalShellGetNodeFromGuid(\r | |
462 | IN CONST EFI_GUID* Guid\r | |
463 | )\r | |
464 | {\r | |
465 | CONST PROTOCOL_INFO_BLOCK *ListWalker;\r | |
466 | \r | |
467 | ASSERT(Guid != NULL);\r | |
468 | \r | |
469 | if (PcdGetBool(PcdShellIncludeNtGuids)) {\r | |
470 | for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r | |
471 | if (CompareGuid(ListWalker->GuidId, Guid)) {\r | |
472 | return (ListWalker);\r | |
473 | }\r | |
474 | }\r | |
475 | }\r | |
476 | for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r | |
477 | if (CompareGuid(ListWalker->GuidId, Guid)) {\r | |
478 | return (ListWalker);\r | |
479 | }\r | |
480 | }\r | |
481 | return (ListWalker);\r | |
482 | }\r | |
483 | \r | |
484 | /**\r | |
485 | Function to get the name of a protocol or struct from it's GUID.\r | |
486 | \r | |
487 | if Guid is NULL, then ASSERT.\r | |
488 | \r | |
489 | @param[in] Guid The GUID to look for the name of.\r | |
490 | @param[in] Lang The language to use.\r | |
491 | \r | |
492 | @return pointer to string of the name. The caller\r | |
493 | is responsible to free this memory.\r | |
494 | **/\r | |
495 | CHAR16*\r | |
496 | EFIAPI\r | |
497 | GetStringNameFromGuid(\r | |
498 | IN CONST EFI_GUID *Guid,\r | |
499 | IN CONST CHAR8 *Lang OPTIONAL\r | |
500 | )\r | |
501 | {\r | |
502 | CONST PROTOCOL_INFO_BLOCK *Id;\r | |
503 | \r | |
504 | Id = InternalShellGetNodeFromGuid(Guid);\r | |
505 | return (HiiGetString(mHandleParsingHiiHandle, Id->StringId, Lang));\r | |
506 | }\r | |
507 | \r | |
508 | /**\r | |
509 | Function to dump protocol information from a handle.\r | |
510 | \r | |
511 | This function will return a allocated string buffer containing the\r | |
512 | information. The caller is responsible for freeing the memory.\r | |
513 | \r | |
514 | If Guid is NULL, ASSERT().\r | |
515 | If TheHandle is NULL, ASSERT().\r | |
516 | \r | |
517 | @param[in] TheHandle The handle to dump information from.\r | |
518 | @param[in] Guid The GUID of the protocol to dump.\r | |
519 | @param[in] Verbose TRUE for extra info. FALSE otherwise.\r | |
520 | \r | |
521 | @return The pointer to string.\r | |
522 | @retval NULL An error was encountered.\r | |
523 | **/\r | |
524 | CHAR16*\r | |
525 | EFIAPI\r | |
526 | GetProtocolInformationDump(\r | |
527 | IN CONST EFI_HANDLE TheHandle,\r | |
528 | IN CONST EFI_GUID *Guid,\r | |
529 | IN CONST BOOLEAN Verbose\r | |
530 | )\r | |
531 | {\r | |
532 | CONST PROTOCOL_INFO_BLOCK *Id;\r | |
533 | \r | |
534 | ASSERT(TheHandle != NULL);\r | |
535 | ASSERT(Guid != NULL);\r | |
536 | \r | |
537 | if (TheHandle == NULL || Guid == NULL) {\r | |
538 | return (NULL);\r | |
539 | }\r | |
540 | \r | |
541 | Id = InternalShellGetNodeFromGuid(Guid);\r | |
542 | if (Id != NULL && Id->DumpInfo != NULL) {\r | |
543 | return (Id->DumpInfo(TheHandle, Verbose));\r | |
544 | }\r | |
545 | return (NULL);\r | |
546 | }\r | |
547 | \r | |
548 | /**\r | |
549 | Function to get the Guid for a protocol or struct based on it's string name.\r | |
550 | \r | |
551 | @param[in] Name The pointer to the string name.\r | |
552 | @param[in] Lang The pointer to the language code.\r | |
553 | @param[in] Guid The pointer to the Guid.\r | |
554 | \r | |
555 | @retval EFI_SUCCESS The operation was sucessful.\r | |
556 | **/\r | |
557 | EFI_STATUS\r | |
558 | EFIAPI\r | |
559 | GetGuidFromStringName(\r | |
560 | IN CONST CHAR16 *Name,\r | |
561 | IN CONST CHAR8 *Lang OPTIONAL,\r | |
562 | IN EFI_GUID **Guid\r | |
563 | )\r | |
564 | {\r | |
565 | CONST PROTOCOL_INFO_BLOCK *ListWalker;\r | |
566 | CHAR16 *String;\r | |
567 | \r | |
568 | ASSERT(Guid != NULL);\r | |
569 | if (Guid == NULL) {\r | |
570 | return (EFI_INVALID_PARAMETER);\r | |
571 | }\r | |
572 | *Guid = NULL;\r | |
573 | \r | |
574 | if (PcdGetBool(PcdShellIncludeNtGuids)) {\r | |
575 | for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r | |
576 | String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);\r | |
577 | if (Name != NULL && String != NULL && StrCmp(Name, String)==0) {\r | |
578 | *Guid = ListWalker->GuidId;\r | |
579 | }\r | |
580 | SHELL_FREE_NON_NULL(String);\r | |
581 | if (*Guid != NULL) {\r | |
582 | return (EFI_SUCCESS);\r | |
583 | }\r | |
584 | }\r | |
585 | }\r | |
586 | for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r | |
587 | String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);\r | |
588 | if (Name != NULL && String != NULL && StrCmp(Name, String)==0) {\r | |
589 | *Guid = ListWalker->GuidId;\r | |
590 | }\r | |
591 | SHELL_FREE_NON_NULL(String);\r | |
592 | if (*Guid != NULL) {\r | |
593 | return (EFI_SUCCESS);\r | |
594 | }\r | |
595 | }\r | |
596 | return (EFI_NOT_FOUND);\r | |
597 | }\r | |
598 | \r | |
599 | /**\r | |
600 | Function to retrieve the driver name (if possible) from the ComponentName or\r | |
601 | ComponentName2 protocol\r | |
602 | \r | |
603 | @param[in] TheHandle The driver handle to get the name of.\r | |
604 | @param[in] Language The language to use.\r | |
605 | \r | |
606 | @retval NULL The name could not be found.\r | |
607 | @return A pointer to the string name. Do not de-allocate the memory.\r | |
608 | **/\r | |
609 | CONST CHAR16*\r | |
610 | EFIAPI\r | |
611 | GetStringNameFromHandle(\r | |
612 | IN CONST EFI_HANDLE TheHandle,\r | |
613 | IN CONST CHAR8 *Language\r | |
614 | )\r | |
615 | {\r | |
616 | EFI_COMPONENT_NAME2_PROTOCOL *CompNameStruct;\r | |
617 | EFI_STATUS Status;\r | |
618 | CHAR16 *RetVal;\r | |
619 | \r | |
620 | Status = gBS->OpenProtocol(\r | |
621 | TheHandle,\r | |
622 | &gEfiComponentName2ProtocolGuid,\r | |
623 | (VOID**)&CompNameStruct,\r | |
624 | gImageHandle,\r | |
625 | NULL,\r | |
626 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
627 | if (!EFI_ERROR(Status)) {\r | |
628 | Status = CompNameStruct->GetDriverName(CompNameStruct, (CHAR8*)Language, &RetVal);\r | |
629 | if (!EFI_ERROR(Status)) {\r | |
630 | return (RetVal);\r | |
631 | }\r | |
632 | }\r | |
633 | Status = gBS->OpenProtocol(\r | |
634 | TheHandle,\r | |
635 | &gEfiComponentNameProtocolGuid,\r | |
636 | (VOID**)&CompNameStruct,\r | |
637 | gImageHandle,\r | |
638 | NULL,\r | |
639 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
640 | if (!EFI_ERROR(Status)) {\r | |
641 | Status = CompNameStruct->GetDriverName(CompNameStruct, (CHAR8*)Language, &RetVal);\r | |
642 | if (!EFI_ERROR(Status)) {\r | |
643 | return (RetVal);\r | |
644 | }\r | |
645 | }\r | |
646 | return (NULL);\r | |
647 | }\r | |
648 | \r | |
649 | /**\r | |
650 | Function to initialize the file global mHandleList object for use in\r | |
651 | vonverting handles to index and index to handle.\r | |
652 | \r | |
653 | @retval EFI_SUCCESS The operation was successful.\r | |
654 | **/\r | |
655 | EFI_STATUS\r | |
656 | EFIAPI\r | |
657 | InternalShellInitHandleList(\r | |
658 | VOID\r | |
659 | )\r | |
660 | {\r | |
661 | EFI_STATUS Status;\r | |
662 | EFI_HANDLE *HandleBuffer;\r | |
663 | UINTN HandleCount;\r | |
664 | HANDLE_LIST *ListWalker;\r | |
665 | \r | |
666 | if (mHandleList.NextIndex != 0) {\r | |
667 | return EFI_SUCCESS;\r | |
668 | }\r | |
669 | InitializeListHead(&mHandleList.List.Link);\r | |
670 | mHandleList.NextIndex = 1;\r | |
671 | Status = gBS->LocateHandleBuffer (\r | |
672 | AllHandles,\r | |
673 | NULL,\r | |
674 | NULL,\r | |
675 | &HandleCount,\r | |
676 | &HandleBuffer\r | |
677 | );\r | |
678 | ASSERT_EFI_ERROR(Status);\r | |
679 | if (EFI_ERROR(Status)) {\r | |
680 | return (Status);\r | |
681 | }\r | |
682 | for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){\r | |
683 | ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));\r | |
684 | ASSERT(ListWalker != NULL);\r | |
685 | ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex-1];\r | |
686 | ListWalker->TheIndex = mHandleList.NextIndex;\r | |
687 | InsertTailList(&mHandleList.List.Link,&ListWalker->Link);\r | |
688 | }\r | |
689 | FreePool(HandleBuffer);\r | |
690 | return (EFI_SUCCESS);\r | |
691 | }\r | |
692 | \r | |
693 | /**\r | |
694 | Function to retrieve the human-friendly index of a given handle. If the handle\r | |
695 | does not have a index one will be automatically assigned. The index value is valid\r | |
696 | until the termination of the shell application.\r | |
697 | \r | |
698 | @param[in] TheHandle The handle to retrieve an index for.\r | |
699 | \r | |
700 | @retval 0 A memory allocation failed.\r | |
701 | @return The index of the handle.\r | |
702 | \r | |
703 | **/\r | |
704 | UINTN\r | |
705 | EFIAPI\r | |
706 | ConvertHandleToHandleIndex(\r | |
707 | IN CONST EFI_HANDLE TheHandle\r | |
708 | )\r | |
709 | {\r | |
710 | HANDLE_LIST *ListWalker;\r | |
711 | if (TheHandle == NULL) {\r | |
712 | return 0;\r | |
713 | }\r | |
714 | \r | |
715 | InternalShellInitHandleList();\r | |
716 | \r | |
717 | for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)\r | |
718 | ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)\r | |
719 | ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)\r | |
720 | ){\r | |
721 | if (ListWalker->TheHandle == TheHandle) {\r | |
722 | return (ListWalker->TheIndex);\r | |
723 | }\r | |
724 | }\r | |
725 | ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));\r | |
726 | ASSERT(ListWalker != NULL);\r | |
727 | ListWalker->TheHandle = TheHandle;\r | |
728 | ListWalker->TheIndex = mHandleList.NextIndex++;\r | |
729 | InsertTailList(&mHandleList.List.Link,&ListWalker->Link);\r | |
730 | return (ListWalker->TheIndex);\r | |
731 | }\r | |
732 | \r | |
733 | \r | |
734 | \r | |
735 | /**\r | |
736 | Function to retrieve the EFI_HANDLE from the human-friendly index.\r | |
737 | \r | |
738 | @param[in] TheIndex The index to retrieve the EFI_HANDLE for.\r | |
739 | \r | |
740 | @retval NULL The index was invalid.\r | |
741 | @return The EFI_HANDLE that index represents.\r | |
742 | \r | |
743 | **/\r | |
744 | EFI_HANDLE\r | |
745 | EFIAPI\r | |
746 | ConvertHandleIndexToHandle(\r | |
747 | IN CONST UINTN TheIndex\r | |
748 | )\r | |
749 | {\r | |
750 | HANDLE_LIST *ListWalker;\r | |
751 | \r | |
752 | InternalShellInitHandleList();\r | |
753 | \r | |
754 | if (TheIndex >= mHandleList.NextIndex) {\r | |
755 | return (NULL);\r | |
756 | }\r | |
757 | \r | |
758 | for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)\r | |
759 | ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)\r | |
760 | ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)\r | |
761 | ){\r | |
762 | if (ListWalker->TheIndex == TheIndex) {\r | |
763 | return (ListWalker->TheHandle);\r | |
764 | }\r | |
765 | }\r | |
766 | return (NULL);\r | |
767 | }\r | |
768 | \r | |
769 | /**\r | |
770 | Gets all the related EFI_HANDLEs based on the mask supplied.\r | |
771 | \r | |
772 | This function scans all EFI_HANDLES in the UEFI environment's handle database\r | |
773 | and returns the ones with the specified relationship (Mask) to the specified\r | |
774 | controller handle.\r | |
775 | \r | |
776 | If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.\r | |
777 | If MatchingHandleCount is NULL, then ASSERT.\r | |
778 | \r | |
779 | If MatchingHandleBuffer is not NULL upon a successful return the memory must be\r | |
780 | caller freed.\r | |
781 | \r | |
782 | @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.\r | |
783 | @param[in] ControllerHandle The handle with Device Path protocol on it.\r | |
784 | @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in\r | |
785 | MatchingHandleBuffer.\r | |
786 | @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount\r | |
787 | EFI_HANDLEs with a terminating NULL EFI_HANDLE.\r | |
788 | @param[out] HandleType An array of type information.\r | |
789 | \r | |
790 | @retval EFI_SUCCESS The operation was successful, and any related handles\r | |
791 | are in MatchingHandleBuffer.\r | |
792 | @retval EFI_NOT_FOUND No matching handles were found.\r | |
793 | @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.\r | |
794 | **/\r | |
795 | EFI_STATUS\r | |
796 | EFIAPI\r | |
797 | ParseHandleDatabaseByRelationshipWithType (\r | |
798 | IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,\r | |
799 | IN CONST EFI_HANDLE ControllerHandle OPTIONAL,\r | |
800 | IN UINTN *HandleCount,\r | |
801 | OUT EFI_HANDLE **HandleBuffer,\r | |
802 | OUT UINTN **HandleType\r | |
803 | )\r | |
804 | {\r | |
805 | EFI_STATUS Status;\r | |
806 | UINTN HandleIndex;\r | |
807 | EFI_GUID **ProtocolGuidArray;\r | |
808 | UINTN ArrayCount;\r | |
809 | UINTN ProtocolIndex;\r | |
810 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;\r | |
811 | UINTN OpenInfoCount;\r | |
812 | UINTN OpenInfoIndex;\r | |
813 | UINTN ChildIndex;\r | |
814 | \r | |
815 | ASSERT(HandleCount != NULL);\r | |
816 | ASSERT(HandleBuffer != NULL);\r | |
817 | ASSERT(HandleType != NULL);\r | |
818 | ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);\r | |
819 | \r | |
820 | *HandleCount = 0;\r | |
821 | *HandleBuffer = NULL;\r | |
822 | *HandleType = NULL;\r | |
823 | \r | |
824 | //\r | |
825 | // Retrieve the list of all handles from the handle database\r | |
826 | //\r | |
827 | Status = gBS->LocateHandleBuffer (\r | |
828 | AllHandles,\r | |
829 | NULL,\r | |
830 | NULL,\r | |
831 | HandleCount,\r | |
832 | HandleBuffer\r | |
833 | );\r | |
834 | if (EFI_ERROR (Status)) {\r | |
835 | return (Status);\r | |
836 | }\r | |
837 | \r | |
838 | *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));\r | |
839 | ASSERT(*HandleType != NULL);\r | |
840 | \r | |
841 | for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {\r | |
842 | //\r | |
843 | // Retrieve the list of all the protocols on each handle\r | |
844 | //\r | |
845 | Status = gBS->ProtocolsPerHandle (\r | |
846 | (*HandleBuffer)[HandleIndex],\r | |
847 | &ProtocolGuidArray,\r | |
848 | &ArrayCount\r | |
849 | );\r | |
850 | if (!EFI_ERROR (Status)) {\r | |
851 | \r | |
852 | for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {\r | |
853 | \r | |
854 | //\r | |
855 | // Set the bit describing what this handle has\r | |
856 | //\r | |
857 | if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) ) {\r | |
858 | (*HandleType)[HandleIndex] |= HR_IMAGE_HANDLE;\r | |
859 | } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) ) {\r | |
860 | (*HandleType)[HandleIndex] |= HR_DRIVER_BINDING_HANDLE;\r | |
861 | } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {\r | |
862 | (*HandleType)[HandleIndex] |= HR_DRIVER_CONFIGURATION_HANDLE;\r | |
863 | } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {\r | |
864 | (*HandleType)[HandleIndex] |= HR_DRIVER_CONFIGURATION_HANDLE;\r | |
865 | } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) ) {\r | |
866 | (*HandleType)[HandleIndex] |= HR_DRIVER_DIAGNOSTICS_HANDLE;\r | |
867 | } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) ) {\r | |
868 | (*HandleType)[HandleIndex] |= HR_DRIVER_DIAGNOSTICS_HANDLE;\r | |
869 | } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) ) {\r | |
870 | (*HandleType)[HandleIndex] |= HR_COMPONENT_NAME_HANDLE;\r | |
871 | } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) ) {\r | |
872 | (*HandleType)[HandleIndex] |= HR_COMPONENT_NAME_HANDLE;\r | |
873 | } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) ) {\r | |
874 | (*HandleType)[HandleIndex] |= HR_DEVICE_HANDLE;\r | |
875 | } else {\r | |
876 | DEBUG_CODE_BEGIN();\r | |
877 | ASSERT((*HandleType)[HandleIndex] == (*HandleType)[HandleIndex]);\r | |
878 | DEBUG_CODE_END();\r | |
879 | }\r | |
880 | //\r | |
881 | // Retrieve the list of agents that have opened each protocol\r | |
882 | //\r | |
883 | Status = gBS->OpenProtocolInformation (\r | |
884 | (*HandleBuffer)[HandleIndex],\r | |
885 | ProtocolGuidArray[ProtocolIndex],\r | |
886 | &OpenInfo,\r | |
887 | &OpenInfoCount\r | |
888 | );\r | |
889 | if (!EFI_ERROR (Status)) {\r | |
890 | for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r | |
891 | if (DriverBindingHandle != NULL && OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {\r | |
892 | if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {\r | |
893 | (*HandleType)[HandleIndex] |= (HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);\r | |
894 | }\r | |
895 | if (ControllerHandle != NULL && (*HandleBuffer)[HandleIndex] == ControllerHandle) {\r | |
896 | if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {\r | |
897 | for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r | |
898 | if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].ControllerHandle) {\r | |
899 | (*HandleType)[ChildIndex] |= (HR_DEVICE_HANDLE | HR_CHILD_HANDLE);\r | |
900 | }\r | |
901 | }\r | |
902 | }\r | |
903 | }\r | |
904 | }\r | |
905 | if (DriverBindingHandle == NULL && OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {\r | |
906 | if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {\r | |
907 | for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r | |
908 | if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {\r | |
909 | (*HandleType)[ChildIndex] |= HR_DEVICE_DRIVER;\r | |
910 | }\r | |
911 | }\r | |
912 | }\r | |
913 | if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {\r | |
914 | (*HandleType)[HandleIndex] |= HR_PARENT_HANDLE;\r | |
915 | for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r | |
916 | if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {\r | |
917 | (*HandleType)[ChildIndex] |= HR_BUS_DRIVER;\r | |
918 | }\r | |
919 | }\r | |
920 | }\r | |
921 | }\r | |
922 | }\r | |
923 | \r | |
924 | FreePool (OpenInfo);\r | |
925 | }\r | |
926 | }\r | |
927 | \r | |
928 | FreePool (ProtocolGuidArray);\r | |
929 | }\r | |
930 | }\r | |
931 | \r | |
932 | if (EFI_ERROR(Status)) {\r | |
933 | if (*HandleType != NULL) {\r | |
934 | FreePool (*HandleType);\r | |
935 | }\r | |
936 | if (*HandleBuffer != NULL) {\r | |
937 | FreePool (*HandleBuffer);\r | |
938 | }\r | |
939 | \r | |
940 | *HandleCount = 0;\r | |
941 | *HandleBuffer = NULL;\r | |
942 | *HandleType = NULL;\r | |
943 | }\r | |
944 | \r | |
945 | return Status;\r | |
946 | }\r | |
947 | \r | |
948 | /**\r | |
949 | Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask\r | |
950 | supplied.\r | |
951 | \r | |
952 | This function will scan all EFI_HANDLES in the UEFI environment's handle database\r | |
953 | and return all the ones with the specified relationship (Mask) to the specified\r | |
954 | controller handle.\r | |
955 | \r | |
956 | If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.\r | |
957 | If MatchingHandleCount is NULL, then ASSERT.\r | |
958 | \r | |
959 | If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be\r | |
960 | caller freed.\r | |
961 | \r | |
962 | @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol\r | |
963 | on it.\r | |
964 | @param[in] ControllerHandle Handle to a device with Device Path protocol on it.\r | |
965 | @param[in] Mask Mask of what relationship(s) is desired.\r | |
966 | @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in\r | |
967 | MatchingHandleBuffer.\r | |
968 | @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount\r | |
969 | EFI_HANDLEs and a terminating NULL EFI_HANDLE.\r | |
970 | \r | |
971 | @retval EFI_SUCCESS The operation was sucessful and any related handles\r | |
972 | are in MatchingHandleBuffer;\r | |
973 | @retval EFI_NOT_FOUND No matching handles were found.\r | |
974 | @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.\r | |
975 | **/\r | |
976 | EFI_STATUS\r | |
977 | EFIAPI\r | |
978 | ParseHandleDatabaseByRelationship (\r | |
979 | IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,\r | |
980 | IN CONST EFI_HANDLE ControllerHandle OPTIONAL,\r | |
981 | IN CONST UINTN Mask,\r | |
982 | IN UINTN *MatchingHandleCount,\r | |
983 | OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r | |
984 | )\r | |
985 | {\r | |
986 | EFI_STATUS Status;\r | |
987 | UINTN HandleCount;\r | |
988 | EFI_HANDLE *HandleBuffer;\r | |
989 | UINTN *HandleType;\r | |
990 | UINTN HandleIndex;\r | |
991 | \r | |
992 | ASSERT(MatchingHandleCount != NULL);\r | |
993 | ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);\r | |
994 | \r | |
995 | if ((Mask & HR_VALID_MASK) != Mask) {\r | |
996 | return (EFI_INVALID_PARAMETER);\r | |
997 | }\r | |
998 | \r | |
999 | if ((Mask & HR_CHILD_HANDLE) != 0 && DriverBindingHandle == NULL) {\r | |
1000 | return (EFI_INVALID_PARAMETER);\r | |
1001 | }\r | |
1002 | \r | |
1003 | *MatchingHandleCount = 0;\r | |
1004 | if (MatchingHandleBuffer != NULL) {\r | |
1005 | *MatchingHandleBuffer = NULL;\r | |
1006 | }\r | |
1007 | \r | |
1008 | HandleBuffer = NULL;\r | |
1009 | HandleType = NULL;\r | |
1010 | \r | |
1011 | Status = ParseHandleDatabaseByRelationshipWithType (\r | |
1012 | DriverBindingHandle,\r | |
1013 | ControllerHandle,\r | |
1014 | &HandleCount,\r | |
1015 | &HandleBuffer,\r | |
1016 | &HandleType\r | |
1017 | );\r | |
1018 | if (!EFI_ERROR (Status)) {\r | |
1019 | //\r | |
1020 | // Count the number of handles that match the attributes in Mask\r | |
1021 | //\r | |
1022 | for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r | |
1023 | if ((HandleType[HandleIndex] & Mask) == Mask) {\r | |
1024 | (*MatchingHandleCount)++;\r | |
1025 | }\r | |
1026 | }\r | |
1027 | //\r | |
1028 | // If no handles match the attributes in Mask then return EFI_NOT_FOUND\r | |
1029 | //\r | |
1030 | if (*MatchingHandleCount == 0) {\r | |
1031 | Status = EFI_NOT_FOUND;\r | |
1032 | } else {\r | |
1033 | \r | |
1034 | if (MatchingHandleBuffer == NULL) {\r | |
1035 | //\r | |
1036 | // Someone just wanted the count...\r | |
1037 | //\r | |
1038 | Status = EFI_SUCCESS;\r | |
1039 | } else {\r | |
1040 | //\r | |
1041 | // Allocate a handle buffer for the number of handles that matched the attributes in Mask\r | |
1042 | //\r | |
1043 | *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE));\r | |
1044 | ASSERT(*MatchingHandleBuffer != NULL);\r | |
1045 | \r | |
1046 | for (HandleIndex = 0,*MatchingHandleCount = 0\r | |
1047 | ; HandleIndex < HandleCount\r | |
1048 | ; HandleIndex++\r | |
1049 | ){\r | |
1050 | //\r | |
1051 | // Fill the allocated buffer with the handles that matched the attributes in Mask\r | |
1052 | //\r | |
1053 | if ((HandleType[HandleIndex] & Mask) == Mask) {\r | |
1054 | (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex];\r | |
1055 | }\r | |
1056 | }\r | |
1057 | \r | |
1058 | //\r | |
1059 | // Make the last one NULL\r | |
1060 | //\r | |
1061 | (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL;\r | |
1062 | \r | |
1063 | Status = EFI_SUCCESS;\r | |
1064 | } // MacthingHandleBuffer == NULL (ELSE)\r | |
1065 | } // *MatchingHandleCount == 0 (ELSE)\r | |
1066 | } // no error on ParseHandleDatabaseByRelationshipWithType\r | |
1067 | \r | |
1068 | if (HandleBuffer != NULL) {\r | |
1069 | FreePool (HandleBuffer);\r | |
1070 | }\r | |
1071 | \r | |
1072 | if (HandleType != NULL) {\r | |
1073 | FreePool (HandleType);\r | |
1074 | }\r | |
1075 | \r | |
1076 | return Status;\r | |
1077 | }\r | |
1078 | \r | |
1079 | /**\r | |
1080 | Gets handles for any child controllers of the passed in controller.\r | |
1081 | \r | |
1082 | @param[in] ControllerHandle The handle of the "parent controller"\r | |
1083 | @param[in] MatchingHandleCount Pointer to the number of handles in\r | |
1084 | MatchingHandleBuffer on return.\r | |
1085 | @param[out] MatchingHandleBuffer Buffer containing handles on a successful\r | |
1086 | return.\r | |
1087 | \r | |
1088 | \r | |
1089 | @retval EFI_SUCCESS The operation was sucessful.\r | |
1090 | **/\r | |
1091 | EFI_STATUS\r | |
1092 | EFIAPI\r | |
1093 | ParseHandleDatabaseForChildControllers(\r | |
1094 | IN CONST EFI_HANDLE ControllerHandle,\r | |
1095 | IN UINTN *MatchingHandleCount,\r | |
1096 | OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r | |
1097 | )\r | |
1098 | {\r | |
1099 | EFI_STATUS Status;\r | |
1100 | // UINTN HandleIndex;\r | |
1101 | UINTN DriverBindingHandleCount;\r | |
1102 | EFI_HANDLE *DriverBindingHandleBuffer;\r | |
1103 | UINTN DriverBindingHandleIndex;\r | |
1104 | UINTN ChildControllerHandleCount;\r | |
1105 | EFI_HANDLE *ChildControllerHandleBuffer;\r | |
1106 | UINTN ChildControllerHandleIndex;\r | |
1107 | // BOOLEAN Found;\r | |
1108 | EFI_HANDLE *HandleBufferForReturn;\r | |
1109 | \r | |
1110 | if (MatchingHandleCount == NULL) {\r | |
1111 | return (EFI_INVALID_PARAMETER);\r | |
1112 | }\r | |
1113 | *MatchingHandleCount = 0;\r | |
1114 | \r | |
1115 | Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (\r | |
1116 | ControllerHandle,\r | |
1117 | &DriverBindingHandleCount,\r | |
1118 | &DriverBindingHandleBuffer\r | |
1119 | );\r | |
1120 | if (EFI_ERROR (Status)) {\r | |
1121 | return Status;\r | |
1122 | }\r | |
1123 | \r | |
1124 | //\r | |
1125 | // Get a buffer big enough for all the controllers.\r | |
1126 | //\r | |
1127 | HandleBufferForReturn = GetHandleListByProtocol(&gEfiDevicePathProtocolGuid);\r | |
1128 | if (HandleBufferForReturn == NULL) {\r | |
1129 | FreePool (DriverBindingHandleBuffer);\r | |
1130 | return (EFI_NOT_FOUND);\r | |
1131 | }\r | |
1132 | \r | |
1133 | for (DriverBindingHandleIndex = 0; DriverBindingHandleIndex < DriverBindingHandleCount; DriverBindingHandleIndex++) {\r | |
1134 | Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (\r | |
1135 | DriverBindingHandleBuffer[DriverBindingHandleIndex],\r | |
1136 | ControllerHandle,\r | |
1137 | &ChildControllerHandleCount,\r | |
1138 | &ChildControllerHandleBuffer\r | |
1139 | );\r | |
1140 | if (EFI_ERROR (Status)) {\r | |
1141 | continue;\r | |
1142 | }\r | |
1143 | \r | |
1144 | for (ChildControllerHandleIndex = 0;\r | |
1145 | ChildControllerHandleIndex < ChildControllerHandleCount;\r | |
1146 | ChildControllerHandleIndex++\r | |
1147 | ) {\r | |
1148 | // Found = FALSE;\r | |
1149 | HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];\r | |
1150 | // for (HandleIndex = 0; HandleBufferForReturn[HandleIndex] != NULL; HandleIndex++) {\r | |
1151 | // if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {\r | |
1152 | // Found = TRUE;\r | |
1153 | // break;\r | |
1154 | // }\r | |
1155 | // }\r | |
1156 | \r | |
1157 | // if (Found) {\r | |
1158 | // HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];\r | |
1159 | // }\r | |
1160 | }\r | |
1161 | \r | |
1162 | FreePool (ChildControllerHandleBuffer);\r | |
1163 | }\r | |
1164 | \r | |
1165 | FreePool (DriverBindingHandleBuffer);\r | |
1166 | \r | |
1167 | if (MatchingHandleBuffer != NULL) {\r | |
1168 | *MatchingHandleBuffer = HandleBufferForReturn;\r | |
1169 | } else {\r | |
1170 | FreePool(HandleBufferForReturn);\r | |
1171 | }\r | |
1172 | \r | |
1173 | return (EFI_SUCCESS);\r | |
1174 | }\r | |
1175 | \r | |
1176 | /**\r | |
1177 | Appends 1 buffer to another buffer. This will re-allocate the destination buffer\r | |
1178 | if necessary to fit all of the data.\r | |
1179 | \r | |
1180 | If DestinationBuffer is NULL, then ASSERT().\r | |
1181 | \r | |
1182 | @param[in,out] DestinationBuffer The pointer to the pointer to the buffer to append onto.\r | |
1183 | @param[in,out] DestinationSize The pointer to the size of DestinationBuffer.\r | |
1184 | @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.\r | |
1185 | @param[in] SourceSize The number of bytes of SourceBuffer to append.\r | |
1186 | \r | |
1187 | @retval NULL A memory allocation failed.\r | |
1188 | @retval NULL A parameter was invalid.\r | |
1189 | @return A pointer to (*DestinationBuffer).\r | |
1190 | **/\r | |
1191 | VOID*\r | |
1192 | EFIAPI\r | |
1193 | BuffernCatGrow (\r | |
1194 | IN OUT VOID **DestinationBuffer,\r | |
1195 | IN OUT UINTN *DestinationSize,\r | |
1196 | IN VOID *SourceBuffer,\r | |
1197 | IN UINTN SourceSize\r | |
1198 | )\r | |
1199 | {\r | |
1200 | UINTN LocalDestinationSize;\r | |
1201 | UINTN LocalDestinationFinalSize;\r | |
1202 | \r | |
1203 | ASSERT(DestinationBuffer != NULL);\r | |
1204 | \r | |
1205 | if (SourceSize == 0 || SourceBuffer == NULL) {\r | |
1206 | return (*DestinationBuffer);\r | |
1207 | }\r | |
1208 | \r | |
1209 | if (DestinationSize == NULL) {\r | |
1210 | LocalDestinationSize = 0;\r | |
1211 | } else {\r | |
1212 | LocalDestinationSize = *DestinationSize;\r | |
1213 | }\r | |
1214 | \r | |
1215 | LocalDestinationFinalSize = LocalDestinationSize + SourceSize;\r | |
1216 | \r | |
1217 | if (DestinationSize != NULL) {\r | |
1218 | *DestinationSize = LocalDestinationSize;\r | |
1219 | }\r | |
1220 | \r | |
1221 | if (LocalDestinationSize == 0) {\r | |
1222 | // allcoate\r | |
1223 | *DestinationBuffer = AllocateZeroPool(LocalDestinationFinalSize);\r | |
1224 | } else {\r | |
1225 | // reallocate\r | |
1226 | *DestinationBuffer = ReallocatePool(LocalDestinationSize, LocalDestinationFinalSize, *DestinationBuffer);\r | |
1227 | }\r | |
1228 | \r | |
1229 | ASSERT(*DestinationBuffer != NULL);\r | |
1230 | \r | |
1231 | // copy\r | |
1232 | return (CopyMem(((UINT8*)(*DestinationBuffer)) + LocalDestinationSize, SourceBuffer, SourceSize));\r | |
1233 | }\r | |
1234 | \r | |
1235 | /**\r | |
1236 | Gets handles for any child devices produced by the passed in driver.\r | |
1237 | \r | |
1238 | @param[in] DriverHandle The handle of the driver.\r | |
1239 | @param[in] MatchingHandleCount Pointer to the number of handles in\r | |
1240 | MatchingHandleBuffer on return.\r | |
1241 | @param[out] MatchingHandleBuffer Buffer containing handles on a successful\r | |
1242 | return.\r | |
1243 | @retval EFI_SUCCESS The operation was sucessful.\r | |
1244 | @sa ParseHandleDatabaseByRelationship\r | |
1245 | **/\r | |
1246 | EFI_STATUS\r | |
1247 | EFIAPI\r | |
1248 | ParseHandleDatabaseForChildDevices(\r | |
1249 | IN CONST EFI_HANDLE DriverHandle,\r | |
1250 | IN UINTN *MatchingHandleCount,\r | |
1251 | OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r | |
1252 | )\r | |
1253 | {\r | |
1254 | EFI_HANDLE *Buffer;\r | |
1255 | EFI_HANDLE *Buffer2;\r | |
1256 | UINTN Count1;\r | |
1257 | UINTN Count2;\r | |
1258 | UINTN HandleIndex;\r | |
1259 | EFI_STATUS Status;\r | |
1260 | UINTN HandleBufferSize;\r | |
1261 | \r | |
1262 | ASSERT(MatchingHandleCount != NULL);\r | |
1263 | \r | |
1264 | HandleBufferSize = 0;\r | |
1265 | Buffer = NULL;\r | |
1266 | Buffer2 = NULL;\r | |
1267 | *MatchingHandleCount = 0;\r | |
1268 | \r | |
1269 | Status = PARSE_HANDLE_DATABASE_DEVICES (\r | |
1270 | DriverHandle,\r | |
1271 | &Count1,\r | |
1272 | &Buffer\r | |
1273 | );\r | |
1274 | if (!EFI_ERROR (Status)) {\r | |
1275 | for (HandleIndex = 0; HandleIndex < Count1; HandleIndex++) {\r | |
1276 | //\r | |
1277 | // now find the children\r | |
1278 | //\r | |
1279 | Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (\r | |
1280 | DriverHandle,\r | |
1281 | Buffer[HandleIndex],\r | |
1282 | &Count2,\r | |
1283 | &Buffer2\r | |
1284 | );\r | |
1285 | if (EFI_ERROR(Status)) {\r | |
1286 | break;\r | |
1287 | }\r | |
1288 | //\r | |
1289 | // save out required and optional data elements\r | |
1290 | //\r | |
1291 | *MatchingHandleCount += Count2;\r | |
1292 | if (MatchingHandleBuffer != NULL) {\r | |
1293 | *MatchingHandleBuffer = BuffernCatGrow((VOID**)MatchingHandleBuffer, &HandleBufferSize, Buffer2, Count2 * sizeof(Buffer2[0]));\r | |
1294 | }\r | |
1295 | \r | |
1296 | //\r | |
1297 | // free the memory\r | |
1298 | //\r | |
1299 | if (Buffer2 != NULL) {\r | |
1300 | FreePool(Buffer2);\r | |
1301 | }\r | |
1302 | }\r | |
1303 | }\r | |
1304 | \r | |
1305 | if (Buffer != NULL) {\r | |
1306 | FreePool(Buffer);\r | |
1307 | }\r | |
1308 | return (Status);\r | |
1309 | }\r | |
1310 | \r | |
1311 | /**\r | |
1312 | Function to get all handles that support a given protocol or all handles.\r | |
1313 | \r | |
1314 | @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL\r | |
1315 | then the function will return all handles.\r | |
1316 | \r | |
1317 | @retval NULL A memory allocation failed.\r | |
1318 | @return A NULL terminated list of handles.\r | |
1319 | **/\r | |
1320 | EFI_HANDLE*\r | |
1321 | EFIAPI\r | |
1322 | GetHandleListByProtocol (\r | |
1323 | IN CONST EFI_GUID *ProtocolGuid OPTIONAL\r | |
1324 | )\r | |
1325 | {\r | |
1326 | EFI_HANDLE *HandleList;\r | |
1327 | UINTN Size;\r | |
1328 | EFI_STATUS Status;\r | |
1329 | \r | |
1330 | Size = 0;\r | |
1331 | HandleList = NULL;\r | |
1332 | \r | |
1333 | //\r | |
1334 | // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!\r | |
1335 | //\r | |
1336 | if (ProtocolGuid == NULL) {\r | |
1337 | Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);\r | |
1338 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
1339 | HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));\r | |
1340 | if (HandleList == NULL) {\r | |
1341 | return (NULL);\r | |
1342 | }\r | |
1343 | Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);\r | |
1344 | HandleList[Size/sizeof(EFI_HANDLE)] = NULL;\r | |
1345 | }\r | |
1346 | } else {\r | |
1347 | Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);\r | |
1348 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
1349 | HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));\r | |
1350 | if (HandleList == NULL) {\r | |
1351 | return (NULL);\r | |
1352 | }\r | |
1353 | Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);\r | |
1354 | HandleList[Size/sizeof(EFI_HANDLE)] = NULL;\r | |
1355 | }\r | |
1356 | }\r | |
1357 | if (EFI_ERROR(Status)) {\r | |
1358 | if (HandleList != NULL) {\r | |
1359 | FreePool(HandleList);\r | |
1360 | }\r | |
1361 | return (NULL);\r | |
1362 | }\r | |
1363 | return (HandleList);\r | |
1364 | }\r | |
1365 | \r | |
1366 | /**\r | |
1367 | Function to get all handles that support some protocols.\r | |
1368 | \r | |
1369 | @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.\r | |
1370 | \r | |
1371 | @retval NULL A memory allocation failed.\r | |
1372 | @retval NULL ProtocolGuids was NULL.\r | |
1373 | @return A NULL terminated list of EFI_HANDLEs.\r | |
1374 | **/\r | |
1375 | EFI_HANDLE*\r | |
1376 | EFIAPI\r | |
1377 | GetHandleListByProtocolList (\r | |
1378 | IN CONST EFI_GUID **ProtocolGuids\r | |
1379 | )\r | |
1380 | {\r | |
1381 | EFI_HANDLE *HandleList;\r | |
1382 | UINTN Size;\r | |
1383 | UINTN TotalSize;\r | |
1384 | UINTN TempSize;\r | |
1385 | EFI_STATUS Status;\r | |
1386 | CONST EFI_GUID **GuidWalker;\r | |
1387 | EFI_HANDLE *HandleWalker1;\r | |
1388 | EFI_HANDLE *HandleWalker2;\r | |
1389 | \r | |
1390 | Size = 0;\r | |
1391 | HandleList = NULL;\r | |
1392 | TotalSize = sizeof(EFI_HANDLE);\r | |
1393 | \r | |
1394 | for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++,Size = 0){\r | |
1395 | Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &Size, NULL);\r | |
1396 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
1397 | TotalSize += Size;\r | |
1398 | }\r | |
1399 | }\r | |
1400 | \r | |
1401 | //\r | |
1402 | // No handles were found... \r | |
1403 | //\r | |
1404 | if (TotalSize == sizeof(EFI_HANDLE)) {\r | |
1405 | return (NULL);\r | |
1406 | }\r | |
1407 | \r | |
1408 | HandleList = AllocateZeroPool(TotalSize);\r | |
1409 | if (HandleList == NULL) {\r | |
1410 | return (NULL);\r | |
1411 | }\r | |
1412 | \r | |
1413 | Size = 0;\r | |
1414 | for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++){\r | |
1415 | TempSize = TotalSize - Size;\r | |
1416 | Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &TempSize, HandleList+(Size/sizeof(EFI_HANDLE)));\r | |
1417 | \r | |
1418 | //\r | |
1419 | // Allow for missing protocols... Only update the 'used' size upon success.\r | |
1420 | //\r | |
1421 | if (!EFI_ERROR(Status)) {\r | |
1422 | Size += TempSize;\r | |
1423 | }\r | |
1424 | }\r | |
1425 | ASSERT(HandleList[(TotalSize/sizeof(EFI_HANDLE))-1] == NULL);\r | |
1426 | \r | |
1427 | for (HandleWalker1 = HandleList ; HandleWalker1 != NULL && *HandleWalker1 != NULL ; HandleWalker1++) {\r | |
1428 | for (HandleWalker2 = HandleWalker1 + 1; HandleWalker2 != NULL && *HandleWalker2 != NULL ; HandleWalker2++) {\r | |
1429 | if (*HandleWalker1 == *HandleWalker2) {\r | |
1430 | //\r | |
1431 | // copy memory back 1 handle width.\r | |
1432 | //\r | |
1433 | CopyMem(HandleWalker2, HandleWalker2 + 1, TotalSize - ((HandleWalker2-HandleList+1)*sizeof(EFI_HANDLE)));\r | |
1434 | }\r | |
1435 | }\r | |
1436 | }\r | |
1437 | \r | |
1438 | return (HandleList);\r | |
1439 | }\r | |
1440 | \r | |
1441 | \r | |
1442 | \r | |
1443 | \r | |
1444 | \r | |
1445 | \r | |
1446 | \r | |
1447 | \r | |
1448 | \r | |
1449 | \r |