aff628b54affd17f0953a9429c87d995573a997c
[mirror_edk2.git] / EdkModulePkg / Universal / DevicePath / Dxe / DevicePathFromText.c
1 /*++
2
3 Copyright (c) 2006, 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
8
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.
11
12 Module Name:
13
14 DevicePathFromText.c
15
16 Abstract:
17
18 DevicePathFromText protocol as defined in the UEFI 2.0 specification.
19
20 --*/
21
22 #include "DevicePath.h"
23
24 CHAR16 *
25 StrDuplicate (
26 IN CONST CHAR16 *Src
27 )
28 /*++
29
30 Routine Description:
31 Duplicate a string
32
33 Arguments:
34 Src - Source string
35
36 Returns:
37 Duplicated string
38
39 --*/
40 {
41 UINTN Length;
42 CHAR16 *ReturnStr;
43
44 Length = StrLen ((CHAR16 *) Src);
45
46 ReturnStr = AllocateCopyPool ((Length + 1) * sizeof (CHAR16), (VOID *) Src);
47
48 return ReturnStr;
49 }
50
51 CHAR16 *
52 GetParamByNodeName (
53 IN CHAR16 *Str,
54 IN CHAR16 *NodeName
55 )
56 /*++
57
58 Routine Description:
59 Get parameter in a pair of parentheses follow the given node name.
60 For example, given the "Pci(0,1)" and NodeName "Pci", it returns "0,1".
61
62 Arguments:
63 Str - Device Path Text
64 NodeName - Name of the node
65
66 Returns:
67 Parameter text for the node
68
69 --*/
70 {
71 CHAR16 *ParamStr;
72 CHAR16 *StrPointer;
73 UINTN NodeNameLength;
74 UINTN ParameterLength;
75
76 //
77 // Check whether the node name matchs
78 //
79 NodeNameLength = StrLen (NodeName);
80 if (CompareMem (Str, NodeName, NodeNameLength * sizeof (CHAR16)) != 0) {
81 return NULL;
82 }
83
84 ParamStr = Str + NodeNameLength;
85 if (!IS_LEFT_PARENTH (*ParamStr)) {
86 return NULL;
87 }
88
89 //
90 // Skip the found '(' and find first occurrence of ')'
91 //
92 ParamStr++;
93 ParameterLength = 0;
94 StrPointer = ParamStr;
95 while (!IS_NULL (*StrPointer)) {
96 if (IS_RIGHT_PARENTH (*StrPointer)) {
97 break;
98 }
99 StrPointer++;
100 ParameterLength++;
101 }
102 if (IS_NULL (*StrPointer)) {
103 //
104 // ')' not found
105 //
106 return NULL;
107 }
108
109 ParamStr = AllocateCopyPool ((ParameterLength + 1) * sizeof (CHAR16), ParamStr);
110 if (ParamStr == NULL) {
111 return NULL;
112 }
113 //
114 // Terminate the parameter string
115 //
116 ParamStr[ParameterLength] = L'\0';
117
118 return ParamStr;
119 }
120
121 CHAR16 *
122 SplitStr (
123 IN OUT CHAR16 **List,
124 IN CHAR16 Separator
125 )
126 /*++
127
128 Routine Description:
129 Get current sub-string from a string list, before return
130 the list header is moved to next sub-string. The sub-string is separated
131 by the specified character. For example, the separator is ',', the string
132 list is "2,0,3", it returns "2", the remain list move to "2,3"
133
134 Arguments:
135 List - A string list separated by the specified separator
136 Separator - The separator character
137
138 Returns:
139 pointer - The current sub-string
140
141 --*/
142 {
143 CHAR16 *Str;
144 CHAR16 *ReturnStr;
145
146 Str = *List;
147 ReturnStr = Str;
148
149 if (IS_NULL (*Str)) {
150 return ReturnStr;
151 }
152
153 //
154 // Find first occurrence of the separator
155 //
156 while (!IS_NULL (*Str)) {
157 if (*Str == Separator) {
158 break;
159 }
160 Str++;
161 }
162
163 if (*Str == Separator) {
164 //
165 // Find a sub-string, terminate it
166 //
167 *Str = L'\0';
168 Str++;
169 }
170
171 //
172 // Move to next sub-string
173 //
174 *List = Str;
175
176 return ReturnStr;
177 }
178
179 CHAR16 *
180 GetNextParamStr (
181 IN OUT CHAR16 **List
182 )
183 {
184 //
185 // The separator is comma
186 //
187 return SplitStr (List, L',');
188 }
189
190 CHAR16 *
191 GetNextDeviceNodeStr (
192 IN OUT CHAR16 **DevicePath,
193 OUT BOOLEAN *IsInstanceEnd
194 )
195 /*++
196
197 Routine Description:
198 Get one device node from entire device path text.
199
200 Arguments:
201 Str - The entire device path text string
202 IsInstanceEnd - This node is the end of a device path instance
203
204 Returns:
205 a pointer - A device node text
206 NULL - No more device node available
207
208 --*/
209 {
210 CHAR16 *Str;
211 CHAR16 *ReturnStr;
212 UINTN ParenthesesStack;
213
214 Str = *DevicePath;
215 if (IS_NULL (*Str)) {
216 return NULL;
217 }
218
219 //
220 // Skip the leading '/', '(', ')' and ','
221 //
222 while (!IS_NULL (*Str)) {
223 if (!IS_SLASH (*Str) &&
224 !IS_COMMA (*Str) &&
225 !IS_LEFT_PARENTH (*Str) &&
226 !IS_RIGHT_PARENTH (*Str)) {
227 break;
228 }
229 Str++;
230 }
231
232 ReturnStr = Str;
233
234 //
235 // Scan for the separator of this device node, '/' or ','
236 //
237 ParenthesesStack = 0;
238 while (!IS_NULL (*Str)) {
239 if ((IS_COMMA (*Str) || IS_SLASH (*Str)) && (ParenthesesStack == 0)) {
240 break;
241 }
242
243 if (IS_LEFT_PARENTH (*Str)) {
244 ParenthesesStack++;
245 } else if (IS_RIGHT_PARENTH (*Str)) {
246 ParenthesesStack--;
247 }
248
249 Str++;
250 }
251
252 if (ParenthesesStack != 0) {
253 //
254 // The '(' doesn't pair with ')', invalid device path text
255 //
256 return NULL;
257 }
258
259 if (IS_COMMA (*Str)) {
260 *IsInstanceEnd = TRUE;
261 *Str = L'\0';
262 Str++;
263 } else {
264 *IsInstanceEnd = FALSE;
265 if (!IS_NULL (*Str)) {
266 *Str = L'\0';
267 Str++;
268 }
269 }
270
271 *DevicePath = Str;
272
273 return ReturnStr;
274 }
275
276 BOOLEAN
277 IsHexDigit (
278 OUT UINT8 *Digit,
279 IN CHAR16 Char
280 )
281 /*++
282
283 Routine Description:
284 Determines if a Unicode character is a hexadecimal digit.
285 The test is case insensitive.
286
287 Arguments:
288 Digit - Pointer to byte that receives the value of the hex character.
289 Char - Unicode character to test.
290
291 Returns:
292 TRUE - If the character is a hexadecimal digit.
293 FALSE - Otherwise.
294
295 --*/
296 {
297 if ((Char >= L'0') && (Char <= L'9')) {
298 *Digit = (UINT8) (Char - L'0');
299 return TRUE;
300 }
301
302 if ((Char >= L'A') && (Char <= L'F')) {
303 *Digit = (UINT8) (Char - L'A' + 0x0A);
304 return TRUE;
305 }
306
307 if ((Char >= L'a') && (Char <= L'f')) {
308 *Digit = (UINT8) (Char - L'a' + 0x0A);
309 return TRUE;
310 }
311
312 return FALSE;
313 }
314
315 CHAR16
316 NibbleToHexChar (
317 IN UINT8 Nibble
318 )
319 /*++
320
321 Routine Description:
322 Converts the low nibble of a byte to hex unicode character.
323
324 Arguments:
325 Nibble - lower nibble of a byte.
326
327 Returns:
328 Hex unicode character.
329
330 --*/
331 {
332 Nibble &= 0x0F;
333 if (Nibble <= 0x9) {
334 return (CHAR16)(Nibble + L'0');
335 }
336
337 return (CHAR16)(Nibble - 0xA + L'A');
338 }
339
340 EFI_STATUS
341 HexStringToBuf (
342 IN OUT UINT8 *Buf,
343 IN OUT UINTN *Len,
344 IN CHAR16 *Str,
345 OUT UINTN *ConvertedStrLen OPTIONAL
346 )
347 /*++
348
349 Routine Description:
350 Converts Unicode string to binary buffer.
351 The conversion may be partial.
352 The first character in the string that is not hex digit stops the conversion.
353 At a minimum, any blob of data could be represented as a hex string.
354
355 Arguments:
356 Buf - Pointer to buffer that receives the data.
357 Len - Length in bytes of the buffer to hold converted data.
358 If routine return with EFI_SUCCESS, containing length of converted data.
359 If routine return with EFI_BUFFER_TOO_SMALL, containg length of buffer desired.
360 Str - String to be converted from.
361 ConvertedStrLen - Length of the Hex String consumed.
362
363 Returns:
364 EFI_SUCCESS: Routine Success.
365 EFI_BUFFER_TOO_SMALL: The buffer is too small to hold converted data.
366 EFI_
367
368 --*/
369 {
370 UINTN HexCnt;
371 UINTN Idx;
372 UINTN BufferLength;
373 UINT8 Digit;
374 UINT8 Byte;
375
376 //
377 // Find out how many hex characters the string has.
378 //
379 for (Idx = 0, HexCnt = 0; IsHexDigit (&Digit, Str[Idx]); Idx++, HexCnt++);
380
381 if (HexCnt == 0) {
382 *Len = 0;
383 return EFI_SUCCESS;
384 }
385 //
386 // Two Unicode characters make up 1 buffer byte. Round up.
387 //
388 BufferLength = (HexCnt + 1) / 2;
389
390 //
391 // Test if buffer is passed enough.
392 //
393 if (BufferLength > (*Len)) {
394 *Len = BufferLength;
395 return EFI_BUFFER_TOO_SMALL;
396 }
397
398 *Len = BufferLength;
399
400 for (Idx = 0; Idx < HexCnt; Idx++) {
401
402 IsHexDigit (&Digit, Str[HexCnt - 1 - Idx]);
403
404 //
405 // For odd charaters, write the lower nibble for each buffer byte,
406 // and for even characters, the upper nibble.
407 //
408 if ((Idx & 1) == 0) {
409 Byte = Digit;
410 } else {
411 Byte = Buf[Idx / 2];
412 Byte &= 0x0F;
413 Byte |= Digit << 4;
414 }
415
416 Buf[Idx / 2] = Byte;
417 }
418
419 if (ConvertedStrLen != NULL) {
420 *ConvertedStrLen = HexCnt;
421 }
422
423 return EFI_SUCCESS;
424 }
425
426 EFI_STATUS
427 BufToHexString (
428 IN OUT CHAR16 *Str,
429 IN OUT UINTN *HexStringBufferLength,
430 IN UINT8 *Buf,
431 IN UINTN Len
432 )
433 /*++
434
435 Routine Description:
436 Converts binary buffer to Unicode string.
437 At a minimum, any blob of data could be represented as a hex string.
438
439 Arguments:
440 Str - Pointer to the string.
441 HexStringBufferLength - Length in bytes of buffer to hold the hex string. Includes tailing '\0' character.
442 If routine return with EFI_SUCCESS, containing length of hex string buffer.
443 If routine return with EFI_BUFFER_TOO_SMALL, containg length of hex string buffer desired.
444 Buf - Buffer to be converted from.
445 Len - Length in bytes of the buffer to be converted.
446
447 Returns:
448 EFI_SUCCESS: Routine success.
449 EFI_BUFFER_TOO_SMALL: The hex string buffer is too small.
450
451 --*/
452 {
453 UINTN Idx;
454 UINT8 Byte;
455 UINTN StrLen;
456
457 //
458 // Make sure string is either passed or allocate enough.
459 // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.
460 // Plus the Unicode termination character.
461 //
462 StrLen = Len * 2;
463 if (StrLen > ((*HexStringBufferLength) - 1)) {
464 *HexStringBufferLength = StrLen + 1;
465 return EFI_BUFFER_TOO_SMALL;
466 }
467
468 *HexStringBufferLength = StrLen + 1;
469 //
470 // Ends the string.
471 //
472 Str[StrLen] = L'\0';
473
474 for (Idx = 0; Idx < Len; Idx++) {
475
476 Byte = Buf[Idx];
477 Str[StrLen - 1 - Idx * 2] = NibbleToHexChar (Byte);
478 Str[StrLen - 2 - Idx * 2] = NibbleToHexChar ((UINT8)(Byte >> 4));
479 }
480
481 return EFI_SUCCESS;
482 }
483
484 CHAR16 *
485 TrimHexStr (
486 IN CHAR16 *Str
487 )
488 /*++
489
490 Routine Description:
491 Skip the leading white space and '0x' or '0X' of a hex string
492
493 Arguments:
494 Str - The hex string
495
496 Returns:
497
498 --*/
499 {
500 //
501 // skip preceeding white space
502 //
503 while (*Str && *Str == ' ') {
504 Str += 1;
505 }
506 //
507 // skip preceeding zeros
508 //
509 while (*Str && *Str == '0') {
510 Str += 1;
511 }
512 //
513 // skip preceeding character 'x' or 'X'
514 //
515 if (*Str && (*Str == 'x' || *Str == 'X')) {
516 Str += 1;
517 }
518
519 return Str;
520 }
521
522 UINTN
523 Xtoi (
524 IN CHAR16 *Str
525 )
526 /*++
527
528 Routine Description:
529
530 Convert hex string to uint
531
532 Arguments:
533
534 Str - The string
535
536 Returns:
537
538 --*/
539 {
540 UINTN Rvalue;
541 UINTN Length;
542
543 ASSERT (Str != NULL);
544
545 //
546 // convert hex digits
547 //
548 Rvalue = 0;
549 Length = sizeof (UINTN);
550 HexStringToBuf ((UINT8 *) &Rvalue, &Length, TrimHexStr (Str), NULL);
551
552 return Rvalue;
553 }
554
555 VOID
556 Xtoi64 (
557 IN CHAR16 *Str,
558 IN UINT64 *Data
559 )
560 /*++
561
562 Routine Description:
563
564 Convert hex string to 64 bit data.
565
566 Arguments:
567
568 Str - The string
569
570 Returns:
571
572 --*/
573 {
574 UINTN Length;
575
576 *Data = 0;
577 Length = sizeof (UINT64);
578 HexStringToBuf ((UINT8 *) Data, &Length, TrimHexStr (Str), NULL);
579 }
580
581 UINTN
582 Atoi (
583 IN CHAR16 *str
584 )
585 /*++
586
587 Routine Description:
588
589 Convert decimal string to uint
590
591 Arguments:
592
593 Str - The string
594
595 Returns:
596
597 --*/
598 {
599 UINTN Rvalue;
600 CHAR16 Char;
601 UINTN High;
602 UINTN Low;
603
604 ASSERT (str != NULL);
605
606 High = (UINTN) -1 / 10;
607 Low = (UINTN) -1 % 10;
608 //
609 // skip preceeding white space
610 //
611 while (*str && *str == ' ') {
612 str += 1;
613 }
614 //
615 // convert digits
616 //
617 Rvalue = 0;
618 Char = *(str++);
619 while (Char) {
620 if (Char >= '0' && Char <= '9') {
621 if ((Rvalue > High || Rvalue == High) && (Char - '0' > (INTN) Low)) {
622 return (UINTN) -1;
623 }
624
625 Rvalue = (Rvalue * 10) + Char - '0';
626 } else {
627 break;
628 }
629
630 Char = *(str++);
631 }
632
633 return Rvalue;
634 }
635
636 EFI_STATUS
637 StrToBuf (
638 OUT UINT8 *Buf,
639 IN UINTN BufferLength,
640 IN CHAR16 *Str
641 )
642 {
643 UINTN Index;
644 UINTN StrLength;
645 UINT8 Digit;
646 UINT8 Byte;
647
648 //
649 // Two hex char make up one byte
650 //
651 StrLength = BufferLength * sizeof (CHAR16);
652
653 for(Index = 0; Index < StrLength; Index++, Str++) {
654
655 IsHexDigit (&Digit, *Str);
656
657 //
658 // For odd charaters, write the upper nibble for each buffer byte,
659 // and for even characters, the lower nibble.
660 //
661 if ((Index & 1) == 0) {
662 Byte = Digit << 4;
663 } else {
664 Byte = Buf[Index / 2];
665 Byte &= 0xF0;
666 Byte |= Digit;
667 }
668
669 Buf[Index / 2] = Byte;
670 }
671
672 return EFI_SUCCESS;
673 }
674
675 EFI_STATUS
676 StrToGuid (
677 IN CHAR16 *Str,
678 OUT EFI_GUID *Guid
679 )
680 {
681 UINTN BufferLength;
682 UINTN ConvertedStrLen;
683 EFI_STATUS Status;
684
685 BufferLength = sizeof (Guid->Data1);
686 Status = HexStringToBuf ((UINT8 *) &Guid->Data1, &BufferLength, Str, &ConvertedStrLen);
687 if (EFI_ERROR (Status)) {
688 return Status;
689 }
690 Str += ConvertedStrLen;
691 if (IS_HYPHEN (*Str)) {
692 Str++;
693 } else {
694 return EFI_UNSUPPORTED;
695 }
696
697 BufferLength = sizeof (Guid->Data2);
698 Status = HexStringToBuf ((UINT8 *) &Guid->Data2, &BufferLength, Str, &ConvertedStrLen);
699 if (EFI_ERROR (Status)) {
700 return Status;
701 }
702 Str += ConvertedStrLen;
703 if (IS_HYPHEN (*Str)) {
704 Str++;
705 } else {
706 return EFI_UNSUPPORTED;
707 }
708
709 BufferLength = sizeof (Guid->Data3);
710 Status = HexStringToBuf ((UINT8 *) &Guid->Data3, &BufferLength, Str, &ConvertedStrLen);
711 if (EFI_ERROR (Status)) {
712 return Status;
713 }
714 Str += ConvertedStrLen;
715 if (IS_HYPHEN (*Str)) {
716 Str++;
717 } else {
718 return EFI_UNSUPPORTED;
719 }
720
721 StrToBuf (&Guid->Data4[0], 2, Str);
722 //
723 // Skip 2 byte hex chars
724 //
725 Str += 2 * 2;
726
727 if (IS_HYPHEN (*Str)) {
728 Str++;
729 } else {
730 return EFI_UNSUPPORTED;
731 }
732 StrToBuf (&Guid->Data4[2], 6, Str);
733
734 return EFI_SUCCESS;
735 }
736
737 VOID
738 StrToIPv4Addr (
739 IN OUT CHAR16 **Str,
740 OUT EFI_IPv4_ADDRESS *IPv4Addr
741 )
742 {
743 UINTN Index;
744
745 for (Index = 0; Index < 4; Index++) {
746 IPv4Addr->Addr[Index] = (UINT8) Atoi (SplitStr (Str, L'.'));
747 }
748 }
749
750 VOID
751 StrToIPv6Addr (
752 IN OUT CHAR16 **Str,
753 OUT EFI_IPv6_ADDRESS *IPv6Addr
754 )
755 {
756 UINTN Index;
757 UINT16 Data;
758
759 for (Index = 0; Index < 8; Index++) {
760 Data = (UINT16) Xtoi (SplitStr (Str, L':'));
761 IPv6Addr->Addr[Index * 2] = (UINT8) (Data >> 8);
762 IPv6Addr->Addr[Index * 2 + 1] = (UINT8) (Data & 0xff);
763 }
764 }
765
766 VOID
767 StrToAscii (
768 IN CHAR16 *Str,
769 IN OUT CHAR8 **AsciiStr
770 )
771 {
772 CHAR8 *Dest;
773
774 Dest = *AsciiStr;
775 while (!IS_NULL (*Str)) {
776 *(Dest++) = (CHAR8) *(Str++);
777 }
778 *Dest = 0;
779
780 //
781 // Return the string next to it
782 //
783 *AsciiStr = Dest + 1;
784 }
785
786 EFI_DEVICE_PATH_PROTOCOL *
787 DevPathFromTextPci (
788 IN CHAR16 *TextDeviceNode
789 )
790 {
791 CHAR16 *FunctionStr;
792 CHAR16 *DeviceStr;
793 PCI_DEVICE_PATH *Pci;
794
795 FunctionStr = GetNextParamStr (&TextDeviceNode);
796 DeviceStr = GetNextParamStr (&TextDeviceNode);
797 Pci = (PCI_DEVICE_PATH *) CreateDeviceNode (
798 HARDWARE_DEVICE_PATH,
799 HW_PCI_DP,
800 sizeof (PCI_DEVICE_PATH)
801 );
802
803 Pci->Function = (UINT8) Xtoi (FunctionStr);
804 Pci->Device = (UINT8) Xtoi (DeviceStr);
805
806 return (EFI_DEVICE_PATH_PROTOCOL *) Pci;
807 }
808
809 EFI_DEVICE_PATH_PROTOCOL *
810 DevPathFromTextPcCard (
811 IN CHAR16 *TextDeviceNode
812 )
813 {
814 CHAR16 *FunctionNumberStr;
815 PCCARD_DEVICE_PATH *Pccard;
816
817 FunctionNumberStr = GetNextParamStr (&TextDeviceNode);
818 Pccard = (PCCARD_DEVICE_PATH *) CreateDeviceNode (
819 HARDWARE_DEVICE_PATH,
820 HW_PCCARD_DP,
821 sizeof (PCCARD_DEVICE_PATH)
822 );
823
824 Pccard->FunctionNumber = (UINT8) Xtoi (FunctionNumberStr);
825
826 return (EFI_DEVICE_PATH_PROTOCOL *) Pccard;
827 }
828
829 EFI_DEVICE_PATH_PROTOCOL *
830 DevPathFromTextMemoryMapped (
831 IN CHAR16 *TextDeviceNode
832 )
833 {
834 CHAR16 *StartingAddressStr;
835 CHAR16 *EndingAddressStr;
836 MEMMAP_DEVICE_PATH *MemMap;
837
838 StartingAddressStr = GetNextParamStr (&TextDeviceNode);
839 EndingAddressStr = GetNextParamStr (&TextDeviceNode);
840 MemMap = (MEMMAP_DEVICE_PATH *) CreateDeviceNode (
841 HARDWARE_DEVICE_PATH,
842 HW_MEMMAP_DP,
843 sizeof (MEMMAP_DEVICE_PATH)
844 );
845
846 MemMap->MemoryType = 0;
847
848 Xtoi64 (StartingAddressStr, &MemMap->StartingAddress);
849 Xtoi64 (EndingAddressStr, &MemMap->EndingAddress);
850
851 return (EFI_DEVICE_PATH_PROTOCOL *) MemMap;
852 }
853
854 EFI_DEVICE_PATH_PROTOCOL *
855 ConvertFromTextVendor (
856 IN CHAR16 *TextDeviceNode,
857 IN UINT8 Type,
858 IN UINT8 SubType
859 )
860 {
861 CHAR16 *GuidStr;
862 CHAR16 *DataStr;
863 UINTN Length;
864 VENDOR_DEVICE_PATH *Vendor;
865
866 GuidStr = GetNextParamStr (&TextDeviceNode);
867
868 DataStr = GetNextParamStr (&TextDeviceNode);
869 Length = StrLen (DataStr);
870 //
871 // Two hex characters make up 1 buffer byte
872 //
873 Length = (Length + 1) / 2;
874
875 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
876 Type,
877 SubType,
878 sizeof (VENDOR_DEVICE_PATH) + (UINT16) Length
879 );
880
881 StrToGuid (GuidStr, &Vendor->Guid);
882 StrToBuf (((UINT8 *) Vendor) + sizeof (VENDOR_DEVICE_PATH), Length, DataStr);
883
884 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
885 }
886
887 EFI_DEVICE_PATH_PROTOCOL *
888 DevPathFromTextVenHw (
889 IN CHAR16 *TextDeviceNode
890 )
891 {
892 return ConvertFromTextVendor (
893 TextDeviceNode,
894 HARDWARE_DEVICE_PATH,
895 HW_VENDOR_DP
896 );
897 }
898
899 EFI_DEVICE_PATH_PROTOCOL *
900 DevPathFromTextCtrl (
901 IN CHAR16 *TextDeviceNode
902 )
903 {
904 CHAR16 *ControllerStr;
905 CONTROLLER_DEVICE_PATH *Controller;
906
907 ControllerStr = GetNextParamStr (&TextDeviceNode);
908 Controller = (CONTROLLER_DEVICE_PATH *) CreateDeviceNode (
909 HARDWARE_DEVICE_PATH,
910 HW_CONTROLLER_DP,
911 sizeof (CONTROLLER_DEVICE_PATH)
912 );
913 Controller->ControllerNumber = (UINT32) Xtoi (ControllerStr);
914
915 return (EFI_DEVICE_PATH_PROTOCOL *) Controller;
916 }
917
918 EFI_DEVICE_PATH_PROTOCOL *
919 DevPathFromTextAcpi (
920 IN CHAR16 *TextDeviceNode
921 )
922 {
923 CHAR16 *HIDStr;
924 CHAR16 *UIDStr;
925 ACPI_HID_DEVICE_PATH *Acpi;
926
927 HIDStr = GetNextParamStr (&TextDeviceNode);
928 UIDStr = GetNextParamStr (&TextDeviceNode);
929 Acpi = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
930 ACPI_DEVICE_PATH,
931 ACPI_DP,
932 sizeof (ACPI_HID_DEVICE_PATH)
933 );
934
935 if ((HIDStr[0] == L'P') && (HIDStr[1] == L'N') && (HIDStr[2] == L'P')) {
936 HIDStr += 3;
937 }
938
939 Acpi->HID = EISA_PNP_ID (Xtoi (HIDStr));
940 Acpi->UID = (UINT32) Xtoi (UIDStr);
941
942 return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
943 }
944
945 EFI_DEVICE_PATH_PROTOCOL *
946 ConvertFromTextAcpi (
947 IN CHAR16 *TextDeviceNode,
948 IN UINT32 Hid
949 )
950 {
951 CHAR16 *UIDStr;
952 ACPI_HID_DEVICE_PATH *Acpi;
953
954 UIDStr = GetNextParamStr (&TextDeviceNode);
955 Acpi = (ACPI_HID_DEVICE_PATH *) CreateDeviceNode (
956 ACPI_DEVICE_PATH,
957 ACPI_DP,
958 sizeof (ACPI_HID_DEVICE_PATH)
959 );
960
961 Acpi->HID = Hid;
962 Acpi->UID = (UINT32) Xtoi (UIDStr);
963
964 return (EFI_DEVICE_PATH_PROTOCOL *) Acpi;
965 }
966
967 EFI_DEVICE_PATH_PROTOCOL *
968 DevPathFromTextPciRoot (
969 IN CHAR16 *TextDeviceNode
970 )
971 {
972 return ConvertFromTextAcpi (TextDeviceNode, 0x0a0341d0);
973 }
974
975 EFI_DEVICE_PATH_PROTOCOL *
976 DevPathFromTextFloppy (
977 IN CHAR16 *TextDeviceNode
978 )
979 {
980 return ConvertFromTextAcpi (TextDeviceNode, 0x060441d0);
981 }
982
983 EFI_DEVICE_PATH_PROTOCOL *
984 DevPathFromTextKeyboard (
985 IN CHAR16 *TextDeviceNode
986 )
987 {
988 return ConvertFromTextAcpi (TextDeviceNode, 0x030141d0);
989 }
990
991 EFI_DEVICE_PATH_PROTOCOL *
992 DevPathFromTextSerial (
993 IN CHAR16 *TextDeviceNode
994 )
995 {
996 return ConvertFromTextAcpi (TextDeviceNode, 0x050141d0);
997 }
998
999 EFI_DEVICE_PATH_PROTOCOL *
1000 DevPathFromTextParallelPort (
1001 IN CHAR16 *TextDeviceNode
1002 )
1003 {
1004 return ConvertFromTextAcpi (TextDeviceNode, 0x040141d0);
1005 }
1006
1007 EFI_DEVICE_PATH_PROTOCOL *
1008 DevPathFromTextAcpiEx (
1009 IN CHAR16 *TextDeviceNode
1010 )
1011 {
1012 CHAR16 *HIDStr;
1013 CHAR16 *CIDStr;
1014 CHAR16 *UIDStr;
1015 CHAR16 *HIDSTRStr;
1016 CHAR16 *CIDSTRStr;
1017 CHAR16 *UIDSTRStr;
1018 CHAR8 *AsciiStr;
1019 UINT16 Length;
1020 ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR *AcpiExt;
1021
1022 HIDStr = GetNextParamStr (&TextDeviceNode);
1023 CIDStr = GetNextParamStr (&TextDeviceNode);
1024 UIDStr = GetNextParamStr (&TextDeviceNode);
1025 HIDSTRStr = GetNextParamStr (&TextDeviceNode);
1026 CIDSTRStr = GetNextParamStr (&TextDeviceNode);
1027 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
1028 Length = sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) +
1029 (UINT16) StrLen (HIDSTRStr) + 1 +
1030 (UINT16) StrLen (UIDSTRStr) + 1 +
1031 (UINT16) StrLen (CIDSTRStr) + 1;
1032 AcpiExt = (ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR *) CreateDeviceNode (
1033 ACPI_DEVICE_PATH,
1034 ACPI_EXTENDED_DP,
1035 Length
1036 );
1037
1038 if ((HIDStr[0] == L'P') && (HIDStr[1] == L'N') && (HIDStr[2] == L'P')) {
1039 HIDStr += 3;
1040 AcpiExt->HID = EISA_PNP_ID (Xtoi (HIDStr));
1041 } else {
1042 AcpiExt->HID = (UINT32) Xtoi (HIDStr);
1043 }
1044
1045 AcpiExt->UID = (UINT32) Xtoi (UIDStr);
1046 AcpiExt->CID = (UINT32) Xtoi (CIDStr);
1047
1048 AsciiStr = AcpiExt->HidUidCidStr;
1049 StrToAscii (HIDSTRStr, &AsciiStr);
1050 StrToAscii (UIDSTRStr, &AsciiStr);
1051 StrToAscii (CIDSTRStr, &AsciiStr);
1052
1053 return (EFI_DEVICE_PATH_PROTOCOL *) AcpiExt;
1054 }
1055
1056 EFI_DEVICE_PATH_PROTOCOL *
1057 DevPathFromTextAcpiExp (
1058 IN CHAR16 *TextDeviceNode
1059 )
1060 {
1061 CHAR16 *HIDStr;
1062 CHAR16 *CIDStr;
1063 CHAR16 *UIDSTRStr;
1064 CHAR8 *AsciiStr;
1065 UINT16 Length;
1066 ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR *AcpiExt;
1067
1068 HIDStr = GetNextParamStr (&TextDeviceNode);
1069 CIDStr = GetNextParamStr (&TextDeviceNode);
1070 UIDSTRStr = GetNextParamStr (&TextDeviceNode);
1071 Length = sizeof (ACPI_EXTENDED_HID_DEVICE_PATH) + (UINT16) StrLen (UIDSTRStr) + 3;
1072 AcpiExt = (ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR *) CreateDeviceNode (
1073 ACPI_DEVICE_PATH,
1074 ACPI_EXTENDED_DP,
1075 Length
1076 );
1077
1078 if ((HIDStr[0] == L'P') && (HIDStr[1] == L'N') && (HIDStr[2] == L'P')) {
1079 HIDStr += 3;
1080 AcpiExt->HID = EISA_PNP_ID (Xtoi (HIDStr));
1081 } else {
1082 AcpiExt->HID = (UINT32) Xtoi (HIDStr);
1083 }
1084
1085 AcpiExt->UID = 0;
1086 AcpiExt->CID = (UINT32) Xtoi (CIDStr);
1087
1088 AsciiStr = AcpiExt->HidUidCidStr;
1089 //
1090 // HID string is NULL
1091 //
1092 *AsciiStr = 0;
1093 //
1094 // Convert UID string
1095 //
1096 AsciiStr++;
1097 StrToAscii (UIDSTRStr, &AsciiStr);
1098 //
1099 // CID string is NULL
1100 //
1101 *AsciiStr = 0;
1102
1103 return (EFI_DEVICE_PATH_PROTOCOL *) AcpiExt;
1104 }
1105
1106 EFI_DEVICE_PATH_PROTOCOL *
1107 DevPathFromTextAta (
1108 IN CHAR16 *TextDeviceNode
1109 )
1110 {
1111 CHAR16 *PrimarySecondaryStr;
1112 CHAR16 *SlaveMasterStr;
1113 CHAR16 *LunStr;
1114 ATAPI_DEVICE_PATH *Atapi;
1115
1116 Atapi = (ATAPI_DEVICE_PATH *) CreateDeviceNode (
1117 MESSAGING_DEVICE_PATH,
1118 MSG_ATAPI_DP,
1119 sizeof (ATAPI_DEVICE_PATH)
1120 );
1121
1122 PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
1123 SlaveMasterStr = GetNextParamStr (&TextDeviceNode);
1124 LunStr = GetNextParamStr (&TextDeviceNode);
1125
1126 Atapi->PrimarySecondary = (StrCmp (PrimarySecondaryStr, L"Primary") == 0) ? (UINT8) 0 : (UINT8) 1;
1127 Atapi->SlaveMaster = (StrCmp (SlaveMasterStr, L"Master") == 0) ? (UINT8) 0 : (UINT8) 1;
1128 Atapi->Lun = (UINT16) Xtoi (LunStr);
1129
1130 return (EFI_DEVICE_PATH_PROTOCOL *) Atapi;
1131 }
1132
1133 EFI_DEVICE_PATH_PROTOCOL *
1134 DevPathFromTextScsi (
1135 IN CHAR16 *TextDeviceNode
1136 )
1137 {
1138 CHAR16 *PunStr;
1139 CHAR16 *LunStr;
1140 SCSI_DEVICE_PATH *Scsi;
1141
1142 PunStr = GetNextParamStr (&TextDeviceNode);
1143 LunStr = GetNextParamStr (&TextDeviceNode);
1144 Scsi = (SCSI_DEVICE_PATH *) CreateDeviceNode (
1145 MESSAGING_DEVICE_PATH,
1146 MSG_SCSI_DP,
1147 sizeof (SCSI_DEVICE_PATH)
1148 );
1149
1150 Scsi->Pun = (UINT16) Xtoi (PunStr);
1151 Scsi->Lun = (UINT16) Xtoi (LunStr);
1152
1153 return (EFI_DEVICE_PATH_PROTOCOL *) Scsi;
1154 }
1155
1156 EFI_DEVICE_PATH_PROTOCOL *
1157 DevPathFromTextFibre (
1158 IN CHAR16 *TextDeviceNode
1159 )
1160 {
1161 CHAR16 *WWNStr;
1162 CHAR16 *LunStr;
1163 FIBRECHANNEL_DEVICE_PATH *Fibre;
1164
1165 WWNStr = GetNextParamStr (&TextDeviceNode);
1166 LunStr = GetNextParamStr (&TextDeviceNode);
1167 Fibre = (FIBRECHANNEL_DEVICE_PATH *) CreateDeviceNode (
1168 MESSAGING_DEVICE_PATH,
1169 MSG_FIBRECHANNEL_DP,
1170 sizeof (FIBRECHANNEL_DEVICE_PATH)
1171 );
1172
1173 Fibre->Reserved = 0;
1174 Xtoi64 (WWNStr, &Fibre->WWN);
1175 Xtoi64 (LunStr, &Fibre->Lun);
1176
1177 return (EFI_DEVICE_PATH_PROTOCOL *) Fibre;
1178 }
1179
1180 EFI_DEVICE_PATH_PROTOCOL *
1181 DevPathFromText1394 (
1182 IN CHAR16 *TextDeviceNode
1183 )
1184 {
1185 CHAR16 *GuidStr;
1186 F1394_DEVICE_PATH *F1394;
1187
1188 GuidStr = GetNextParamStr (&TextDeviceNode);
1189 F1394 = (F1394_DEVICE_PATH *) CreateDeviceNode (
1190 MESSAGING_DEVICE_PATH,
1191 MSG_1394_DP,
1192 sizeof (F1394_DEVICE_PATH)
1193 );
1194
1195 F1394->Reserved = 0;
1196 Xtoi64 (GuidStr, &F1394->Guid);
1197
1198 return (EFI_DEVICE_PATH_PROTOCOL *) F1394;
1199 }
1200
1201 EFI_DEVICE_PATH_PROTOCOL *
1202 DevPathFromTextUsb (
1203 IN CHAR16 *TextDeviceNode
1204 )
1205 {
1206 CHAR16 *PortStr;
1207 CHAR16 *InterfaceStr;
1208 USB_DEVICE_PATH *Usb;
1209
1210 PortStr = GetNextParamStr (&TextDeviceNode);
1211 InterfaceStr = GetNextParamStr (&TextDeviceNode);
1212 Usb = (USB_DEVICE_PATH *) CreateDeviceNode (
1213 MESSAGING_DEVICE_PATH,
1214 MSG_USB_DP,
1215 sizeof (USB_DEVICE_PATH)
1216 );
1217
1218 Usb->ParentPortNumber = (UINT8) Xtoi (PortStr);
1219 Usb->InterfaceNumber = (UINT8) Xtoi (InterfaceStr);
1220
1221 return (EFI_DEVICE_PATH_PROTOCOL *) Usb;
1222 }
1223
1224 EFI_DEVICE_PATH_PROTOCOL *
1225 DevPathFromTextI2O (
1226 IN CHAR16 *TextDeviceNode
1227 )
1228 {
1229 CHAR16 *TIDStr;
1230 I2O_DEVICE_PATH *I2O;
1231
1232 TIDStr = GetNextParamStr (&TextDeviceNode);
1233 I2O = (I2O_DEVICE_PATH *) CreateDeviceNode (
1234 MESSAGING_DEVICE_PATH,
1235 MSG_I2O_DP,
1236 sizeof (I2O_DEVICE_PATH)
1237 );
1238
1239 I2O->Tid = (UINT32) Xtoi (TIDStr);
1240
1241 return (EFI_DEVICE_PATH_PROTOCOL *) I2O;
1242 }
1243
1244 EFI_DEVICE_PATH_PROTOCOL *
1245 DevPathFromTextInfiniband (
1246 IN CHAR16 *TextDeviceNode
1247 )
1248 {
1249 CHAR16 *FlagsStr;
1250 CHAR16 *GuidStr;
1251 CHAR16 *SidStr;
1252 CHAR16 *TidStr;
1253 CHAR16 *DidStr;
1254 EFI_GUID PortGid;
1255 INFINIBAND_DEVICE_PATH *InfiniBand;
1256
1257 FlagsStr = GetNextParamStr (&TextDeviceNode);
1258 GuidStr = GetNextParamStr (&TextDeviceNode);
1259 SidStr = GetNextParamStr (&TextDeviceNode);
1260 TidStr = GetNextParamStr (&TextDeviceNode);
1261 DidStr = GetNextParamStr (&TextDeviceNode);
1262 InfiniBand = (INFINIBAND_DEVICE_PATH *) CreateDeviceNode (
1263 MESSAGING_DEVICE_PATH,
1264 MSG_INFINIBAND_DP,
1265 sizeof (INFINIBAND_DEVICE_PATH)
1266 );
1267
1268 InfiniBand->ResourceFlags = (UINT32) Xtoi (FlagsStr);
1269 StrToGuid (GuidStr, &PortGid);
1270 CopyMem (InfiniBand->PortGid, &PortGid, sizeof (EFI_GUID));
1271 Xtoi64 (SidStr, &InfiniBand->ServiceId);
1272 Xtoi64 (TidStr, &InfiniBand->TargetPortId);
1273 Xtoi64 (DidStr, &InfiniBand->DeviceId);
1274
1275 return (EFI_DEVICE_PATH_PROTOCOL *) InfiniBand;
1276 }
1277
1278 EFI_DEVICE_PATH_PROTOCOL *
1279 DevPathFromTextVenMsg (
1280 IN CHAR16 *TextDeviceNode
1281 )
1282 {
1283 return ConvertFromTextVendor (
1284 TextDeviceNode,
1285 MESSAGING_DEVICE_PATH,
1286 MSG_VENDOR_DP
1287 );
1288 }
1289
1290 EFI_DEVICE_PATH_PROTOCOL *
1291 DevPathFromTextVenPcAnsi (
1292 IN CHAR16 *TextDeviceNode
1293 )
1294 {
1295 VENDOR_DEVICE_PATH *Vendor;
1296
1297 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1298 MESSAGING_DEVICE_PATH,
1299 MSG_VENDOR_DP,
1300 sizeof (VENDOR_DEVICE_PATH));
1301 CopyGuid (&Vendor->Guid, &gEfiPcAnsiGuid);
1302
1303 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1304 }
1305
1306 EFI_DEVICE_PATH_PROTOCOL *
1307 DevPathFromTextVenVt100 (
1308 IN CHAR16 *TextDeviceNode
1309 )
1310 {
1311 VENDOR_DEVICE_PATH *Vendor;
1312
1313 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1314 MESSAGING_DEVICE_PATH,
1315 MSG_VENDOR_DP,
1316 sizeof (VENDOR_DEVICE_PATH));
1317 CopyGuid (&Vendor->Guid, &gEfiVT100Guid);
1318
1319 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1320 }
1321
1322 EFI_DEVICE_PATH_PROTOCOL *
1323 DevPathFromTextVenVt100Plus (
1324 IN CHAR16 *TextDeviceNode
1325 )
1326 {
1327 VENDOR_DEVICE_PATH *Vendor;
1328
1329 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1330 MESSAGING_DEVICE_PATH,
1331 MSG_VENDOR_DP,
1332 sizeof (VENDOR_DEVICE_PATH));
1333 CopyGuid (&Vendor->Guid, &gEfiVT100PlusGuid);
1334
1335 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1336 }
1337
1338 EFI_DEVICE_PATH_PROTOCOL *
1339 DevPathFromTextVenUtf8 (
1340 IN CHAR16 *TextDeviceNode
1341 )
1342 {
1343 VENDOR_DEVICE_PATH *Vendor;
1344
1345 Vendor = (VENDOR_DEVICE_PATH *) CreateDeviceNode (
1346 MESSAGING_DEVICE_PATH,
1347 MSG_VENDOR_DP,
1348 sizeof (VENDOR_DEVICE_PATH));
1349 CopyGuid (&Vendor->Guid, &gEfiVTUTF8Guid);
1350
1351 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor;
1352 }
1353
1354 EFI_DEVICE_PATH_PROTOCOL *
1355 DevPathFromTextUartFlowCtrl (
1356 IN CHAR16 *TextDeviceNode
1357 )
1358 {
1359 CHAR16 *ValueStr;
1360 UART_FLOW_CONTROL_DEVICE_PATH *UartFlowControl;
1361
1362 ValueStr = GetNextParamStr (&TextDeviceNode);
1363 UartFlowControl = (UART_FLOW_CONTROL_DEVICE_PATH *) CreateDeviceNode (
1364 MESSAGING_DEVICE_PATH,
1365 MSG_VENDOR_DP,
1366 sizeof (UART_FLOW_CONTROL_DEVICE_PATH)
1367 );
1368
1369 CopyGuid (&UartFlowControl->Guid, &mEfiDevicePathMessagingUartFlowControlGuid);
1370 if (StrCmp (ValueStr, L"XonXoff") == 0) {
1371 UartFlowControl->FlowControlMap = 2;
1372 } else if (StrCmp (ValueStr, L"Hardware") == 0) {
1373 UartFlowControl->FlowControlMap = 1;
1374 } else {
1375 UartFlowControl->FlowControlMap = 0;
1376 }
1377
1378 return (EFI_DEVICE_PATH_PROTOCOL *) UartFlowControl;
1379 }
1380
1381 EFI_DEVICE_PATH_PROTOCOL *
1382 DevPathFromTextSAS (
1383 IN CHAR16 *TextDeviceNode
1384 )
1385 {
1386 CHAR16 *AddressStr;
1387 CHAR16 *LunStr;
1388 CHAR16 *RTPStr;
1389 CHAR16 *SASSATAStr;
1390 CHAR16 *LocationStr;
1391 CHAR16 *ConnectStr;
1392 CHAR16 *DriveBayStr;
1393 CHAR16 *ReservedStr;
1394 UINT16 Info;
1395 SAS_DEVICE_PATH *Sas;
1396
1397 AddressStr = GetNextParamStr (&TextDeviceNode);
1398 LunStr = GetNextParamStr (&TextDeviceNode);
1399 RTPStr = GetNextParamStr (&TextDeviceNode);
1400 SASSATAStr = GetNextParamStr (&TextDeviceNode);
1401 LocationStr = GetNextParamStr (&TextDeviceNode);
1402 ConnectStr = GetNextParamStr (&TextDeviceNode);
1403 DriveBayStr = GetNextParamStr (&TextDeviceNode);
1404 ReservedStr = GetNextParamStr (&TextDeviceNode);
1405 Info = 0x0000;
1406 Sas = (SAS_DEVICE_PATH *) CreateDeviceNode (
1407 MESSAGING_DEVICE_PATH,
1408 MSG_VENDOR_DP,
1409 sizeof (SAS_DEVICE_PATH)
1410 );
1411
1412 CopyGuid (&Sas->Guid, &mEfiDevicePathMessagingSASGuid);
1413 Xtoi64 (AddressStr, &Sas->SasAddress);
1414 Xtoi64 (LunStr, &Sas->Lun);
1415 Sas->RelativeTargetPort = (UINT16) Xtoi (RTPStr);
1416 if (StrCmp (SASSATAStr, L"NoTopology") == 0)
1417 ;
1418 else {
1419 if (StrCmp (DriveBayStr, L"0") == 0) {
1420 Info |= 0x0001;
1421 } else {
1422 Info |= 0x0002;
1423 Info |= (Xtoi (DriveBayStr) << 8);
1424 }
1425
1426 if (StrCmp (SASSATAStr, L"SATA") == 0) {
1427 Info |= 0x0010;
1428 }
1429
1430 if (StrCmp (LocationStr, L"External") == 0) {
1431 Info |= 0x0020;
1432 }
1433
1434 if (StrCmp (ConnectStr, L"Expanded") == 0) {
1435 Info |= 0x0040;
1436 }
1437 }
1438
1439 Sas->DeviceTopology = Info;
1440 Sas->Reserved = (UINT32) Xtoi (ReservedStr);
1441
1442 return (EFI_DEVICE_PATH_PROTOCOL *) Sas;
1443 }
1444
1445 EFI_DEVICE_PATH_PROTOCOL *
1446 DevPathFromTextDebugPort (
1447 IN CHAR16 *TextDeviceNode
1448 )
1449 {
1450 VENDOR_DEFINED_MESSAGING_DEVICE_PATH *Vend;
1451
1452 Vend = (VENDOR_DEFINED_MESSAGING_DEVICE_PATH *) CreateDeviceNode (
1453 MESSAGING_DEVICE_PATH,
1454 MSG_VENDOR_DP,
1455 sizeof (VENDOR_DEFINED_MESSAGING_DEVICE_PATH)
1456 );
1457
1458 CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid);
1459
1460 return (EFI_DEVICE_PATH_PROTOCOL *) Vend;
1461 }
1462
1463 EFI_DEVICE_PATH_PROTOCOL *
1464 DevPathFromTextMAC (
1465 IN CHAR16 *TextDeviceNode
1466 )
1467 {
1468 CHAR16 *AddressStr;
1469 CHAR16 *IfTypeStr;
1470 UINTN Length;
1471 MAC_ADDR_DEVICE_PATH *MAC;
1472
1473 AddressStr = GetNextParamStr (&TextDeviceNode);
1474 IfTypeStr = GetNextParamStr (&TextDeviceNode);
1475 MAC = (MAC_ADDR_DEVICE_PATH *) CreateDeviceNode (
1476 MESSAGING_DEVICE_PATH,
1477 MSG_MAC_ADDR_DP,
1478 sizeof (MAC_ADDR_DEVICE_PATH)
1479 );
1480
1481 MAC->IfType = (UINT8) Xtoi (IfTypeStr);
1482
1483 Length = sizeof (EFI_MAC_ADDRESS);
1484 StrToBuf (&MAC->MacAddress.Addr[0], Length, AddressStr);
1485
1486 return (EFI_DEVICE_PATH_PROTOCOL *) MAC;
1487 }
1488
1489 EFI_DEVICE_PATH_PROTOCOL *
1490 DevPathFromTextIPv4 (
1491 IN CHAR16 *TextDeviceNode
1492 )
1493 {
1494 CHAR16 *RemoteIPStr;
1495 CHAR16 *ProtocolStr;
1496 CHAR16 *TypeStr;
1497 CHAR16 *LocalIPStr;
1498 IPv4_DEVICE_PATH *IPv4;
1499
1500 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
1501 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1502 TypeStr = GetNextParamStr (&TextDeviceNode);
1503 LocalIPStr = GetNextParamStr (&TextDeviceNode);
1504 IPv4 = (IPv4_DEVICE_PATH *) CreateDeviceNode (
1505 MESSAGING_DEVICE_PATH,
1506 MSG_IPv4_DP,
1507 sizeof (IPv4_DEVICE_PATH)
1508 );
1509
1510 StrToIPv4Addr (&RemoteIPStr, &IPv4->RemoteIpAddress);
1511 IPv4->Protocol = (StrCmp (ProtocolStr, L"UDP") == 0) ? (UINT16) 0 : (UINT16) 1;
1512 if (StrCmp (TypeStr, L"Static") == 0) {
1513 IPv4->StaticIpAddress = TRUE;
1514 } else {
1515 IPv4->StaticIpAddress = FALSE;
1516 }
1517
1518 StrToIPv4Addr (&LocalIPStr, &IPv4->LocalIpAddress);
1519
1520 IPv4->LocalPort = 0;
1521 IPv4->RemotePort = 0;
1522
1523 return (EFI_DEVICE_PATH_PROTOCOL *) IPv4;
1524 }
1525
1526 EFI_DEVICE_PATH_PROTOCOL *
1527 DevPathFromTextIPv6 (
1528 IN CHAR16 *TextDeviceNode
1529 )
1530 {
1531 CHAR16 *RemoteIPStr;
1532 CHAR16 *ProtocolStr;
1533 CHAR16 *TypeStr;
1534 CHAR16 *LocalIPStr;
1535 IPv6_DEVICE_PATH *IPv6;
1536
1537 RemoteIPStr = GetNextParamStr (&TextDeviceNode);
1538 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1539 TypeStr = GetNextParamStr (&TextDeviceNode);
1540 LocalIPStr = GetNextParamStr (&TextDeviceNode);
1541 IPv6 = (IPv6_DEVICE_PATH *) CreateDeviceNode (
1542 MESSAGING_DEVICE_PATH,
1543 MSG_IPv6_DP,
1544 sizeof (IPv6_DEVICE_PATH)
1545 );
1546
1547 StrToIPv6Addr (&RemoteIPStr, &IPv6->RemoteIpAddress);
1548 IPv6->Protocol = (StrCmp (ProtocolStr, L"UDP") == 0) ? (UINT16) 0 : (UINT16) 1;
1549 if (StrCmp (TypeStr, L"Static") == 0) {
1550 IPv6->StaticIpAddress = TRUE;
1551 } else {
1552 IPv6->StaticIpAddress = FALSE;
1553 }
1554
1555 StrToIPv6Addr (&LocalIPStr, &IPv6->LocalIpAddress);
1556
1557 IPv6->LocalPort = 0;
1558 IPv6->RemotePort = 0;
1559
1560 return (EFI_DEVICE_PATH_PROTOCOL *) IPv6;
1561 }
1562
1563 EFI_DEVICE_PATH_PROTOCOL *
1564 DevPathFromTextUart (
1565 IN CHAR16 *TextDeviceNode
1566 )
1567 {
1568 CHAR16 *BaudStr;
1569 CHAR16 *DataBitsStr;
1570 CHAR16 *ParityStr;
1571 CHAR16 *StopBitsStr;
1572 UART_DEVICE_PATH *Uart;
1573
1574 BaudStr = GetNextParamStr (&TextDeviceNode);
1575 DataBitsStr = GetNextParamStr (&TextDeviceNode);
1576 ParityStr = GetNextParamStr (&TextDeviceNode);
1577 StopBitsStr = GetNextParamStr (&TextDeviceNode);
1578 Uart = (UART_DEVICE_PATH *) CreateDeviceNode (
1579 MESSAGING_DEVICE_PATH,
1580 MSG_UART_DP,
1581 sizeof (UART_DEVICE_PATH)
1582 );
1583
1584 Uart->BaudRate = (StrCmp (BaudStr, L"DEFAULT") == 0) ? 115200 : Atoi (BaudStr);
1585 Uart->DataBits = (StrCmp (DataBitsStr, L"DEFAULT") == 0) ? (UINT8) 8 : (UINT8) Atoi (DataBitsStr);
1586 switch (*ParityStr) {
1587 case L'D':
1588 Uart->Parity = 0;
1589 break;
1590
1591 case L'N':
1592 Uart->Parity = 1;
1593 break;
1594
1595 case L'E':
1596 Uart->Parity = 2;
1597 break;
1598
1599 case L'O':
1600 Uart->Parity = 3;
1601 break;
1602
1603 case L'M':
1604 Uart->Parity = 4;
1605 break;
1606
1607 case L'S':
1608 Uart->Parity = 5;
1609
1610 default:
1611 Uart->Parity = 0xff;
1612 }
1613
1614 if (StrCmp (StopBitsStr, L"D") == 0) {
1615 Uart->StopBits = (UINT8) 0;
1616 } else if (StrCmp (StopBitsStr, L"1") == 0) {
1617 Uart->StopBits = (UINT8) 1;
1618 } else if (StrCmp (StopBitsStr, L"1.5") == 0) {
1619 Uart->StopBits = (UINT8) 2;
1620 } else if (StrCmp (StopBitsStr, L"2") == 0) {
1621 Uart->StopBits = (UINT8) 3;
1622 } else {
1623 Uart->StopBits = 0xff;
1624 }
1625
1626 return (EFI_DEVICE_PATH_PROTOCOL *) Uart;
1627 }
1628
1629 EFI_DEVICE_PATH_PROTOCOL *
1630 ConvertFromTextUsbClass (
1631 IN CHAR16 *TextDeviceNode,
1632 IN USB_CLASS_TEXT *UsbClassText
1633 )
1634 {
1635 CHAR16 *VIDStr;
1636 CHAR16 *PIDStr;
1637 CHAR16 *ClassStr;
1638 CHAR16 *SubClassStr;
1639 CHAR16 *ProtocolStr;
1640 USB_CLASS_DEVICE_PATH *UsbClass;
1641
1642 UsbClass = (USB_CLASS_DEVICE_PATH *) CreateDeviceNode (
1643 MESSAGING_DEVICE_PATH,
1644 MSG_USB_CLASS_DP,
1645 sizeof (USB_CLASS_DEVICE_PATH)
1646 );
1647
1648 VIDStr = GetNextParamStr (&TextDeviceNode);
1649 PIDStr = GetNextParamStr (&TextDeviceNode);
1650 if (UsbClassText->ClassExist) {
1651 ClassStr = GetNextParamStr (&TextDeviceNode);
1652 UsbClass->DeviceClass = (UINT8) Xtoi (ClassStr);
1653 } else {
1654 UsbClass->DeviceClass = UsbClassText->Class;
1655 }
1656 if (UsbClassText->SubClassExist) {
1657 SubClassStr = GetNextParamStr (&TextDeviceNode);
1658 UsbClass->DeviceSubClass = (UINT8) Xtoi (SubClassStr);
1659 } else {
1660 UsbClass->DeviceSubClass = UsbClassText->SubClass;
1661 }
1662
1663 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1664
1665 UsbClass->VendorId = (UINT16) Xtoi (VIDStr);
1666 UsbClass->ProductId = (UINT16) Xtoi (PIDStr);
1667 UsbClass->DeviceProtocol = (UINT8) Xtoi (ProtocolStr);
1668
1669 return (EFI_DEVICE_PATH_PROTOCOL *) UsbClass;
1670 }
1671
1672
1673 EFI_DEVICE_PATH_PROTOCOL *
1674 DevPathFromTextUsbClass (
1675 IN CHAR16 *TextDeviceNode
1676 )
1677 {
1678 USB_CLASS_TEXT UsbClassText;
1679
1680 UsbClassText.ClassExist = TRUE;
1681 UsbClassText.SubClassExist = TRUE;
1682
1683 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1684 }
1685
1686 EFI_DEVICE_PATH_PROTOCOL *
1687 DevPathFromTextUsbAudio (
1688 IN CHAR16 *TextDeviceNode
1689 )
1690 {
1691 USB_CLASS_TEXT UsbClassText;
1692
1693 UsbClassText.ClassExist = FALSE;
1694 UsbClassText.Class = USB_CLASS_AUDIO;
1695 UsbClassText.SubClassExist = TRUE;
1696
1697 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1698 }
1699
1700 EFI_DEVICE_PATH_PROTOCOL *
1701 DevPathFromTextUsbCDCControl (
1702 IN CHAR16 *TextDeviceNode
1703 )
1704 {
1705 USB_CLASS_TEXT UsbClassText;
1706
1707 UsbClassText.ClassExist = FALSE;
1708 UsbClassText.Class = USB_CLASS_CDCCONTROL;
1709 UsbClassText.SubClassExist = TRUE;
1710
1711 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1712 }
1713
1714 EFI_DEVICE_PATH_PROTOCOL *
1715 DevPathFromTextUsbHID (
1716 IN CHAR16 *TextDeviceNode
1717 )
1718 {
1719 USB_CLASS_TEXT UsbClassText;
1720
1721 UsbClassText.ClassExist = FALSE;
1722 UsbClassText.Class = USB_CLASS_HID;
1723 UsbClassText.SubClassExist = TRUE;
1724
1725 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1726 }
1727
1728 EFI_DEVICE_PATH_PROTOCOL *
1729 DevPathFromTextUsbImage (
1730 IN CHAR16 *TextDeviceNode
1731 )
1732 {
1733 USB_CLASS_TEXT UsbClassText;
1734
1735 UsbClassText.ClassExist = FALSE;
1736 UsbClassText.Class = USB_CLASS_IMAGE;
1737 UsbClassText.SubClassExist = TRUE;
1738
1739 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1740 }
1741
1742 EFI_DEVICE_PATH_PROTOCOL *
1743 DevPathFromTextUsbPrinter (
1744 IN CHAR16 *TextDeviceNode
1745 )
1746 {
1747 USB_CLASS_TEXT UsbClassText;
1748
1749 UsbClassText.ClassExist = FALSE;
1750 UsbClassText.Class = USB_CLASS_PRINTER;
1751 UsbClassText.SubClassExist = TRUE;
1752
1753 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1754 }
1755
1756 EFI_DEVICE_PATH_PROTOCOL *
1757 DevPathFromTextUsbMassStorage (
1758 IN CHAR16 *TextDeviceNode
1759 )
1760 {
1761 USB_CLASS_TEXT UsbClassText;
1762
1763 UsbClassText.ClassExist = FALSE;
1764 UsbClassText.Class = USB_CLASS_MASS_STORAGE;
1765 UsbClassText.SubClassExist = TRUE;
1766
1767 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1768 }
1769
1770 EFI_DEVICE_PATH_PROTOCOL *
1771 DevPathFromTextUsbHub (
1772 IN CHAR16 *TextDeviceNode
1773 )
1774 {
1775 USB_CLASS_TEXT UsbClassText;
1776
1777 UsbClassText.ClassExist = FALSE;
1778 UsbClassText.Class = USB_CLASS_HUB;
1779 UsbClassText.SubClassExist = TRUE;
1780
1781 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1782 }
1783
1784 EFI_DEVICE_PATH_PROTOCOL *
1785 DevPathFromTextUsbCDCData (
1786 IN CHAR16 *TextDeviceNode
1787 )
1788 {
1789 USB_CLASS_TEXT UsbClassText;
1790
1791 UsbClassText.ClassExist = FALSE;
1792 UsbClassText.Class = USB_CLASS_CDCDATA;
1793 UsbClassText.SubClassExist = TRUE;
1794
1795 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1796 }
1797
1798 EFI_DEVICE_PATH_PROTOCOL *
1799 DevPathFromTextUsbSmartCard (
1800 IN CHAR16 *TextDeviceNode
1801 )
1802 {
1803 USB_CLASS_TEXT UsbClassText;
1804
1805 UsbClassText.ClassExist = FALSE;
1806 UsbClassText.Class = USB_CLASS_SMART_CARD;
1807 UsbClassText.SubClassExist = TRUE;
1808
1809 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1810 }
1811
1812 EFI_DEVICE_PATH_PROTOCOL *
1813 DevPathFromTextUsbVideo (
1814 IN CHAR16 *TextDeviceNode
1815 )
1816 {
1817 USB_CLASS_TEXT UsbClassText;
1818
1819 UsbClassText.ClassExist = FALSE;
1820 UsbClassText.Class = USB_CLASS_VIDEO;
1821 UsbClassText.SubClassExist = TRUE;
1822
1823 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1824 }
1825
1826 EFI_DEVICE_PATH_PROTOCOL *
1827 DevPathFromTextUsbDiagnostic (
1828 IN CHAR16 *TextDeviceNode
1829 )
1830 {
1831 USB_CLASS_TEXT UsbClassText;
1832
1833 UsbClassText.ClassExist = FALSE;
1834 UsbClassText.Class = USB_CLASS_DIAGNOSTIC;
1835 UsbClassText.SubClassExist = TRUE;
1836
1837 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1838 }
1839
1840 EFI_DEVICE_PATH_PROTOCOL *
1841 DevPathFromTextUsbWireless (
1842 IN CHAR16 *TextDeviceNode
1843 )
1844 {
1845 USB_CLASS_TEXT UsbClassText;
1846
1847 UsbClassText.ClassExist = FALSE;
1848 UsbClassText.Class = USB_CLASS_WIRELESS;
1849 UsbClassText.SubClassExist = TRUE;
1850
1851 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1852 }
1853
1854 EFI_DEVICE_PATH_PROTOCOL *
1855 DevPathFromTextUsbDeviceFirmwareUpdate (
1856 IN CHAR16 *TextDeviceNode
1857 )
1858 {
1859 USB_CLASS_TEXT UsbClassText;
1860
1861 UsbClassText.ClassExist = FALSE;
1862 UsbClassText.Class = USB_CLASS_RESERVE;
1863 UsbClassText.SubClassExist = FALSE;
1864 UsbClassText.SubClass = USB_SUBCLASS_FW_UPDATE;
1865
1866 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1867 }
1868
1869 EFI_DEVICE_PATH_PROTOCOL *
1870 DevPathFromTextUsbIrdaBridge (
1871 IN CHAR16 *TextDeviceNode
1872 )
1873 {
1874 USB_CLASS_TEXT UsbClassText;
1875
1876 UsbClassText.ClassExist = FALSE;
1877 UsbClassText.Class = USB_CLASS_RESERVE;
1878 UsbClassText.SubClassExist = FALSE;
1879 UsbClassText.SubClass = USB_SUBCLASS_IRDA_BRIDGE;
1880
1881 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1882 }
1883
1884 EFI_DEVICE_PATH_PROTOCOL *
1885 DevPathFromTextUsbTestAndMeasurement (
1886 IN CHAR16 *TextDeviceNode
1887 )
1888 {
1889 USB_CLASS_TEXT UsbClassText;
1890
1891 UsbClassText.ClassExist = FALSE;
1892 UsbClassText.Class = USB_CLASS_RESERVE;
1893 UsbClassText.SubClassExist = FALSE;
1894 UsbClassText.SubClass = USB_SUBCLASS_TEST;
1895
1896 return ConvertFromTextUsbClass (TextDeviceNode, &UsbClassText);
1897 }
1898
1899 EFI_DEVICE_PATH_PROTOCOL *
1900 DevPathFromTextUsbWwid (
1901 IN CHAR16 *TextDeviceNode
1902 )
1903 {
1904 CHAR16 *VIDStr;
1905 CHAR16 *PIDStr;
1906 CHAR16 *InterfaceNumStr;
1907 USB_WWID_DEVICE_PATH *UsbWwid;
1908
1909 VIDStr = GetNextParamStr (&TextDeviceNode);
1910 PIDStr = GetNextParamStr (&TextDeviceNode);
1911 InterfaceNumStr = GetNextParamStr (&TextDeviceNode);
1912 UsbWwid = (USB_WWID_DEVICE_PATH *) CreateDeviceNode (
1913 MESSAGING_DEVICE_PATH,
1914 MSG_USB_WWID_DP,
1915 sizeof (USB_WWID_DEVICE_PATH)
1916 );
1917
1918 UsbWwid->VendorId = (UINT16) Xtoi (VIDStr);
1919 UsbWwid->ProductId = (UINT16) Xtoi (PIDStr);
1920 UsbWwid->InterfaceNumber = (UINT16) Xtoi (InterfaceNumStr);
1921
1922 return (EFI_DEVICE_PATH_PROTOCOL *) UsbWwid;
1923 }
1924
1925 EFI_DEVICE_PATH_PROTOCOL *
1926 DevPathFromTextUnit (
1927 IN CHAR16 *TextDeviceNode
1928 )
1929 {
1930 CHAR16 *LunStr;
1931 DEVICE_LOGICAL_UNIT_DEVICE_PATH *LogicalUnit;
1932
1933 LunStr = GetNextParamStr (&TextDeviceNode);
1934 LogicalUnit = (DEVICE_LOGICAL_UNIT_DEVICE_PATH *) CreateDeviceNode (
1935 MESSAGING_DEVICE_PATH,
1936 MSG_DEVICE_LOGICAL_UNIT_DP,
1937 sizeof (DEVICE_LOGICAL_UNIT_DEVICE_PATH)
1938 );
1939
1940 LogicalUnit->Lun = (UINT8) Xtoi (LunStr);
1941
1942 return (EFI_DEVICE_PATH_PROTOCOL *) LogicalUnit;
1943 }
1944
1945 EFI_DEVICE_PATH_PROTOCOL *
1946 DevPathFromTextiSCSI (
1947 IN CHAR16 *TextDeviceNode
1948 )
1949 {
1950 UINT16 Options;
1951 CHAR16 *NameStr;
1952 CHAR16 *PortalGroupStr;
1953 CHAR16 *LunStr;
1954 CHAR16 *HeaderDigestStr;
1955 CHAR16 *DataDigestStr;
1956 CHAR16 *AuthenticationStr;
1957 CHAR16 *ProtocolStr;
1958 ISCSI_DEVICE_PATH_WITH_NAME *iSCSI;
1959
1960 NameStr = GetNextParamStr (&TextDeviceNode);
1961 PortalGroupStr = GetNextParamStr (&TextDeviceNode);
1962 LunStr = GetNextParamStr (&TextDeviceNode);
1963 HeaderDigestStr = GetNextParamStr (&TextDeviceNode);
1964 DataDigestStr = GetNextParamStr (&TextDeviceNode);
1965 AuthenticationStr = GetNextParamStr (&TextDeviceNode);
1966 ProtocolStr = GetNextParamStr (&TextDeviceNode);
1967 iSCSI = (ISCSI_DEVICE_PATH_WITH_NAME *) CreateDeviceNode (
1968 MESSAGING_DEVICE_PATH,
1969 MSG_ISCSI_DP,
1970 sizeof (ISCSI_DEVICE_PATH_WITH_NAME) + (UINT16) (StrLen (NameStr) * 2)
1971 );
1972
1973 StrCpy (iSCSI->iSCSITargetName, NameStr);
1974 iSCSI->TargetPortalGroupTag = (UINT16) Xtoi (PortalGroupStr);
1975 Xtoi64 (LunStr, &iSCSI->Lun);
1976
1977 Options = 0x0000;
1978 if (StrCmp (HeaderDigestStr, L"CRC32C") == 0) {
1979 Options |= 0x0002;
1980 }
1981
1982 if (StrCmp (DataDigestStr, L"CRC32C") == 0) {
1983 Options |= 0x0008;
1984 }
1985
1986 if (StrCmp (AuthenticationStr, L"None") == 0) {
1987 Options |= 0x0800;
1988 }
1989
1990 if (StrCmp (AuthenticationStr, L"CHAP_UNI") == 0) {
1991 Options |= 0x1000;
1992 }
1993
1994 iSCSI->LoginOption = (UINT16) Options;
1995
1996 iSCSI->NetworkProtocol = (UINT16) StrCmp (ProtocolStr, L"TCP");
1997 iSCSI->Reserved = (UINT16) 0;
1998
1999 return (EFI_DEVICE_PATH_PROTOCOL *) iSCSI;
2000 }
2001
2002 EFI_DEVICE_PATH_PROTOCOL *
2003 DevPathFromTextHD (
2004 IN CHAR16 *TextDeviceNode
2005 )
2006 {
2007 CHAR16 *PartitionStr;
2008 CHAR16 *TypeStr;
2009 CHAR16 *SignatureStr;
2010 CHAR16 *StartStr;
2011 CHAR16 *SizeStr;
2012 UINT32 Signature32;
2013 EFI_GUID SignatureGuid;
2014 HARDDRIVE_DEVICE_PATH *Hd;
2015
2016 PartitionStr = GetNextParamStr (&TextDeviceNode);
2017 TypeStr = GetNextParamStr (&TextDeviceNode);
2018 SignatureStr = GetNextParamStr (&TextDeviceNode);
2019 StartStr = GetNextParamStr (&TextDeviceNode);
2020 SizeStr = GetNextParamStr (&TextDeviceNode);
2021 Hd = (HARDDRIVE_DEVICE_PATH *) CreateDeviceNode (
2022 MEDIA_DEVICE_PATH,
2023 MEDIA_HARDDRIVE_DP,
2024 sizeof (HARDDRIVE_DEVICE_PATH)
2025 );
2026
2027 Hd->PartitionNumber = (UINT32) Atoi (PartitionStr);
2028
2029 ZeroMem (Hd->Signature, 16);
2030 Hd->MBRType = (UINT8) 0;
2031
2032 if (StrCmp (TypeStr, L"None") == 0) {
2033 Hd->SignatureType = (UINT8) 0;
2034 } else if (StrCmp (TypeStr, L"MBR") == 0) {
2035 Hd->SignatureType = SIGNATURE_TYPE_MBR;
2036 Hd->MBRType = 0x01;
2037
2038 Signature32 = (UINT32) Xtoi (SignatureStr);
2039 CopyMem (Hd->Signature, &Signature32, sizeof (UINT32));
2040 } else if (StrCmp (TypeStr, L"GUID") == 0) {
2041 Hd->SignatureType = SIGNATURE_TYPE_GUID;
2042 Hd->MBRType = 0x02;
2043
2044 StrToGuid (SignatureStr, &SignatureGuid);
2045 CopyMem (Hd->Signature, &SignatureGuid, sizeof (EFI_GUID));
2046 } else {
2047 Hd->SignatureType = 0xff;
2048
2049 }
2050
2051 Xtoi64 (StartStr, &Hd->PartitionStart);
2052 Xtoi64 (SizeStr, &Hd->PartitionSize);
2053
2054 return (EFI_DEVICE_PATH_PROTOCOL *) Hd;
2055 }
2056
2057 EFI_DEVICE_PATH_PROTOCOL *
2058 DevPathFromTextCDROM (
2059 IN CHAR16 *TextDeviceNode
2060 )
2061 {
2062 CHAR16 *EntryStr;
2063 CHAR16 *StartStr;
2064 CHAR16 *SizeStr;
2065 CDROM_DEVICE_PATH *CDROM;
2066
2067 EntryStr = GetNextParamStr (&TextDeviceNode);
2068 StartStr = GetNextParamStr (&TextDeviceNode);
2069 SizeStr = GetNextParamStr (&TextDeviceNode);
2070 CDROM = (CDROM_DEVICE_PATH *) CreateDeviceNode (
2071 MEDIA_DEVICE_PATH,
2072 MEDIA_CDROM_DP,
2073 sizeof (CDROM_DEVICE_PATH)
2074 );
2075
2076 CDROM->BootEntry = (UINT32) Xtoi (EntryStr);
2077 Xtoi64 (StartStr, &CDROM->PartitionStart);
2078 Xtoi64 (SizeStr, &CDROM->PartitionSize);
2079
2080 return (EFI_DEVICE_PATH_PROTOCOL *) CDROM;
2081 }
2082
2083 EFI_DEVICE_PATH_PROTOCOL *
2084 DevPathFromTextVenMEDIA (
2085 IN CHAR16 *TextDeviceNode
2086 )
2087 {
2088 return ConvertFromTextVendor (
2089 TextDeviceNode,
2090 MEDIA_DEVICE_PATH,
2091 MEDIA_VENDOR_DP
2092 );
2093 }
2094
2095 EFI_DEVICE_PATH_PROTOCOL *
2096 DevPathFromTextFilePath (
2097 IN CHAR16 *TextDeviceNode
2098 )
2099 {
2100 FILEPATH_DEVICE_PATH *File;
2101
2102 File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode (
2103 MEDIA_DEVICE_PATH,
2104 MEDIA_FILEPATH_DP,
2105 sizeof (FILEPATH_DEVICE_PATH) + (UINT16) (StrLen (TextDeviceNode) * 2)
2106 );
2107
2108 StrCpy (File->PathName, TextDeviceNode);
2109
2110 return (EFI_DEVICE_PATH_PROTOCOL *) File;
2111 }
2112
2113 EFI_DEVICE_PATH_PROTOCOL *
2114 DevPathFromTextMedia (
2115 IN CHAR16 *TextDeviceNode
2116 )
2117 {
2118 CHAR16 *GuidStr;
2119 MEDIA_PROTOCOL_DEVICE_PATH *Media;
2120
2121 GuidStr = GetNextParamStr (&TextDeviceNode);
2122 Media = (MEDIA_PROTOCOL_DEVICE_PATH *) CreateDeviceNode (
2123 MEDIA_DEVICE_PATH,
2124 MEDIA_PROTOCOL_DP,
2125 sizeof (MEDIA_PROTOCOL_DEVICE_PATH)
2126 );
2127
2128 StrToGuid (GuidStr, &Media->Protocol);
2129
2130 return (EFI_DEVICE_PATH_PROTOCOL *) Media;
2131 }
2132
2133 EFI_DEVICE_PATH_PROTOCOL *
2134 DevPathFromTextBBS (
2135 IN CHAR16 *TextDeviceNode
2136 )
2137 {
2138 CHAR16 *TypeStr;
2139 CHAR16 *IdStr;
2140 CHAR16 *FlagsStr;
2141 UINT8 *AsciiStr;
2142 BBS_BBS_DEVICE_PATH *Bbs;
2143
2144 TypeStr = GetNextParamStr (&TextDeviceNode);
2145 IdStr = GetNextParamStr (&TextDeviceNode);
2146 FlagsStr = GetNextParamStr (&TextDeviceNode);
2147 Bbs = (BBS_BBS_DEVICE_PATH *) CreateDeviceNode (
2148 BBS_DEVICE_PATH,
2149 BBS_BBS_DP,
2150 sizeof (BBS_BBS_DEVICE_PATH) + (UINT16) (StrLen (IdStr))
2151 );
2152
2153 if (StrCmp (TypeStr, L"Floppy") == 0) {
2154 Bbs->DeviceType = BBS_TYPE_FLOPPY;
2155 } else if (StrCmp (TypeStr, L"HD") == 0) {
2156 Bbs->DeviceType = BBS_TYPE_HARDDRIVE;
2157 } else if (StrCmp (TypeStr, L"CDROM") == 0) {
2158 Bbs->DeviceType = BBS_TYPE_CDROM;
2159 } else if (StrCmp (TypeStr, L"PCMCIA") == 0) {
2160 Bbs->DeviceType = BBS_TYPE_PCMCIA;
2161 } else if (StrCmp (TypeStr, L"USB") == 0) {
2162 Bbs->DeviceType = BBS_TYPE_USB;
2163 } else if (StrCmp (TypeStr, L"Network") == 0) {
2164 Bbs->DeviceType = BBS_TYPE_EMBEDDED_NETWORK;
2165 } else {
2166 Bbs->DeviceType = BBS_TYPE_UNKNOWN;
2167 }
2168
2169 AsciiStr = (UINT8 *) Bbs->String;
2170 StrToAscii (IdStr, (CHAR8 **) &AsciiStr);
2171
2172 Bbs->StatusFlag = (UINT16) Xtoi (FlagsStr);
2173
2174 return (EFI_DEVICE_PATH_PROTOCOL *) Bbs;
2175 }
2176
2177 GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE DevPathFromTextTable[] = {
2178 {L"Pci", DevPathFromTextPci},
2179 {L"PcCard", DevPathFromTextPcCard},
2180 {L"MemoryMapped", DevPathFromTextMemoryMapped},
2181 {L"VenHw", DevPathFromTextVenHw},
2182 {L"Ctrl", DevPathFromTextCtrl},
2183 {L"Acpi", DevPathFromTextAcpi},
2184 {L"PciRoot", DevPathFromTextPciRoot},
2185 {L"Floppy", DevPathFromTextFloppy},
2186 {L"Keyboard", DevPathFromTextKeyboard},
2187 {L"Serial", DevPathFromTextSerial},
2188 {L"ParallelPort", DevPathFromTextParallelPort},
2189 {L"AcpiEx", DevPathFromTextAcpiEx},
2190 {L"AcpiExp", DevPathFromTextAcpiExp},
2191 {L"Ata", DevPathFromTextAta},
2192 {L"Scsi", DevPathFromTextScsi},
2193 {L"Fibre", DevPathFromTextFibre},
2194 {L"I1394", DevPathFromText1394},
2195 {L"USB", DevPathFromTextUsb},
2196 {L"I2O", DevPathFromTextI2O},
2197 {L"Infiniband", DevPathFromTextInfiniband},
2198 {L"VenMsg", DevPathFromTextVenMsg},
2199 {L"VenPcAnsi", DevPathFromTextVenPcAnsi},
2200 {L"VenVt100", DevPathFromTextVenVt100},
2201 {L"VenVt100Plus", DevPathFromTextVenVt100Plus},
2202 {L"VenUtf8", DevPathFromTextVenUtf8},
2203 {L"UartFlowCtrl", DevPathFromTextUartFlowCtrl},
2204 {L"SAS", DevPathFromTextSAS},
2205 {L"DebugPort", DevPathFromTextDebugPort},
2206 {L"MAC", DevPathFromTextMAC},
2207 {L"IPv4", DevPathFromTextIPv4},
2208 {L"IPv6", DevPathFromTextIPv6},
2209 {L"Uart", DevPathFromTextUart},
2210 {L"UsbClass", DevPathFromTextUsbClass},
2211 {L"UsbAudio", DevPathFromTextUsbAudio},
2212 {L"UsbCDCControl", DevPathFromTextUsbCDCControl},
2213 {L"UsbHID", DevPathFromTextUsbHID},
2214 {L"UsbImage", DevPathFromTextUsbImage},
2215 {L"UsbPrinter", DevPathFromTextUsbPrinter},
2216 {L"UsbMassStorage", DevPathFromTextUsbMassStorage},
2217 {L"UsbHub", DevPathFromTextUsbHub},
2218 {L"UsbCDCData", DevPathFromTextUsbCDCData},
2219 {L"UsbSmartCard", DevPathFromTextUsbSmartCard},
2220 {L"UsbVideo", DevPathFromTextUsbVideo},
2221 {L"UsbDiagnostic", DevPathFromTextUsbDiagnostic},
2222 {L"UsbWireless", DevPathFromTextUsbWireless},
2223 {L"UsbDeviceFirmwareUpdate", DevPathFromTextUsbDeviceFirmwareUpdate},
2224 {L"UsbIrdaBridge", DevPathFromTextUsbIrdaBridge},
2225 {L"UsbTestAndMeasurement", DevPathFromTextUsbTestAndMeasurement},
2226 {L"UsbWwid", DevPathFromTextUsbWwid},
2227 {L"Unit", DevPathFromTextUnit},
2228 {L"iSCSI", DevPathFromTextiSCSI},
2229 {L"HD", DevPathFromTextHD},
2230 {L"CDROM", DevPathFromTextCDROM},
2231 {L"VenMEDIA", DevPathFromTextVenMEDIA},
2232 {L"Media", DevPathFromTextMedia},
2233 {L"BBS", DevPathFromTextBBS},
2234 {NULL, NULL}
2235 };
2236
2237 EFI_DEVICE_PATH_PROTOCOL *
2238 ConvertTextToDeviceNode (
2239 IN CONST CHAR16 *TextDeviceNode
2240 )
2241 /*++
2242
2243 Routine Description:
2244 Convert text to the binary representation of a device node.
2245
2246 Arguments:
2247 TextDeviceNode - TextDeviceNode points to the text representation of a device
2248 node. Conversion starts with the first character and continues
2249 until the first non-device node character.
2250
2251 Returns:
2252 A pointer - Pointer to the EFI device node.
2253 NULL - If TextDeviceNode is NULL or there was insufficient memory or text unsupported.
2254
2255 --*/
2256 {
2257 EFI_DEVICE_PATH_PROTOCOL * (*DumpNode) (CHAR16 *);
2258 CHAR16 *ParamStr;
2259 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
2260 CHAR16 *DeviceNodeStr;
2261 UINTN Index;
2262
2263 if ((TextDeviceNode == NULL) || (IS_NULL (*TextDeviceNode))) {
2264 return NULL;
2265 }
2266
2267 ParamStr = NULL;
2268 DumpNode = NULL;
2269 DeviceNodeStr = StrDuplicate (TextDeviceNode);
2270
2271 for (Index = 0; DevPathFromTextTable[Index].Function; Index++) {
2272 ParamStr = GetParamByNodeName (DeviceNodeStr, DevPathFromTextTable[Index].DevicePathNodeText);
2273 if (ParamStr != NULL) {
2274 DumpNode = DevPathFromTextTable[Index].Function;
2275 break;
2276 }
2277 }
2278
2279 if (DumpNode == NULL) {
2280 //
2281 // A file path
2282 //
2283 DumpNode = DevPathFromTextFilePath;
2284 DeviceNode = DumpNode (DeviceNodeStr);
2285 } else {
2286 DeviceNode = DumpNode (ParamStr);
2287 gBS->FreePool (ParamStr);
2288 }
2289
2290 gBS->FreePool (DeviceNodeStr);
2291
2292 return DeviceNode;
2293 }
2294
2295 EFI_DEVICE_PATH_PROTOCOL *
2296 ConvertTextToDevicePath (
2297 IN CONST CHAR16 *TextDevicePath
2298 )
2299 /*++
2300
2301 Routine Description:
2302 Convert text to the binary representation of a device path.
2303
2304 Arguments:
2305 TextDevicePath - TextDevicePath points to the text representation of a device
2306 path. Conversion starts with the first character and continues
2307 until the first non-device node character.
2308
2309 Returns:
2310 A pointer - Pointer to the allocated device path.
2311 NULL - If TextDeviceNode is NULL or there was insufficient memory.
2312
2313 --*/
2314 {
2315 EFI_DEVICE_PATH_PROTOCOL * (*DumpNode) (CHAR16 *);
2316 CHAR16 *ParamStr;
2317 EFI_DEVICE_PATH_PROTOCOL *DeviceNode;
2318 UINTN Index;
2319 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
2320 CHAR16 *DevicePathStr;
2321 CHAR16 *Str;
2322 CHAR16 *DeviceNodeStr;
2323 UINT8 IsInstanceEnd;
2324 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
2325
2326 if ((TextDevicePath == NULL) || (IS_NULL (*TextDevicePath))) {
2327 return NULL;
2328 }
2329
2330 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
2331 SetDevicePathEndNode (DevicePath);
2332
2333 ParamStr = NULL;
2334 DeviceNodeStr = NULL;
2335 DevicePathStr = StrDuplicate (TextDevicePath);
2336
2337 Str = DevicePathStr;
2338 while ((DeviceNodeStr = GetNextDeviceNodeStr (&Str, &IsInstanceEnd)) != NULL) {
2339 DumpNode = NULL;
2340 for (Index = 0; DevPathFromTextTable[Index].Function; Index++) {
2341 ParamStr = GetParamByNodeName (DeviceNodeStr, DevPathFromTextTable[Index].DevicePathNodeText);
2342 if (ParamStr != NULL) {
2343 DumpNode = DevPathFromTextTable[Index].Function;
2344 break;
2345 }
2346 }
2347
2348 if (DumpNode == NULL) {
2349 //
2350 // A file path
2351 //
2352 DumpNode = DevPathFromTextFilePath;
2353 DeviceNode = DumpNode (DeviceNodeStr);
2354 } else {
2355 DeviceNode = DumpNode (ParamStr);
2356 gBS->FreePool (ParamStr);
2357 }
2358
2359 NewDevicePath = AppendDeviceNodeProtocolInterface (DevicePath, DeviceNode);
2360 gBS->FreePool (DevicePath);
2361 gBS->FreePool (DeviceNode);
2362 DevicePath = NewDevicePath;
2363
2364 if (IsInstanceEnd) {
2365 DeviceNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);
2366 SetDevicePathInstanceEndNode (DeviceNode);
2367
2368 NewDevicePath = AppendDeviceNodeProtocolInterface (DevicePath, DeviceNode);
2369 gBS->FreePool (DevicePath);
2370 gBS->FreePool (DeviceNode);
2371 DevicePath = NewDevicePath;
2372 }
2373 }
2374
2375 gBS->FreePool (DevicePathStr);
2376 return DevicePath;
2377 }