]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DevicePathDxe/DevicePathToText.c
sync comments, fix function header, rename variable name to follow coding style.
[mirror_edk2.git] / MdeModulePkg / Universal / DevicePathDxe / DevicePathToText.c
1 /** @file
2 DevicePathToText protocol as defined in the UEFI 2.0 specification.
3
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DevicePath.h"
16
17 /**
18 Adjusts the size of a previously allocated buffer.
19
20 @param OldPool A pointer to the buffer whose size is being adjusted.
21 @param OldSize The size of the current buffer.
22 @param NewSize The size of the new buffer.
23
24 @return A pointer to the new buffer or NULL if allocation fails.
25
26 **/
27 VOID *
28 ReallocatePool (
29 IN VOID *OldPool,
30 IN UINTN OldSize,
31 IN UINTN NewSize
32 )
33 {
34 VOID *NewPool;
35
36 NewPool = NULL;
37 if (NewSize != 0) {
38 NewPool = AllocateZeroPool (NewSize);
39 }
40
41 if (OldPool != NULL) {
42 if (NewPool != NULL) {
43 CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
44 }
45
46 FreePool (OldPool);
47 }
48
49 return NewPool;
50 }
51
52 /**
53 Concatenates a formatted unicode string to allocated pool. The caller must
54 free the resulting buffer.
55
56 @param Str Tracks the allocated pool, size in use, and
57 amount of pool allocated.
58 @param Fmt The format string
59 @param ... Variable arguments based on the format string.
60
61 @return Allocated buffer with the formatted string printed in it.
62 The caller must free the allocated buffer. The buffer
63 allocation is not packed.
64
65 **/
66 CHAR16 *
67 CatPrint (
68 IN OUT POOL_PRINT *Str,
69 IN CHAR16 *Fmt,
70 ...
71 )
72 {
73 UINT16 *AppendStr;
74 VA_LIST Args;
75 UINTN Size;
76
77 AppendStr = AllocateZeroPool (0x1000);
78 if (AppendStr == NULL) {
79 return Str->Str;
80 }
81
82 VA_START (Args, Fmt);
83 UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args);
84 VA_END (Args);
85 if (NULL == Str->Str) {
86 Size = StrSize (AppendStr);
87 Str->Str = AllocateZeroPool (Size);
88 ASSERT (Str->Str != NULL);
89 } else {
90 Size = StrSize (AppendStr) - sizeof (UINT16);
91 Size = Size + StrSize (Str->Str);
92 Str->Str = ReallocatePool (
93 Str->Str,
94 StrSize (Str->Str),
95 Size
96 );
97 ASSERT (Str->Str != NULL);
98 }
99
100 Str->MaxLen = MAX_CHAR * sizeof (UINT16);
101 if (Size < Str->MaxLen) {
102 StrCat (Str->Str, AppendStr);
103 Str->Len = Size - sizeof (UINT16);
104 }
105
106 FreePool (AppendStr);
107 return Str->Str;
108 }
109
110 /**
111 Converts a PCI device path structure to its string representive.
112
113 @param Str The string representive of input device.
114 @param DevPath The input device path structure.
115 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
116 of the display node is used, where applicable. If DisplayOnly
117 is FALSE, then the longer text representation of the display node
118 is used.
119 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
120 representation for a device node can be used, where applicable.
121
122 **/
123 VOID
124 DevPathToTextPci (
125 IN OUT POOL_PRINT *Str,
126 IN VOID *DevPath,
127 IN BOOLEAN DisplayOnly,
128 IN BOOLEAN AllowShortcuts
129 )
130 {
131 PCI_DEVICE_PATH *Pci;
132
133 Pci = DevPath;
134 CatPrint (Str, L"Pci(0x%x,0x%x)", Pci->Device, Pci->Function);
135 }
136
137 /**
138 Converts a PC Card device path structure to its string representive.
139
140 @param Str The string representive of input device.
141 @param DevPath The input device path structure.
142 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
143 of the display node is used, where applicable. If DisplayOnly
144 is FALSE, then the longer text representation of the display node
145 is used.
146 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
147 representation for a device node can be used, where applicable.
148
149 **/
150 VOID
151 DevPathToTextPccard (
152 IN OUT POOL_PRINT *Str,
153 IN VOID *DevPath,
154 IN BOOLEAN DisplayOnly,
155 IN BOOLEAN AllowShortcuts
156 )
157 {
158 PCCARD_DEVICE_PATH *Pccard;
159
160 Pccard = DevPath;
161 CatPrint (Str, L"PcCard(0x%x)", Pccard->FunctionNumber);
162 }
163
164 /**
165 Converts a Memory Map device path structure to its string representive.
166
167 @param Str The string representive of input device.
168 @param DevPath The input device path structure.
169 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
170 of the display node is used, where applicable. If DisplayOnly
171 is FALSE, then the longer text representation of the display node
172 is used.
173 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
174 representation for a device node can be used, where applicable.
175
176 **/
177 VOID
178 DevPathToTextMemMap (
179 IN OUT POOL_PRINT *Str,
180 IN VOID *DevPath,
181 IN BOOLEAN DisplayOnly,
182 IN BOOLEAN AllowShortcuts
183 )
184 {
185 MEMMAP_DEVICE_PATH *MemMap;
186
187 MemMap = DevPath;
188 CatPrint (
189 Str,
190 L"MemoryMapped(0x%x,0x%lx,0x%lx)",
191 MemMap->MemoryType,
192 MemMap->StartingAddress,
193 MemMap->EndingAddress
194 );
195 }
196
197 /**
198 Converts a Vendor device path structure to its string representive.
199
200 @param Str The string representive of input device.
201 @param DevPath The input device path structure.
202 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
203 of the display node is used, where applicable. If DisplayOnly
204 is FALSE, then the longer text representation of the display node
205 is used.
206 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
207 representation for a device node can be used, where applicable.
208
209 **/
210 VOID
211 DevPathToTextVendor (
212 IN OUT POOL_PRINT *Str,
213 IN VOID *DevPath,
214 IN BOOLEAN DisplayOnly,
215 IN BOOLEAN AllowShortcuts
216 )
217 {
218 VENDOR_DEVICE_PATH *Vendor;
219 CHAR16 *Type;
220 UINTN Index;
221 UINTN DataLength;
222 UINT32 FlowControlMap;
223 UINT16 Info;
224
225 Vendor = (VENDOR_DEVICE_PATH *) DevPath;
226 switch (DevicePathType (&Vendor->Header)) {
227 case HARDWARE_DEVICE_PATH:
228 Type = L"Hw";
229 break;
230
231 case MESSAGING_DEVICE_PATH:
232 Type = L"Msg";
233 if (AllowShortcuts) {
234 if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {
235 CatPrint (Str, L"VenPcAnsi()");
236 return ;
237 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {
238 CatPrint (Str, L"VenVt100()");
239 return ;
240 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {
241 CatPrint (Str, L"VenVt100Plus()");
242 return ;
243 } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {
244 CatPrint (Str, L"VenUft8()");
245 return ;
246 } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingUartFlowControlGuid)) {
247 FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);
248 switch (FlowControlMap & 0x00000003) {
249 case 0:
250 CatPrint (Str, L"UartFlowCtrl(%s)", L"None");
251 break;
252
253 case 1:
254 CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");
255 break;
256
257 case 2:
258 CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");
259 break;
260
261 default:
262 break;
263 }
264
265 return ;
266 } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingSASGuid)) {
267 CatPrint (
268 Str,
269 L"SAS(0x%lx,0x%lx,0x%x,",
270 ((SAS_DEVICE_PATH *) Vendor)->SasAddress,
271 ((SAS_DEVICE_PATH *) Vendor)->Lun,
272 ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort
273 );
274 Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);
275 if ((Info & 0x0f) == 0) {
276 CatPrint (Str, L"NoTopology,0,0,0,");
277 } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {
278 CatPrint (
279 Str,
280 L"%s,%s,%s,",
281 ((Info & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",
282 ((Info & (0x1 << 5)) != 0) ? L"External" : L"Internal",
283 ((Info & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"
284 );
285 if ((Info & 0x0f) == 1) {
286 CatPrint (Str, L"0,");
287 } else {
288 CatPrint (Str, L"0x%x,", (Info >> 8) & 0xff);
289 }
290 } else {
291 CatPrint (Str, L"0,0,0,0,");
292 }
293
294 CatPrint (Str, L"0x%x)", ((SAS_DEVICE_PATH *) Vendor)->Reserved);
295 return ;
296 } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {
297 CatPrint (Str, L"DebugPort()");
298 return ;
299 }
300 }
301 break;
302
303 case MEDIA_DEVICE_PATH:
304 Type = L"Media";
305 break;
306
307 default:
308 Type = L"?";
309 break;
310 }
311
312 DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);
313 CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);
314 if (DataLength != 0) {
315 CatPrint (Str, L",");
316 for (Index = 0; Index < DataLength; Index++) {
317 CatPrint (Str, L"%02x", ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);
318 }
319 }
320
321 CatPrint (Str, L")");
322 }
323
324 /**
325 Converts a Controller device path structure to its string representive.
326
327 @param Str The string representive of input device.
328 @param DevPath The input device path structure.
329 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
330 of the display node is used, where applicable. If DisplayOnly
331 is FALSE, then the longer text representation of the display node
332 is used.
333 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
334 representation for a device node can be used, where applicable.
335
336 **/
337 VOID
338 DevPathToTextController (
339 IN OUT POOL_PRINT *Str,
340 IN VOID *DevPath,
341 IN BOOLEAN DisplayOnly,
342 IN BOOLEAN AllowShortcuts
343 )
344 {
345 CONTROLLER_DEVICE_PATH *Controller;
346
347 Controller = DevPath;
348 CatPrint (
349 Str,
350 L"Ctrl(0x%x)",
351 Controller->ControllerNumber
352 );
353 }
354
355 /**
356 Converts a ACPI device path structure to its string representive.
357
358 @param Str The string representive of input device.
359 @param DevPath The input device path structure.
360 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
361 of the display node is used, where applicable. If DisplayOnly
362 is FALSE, then the longer text representation of the display node
363 is used.
364 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
365 representation for a device node can be used, where applicable.
366
367 **/
368 VOID
369 DevPathToTextAcpi (
370 IN OUT POOL_PRINT *Str,
371 IN VOID *DevPath,
372 IN BOOLEAN DisplayOnly,
373 IN BOOLEAN AllowShortcuts
374 )
375 {
376 ACPI_HID_DEVICE_PATH *Acpi;
377
378 Acpi = DevPath;
379 if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
380 switch (EISA_ID_TO_NUM (Acpi->HID)) {
381 case 0x0a03:
382 CatPrint (Str, L"PciRoot(0x%x)", Acpi->UID);
383 break;
384
385 case 0x0604:
386 CatPrint (Str, L"Floppy(0x%x)", Acpi->UID);
387 break;
388
389 case 0x0301:
390 CatPrint (Str, L"Keyboard(0x%x)", Acpi->UID);
391 break;
392
393 case 0x0501:
394 CatPrint (Str, L"Serial(0x%x)", Acpi->UID);
395 break;
396
397 case 0x0401:
398 CatPrint (Str, L"ParallelPort(0x%x)", Acpi->UID);
399 break;
400
401 default:
402 CatPrint (Str, L"Acpi(PNP%04x,0x%x)", EISA_ID_TO_NUM (Acpi->HID), Acpi->UID);
403 break;
404 }
405 } else {
406 CatPrint (Str, L"Acpi(0x%08x,0x%x)", Acpi->HID, Acpi->UID);
407 }
408 }
409
410 /**
411 Converts EISA identification to string.
412
413 @param EisaId The input EISA identification.
414 @param Text A pointer to the output string.
415
416 **/
417 VOID
418 EisaIdToText (
419 IN UINT32 EisaId,
420 IN OUT CHAR16 *Text
421 )
422 {
423 CHAR16 PnpIdStr[17];
424
425 //
426 //UnicodeSPrint ("%X", 0x0a03) => "0000000000000A03"
427 //
428 UnicodeSPrint (PnpIdStr, 17 * 2, L"%16X", EisaId >> 16);
429
430 UnicodeSPrint (
431 Text,
432 sizeof (CHAR16) + sizeof (CHAR16) + sizeof (CHAR16) + sizeof (PnpIdStr),
433 L"%c%c%c%s",
434 '@' + ((EisaId >> 10) & 0x1f),
435 '@' + ((EisaId >> 5) & 0x1f),
436 '@' + ((EisaId >> 0) & 0x1f),
437 PnpIdStr + (16 - 4)
438 );
439 }
440
441 /**
442 Converts a ACPI extended HID device path structure to its string representive.
443
444 @param Str The string representive of input device.
445 @param DevPath The input device path structure.
446 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
447 of the display node is used, where applicable. If DisplayOnly
448 is FALSE, then the longer text representation of the display node
449 is used.
450 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
451 representation for a device node can be used, where applicable.
452
453 **/
454 VOID
455 DevPathToTextAcpiEx (
456 IN OUT POOL_PRINT *Str,
457 IN VOID *DevPath,
458 IN BOOLEAN DisplayOnly,
459 IN BOOLEAN AllowShortcuts
460 )
461 {
462 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
463 CHAR8 *HIDStr;
464 CHAR8 *UIDStr;
465 CHAR8 *CIDStr;
466 CHAR16 HIDText[11];
467 CHAR16 CIDText[11];
468
469 AcpiEx = DevPath;
470 HIDStr = (CHAR8 *) (((UINT8 *) AcpiEx) + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
471 UIDStr = HIDStr + AsciiStrLen (HIDStr) + 1;
472 CIDStr = UIDStr + AsciiStrLen (UIDStr) + 1;
473
474 EisaIdToText (AcpiEx->HID, HIDText);
475 EisaIdToText (AcpiEx->CID, CIDText);
476
477 if ((*HIDStr == '\0') && (*CIDStr == '\0') && (AcpiEx->UID == 0)) {
478 //
479 // use AcpiExp()
480 //
481 CatPrint (
482 Str,
483 L"AcpiExp(%s,%s,%a)",
484 HIDText,
485 CIDText,
486 UIDStr
487 );
488 } else {
489 if (AllowShortcuts) {
490 //
491 // display only
492 //
493 if (AcpiEx->HID == 0) {
494 CatPrint (Str, L"AcpiEx(%a,", HIDStr);
495 } else {
496 CatPrint (Str, L"AcpiEx(%s,", HIDText);
497 }
498
499 if (AcpiEx->UID == 0) {
500 CatPrint (Str, L"%a,", UIDStr);
501 } else {
502 CatPrint (Str, L"0x%x,", AcpiEx->UID);
503 }
504
505 if (AcpiEx->CID == 0) {
506 CatPrint (Str, L"%a)", CIDStr);
507 } else {
508 CatPrint (Str, L"%s)", CIDText);
509 }
510 } else {
511 CatPrint (
512 Str,
513 L"AcpiEx(%s,%s,0x%x,%a,%a,%a)",
514 HIDText,
515 CIDText,
516 AcpiEx->UID,
517 HIDStr,
518 CIDStr,
519 UIDStr
520 );
521 }
522 }
523 }
524
525 /**
526 Converts a ACPI address device path structure to its string representive.
527
528 @param Str The string representive of input device.
529 @param DevPath The input device path structure.
530 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
531 of the display node is used, where applicable. If DisplayOnly
532 is FALSE, then the longer text representation of the display node
533 is used.
534 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
535 representation for a device node can be used, where applicable.
536
537 **/
538 VOID
539 DevPathToTextAcpiAdr (
540 IN OUT POOL_PRINT *Str,
541 IN VOID *DevPath,
542 IN BOOLEAN DisplayOnly,
543 IN BOOLEAN AllowShortcuts
544 )
545 {
546 ACPI_ADR_DEVICE_PATH *AcpiAdr;
547 UINT16 Index;
548 UINT16 Length;
549 UINT16 AdditionalAdrCount;
550
551 AcpiAdr = DevPath;
552 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);
553 AdditionalAdrCount = (UINT16) ((Length - 8) / 4);
554
555 CatPrint (Str, L"AcpiAdr(0x%x", AcpiAdr->ADR);
556 for (Index = 0; Index < AdditionalAdrCount; Index++) {
557 CatPrint (Str, L",0x%x", *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
558 }
559 CatPrint (Str, L")");
560 }
561
562 /**
563 Converts a ATAPI device path structure to its string representive.
564
565 @param Str The string representive of input device.
566 @param DevPath The input device path structure.
567 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
568 of the display node is used, where applicable. If DisplayOnly
569 is FALSE, then the longer text representation of the display node
570 is used.
571 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
572 representation for a device node can be used, where applicable.
573
574 **/
575 VOID
576 DevPathToTextAtapi (
577 IN OUT POOL_PRINT *Str,
578 IN VOID *DevPath,
579 IN BOOLEAN DisplayOnly,
580 IN BOOLEAN AllowShortcuts
581 )
582 {
583 ATAPI_DEVICE_PATH *Atapi;
584
585 Atapi = DevPath;
586
587 if (DisplayOnly) {
588 CatPrint (Str, L"Ata(0x%x)", Atapi->Lun);
589 } else {
590 CatPrint (
591 Str,
592 L"Ata(%s,%s,0x%x)",
593 Atapi->PrimarySecondary ? L"Secondary" : L"Primary",
594 Atapi->SlaveMaster ? L"Slave" : L"Master",
595 Atapi->Lun
596 );
597 }
598 }
599
600 /**
601 Converts a SCSI device path structure to its string representive.
602
603 @param Str The string representive of input device.
604 @param DevPath The input device path structure.
605 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
606 of the display node is used, where applicable. If DisplayOnly
607 is FALSE, then the longer text representation of the display node
608 is used.
609 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
610 representation for a device node can be used, where applicable.
611
612 **/
613 VOID
614 DevPathToTextScsi (
615 IN OUT POOL_PRINT *Str,
616 IN VOID *DevPath,
617 IN BOOLEAN DisplayOnly,
618 IN BOOLEAN AllowShortcuts
619 )
620 {
621 SCSI_DEVICE_PATH *Scsi;
622
623 Scsi = DevPath;
624 CatPrint (Str, L"Scsi(0x%x,0x%x)", Scsi->Pun, Scsi->Lun);
625 }
626
627 /**
628 Converts a Fibre device path structure to its string representive.
629
630 @param Str The string representive of input device.
631 @param DevPath The input device path structure.
632 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
633 of the display node is used, where applicable. If DisplayOnly
634 is FALSE, then the longer text representation of the display node
635 is used.
636 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
637 representation for a device node can be used, where applicable.
638
639 **/
640 VOID
641 DevPathToTextFibre (
642 IN OUT POOL_PRINT *Str,
643 IN VOID *DevPath,
644 IN BOOLEAN DisplayOnly,
645 IN BOOLEAN AllowShortcuts
646 )
647 {
648 FIBRECHANNEL_DEVICE_PATH *Fibre;
649
650 Fibre = DevPath;
651 CatPrint (Str, L"Fibre(0x%lx,0x%lx)", Fibre->WWN, Fibre->Lun);
652 }
653
654 /**
655 Converts a 1394 device path structure to its string representive.
656
657 @param Str The string representive of input device.
658 @param DevPath The input device path structure.
659 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
660 of the display node is used, where applicable. If DisplayOnly
661 is FALSE, then the longer text representation of the display node
662 is used.
663 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
664 representation for a device node can be used, where applicable.
665
666 **/
667 VOID
668 DevPathToText1394 (
669 IN OUT POOL_PRINT *Str,
670 IN VOID *DevPath,
671 IN BOOLEAN DisplayOnly,
672 IN BOOLEAN AllowShortcuts
673 )
674 {
675 F1394_DEVICE_PATH *F1394DevPath;
676
677 F1394DevPath = DevPath;
678 //
679 // Guid has format of IEEE-EUI64
680 //
681 CatPrint (Str, L"I1394(%016lx)", F1394DevPath->Guid);
682 }
683
684 /**
685 Converts a USB device path structure to its string representive.
686
687 @param Str The string representive of input device.
688 @param DevPath The input device path structure.
689 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
690 of the display node is used, where applicable. If DisplayOnly
691 is FALSE, then the longer text representation of the display node
692 is used.
693 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
694 representation for a device node can be used, where applicable.
695
696 **/
697 VOID
698 DevPathToTextUsb (
699 IN OUT POOL_PRINT *Str,
700 IN VOID *DevPath,
701 IN BOOLEAN DisplayOnly,
702 IN BOOLEAN AllowShortcuts
703 )
704 {
705 USB_DEVICE_PATH *Usb;
706
707 Usb = DevPath;
708 CatPrint (Str, L"USB(0x%x,0x%x)", Usb->ParentPortNumber, Usb->InterfaceNumber);
709 }
710
711 /**
712 Converts a USB WWID device path structure to its string representive.
713
714 @param Str The string representive of input device.
715 @param DevPath The input device path structure.
716 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
717 of the display node is used, where applicable. If DisplayOnly
718 is FALSE, then the longer text representation of the display node
719 is used.
720 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
721 representation for a device node can be used, where applicable.
722
723 **/
724 VOID
725 DevPathToTextUsbWWID (
726 IN OUT POOL_PRINT *Str,
727 IN VOID *DevPath,
728 IN BOOLEAN DisplayOnly,
729 IN BOOLEAN AllowShortcuts
730 )
731 {
732 USB_WWID_DEVICE_PATH *UsbWWId;
733 CHAR16 *SerialNumberStr;
734 CHAR16 *NewStr;
735 UINT16 Length;
736
737 UsbWWId = DevPath;
738
739 SerialNumberStr = (CHAR16 *) ((UINT8 *) UsbWWId + sizeof (USB_WWID_DEVICE_PATH));
740 Length = (UINT16) ((DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) UsbWWId) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16));
741 if (SerialNumberStr [Length - 1] != 0) {
742 //
743 // In case no NULL terminator in SerialNumber, create a new one with NULL terminator
744 //
745 NewStr = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), SerialNumberStr);
746 NewStr [Length] = 0;
747 SerialNumberStr = NewStr;
748 }
749
750 CatPrint (
751 Str,
752 L"UsbWwid(0x%x,0x%x,0x%x,\"%s\")",
753 UsbWWId->VendorId,
754 UsbWWId->ProductId,
755 UsbWWId->InterfaceNumber,
756 SerialNumberStr
757 );
758 }
759
760 /**
761 Converts a Logic Unit device path structure to its string representive.
762
763 @param Str The string representive of input device.
764 @param DevPath The input device path structure.
765 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
766 of the display node is used, where applicable. If DisplayOnly
767 is FALSE, then the longer text representation of the display node
768 is used.
769 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
770 representation for a device node can be used, where applicable.
771
772 **/
773 VOID
774 DevPathToTextLogicalUnit (
775 IN OUT POOL_PRINT *Str,
776 IN VOID *DevPath,
777 IN BOOLEAN DisplayOnly,
778 IN BOOLEAN AllowShortcuts
779 )
780 {
781 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
782
783 LogicalUnit = DevPath;
784 CatPrint (Str, L"Unit(0x%x)", LogicalUnit->Lun);
785 }
786
787 /**
788 Converts a USB class device path structure to its string representive.
789
790 @param Str The string representive of input device.
791 @param DevPath The input device path structure.
792 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
793 of the display node is used, where applicable. If DisplayOnly
794 is FALSE, then the longer text representation of the display node
795 is used.
796 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
797 representation for a device node can be used, where applicable.
798
799 **/
800 VOID
801 DevPathToTextUsbClass (
802 IN OUT POOL_PRINT *Str,
803 IN VOID *DevPath,
804 IN BOOLEAN DisplayOnly,
805 IN BOOLEAN AllowShortcuts
806 )
807 {
808 USB_CLASS_DEVICE_PATH *UsbClass;
809 BOOLEAN IsKnownSubClass;
810
811
812 UsbClass = DevPath;
813
814 IsKnownSubClass = TRUE;
815 switch (UsbClass->DeviceClass) {
816 case USB_CLASS_AUDIO:
817 CatPrint (Str, L"UsbAudio");
818 break;
819
820 case USB_CLASS_CDCCONTROL:
821 CatPrint (Str, L"UsbCDCControl");
822 break;
823
824 case USB_CLASS_HID:
825 CatPrint (Str, L"UsbHID");
826 break;
827
828 case USB_CLASS_IMAGE:
829 CatPrint (Str, L"UsbImage");
830 break;
831
832 case USB_CLASS_PRINTER:
833 CatPrint (Str, L"UsbPrinter");
834 break;
835
836 case USB_CLASS_MASS_STORAGE:
837 CatPrint (Str, L"UsbMassStorage");
838 break;
839
840 case USB_CLASS_HUB:
841 CatPrint (Str, L"UsbHub");
842 break;
843
844 case USB_CLASS_CDCDATA:
845 CatPrint (Str, L"UsbCDCData");
846 break;
847
848 case USB_CLASS_SMART_CARD:
849 CatPrint (Str, L"UsbSmartCard");
850 break;
851
852 case USB_CLASS_VIDEO:
853 CatPrint (Str, L"UsbVideo");
854 break;
855
856 case USB_CLASS_DIAGNOSTIC:
857 CatPrint (Str, L"UsbDiagnostic");
858 break;
859
860 case USB_CLASS_WIRELESS:
861 CatPrint (Str, L"UsbWireless");
862 break;
863
864 default:
865 IsKnownSubClass = FALSE;
866 break;
867 }
868
869 if (IsKnownSubClass) {
870 CatPrint (
871 Str,
872 L"(0x%x,0x%x,0x%x,0x%x)",
873 UsbClass->VendorId,
874 UsbClass->ProductId,
875 UsbClass->DeviceSubClass,
876 UsbClass->DeviceProtocol
877 );
878 return;
879 }
880
881 if (UsbClass->DeviceClass == USB_CLASS_RESERVE) {
882 if (UsbClass->DeviceSubClass == USB_SUBCLASS_FW_UPDATE) {
883 CatPrint (
884 Str,
885 L"UsbDeviceFirmwareUpdate(0x%x,0x%x,0x%x)",
886 UsbClass->VendorId,
887 UsbClass->ProductId,
888 UsbClass->DeviceProtocol
889 );
890 return;
891 } else if (UsbClass->DeviceSubClass == USB_SUBCLASS_IRDA_BRIDGE) {
892 CatPrint (
893 Str,
894 L"UsbIrdaBridge(0x%x,0x%x,0x%x)",
895 UsbClass->VendorId,
896 UsbClass->ProductId,
897 UsbClass->DeviceProtocol
898 );
899 return;
900 } else if (UsbClass->DeviceSubClass == USB_SUBCLASS_TEST) {
901 CatPrint (
902 Str,
903 L"UsbTestAndMeasurement(0x%x,0x%x,0x%x)",
904 UsbClass->VendorId,
905 UsbClass->ProductId,
906 UsbClass->DeviceProtocol
907 );
908 return;
909 }
910 }
911
912 CatPrint (
913 Str,
914 L"UsbClass(0x%x,0x%x,0x%x,0x%x,0x%x)",
915 UsbClass->VendorId,
916 UsbClass->ProductId,
917 UsbClass->DeviceClass,
918 UsbClass->DeviceSubClass,
919 UsbClass->DeviceProtocol
920 );
921 }
922
923 /**
924 Converts a SATA device path structure to its string representive.
925
926 @param Str The string representive of input device.
927 @param DevPath The input device path structure.
928 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
929 of the display node is used, where applicable. If DisplayOnly
930 is FALSE, then the longer text representation of the display node
931 is used.
932 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
933 representation for a device node can be used, where applicable.
934
935 **/
936 VOID
937 DevPathToTextSata (
938 IN OUT POOL_PRINT *Str,
939 IN VOID *DevPath,
940 IN BOOLEAN DisplayOnly,
941 IN BOOLEAN AllowShortcuts
942 )
943 {
944 SATA_DEVICE_PATH *Sata;
945
946 Sata = DevPath;
947 CatPrint (
948 Str,
949 L"Sata(0x%x,0x%x,0x%x)",
950 (UINTN) Sata->HBAPortNumber,
951 (UINTN) Sata->PortMultiplierPortNumber,
952 (UINTN) Sata->Lun
953 );
954 }
955
956 /**
957 Converts a I20 device path structure to its string representive.
958
959 @param Str The string representive of input device.
960 @param DevPath The input device path structure.
961 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
962 of the display node is used, where applicable. If DisplayOnly
963 is FALSE, then the longer text representation of the display node
964 is used.
965 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
966 representation for a device node can be used, where applicable.
967
968 **/
969 VOID
970 DevPathToTextI2O (
971 IN OUT POOL_PRINT *Str,
972 IN VOID *DevPath,
973 IN BOOLEAN DisplayOnly,
974 IN BOOLEAN AllowShortcuts
975 )
976 {
977 I2O_DEVICE_PATH *I2ODevPath;
978
979 I2ODevPath = DevPath;
980 CatPrint (Str, L"I2O(0x%x)", I2ODevPath->Tid);
981 }
982
983 /**
984 Converts a MAC address device path structure to its string representive.
985
986 @param Str The string representive of input device.
987 @param DevPath The input device path structure.
988 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
989 of the display node is used, where applicable. If DisplayOnly
990 is FALSE, then the longer text representation of the display node
991 is used.
992 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
993 representation for a device node can be used, where applicable.
994
995 **/
996 VOID
997 DevPathToTextMacAddr (
998 IN OUT POOL_PRINT *Str,
999 IN VOID *DevPath,
1000 IN BOOLEAN DisplayOnly,
1001 IN BOOLEAN AllowShortcuts
1002 )
1003 {
1004 MAC_ADDR_DEVICE_PATH *MacDevPath;
1005 UINTN HwAddressSize;
1006 UINTN Index;
1007
1008 MacDevPath = DevPath;
1009
1010 HwAddressSize = sizeof (EFI_MAC_ADDRESS);
1011 if (MacDevPath->IfType == 0x01 || MacDevPath->IfType == 0x00) {
1012 HwAddressSize = 6;
1013 }
1014
1015 CatPrint (Str, L"MAC(");
1016
1017 for (Index = 0; Index < HwAddressSize; Index++) {
1018 CatPrint (Str, L"%02x", MacDevPath->MacAddress.Addr[Index]);
1019 }
1020
1021 CatPrint (Str, L",0x%x)", MacDevPath->IfType);
1022 }
1023
1024 /**
1025 Converts a IPv4 device path structure to its string representive.
1026
1027 @param Str The string representive of input device.
1028 @param DevPath The input device path structure.
1029 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1030 of the display node is used, where applicable. If DisplayOnly
1031 is FALSE, then the longer text representation of the display node
1032 is used.
1033 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1034 representation for a device node can be used, where applicable.
1035
1036 **/
1037 VOID
1038 DevPathToTextIPv4 (
1039 IN OUT POOL_PRINT *Str,
1040 IN VOID *DevPath,
1041 IN BOOLEAN DisplayOnly,
1042 IN BOOLEAN AllowShortcuts
1043 )
1044 {
1045 IPv4_DEVICE_PATH *IPDevPath;
1046
1047 IPDevPath = DevPath;
1048 if (DisplayOnly) {
1049 CatPrint (
1050 Str,
1051 L"IPv4(%d.%d.%d.%d)",
1052 IPDevPath->RemoteIpAddress.Addr[0],
1053 IPDevPath->RemoteIpAddress.Addr[1],
1054 IPDevPath->RemoteIpAddress.Addr[2],
1055 IPDevPath->RemoteIpAddress.Addr[3]
1056 );
1057 return ;
1058 }
1059
1060 CatPrint (
1061 Str,
1062 L"IPv4(%d.%d.%d.%d,%s,%s,%d.%d.%d.%d)",
1063 IPDevPath->RemoteIpAddress.Addr[0],
1064 IPDevPath->RemoteIpAddress.Addr[1],
1065 IPDevPath->RemoteIpAddress.Addr[2],
1066 IPDevPath->RemoteIpAddress.Addr[3],
1067 IPDevPath->Protocol ? L"TCP" : L"UDP",
1068 (IPDevPath->StaticIpAddress == TRUE) ? L"Static" : L"DHCP",
1069 IPDevPath->LocalIpAddress.Addr[0],
1070 IPDevPath->LocalIpAddress.Addr[1],
1071 IPDevPath->LocalIpAddress.Addr[2],
1072 IPDevPath->LocalIpAddress.Addr[3]
1073 );
1074 }
1075
1076 /**
1077 Converts a IPv6 device path structure to its string representive.
1078
1079 @param Str The string representive of input device.
1080 @param DevPath The input device path structure.
1081 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1082 of the display node is used, where applicable. If DisplayOnly
1083 is FALSE, then the longer text representation of the display node
1084 is used.
1085 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1086 representation for a device node can be used, where applicable.
1087
1088 **/
1089 VOID
1090 DevPathToTextIPv6 (
1091 IN OUT POOL_PRINT *Str,
1092 IN VOID *DevPath,
1093 IN BOOLEAN DisplayOnly,
1094 IN BOOLEAN AllowShortcuts
1095 )
1096 {
1097 IPv6_DEVICE_PATH *IPDevPath;
1098
1099 IPDevPath = DevPath;
1100 if (DisplayOnly) {
1101 CatPrint (
1102 Str,
1103 L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",
1104 IPDevPath->RemoteIpAddress.Addr[0],
1105 IPDevPath->RemoteIpAddress.Addr[1],
1106 IPDevPath->RemoteIpAddress.Addr[2],
1107 IPDevPath->RemoteIpAddress.Addr[3],
1108 IPDevPath->RemoteIpAddress.Addr[4],
1109 IPDevPath->RemoteIpAddress.Addr[5],
1110 IPDevPath->RemoteIpAddress.Addr[6],
1111 IPDevPath->RemoteIpAddress.Addr[7],
1112 IPDevPath->RemoteIpAddress.Addr[8],
1113 IPDevPath->RemoteIpAddress.Addr[9],
1114 IPDevPath->RemoteIpAddress.Addr[10],
1115 IPDevPath->RemoteIpAddress.Addr[11],
1116 IPDevPath->RemoteIpAddress.Addr[12],
1117 IPDevPath->RemoteIpAddress.Addr[13],
1118 IPDevPath->RemoteIpAddress.Addr[14],
1119 IPDevPath->RemoteIpAddress.Addr[15]
1120 );
1121 return ;
1122 }
1123
1124 CatPrint (
1125 Str,
1126 L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x,%s,%s,%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",
1127 IPDevPath->RemoteIpAddress.Addr[0],
1128 IPDevPath->RemoteIpAddress.Addr[1],
1129 IPDevPath->RemoteIpAddress.Addr[2],
1130 IPDevPath->RemoteIpAddress.Addr[3],
1131 IPDevPath->RemoteIpAddress.Addr[4],
1132 IPDevPath->RemoteIpAddress.Addr[5],
1133 IPDevPath->RemoteIpAddress.Addr[6],
1134 IPDevPath->RemoteIpAddress.Addr[7],
1135 IPDevPath->RemoteIpAddress.Addr[8],
1136 IPDevPath->RemoteIpAddress.Addr[9],
1137 IPDevPath->RemoteIpAddress.Addr[10],
1138 IPDevPath->RemoteIpAddress.Addr[11],
1139 IPDevPath->RemoteIpAddress.Addr[12],
1140 IPDevPath->RemoteIpAddress.Addr[13],
1141 IPDevPath->RemoteIpAddress.Addr[14],
1142 IPDevPath->RemoteIpAddress.Addr[15],
1143 IPDevPath->Protocol ? L"TCP" : L"UDP",
1144 (IPDevPath->StaticIpAddress == TRUE) ? L"Static" : L"DHCP",
1145 IPDevPath->LocalIpAddress.Addr[0],
1146 IPDevPath->LocalIpAddress.Addr[1],
1147 IPDevPath->LocalIpAddress.Addr[2],
1148 IPDevPath->LocalIpAddress.Addr[3],
1149 IPDevPath->LocalIpAddress.Addr[4],
1150 IPDevPath->LocalIpAddress.Addr[5],
1151 IPDevPath->LocalIpAddress.Addr[6],
1152 IPDevPath->LocalIpAddress.Addr[7],
1153 IPDevPath->LocalIpAddress.Addr[8],
1154 IPDevPath->LocalIpAddress.Addr[9],
1155 IPDevPath->LocalIpAddress.Addr[10],
1156 IPDevPath->LocalIpAddress.Addr[11],
1157 IPDevPath->LocalIpAddress.Addr[12],
1158 IPDevPath->LocalIpAddress.Addr[13],
1159 IPDevPath->LocalIpAddress.Addr[14],
1160 IPDevPath->LocalIpAddress.Addr[15]
1161 );
1162 }
1163
1164 /**
1165 Converts an Infini Band device path structure to its string representive.
1166
1167 @param Str The string representive of input device.
1168 @param DevPath The input device path structure.
1169 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1170 of the display node is used, where applicable. If DisplayOnly
1171 is FALSE, then the longer text representation of the display node
1172 is used.
1173 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1174 representation for a device node can be used, where applicable.
1175
1176 **/
1177 VOID
1178 DevPathToTextInfiniBand (
1179 IN OUT POOL_PRINT *Str,
1180 IN VOID *DevPath,
1181 IN BOOLEAN DisplayOnly,
1182 IN BOOLEAN AllowShortcuts
1183 )
1184 {
1185 INFINIBAND_DEVICE_PATH *InfiniBand;
1186
1187 InfiniBand = DevPath;
1188 CatPrint (
1189 Str,
1190 L"Infiniband(0x%x,%g,0x%lx,0x%lx,0x%lx)",
1191 InfiniBand->ResourceFlags,
1192 InfiniBand->PortGid,
1193 InfiniBand->ServiceId,
1194 InfiniBand->TargetPortId,
1195 InfiniBand->DeviceId
1196 );
1197 }
1198
1199 /**
1200 Converts a UART device path structure to its string representive.
1201
1202 @param Str The string representive of input device.
1203 @param DevPath The input device path structure.
1204 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1205 of the display node is used, where applicable. If DisplayOnly
1206 is FALSE, then the longer text representation of the display node
1207 is used.
1208 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1209 representation for a device node can be used, where applicable.
1210
1211 **/
1212 VOID
1213 DevPathToTextUart (
1214 IN OUT POOL_PRINT *Str,
1215 IN VOID *DevPath,
1216 IN BOOLEAN DisplayOnly,
1217 IN BOOLEAN AllowShortcuts
1218 )
1219 {
1220 UART_DEVICE_PATH *Uart;
1221 CHAR8 Parity;
1222
1223 Uart = DevPath;
1224 switch (Uart->Parity) {
1225 case 0:
1226 Parity = 'D';
1227 break;
1228
1229 case 1:
1230 Parity = 'N';
1231 break;
1232
1233 case 2:
1234 Parity = 'E';
1235 break;
1236
1237 case 3:
1238 Parity = 'O';
1239 break;
1240
1241 case 4:
1242 Parity = 'M';
1243 break;
1244
1245 case 5:
1246 Parity = 'S';
1247 break;
1248
1249 default:
1250 Parity = 'x';
1251 break;
1252 }
1253
1254 if (Uart->BaudRate == 0) {
1255 CatPrint (Str, L"Uart(DEFAULT,");
1256 } else {
1257 CatPrint (Str, L"Uart(%ld,", Uart->BaudRate);
1258 }
1259
1260 if (Uart->DataBits == 0) {
1261 CatPrint (Str, L"DEFAULT,");
1262 } else {
1263 CatPrint (Str, L"%d,", Uart->DataBits);
1264 }
1265
1266 CatPrint (Str, L"%c,", Parity);
1267
1268 switch (Uart->StopBits) {
1269 case 0:
1270 CatPrint (Str, L"D)");
1271 break;
1272
1273 case 1:
1274 CatPrint (Str, L"1)");
1275 break;
1276
1277 case 2:
1278 CatPrint (Str, L"1.5)");
1279 break;
1280
1281 case 3:
1282 CatPrint (Str, L"2)");
1283 break;
1284
1285 default:
1286 CatPrint (Str, L"x)");
1287 break;
1288 }
1289 }
1290
1291 /**
1292 Converts an iSCSI device path structure to its string representive.
1293
1294 @param Str The string representive of input device.
1295 @param DevPath The input device path structure.
1296 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1297 of the display node is used, where applicable. If DisplayOnly
1298 is FALSE, then the longer text representation of the display node
1299 is used.
1300 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1301 representation for a device node can be used, where applicable.
1302
1303 **/
1304 VOID
1305 DevPathToTextiSCSI (
1306 IN OUT POOL_PRINT *Str,
1307 IN VOID *DevPath,
1308 IN BOOLEAN DisplayOnly,
1309 IN BOOLEAN AllowShortcuts
1310 )
1311 {
1312 ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;
1313 UINT16 Options;
1314
1315 ISCSIDevPath = DevPath;
1316 CatPrint (
1317 Str,
1318 L"iSCSI(%a,0x%x,0x%lx,",
1319 ISCSIDevPath->iSCSITargetName,
1320 ISCSIDevPath->TargetPortalGroupTag,
1321 ISCSIDevPath->Lun
1322 );
1323
1324 Options = ISCSIDevPath->LoginOption;
1325 CatPrint (Str, L"%s,", (((Options >> 1) & 0x0001) != 0) ? L"CRC32C" : L"None");
1326 CatPrint (Str, L"%s,", (((Options >> 3) & 0x0001) != 0) ? L"CRC32C" : L"None");
1327 if (((Options >> 11) & 0x0001) != 0) {
1328 CatPrint (Str, L"%s,", L"None");
1329 } else if (((Options >> 12) & 0x0001) != 0) {
1330 CatPrint (Str, L"%s,", L"CHAP_UNI");
1331 } else {
1332 CatPrint (Str, L"%s,", L"CHAP_BI");
1333
1334 }
1335
1336 CatPrint (Str, L"%s)", (ISCSIDevPath->NetworkProtocol == 0) ? L"TCP" : L"reserved");
1337 }
1338
1339 /**
1340 Converts a Hard drive device path structure to its string representive.
1341
1342 @param Str The string representive of input device.
1343 @param DevPath The input device path structure.
1344 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1345 of the display node is used, where applicable. If DisplayOnly
1346 is FALSE, then the longer text representation of the display node
1347 is used.
1348 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1349 representation for a device node can be used, where applicable.
1350
1351 **/
1352 VOID
1353 DevPathToTextHardDrive (
1354 IN OUT POOL_PRINT *Str,
1355 IN VOID *DevPath,
1356 IN BOOLEAN DisplayOnly,
1357 IN BOOLEAN AllowShortcuts
1358 )
1359 {
1360 HARDDRIVE_DEVICE_PATH *Hd;
1361
1362 Hd = DevPath;
1363 switch (Hd->SignatureType) {
1364 case SIGNATURE_TYPE_MBR:
1365 CatPrint (
1366 Str,
1367 L"HD(%d,%s,0x%08x,",
1368 Hd->PartitionNumber,
1369 L"MBR",
1370 *((UINT32 *) (&(Hd->Signature[0])))
1371 );
1372 break;
1373
1374 case SIGNATURE_TYPE_GUID:
1375 CatPrint (
1376 Str,
1377 L"HD(%d,%s,%g,",
1378 Hd->PartitionNumber,
1379 L"GPT",
1380 (EFI_GUID *) &(Hd->Signature[0])
1381 );
1382 break;
1383
1384 default:
1385 CatPrint (
1386 Str,
1387 L"HD(%d,%d,0,",
1388 Hd->PartitionNumber,
1389 Hd->SignatureType
1390 );
1391 break;
1392 }
1393
1394 CatPrint (Str, L"0x%lx,0x%lx)", Hd->PartitionStart, Hd->PartitionSize);
1395 }
1396
1397 /**
1398 Converts a CDROM device path structure to its string representive.
1399
1400 @param Str The string representive of input device.
1401 @param DevPath The input device path structure.
1402 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1403 of the display node is used, where applicable. If DisplayOnly
1404 is FALSE, then the longer text representation of the display node
1405 is used.
1406 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1407 representation for a device node can be used, where applicable.
1408
1409 **/
1410 VOID
1411 DevPathToTextCDROM (
1412 IN OUT POOL_PRINT *Str,
1413 IN VOID *DevPath,
1414 IN BOOLEAN DisplayOnly,
1415 IN BOOLEAN AllowShortcuts
1416 )
1417 {
1418 CDROM_DEVICE_PATH *Cd;
1419
1420 Cd = DevPath;
1421 if (DisplayOnly) {
1422 CatPrint (Str, L"CDROM(0x%x)", Cd->BootEntry);
1423 return ;
1424 }
1425
1426 CatPrint (Str, L"CDROM(0x%x,0x%lx,0x%lx)", Cd->BootEntry, Cd->PartitionStart, Cd->PartitionSize);
1427 }
1428
1429 /**
1430 Converts a File device path structure to its string representive.
1431
1432 @param Str The string representive of input device.
1433 @param DevPath The input device path structure.
1434 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1435 of the display node is used, where applicable. If DisplayOnly
1436 is FALSE, then the longer text representation of the display node
1437 is used.
1438 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1439 representation for a device node can be used, where applicable.
1440
1441 **/
1442 VOID
1443 DevPathToTextFilePath (
1444 IN OUT POOL_PRINT *Str,
1445 IN VOID *DevPath,
1446 IN BOOLEAN DisplayOnly,
1447 IN BOOLEAN AllowShortcuts
1448 )
1449 {
1450 FILEPATH_DEVICE_PATH *Fp;
1451
1452 Fp = DevPath;
1453 CatPrint (Str, L"%s", Fp->PathName);
1454 }
1455
1456 /**
1457 Converts a Media protocol device path structure to its string representive.
1458
1459 @param Str The string representive of input device.
1460 @param DevPath The input device path structure.
1461 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1462 of the display node is used, where applicable. If DisplayOnly
1463 is FALSE, then the longer text representation of the display node
1464 is used.
1465 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1466 representation for a device node can be used, where applicable.
1467
1468 **/
1469 VOID
1470 DevPathToTextMediaProtocol (
1471 IN OUT POOL_PRINT *Str,
1472 IN VOID *DevPath,
1473 IN BOOLEAN DisplayOnly,
1474 IN BOOLEAN AllowShortcuts
1475 )
1476 {
1477 MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
1478
1479 MediaProt = DevPath;
1480 CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
1481 }
1482
1483 /**
1484 Converts a Firmware Volume device path structure to its string representive.
1485
1486 @param Str The string representive of input device.
1487 @param DevPath The input device path structure.
1488 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1489 of the display node is used, where applicable. If DisplayOnly
1490 is FALSE, then the longer text representation of the display node
1491 is used.
1492 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1493 representation for a device node can be used, where applicable.
1494
1495 **/
1496 VOID
1497 DevPathToTextFv (
1498 IN OUT POOL_PRINT *Str,
1499 IN VOID *DevPath,
1500 IN BOOLEAN DisplayOnly,
1501 IN BOOLEAN AllowShortcuts
1502 )
1503 {
1504 MEDIA_FW_VOL_DEVICE_PATH *Fv;
1505
1506 Fv = DevPath;
1507 CatPrint (Str, L"Fv(%g)", &Fv->FvName);
1508 }
1509
1510 /**
1511 Converts a Firmware Volume File device path structure to its string representive.
1512
1513 @param Str The string representive of input device.
1514 @param DevPath The input device path structure.
1515 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1516 of the display node is used, where applicable. If DisplayOnly
1517 is FALSE, then the longer text representation of the display node
1518 is used.
1519 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1520 representation for a device node can be used, where applicable.
1521
1522 **/
1523 VOID
1524 DevPathToTextFvFile (
1525 IN OUT POOL_PRINT *Str,
1526 IN VOID *DevPath,
1527 IN BOOLEAN DisplayOnly,
1528 IN BOOLEAN AllowShortcuts
1529 )
1530 {
1531 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;
1532
1533 FvFile = DevPath;
1534 CatPrint (Str, L"FvFile(%g)", &FvFile->FvFileName);
1535 }
1536
1537 /**
1538 Converts a BIOS Boot Specification device path structure to its string representive.
1539
1540 @param Str The string representive of input device.
1541 @param DevPath The input device path structure.
1542 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1543 of the display node is used, where applicable. If DisplayOnly
1544 is FALSE, then the longer text representation of the display node
1545 is used.
1546 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1547 representation for a device node can be used, where applicable.
1548
1549 **/
1550 VOID
1551 DevPathToTextBBS (
1552 IN OUT POOL_PRINT *Str,
1553 IN VOID *DevPath,
1554 IN BOOLEAN DisplayOnly,
1555 IN BOOLEAN AllowShortcuts
1556 )
1557 {
1558 BBS_BBS_DEVICE_PATH *Bbs;
1559 CHAR16 *Type;
1560
1561 Bbs = DevPath;
1562 switch (Bbs->DeviceType) {
1563 case BBS_TYPE_FLOPPY:
1564 Type = L"Floppy";
1565 break;
1566
1567 case BBS_TYPE_HARDDRIVE:
1568 Type = L"HD";
1569 break;
1570
1571 case BBS_TYPE_CDROM:
1572 Type = L"CDROM";
1573 break;
1574
1575 case BBS_TYPE_PCMCIA:
1576 Type = L"PCMCIA";
1577 break;
1578
1579 case BBS_TYPE_USB:
1580 Type = L"USB";
1581 break;
1582
1583 case BBS_TYPE_EMBEDDED_NETWORK:
1584 Type = L"Network";
1585 break;
1586
1587 default:
1588 Type = NULL;
1589 break;
1590 }
1591
1592 if (Type != NULL) {
1593 CatPrint (Str, L"BBS(%s,%a", Type, Bbs->String);
1594 } else {
1595 CatPrint (Str, L"BBS(0x%x,%a", Bbs->DeviceType, Bbs->String);
1596 }
1597
1598 if (DisplayOnly) {
1599 CatPrint (Str, L")");
1600 return ;
1601 }
1602
1603 CatPrint (Str, L",0x%x)", Bbs->StatusFlag);
1604 }
1605
1606 /**
1607 Converts an End-of-Device-Path structure to its string representive.
1608
1609 @param Str The string representive of input device.
1610 @param DevPath The input device path structure.
1611 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1612 of the display node is used, where applicable. If DisplayOnly
1613 is FALSE, then the longer text representation of the display node
1614 is used.
1615 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1616 representation for a device node can be used, where applicable.
1617
1618 **/
1619 VOID
1620 DevPathToTextEndInstance (
1621 IN OUT POOL_PRINT *Str,
1622 IN VOID *DevPath,
1623 IN BOOLEAN DisplayOnly,
1624 IN BOOLEAN AllowShortcuts
1625 )
1626 {
1627 CatPrint (Str, L",");
1628 }
1629
1630 /**
1631 Converts an unknown device path structure to its string representive.
1632
1633 @param Str The string representive of input device.
1634 @param DevPath The input device path structure.
1635 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1636 of the display node is used, where applicable. If DisplayOnly
1637 is FALSE, then the longer text representation of the display node
1638 is used.
1639 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1640 representation for a device node can be used, where applicable.
1641
1642 **/
1643 VOID
1644 DevPathToTextNodeUnknown (
1645 IN OUT POOL_PRINT *Str,
1646 IN VOID *DevPath,
1647 IN BOOLEAN DisplayOnly,
1648 IN BOOLEAN AllowShortcuts
1649 )
1650 {
1651 CatPrint (Str, L"?");
1652 }
1653
1654 GLOBAL_REMOVE_IF_UNREFERENCED const DEVICE_PATH_TO_TEXT_TABLE DevPathToTextTable[] = {
1655 {HARDWARE_DEVICE_PATH, HW_PCI_DP, DevPathToTextPci},
1656 {HARDWARE_DEVICE_PATH, HW_PCCARD_DP, DevPathToTextPccard},
1657 {HARDWARE_DEVICE_PATH, HW_MEMMAP_DP, DevPathToTextMemMap},
1658 {HARDWARE_DEVICE_PATH, HW_VENDOR_DP, DevPathToTextVendor},
1659 {HARDWARE_DEVICE_PATH, HW_CONTROLLER_DP, DevPathToTextController},
1660 {ACPI_DEVICE_PATH, ACPI_DP, DevPathToTextAcpi},
1661 {ACPI_DEVICE_PATH, ACPI_EXTENDED_DP, DevPathToTextAcpiEx},
1662 {ACPI_DEVICE_PATH, ACPI_ADR_DP, DevPathToTextAcpiAdr},
1663 {MESSAGING_DEVICE_PATH, MSG_ATAPI_DP, DevPathToTextAtapi},
1664 {MESSAGING_DEVICE_PATH, MSG_SCSI_DP, DevPathToTextScsi},
1665 {MESSAGING_DEVICE_PATH, MSG_FIBRECHANNEL_DP, DevPathToTextFibre},
1666 {MESSAGING_DEVICE_PATH, MSG_1394_DP, DevPathToText1394},
1667 {MESSAGING_DEVICE_PATH, MSG_USB_DP, DevPathToTextUsb},
1668 {MESSAGING_DEVICE_PATH, MSG_USB_WWID_DP, DevPathToTextUsbWWID},
1669 {MESSAGING_DEVICE_PATH, MSG_DEVICE_LOGICAL_UNIT_DP, DevPathToTextLogicalUnit},
1670 {MESSAGING_DEVICE_PATH, MSG_USB_CLASS_DP, DevPathToTextUsbClass},
1671 {MESSAGING_DEVICE_PATH, MSG_SATA_DP, DevPathToTextSata},
1672 {MESSAGING_DEVICE_PATH, MSG_I2O_DP, DevPathToTextI2O},
1673 {MESSAGING_DEVICE_PATH, MSG_MAC_ADDR_DP, DevPathToTextMacAddr},
1674 {MESSAGING_DEVICE_PATH, MSG_IPv4_DP, DevPathToTextIPv4},
1675 {MESSAGING_DEVICE_PATH, MSG_IPv6_DP, DevPathToTextIPv6},
1676 {MESSAGING_DEVICE_PATH, MSG_INFINIBAND_DP, DevPathToTextInfiniBand},
1677 {MESSAGING_DEVICE_PATH, MSG_UART_DP, DevPathToTextUart},
1678 {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, DevPathToTextVendor},
1679 {MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, DevPathToTextiSCSI},
1680 {MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP, DevPathToTextHardDrive},
1681 {MEDIA_DEVICE_PATH, MEDIA_CDROM_DP, DevPathToTextCDROM},
1682 {MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, DevPathToTextVendor},
1683 {MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, DevPathToTextFilePath},
1684 {MEDIA_DEVICE_PATH, MEDIA_PROTOCOL_DP, DevPathToTextMediaProtocol},
1685 {MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, DevPathToTextFilePath},
1686 {MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_VOL_DP, DevPathToTextFv},
1687 {MEDIA_DEVICE_PATH, MEDIA_PIWG_FW_FILE_DP, DevPathToTextFvFile},
1688 {BBS_DEVICE_PATH, BBS_BBS_DP, DevPathToTextBBS},
1689 {END_DEVICE_PATH_TYPE, END_INSTANCE_DEVICE_PATH_SUBTYPE, DevPathToTextEndInstance},
1690 {0, 0, NULL}
1691 };
1692
1693 /**
1694 Converts a device node to its string representation.
1695
1696 @param DeviceNode A Pointer to the device node to be converted.
1697 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1698 of the display node is used, where applicable. If DisplayOnly
1699 is FALSE, then the longer text representation of the display node
1700 is used.
1701 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1702 representation for a device node can be used, where applicable.
1703
1704 @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
1705 is NULL or there was insufficient memory.
1706
1707 **/
1708 CHAR16 *
1709 EFIAPI
1710 ConvertDeviceNodeToText (
1711 IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
1712 IN BOOLEAN DisplayOnly,
1713 IN BOOLEAN AllowShortcuts
1714 )
1715 {
1716 POOL_PRINT Str;
1717 UINTN Index;
1718 UINTN NewSize;
1719 VOID (*DumpNode)(POOL_PRINT *, VOID *, BOOLEAN, BOOLEAN);
1720
1721 if (DeviceNode == NULL) {
1722 return NULL;
1723 }
1724
1725 ZeroMem (&Str, sizeof (Str));
1726
1727 //
1728 // Process the device path node
1729 //
1730 DumpNode = NULL;
1731 for (Index = 0; DevPathToTextTable[Index].Function != NULL; Index++) {
1732 if (DevicePathType (DeviceNode) == DevPathToTextTable[Index].Type &&
1733 DevicePathSubType (DeviceNode) == DevPathToTextTable[Index].SubType
1734 ) {
1735 DumpNode = DevPathToTextTable[Index].Function;
1736 break;
1737 }
1738 }
1739 //
1740 // If not found, use a generic function
1741 //
1742 if (DumpNode == NULL) {
1743 DumpNode = DevPathToTextNodeUnknown;
1744 }
1745
1746 //
1747 // Print this node
1748 //
1749 DumpNode (&Str, (VOID *) DeviceNode, DisplayOnly, AllowShortcuts);
1750
1751 //
1752 // Shrink pool used for string allocation
1753 //
1754 NewSize = (Str.Len + 1) * sizeof (CHAR16);
1755 Str.Str = ReallocatePool (Str.Str, NewSize, NewSize);
1756 ASSERT (Str.Str != NULL);
1757 Str.Str[Str.Len] = 0;
1758 return Str.Str;
1759 }
1760
1761 /**
1762 Converts a device path to its text representation.
1763
1764 @param DevicePath A Pointer to the device to be converted.
1765 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
1766 of the display node is used, where applicable. If DisplayOnly
1767 is FALSE, then the longer text representation of the display node
1768 is used.
1769 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
1770 representation for a device node can be used, where applicable.
1771
1772 @return A pointer to the allocated text representation of the device path or
1773 NULL if DeviceNode is NULL or there was insufficient memory.
1774
1775 **/
1776 CHAR16 *
1777 EFIAPI
1778 ConvertDevicePathToText (
1779 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
1780 IN BOOLEAN DisplayOnly,
1781 IN BOOLEAN AllowShortcuts
1782 )
1783 {
1784 POOL_PRINT Str;
1785 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
1786 EFI_DEVICE_PATH_PROTOCOL *AlignedDevPathNode;
1787 UINTN Index;
1788 UINTN NewSize;
1789 VOID (*DumpNode) (POOL_PRINT *, VOID *, BOOLEAN, BOOLEAN);
1790
1791 if (DevicePath == NULL) {
1792 return NULL;
1793 }
1794
1795 ZeroMem (&Str, sizeof (Str));
1796
1797 //
1798 // Process each device path node
1799 //
1800 DevPathNode = (EFI_DEVICE_PATH_PROTOCOL *) DevicePath;
1801 while (!IsDevicePathEnd (DevPathNode)) {
1802 //
1803 // Find the handler to dump this device path node
1804 //
1805 DumpNode = NULL;
1806 for (Index = 0; DevPathToTextTable[Index].Function; Index += 1) {
1807
1808 if (DevicePathType (DevPathNode) == DevPathToTextTable[Index].Type &&
1809 DevicePathSubType (DevPathNode) == DevPathToTextTable[Index].SubType
1810 ) {
1811 DumpNode = DevPathToTextTable[Index].Function;
1812 break;
1813 }
1814 }
1815 //
1816 // If not found, use a generic function
1817 //
1818 if (!DumpNode) {
1819 DumpNode = DevPathToTextNodeUnknown;
1820 }
1821 //
1822 // Put a path seperator in if needed
1823 //
1824 if ((Str.Len != 0) && DumpNode != DevPathToTextEndInstance) {
1825 if (*(Str.Str + Str.Len / sizeof (CHAR16) - 1) != L',') {
1826 CatPrint (&Str, L"/");
1827 }
1828 }
1829
1830 AlignedDevPathNode = AllocateCopyPool (DevicePathNodeLength (DevPathNode), DevPathNode);
1831 //
1832 // Print this node of the device path
1833 //
1834 DumpNode (&Str, AlignedDevPathNode, DisplayOnly, AllowShortcuts);
1835 FreePool (AlignedDevPathNode);
1836
1837 //
1838 // Next device path node
1839 //
1840 DevPathNode = NextDevicePathNode (DevPathNode);
1841 }
1842
1843 NewSize = (Str.Len + 1) * sizeof (CHAR16);
1844 Str.Str = ReallocatePool (Str.Str, NewSize, NewSize);
1845 ASSERT (Str.Str != NULL);
1846 Str.Str[Str.Len] = 0;
1847 return Str.Str;
1848 }