psargs.c revision 246849
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 <contrib/dev/acpica/include/acpi.h>
47#include <contrib/dev/acpica/include/accommon.h>
48#include <contrib/dev/acpica/include/acparser.h>
49#include <contrib/dev/acpica/include/amlcode.h>
50#include <contrib/dev/acpica/include/acnamesp.h>
51#include <contrib/dev/acpica/include/acdispat.h>
52
53#define _COMPONENT          ACPI_PARSER
54        ACPI_MODULE_NAME    ("psargs")
55
56/* Local prototypes */
57
58static UINT32
59AcpiPsGetNextPackageLength (
60    ACPI_PARSE_STATE        *ParserState);
61
62static ACPI_PARSE_OBJECT *
63AcpiPsGetNextField (
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
81static UINT32
82AcpiPsGetNextPackageLength (
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
138UINT8 *
139AcpiPsGetNextPackageEnd (
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
172char *
173AcpiPsGetNextNamestring (
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
254ACPI_STATUS
255AcpiPsGetNextNamepath (
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
425void
426AcpiPsGetNextSimpleArg (
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
451    case ARGP_WORDDATA:
452
453        /* Get 2 bytes from the AML stream */
454
455        Opcode = AML_WORD_OP;
456        ACPI_MOVE_16_TO_64 (&Arg->Common.Value.Integer, Aml);
457        Length = 2;
458        break;
459
460
461    case ARGP_DWORDDATA:
462
463        /* Get 4 bytes from the AML stream */
464
465        Opcode = AML_DWORD_OP;
466        ACPI_MOVE_32_TO_64 (&Arg->Common.Value.Integer, Aml);
467        Length = 4;
468        break;
469
470
471    case ARGP_QWORDDATA:
472
473        /* Get 8 bytes from the AML stream */
474
475        Opcode = AML_QWORD_OP;
476        ACPI_MOVE_64_TO_64 (&Arg->Common.Value.Integer, Aml);
477        Length = 8;
478        break;
479
480
481    case ARGP_CHARLIST:
482
483        /* Get a pointer to the string, point past the string */
484
485        Opcode = AML_STRING_OP;
486        Arg->Common.Value.String = ACPI_CAST_PTR (char, Aml);
487
488        /* Find the null terminator */
489
490        Length = 0;
491        while (Aml[Length])
492        {
493            Length++;
494        }
495        Length++;
496        break;
497
498
499    case ARGP_NAME:
500    case ARGP_NAMESTRING:
501
502        AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
503        Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
504        return_VOID;
505
506
507    default:
508
509        ACPI_ERROR ((AE_INFO, "Invalid ArgType 0x%X", ArgType));
510        return_VOID;
511    }
512
513    AcpiPsInitOp (Arg, Opcode);
514    ParserState->Aml += Length;
515    return_VOID;
516}
517
518
519/*******************************************************************************
520 *
521 * FUNCTION:    AcpiPsGetNextField
522 *
523 * PARAMETERS:  ParserState         - Current parser state object
524 *
525 * RETURN:      A newly allocated FIELD op
526 *
527 * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
528 *
529 ******************************************************************************/
530
531static ACPI_PARSE_OBJECT *
532AcpiPsGetNextField (
533    ACPI_PARSE_STATE        *ParserState)
534{
535    UINT32                  AmlOffset;
536    ACPI_PARSE_OBJECT       *Field;
537    ACPI_PARSE_OBJECT       *Arg = NULL;
538    UINT16                  Opcode;
539    UINT32                  Name;
540    UINT8                   AccessType;
541    UINT8                   AccessAttribute;
542    UINT8                   AccessLength;
543    UINT32                  PkgLength;
544    UINT8                   *PkgEnd;
545    UINT32                  BufferLength;
546
547
548    ACPI_FUNCTION_TRACE (PsGetNextField);
549
550
551    AmlOffset = (UINT32) ACPI_PTR_DIFF (
552        ParserState->Aml, ParserState->AmlStart);
553
554    /* Determine field type */
555
556    switch (ACPI_GET8 (ParserState->Aml))
557    {
558    case AML_FIELD_OFFSET_OP:
559
560        Opcode = AML_INT_RESERVEDFIELD_OP;
561        ParserState->Aml++;
562        break;
563
564    case AML_FIELD_ACCESS_OP:
565
566        Opcode = AML_INT_ACCESSFIELD_OP;
567        ParserState->Aml++;
568        break;
569
570    case AML_FIELD_CONNECTION_OP:
571
572        Opcode = AML_INT_CONNECTION_OP;
573        ParserState->Aml++;
574        break;
575
576    case AML_FIELD_EXT_ACCESS_OP:
577
578        Opcode = AML_INT_EXTACCESSFIELD_OP;
579        ParserState->Aml++;
580        break;
581
582    default:
583
584        Opcode = AML_INT_NAMEDFIELD_OP;
585        break;
586    }
587
588    /* Allocate a new field op */
589
590    Field = AcpiPsAllocOp (Opcode);
591    if (!Field)
592    {
593        return_PTR (NULL);
594    }
595
596    Field->Common.AmlOffset = AmlOffset;
597
598    /* Decode the field type */
599
600    switch (Opcode)
601    {
602    case AML_INT_NAMEDFIELD_OP:
603
604        /* Get the 4-character name */
605
606        ACPI_MOVE_32_TO_32 (&Name, ParserState->Aml);
607        AcpiPsSetName (Field, Name);
608        ParserState->Aml += ACPI_NAME_SIZE;
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_RESERVEDFIELD_OP:
617
618        /* Get the length which is encoded as a package length */
619
620        Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
621        break;
622
623
624    case AML_INT_ACCESSFIELD_OP:
625    case AML_INT_EXTACCESSFIELD_OP:
626
627        /*
628         * Get AccessType and AccessAttrib and merge into the field Op
629         * AccessType is first operand, AccessAttribute is second. stuff
630         * these bytes into the node integer value for convenience.
631         */
632
633        /* Get the two bytes (Type/Attribute) */
634
635        AccessType = ACPI_GET8 (ParserState->Aml);
636        ParserState->Aml++;
637        AccessAttribute = ACPI_GET8 (ParserState->Aml);
638        ParserState->Aml++;
639
640        Field->Common.Value.Integer = (UINT8) AccessType;
641        Field->Common.Value.Integer |= (UINT16) (AccessAttribute << 8);
642
643        /* This opcode has a third byte, AccessLength */
644
645        if (Opcode == AML_INT_EXTACCESSFIELD_OP)
646        {
647            AccessLength = ACPI_GET8 (ParserState->Aml);
648            ParserState->Aml++;
649
650            Field->Common.Value.Integer |= (UINT32) (AccessLength << 16);
651        }
652        break;
653
654
655    case AML_INT_CONNECTION_OP:
656
657        /*
658         * Argument for Connection operator can be either a Buffer
659         * (resource descriptor), or a NameString.
660         */
661        if (ACPI_GET8 (ParserState->Aml) == AML_BUFFER_OP)
662        {
663            ParserState->Aml++;
664
665            PkgEnd = ParserState->Aml;
666            PkgLength = AcpiPsGetNextPackageLength (ParserState);
667            PkgEnd += PkgLength;
668
669            if (ParserState->Aml < PkgEnd)
670            {
671                /* Non-empty list */
672
673                Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
674                if (!Arg)
675                {
676                    AcpiPsFreeOp (Field);
677                    return_PTR (NULL);
678                }
679
680                /* Get the actual buffer length argument */
681
682                Opcode = ACPI_GET8 (ParserState->Aml);
683                ParserState->Aml++;
684
685                switch (Opcode)
686                {
687                case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
688                    BufferLength = ACPI_GET8 (ParserState->Aml);
689                    ParserState->Aml += 1;
690                    break;
691
692                case AML_WORD_OP:       /* AML_WORDDATA_ARG */
693                    BufferLength = ACPI_GET16 (ParserState->Aml);
694                    ParserState->Aml += 2;
695                    break;
696
697                case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
698                    BufferLength = ACPI_GET32 (ParserState->Aml);
699                    ParserState->Aml += 4;
700                    break;
701
702                default:
703                    BufferLength = 0;
704                    break;
705                }
706
707                /* Fill in bytelist data */
708
709                Arg->Named.Value.Size = BufferLength;
710                Arg->Named.Data = ParserState->Aml;
711            }
712
713            /* Skip to End of byte data */
714
715            ParserState->Aml = PkgEnd;
716        }
717        else
718        {
719            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
720            if (!Arg)
721            {
722                AcpiPsFreeOp (Field);
723                return_PTR (NULL);
724            }
725
726            /* Get the Namestring argument */
727
728            Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
729        }
730
731        /* Link the buffer/namestring to parent (CONNECTION_OP) */
732
733        AcpiPsAppendArg (Field, Arg);
734        break;
735
736
737    default:
738
739        /* Opcode was set in previous switch */
740        break;
741    }
742
743    return_PTR (Field);
744}
745
746
747/*******************************************************************************
748 *
749 * FUNCTION:    AcpiPsGetNextArg
750 *
751 * PARAMETERS:  WalkState           - Current state
752 *              ParserState         - Current parser state object
753 *              ArgType             - The argument type (AML_*_ARG)
754 *              ReturnArg           - Where the next arg is returned
755 *
756 * RETURN:      Status, and an op object containing the next argument.
757 *
758 * DESCRIPTION: Get next argument (including complex list arguments that require
759 *              pushing the parser stack)
760 *
761 ******************************************************************************/
762
763ACPI_STATUS
764AcpiPsGetNextArg (
765    ACPI_WALK_STATE         *WalkState,
766    ACPI_PARSE_STATE        *ParserState,
767    UINT32                  ArgType,
768    ACPI_PARSE_OBJECT       **ReturnArg)
769{
770    ACPI_PARSE_OBJECT       *Arg = NULL;
771    ACPI_PARSE_OBJECT       *Prev = NULL;
772    ACPI_PARSE_OBJECT       *Field;
773    UINT32                  Subop;
774    ACPI_STATUS             Status = AE_OK;
775
776
777    ACPI_FUNCTION_TRACE_PTR (PsGetNextArg, ParserState);
778
779
780    switch (ArgType)
781    {
782    case ARGP_BYTEDATA:
783    case ARGP_WORDDATA:
784    case ARGP_DWORDDATA:
785    case ARGP_CHARLIST:
786    case ARGP_NAME:
787    case ARGP_NAMESTRING:
788
789        /* Constants, strings, and namestrings are all the same size */
790
791        Arg = AcpiPsAllocOp (AML_BYTE_OP);
792        if (!Arg)
793        {
794            return_ACPI_STATUS (AE_NO_MEMORY);
795        }
796        AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
797        break;
798
799
800    case ARGP_PKGLENGTH:
801
802        /* Package length, nothing returned */
803
804        ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
805        break;
806
807
808    case ARGP_FIELDLIST:
809
810        if (ParserState->Aml < ParserState->PkgEnd)
811        {
812            /* Non-empty list */
813
814            while (ParserState->Aml < ParserState->PkgEnd)
815            {
816                Field = AcpiPsGetNextField (ParserState);
817                if (!Field)
818                {
819                    return_ACPI_STATUS (AE_NO_MEMORY);
820                }
821
822                if (Prev)
823                {
824                    Prev->Common.Next = Field;
825                }
826                else
827                {
828                    Arg = Field;
829                }
830                Prev = Field;
831            }
832
833            /* Skip to End of byte data */
834
835            ParserState->Aml = ParserState->PkgEnd;
836        }
837        break;
838
839
840    case ARGP_BYTELIST:
841
842        if (ParserState->Aml < ParserState->PkgEnd)
843        {
844            /* Non-empty list */
845
846            Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
847            if (!Arg)
848            {
849                return_ACPI_STATUS (AE_NO_MEMORY);
850            }
851
852            /* Fill in bytelist data */
853
854            Arg->Common.Value.Size = (UINT32)
855                ACPI_PTR_DIFF (ParserState->PkgEnd, ParserState->Aml);
856            Arg->Named.Data = ParserState->Aml;
857
858            /* Skip to End of byte data */
859
860            ParserState->Aml = ParserState->PkgEnd;
861        }
862        break;
863
864
865    case ARGP_TARGET:
866    case ARGP_SUPERNAME:
867    case ARGP_SIMPLENAME:
868
869        Subop = AcpiPsPeekOpcode (ParserState);
870        if (Subop == 0                  ||
871            AcpiPsIsLeadingChar (Subop) ||
872            ACPI_IS_ROOT_PREFIX (Subop) ||
873            ACPI_IS_PARENT_PREFIX (Subop))
874        {
875            /* NullName or NameString */
876
877            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
878            if (!Arg)
879            {
880                return_ACPI_STATUS (AE_NO_MEMORY);
881            }
882
883            /* To support SuperName arg of Unload */
884
885            if (WalkState->Opcode == AML_UNLOAD_OP)
886            {
887                Status = AcpiPsGetNextNamepath (WalkState, ParserState, Arg, 1);
888
889                /*
890                 * If the SuperName arg of Unload is a method call,
891                 * we have restored the AML pointer, just free this Arg
892                 */
893                if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)
894                {
895                    AcpiPsFreeOp (Arg);
896                    Arg = NULL;
897                }
898            }
899            else
900            {
901                Status = AcpiPsGetNextNamepath (WalkState, ParserState, Arg, 0);
902            }
903        }
904        else
905        {
906            /* Single complex argument, nothing returned */
907
908            WalkState->ArgCount = 1;
909        }
910        break;
911
912
913    case ARGP_DATAOBJ:
914    case ARGP_TERMARG:
915
916        /* Single complex argument, nothing returned */
917
918        WalkState->ArgCount = 1;
919        break;
920
921
922    case ARGP_DATAOBJLIST:
923    case ARGP_TERMLIST:
924    case ARGP_OBJLIST:
925
926        if (ParserState->Aml < ParserState->PkgEnd)
927        {
928            /* Non-empty list of variable arguments, nothing returned */
929
930            WalkState->ArgCount = ACPI_VAR_ARGS;
931        }
932        break;
933
934
935    default:
936
937        ACPI_ERROR ((AE_INFO, "Invalid ArgType: 0x%X", ArgType));
938        Status = AE_AML_OPERAND_TYPE;
939        break;
940    }
941
942    *ReturnArg = Arg;
943    return_ACPI_STATUS (Status);
944}
945