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