]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
acc8a29796bb9af24fcc6c8496513904f9e8eafd
[mirror_edk2.git] / ShellPkg / Library / UefiHandleParsingLib / UefiHandleParsingLib.c
1 /** @file
2 Provides interface to advanced shell functionality for parsing both handle and protocol database.
3
4 Copyright (c) 2013 - 2014, Hewlett-Packard Development Company, L.P.
5 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "UefiHandleParsingLib.h"
17 #include "IndustryStandard/Acpi10.h"
18
19 EFI_HANDLE mHandleParsingHiiHandle = NULL;
20 HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};
21 GUID_INFO_BLOCK *GuidList;
22 UINTN GuidListCount;
23 /**
24 Function to translate the EFI_MEMORY_TYPE into a string.
25
26 @param[in] Memory The memory type.
27
28 @retval A string representation of the type allocated from BS Pool.
29 **/
30 CHAR16*
31 EFIAPI
32 ConvertMemoryType (
33 IN CONST EFI_MEMORY_TYPE Memory
34 )
35 {
36 CHAR16 *RetVal;
37 RetVal = NULL;
38
39 switch (Memory) {
40 case EfiReservedMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiReservedMemoryType", 0); break;
41 case EfiLoaderCode: StrnCatGrow(&RetVal, NULL, L"EfiLoaderCode", 0); break;
42 case EfiLoaderData: StrnCatGrow(&RetVal, NULL, L"EfiLoaderData", 0); break;
43 case EfiBootServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesCode", 0); break;
44 case EfiBootServicesData: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesData", 0); break;
45 case EfiRuntimeServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesCode", 0); break;
46 case EfiRuntimeServicesData: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesData", 0); break;
47 case EfiConventionalMemory: StrnCatGrow(&RetVal, NULL, L"EfiConventionalMemory", 0); break;
48 case EfiUnusableMemory: StrnCatGrow(&RetVal, NULL, L"EfiUnusableMemory", 0); break;
49 case EfiACPIReclaimMemory: StrnCatGrow(&RetVal, NULL, L"EfiACPIReclaimMemory", 0); break;
50 case EfiACPIMemoryNVS: StrnCatGrow(&RetVal, NULL, L"EfiACPIMemoryNVS", 0); break;
51 case EfiMemoryMappedIO: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIO", 0); break;
52 case EfiMemoryMappedIOPortSpace: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIOPortSpace", 0); break;
53 case EfiPalCode: StrnCatGrow(&RetVal, NULL, L"EfiPalCode", 0); break;
54 case EfiMaxMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiMaxMemoryType", 0); break;
55 default: ASSERT(FALSE);
56 }
57 return (RetVal);
58 }
59
60 /**
61 Function to translate the EFI_GRAPHICS_PIXEL_FORMAT into a string.
62
63 @param[in] Fmt The format type.
64
65 @retval A string representation of the type allocated from BS Pool.
66 **/
67 CHAR16*
68 EFIAPI
69 ConvertPixelFormat (
70 IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt
71 )
72 {
73 CHAR16 *RetVal;
74 RetVal = NULL;
75
76 switch (Fmt) {
77 case PixelRedGreenBlueReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelRedGreenBlueReserved8BitPerColor", 0); break;
78 case PixelBlueGreenRedReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelBlueGreenRedReserved8BitPerColor", 0); break;
79 case PixelBitMask: StrnCatGrow(&RetVal, NULL, L"PixelBitMask", 0); break;
80 case PixelBltOnly: StrnCatGrow(&RetVal, NULL, L"PixelBltOnly", 0); break;
81 case PixelFormatMax: StrnCatGrow(&RetVal, NULL, L"PixelFormatMax", 0); break;
82 default: ASSERT(FALSE);
83 }
84 return (RetVal);
85 }
86
87 /**
88 Constructor for the library.
89
90 @param[in] ImageHandle Ignored.
91 @param[in] SystemTable Ignored.
92
93 @retval EFI_SUCCESS The operation was successful.
94 **/
95 EFI_STATUS
96 EFIAPI
97 HandleParsingLibConstructor (
98 IN EFI_HANDLE ImageHandle,
99 IN EFI_SYSTEM_TABLE *SystemTable
100 )
101 {
102 GuidListCount = 0;
103 GuidList = NULL;
104
105 //
106 // Do nothing with mHandleParsingHiiHandle. Initialize HII as needed.
107 //
108 return (EFI_SUCCESS);
109 }
110
111 /**
112 Initialization function for HII packages.
113
114 **/
115 VOID
116 HandleParsingHiiInit (VOID)
117 {
118 if (mHandleParsingHiiHandle == NULL) {
119 mHandleParsingHiiHandle = HiiAddPackages (&gHandleParsingHiiGuid, gImageHandle, UefiHandleParsingLibStrings, NULL);
120 ASSERT (mHandleParsingHiiHandle != NULL);
121 }
122 }
123
124 /**
125 Destructor for the library. free any resources.
126
127 @param[in] ImageHandle Ignored.
128 @param[in] SystemTable Ignored.
129
130 @retval EFI_SUCCESS The operation was successful.
131 **/
132 EFI_STATUS
133 EFIAPI
134 HandleParsingLibDestructor (
135 IN EFI_HANDLE ImageHandle,
136 IN EFI_SYSTEM_TABLE *SystemTable
137 )
138 {
139 UINTN LoopCount;
140
141 for (LoopCount = 0; GuidList != NULL && LoopCount < GuidListCount; LoopCount++) {
142 SHELL_FREE_NON_NULL(GuidList[LoopCount].GuidId);
143 }
144
145 SHELL_FREE_NON_NULL(GuidList);
146 if (mHandleParsingHiiHandle != NULL) {
147 HiiRemovePackages(mHandleParsingHiiHandle);
148 }
149 return (EFI_SUCCESS);
150 }
151
152 /**
153 Function to dump information about LoadedImage.
154
155 This will allocate the return buffer from boot services pool.
156
157 @param[in] TheHandle The handle that has LoadedImage installed.
158 @param[in] Verbose TRUE for additional information, FALSE otherwise.
159
160 @retval A poitner to a string containing the information.
161 **/
162 CHAR16*
163 EFIAPI
164 LoadedImageProtocolDumpInformation(
165 IN CONST EFI_HANDLE TheHandle,
166 IN CONST BOOLEAN Verbose
167 )
168 {
169 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
170 EFI_STATUS Status;
171 CHAR16 *RetVal;
172 CHAR16 *Temp;
173 CHAR16 *CodeType;
174 CHAR16 *DataType;
175
176 if (!Verbose) {
177 return (CatSPrint(NULL, L"LoadedImage"));
178 }
179
180 HandleParsingHiiInit();
181
182 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL);
183 RetVal = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));
184 if (Temp == NULL || RetVal == NULL) {
185 SHELL_FREE_NON_NULL(Temp);
186 SHELL_FREE_NON_NULL(RetVal);
187 return NULL;
188 }
189
190 Status = gBS->OpenProtocol (
191 TheHandle,
192 &gEfiLoadedImageProtocolGuid,
193 (VOID**)&LoadedImage,
194 gImageHandle,
195 NULL,
196 EFI_OPEN_PROTOCOL_GET_PROTOCOL
197 );
198
199 if (EFI_ERROR (Status)) {
200 SHELL_FREE_NON_NULL (Temp);
201 SHELL_FREE_NON_NULL (RetVal);
202 return NULL;
203 }
204
205 DataType = ConvertMemoryType(LoadedImage->ImageDataType);
206 CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);
207
208 RetVal = CatSPrint(RetVal,
209 Temp,
210 LoadedImage->Revision,
211 LoadedImage->ParentHandle,
212 LoadedImage->SystemTable,
213 LoadedImage->DeviceHandle,
214 LoadedImage->FilePath,
215 LoadedImage->LoadOptionsSize,
216 LoadedImage->LoadOptions,
217 LoadedImage->ImageBase,
218 LoadedImage->ImageSize,
219 CodeType,
220 DataType,
221 LoadedImage->Unload);
222
223
224 SHELL_FREE_NON_NULL(Temp);
225 SHELL_FREE_NON_NULL(CodeType);
226 SHELL_FREE_NON_NULL(DataType);
227
228 return RetVal;
229 }
230
231 /**
232 Function to dump information about GOP.
233
234 This will allocate the return buffer from boot services pool.
235
236 @param[in] TheHandle The handle that has LoadedImage installed.
237 @param[in] Verbose TRUE for additional information, FALSE otherwise.
238
239 @retval A poitner to a string containing the information.
240 **/
241 CHAR16*
242 EFIAPI
243 GraphicsOutputProtocolDumpInformation(
244 IN CONST EFI_HANDLE TheHandle,
245 IN CONST BOOLEAN Verbose
246 )
247 {
248 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
249 EFI_STATUS Status;
250 CHAR16 *RetVal;
251 CHAR16 *Temp;
252 CHAR16 *Fmt;
253
254 if (!Verbose) {
255 return (CatSPrint(NULL, L"GraphicsOutput"));
256 }
257
258 HandleParsingHiiInit();
259
260 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_GOP_DUMP_MAIN), NULL);
261 RetVal = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));
262 if (Temp == NULL || RetVal == NULL) {
263 SHELL_FREE_NON_NULL(Temp);
264 SHELL_FREE_NON_NULL(RetVal);
265 return NULL;
266 }
267
268 Status = gBS->OpenProtocol (
269 TheHandle,
270 &gEfiGraphicsOutputProtocolGuid,
271 (VOID**)&GraphicsOutput,
272 gImageHandle,
273 NULL,
274 EFI_OPEN_PROTOCOL_GET_PROTOCOL
275 );
276
277 if (EFI_ERROR (Status)) {
278 SHELL_FREE_NON_NULL (Temp);
279 SHELL_FREE_NON_NULL (RetVal);
280 return NULL;
281 }
282
283 Fmt = ConvertPixelFormat(GraphicsOutput->Mode->Info->PixelFormat);
284
285 RetVal = CatSPrint(RetVal,
286 Temp,
287 GraphicsOutput->Mode->MaxMode,
288 GraphicsOutput->Mode->Mode,
289 GraphicsOutput->Mode->FrameBufferBase,
290 (UINT64)GraphicsOutput->Mode->FrameBufferSize,
291 (UINT64)GraphicsOutput->Mode->SizeOfInfo,
292 GraphicsOutput->Mode->Info->Version,
293 GraphicsOutput->Mode->Info->HorizontalResolution,
294 GraphicsOutput->Mode->Info->VerticalResolution,
295 Fmt,
296 GraphicsOutput->Mode->Info->PixelsPerScanLine,
297 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.RedMask,
298 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.GreenMask,
299 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.BlueMask
300 );
301
302 SHELL_FREE_NON_NULL(Temp);
303 SHELL_FREE_NON_NULL(Fmt);
304
305 return RetVal;
306 }
307
308 /**
309 Function to dump information about PciRootBridgeIo.
310
311 This will allocate the return buffer from boot services pool.
312
313 @param[in] TheHandle The handle that has PciRootBridgeIo installed.
314 @param[in] Verbose TRUE for additional information, FALSE otherwise.
315
316 @retval A poitner to a string containing the information.
317 **/
318 CHAR16*
319 EFIAPI
320 PciRootBridgeIoDumpInformation(
321 IN CONST EFI_HANDLE TheHandle,
322 IN CONST BOOLEAN Verbose
323 )
324 {
325 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
326 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration;
327 UINT64 Supports;
328 UINT64 Attributes;
329 CHAR16 *Temp;
330 CHAR16 *Temp2;
331 CHAR16 *RetVal;
332 EFI_STATUS Status;
333
334 RetVal = NULL;
335
336 if (!Verbose) {
337 return (CatSPrint(NULL, L"PciRootBridgeIo"));
338 }
339
340 HandleParsingHiiInit();
341
342 Status = gBS->HandleProtocol(
343 TheHandle,
344 &gEfiPciRootBridgeIoProtocolGuid,
345 (VOID**)&PciRootBridgeIo);
346
347 if (EFI_ERROR(Status)) {
348 return NULL;
349 }
350
351 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_PH), NULL);
352 ASSERT (Temp != NULL);
353 Temp2 = CatSPrint(L"\r\n", Temp, PciRootBridgeIo->ParentHandle);
354 FreePool(Temp);
355 RetVal = Temp2;
356 Temp2 = NULL;
357
358 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SEG), NULL);
359 ASSERT (Temp != NULL);
360 Temp2 = CatSPrint(RetVal, Temp, PciRootBridgeIo->SegmentNumber);
361 FreePool(Temp);
362 FreePool(RetVal);
363 RetVal = Temp2;
364 Temp2 = NULL;
365
366 Supports = 0;
367 Attributes = 0;
368 Status = PciRootBridgeIo->GetAttributes (PciRootBridgeIo, &Supports, &Attributes);
369 if (!EFI_ERROR(Status)) {
370 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_ATT), NULL);
371 ASSERT (Temp != NULL);
372 Temp2 = CatSPrint(RetVal, Temp, Attributes);
373 FreePool(Temp);
374 FreePool(RetVal);
375 RetVal = Temp2;
376 Temp2 = NULL;
377
378 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS), NULL);
379 ASSERT (Temp != NULL);
380 Temp2 = CatSPrint(RetVal, Temp, Supports);
381 FreePool(Temp);
382 FreePool(RetVal);
383 RetVal = Temp2;
384 Temp2 = NULL;
385 }
386
387 Configuration = NULL;
388 Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Configuration);
389 if (!EFI_ERROR(Status) && Configuration != NULL) {
390 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_TITLE), NULL);
391 ASSERT (Temp != NULL);
392 Temp2 = CatSPrint(RetVal, Temp, Supports);
393 FreePool(Temp);
394 FreePool(RetVal);
395 RetVal = Temp2;
396 Temp2 = NULL;
397 while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
398 Temp = NULL;
399 switch (Configuration->ResType) {
400 case ACPI_ADDRESS_SPACE_TYPE_MEM:
401 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_MEM), NULL);
402 break;
403 case ACPI_ADDRESS_SPACE_TYPE_IO:
404 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_IO), NULL);
405 break;
406 case ACPI_ADDRESS_SPACE_TYPE_BUS:
407 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_BUS), NULL);
408 break;
409 }
410 if (Temp != NULL) {
411 Temp2 = CatSPrint(RetVal, L"%s", Temp);
412 FreePool(Temp);
413 FreePool(RetVal);
414 RetVal = Temp2;
415 Temp2 = NULL;
416 }
417
418 Temp2 = CatSPrint(RetVal,
419 L"%H%02x %016lx %016lx %02x%N\r\n",
420 Configuration->SpecificFlag,
421 Configuration->AddrRangeMin,
422 Configuration->AddrRangeMax,
423 Configuration->AddrSpaceGranularity
424 );
425 FreePool(RetVal);
426 RetVal = Temp2;
427 Temp2 = NULL;
428 Configuration++;
429 }
430 }
431 return (RetVal);
432 }
433
434 /**
435 Function to dump information about SimpleTextOut.
436
437 This will allocate the return buffer from boot services pool.
438
439 @param[in] TheHandle The handle that has SimpleTextOut installed.
440 @param[in] Verbose TRUE for additional information, FALSE otherwise.
441
442 @retval A poitner to a string containing the information.
443 **/
444 CHAR16*
445 EFIAPI
446 TxtOutProtocolDumpInformation(
447 IN CONST EFI_HANDLE TheHandle,
448 IN CONST BOOLEAN Verbose
449 )
450 {
451 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Dev;
452 INTN Index;
453 UINTN Col;
454 UINTN Row;
455 EFI_STATUS Status;
456 CHAR16 *RetVal;
457 UINTN Size;
458 CHAR16 *Temp;
459 UINTN NewSize;
460
461 if (!Verbose) {
462 return (NULL);
463 }
464
465 HandleParsingHiiInit();
466
467 RetVal = NULL;
468 Size = 0;
469
470 Status = gBS->HandleProtocol(
471 TheHandle,
472 &gEfiSimpleTextOutProtocolGuid,
473 (VOID**)&Dev);
474
475 ASSERT_EFI_ERROR(Status);
476 ASSERT (Dev != NULL && Dev->Mode != NULL);
477
478 Size = (Dev->Mode->MaxMode + 1) * 80;
479 RetVal = AllocateZeroPool(Size);
480
481 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER), NULL);
482 if (Temp != NULL) {
483 UnicodeSPrint(RetVal, Size, Temp, Dev, Dev->Mode->Attribute);
484 FreePool(Temp);
485 }
486
487 //
488 // Dump TextOut Info
489 //
490 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE), NULL);
491 for (Index = 0; Index < Dev->Mode->MaxMode; Index++) {
492 Status = Dev->QueryMode (Dev, Index, &Col, &Row);
493 NewSize = Size - StrSize(RetVal);
494 UnicodeSPrint(
495 RetVal + StrLen(RetVal),
496 NewSize,
497 Temp == NULL?L"":Temp,
498 Index == Dev->Mode->Mode ? L'*' : L' ',
499 Index,
500 !EFI_ERROR(Status)?(INTN)Col:-1,
501 !EFI_ERROR(Status)?(INTN)Row:-1
502 );
503 }
504 FreePool(Temp);
505 return (RetVal);
506 }
507
508 STATIC CONST UINTN VersionStringSize = 60;
509
510 /**
511 Function to dump information about EfiDriverSupportedEfiVersion protocol.
512
513 This will allocate the return buffer from boot services pool.
514
515 @param[in] TheHandle The handle that has the protocol installed.
516 @param[in] Verbose TRUE for additional information, FALSE otherwise.
517
518 @retval A poitner to a string containing the information.
519 **/
520 CHAR16*
521 EFIAPI
522 DriverEfiVersionProtocolDumpInformation(
523 IN CONST EFI_HANDLE TheHandle,
524 IN CONST BOOLEAN Verbose
525 )
526 {
527 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL *DriverEfiVersion;
528 EFI_STATUS Status;
529 CHAR16 *RetVal;
530
531 Status = gBS->HandleProtocol(
532 TheHandle,
533 &gEfiDriverSupportedEfiVersionProtocolGuid,
534 (VOID**)&DriverEfiVersion);
535
536 ASSERT_EFI_ERROR(Status);
537
538 RetVal = AllocateZeroPool(VersionStringSize);
539 ASSERT(RetVal != NULL);
540 UnicodeSPrint(RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion);
541 return (RetVal);
542 }
543
544 /**
545 Function to dump information about DevicePath protocol.
546
547 This will allocate the return buffer from boot services pool.
548
549 @param[in] TheHandle The handle that has the protocol installed.
550 @param[in] Verbose TRUE for additional information, FALSE otherwise.
551
552 @retval A poitner to a string containing the information.
553 **/
554 CHAR16*
555 EFIAPI
556 DevicePathProtocolDumpInformation(
557 IN CONST EFI_HANDLE TheHandle,
558 IN CONST BOOLEAN Verbose
559 )
560 {
561 EFI_DEVICE_PATH_PROTOCOL *DevPath;
562 CHAR16 *Temp;
563 CHAR16 *Temp2;
564 EFI_STATUS Status;
565 Temp = NULL;
566
567 Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
568 if (!EFI_ERROR(Status)) {
569 //
570 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
571 //
572 Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);
573 gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);
574 }
575 if (!Verbose && Temp != NULL && StrLen(Temp) > 30) {
576 Temp2 = NULL;
577 Temp2 = StrnCatGrow(&Temp2, NULL, Temp+(StrLen(Temp) - 30), 30);
578 FreePool(Temp);
579 Temp = Temp2;
580 }
581 return (Temp);
582 }
583
584 //
585 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
586 //
587 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
588 { \
589 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
590 }
591
592 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
593 { \
594 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
595 }
596
597 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
598 { \
599 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
600 }
601 STATIC CONST EFI_GUID WinNtThunkProtocolGuid = LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID;
602 STATIC CONST EFI_GUID WinNtIoProtocolGuid = LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID;
603 STATIC CONST EFI_GUID WinNtSerialPortGuid = LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID;
604
605 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT[] = {
606 {STRING_TOKEN(STR_WINNT_THUNK), (EFI_GUID*)&WinNtThunkProtocolGuid, NULL},
607 {STRING_TOKEN(STR_WINNT_DRIVER_IO), (EFI_GUID*)&WinNtIoProtocolGuid, NULL},
608 {STRING_TOKEN(STR_WINNT_SERIAL_PORT), (EFI_GUID*)&WinNtSerialPortGuid, NULL},
609 {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},
610 };
611
612 STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = {
613 {STRING_TOKEN(STR_LOADED_IMAGE), &gEfiLoadedImageProtocolGuid, LoadedImageProtocolDumpInformation},
614 {STRING_TOKEN(STR_DEVICE_PATH), &gEfiDevicePathProtocolGuid, DevicePathProtocolDumpInformation},
615 {STRING_TOKEN(STR_IMAGE_PATH), &gEfiLoadedImageDevicePathProtocolGuid, DevicePathProtocolDumpInformation},
616 {STRING_TOKEN(STR_DEVICE_PATH_UTIL), &gEfiDevicePathUtilitiesProtocolGuid, NULL},
617 {STRING_TOKEN(STR_DEVICE_PATH_TXT), &gEfiDevicePathToTextProtocolGuid, NULL},
618 {STRING_TOKEN(STR_DEVICE_PATH_FTXT), &gEfiDevicePathFromTextProtocolGuid, NULL},
619 {STRING_TOKEN(STR_DEVICE_PATH_PC), &gEfiPcAnsiGuid, NULL},
620 {STRING_TOKEN(STR_DEVICE_PATH_VT100), &gEfiVT100Guid, NULL},
621 {STRING_TOKEN(STR_DEVICE_PATH_VT100P), &gEfiVT100PlusGuid, NULL},
622 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8), &gEfiVTUTF8Guid, NULL},
623 {STRING_TOKEN(STR_DRIVER_BINDING), &gEfiDriverBindingProtocolGuid, NULL},
624 {STRING_TOKEN(STR_PLATFORM_OVERRIDE), &gEfiPlatformDriverOverrideProtocolGuid, NULL},
625 {STRING_TOKEN(STR_BUS_OVERRIDE), &gEfiBusSpecificDriverOverrideProtocolGuid, NULL},
626 {STRING_TOKEN(STR_DRIVER_DIAG), &gEfiDriverDiagnosticsProtocolGuid, NULL},
627 {STRING_TOKEN(STR_DRIVER_DIAG2), &gEfiDriverDiagnostics2ProtocolGuid, NULL},
628 {STRING_TOKEN(STR_DRIVER_CN), &gEfiComponentNameProtocolGuid, NULL},
629 {STRING_TOKEN(STR_DRIVER_CN2), &gEfiComponentName2ProtocolGuid, NULL},
630 {STRING_TOKEN(STR_PLAT_DRV_CFG), &gEfiPlatformToDriverConfigurationProtocolGuid, NULL},
631 {STRING_TOKEN(STR_DRIVER_VERSION), &gEfiDriverSupportedEfiVersionProtocolGuid, DriverEfiVersionProtocolDumpInformation},
632 {STRING_TOKEN(STR_TXT_IN), &gEfiSimpleTextInProtocolGuid, NULL},
633 {STRING_TOKEN(STR_TXT_IN_EX), &gEfiSimpleTextInputExProtocolGuid, NULL},
634 {STRING_TOKEN(STR_TXT_OUT), &gEfiSimpleTextOutProtocolGuid, TxtOutProtocolDumpInformation},
635 {STRING_TOKEN(STR_SIM_POINTER), &gEfiSimplePointerProtocolGuid, NULL},
636 {STRING_TOKEN(STR_ABS_POINTER), &gEfiAbsolutePointerProtocolGuid, NULL},
637 {STRING_TOKEN(STR_SERIAL_IO), &gEfiSerialIoProtocolGuid, NULL},
638 {STRING_TOKEN(STR_GRAPHICS_OUTPUT), &gEfiGraphicsOutputProtocolGuid, GraphicsOutputProtocolDumpInformation},
639 {STRING_TOKEN(STR_EDID_DISCOVERED), &gEfiEdidDiscoveredProtocolGuid, NULL},
640 {STRING_TOKEN(STR_EDID_ACTIVE), &gEfiEdidActiveProtocolGuid, NULL},
641 {STRING_TOKEN(STR_EDID_OVERRIDE), &gEfiEdidOverrideProtocolGuid, NULL},
642 {STRING_TOKEN(STR_CON_IN), &gEfiConsoleInDeviceGuid, NULL},
643 {STRING_TOKEN(STR_CON_OUT), &gEfiConsoleOutDeviceGuid, NULL},
644 {STRING_TOKEN(STR_STD_ERR), &gEfiStandardErrorDeviceGuid, NULL},
645 {STRING_TOKEN(STR_LOAD_FILE), &gEfiLoadFileProtocolGuid, NULL},
646 {STRING_TOKEN(STR_LOAD_FILE2), &gEfiLoadFile2ProtocolGuid, NULL},
647 {STRING_TOKEN(STR_SIMPLE_FILE_SYS), &gEfiSimpleFileSystemProtocolGuid, NULL},
648 {STRING_TOKEN(STR_TAPE_IO), &gEfiTapeIoProtocolGuid, NULL},
649 {STRING_TOKEN(STR_DISK_IO), &gEfiDiskIoProtocolGuid, NULL},
650 {STRING_TOKEN(STR_BLK_IO), &gEfiBlockIoProtocolGuid, NULL},
651 {STRING_TOKEN(STR_UC), &gEfiUnicodeCollationProtocolGuid, NULL},
652 {STRING_TOKEN(STR_UC2), &gEfiUnicodeCollation2ProtocolGuid, NULL},
653 {STRING_TOKEN(STR_PCIRB_IO), &gEfiPciRootBridgeIoProtocolGuid, PciRootBridgeIoDumpInformation},
654 {STRING_TOKEN(STR_PCI_IO), &gEfiPciIoProtocolGuid, NULL},
655 {STRING_TOKEN(STR_SCSI_PT), &gEfiScsiPassThruProtocolGuid, NULL},
656 {STRING_TOKEN(STR_SCSI_IO), &gEfiScsiIoProtocolGuid, NULL},
657 {STRING_TOKEN(STR_SCSI_PT_EXT), &gEfiExtScsiPassThruProtocolGuid, NULL},
658 {STRING_TOKEN(STR_ISCSI), &gEfiIScsiInitiatorNameProtocolGuid, NULL},
659 {STRING_TOKEN(STR_USB_IO), &gEfiUsbIoProtocolGuid, NULL},
660 {STRING_TOKEN(STR_USB_HC), &gEfiUsbHcProtocolGuid, NULL},
661 {STRING_TOKEN(STR_USB_HC2), &gEfiUsb2HcProtocolGuid, NULL},
662 {STRING_TOKEN(STR_DEBUG_SUPPORT), &gEfiDebugSupportProtocolGuid, NULL},
663 {STRING_TOKEN(STR_DEBUG_PORT), &gEfiDebugPortProtocolGuid, NULL},
664 {STRING_TOKEN(STR_DECOMPRESS), &gEfiDecompressProtocolGuid, NULL},
665 {STRING_TOKEN(STR_ACPI_TABLE), &gEfiAcpiTableProtocolGuid, NULL},
666 {STRING_TOKEN(STR_EBC_INTERPRETER), &gEfiEbcProtocolGuid, NULL},
667 {STRING_TOKEN(STR_SNP), &gEfiSimpleNetworkProtocolGuid, NULL},
668 {STRING_TOKEN(STR_NII), &gEfiNetworkInterfaceIdentifierProtocolGuid, NULL},
669 {STRING_TOKEN(STR_NII_31), &gEfiNetworkInterfaceIdentifierProtocolGuid_31, NULL},
670 {STRING_TOKEN(STR_PXE_BC), &gEfiPxeBaseCodeProtocolGuid, NULL},
671 {STRING_TOKEN(STR_PXE_CB), &gEfiPxeBaseCodeCallbackProtocolGuid, NULL},
672 {STRING_TOKEN(STR_BIS), &gEfiBisProtocolGuid, NULL},
673 {STRING_TOKEN(STR_MNP_SB), &gEfiManagedNetworkServiceBindingProtocolGuid, NULL},
674 {STRING_TOKEN(STR_MNP), &gEfiManagedNetworkProtocolGuid, NULL},
675 {STRING_TOKEN(STR_ARP_SB), &gEfiArpServiceBindingProtocolGuid, NULL},
676 {STRING_TOKEN(STR_ARP), &gEfiArpProtocolGuid, NULL},
677 {STRING_TOKEN(STR_DHCPV4_SB), &gEfiDhcp4ServiceBindingProtocolGuid, NULL},
678 {STRING_TOKEN(STR_DHCPV4), &gEfiDhcp4ProtocolGuid, NULL},
679 {STRING_TOKEN(STR_TCPV4_SB), &gEfiTcp4ServiceBindingProtocolGuid, NULL},
680 {STRING_TOKEN(STR_TCPV4), &gEfiTcp4ProtocolGuid, NULL},
681 {STRING_TOKEN(STR_IPV4_SB), &gEfiIp4ServiceBindingProtocolGuid, NULL},
682 {STRING_TOKEN(STR_IPV4), &gEfiIp4ProtocolGuid, NULL},
683 {STRING_TOKEN(STR_IPV4_CFG), &gEfiIp4ConfigProtocolGuid, NULL},
684 {STRING_TOKEN(STR_UDPV4_SB), &gEfiUdp4ServiceBindingProtocolGuid, NULL},
685 {STRING_TOKEN(STR_UDPV4), &gEfiUdp4ProtocolGuid, NULL},
686 {STRING_TOKEN(STR_MTFTPV4_SB), &gEfiMtftp4ServiceBindingProtocolGuid, NULL},
687 {STRING_TOKEN(STR_MTFTPV4), &gEfiMtftp4ProtocolGuid, NULL},
688 {STRING_TOKEN(STR_AUTH_INFO), &gEfiAuthenticationInfoProtocolGuid, NULL},
689 {STRING_TOKEN(STR_HASH_SB), &gEfiHashServiceBindingProtocolGuid, NULL},
690 {STRING_TOKEN(STR_HASH), &gEfiHashProtocolGuid, NULL},
691 {STRING_TOKEN(STR_HII_FONT), &gEfiHiiFontProtocolGuid, NULL},
692 {STRING_TOKEN(STR_HII_STRING), &gEfiHiiStringProtocolGuid, NULL},
693 {STRING_TOKEN(STR_HII_IMAGE), &gEfiHiiImageProtocolGuid, NULL},
694 {STRING_TOKEN(STR_HII_DATABASE), &gEfiHiiDatabaseProtocolGuid, NULL},
695 {STRING_TOKEN(STR_HII_CONFIG_ROUT), &gEfiHiiConfigRoutingProtocolGuid, NULL},
696 {STRING_TOKEN(STR_HII_CONFIG_ACC), &gEfiHiiConfigAccessProtocolGuid, NULL},
697 {STRING_TOKEN(STR_HII_FORM_BROWSER2), &gEfiFormBrowser2ProtocolGuid, NULL},
698 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE), &gEfiDriverFamilyOverrideProtocolGuid, NULL},
699 {STRING_TOKEN(STR_PCD), &gPcdProtocolGuid, NULL},
700 {STRING_TOKEN(STR_TCG), &gEfiTcgProtocolGuid, NULL},
701 {STRING_TOKEN(STR_HII_PACKAGE_LIST), &gEfiHiiPackageListProtocolGuid, NULL},
702
703 //
704 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
705 //
706 {STRING_TOKEN(STR_SHELL_INTERFACE), &gEfiShellInterfaceGuid, NULL},
707 {STRING_TOKEN(STR_SHELL_ENV2), &gEfiShellEnvironment2Guid, NULL},
708 {STRING_TOKEN(STR_SHELL_ENV), &gEfiShellEnvironment2Guid, NULL},
709 {STRING_TOKEN(STR_DEVICE_IO), &gEfiDeviceIoProtocolGuid, NULL},
710 {STRING_TOKEN(STR_UGA_DRAW), &gEfiUgaDrawProtocolGuid, NULL},
711 {STRING_TOKEN(STR_UGA_IO), &gEfiUgaIoProtocolGuid, NULL},
712 {STRING_TOKEN(STR_ESP), &gEfiPartTypeSystemPartGuid, NULL},
713 {STRING_TOKEN(STR_GPT_NBR), &gEfiPartTypeLegacyMbrGuid, NULL},
714 {STRING_TOKEN(STR_DRIVER_CONFIG), &gEfiDriverConfigurationProtocolGuid, NULL},
715 {STRING_TOKEN(STR_DRIVER_CONFIG2), &gEfiDriverConfiguration2ProtocolGuid, NULL},
716
717 //
718 // the ones under this are GUID identified structs, not protocols
719 //
720 {STRING_TOKEN(STR_FILE_INFO), &gEfiFileInfoGuid, NULL},
721 {STRING_TOKEN(STR_FILE_SYS_INFO), &gEfiFileSystemInfoGuid, NULL},
722
723 //
724 // the ones under this are misc GUIDS.
725 //
726 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE), &gEfiGlobalVariableGuid, NULL},
727
728 //
729 // UEFI 2.2
730 //
731 {STRING_TOKEN(STR_IP6_SB), &gEfiIp6ServiceBindingProtocolGuid, NULL},
732 {STRING_TOKEN(STR_IP6), &gEfiIp6ProtocolGuid, NULL},
733 {STRING_TOKEN(STR_IP6_CONFIG), &gEfiIp6ConfigProtocolGuid, NULL},
734 {STRING_TOKEN(STR_MTFTP6_SB), &gEfiMtftp6ServiceBindingProtocolGuid, NULL},
735 {STRING_TOKEN(STR_MTFTP6), &gEfiMtftp6ProtocolGuid, NULL},
736 {STRING_TOKEN(STR_DHCP6_SB), &gEfiDhcp6ServiceBindingProtocolGuid, NULL},
737 {STRING_TOKEN(STR_DHCP6), &gEfiDhcp6ProtocolGuid, NULL},
738 {STRING_TOKEN(STR_UDP6_SB), &gEfiUdp6ServiceBindingProtocolGuid, NULL},
739 {STRING_TOKEN(STR_UDP6), &gEfiUdp6ProtocolGuid, NULL},
740 {STRING_TOKEN(STR_TCP6_SB), &gEfiTcp6ServiceBindingProtocolGuid, NULL},
741 {STRING_TOKEN(STR_TCP6), &gEfiTcp6ProtocolGuid, NULL},
742 {STRING_TOKEN(STR_VLAN_CONFIG), &gEfiVlanConfigProtocolGuid, NULL},
743 {STRING_TOKEN(STR_EAP), &gEfiEapProtocolGuid, NULL},
744 {STRING_TOKEN(STR_EAP_MGMT), &gEfiEapManagementProtocolGuid, NULL},
745 {STRING_TOKEN(STR_FTP4_SB), &gEfiFtp4ServiceBindingProtocolGuid, NULL},
746 {STRING_TOKEN(STR_FTP4), &gEfiFtp4ProtocolGuid, NULL},
747 {STRING_TOKEN(STR_IP_SEC_CONFIG), &gEfiIpSecConfigProtocolGuid, NULL},
748 {STRING_TOKEN(STR_DH), &gEfiDriverHealthProtocolGuid, NULL},
749 {STRING_TOKEN(STR_DEF_IMG_LOAD), &gEfiDeferredImageLoadProtocolGuid, NULL},
750 {STRING_TOKEN(STR_USER_CRED), &gEfiUserCredentialProtocolGuid, NULL},
751 {STRING_TOKEN(STR_USER_MNGR), &gEfiUserManagerProtocolGuid, NULL},
752 {STRING_TOKEN(STR_ATA_PASS_THRU), &gEfiAtaPassThruProtocolGuid, NULL},
753
754 //
755 // UEFI 2.3
756 //
757 {STRING_TOKEN(STR_FW_MGMT), &gEfiFirmwareManagementProtocolGuid, NULL},
758 {STRING_TOKEN(STR_IP_SEC), &gEfiIpSecProtocolGuid, NULL},
759 {STRING_TOKEN(STR_IP_SEC2), &gEfiIpSec2ProtocolGuid, NULL},
760
761 //
762 // UEFI 2.3.1
763 //
764 {STRING_TOKEN(STR_KMS), &gEfiKmsProtocolGuid, NULL},
765 {STRING_TOKEN(STR_BLK_IO2), &gEfiBlockIo2ProtocolGuid, NULL},
766 {STRING_TOKEN(STR_SSC), &gEfiStorageSecurityCommandProtocolGuid, NULL},
767 {STRING_TOKEN(STR_UCRED2), &gEfiUserCredential2ProtocolGuid, NULL},
768
769 //
770 // UEFI 2.4
771 //
772 {STRING_TOKEN(STR_DISK_IO2), &gEfiDiskIo2ProtocolGuid, NULL},
773 {STRING_TOKEN(STR_ADAPTER_INFO), &gEfiAdapterInformationProtocolGuid, NULL},
774
775 //
776 // PI Spec ones
777 //
778 {STRING_TOKEN(STR_IDE_CONT_INIT), &gEfiIdeControllerInitProtocolGuid, NULL},
779
780 //
781 // UEFI Shell Spec 2.0
782 //
783 {STRING_TOKEN(STR_SHELL_PARAMETERS), &gEfiShellParametersProtocolGuid, NULL},
784 {STRING_TOKEN(STR_SHELL), &gEfiShellProtocolGuid, NULL},
785
786 //
787 // UEFI Shell Spec 2.1
788 //
789 {STRING_TOKEN(STR_SHELL_DYNAMIC), &gEfiShellDynamicCommandProtocolGuid, NULL},
790
791 //
792 // terminator
793 //
794 {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},
795 };
796
797 /**
798 Function to get the node for a protocol or struct from it's GUID.
799
800 if Guid is NULL, then ASSERT.
801
802 @param[in] Guid The GUID to look for the name of.
803
804 @return The node.
805 **/
806 CONST GUID_INFO_BLOCK *
807 EFIAPI
808 InternalShellGetNodeFromGuid(
809 IN CONST EFI_GUID* Guid
810 )
811 {
812 CONST GUID_INFO_BLOCK *ListWalker;
813 UINTN LoopCount;
814
815 ASSERT(Guid != NULL);
816
817 for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {
818 if (CompareGuid(ListWalker->GuidId, Guid)) {
819 return (ListWalker);
820 }
821 }
822
823 if (PcdGetBool(PcdShellIncludeNtGuids)) {
824 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
825 if (CompareGuid(ListWalker->GuidId, Guid)) {
826 return (ListWalker);
827 }
828 }
829 }
830 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
831 if (CompareGuid(ListWalker->GuidId, Guid)) {
832 return (ListWalker);
833 }
834 }
835 return (NULL);
836 }
837
838 /**
839 Function to add a new GUID/Name mapping.
840
841 @param[in] Guid The Guid
842 @param[in] NameID The STRING id of the HII string to use
843 @param[in] DumpFunc The pointer to the dump function
844
845
846 @retval EFI_SUCCESS The operation was sucessful
847 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
848 @retval EFI_INVALID_PARAMETER Guid NameId was invalid
849 **/
850 STATIC
851 EFI_STATUS
852 EFIAPI
853 InsertNewGuidNameMapping(
854 IN CONST EFI_GUID *Guid,
855 IN CONST EFI_STRING_ID NameID,
856 IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
857 )
858 {
859 ASSERT(Guid != NULL);
860 ASSERT(NameID != 0);
861
862 GuidList = ReallocatePool(GuidListCount * sizeof(GUID_INFO_BLOCK), GuidListCount+1 * sizeof(GUID_INFO_BLOCK), GuidList);
863 if (GuidList == NULL) {
864 GuidListCount = 0;
865 return (EFI_OUT_OF_RESOURCES);
866 }
867 GuidListCount++;
868
869 GuidList[GuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid);
870 GuidList[GuidListCount - 1].StringId = NameID;
871 GuidList[GuidListCount - 1].DumpInfo = DumpFunc;
872
873 if (GuidList[GuidListCount - 1].GuidId == NULL) {
874 return (EFI_OUT_OF_RESOURCES);
875 }
876
877 return (EFI_SUCCESS);
878 }
879
880 /**
881 Function to add a new GUID/Name mapping.
882
883 This cannot overwrite an existing mapping.
884
885 @param[in] Guid The Guid
886 @param[in] TheName The Guid's name
887 @param[in] Lang RFC4646 language code list or NULL
888
889 @retval EFI_SUCCESS The operation was sucessful
890 @retval EFI_ACCESS_DENIED There was a duplicate
891 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
892 @retval EFI_INVALID_PARAMETER Guid or TheName was NULL
893 **/
894 EFI_STATUS
895 EFIAPI
896 AddNewGuidNameMapping(
897 IN CONST EFI_GUID *Guid,
898 IN CONST CHAR16 *TheName,
899 IN CONST CHAR8 *Lang OPTIONAL
900 )
901 {
902 CONST GUID_INFO_BLOCK *Temp;
903 EFI_STRING_ID NameID;
904
905 HandleParsingHiiInit();
906
907 if (Guid == NULL || TheName == NULL){
908 return (EFI_INVALID_PARAMETER);
909 }
910
911 if ((Temp = InternalShellGetNodeFromGuid(Guid)) != NULL) {
912 return (EFI_ACCESS_DENIED);
913 }
914
915 NameID = HiiSetString(mHandleParsingHiiHandle, 0, (CHAR16*)TheName, Lang);
916 if (NameID == 0) {
917 return (EFI_OUT_OF_RESOURCES);
918 }
919
920 return (InsertNewGuidNameMapping(Guid, NameID, NULL));
921 }
922
923 /**
924 Function to get the name of a protocol or struct from it's GUID.
925
926 if Guid is NULL, then ASSERT.
927
928 @param[in] Guid The GUID to look for the name of.
929 @param[in] Lang The language to use.
930
931 @return pointer to string of the name. The caller
932 is responsible to free this memory.
933 **/
934 CHAR16*
935 EFIAPI
936 GetStringNameFromGuid(
937 IN CONST EFI_GUID *Guid,
938 IN CONST CHAR8 *Lang OPTIONAL
939 )
940 {
941 CONST GUID_INFO_BLOCK *Id;
942
943 HandleParsingHiiInit();
944
945 Id = InternalShellGetNodeFromGuid(Guid);
946 return (HiiGetString(mHandleParsingHiiHandle, Id==NULL?STRING_TOKEN(STR_UNKNOWN_DEVICE):Id->StringId, Lang));
947 }
948
949 /**
950 Function to dump protocol information from a handle.
951
952 This function will return a allocated string buffer containing the
953 information. The caller is responsible for freeing the memory.
954
955 If Guid is NULL, ASSERT().
956 If TheHandle is NULL, ASSERT().
957
958 @param[in] TheHandle The handle to dump information from.
959 @param[in] Guid The GUID of the protocol to dump.
960 @param[in] Verbose TRUE for extra info. FALSE otherwise.
961
962 @return The pointer to string.
963 @retval NULL An error was encountered.
964 **/
965 CHAR16*
966 EFIAPI
967 GetProtocolInformationDump(
968 IN CONST EFI_HANDLE TheHandle,
969 IN CONST EFI_GUID *Guid,
970 IN CONST BOOLEAN Verbose
971 )
972 {
973 CONST GUID_INFO_BLOCK *Id;
974
975 ASSERT(TheHandle != NULL);
976 ASSERT(Guid != NULL);
977
978 if (TheHandle == NULL || Guid == NULL) {
979 return (NULL);
980 }
981
982 Id = InternalShellGetNodeFromGuid(Guid);
983 if (Id != NULL && Id->DumpInfo != NULL) {
984 return (Id->DumpInfo(TheHandle, Verbose));
985 }
986 return (NULL);
987 }
988
989 /**
990 Function to get the Guid for a protocol or struct based on it's string name.
991
992 do not modify the returned Guid.
993
994 @param[in] Name The pointer to the string name.
995 @param[in] Lang The pointer to the language code.
996 @param[out] Guid The pointer to the Guid.
997
998 @retval EFI_SUCCESS The operation was sucessful.
999 **/
1000 EFI_STATUS
1001 EFIAPI
1002 GetGuidFromStringName(
1003 IN CONST CHAR16 *Name,
1004 IN CONST CHAR8 *Lang OPTIONAL,
1005 OUT EFI_GUID **Guid
1006 )
1007 {
1008 CONST GUID_INFO_BLOCK *ListWalker;
1009 CHAR16 *String;
1010 UINTN LoopCount;
1011
1012 HandleParsingHiiInit();
1013
1014 ASSERT(Guid != NULL);
1015 if (Guid == NULL) {
1016 return (EFI_INVALID_PARAMETER);
1017 }
1018 *Guid = NULL;
1019
1020 if (PcdGetBool(PcdShellIncludeNtGuids)) {
1021 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
1022 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
1023 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
1024 *Guid = ListWalker->GuidId;
1025 }
1026 SHELL_FREE_NON_NULL(String);
1027 if (*Guid != NULL) {
1028 return (EFI_SUCCESS);
1029 }
1030 }
1031 }
1032 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
1033 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
1034 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
1035 *Guid = ListWalker->GuidId;
1036 }
1037 SHELL_FREE_NON_NULL(String);
1038 if (*Guid != NULL) {
1039 return (EFI_SUCCESS);
1040 }
1041 }
1042
1043 for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {
1044 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
1045 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
1046 *Guid = ListWalker->GuidId;
1047 }
1048 SHELL_FREE_NON_NULL(String);
1049 if (*Guid != NULL) {
1050 return (EFI_SUCCESS);
1051 }
1052 }
1053
1054 return (EFI_NOT_FOUND);
1055 }
1056
1057 /**
1058 Get best support language for this driver.
1059
1060 First base on the user input language to search, second base on the current
1061 platform used language to search, third get the first language from the
1062 support language list. The caller need to free the buffer of the best language.
1063
1064 @param[in] SupportedLanguages The support languages for this driver.
1065 @param[in] InputLanguage The user input language.
1066 @param[in] Iso639Language Whether get language for ISO639.
1067
1068 @return The best support language for this driver.
1069 **/
1070 CHAR8 *
1071 EFIAPI
1072 GetBestLanguageForDriver (
1073 IN CONST CHAR8 *SupportedLanguages,
1074 IN CONST CHAR8 *InputLanguage,
1075 IN BOOLEAN Iso639Language
1076 )
1077 {
1078 CHAR8 *LanguageVariable;
1079 CHAR8 *BestLanguage;
1080
1081 LanguageVariable = GetVariable (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid);
1082
1083 BestLanguage = GetBestLanguage(
1084 SupportedLanguages,
1085 Iso639Language,
1086 (InputLanguage != NULL) ? InputLanguage : "",
1087 (LanguageVariable != NULL) ? LanguageVariable : "",
1088 SupportedLanguages,
1089 NULL
1090 );
1091
1092 if (LanguageVariable != NULL) {
1093 FreePool (LanguageVariable);
1094 }
1095
1096 return BestLanguage;
1097 }
1098
1099 /**
1100 Function to retrieve the driver name (if possible) from the ComponentName or
1101 ComponentName2 protocol
1102
1103 @param[in] TheHandle The driver handle to get the name of.
1104 @param[in] Language The language to use.
1105
1106 @retval NULL The name could not be found.
1107 @return A pointer to the string name. Do not de-allocate the memory.
1108 **/
1109 CONST CHAR16*
1110 EFIAPI
1111 GetStringNameFromHandle(
1112 IN CONST EFI_HANDLE TheHandle,
1113 IN CONST CHAR8 *Language
1114 )
1115 {
1116 EFI_COMPONENT_NAME2_PROTOCOL *CompNameStruct;
1117 EFI_STATUS Status;
1118 CHAR16 *RetVal;
1119 CHAR8 *BestLang;
1120
1121 BestLang = NULL;
1122
1123 Status = gBS->OpenProtocol(
1124 TheHandle,
1125 &gEfiComponentName2ProtocolGuid,
1126 (VOID**)&CompNameStruct,
1127 gImageHandle,
1128 NULL,
1129 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
1130 if (!EFI_ERROR(Status)) {
1131 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
1132 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
1133 if (BestLang != NULL) {
1134 FreePool (BestLang);
1135 BestLang = NULL;
1136 }
1137 if (!EFI_ERROR(Status)) {
1138 return (RetVal);
1139 }
1140 }
1141 Status = gBS->OpenProtocol(
1142 TheHandle,
1143 &gEfiComponentNameProtocolGuid,
1144 (VOID**)&CompNameStruct,
1145 gImageHandle,
1146 NULL,
1147 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
1148 if (!EFI_ERROR(Status)) {
1149 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
1150 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
1151 if (BestLang != NULL) {
1152 FreePool (BestLang);
1153 }
1154 if (!EFI_ERROR(Status)) {
1155 return (RetVal);
1156 }
1157 }
1158 return (NULL);
1159 }
1160
1161 /**
1162 Function to initialize the file global mHandleList object for use in
1163 vonverting handles to index and index to handle.
1164
1165 @retval EFI_SUCCESS The operation was successful.
1166 **/
1167 EFI_STATUS
1168 EFIAPI
1169 InternalShellInitHandleList(
1170 VOID
1171 )
1172 {
1173 EFI_STATUS Status;
1174 EFI_HANDLE *HandleBuffer;
1175 UINTN HandleCount;
1176 HANDLE_LIST *ListWalker;
1177
1178 if (mHandleList.NextIndex != 0) {
1179 return EFI_SUCCESS;
1180 }
1181 InitializeListHead(&mHandleList.List.Link);
1182 mHandleList.NextIndex = 1;
1183 Status = gBS->LocateHandleBuffer (
1184 AllHandles,
1185 NULL,
1186 NULL,
1187 &HandleCount,
1188 &HandleBuffer
1189 );
1190 ASSERT_EFI_ERROR(Status);
1191 if (EFI_ERROR(Status)) {
1192 return (Status);
1193 }
1194 for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){
1195 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
1196 ASSERT(ListWalker != NULL);
1197 ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex-1];
1198 ListWalker->TheIndex = mHandleList.NextIndex;
1199 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);
1200 }
1201 FreePool(HandleBuffer);
1202 return (EFI_SUCCESS);
1203 }
1204
1205 /**
1206 Function to retrieve the human-friendly index of a given handle. If the handle
1207 does not have a index one will be automatically assigned. The index value is valid
1208 until the termination of the shell application.
1209
1210 @param[in] TheHandle The handle to retrieve an index for.
1211
1212 @retval 0 A memory allocation failed.
1213 @return The index of the handle.
1214
1215 **/
1216 UINTN
1217 EFIAPI
1218 ConvertHandleToHandleIndex(
1219 IN CONST EFI_HANDLE TheHandle
1220 )
1221 {
1222 EFI_STATUS Status;
1223 EFI_GUID **ProtocolBuffer;
1224 UINTN ProtocolCount;
1225 HANDLE_LIST *ListWalker;
1226
1227 if (TheHandle == NULL) {
1228 return 0;
1229 }
1230
1231 InternalShellInitHandleList();
1232
1233 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
1234 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
1235 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
1236 ){
1237 if (ListWalker->TheHandle == TheHandle) {
1238 //
1239 // Verify that TheHandle is still present in the Handle Database
1240 //
1241 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
1242 if (EFI_ERROR (Status)) {
1243 //
1244 // TheHandle is not present in the Handle Database, so delete from the handle list
1245 //
1246 RemoveEntryList (&ListWalker->Link);
1247 return 0;
1248 }
1249 FreePool (ProtocolBuffer);
1250 return (ListWalker->TheIndex);
1251 }
1252 }
1253
1254 //
1255 // Verify that TheHandle is valid handle
1256 //
1257 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
1258 if (EFI_ERROR (Status)) {
1259 //
1260 // TheHandle is not valid, so do not add to handle list
1261 //
1262 return 0;
1263 }
1264 FreePool (ProtocolBuffer);
1265
1266 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
1267 ASSERT(ListWalker != NULL);
1268 ListWalker->TheHandle = TheHandle;
1269 ListWalker->TheIndex = mHandleList.NextIndex++;
1270 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);
1271 return (ListWalker->TheIndex);
1272 }
1273
1274
1275
1276 /**
1277 Function to retrieve the EFI_HANDLE from the human-friendly index.
1278
1279 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
1280
1281 @retval NULL The index was invalid.
1282 @return The EFI_HANDLE that index represents.
1283
1284 **/
1285 EFI_HANDLE
1286 EFIAPI
1287 ConvertHandleIndexToHandle(
1288 IN CONST UINTN TheIndex
1289 )
1290 {
1291 EFI_STATUS Status;
1292 EFI_GUID **ProtocolBuffer;
1293 UINTN ProtocolCount;
1294 HANDLE_LIST *ListWalker;
1295
1296 InternalShellInitHandleList();
1297
1298 if (TheIndex >= mHandleList.NextIndex) {
1299 return NULL;
1300 }
1301
1302 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
1303 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
1304 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
1305 ){
1306 if (ListWalker->TheIndex == TheIndex && ListWalker->TheHandle != NULL) {
1307 //
1308 // Verify that LinkWalker->TheHandle is valid handle
1309 //
1310 Status = gBS->ProtocolsPerHandle(ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);
1311 if (EFI_ERROR (Status)) {
1312 //
1313 // TheHandle is not valid, so do not add to handle list
1314 //
1315 ListWalker->TheHandle = NULL;
1316 }
1317 return (ListWalker->TheHandle);
1318 }
1319 }
1320 return NULL;
1321 }
1322
1323 /**
1324 Gets all the related EFI_HANDLEs based on the mask supplied.
1325
1326 This function scans all EFI_HANDLES in the UEFI environment's handle database
1327 and returns the ones with the specified relationship (Mask) to the specified
1328 controller handle.
1329
1330 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1331 If MatchingHandleCount is NULL, then ASSERT.
1332
1333 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
1334 caller freed.
1335
1336 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
1337 @param[in] ControllerHandle The handle with Device Path protocol on it.
1338 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
1339 MatchingHandleBuffer.
1340 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
1341 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
1342 @param[out] HandleType An array of type information.
1343
1344 @retval EFI_SUCCESS The operation was successful, and any related handles
1345 are in MatchingHandleBuffer.
1346 @retval EFI_NOT_FOUND No matching handles were found.
1347 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1348 **/
1349 EFI_STATUS
1350 EFIAPI
1351 ParseHandleDatabaseByRelationshipWithType (
1352 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
1353 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
1354 IN UINTN *HandleCount,
1355 OUT EFI_HANDLE **HandleBuffer,
1356 OUT UINTN **HandleType
1357 )
1358 {
1359 EFI_STATUS Status;
1360 UINTN HandleIndex;
1361 EFI_GUID **ProtocolGuidArray;
1362 UINTN ArrayCount;
1363 UINTN ProtocolIndex;
1364 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
1365 UINTN OpenInfoCount;
1366 UINTN OpenInfoIndex;
1367 UINTN ChildIndex;
1368 INTN DriverBindingHandleIndex;
1369
1370 ASSERT(HandleCount != NULL);
1371 ASSERT(HandleBuffer != NULL);
1372 ASSERT(HandleType != NULL);
1373 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
1374
1375 *HandleCount = 0;
1376 *HandleBuffer = NULL;
1377 *HandleType = NULL;
1378
1379 //
1380 // Retrieve the list of all handles from the handle database
1381 //
1382 Status = gBS->LocateHandleBuffer (
1383 AllHandles,
1384 NULL,
1385 NULL,
1386 HandleCount,
1387 HandleBuffer
1388 );
1389 if (EFI_ERROR (Status)) {
1390 return (Status);
1391 }
1392
1393 *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));
1394 ASSERT(*HandleType != NULL);
1395
1396 DriverBindingHandleIndex = -1;
1397 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
1398 if (DriverBindingHandle != NULL && (*HandleBuffer)[HandleIndex] == DriverBindingHandle) {
1399 DriverBindingHandleIndex = (INTN)HandleIndex;
1400 }
1401 }
1402
1403 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
1404 //
1405 // Retrieve the list of all the protocols on each handle
1406 //
1407 Status = gBS->ProtocolsPerHandle (
1408 (*HandleBuffer)[HandleIndex],
1409 &ProtocolGuidArray,
1410 &ArrayCount
1411 );
1412 if (EFI_ERROR (Status)) {
1413 continue;
1414 }
1415
1416 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
1417
1418 //
1419 // Set the bit describing what this handle has
1420 //
1421 if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) ) {
1422 (*HandleType)[HandleIndex] |= (UINTN)HR_IMAGE_HANDLE;
1423 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) ) {
1424 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_BINDING_HANDLE;
1425 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {
1426 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
1427 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {
1428 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
1429 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) ) {
1430 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
1431 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) ) {
1432 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
1433 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) ) {
1434 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
1435 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) ) {
1436 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
1437 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) ) {
1438 (*HandleType)[HandleIndex] |= (UINTN)HR_DEVICE_HANDLE;
1439 } else {
1440 DEBUG_CODE_BEGIN();
1441 ASSERT((*HandleType)[HandleIndex] == (*HandleType)[HandleIndex]);
1442 DEBUG_CODE_END();
1443 }
1444 //
1445 // Retrieve the list of agents that have opened each protocol
1446 //
1447 Status = gBS->OpenProtocolInformation (
1448 (*HandleBuffer)[HandleIndex],
1449 ProtocolGuidArray[ProtocolIndex],
1450 &OpenInfo,
1451 &OpenInfoCount
1452 );
1453 if (EFI_ERROR (Status)) {
1454 continue;
1455 }
1456
1457 if (ControllerHandle == NULL) {
1458 //
1459 // ControllerHandle == NULL and DriverBindingHandle != NULL.
1460 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
1461 //
1462 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
1463 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
1464 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
1465 if (DriverBindingHandleIndex != -1) {
1466 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
1467 }
1468 }
1469 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
1470 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
1471 if (DriverBindingHandleIndex != -1) {
1472 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
1473 }
1474 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
1475 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
1476 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
1477 }
1478 }
1479 }
1480 }
1481 }
1482 if (DriverBindingHandle == NULL && ControllerHandle != NULL) {
1483 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
1484 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
1485 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
1486 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
1487 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
1488 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
1489 (*HandleType)[ChildIndex] |= (UINTN)HR_DEVICE_DRIVER;
1490 }
1491 }
1492 }
1493 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
1494 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
1495 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
1496 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
1497 }
1498 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
1499 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
1500 }
1501 }
1502 }
1503 }
1504 } else {
1505 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
1506 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
1507 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
1508 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
1509 }
1510 }
1511 }
1512 }
1513 }
1514 if (DriverBindingHandle != NULL && ControllerHandle != NULL) {
1515 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
1516 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
1517 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
1518 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
1519 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
1520 if (DriverBindingHandleIndex != -1) {
1521 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
1522 }
1523 }
1524 }
1525 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
1526 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
1527 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
1528 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
1529 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
1530 }
1531 }
1532 }
1533
1534 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
1535 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
1536 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
1537 }
1538 }
1539 }
1540 }
1541 } else {
1542 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
1543 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
1544 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
1545 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
1546 }
1547 }
1548 }
1549 }
1550 }
1551 FreePool (OpenInfo);
1552 }
1553 FreePool (ProtocolGuidArray);
1554 }
1555 return EFI_SUCCESS;
1556 }
1557
1558 /**
1559 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
1560 supplied.
1561
1562 This function will scan all EFI_HANDLES in the UEFI environment's handle database
1563 and return all the ones with the specified relationship (Mask) to the specified
1564 controller handle.
1565
1566 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1567 If MatchingHandleCount is NULL, then ASSERT.
1568
1569 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
1570 caller freed.
1571
1572 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
1573 on it.
1574 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
1575 @param[in] Mask Mask of what relationship(s) is desired.
1576 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
1577 MatchingHandleBuffer.
1578 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
1579 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
1580
1581 @retval EFI_SUCCESS The operation was sucessful and any related handles
1582 are in MatchingHandleBuffer;
1583 @retval EFI_NOT_FOUND No matching handles were found.
1584 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1585 **/
1586 EFI_STATUS
1587 EFIAPI
1588 ParseHandleDatabaseByRelationship (
1589 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
1590 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
1591 IN CONST UINTN Mask,
1592 IN UINTN *MatchingHandleCount,
1593 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
1594 )
1595 {
1596 EFI_STATUS Status;
1597 UINTN HandleCount;
1598 EFI_HANDLE *HandleBuffer;
1599 UINTN *HandleType;
1600 UINTN HandleIndex;
1601
1602 ASSERT(MatchingHandleCount != NULL);
1603 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
1604
1605 if ((Mask & HR_VALID_MASK) != Mask) {
1606 return (EFI_INVALID_PARAMETER);
1607 }
1608
1609 if ((Mask & HR_CHILD_HANDLE) != 0 && DriverBindingHandle == NULL) {
1610 return (EFI_INVALID_PARAMETER);
1611 }
1612
1613 *MatchingHandleCount = 0;
1614 if (MatchingHandleBuffer != NULL) {
1615 *MatchingHandleBuffer = NULL;
1616 }
1617
1618 HandleBuffer = NULL;
1619 HandleType = NULL;
1620
1621 Status = ParseHandleDatabaseByRelationshipWithType (
1622 DriverBindingHandle,
1623 ControllerHandle,
1624 &HandleCount,
1625 &HandleBuffer,
1626 &HandleType
1627 );
1628 if (!EFI_ERROR (Status)) {
1629 //
1630 // Count the number of handles that match the attributes in Mask
1631 //
1632 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
1633 if ((HandleType[HandleIndex] & Mask) == Mask) {
1634 (*MatchingHandleCount)++;
1635 }
1636 }
1637 //
1638 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
1639 //
1640 if (*MatchingHandleCount == 0) {
1641 Status = EFI_NOT_FOUND;
1642 } else {
1643
1644 if (MatchingHandleBuffer == NULL) {
1645 //
1646 // Someone just wanted the count...
1647 //
1648 Status = EFI_SUCCESS;
1649 } else {
1650 //
1651 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
1652 //
1653 *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE));
1654 ASSERT(*MatchingHandleBuffer != NULL);
1655
1656 for (HandleIndex = 0,*MatchingHandleCount = 0
1657 ; HandleIndex < HandleCount
1658 ; HandleIndex++
1659 ){
1660 //
1661 // Fill the allocated buffer with the handles that matched the attributes in Mask
1662 //
1663 if ((HandleType[HandleIndex] & Mask) == Mask) {
1664 (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex];
1665 }
1666 }
1667
1668 //
1669 // Make the last one NULL
1670 //
1671 (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL;
1672
1673 Status = EFI_SUCCESS;
1674 } // MacthingHandleBuffer == NULL (ELSE)
1675 } // *MatchingHandleCount == 0 (ELSE)
1676 } // no error on ParseHandleDatabaseByRelationshipWithType
1677
1678 if (HandleBuffer != NULL) {
1679 FreePool (HandleBuffer);
1680 }
1681
1682 if (HandleType != NULL) {
1683 FreePool (HandleType);
1684 }
1685
1686 return Status;
1687 }
1688
1689 /**
1690 Gets handles for any child controllers of the passed in controller.
1691
1692 @param[in] ControllerHandle The handle of the "parent controller"
1693 @param[in] MatchingHandleCount Pointer to the number of handles in
1694 MatchingHandleBuffer on return.
1695 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1696 return.
1697
1698
1699 @retval EFI_SUCCESS The operation was sucessful.
1700 **/
1701 EFI_STATUS
1702 EFIAPI
1703 ParseHandleDatabaseForChildControllers(
1704 IN CONST EFI_HANDLE ControllerHandle,
1705 IN UINTN *MatchingHandleCount,
1706 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
1707 )
1708 {
1709 EFI_STATUS Status;
1710 UINTN HandleIndex;
1711 UINTN DriverBindingHandleCount;
1712 EFI_HANDLE *DriverBindingHandleBuffer;
1713 UINTN DriverBindingHandleIndex;
1714 UINTN ChildControllerHandleCount;
1715 EFI_HANDLE *ChildControllerHandleBuffer;
1716 UINTN ChildControllerHandleIndex;
1717 EFI_HANDLE *HandleBufferForReturn;
1718
1719 if (MatchingHandleCount == NULL) {
1720 return (EFI_INVALID_PARAMETER);
1721 }
1722 *MatchingHandleCount = 0;
1723
1724 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
1725 ControllerHandle,
1726 &DriverBindingHandleCount,
1727 &DriverBindingHandleBuffer
1728 );
1729 if (EFI_ERROR (Status)) {
1730 return Status;
1731 }
1732
1733 //
1734 // Get a buffer big enough for all the controllers.
1735 //
1736 HandleBufferForReturn = GetHandleListByProtocol(NULL);
1737 if (HandleBufferForReturn == NULL) {
1738 FreePool (DriverBindingHandleBuffer);
1739 return (EFI_NOT_FOUND);
1740 }
1741
1742 for (DriverBindingHandleIndex = 0; DriverBindingHandleIndex < DriverBindingHandleCount; DriverBindingHandleIndex++) {
1743 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1744 DriverBindingHandleBuffer[DriverBindingHandleIndex],
1745 ControllerHandle,
1746 &ChildControllerHandleCount,
1747 &ChildControllerHandleBuffer
1748 );
1749 if (EFI_ERROR (Status)) {
1750 continue;
1751 }
1752
1753 for (ChildControllerHandleIndex = 0;
1754 ChildControllerHandleIndex < ChildControllerHandleCount;
1755 ChildControllerHandleIndex++
1756 ) {
1757 for (HandleIndex = 0; HandleIndex < *MatchingHandleCount; HandleIndex++) {
1758 if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {
1759 break;
1760 }
1761 }
1762 if (HandleIndex >= *MatchingHandleCount) {
1763 HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];
1764 }
1765 }
1766
1767 FreePool (ChildControllerHandleBuffer);
1768 }
1769
1770 FreePool (DriverBindingHandleBuffer);
1771
1772 if (MatchingHandleBuffer != NULL) {
1773 *MatchingHandleBuffer = HandleBufferForReturn;
1774 } else {
1775 FreePool(HandleBufferForReturn);
1776 }
1777
1778 return (EFI_SUCCESS);
1779 }
1780
1781 /**
1782 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
1783 if necessary to fit all of the data.
1784
1785 If DestinationBuffer is NULL, then ASSERT().
1786
1787 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
1788 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
1789 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
1790 @param[in] SourceSize The number of bytes of SourceBuffer to append.
1791
1792 @retval NULL A memory allocation failed.
1793 @retval NULL A parameter was invalid.
1794 @return A pointer to (*DestinationBuffer).
1795 **/
1796 VOID*
1797 EFIAPI
1798 BuffernCatGrow (
1799 IN OUT VOID **DestinationBuffer,
1800 IN OUT UINTN *DestinationSize,
1801 IN VOID *SourceBuffer,
1802 IN UINTN SourceSize
1803 )
1804 {
1805 UINTN LocalDestinationSize;
1806 UINTN LocalDestinationFinalSize;
1807
1808 ASSERT(DestinationBuffer != NULL);
1809
1810 if (SourceSize == 0 || SourceBuffer == NULL) {
1811 return (*DestinationBuffer);
1812 }
1813
1814 if (DestinationSize == NULL) {
1815 LocalDestinationSize = 0;
1816 } else {
1817 LocalDestinationSize = *DestinationSize;
1818 }
1819
1820 LocalDestinationFinalSize = LocalDestinationSize + SourceSize;
1821
1822 if (DestinationSize != NULL) {
1823 *DestinationSize = LocalDestinationSize;
1824 }
1825
1826 if (LocalDestinationSize == 0) {
1827 // allcoate
1828 *DestinationBuffer = AllocateZeroPool(LocalDestinationFinalSize);
1829 } else {
1830 // reallocate
1831 *DestinationBuffer = ReallocatePool(LocalDestinationSize, LocalDestinationFinalSize, *DestinationBuffer);
1832 }
1833
1834 ASSERT(*DestinationBuffer != NULL);
1835
1836 // copy
1837 return (CopyMem(((UINT8*)(*DestinationBuffer)) + LocalDestinationSize, SourceBuffer, SourceSize));
1838 }
1839
1840 /**
1841 Gets handles for any child devices produced by the passed in driver.
1842
1843 @param[in] DriverHandle The handle of the driver.
1844 @param[in] MatchingHandleCount Pointer to the number of handles in
1845 MatchingHandleBuffer on return.
1846 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1847 return.
1848 @retval EFI_SUCCESS The operation was sucessful.
1849 @sa ParseHandleDatabaseByRelationship
1850 **/
1851 EFI_STATUS
1852 EFIAPI
1853 ParseHandleDatabaseForChildDevices(
1854 IN CONST EFI_HANDLE DriverHandle,
1855 IN UINTN *MatchingHandleCount,
1856 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
1857 )
1858 {
1859 EFI_HANDLE *Buffer;
1860 EFI_HANDLE *Buffer2;
1861 UINTN Count1;
1862 UINTN Count2;
1863 UINTN HandleIndex;
1864 EFI_STATUS Status;
1865 UINTN HandleBufferSize;
1866
1867 ASSERT(MatchingHandleCount != NULL);
1868
1869 HandleBufferSize = 0;
1870 Buffer = NULL;
1871 Buffer2 = NULL;
1872 *MatchingHandleCount = 0;
1873
1874 Status = PARSE_HANDLE_DATABASE_DEVICES (
1875 DriverHandle,
1876 &Count1,
1877 &Buffer
1878 );
1879 if (!EFI_ERROR (Status)) {
1880 for (HandleIndex = 0; HandleIndex < Count1; HandleIndex++) {
1881 //
1882 // now find the children
1883 //
1884 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1885 DriverHandle,
1886 Buffer[HandleIndex],
1887 &Count2,
1888 &Buffer2
1889 );
1890 if (EFI_ERROR(Status)) {
1891 break;
1892 }
1893 //
1894 // save out required and optional data elements
1895 //
1896 *MatchingHandleCount += Count2;
1897 if (MatchingHandleBuffer != NULL) {
1898 *MatchingHandleBuffer = BuffernCatGrow((VOID**)MatchingHandleBuffer, &HandleBufferSize, Buffer2, Count2 * sizeof(Buffer2[0]));
1899 }
1900
1901 //
1902 // free the memory
1903 //
1904 if (Buffer2 != NULL) {
1905 FreePool(Buffer2);
1906 }
1907 }
1908 }
1909
1910 if (Buffer != NULL) {
1911 FreePool(Buffer);
1912 }
1913 return (Status);
1914 }
1915
1916 /**
1917 Function to get all handles that support a given protocol or all handles.
1918
1919 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
1920 then the function will return all handles.
1921
1922 @retval NULL A memory allocation failed.
1923 @return A NULL terminated list of handles.
1924 **/
1925 EFI_HANDLE*
1926 EFIAPI
1927 GetHandleListByProtocol (
1928 IN CONST EFI_GUID *ProtocolGuid OPTIONAL
1929 )
1930 {
1931 EFI_HANDLE *HandleList;
1932 UINTN Size;
1933 EFI_STATUS Status;
1934
1935 Size = 0;
1936 HandleList = NULL;
1937
1938 //
1939 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
1940 //
1941 if (ProtocolGuid == NULL) {
1942 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
1943 if (Status == EFI_BUFFER_TOO_SMALL) {
1944 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));
1945 if (HandleList == NULL) {
1946 return (NULL);
1947 }
1948 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
1949 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
1950 }
1951 } else {
1952 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
1953 if (Status == EFI_BUFFER_TOO_SMALL) {
1954 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));
1955 if (HandleList == NULL) {
1956 return (NULL);
1957 }
1958 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
1959 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
1960 }
1961 }
1962 if (EFI_ERROR(Status)) {
1963 if (HandleList != NULL) {
1964 FreePool(HandleList);
1965 }
1966 return (NULL);
1967 }
1968 return (HandleList);
1969 }
1970
1971 /**
1972 Function to get all handles that support some protocols.
1973
1974 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
1975
1976 @retval NULL A memory allocation failed.
1977 @retval NULL ProtocolGuids was NULL.
1978 @return A NULL terminated list of EFI_HANDLEs.
1979 **/
1980 EFI_HANDLE*
1981 EFIAPI
1982 GetHandleListByProtocolList (
1983 IN CONST EFI_GUID **ProtocolGuids
1984 )
1985 {
1986 EFI_HANDLE *HandleList;
1987 UINTN Size;
1988 UINTN TotalSize;
1989 UINTN TempSize;
1990 EFI_STATUS Status;
1991 CONST EFI_GUID **GuidWalker;
1992 EFI_HANDLE *HandleWalker1;
1993 EFI_HANDLE *HandleWalker2;
1994
1995 Size = 0;
1996 HandleList = NULL;
1997 TotalSize = sizeof(EFI_HANDLE);
1998
1999 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++,Size = 0){
2000 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &Size, NULL);
2001 if (Status == EFI_BUFFER_TOO_SMALL) {
2002 TotalSize += Size;
2003 }
2004 }
2005
2006 //
2007 // No handles were found...
2008 //
2009 if (TotalSize == sizeof(EFI_HANDLE)) {
2010 return (NULL);
2011 }
2012
2013 HandleList = AllocateZeroPool(TotalSize);
2014 if (HandleList == NULL) {
2015 return (NULL);
2016 }
2017
2018 Size = 0;
2019 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++){
2020 TempSize = TotalSize - Size;
2021 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &TempSize, HandleList+(Size/sizeof(EFI_HANDLE)));
2022
2023 //
2024 // Allow for missing protocols... Only update the 'used' size upon success.
2025 //
2026 if (!EFI_ERROR(Status)) {
2027 Size += TempSize;
2028 }
2029 }
2030 ASSERT(HandleList[(TotalSize/sizeof(EFI_HANDLE))-1] == NULL);
2031
2032 for (HandleWalker1 = HandleList ; HandleWalker1 != NULL && *HandleWalker1 != NULL ; HandleWalker1++) {
2033 for (HandleWalker2 = HandleWalker1 + 1; HandleWalker2 != NULL && *HandleWalker2 != NULL ; HandleWalker2++) {
2034 if (*HandleWalker1 == *HandleWalker2) {
2035 //
2036 // copy memory back 1 handle width.
2037 //
2038 CopyMem(HandleWalker2, HandleWalker2 + 1, TotalSize - ((HandleWalker2-HandleList+1)*sizeof(EFI_HANDLE)));
2039 }
2040 }
2041 }
2042
2043 return (HandleList);
2044 }
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054