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