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