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