]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/GenericBdsLib/DevicePath.c
Parameter checking in BdsLibMatchDevicePaths() is wrong. This bug was found because...
[mirror_edk2.git] / MdeModulePkg / 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
23 allocated.
24 @param fmt The format string
25
26 @param ... Variable argument list.
27
28 @return Allocated buffer with the formatted string printed in it.
29 The caller must free the allocated buffer. The buffer
30 allocation is not packed.
31
32 **/
33 CHAR16 *
34 EFIAPI
35 CatPrint (
36 IN OUT POOL_PRINT *Str,
37 IN CHAR16 *fmt,
38 ...
39 )
40 {
41 UINT16 *AppendStr;
42 VA_LIST Args;
43 UINTN StringSize;
44
45 AppendStr = AllocateZeroPool (0x1000);
46 if (AppendStr == NULL) {
47 return Str->str;
48 }
49
50 VA_START (Args, fmt);
51 UnicodeVSPrint (AppendStr, 0x1000, fmt, Args);
52 VA_END (Args);
53 if (NULL == Str->str) {
54 StringSize = StrSize (AppendStr);
55 Str->str = AllocateZeroPool (StringSize);
56 ASSERT (Str->str != NULL);
57 } else {
58 StringSize = StrSize (AppendStr);
59 StringSize += (StrSize (Str->str) - sizeof (UINT16));
60
61 Str->str = ReallocatePool (
62 StrSize (Str->str),
63 StringSize,
64 Str->str
65 );
66 ASSERT (Str->str != NULL);
67 }
68
69 Str->maxlen = MAX_CHAR * sizeof (UINT16);
70 if (StringSize < Str->maxlen) {
71 StrCat (Str->str, AppendStr);
72 Str->len = StringSize - sizeof (UINT16);
73 }
74
75 FreePool (AppendStr);
76 return Str->str;
77 }
78
79 /**
80 Convert Device Path to a Unicode string for printing.
81
82 @param Str The buffer holding the output string.
83 This buffer contains the length of the
84 string and the maixmum length reserved
85 for the string buffer.
86 @param DevPath The device path.
87
88 **/
89 VOID
90 DevPathPci (
91 IN OUT POOL_PRINT *Str,
92 IN VOID *DevPath
93 )
94 {
95 PCI_DEVICE_PATH *Pci;
96
97 Pci = DevPath;
98 CatPrint (Str, L"Pci(%x|%x)", (UINTN) Pci->Device, (UINTN) Pci->Function);
99 }
100
101 /**
102 Convert Device Path to a Unicode string for printing.
103
104 @param Str The buffer holding the output string.
105 This buffer contains the length of the
106 string and the maixmum length reserved
107 for the string buffer.
108 @param DevPath The device path.
109
110 **/
111 VOID
112 DevPathPccard (
113 IN OUT POOL_PRINT *Str,
114 IN VOID *DevPath
115 )
116 {
117 PCCARD_DEVICE_PATH *Pccard;
118
119 Pccard = DevPath;
120 CatPrint (Str, L"Pcmcia(Function%x)", (UINTN) Pccard->FunctionNumber);
121 }
122
123 /**
124 Convert Device Path to a Unicode string for printing.
125
126 @param Str The buffer holding the output string.
127 This buffer contains the length of the
128 string and the maixmum length reserved
129 for the string buffer.
130 @param DevPath The device path.
131
132 **/
133 VOID
134 DevPathMemMap (
135 IN OUT POOL_PRINT *Str,
136 IN VOID *DevPath
137 )
138 {
139 MEMMAP_DEVICE_PATH *MemMap;
140
141 MemMap = DevPath;
142 CatPrint (
143 Str,
144 L"MemMap(%d:%lx-%lx)",
145 MemMap->MemoryType,
146 MemMap->StartingAddress,
147 MemMap->EndingAddress
148 );
149 }
150
151 /**
152 Convert Device Path to a Unicode string for printing.
153
154 @param Str The buffer holding the output string.
155 This buffer contains the length of the
156 string and the maixmum length reserved
157 for the string buffer.
158 @param DevPath The device path.
159
160 **/
161 VOID
162 DevPathController (
163 IN OUT POOL_PRINT *Str,
164 IN VOID *DevPath
165 )
166 {
167 CONTROLLER_DEVICE_PATH *Controller;
168
169 Controller = DevPath;
170 CatPrint (Str, L"Ctrl(%d)", (UINTN) Controller->ControllerNumber);
171 }
172
173
174 /**
175 Convert Device Path to a Unicode string for printing.
176
177 @param Str The buffer holding the output string.
178 This buffer contains the length of the
179 string and the maixmum length reserved
180 for the string buffer.
181 @param DevPath The device path.
182
183 **/
184 VOID
185 EFIAPI
186 DevPathVendor (
187 IN OUT POOL_PRINT *Str,
188 IN VOID *DevPath
189 )
190 {
191 VENDOR_DEVICE_PATH *Vendor;
192 CHAR16 *Type;
193 UINTN DataLength;
194 UINTN Index;
195 UINT32 FlowControlMap;
196
197 UINT16 Info;
198
199 Vendor = DevPath;
200
201 switch (DevicePathType (&Vendor->Header)) {
202 case HARDWARE_DEVICE_PATH:
203 Type = L"Hw";
204 break;
205
206 case MESSAGING_DEVICE_PATH:
207 Type = L"Msg";
208 if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {
209 CatPrint (Str, L"VenPcAnsi()");
210 return ;
211 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {
212 CatPrint (Str, L"VenVt100()");
213 return ;
214 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {
215 CatPrint (Str, L"VenVt100Plus()");
216 return ;
217 } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {
218 CatPrint (Str, L"VenUft8()");
219 return ;
220 } else if (CompareGuid (&Vendor->Guid, &gEfiUartDevicePathGuid )) {
221 FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);
222 switch (FlowControlMap & 0x00000003) {
223 case 0:
224 CatPrint (Str, L"UartFlowCtrl(%s)", L"None");
225 break;
226
227 case 1:
228 CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");
229 break;
230
231 case 2:
232 CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");
233 break;
234
235 default:
236 break;
237 }
238
239 return ;
240
241 } else if (CompareGuid (&Vendor->Guid, &gEfiSasDevicePathGuid)) {
242 CatPrint (
243 Str,
244 L"SAS(%lx,%lx,%x,",
245 ((SAS_DEVICE_PATH *) Vendor)->SasAddress,
246 ((SAS_DEVICE_PATH *) Vendor)->Lun,
247 ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort
248 );
249 Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);
250 if ((Info & 0x0f) == 0) {
251 CatPrint (Str, L"NoTopology,0,0,0,");
252 } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {
253 CatPrint (
254 Str,
255 L"%s,%s,%s,",
256 ((Info & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",
257 ((Info & (0x1 << 5)) != 0) ? L"External" : L"Internal",
258 ((Info & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"
259 );
260 if ((Info & 0x0f) == 1) {
261 CatPrint (Str, L"0,");
262 } else {
263 CatPrint (Str, L"%x,", (UINTN) ((Info >> 8) & 0xff));
264 }
265 } else {
266 CatPrint (Str, L"0,0,0,0,");
267 }
268
269 CatPrint (Str, L"%x)", (UINTN) ((SAS_DEVICE_PATH *) Vendor)->Reserved);
270 return ;
271
272 } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {
273 CatPrint (Str, L"DebugPort()");
274 return ;
275 }
276 break;
277
278 case MEDIA_DEVICE_PATH:
279 Type = L"Media";
280 break;
281
282 default:
283 Type = L"?";
284 break;
285 }
286
287 CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);
288 DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);
289 if (DataLength > 0) {
290 CatPrint (Str, L",");
291 for (Index = 0; Index < DataLength; Index++) {
292 CatPrint (Str, L"%02x", (UINTN) ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);
293 }
294 }
295 CatPrint (Str, L")");
296 }
297
298 /**
299 Convert Device Path to a Unicode string for printing.
300
301 @param Str The buffer holding the output string.
302 This buffer contains the length of the
303 string and the maixmum length reserved
304 for the string buffer.
305 @param DevPath The device path.
306
307 **/
308 VOID
309 DevPathAcpi (
310 IN OUT POOL_PRINT *Str,
311 IN VOID *DevPath
312 )
313 {
314 ACPI_HID_DEVICE_PATH *Acpi;
315
316 Acpi = DevPath;
317 if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
318 CatPrint (Str, L"Acpi(PNP%04x,%x)", (UINTN) EISA_ID_TO_NUM (Acpi->HID), (UINTN) Acpi->UID);
319 } else {
320 CatPrint (Str, L"Acpi(%08x,%x)", (UINTN) Acpi->HID, (UINTN) Acpi->UID);
321 }
322 }
323
324 /**
325 Convert Device Path to a Unicode string for printing.
326
327 @param Str The buffer holding the output string.
328 This buffer contains the length of the
329 string and the maixmum length reserved
330 for the string buffer.
331 @param DevPath The device path.
332
333 **/
334 VOID
335 DevPathExtendedAcpi (
336 IN OUT POOL_PRINT *Str,
337 IN VOID *DevPath
338 )
339 {
340 ACPI_EXTENDED_HID_DEVICE_PATH *ExtendedAcpi;
341
342 //
343 // Index for HID, UID and CID strings, 0 for non-exist
344 //
345 UINT16 HIDSTRIdx;
346 UINT16 UIDSTRIdx;
347 UINT16 CIDSTRIdx;
348 UINT16 Index;
349 UINT16 Length;
350 UINT16 Anchor;
351 CHAR8 *AsChar8Array;
352
353 ASSERT (Str != NULL);
354 ASSERT (DevPath != NULL);
355
356 HIDSTRIdx = 0;
357 UIDSTRIdx = 0;
358 CIDSTRIdx = 0;
359 ExtendedAcpi = DevPath;
360 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) ExtendedAcpi);
361
362 ASSERT (Length >= 19);
363 AsChar8Array = (CHAR8 *) ExtendedAcpi;
364
365 //
366 // find HIDSTR
367 //
368 Anchor = 16;
369 for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
370 ;
371 }
372 if (Index > Anchor) {
373 HIDSTRIdx = Anchor;
374 }
375 //
376 // find UIDSTR
377 //
378 Anchor = (UINT16) (Index + 1);
379 for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
380 ;
381 }
382 if (Index > Anchor) {
383 UIDSTRIdx = Anchor;
384 }
385 //
386 // find CIDSTR
387 //
388 Anchor = (UINT16) (Index + 1);
389 for (Index = Anchor; Index < Length && AsChar8Array[Index] != '\0'; Index++) {
390 ;
391 }
392 if (Index > Anchor) {
393 CIDSTRIdx = Anchor;
394 }
395
396 if (HIDSTRIdx == 0 && CIDSTRIdx == 0 && ExtendedAcpi->UID == 0) {
397 CatPrint (Str, L"AcpiExp(");
398 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
399 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));
400 } else {
401 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
402 }
403 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
404 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));
405 } else {
406 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);
407 }
408 if (UIDSTRIdx != 0) {
409 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
410 } else {
411 CatPrint (Str, L"\"\")");
412 }
413 } else {
414 CatPrint (Str, L"AcpiEx(");
415 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
416 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));
417 } else {
418 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
419 }
420 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
421 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));
422 } else {
423 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);
424 }
425 CatPrint (Str, L"%x,", (UINTN) ExtendedAcpi->UID);
426
427 if (HIDSTRIdx != 0) {
428 CatPrint (Str, L"%a,", AsChar8Array + HIDSTRIdx);
429 } else {
430 CatPrint (Str, L"\"\",");
431 }
432 if (CIDSTRIdx != 0) {
433 CatPrint (Str, L"%a,", AsChar8Array + CIDSTRIdx);
434 } else {
435 CatPrint (Str, L"\"\",");
436 }
437 if (UIDSTRIdx != 0) {
438 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
439 } else {
440 CatPrint (Str, L"\"\")");
441 }
442 }
443
444 }
445
446 /**
447 Convert Device Path to a Unicode string for printing.
448
449 @param Str The buffer holding the output string.
450 This buffer contains the length of the
451 string and the maixmum length reserved
452 for the string buffer.
453 @param DevPath The device path.
454
455 **/
456 VOID
457 DevPathAdrAcpi (
458 IN OUT POOL_PRINT *Str,
459 IN VOID *DevPath
460 )
461 {
462 ACPI_ADR_DEVICE_PATH *AcpiAdr;
463 UINT16 Index;
464 UINT16 Length;
465 UINT16 AdditionalAdrCount;
466
467 AcpiAdr = DevPath;
468 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);
469 AdditionalAdrCount = (UINT16) ((Length - 8) / 4);
470
471 CatPrint (Str, L"AcpiAdr(%x", (UINTN) AcpiAdr->ADR);
472 for (Index = 0; Index < AdditionalAdrCount; Index++) {
473 CatPrint (Str, L",%x", (UINTN) *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
474 }
475 CatPrint (Str, L")");
476 }
477
478 /**
479 Convert Device Path to a Unicode string for printing.
480
481 @param Str The buffer holding the output string.
482 This buffer contains the length of the
483 string and the maixmum length reserved
484 for the string buffer.
485 @param DevPath The device path.
486
487 **/
488 VOID
489 DevPathAtapi (
490 IN OUT POOL_PRINT *Str,
491 IN VOID *DevPath
492 )
493 {
494 ATAPI_DEVICE_PATH *Atapi;
495
496 Atapi = DevPath;
497 CatPrint (
498 Str,
499 L"Ata(%s,%s)",
500 Atapi->PrimarySecondary ? L"Secondary" : L"Primary",
501 Atapi->SlaveMaster ? L"Slave" : L"Master"
502 );
503 }
504
505 /**
506 Convert Device Path to a Unicode string for printing.
507
508 @param Str The buffer holding the output string.
509 This buffer contains the length of the
510 string and the maixmum length reserved
511 for the string buffer.
512 @param DevPath The device path.
513
514 **/
515 VOID
516 DevPathScsi (
517 IN OUT POOL_PRINT *Str,
518 IN VOID *DevPath
519 )
520 {
521 SCSI_DEVICE_PATH *Scsi;
522
523 Scsi = DevPath;
524 CatPrint (Str, L"Scsi(Pun%x,Lun%x)", (UINTN) Scsi->Pun, (UINTN) Scsi->Lun);
525 }
526
527 /**
528 Convert Device Path to a Unicode string for printing.
529
530 @param Str The buffer holding the output string.
531 This buffer contains the length of the
532 string and the maixmum length reserved
533 for the string buffer.
534 @param DevPath The device path.
535
536 **/
537 VOID
538 DevPathFibre (
539 IN OUT POOL_PRINT *Str,
540 IN VOID *DevPath
541 )
542 {
543 FIBRECHANNEL_DEVICE_PATH *Fibre;
544
545 Fibre = DevPath;
546 CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun);
547 }
548
549 /**
550 Convert Device Path to a Unicode string for printing.
551
552 @param Str The buffer holding the output string.
553 This buffer contains the length of the
554 string and the maixmum length reserved
555 for the string buffer.
556 @param DevPath The device path.
557
558 **/
559 VOID
560 DevPath1394 (
561 IN OUT POOL_PRINT *Str,
562 IN VOID *DevPath
563 )
564 {
565 F1394_DEVICE_PATH *F1394Path;
566
567 F1394Path = DevPath;
568 CatPrint (Str, L"1394(%g)", &F1394Path->Guid);
569 }
570
571 /**
572 Convert Device Path to a Unicode string for printing.
573
574 @param Str The buffer holding the output string.
575 This buffer contains the length of the
576 string and the maixmum length reserved
577 for the string buffer.
578 @param DevPath The device path.
579
580 **/
581 VOID
582 DevPathUsb (
583 IN OUT POOL_PRINT *Str,
584 IN VOID *DevPath
585 )
586 {
587 USB_DEVICE_PATH *Usb;
588
589 Usb = DevPath;
590 CatPrint (Str, L"Usb(%x,%x)", (UINTN) Usb->ParentPortNumber, (UINTN) Usb->InterfaceNumber);
591 }
592
593 /**
594 Convert Device Path to a Unicode string for printing.
595
596 @param Str The buffer holding the output string.
597 This buffer contains the length of the
598 string and the maixmum length reserved
599 for the string buffer.
600 @param DevPath The device path.
601
602 **/
603 VOID
604 DevPathUsbWWID (
605 IN OUT POOL_PRINT *Str,
606 IN VOID *DevPath
607 )
608 {
609 USB_WWID_DEVICE_PATH *UsbWWId;
610
611 UsbWWId = DevPath;
612 CatPrint (
613 Str,
614 L"UsbWwid(%x,%x,%x,\"WWID\")",
615 (UINTN) UsbWWId->VendorId,
616 (UINTN) UsbWWId->ProductId,
617 (UINTN) UsbWWId->InterfaceNumber
618 );
619 }
620
621 /**
622 Convert Device Path to a Unicode string for printing.
623
624 @param Str The buffer holding the output string.
625 This buffer contains the length of the
626 string and the maixmum length reserved
627 for the string buffer.
628 @param DevPath The device path.
629
630 **/
631 VOID
632 DevPathLogicalUnit (
633 IN OUT POOL_PRINT *Str,
634 IN VOID *DevPath
635 )
636 {
637 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
638
639 LogicalUnit = DevPath;
640 CatPrint (Str, L"Unit(%x)", (UINTN) LogicalUnit->Lun);
641 }
642
643 /**
644 Convert Device Path to a Unicode string for printing.
645
646 @param Str The buffer holding the output string.
647 This buffer contains the length of the
648 string and the maixmum length reserved
649 for the string buffer.
650 @param DevPath The device path.
651
652 **/
653 VOID
654 DevPathUsbClass (
655 IN OUT POOL_PRINT *Str,
656 IN VOID *DevPath
657 )
658 {
659 USB_CLASS_DEVICE_PATH *UsbClass;
660
661 UsbClass = DevPath;
662 CatPrint (
663 Str,
664 L"Usb Class(%x,%x,%x,%x,%x)",
665 (UINTN) UsbClass->VendorId,
666 (UINTN) UsbClass->ProductId,
667 (UINTN) UsbClass->DeviceClass,
668 (UINTN) UsbClass->DeviceSubClass,
669 (UINTN) UsbClass->DeviceProtocol
670 );
671 }
672
673 /**
674 Convert Device Path to a Unicode string for printing.
675
676 @param Str The buffer holding the output string.
677 This buffer contains the length of the
678 string and the maixmum length reserved
679 for the string buffer.
680 @param DevPath The device path.
681
682 **/
683 VOID
684 DevPathSata (
685 IN OUT POOL_PRINT *Str,
686 IN VOID *DevPath
687 )
688 {
689 SATA_DEVICE_PATH *Sata;
690
691 Sata = DevPath;
692 CatPrint (
693 Str,
694 L"Sata(%x,%x,%x)",
695 (UINTN) Sata->HBAPortNumber,
696 (UINTN) Sata->PortMultiplierPortNumber,
697 (UINTN) Sata->Lun
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(%d,%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 ASSERT (Str != NULL);
965 ASSERT (DevPath != NULL);
966
967 IScsi = DevPath;
968 CatPrint (
969 Str,
970 L"iSCSI(%s,%x,%lx,",
971 IScsi->iSCSITargetName,
972 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 DevPathHardDrive (
1003 IN OUT POOL_PRINT *Str,
1004 IN VOID *DevPath
1005 )
1006 {
1007 HARDDRIVE_DEVICE_PATH *Hd;
1008
1009 Hd = DevPath;
1010 switch (Hd->SignatureType) {
1011 case SIGNATURE_TYPE_MBR:
1012 CatPrint (
1013 Str,
1014 L"HD(Part%d,Sig%08x)",
1015 (UINTN) Hd->PartitionNumber,
1016 (UINTN) *((UINT32 *) (&(Hd->Signature[0])))
1017 );
1018 break;
1019
1020 case SIGNATURE_TYPE_GUID:
1021 CatPrint (
1022 Str,
1023 L"HD(Part%d,Sig%g)",
1024 (UINTN) Hd->PartitionNumber,
1025 (EFI_GUID *) &(Hd->Signature[0])
1026 );
1027 break;
1028
1029 default:
1030 CatPrint (
1031 Str,
1032 L"HD(Part%d,MBRType=%02x,SigType=%02x)",
1033 (UINTN) Hd->PartitionNumber,
1034 (UINTN) Hd->MBRType,
1035 (UINTN) Hd->SignatureType
1036 );
1037 break;
1038 }
1039 }
1040
1041 /**
1042 Convert Device Path to a Unicode string for printing.
1043
1044 @param Str The buffer holding the output string.
1045 This buffer contains the length of the
1046 string and the maixmum length reserved
1047 for the string buffer.
1048 @param DevPath The device path.
1049
1050 **/
1051 VOID
1052 DevPathCDROM (
1053 IN OUT POOL_PRINT *Str,
1054 IN VOID *DevPath
1055 )
1056 {
1057 CDROM_DEVICE_PATH *Cd;
1058
1059 Cd = DevPath;
1060 CatPrint (Str, L"CDROM(Entry%x)", (UINTN) Cd->BootEntry);
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 DevPathFilePath (
1075 IN OUT POOL_PRINT *Str,
1076 IN VOID *DevPath
1077 )
1078 {
1079 FILEPATH_DEVICE_PATH *Fp;
1080
1081 Fp = DevPath;
1082 CatPrint (Str, L"%s", Fp->PathName);
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 DevPathMediaProtocol (
1097 IN OUT POOL_PRINT *Str,
1098 IN VOID *DevPath
1099 )
1100 {
1101 MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
1102
1103 MediaProt = DevPath;
1104 CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
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 DevPathFvFilePath (
1119 IN OUT POOL_PRINT *Str,
1120 IN VOID *DevPath
1121 )
1122 {
1123 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
1124
1125 FvFilePath = DevPath;
1126 CatPrint (Str, L"%g", &FvFilePath->FvFileName);
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 DevPathBssBss (
1141 IN OUT POOL_PRINT *Str,
1142 IN VOID *DevPath
1143 )
1144 {
1145 BBS_BBS_DEVICE_PATH *Bbs;
1146 CHAR16 *Type;
1147
1148 Bbs = DevPath;
1149 switch (Bbs->DeviceType) {
1150 case BBS_TYPE_FLOPPY:
1151 Type = L"Floppy";
1152 break;
1153
1154 case BBS_TYPE_HARDDRIVE:
1155 Type = L"Harddrive";
1156 break;
1157
1158 case BBS_TYPE_CDROM:
1159 Type = L"CDROM";
1160 break;
1161
1162 case BBS_TYPE_PCMCIA:
1163 Type = L"PCMCIA";
1164 break;
1165
1166 case BBS_TYPE_USB:
1167 Type = L"Usb";
1168 break;
1169
1170 case BBS_TYPE_EMBEDDED_NETWORK:
1171 Type = L"Net";
1172 break;
1173
1174 case BBS_TYPE_BEV:
1175 Type = L"BEV";
1176 break;
1177
1178 default:
1179 Type = L"?";
1180 break;
1181 }
1182 CatPrint (Str, L"Legacy-%s", Type);
1183 }
1184
1185 /**
1186 Convert Device Path to a Unicode string for printing.
1187
1188 @param Str The buffer holding the output string.
1189 This buffer contains the length of the
1190 string and the maixmum length reserved
1191 for the string buffer.
1192 @param DevPath The device path.
1193
1194 **/
1195 VOID
1196 DevPathEndInstance (
1197 IN OUT POOL_PRINT *Str,
1198 IN VOID *DevPath
1199 )
1200 {
1201 CatPrint (Str, L",");
1202 }
1203
1204 /**
1205 Convert Device Path to a Unicode string for printing.
1206
1207 @param Str The buffer holding the output string.
1208 This buffer contains the length of the
1209 string and the maixmum length reserved
1210 for the string buffer.
1211 @param DevPath The device path.
1212
1213 **/
1214 VOID
1215 DevPathNodeUnknown (
1216 IN OUT POOL_PRINT *Str,
1217 IN VOID *DevPath
1218 )
1219 {
1220 CatPrint (Str, L"?");
1221 }
1222
1223 DEVICE_PATH_STRING_TABLE DevPathTable[] = {
1224 {
1225 HARDWARE_DEVICE_PATH,
1226 HW_PCI_DP,
1227 DevPathPci
1228 },
1229 {
1230 HARDWARE_DEVICE_PATH,
1231 HW_PCCARD_DP,
1232 DevPathPccard
1233 },
1234 {
1235 HARDWARE_DEVICE_PATH,
1236 HW_MEMMAP_DP,
1237 DevPathMemMap
1238 },
1239 {
1240 HARDWARE_DEVICE_PATH,
1241 HW_VENDOR_DP,
1242 DevPathVendor
1243 },
1244 {
1245 HARDWARE_DEVICE_PATH,
1246 HW_CONTROLLER_DP,
1247 DevPathController
1248 },
1249 {
1250 ACPI_DEVICE_PATH,
1251 ACPI_DP,
1252 DevPathAcpi
1253 },
1254 {
1255 ACPI_DEVICE_PATH,
1256 ACPI_EXTENDED_DP,
1257 DevPathExtendedAcpi
1258 },
1259 {
1260 ACPI_DEVICE_PATH,
1261 ACPI_ADR_DP,
1262 DevPathAdrAcpi
1263 },
1264 {
1265 MESSAGING_DEVICE_PATH,
1266 MSG_ATAPI_DP,
1267 DevPathAtapi
1268 },
1269 {
1270 MESSAGING_DEVICE_PATH,
1271 MSG_SCSI_DP,
1272 DevPathScsi
1273 },
1274 {
1275 MESSAGING_DEVICE_PATH,
1276 MSG_FIBRECHANNEL_DP,
1277 DevPathFibre
1278 },
1279 {
1280 MESSAGING_DEVICE_PATH,
1281 MSG_1394_DP,
1282 DevPath1394
1283 },
1284 {
1285 MESSAGING_DEVICE_PATH,
1286 MSG_USB_DP,
1287 DevPathUsb
1288 },
1289 {
1290 MESSAGING_DEVICE_PATH,
1291 MSG_USB_WWID_DP,
1292 DevPathUsbWWID
1293 },
1294 {
1295 MESSAGING_DEVICE_PATH,
1296 MSG_DEVICE_LOGICAL_UNIT_DP,
1297 DevPathLogicalUnit
1298 },
1299 {
1300 MESSAGING_DEVICE_PATH,
1301 MSG_USB_CLASS_DP,
1302 DevPathUsbClass
1303 },
1304 {
1305 MESSAGING_DEVICE_PATH,
1306 MSG_SATA_DP,
1307 DevPathSata
1308 },
1309 {
1310 MESSAGING_DEVICE_PATH,
1311 MSG_I2O_DP,
1312 DevPathI2O
1313 },
1314 {
1315 MESSAGING_DEVICE_PATH,
1316 MSG_MAC_ADDR_DP,
1317 DevPathMacAddr
1318 },
1319 {
1320 MESSAGING_DEVICE_PATH,
1321 MSG_IPv4_DP,
1322 DevPathIPv4
1323 },
1324 {
1325 MESSAGING_DEVICE_PATH,
1326 MSG_IPv6_DP,
1327 DevPathIPv6
1328 },
1329 {
1330 MESSAGING_DEVICE_PATH,
1331 MSG_INFINIBAND_DP,
1332 DevPathInfiniBand
1333 },
1334 {
1335 MESSAGING_DEVICE_PATH,
1336 MSG_UART_DP,
1337 DevPathUart
1338 },
1339 {
1340 MESSAGING_DEVICE_PATH,
1341 MSG_VENDOR_DP,
1342 DevPathVendor
1343 },
1344 {
1345 MESSAGING_DEVICE_PATH,
1346 MSG_ISCSI_DP,
1347 DevPathiSCSI
1348 },
1349 {
1350 MEDIA_DEVICE_PATH,
1351 MEDIA_HARDDRIVE_DP,
1352 DevPathHardDrive
1353 },
1354 {
1355 MEDIA_DEVICE_PATH,
1356 MEDIA_CDROM_DP,
1357 DevPathCDROM
1358 },
1359 {
1360 MEDIA_DEVICE_PATH,
1361 MEDIA_VENDOR_DP,
1362 DevPathVendor
1363 },
1364 {
1365 MEDIA_DEVICE_PATH,
1366 MEDIA_FILEPATH_DP,
1367 DevPathFilePath
1368 },
1369 {
1370 MEDIA_DEVICE_PATH,
1371 MEDIA_PROTOCOL_DP,
1372 DevPathMediaProtocol
1373 },
1374 {
1375 MEDIA_DEVICE_PATH,
1376 MEDIA_PIWG_FW_FILE_DP,
1377 DevPathFvFilePath
1378 },
1379 {
1380 BBS_DEVICE_PATH,
1381 BBS_BBS_DP,
1382 DevPathBssBss
1383 },
1384 {
1385 END_DEVICE_PATH_TYPE,
1386 END_INSTANCE_DEVICE_PATH_SUBTYPE,
1387 DevPathEndInstance
1388 },
1389 {
1390 0,
1391 0,
1392 NULL
1393 }
1394 };
1395
1396
1397 /**
1398 This function converts an input device structure to a Unicode string.
1399
1400 @param DevPath A pointer to the device path structure.
1401
1402 @return A new allocated Unicode string that represents the device path.
1403
1404 **/
1405 CHAR16 *
1406 EFIAPI
1407 DevicePathToStr (
1408 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
1409 )
1410 {
1411 POOL_PRINT Str;
1412 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
1413 VOID (*DumpNode) (POOL_PRINT *, VOID *);
1414
1415 UINTN Index;
1416 UINTN NewSize;
1417
1418 EFI_STATUS Status;
1419 CHAR16 *ToText;
1420 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;
1421
1422 ZeroMem (&Str, sizeof (Str));
1423
1424 if (DevPath == NULL) {
1425 goto Done;
1426 }
1427
1428 Status = gBS->LocateProtocol (
1429 &gEfiDevicePathToTextProtocolGuid,
1430 NULL,
1431 (VOID **) &DevPathToText
1432 );
1433 if (!EFI_ERROR (Status)) {
1434 ToText = DevPathToText->ConvertDevicePathToText (
1435 DevPath,
1436 FALSE,
1437 TRUE
1438 );
1439 ASSERT (ToText != NULL);
1440 return ToText;
1441 }
1442
1443 //
1444 // Process each device path node
1445 //
1446 DevPathNode = DevPath;
1447 while (!IsDevicePathEnd (DevPathNode)) {
1448 //
1449 // Find the handler to dump this device path node
1450 //
1451 DumpNode = NULL;
1452 for (Index = 0; DevPathTable[Index].Function; Index += 1) {
1453
1454 if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&
1455 DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType
1456 ) {
1457 DumpNode = DevPathTable[Index].Function;
1458 break;
1459 }
1460 }
1461 //
1462 // If not found, use a generic function
1463 //
1464 if (!DumpNode) {
1465 DumpNode = DevPathNodeUnknown;
1466 }
1467 //
1468 // Put a path seperator in if needed
1469 //
1470 if (Str.len && DumpNode != DevPathEndInstance) {
1471 CatPrint (&Str, L"/");
1472 }
1473 //
1474 // Print this node of the device path
1475 //
1476 DumpNode (&Str, DevPathNode);
1477
1478 //
1479 // Next device path node
1480 //
1481 DevPathNode = NextDevicePathNode (DevPathNode);
1482 }
1483 //
1484 // Shrink pool used for string allocation
1485 //
1486 FreePool (DevPath);
1487
1488 Done:
1489 NewSize = (Str.len + 1) * sizeof (CHAR16);
1490 Str.str = ReallocatePool (NewSize, NewSize, Str.str);
1491 ASSERT (Str.str != NULL);
1492 Str.str[Str.len] = 0;
1493 return Str.str;
1494 }