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