VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware2/VBoxPkg/Library/VBoxGenericBdsLib/DevicePath.c@ 33540

Last change on this file since 33540 was 33540, checked in by vboxsync, 14 years ago

*: spelling fixes, thanks Timeless!

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette