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