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