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