1 /******************************************************************************
2 *
3 * Module Name: psargs - Parse AML opcode arguments
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #define __PSARGS_C__
45
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acparser.h"
49 #include "amlcode.h"
50 #include "acnamesp.h"
51 #include "acdispat.h"
52
53 #define _COMPONENT ACPI_PARSER
54 ACPI_MODULE_NAME ("psargs")
55
56 /* Local prototypes */
57
58 static UINT32
59 AcpiPsGetNextPackageLength (
60 ACPI_PARSE_STATE *ParserState);
61
62 static ACPI_PARSE_OBJECT *
63 AcpiPsGetNextField (
64 ACPI_PARSE_STATE *ParserState);
65
66
67 /*******************************************************************************
68 *
69 * FUNCTION: AcpiPsGetNextPackageLength
70 *
71 * PARAMETERS: ParserState - Current parser state object
72 *
73 * RETURN: Decoded package length. On completion, the AML pointer points
74 * past the length byte or bytes.
75 *
76 * DESCRIPTION: Decode and return a package length field.
77 * Note: Largest package length is 28 bits, from ACPI specification
78 *
79 ******************************************************************************/
80
81 static UINT32
82 AcpiPsGetNextPackageLength (
83 ACPI_PARSE_STATE *ParserState)
84 {
85 UINT8 *Aml = ParserState->Aml;
86 UINT32 PackageLength = 0;
87 UINT32 ByteCount;
88 UINT8 ByteZeroMask = 0x3F; /* Default [0:5] */
89
90
91 ACPI_FUNCTION_TRACE (PsGetNextPackageLength);
92
93
94 /*
95 * Byte 0 bits [6:7] contain the number of additional bytes
96 * used to encode the package length, either 0,1,2, or 3
97 */
98 ByteCount = (Aml[0] >> 6);
99 ParserState->Aml += ((ACPI_SIZE) ByteCount + 1);
100
101 /* Get bytes 3, 2, 1 as needed */
102
103 while (ByteCount)
104 {
105 /*
106 * Final bit positions for the package length bytes:
107 * Byte3->[20:27]
108 * Byte2->[12:19]
109 * Byte1->[04:11]
110 * Byte0->[00:03]
111 */
112 PackageLength |= (Aml[ByteCount] << ((ByteCount << 3) - 4));
113
114 ByteZeroMask = 0x0F; /* Use bits [0:3] of byte 0 */
115 ByteCount--;
116 }
117
118 /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
119
120 PackageLength |= (Aml[0] & ByteZeroMask);
121 return_UINT32 (PackageLength);
122 }
123
124
125 /*******************************************************************************
126 *
127 * FUNCTION: AcpiPsGetNextPackageEnd
128 *
129 * PARAMETERS: ParserState - Current parser state object
130 *
131 * RETURN: Pointer to end-of-package +1
132 *
133 * DESCRIPTION: Get next package length and return a pointer past the end of
134 * the package. Consumes the package length field
135 *
136 ******************************************************************************/
137
138 UINT8 *
139 AcpiPsGetNextPackageEnd (
140 ACPI_PARSE_STATE *ParserState)
141 {
142 UINT8 *Start = ParserState->Aml;
143 UINT32 PackageLength;
144
145
146 ACPI_FUNCTION_TRACE (PsGetNextPackageEnd);
147
148
149 /* Function below updates ParserState->Aml */
150
151 PackageLength = AcpiPsGetNextPackageLength (ParserState);
152
153 return_PTR (Start + PackageLength); /* end of package */
154 }
155
156
157 /*******************************************************************************
158 *
159 * FUNCTION: AcpiPsGetNextNamestring
160 *
161 * PARAMETERS: ParserState - Current parser state object
162 *
163 * RETURN: Pointer to the start of the name string (pointer points into
164 * the AML.
165 *
166 * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
167 * prefix characters. Set parser state to point past the string.
168 * (Name is consumed from the AML.)
169 *
170 ******************************************************************************/
171
172 char *
173 AcpiPsGetNextNamestring (
174 ACPI_PARSE_STATE *ParserState)
175 {
176 UINT8 *Start = ParserState->Aml;
177 UINT8 *End = ParserState->Aml;
178
179
180 ACPI_FUNCTION_TRACE (PsGetNextNamestring);
181
182
183 /* Point past any namestring prefix characters (backslash or carat) */
184
185 while (ACPI_IS_ROOT_PREFIX (*End) ||
186 ACPI_IS_PARENT_PREFIX (*End))
187 {
188 End++;
189 }
190
191 /* Decode the path prefix character */
192
193 switch (*End)
194 {
195 case 0:
196
197 /* NullName */
198
199 if (End == Start)
200 {
201 Start = NULL;
202 }
203 End++;
204 break;
205
206 case AML_DUAL_NAME_PREFIX:
207
208 /* Two name segments */
209
210 End += 1 + (2 * ACPI_NAME_SIZE);
211 break;
212
213 case AML_MULTI_NAME_PREFIX_OP:
214
215 /* Multiple name segments, 4 chars each, count in next byte */
216
217 End += 2 + (*(End + 1) * ACPI_NAME_SIZE);
218 break;
219
220 default:
221
222 /* Single name segment */
223
224 End += ACPI_NAME_SIZE;
225 break;
226 }
227
228 ParserState->Aml = End;
229 return_PTR ((char *) Start);
230 }
231
232
233 /*******************************************************************************
234 *
235 * FUNCTION: AcpiPsGetNextNamepath
236 *
237 * PARAMETERS: ParserState - Current parser state object
238 * Arg - Where the namepath will be stored
239 * ArgCount - If the namepath points to a control method
240 * the method's argument is returned here.
241 * PossibleMethodCall - Whether the namepath can possibly be the
242 * start of a method call
243 *
244 * RETURN: Status
245 *
246 * DESCRIPTION: Get next name (if method call, return # of required args).
247 * Names are looked up in the internal namespace to determine
248 * if the name represents a control method. If a method
249 * is found, the number of arguments to the method is returned.
250 * This information is critical for parsing to continue correctly.
251 *
252 ******************************************************************************/
253
254 ACPI_STATUS
255 AcpiPsGetNextNamepath (
256 ACPI_WALK_STATE *WalkState,
257 ACPI_PARSE_STATE *ParserState,
258 ACPI_PARSE_OBJECT *Arg,
259 BOOLEAN PossibleMethodCall)
260 {
261 ACPI_STATUS Status;
262 char *Path;
263 ACPI_PARSE_OBJECT *NameOp;
264 ACPI_OPERAND_OBJECT *MethodDesc;
265 ACPI_NAMESPACE_NODE *Node;
266 UINT8 *Start = ParserState->Aml;
267
268
269 ACPI_FUNCTION_TRACE (PsGetNextNamepath);
270
271
272 Path = AcpiPsGetNextNamestring (ParserState);
273 AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
274
275 /* Null path case is allowed, just exit */
276
277 if (!Path)
278 {
279 Arg->Common.Value.Name = Path;
280 return_ACPI_STATUS (AE_OK);
281 }
282
283 /*
284 * Lookup the name in the internal namespace, starting with the current
285 * scope. We don't want to add anything new to the namespace here,
286 * however, so we use MODE_EXECUTE.
287 * Allow searching of the parent tree, but don't open a new scope -
288 * we just want to lookup the object (must be mode EXECUTE to perform
289 * the upsearch)
290 */
291 Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
292 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
293 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
294
295 /*
296 * If this name is a control method invocation, we must
297 * setup the method call
298 */
299 if (ACPI_SUCCESS (Status) &&
300 PossibleMethodCall &&
301 (Node->Type == ACPI_TYPE_METHOD))
302 {
303 if (WalkState->Opcode == AML_UNLOAD_OP)
304 {
305 /*
306 * AcpiPsGetNextNamestring has increased the AML pointer,
307 * so we need to restore the saved AML pointer for method call.
308 */
309 WalkState->ParserState.Aml = Start;
310 WalkState->ArgCount = 1;
311 AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
312 return_ACPI_STATUS (AE_OK);
313 }
314
315 /* This name is actually a control method invocation */
316
317 MethodDesc = AcpiNsGetAttachedObject (Node);
318 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
319 "Control Method - %p Desc %p Path=%p\n", Node, MethodDesc, Path));
320
321 NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
322 if (!NameOp)
323 {
324 return_ACPI_STATUS (AE_NO_MEMORY);
325 }
326
327 /* Change Arg into a METHOD CALL and attach name to it */
328
329 AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
330 NameOp->Common.Value.Name = Path;
331
332 /* Point METHODCALL/NAME to the METHOD Node */
333
334 NameOp->Common.Node = Node;
335 AcpiPsAppendArg (Arg, NameOp);
336
337 if (!MethodDesc)
338 {
339 ACPI_ERROR ((AE_INFO,
340 "Control Method %p has no attached object",
341 Node));
342 return_ACPI_STATUS (AE_AML_INTERNAL);
343 }
344
345 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
346 "Control Method - %p Args %X\n",
347 Node, MethodDesc->Method.ParamCount));
348
349 /* Get the number of arguments to expect */
350
351 WalkState->ArgCount = MethodDesc->Method.ParamCount;
352 return_ACPI_STATUS (AE_OK);
353 }
354
355 /*
356 * Special handling if the name was not found during the lookup -
357 * some NotFound cases are allowed
358 */
359 if (Status == AE_NOT_FOUND)
360 {
361 /* 1) NotFound is ok during load pass 1/2 (allow forward references) */
362
363 if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) !=
364 ACPI_PARSE_EXECUTE)
365 {
366 Status = AE_OK;
367 }
368
369 /* 2) NotFound during a CondRefOf(x) is ok by definition */
370
371 else if (WalkState->Op->Common.AmlOpcode == AML_COND_REF_OF_OP)
372 {
373 Status = AE_OK;
374 }
375
376 /*
377 * 3) NotFound while building a Package is ok at this point, we
378 * may flag as an error later if slack mode is not enabled.
379 * (Some ASL code depends on allowing this behavior)
380 */
381 else if ((Arg->Common.Parent) &&
382 ((Arg->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
383 (Arg->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
384 {
385 Status = AE_OK;
386 }
387 }
388
389 /* Final exception check (may have been changed from code above) */
390
391 if (ACPI_FAILURE (Status))
392 {
393 ACPI_ERROR_NAMESPACE (Path, Status);
394
395 if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==
396 ACPI_PARSE_EXECUTE)
397 {
398 /* Report a control method execution error */
399
400 Status = AcpiDsMethodError (Status, WalkState);
401 }
402 }
403
404 /* Save the namepath */
405
406 Arg->Common.Value.Name = Path;
407 return_ACPI_STATUS (Status);
408 }
409
410
411 /*******************************************************************************
412 *
413 * FUNCTION: AcpiPsGetNextSimpleArg
414 *
415 * PARAMETERS: ParserState - Current parser state object
416 * ArgType - The argument type (AML_*_ARG)
417 * Arg - Where the argument is returned
418 *
419 * RETURN: None
420 *
421 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
422 *
423 ******************************************************************************/
424
425 void
426 AcpiPsGetNextSimpleArg (
427 ACPI_PARSE_STATE *ParserState,
428 UINT32 ArgType,
429 ACPI_PARSE_OBJECT *Arg)
430 {
431 UINT32 Length;
432 UINT16 Opcode;
433 UINT8 *Aml = ParserState->Aml;
434
435
436 ACPI_FUNCTION_TRACE_U32 (PsGetNextSimpleArg, ArgType);
437
438
439 switch (ArgType)
440 {
441 case ARGP_BYTEDATA:
442
443 /* Get 1 byte from the AML stream */
444
445 Opcode = AML_BYTE_OP;
446 Arg->Common.Value.Integer = (UINT64) *Aml;
447 Length = 1;
448 break;
449
450 case ARGP_WORDDATA:
451
452 /* Get 2 bytes from the AML stream */
453
454 Opcode = AML_WORD_OP;
455 ACPI_MOVE_16_TO_64 (&Arg->Common.Value.Integer, Aml);
456 Length = 2;
457 break;
458
459 case ARGP_DWORDDATA:
460
461 /* Get 4 bytes from the AML stream */
462
463 Opcode = AML_DWORD_OP;
464 ACPI_MOVE_32_TO_64 (&Arg->Common.Value.Integer, Aml);
465 Length = 4;
466 break;
467
468 case ARGP_QWORDDATA:
469
470 /* Get 8 bytes from the AML stream */
471
472 Opcode = AML_QWORD_OP;
473 ACPI_MOVE_64_TO_64 (&Arg->Common.Value.Integer, Aml);
474 Length = 8;
475 break;
476
477 case ARGP_CHARLIST:
478
479 /* Get a pointer to the string, point past the string */
480
481 Opcode = AML_STRING_OP;
482 Arg->Common.Value.String = ACPI_CAST_PTR (char, Aml);
483
484 /* Find the null terminator */
485
486 Length = 0;
487 while (Aml[Length])
488 {
489 Length++;
490 }
491 Length++;
492 break;
493
494 case ARGP_NAME:
495 case ARGP_NAMESTRING:
496
497 AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
498 Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
499 return_VOID;
500
501 default:
502
503 ACPI_ERROR ((AE_INFO, "Invalid ArgType 0x%X", ArgType));
504 return_VOID;
505 }
506
507 AcpiPsInitOp (Arg, Opcode);
508 ParserState->Aml += Length;
509 return_VOID;
510 }
511
512
513 /*******************************************************************************
514 *
515 * FUNCTION: AcpiPsGetNextField
516 *
517 * PARAMETERS: ParserState - Current parser state object
518 *
519 * RETURN: A newly allocated FIELD op
520 *
521 * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
522 *
523 ******************************************************************************/
524
525 static ACPI_PARSE_OBJECT *
526 AcpiPsGetNextField (
527 ACPI_PARSE_STATE *ParserState)
528 {
529 UINT32 AmlOffset;
530 ACPI_PARSE_OBJECT *Field;
531 ACPI_PARSE_OBJECT *Arg = NULL;
532 UINT16 Opcode;
533 UINT32 Name;
534 UINT8 AccessType;
535 UINT8 AccessAttribute;
536 UINT8 AccessLength;
537 UINT32 PkgLength;
538 UINT8 *PkgEnd;
539 UINT32 BufferLength;
540
541
542 ACPI_FUNCTION_TRACE (PsGetNextField);
543
544
545 AmlOffset = (UINT32) ACPI_PTR_DIFF (
546 ParserState->Aml, ParserState->AmlStart);
547
548 /* Determine field type */
549
550 switch (ACPI_GET8 (ParserState->Aml))
551 {
552 case AML_FIELD_OFFSET_OP:
553
554 Opcode = AML_INT_RESERVEDFIELD_OP;
555 ParserState->Aml++;
556 break;
557
558 case AML_FIELD_ACCESS_OP:
559
560 Opcode = AML_INT_ACCESSFIELD_OP;
561 ParserState->Aml++;
562 break;
563
564 case AML_FIELD_CONNECTION_OP:
565
566 Opcode = AML_INT_CONNECTION_OP;
567 ParserState->Aml++;
568 break;
569
570 case AML_FIELD_EXT_ACCESS_OP:
571
572 Opcode = AML_INT_EXTACCESSFIELD_OP;
573 ParserState->Aml++;
574 break;
575
576 default:
577
578 Opcode = AML_INT_NAMEDFIELD_OP;
579 break;
580 }
581
582 /* Allocate a new field op */
583
584 Field = AcpiPsAllocOp (Opcode);
585 if (!Field)
586 {
587 return_PTR (NULL);
588 }
589
590 Field->Common.AmlOffset = AmlOffset;
591
592 /* Decode the field type */
593
594 switch (Opcode)
595 {
596 case AML_INT_NAMEDFIELD_OP:
597
598 /* Get the 4-character name */
599
600 ACPI_MOVE_32_TO_32 (&Name, ParserState->Aml);
601 AcpiPsSetName (Field, Name);
602 ParserState->Aml += ACPI_NAME_SIZE;
603
604 /* Get the length which is encoded as a package length */
605
606 Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
607 break;
608
609
610 case AML_INT_RESERVEDFIELD_OP:
611
612 /* Get the length which is encoded as a package length */
613
614 Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
615 break;
616
617
618 case AML_INT_ACCESSFIELD_OP:
619 case AML_INT_EXTACCESSFIELD_OP:
620
621 /*
622 * Get AccessType and AccessAttrib and merge into the field Op
623 * AccessType is first operand, AccessAttribute is second. stuff
624 * these bytes into the node integer value for convenience.
625 */
626
627 /* Get the two bytes (Type/Attribute) */
628
629 AccessType = ACPI_GET8 (ParserState->Aml);
630 ParserState->Aml++;
631 AccessAttribute = ACPI_GET8 (ParserState->Aml);
632 ParserState->Aml++;
633
634 Field->Common.Value.Integer = (UINT8) AccessType;
635 Field->Common.Value.Integer |= (UINT16) (AccessAttribute << 8);
636
637 /* This opcode has a third byte, AccessLength */
638
639 if (Opcode == AML_INT_EXTACCESSFIELD_OP)
640 {
641 AccessLength = ACPI_GET8 (ParserState->Aml);
642 ParserState->Aml++;
643
644 Field->Common.Value.Integer |= (UINT32) (AccessLength << 16);
645 }
646 break;
647
648
649 case AML_INT_CONNECTION_OP:
650
651 /*
652 * Argument for Connection operator can be either a Buffer
653 * (resource descriptor), or a NameString.
654 */
655 if (ACPI_GET8 (ParserState->Aml) == AML_BUFFER_OP)
656 {
657 ParserState->Aml++;
658
659 PkgEnd = ParserState->Aml;
660 PkgLength = AcpiPsGetNextPackageLength (ParserState);
661 PkgEnd += PkgLength;
662
663 if (ParserState->Aml < PkgEnd)
664 {
665 /* Non-empty list */
666
667 Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
668 if (!Arg)
669 {
670 AcpiPsFreeOp (Field);
671 return_PTR (NULL);
672 }
673
674 /* Get the actual buffer length argument */
675
676 Opcode = ACPI_GET8 (ParserState->Aml);
677 ParserState->Aml++;
678
679 switch (Opcode)
680 {
681 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
682
683 BufferLength = ACPI_GET8 (ParserState->Aml);
684 ParserState->Aml += 1;
685 break;
686
687 case AML_WORD_OP: /* AML_WORDDATA_ARG */
688
689 BufferLength = ACPI_GET16 (ParserState->Aml);
690 ParserState->Aml += 2;
691 break;
692
693 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
694
695 BufferLength = ACPI_GET32 (ParserState->Aml);
696 ParserState->Aml += 4;
697 break;
698
699 default:
700
701 BufferLength = 0;
702 break;
703 }
704
705 /* Fill in bytelist data */
706
707 Arg->Named.Value.Size = BufferLength;
708 Arg->Named.Data = ParserState->Aml;
709 }
710
711 /* Skip to End of byte data */
712
713 ParserState->Aml = PkgEnd;
714 }
715 else
716 {
717 Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
718 if (!Arg)
719 {
720 AcpiPsFreeOp (Field);
721 return_PTR (NULL);
722 }
723
724 /* Get the Namestring argument */
725
726 Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
727 }
728
729 /* Link the buffer/namestring to parent (CONNECTION_OP) */
730
731 AcpiPsAppendArg (Field, Arg);
732 break;
733
734
735 default:
736
737 /* Opcode was set in previous switch */
738 break;
739 }
740
741 return_PTR (Field);
742 }
743
744
745 /*******************************************************************************
746 *
747 * FUNCTION: AcpiPsGetNextArg
748 *
749 * PARAMETERS: WalkState - Current state
750 * ParserState - Current parser state object
751 * ArgType - The argument type (AML_*_ARG)
752 * ReturnArg - Where the next arg is returned
753 *
754 * RETURN: Status, and an op object containing the next argument.
755 *
756 * DESCRIPTION: Get next argument (including complex list arguments that require
757 * pushing the parser stack)
758 *
759 ******************************************************************************/
760
761 ACPI_STATUS
762 AcpiPsGetNextArg (
763 ACPI_WALK_STATE *WalkState,
764 ACPI_PARSE_STATE *ParserState,
765 UINT32 ArgType,
766 ACPI_PARSE_OBJECT **ReturnArg)
767 {
768 ACPI_PARSE_OBJECT *Arg = NULL;
769 ACPI_PARSE_OBJECT *Prev = NULL;
770 ACPI_PARSE_OBJECT *Field;
771 UINT32 Subop;
772 ACPI_STATUS Status = AE_OK;
773
774
775 ACPI_FUNCTION_TRACE_PTR (PsGetNextArg, ParserState);
776
777
778 switch (ArgType)
779 {
780 case ARGP_BYTEDATA:
781 case ARGP_WORDDATA:
782 case ARGP_DWORDDATA:
783 case ARGP_CHARLIST:
784 case ARGP_NAME:
785 case ARGP_NAMESTRING:
786
787 /* Constants, strings, and namestrings are all the same size */
788
789 Arg = AcpiPsAllocOp (AML_BYTE_OP);
790 if (!Arg)
791 {
792 return_ACPI_STATUS (AE_NO_MEMORY);
793 }
794 AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
795 break;
796
797 case ARGP_PKGLENGTH:
798
799 /* Package length, nothing returned */
800
801 ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
802 break;
803
804 case ARGP_FIELDLIST:
805
806 if (ParserState->Aml < ParserState->PkgEnd)
807 {
808 /* Non-empty list */
809
810 while (ParserState->Aml < ParserState->PkgEnd)
811 {
812 Field = AcpiPsGetNextField (ParserState);
813 if (!Field)
814 {
815 return_ACPI_STATUS (AE_NO_MEMORY);
816 }
817
818 if (Prev)
819 {
820 Prev->Common.Next = Field;
821 }
822 else
823 {
824 Arg = Field;
825 }
826 Prev = Field;
827 }
828
829 /* Skip to End of byte data */
830
831 ParserState->Aml = ParserState->PkgEnd;
832 }
833 break;
834
835 case ARGP_BYTELIST:
836
837 if (ParserState->Aml < ParserState->PkgEnd)
838 {
839 /* Non-empty list */
840
841 Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
842 if (!Arg)
843 {
844 return_ACPI_STATUS (AE_NO_MEMORY);
845 }
846
847 /* Fill in bytelist data */
848
849 Arg->Common.Value.Size = (UINT32)
850 ACPI_PTR_DIFF (ParserState->PkgEnd, ParserState->Aml);
851 Arg->Named.Data = ParserState->Aml;
852
853 /* Skip to End of byte data */
854
855 ParserState->Aml = ParserState->PkgEnd;
856 }
857 break;
858
859 case ARGP_TARGET:
860 case ARGP_SUPERNAME:
861 case ARGP_SIMPLENAME:
862
863 Subop = AcpiPsPeekOpcode (ParserState);
864 if (Subop == 0 ||
865 AcpiPsIsLeadingChar (Subop) ||
866 ACPI_IS_ROOT_PREFIX (Subop) ||
867 ACPI_IS_PARENT_PREFIX (Subop))
868 {
869 /* NullName or NameString */
870
871 Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
872 if (!Arg)
873 {
874 return_ACPI_STATUS (AE_NO_MEMORY);
875 }
876
877 /* To support SuperName arg of Unload */
878
879 if (WalkState->Opcode == AML_UNLOAD_OP)
880 {
881 Status = AcpiPsGetNextNamepath (WalkState, ParserState, Arg, 1);
882
883 /*
884 * If the SuperName arg of Unload is a method call,
885 * we have restored the AML pointer, just free this Arg
886 */
887 if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)
888 {
889 AcpiPsFreeOp (Arg);
890 Arg = NULL;
891 }
892 }
893 else
894 {
895 Status = AcpiPsGetNextNamepath (WalkState, ParserState, Arg, 0);
896 }
897 }
898 else
899 {
900 /* Single complex argument, nothing returned */
901
902 WalkState->ArgCount = 1;
903 }
904 break;
905
906 case ARGP_DATAOBJ:
907 case ARGP_TERMARG:
908
909 /* Single complex argument, nothing returned */
910
911 WalkState->ArgCount = 1;
912 break;
913
914 case ARGP_DATAOBJLIST:
915 case ARGP_TERMLIST:
916 case ARGP_OBJLIST:
917
918 if (ParserState->Aml < ParserState->PkgEnd)
919 {
920 /* Non-empty list of variable arguments, nothing returned */
921
922 WalkState->ArgCount = ACPI_VAR_ARGS;
923 }
924 break;
925
926 default:
927
928 ACPI_ERROR ((AE_INFO, "Invalid ArgType: 0x%X", ArgType));
929 Status = AE_AML_OPERAND_TYPE;
930 break;
931 }
932
933 *ReturnArg = Arg;
934 return_ACPI_STATUS (Status);
935 }