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