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