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