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