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