]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
da1d92fd1717b7101ae40dabf3920d1578918ad7
[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) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
6 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<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 *mGuidList;
23 UINTN mGuidListCount;
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 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 ConvertPixelFormat (
69 IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt
70 )
71 {
72 CHAR16 *RetVal;
73 RetVal = NULL;
74
75 switch (Fmt) {
76 case PixelRedGreenBlueReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelRedGreenBlueReserved8BitPerColor", 0); break;
77 case PixelBlueGreenRedReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelBlueGreenRedReserved8BitPerColor", 0); break;
78 case PixelBitMask: StrnCatGrow(&RetVal, NULL, L"PixelBitMask", 0); break;
79 case PixelBltOnly: StrnCatGrow(&RetVal, NULL, L"PixelBltOnly", 0); break;
80 case PixelFormatMax: StrnCatGrow(&RetVal, NULL, L"PixelFormatMax", 0); break;
81 default: ASSERT(FALSE);
82 }
83 return (RetVal);
84 }
85
86 /**
87 Constructor for the library.
88
89 @param[in] ImageHandle Ignored.
90 @param[in] SystemTable Ignored.
91
92 @retval EFI_SUCCESS The operation was successful.
93 **/
94 EFI_STATUS
95 EFIAPI
96 HandleParsingLibConstructor (
97 IN EFI_HANDLE ImageHandle,
98 IN EFI_SYSTEM_TABLE *SystemTable
99 )
100 {
101 mGuidListCount = 0;
102 mGuidList = NULL;
103
104 //
105 // Do nothing with mHandleParsingHiiHandle. Initialize HII as needed.
106 //
107 return (EFI_SUCCESS);
108 }
109
110 /**
111 Initialization function for HII packages.
112
113 **/
114 VOID
115 HandleParsingHiiInit (VOID)
116 {
117 if (mHandleParsingHiiHandle == NULL) {
118 mHandleParsingHiiHandle = HiiAddPackages (&gHandleParsingHiiGuid, gImageHandle, UefiHandleParsingLibStrings, NULL);
119 ASSERT (mHandleParsingHiiHandle != NULL);
120 }
121 }
122
123 /**
124 Destructor for the library. free any resources.
125
126 @param[in] ImageHandle Ignored.
127 @param[in] SystemTable Ignored.
128
129 @retval EFI_SUCCESS The operation was successful.
130 **/
131 EFI_STATUS
132 EFIAPI
133 HandleParsingLibDestructor (
134 IN EFI_HANDLE ImageHandle,
135 IN EFI_SYSTEM_TABLE *SystemTable
136 )
137 {
138 UINTN LoopCount;
139
140 for (LoopCount = 0; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++) {
141 SHELL_FREE_NON_NULL(mGuidList[LoopCount].GuidId);
142 }
143
144 SHELL_FREE_NON_NULL(mGuidList);
145 if (mHandleParsingHiiHandle != NULL) {
146 HiiRemovePackages(mHandleParsingHiiHandle);
147 }
148 return (EFI_SUCCESS);
149 }
150
151 /**
152 Function to dump information about LoadedImage.
153
154 This will allocate the return buffer from boot services pool.
155
156 @param[in] TheHandle The handle that has LoadedImage installed.
157 @param[in] Verbose TRUE for additional information, FALSE otherwise.
158
159 @retval A poitner to a string containing the information.
160 **/
161 CHAR16*
162 EFIAPI
163 LoadedImageProtocolDumpInformation(
164 IN CONST EFI_HANDLE TheHandle,
165 IN CONST BOOLEAN Verbose
166 )
167 {
168 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
169 EFI_STATUS Status;
170 CHAR16 *RetVal;
171 CHAR16 *Temp;
172 CHAR16 *CodeType;
173 CHAR16 *DataType;
174
175 if (!Verbose) {
176 return (CatSPrint(NULL, L"LoadedImage"));
177 }
178
179 HandleParsingHiiInit();
180
181 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL);
182 if (Temp == NULL) {
183 return NULL;
184 }
185
186 Status = gBS->OpenProtocol (
187 TheHandle,
188 &gEfiLoadedImageProtocolGuid,
189 (VOID**)&LoadedImage,
190 gImageHandle,
191 NULL,
192 EFI_OPEN_PROTOCOL_GET_PROTOCOL
193 );
194
195 if (EFI_ERROR (Status)) {
196 SHELL_FREE_NON_NULL (Temp);
197 return NULL;
198 }
199
200 DataType = ConvertMemoryType(LoadedImage->ImageDataType);
201 CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);
202
203 RetVal = CatSPrint(
204 NULL,
205 Temp,
206 LoadedImage->Revision,
207 LoadedImage->ParentHandle,
208 LoadedImage->SystemTable,
209 LoadedImage->DeviceHandle,
210 LoadedImage->FilePath,
211 LoadedImage->LoadOptionsSize,
212 LoadedImage->LoadOptions,
213 LoadedImage->ImageBase,
214 LoadedImage->ImageSize,
215 CodeType,
216 DataType,
217 LoadedImage->Unload
218 );
219
220
221 SHELL_FREE_NON_NULL(Temp);
222 SHELL_FREE_NON_NULL(CodeType);
223 SHELL_FREE_NON_NULL(DataType);
224
225 return RetVal;
226 }
227
228 /**
229 Function to dump information about GOP.
230
231 This will allocate the return buffer from boot services pool.
232
233 @param[in] TheHandle The handle that has LoadedImage installed.
234 @param[in] Verbose TRUE for additional information, FALSE otherwise.
235
236 @retval A poitner to a string containing the information.
237 **/
238 CHAR16*
239 EFIAPI
240 GraphicsOutputProtocolDumpInformation(
241 IN CONST EFI_HANDLE TheHandle,
242 IN CONST BOOLEAN Verbose
243 )
244 {
245 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
246 EFI_STATUS Status;
247 CHAR16 *RetVal;
248 CHAR16 *Temp;
249 CHAR16 *Fmt;
250 CHAR16 *TempRetVal;
251 UINTN GopInfoSize;
252 UINT32 Mode;
253 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GopInfo;
254
255 if (!Verbose) {
256 return (CatSPrint(NULL, L"GraphicsOutput"));
257 }
258
259 HandleParsingHiiInit();
260
261 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_GOP_DUMP_MAIN), NULL);
262 if (Temp == NULL) {
263 return NULL;
264 }
265
266 Status = gBS->OpenProtocol (
267 TheHandle,
268 &gEfiGraphicsOutputProtocolGuid,
269 (VOID**)&GraphicsOutput,
270 gImageHandle,
271 NULL,
272 EFI_OPEN_PROTOCOL_GET_PROTOCOL
273 );
274
275 if (EFI_ERROR (Status)) {
276 SHELL_FREE_NON_NULL (Temp);
277 return NULL;
278 }
279
280 Fmt = ConvertPixelFormat(GraphicsOutput->Mode->Info->PixelFormat);
281
282 RetVal = CatSPrint(
283 NULL,
284 Temp,
285 GraphicsOutput->Mode->MaxMode,
286 GraphicsOutput->Mode->Mode,
287 GraphicsOutput->Mode->FrameBufferBase,
288 (UINT64)GraphicsOutput->Mode->FrameBufferSize,
289 (UINT64)GraphicsOutput->Mode->SizeOfInfo,
290 GraphicsOutput->Mode->Info->Version,
291 GraphicsOutput->Mode->Info->HorizontalResolution,
292 GraphicsOutput->Mode->Info->VerticalResolution,
293 Fmt,
294 GraphicsOutput->Mode->Info->PixelsPerScanLine,
295 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.RedMask,
296 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.GreenMask,
297 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.BlueMask
298 );
299
300 SHELL_FREE_NON_NULL (Temp);
301
302 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_GOP_RES_LIST_MAIN), NULL);
303 if (Temp == NULL) {
304 SHELL_FREE_NON_NULL (RetVal);
305 goto EXIT;
306 }
307
308 TempRetVal = CatSPrint (RetVal, Temp);
309 SHELL_FREE_NON_NULL (RetVal);
310 if (TempRetVal == NULL) {
311 goto EXIT;
312 }
313 RetVal = TempRetVal;
314 SHELL_FREE_NON_NULL (Temp);
315
316 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_GOP_RES_LIST_ENTRY), NULL);
317 if (Temp == NULL) {
318 SHELL_FREE_NON_NULL (RetVal);
319 goto EXIT;
320 }
321
322
323 for (Mode = 0; Mode < GraphicsOutput->Mode->MaxMode; Mode++) {
324 Status = GraphicsOutput->QueryMode (
325 GraphicsOutput,
326 Mode,
327 &GopInfoSize,
328 &GopInfo
329 );
330 if (EFI_ERROR (Status)) {
331 continue;
332 }
333
334 TempRetVal = CatSPrint (
335 RetVal,
336 Temp,
337 Mode,
338 GopInfo->HorizontalResolution,
339 GopInfo->VerticalResolution
340 );
341
342 SHELL_FREE_NON_NULL (GopInfo);
343 SHELL_FREE_NON_NULL (RetVal);
344 RetVal = TempRetVal;
345 }
346
347
348 EXIT:
349 SHELL_FREE_NON_NULL(Temp);
350 SHELL_FREE_NON_NULL(Fmt);
351
352 return RetVal;
353 }
354
355 /**
356 Function to dump information about EDID Discovered Protocol.
357
358 This will allocate the return buffer from boot services pool.
359
360 @param[in] TheHandle The handle that has LoadedImage installed.
361 @param[in] Verbose TRUE for additional information, FALSE otherwise.
362
363 @retval A pointer to a string containing the information.
364 **/
365 CHAR16*
366 EFIAPI
367 EdidDiscoveredProtocolDumpInformation (
368 IN CONST EFI_HANDLE TheHandle,
369 IN CONST BOOLEAN Verbose
370 )
371 {
372 EFI_EDID_DISCOVERED_PROTOCOL *EdidDiscovered;
373 EFI_STATUS Status;
374 CHAR16 *RetVal;
375 CHAR16 *Temp;
376 CHAR16 *TempRetVal;
377
378 if (!Verbose) {
379 return (CatSPrint (NULL, L"EDIDDiscovered"));
380 }
381
382 Status = gBS->OpenProtocol (
383 TheHandle,
384 &gEfiEdidDiscoveredProtocolGuid,
385 (VOID**)&EdidDiscovered,
386 NULL,
387 NULL,
388 EFI_OPEN_PROTOCOL_GET_PROTOCOL
389 );
390
391 if (EFI_ERROR (Status)) {
392 return NULL;
393 }
394
395 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_DISCOVERED_MAIN), NULL);
396 if (Temp == NULL) {
397 return NULL;
398 }
399
400 RetVal = CatSPrint (NULL, Temp, EdidDiscovered->SizeOfEdid);
401 SHELL_FREE_NON_NULL (Temp);
402
403 if (EdidDiscovered->SizeOfEdid != 0) {
404 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_DISCOVERED_DATA), NULL);
405 if (Temp == NULL) {
406 SHELL_FREE_NON_NULL (RetVal);
407 return NULL;
408 }
409 TempRetVal = CatSPrint (RetVal, Temp);
410 SHELL_FREE_NON_NULL (RetVal);
411 RetVal = TempRetVal;
412
413 TempRetVal = CatSDumpHex (RetVal, 7, 0, EdidDiscovered->SizeOfEdid, EdidDiscovered->Edid);
414 RetVal = TempRetVal;
415 }
416 return RetVal;
417 }
418
419 /**
420 Function to dump information about EDID Active Protocol.
421
422 This will allocate the return buffer from boot services pool.
423
424 @param[in] TheHandle The handle that has LoadedImage installed.
425 @param[in] Verbose TRUE for additional information, FALSE otherwise.
426
427 @retval A pointer to a string containing the information.
428 **/
429 CHAR16*
430 EFIAPI
431 EdidActiveProtocolDumpInformation (
432 IN CONST EFI_HANDLE TheHandle,
433 IN CONST BOOLEAN Verbose
434 )
435 {
436 EFI_EDID_ACTIVE_PROTOCOL *EdidActive;
437 EFI_STATUS Status;
438 CHAR16 *RetVal;
439 CHAR16 *Temp;
440 CHAR16 *TempRetVal;
441
442 if (!Verbose) {
443 return (CatSPrint (NULL, L"EDIDActive"));
444 }
445
446 Status = gBS->OpenProtocol (
447 TheHandle,
448 &gEfiEdidActiveProtocolGuid,
449 (VOID**)&EdidActive,
450 NULL,
451 NULL,
452 EFI_OPEN_PROTOCOL_GET_PROTOCOL
453 );
454
455 if (EFI_ERROR (Status)) {
456 return NULL;
457 }
458
459 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_ACTIVE_MAIN), NULL);
460 if (Temp == NULL) {
461 return NULL;
462 }
463
464 RetVal = CatSPrint (NULL, Temp, EdidActive->SizeOfEdid);
465 SHELL_FREE_NON_NULL (Temp);
466
467 if (EdidActive->SizeOfEdid != 0) {
468 Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_ACTIVE_DATA), NULL);
469 if (Temp == NULL) {
470 SHELL_FREE_NON_NULL (RetVal);
471 return NULL;
472 }
473 TempRetVal = CatSPrint (RetVal, Temp);
474 SHELL_FREE_NON_NULL (RetVal);
475 RetVal = TempRetVal;
476
477 TempRetVal = CatSDumpHex (RetVal, 7, 0, EdidActive->SizeOfEdid, EdidActive->Edid);
478 RetVal = TempRetVal;
479 }
480 return RetVal;
481 }
482
483 /**
484 Function to dump information about PciRootBridgeIo.
485
486 This will allocate the return buffer from boot services pool.
487
488 @param[in] TheHandle The handle that has PciRootBridgeIo installed.
489 @param[in] Verbose TRUE for additional information, FALSE otherwise.
490
491 @retval A poitner to a string containing the information.
492 **/
493 CHAR16*
494 EFIAPI
495 PciRootBridgeIoDumpInformation(
496 IN CONST EFI_HANDLE TheHandle,
497 IN CONST BOOLEAN Verbose
498 )
499 {
500 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
501 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration;
502 UINT64 Supports;
503 UINT64 Attributes;
504 CHAR16 *Temp;
505 CHAR16 *Temp2;
506 CHAR16 *RetVal;
507 EFI_STATUS Status;
508
509 RetVal = NULL;
510
511 if (!Verbose) {
512 return (CatSPrint(NULL, L"PciRootBridgeIo"));
513 }
514
515 HandleParsingHiiInit();
516
517 Status = gBS->HandleProtocol(
518 TheHandle,
519 &gEfiPciRootBridgeIoProtocolGuid,
520 (VOID**)&PciRootBridgeIo);
521
522 if (EFI_ERROR(Status)) {
523 return NULL;
524 }
525
526 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_PH), NULL);
527 if (Temp == NULL) {
528 return NULL;
529 }
530 Temp2 = CatSPrint(L"\r\n", Temp, PciRootBridgeIo->ParentHandle);
531 FreePool(Temp);
532 RetVal = Temp2;
533 Temp2 = NULL;
534
535 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SEG), NULL);
536 if (Temp == NULL) {
537 SHELL_FREE_NON_NULL(RetVal);
538 return NULL;
539 }
540 Temp2 = CatSPrint(RetVal, Temp, PciRootBridgeIo->SegmentNumber);
541 FreePool(Temp);
542 FreePool(RetVal);
543 RetVal = Temp2;
544 Temp2 = NULL;
545
546 Supports = 0;
547 Attributes = 0;
548 Status = PciRootBridgeIo->GetAttributes (PciRootBridgeIo, &Supports, &Attributes);
549 if (!EFI_ERROR(Status)) {
550 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_ATT), NULL);
551 if (Temp == NULL) {
552 SHELL_FREE_NON_NULL(RetVal);
553 return NULL;
554 }
555 Temp2 = CatSPrint(RetVal, Temp, Attributes);
556 FreePool(Temp);
557 FreePool(RetVal);
558 RetVal = Temp2;
559 Temp2 = NULL;
560
561 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS), NULL);
562 if (Temp == NULL) {
563 SHELL_FREE_NON_NULL(RetVal);
564 return NULL;
565 }
566 Temp2 = CatSPrint(RetVal, Temp, Supports);
567 FreePool(Temp);
568 FreePool(RetVal);
569 RetVal = Temp2;
570 Temp2 = NULL;
571 }
572
573 Configuration = NULL;
574 Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Configuration);
575 if (!EFI_ERROR(Status) && Configuration != NULL) {
576 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_TITLE), NULL);
577 if (Temp == NULL) {
578 SHELL_FREE_NON_NULL(RetVal);
579 return NULL;
580 }
581 Temp2 = CatSPrint(RetVal, Temp, Supports);
582 FreePool(Temp);
583 FreePool(RetVal);
584 RetVal = Temp2;
585 Temp2 = NULL;
586 while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
587 Temp = NULL;
588 switch (Configuration->ResType) {
589 case ACPI_ADDRESS_SPACE_TYPE_MEM:
590 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_MEM), NULL);
591 break;
592 case ACPI_ADDRESS_SPACE_TYPE_IO:
593 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_IO), NULL);
594 break;
595 case ACPI_ADDRESS_SPACE_TYPE_BUS:
596 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_BUS), NULL);
597 break;
598 }
599 if (Temp != NULL) {
600 Temp2 = CatSPrint(RetVal, L"%s", Temp);
601 FreePool(Temp);
602 FreePool(RetVal);
603 RetVal = Temp2;
604 Temp2 = NULL;
605 }
606
607 Temp2 = CatSPrint(RetVal,
608 L"%H%02x %016lx %016lx %02x%N\r\n",
609 Configuration->SpecificFlag,
610 Configuration->AddrRangeMin,
611 Configuration->AddrRangeMax,
612 Configuration->AddrSpaceGranularity
613 );
614 FreePool(RetVal);
615 RetVal = Temp2;
616 Temp2 = NULL;
617 Configuration++;
618 }
619 }
620 return (RetVal);
621 }
622
623 /**
624 Function to dump information about SimpleTextOut.
625
626 This will allocate the return buffer from boot services pool.
627
628 @param[in] TheHandle The handle that has SimpleTextOut installed.
629 @param[in] Verbose TRUE for additional information, FALSE otherwise.
630
631 @retval A poitner to a string containing the information.
632 **/
633 CHAR16*
634 EFIAPI
635 TxtOutProtocolDumpInformation(
636 IN CONST EFI_HANDLE TheHandle,
637 IN CONST BOOLEAN Verbose
638 )
639 {
640 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Dev;
641 INTN Index;
642 UINTN Col;
643 UINTN Row;
644 EFI_STATUS Status;
645 CHAR16 *RetVal;
646 UINTN Size;
647 CHAR16 *Temp;
648 UINTN NewSize;
649
650 if (!Verbose) {
651 return (NULL);
652 }
653
654 HandleParsingHiiInit();
655
656 RetVal = NULL;
657 Size = 0;
658
659 Status = gBS->HandleProtocol(
660 TheHandle,
661 &gEfiSimpleTextOutProtocolGuid,
662 (VOID**)&Dev);
663
664 ASSERT_EFI_ERROR(Status);
665 ASSERT (Dev != NULL && Dev->Mode != NULL);
666
667 Size = (Dev->Mode->MaxMode + 1) * 80;
668 RetVal = AllocateZeroPool(Size);
669
670 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER), NULL);
671 if (Temp != NULL) {
672 UnicodeSPrint(RetVal, Size, Temp, Dev, Dev->Mode->Attribute);
673 FreePool(Temp);
674 }
675
676 //
677 // Dump TextOut Info
678 //
679 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE), NULL);
680 for (Index = 0; Index < Dev->Mode->MaxMode; Index++) {
681 Status = Dev->QueryMode (Dev, Index, &Col, &Row);
682 NewSize = Size - StrSize(RetVal);
683 UnicodeSPrint(
684 RetVal + StrLen(RetVal),
685 NewSize,
686 Temp == NULL?L"":Temp,
687 Index == Dev->Mode->Mode ? L'*' : L' ',
688 Index,
689 !EFI_ERROR(Status)?(INTN)Col:-1,
690 !EFI_ERROR(Status)?(INTN)Row:-1
691 );
692 }
693 FreePool(Temp);
694 return (RetVal);
695 }
696
697 STATIC CONST UINTN VersionStringSize = 60;
698
699 /**
700 Function to dump information about EfiDriverSupportedEfiVersion protocol.
701
702 This will allocate the return buffer from boot services pool.
703
704 @param[in] TheHandle The handle that has the protocol installed.
705 @param[in] Verbose TRUE for additional information, FALSE otherwise.
706
707 @retval A poitner to a string containing the information.
708 **/
709 CHAR16*
710 EFIAPI
711 DriverEfiVersionProtocolDumpInformation(
712 IN CONST EFI_HANDLE TheHandle,
713 IN CONST BOOLEAN Verbose
714 )
715 {
716 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL *DriverEfiVersion;
717 EFI_STATUS Status;
718 CHAR16 *RetVal;
719
720 Status = gBS->HandleProtocol(
721 TheHandle,
722 &gEfiDriverSupportedEfiVersionProtocolGuid,
723 (VOID**)&DriverEfiVersion);
724
725 ASSERT_EFI_ERROR(Status);
726
727 RetVal = AllocateZeroPool(VersionStringSize);
728 if (RetVal != NULL) {
729 UnicodeSPrint (RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion);
730 }
731 return (RetVal);
732 }
733 /**
734 Function to convert device path to string.
735
736 This will allocate the return buffer from boot services pool.
737
738 @param[in] DevPath Pointer to device path instance.
739 @param[in] Verbose TRUE for additional information, FALSE otherwise.
740 @param[in] Length Maximum allowed text length of the device path.
741
742 @retval A pointer to a string containing the information.
743 **/
744 CHAR16*
745 ConvertDevicePathToShortText(
746 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath,
747 IN CONST BOOLEAN Verbose,
748 IN CONST UINTN Length
749 )
750 {
751 CHAR16 *Temp;
752 CHAR16 *Temp2;
753 UINTN Size;
754
755 //
756 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
757 //
758 Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);
759 if (!Verbose && Temp != NULL && StrLen(Temp) > Length) {
760 Temp2 = NULL;
761 Size = 0;
762 Temp2 = StrnCatGrow(&Temp2, &Size, L"..", 0);
763 Temp2 = StrnCatGrow(&Temp2, &Size, Temp+(StrLen(Temp) - (Length - 2)), 0);
764 FreePool(Temp);
765 Temp = Temp2;
766 }
767 return (Temp);
768 }
769
770 /**
771 Function to dump information about DevicePath protocol.
772
773 This will allocate the return buffer from boot services pool.
774
775 @param[in] TheHandle The handle that has the protocol installed.
776 @param[in] Verbose TRUE for additional information, FALSE otherwise.
777
778 @retval A pointer to a string containing the information.
779 **/
780 CHAR16*
781 EFIAPI
782 DevicePathProtocolDumpInformation(
783 IN CONST EFI_HANDLE TheHandle,
784 IN CONST BOOLEAN Verbose
785 )
786 {
787 EFI_DEVICE_PATH_PROTOCOL *DevPath;
788 CHAR16 *Temp;
789 EFI_STATUS Status;
790 Temp = NULL;
791
792 Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
793 if (!EFI_ERROR(Status)) {
794 Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30);
795 gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);
796 }
797 return (Temp);
798 }
799
800 /**
801 Function to dump information about LoadedImageDevicePath protocol.
802
803 This will allocate the return buffer from boot services pool.
804
805 @param[in] TheHandle The handle that has the protocol installed.
806 @param[in] Verbose TRUE for additional information, FALSE otherwise.
807
808 @retval A pointer to a string containing the information.
809 **/
810 CHAR16*
811 EFIAPI
812 LoadedImageDevicePathProtocolDumpInformation(
813 IN CONST EFI_HANDLE TheHandle,
814 IN CONST BOOLEAN Verbose
815 )
816 {
817 EFI_DEVICE_PATH_PROTOCOL *DevPath;
818 CHAR16 *Temp;
819 EFI_STATUS Status;
820 Temp = NULL;
821
822 Status = gBS->OpenProtocol(TheHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
823 if (!EFI_ERROR(Status)) {
824 Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30);
825 gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);
826 }
827 return (Temp);
828 }
829
830 /**
831 Function to dump information about EfiAdapterInformation Protocol.
832
833 @param[in] TheHandle The handle that has the protocol installed.
834 @param[in] Verbose TRUE for additional information, FALSE otherwise.
835
836 @retval A pointer to a string containing the information.
837 **/
838 CHAR16*
839 EFIAPI
840 AdapterInformationDumpInformation (
841 IN CONST EFI_HANDLE TheHandle,
842 IN CONST BOOLEAN Verbose
843 )
844 {
845 EFI_STATUS Status;
846 EFI_ADAPTER_INFORMATION_PROTOCOL *EfiAdptrInfoProtocol;
847 UINTN InfoTypesBufferCount;
848 UINTN GuidIndex;
849 EFI_GUID *InfoTypesBuffer;
850 CHAR16 *GuidStr;
851 CHAR16 *TempStr;
852 CHAR16 *RetVal;
853 CHAR16 *TempRetVal;
854 VOID *InformationBlock;
855 UINTN InformationBlockSize;
856
857 if (!Verbose) {
858 return (CatSPrint(NULL, L"AdapterInfo"));
859 }
860
861 InfoTypesBuffer = NULL;
862 InformationBlock = NULL;
863
864
865 Status = gBS->OpenProtocol (
866 (EFI_HANDLE) (TheHandle),
867 &gEfiAdapterInformationProtocolGuid,
868 (VOID **) &EfiAdptrInfoProtocol,
869 NULL,
870 NULL,
871 EFI_OPEN_PROTOCOL_GET_PROTOCOL
872 );
873
874 if (EFI_ERROR (Status)) {
875 return NULL;
876 }
877
878 //
879 // Get a list of supported information types for this instance of the protocol.
880 //
881 Status = EfiAdptrInfoProtocol->GetSupportedTypes (
882 EfiAdptrInfoProtocol,
883 &InfoTypesBuffer,
884 &InfoTypesBufferCount
885 );
886 RetVal = NULL;
887 if (EFI_ERROR (Status)) {
888 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GET_SUPP_TYPES_FAILED), NULL);
889 if (TempStr != NULL) {
890 RetVal = CatSPrint (NULL, TempStr, Status);
891 } else {
892 goto ERROR_EXIT;
893 }
894 } else {
895 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SUPP_TYPE_HEADER), NULL);
896 if (TempStr == NULL) {
897 goto ERROR_EXIT;
898 }
899 RetVal = CatSPrint (NULL, TempStr);
900 SHELL_FREE_NON_NULL (TempStr);
901
902 for (GuidIndex = 0; GuidIndex < InfoTypesBufferCount; GuidIndex++) {
903 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GUID_NUMBER), NULL);
904 if (TempStr == NULL) {
905 goto ERROR_EXIT;
906 }
907 TempRetVal = CatSPrint (RetVal, TempStr, (GuidIndex + 1), &InfoTypesBuffer[GuidIndex]);
908 SHELL_FREE_NON_NULL (RetVal);
909 RetVal = TempRetVal;
910 SHELL_FREE_NON_NULL (TempStr);
911
912 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GUID_STRING), NULL);
913 if (TempStr == NULL) {
914 goto ERROR_EXIT;
915 }
916
917 if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) {
918 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoMediaStateGuid");
919 SHELL_FREE_NON_NULL (RetVal);
920 RetVal = TempRetVal;
921 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) {
922 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoNetworkBootGuid");
923 SHELL_FREE_NON_NULL (RetVal);
924 RetVal = TempRetVal;
925 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid)) {
926 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoSanMacAddressGuid");
927 SHELL_FREE_NON_NULL (RetVal);
928 RetVal = TempRetVal;
929 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoUndiIpv6SupportGuid)) {
930 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoUndiIpv6SupportGuid");
931 SHELL_FREE_NON_NULL (RetVal);
932 RetVal = TempRetVal;
933 } else {
934
935 GuidStr = GetStringNameFromGuid (&InfoTypesBuffer[GuidIndex], NULL);
936 if (GuidStr == NULL) {
937 TempRetVal = CatSPrint (RetVal, TempStr, L"UnknownInfoType");
938 SHELL_FREE_NON_NULL (RetVal);
939 RetVal = TempRetVal;
940
941 SHELL_FREE_NON_NULL (TempStr);
942 SHELL_FREE_NON_NULL(GuidStr);
943 //
944 // So that we never have to pass this UnknownInfoType to the parsing function "GetInformation" service of AIP
945 //
946 continue;
947 } else {
948 TempRetVal = CatSPrint (RetVal, TempStr, GuidStr);
949 SHELL_FREE_NON_NULL (RetVal);
950 RetVal = TempRetVal;
951 SHELL_FREE_NON_NULL(GuidStr);
952 }
953 }
954
955 SHELL_FREE_NON_NULL (TempStr);
956
957 Status = EfiAdptrInfoProtocol->GetInformation (
958 EfiAdptrInfoProtocol,
959 &InfoTypesBuffer[GuidIndex],
960 &InformationBlock,
961 &InformationBlockSize
962 );
963
964 if (EFI_ERROR (Status)) {
965 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GETINFO_FAILED), NULL);
966 if (TempStr == NULL) {
967 goto ERROR_EXIT;
968 }
969 TempRetVal = CatSPrint (RetVal, TempStr, Status);
970 SHELL_FREE_NON_NULL (RetVal);
971 RetVal = TempRetVal;
972 } else {
973 if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) {
974 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_MEDIA_STATE), NULL);
975 if (TempStr == NULL) {
976 goto ERROR_EXIT;
977 }
978 TempRetVal = CatSPrint (
979 RetVal,
980 TempStr,
981 ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState,
982 ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState
983 );
984 SHELL_FREE_NON_NULL (RetVal);
985 RetVal = TempRetVal;
986 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) {
987 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_NETWORK_BOOT_INFO), NULL);
988 if (TempStr == NULL) {
989 goto ERROR_EXIT;
990 }
991 TempRetVal = CatSPrint (
992 RetVal,
993 TempStr,
994 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4BootCapablity,
995 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6BootCapablity,
996 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBootCapablity,
997 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->OffloadCapability,
998 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiMpioCapability,
999 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4Boot,
1000 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6Boot,
1001 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBoot
1002 );
1003 SHELL_FREE_NON_NULL (RetVal);
1004 RetVal = TempRetVal;
1005 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid) == TRUE) {
1006 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SAN_MAC_ADDRESS_INFO), NULL);
1007 if (TempStr == NULL) {
1008 goto ERROR_EXIT;
1009 }
1010 TempRetVal = CatSPrint (
1011 RetVal,
1012 TempStr,
1013 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[0],
1014 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[1],
1015 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[2],
1016 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[3],
1017 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[4],
1018 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[5]
1019 );
1020 SHELL_FREE_NON_NULL (RetVal);
1021 RetVal = TempRetVal;
1022 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoUndiIpv6SupportGuid) == TRUE) {
1023 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_UNDI_IPV6_INFO), NULL);
1024 if (TempStr == NULL) {
1025 goto ERROR_EXIT;
1026 }
1027
1028 TempRetVal = CatSPrint (
1029 RetVal,
1030 TempStr,
1031 ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT *)InformationBlock)->Ipv6Support
1032 );
1033 SHELL_FREE_NON_NULL (RetVal);
1034 RetVal = TempRetVal;
1035 } else {
1036 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_UNKNOWN_INFO_TYPE), NULL);
1037 if (TempStr == NULL) {
1038 goto ERROR_EXIT;
1039 }
1040 TempRetVal = CatSPrint (RetVal, TempStr, &InfoTypesBuffer[GuidIndex]);
1041 SHELL_FREE_NON_NULL (RetVal);
1042 RetVal = TempRetVal;
1043 }
1044 }
1045 SHELL_FREE_NON_NULL (TempStr);
1046 SHELL_FREE_NON_NULL (InformationBlock);
1047 }
1048 }
1049
1050 SHELL_FREE_NON_NULL (InfoTypesBuffer);
1051 return RetVal;
1052
1053 ERROR_EXIT:
1054 SHELL_FREE_NON_NULL (RetVal);
1055 SHELL_FREE_NON_NULL (InfoTypesBuffer);
1056 SHELL_FREE_NON_NULL (InformationBlock);
1057 return NULL;
1058 }
1059
1060 /**
1061 Function to dump information about EFI_FIRMWARE_MANAGEMENT_PROTOCOL Protocol.
1062
1063 @param[in] TheHandle The handle that has the protocol installed.
1064 @param[in] Verbose TRUE for additional information, FALSE otherwise.
1065
1066 @retval A pointer to a string containing the information.
1067 **/
1068 CHAR16*
1069 EFIAPI
1070 FirmwareManagementDumpInformation (
1071 IN CONST EFI_HANDLE TheHandle,
1072 IN CONST BOOLEAN Verbose
1073 )
1074 {
1075 EFI_STATUS Status;
1076 EFI_FIRMWARE_MANAGEMENT_PROTOCOL *EfiFwMgmtProtocol;
1077 EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo;
1078 EFI_FIRMWARE_IMAGE_DESCRIPTOR_V1 *ImageInfoV1;
1079 EFI_FIRMWARE_IMAGE_DESCRIPTOR_V2 *ImageInfoV2;
1080 UINT64 AttributeSetting;
1081 UINTN ImageInfoSize;
1082 UINTN DescriptorSize;
1083 UINT32 DescriptorVersion;
1084 UINT32 PackageVersion;
1085 UINT8 DescriptorCount;
1086 UINT8 Index;
1087 UINT8 Index1;
1088 UINT8 ImageCount;
1089 CHAR16 *PackageVersionName;
1090 CHAR16 *TempStr;
1091 CHAR16 *RetVal;
1092 CHAR16 *TempRetVal;
1093 CHAR16 *AttributeSettingStr;
1094 BOOLEAN Found;
1095 BOOLEAN AttributeSupported;
1096
1097 //
1098 // Initialize local variables
1099 //
1100 ImageCount = 0;
1101 ImageInfoSize = 1;
1102 AttributeSetting = 0;
1103 Found = FALSE;
1104 AttributeSupported = FALSE;
1105 ImageInfo = NULL;
1106 ImageInfoV1 = NULL;
1107 ImageInfoV2 = NULL;
1108 PackageVersionName = NULL;
1109 RetVal = NULL;
1110 TempRetVal = NULL;
1111 TempStr = NULL;
1112 AttributeSettingStr = NULL;
1113
1114 if (!Verbose) {
1115 return (CatSPrint(NULL, L"FirmwareManagement"));
1116 }
1117
1118 Status = gBS->OpenProtocol (
1119 (EFI_HANDLE) (TheHandle),
1120 &gEfiFirmwareManagementProtocolGuid,
1121 (VOID **) &EfiFwMgmtProtocol,
1122 NULL,
1123 NULL,
1124 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1125 );
1126
1127 if (EFI_ERROR (Status)) {
1128 return NULL;
1129 }
1130
1131 Status = EfiFwMgmtProtocol->GetImageInfo (
1132 EfiFwMgmtProtocol,
1133 &ImageInfoSize,
1134 ImageInfo,
1135 &DescriptorVersion,
1136 &DescriptorCount,
1137 &DescriptorSize,
1138 &PackageVersion,
1139 &PackageVersionName
1140 );
1141
1142 if (Status == EFI_BUFFER_TOO_SMALL) {
1143 ImageInfo = AllocateZeroPool (ImageInfoSize);
1144
1145 if (ImageInfo == NULL) {
1146 Status = EFI_OUT_OF_RESOURCES;
1147 } else {
1148 Status = EfiFwMgmtProtocol->GetImageInfo (
1149 EfiFwMgmtProtocol,
1150 &ImageInfoSize,
1151 ImageInfo,
1152 &DescriptorVersion,
1153 &DescriptorCount,
1154 &DescriptorSize,
1155 &PackageVersion,
1156 &PackageVersionName
1157 );
1158 }
1159 }
1160
1161 if (EFI_ERROR (Status)) {
1162 goto ERROR_EXIT;
1163 }
1164
1165 //
1166 // Decode Image Descriptor data only if its version is supported
1167 //
1168 if (DescriptorVersion <= EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION) {
1169
1170 if (ImageInfo == NULL) {
1171 goto ERROR_EXIT;
1172 }
1173
1174 ImageInfoV1 = (EFI_FIRMWARE_IMAGE_DESCRIPTOR_V1 *)ImageInfo;
1175 ImageInfoV2 = (EFI_FIRMWARE_IMAGE_DESCRIPTOR_V2 *)ImageInfo;
1176
1177 //
1178 // Set ImageInfoSize in return buffer
1179 //
1180 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_INFO_SIZE), NULL);
1181 if (TempStr == NULL) {
1182 goto ERROR_EXIT;
1183 }
1184 RetVal = CatSPrint (NULL, TempStr, ImageInfoSize);
1185 SHELL_FREE_NON_NULL (TempStr);
1186
1187 //
1188 // Set DescriptorVersion in return buffer
1189 //
1190 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_VERSION), NULL);
1191 if (TempStr == NULL) {
1192 goto ERROR_EXIT;
1193 }
1194 TempRetVal = CatSPrint (RetVal, TempStr, DescriptorVersion);
1195 SHELL_FREE_NON_NULL (RetVal);
1196 RetVal = TempRetVal;
1197 SHELL_FREE_NON_NULL (TempStr);
1198
1199 //
1200 // Set DescriptorCount in return buffer
1201 //
1202 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_COUNT), NULL);
1203 if (TempStr == NULL) {
1204 goto ERROR_EXIT;
1205 }
1206 TempRetVal = CatSPrint (RetVal, TempStr, DescriptorCount);
1207 SHELL_FREE_NON_NULL (RetVal);
1208 RetVal = TempRetVal;
1209 SHELL_FREE_NON_NULL (TempStr);
1210
1211
1212 //
1213 // Set DescriptorSize in return buffer
1214 //
1215 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_SIZE), NULL);
1216 if (TempStr == NULL) {
1217 goto ERROR_EXIT;
1218 }
1219 TempRetVal = CatSPrint (RetVal, TempStr, DescriptorSize);
1220 SHELL_FREE_NON_NULL (RetVal);
1221 RetVal = TempRetVal;
1222 SHELL_FREE_NON_NULL (TempStr);
1223
1224 //
1225 // Set PackageVersion in return buffer
1226 //
1227 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_PACKAGE_VERSION), NULL);
1228 if (TempStr == NULL) {
1229 goto ERROR_EXIT;
1230 }
1231 TempRetVal = CatSPrint (RetVal, TempStr, PackageVersion);
1232 SHELL_FREE_NON_NULL (RetVal);
1233 RetVal = TempRetVal;
1234 SHELL_FREE_NON_NULL (TempStr);
1235
1236 //
1237 // Set PackageVersionName in return buffer
1238 //
1239 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_PACKAGE_VERSION_NAME), NULL);
1240 if (TempStr == NULL) {
1241 goto ERROR_EXIT;
1242 }
1243 TempRetVal = CatSPrint (RetVal, TempStr, PackageVersionName);
1244 SHELL_FREE_NON_NULL (RetVal);
1245 RetVal = TempRetVal;
1246 SHELL_FREE_NON_NULL (TempStr);
1247
1248 for (Index = 0; Index < DescriptorCount; Index++) {
1249 //
1250 // First check if Attribute is supported
1251 // and generate a string for AttributeSetting field
1252 //
1253 SHELL_FREE_NON_NULL (AttributeSettingStr);
1254 AttributeSupported = FALSE;
1255 AttributeSetting = 0;
1256 if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) {
1257 if (ImageInfoV1[Index].AttributesSupported != 0x0) {
1258 AttributeSupported = TRUE;
1259 AttributeSetting = ImageInfoV1[Index].AttributesSetting;
1260 }
1261 } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) {
1262 if (ImageInfoV2[Index].AttributesSupported != 0x0) {
1263 AttributeSupported = TRUE;
1264 AttributeSetting = ImageInfoV2[Index].AttributesSetting;
1265 }
1266 } else {
1267 if (ImageInfo[Index].AttributesSupported != 0x0) {
1268 AttributeSupported = TRUE;
1269 AttributeSetting = ImageInfo[Index].AttributesSetting;
1270 }
1271 }
1272
1273 if (!AttributeSupported) {
1274 AttributeSettingStr = CatSPrint (NULL, L"None");
1275 } else {
1276 AttributeSettingStr = CatSPrint (NULL, L"(");
1277
1278 if ((AttributeSetting & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) != 0x0) {
1279 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IMAGE_UPDATABLE");
1280 SHELL_FREE_NON_NULL (AttributeSettingStr);
1281 AttributeSettingStr = TempRetVal;
1282 }
1283 if ((AttributeSetting & IMAGE_ATTRIBUTE_RESET_REQUIRED) != 0x0) {
1284 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_RESET_REQUIRED");
1285 SHELL_FREE_NON_NULL (AttributeSettingStr);
1286 AttributeSettingStr = TempRetVal;
1287 }
1288 if ((AttributeSetting & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED) != 0x0) {
1289 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED");
1290 SHELL_FREE_NON_NULL (AttributeSettingStr);
1291 AttributeSettingStr = TempRetVal;
1292 }
1293 if ((AttributeSetting & IMAGE_ATTRIBUTE_IN_USE) != 0x0) {
1294 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IN_USE");
1295 SHELL_FREE_NON_NULL (AttributeSettingStr);
1296 AttributeSettingStr = TempRetVal;
1297 }
1298 if ((AttributeSetting & IMAGE_ATTRIBUTE_UEFI_IMAGE) != 0x0) {
1299 TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_UEFI_IMAGE");
1300 SHELL_FREE_NON_NULL (AttributeSettingStr);
1301 AttributeSettingStr = TempRetVal;
1302 }
1303 TempRetVal = CatSPrint (AttributeSettingStr, L" )");
1304 SHELL_FREE_NON_NULL (AttributeSettingStr);
1305 AttributeSettingStr = TempRetVal;
1306 }
1307
1308 if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) {
1309 if (ImageInfoV1[Index].ImageIndex != 0x0) {
1310 ImageCount++;
1311 }
1312
1313 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO_V1), NULL);
1314 if (TempStr == NULL) {
1315 goto ERROR_EXIT;
1316 }
1317 TempRetVal = CatSPrint (
1318 RetVal,
1319 TempStr,
1320 Index,
1321 ImageInfoV1[Index].ImageIndex,
1322 &ImageInfoV1[Index].ImageTypeId,
1323 ImageInfoV1[Index].ImageId,
1324 ImageInfoV1[Index].ImageIdName,
1325 ImageInfoV1[Index].Version,
1326 ImageInfoV1[Index].VersionName,
1327 ImageInfoV1[Index].Size,
1328 ImageInfoV1[Index].AttributesSupported,
1329 AttributeSettingStr,
1330 ImageInfoV1[Index].Compatibilities
1331 );
1332 SHELL_FREE_NON_NULL (RetVal);
1333 RetVal = TempRetVal;
1334 SHELL_FREE_NON_NULL (TempStr);
1335 } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) {
1336 if (ImageInfoV2[Index].ImageIndex != 0x0) {
1337 ImageCount++;
1338 }
1339
1340 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO_V2), NULL);
1341 if (TempStr == NULL) {
1342 goto ERROR_EXIT;
1343 }
1344 TempRetVal = CatSPrint (
1345 RetVal,
1346 TempStr,
1347 Index,
1348 ImageInfoV2[Index].ImageIndex,
1349 &ImageInfoV2[Index].ImageTypeId,
1350 ImageInfoV2[Index].ImageId,
1351 ImageInfoV2[Index].ImageIdName,
1352 ImageInfoV2[Index].Version,
1353 ImageInfoV2[Index].VersionName,
1354 ImageInfoV2[Index].Size,
1355 ImageInfoV2[Index].AttributesSupported,
1356 AttributeSettingStr,
1357 ImageInfoV2[Index].Compatibilities,
1358 ImageInfoV2[Index].LowestSupportedImageVersion
1359 );
1360 SHELL_FREE_NON_NULL (RetVal);
1361 RetVal = TempRetVal;
1362 SHELL_FREE_NON_NULL (TempStr);
1363 } else {
1364 if (ImageInfo[Index].ImageIndex != 0x0) {
1365 ImageCount++;
1366 }
1367
1368 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO), NULL);
1369 if (TempStr == NULL) {
1370 goto ERROR_EXIT;
1371 }
1372 TempRetVal = CatSPrint (
1373 RetVal,
1374 TempStr,
1375 Index,
1376 ImageInfo[Index].ImageIndex,
1377 &ImageInfo[Index].ImageTypeId,
1378 ImageInfo[Index].ImageId,
1379 ImageInfo[Index].ImageIdName,
1380 ImageInfo[Index].Version,
1381 ImageInfo[Index].VersionName,
1382 ImageInfo[Index].Size,
1383 ImageInfo[Index].AttributesSupported,
1384 AttributeSettingStr,
1385 ImageInfo[Index].Compatibilities,
1386 ImageInfo[Index].LowestSupportedImageVersion,
1387 ImageInfo[Index].LastAttemptVersion,
1388 ImageInfo[Index].LastAttemptStatus,
1389 ImageInfo[Index].HardwareInstance
1390 );
1391 SHELL_FREE_NON_NULL (RetVal);
1392 RetVal = TempRetVal;
1393 SHELL_FREE_NON_NULL (TempStr);
1394 }
1395 }
1396 }
1397
1398 if (ImageCount > 0) {
1399 for (Index=0; Index<DescriptorCount; Index++) {
1400 for (Index1=Index+1; Index1<DescriptorCount; Index1++) {
1401 if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) {
1402 if (ImageInfoV1[Index].ImageId == ImageInfoV1[Index1].ImageId) {
1403 Found = TRUE;
1404 //
1405 // At least one match found indicating presense of non unique ImageId values so no more comparisons needed
1406 //
1407 goto ENDLOOP;
1408 }
1409 } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) {
1410 if (ImageInfoV2[Index].ImageId == ImageInfoV2[Index1].ImageId) {
1411 Found = TRUE;
1412 //
1413 // At least one match found indicating presense of non unique ImageId values so no more comparisons needed
1414 //
1415 goto ENDLOOP;
1416 }
1417 } else {
1418 if (ImageInfo[Index].ImageId == ImageInfo[Index1].ImageId) {
1419 Found = TRUE;
1420 //
1421 // At least one match found indicating presense of non unique ImageId values so no more comparisons needed
1422 //
1423 goto ENDLOOP;
1424 }
1425 }
1426 }
1427 }
1428 }
1429
1430 ENDLOOP:
1431 //
1432 // Check if ImageId with duplicate value was found
1433 //
1434 if (Found) {
1435 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGEID_NON_UNIQUE), NULL);
1436 if (TempStr == NULL) {
1437 goto ERROR_EXIT;
1438 }
1439 TempRetVal = CatSPrint (RetVal, TempStr);
1440 SHELL_FREE_NON_NULL (RetVal);
1441 RetVal = TempRetVal;
1442 SHELL_FREE_NON_NULL (TempStr);
1443 }
1444
1445 SHELL_FREE_NON_NULL (ImageInfo);
1446 SHELL_FREE_NON_NULL (PackageVersionName);
1447 SHELL_FREE_NON_NULL (AttributeSettingStr);
1448
1449 return RetVal;
1450
1451 ERROR_EXIT:
1452 SHELL_FREE_NON_NULL (RetVal);
1453 SHELL_FREE_NON_NULL (ImageInfo);
1454 SHELL_FREE_NON_NULL (PackageVersionName);
1455 SHELL_FREE_NON_NULL (AttributeSettingStr);
1456
1457 return NULL;
1458 }
1459
1460 //
1461 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
1462 //
1463 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
1464 { \
1465 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
1466 }
1467
1468 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
1469 { \
1470 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
1471 }
1472
1473 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
1474 { \
1475 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
1476 }
1477 STATIC CONST EFI_GUID WinNtThunkProtocolGuid = LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID;
1478 STATIC CONST EFI_GUID WinNtIoProtocolGuid = LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID;
1479 STATIC CONST EFI_GUID WinNtSerialPortGuid = LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID;
1480
1481 //
1482 // Deprecated protocols we dont want to link from IntelFrameworkModulePkg
1483 //
1484 #define LOCAL_EFI_ISA_IO_PROTOCOL_GUID \
1485 { \
1486 0x7ee2bd44, 0x3da0, 0x11d4, { 0x9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
1487 }
1488 #define LOCAL_EFI_ISA_ACPI_PROTOCOL_GUID \
1489 { \
1490 0x64a892dc, 0x5561, 0x4536, { 0x92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55 } \
1491 }
1492 STATIC CONST EFI_GUID EfiIsaIoProtocolGuid = LOCAL_EFI_ISA_IO_PROTOCOL_GUID;
1493 STATIC CONST EFI_GUID EfiIsaAcpiProtocolGuid = LOCAL_EFI_ISA_ACPI_PROTOCOL_GUID;
1494
1495
1496 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT[] = {
1497 {STRING_TOKEN(STR_WINNT_THUNK), (EFI_GUID*)&WinNtThunkProtocolGuid, NULL},
1498 {STRING_TOKEN(STR_WINNT_DRIVER_IO), (EFI_GUID*)&WinNtIoProtocolGuid, NULL},
1499 {STRING_TOKEN(STR_WINNT_SERIAL_PORT), (EFI_GUID*)&WinNtSerialPortGuid, NULL},
1500 {0, NULL, NULL},
1501 };
1502
1503 STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = {
1504 {STRING_TOKEN(STR_LOADED_IMAGE), &gEfiLoadedImageProtocolGuid, LoadedImageProtocolDumpInformation},
1505 {STRING_TOKEN(STR_DEVICE_PATH), &gEfiDevicePathProtocolGuid, DevicePathProtocolDumpInformation},
1506 {STRING_TOKEN(STR_IMAGE_PATH), &gEfiLoadedImageDevicePathProtocolGuid, LoadedImageDevicePathProtocolDumpInformation},
1507 {STRING_TOKEN(STR_DEVICE_PATH_UTIL), &gEfiDevicePathUtilitiesProtocolGuid, NULL},
1508 {STRING_TOKEN(STR_DEVICE_PATH_TXT), &gEfiDevicePathToTextProtocolGuid, NULL},
1509 {STRING_TOKEN(STR_DEVICE_PATH_FTXT), &gEfiDevicePathFromTextProtocolGuid, NULL},
1510 {STRING_TOKEN(STR_DEVICE_PATH_PC), &gEfiPcAnsiGuid, NULL},
1511 {STRING_TOKEN(STR_DEVICE_PATH_VT100), &gEfiVT100Guid, NULL},
1512 {STRING_TOKEN(STR_DEVICE_PATH_VT100P), &gEfiVT100PlusGuid, NULL},
1513 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8), &gEfiVTUTF8Guid, NULL},
1514 {STRING_TOKEN(STR_DRIVER_BINDING), &gEfiDriverBindingProtocolGuid, NULL},
1515 {STRING_TOKEN(STR_PLATFORM_OVERRIDE), &gEfiPlatformDriverOverrideProtocolGuid, NULL},
1516 {STRING_TOKEN(STR_BUS_OVERRIDE), &gEfiBusSpecificDriverOverrideProtocolGuid, NULL},
1517 {STRING_TOKEN(STR_DRIVER_DIAG), &gEfiDriverDiagnosticsProtocolGuid, NULL},
1518 {STRING_TOKEN(STR_DRIVER_DIAG2), &gEfiDriverDiagnostics2ProtocolGuid, NULL},
1519 {STRING_TOKEN(STR_DRIVER_CN), &gEfiComponentNameProtocolGuid, NULL},
1520 {STRING_TOKEN(STR_DRIVER_CN2), &gEfiComponentName2ProtocolGuid, NULL},
1521 {STRING_TOKEN(STR_PLAT_DRV_CFG), &gEfiPlatformToDriverConfigurationProtocolGuid, NULL},
1522 {STRING_TOKEN(STR_DRIVER_VERSION), &gEfiDriverSupportedEfiVersionProtocolGuid, DriverEfiVersionProtocolDumpInformation},
1523 {STRING_TOKEN(STR_TXT_IN), &gEfiSimpleTextInProtocolGuid, NULL},
1524 {STRING_TOKEN(STR_TXT_IN_EX), &gEfiSimpleTextInputExProtocolGuid, NULL},
1525 {STRING_TOKEN(STR_TXT_OUT), &gEfiSimpleTextOutProtocolGuid, TxtOutProtocolDumpInformation},
1526 {STRING_TOKEN(STR_SIM_POINTER), &gEfiSimplePointerProtocolGuid, NULL},
1527 {STRING_TOKEN(STR_ABS_POINTER), &gEfiAbsolutePointerProtocolGuid, NULL},
1528 {STRING_TOKEN(STR_SERIAL_IO), &gEfiSerialIoProtocolGuid, NULL},
1529 {STRING_TOKEN(STR_GRAPHICS_OUTPUT), &gEfiGraphicsOutputProtocolGuid, GraphicsOutputProtocolDumpInformation},
1530 {STRING_TOKEN(STR_EDID_DISCOVERED), &gEfiEdidDiscoveredProtocolGuid, EdidDiscoveredProtocolDumpInformation},
1531 {STRING_TOKEN(STR_EDID_ACTIVE), &gEfiEdidActiveProtocolGuid, EdidActiveProtocolDumpInformation},
1532 {STRING_TOKEN(STR_EDID_OVERRIDE), &gEfiEdidOverrideProtocolGuid, NULL},
1533 {STRING_TOKEN(STR_CON_IN), &gEfiConsoleInDeviceGuid, NULL},
1534 {STRING_TOKEN(STR_CON_OUT), &gEfiConsoleOutDeviceGuid, NULL},
1535 {STRING_TOKEN(STR_STD_ERR), &gEfiStandardErrorDeviceGuid, NULL},
1536 {STRING_TOKEN(STR_LOAD_FILE), &gEfiLoadFileProtocolGuid, NULL},
1537 {STRING_TOKEN(STR_LOAD_FILE2), &gEfiLoadFile2ProtocolGuid, NULL},
1538 {STRING_TOKEN(STR_SIMPLE_FILE_SYS), &gEfiSimpleFileSystemProtocolGuid, NULL},
1539 {STRING_TOKEN(STR_TAPE_IO), &gEfiTapeIoProtocolGuid, NULL},
1540 {STRING_TOKEN(STR_DISK_IO), &gEfiDiskIoProtocolGuid, NULL},
1541 {STRING_TOKEN(STR_BLK_IO), &gEfiBlockIoProtocolGuid, NULL},
1542 {STRING_TOKEN(STR_UC), &gEfiUnicodeCollationProtocolGuid, NULL},
1543 {STRING_TOKEN(STR_UC2), &gEfiUnicodeCollation2ProtocolGuid, NULL},
1544 {STRING_TOKEN(STR_PCIRB_IO), &gEfiPciRootBridgeIoProtocolGuid, PciRootBridgeIoDumpInformation},
1545 {STRING_TOKEN(STR_PCI_IO), &gEfiPciIoProtocolGuid, NULL},
1546 {STRING_TOKEN(STR_SCSI_PT), &gEfiScsiPassThruProtocolGuid, NULL},
1547 {STRING_TOKEN(STR_SCSI_IO), &gEfiScsiIoProtocolGuid, NULL},
1548 {STRING_TOKEN(STR_SCSI_PT_EXT), &gEfiExtScsiPassThruProtocolGuid, NULL},
1549 {STRING_TOKEN(STR_ISCSI), &gEfiIScsiInitiatorNameProtocolGuid, NULL},
1550 {STRING_TOKEN(STR_USB_IO), &gEfiUsbIoProtocolGuid, NULL},
1551 {STRING_TOKEN(STR_USB_HC), &gEfiUsbHcProtocolGuid, NULL},
1552 {STRING_TOKEN(STR_USB_HC2), &gEfiUsb2HcProtocolGuid, NULL},
1553 {STRING_TOKEN(STR_DEBUG_SUPPORT), &gEfiDebugSupportProtocolGuid, NULL},
1554 {STRING_TOKEN(STR_DEBUG_PORT), &gEfiDebugPortProtocolGuid, NULL},
1555 {STRING_TOKEN(STR_DECOMPRESS), &gEfiDecompressProtocolGuid, NULL},
1556 {STRING_TOKEN(STR_ACPI_TABLE), &gEfiAcpiTableProtocolGuid, NULL},
1557 {STRING_TOKEN(STR_EBC_INTERPRETER), &gEfiEbcProtocolGuid, NULL},
1558 {STRING_TOKEN(STR_SNP), &gEfiSimpleNetworkProtocolGuid, NULL},
1559 {STRING_TOKEN(STR_NII), &gEfiNetworkInterfaceIdentifierProtocolGuid, NULL},
1560 {STRING_TOKEN(STR_NII_31), &gEfiNetworkInterfaceIdentifierProtocolGuid_31, NULL},
1561 {STRING_TOKEN(STR_PXE_BC), &gEfiPxeBaseCodeProtocolGuid, NULL},
1562 {STRING_TOKEN(STR_PXE_CB), &gEfiPxeBaseCodeCallbackProtocolGuid, NULL},
1563 {STRING_TOKEN(STR_BIS), &gEfiBisProtocolGuid, NULL},
1564 {STRING_TOKEN(STR_MNP_SB), &gEfiManagedNetworkServiceBindingProtocolGuid, NULL},
1565 {STRING_TOKEN(STR_MNP), &gEfiManagedNetworkProtocolGuid, NULL},
1566 {STRING_TOKEN(STR_ARP_SB), &gEfiArpServiceBindingProtocolGuid, NULL},
1567 {STRING_TOKEN(STR_ARP), &gEfiArpProtocolGuid, NULL},
1568 {STRING_TOKEN(STR_DHCPV4_SB), &gEfiDhcp4ServiceBindingProtocolGuid, NULL},
1569 {STRING_TOKEN(STR_DHCPV4), &gEfiDhcp4ProtocolGuid, NULL},
1570 {STRING_TOKEN(STR_TCPV4_SB), &gEfiTcp4ServiceBindingProtocolGuid, NULL},
1571 {STRING_TOKEN(STR_TCPV4), &gEfiTcp4ProtocolGuid, NULL},
1572 {STRING_TOKEN(STR_IPV4_SB), &gEfiIp4ServiceBindingProtocolGuid, NULL},
1573 {STRING_TOKEN(STR_IPV4), &gEfiIp4ProtocolGuid, NULL},
1574 {STRING_TOKEN(STR_IPV4_CFG), &gEfiIp4ConfigProtocolGuid, NULL},
1575 {STRING_TOKEN(STR_IPV4_CFG2), &gEfiIp4Config2ProtocolGuid, NULL},
1576 {STRING_TOKEN(STR_UDPV4_SB), &gEfiUdp4ServiceBindingProtocolGuid, NULL},
1577 {STRING_TOKEN(STR_UDPV4), &gEfiUdp4ProtocolGuid, NULL},
1578 {STRING_TOKEN(STR_MTFTPV4_SB), &gEfiMtftp4ServiceBindingProtocolGuid, NULL},
1579 {STRING_TOKEN(STR_MTFTPV4), &gEfiMtftp4ProtocolGuid, NULL},
1580 {STRING_TOKEN(STR_AUTH_INFO), &gEfiAuthenticationInfoProtocolGuid, NULL},
1581 {STRING_TOKEN(STR_HASH_SB), &gEfiHashServiceBindingProtocolGuid, NULL},
1582 {STRING_TOKEN(STR_HASH), &gEfiHashProtocolGuid, NULL},
1583 {STRING_TOKEN(STR_HII_FONT), &gEfiHiiFontProtocolGuid, NULL},
1584 {STRING_TOKEN(STR_HII_STRING), &gEfiHiiStringProtocolGuid, NULL},
1585 {STRING_TOKEN(STR_HII_IMAGE), &gEfiHiiImageProtocolGuid, NULL},
1586 {STRING_TOKEN(STR_HII_DATABASE), &gEfiHiiDatabaseProtocolGuid, NULL},
1587 {STRING_TOKEN(STR_HII_CONFIG_ROUT), &gEfiHiiConfigRoutingProtocolGuid, NULL},
1588 {STRING_TOKEN(STR_HII_CONFIG_ACC), &gEfiHiiConfigAccessProtocolGuid, NULL},
1589 {STRING_TOKEN(STR_HII_FORM_BROWSER2), &gEfiFormBrowser2ProtocolGuid, NULL},
1590 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE), &gEfiDriverFamilyOverrideProtocolGuid, NULL},
1591 {STRING_TOKEN(STR_PCD), &gPcdProtocolGuid, NULL},
1592 {STRING_TOKEN(STR_TCG), &gEfiTcgProtocolGuid, NULL},
1593 {STRING_TOKEN(STR_HII_PACKAGE_LIST), &gEfiHiiPackageListProtocolGuid, NULL},
1594
1595 //
1596 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
1597 //
1598 {STRING_TOKEN(STR_SHELL_INTERFACE), &gEfiShellInterfaceGuid, NULL},
1599 {STRING_TOKEN(STR_SHELL_ENV2), &gEfiShellEnvironment2Guid, NULL},
1600 {STRING_TOKEN(STR_SHELL_ENV), &gEfiShellEnvironment2Guid, NULL},
1601 {STRING_TOKEN(STR_DEVICE_IO), &gEfiDeviceIoProtocolGuid, NULL},
1602 {STRING_TOKEN(STR_UGA_DRAW), &gEfiUgaDrawProtocolGuid, NULL},
1603 {STRING_TOKEN(STR_UGA_IO), &gEfiUgaIoProtocolGuid, NULL},
1604 {STRING_TOKEN(STR_ESP), &gEfiPartTypeSystemPartGuid, NULL},
1605 {STRING_TOKEN(STR_GPT_NBR), &gEfiPartTypeLegacyMbrGuid, NULL},
1606 {STRING_TOKEN(STR_DRIVER_CONFIG), &gEfiDriverConfigurationProtocolGuid, NULL},
1607 {STRING_TOKEN(STR_DRIVER_CONFIG2), &gEfiDriverConfiguration2ProtocolGuid, NULL},
1608
1609 //
1610 // these are using local (non-global) definitions to reduce package dependancy.
1611 //
1612 {STRING_TOKEN(STR_ISA_IO), (EFI_GUID*)&EfiIsaIoProtocolGuid, NULL},
1613 {STRING_TOKEN(STR_ISA_ACPI), (EFI_GUID*)&EfiIsaAcpiProtocolGuid, NULL},
1614
1615 //
1616 // the ones under this are GUID identified structs, not protocols
1617 //
1618 {STRING_TOKEN(STR_FILE_INFO), &gEfiFileInfoGuid, NULL},
1619 {STRING_TOKEN(STR_FILE_SYS_INFO), &gEfiFileSystemInfoGuid, NULL},
1620
1621 //
1622 // the ones under this are misc GUIDS.
1623 //
1624 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE), &gEfiGlobalVariableGuid, NULL},
1625
1626 //
1627 // UEFI 2.2
1628 //
1629 {STRING_TOKEN(STR_IP6_SB), &gEfiIp6ServiceBindingProtocolGuid, NULL},
1630 {STRING_TOKEN(STR_IP6), &gEfiIp6ProtocolGuid, NULL},
1631 {STRING_TOKEN(STR_IP6_CONFIG), &gEfiIp6ConfigProtocolGuid, NULL},
1632 {STRING_TOKEN(STR_MTFTP6_SB), &gEfiMtftp6ServiceBindingProtocolGuid, NULL},
1633 {STRING_TOKEN(STR_MTFTP6), &gEfiMtftp6ProtocolGuid, NULL},
1634 {STRING_TOKEN(STR_DHCP6_SB), &gEfiDhcp6ServiceBindingProtocolGuid, NULL},
1635 {STRING_TOKEN(STR_DHCP6), &gEfiDhcp6ProtocolGuid, NULL},
1636 {STRING_TOKEN(STR_UDP6_SB), &gEfiUdp6ServiceBindingProtocolGuid, NULL},
1637 {STRING_TOKEN(STR_UDP6), &gEfiUdp6ProtocolGuid, NULL},
1638 {STRING_TOKEN(STR_TCP6_SB), &gEfiTcp6ServiceBindingProtocolGuid, NULL},
1639 {STRING_TOKEN(STR_TCP6), &gEfiTcp6ProtocolGuid, NULL},
1640 {STRING_TOKEN(STR_VLAN_CONFIG), &gEfiVlanConfigProtocolGuid, NULL},
1641 {STRING_TOKEN(STR_EAP), &gEfiEapProtocolGuid, NULL},
1642 {STRING_TOKEN(STR_EAP_MGMT), &gEfiEapManagementProtocolGuid, NULL},
1643 {STRING_TOKEN(STR_FTP4_SB), &gEfiFtp4ServiceBindingProtocolGuid, NULL},
1644 {STRING_TOKEN(STR_FTP4), &gEfiFtp4ProtocolGuid, NULL},
1645 {STRING_TOKEN(STR_IP_SEC_CONFIG), &gEfiIpSecConfigProtocolGuid, NULL},
1646 {STRING_TOKEN(STR_DH), &gEfiDriverHealthProtocolGuid, NULL},
1647 {STRING_TOKEN(STR_DEF_IMG_LOAD), &gEfiDeferredImageLoadProtocolGuid, NULL},
1648 {STRING_TOKEN(STR_USER_CRED), &gEfiUserCredentialProtocolGuid, NULL},
1649 {STRING_TOKEN(STR_USER_MNGR), &gEfiUserManagerProtocolGuid, NULL},
1650 {STRING_TOKEN(STR_ATA_PASS_THRU), &gEfiAtaPassThruProtocolGuid, NULL},
1651
1652 //
1653 // UEFI 2.3
1654 //
1655 {STRING_TOKEN(STR_FW_MGMT), &gEfiFirmwareManagementProtocolGuid, FirmwareManagementDumpInformation},
1656 {STRING_TOKEN(STR_IP_SEC), &gEfiIpSecProtocolGuid, NULL},
1657 {STRING_TOKEN(STR_IP_SEC2), &gEfiIpSec2ProtocolGuid, NULL},
1658
1659 //
1660 // UEFI 2.3.1
1661 //
1662 {STRING_TOKEN(STR_KMS), &gEfiKmsProtocolGuid, NULL},
1663 {STRING_TOKEN(STR_BLK_IO2), &gEfiBlockIo2ProtocolGuid, NULL},
1664 {STRING_TOKEN(STR_SSC), &gEfiStorageSecurityCommandProtocolGuid, NULL},
1665 {STRING_TOKEN(STR_UCRED2), &gEfiUserCredential2ProtocolGuid, NULL},
1666
1667 //
1668 // UEFI 2.4
1669 //
1670 {STRING_TOKEN(STR_DISK_IO2), &gEfiDiskIo2ProtocolGuid, NULL},
1671 {STRING_TOKEN(STR_ADAPTER_INFO), &gEfiAdapterInformationProtocolGuid, AdapterInformationDumpInformation},
1672
1673 //
1674 // PI Spec ones
1675 //
1676 {STRING_TOKEN(STR_IDE_CONT_INIT), &gEfiIdeControllerInitProtocolGuid, NULL},
1677 {STRING_TOKEN(STR_DISK_INFO), &gEfiDiskInfoProtocolGuid, NULL},
1678
1679 //
1680 // PI Spec 1.0
1681 //
1682 {STRING_TOKEN(STR_BDS_ARCH), &gEfiBdsArchProtocolGuid, NULL},
1683 {STRING_TOKEN(STR_CPU_ARCH), &gEfiCpuArchProtocolGuid, NULL},
1684 {STRING_TOKEN(STR_MET_ARCH), &gEfiMetronomeArchProtocolGuid, NULL},
1685 {STRING_TOKEN(STR_MON_ARCH), &gEfiMonotonicCounterArchProtocolGuid, NULL},
1686 {STRING_TOKEN(STR_RTC_ARCH), &gEfiRealTimeClockArchProtocolGuid, NULL},
1687 {STRING_TOKEN(STR_RESET_ARCH), &gEfiResetArchProtocolGuid, NULL},
1688 {STRING_TOKEN(STR_RT_ARCH), &gEfiRuntimeArchProtocolGuid, NULL},
1689 {STRING_TOKEN(STR_SEC_ARCH), &gEfiSecurityArchProtocolGuid, NULL},
1690 {STRING_TOKEN(STR_TIMER_ARCH), &gEfiTimerArchProtocolGuid, NULL},
1691 {STRING_TOKEN(STR_VAR_ARCH), &gEfiVariableWriteArchProtocolGuid, NULL},
1692 {STRING_TOKEN(STR_V_ARCH), &gEfiVariableArchProtocolGuid, NULL},
1693 {STRING_TOKEN(STR_SECP), &gEfiSecurityPolicyProtocolGuid, NULL},
1694 {STRING_TOKEN(STR_WDT_ARCH), &gEfiWatchdogTimerArchProtocolGuid, NULL},
1695 {STRING_TOKEN(STR_SCR), &gEfiStatusCodeRuntimeProtocolGuid, NULL},
1696 {STRING_TOKEN(STR_SMB_HC), &gEfiSmbusHcProtocolGuid, NULL},
1697 {STRING_TOKEN(STR_FV_2), &gEfiFirmwareVolume2ProtocolGuid, NULL},
1698 {STRING_TOKEN(STR_FV_BLOCK), &gEfiFirmwareVolumeBlockProtocolGuid, NULL},
1699 {STRING_TOKEN(STR_CAP_ARCH), &gEfiCapsuleArchProtocolGuid, NULL},
1700 {STRING_TOKEN(STR_MP_SERVICE), &gEfiMpServiceProtocolGuid, NULL},
1701 {STRING_TOKEN(STR_HBRAP), &gEfiPciHostBridgeResourceAllocationProtocolGuid, NULL},
1702 {STRING_TOKEN(STR_PCIP), &gEfiPciPlatformProtocolGuid, NULL},
1703 {STRING_TOKEN(STR_PCIO), &gEfiPciOverrideProtocolGuid, NULL},
1704 {STRING_TOKEN(STR_PCIE), &gEfiPciEnumerationCompleteProtocolGuid, NULL},
1705 {STRING_TOKEN(STR_IPCID), &gEfiIncompatiblePciDeviceSupportProtocolGuid, NULL},
1706 {STRING_TOKEN(STR_PCIHPI), &gEfiPciHotPlugInitProtocolGuid, NULL},
1707 {STRING_TOKEN(STR_PCIHPR), &gEfiPciHotPlugRequestProtocolGuid, NULL},
1708 {STRING_TOKEN(STR_SMBIOS), &gEfiSmbiosProtocolGuid, NULL},
1709 {STRING_TOKEN(STR_S3_SAVE), &gEfiS3SaveStateProtocolGuid, NULL},
1710 {STRING_TOKEN(STR_S3_S_SMM), &gEfiS3SmmSaveStateProtocolGuid, NULL},
1711 {STRING_TOKEN(STR_RSC), &gEfiRscHandlerProtocolGuid, NULL},
1712 {STRING_TOKEN(STR_S_RSC), &gEfiSmmRscHandlerProtocolGuid, NULL},
1713 {STRING_TOKEN(STR_ACPI_SDT), &gEfiAcpiSdtProtocolGuid, NULL},
1714 {STRING_TOKEN(STR_SIO), &gEfiSioProtocolGuid, NULL},
1715 {STRING_TOKEN(STR_S_CPU2), &gEfiSmmCpuIo2ProtocolGuid, NULL},
1716 {STRING_TOKEN(STR_S_BASE2), &gEfiSmmBase2ProtocolGuid, NULL},
1717 {STRING_TOKEN(STR_S_ACC_2), &gEfiSmmAccess2ProtocolGuid, NULL},
1718 {STRING_TOKEN(STR_S_CON_2), &gEfiSmmControl2ProtocolGuid, NULL},
1719 {STRING_TOKEN(STR_S_CONFIG), &gEfiSmmConfigurationProtocolGuid, NULL},
1720 {STRING_TOKEN(STR_S_RTL), &gEfiSmmReadyToLockProtocolGuid, NULL},
1721 {STRING_TOKEN(STR_DS_RTL), &gEfiDxeSmmReadyToLockProtocolGuid, NULL},
1722 {STRING_TOKEN(STR_S_COMM), &gEfiSmmCommunicationProtocolGuid, NULL},
1723 {STRING_TOKEN(STR_S_STAT), &gEfiSmmStatusCodeProtocolGuid, NULL},
1724 {STRING_TOKEN(STR_S_CPU), &gEfiSmmCpuProtocolGuid, NULL},
1725 {STRING_TOKEN(STR_S_PCIRBIO), &gEfiPciRootBridgeIoProtocolGuid, NULL},
1726 {STRING_TOKEN(STR_S_SWD), &gEfiSmmSwDispatch2ProtocolGuid, NULL},
1727 {STRING_TOKEN(STR_S_SXD), &gEfiSmmSxDispatch2ProtocolGuid, NULL},
1728 {STRING_TOKEN(STR_S_PTD2), &gEfiSmmPeriodicTimerDispatch2ProtocolGuid, NULL},
1729 {STRING_TOKEN(STR_S_UD2), &gEfiSmmUsbDispatch2ProtocolGuid, NULL},
1730 {STRING_TOKEN(STR_S_GD2), &gEfiSmmGpiDispatch2ProtocolGuid, NULL},
1731 {STRING_TOKEN(STR_S_SBD2), &gEfiSmmStandbyButtonDispatch2ProtocolGuid, NULL},
1732 {STRING_TOKEN(STR_S_PBD2), &gEfiSmmPowerButtonDispatch2ProtocolGuid, NULL},
1733 {STRING_TOKEN(STR_S_ITD2), &gEfiSmmIoTrapDispatch2ProtocolGuid, NULL},
1734 {STRING_TOKEN(STR_PCD), &gEfiPcdProtocolGuid, NULL},
1735 {STRING_TOKEN(STR_FVB2), &gEfiFirmwareVolumeBlock2ProtocolGuid, NULL},
1736 {STRING_TOKEN(STR_CPUIO2), &gEfiCpuIo2ProtocolGuid, NULL},
1737 {STRING_TOKEN(STR_LEGACY_R2), &gEfiLegacyRegion2ProtocolGuid, NULL},
1738 {STRING_TOKEN(STR_SAL_MIP), &gEfiSalMcaInitPmiProtocolGuid, NULL},
1739 {STRING_TOKEN(STR_ES_BS), &gEfiExtendedSalBootServiceProtocolGuid, NULL},
1740 {STRING_TOKEN(STR_ES_BIO), &gEfiExtendedSalBaseIoServicesProtocolGuid, NULL},
1741 {STRING_TOKEN(STR_ES_STALL), &gEfiExtendedSalStallServicesProtocolGuid, NULL},
1742 {STRING_TOKEN(STR_ES_RTC), &gEfiExtendedSalRtcServicesProtocolGuid, NULL},
1743 {STRING_TOKEN(STR_ES_VS), &gEfiExtendedSalVariableServicesProtocolGuid, NULL},
1744 {STRING_TOKEN(STR_ES_MTC), &gEfiExtendedSalMtcServicesProtocolGuid, NULL},
1745 {STRING_TOKEN(STR_ES_RESET), &gEfiExtendedSalResetServicesProtocolGuid, NULL},
1746 {STRING_TOKEN(STR_ES_SC), &gEfiExtendedSalStatusCodeServicesProtocolGuid, NULL},
1747 {STRING_TOKEN(STR_ES_FBS), &gEfiExtendedSalFvBlockServicesProtocolGuid, NULL},
1748 {STRING_TOKEN(STR_ES_MP), &gEfiExtendedSalMpServicesProtocolGuid, NULL},
1749 {STRING_TOKEN(STR_ES_PAL), &gEfiExtendedSalPalServicesProtocolGuid, NULL},
1750 {STRING_TOKEN(STR_ES_BASE), &gEfiExtendedSalBaseServicesProtocolGuid, NULL},
1751 {STRING_TOKEN(STR_ES_MCA), &gEfiExtendedSalMcaServicesProtocolGuid, NULL},
1752 {STRING_TOKEN(STR_ES_PCI), &gEfiExtendedSalPciServicesProtocolGuid, NULL},
1753 {STRING_TOKEN(STR_ES_CACHE), &gEfiExtendedSalCacheServicesProtocolGuid, NULL},
1754 {STRING_TOKEN(STR_ES_MCA_LOG), &gEfiExtendedSalMcaLogServicesProtocolGuid, NULL},
1755 {STRING_TOKEN(STR_S2ARCH), &gEfiSecurity2ArchProtocolGuid, NULL},
1756 {STRING_TOKEN(STR_EODXE), &gEfiSmmEndOfDxeProtocolGuid, NULL},
1757 {STRING_TOKEN(STR_ISAHC), &gEfiIsaHcProtocolGuid, NULL},
1758 {STRING_TOKEN(STR_ISAHC_B), &gEfiIsaHcServiceBindingProtocolGuid, NULL},
1759 {STRING_TOKEN(STR_SIO_C), &gEfiSioControlProtocolGuid, NULL},
1760 {STRING_TOKEN(STR_GET_PCD), &gEfiGetPcdInfoProtocolGuid, NULL},
1761 {STRING_TOKEN(STR_I2C_M), &gEfiI2cMasterProtocolGuid, NULL},
1762 {STRING_TOKEN(STR_I2CIO), &gEfiI2cIoProtocolGuid, NULL},
1763 {STRING_TOKEN(STR_I2CEN), &gEfiI2cEnumerateProtocolGuid, NULL},
1764 {STRING_TOKEN(STR_I2C_H), &gEfiI2cHostProtocolGuid, NULL},
1765 {STRING_TOKEN(STR_I2C_BCM), &gEfiI2cBusConfigurationManagementProtocolGuid, NULL},
1766 {STRING_TOKEN(STR_TREE), &gEfiTrEEProtocolGuid, NULL},
1767 {STRING_TOKEN(STR_TCG2), &gEfiTcg2ProtocolGuid, NULL},
1768 {STRING_TOKEN(STR_TIMESTAMP), &gEfiTimestampProtocolGuid, NULL},
1769 {STRING_TOKEN(STR_RNG), &gEfiRngProtocolGuid, NULL},
1770 {STRING_TOKEN(STR_NVMEPT), &gEfiNvmExpressPassThruProtocolGuid, NULL},
1771 {STRING_TOKEN(STR_H2_SB), &gEfiHash2ServiceBindingProtocolGuid, NULL},
1772 {STRING_TOKEN(STR_HASH2), &gEfiHash2ProtocolGuid, NULL},
1773 {STRING_TOKEN(STR_BIO_C), &gEfiBlockIoCryptoProtocolGuid, NULL},
1774 {STRING_TOKEN(STR_SCR), &gEfiSmartCardReaderProtocolGuid, NULL},
1775 {STRING_TOKEN(STR_SCE), &gEfiSmartCardEdgeProtocolGuid, NULL},
1776 {STRING_TOKEN(STR_USB_FIO), &gEfiUsbFunctionIoProtocolGuid, NULL},
1777 {STRING_TOKEN(STR_BC_HC), &gEfiBluetoothHcProtocolGuid, NULL},
1778 {STRING_TOKEN(STR_BC_IO_SB), &gEfiBluetoothIoServiceBindingProtocolGuid, NULL},
1779 {STRING_TOKEN(STR_BC_IO), &gEfiBluetoothIoProtocolGuid, NULL},
1780 {STRING_TOKEN(STR_BC_C), &gEfiBluetoothConfigProtocolGuid, NULL},
1781 {STRING_TOKEN(STR_REG_EXP), &gEfiRegularExpressionProtocolGuid, NULL},
1782 {STRING_TOKEN(STR_B_MGR_P), &gEfiBootManagerPolicyProtocolGuid, NULL},
1783 {STRING_TOKEN(STR_CKH), &gEfiConfigKeywordHandlerProtocolGuid, NULL},
1784 {STRING_TOKEN(STR_WIFI), &gEfiWiFiProtocolGuid, NULL},
1785 {STRING_TOKEN(STR_EAP_M), &gEfiEapManagement2ProtocolGuid, NULL},
1786 {STRING_TOKEN(STR_EAP_C), &gEfiEapConfigurationProtocolGuid, NULL},
1787 {STRING_TOKEN(STR_PKCS7), &gEfiPkcs7VerifyProtocolGuid, NULL},
1788 {STRING_TOKEN(STR_NET_DNS4_SB), &gEfiDns4ServiceBindingProtocolGuid, NULL},
1789 {STRING_TOKEN(STR_NET_DNS4), &gEfiDns4ProtocolGuid, NULL},
1790 {STRING_TOKEN(STR_NET_DNS6_SB), &gEfiDns6ServiceBindingProtocolGuid, NULL},
1791 {STRING_TOKEN(STR_NET_DNS6), &gEfiDns6ProtocolGuid, NULL},
1792 {STRING_TOKEN(STR_NET_HTTP_SB), &gEfiHttpServiceBindingProtocolGuid, NULL},
1793 {STRING_TOKEN(STR_NET_HTTP), &gEfiHttpProtocolGuid, NULL},
1794 {STRING_TOKEN(STR_NET_HTTP_U), &gEfiHttpUtilitiesProtocolGuid, NULL},
1795 {STRING_TOKEN(STR_REST), &gEfiRestProtocolGuid, NULL},
1796
1797 //
1798 // UEFI Shell Spec 2.0
1799 //
1800 {STRING_TOKEN(STR_SHELL_PARAMETERS), &gEfiShellParametersProtocolGuid, NULL},
1801 {STRING_TOKEN(STR_SHELL), &gEfiShellProtocolGuid, NULL},
1802
1803 //
1804 // UEFI Shell Spec 2.1
1805 //
1806 {STRING_TOKEN(STR_SHELL_DYNAMIC), &gEfiShellDynamicCommandProtocolGuid, NULL},
1807
1808 //
1809 // Misc
1810 //
1811 {STRING_TOKEN(STR_PCDINFOPROT), &gGetPcdInfoProtocolGuid, NULL},
1812
1813 //
1814 // terminator
1815 //
1816 {0, NULL, NULL},
1817 };
1818
1819 /**
1820 Function to get the node for a protocol or struct from it's GUID.
1821
1822 if Guid is NULL, then ASSERT.
1823
1824 @param[in] Guid The GUID to look for the name of.
1825
1826 @return The node.
1827 **/
1828 CONST GUID_INFO_BLOCK *
1829 InternalShellGetNodeFromGuid(
1830 IN CONST EFI_GUID* Guid
1831 )
1832 {
1833 CONST GUID_INFO_BLOCK *ListWalker;
1834 UINTN LoopCount;
1835
1836 ASSERT(Guid != NULL);
1837
1838 for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) {
1839 if (CompareGuid(ListWalker->GuidId, Guid)) {
1840 return (ListWalker);
1841 }
1842 }
1843
1844 if (PcdGetBool(PcdShellIncludeNtGuids)) {
1845 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
1846 if (CompareGuid(ListWalker->GuidId, Guid)) {
1847 return (ListWalker);
1848 }
1849 }
1850 }
1851 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
1852 if (CompareGuid(ListWalker->GuidId, Guid)) {
1853 return (ListWalker);
1854 }
1855 }
1856 return (NULL);
1857 }
1858
1859 /**
1860 Function to add a new GUID/Name mapping.
1861
1862 @param[in] Guid The Guid
1863 @param[in] NameID The STRING id of the HII string to use
1864 @param[in] DumpFunc The pointer to the dump function
1865
1866
1867 @retval EFI_SUCCESS The operation was sucessful
1868 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
1869 @retval EFI_INVALID_PARAMETER Guid NameId was invalid
1870 **/
1871 EFI_STATUS
1872 InsertNewGuidNameMapping(
1873 IN CONST EFI_GUID *Guid,
1874 IN CONST EFI_STRING_ID NameID,
1875 IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
1876 )
1877 {
1878 ASSERT(Guid != NULL);
1879 ASSERT(NameID != 0);
1880
1881 mGuidList = ReallocatePool(mGuidListCount * sizeof(GUID_INFO_BLOCK), mGuidListCount+1 * sizeof(GUID_INFO_BLOCK), mGuidList);
1882 if (mGuidList == NULL) {
1883 mGuidListCount = 0;
1884 return (EFI_OUT_OF_RESOURCES);
1885 }
1886 mGuidListCount++;
1887
1888 mGuidList[mGuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid);
1889 mGuidList[mGuidListCount - 1].StringId = NameID;
1890 mGuidList[mGuidListCount - 1].DumpInfo = DumpFunc;
1891
1892 if (mGuidList[mGuidListCount - 1].GuidId == NULL) {
1893 return (EFI_OUT_OF_RESOURCES);
1894 }
1895
1896 return (EFI_SUCCESS);
1897 }
1898
1899 /**
1900 Function to add a new GUID/Name mapping.
1901
1902 This cannot overwrite an existing mapping.
1903
1904 @param[in] Guid The Guid
1905 @param[in] TheName The Guid's name
1906 @param[in] Lang RFC4646 language code list or NULL
1907
1908 @retval EFI_SUCCESS The operation was sucessful
1909 @retval EFI_ACCESS_DENIED There was a duplicate
1910 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
1911 @retval EFI_INVALID_PARAMETER Guid or TheName was NULL
1912 **/
1913 EFI_STATUS
1914 EFIAPI
1915 AddNewGuidNameMapping(
1916 IN CONST EFI_GUID *Guid,
1917 IN CONST CHAR16 *TheName,
1918 IN CONST CHAR8 *Lang OPTIONAL
1919 )
1920 {
1921 EFI_STRING_ID NameID;
1922
1923 HandleParsingHiiInit();
1924
1925 if (Guid == NULL || TheName == NULL){
1926 return (EFI_INVALID_PARAMETER);
1927 }
1928
1929 if ((InternalShellGetNodeFromGuid(Guid)) != NULL) {
1930 return (EFI_ACCESS_DENIED);
1931 }
1932
1933 NameID = HiiSetString(mHandleParsingHiiHandle, 0, (CHAR16*)TheName, Lang);
1934 if (NameID == 0) {
1935 return (EFI_OUT_OF_RESOURCES);
1936 }
1937
1938 return (InsertNewGuidNameMapping(Guid, NameID, NULL));
1939 }
1940
1941 /**
1942 Function to get the name of a protocol or struct from it's GUID.
1943
1944 if Guid is NULL, then ASSERT.
1945
1946 @param[in] Guid The GUID to look for the name of.
1947 @param[in] Lang The language to use.
1948
1949 @return pointer to string of the name. The caller
1950 is responsible to free this memory.
1951 **/
1952 CHAR16*
1953 EFIAPI
1954 GetStringNameFromGuid(
1955 IN CONST EFI_GUID *Guid,
1956 IN CONST CHAR8 *Lang OPTIONAL
1957 )
1958 {
1959 CONST GUID_INFO_BLOCK *Id;
1960
1961 HandleParsingHiiInit();
1962
1963 Id = InternalShellGetNodeFromGuid(Guid);
1964 if (Id == NULL) {
1965 return NULL;
1966 }
1967 return HiiGetString (mHandleParsingHiiHandle, Id->StringId, Lang);
1968 }
1969
1970 /**
1971 Function to dump protocol information from a handle.
1972
1973 This function will return a allocated string buffer containing the
1974 information. The caller is responsible for freeing the memory.
1975
1976 If Guid is NULL, ASSERT().
1977 If TheHandle is NULL, ASSERT().
1978
1979 @param[in] TheHandle The handle to dump information from.
1980 @param[in] Guid The GUID of the protocol to dump.
1981 @param[in] Verbose TRUE for extra info. FALSE otherwise.
1982
1983 @return The pointer to string.
1984 @retval NULL An error was encountered.
1985 **/
1986 CHAR16*
1987 EFIAPI
1988 GetProtocolInformationDump(
1989 IN CONST EFI_HANDLE TheHandle,
1990 IN CONST EFI_GUID *Guid,
1991 IN CONST BOOLEAN Verbose
1992 )
1993 {
1994 CONST GUID_INFO_BLOCK *Id;
1995
1996 ASSERT(TheHandle != NULL);
1997 ASSERT(Guid != NULL);
1998
1999 if (TheHandle == NULL || Guid == NULL) {
2000 return (NULL);
2001 }
2002
2003 Id = InternalShellGetNodeFromGuid(Guid);
2004 if (Id != NULL && Id->DumpInfo != NULL) {
2005 return (Id->DumpInfo(TheHandle, Verbose));
2006 }
2007 return (NULL);
2008 }
2009
2010 /**
2011 Function to get the Guid for a protocol or struct based on it's string name.
2012
2013 do not modify the returned Guid.
2014
2015 @param[in] Name The pointer to the string name.
2016 @param[in] Lang The pointer to the language code.
2017 @param[out] Guid The pointer to the Guid.
2018
2019 @retval EFI_SUCCESS The operation was sucessful.
2020 **/
2021 EFI_STATUS
2022 EFIAPI
2023 GetGuidFromStringName(
2024 IN CONST CHAR16 *Name,
2025 IN CONST CHAR8 *Lang OPTIONAL,
2026 OUT EFI_GUID **Guid
2027 )
2028 {
2029 CONST GUID_INFO_BLOCK *ListWalker;
2030 CHAR16 *String;
2031 UINTN LoopCount;
2032
2033 HandleParsingHiiInit();
2034
2035 ASSERT(Guid != NULL);
2036 if (Guid == NULL) {
2037 return (EFI_INVALID_PARAMETER);
2038 }
2039 *Guid = NULL;
2040
2041 if (PcdGetBool(PcdShellIncludeNtGuids)) {
2042 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2043 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2044 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2045 *Guid = ListWalker->GuidId;
2046 }
2047 SHELL_FREE_NON_NULL(String);
2048 if (*Guid != NULL) {
2049 return (EFI_SUCCESS);
2050 }
2051 }
2052 }
2053 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
2054 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2055 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2056 *Guid = ListWalker->GuidId;
2057 }
2058 SHELL_FREE_NON_NULL(String);
2059 if (*Guid != NULL) {
2060 return (EFI_SUCCESS);
2061 }
2062 }
2063
2064 for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) {
2065 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
2066 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
2067 *Guid = ListWalker->GuidId;
2068 }
2069 SHELL_FREE_NON_NULL(String);
2070 if (*Guid != NULL) {
2071 return (EFI_SUCCESS);
2072 }
2073 }
2074
2075 return (EFI_NOT_FOUND);
2076 }
2077
2078 /**
2079 Get best support language for this driver.
2080
2081 First base on the user input language to search, second base on the current
2082 platform used language to search, third get the first language from the
2083 support language list. The caller need to free the buffer of the best language.
2084
2085 @param[in] SupportedLanguages The support languages for this driver.
2086 @param[in] InputLanguage The user input language.
2087 @param[in] Iso639Language Whether get language for ISO639.
2088
2089 @return The best support language for this driver.
2090 **/
2091 CHAR8 *
2092 EFIAPI
2093 GetBestLanguageForDriver (
2094 IN CONST CHAR8 *SupportedLanguages,
2095 IN CONST CHAR8 *InputLanguage,
2096 IN BOOLEAN Iso639Language
2097 )
2098 {
2099 CHAR8 *LanguageVariable;
2100 CHAR8 *BestLanguage;
2101
2102 GetVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid, (VOID**)&LanguageVariable, NULL);
2103
2104 BestLanguage = GetBestLanguage(
2105 SupportedLanguages,
2106 Iso639Language,
2107 (InputLanguage != NULL) ? InputLanguage : "",
2108 (LanguageVariable != NULL) ? LanguageVariable : "",
2109 SupportedLanguages,
2110 NULL
2111 );
2112
2113 if (LanguageVariable != NULL) {
2114 FreePool (LanguageVariable);
2115 }
2116
2117 return BestLanguage;
2118 }
2119
2120 /**
2121 Function to retrieve the driver name (if possible) from the ComponentName or
2122 ComponentName2 protocol
2123
2124 @param[in] TheHandle The driver handle to get the name of.
2125 @param[in] Language The language to use.
2126
2127 @retval NULL The name could not be found.
2128 @return A pointer to the string name. Do not de-allocate the memory.
2129 **/
2130 CONST CHAR16*
2131 EFIAPI
2132 GetStringNameFromHandle(
2133 IN CONST EFI_HANDLE TheHandle,
2134 IN CONST CHAR8 *Language
2135 )
2136 {
2137 EFI_COMPONENT_NAME2_PROTOCOL *CompNameStruct;
2138 EFI_STATUS Status;
2139 CHAR16 *RetVal;
2140 CHAR8 *BestLang;
2141
2142 BestLang = NULL;
2143
2144 Status = gBS->OpenProtocol(
2145 TheHandle,
2146 &gEfiComponentName2ProtocolGuid,
2147 (VOID**)&CompNameStruct,
2148 gImageHandle,
2149 NULL,
2150 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
2151 if (!EFI_ERROR(Status)) {
2152 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
2153 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
2154 if (BestLang != NULL) {
2155 FreePool (BestLang);
2156 BestLang = NULL;
2157 }
2158 if (!EFI_ERROR(Status)) {
2159 return (RetVal);
2160 }
2161 }
2162 Status = gBS->OpenProtocol(
2163 TheHandle,
2164 &gEfiComponentNameProtocolGuid,
2165 (VOID**)&CompNameStruct,
2166 gImageHandle,
2167 NULL,
2168 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
2169 if (!EFI_ERROR(Status)) {
2170 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
2171 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
2172 if (BestLang != NULL) {
2173 FreePool (BestLang);
2174 }
2175 if (!EFI_ERROR(Status)) {
2176 return (RetVal);
2177 }
2178 }
2179 return (NULL);
2180 }
2181
2182 /**
2183 Function to initialize the file global mHandleList object for use in
2184 vonverting handles to index and index to handle.
2185
2186 @retval EFI_SUCCESS The operation was successful.
2187 **/
2188 EFI_STATUS
2189 InternalShellInitHandleList(
2190 VOID
2191 )
2192 {
2193 EFI_STATUS Status;
2194 EFI_HANDLE *HandleBuffer;
2195 UINTN HandleCount;
2196 HANDLE_LIST *ListWalker;
2197
2198 if (mHandleList.NextIndex != 0) {
2199 return EFI_SUCCESS;
2200 }
2201 InitializeListHead(&mHandleList.List.Link);
2202 mHandleList.NextIndex = 1;
2203 Status = gBS->LocateHandleBuffer (
2204 AllHandles,
2205 NULL,
2206 NULL,
2207 &HandleCount,
2208 &HandleBuffer
2209 );
2210 ASSERT_EFI_ERROR(Status);
2211 if (EFI_ERROR(Status)) {
2212 return (Status);
2213 }
2214 for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){
2215 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
2216 if (ListWalker != NULL) {
2217 ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex - 1];
2218 ListWalker->TheIndex = mHandleList.NextIndex;
2219 InsertTailList (&mHandleList.List.Link, &ListWalker->Link);
2220 }
2221 }
2222 FreePool(HandleBuffer);
2223 return (EFI_SUCCESS);
2224 }
2225
2226 /**
2227 Function to retrieve the human-friendly index of a given handle. If the handle
2228 does not have a index one will be automatically assigned. The index value is valid
2229 until the termination of the shell application.
2230
2231 @param[in] TheHandle The handle to retrieve an index for.
2232
2233 @retval 0 A memory allocation failed.
2234 @return The index of the handle.
2235
2236 **/
2237 UINTN
2238 EFIAPI
2239 ConvertHandleToHandleIndex(
2240 IN CONST EFI_HANDLE TheHandle
2241 )
2242 {
2243 EFI_STATUS Status;
2244 EFI_GUID **ProtocolBuffer;
2245 UINTN ProtocolCount;
2246 HANDLE_LIST *ListWalker;
2247
2248 if (TheHandle == NULL) {
2249 return 0;
2250 }
2251
2252 InternalShellInitHandleList();
2253
2254 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
2255 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
2256 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
2257 ){
2258 if (ListWalker->TheHandle == TheHandle) {
2259 //
2260 // Verify that TheHandle is still present in the Handle Database
2261 //
2262 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
2263 if (EFI_ERROR (Status)) {
2264 //
2265 // TheHandle is not present in the Handle Database, so delete from the handle list
2266 //
2267 RemoveEntryList (&ListWalker->Link);
2268 return 0;
2269 }
2270 FreePool (ProtocolBuffer);
2271 return (ListWalker->TheIndex);
2272 }
2273 }
2274
2275 //
2276 // Verify that TheHandle is valid handle
2277 //
2278 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
2279 if (EFI_ERROR (Status)) {
2280 //
2281 // TheHandle is not valid, so do not add to handle list
2282 //
2283 return 0;
2284 }
2285 FreePool (ProtocolBuffer);
2286
2287 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
2288 if (ListWalker == NULL) {
2289 return 0;
2290 }
2291 ListWalker->TheHandle = TheHandle;
2292 ListWalker->TheIndex = mHandleList.NextIndex++;
2293 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);
2294 return (ListWalker->TheIndex);
2295 }
2296
2297
2298
2299 /**
2300 Function to retrieve the EFI_HANDLE from the human-friendly index.
2301
2302 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
2303
2304 @retval NULL The index was invalid.
2305 @return The EFI_HANDLE that index represents.
2306
2307 **/
2308 EFI_HANDLE
2309 EFIAPI
2310 ConvertHandleIndexToHandle(
2311 IN CONST UINTN TheIndex
2312 )
2313 {
2314 EFI_STATUS Status;
2315 EFI_GUID **ProtocolBuffer;
2316 UINTN ProtocolCount;
2317 HANDLE_LIST *ListWalker;
2318
2319 InternalShellInitHandleList();
2320
2321 if (TheIndex >= mHandleList.NextIndex) {
2322 return NULL;
2323 }
2324
2325 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)
2326 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)
2327 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
2328 ){
2329 if (ListWalker->TheIndex == TheIndex && ListWalker->TheHandle != NULL) {
2330 //
2331 // Verify that LinkWalker->TheHandle is valid handle
2332 //
2333 Status = gBS->ProtocolsPerHandle(ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);
2334 if (!EFI_ERROR (Status)) {
2335 FreePool (ProtocolBuffer);
2336 } else {
2337 //
2338 // TheHandle is not valid, so do not add to handle list
2339 //
2340 ListWalker->TheHandle = NULL;
2341 }
2342 return (ListWalker->TheHandle);
2343 }
2344 }
2345 return NULL;
2346 }
2347
2348 /**
2349 Gets all the related EFI_HANDLEs based on the mask supplied.
2350
2351 This function scans all EFI_HANDLES in the UEFI environment's handle database
2352 and returns the ones with the specified relationship (Mask) to the specified
2353 controller handle.
2354
2355 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
2356 If MatchingHandleCount is NULL, then ASSERT.
2357
2358 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
2359 caller freed.
2360
2361 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
2362 @param[in] ControllerHandle The handle with Device Path protocol on it.
2363 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
2364 MatchingHandleBuffer.
2365 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
2366 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
2367 @param[out] HandleType An array of type information.
2368
2369 @retval EFI_SUCCESS The operation was successful, and any related handles
2370 are in MatchingHandleBuffer.
2371 @retval EFI_NOT_FOUND No matching handles were found.
2372 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
2373 **/
2374 EFI_STATUS
2375 EFIAPI
2376 ParseHandleDatabaseByRelationshipWithType (
2377 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
2378 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
2379 IN UINTN *HandleCount,
2380 OUT EFI_HANDLE **HandleBuffer,
2381 OUT UINTN **HandleType
2382 )
2383 {
2384 EFI_STATUS Status;
2385 UINTN HandleIndex;
2386 EFI_GUID **ProtocolGuidArray;
2387 UINTN ArrayCount;
2388 UINTN ProtocolIndex;
2389 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
2390 UINTN OpenInfoCount;
2391 UINTN OpenInfoIndex;
2392 UINTN ChildIndex;
2393 INTN DriverBindingHandleIndex;
2394
2395 ASSERT(HandleCount != NULL);
2396 ASSERT(HandleBuffer != NULL);
2397 ASSERT(HandleType != NULL);
2398 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
2399
2400 *HandleCount = 0;
2401 *HandleBuffer = NULL;
2402 *HandleType = NULL;
2403
2404 //
2405 // Retrieve the list of all handles from the handle database
2406 //
2407 Status = gBS->LocateHandleBuffer (
2408 AllHandles,
2409 NULL,
2410 NULL,
2411 HandleCount,
2412 HandleBuffer
2413 );
2414 if (EFI_ERROR (Status)) {
2415 return (Status);
2416 }
2417
2418 *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));
2419 if (*HandleType == NULL) {
2420 SHELL_FREE_NON_NULL (*HandleBuffer);
2421 *HandleCount = 0;
2422 return EFI_OUT_OF_RESOURCES;
2423 }
2424
2425 DriverBindingHandleIndex = -1;
2426 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
2427 if (DriverBindingHandle != NULL && (*HandleBuffer)[HandleIndex] == DriverBindingHandle) {
2428 DriverBindingHandleIndex = (INTN)HandleIndex;
2429 }
2430 }
2431
2432 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
2433 //
2434 // Retrieve the list of all the protocols on each handle
2435 //
2436 Status = gBS->ProtocolsPerHandle (
2437 (*HandleBuffer)[HandleIndex],
2438 &ProtocolGuidArray,
2439 &ArrayCount
2440 );
2441 if (EFI_ERROR (Status)) {
2442 continue;
2443 }
2444
2445 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
2446
2447 //
2448 // Set the bit describing what this handle has
2449 //
2450 if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) ) {
2451 (*HandleType)[HandleIndex] |= (UINTN)HR_IMAGE_HANDLE;
2452 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) ) {
2453 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_BINDING_HANDLE;
2454 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {
2455 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
2456 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {
2457 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
2458 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) ) {
2459 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
2460 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) ) {
2461 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
2462 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) ) {
2463 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
2464 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) ) {
2465 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
2466 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) ) {
2467 (*HandleType)[HandleIndex] |= (UINTN)HR_DEVICE_HANDLE;
2468 }
2469 //
2470 // Retrieve the list of agents that have opened each protocol
2471 //
2472 Status = gBS->OpenProtocolInformation (
2473 (*HandleBuffer)[HandleIndex],
2474 ProtocolGuidArray[ProtocolIndex],
2475 &OpenInfo,
2476 &OpenInfoCount
2477 );
2478 if (EFI_ERROR (Status)) {
2479 continue;
2480 }
2481
2482 if (ControllerHandle == NULL) {
2483 //
2484 // ControllerHandle == NULL and DriverBindingHandle != NULL.
2485 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
2486 //
2487 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2488 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
2489 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2490 if (DriverBindingHandleIndex != -1) {
2491 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
2492 }
2493 }
2494 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2495 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2496 if (DriverBindingHandleIndex != -1) {
2497 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
2498 }
2499 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2500 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
2501 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
2502 }
2503 }
2504 }
2505 }
2506 }
2507 if (DriverBindingHandle == NULL && ControllerHandle != NULL) {
2508 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
2509 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2510 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2511 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
2512 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2513 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
2514 (*HandleType)[ChildIndex] |= (UINTN)HR_DEVICE_DRIVER;
2515 }
2516 }
2517 }
2518 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2519 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2520 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
2521 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
2522 }
2523 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
2524 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
2525 }
2526 }
2527 }
2528 }
2529 } else {
2530 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2531 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2532 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
2533 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
2534 }
2535 }
2536 }
2537 }
2538 }
2539 if (DriverBindingHandle != NULL && ControllerHandle != NULL) {
2540 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
2541 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
2542 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2543 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
2544 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
2545 if (DriverBindingHandleIndex != -1) {
2546 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
2547 }
2548 }
2549 }
2550 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2551 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
2552 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2553 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
2554 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
2555 }
2556 }
2557 }
2558
2559 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
2560 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
2561 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
2562 }
2563 }
2564 }
2565 }
2566 } else {
2567 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
2568 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
2569 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
2570 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
2571 }
2572 }
2573 }
2574 }
2575 }
2576 FreePool (OpenInfo);
2577 }
2578 FreePool (ProtocolGuidArray);
2579 }
2580 return EFI_SUCCESS;
2581 }
2582
2583 /**
2584 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
2585 supplied.
2586
2587 This function will scan all EFI_HANDLES in the UEFI environment's handle database
2588 and return all the ones with the specified relationship (Mask) to the specified
2589 controller handle.
2590
2591 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
2592 If MatchingHandleCount is NULL, then ASSERT.
2593
2594 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
2595 caller freed.
2596
2597 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
2598 on it.
2599 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
2600 @param[in] Mask Mask of what relationship(s) is desired.
2601 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
2602 MatchingHandleBuffer.
2603 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
2604 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
2605
2606 @retval EFI_SUCCESS The operation was sucessful and any related handles
2607 are in MatchingHandleBuffer;
2608 @retval EFI_NOT_FOUND No matching handles were found.
2609 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
2610 **/
2611 EFI_STATUS
2612 EFIAPI
2613 ParseHandleDatabaseByRelationship (
2614 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,
2615 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
2616 IN CONST UINTN Mask,
2617 IN UINTN *MatchingHandleCount,
2618 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
2619 )
2620 {
2621 EFI_STATUS Status;
2622 UINTN HandleCount;
2623 EFI_HANDLE *HandleBuffer;
2624 UINTN *HandleType;
2625 UINTN HandleIndex;
2626
2627 ASSERT(MatchingHandleCount != NULL);
2628 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);
2629
2630 if ((Mask & HR_VALID_MASK) != Mask) {
2631 return (EFI_INVALID_PARAMETER);
2632 }
2633
2634 if ((Mask & HR_CHILD_HANDLE) != 0 && DriverBindingHandle == NULL) {
2635 return (EFI_INVALID_PARAMETER);
2636 }
2637
2638 *MatchingHandleCount = 0;
2639 if (MatchingHandleBuffer != NULL) {
2640 *MatchingHandleBuffer = NULL;
2641 }
2642
2643 HandleBuffer = NULL;
2644 HandleType = NULL;
2645
2646 Status = ParseHandleDatabaseByRelationshipWithType (
2647 DriverBindingHandle,
2648 ControllerHandle,
2649 &HandleCount,
2650 &HandleBuffer,
2651 &HandleType
2652 );
2653 if (!EFI_ERROR (Status)) {
2654 //
2655 // Count the number of handles that match the attributes in Mask
2656 //
2657 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
2658 if ((HandleType[HandleIndex] & Mask) == Mask) {
2659 (*MatchingHandleCount)++;
2660 }
2661 }
2662 //
2663 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
2664 //
2665 if (*MatchingHandleCount == 0) {
2666 Status = EFI_NOT_FOUND;
2667 } else {
2668
2669 if (MatchingHandleBuffer == NULL) {
2670 //
2671 // Someone just wanted the count...
2672 //
2673 Status = EFI_SUCCESS;
2674 } else {
2675 //
2676 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
2677 //
2678 *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE));
2679 if (*MatchingHandleBuffer == NULL) {
2680 Status = EFI_OUT_OF_RESOURCES;
2681 } else {
2682 for (HandleIndex = 0, *MatchingHandleCount = 0
2683 ; HandleIndex < HandleCount
2684 ; HandleIndex++
2685 ) {
2686 //
2687 // Fill the allocated buffer with the handles that matched the attributes in Mask
2688 //
2689 if ((HandleType[HandleIndex] & Mask) == Mask) {
2690 (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex];
2691 }
2692 }
2693
2694 //
2695 // Make the last one NULL
2696 //
2697 (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL;
2698
2699 Status = EFI_SUCCESS;
2700 } // *MatchingHandleBuffer == NULL (ELSE)
2701 } // MacthingHandleBuffer == NULL (ELSE)
2702 } // *MatchingHandleCount == 0 (ELSE)
2703 } // no error on ParseHandleDatabaseByRelationshipWithType
2704
2705 if (HandleBuffer != NULL) {
2706 FreePool (HandleBuffer);
2707 }
2708
2709 if (HandleType != NULL) {
2710 FreePool (HandleType);
2711 }
2712
2713 ASSERT ((MatchingHandleBuffer == NULL) ||
2714 (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||
2715 (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));
2716 return Status;
2717 }
2718
2719 /**
2720 Gets handles for any child controllers of the passed in controller.
2721
2722 @param[in] ControllerHandle The handle of the "parent controller"
2723 @param[out] MatchingHandleCount Pointer to the number of handles in
2724 MatchingHandleBuffer on return.
2725 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
2726 return.
2727
2728
2729 @retval EFI_SUCCESS The operation was sucessful.
2730 **/
2731 EFI_STATUS
2732 EFIAPI
2733 ParseHandleDatabaseForChildControllers(
2734 IN CONST EFI_HANDLE ControllerHandle,
2735 OUT UINTN *MatchingHandleCount,
2736 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
2737 )
2738 {
2739 EFI_STATUS Status;
2740 UINTN HandleIndex;
2741 UINTN DriverBindingHandleCount;
2742 EFI_HANDLE *DriverBindingHandleBuffer;
2743 UINTN DriverBindingHandleIndex;
2744 UINTN ChildControllerHandleCount;
2745 EFI_HANDLE *ChildControllerHandleBuffer;
2746 UINTN ChildControllerHandleIndex;
2747 EFI_HANDLE *HandleBufferForReturn;
2748
2749 if (MatchingHandleCount == NULL) {
2750 return (EFI_INVALID_PARAMETER);
2751 }
2752 *MatchingHandleCount = 0;
2753
2754 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
2755 ControllerHandle,
2756 &DriverBindingHandleCount,
2757 &DriverBindingHandleBuffer
2758 );
2759 if (EFI_ERROR (Status)) {
2760 return Status;
2761 }
2762
2763 //
2764 // Get a buffer big enough for all the controllers.
2765 //
2766 HandleBufferForReturn = GetHandleListByProtocol(NULL);
2767 if (HandleBufferForReturn == NULL) {
2768 FreePool (DriverBindingHandleBuffer);
2769 return (EFI_NOT_FOUND);
2770 }
2771
2772 for (DriverBindingHandleIndex = 0; DriverBindingHandleIndex < DriverBindingHandleCount; DriverBindingHandleIndex++) {
2773 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
2774 DriverBindingHandleBuffer[DriverBindingHandleIndex],
2775 ControllerHandle,
2776 &ChildControllerHandleCount,
2777 &ChildControllerHandleBuffer
2778 );
2779 if (EFI_ERROR (Status)) {
2780 continue;
2781 }
2782
2783 for (ChildControllerHandleIndex = 0;
2784 ChildControllerHandleIndex < ChildControllerHandleCount;
2785 ChildControllerHandleIndex++
2786 ) {
2787 for (HandleIndex = 0; HandleIndex < *MatchingHandleCount; HandleIndex++) {
2788 if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {
2789 break;
2790 }
2791 }
2792 if (HandleIndex >= *MatchingHandleCount) {
2793 HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];
2794 }
2795 }
2796
2797 FreePool (ChildControllerHandleBuffer);
2798 }
2799
2800 FreePool (DriverBindingHandleBuffer);
2801
2802 if (MatchingHandleBuffer == NULL || *MatchingHandleCount == 0) {
2803 //
2804 // The caller is not interested in the actual handles, or we've found none.
2805 //
2806 FreePool (HandleBufferForReturn);
2807 HandleBufferForReturn = NULL;
2808 }
2809
2810 if (MatchingHandleBuffer != NULL) {
2811 *MatchingHandleBuffer = HandleBufferForReturn;
2812 }
2813
2814 ASSERT ((MatchingHandleBuffer == NULL) ||
2815 (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) ||
2816 (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL));
2817
2818 return (EFI_SUCCESS);
2819 }
2820
2821 /**
2822 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
2823 if necessary to fit all of the data.
2824
2825 If DestinationBuffer is NULL, then ASSERT().
2826
2827 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
2828 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
2829 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
2830 @param[in] SourceSize The number of bytes of SourceBuffer to append.
2831
2832 @retval NULL A memory allocation failed.
2833 @retval NULL A parameter was invalid.
2834 @return A pointer to (*DestinationBuffer).
2835 **/
2836 VOID*
2837 BuffernCatGrow (
2838 IN OUT VOID **DestinationBuffer,
2839 IN OUT UINTN *DestinationSize,
2840 IN VOID *SourceBuffer,
2841 IN UINTN SourceSize
2842 )
2843 {
2844 UINTN LocalDestinationSize;
2845 UINTN LocalDestinationFinalSize;
2846
2847 ASSERT(DestinationBuffer != NULL);
2848
2849 if (SourceSize == 0 || SourceBuffer == NULL) {
2850 return (*DestinationBuffer);
2851 }
2852
2853 if (DestinationSize == NULL) {
2854 LocalDestinationSize = 0;
2855 } else {
2856 LocalDestinationSize = *DestinationSize;
2857 }
2858
2859 LocalDestinationFinalSize = LocalDestinationSize + SourceSize;
2860
2861 if (DestinationSize != NULL) {
2862 *DestinationSize = LocalDestinationSize;
2863 }
2864
2865 if (LocalDestinationSize == 0) {
2866 // allcoate
2867 *DestinationBuffer = AllocateZeroPool(LocalDestinationFinalSize);
2868 } else {
2869 // reallocate
2870 *DestinationBuffer = ReallocatePool(LocalDestinationSize, LocalDestinationFinalSize, *DestinationBuffer);
2871 }
2872
2873 ASSERT(*DestinationBuffer != NULL);
2874
2875 // copy
2876 return (CopyMem(((UINT8*)(*DestinationBuffer)) + LocalDestinationSize, SourceBuffer, SourceSize));
2877 }
2878
2879 /**
2880 Gets handles for any child devices produced by the passed in driver.
2881
2882 @param[in] DriverHandle The handle of the driver.
2883 @param[in] MatchingHandleCount Pointer to the number of handles in
2884 MatchingHandleBuffer on return.
2885 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
2886 return.
2887 @retval EFI_SUCCESS The operation was sucessful.
2888 @sa ParseHandleDatabaseByRelationship
2889 **/
2890 EFI_STATUS
2891 EFIAPI
2892 ParseHandleDatabaseForChildDevices(
2893 IN CONST EFI_HANDLE DriverHandle,
2894 IN UINTN *MatchingHandleCount,
2895 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL
2896 )
2897 {
2898 EFI_HANDLE *Buffer;
2899 EFI_HANDLE *Buffer2;
2900 UINTN Count1;
2901 UINTN Count2;
2902 UINTN HandleIndex;
2903 EFI_STATUS Status;
2904 UINTN HandleBufferSize;
2905
2906 ASSERT(MatchingHandleCount != NULL);
2907
2908 HandleBufferSize = 0;
2909 Buffer = NULL;
2910 Buffer2 = NULL;
2911 *MatchingHandleCount = 0;
2912
2913 Status = PARSE_HANDLE_DATABASE_DEVICES (
2914 DriverHandle,
2915 &Count1,
2916 &Buffer
2917 );
2918 if (!EFI_ERROR (Status)) {
2919 for (HandleIndex = 0; HandleIndex < Count1; HandleIndex++) {
2920 //
2921 // now find the children
2922 //
2923 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
2924 DriverHandle,
2925 Buffer[HandleIndex],
2926 &Count2,
2927 &Buffer2
2928 );
2929 if (EFI_ERROR(Status)) {
2930 break;
2931 }
2932 //
2933 // save out required and optional data elements
2934 //
2935 *MatchingHandleCount += Count2;
2936 if (MatchingHandleBuffer != NULL) {
2937 *MatchingHandleBuffer = BuffernCatGrow((VOID**)MatchingHandleBuffer, &HandleBufferSize, Buffer2, Count2 * sizeof(Buffer2[0]));
2938 }
2939
2940 //
2941 // free the memory
2942 //
2943 if (Buffer2 != NULL) {
2944 FreePool(Buffer2);
2945 }
2946 }
2947 }
2948
2949 if (Buffer != NULL) {
2950 FreePool(Buffer);
2951 }
2952 return (Status);
2953 }
2954
2955 /**
2956 Function to get all handles that support a given protocol or all handles.
2957
2958 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
2959 then the function will return all handles.
2960
2961 @retval NULL A memory allocation failed.
2962 @return A NULL terminated list of handles.
2963 **/
2964 EFI_HANDLE*
2965 EFIAPI
2966 GetHandleListByProtocol (
2967 IN CONST EFI_GUID *ProtocolGuid OPTIONAL
2968 )
2969 {
2970 EFI_HANDLE *HandleList;
2971 UINTN Size;
2972 EFI_STATUS Status;
2973
2974 Size = 0;
2975 HandleList = NULL;
2976
2977 //
2978 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
2979 //
2980 if (ProtocolGuid == NULL) {
2981 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
2982 if (Status == EFI_BUFFER_TOO_SMALL) {
2983 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));
2984 if (HandleList == NULL) {
2985 return (NULL);
2986 }
2987 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);
2988 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
2989 }
2990 } else {
2991 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
2992 if (Status == EFI_BUFFER_TOO_SMALL) {
2993 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));
2994 if (HandleList == NULL) {
2995 return (NULL);
2996 }
2997 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);
2998 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;
2999 }
3000 }
3001 if (EFI_ERROR(Status)) {
3002 if (HandleList != NULL) {
3003 FreePool(HandleList);
3004 }
3005 return (NULL);
3006 }
3007 return (HandleList);
3008 }
3009
3010 /**
3011 Function to get all handles that support some protocols.
3012
3013 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
3014
3015 @retval NULL A memory allocation failed.
3016 @retval NULL ProtocolGuids was NULL.
3017 @return A NULL terminated list of EFI_HANDLEs.
3018 **/
3019 EFI_HANDLE*
3020 EFIAPI
3021 GetHandleListByProtocolList (
3022 IN CONST EFI_GUID **ProtocolGuids
3023 )
3024 {
3025 EFI_HANDLE *HandleList;
3026 UINTN Size;
3027 UINTN TotalSize;
3028 UINTN TempSize;
3029 EFI_STATUS Status;
3030 CONST EFI_GUID **GuidWalker;
3031 EFI_HANDLE *HandleWalker1;
3032 EFI_HANDLE *HandleWalker2;
3033
3034 Size = 0;
3035 HandleList = NULL;
3036 TotalSize = sizeof(EFI_HANDLE);
3037
3038 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++,Size = 0){
3039 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &Size, NULL);
3040 if (Status == EFI_BUFFER_TOO_SMALL) {
3041 TotalSize += Size;
3042 }
3043 }
3044
3045 //
3046 // No handles were found...
3047 //
3048 if (TotalSize == sizeof(EFI_HANDLE)) {
3049 return (NULL);
3050 }
3051
3052 HandleList = AllocateZeroPool(TotalSize);
3053 if (HandleList == NULL) {
3054 return (NULL);
3055 }
3056
3057 Size = 0;
3058 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++){
3059 TempSize = TotalSize - Size;
3060 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &TempSize, HandleList+(Size/sizeof(EFI_HANDLE)));
3061
3062 //
3063 // Allow for missing protocols... Only update the 'used' size upon success.
3064 //
3065 if (!EFI_ERROR(Status)) {
3066 Size += TempSize;
3067 }
3068 }
3069 ASSERT(HandleList[(TotalSize/sizeof(EFI_HANDLE))-1] == NULL);
3070
3071 for (HandleWalker1 = HandleList ; HandleWalker1 != NULL && *HandleWalker1 != NULL ; HandleWalker1++) {
3072 for (HandleWalker2 = HandleWalker1 + 1; HandleWalker2 != NULL && *HandleWalker2 != NULL ; HandleWalker2++) {
3073 if (*HandleWalker1 == *HandleWalker2) {
3074 //
3075 // copy memory back 1 handle width.
3076 //
3077 CopyMem(HandleWalker2, HandleWalker2 + 1, TotalSize - ((HandleWalker2-HandleList+1)*sizeof(EFI_HANDLE)));
3078 }
3079 }
3080 }
3081
3082 return (HandleList);
3083 }
3084
3085 /**
3086 Return all supported GUIDs.
3087
3088 @param[out] Guids The buffer to return all supported GUIDs.
3089 @param[in, out] Count On input, the count of GUIDs the buffer can hold,
3090 On output, the count of GUIDs to return.
3091
3092 @retval EFI_INVALID_PARAMETER Count is NULL.
3093 @retval EFI_BUFFER_TOO_SMALL Buffer is not enough to hold all GUIDs.
3094 @retval EFI_SUCCESS GUIDs are returned successfully.
3095 **/
3096 EFI_STATUS
3097 EFIAPI
3098 GetAllMappingGuids (
3099 OUT EFI_GUID *Guids,
3100 IN OUT UINTN *Count
3101 )
3102 {
3103 UINTN GuidCount;
3104 UINTN NtGuidCount;
3105 UINTN Index;
3106
3107 if (Count == NULL) {
3108 return EFI_INVALID_PARAMETER;
3109 }
3110
3111 NtGuidCount = 0;
3112 if (PcdGetBool (PcdShellIncludeNtGuids)) {
3113 NtGuidCount = ARRAY_SIZE (mGuidStringListNT) - 1;
3114 }
3115 GuidCount = ARRAY_SIZE (mGuidStringList) - 1;
3116
3117 if (*Count < NtGuidCount + GuidCount + mGuidListCount) {
3118 *Count = NtGuidCount + GuidCount + mGuidListCount;
3119 return EFI_BUFFER_TOO_SMALL;
3120 }
3121
3122 for (Index = 0; Index < NtGuidCount; Index++) {
3123 CopyGuid (&Guids[Index], mGuidStringListNT[Index].GuidId);
3124 }
3125
3126 for (Index = 0; Index < GuidCount; Index++) {
3127 CopyGuid (&Guids[NtGuidCount + Index], mGuidStringList[Index].GuidId);
3128 }
3129
3130 for (Index = 0; Index < mGuidListCount; Index++) {
3131 CopyGuid (&Guids[NtGuidCount + GuidCount + Index], mGuidList[Index].GuidId);
3132 }
3133
3134 return EFI_SUCCESS;
3135 }