]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/GenericBdsLib/DevicePath.c
Update code style and comments
[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 (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 ? L"Secondary" : L"Primary",
491 Atapi->SlaveMaster ? 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) {
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->iSCSITargetName,
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 DevPathHardDrive (
999 IN OUT POOL_PRINT *Str,
1000 IN VOID *DevPath
1001 )
1002 {
1003 HARDDRIVE_DEVICE_PATH *Hd;
1004
1005 Hd = DevPath;
1006 switch (Hd->SignatureType) {
1007 case SIGNATURE_TYPE_MBR:
1008 CatPrint (
1009 Str,
1010 L"HD(Part%d,Sig%08x)",
1011 (UINTN) Hd->PartitionNumber,
1012 (UINTN) *((UINT32 *) (&(Hd->Signature[0])))
1013 );
1014 break;
1015
1016 case SIGNATURE_TYPE_GUID:
1017 CatPrint (
1018 Str,
1019 L"HD(Part%d,Sig%g)",
1020 (UINTN) Hd->PartitionNumber,
1021 (EFI_GUID *) &(Hd->Signature[0])
1022 );
1023 break;
1024
1025 default:
1026 CatPrint (
1027 Str,
1028 L"HD(Part%d,MBRType=%02x,SigType=%02x)",
1029 (UINTN) Hd->PartitionNumber,
1030 (UINTN) Hd->MBRType,
1031 (UINTN) Hd->SignatureType
1032 );
1033 break;
1034 }
1035 }
1036
1037 /**
1038 Convert Device Path to a Unicode string for printing.
1039
1040 @param Str The buffer holding the output string.
1041 This buffer contains the length of the
1042 string and the maixmum length reserved
1043 for the string buffer.
1044 @param DevPath The device path.
1045
1046 **/
1047 VOID
1048 DevPathCDROM (
1049 IN OUT POOL_PRINT *Str,
1050 IN VOID *DevPath
1051 )
1052 {
1053 CDROM_DEVICE_PATH *Cd;
1054
1055 Cd = DevPath;
1056 CatPrint (Str, L"CDROM(Entry%x)", (UINTN) Cd->BootEntry);
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 DevPathFilePath (
1071 IN OUT POOL_PRINT *Str,
1072 IN VOID *DevPath
1073 )
1074 {
1075 FILEPATH_DEVICE_PATH *Fp;
1076
1077 Fp = DevPath;
1078 CatPrint (Str, L"%s", Fp->PathName);
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 DevPathMediaProtocol (
1093 IN OUT POOL_PRINT *Str,
1094 IN VOID *DevPath
1095 )
1096 {
1097 MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
1098
1099 MediaProt = DevPath;
1100 CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
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 DevPathFvFilePath (
1115 IN OUT POOL_PRINT *Str,
1116 IN VOID *DevPath
1117 )
1118 {
1119 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
1120
1121 FvFilePath = DevPath;
1122 CatPrint (Str, L"%g", &FvFilePath->FvFileName);
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 DevPathRelativeOffsetRange (
1137 IN OUT POOL_PRINT *Str,
1138 IN VOID *DevPath
1139 )
1140 {
1141 MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
1142
1143 Offset = DevPath;
1144 CatPrint (
1145 Str,
1146 L"Offset(%lx,%lx)",
1147 Offset->StartingOffset,
1148 Offset->EndingOffset
1149 );
1150 }
1151
1152 /**
1153 Convert Device Path to a Unicode string for printing.
1154
1155 @param Str The buffer holding the output string.
1156 This buffer contains the length of the
1157 string and the maixmum length reserved
1158 for the string buffer.
1159 @param DevPath The device path.
1160
1161 **/
1162 VOID
1163 DevPathBssBss (
1164 IN OUT POOL_PRINT *Str,
1165 IN VOID *DevPath
1166 )
1167 {
1168 BBS_BBS_DEVICE_PATH *Bbs;
1169 CHAR16 *Type;
1170
1171 Bbs = DevPath;
1172 switch (Bbs->DeviceType) {
1173 case BBS_TYPE_FLOPPY:
1174 Type = L"Floppy";
1175 break;
1176
1177 case BBS_TYPE_HARDDRIVE:
1178 Type = L"Harddrive";
1179 break;
1180
1181 case BBS_TYPE_CDROM:
1182 Type = L"CDROM";
1183 break;
1184
1185 case BBS_TYPE_PCMCIA:
1186 Type = L"PCMCIA";
1187 break;
1188
1189 case BBS_TYPE_USB:
1190 Type = L"Usb";
1191 break;
1192
1193 case BBS_TYPE_EMBEDDED_NETWORK:
1194 Type = L"Net";
1195 break;
1196
1197 case BBS_TYPE_BEV:
1198 Type = L"BEV";
1199 break;
1200
1201 default:
1202 Type = L"?";
1203 break;
1204 }
1205 CatPrint (Str, L"Legacy-%s", Type);
1206 }
1207
1208 /**
1209 Convert Device Path to a Unicode string for printing.
1210
1211 @param Str The buffer holding the output string.
1212 This buffer contains the length of the
1213 string and the maixmum length reserved
1214 for the string buffer.
1215 @param DevPath The device path.
1216
1217 **/
1218 VOID
1219 DevPathEndInstance (
1220 IN OUT POOL_PRINT *Str,
1221 IN VOID *DevPath
1222 )
1223 {
1224 CatPrint (Str, L",");
1225 }
1226
1227 /**
1228 Convert Device Path to a Unicode string for printing.
1229
1230 @param Str The buffer holding the output string.
1231 This buffer contains the length of the
1232 string and the maixmum length reserved
1233 for the string buffer.
1234 @param DevPath The device path.
1235
1236 **/
1237 VOID
1238 DevPathNodeUnknown (
1239 IN OUT POOL_PRINT *Str,
1240 IN VOID *DevPath
1241 )
1242 {
1243 CatPrint (Str, L"?");
1244 }
1245 /**
1246 Convert Device Path to a Unicode string for printing.
1247
1248 @param Str The buffer holding the output string.
1249 This buffer contains the length of the
1250 string and the maximum length reserved
1251 for the string buffer.
1252 @param DevPath The device path.
1253
1254 **/
1255 VOID
1256 DevPathFvPath (
1257 IN OUT POOL_PRINT *Str,
1258 IN VOID *DevPath
1259 )
1260 {
1261 MEDIA_FW_VOL_DEVICE_PATH *FvPath;
1262
1263 FvPath = DevPath;
1264 CatPrint (Str, L"Fv(%g)", &FvPath->FvName);
1265 }
1266
1267 DEVICE_PATH_STRING_TABLE DevPathTable[] = {
1268 {
1269 HARDWARE_DEVICE_PATH,
1270 HW_PCI_DP,
1271 DevPathPci
1272 },
1273 {
1274 HARDWARE_DEVICE_PATH,
1275 HW_PCCARD_DP,
1276 DevPathPccard
1277 },
1278 {
1279 HARDWARE_DEVICE_PATH,
1280 HW_MEMMAP_DP,
1281 DevPathMemMap
1282 },
1283 {
1284 HARDWARE_DEVICE_PATH,
1285 HW_VENDOR_DP,
1286 DevPathVendor
1287 },
1288 {
1289 HARDWARE_DEVICE_PATH,
1290 HW_CONTROLLER_DP,
1291 DevPathController
1292 },
1293 {
1294 ACPI_DEVICE_PATH,
1295 ACPI_DP,
1296 DevPathAcpi
1297 },
1298 {
1299 ACPI_DEVICE_PATH,
1300 ACPI_EXTENDED_DP,
1301 DevPathExtendedAcpi
1302 },
1303 {
1304 ACPI_DEVICE_PATH,
1305 ACPI_ADR_DP,
1306 DevPathAdrAcpi
1307 },
1308 {
1309 MESSAGING_DEVICE_PATH,
1310 MSG_ATAPI_DP,
1311 DevPathAtapi
1312 },
1313 {
1314 MESSAGING_DEVICE_PATH,
1315 MSG_SCSI_DP,
1316 DevPathScsi
1317 },
1318 {
1319 MESSAGING_DEVICE_PATH,
1320 MSG_FIBRECHANNEL_DP,
1321 DevPathFibre
1322 },
1323 {
1324 MESSAGING_DEVICE_PATH,
1325 MSG_1394_DP,
1326 DevPath1394
1327 },
1328 {
1329 MESSAGING_DEVICE_PATH,
1330 MSG_USB_DP,
1331 DevPathUsb
1332 },
1333 {
1334 MESSAGING_DEVICE_PATH,
1335 MSG_USB_WWID_DP,
1336 DevPathUsbWWID
1337 },
1338 {
1339 MESSAGING_DEVICE_PATH,
1340 MSG_DEVICE_LOGICAL_UNIT_DP,
1341 DevPathLogicalUnit
1342 },
1343 {
1344 MESSAGING_DEVICE_PATH,
1345 MSG_USB_CLASS_DP,
1346 DevPathUsbClass
1347 },
1348 {
1349 MESSAGING_DEVICE_PATH,
1350 MSG_SATA_DP,
1351 DevPathSata
1352 },
1353 {
1354 MESSAGING_DEVICE_PATH,
1355 MSG_I2O_DP,
1356 DevPathI2O
1357 },
1358 {
1359 MESSAGING_DEVICE_PATH,
1360 MSG_MAC_ADDR_DP,
1361 DevPathMacAddr
1362 },
1363 {
1364 MESSAGING_DEVICE_PATH,
1365 MSG_IPv4_DP,
1366 DevPathIPv4
1367 },
1368 {
1369 MESSAGING_DEVICE_PATH,
1370 MSG_IPv6_DP,
1371 DevPathIPv6
1372 },
1373 {
1374 MESSAGING_DEVICE_PATH,
1375 MSG_INFINIBAND_DP,
1376 DevPathInfiniBand
1377 },
1378 {
1379 MESSAGING_DEVICE_PATH,
1380 MSG_UART_DP,
1381 DevPathUart
1382 },
1383 {
1384 MESSAGING_DEVICE_PATH,
1385 MSG_VENDOR_DP,
1386 DevPathVendor
1387 },
1388 {
1389 MESSAGING_DEVICE_PATH,
1390 MSG_ISCSI_DP,
1391 DevPathiSCSI
1392 },
1393 {
1394 MEDIA_DEVICE_PATH,
1395 MEDIA_HARDDRIVE_DP,
1396 DevPathHardDrive
1397 },
1398 {
1399 MEDIA_DEVICE_PATH,
1400 MEDIA_CDROM_DP,
1401 DevPathCDROM
1402 },
1403 {
1404 MEDIA_DEVICE_PATH,
1405 MEDIA_VENDOR_DP,
1406 DevPathVendor
1407 },
1408 {
1409 MEDIA_DEVICE_PATH,
1410 MEDIA_FILEPATH_DP,
1411 DevPathFilePath
1412 },
1413 {
1414 MEDIA_DEVICE_PATH,
1415 MEDIA_PROTOCOL_DP,
1416 DevPathMediaProtocol
1417 },
1418 {
1419 MEDIA_DEVICE_PATH,
1420 MEDIA_PIWG_FW_VOL_DP,
1421 DevPathFvPath,
1422 },
1423 {
1424 MEDIA_DEVICE_PATH,
1425 MEDIA_PIWG_FW_FILE_DP,
1426 DevPathFvFilePath
1427 },
1428 {
1429 MEDIA_DEVICE_PATH,
1430 MEDIA_RELATIVE_OFFSET_RANGE_DP,
1431 DevPathRelativeOffsetRange,
1432 },
1433 {
1434 BBS_DEVICE_PATH,
1435 BBS_BBS_DP,
1436 DevPathBssBss
1437 },
1438 {
1439 END_DEVICE_PATH_TYPE,
1440 END_INSTANCE_DEVICE_PATH_SUBTYPE,
1441 DevPathEndInstance
1442 },
1443 {
1444 0,
1445 0,
1446 NULL
1447 }
1448 };
1449
1450
1451 /**
1452 This function converts an input device structure to a Unicode string.
1453
1454 @param DevPath A pointer to the device path structure.
1455
1456 @return A new allocated Unicode string that represents the device path.
1457
1458 **/
1459 CHAR16 *
1460 EFIAPI
1461 DevicePathToStr (
1462 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
1463 )
1464 {
1465 POOL_PRINT Str;
1466 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
1467 VOID (*DumpNode) (POOL_PRINT *, VOID *);
1468
1469 UINTN Index;
1470 UINTN NewSize;
1471
1472 EFI_STATUS Status;
1473 CHAR16 *ToText;
1474 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;
1475
1476 ZeroMem (&Str, sizeof (Str));
1477
1478 if (DevPath == NULL) {
1479 goto Done;
1480 }
1481
1482 Status = gBS->LocateProtocol (
1483 &gEfiDevicePathToTextProtocolGuid,
1484 NULL,
1485 (VOID **) &DevPathToText
1486 );
1487 if (!EFI_ERROR (Status)) {
1488 ToText = DevPathToText->ConvertDevicePathToText (
1489 DevPath,
1490 FALSE,
1491 TRUE
1492 );
1493 ASSERT (ToText != NULL);
1494 return ToText;
1495 }
1496
1497 //
1498 // Process each device path node
1499 //
1500 DevPathNode = DevPath;
1501 while (!IsDevicePathEnd (DevPathNode)) {
1502 //
1503 // Find the handler to dump this device path node
1504 //
1505 DumpNode = NULL;
1506 for (Index = 0; DevPathTable[Index].Function; Index += 1) {
1507
1508 if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&
1509 DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType
1510 ) {
1511 DumpNode = DevPathTable[Index].Function;
1512 break;
1513 }
1514 }
1515 //
1516 // If not found, use a generic function
1517 //
1518 if (!DumpNode) {
1519 DumpNode = DevPathNodeUnknown;
1520 }
1521 //
1522 // Put a path seperator in if needed
1523 //
1524 if (Str.Len && DumpNode != DevPathEndInstance) {
1525 CatPrint (&Str, L"/");
1526 }
1527 //
1528 // Print this node of the device path
1529 //
1530 DumpNode (&Str, DevPathNode);
1531
1532 //
1533 // Next device path node
1534 //
1535 DevPathNode = NextDevicePathNode (DevPathNode);
1536 }
1537
1538 Done:
1539 NewSize = (Str.Len + 1) * sizeof (CHAR16);
1540 Str.Str = ReallocatePool (NewSize, NewSize, Str.Str);
1541 ASSERT (Str.Str != NULL);
1542 Str.Str[Str.Len] = 0;
1543 return Str.Str;
1544 }