psargs.c revision 281075
1/******************************************************************************
2 *
3 * Module Name: psargs - Parse AML opcode arguments
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2015, 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 <contrib/dev/acpica/include/acpi.h>
45#include <contrib/dev/acpica/include/accommon.h>
46#include <contrib/dev/acpica/include/acparser.h>
47#include <contrib/dev/acpica/include/amlcode.h>
48#include <contrib/dev/acpica/include/acnamesp.h>
49#include <contrib/dev/acpica/include/acdispat.h>
50
51#define _COMPONENT          ACPI_PARSER
52        ACPI_MODULE_NAME    ("psargs")
53
54/* Local prototypes */
55
56static UINT32
57AcpiPsGetNextPackageLength (
58    ACPI_PARSE_STATE        *ParserState);
59
60static ACPI_PARSE_OBJECT *
61AcpiPsGetNextField (
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
79static UINT32
80AcpiPsGetNextPackageLength (
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
136UINT8 *
137AcpiPsGetNextPackageEnd (
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
170char *
171AcpiPsGetNextNamestring (
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
252ACPI_STATUS
253AcpiPsGetNextNamepath (
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        if (WalkState->Opcode == AML_UNLOAD_OP)
302        {
303            /*
304             * AcpiPsGetNextNamestring has increased the AML pointer,
305             * so we need to restore the saved AML pointer for method call.
306             */
307            WalkState->ParserState.Aml = Start;
308            WalkState->ArgCount = 1;
309            AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
310            return_ACPI_STATUS (AE_OK);
311        }
312
313        /* This name is actually a control method invocation */
314
315        MethodDesc = AcpiNsGetAttachedObject (Node);
316        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
317            "Control Method - %p Desc %p Path=%p\n", Node, MethodDesc, Path));
318
319        NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
320        if (!NameOp)
321        {
322            return_ACPI_STATUS (AE_NO_MEMORY);
323        }
324
325        /* Change Arg into a METHOD CALL and attach name to it */
326
327        AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
328        NameOp->Common.Value.Name = Path;
329
330        /* Point METHODCALL/NAME to the METHOD Node */
331
332        NameOp->Common.Node = Node;
333        AcpiPsAppendArg (Arg, NameOp);
334
335        if (!MethodDesc)
336        {
337            ACPI_ERROR ((AE_INFO,
338                "Control Method %p has no attached object",
339                Node));
340            return_ACPI_STATUS (AE_AML_INTERNAL);
341        }
342
343        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
344            "Control Method - %p Args %X\n",
345            Node, MethodDesc->Method.ParamCount));
346
347        /* Get the number of arguments to expect */
348
349        WalkState->ArgCount = MethodDesc->Method.ParamCount;
350        return_ACPI_STATUS (AE_OK);
351    }
352
353    /*
354     * Special handling if the name was not found during the lookup -
355     * some NotFound cases are allowed
356     */
357    if (Status == AE_NOT_FOUND)
358    {
359        /* 1) NotFound is ok during load pass 1/2 (allow forward references) */
360
361        if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) !=
362                ACPI_PARSE_EXECUTE)
363        {
364            Status = AE_OK;
365        }
366
367        /* 2) NotFound during a CondRefOf(x) is ok by definition */
368
369        else if (WalkState->Op->Common.AmlOpcode == AML_COND_REF_OF_OP)
370        {
371            Status = AE_OK;
372        }
373
374        /*
375         * 3) NotFound while building a Package is ok at this point, we
376         * may flag as an error later if slack mode is not enabled.
377         * (Some ASL code depends on allowing this behavior)
378         */
379        else if ((Arg->Common.Parent) &&
380            ((Arg->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
381             (Arg->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
382        {
383            Status = AE_OK;
384        }
385    }
386
387    /* Final exception check (may have been changed from code above) */
388
389    if (ACPI_FAILURE (Status))
390    {
391        ACPI_ERROR_NAMESPACE (Path, Status);
392
393        if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==
394                ACPI_PARSE_EXECUTE)
395        {
396            /* Report a control method execution error */
397
398            Status = AcpiDsMethodError (Status, WalkState);
399        }
400    }
401
402    /* Save the namepath */
403
404    Arg->Common.Value.Name = Path;
405    return_ACPI_STATUS (Status);
406}
407
408
409/*******************************************************************************
410 *
411 * FUNCTION:    AcpiPsGetNextSimpleArg
412 *
413 * PARAMETERS:  ParserState         - Current parser state object
414 *              ArgType             - The argument type (AML_*_ARG)
415 *              Arg                 - Where the argument is returned
416 *
417 * RETURN:      None
418 *
419 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
420 *
421 ******************************************************************************/
422
423void
424AcpiPsGetNextSimpleArg (
425    ACPI_PARSE_STATE        *ParserState,
426    UINT32                  ArgType,
427    ACPI_PARSE_OBJECT       *Arg)
428{
429    UINT32                  Length;
430    UINT16                  Opcode;
431    UINT8                   *Aml = ParserState->Aml;
432
433
434    ACPI_FUNCTION_TRACE_U32 (PsGetNextSimpleArg, ArgType);
435
436
437    switch (ArgType)
438    {
439    case ARGP_BYTEDATA:
440
441        /* Get 1 byte from the AML stream */
442
443        Opcode = AML_BYTE_OP;
444        Arg->Common.Value.Integer = (UINT64) *Aml;
445        Length = 1;
446        break;
447
448    case ARGP_WORDDATA:
449
450        /* Get 2 bytes from the AML stream */
451
452        Opcode = AML_WORD_OP;
453        ACPI_MOVE_16_TO_64 (&Arg->Common.Value.Integer, Aml);
454        Length = 2;
455        break;
456
457    case ARGP_DWORDDATA:
458
459        /* Get 4 bytes from the AML stream */
460
461        Opcode = AML_DWORD_OP;
462        ACPI_MOVE_32_TO_64 (&Arg->Common.Value.Integer, Aml);
463        Length = 4;
464        break;
465
466    case ARGP_QWORDDATA:
467
468        /* Get 8 bytes from the AML stream */
469
470        Opcode = AML_QWORD_OP;
471        ACPI_MOVE_64_TO_64 (&Arg->Common.Value.Integer, Aml);
472        Length = 8;
473        break;
474
475    case ARGP_CHARLIST:
476
477        /* Get a pointer to the string, point past the string */
478
479        Opcode = AML_STRING_OP;
480        Arg->Common.Value.String = ACPI_CAST_PTR (char, Aml);
481
482        /* Find the null terminator */
483
484        Length = 0;
485        while (Aml[Length])
486        {
487            Length++;
488        }
489        Length++;
490        break;
491
492    case ARGP_NAME:
493    case ARGP_NAMESTRING:
494
495        AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
496        Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
497        return_VOID;
498
499    default:
500
501        ACPI_ERROR ((AE_INFO, "Invalid ArgType 0x%X", ArgType));
502        return_VOID;
503    }
504
505    AcpiPsInitOp (Arg, Opcode);
506    ParserState->Aml += Length;
507    return_VOID;
508}
509
510
511/*******************************************************************************
512 *
513 * FUNCTION:    AcpiPsGetNextField
514 *
515 * PARAMETERS:  ParserState         - Current parser state object
516 *
517 * RETURN:      A newly allocated FIELD op
518 *
519 * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
520 *
521 ******************************************************************************/
522
523static ACPI_PARSE_OBJECT *
524AcpiPsGetNextField (
525    ACPI_PARSE_STATE        *ParserState)
526{
527    UINT32                  AmlOffset;
528    ACPI_PARSE_OBJECT       *Field;
529    ACPI_PARSE_OBJECT       *Arg = NULL;
530    UINT16                  Opcode;
531    UINT32                  Name;
532    UINT8                   AccessType;
533    UINT8                   AccessAttribute;
534    UINT8                   AccessLength;
535    UINT32                  PkgLength;
536    UINT8                   *PkgEnd;
537    UINT32                  BufferLength;
538
539
540    ACPI_FUNCTION_TRACE (PsGetNextField);
541
542
543    AmlOffset = (UINT32) ACPI_PTR_DIFF (
544        ParserState->Aml, ParserState->AmlStart);
545
546    /* Determine field type */
547
548    switch (ACPI_GET8 (ParserState->Aml))
549    {
550    case AML_FIELD_OFFSET_OP:
551
552        Opcode = AML_INT_RESERVEDFIELD_OP;
553        ParserState->Aml++;
554        break;
555
556    case AML_FIELD_ACCESS_OP:
557
558        Opcode = AML_INT_ACCESSFIELD_OP;
559        ParserState->Aml++;
560        break;
561
562    case AML_FIELD_CONNECTION_OP:
563
564        Opcode = AML_INT_CONNECTION_OP;
565        ParserState->Aml++;
566        break;
567
568    case AML_FIELD_EXT_ACCESS_OP:
569
570        Opcode = AML_INT_EXTACCESSFIELD_OP;
571        ParserState->Aml++;
572        break;
573
574    default:
575
576        Opcode = AML_INT_NAMEDFIELD_OP;
577        break;
578    }
579
580    /* Allocate a new field op */
581
582    Field = AcpiPsAllocOp (Opcode);
583    if (!Field)
584    {
585        return_PTR (NULL);
586    }
587
588    Field->Common.AmlOffset = AmlOffset;
589
590    /* Decode the field type */
591
592    switch (Opcode)
593    {
594    case AML_INT_NAMEDFIELD_OP:
595
596        /* Get the 4-character name */
597
598        ACPI_MOVE_32_TO_32 (&Name, ParserState->Aml);
599        AcpiPsSetName (Field, Name);
600        ParserState->Aml += ACPI_NAME_SIZE;
601
602        /* Get the length which is encoded as a package length */
603
604        Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
605        break;
606
607
608    case AML_INT_RESERVEDFIELD_OP:
609
610        /* Get the length which is encoded as a package length */
611
612        Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
613        break;
614
615
616    case AML_INT_ACCESSFIELD_OP:
617    case AML_INT_EXTACCESSFIELD_OP:
618
619        /*
620         * Get AccessType and AccessAttrib and merge into the field Op
621         * AccessType is first operand, AccessAttribute is second. stuff
622         * these bytes into the node integer value for convenience.
623         */
624
625        /* Get the two bytes (Type/Attribute) */
626
627        AccessType = ACPI_GET8 (ParserState->Aml);
628        ParserState->Aml++;
629        AccessAttribute = ACPI_GET8 (ParserState->Aml);
630        ParserState->Aml++;
631
632        Field->Common.Value.Integer = (UINT8) AccessType;
633        Field->Common.Value.Integer |= (UINT16) (AccessAttribute << 8);
634
635        /* This opcode has a third byte, AccessLength */
636
637        if (Opcode == AML_INT_EXTACCESSFIELD_OP)
638        {
639            AccessLength = ACPI_GET8 (ParserState->Aml);
640            ParserState->Aml++;
641
642            Field->Common.Value.Integer |= (UINT32) (AccessLength << 16);
643        }
644        break;
645
646
647    case AML_INT_CONNECTION_OP:
648
649        /*
650         * Argument for Connection operator can be either a Buffer
651         * (resource descriptor), or a NameString.
652         */
653        if (ACPI_GET8 (ParserState->Aml) == AML_BUFFER_OP)
654        {
655            ParserState->Aml++;
656
657            PkgEnd = ParserState->Aml;
658            PkgLength = AcpiPsGetNextPackageLength (ParserState);
659            PkgEnd += PkgLength;
660
661            if (ParserState->Aml < PkgEnd)
662            {
663                /* Non-empty list */
664
665                Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
666                if (!Arg)
667                {
668                    AcpiPsFreeOp (Field);
669                    return_PTR (NULL);
670                }
671
672                /* Get the actual buffer length argument */
673
674                Opcode = ACPI_GET8 (ParserState->Aml);
675                ParserState->Aml++;
676
677                switch (Opcode)
678                {
679                case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
680
681                    BufferLength = ACPI_GET8 (ParserState->Aml);
682                    ParserState->Aml += 1;
683                    break;
684
685                case AML_WORD_OP:       /* AML_WORDDATA_ARG */
686
687                    BufferLength = ACPI_GET16 (ParserState->Aml);
688                    ParserState->Aml += 2;
689                    break;
690
691                case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
692
693                    BufferLength = ACPI_GET32 (ParserState->Aml);
694                    ParserState->Aml += 4;
695                    break;
696
697                default:
698
699                    BufferLength = 0;
700                    break;
701                }
702
703                /* Fill in bytelist data */
704
705                Arg->Named.Value.Size = BufferLength;
706                Arg->Named.Data = ParserState->Aml;
707            }
708
709            /* Skip to End of byte data */
710
711            ParserState->Aml = PkgEnd;
712        }
713        else
714        {
715            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
716            if (!Arg)
717            {
718                AcpiPsFreeOp (Field);
719                return_PTR (NULL);
720            }
721
722            /* Get the Namestring argument */
723
724            Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
725        }
726
727        /* Link the buffer/namestring to parent (CONNECTION_OP) */
728
729        AcpiPsAppendArg (Field, Arg);
730        break;
731
732
733    default:
734
735        /* Opcode was set in previous switch */
736        break;
737    }
738
739    return_PTR (Field);
740}
741
742
743/*******************************************************************************
744 *
745 * FUNCTION:    AcpiPsGetNextArg
746 *
747 * PARAMETERS:  WalkState           - Current state
748 *              ParserState         - Current parser state object
749 *              ArgType             - The argument type (AML_*_ARG)
750 *              ReturnArg           - Where the next arg is returned
751 *
752 * RETURN:      Status, and an op object containing the next argument.
753 *
754 * DESCRIPTION: Get next argument (including complex list arguments that require
755 *              pushing the parser stack)
756 *
757 ******************************************************************************/
758
759ACPI_STATUS
760AcpiPsGetNextArg (
761    ACPI_WALK_STATE         *WalkState,
762    ACPI_PARSE_STATE        *ParserState,
763    UINT32                  ArgType,
764    ACPI_PARSE_OBJECT       **ReturnArg)
765{
766    ACPI_PARSE_OBJECT       *Arg = NULL;
767    ACPI_PARSE_OBJECT       *Prev = NULL;
768    ACPI_PARSE_OBJECT       *Field;
769    UINT32                  Subop;
770    ACPI_STATUS             Status = AE_OK;
771
772
773    ACPI_FUNCTION_TRACE_PTR (PsGetNextArg, ParserState);
774
775
776    switch (ArgType)
777    {
778    case ARGP_BYTEDATA:
779    case ARGP_WORDDATA:
780    case ARGP_DWORDDATA:
781    case ARGP_CHARLIST:
782    case ARGP_NAME:
783    case ARGP_NAMESTRING:
784
785        /* Constants, strings, and namestrings are all the same size */
786
787        Arg = AcpiPsAllocOp (AML_BYTE_OP);
788        if (!Arg)
789        {
790            return_ACPI_STATUS (AE_NO_MEMORY);
791        }
792        AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
793        break;
794
795    case ARGP_PKGLENGTH:
796
797        /* Package length, nothing returned */
798
799        ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
800        break;
801
802    case ARGP_FIELDLIST:
803
804        if (ParserState->Aml < ParserState->PkgEnd)
805        {
806            /* Non-empty list */
807
808            while (ParserState->Aml < ParserState->PkgEnd)
809            {
810                Field = AcpiPsGetNextField (ParserState);
811                if (!Field)
812                {
813                    return_ACPI_STATUS (AE_NO_MEMORY);
814                }
815
816                if (Prev)
817                {
818                    Prev->Common.Next = Field;
819                }
820                else
821                {
822                    Arg = Field;
823                }
824                Prev = Field;
825            }
826
827            /* Skip to End of byte data */
828
829            ParserState->Aml = ParserState->PkgEnd;
830        }
831        break;
832
833    case ARGP_BYTELIST:
834
835        if (ParserState->Aml < ParserState->PkgEnd)
836        {
837            /* Non-empty list */
838
839            Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
840            if (!Arg)
841            {
842                return_ACPI_STATUS (AE_NO_MEMORY);
843            }
844
845            /* Fill in bytelist data */
846
847            Arg->Common.Value.Size = (UINT32)
848                ACPI_PTR_DIFF (ParserState->PkgEnd, ParserState->Aml);
849            Arg->Named.Data = ParserState->Aml;
850
851            /* Skip to End of byte data */
852
853            ParserState->Aml = ParserState->PkgEnd;
854        }
855        break;
856
857    case ARGP_TARGET:
858    case ARGP_SUPERNAME:
859    case ARGP_SIMPLENAME:
860
861        Subop = AcpiPsPeekOpcode (ParserState);
862        if (Subop == 0                  ||
863            AcpiPsIsLeadingChar (Subop) ||
864            ACPI_IS_ROOT_PREFIX (Subop) ||
865            ACPI_IS_PARENT_PREFIX (Subop))
866        {
867            /* NullName or NameString */
868
869            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
870            if (!Arg)
871            {
872                return_ACPI_STATUS (AE_NO_MEMORY);
873            }
874
875            /* To support SuperName arg of Unload */
876
877            if (WalkState->Opcode == AML_UNLOAD_OP)
878            {
879                Status = AcpiPsGetNextNamepath (WalkState, ParserState, Arg, 1);
880
881                /*
882                 * If the SuperName arg of Unload is a method call,
883                 * we have restored the AML pointer, just free this Arg
884                 */
885                if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)
886                {
887                    AcpiPsFreeOp (Arg);
888                    Arg = NULL;
889                }
890            }
891            else
892            {
893                Status = AcpiPsGetNextNamepath (WalkState, ParserState, Arg, 0);
894            }
895        }
896        else
897        {
898            /* Single complex argument, nothing returned */
899
900            WalkState->ArgCount = 1;
901        }
902        break;
903
904    case ARGP_DATAOBJ:
905    case ARGP_TERMARG:
906
907        /* Single complex argument, nothing returned */
908
909        WalkState->ArgCount = 1;
910        break;
911
912    case ARGP_DATAOBJLIST:
913    case ARGP_TERMLIST:
914    case ARGP_OBJLIST:
915
916        if (ParserState->Aml < ParserState->PkgEnd)
917        {
918            /* Non-empty list of variable arguments, nothing returned */
919
920            WalkState->ArgCount = ACPI_VAR_ARGS;
921        }
922        break;
923
924    default:
925
926        ACPI_ERROR ((AE_INFO, "Invalid ArgType: 0x%X", ArgType));
927        Status = AE_AML_OPERAND_TYPE;
928        break;
929    }
930
931    *ReturnArg = Arg;
932    return_ACPI_STATUS (Status);
933}
934