]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/GenericBdsLib/DevicePath.c
Update all files to follow doxygen style file header.
[mirror_edk2.git] / MdeModulePkg / Library / GenericBdsLib / DevicePath.c
CommitLineData
93e3992d 1/** @file
2
3Copyright (c) 2004 - 2007, Intel Corporation
4All rights reserved. This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution. The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12Module Name:
13
14 DevicePath.c
15
16Abstract:
17
18 BDS internal function define the default device path string, it can be
19 replaced by platform device path.
20
21
22**/
23
24#include "InternalBdsLib.h"
25
26//
27// Platform Code should implement the Vendor specific Device Path display routine.
28//
29extern
30VOID
31DevPathVendor (
32 IN OUT POOL_PRINT *Str,
33 IN VOID *DevPath
34 )
35;
36
37EFI_GUID mEfiDevicePathMessagingUartFlowControlGuid = DEVICE_PATH_MESSAGING_UART_FLOW_CONTROL;
38
39EFI_GUID mEfiDevicePathMessagingSASGuid = DEVICE_PATH_MESSAGING_SAS;
40
41
42VOID *
43ReallocatePool (
44 IN VOID *OldPool,
45 IN UINTN OldSize,
46 IN UINTN NewSize
47 )
48/*++
49
50Routine Description:
51
52 Adjusts the size of a previously allocated buffer.
53
54Arguments:
55
56 OldPool - A pointer to the buffer whose size is being adjusted.
57
58 OldSize - The size of the current buffer.
59
60 NewSize - The size of the new buffer.
61
62Returns:
63
64 EFI_SUCEESS - The requested number of bytes were allocated.
65
66 EFI_OUT_OF_RESOURCES - The pool requested could not be allocated.
67
68 EFI_INVALID_PARAMETER - The buffer was invalid.
69
70--*/
71{
72 VOID *NewPool;
73
74 NewPool = NULL;
75 if (NewSize) {
76 NewPool = AllocateZeroPool (NewSize);
77 }
78
79 if (OldPool) {
80 if (NewPool) {
81 CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
82 }
83
84 gBS->FreePool (OldPool);
85 }
86
87 return NewPool;
88}
89
90
91/**
92 Concatenates a formatted unicode string to allocated pool.
93 The caller must free the resulting buffer.
94
95 @param Str Tracks the allocated pool, size in use, and amount of pool
96 allocated.
97 @param fmt The format string
98
99 @return Allocated buffer with the formatted string printed in it.
100 @return The caller must free the allocated buffer. The buffer
101 @return allocation is not packed.
102
103**/
104CHAR16 *
105CatPrint (
106 IN OUT POOL_PRINT *Str,
107 IN CHAR16 *fmt,
108 ...
109 )
110{
111 UINT16 *AppendStr;
112 VA_LIST args;
113 UINTN strsize;
114
115 AppendStr = AllocateZeroPool (0x1000);
116 if (AppendStr == NULL) {
117 return Str->str;
118 }
119
120 VA_START (args, fmt);
121 UnicodeVSPrint (AppendStr, 0x1000, fmt, args);
122 VA_END (args);
123 if (NULL == Str->str) {
124 strsize = StrSize (AppendStr);
125 Str->str = AllocateZeroPool (strsize);
126 ASSERT (Str->str != NULL);
127 } else {
128 strsize = StrSize (AppendStr);
129 strsize += (StrSize (Str->str) - sizeof (UINT16));
130
131 Str->str = ReallocatePool (
132 Str->str,
133 StrSize (Str->str),
134 strsize
135 );
136 ASSERT (Str->str != NULL);
137 }
138
139 Str->maxlen = MAX_CHAR * sizeof (UINT16);
140 if (strsize < Str->maxlen) {
141 StrCat (Str->str, AppendStr);
142 Str->len = strsize - sizeof (UINT16);
143 }
144
145 gBS->FreePool (AppendStr);
146 return Str->str;
147}
148
149
150/**
151 Function unpacks a device path data structure so that all the nodes
152 of a device path are naturally aligned.
153
154 @param DevPath A pointer to a device path data structure
155
156 @return If the memory for the device path is successfully allocated, then a
157 @return pointer to the new device path is returned. Otherwise, NULL is returned.
158
159**/
160EFI_DEVICE_PATH_PROTOCOL *
161BdsLibUnpackDevicePath (
162 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
163 )
164{
165 EFI_DEVICE_PATH_PROTOCOL *Src;
166 EFI_DEVICE_PATH_PROTOCOL *Dest;
167 EFI_DEVICE_PATH_PROTOCOL *NewPath;
168 UINTN Size;
169
170 //
171 // Walk device path and round sizes to valid boundries
172 //
173 Src = DevPath;
174 Size = 0;
175 for (;;) {
176 Size += DevicePathNodeLength (Src);
177 Size += ALIGN_SIZE (Size);
178
179 if (IsDevicePathEnd (Src)) {
180 break;
181 }
182
183 Src = NextDevicePathNode (Src);
184 }
185 //
186 // Allocate space for the unpacked path
187 //
188 NewPath = AllocateZeroPool (Size);
189 if (NewPath) {
190
191 ASSERT (((UINTN) NewPath) % MIN_ALIGNMENT_SIZE == 0);
192
193 //
194 // Copy each node
195 //
196 Src = DevPath;
197 Dest = NewPath;
198 for (;;) {
199 Size = DevicePathNodeLength (Src);
200 CopyMem (Dest, Src, Size);
201 Size += ALIGN_SIZE (Size);
202 SetDevicePathNodeLength (Dest, Size);
203 Dest->Type |= EFI_DP_TYPE_UNPACKED;
204 Dest = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) Dest) + Size);
205
206 if (IsDevicePathEnd (Src)) {
207 break;
208 }
209
210 Src = NextDevicePathNode (Src);
211 }
212 }
213
214 return NewPath;
215}
216
217VOID
218DevPathPci (
219 IN OUT POOL_PRINT *Str,
220 IN VOID *DevPath
221 )
222{
223 PCI_DEVICE_PATH *Pci;
224
225 Pci = DevPath;
226 CatPrint (Str, L"Pci(%x|%x)", (UINTN) Pci->Device, (UINTN) Pci->Function);
227}
228
229VOID
230DevPathPccard (
231 IN OUT POOL_PRINT *Str,
232 IN VOID *DevPath
233 )
234{
235 PCCARD_DEVICE_PATH *Pccard;
236
237 Pccard = DevPath;
238 CatPrint (Str, L"Pcmcia(Function%x)", (UINTN) Pccard->FunctionNumber);
239}
240
241VOID
242DevPathMemMap (
243 IN OUT POOL_PRINT *Str,
244 IN VOID *DevPath
245 )
246{
247 MEMMAP_DEVICE_PATH *MemMap;
248
249 MemMap = DevPath;
250 CatPrint (
251 Str,
252 L"MemMap(%d:%lx-%lx)",
253 MemMap->MemoryType,
254 MemMap->StartingAddress,
255 MemMap->EndingAddress
256 );
257}
258
259VOID
260DevPathController (
261 IN OUT POOL_PRINT *Str,
262 IN VOID *DevPath
263 )
264{
265 CONTROLLER_DEVICE_PATH *Controller;
266
267 Controller = DevPath;
268 CatPrint (Str, L"Ctrl(%d)", (UINTN) Controller->ControllerNumber);
269}
270
271
272/**
273 Convert Vendor device path to device name
274
275 @param Str The buffer store device name
276 @param DevPath Pointer to vendor device path
277
278 @return When it return, the device name have been stored in *Str.
279
280**/
281VOID
282DevPathVendor (
283 IN OUT POOL_PRINT *Str,
284 IN VOID *DevPath
285 )
286{
287 VENDOR_DEVICE_PATH *Vendor;
288 CHAR16 *Type;
289 UINTN DataLength;
290 UINTN Index;
291 UINT32 FlowControlMap;
292
293 UINT16 Info;
294
295 Vendor = DevPath;
296
297 switch (DevicePathType (&Vendor->Header)) {
298 case HARDWARE_DEVICE_PATH:
299 Type = L"Hw";
300// bugbug: nt 32 specific definition
301#if 0
302 //
303 // If the device is a winntbus device, we will give it a readable device name.
304 //
305 if (CompareGuid (&Vendor->Guid, &mEfiWinNtThunkProtocolGuid)) {
306 CatPrint (Str, L"%s", L"WinNtBus");
307 return ;
308 } else if (CompareGuid (&Vendor->Guid, &mEfiWinNtGopGuid)) {
309 CatPrint (Str, L"%s", L"GOP");
310 return ;
311 } else if (CompareGuid (&Vendor->Guid, &mEfiWinNtSerialPortGuid)) {
312 CatPrint (Str, L"%s", L"Serial");
313 return ;
314 }
315#endif
316 break;
317
318 case MESSAGING_DEVICE_PATH:
319 Type = L"Msg";
320 if (CompareGuid (&Vendor->Guid, &gEfiPcAnsiGuid)) {
321 CatPrint (Str, L"VenPcAnsi()");
322 return ;
323 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100Guid)) {
324 CatPrint (Str, L"VenVt100()");
325 return ;
326 } else if (CompareGuid (&Vendor->Guid, &gEfiVT100PlusGuid)) {
327 CatPrint (Str, L"VenVt100Plus()");
328 return ;
329 } else if (CompareGuid (&Vendor->Guid, &gEfiVTUTF8Guid)) {
330 CatPrint (Str, L"VenUft8()");
331 return ;
332 } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingUartFlowControlGuid)) {
333 FlowControlMap = (((UART_FLOW_CONTROL_DEVICE_PATH *) Vendor)->FlowControlMap);
334 switch (FlowControlMap & 0x00000003) {
335 case 0:
336 CatPrint (Str, L"UartFlowCtrl(%s)", L"None");
337 break;
338
339 case 1:
340 CatPrint (Str, L"UartFlowCtrl(%s)", L"Hardware");
341 break;
342
343 case 2:
344 CatPrint (Str, L"UartFlowCtrl(%s)", L"XonXoff");
345 break;
346
347 default:
348 break;
349 }
350
351 return ;
352
353 } else if (CompareGuid (&Vendor->Guid, &mEfiDevicePathMessagingSASGuid)) {
354 CatPrint (
355 Str,
356 L"SAS(%lx,%lx,%x,",
357 ((SAS_DEVICE_PATH *) Vendor)->SasAddress,
358 ((SAS_DEVICE_PATH *) Vendor)->Lun,
359 ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort
360 );
361 Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);
362 if ((Info & 0x0f) == 0) {
363 CatPrint (Str, L"NoTopology,0,0,0,");
364 } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {
365 CatPrint (
366 Str,
367 L"%s,%s,%s,",
368 (Info & (0x1 << 4)) ? L"SATA" : L"SAS",
369 (Info & (0x1 << 5)) ? L"External" : L"Internal",
370 (Info & (0x1 << 6)) ? L"Expanded" : L"Direct"
371 );
372 if ((Info & 0x0f) == 1) {
373 CatPrint (Str, L"0,");
374 } else {
375 CatPrint (Str, L"%x,", (UINTN) ((Info >> 8) & 0xff));
376 }
377 } else {
378 CatPrint (Str, L"0,0,0,0,");
379 }
380
381 CatPrint (Str, L"%x)", (UINTN) ((SAS_DEVICE_PATH *) Vendor)->Reserved);
382 return ;
383
384 } else if (CompareGuid (&Vendor->Guid, &gEfiDebugPortProtocolGuid)) {
385 CatPrint (Str, L"DebugPort()");
386 return ;
387 }
388 break;
389
390 case MEDIA_DEVICE_PATH:
391 Type = L"Media";
392 break;
393
394 default:
395 Type = L"?";
396 break;
397 }
398
399 CatPrint (Str, L"Ven%s(%g", Type, &Vendor->Guid);
400 DataLength = DevicePathNodeLength (&Vendor->Header) - sizeof (VENDOR_DEVICE_PATH);
401 if (DataLength > 0) {
402 CatPrint (Str, L",");
403 for (Index = 0; Index < DataLength; Index++) {
404 CatPrint (Str, L"%02x", (UINTN) ((VENDOR_DEVICE_PATH_WITH_DATA *) Vendor)->VendorDefinedData[Index]);
405 }
406 }
407 CatPrint (Str, L")");
408}
409
410
411VOID
412DevPathAcpi (
413 IN OUT POOL_PRINT *Str,
414 IN VOID *DevPath
415 )
416{
417 ACPI_HID_DEVICE_PATH *Acpi;
418
419 Acpi = DevPath;
420 if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
421 CatPrint (Str, L"Acpi(PNP%04x,%x)", (UINTN) EISA_ID_TO_NUM (Acpi->HID), (UINTN) Acpi->UID);
422 } else {
423 CatPrint (Str, L"Acpi(%08x,%x)", (UINTN) Acpi->HID, (UINTN) Acpi->UID);
424 }
425}
426
427VOID
428DevPathExtendedAcpi (
429 IN OUT POOL_PRINT *Str,
430 IN VOID *DevPath
431 )
432{
433 ACPI_EXTENDED_HID_DEVICE_PATH *ExtendedAcpi;
434 //
435 // Index for HID, UID and CID strings, 0 for non-exist
436 //
437 UINT16 HIDSTRIdx;
438 UINT16 UIDSTRIdx;
439 UINT16 CIDSTRIdx;
440 UINT16 Index;
441 UINT16 Length;
442 UINT16 Anchor;
443 CHAR8 *AsChar8Array;
444
445 ASSERT (Str != NULL);
446 ASSERT (DevPath != NULL);
447
448 HIDSTRIdx = 0;
449 UIDSTRIdx = 0;
450 CIDSTRIdx = 0;
451 ExtendedAcpi = DevPath;
452 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) ExtendedAcpi);
453
454 ASSERT (Length >= 19);
455 AsChar8Array = (CHAR8 *) ExtendedAcpi;
456
457 //
458 // find HIDSTR
459 //
460 Anchor = 16;
461 for (Index = Anchor; Index < Length && AsChar8Array[Index]; Index++) {
462 ;
463 }
464 if (Index > Anchor) {
465 HIDSTRIdx = Anchor;
466 }
467 //
468 // find UIDSTR
469 //
470 Anchor = (UINT16) (Index + 1);
471 for (Index = Anchor; Index < Length && AsChar8Array[Index]; Index++) {
472 ;
473 }
474 if (Index > Anchor) {
475 UIDSTRIdx = Anchor;
476 }
477 //
478 // find CIDSTR
479 //
480 Anchor = (UINT16) (Index + 1);
481 for (Index = Anchor; Index < Length && AsChar8Array[Index]; Index++) {
482 ;
483 }
484 if (Index > Anchor) {
485 CIDSTRIdx = Anchor;
486 }
487
488 if (HIDSTRIdx == 0 && CIDSTRIdx == 0 && ExtendedAcpi->UID == 0) {
489 CatPrint (Str, L"AcpiExp(");
490 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
491 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));
492 } else {
493 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
494 }
495 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
496 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));
497 } else {
498 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);
499 }
500 if (UIDSTRIdx != 0) {
501 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
502 } else {
503 CatPrint (Str, L"\"\")");
504 }
505 } else {
506 CatPrint (Str, L"AcpiEx(");
507 if ((ExtendedAcpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
508 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->HID));
509 } else {
510 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->HID);
511 }
512 if ((ExtendedAcpi->CID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
513 CatPrint (Str, L"PNP%04x,", (UINTN) EISA_ID_TO_NUM (ExtendedAcpi->CID));
514 } else {
515 CatPrint (Str, L"%08x,", (UINTN) ExtendedAcpi->CID);
516 }
517 CatPrint (Str, L"%x,", (UINTN) ExtendedAcpi->UID);
518
519 if (HIDSTRIdx != 0) {
520 CatPrint (Str, L"%a,", AsChar8Array + HIDSTRIdx);
521 } else {
522 CatPrint (Str, L"\"\",");
523 }
524 if (CIDSTRIdx != 0) {
525 CatPrint (Str, L"%a,", AsChar8Array + CIDSTRIdx);
526 } else {
527 CatPrint (Str, L"\"\",");
528 }
529 if (UIDSTRIdx != 0) {
530 CatPrint (Str, L"%a)", AsChar8Array + UIDSTRIdx);
531 } else {
532 CatPrint (Str, L"\"\")");
533 }
534 }
535
536}
537
538VOID
539DevPathAdrAcpi (
540 IN OUT POOL_PRINT *Str,
541 IN VOID *DevPath
542 )
543{
544 ACPI_ADR_DEVICE_PATH *AcpiAdr;
545 UINT16 Index;
546 UINT16 Length;
547 UINT16 AdditionalAdrCount;
548
549 AcpiAdr = DevPath;
550 Length = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr);
551 AdditionalAdrCount = (UINT16) ((Length - 8) / 4);
552
553 CatPrint (Str, L"AcpiAdr(%x", (UINTN) AcpiAdr->ADR);
554 for (Index = 0; Index < AdditionalAdrCount; Index++) {
555 CatPrint (Str, L",%x", (UINTN) *(UINT32 *) ((UINT8 *) AcpiAdr + 8 + Index * 4));
556 }
557 CatPrint (Str, L")");
558}
559
560VOID
561DevPathAtapi (
562 IN OUT POOL_PRINT *Str,
563 IN VOID *DevPath
564 )
565{
566 ATAPI_DEVICE_PATH *Atapi;
567
568 Atapi = DevPath;
569 CatPrint (
570 Str,
571 L"Ata(%s,%s)",
572 Atapi->PrimarySecondary ? L"Secondary" : L"Primary",
573 Atapi->SlaveMaster ? L"Slave" : L"Master"
574 );
575}
576
577VOID
578DevPathScsi (
579 IN OUT POOL_PRINT *Str,
580 IN VOID *DevPath
581 )
582{
583 SCSI_DEVICE_PATH *Scsi;
584
585 Scsi = DevPath;
586 CatPrint (Str, L"Scsi(Pun%x,Lun%x)", (UINTN) Scsi->Pun, (UINTN) Scsi->Lun);
587}
588
589VOID
590DevPathFibre (
591 IN OUT POOL_PRINT *Str,
592 IN VOID *DevPath
593 )
594{
595 FIBRECHANNEL_DEVICE_PATH *Fibre;
596
597 Fibre = DevPath;
598 CatPrint (Str, L"Fibre(Wwn%lx,Lun%x)", Fibre->WWN, Fibre->Lun);
599}
600
601VOID
602DevPath1394 (
603 IN OUT POOL_PRINT *Str,
604 IN VOID *DevPath
605 )
606{
607 F1394_DEVICE_PATH *F1394;
608
609 F1394 = DevPath;
610 CatPrint (Str, L"1394(%g)", &F1394->Guid);
611}
612
613VOID
614DevPathUsb (
615 IN OUT POOL_PRINT *Str,
616 IN VOID *DevPath
617 )
618{
619 USB_DEVICE_PATH *Usb;
620
621 Usb = DevPath;
622 CatPrint (Str, L"Usb(%x,%x)", (UINTN) Usb->ParentPortNumber, (UINTN) Usb->InterfaceNumber);
623}
624
93e3992d 625VOID
626DevPathUsbWWID (
627 IN OUT POOL_PRINT *Str,
628 IN VOID *DevPath
629 )
630{
631 USB_WWID_DEVICE_PATH *UsbWWId;
632
633 UsbWWId = DevPath;
634 CatPrint (
635 Str,
636 L"UsbWwid(%x,%x,%x,\"WWID\")",
637 (UINTN) UsbWWId->VendorId,
638 (UINTN) UsbWWId->ProductId,
639 (UINTN) UsbWWId->InterfaceNumber
640 );
641}
642
643VOID
644DevPathLogicalUnit (
645 IN OUT POOL_PRINT *Str,
646 IN VOID *DevPath
647 )
648{
649 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
650
651 LogicalUnit = DevPath;
652 CatPrint (Str, L"Unit(%x)", (UINTN) LogicalUnit->Lun);
653}
93e3992d 654
655VOID
656DevPathUsbClass (
657 IN OUT POOL_PRINT *Str,
658 IN VOID *DevPath
659 )
660{
661 USB_CLASS_DEVICE_PATH *UsbClass;
662
663 UsbClass = DevPath;
664 CatPrint (
665 Str,
666 L"Usb Class(%x,%x,%x,%x,%x)",
667 (UINTN) UsbClass->VendorId,
668 (UINTN) UsbClass->ProductId,
669 (UINTN) UsbClass->DeviceClass,
670 (UINTN) UsbClass->DeviceSubClass,
671 (UINTN) UsbClass->DeviceProtocol
672 );
673}
674
675VOID
676DevPathSata (
677 IN OUT POOL_PRINT *Str,
678 IN VOID *DevPath
679 )
680{
681 SATA_DEVICE_PATH *Sata;
682
683 Sata = DevPath;
684 CatPrint (
685 Str,
686 L"Sata(%x,%x,%x)",
687 (UINTN) Sata->HBAPortNumber,
688 (UINTN) Sata->PortMultiplierPortNumber,
689 (UINTN) Sata->Lun
690 );
691}
692
693VOID
694DevPathI2O (
695 IN OUT POOL_PRINT *Str,
696 IN VOID *DevPath
697 )
698{
699 I2O_DEVICE_PATH *I2O;
700
701 I2O = DevPath;
702 CatPrint (Str, L"I2O(%x)", (UINTN) I2O->Tid);
703}
704
705VOID
706DevPathMacAddr (
707 IN OUT POOL_PRINT *Str,
708 IN VOID *DevPath
709 )
710{
711 MAC_ADDR_DEVICE_PATH *MAC;
712 UINTN HwAddressSize;
713 UINTN Index;
714
715 MAC = DevPath;
716
717 HwAddressSize = sizeof (EFI_MAC_ADDRESS);
718 if (MAC->IfType == 0x01 || MAC->IfType == 0x00) {
719 HwAddressSize = 6;
720 }
721
722 CatPrint (Str, L"Mac(");
723
724 for (Index = 0; Index < HwAddressSize; Index++) {
725 CatPrint (Str, L"%02x", (UINTN) MAC->MacAddress.Addr[Index]);
726 }
727
728 CatPrint (Str, L")");
729}
730
731VOID
732DevPathIPv4 (
733 IN OUT POOL_PRINT *Str,
734 IN VOID *DevPath
735 )
736{
737 IPv4_DEVICE_PATH *IP;
738
739 IP = DevPath;
740 CatPrint (
741 Str,
742 L"IPv4(%d.%d.%d.%d:%d)",
743 (UINTN) IP->RemoteIpAddress.Addr[0],
744 (UINTN) IP->RemoteIpAddress.Addr[1],
745 (UINTN) IP->RemoteIpAddress.Addr[2],
746 (UINTN) IP->RemoteIpAddress.Addr[3],
747 (UINTN) IP->RemotePort
748 );
749}
750
751VOID
752DevPathIPv6 (
753 IN OUT POOL_PRINT *Str,
754 IN VOID *DevPath
755 )
756{
757 IPv6_DEVICE_PATH *IP;
758
759 IP = DevPath;
760 CatPrint (
761 Str,
762 L"IPv6(%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x)",
763 (UINTN) IP->RemoteIpAddress.Addr[0],
764 (UINTN) IP->RemoteIpAddress.Addr[1],
765 (UINTN) IP->RemoteIpAddress.Addr[2],
766 (UINTN) IP->RemoteIpAddress.Addr[3],
767 (UINTN) IP->RemoteIpAddress.Addr[4],
768 (UINTN) IP->RemoteIpAddress.Addr[5],
769 (UINTN) IP->RemoteIpAddress.Addr[6],
770 (UINTN) IP->RemoteIpAddress.Addr[7],
771 (UINTN) IP->RemoteIpAddress.Addr[8],
772 (UINTN) IP->RemoteIpAddress.Addr[9],
773 (UINTN) IP->RemoteIpAddress.Addr[10],
774 (UINTN) IP->RemoteIpAddress.Addr[11],
775 (UINTN) IP->RemoteIpAddress.Addr[12],
776 (UINTN) IP->RemoteIpAddress.Addr[13],
777 (UINTN) IP->RemoteIpAddress.Addr[14],
778 (UINTN) IP->RemoteIpAddress.Addr[15]
779 );
780}
781
782VOID
783DevPathInfiniBand (
784 IN OUT POOL_PRINT *Str,
785 IN VOID *DevPath
786 )
787{
788 INFINIBAND_DEVICE_PATH *InfiniBand;
789
790 InfiniBand = DevPath;
791 CatPrint (
792 Str,
793 L"Infiniband(%x,%g,%lx,%lx,%lx)",
794 (UINTN) InfiniBand->ResourceFlags,
795 InfiniBand->PortGid,
796 InfiniBand->ServiceId,
797 InfiniBand->TargetPortId,
798 InfiniBand->DeviceId
799 );
800}
801
802VOID
803DevPathUart (
804 IN OUT POOL_PRINT *Str,
805 IN VOID *DevPath
806 )
807{
808 UART_DEVICE_PATH *Uart;
809 CHAR8 Parity;
810
811 Uart = DevPath;
812 switch (Uart->Parity) {
813 case 0:
814 Parity = 'D';
815 break;
816
817 case 1:
818 Parity = 'N';
819 break;
820
821 case 2:
822 Parity = 'E';
823 break;
824
825 case 3:
826 Parity = 'O';
827 break;
828
829 case 4:
830 Parity = 'M';
831 break;
832
833 case 5:
834 Parity = 'S';
835 break;
836
837 default:
838 Parity = 'x';
839 break;
840 }
841
842 if (Uart->BaudRate == 0) {
843 CatPrint (Str, L"Uart(DEFAULT,%c,", Parity);
844 } else {
845 CatPrint (Str, L"Uart(%d,%c,", Uart->BaudRate, Parity);
846 }
847
848 if (Uart->DataBits == 0) {
849 CatPrint (Str, L"D,");
850 } else {
851 CatPrint (Str, L"%d,", (UINTN) Uart->DataBits);
852 }
853
854 switch (Uart->StopBits) {
855 case 0:
856 CatPrint (Str, L"D)");
857 break;
858
859 case 1:
860 CatPrint (Str, L"1)");
861 break;
862
863 case 2:
864 CatPrint (Str, L"1.5)");
865 break;
866
867 case 3:
868 CatPrint (Str, L"2)");
869 break;
870
871 default:
872 CatPrint (Str, L"x)");
873 break;
874 }
875}
876
93e3992d 877VOID
878DevPathiSCSI (
879 IN OUT POOL_PRINT *Str,
880 IN VOID *DevPath
881 )
882{
883 ISCSI_DEVICE_PATH_WITH_NAME *iSCSI;
884 UINT16 Options;
885
886 ASSERT (Str != NULL);
887 ASSERT (DevPath != NULL);
888
889 iSCSI = DevPath;
890 CatPrint (
891 Str,
892 L"iSCSI(%s,%x,%lx,",
893 iSCSI->iSCSITargetName,
894 iSCSI->TargetPortalGroupTag,
895 iSCSI->Lun
896 );
897
898 Options = iSCSI->LoginOption;
899 CatPrint (Str, L"%s,", ((Options >> 1) & 0x0001) ? L"CRC32C" : L"None");
900 CatPrint (Str, L"%s,", ((Options >> 3) & 0x0001) ? L"CRC32C" : L"None");
901 if ((Options >> 11) & 0x0001) {
902 CatPrint (Str, L"%s,", L"None");
903 } else if ((Options >> 12) & 0x0001) {
904 CatPrint (Str, L"%s,", L"CHAP_UNI");
905 } else {
906 CatPrint (Str, L"%s,", L"CHAP_BI");
907
908 }
909
910 CatPrint (Str, L"%s)", (iSCSI->NetworkProtocol == 0) ? L"TCP" : L"reserved");
911}
93e3992d 912
913VOID
914DevPathHardDrive (
915 IN OUT POOL_PRINT *Str,
916 IN VOID *DevPath
917 )
918{
919 HARDDRIVE_DEVICE_PATH *Hd;
920
921 Hd = DevPath;
922 switch (Hd->SignatureType) {
923 case SIGNATURE_TYPE_MBR:
924 CatPrint (
925 Str,
926 L"HD(Part%d,Sig%08x)",
927 (UINTN) Hd->PartitionNumber,
928 (UINTN) *((UINT32 *) (&(Hd->Signature[0])))
929 );
930 break;
931
932 case SIGNATURE_TYPE_GUID:
933 CatPrint (
934 Str,
935 L"HD(Part%d,Sig%g)",
936 (UINTN) Hd->PartitionNumber,
937 (EFI_GUID *) &(Hd->Signature[0])
938 );
939 break;
940
941 default:
942 CatPrint (
943 Str,
944 L"HD(Part%d,MBRType=%02x,SigType=%02x)",
945 (UINTN) Hd->PartitionNumber,
946 (UINTN) Hd->MBRType,
947 (UINTN) Hd->SignatureType
948 );
949 break;
950 }
951}
952
953VOID
954DevPathCDROM (
955 IN OUT POOL_PRINT *Str,
956 IN VOID *DevPath
957 )
958{
959 CDROM_DEVICE_PATH *Cd;
960
961 Cd = DevPath;
962 CatPrint (Str, L"CDROM(Entry%x)", (UINTN) Cd->BootEntry);
963}
964
965VOID
966DevPathFilePath (
967 IN OUT POOL_PRINT *Str,
968 IN VOID *DevPath
969 )
970{
971 FILEPATH_DEVICE_PATH *Fp;
972
973 Fp = DevPath;
974 CatPrint (Str, L"%s", Fp->PathName);
975}
976
977VOID
978DevPathMediaProtocol (
979 IN OUT POOL_PRINT *Str,
980 IN VOID *DevPath
981 )
982{
983 MEDIA_PROTOCOL_DEVICE_PATH *MediaProt;
984
985 MediaProt = DevPath;
986 CatPrint (Str, L"Media(%g)", &MediaProt->Protocol);
987}
988
989VOID
990DevPathFvFilePath (
991 IN OUT POOL_PRINT *Str,
992 IN VOID *DevPath
993 )
994{
995 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;
996
997 FvFilePath = DevPath;
998 CatPrint (Str, L"%g", &FvFilePath->FvFileName);
999}
1000
1001VOID
1002DevPathBssBss (
1003 IN OUT POOL_PRINT *Str,
1004 IN VOID *DevPath
1005 )
1006{
1007 BBS_BBS_DEVICE_PATH *Bbs;
1008 CHAR16 *Type;
1009
1010 Bbs = DevPath;
1011 switch (Bbs->DeviceType) {
1012 case BBS_TYPE_FLOPPY:
1013 Type = L"Floppy";
1014 break;
1015
1016 case BBS_TYPE_HARDDRIVE:
1017 Type = L"Harddrive";
1018 break;
1019
1020 case BBS_TYPE_CDROM:
1021 Type = L"CDROM";
1022 break;
1023
1024 case BBS_TYPE_PCMCIA:
1025 Type = L"PCMCIA";
1026 break;
1027
1028 case BBS_TYPE_USB:
1029 Type = L"Usb";
1030 break;
1031
1032 case BBS_TYPE_EMBEDDED_NETWORK:
1033 Type = L"Net";
1034 break;
1035
1036 case BBS_TYPE_BEV:
1037 Type = L"BEV";
1038 break;
1039
1040 default:
1041 Type = L"?";
1042 break;
1043 }
1044 CatPrint (Str, L"Legacy-%s", Type);
1045}
1046
1047VOID
1048DevPathEndInstance (
1049 IN OUT POOL_PRINT *Str,
1050 IN VOID *DevPath
1051 )
1052{
1053 CatPrint (Str, L",");
1054}
1055
1056VOID
1057DevPathNodeUnknown (
1058 IN OUT POOL_PRINT *Str,
1059 IN VOID *DevPath
1060 )
1061{
1062 CatPrint (Str, L"?");
1063}
1064
1065DEVICE_PATH_STRING_TABLE DevPathTable[] = {
1066 HARDWARE_DEVICE_PATH,
1067 HW_PCI_DP,
1068 DevPathPci,
1069 HARDWARE_DEVICE_PATH,
1070 HW_PCCARD_DP,
1071 DevPathPccard,
1072 HARDWARE_DEVICE_PATH,
1073 HW_MEMMAP_DP,
1074 DevPathMemMap,
1075 HARDWARE_DEVICE_PATH,
1076 HW_VENDOR_DP,
1077 DevPathVendor,
1078 HARDWARE_DEVICE_PATH,
1079 HW_CONTROLLER_DP,
1080 DevPathController,
1081 ACPI_DEVICE_PATH,
1082 ACPI_DP,
1083 DevPathAcpi,
1084 ACPI_DEVICE_PATH,
1085 ACPI_EXTENDED_DP,
1086 DevPathExtendedAcpi,
1087 ACPI_DEVICE_PATH,
1088 ACPI_ADR_DP,
1089 DevPathAdrAcpi,
1090 MESSAGING_DEVICE_PATH,
1091 MSG_ATAPI_DP,
1092 DevPathAtapi,
1093 MESSAGING_DEVICE_PATH,
1094 MSG_SCSI_DP,
1095 DevPathScsi,
1096 MESSAGING_DEVICE_PATH,
1097 MSG_FIBRECHANNEL_DP,
1098 DevPathFibre,
1099 MESSAGING_DEVICE_PATH,
1100 MSG_1394_DP,
1101 DevPath1394,
1102 MESSAGING_DEVICE_PATH,
1103 MSG_USB_DP,
1104 DevPathUsb,
93e3992d 1105 MESSAGING_DEVICE_PATH,
1106 MSG_USB_WWID_DP,
1107 DevPathUsbWWID,
1108 MESSAGING_DEVICE_PATH,
1109 MSG_DEVICE_LOGICAL_UNIT_DP,
1110 DevPathLogicalUnit,
93e3992d 1111 MESSAGING_DEVICE_PATH,
1112 MSG_USB_CLASS_DP,
1113 DevPathUsbClass,
1114 MESSAGING_DEVICE_PATH,
1115 MSG_SATA_DP,
1116 DevPathSata,
1117 MESSAGING_DEVICE_PATH,
1118 MSG_I2O_DP,
1119 DevPathI2O,
1120 MESSAGING_DEVICE_PATH,
1121 MSG_MAC_ADDR_DP,
1122 DevPathMacAddr,
1123 MESSAGING_DEVICE_PATH,
1124 MSG_IPv4_DP,
1125 DevPathIPv4,
1126 MESSAGING_DEVICE_PATH,
1127 MSG_IPv6_DP,
1128 DevPathIPv6,
1129 MESSAGING_DEVICE_PATH,
1130 MSG_INFINIBAND_DP,
1131 DevPathInfiniBand,
1132 MESSAGING_DEVICE_PATH,
1133 MSG_UART_DP,
1134 DevPathUart,
1135 MESSAGING_DEVICE_PATH,
1136 MSG_VENDOR_DP,
1137 DevPathVendor,
93e3992d 1138 MESSAGING_DEVICE_PATH,
1139 MSG_ISCSI_DP,
1140 DevPathiSCSI,
93e3992d 1141 MEDIA_DEVICE_PATH,
1142 MEDIA_HARDDRIVE_DP,
1143 DevPathHardDrive,
1144 MEDIA_DEVICE_PATH,
1145 MEDIA_CDROM_DP,
1146 DevPathCDROM,
1147 MEDIA_DEVICE_PATH,
1148 MEDIA_VENDOR_DP,
1149 DevPathVendor,
1150 MEDIA_DEVICE_PATH,
1151 MEDIA_FILEPATH_DP,
1152 DevPathFilePath,
1153 MEDIA_DEVICE_PATH,
1154 MEDIA_PROTOCOL_DP,
1155 DevPathMediaProtocol,
93e3992d 1156 MEDIA_DEVICE_PATH,
1157 MEDIA_PIWG_FW_FILE_DP,
1158 DevPathFvFilePath,
93e3992d 1159 BBS_DEVICE_PATH,
1160 BBS_BBS_DP,
1161 DevPathBssBss,
1162 END_DEVICE_PATH_TYPE,
1163 END_INSTANCE_DEVICE_PATH_SUBTYPE,
1164 DevPathEndInstance,
1165 0,
1166 0,
1167 NULL
1168};
1169
1170
1171/**
1172
1173**/
1174CHAR16 *
1175DevicePathToStr (
1176 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
1177 )
1178{
1179 POOL_PRINT Str;
1180 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
1181 VOID (*DumpNode) (POOL_PRINT *, VOID *);
1182
1183 UINTN Index;
1184 UINTN NewSize;
1185
1186 EFI_STATUS Status;
1187 CHAR16 *ToText;
1188 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;
1189
1190 ZeroMem (&Str, sizeof (Str));
1191
1192 if (DevPath == NULL) {
1193 goto Done;
1194 }
1195
1196 Status = gBS->LocateProtocol (
1197 &gEfiDevicePathToTextProtocolGuid,
1198 NULL,
1199 (VOID **) &DevPathToText
1200 );
1201 if (!EFI_ERROR (Status)) {
1202 ToText = DevPathToText->ConvertDevicePathToText (
1203 DevPath,
1204 FALSE,
1205 TRUE
1206 );
1207 ASSERT (ToText != NULL);
1208 return ToText;
1209 }
1210
1211 //
1212 // Unpacked the device path
1213 //
1214 DevPath = BdsLibUnpackDevicePath (DevPath);
1215 ASSERT (DevPath);
1216
1217 //
1218 // Process each device path node
1219 //
1220 DevPathNode = DevPath;
1221 while (!IsDevicePathEnd (DevPathNode)) {
1222 //
1223 // Find the handler to dump this device path node
1224 //
1225 DumpNode = NULL;
1226 for (Index = 0; DevPathTable[Index].Function; Index += 1) {
1227
1228 if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&
1229 DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType
1230 ) {
1231 DumpNode = DevPathTable[Index].Function;
1232 break;
1233 }
1234 }
1235 //
1236 // If not found, use a generic function
1237 //
1238 if (!DumpNode) {
1239 DumpNode = DevPathNodeUnknown;
1240 }
1241 //
1242 // Put a path seperator in if needed
1243 //
1244 if (Str.len && DumpNode != DevPathEndInstance) {
1245 CatPrint (&Str, L"/");
1246 }
1247 //
1248 // Print this node of the device path
1249 //
1250 DumpNode (&Str, DevPathNode);
1251
1252 //
1253 // Next device path node
1254 //
1255 DevPathNode = NextDevicePathNode (DevPathNode);
1256 }
1257 //
1258 // Shrink pool used for string allocation
1259 //
1260 gBS->FreePool (DevPath);
1261
1262Done:
1263 NewSize = (Str.len + 1) * sizeof (CHAR16);
1264 Str.str = ReallocatePool (Str.str, NewSize, NewSize);
1265 ASSERT (Str.str != NULL);
1266 Str.str[Str.len] = 0;
1267 return Str.str;
1268}
1269
1270
1271/**
1272 Function creates a device path data structure that identically matches the
1273 device path passed in.
1274
1275 @param DevPath A pointer to a device path data structure.
1276
1277 @return The new copy of DevPath is created to identically match the input.
1278 @return Otherwise, NULL is returned.
1279
1280**/
1281EFI_DEVICE_PATH_PROTOCOL *
1282LibDuplicateDevicePathInstance (
1283 IN EFI_DEVICE_PATH_PROTOCOL *DevPath
1284 )
1285{
1286 EFI_DEVICE_PATH_PROTOCOL *NewDevPath;
1287 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
1288 EFI_DEVICE_PATH_PROTOCOL *Temp;
1289 UINTN Size;
1290
1291 //
1292 // get the size of an instance from the input
1293 //
1294 Temp = DevPath;
1295 DevicePathInst = GetNextDevicePathInstance (&Temp, &Size);
1296
1297 //
1298 // Make a copy
1299 //
1300 NewDevPath = NULL;
1301 if (Size) {
1302 NewDevPath = AllocateZeroPool (Size);
1303 ASSERT (NewDevPath != NULL);
1304 }
1305
1306 if (NewDevPath) {
1307 CopyMem (NewDevPath, DevicePathInst, Size);
1308 }
1309
1310 return NewDevPath;
1311}