3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 BDS internal function define the default device path string, it can be
19 replaced by platform device path.
23 EFI_GUID mEfiUnixThunkProtocolGuid
= EFI_UNIX_THUNK_PROTOCOL_GUID
;
24 EFI_GUID mEfiUnixUgaGuid
= EFI_UNIX_UGA_GUID
;
25 EFI_GUID mEfiMsgPcAnsiGuid
= DEVICE_PATH_MESSAGING_PC_ANSI
;
26 EFI_GUID mEfiMsgVt100Guid
= DEVICE_PATH_MESSAGING_VT_100
;
27 EFI_GUID mEfiMsgVt100PlusGuid
= DEVICE_PATH_MESSAGING_VT_100_PLUS
;
28 EFI_GUID mEfiMsgVt100Utf8Guid
= DEVICE_PATH_MESSAGING_VT_UTF8
;
40 Adjusts the size of a previously allocated buffer.
44 OldPool - A pointer to the buffer whose size is being adjusted.
46 OldSize - The size of the current buffer.
48 NewSize - The size of the new buffer.
52 EFI_SUCEESS - The requested number of bytes were allocated.
54 EFI_OUT_OF_RESOURCES - The pool requested could not be allocated.
56 EFI_INVALID_PARAMETER - The buffer was invalid.
64 NewPool
= AllocateZeroPool (NewSize
);
69 CopyMem (NewPool
, OldPool
, OldSize
< NewSize
? OldSize
: NewSize
);
72 gBS
->FreePool (OldPool
);
80 IN OUT POOL_PRINT
*Str
,
88 Concatenates a formatted unicode string to allocated pool.
89 The caller must free the resulting buffer.
93 Str - Tracks the allocated pool, size in use, and
94 amount of pool allocated.
96 fmt - The format string
100 Allocated buffer with the formatted string printed in it.
101 The caller must free the allocated buffer. The buffer
102 allocation is not packed.
110 AppendStr
= AllocateZeroPool (0x1000);
111 if (AppendStr
== NULL
) {
115 VA_START (args
, fmt
);
116 UnicodeVSPrint (AppendStr
, 0x1000, fmt
, args
);
118 if (NULL
== Str
->str
) {
119 strsize
= StrSize (AppendStr
);
120 Str
->str
= AllocateZeroPool (strsize
);
121 ASSERT (Str
->str
!= NULL
);
123 strsize
= StrSize (AppendStr
) + StrSize (Str
->str
) - sizeof (UINT16
);
124 Str
->str
= ReallocatePool (
129 ASSERT (Str
->str
!= NULL
);
132 Str
->maxlen
= MAX_CHAR
* sizeof (UINT16
);
133 if (strsize
< Str
->maxlen
) {
134 StrCat (Str
->str
, AppendStr
);
135 Str
->len
= strsize
- sizeof (UINT16
);
138 gBS
->FreePool (AppendStr
);
142 EFI_DEVICE_PATH_PROTOCOL
*
143 BdsLibUnpackDevicePath (
144 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
150 Function unpacks a device path data structure so that all the nodes
151 of a device path are naturally aligned.
155 DevPath - A pointer to a device path data structure
159 If the memory for the device path is successfully allocated, then a
160 pointer to the new device path is returned. Otherwise, NULL is returned.
164 EFI_DEVICE_PATH_PROTOCOL
*Src
;
165 EFI_DEVICE_PATH_PROTOCOL
*Dest
;
166 EFI_DEVICE_PATH_PROTOCOL
*NewPath
;
170 // Walk device path and round sizes to valid boundries
175 Size
+= DevicePathNodeLength (Src
);
176 Size
+= ALIGN_SIZE (Size
);
178 if (IsDevicePathEnd (Src
)) {
182 Src
= NextDevicePathNode (Src
);
185 // Allocate space for the unpacked path
187 NewPath
= AllocateZeroPool (Size
);
190 ASSERT (((UINTN
) NewPath
) % MIN_ALIGNMENT_SIZE
== 0);
198 Size
= DevicePathNodeLength (Src
);
199 CopyMem (Dest
, Src
, Size
);
200 Size
+= ALIGN_SIZE (Size
);
201 SetDevicePathNodeLength (Dest
, Size
);
202 Dest
->Type
|= EFI_DP_TYPE_UNPACKED
;
203 Dest
= (EFI_DEVICE_PATH_PROTOCOL
*) (((UINT8
*) Dest
) + Size
);
205 if (IsDevicePathEnd (Src
)) {
209 Src
= NextDevicePathNode (Src
);
218 IN OUT POOL_PRINT
*Str
,
222 PCI_DEVICE_PATH
*Pci
;
225 CatPrint (Str
, L
"Pci(%x|%x)", Pci
->Device
, Pci
->Function
);
230 IN OUT POOL_PRINT
*Str
,
234 PCCARD_DEVICE_PATH
*Pccard
;
237 CatPrint (Str
, L
"Pcmcia(Function%x)", Pccard
->FunctionNumber
);
242 IN OUT POOL_PRINT
*Str
,
246 MEMMAP_DEVICE_PATH
*MemMap
;
251 L
"MemMap(%d:%.lx-%.lx)",
253 MemMap
->StartingAddress
,
254 MemMap
->EndingAddress
260 IN OUT POOL_PRINT
*Str
,
264 CONTROLLER_DEVICE_PATH
*Controller
;
266 Controller
= DevPath
;
267 CatPrint (Str
, L
"Ctrl(%d)", Controller
->ControllerNumber
);
272 IN OUT POOL_PRINT
*Str
,
279 Convert Vendor device path to device name
283 Str - The buffer store device name
284 DevPath - Pointer to vendor device path
288 When it return, the device name have been stored in *Str.
292 VENDOR_DEVICE_PATH
*Vendor
;
297 Temp
= (INT32
*) (&Vendor
->Guid
);
299 switch (DevicePathType (&Vendor
->Header
)) {
300 case HARDWARE_DEVICE_PATH
:
302 // If the device is an Unix device, we will give it a readable device name.
304 if (CompareGuid (&Vendor
->Guid
, &mEfiUnixThunkProtocolGuid
)) {
305 CatPrint (Str
, L
"%s", L
"UnixBus");
307 } else if (CompareGuid (&Vendor
->Guid
, &mEfiUnixUgaGuid
)) {
308 CatPrint (Str
, L
"%s", L
"UGA");
315 case MESSAGING_DEVICE_PATH
:
317 // If the device is an Unix device, we will give it a readable device name.
319 if (CompareGuid (&Vendor
->Guid
, &mEfiMsgPcAnsiGuid
)) {
320 CatPrint (Str
, L
"%s", L
"PC-ANSI");
322 } else if (CompareGuid (&Vendor
->Guid
, &mEfiMsgVt100Guid
)) {
323 CatPrint (Str
, L
"%s", L
"VT100");
325 } else if (CompareGuid (&Vendor
->Guid
, &mEfiMsgVt100PlusGuid
)) {
326 CatPrint (Str
, L
"%s", L
"VT100+");
328 } else if (CompareGuid (&Vendor
->Guid
, &mEfiMsgVt100Utf8Guid
)) {
329 CatPrint (Str
, L
"%s", L
"VT100-UTF8");
336 case MEDIA_DEVICE_PATH
:
345 CatPrint (Str
, L
"Ven%s(%g)", Type
, &Vendor
->Guid
);
350 IN OUT POOL_PRINT
*Str
,
354 ACPI_HID_DEVICE_PATH
*Acpi
;
357 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
358 CatPrint (Str
, L
"Acpi(PNP%04x,%x)", EISA_ID_TO_NUM (Acpi
->HID
), Acpi
->UID
);
360 CatPrint (Str
, L
"Acpi(%08x,%x)", Acpi
->HID
, Acpi
->UID
);
366 IN OUT POOL_PRINT
*Str
,
370 ATAPI_DEVICE_PATH
*Atapi
;
376 Atapi
->PrimarySecondary
? L
"Secondary" : L
"Primary",
377 Atapi
->SlaveMaster
? L
"Slave" : L
"Master"
383 IN OUT POOL_PRINT
*Str
,
387 SCSI_DEVICE_PATH
*Scsi
;
390 CatPrint (Str
, L
"Scsi(Pun%x,Lun%x)", Scsi
->Pun
, Scsi
->Lun
);
395 IN OUT POOL_PRINT
*Str
,
399 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
402 CatPrint (Str
, L
"Fibre(Wwn%lx,Lun%x)", Fibre
->WWN
, Fibre
->Lun
);
407 IN OUT POOL_PRINT
*Str
,
411 F1394_DEVICE_PATH
*F1394
;
414 CatPrint (Str
, L
"1394(%g)", &F1394
->Guid
);
419 IN OUT POOL_PRINT
*Str
,
423 USB_DEVICE_PATH
*Usb
;
426 CatPrint (Str
, L
"Usb(%x, %x)", Usb
->ParentPortNumber
, Usb
->InterfaceNumber
);
431 IN OUT POOL_PRINT
*Str
,
435 USB_CLASS_DEVICE_PATH
*UsbClass
;
440 L
"Usb Class(%x, %x, %x, %x, %x)",
443 UsbClass
->DeviceClass
,
444 UsbClass
->DeviceSubClass
,
445 UsbClass
->DeviceProtocol
451 IN OUT POOL_PRINT
*Str
,
455 I2O_DEVICE_PATH
*I2O
;
458 CatPrint (Str
, L
"I2O(%x)", I2O
->Tid
);
463 IN OUT POOL_PRINT
*Str
,
467 MAC_ADDR_DEVICE_PATH
*MAC
;
473 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
474 if (MAC
->IfType
== 0x01 || MAC
->IfType
== 0x00) {
478 CatPrint (Str
, L
"Mac(");
480 for (Index
= 0; Index
< HwAddressSize
; Index
++) {
481 CatPrint (Str
, L
"%02x", MAC
->MacAddress
.Addr
[Index
]);
484 CatPrint (Str
, L
")");
489 IN OUT POOL_PRINT
*Str
,
493 IPv4_DEVICE_PATH
*IP
;
498 L
"IPv4(%d.%d.%d.%d:%d)",
499 IP
->RemoteIpAddress
.Addr
[0],
500 IP
->RemoteIpAddress
.Addr
[1],
501 IP
->RemoteIpAddress
.Addr
[2],
502 IP
->RemoteIpAddress
.Addr
[3],
509 IN OUT POOL_PRINT
*Str
,
513 IPv6_DEVICE_PATH
*IP
;
516 CatPrint (Str
, L
"IP-v6(not-done)");
521 IN OUT POOL_PRINT
*Str
,
525 INFINIBAND_DEVICE_PATH
*InfiniBand
;
527 InfiniBand
= DevPath
;
528 CatPrint (Str
, L
"InfiniBand(not-done)");
533 IN OUT POOL_PRINT
*Str
,
537 UART_DEVICE_PATH
*Uart
;
541 switch (Uart
->Parity
) {
571 if (Uart
->BaudRate
== 0) {
572 CatPrint (Str
, L
"Uart(DEFAULT %c", Parity
);
574 CatPrint (Str
, L
"Uart(%d %c", Uart
->BaudRate
, Parity
);
577 if (Uart
->DataBits
== 0) {
578 CatPrint (Str
, L
"D");
580 CatPrint (Str
, L
"%d", Uart
->DataBits
);
583 switch (Uart
->StopBits
) {
585 CatPrint (Str
, L
"D)");
589 CatPrint (Str
, L
"1)");
593 CatPrint (Str
, L
"1.5)");
597 CatPrint (Str
, L
"2)");
601 CatPrint (Str
, L
"x)");
608 IN OUT POOL_PRINT
*Str
,
612 HARDDRIVE_DEVICE_PATH
*Hd
;
615 switch (Hd
->SignatureType
) {
616 case SIGNATURE_TYPE_MBR
:
619 L
"HD(Part%d,Sig%08x)",
621 *((UINT32
*) (&(Hd
->Signature
[0])))
625 case SIGNATURE_TYPE_GUID
:
630 (EFI_GUID
*) &(Hd
->Signature
[0])
637 L
"HD(Part%d,MBRType=%02x,SigType=%02x)",
648 IN OUT POOL_PRINT
*Str
,
652 CDROM_DEVICE_PATH
*Cd
;
655 CatPrint (Str
, L
"CDROM(Entry%x)", Cd
->BootEntry
);
660 IN OUT POOL_PRINT
*Str
,
664 FILEPATH_DEVICE_PATH
*Fp
;
667 CatPrint (Str
, L
"%s", Fp
->PathName
);
671 DevPathMediaProtocol (
672 IN OUT POOL_PRINT
*Str
,
676 MEDIA_PROTOCOL_DEVICE_PATH
*MediaProt
;
679 CatPrint (Str
, L
"%g", &MediaProt
->Protocol
);
684 IN OUT POOL_PRINT
*Str
,
688 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
690 FvFilePath
= DevPath
;
691 CatPrint (Str
, L
"%g", &FvFilePath
->NameGuid
);
696 IN OUT POOL_PRINT
*Str
,
700 BBS_BBS_DEVICE_PATH
*Bbs
;
704 switch (Bbs
->DeviceType
) {
705 case BBS_TYPE_FLOPPY
:
709 case BBS_TYPE_HARDDRIVE
:
717 case BBS_TYPE_PCMCIA
:
725 case BBS_TYPE_EMBEDDED_NETWORK
:
734 // Since current Print function hasn't implemented %a (for ansi string)
735 // we will only print Unicode strings.
737 CatPrint (Str
, L
"Legacy-%s", Type
);
742 IN OUT POOL_PRINT
*Str
,
746 CatPrint (Str
, L
",");
751 IN OUT POOL_PRINT
*Str
,
755 CatPrint (Str
, L
"?");
758 DEVICE_PATH_STRING_TABLE DevPathTable
[] = {
760 HARDWARE_DEVICE_PATH
,
765 HARDWARE_DEVICE_PATH
,
770 HARDWARE_DEVICE_PATH
,
775 HARDWARE_DEVICE_PATH
,
780 HARDWARE_DEVICE_PATH
,
790 MESSAGING_DEVICE_PATH
,
795 MESSAGING_DEVICE_PATH
,
800 MESSAGING_DEVICE_PATH
,
805 MESSAGING_DEVICE_PATH
,
810 MESSAGING_DEVICE_PATH
,
815 MESSAGING_DEVICE_PATH
,
820 MESSAGING_DEVICE_PATH
,
825 MESSAGING_DEVICE_PATH
,
830 MESSAGING_DEVICE_PATH
,
835 MESSAGING_DEVICE_PATH
,
840 MESSAGING_DEVICE_PATH
,
845 MESSAGING_DEVICE_PATH
,
850 MESSAGING_DEVICE_PATH
,
880 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
883 MEDIA_FV_FILEPATH_DP
,
894 END_DEVICE_PATH_TYPE
,
895 END_INSTANCE_DEVICE_PATH_SUBTYPE
,
907 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
911 Turns the Device Path into a printable string. Allcoates
912 the string from pool. The caller must SafeFreePool the returned
918 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
919 VOID (*DumpNode
) (POOL_PRINT
*, VOID
*);
924 ZeroMem (&Str
, sizeof (Str
));
926 if (DevPath
== NULL
) {
930 // Unpacked the device path
932 DevPath
= BdsLibUnpackDevicePath (DevPath
);
936 // Process each device path node
938 DevPathNode
= DevPath
;
939 while (!IsDevicePathEnd (DevPathNode
)) {
941 // Find the handler to dump this device path node
944 for (Index
= 0; DevPathTable
[Index
].Function
; Index
+= 1) {
946 if (DevicePathType (DevPathNode
) == DevPathTable
[Index
].Type
&&
947 DevicePathSubType (DevPathNode
) == DevPathTable
[Index
].SubType
949 DumpNode
= DevPathTable
[Index
].Function
;
954 // If not found, use a generic function
957 DumpNode
= DevPathNodeUnknown
;
960 // Put a path seperator in if needed
962 if (Str
.len
&& DumpNode
!= DevPathEndInstance
) {
963 CatPrint (&Str
, L
"/");
966 // Print this node of the device path
968 DumpNode (&Str
, DevPathNode
);
971 // Next device path node
973 DevPathNode
= NextDevicePathNode (DevPathNode
);
976 // Shrink pool used for string allocation
978 gBS
->FreePool (DevPath
);
981 NewSize
= (Str
.len
+ 1) * sizeof (CHAR16
);
982 Str
.str
= ReallocatePool (Str
.str
, NewSize
, NewSize
);
983 ASSERT (Str
.str
!= NULL
);
984 Str
.str
[Str
.len
] = 0;
988 EFI_DEVICE_PATH_PROTOCOL
*
989 LibDuplicateDevicePathInstance (
990 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
996 Function creates a device path data structure that identically matches the
997 device path passed in.
1001 DevPath - A pointer to a device path data structure.
1005 The new copy of DevPath is created to identically match the input.
1006 Otherwise, NULL is returned.
1010 EFI_DEVICE_PATH_PROTOCOL
*NewDevPath
;
1011 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInst
;
1012 EFI_DEVICE_PATH_PROTOCOL
*Temp
;
1016 // get the size of an instance from the input
1019 DevicePathInst
= GetNextDevicePathInstance (&Temp
, &Size
);
1026 NewDevPath
= AllocateZeroPool (Size
);
1027 ASSERT (NewDevPath
!= NULL
);
1031 CopyMem (NewDevPath
, DevicePathInst
, Size
);