]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/GenericBdsLib/DevicePath.c
Move BdsDxe and GenericBdsLib to IntelFrameworkModulePkg, these modules need dependen...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / DevicePath.c
1 /** @file
2 BDS internal function define the default device path string, it can be
3 replaced by platform device path.
4
5 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "InternalBdsLib.h"
17
18 /**
19 Concatenates a formatted unicode string to allocated pool.
20 The caller must free the resulting buffer.
21
22 @param Str Tracks the allocated pool, size in use, and amount of pool allocated.
23 @param fmt The format string
24 @param ... The data will be printed.
25
26 @return Allocated buffer with the formatted string printed in it.
27 The caller must free the allocated buffer.
28 The buffer allocation is not packed.
29
30 **/
31 CHAR16 *
32 EFIAPI
33 CatPrint (
34 IN OUT POOL_PRINT *Str,
35 IN CHAR16 *fmt,
36 ...
37 )
38 {
39 UINT16 *AppendStr;
40 VA_LIST Args;
41 UINTN StringSize;
42
43 AppendStr = AllocateZeroPool (0x1000);
44 if (AppendStr == NULL) {
45 return Str->str;
46 }
47
48 VA_START (Args, fmt);
49 UnicodeVSPrint (AppendStr, 0x1000, fmt, Args);
50 VA_END (Args);
51 if (NULL == Str->str) {
52 StringSize = StrSize (AppendStr);
53 Str->str = AllocateZeroPool (StringSize);
54 ASSERT (Str->str != NULL);
55 } else {
56 StringSize = StrSize (AppendStr);
57 StringSize += (StrSize (Str->str) - sizeof (UINT16));
58
59 Str->str = ReallocatePool (
60 StrSize (Str->str),
61 StringSize,
62 Str->str
63 );
64 ASSERT (Str->str != NULL);
65 }
66
67 Str->maxlen = MAX_CHAR * sizeof (UINT16);
68 if (StringSize < Str->maxlen) {
69 StrCat (Str->str, AppendStr);
70 Str->len = StringSize - sizeof (UINT16);
71 }
72
73 FreePool (AppendStr);
74 return Str->str;
75 }
76
77 /**
78 Convert Device Path to a Unicode string for printing.
79
80 @param Str The buffer holding the output string.
81 This buffer contains the length of the
82 string and the maixmum length reserved
83 for the string buffer.
84 @param DevPath The device path.
85
86 **/
87 VOID
88 DevPathPci (
89 IN OUT POOL_PRINT *Str,
90 IN VOID *DevPath
91 )
92 {
93 PCI_DEVICE_PATH *Pci;
94
95 Pci = DevPath;
96 CatPrint (Str, L"Pci(%x|%x)", (UINTN) Pci->Device, (UINTN) Pci->Function);
97 }
98
99 /**
100 Convert Device Path to a Unicode string for printing.
101
102 @param Str The buffer holding the output string.
103 This buffer contains the length of the
104 string and the maixmum length reserved
105 for the string buffer.
106 @param DevPath The device path.
107
108 **/
109 VOID
110 DevPathPccard (
111 IN OUT POOL_PRINT *Str,
112 IN VOID *DevPath
113 )
114 {
115 PCCARD_DEVICE_PATH *Pccard;
116
117 Pccard = DevPath;
118 CatPrint (Str, L"Pcmcia(Function%x)", (UINTN) Pccard->FunctionNumber);
119 }
120
121 /**
122 Convert Device Path to a Unicode string for printing.
123
124 @param Str The buffer holding the output string.
125 This buffer contains the length of the
126 string and the maixmum length reserved
127 for the string buffer.
128 @param DevPath The device path.
129
130 **/
131 VOID
132 DevPathMemMap (
133 IN OUT POOL_PRINT *Str,
134 IN VOID *DevPath
135 )
136 {
137 MEMMAP_DEVICE_PATH *MemMap;
138
139 MemMap = DevPath;
140 CatPrint (
141 Str,
142 L"MemMap(%d:%lx-%lx)",
143 MemMap->MemoryType,
144 MemMap->StartingAddress,
145 MemMap->EndingAddress
146 );
147 }
148
149 /**
150 Convert Device Path to a Unicode string for printing.
151
152 @param Str The buffer holding the output string.
153 This buffer contains the length of the
154 string and the maixmum length reserved
155 for the string buffer.
156 @param DevPath The device path.
157
158 **/
159 VOID
160 DevPathController (
161 IN OUT POOL_PRINT *Str,
162 IN VOID *DevPath
163 )
164 {
165 CONTROLLER_DEVICE_PATH *Controller;
166
167 Controller = DevPath;
168 CatPrint (Str, L"Ctrl(%d)", (UINTN) Controller->ControllerNumber);
169 }
170
171
172 /**
173 Convert Vendor device path to device name.
174
175 @param Str The buffer store device name
176 @param DevPath Pointer to vendor device path
177
178 **/
179 VOID
180 EFIAPI
181 DevPathVendor (
182 IN OUT POOL_PRINT *Str,
183 IN VOID *DevPath
184 )
185 {
186 VENDOR_DEVICE_PATH *Vendor;
187 CHAR16 *Type;
188 UINTN DataLength;
189 UINTN Index;
190 UINT32 FlowControlMap;
191
192 UINT16 Info;
193
194 Vendor = DevPath;
195
196 switch (DevicePathType (&Vendor->Header)) {
197 case HARDWARE_DEVICE_PATH:
198 Type = L"Hw";
199 break;
200
201 case MESSAGING_DEVICE_PATH:
202 Type = L"Msg";
203 if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {
204 CatPrint (Str, L"VenPcAnsi()");
205 return ;
206 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {
207 CatPrint (Str, L"VenVt100()");
208 return ;
209 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {
210 CatPrint (Str, L"VenVt100Plus()");
211 return ;
212 } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {
213 CatPrint (Str, L"VenUft8()");
214 return ;
215 } else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid )) {
216 FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);
217 switch (FlowControlMap & 0x00000003) {
218 case 0:
219 CatPrint (Str, L"UartFlowCtrl(%s)", L"None");
220 break;
221
222 case 1:
223 CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");
224 break;
225
226 case 2:
227 CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");
228 break;
229
230 default:
231 break;
232 }
233
234 return ;
235
236 } else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) {
237 CatPrint (
238 Str,
239 L"SAS(%lx,%lx,%x,",
240 ((SAS_DEVICE_PATH *) Vendor)->SasAddress,
241 ((SAS_DEVICE_PATH *) Vendor)->Lun,
242 ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort
243 );
244 Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);
245 if ((Info & 0x0f) == 0) {
246 CatPrint (Str, L"NoTopology,0,0,0,");
247 } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {
248 CatPrint (
249 Str,
250 L"%s,%s,%s,",
251 ((Info & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",
252 ((Info & (0x1 << 5)) != 0) ? L"External" : L"Internal",
253 ((Info & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"
254 );
255 if ((Info & 0x0f) == 1) {
256 CatPrint (Str, L"0,");
257 } else {
258 CatPrint (Str, L"%x,", (UINTN) ((Info >> 8) & 0xff));
259 }
260 } else {
261 CatPrint (Str, L"0,0,0,0,");
262 }
263
264 CatPrint (Str, L"%x)", (UINTN) ((SAS_DEVICE_PATH *) Vendor)->Reserved);
265 return ;
266
267 } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {
268 CatPrint (Str, L"DebugPort()");
269 return ;
270 }
271 break;
272
273 case MEDIA_DEVICE_PATH:
274 Type = L"Media";
275 break;
276
277 default:
278 Type = L"?";
279 break;
280 }
281
282 CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);
283 DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);
284 if (DataLength > 0) {
285 CatPrint (Str, L",");
286 for (Index = 0; Index < DataLength; Index++) {
287 CatPrint (Str, L"%02x", (UINTN) ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);
288 }
289 }
290 CatPrint (Str, L")");
291 }
292
293 /**
294 Convert Device Path to a Unicode string for printing.
295
296 @param Str The buffer holding the output string.
297 This buffer contains the length of the
298 string and the maixmum length reserved
299 for the string buffer.
300 @param DevPath The device path.
301
302 **/
303 VOID
304 DevPathAcpi (
305 IN OUT POOL_PRINT *Str,
306 IN VOID *DevPath
307 )
308 {
309 ACPI_HID_DEVICE_PATH *Acpi;
310
311 Acpi = DevPath;
312 if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
313 CatPrint (Str, L"Acpi(PNP%04x,%x)", (UINTN) EISA_ID_TO_NUM (Acpi->HID), (UINTN) Acpi->UID);
314 } else {
315 CatPrint (Str, L"Acpi(%08x,%x)", (UINTN) Acpi->HID, (UINTN) Acpi->UID);
316 }
317 }
318
319 /**
320 Convert Device Path to a Unicode string for printing.
321
322 @param Str The buffer holding the output string.
323 This buffer contains the length of the
324 string and the maixmum length reserved
325 for the string buffer.
326 @param DevPath The device path.
327
328 **/
329 VOID
330 DevPathExtendedAcpi (
331 IN OUT POOL_PRINT *Str,
332 IN VOID *DevPath
333 )
334 {
335 ACPI_EXTENDED_HID_DEVICE_PATH *ExtendedAcpi;
336
337 //
338 // Index for HID, UID and CID strings, 0 for non-exist
339 //
340 UINT16 HIDSTRIdx;
341 UINT16 UIDSTRIdx;
342 UINT16 CIDSTRIdx;
343 UINT16 Index;
344 UINT16 Length;
345 UINT16 Anchor;
346 CHAR8 *AsChar8Array;
347
348 ASSERT (Str != NULL);
349 ASSERT (DevPath != NULL);
350
351 HIDSTRIdx = 0;
352 UIDSTRIdx = 0;
353 CIDSTRIdx = 0;
354 ExtendedAcpi = DevPath;
355 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) ExtendedAcpi);
356
357 ASSERT (Length >= 19);
358 AsChar8Array = (CHAR8 *) ExtendedAcpi;
359
360 //
361 // find HIDSTR
362 //
363 Anchor = 16;
364 for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
365 ;
366 }
367 if (Index > Anchor) {
368 HIDSTRIdx = Anchor;
369 }
370 //
371 // find UIDSTR
372 //
373 Anchor = (UINT16) (Index + 1);
374 for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
375 ;
376 }
377 if (Index > Anchor) {
378 UIDSTRIdx = Anchor;
379 }
380 //
381 // find CIDSTR
382 //
383 Anchor = (UINT16) (Index + 1);
384 for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
385 ;
386 }
387 if (Index > Anchor) {
388 CIDSTRIdx = Anchor;
389 }
390
391 if (HIDSTRIdx == 0 && CIDSTRIdx == 0 && ExtendedAcpi->UID == 0) {
392 CatPrint (Str, L"AcpiExp(");
393 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
394 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));
395 } else {
396 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
397 }
398 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
399 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));
400 } else {
401 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);
402 }
403 if (UIDSTRIdx != 0) {
404 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
405 } else {
406 CatPrint (Str, L"\"\")");
407 }
408 } else {
409 CatPrint (Str, L"AcpiEx(");
410 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
411 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));
412 } else {
413 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
414 }
415 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
416 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));
417 } else {
418 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);
419 }
420 CatPrint (Str, L"%x,", (UINTN) ExtendedAcpi->UID);
421
422 if (HIDSTRIdx != 0) {
423 CatPrint (Str, L"%a,", AsChar8Array + HIDSTRIdx);
424 } else {
425 CatPrint (Str, L"\"\",");
426 }
427 if (CIDSTRIdx != 0) {
428 CatPrint (Str, L"%a,", AsChar8Array + CIDSTRIdx);
429 } else {
430 CatPrint (Str, L"\"\",");
431 }
432 if (UIDSTRIdx != 0) {
433 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
434 } else {
435 CatPrint (Str, L"\"\")");
436 }
437 }
438
439 }
440
441 /**
442 Convert Device Path to a Unicode string for printing.
443
444 @param Str The buffer holding the output string.
445 This buffer contains the length of the
446 string and the maixmum length reserved
447 for the string buffer.
448 @param DevPath The device path.
449
450 **/
451 VOID
452 DevPathAdrAcpi (
453 IN OUT POOL_PRINT *Str,
454 IN VOID *DevPath
455 )
456 {
457 ACPI_ADR_DEVICE_PATH *AcpiAdr;
458 UINT16 Index;
459 UINT16 Length;
460 UINT16 AdditionalAdrCount;
461
462 AcpiAdr = DevPath;
463 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);
464 AdditionalAdrCount = (UINT16) ((Length - 8) / 4);
465
466 CatPrint (Str, L"AcpiAdr(%x", (UINTN) AcpiAdr->ADR);
467 for (Index = 0; Index < AdditionalAdrCount; Index++) {
468 CatPrint (Str, L",%x", (UINTN) *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
469 }
470 CatPrint (Str, L")");
471 }
472
473 /**
474 Convert Device Path to a Unicode string for printing.
475
476 @param Str The buffer holding the output string.
477 This buffer contains the length of the
478 string and the maixmum length reserved
479 for the string buffer.
480 @param DevPath The device path.
481
482 **/
483 VOID
484 DevPathAtapi (
485 IN OUT POOL_PRINT *Str,
486 IN VOID *DevPath
487 )
488 {
489 ATAPI_DEVICE_PATH *Atapi;
490
491 Atapi = DevPath;
492 CatPrint (
493 Str,
494 L"Ata(%s,%s)",
495 Atapi->PrimarySecondary ? L"Secondary" : L"Primary",
496 Atapi->SlaveMaster ? L"Slave" : L"Master"
497 );
498 }
499
500 /**
501 Convert Device Path to a Unicode string for printing.
502
503 @param Str The buffer holding the output string.
504 This buffer contains the length of the
505 string and the maixmum length reserved
506 for the string buffer.
507 @param DevPath The device path.
508
509 **/
510 VOID
511 DevPathScsi (
512 IN OUT POOL_PRINT *Str,
513 IN VOID *DevPath
514 )
515 {
516 SCSI_DEVICE_PATH *Scsi;
517
518 Scsi = DevPath;
519 CatPrint (Str, L"Scsi(Pun%x,Lun%x)", (UINTN) Scsi->Pun, (UINTN) Scsi->Lun);
520 }
521
522 /**
523 Convert Device Path to a Unicode string for printing.
524
525 @param Str The buffer holding the output string.
526 This buffer contains the length of the
527 string and the maixmum length reserved
528 for the string buffer.
529 @param DevPath The device path.
530
531 **/
532 VOID
533 DevPathFibre (
534 IN OUT POOL_PRINT *Str,
535 IN VOID *DevPath
536 )
537 {
538 FIBRECHANNEL_DEVICE_PATH *Fibre;
539
540 Fibre = DevPath;
541 CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun);
542 }
543
544 /**
545 Convert Device Path to a Unicode string for printing.
546
547 @param Str The buffer holding the output string.
548 This buffer contains the length of the
549 string and the maixmum length reserved
550 for the string buffer.
551 @param DevPath The device path.
552
553 **/
554 VOID
555 DevPath1394 (
556 IN OUT POOL_PRINT *Str,
557 IN VOID *DevPath
558 )
559 {
560 F1394_DEVICE_PATH *F1394Path;
561
562 F1394Path = DevPath;
563 CatPrint (Str, L"1394(%g)", &F1394Path->Guid);
564 }
565
566 /**
567 Convert Device Path to a Unicode string for printing.
568
569 @param Str The buffer holding the output string.
570 This buffer contains the length of the
571 string and the maixmum length reserved
572 for the string buffer.
573 @param DevPath The device path.
574
575 **/
576 VOID
577 DevPathUsb (
578 IN OUT POOL_PRINT *Str,
579 IN VOID *DevPath
580 )
581 {
582 USB_DEVICE_PATH *Usb;
583
584 Usb = DevPath;
585 CatPrint (Str, L"Usb(%x,%x)", (UINTN) Usb->ParentPortNumber, (UINTN) Usb->InterfaceNumber);
586 }
587
588 /**
589 Convert Device Path to a Unicode string for printing.
590
591 @param Str The buffer holding the output string.
592 This buffer contains the length of the
593 string and the maixmum length reserved
594 for the string buffer.
595 @param DevPath The device path.
596
597 **/
598 VOID
599 DevPathUsbWWID (
600 IN OUT POOL_PRINT *Str,
601 IN VOID *DevPath
602 )
603 {
604 USB_WWID_DEVICE_PATH *UsbWWId;
605
606 UsbWWId = DevPath;
607 CatPrint (
608 Str,
609 L"UsbWwid(%x,%x,%x,\"WWID\")",
610 (UINTN) UsbWWId->VendorId,
611 (UINTN) UsbWWId->ProductId,
612 (UINTN) UsbWWId->InterfaceNumber
613 );
614 }
615
616 /**
617 Convert Device Path to a Unicode string for printing.
618
619 @param Str The buffer holding the output string.
620 This buffer contains the length of the
621 string and the maixmum length reserved
622 for the string buffer.
623 @param DevPath The device path.
624
625 **/
626 VOID
627 DevPathLogicalUnit (
628 IN OUT POOL_PRINT *Str,
629 IN VOID *DevPath
630 )
631 {
632 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
633
634 LogicalUnit = DevPath;
635 CatPrint (Str, L"Unit(%x)", (UINTN) LogicalUnit->Lun);
636 }
637
638 /**
639 Convert Device Path to a Unicode string for printing.
640
641 @param Str The buffer holding the output string.
642 This buffer contains the length of the
643 string and the maixmum length reserved
644 for the string buffer.
645 @param DevPath The device path.
646
647 **/
648 VOID
649 DevPathUsbClass (
650 IN OUT POOL_PRINT *Str,
651 IN VOID *DevPath
652 )
653 {
654 USB_CLASS_DEVICE_PATH *UsbClass;
655
656 UsbClass = DevPath;
657 CatPrint (
658 Str,
659 L"Usb Class(%x,%x,%x,%x,%x)",
660 (UINTN) UsbClass->VendorId,
661 (UINTN) UsbClass->ProductId,
662 (UINTN) UsbClass->DeviceClass,
663 (UINTN) UsbClass->DeviceSubClass,
664 (UINTN) UsbClass->DeviceProtocol
665 );
666 }
667
668 /**
669 Convert Device Path to a Unicode string for printing.
670
671 @param Str The buffer holding the output string.
672 This buffer contains the length of the
673 string and the maixmum length reserved
674 for the string buffer.
675 @param DevPath The device path.
676
677 **/
678 VOID
679 DevPathSata (
680 IN OUT POOL_PRINT *Str,
681 IN VOID *DevPath
682 )
683 {
684 SATA_DEVICE_PATH *Sata;
685
686 Sata = DevPath;
687 CatPrint (
688 Str,
689 L"Sata(%x,%x,%x)",
690 (UINTN) Sata->HBAPortNumber,
691 (UINTN) Sata->PortMultiplierPortNumber,
692 (UINTN) Sata->Lun
693 );
694 }
695
696 /**
697 Convert Device Path to a Unicode string for printing.
698
699 @param Str The buffer holding the output string.
700 This buffer contains the length of the
701 string and the maixmum length reserved
702 for the string buffer.
703 @param DevPath The device path.
704
705 **/
706 VOID
707 DevPathI2O (
708 IN OUT POOL_PRINT *Str,
709 IN VOID *DevPath
710 )
711 {
712 I2O_DEVICE_PATH *I2OPath;
713
714 I2OPath = DevPath;
715 CatPrint (Str, L"I2O(%x)", (UINTN) I2OPath->Tid);
716 }
717
718 /**
719 Convert Device Path to a Unicode string for printing.
720
721 @param Str The buffer holding the output string.
722 This buffer contains the length of the
723 string and the maixmum length reserved
724 for the string buffer.
725 @param DevPath The device path.
726
727 **/
728 VOID
729 DevPathMacAddr (
730 IN OUT POOL_PRINT *Str,
731 IN VOID *DevPath
732 )
733 {
734 MAC_ADDR_DEVICE_PATH *MACDevPath;
735 UINTN HwAddressSize;
736 UINTN Index;
737
738 MACDevPath = DevPath;
739
740 HwAddressSize = sizeof (EFI_MAC_ADDRESS);
741 if (MACDevPath->IfType == 0x01 || MACDevPath->IfType == 0x00) {
742 HwAddressSize = 6;
743 }
744
745 CatPrint (Str, L"Mac(");
746
747 for (Index = 0; Index < HwAddressSize; Index++) {
748 CatPrint (Str, L"%02x", (UINTN) MACDevPath->MacAddress.Addr[Index]);
749 }
750
751 CatPrint (Str, L")");
752 }
753
754 /**
755 Convert Device Path to a Unicode string for printing.
756
757 @param Str The buffer holding the output string.
758 This buffer contains the length of the
759 string and the maixmum length reserved
760 for the string buffer.
761 @param DevPath The device path.
762
763 **/
764 VOID
765 DevPathIPv4 (
766 IN OUT POOL_PRINT *Str,
767 IN VOID *DevPath
768 )
769 {
770 IPv4_DEVICE_PATH *IPDevPath;
771
772 IPDevPath = DevPath;
773 CatPrint (
774 Str,
775 L"IPv4(%d.%d.%d.%d:%d)",
776 (UINTN) IPDevPath->RemoteIpAddress.Addr[0],
777 (UINTN) IPDevPath->RemoteIpAddress.Addr[1],
778 (UINTN) IPDevPath->RemoteIpAddress.Addr[2],
779 (UINTN) IPDevPath->RemoteIpAddress.Addr[3],
780 (UINTN) IPDevPath->RemotePort
781 );
782 }
783
784 /**
785 Convert Device Path to a Unicode string for printing.
786
787 @param Str The buffer holding the output string.
788 This buffer contains the length of the
789 string and the maixmum length reserved
790 for the string buffer.
791 @param DevPath The device path.
792
793 **/
794 VOID
795 DevPathIPv6 (
796 IN OUT POOL_PRINT *Str,
797 IN VOID *DevPath
798 )
799 {
800 IPv6_DEVICE_PATH *IPv6DevPath;
801
802 IPv6DevPath = DevPath;
803 CatPrint (
804 Str,
805 L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",
806 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[0],
807 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[1],
808 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[2],
809 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[3],
810 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[4],
811 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[5],
812 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[6],
813 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[7],
814 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[8],
815 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[9],
816 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[10],
817 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[11],
818 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[12],
819 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[13],
820 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[14],
821 (UINTN) IPv6DevPath->RemoteIpAddress.Addr[15]
822 );
823 }
824
825 /**
826 Convert Device Path to a Unicode string for printing.
827
828 @param Str The buffer holding the output string.
829 This buffer contains the length of the
830 string and the maixmum length reserved
831 for the string buffer.
832 @param DevPath The device path.
833
834 **/
835 VOID
836 DevPathInfiniBand (
837 IN OUT POOL_PRINT *Str,
838 IN VOID *DevPath
839 )
840 {
841 INFINIBAND_DEVICE_PATH *InfiniBand;
842
843 InfiniBand = DevPath;
844 CatPrint (
845 Str,
846 L"Infiniband(%x,%g,%lx,%lx,%lx)",
847 (UINTN) InfiniBand->ResourceFlags,
848 InfiniBand->PortGid,
849 InfiniBand->ServiceId,
850 InfiniBand->TargetPortId,
851 InfiniBand->DeviceId
852 );
853 }
854
855 /**
856 Convert Device Path to a Unicode string for printing.
857
858 @param Str The buffer holding the output string.
859 This buffer contains the length of the
860 string and the maixmum length reserved
861 for the string buffer.
862 @param DevPath The device path.
863
864 **/
865 VOID
866 DevPathUart (
867 IN OUT POOL_PRINT *Str,
868 IN VOID *DevPath
869 )
870 {
871 UART_DEVICE_PATH *Uart;
872 CHAR8 Parity;
873
874 Uart = DevPath;
875 switch (Uart->Parity) {
876 case 0:
877 Parity = 'D';
878 break;
879
880 case 1:
881 Parity = 'N';
882 break;
883
884 case 2:
885 Parity = 'E';
886 break;
887
888 case 3:
889 Parity = 'O';
890 break;
891
892 case 4:
893 Parity = 'M';
894 break;
895
896 case 5:
897 Parity = 'S';
898 break;
899
900 default:
901 Parity = 'x';
902 break;
903 }
904
905 if (Uart->BaudRate == 0) {
906 CatPrint (Str, L"Uart(DEFAULT,%c,", Parity);
907 } else {
908 CatPrint (Str, L"Uart(%d,%c,", Uart->BaudRate, Parity);
909 }
910
911 if (Uart->DataBits == 0) {
912 CatPrint (Str, L"D,");
913 } else {
914 CatPrint (Str, L"%d,", (UINTN) Uart->DataBits);
915 }
916
917 switch (Uart->StopBits) {
918 case 0:
919 CatPrint (Str, L"D)");
920 break;
921
922 case 1:
923 CatPrint (Str, L"1)");
924 break;
925
926 case 2:
927 CatPrint (Str, L"1.5)");
928 break;
929
930 case 3:
931 CatPrint (Str, L"2)");
932 break;
933
934 default:
935 CatPrint (Str, L"x)");
936 break;
937 }
938 }
939
940 /**
941 Convert Device Path to a Unicode string for printing.
942
943 @param Str The buffer holding the output string.
944 This buffer contains the length of the
945 string and the maixmum length reserved
946 for the string buffer.
947 @param DevPath The device path.
948
949 **/
950 VOID
951 DevPathiSCSI (
952 IN OUT POOL_PRINT *Str,
953 IN VOID *DevPath
954 )
955 {
956 ISCSI_DEVICE_PATH_WITH_NAME *IScsi;
957 UINT16 Options;
958
959 ASSERT (Str != NULL);
960 ASSERT (DevPath != NULL);
961
962 IScsi = DevPath;
963 CatPrint (
964 Str,
965 L"iSCSI(%s,%x,%lx,",
966 IScsi->iSCSITargetName,
967 IScsi->TargetPortalGroupTag,
968 IScsi->Lun
969 );
970
971 Options = IScsi->LoginOption;
972 CatPrint (Str, L"%s,", (((Options >> 1) & 0x0001) != 0) ? L"CRC32C" : L"None");
973 CatPrint (Str, L"%s,", (((Options >> 3) & 0x0001) != 0) ? L"CRC32C" : L"None");
974 if (((Options >> 11) & 0x0001) != 0) {
975 CatPrint (Str, L"%s,", L"None");
976 } else if (((Options >> 12) & 0x0001) != 0) {
977 CatPrint (Str, L"%s,", L"CHAP_UNI");
978 } else {
979 CatPrint (Str, L"%s,", L"CHAP_BI");
980
981 }
982
983 CatPrint (Str, L"%s)", (IScsi->NetworkProtocol == 0) ? L"TCP" : L"reserved");
984 }
985
986 /**
987 Convert Device Path to a Unicode string for printing.
988
989 @param Str The buffer holding the output string.
990 This buffer contains the length of the
991 string and the maixmum length reserved
992 for the string buffer.
993 @param DevPath The device path.
994
995 **/
996 VOID
997 DevPathHardDrive (
998 IN OUT POOL_PRINT *Str,
999 IN VOID *DevPath
1000 )
1001 {
1002 HARDDRIVE_DEVICE_PATH *Hd;
1003
1004 Hd = DevPath;
1005 switch (Hd->SignatureType) {
1006 case SIGNATURE_TYPE_MBR:
1007 CatPrint (
1008 Str,
1009 L"HD(Part%d,Sig%08x)",
1010 (UINTN) Hd->PartitionNumber,
1011 (UINTN) *((UINT32 *) (&(Hd->Signature[0])))
1012 );
1013 break;
1014
1015 case SIGNATURE_TYPE_GUID:
1016 CatPrint (
1017 Str,
1018 L"HD(Part%d,Sig%g)",
1019 (UINTN) Hd->PartitionNumber,
1020 (EFI_GUID *) &(Hd->Signature[0])
1021 );
1022 break;
1023
1024 default:
1025 CatPrint (
1026 Str,
1027 L"HD(Part%d,MBRType=%02x,SigType=%02x)",
1028 (UINTN) Hd->PartitionNumber,
1029 (UINTN) Hd->MBRType,
1030 (UINTN) Hd->SignatureType
1031 );
1032 break;
1033 }
1034 }
1035
1036 /**
1037 Convert Device Path to a Unicode string for printing.
1038
1039 @param Str The buffer holding the output string.
1040 This buffer contains the length of the
1041 string and the maixmum length reserved
1042 for the string buffer.
1043 @param DevPath The device path.
1044
1045 **/
1046 VOID
1047 DevPathCDROM (
1048 IN OUT POOL_PRINT *Str,
1049 IN VOID *DevPath
1050 )
1051 {
1052 CDROM_DEVICE_PATH *Cd;
1053
1054 Cd = DevPath;
1055 CatPrint (Str, L"CDROM(Entry%x)", (UINTN) Cd->BootEntry);
1056 }
1057
1058 /**
1059 Convert Device Path to a Unicode string for printing.
1060
1061 @param Str The buffer holding the output string.
1062 This buffer contains the length of the
1063 string and the maixmum length reserved
1064 for the string buffer.
1065 @param DevPath The device path.
1066
1067 **/
1068 VOID
1069 DevPathFilePath (
1070 IN OUT POOL_PRINT *Str,
1071 IN VOID *DevPath
1072 )
1073 {
1074 FILEPATH_DEVICE_PATH *Fp;
1075
1076 Fp = DevPath;
1077 CatPrint (Str, L"%s", Fp->PathName);
1078 }
1079
1080 /**
1081 Convert Device Path to a Unicode string for printing.
1082
1083 @param Str The buffer holding the output string.
1084 This buffer contains the length of the
1085 string and the maixmum length reserved
1086 for the string buffer.
1087 @param DevPath The device path.
1088
1089 **/
1090 VOID
1091 DevPathMediaProtocol (
1092 IN OUT POOL_PRINT *Str,
1093 IN VOID *DevPath
1094 )
1095 {
1096 MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
1097
1098 MediaProt = DevPath;
1099 CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
1100 }
1101
1102 /**
1103 Convert Device Path to a Unicode string for printing.
1104
1105 @param Str The buffer holding the output string.
1106 This buffer contains the length of the
1107 string and the maixmum length reserved
1108 for the string buffer.
1109 @param DevPath The device path.
1110
1111 **/
1112 VOID
1113 DevPathFvFilePath (
1114 IN OUT POOL_PRINT *Str,
1115 IN VOID *DevPath
1116 )
1117 {
1118 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
1119
1120 FvFilePath = DevPath;
1121 CatPrint (Str, L"%g", &FvFilePath->FvFileName);
1122 }
1123
1124 /**
1125 Convert Device Path to a Unicode string for printing.
1126
1127 @param Str The buffer holding the output string.
1128 This buffer contains the length of the
1129 string and the maixmum length reserved
1130 for the string buffer.
1131 @param DevPath The device path.
1132
1133 **/
1134 VOID
1135 DevPathBssBss (
1136 IN OUT POOL_PRINT *Str,
1137 IN VOID *DevPath
1138 )
1139 {
1140 BBS_BBS_DEVICE_PATH *Bbs;
1141 CHAR16 *Type;
1142
1143 Bbs = DevPath;
1144 switch (Bbs->DeviceType) {
1145 case BBS_TYPE_FLOPPY:
1146 Type = L"Floppy";
1147 break;
1148
1149 case BBS_TYPE_HARDDRIVE:
1150 Type = L"Harddrive";
1151 break;
1152
1153 case BBS_TYPE_CDROM:
1154 Type = L"CDROM";
1155 break;
1156
1157 case BBS_TYPE_PCMCIA:
1158 Type = L"PCMCIA";
1159 break;
1160
1161 case BBS_TYPE_USB:
1162 Type = L"Usb";
1163 break;
1164
1165 case BBS_TYPE_EMBEDDED_NETWORK:
1166 Type = L"Net";
1167 break;
1168
1169 case BBS_TYPE_BEV:
1170 Type = L"BEV";
1171 break;
1172
1173 default:
1174 Type = L"?";
1175 break;
1176 }
1177 CatPrint (Str, L"Legacy-%s", Type);
1178 }
1179
1180 /**
1181 Convert Device Path to a Unicode string for printing.
1182
1183 @param Str The buffer holding the output string.
1184 This buffer contains the length of the
1185 string and the maixmum length reserved
1186 for the string buffer.
1187 @param DevPath The device path.
1188
1189 **/
1190 VOID
1191 DevPathEndInstance (
1192 IN OUT POOL_PRINT *Str,
1193 IN VOID *DevPath
1194 )
1195 {
1196 CatPrint (Str, L",");
1197 }
1198
1199 /**
1200 Convert Device Path to a Unicode string for printing.
1201
1202 @param Str The buffer holding the output string.
1203 This buffer contains the length of the
1204 string and the maixmum length reserved
1205 for the string buffer.
1206 @param DevPath The device path.
1207
1208 **/
1209 VOID
1210 DevPathNodeUnknown (
1211 IN OUT POOL_PRINT *Str,
1212 IN VOID *DevPath
1213 )
1214 {
1215 CatPrint (Str, L"?");
1216 }
1217
1218 DEVICE_PATH_STRING_TABLE DevPathTable[] = {
1219 {
1220 HARDWARE_DEVICE_PATH,
1221 HW_PCI_DP,
1222 DevPathPci
1223 },
1224 {
1225 HARDWARE_DEVICE_PATH,
1226 HW_PCCARD_DP,
1227 DevPathPccard
1228 },
1229 {
1230 HARDWARE_DEVICE_PATH,
1231 HW_MEMMAP_DP,
1232 DevPathMemMap
1233 },
1234 {
1235 HARDWARE_DEVICE_PATH,
1236 HW_VENDOR_DP,
1237 DevPathVendor
1238 },
1239 {
1240 HARDWARE_DEVICE_PATH,
1241 HW_CONTROLLER_DP,
1242 DevPathController
1243 },
1244 {
1245 ACPI_DEVICE_PATH,
1246 ACPI_DP,
1247 DevPathAcpi
1248 },
1249 {
1250 ACPI_DEVICE_PATH,
1251 ACPI_EXTENDED_DP,
1252 DevPathExtendedAcpi
1253 },
1254 {
1255 ACPI_DEVICE_PATH,
1256 ACPI_ADR_DP,
1257 DevPathAdrAcpi
1258 },
1259 {
1260 MESSAGING_DEVICE_PATH,
1261 MSG_ATAPI_DP,
1262 DevPathAtapi
1263 },
1264 {
1265 MESSAGING_DEVICE_PATH,
1266 MSG_SCSI_DP,
1267 DevPathScsi
1268 },
1269 {
1270 MESSAGING_DEVICE_PATH,
1271 MSG_FIBRECHANNEL_DP,
1272 DevPathFibre
1273 },
1274 {
1275 MESSAGING_DEVICE_PATH,
1276 MSG_1394_DP,
1277 DevPath1394
1278 },
1279 {
1280 MESSAGING_DEVICE_PATH,
1281 MSG_USB_DP,
1282 DevPathUsb
1283 },
1284 {
1285 MESSAGING_DEVICE_PATH,
1286 MSG_USB_WWID_DP,
1287 DevPathUsbWWID
1288 },
1289 {
1290 MESSAGING_DEVICE_PATH,
1291 MSG_DEVICE_LOGICAL_UNIT_DP,
1292 DevPathLogicalUnit
1293 },
1294 {
1295 MESSAGING_DEVICE_PATH,
1296 MSG_USB_CLASS_DP,
1297 DevPathUsbClass
1298 },
1299 {
1300 MESSAGING_DEVICE_PATH,
1301 MSG_SATA_DP,
1302 DevPathSata
1303 },
1304 {
1305 MESSAGING_DEVICE_PATH,
1306 MSG_I2O_DP,
1307 DevPathI2O
1308 },
1309 {
1310 MESSAGING_DEVICE_PATH,
1311 MSG_MAC_ADDR_DP,
1312 DevPathMacAddr
1313 },
1314 {
1315 MESSAGING_DEVICE_PATH,
1316 MSG_IPv4_DP,
1317 DevPathIPv4
1318 },
1319 {
1320 MESSAGING_DEVICE_PATH,
1321 MSG_IPv6_DP,
1322 DevPathIPv6
1323 },
1324 {
1325 MESSAGING_DEVICE_PATH,
1326 MSG_INFINIBAND_DP,
1327 DevPathInfiniBand
1328 },
1329 {
1330 MESSAGING_DEVICE_PATH,
1331 MSG_UART_DP,
1332 DevPathUart
1333 },
1334 {
1335 MESSAGING_DEVICE_PATH,
1336 MSG_VENDOR_DP,
1337 DevPathVendor
1338 },
1339 {
1340 MESSAGING_DEVICE_PATH,
1341 MSG_ISCSI_DP,
1342 DevPathiSCSI
1343 },
1344 {
1345 MEDIA_DEVICE_PATH,
1346 MEDIA_HARDDRIVE_DP,
1347 DevPathHardDrive
1348 },
1349 {
1350 MEDIA_DEVICE_PATH,
1351 MEDIA_CDROM_DP,
1352 DevPathCDROM
1353 },
1354 {
1355 MEDIA_DEVICE_PATH,
1356 MEDIA_VENDOR_DP,
1357 DevPathVendor
1358 },
1359 {
1360 MEDIA_DEVICE_PATH,
1361 MEDIA_FILEPATH_DP,
1362 DevPathFilePath
1363 },
1364 {
1365 MEDIA_DEVICE_PATH,
1366 MEDIA_PROTOCOL_DP,
1367 DevPathMediaProtocol
1368 },
1369 {
1370 MEDIA_DEVICE_PATH,
1371 MEDIA_PIWG_FW_FILE_DP,
1372 DevPathFvFilePath
1373 },
1374 {
1375 BBS_DEVICE_PATH,
1376 BBS_BBS_DP,
1377 DevPathBssBss
1378 },
1379 {
1380 END_DEVICE_PATH_TYPE,
1381 END_INSTANCE_DEVICE_PATH_SUBTYPE,
1382 DevPathEndInstance
1383 },
1384 {
1385 0,
1386 0,
1387 NULL
1388 }
1389 };
1390
1391
1392 /**
1393 This function converts an input device structure to a Unicode string.
1394
1395 @param DevPath A pointer to the device path structure.
1396
1397 @return A new allocated Unicode string that represents the device path.
1398
1399 **/
1400 CHAR16 *
1401 EFIAPI
1402 DevicePathToStr (
1403 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
1404 )
1405 {
1406 POOL_PRINT Str;
1407 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
1408 VOID (*DumpNode) (POOL_PRINT *, VOID *);
1409
1410 UINTN Index;
1411 UINTN NewSize;
1412
1413 EFI_STATUS Status;
1414 CHAR16 *ToText;
1415 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;
1416
1417 ZeroMem (&Str, sizeof (Str));
1418
1419 if (DevPath == NULL) {
1420 goto Done;
1421 }
1422
1423 Status = gBS->LocateProtocol (
1424 &gEfiDevicePathToTextProtocolGuid,
1425 NULL,
1426 (VOID **) &DevPathToText
1427 );
1428 if (!EFI_ERROR (Status)) {
1429 ToText = DevPathToText->ConvertDevicePathToText (
1430 DevPath,
1431 FALSE,
1432 TRUE
1433 );
1434 ASSERT (ToText != NULL);
1435 return ToText;
1436 }
1437
1438 //
1439 // Process each device path node
1440 //
1441 DevPathNode = DevPath;
1442 while (!IsDevicePathEnd (DevPathNode)) {
1443 //
1444 // Find the handler to dump this device path node
1445 //
1446 DumpNode = NULL;
1447 for (Index = 0; DevPathTable[Index].Function; Index += 1) {
1448
1449 if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&
1450 DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType
1451 ) {
1452 DumpNode = DevPathTable[Index].Function;
1453 break;
1454 }
1455 }
1456 //
1457 // If not found, use a generic function
1458 //
1459 if (!DumpNode) {
1460 DumpNode = DevPathNodeUnknown;
1461 }
1462 //
1463 // Put a path seperator in if needed
1464 //
1465 if (Str.len && DumpNode != DevPathEndInstance) {
1466 CatPrint (&Str, L"/");
1467 }
1468 //
1469 // Print this node of the device path
1470 //
1471 DumpNode (&Str, DevPathNode);
1472
1473 //
1474 // Next device path node
1475 //
1476 DevPathNode = NextDevicePathNode (DevPathNode);
1477 }
1478
1479 Done:
1480 NewSize = (Str.len + 1) * sizeof (CHAR16);
1481 Str.str = ReallocatePool (NewSize, NewSize, Str.str);
1482 ASSERT (Str.str != NULL);
1483 Str.str[Str.len] = 0;
1484 return Str.str;
1485 }