]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
Add 4 APIs to DevicePathLib: ConvertDeviceNodeToText, ConvertDevicePathToText, Conver...
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / DevicePathFromText.c
1 /** @file
2 DevicePathFromText protocol as defined in the UEFI 2.0 specification.
3
4 Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "UefiDevicePathLib.h"
16
17 /**
18
19 Duplicates a string.
20
21 @param Src Source string.
22
23 @return The duplicated string.
24
25 **/
26 CHAR16 *
27 UefiDevicePathLibStrDuplicate (
28 IN CONST CHAR16 *Src
29 )
30 {
31 return AllocateCopyPool (StrSize (Src), Src);
32 }
33
34 /**
35
36 Get parameter in a pair of parentheses follow the given node name.
37 For example, given the "Pci(0,1)" and NodeName "Pci", it returns "0,1".
38
39 @param Str Device Path Text.
40 @param NodeName Name of the node.
41
42 @return Parameter text for the node.
43
44 **/
45 CHAR16 *
46 GetParamByNodeName (
47 IN CHAR16 *Str,
48 IN CHAR16 *NodeName
49 )
50 {
51 CHAR16 *ParamStr;
52 CHAR16 *StrPointer;
53 UINTN NodeNameLength;
54 UINTN ParameterLength;
55
56 //
57 // Check whether the node name matchs
58 //
59 NodeNameLength = StrLen (NodeName);
60 if (StrnCmp (Str, NodeName, NodeNameLength) != 0) {
61 return NULL;
62 }
63
64 ParamStr = Str + NodeNameLength;
65 if (!IS_LEFT_PARENTH (*ParamStr)) {
66 return NULL;
67 }
68
69 //
70 // Skip the found '(' and find first occurrence of ')'
71 //
72 ParamStr++;
73 ParameterLength = 0;
74 StrPointer = ParamStr;
75 while (!IS_NULL (*StrPointer)) {
76 if (IS_RIGHT_PARENTH (*StrPointer)) {
77 break;
78 }
79 StrPointer++;
80 ParameterLength++;
81 }
82 if (IS_NULL (*StrPointer)) {
83 //
84 // ')' not found
85 //
86 return NULL;
87 }
88
89 ParamStr = AllocateCopyPool ((ParameterLength + 1) * sizeof (CHAR16), ParamStr);
90 if (ParamStr == NULL) {
91 return NULL;
92 }
93 //
94 // Terminate the parameter string
95 //
96 ParamStr[ParameterLength] = L'\0';
97
98 return ParamStr;
99 }
100
101 /**
102 Gets current sub-string from a string list, before return
103 the list header is moved to next sub-string. The sub-string is separated
104 by the specified character. For example, the separator is ',', the string
105 list is "2,0,3", it returns "2", the remain list move to "0,3"
106
107 @param List A string list separated by the specified separator
108 @param Separator The separator character
109
110 @return A pointer to the current sub-string
111
112 **/
113 CHAR16 *
114 SplitStr (
115 IN OUT CHAR16 **List,
116 IN CHAR16 Separator
117 )
118 {
119 CHAR16 *Str;
120 CHAR16 *ReturnStr;
121
122 Str = *List;
123 ReturnStr = Str;
124
125 if (IS_NULL (*Str)) {
126 return ReturnStr;
127 }
128
129 //
130 // Find first occurrence of the separator
131 //
132 while (!IS_NULL (*Str)) {
133 if (*Str == Separator) {
134 break;
135 }
136 Str++;
137 }
138
139 if (*Str == Separator) {
140 //
141 // Find a sub-string, terminate it
142 //
143 *Str = L'\0';
144 Str++;
145 }
146
147 //
148 // Move to next sub-string
149 //
150 *List = Str;
151
152 return ReturnStr;
153 }
154
155 /**
156 Gets the next parameter string from the list.
157
158 @param List A string list separated by the specified separator
159
160 @return A pointer to the current sub-string
161
162 **/
163 CHAR16 *
164 GetNextParamStr (
165 IN OUT CHAR16 **List
166 )
167 {
168 //
169 // The separator is comma
170 //
171 return SplitStr (List, L',');
172 }
173
174 /**
175 Get one device node from entire device path text.
176
177 @param DevicePath On input, the current Device Path node; on output, the next device path node
178 @param IsInstanceEnd This node is the end of a device path instance
179
180 @return A device node text or NULL if no more device node available
181
182 **/
183 CHAR16 *
184 GetNextDeviceNodeStr (
185 IN OUT CHAR16 **DevicePath,
186 OUT BOOLEAN *IsInstanceEnd
187 )
188 {
189 CHAR16 *Str;
190 CHAR16 *ReturnStr;
191 UINTN ParenthesesStack;
192
193 Str = *DevicePath;
194 if (IS_NULL (*Str)) {
195 return NULL;
196 }
197
198 //
199 // Skip the leading '/', '(', ')' and ','
200 //
201 while (!IS_NULL (*Str)) {
202 if (!IS_SLASH (*Str) &&
203 !IS_COMMA (*Str) &&
204 !IS_LEFT_PARENTH (*Str) &&
205 !IS_RIGHT_PARENTH (*Str)) {
206 break;
207 }
208 Str++;
209 }
210
211 ReturnStr = Str;
212
213 //
214 // Scan for the separator of this device node, '/' or ','
215 //
216 ParenthesesStack = 0;
217 while (!IS_NULL (*Str)) {
218 if ((IS_COMMA (*Str) || IS_SLASH (*Str)) && (ParenthesesStack == 0)) {
219 break;
220 }
221
222 if (IS_LEFT_PARENTH (*Str)) {
223 ParenthesesStack++;
224 } else if (IS_RIGHT_PARENTH (*Str)) {
225 ParenthesesStack--;
226 }
227
228 Str++;
229 }
230
231 if (ParenthesesStack != 0) {
232 //
233 // The '(' doesn't pair with ')', invalid device path text
234 //
235 return NULL;
236 }
237
238 if (IS_COMMA (*Str)) {
239 *IsInstanceEnd = TRUE;
240 *Str = L'\0';
241 Str++;
242 } else {
243 *IsInstanceEnd = FALSE;
244 if (!IS_NULL (*Str)) {
245 *Str = L'\0';
246 Str++;
247 }
248 }
249
250 *DevicePath = Str;
251
252 return ReturnStr;
253 }
254
255
256 /**
257 Return whether the integer string is a hex string.
258
259 @param Str The integer string
260
261 @retval TRUE Hex string
262 @retval FALSE Decimal string
263
264 **/
265 BOOLEAN
266 IsHexStr (
267 IN CHAR16 *Str
268 )
269 {
270 //
271 // skip preceeding white space
272 //
273 while ((*Str != 0) && *Str == L' ') {
274 Str ++;
275 }
276 //
277 // skip preceeding zeros
278 //
279 while ((*Str != 0) && *Str == L'0') {
280 Str ++;
281 }
282
283 return (BOOLEAN) (*Str == L'x' || *Str == L'X');
284 }
285
286 /**
287
288 Convert integer string to uint.
289
290 @param Str The integer string. If leading with "0x" or "0X", it's hexadecimal.
291
292 @return A UINTN value represented by Str
293
294 **/
295 UINTN
296 Strtoi (
297 IN CHAR16 *Str
298 )
299 {
300 if (IsHexStr (Str)) {
301 return StrHexToUintn (Str);
302 } else {
303 return StrDecimalToUintn (Str);
304 }
305 }
306
307 /**
308
309 Convert integer string to 64 bit data.
310
311 @param Str The integer string. If leading with "0x" or "0X", it's hexadecimal.
312 @param Data A pointer to the UINT64 value represented by Str
313
314 **/
315 VOID
316 Strtoi64 (
317 IN CHAR16 *Str,
318 OUT UINT64 *Data
319 )
320 {
321 if (IsHexStr (Str)) {
322 *Data = StrHexToUint64 (Str);
323 } else {
324 *Data = StrDecimalToUint64 (Str);
325 }
326 }
327
328 /**
329 Converts a list of string to a specified buffer.
330
331 @param Buf The output buffer that contains the string.
332 @param BufferLength The length of the buffer
333 @param Str The input string that contains the hex number
334
335 @retval EFI_SUCCESS The string was successfully converted to the buffer.
336
337 **/
338 EFI_STATUS
339 StrToBuf (
340 OUT UINT8 *Buf,
341 IN UINTN BufferLength,
342 IN CHAR16 *Str
343 )
344 {
345 UINTN Index;
346 UINTN StrLength;
347 UINT8 Digit;
348 UINT8 Byte;
349
350 Digit = 0;
351
352 //
353 // Two hex char make up one byte
354 //
355 StrLength = BufferLength * sizeof (CHAR16);
356
357 for(Index = 0; Index < StrLength; Index++, Str++) {
358
359 if ((*Str >= L'a') && (*Str <= L'f')) {
360 Digit = (UINT8) (*Str - L'a' + 0x0A);
361 } else if ((*Str >= L'A') && (*Str <= L'F')) {
362 Digit = (UINT8) (*Str - L'A' + 0x0A);
363 } else if ((*Str >= L'0') && (*Str <= L'9')) {
364 Digit = (UINT8) (*Str - L'0');
365 } else {
366 return EFI_INVALID_PARAMETER;
367 }
368
369 //
370 // For odd characters, write the upper nibble for each buffer byte,
371 // and for even characters, the lower nibble.
372 //
373 if ((Index & 1) == 0) {
374 Byte = (UINT8) (Digit << 4);
375 } else {
376 Byte = Buf[Index / 2];
377 Byte &= 0xF0;
378 Byte = (UINT8) (Byte | Digit);
379 }
380
381 Buf[Index / 2] = Byte;
382 }
383
384 return EFI_SUCCESS;
385 }
386
387 /**
388 Converts a string to GUID value.
389 Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
390
391 @param Str The registry format GUID string that contains the GUID value.
392 @param Guid A pointer to the converted GUID value.
393
394 @retval EFI_SUCCESS The GUID string was successfully converted to the GUID value.
395 @retval EFI_UNSUPPORTED The input string is not in registry format.
396 @return others Some error occurred when converting part of GUID value.
397
398 **/
399 EFI_STATUS
400 StrToGuid (
401 IN CHAR16 *Str,
402 OUT EFI_GUID *Guid
403 )
404 {
405 //
406 // Get the first UINT32 data
407 //
408 Guid->Data1 = (UINT32) StrHexToUint64 (Str);
409 while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {
410 Str ++;
411 }
412
413 if (IS_HYPHEN (*Str)) {
414 Str++;
415 } else {
416 return EFI_UNSUPPORTED;
417 }
418
419 //
420 // Get the second UINT16 data
421 //
422 Guid->Data2 = (UINT16) StrHexToUint64 (Str);
423 while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {
424 Str ++;
425 }
426
427 if (IS_HYPHEN (*Str)) {
428 Str++;
429 } else {
430 return EFI_UNSUPPORTED;
431 }
432
433 //
434 // Get the third UINT16 data
435 //
436 Guid->Data3 = (UINT16) StrHexToUint64 (Str);
437 while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {
438 Str ++;
439 }
440
441 if (IS_HYPHEN (*Str)) {
442 Str++;
443 } else {
444 return EFI_UNSUPPORTED;
445 }
446
447 //
448 // Get the following 8 bytes data
449 //
450 StrToBuf (&Guid->Data4[0], 2, Str);
451 //
452 // Skip 2 byte hex chars
453 //
454 Str += 2 * 2;
455
456 if (IS_HYPHEN (*Str)) {
457 Str++;
458 } else {
459 return EFI_UNSUPPORTED;
460 }
461 StrToBuf (&Guid->Data4[2], 6, Str);
462
463 return EFI_SUCCESS;
464 }
465
466 /**
467 Converts a string to IPv4 address
468
469 @param Str A string representation of IPv4 address.
470 @param IPv4Addr A pointer to the converted IPv4 address.
471
472 **/
473 VOID
474 StrToIPv4Addr (
475 IN OUT CHAR16 **Str,
476 OUT EFI_IPv4_ADDRESS *IPv4Addr
477 )
478 {
479 UINTN Index;
480
481 for (Index = 0; Index < 4; Index++) {
482 IPv4Addr->Addr[Index] = (UINT8) StrDecimalToUintn (SplitStr (Str, L'.'));
483 }
484 }
485
486 /**
487 Converts a string to IPv4 address
488
489 @param Str A string representation of IPv6 address.
490 @param IPv6Addr A pointer to the converted IPv6 address.
491
492 **/
493 VOID
494 StrToIPv6Addr (
495 IN OUT CHAR16 **Str,
496 OUT EFI_IPv6_ADDRESS *IPv6Addr
497 )
498 {
499 UINTN Index;
500 UINT16 Data;
501
502 for (Index = 0; Index < 8; Index++) {
503 Data = (UINT16) StrHexToUintn (SplitStr (Str, L':'));
504 IPv6Addr->Addr[Index * 2] = (UINT8) (Data >> 8);
505 IPv6Addr->Addr[Index * 2 + 1] = (UINT8) (Data & 0xff);
506 }
507 }
508
509 /**
510 Converts a Unicode string to ASCII string.
511
512 @param Str The equivalent Unicode string
513 @param AsciiStr On input, it points to destination ASCII string buffer; on output, it points
514 to the next ASCII string next to it
515
516 **/
517 VOID
518 StrToAscii (
519 IN CHAR16 *Str,
520 IN OUT CHAR8 **AsciiStr
521 )
522 {
523 CHAR8 *Dest;
524
525 Dest = *AsciiStr;
526 while (!IS_NULL (*Str)) {
527 *(Dest++) = (CHAR8) *(Str++);
528 }
529 *Dest = 0;
530
531 //
532 // Return the string next to it
533 //
534 *AsciiStr = Dest + 1;
535 }
536
537 /**
538 Converts a text device path node to Hardware PCI device path structure.
539
540 @param TextDeviceNode The input Text device path node.
541
542 @return A pointer to Hardware PCI device path structure.
543
544 **/
545 EFI_DEVICE_PATH_PROTOCOL *
546 DevPathFromTextPci (
547 IN CHAR16 *TextDeviceNode
548 )
549 {
550 CHAR16 *FunctionStr;
551 CHAR16 *DeviceStr;
552 PCI_DEVICE_PATH *Pci;
553
554 DeviceStr = GetNextParamStr (&TextDeviceNode);
555 FunctionStr = GetNextParamStr (&TextDeviceNode);
556 Pci = (PCI_DEVICE_PATH *) CreateDeviceNode (
557 HARDWARE_DEVICE_PATH,
558 HW_PCI_DP,
559 (UINT16) sizeof (PCI_DEVICE_PATH)
560 );
561
562 Pci->Function = (UINT8) Strtoi (FunctionStr);
563 Pci->Device = (UINT8) Strtoi (DeviceStr);
564
565 return (EFI_DEVICE_PATH_PROTOCOL *) Pci;
566 }
567
568 /**
569 Converts a text device path node to Hardware PC card device path structure.
570
571 @param TextDeviceNode The input Text device path node.
572
573 @return A pointer to Hardware PC card device path structure.
574
575 **/
576 EFI_DEVICE_PATH_PROTOCOL *
577 DevPathFromTextPcCard (
578 IN CHAR16 *TextDeviceNode
579 )
580 {
581 CHAR16 *FunctionNumberStr;
582 PCCARD_DEVICE_PATH *Pccard;
583
584 FunctionNumberStr = GetNextParamStr (&TextDeviceNode);
585 Pccard = (PCCARD_DEVICE_PATH *) CreateDeviceNode (
586 HARDWARE_DEVICE_PATH,
587 HW_PCCARD_DP,
588 (UINT16) sizeof (PCCARD_DEVICE_PATH)
589 );
590
591 Pccard->FunctionNumber = (UINT8) Strtoi (FunctionNumberStr);
592
593 return (EFI_DEVICE_PATH_PROTOCOL *) Pccard;
594 }
595
596 /**
597 Converts a text device path node to Hardware memory map device path structure.
598
599 @param TextDeviceNode The input Text device path node.
600
601 @return A pointer to Hardware memory map device path structure.
602
603 **/
604 EFI_DEVICE_PATH_PROTOCOL *
605 DevPathFromTextMemoryMapped (
606 IN CHAR16 *TextDeviceNode
607 )
608 {
609 CHAR16 *MemoryTypeStr;
610 CHAR16 *StartingAddressStr;
611 CHAR16 *EndingAddressStr;
612 MEMMAP_DEVICE_PATH *MemMap;
613
614 MemoryTypeStr = GetNextParamStr (&TextDeviceNode);
615 StartingAddressStr = GetNextParamStr (&TextDeviceNode);
616 EndingAddressStr = GetNextParamStr (&TextDeviceNode);
617 MemMap = (MEMMAP_DEVICE_PATH *) CreateDeviceNode (
618 HARDWARE_DEVICE_PATH,
619 HW_MEMMAP_DP,
620 (UINT16) sizeof (MEMMAP_DEVICE_PATH)
621 );
622
623 MemMap->MemoryType = (UINT32) Strtoi (MemoryTypeStr);
624 Strtoi64 (StartingAddressStr, &MemMap->StartingAddress);
625 Strtoi64 (EndingAddressStr, &MemMap->EndingAddress);
626
627 return (EFI_DEVICE_PATH_PROTOCOL *) MemMap;
628 }
629
630 /**
631 Converts a text device path node to Vendor device path structure based on the input Type
632 and SubType.
633
634 @param TextDeviceNode The input Text device path node.
635 @param Type The type of device path node.
636 @param SubType The subtype of device path node.
637
638 @return A pointer to the newly-created Vendor device path structure.
639
640 **/
641 EFI_DEVICE_PATH_PROTOCOL *
642 ConvertFromTextVendor (
643 IN CHAR16 *TextDeviceNode,
644 IN UINT8 Type,
645 IN UINT8 SubType
646 )
647 {
648 CHAR16 *GuidStr;
649 CHAR16 *DataStr;
650 UINTN Length;
651 VENDOR_DEVICE_PATH *Vendor;
652
653 GuidStr = GetNextParamStr (&TextDeviceNode);
654
655 DataStr = GetNextParamStr (&TextDeviceNode);
656 Length = StrLen (DataStr);
657 //
658 // Two hex characters make up 1 buffer byte
659 //
660 Length = (Length + 1) / 2;
661
662 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
663 Type,
664 SubType,
665 (UINT16) (sizeof (VENDOR_DEVICE_PATH) + Length)
666 );
667
668 StrToGuid (GuidStr, &Vendor->Guid);
669 StrToBuf (((UINT8 *) Vendor) + sizeof (VENDOR_DEVICE_PATH), Length, DataStr);
670
671 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
672 }
673
674 /**
675 Converts a text device path node to Vendor Hardware device path structure.
676
677 @param TextDeviceNode The input Text device path node.
678
679 @return A pointer to the newly-created Vendor Hardware device path structure.
680
681 **/
682 EFI_DEVICE_PATH_PROTOCOL *
683 DevPathFromTextVenHw (
684 IN CHAR16 *TextDeviceNode
685 )
686 {
687 return ConvertFromTextVendor (
688 TextDeviceNode,
689 HARDWARE_DEVICE_PATH,
690 HW_VENDOR_DP
691 );
692 }
693
694 /**
695 Converts a text device path node to Hardware Controller device path structure.
696
697 @param TextDeviceNode The input Text device path node.
698
699 @return A pointer to the newly-created Hardware Controller device path structure.
700
701 **/
702 EFI_DEVICE_PATH_PROTOCOL *
703 DevPathFromTextCtrl (
704 IN CHAR16 *TextDeviceNode
705 )
706 {
707 CHAR16 *ControllerStr;
708 CONTROLLER_DEVICE_PATH *Controller;
709
710 ControllerStr = GetNextParamStr (&TextDeviceNode);
711 Controller = (CONTROLLER_DEVICE_PATH *) CreateDeviceNode (
712 HARDWARE_DEVICE_PATH,
713 HW_CONTROLLER_DP,
714 (UINT16) sizeof (CONTROLLER_DEVICE_PATH)
715 );
716 Controller->ControllerNumber = (UINT32) Strtoi (ControllerStr);
717
718 return (EFI_DEVICE_PATH_PROTOCOL *) Controller;
719 }
720
721 /**
722 Converts a string to EisaId.
723
724 @param Text The input string.
725
726 @return UINT32 EISA ID.
727 **/
728 UINT32
729 EisaIdFromText (
730 IN CHAR16 *Text
731 )
732 {
733 return (((Text[0] - 'A' + 1) & 0x1f) << 10)
734 + (((Text[1] - 'A' + 1) & 0x1f) << 5)
735 + (((Text[2] - 'A' + 1) & 0x1f) << 0)
736 + (UINT32) (StrHexToUintn (&Text[3]) << 16)
737 ;
738 }
739
740 /**
741 Converts a text device path node to ACPI HID device path structure.
742
743 @param TextDeviceNode The input Text device path node.
744
745 @return A pointer to the newly-created ACPI HID device path structure.
746
747 **/
748 EFI_DEVICE_PATH_PROTOCOL *
749 DevPathFromTextAcpi (
750 IN CHAR16 *TextDeviceNode
751 )
752 {
753 CHAR16 *HIDStr;
754 CHAR16 *UIDStr;
755 ACPI_HID_DEVICE_PATH *Acpi;
756
757 HIDStr = GetNextParamStr (&TextDeviceNode);
758 UIDStr = GetNextParamStr (&TextDeviceNode);
759 Acpi = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
760 ACPI_DEVICE_PATH,
761 ACPI_DP,
762 (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
763 );
764
765 Acpi->HID = EisaIdFromText (HIDStr);
766 Acpi->UID = (UINT32) Strtoi (UIDStr);
767
768 return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
769 }
770
771 /**
772 Converts a text device path node to ACPI HID device path structure.
773
774 @param TextDeviceNode The input Text device path node.
775 @param PnPId The input plug and play identification.
776
777 @return A pointer to the newly-created ACPI HID device path structure.
778
779 **/
780 EFI_DEVICE_PATH_PROTOCOL *
781 ConvertFromTextAcpi (
782 IN CHAR16 *TextDeviceNode,
783 IN UINT32 PnPId
784 )
785 {
786 CHAR16 *UIDStr;
787 ACPI_HID_DEVICE_PATH *Acpi;
788
789 UIDStr = GetNextParamStr (&TextDeviceNode);
790 Acpi = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
791 ACPI_DEVICE_PATH,
792 ACPI_DP,
793 (UINT16) sizeof (ACPI_HID_DEVICE_PATH)
794 );
795
796 Acpi->HID = EFI_PNP_ID (PnPId);
797 Acpi->UID = (UINT32) Strtoi (UIDStr);
798
799 return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
800 }
801
802 /**
803 Converts a text device path node to PCI root device path structure.
804
805 @param TextDeviceNode The input Text device path node.
806
807 @return A pointer to the newly-created PCI root device path structure.
808
809 **/
810 EFI_DEVICE_PATH_PROTOCOL *
811 DevPathFromTextPciRoot (
812 IN CHAR16 *TextDeviceNode
813 )
814 {
815 return ConvertFromTextAcpi (TextDeviceNode, 0x0a03);
816 }
817
818 /**
819 Converts a text device path node to PCIE root device path structure.
820
821 @param TextDeviceNode The input Text device path node.
822
823 @return A pointer to the newly-created PCIE root device path structure.
824
825 **/
826 EFI_DEVICE_PATH_PROTOCOL *
827 DevPathFromTextPcieRoot (
828 IN CHAR16 *TextDeviceNode
829 )
830 {
831 return ConvertFromTextAcpi (TextDeviceNode, 0x0a08);
832 }
833
834 /**
835 Converts a text device path node to Floppy device path structure.
836
837 @param TextDeviceNode The input Text device path node.
838
839 @return A pointer to the newly-created Floppy device path structure.
840
841 **/
842 EFI_DEVICE_PATH_PROTOCOL *
843 DevPathFromTextFloppy (
844 IN CHAR16 *TextDeviceNode
845 )
846 {
847 return ConvertFromTextAcpi (TextDeviceNode, 0x0604);
848 }
849
850 /**
851 Converts a text device path node to Keyboard device path structure.
852
853 @param TextDeviceNode The input Text device path node.
854
855 @return A pointer to the newly-created Keyboard device path structure.
856
857 **/
858 EFI_DEVICE_PATH_PROTOCOL *
859 DevPathFromTextKeyboard (
860 IN CHAR16 *TextDeviceNode
861 )
862 {
863 return ConvertFromTextAcpi (TextDeviceNode, 0x0301);
864 }
865
866 /**
867 Converts a text device path node to Serial device path structure.
868
869 @param TextDeviceNode The input Text device path node.
870
871 @return A pointer to the newly-created Serial device path structure.
872
873 **/
874 EFI_DEVICE_PATH_PROTOCOL *
875 DevPathFromTextSerial (
876 IN CHAR16 *TextDeviceNode
877 )
878 {
879 return ConvertFromTextAcpi (TextDeviceNode, 0x0501);
880 }
881
882 /**
883 Converts a text device path node to Parallel Port device path structure.
884
885 @param TextDeviceNode The input Text device path node.
886
887 @return A pointer to the newly-created Parallel Port device path structure.
888
889 **/
890 EFI_DEVICE_PATH_PROTOCOL *
891 DevPathFromTextParallelPort (
892 IN CHAR16 *TextDeviceNode
893 )
894 {
895 return ConvertFromTextAcpi (TextDeviceNode, 0x0401);
896 }
897
898 /**
899 Converts a text device path node to ACPI extension device path structure.
900
901 @param TextDeviceNode The input Text device path node.
902
903 @return A pointer to the newly-created ACPI extension device path structure.
904
905 **/
906 EFI_DEVICE_PATH_PROTOCOL *
907 DevPathFromTextAcpiEx (
908 IN CHAR16 *TextDeviceNode
909 )
910 {
911 CHAR16 *HIDStr;
912 CHAR16 *CIDStr;
913 CHAR16 *UIDStr;
914 CHAR16 *HIDSTRStr;
915 CHAR16 *CIDSTRStr;
916 CHAR16 *UIDSTRStr;
917 CHAR8 *AsciiStr;
918 UINT16 Length;
919 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
920
921 HIDStr = GetNextParamStr (&TextDeviceNode);
922 CIDStr = GetNextParamStr (&TextDeviceNode);
923 UIDStr = GetNextParamStr (&TextDeviceNode);
924 HIDSTRStr = GetNextParamStr (&TextDeviceNode);
925 CIDSTRStr = GetNextParamStr (&TextDeviceNode);
926 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
927
928 Length = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (HIDSTRStr) + 1);
929 Length = (UINT16) (Length + StrLen (UIDSTRStr) + 1);
930 Length = (UINT16) (Length + StrLen (CIDSTRStr) + 1);
931 AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
932 ACPI_DEVICE_PATH,
933 ACPI_EXTENDED_DP,
934 Length
935 );
936
937 AcpiEx->HID = EisaIdFromText (HIDStr);
938 AcpiEx->CID = EisaIdFromText (CIDStr);
939 AcpiEx->UID = (UINT32) Strtoi (UIDStr);
940
941 AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
942 StrToAscii (HIDSTRStr, &AsciiStr);
943 StrToAscii (UIDSTRStr, &AsciiStr);
944 StrToAscii (CIDSTRStr, &AsciiStr);
945
946 return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
947 }
948
949 /**
950 Converts a text device path node to ACPI extension device path structure.
951
952 @param TextDeviceNode The input Text device path node.
953
954 @return A pointer to the newly-created ACPI extension device path structure.
955
956 **/
957 EFI_DEVICE_PATH_PROTOCOL *
958 DevPathFromTextAcpiExp (
959 IN CHAR16 *TextDeviceNode
960 )
961 {
962 CHAR16 *HIDStr;
963 CHAR16 *CIDStr;
964 CHAR16 *UIDSTRStr;
965 CHAR8 *AsciiStr;
966 UINT16 Length;
967 ACPI_EXTENDED_HID_DEVICE_PATH *AcpiEx;
968
969 HIDStr = GetNextParamStr (&TextDeviceNode);
970 CIDStr = GetNextParamStr (&TextDeviceNode);
971 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
972 Length = (UINT16) (sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + StrLen (UIDSTRStr) + 3);
973 AcpiEx = (ACPI_EXTENDED_HID_DEVICE_PATH *) CreateDeviceNode (
974 ACPI_DEVICE_PATH,
975 ACPI_EXTENDED_DP,
976 Length
977 );
978
979 AcpiEx->HID = EisaIdFromText (HIDStr);
980 AcpiEx->CID = EisaIdFromText (CIDStr);
981 AcpiEx->UID = 0;
982
983 AsciiStr = (CHAR8 *) ((UINT8 *)AcpiEx + sizeof (ACPI_EXTENDED_HID_DEVICE_PATH));
984 //
985 // HID string is NULL
986 //
987 *AsciiStr = '\0';
988 //
989 // Convert UID string
990 //
991 AsciiStr++;
992 StrToAscii (UIDSTRStr, &AsciiStr);
993 //
994 // CID string is NULL
995 //
996 *AsciiStr = '\0';
997
998 return (EFI_DEVICE_PATH_PROTOCOL *) AcpiEx;
999 }
1000
1001 /**
1002 Converts a text device path node to ACPI _ADR device path structure.
1003
1004 @param TextDeviceNode The input Text device path node.
1005
1006 @return A pointer to the newly-created ACPI _ADR device path structure.
1007
1008 **/
1009 EFI_DEVICE_PATH_PROTOCOL *
1010 DevPathFromTextAcpiAdr (
1011 IN CHAR16 *TextDeviceNode
1012 )
1013 {
1014 CHAR16 *DisplayDeviceStr;
1015 ACPI_ADR_DEVICE_PATH *AcpiAdr;
1016 UINTN Index;
1017 UINTN Length;
1018
1019 AcpiAdr = (ACPI_ADR_DEVICE_PATH *) CreateDeviceNode (
1020 ACPI_DEVICE_PATH,
1021 ACPI_ADR_DP,
1022 (UINT16) sizeof (ACPI_ADR_DEVICE_PATH)
1023 );
1024 ASSERT (AcpiAdr != NULL);
1025
1026 for (Index = 0; ; Index++) {
1027 DisplayDeviceStr = GetNextParamStr (&TextDeviceNode);
1028 if (IS_NULL (*DisplayDeviceStr)) {
1029 break;
1030 }
1031 if (Index > 0) {
1032 Length = DevicePathNodeLength (AcpiAdr);
1033 AcpiAdr = ReallocatePool (
1034 Length,
1035 Length + sizeof (UINT32),
1036 AcpiAdr
1037 );
1038 ASSERT (AcpiAdr != NULL);
1039 SetDevicePathNodeLength (AcpiAdr, Length + sizeof (UINT32));
1040 }
1041
1042 (&AcpiAdr->ADR)[Index] = (UINT32) Strtoi (DisplayDeviceStr);
1043 }
1044
1045 return (EFI_DEVICE_PATH_PROTOCOL *) AcpiAdr;
1046 }
1047
1048 /**
1049 Converts a text device path node to Parallel Port device path structure.
1050
1051 @param TextDeviceNode The input Text device path node.
1052
1053 @return A pointer to the newly-created Parallel Port device path structure.
1054
1055 **/
1056 EFI_DEVICE_PATH_PROTOCOL *
1057 DevPathFromTextAta (
1058 IN CHAR16 *TextDeviceNode
1059 )
1060 {
1061 CHAR16 *PrimarySecondaryStr;
1062 CHAR16 *SlaveMasterStr;
1063 CHAR16 *LunStr;
1064 ATAPI_DEVICE_PATH *Atapi;
1065
1066 Atapi = (ATAPI_DEVICE_PATH *) CreateDeviceNode (
1067 MESSAGING_DEVICE_PATH,
1068 MSG_ATAPI_DP,
1069 (UINT16) sizeof (ATAPI_DEVICE_PATH)
1070 );
1071
1072 PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
1073 SlaveMasterStr = GetNextParamStr (&TextDeviceNode);
1074 LunStr = GetNextParamStr (&TextDeviceNode);
1075
1076 Atapi->PrimarySecondary = (UINT8) ((StrCmp (PrimarySecondaryStr, L"Primary") == 0) ? 0 : 1);
1077 Atapi->SlaveMaster = (UINT8) ((StrCmp (SlaveMasterStr, L"Master") == 0) ? 0 : 1);
1078 Atapi->Lun = (UINT16) Strtoi (LunStr);
1079
1080 return (EFI_DEVICE_PATH_PROTOCOL *) Atapi;
1081 }
1082
1083 /**
1084 Converts a text device path node to SCSI device path structure.
1085
1086 @param TextDeviceNode The input Text device path node.
1087
1088 @return A pointer to the newly-created SCSI device path structure.
1089
1090 **/
1091 EFI_DEVICE_PATH_PROTOCOL *
1092 DevPathFromTextScsi (
1093 IN CHAR16 *TextDeviceNode
1094 )
1095 {
1096 CHAR16 *PunStr;
1097 CHAR16 *LunStr;
1098 SCSI_DEVICE_PATH *Scsi;
1099
1100 PunStr = GetNextParamStr (&TextDeviceNode);
1101 LunStr = GetNextParamStr (&TextDeviceNode);
1102 Scsi = (SCSI_DEVICE_PATH *) CreateDeviceNode (
1103 MESSAGING_DEVICE_PATH,
1104 MSG_SCSI_DP,
1105 (UINT16) sizeof (SCSI_DEVICE_PATH)
1106 );
1107
1108 Scsi->Pun = (UINT16) Strtoi (PunStr);
1109 Scsi->Lun = (UINT16) Strtoi (LunStr);
1110
1111 return (EFI_DEVICE_PATH_PROTOCOL *) Scsi;
1112 }
1113
1114 /**
1115 Converts a text device path node to Fibre device path structure.
1116
1117 @param TextDeviceNode The input Text device path node.
1118
1119 @return A pointer to the newly-created Fibre device path structure.
1120
1121 **/
1122 EFI_DEVICE_PATH_PROTOCOL *
1123 DevPathFromTextFibre (
1124 IN CHAR16 *TextDeviceNode
1125 )
1126 {
1127 CHAR16 *WWNStr;
1128 CHAR16 *LunStr;
1129 FIBRECHANNEL_DEVICE_PATH *Fibre;
1130
1131 WWNStr = GetNextParamStr (&TextDeviceNode);
1132 LunStr = GetNextParamStr (&TextDeviceNode);
1133 Fibre = (FIBRECHANNEL_DEVICE_PATH *) CreateDeviceNode (
1134 MESSAGING_DEVICE_PATH,
1135 MSG_FIBRECHANNEL_DP,
1136 (UINT16) sizeof (FIBRECHANNEL_DEVICE_PATH)
1137 );
1138
1139 Fibre->Reserved = 0;
1140 Strtoi64 (WWNStr, &Fibre->WWN);
1141 Strtoi64 (LunStr, &Fibre->Lun);
1142
1143 return (EFI_DEVICE_PATH_PROTOCOL *) Fibre;
1144 }
1145
1146 /**
1147 Converts a text device path node to FibreEx device path structure.
1148
1149 @param TextDeviceNode The input Text device path node.
1150
1151 @return A pointer to the newly-created FibreEx device path structure.
1152
1153 **/
1154 EFI_DEVICE_PATH_PROTOCOL *
1155 DevPathFromTextFibreEx (
1156 IN CHAR16 *TextDeviceNode
1157 )
1158 {
1159 CHAR16 *WWNStr;
1160 CHAR16 *LunStr;
1161 FIBRECHANNELEX_DEVICE_PATH *FibreEx;
1162
1163 WWNStr = GetNextParamStr (&TextDeviceNode);
1164 LunStr = GetNextParamStr (&TextDeviceNode);
1165 FibreEx = (FIBRECHANNELEX_DEVICE_PATH *) CreateDeviceNode (
1166 MESSAGING_DEVICE_PATH,
1167 MSG_FIBRECHANNELEX_DP,
1168 (UINT16) sizeof (FIBRECHANNELEX_DEVICE_PATH)
1169 );
1170
1171 FibreEx->Reserved = 0;
1172 Strtoi64 (WWNStr, (UINT64 *) (&FibreEx->WWN));
1173 Strtoi64 (LunStr, (UINT64 *) (&FibreEx->Lun));
1174
1175 *(UINT64 *) (&FibreEx->WWN) = SwapBytes64 (*(UINT64 *) (&FibreEx->WWN));
1176 *(UINT64 *) (&FibreEx->Lun) = SwapBytes64 (*(UINT64 *) (&FibreEx->Lun));
1177
1178 return (EFI_DEVICE_PATH_PROTOCOL *) FibreEx;
1179 }
1180
1181 /**
1182 Converts a text device path node to 1394 device path structure.
1183
1184 @param TextDeviceNode The input Text device path node.
1185
1186 @return A pointer to the newly-created 1394 device path structure.
1187
1188 **/
1189 EFI_DEVICE_PATH_PROTOCOL *
1190 DevPathFromText1394 (
1191 IN CHAR16 *TextDeviceNode
1192 )
1193 {
1194 CHAR16 *GuidStr;
1195 F1394_DEVICE_PATH *F1394DevPath;
1196
1197 GuidStr = GetNextParamStr (&TextDeviceNode);
1198 F1394DevPath = (F1394_DEVICE_PATH *) CreateDeviceNode (
1199 MESSAGING_DEVICE_PATH,
1200 MSG_1394_DP,
1201 (UINT16) sizeof (F1394_DEVICE_PATH)
1202 );
1203
1204 F1394DevPath->Reserved = 0;
1205 F1394DevPath->Guid = StrHexToUint64 (GuidStr);
1206
1207 return (EFI_DEVICE_PATH_PROTOCOL *) F1394DevPath;
1208 }
1209
1210 /**
1211 Converts a text device path node to USB device path structure.
1212
1213 @param TextDeviceNode The input Text device path node.
1214
1215 @return A pointer to the newly-created USB device path structure.
1216
1217 **/
1218 EFI_DEVICE_PATH_PROTOCOL *
1219 DevPathFromTextUsb (
1220 IN CHAR16 *TextDeviceNode
1221 )
1222 {
1223 CHAR16 *PortStr;
1224 CHAR16 *InterfaceStr;
1225 USB_DEVICE_PATH *Usb;
1226
1227 PortStr = GetNextParamStr (&TextDeviceNode);
1228 InterfaceStr = GetNextParamStr (&TextDeviceNode);
1229 Usb = (USB_DEVICE_PATH *) CreateDeviceNode (
1230 MESSAGING_DEVICE_PATH,
1231 MSG_USB_DP,
1232 (UINT16) sizeof (USB_DEVICE_PATH)
1233 );
1234
1235 Usb->ParentPortNumber = (UINT8) Strtoi (PortStr);
1236 Usb->InterfaceNumber = (UINT8) Strtoi (InterfaceStr);
1237
1238 return (EFI_DEVICE_PATH_PROTOCOL *) Usb;
1239 }
1240
1241 /**
1242 Converts a text device path node to I20 device path structure.
1243
1244 @param TextDeviceNode The input Text device path node.
1245
1246 @return A pointer to the newly-created I20 device path structure.
1247
1248 **/
1249 EFI_DEVICE_PATH_PROTOCOL *
1250 DevPathFromTextI2O (
1251 IN CHAR16 *TextDeviceNode
1252 )
1253 {
1254 CHAR16 *TIDStr;
1255 I2O_DEVICE_PATH *I2ODevPath;
1256
1257 TIDStr = GetNextParamStr (&TextDeviceNode);
1258 I2ODevPath = (I2O_DEVICE_PATH *) CreateDeviceNode (
1259 MESSAGING_DEVICE_PATH,
1260 MSG_I2O_DP,
1261 (UINT16) sizeof (I2O_DEVICE_PATH)
1262 );
1263
1264 I2ODevPath->Tid = (UINT32) Strtoi (TIDStr);
1265
1266 return (EFI_DEVICE_PATH_PROTOCOL *) I2ODevPath;
1267 }
1268
1269 /**
1270 Converts a text device path node to Infini Band device path structure.
1271
1272 @param TextDeviceNode The input Text device path node.
1273
1274 @return A pointer to the newly-created Infini Band device path structure.
1275
1276 **/
1277 EFI_DEVICE_PATH_PROTOCOL *
1278 DevPathFromTextInfiniband (
1279 IN CHAR16 *TextDeviceNode
1280 )
1281 {
1282 CHAR16 *FlagsStr;
1283 CHAR16 *GuidStr;
1284 CHAR16 *SidStr;
1285 CHAR16 *TidStr;
1286 CHAR16 *DidStr;
1287 EFI_GUID PortGid;
1288 INFINIBAND_DEVICE_PATH *InfiniBand;
1289
1290 FlagsStr = GetNextParamStr (&TextDeviceNode);
1291 GuidStr = GetNextParamStr (&TextDeviceNode);
1292 SidStr = GetNextParamStr (&TextDeviceNode);
1293 TidStr = GetNextParamStr (&TextDeviceNode);
1294 DidStr = GetNextParamStr (&TextDeviceNode);
1295 InfiniBand = (INFINIBAND_DEVICE_PATH *) CreateDeviceNode (
1296 MESSAGING_DEVICE_PATH,
1297 MSG_INFINIBAND_DP,
1298 (UINT16) sizeof (INFINIBAND_DEVICE_PATH)
1299 );
1300
1301 InfiniBand->ResourceFlags = (UINT32) Strtoi (FlagsStr);
1302 StrToGuid (GuidStr, &PortGid);
1303 CopyMem (InfiniBand->PortGid, &PortGid, sizeof (EFI_GUID));
1304 Strtoi64 (SidStr, &InfiniBand->ServiceId);
1305 Strtoi64 (TidStr, &InfiniBand->TargetPortId);
1306 Strtoi64 (DidStr, &InfiniBand->DeviceId);
1307
1308 return (EFI_DEVICE_PATH_PROTOCOL *) InfiniBand;
1309 }
1310
1311 /**
1312 Converts a text device path node to Vendor-Defined Messaging device path structure.
1313
1314 @param TextDeviceNode The input Text device path node.
1315
1316 @return A pointer to the newly-created Vendor-Defined Messaging device path structure.
1317
1318 **/
1319 EFI_DEVICE_PATH_PROTOCOL *
1320 DevPathFromTextVenMsg (
1321 IN CHAR16 *TextDeviceNode
1322 )
1323 {
1324 return ConvertFromTextVendor (
1325 TextDeviceNode,
1326 MESSAGING_DEVICE_PATH,
1327 MSG_VENDOR_DP
1328 );
1329 }
1330
1331 /**
1332 Converts a text device path node to Vendor defined PC-ANSI device path structure.
1333
1334 @param TextDeviceNode The input Text device path node.
1335
1336 @return A pointer to the newly-created Vendor defined PC-ANSI device path structure.
1337
1338 **/
1339 EFI_DEVICE_PATH_PROTOCOL *
1340 DevPathFromTextVenPcAnsi (
1341 IN CHAR16 *TextDeviceNode
1342 )
1343 {
1344 VENDOR_DEVICE_PATH *Vendor;
1345
1346 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1347 MESSAGING_DEVICE_PATH,
1348 MSG_VENDOR_DP,
1349 (UINT16) sizeof (VENDOR_DEVICE_PATH));
1350 CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
1351
1352 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1353 }
1354
1355 /**
1356 Converts a text device path node to Vendor defined VT100 device path structure.
1357
1358 @param TextDeviceNode The input Text device path node.
1359
1360 @return A pointer to the newly-created Vendor defined VT100 device path structure.
1361
1362 **/
1363 EFI_DEVICE_PATH_PROTOCOL *
1364 DevPathFromTextVenVt100 (
1365 IN CHAR16 *TextDeviceNode
1366 )
1367 {
1368 VENDOR_DEVICE_PATH *Vendor;
1369
1370 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1371 MESSAGING_DEVICE_PATH,
1372 MSG_VENDOR_DP,
1373 (UINT16) sizeof (VENDOR_DEVICE_PATH));
1374 CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
1375
1376 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1377 }
1378
1379 /**
1380 Converts a text device path node to Vendor defined VT100 Plus device path structure.
1381
1382 @param TextDeviceNode The input Text device path node.
1383
1384 @return A pointer to the newly-created Vendor defined VT100 Plus device path structure.
1385
1386 **/
1387 EFI_DEVICE_PATH_PROTOCOL *
1388 DevPathFromTextVenVt100Plus (
1389 IN CHAR16 *TextDeviceNode
1390 )
1391 {
1392 VENDOR_DEVICE_PATH *Vendor;
1393
1394 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1395 MESSAGING_DEVICE_PATH,
1396 MSG_VENDOR_DP,
1397 (UINT16) sizeof (VENDOR_DEVICE_PATH));
1398 CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
1399
1400 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1401 }
1402
1403 /**
1404 Converts a text device path node to Vendor defined UTF8 device path structure.
1405
1406 @param TextDeviceNode The input Text device path node.
1407
1408 @return A pointer to the newly-created Vendor defined UTF8 device path structure.
1409
1410 **/
1411 EFI_DEVICE_PATH_PROTOCOL *
1412 DevPathFromTextVenUtf8 (
1413 IN CHAR16 *TextDeviceNode
1414 )
1415 {
1416 VENDOR_DEVICE_PATH *Vendor;
1417
1418 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1419 MESSAGING_DEVICE_PATH,
1420 MSG_VENDOR_DP,
1421 (UINT16) sizeof (VENDOR_DEVICE_PATH));
1422 CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
1423
1424 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1425 }
1426
1427 /**
1428 Converts a text device path node to UART Flow Control device path structure.
1429
1430 @param TextDeviceNode The input Text device path node.
1431
1432 @return A pointer to the newly-created UART Flow Control device path structure.
1433
1434 **/
1435 EFI_DEVICE_PATH_PROTOCOL *
1436 DevPathFromTextUartFlowCtrl (
1437 IN CHAR16 *TextDeviceNode
1438 )
1439 {
1440 CHAR16 *ValueStr;
1441 UART_FLOW_CONTROL_DEVICE_PATH *UartFlowControl;
1442
1443 ValueStr = GetNextParamStr (&TextDeviceNode);
1444 UartFlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) CreateDeviceNode (
1445 MESSAGING_DEVICE_PATH,
1446 MSG_VENDOR_DP,
1447 (UINT16) sizeof (UART_FLOW_CONTROL_DEVICE_PATH)
1448 );
1449
1450 CopyGuid (&UartFlowControl->Guid, &gEfiUartDevicePathGuid);
1451 if (StrCmp (ValueStr, L"XonXoff") == 0) {
1452 UartFlowControl->FlowControlMap = 2;
1453 } else if (StrCmp (ValueStr, L"Hardware") == 0) {
1454 UartFlowControl->FlowControlMap = 1;
1455 } else {
1456 UartFlowControl->FlowControlMap = 0;
1457 }
1458
1459 return (EFI_DEVICE_PATH_PROTOCOL *) UartFlowControl;
1460 }
1461
1462 /**
1463 Converts a text device path node to Serial Attached SCSI device path structure.
1464
1465 @param TextDeviceNode The input Text device path node.
1466
1467 @return A pointer to the newly-created Serial Attached SCSI device path structure.
1468
1469 **/
1470 EFI_DEVICE_PATH_PROTOCOL *
1471 DevPathFromTextSAS (
1472 IN CHAR16 *TextDeviceNode
1473 )
1474 {
1475 CHAR16 *AddressStr;
1476 CHAR16 *LunStr;
1477 CHAR16 *RTPStr;
1478 CHAR16 *SASSATAStr;
1479 CHAR16 *LocationStr;
1480 CHAR16 *ConnectStr;
1481 CHAR16 *DriveBayStr;
1482 CHAR16 *ReservedStr;
1483 UINT16 Info;
1484 UINT16 Uint16;
1485 SAS_DEVICE_PATH *Sas;
1486
1487 AddressStr = GetNextParamStr (&TextDeviceNode);
1488 LunStr = GetNextParamStr (&TextDeviceNode);
1489 RTPStr = GetNextParamStr (&TextDeviceNode);
1490 SASSATAStr = GetNextParamStr (&TextDeviceNode);
1491 LocationStr = GetNextParamStr (&TextDeviceNode);
1492 ConnectStr = GetNextParamStr (&TextDeviceNode);
1493 DriveBayStr = GetNextParamStr (&TextDeviceNode);
1494 ReservedStr = GetNextParamStr (&TextDeviceNode);
1495 Sas = (SAS_DEVICE_PATH *) CreateDeviceNode (
1496 MESSAGING_DEVICE_PATH,
1497 MSG_VENDOR_DP,
1498 (UINT16) sizeof (SAS_DEVICE_PATH)
1499 );
1500
1501 CopyGuid (&Sas->Guid, &gEfiSasDevicePathGuid);
1502 Strtoi64 (AddressStr, &Sas->SasAddress);
1503 Strtoi64 (LunStr, &Sas->Lun);
1504 Sas->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
1505
1506 if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
1507 Info = 0x0;
1508
1509 } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
1510
1511 Uint16 = (UINT16) Strtoi (DriveBayStr);
1512 if (Uint16 == 0) {
1513 Info = 0x1;
1514 } else {
1515 Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
1516 }
1517
1518 if (StrCmp (SASSATAStr, L"SATA") == 0) {
1519 Info |= BIT4;
1520 }
1521
1522 //
1523 // Location is an integer between 0 and 1 or else
1524 // the keyword Internal (0) or External (1).
1525 //
1526 if (StrCmp (LocationStr, L"External") == 0) {
1527 Uint16 = 1;
1528 } else if (StrCmp (LocationStr, L"Internal") == 0) {
1529 Uint16 = 0;
1530 } else {
1531 Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
1532 }
1533 Info |= (Uint16 << 5);
1534
1535 //
1536 // Connect is an integer between 0 and 3 or else
1537 // the keyword Direct (0) or Expanded (1).
1538 //
1539 if (StrCmp (ConnectStr, L"Expanded") == 0) {
1540 Uint16 = 1;
1541 } else if (StrCmp (ConnectStr, L"Direct") == 0) {
1542 Uint16 = 0;
1543 } else {
1544 Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
1545 }
1546 Info |= (Uint16 << 6);
1547
1548 } else {
1549 Info = (UINT16) Strtoi (SASSATAStr);
1550 }
1551
1552 Sas->DeviceTopology = Info;
1553 Sas->Reserved = (UINT32) Strtoi (ReservedStr);
1554
1555 return (EFI_DEVICE_PATH_PROTOCOL *) Sas;
1556 }
1557
1558 /**
1559 Converts a text device path node to Serial Attached SCSI Ex device path structure.
1560
1561 @param TextDeviceNode The input Text device path node.
1562
1563 @return A pointer to the newly-created Serial Attached SCSI Ex device path structure.
1564
1565 **/
1566 EFI_DEVICE_PATH_PROTOCOL *
1567 DevPathFromTextSasEx (
1568 IN CHAR16 *TextDeviceNode
1569 )
1570 {
1571 CHAR16 *AddressStr;
1572 CHAR16 *LunStr;
1573 CHAR16 *RTPStr;
1574 CHAR16 *SASSATAStr;
1575 CHAR16 *LocationStr;
1576 CHAR16 *ConnectStr;
1577 CHAR16 *DriveBayStr;
1578 UINT16 Info;
1579 UINT16 Uint16;
1580 UINT64 SasAddress;
1581 UINT64 Lun;
1582 SASEX_DEVICE_PATH *SasEx;
1583
1584 AddressStr = GetNextParamStr (&TextDeviceNode);
1585 LunStr = GetNextParamStr (&TextDeviceNode);
1586 RTPStr = GetNextParamStr (&TextDeviceNode);
1587 SASSATAStr = GetNextParamStr (&TextDeviceNode);
1588 LocationStr = GetNextParamStr (&TextDeviceNode);
1589 ConnectStr = GetNextParamStr (&TextDeviceNode);
1590 DriveBayStr = GetNextParamStr (&TextDeviceNode);
1591 SasEx = (SASEX_DEVICE_PATH *) CreateDeviceNode (
1592 MESSAGING_DEVICE_PATH,
1593 MSG_SASEX_DP,
1594 (UINT16) sizeof (SASEX_DEVICE_PATH)
1595 );
1596
1597 Strtoi64 (AddressStr, &SasAddress);
1598 Strtoi64 (LunStr, &Lun);
1599 WriteUnaligned64 ((UINT64 *) &SasEx->SasAddress, SwapBytes64 (SasAddress));
1600 WriteUnaligned64 ((UINT64 *) &SasEx->Lun, SwapBytes64 (Lun));
1601 SasEx->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
1602
1603 if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
1604 Info = 0x0;
1605
1606 } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
1607
1608 Uint16 = (UINT16) Strtoi (DriveBayStr);
1609 if (Uint16 == 0) {
1610 Info = 0x1;
1611 } else {
1612 Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
1613 }
1614
1615 if (StrCmp (SASSATAStr, L"SATA") == 0) {
1616 Info |= BIT4;
1617 }
1618
1619 //
1620 // Location is an integer between 0 and 1 or else
1621 // the keyword Internal (0) or External (1).
1622 //
1623 if (StrCmp (LocationStr, L"External") == 0) {
1624 Uint16 = 1;
1625 } else if (StrCmp (LocationStr, L"Internal") == 0) {
1626 Uint16 = 0;
1627 } else {
1628 Uint16 = ((UINT16) Strtoi (LocationStr) & BIT0);
1629 }
1630 Info |= (Uint16 << 5);
1631
1632 //
1633 // Connect is an integer between 0 and 3 or else
1634 // the keyword Direct (0) or Expanded (1).
1635 //
1636 if (StrCmp (ConnectStr, L"Expanded") == 0) {
1637 Uint16 = 1;
1638 } else if (StrCmp (ConnectStr, L"Direct") == 0) {
1639 Uint16 = 0;
1640 } else {
1641 Uint16 = ((UINT16) Strtoi (ConnectStr) & (BIT0 | BIT1));
1642 }
1643 Info |= (Uint16 << 6);
1644
1645 } else {
1646 Info = (UINT16) Strtoi (SASSATAStr);
1647 }
1648
1649 SasEx->DeviceTopology = Info;
1650
1651 return (EFI_DEVICE_PATH_PROTOCOL *) SasEx;
1652 }
1653
1654 /**
1655 Converts a text device path node to Debug Port device path structure.
1656
1657 @param TextDeviceNode The input Text device path node.
1658
1659 @return A pointer to the newly-created Debug Port device path structure.
1660
1661 **/
1662 EFI_DEVICE_PATH_PROTOCOL *
1663 DevPathFromTextDebugPort (
1664 IN CHAR16 *TextDeviceNode
1665 )
1666 {
1667 VENDOR_DEFINED_MESSAGING_DEVICE_PATH *Vend;
1668
1669 Vend = (VENDOR_DEFINED_MESSAGING_DEVICE_PATH *) CreateDeviceNode (
1670 MESSAGING_DEVICE_PATH,
1671 MSG_VENDOR_DP,
1672 (UINT16) sizeof (VENDOR_DEFINED_MESSAGING_DEVICE_PATH)
1673 );
1674
1675 CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
1676
1677 return (EFI_DEVICE_PATH_PROTOCOL *) Vend;
1678 }
1679
1680 /**
1681 Converts a text device path node to MAC device path structure.
1682
1683 @param TextDeviceNode The input Text device path node.
1684
1685 @return A pointer to the newly-created MAC device path structure.
1686
1687 **/
1688 EFI_DEVICE_PATH_PROTOCOL *
1689 DevPathFromTextMAC (
1690 IN CHAR16 *TextDeviceNode
1691 )
1692 {
1693 CHAR16 *AddressStr;
1694 CHAR16 *IfTypeStr;
1695 UINTN Length;
1696 MAC_ADDR_DEVICE_PATH *MACDevPath;
1697
1698 AddressStr = GetNextParamStr (&TextDeviceNode);
1699 IfTypeStr = GetNextParamStr (&TextDeviceNode);
1700 MACDevPath = (MAC_ADDR_DEVICE_PATH *) CreateDeviceNode (
1701 MESSAGING_DEVICE_PATH,
1702 MSG_MAC_ADDR_DP,
1703 (UINT16) sizeof (MAC_ADDR_DEVICE_PATH)
1704 );
1705
1706 MACDevPath->IfType = (UINT8) Strtoi (IfTypeStr);
1707
1708 Length = sizeof (EFI_MAC_ADDRESS);
1709 StrToBuf (&MACDevPath->MacAddress.Addr[0], Length, AddressStr);
1710
1711 return (EFI_DEVICE_PATH_PROTOCOL *) MACDevPath;
1712 }
1713
1714
1715 /**
1716 Converts a text format to the network protocol ID.
1717
1718 @param Text String of protocol field.
1719
1720 @return Network protocol ID .
1721
1722 **/
1723 UINTN
1724 NetworkProtocolFromText (
1725 IN CHAR16 *Text
1726 )
1727 {
1728 if (StrCmp (Text, L"UDP") == 0) {
1729 return RFC_1700_UDP_PROTOCOL;
1730 }
1731
1732 if (StrCmp (Text, L"TCP") == 0) {
1733 return RFC_1700_TCP_PROTOCOL;
1734 }
1735
1736 return Strtoi (Text);
1737 }
1738
1739
1740 /**
1741 Converts a text device path node to IPV4 device path structure.
1742
1743 @param TextDeviceNode The input Text device path node.
1744
1745 @return A pointer to the newly-created IPV4 device path structure.
1746
1747 **/
1748 EFI_DEVICE_PATH_PROTOCOL *
1749 DevPathFromTextIPv4 (
1750 IN CHAR16 *TextDeviceNode
1751 )
1752 {
1753 CHAR16 *RemoteIPStr;
1754 CHAR16 *ProtocolStr;
1755 CHAR16 *TypeStr;
1756 CHAR16 *LocalIPStr;
1757 CHAR16 *GatewayIPStr;
1758 CHAR16 *SubnetMaskStr;
1759 IPv4_DEVICE_PATH *IPv4;
1760
1761 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
1762 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1763 TypeStr = GetNextParamStr (&TextDeviceNode);
1764 LocalIPStr = GetNextParamStr (&TextDeviceNode);
1765 GatewayIPStr = GetNextParamStr (&TextDeviceNode);
1766 SubnetMaskStr = GetNextParamStr (&TextDeviceNode);
1767 IPv4 = (IPv4_DEVICE_PATH *) CreateDeviceNode (
1768 MESSAGING_DEVICE_PATH,
1769 MSG_IPv4_DP,
1770 (UINT16) sizeof (IPv4_DEVICE_PATH)
1771 );
1772
1773 StrToIPv4Addr (&RemoteIPStr, &IPv4->RemoteIpAddress);
1774 IPv4->Protocol = (UINT16) NetworkProtocolFromText (ProtocolStr);
1775 if (StrCmp (TypeStr, L"Static") == 0) {
1776 IPv4->StaticIpAddress = TRUE;
1777 } else {
1778 IPv4->StaticIpAddress = FALSE;
1779 }
1780
1781 StrToIPv4Addr (&LocalIPStr, &IPv4->LocalIpAddress);
1782 if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) {
1783 StrToIPv4Addr (&GatewayIPStr, &IPv4->GatewayIpAddress);
1784 StrToIPv4Addr (&SubnetMaskStr, &IPv4->SubnetMask);
1785 } else {
1786 ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress));
1787 ZeroMem (&IPv4->SubnetMask, sizeof (IPv4->SubnetMask));
1788 }
1789
1790 IPv4->LocalPort = 0;
1791 IPv4->RemotePort = 0;
1792
1793 return (EFI_DEVICE_PATH_PROTOCOL *) IPv4;
1794 }
1795
1796 /**
1797 Converts a text device path node to IPV6 device path structure.
1798
1799 @param TextDeviceNode The input Text device path node.
1800
1801 @return A pointer to the newly-created IPV6 device path structure.
1802
1803 **/
1804 EFI_DEVICE_PATH_PROTOCOL *
1805 DevPathFromTextIPv6 (
1806 IN CHAR16 *TextDeviceNode
1807 )
1808 {
1809 CHAR16 *RemoteIPStr;
1810 CHAR16 *ProtocolStr;
1811 CHAR16 *TypeStr;
1812 CHAR16 *LocalIPStr;
1813 CHAR16 *GatewayIPStr;
1814 CHAR16 *PrefixLengthStr;
1815 IPv6_DEVICE_PATH *IPv6;
1816
1817 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
1818 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1819 TypeStr = GetNextParamStr (&TextDeviceNode);
1820 LocalIPStr = GetNextParamStr (&TextDeviceNode);
1821 PrefixLengthStr = GetNextParamStr (&TextDeviceNode);
1822 GatewayIPStr = GetNextParamStr (&TextDeviceNode);
1823 IPv6 = (IPv6_DEVICE_PATH *) CreateDeviceNode (
1824 MESSAGING_DEVICE_PATH,
1825 MSG_IPv6_DP,
1826 (UINT16) sizeof (IPv6_DEVICE_PATH)
1827 );
1828
1829 StrToIPv6Addr (&RemoteIPStr, &IPv6->RemoteIpAddress);
1830 IPv6->Protocol = (UINT16) NetworkProtocolFromText (ProtocolStr);
1831 if (StrCmp (TypeStr, L"Static") == 0) {
1832 IPv6->IpAddressOrigin = 0;
1833 } else if (StrCmp (TypeStr, L"StatelessAutoConfigure") == 0) {
1834 IPv6->IpAddressOrigin = 1;
1835 } else {
1836 IPv6->IpAddressOrigin = 2;
1837 }
1838
1839 StrToIPv6Addr (&LocalIPStr, &IPv6->LocalIpAddress);
1840 if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) {
1841 StrToIPv6Addr (&GatewayIPStr, &IPv6->GatewayIpAddress);
1842 IPv6->PrefixLength = (UINT8) Strtoi (PrefixLengthStr);
1843 } else {
1844 ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress));
1845 IPv6->PrefixLength = 0;
1846 }
1847
1848 IPv6->LocalPort = 0;
1849 IPv6->RemotePort = 0;
1850
1851 return (EFI_DEVICE_PATH_PROTOCOL *) IPv6;
1852 }
1853
1854 /**
1855 Converts a text device path node to UART device path structure.
1856
1857 @param TextDeviceNode The input Text device path node.
1858
1859 @return A pointer to the newly-created UART device path structure.
1860
1861 **/
1862 EFI_DEVICE_PATH_PROTOCOL *
1863 DevPathFromTextUart (
1864 IN CHAR16 *TextDeviceNode
1865 )
1866 {
1867 CHAR16 *BaudStr;
1868 CHAR16 *DataBitsStr;
1869 CHAR16 *ParityStr;
1870 CHAR16 *StopBitsStr;
1871 UART_DEVICE_PATH *Uart;
1872
1873 BaudStr = GetNextParamStr (&TextDeviceNode);
1874 DataBitsStr = GetNextParamStr (&TextDeviceNode);
1875 ParityStr = GetNextParamStr (&TextDeviceNode);
1876 StopBitsStr = GetNextParamStr (&TextDeviceNode);
1877 Uart = (UART_DEVICE_PATH *) CreateDeviceNode (
1878 MESSAGING_DEVICE_PATH,
1879 MSG_UART_DP,
1880 (UINT16) sizeof (UART_DEVICE_PATH)
1881 );
1882
1883 Uart->BaudRate = (StrCmp (BaudStr, L"DEFAULT") == 0) ? 115200 : StrDecimalToUintn (BaudStr);
1884 Uart->DataBits = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : StrDecimalToUintn (DataBitsStr));
1885 switch (*ParityStr) {
1886 case L'D':
1887 Uart->Parity = 0;
1888 break;
1889
1890 case L'N':
1891 Uart->Parity = 1;
1892 break;
1893
1894 case L'E':
1895 Uart->Parity = 2;
1896 break;
1897
1898 case L'O':
1899 Uart->Parity = 3;
1900 break;
1901
1902 case L'M':
1903 Uart->Parity = 4;
1904 break;
1905
1906 case L'S':
1907 Uart->Parity = 5;
1908 break;
1909
1910 default:
1911 Uart->Parity = 0xff;
1912 }
1913
1914 if (StrCmp (StopBitsStr, L"D") == 0) {
1915 Uart->StopBits = (UINT8) 0;
1916 } else if (StrCmp (StopBitsStr, L"1") == 0) {
1917 Uart->StopBits = (UINT8) 1;
1918 } else if (StrCmp (StopBitsStr, L"1.5") == 0) {
1919 Uart->StopBits = (UINT8) 2;
1920 } else if (StrCmp (StopBitsStr, L"2") == 0) {
1921 Uart->StopBits = (UINT8) 3;
1922 } else {
1923 Uart->StopBits = 0xff;
1924 }
1925
1926 return (EFI_DEVICE_PATH_PROTOCOL *) Uart;
1927 }
1928
1929 /**
1930 Converts a text device path node to USB class device path structure.
1931
1932 @param TextDeviceNode The input Text device path node.
1933 @param UsbClassText A pointer to USB_CLASS_TEXT structure to be integrated to USB Class Text.
1934
1935 @return A pointer to the newly-created USB class device path structure.
1936
1937 **/
1938 EFI_DEVICE_PATH_PROTOCOL *
1939 ConvertFromTextUsbClass (
1940 IN CHAR16 *TextDeviceNode,
1941 IN USB_CLASS_TEXT *UsbClassText
1942 )
1943 {
1944 CHAR16 *VIDStr;
1945 CHAR16 *PIDStr;
1946 CHAR16 *ClassStr;
1947 CHAR16 *SubClassStr;
1948 CHAR16 *ProtocolStr;
1949 USB_CLASS_DEVICE_PATH *UsbClass;
1950
1951 UsbClass = (USB_CLASS_DEVICE_PATH *) CreateDeviceNode (
1952 MESSAGING_DEVICE_PATH,
1953 MSG_USB_CLASS_DP,
1954 (UINT16) sizeof (USB_CLASS_DEVICE_PATH)
1955 );
1956
1957 VIDStr = GetNextParamStr (&TextDeviceNode);
1958 PIDStr = GetNextParamStr (&TextDeviceNode);
1959 if (UsbClassText->ClassExist) {
1960 ClassStr = GetNextParamStr (&TextDeviceNode);
1961 UsbClass->DeviceClass = (UINT8) Strtoi (ClassStr);
1962 } else {
1963 UsbClass->DeviceClass = UsbClassText->Class;
1964 }
1965 if (UsbClassText->SubClassExist) {
1966 SubClassStr = GetNextParamStr (&TextDeviceNode);
1967 UsbClass->DeviceSubClass = (UINT8) Strtoi (SubClassStr);
1968 } else {
1969 UsbClass->DeviceSubClass = UsbClassText->SubClass;
1970 }
1971
1972 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1973
1974 UsbClass->VendorId = (UINT16) Strtoi (VIDStr);
1975 UsbClass->ProductId = (UINT16) Strtoi (PIDStr);
1976 UsbClass->DeviceProtocol = (UINT8) Strtoi (ProtocolStr);
1977
1978 return (EFI_DEVICE_PATH_PROTOCOL *) UsbClass;
1979 }
1980
1981
1982 /**
1983 Converts a text device path node to USB class device path structure.
1984
1985 @param TextDeviceNode The input Text device path node.
1986
1987 @return A pointer to the newly-created USB class device path structure.
1988
1989 **/
1990 EFI_DEVICE_PATH_PROTOCOL *
1991 DevPathFromTextUsbClass (
1992 IN CHAR16 *TextDeviceNode
1993 )
1994 {
1995 USB_CLASS_TEXT UsbClassText;
1996
1997 UsbClassText.ClassExist = TRUE;
1998 UsbClassText.SubClassExist = TRUE;
1999
2000 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2001 }
2002
2003 /**
2004 Converts a text device path node to USB audio device path structure.
2005
2006 @param TextDeviceNode The input Text device path node.
2007
2008 @return A pointer to the newly-created USB audio device path structure.
2009
2010 **/
2011 EFI_DEVICE_PATH_PROTOCOL *
2012 DevPathFromTextUsbAudio (
2013 IN CHAR16 *TextDeviceNode
2014 )
2015 {
2016 USB_CLASS_TEXT UsbClassText;
2017
2018 UsbClassText.ClassExist = FALSE;
2019 UsbClassText.Class = USB_CLASS_AUDIO;
2020 UsbClassText.SubClassExist = TRUE;
2021
2022 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2023 }
2024
2025 /**
2026 Converts a text device path node to USB CDC Control device path structure.
2027
2028 @param TextDeviceNode The input Text device path node.
2029
2030 @return A pointer to the newly-created USB CDC Control device path structure.
2031
2032 **/
2033 EFI_DEVICE_PATH_PROTOCOL *
2034 DevPathFromTextUsbCDCControl (
2035 IN CHAR16 *TextDeviceNode
2036 )
2037 {
2038 USB_CLASS_TEXT UsbClassText;
2039
2040 UsbClassText.ClassExist = FALSE;
2041 UsbClassText.Class = USB_CLASS_CDCCONTROL;
2042 UsbClassText.SubClassExist = TRUE;
2043
2044 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2045 }
2046
2047 /**
2048 Converts a text device path node to USB HID device path structure.
2049
2050 @param TextDeviceNode The input Text device path node.
2051
2052 @return A pointer to the newly-created USB HID device path structure.
2053
2054 **/
2055 EFI_DEVICE_PATH_PROTOCOL *
2056 DevPathFromTextUsbHID (
2057 IN CHAR16 *TextDeviceNode
2058 )
2059 {
2060 USB_CLASS_TEXT UsbClassText;
2061
2062 UsbClassText.ClassExist = FALSE;
2063 UsbClassText.Class = USB_CLASS_HID;
2064 UsbClassText.SubClassExist = TRUE;
2065
2066 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2067 }
2068
2069 /**
2070 Converts a text device path node to USB Image device path structure.
2071
2072 @param TextDeviceNode The input Text device path node.
2073
2074 @return A pointer to the newly-created USB Image device path structure.
2075
2076 **/
2077 EFI_DEVICE_PATH_PROTOCOL *
2078 DevPathFromTextUsbImage (
2079 IN CHAR16 *TextDeviceNode
2080 )
2081 {
2082 USB_CLASS_TEXT UsbClassText;
2083
2084 UsbClassText.ClassExist = FALSE;
2085 UsbClassText.Class = USB_CLASS_IMAGE;
2086 UsbClassText.SubClassExist = TRUE;
2087
2088 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2089 }
2090
2091 /**
2092 Converts a text device path node to USB Print device path structure.
2093
2094 @param TextDeviceNode The input Text device path node.
2095
2096 @return A pointer to the newly-created USB Print device path structure.
2097
2098 **/
2099 EFI_DEVICE_PATH_PROTOCOL *
2100 DevPathFromTextUsbPrinter (
2101 IN CHAR16 *TextDeviceNode
2102 )
2103 {
2104 USB_CLASS_TEXT UsbClassText;
2105
2106 UsbClassText.ClassExist = FALSE;
2107 UsbClassText.Class = USB_CLASS_PRINTER;
2108 UsbClassText.SubClassExist = TRUE;
2109
2110 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2111 }
2112
2113 /**
2114 Converts a text device path node to USB mass storage device path structure.
2115
2116 @param TextDeviceNode The input Text device path node.
2117
2118 @return A pointer to the newly-created USB mass storage device path structure.
2119
2120 **/
2121 EFI_DEVICE_PATH_PROTOCOL *
2122 DevPathFromTextUsbMassStorage (
2123 IN CHAR16 *TextDeviceNode
2124 )
2125 {
2126 USB_CLASS_TEXT UsbClassText;
2127
2128 UsbClassText.ClassExist = FALSE;
2129 UsbClassText.Class = USB_CLASS_MASS_STORAGE;
2130 UsbClassText.SubClassExist = TRUE;
2131
2132 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2133 }
2134
2135 /**
2136 Converts a text device path node to USB HUB device path structure.
2137
2138 @param TextDeviceNode The input Text device path node.
2139
2140 @return A pointer to the newly-created USB HUB device path structure.
2141
2142 **/
2143 EFI_DEVICE_PATH_PROTOCOL *
2144 DevPathFromTextUsbHub (
2145 IN CHAR16 *TextDeviceNode
2146 )
2147 {
2148 USB_CLASS_TEXT UsbClassText;
2149
2150 UsbClassText.ClassExist = FALSE;
2151 UsbClassText.Class = USB_CLASS_HUB;
2152 UsbClassText.SubClassExist = TRUE;
2153
2154 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2155 }
2156
2157 /**
2158 Converts a text device path node to USB CDC data device path structure.
2159
2160 @param TextDeviceNode The input Text device path node.
2161
2162 @return A pointer to the newly-created USB CDC data device path structure.
2163
2164 **/
2165 EFI_DEVICE_PATH_PROTOCOL *
2166 DevPathFromTextUsbCDCData (
2167 IN CHAR16 *TextDeviceNode
2168 )
2169 {
2170 USB_CLASS_TEXT UsbClassText;
2171
2172 UsbClassText.ClassExist = FALSE;
2173 UsbClassText.Class = USB_CLASS_CDCDATA;
2174 UsbClassText.SubClassExist = TRUE;
2175
2176 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2177 }
2178
2179 /**
2180 Converts a text device path node to USB smart card device path structure.
2181
2182 @param TextDeviceNode The input Text device path node.
2183
2184 @return A pointer to the newly-created USB smart card device path structure.
2185
2186 **/
2187 EFI_DEVICE_PATH_PROTOCOL *
2188 DevPathFromTextUsbSmartCard (
2189 IN CHAR16 *TextDeviceNode
2190 )
2191 {
2192 USB_CLASS_TEXT UsbClassText;
2193
2194 UsbClassText.ClassExist = FALSE;
2195 UsbClassText.Class = USB_CLASS_SMART_CARD;
2196 UsbClassText.SubClassExist = TRUE;
2197
2198 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2199 }
2200
2201 /**
2202 Converts a text device path node to USB video device path structure.
2203
2204 @param TextDeviceNode The input Text device path node.
2205
2206 @return A pointer to the newly-created USB video device path structure.
2207
2208 **/
2209 EFI_DEVICE_PATH_PROTOCOL *
2210 DevPathFromTextUsbVideo (
2211 IN CHAR16 *TextDeviceNode
2212 )
2213 {
2214 USB_CLASS_TEXT UsbClassText;
2215
2216 UsbClassText.ClassExist = FALSE;
2217 UsbClassText.Class = USB_CLASS_VIDEO;
2218 UsbClassText.SubClassExist = TRUE;
2219
2220 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2221 }
2222
2223 /**
2224 Converts a text device path node to USB diagnostic device path structure.
2225
2226 @param TextDeviceNode The input Text device path node.
2227
2228 @return A pointer to the newly-created USB diagnostic device path structure.
2229
2230 **/
2231 EFI_DEVICE_PATH_PROTOCOL *
2232 DevPathFromTextUsbDiagnostic (
2233 IN CHAR16 *TextDeviceNode
2234 )
2235 {
2236 USB_CLASS_TEXT UsbClassText;
2237
2238 UsbClassText.ClassExist = FALSE;
2239 UsbClassText.Class = USB_CLASS_DIAGNOSTIC;
2240 UsbClassText.SubClassExist = TRUE;
2241
2242 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2243 }
2244
2245 /**
2246 Converts a text device path node to USB wireless device path structure.
2247
2248 @param TextDeviceNode The input Text device path node.
2249
2250 @return A pointer to the newly-created USB wireless device path structure.
2251
2252 **/
2253 EFI_DEVICE_PATH_PROTOCOL *
2254 DevPathFromTextUsbWireless (
2255 IN CHAR16 *TextDeviceNode
2256 )
2257 {
2258 USB_CLASS_TEXT UsbClassText;
2259
2260 UsbClassText.ClassExist = FALSE;
2261 UsbClassText.Class = USB_CLASS_WIRELESS;
2262 UsbClassText.SubClassExist = TRUE;
2263
2264 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2265 }
2266
2267 /**
2268 Converts a text device path node to USB device firmware update device path structure.
2269
2270 @param TextDeviceNode The input Text device path node.
2271
2272 @return A pointer to the newly-created USB device firmware update device path structure.
2273
2274 **/
2275 EFI_DEVICE_PATH_PROTOCOL *
2276 DevPathFromTextUsbDeviceFirmwareUpdate (
2277 IN CHAR16 *TextDeviceNode
2278 )
2279 {
2280 USB_CLASS_TEXT UsbClassText;
2281
2282 UsbClassText.ClassExist = FALSE;
2283 UsbClassText.Class = USB_CLASS_RESERVE;
2284 UsbClassText.SubClassExist = FALSE;
2285 UsbClassText.SubClass = USB_SUBCLASS_FW_UPDATE;
2286
2287 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2288 }
2289
2290 /**
2291 Converts a text device path node to USB IRDA bridge device path structure.
2292
2293 @param TextDeviceNode The input Text device path node.
2294
2295 @return A pointer to the newly-created USB IRDA bridge device path structure.
2296
2297 **/
2298 EFI_DEVICE_PATH_PROTOCOL *
2299 DevPathFromTextUsbIrdaBridge (
2300 IN CHAR16 *TextDeviceNode
2301 )
2302 {
2303 USB_CLASS_TEXT UsbClassText;
2304
2305 UsbClassText.ClassExist = FALSE;
2306 UsbClassText.Class = USB_CLASS_RESERVE;
2307 UsbClassText.SubClassExist = FALSE;
2308 UsbClassText.SubClass = USB_SUBCLASS_IRDA_BRIDGE;
2309
2310 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2311 }
2312
2313 /**
2314 Converts a text device path node to USB text and measurement device path structure.
2315
2316 @param TextDeviceNode The input Text device path node.
2317
2318 @return A pointer to the newly-created USB text and measurement device path structure.
2319
2320 **/
2321 EFI_DEVICE_PATH_PROTOCOL *
2322 DevPathFromTextUsbTestAndMeasurement (
2323 IN CHAR16 *TextDeviceNode
2324 )
2325 {
2326 USB_CLASS_TEXT UsbClassText;
2327
2328 UsbClassText.ClassExist = FALSE;
2329 UsbClassText.Class = USB_CLASS_RESERVE;
2330 UsbClassText.SubClassExist = FALSE;
2331 UsbClassText.SubClass = USB_SUBCLASS_TEST;
2332
2333 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
2334 }
2335
2336 /**
2337 Converts a text device path node to USB WWID device path structure.
2338
2339 @param TextDeviceNode The input Text device path node.
2340
2341 @return A pointer to the newly-created USB WWID device path structure.
2342
2343 **/
2344 EFI_DEVICE_PATH_PROTOCOL *
2345 DevPathFromTextUsbWwid (
2346 IN CHAR16 *TextDeviceNode
2347 )
2348 {
2349 CHAR16 *VIDStr;
2350 CHAR16 *PIDStr;
2351 CHAR16 *InterfaceNumStr;
2352 CHAR16 *SerialNumberStr;
2353 USB_WWID_DEVICE_PATH *UsbWwid;
2354
2355 VIDStr = GetNextParamStr (&TextDeviceNode);
2356 PIDStr = GetNextParamStr (&TextDeviceNode);
2357 InterfaceNumStr = GetNextParamStr (&TextDeviceNode);
2358 SerialNumberStr = GetNextParamStr (&TextDeviceNode);
2359 UsbWwid = (USB_WWID_DEVICE_PATH *) CreateDeviceNode (
2360 MESSAGING_DEVICE_PATH,
2361 MSG_USB_WWID_DP,
2362 (UINT16) (sizeof (USB_WWID_DEVICE_PATH) + StrSize (SerialNumberStr))
2363 );
2364
2365 UsbWwid->VendorId = (UINT16) Strtoi (VIDStr);
2366 UsbWwid->ProductId = (UINT16) Strtoi (PIDStr);
2367 UsbWwid->InterfaceNumber = (UINT16) Strtoi (InterfaceNumStr);
2368 StrCpy ((CHAR16 *) ((UINT8 *) UsbWwid + sizeof (USB_WWID_DEVICE_PATH)), SerialNumberStr);
2369
2370 return (EFI_DEVICE_PATH_PROTOCOL *) UsbWwid;
2371 }
2372
2373 /**
2374 Converts a text device path node to Logic Unit device path structure.
2375
2376 @param TextDeviceNode The input Text device path node.
2377
2378 @return A pointer to the newly-created Logic Unit device path structure.
2379
2380 **/
2381 EFI_DEVICE_PATH_PROTOCOL *
2382 DevPathFromTextUnit (
2383 IN CHAR16 *TextDeviceNode
2384 )
2385 {
2386 CHAR16 *LunStr;
2387 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
2388
2389 LunStr = GetNextParamStr (&TextDeviceNode);
2390 LogicalUnit = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) CreateDeviceNode (
2391 MESSAGING_DEVICE_PATH,
2392 MSG_DEVICE_LOGICAL_UNIT_DP,
2393 (UINT16) sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)
2394 );
2395
2396 LogicalUnit->Lun = (UINT8) Strtoi (LunStr);
2397
2398 return (EFI_DEVICE_PATH_PROTOCOL *) LogicalUnit;
2399 }
2400
2401 /**
2402 Converts a text device path node to iSCSI device path structure.
2403
2404 @param TextDeviceNode The input Text device path node.
2405
2406 @return A pointer to the newly-created iSCSI device path structure.
2407
2408 **/
2409 EFI_DEVICE_PATH_PROTOCOL *
2410 DevPathFromTextiSCSI (
2411 IN CHAR16 *TextDeviceNode
2412 )
2413 {
2414 UINT16 Options;
2415 CHAR16 *NameStr;
2416 CHAR16 *PortalGroupStr;
2417 CHAR16 *LunStr;
2418 CHAR16 *HeaderDigestStr;
2419 CHAR16 *DataDigestStr;
2420 CHAR16 *AuthenticationStr;
2421 CHAR16 *ProtocolStr;
2422 CHAR8 *AsciiStr;
2423 ISCSI_DEVICE_PATH_WITH_NAME *ISCSIDevPath;
2424
2425 NameStr = GetNextParamStr (&TextDeviceNode);
2426 PortalGroupStr = GetNextParamStr (&TextDeviceNode);
2427 LunStr = GetNextParamStr (&TextDeviceNode);
2428 HeaderDigestStr = GetNextParamStr (&TextDeviceNode);
2429 DataDigestStr = GetNextParamStr (&TextDeviceNode);
2430 AuthenticationStr = GetNextParamStr (&TextDeviceNode);
2431 ProtocolStr = GetNextParamStr (&TextDeviceNode);
2432 ISCSIDevPath = (ISCSI_DEVICE_PATH_WITH_NAME *) CreateDeviceNode (
2433 MESSAGING_DEVICE_PATH,
2434 MSG_ISCSI_DP,
2435 (UINT16) (sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + StrLen (NameStr))
2436 );
2437
2438 AsciiStr = ISCSIDevPath->TargetName;
2439 StrToAscii (NameStr, &AsciiStr);
2440
2441 ISCSIDevPath->TargetPortalGroupTag = (UINT16) Strtoi (PortalGroupStr);
2442 Strtoi64 (LunStr, &ISCSIDevPath->Lun);
2443
2444 Options = 0x0000;
2445 if (StrCmp (HeaderDigestStr, L"CRC32C") == 0) {
2446 Options |= 0x0002;
2447 }
2448
2449 if (StrCmp (DataDigestStr, L"CRC32C") == 0) {
2450 Options |= 0x0008;
2451 }
2452
2453 if (StrCmp (AuthenticationStr, L"None") == 0) {
2454 Options |= 0x0800;
2455 }
2456
2457 if (StrCmp (AuthenticationStr, L"CHAP_UNI") == 0) {
2458 Options |= 0x1000;
2459 }
2460
2461 ISCSIDevPath->LoginOption = (UINT16) Options;
2462
2463 ISCSIDevPath->NetworkProtocol = (UINT16) StrCmp (ProtocolStr, L"TCP");
2464
2465 return (EFI_DEVICE_PATH_PROTOCOL *) ISCSIDevPath;
2466 }
2467
2468 /**
2469 Converts a text device path node to VLAN device path structure.
2470
2471 @param TextDeviceNode The input Text device path node.
2472
2473 @return A pointer to the newly-created VLAN device path structure.
2474
2475 **/
2476 EFI_DEVICE_PATH_PROTOCOL *
2477 DevPathFromTextVlan (
2478 IN CHAR16 *TextDeviceNode
2479 )
2480 {
2481 CHAR16 *VlanStr;
2482 VLAN_DEVICE_PATH *Vlan;
2483
2484 VlanStr = GetNextParamStr (&TextDeviceNode);
2485 Vlan = (VLAN_DEVICE_PATH *) CreateDeviceNode (
2486 MESSAGING_DEVICE_PATH,
2487 MSG_VLAN_DP,
2488 (UINT16) sizeof (VLAN_DEVICE_PATH)
2489 );
2490
2491 Vlan->VlanId = (UINT16) Strtoi (VlanStr);
2492
2493 return (EFI_DEVICE_PATH_PROTOCOL *) Vlan;
2494 }
2495
2496 /**
2497 Converts a text device path node to HD device path structure.
2498
2499 @param TextDeviceNode The input Text device path node.
2500
2501 @return A pointer to the newly-created HD device path structure.
2502
2503 **/
2504 EFI_DEVICE_PATH_PROTOCOL *
2505 DevPathFromTextHD (
2506 IN CHAR16 *TextDeviceNode
2507 )
2508 {
2509 CHAR16 *PartitionStr;
2510 CHAR16 *TypeStr;
2511 CHAR16 *SignatureStr;
2512 CHAR16 *StartStr;
2513 CHAR16 *SizeStr;
2514 UINT32 Signature32;
2515 EFI_GUID SignatureGuid;
2516 HARDDRIVE_DEVICE_PATH *Hd;
2517
2518 PartitionStr = GetNextParamStr (&TextDeviceNode);
2519 TypeStr = GetNextParamStr (&TextDeviceNode);
2520 SignatureStr = GetNextParamStr (&TextDeviceNode);
2521 StartStr = GetNextParamStr (&TextDeviceNode);
2522 SizeStr = GetNextParamStr (&TextDeviceNode);
2523 Hd = (HARDDRIVE_DEVICE_PATH *) CreateDeviceNode (
2524 MEDIA_DEVICE_PATH,
2525 MEDIA_HARDDRIVE_DP,
2526 (UINT16) sizeof (HARDDRIVE_DEVICE_PATH)
2527 );
2528
2529 Hd->PartitionNumber = (UINT32) StrDecimalToUintn (PartitionStr);
2530
2531 ZeroMem (Hd->Signature, 16);
2532 Hd->MBRType = (UINT8) 0;
2533
2534 if (StrCmp (TypeStr, L"MBR") == 0) {
2535 Hd->SignatureType = SIGNATURE_TYPE_MBR;
2536 Hd->MBRType = 0x01;
2537
2538 Signature32 = (UINT32) Strtoi (SignatureStr);
2539 CopyMem (Hd->Signature, &Signature32, sizeof (UINT32));
2540 } else if (StrCmp (TypeStr, L"GPT") == 0) {
2541 Hd->SignatureType = SIGNATURE_TYPE_GUID;
2542 Hd->MBRType = 0x02;
2543
2544 StrToGuid (SignatureStr, &SignatureGuid);
2545 CopyMem (Hd->Signature, &SignatureGuid, sizeof (EFI_GUID));
2546 } else {
2547 Hd->SignatureType = (UINT8) Strtoi (TypeStr);
2548 }
2549
2550 Strtoi64 (StartStr, &Hd->PartitionStart);
2551 Strtoi64 (SizeStr, &Hd->PartitionSize);
2552
2553 return (EFI_DEVICE_PATH_PROTOCOL *) Hd;
2554 }
2555
2556 /**
2557 Converts a text device path node to CDROM device path structure.
2558
2559 @param TextDeviceNode The input Text device path node.
2560
2561 @return A pointer to the newly-created CDROM device path structure.
2562
2563 **/
2564 EFI_DEVICE_PATH_PROTOCOL *
2565 DevPathFromTextCDROM (
2566 IN CHAR16 *TextDeviceNode
2567 )
2568 {
2569 CHAR16 *EntryStr;
2570 CHAR16 *StartStr;
2571 CHAR16 *SizeStr;
2572 CDROM_DEVICE_PATH *CDROMDevPath;
2573
2574 EntryStr = GetNextParamStr (&TextDeviceNode);
2575 StartStr = GetNextParamStr (&TextDeviceNode);
2576 SizeStr = GetNextParamStr (&TextDeviceNode);
2577 CDROMDevPath = (CDROM_DEVICE_PATH *) CreateDeviceNode (
2578 MEDIA_DEVICE_PATH,
2579 MEDIA_CDROM_DP,
2580 (UINT16) sizeof (CDROM_DEVICE_PATH)
2581 );
2582
2583 CDROMDevPath->BootEntry = (UINT32) Strtoi (EntryStr);
2584 Strtoi64 (StartStr, &CDROMDevPath->PartitionStart);
2585 Strtoi64 (SizeStr, &CDROMDevPath->PartitionSize);
2586
2587 return (EFI_DEVICE_PATH_PROTOCOL *) CDROMDevPath;
2588 }
2589
2590 /**
2591 Converts a text device path node to Vendor-defined media device path structure.
2592
2593 @param TextDeviceNode The input Text device path node.
2594
2595 @return A pointer to the newly-created Vendor-defined media device path structure.
2596
2597 **/
2598 EFI_DEVICE_PATH_PROTOCOL *
2599 DevPathFromTextVenMEDIA (
2600 IN CHAR16 *TextDeviceNode
2601 )
2602 {
2603 return ConvertFromTextVendor (
2604 TextDeviceNode,
2605 MEDIA_DEVICE_PATH,
2606 MEDIA_VENDOR_DP
2607 );
2608 }
2609
2610 /**
2611 Converts a text device path node to File device path structure.
2612
2613 @param TextDeviceNode The input Text device path node.
2614
2615 @return A pointer to the newly-created File device path structure.
2616
2617 **/
2618 EFI_DEVICE_PATH_PROTOCOL *
2619 DevPathFromTextFilePath (
2620 IN CHAR16 *TextDeviceNode
2621 )
2622 {
2623 FILEPATH_DEVICE_PATH *File;
2624
2625 File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
2626 MEDIA_DEVICE_PATH,
2627 MEDIA_FILEPATH_DP,
2628 (UINT16) (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2)
2629 );
2630
2631 StrCpy (File->PathName, TextDeviceNode);
2632
2633 return (EFI_DEVICE_PATH_PROTOCOL *) File;
2634 }
2635
2636 /**
2637 Converts a text device path node to Media protocol device path structure.
2638
2639 @param TextDeviceNode The input Text device path node.
2640
2641 @return A pointer to the newly-created Media protocol device path structure.
2642
2643 **/
2644 EFI_DEVICE_PATH_PROTOCOL *
2645 DevPathFromTextMedia (
2646 IN CHAR16 *TextDeviceNode
2647 )
2648 {
2649 CHAR16 *GuidStr;
2650 MEDIA_PROTOCOL_DEVICE_PATH *Media;
2651
2652 GuidStr = GetNextParamStr (&TextDeviceNode);
2653 Media = (MEDIA_PROTOCOL_DEVICE_PATH *) CreateDeviceNode (
2654 MEDIA_DEVICE_PATH,
2655 MEDIA_PROTOCOL_DP,
2656 (UINT16) sizeof (MEDIA_PROTOCOL_DEVICE_PATH)
2657 );
2658
2659 StrToGuid (GuidStr, &Media->Protocol);
2660
2661 return (EFI_DEVICE_PATH_PROTOCOL *) Media;
2662 }
2663
2664 /**
2665 Converts a text device path node to firmware volume device path structure.
2666
2667 @param TextDeviceNode The input Text device path node.
2668
2669 @return A pointer to the newly-created firmware volume device path structure.
2670
2671 **/
2672 EFI_DEVICE_PATH_PROTOCOL *
2673 DevPathFromTextFv (
2674 IN CHAR16 *TextDeviceNode
2675 )
2676 {
2677 CHAR16 *GuidStr;
2678 MEDIA_FW_VOL_DEVICE_PATH *Fv;
2679
2680 GuidStr = GetNextParamStr (&TextDeviceNode);
2681 Fv = (MEDIA_FW_VOL_DEVICE_PATH *) CreateDeviceNode (
2682 MEDIA_DEVICE_PATH,
2683 MEDIA_PIWG_FW_VOL_DP,
2684 (UINT16) sizeof (MEDIA_FW_VOL_DEVICE_PATH)
2685 );
2686
2687 StrToGuid (GuidStr, &Fv->FvName);
2688
2689 return (EFI_DEVICE_PATH_PROTOCOL *) Fv;
2690 }
2691
2692 /**
2693 Converts a text device path node to firmware file device path structure.
2694
2695 @param TextDeviceNode The input Text device path node.
2696
2697 @return A pointer to the newly-created firmware file device path structure.
2698
2699 **/
2700 EFI_DEVICE_PATH_PROTOCOL *
2701 DevPathFromTextFvFile (
2702 IN CHAR16 *TextDeviceNode
2703 )
2704 {
2705 CHAR16 *GuidStr;
2706 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFile;
2707
2708 GuidStr = GetNextParamStr (&TextDeviceNode);
2709 FvFile = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) CreateDeviceNode (
2710 MEDIA_DEVICE_PATH,
2711 MEDIA_PIWG_FW_FILE_DP,
2712 (UINT16) sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH)
2713 );
2714
2715 StrToGuid (GuidStr, &FvFile->FvFileName);
2716
2717 return (EFI_DEVICE_PATH_PROTOCOL *) FvFile;
2718 }
2719
2720 /**
2721 Converts a text device path node to text relative offset device path structure.
2722
2723 @param TextDeviceNode The input Text device path node.
2724
2725 @return A pointer to the newly-created Text device path structure.
2726
2727 **/
2728 EFI_DEVICE_PATH_PROTOCOL *
2729 DevPathFromTextRelativeOffsetRange (
2730 IN CHAR16 *TextDeviceNode
2731 )
2732 {
2733 CHAR16 *StartingOffsetStr;
2734 CHAR16 *EndingOffsetStr;
2735 MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;
2736
2737 StartingOffsetStr = GetNextParamStr (&TextDeviceNode);
2738 EndingOffsetStr = GetNextParamStr (&TextDeviceNode);
2739 Offset = (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *) CreateDeviceNode (
2740 MEDIA_DEVICE_PATH,
2741 MEDIA_RELATIVE_OFFSET_RANGE_DP,
2742 (UINT16) sizeof (MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH)
2743 );
2744
2745 Strtoi64 (StartingOffsetStr, &Offset->StartingOffset);
2746 Strtoi64 (EndingOffsetStr, &Offset->EndingOffset);
2747
2748 return (EFI_DEVICE_PATH_PROTOCOL *) Offset;
2749 }
2750
2751 /**
2752 Converts a text device path node to BIOS Boot Specification device path structure.
2753
2754 @param TextDeviceNode The input Text device path node.
2755
2756 @return A pointer to the newly-created BIOS Boot Specification device path structure.
2757
2758 **/
2759 EFI_DEVICE_PATH_PROTOCOL *
2760 DevPathFromTextBBS (
2761 IN CHAR16 *TextDeviceNode
2762 )
2763 {
2764 CHAR16 *TypeStr;
2765 CHAR16 *IdStr;
2766 CHAR16 *FlagsStr;
2767 CHAR8 *AsciiStr;
2768 BBS_BBS_DEVICE_PATH *Bbs;
2769
2770 TypeStr = GetNextParamStr (&TextDeviceNode);
2771 IdStr = GetNextParamStr (&TextDeviceNode);
2772 FlagsStr = GetNextParamStr (&TextDeviceNode);
2773 Bbs = (BBS_BBS_DEVICE_PATH *) CreateDeviceNode (
2774 BBS_DEVICE_PATH,
2775 BBS_BBS_DP,
2776 (UINT16) (sizeof (BBS_BBS_DEVICE_PATH) + StrLen (IdStr))
2777 );
2778
2779 if (StrCmp (TypeStr, L"Floppy") == 0) {
2780 Bbs->DeviceType = BBS_TYPE_FLOPPY;
2781 } else if (StrCmp (TypeStr, L"HD") == 0) {
2782 Bbs->DeviceType = BBS_TYPE_HARDDRIVE;
2783 } else if (StrCmp (TypeStr, L"CDROM") == 0) {
2784 Bbs->DeviceType = BBS_TYPE_CDROM;
2785 } else if (StrCmp (TypeStr, L"PCMCIA") == 0) {
2786 Bbs->DeviceType = BBS_TYPE_PCMCIA;
2787 } else if (StrCmp (TypeStr, L"USB") == 0) {
2788 Bbs->DeviceType = BBS_TYPE_USB;
2789 } else if (StrCmp (TypeStr, L"Network") == 0) {
2790 Bbs->DeviceType = BBS_TYPE_EMBEDDED_NETWORK;
2791 } else {
2792 Bbs->DeviceType = (UINT16) Strtoi (TypeStr);
2793 }
2794
2795 AsciiStr = Bbs->String;
2796 StrToAscii (IdStr, &AsciiStr);
2797
2798 Bbs->StatusFlag = (UINT16) Strtoi (FlagsStr);
2799
2800 return (EFI_DEVICE_PATH_PROTOCOL *) Bbs;
2801 }
2802
2803 /**
2804 Converts a text device path node to SATA device path structure.
2805
2806 @param TextDeviceNode The input Text device path node.
2807
2808 @return A pointer to the newly-created SATA device path structure.
2809
2810 **/
2811 EFI_DEVICE_PATH_PROTOCOL *
2812 DevPathFromTextSata (
2813 IN CHAR16 *TextDeviceNode
2814 )
2815 {
2816 SATA_DEVICE_PATH *Sata;
2817 CHAR16 *Param1;
2818 CHAR16 *Param2;
2819 CHAR16 *Param3;
2820
2821 //
2822 // The PMPN is optional.
2823 //
2824 Param1 = GetNextParamStr (&TextDeviceNode);
2825 Param2 = GetNextParamStr (&TextDeviceNode);
2826 Param3 = NULL;
2827 if (!IS_NULL (TextDeviceNode)) {
2828 Param3 = GetNextParamStr (&TextDeviceNode);
2829 }
2830
2831 Sata = (SATA_DEVICE_PATH *) CreateDeviceNode (
2832 MESSAGING_DEVICE_PATH,
2833 MSG_SATA_DP,
2834 (UINT16) sizeof (SATA_DEVICE_PATH)
2835 );
2836 Sata->HBAPortNumber = (UINT16) StrHexToUintn (Param1);
2837 if (Param3 != NULL) {
2838 Sata->PortMultiplierPortNumber = (UINT16) StrHexToUintn (Param2);
2839 Param2 = Param3;
2840 } else {
2841 Sata->PortMultiplierPortNumber = SATA_HBA_DIRECT_CONNECT_FLAG;
2842 }
2843 Sata->Lun = (UINT16) StrHexToUintn (Param2);
2844
2845 return (EFI_DEVICE_PATH_PROTOCOL *) Sata;
2846 }
2847
2848 GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevPathFromTextTable[] = {
2849 {L"Pci", DevPathFromTextPci },
2850 {L"PcCard", DevPathFromTextPcCard },
2851 {L"MemoryMapped", DevPathFromTextMemoryMapped },
2852 {L"VenHw", DevPathFromTextVenHw },
2853 {L"Ctrl", DevPathFromTextCtrl },
2854 {L"Acpi", DevPathFromTextAcpi },
2855 {L"PciRoot", DevPathFromTextPciRoot },
2856 {L"PcieRoot", DevPathFromTextPcieRoot },
2857 {L"Floppy", DevPathFromTextFloppy },
2858 {L"Keyboard", DevPathFromTextKeyboard },
2859 {L"Serial", DevPathFromTextSerial },
2860 {L"ParallelPort", DevPathFromTextParallelPort },
2861 {L"AcpiEx", DevPathFromTextAcpiEx },
2862 {L"AcpiExp", DevPathFromTextAcpiExp },
2863 {L"AcpiAdr", DevPathFromTextAcpiAdr },
2864 {L"Ata", DevPathFromTextAta },
2865 {L"Scsi", DevPathFromTextScsi },
2866 {L"Fibre", DevPathFromTextFibre },
2867 {L"FibreEx", DevPathFromTextFibreEx },
2868 {L"I1394", DevPathFromText1394 },
2869 {L"USB", DevPathFromTextUsb },
2870 {L"I2O", DevPathFromTextI2O },
2871 {L"Infiniband", DevPathFromTextInfiniband },
2872 {L"VenMsg", DevPathFromTextVenMsg },
2873 {L"VenPcAnsi", DevPathFromTextVenPcAnsi },
2874 {L"VenVt100", DevPathFromTextVenVt100 },
2875 {L"VenVt100Plus", DevPathFromTextVenVt100Plus },
2876 {L"VenUtf8", DevPathFromTextVenUtf8 },
2877 {L"UartFlowCtrl", DevPathFromTextUartFlowCtrl },
2878 {L"SAS", DevPathFromTextSAS },
2879 {L"SasEx", DevPathFromTextSasEx },
2880 {L"DebugPort", DevPathFromTextDebugPort },
2881 {L"MAC", DevPathFromTextMAC },
2882 {L"IPv4", DevPathFromTextIPv4 },
2883 {L"IPv6", DevPathFromTextIPv6 },
2884 {L"Uart", DevPathFromTextUart },
2885 {L"UsbClass", DevPathFromTextUsbClass },
2886 {L"UsbAudio", DevPathFromTextUsbAudio },
2887 {L"UsbCDCControl", DevPathFromTextUsbCDCControl },
2888 {L"UsbHID", DevPathFromTextUsbHID },
2889 {L"UsbImage", DevPathFromTextUsbImage },
2890 {L"UsbPrinter", DevPathFromTextUsbPrinter },
2891 {L"UsbMassStorage", DevPathFromTextUsbMassStorage },
2892 {L"UsbHub", DevPathFromTextUsbHub },
2893 {L"UsbCDCData", DevPathFromTextUsbCDCData },
2894 {L"UsbSmartCard", DevPathFromTextUsbSmartCard },
2895 {L"UsbVideo", DevPathFromTextUsbVideo },
2896 {L"UsbDiagnostic", DevPathFromTextUsbDiagnostic },
2897 {L"UsbWireless", DevPathFromTextUsbWireless },
2898 {L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate },
2899 {L"UsbIrdaBridge", DevPathFromTextUsbIrdaBridge },
2900 {L"UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement },
2901 {L"UsbWwid", DevPathFromTextUsbWwid },
2902 {L"Unit", DevPathFromTextUnit },
2903 {L"iSCSI", DevPathFromTextiSCSI },
2904 {L"Vlan", DevPathFromTextVlan },
2905 {L"HD", DevPathFromTextHD },
2906 {L"CDROM", DevPathFromTextCDROM },
2907 {L"VenMEDIA", DevPathFromTextVenMEDIA },
2908 {L"Media", DevPathFromTextMedia },
2909 {L"Fv", DevPathFromTextFv },
2910 {L"FvFile", DevPathFromTextFvFile },
2911 {L"Offset", DevPathFromTextRelativeOffsetRange },
2912 {L"BBS", DevPathFromTextBBS },
2913 {L"Sata", DevPathFromTextSata },
2914 {NULL, NULL}
2915 };
2916
2917 /**
2918 Convert text to the binary representation of a device node.
2919
2920 @param TextDeviceNode TextDeviceNode points to the text representation of a device
2921 node. Conversion starts with the first character and continues
2922 until the first non-device node character.
2923
2924 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
2925 insufficient memory or text unsupported.
2926
2927 **/
2928 EFI_DEVICE_PATH_PROTOCOL *
2929 EFIAPI
2930 UefiDevicePathLibConvertTextToDeviceNode (
2931 IN CONST CHAR16 *TextDeviceNode
2932 )
2933 {
2934 DEVICE_PATH_FROM_TEXT FromText;
2935 CHAR16 *ParamStr;
2936 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
2937 CHAR16 *DeviceNodeStr;
2938 UINTN Index;
2939
2940 if ((TextDeviceNode == NULL) || (IS_NULL (*TextDeviceNode))) {
2941 return NULL;
2942 }
2943
2944 ParamStr = NULL;
2945 FromText = NULL;
2946 DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode);
2947 ASSERT (DeviceNodeStr != NULL);
2948
2949 for (Index = 0; mUefiDevicePathLibDevPathFromTextTable[Index].Function != NULL; Index++) {
2950 ParamStr = GetParamByNodeName (DeviceNodeStr, mUefiDevicePathLibDevPathFromTextTable[Index].DevicePathNodeText);
2951 if (ParamStr != NULL) {
2952 FromText = mUefiDevicePathLibDevPathFromTextTable[Index].Function;
2953 break;
2954 }
2955 }
2956
2957 if (FromText == NULL) {
2958 //
2959 // A file path
2960 //
2961 FromText = DevPathFromTextFilePath;
2962 DeviceNode = FromText (DeviceNodeStr);
2963 } else {
2964 DeviceNode = FromText (ParamStr);
2965 FreePool (ParamStr);
2966 }
2967
2968 FreePool (DeviceNodeStr);
2969
2970 return DeviceNode;
2971 }
2972
2973 /**
2974 Convert text to the binary representation of a device path.
2975
2976
2977 @param TextDevicePath TextDevicePath points to the text representation of a device
2978 path. Conversion starts with the first character and continues
2979 until the first non-device node character.
2980
2981 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
2982 there was insufficient memory.
2983
2984 **/
2985 EFI_DEVICE_PATH_PROTOCOL *
2986 EFIAPI
2987 UefiDevicePathLibConvertTextToDevicePath (
2988 IN CONST CHAR16 *TextDevicePath
2989 )
2990 {
2991 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
2992 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
2993 CHAR16 *DevicePathStr;
2994 CHAR16 *Str;
2995 CHAR16 *DeviceNodeStr;
2996 BOOLEAN IsInstanceEnd;
2997 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
2998
2999 if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
3000 return NULL;
3001 }
3002
3003 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
3004 ASSERT (DevicePath != NULL);
3005 SetDevicePathEndNode (DevicePath);
3006
3007 DevicePathStr = UefiDevicePathLibStrDuplicate (TextDevicePath);
3008
3009 Str = DevicePathStr;
3010 while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
3011 DeviceNode = UefiDevicePathLibConvertTextToDeviceNode (DeviceNodeStr);
3012
3013 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3014 FreePool (DevicePath);
3015 FreePool (DeviceNode);
3016 DevicePath = NewDevicePath;
3017
3018 if (IsInstanceEnd) {
3019 DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
3020 ASSERT (DeviceNode != NULL);
3021 SetDevicePathEndNode (DeviceNode);
3022
3023 NewDevicePath = AppendDevicePathNode (DevicePath, DeviceNode);
3024 FreePool (DevicePath);
3025 FreePool (DeviceNode);
3026 DevicePath = NewDevicePath;
3027 }
3028 }
3029
3030 FreePool (DevicePathStr);
3031 return DevicePath;
3032 }