167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: psargs - Parse AML opcode arguments
467754Smsmith *
567754Smsmith *****************************************************************************/
667754Smsmith
7316303Sjkim/******************************************************************************
8316303Sjkim *
9316303Sjkim * 1. Copyright Notice
10316303Sjkim *
11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
1270243Smsmith * All rights reserved.
1367754Smsmith *
14316303Sjkim * 2. License
15316303Sjkim *
16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17316303Sjkim * rights. You may have additional license terms from the party that provided
18316303Sjkim * you this software, covering your right to use that party's intellectual
19316303Sjkim * property rights.
20316303Sjkim *
21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
26316303Sjkim * Code in any form, with the right to sublicense such rights; and
27316303Sjkim *
28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29316303Sjkim * license (with the right to sublicense), under only those claims of Intel
30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
33316303Sjkim * license, and in no event shall the patent license extend to any additions
34316303Sjkim * to or modifications of the Original Intel Code. No other license or right
35316303Sjkim * is granted directly or by implication, estoppel or otherwise;
36316303Sjkim *
37316303Sjkim * The above copyright and patent license is granted only if the following
38316303Sjkim * conditions are met:
39316303Sjkim *
40316303Sjkim * 3. Conditions
41316303Sjkim *
42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43316303Sjkim * Redistribution of source code of any substantial portion of the Covered
44316303Sjkim * Code or modification with rights to further distribute source must include
45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
49316303Sjkim * Code and the date of any change. Licensee must include in that file the
50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
51316303Sjkim * must include a prominent statement that the modification is derived,
52316303Sjkim * directly or indirectly, from Original Intel Code.
53316303Sjkim *
54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55316303Sjkim * Redistribution of source code of any substantial portion of the Covered
56316303Sjkim * Code or modification without rights to further distribute source must
57316303Sjkim * include the following Disclaimer and Export Compliance provision in the
58316303Sjkim * documentation and/or other materials provided with distribution. In
59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
61316303Sjkim * license from Licensee to its licensee is limited to the intellectual
62316303Sjkim * property embodied in the software Licensee provides to its licensee, and
63316303Sjkim * not to intellectual property embodied in modifications its licensee may
64316303Sjkim * make.
65316303Sjkim *
66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69316303Sjkim * provision in the documentation and/or other materials provided with the
70316303Sjkim * distribution.
71316303Sjkim *
72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73316303Sjkim * Intel Code.
74316303Sjkim *
75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77316303Sjkim * other dealings in products derived from or relating to the Covered Code
78316303Sjkim * without prior written authorization from Intel.
79316303Sjkim *
80316303Sjkim * 4. Disclaimer and Export Compliance
81316303Sjkim *
82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88316303Sjkim * PARTICULAR PURPOSE.
89316303Sjkim *
90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97316303Sjkim * LIMITED REMEDY.
98316303Sjkim *
99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100316303Sjkim * software or system incorporating such software without first obtaining any
101316303Sjkim * required license or other approval from the U. S. Department of Commerce or
102316303Sjkim * any other agency or department of the United States Government. In the
103316303Sjkim * event Licensee exports any such software from the United States or
104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
105316303Sjkim * ensure that the distribution and export/re-export of the software is in
106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109316303Sjkim * software, or service, directly or indirectly, to any country for which the
110316303Sjkim * United States government or any agency thereof requires an export license,
111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
112316303Sjkim * such license, approval or letter.
113316303Sjkim *
114316303Sjkim *****************************************************************************
115316303Sjkim *
116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
117316303Sjkim * following license:
118316303Sjkim *
119217365Sjkim * Redistribution and use in source and binary forms, with or without
120217365Sjkim * modification, are permitted provided that the following conditions
121217365Sjkim * are met:
122217365Sjkim * 1. Redistributions of source code must retain the above copyright
123217365Sjkim *    notice, this list of conditions, and the following disclaimer,
124217365Sjkim *    without modification.
125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
127217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
128217365Sjkim *    including a substantially similar Disclaimer requirement for further
129217365Sjkim *    binary redistribution.
130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
131217365Sjkim *    of any contributors may be used to endorse or promote products derived
132217365Sjkim *    from this software without specific prior written permission.
13367754Smsmith *
134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145316303Sjkim *
146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
148217365Sjkim * Software Foundation.
14967754Smsmith *
150316303Sjkim *****************************************************************************/
15167754Smsmith
152193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
153193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
154193341Sjkim#include <contrib/dev/acpica/include/acparser.h>
155193341Sjkim#include <contrib/dev/acpica/include/amlcode.h>
156193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
157193341Sjkim#include <contrib/dev/acpica/include/acdispat.h>
158316303Sjkim#include <contrib/dev/acpica/include/acconvert.h>
15967754Smsmith
16077424Smsmith#define _COMPONENT          ACPI_PARSER
16191116Smsmith        ACPI_MODULE_NAME    ("psargs")
16267754Smsmith
163151937Sjkim/* Local prototypes */
16467754Smsmith
165151937Sjkimstatic UINT32
166151937SjkimAcpiPsGetNextPackageLength (
167151937Sjkim    ACPI_PARSE_STATE        *ParserState);
168151937Sjkim
169151937Sjkimstatic ACPI_PARSE_OBJECT *
170151937SjkimAcpiPsGetNextField (
171151937Sjkim    ACPI_PARSE_STATE        *ParserState);
172151937Sjkim
173151937Sjkim
17467754Smsmith/*******************************************************************************
17567754Smsmith *
17667754Smsmith * FUNCTION:    AcpiPsGetNextPackageLength
17767754Smsmith *
17867754Smsmith * PARAMETERS:  ParserState         - Current parser state object
17967754Smsmith *
180167802Sjkim * RETURN:      Decoded package length. On completion, the AML pointer points
18167754Smsmith *              past the length byte or bytes.
18267754Smsmith *
183167802Sjkim * DESCRIPTION: Decode and return a package length field.
184167802Sjkim *              Note: Largest package length is 28 bits, from ACPI specification
18567754Smsmith *
18667754Smsmith ******************************************************************************/
18767754Smsmith
188151937Sjkimstatic UINT32
18967754SmsmithAcpiPsGetNextPackageLength (
19067754Smsmith    ACPI_PARSE_STATE        *ParserState)
19167754Smsmith{
192167802Sjkim    UINT8                   *Aml = ParserState->Aml;
193167802Sjkim    UINT32                  PackageLength = 0;
194193267Sjkim    UINT32                  ByteCount;
195167802Sjkim    UINT8                   ByteZeroMask = 0x3F; /* Default [0:5] */
19667754Smsmith
19767754Smsmith
198167802Sjkim    ACPI_FUNCTION_TRACE (PsGetNextPackageLength);
19967754Smsmith
20067754Smsmith
201167802Sjkim    /*
202167802Sjkim     * Byte 0 bits [6:7] contain the number of additional bytes
203167802Sjkim     * used to encode the package length, either 0,1,2, or 3
204167802Sjkim     */
205167802Sjkim    ByteCount = (Aml[0] >> 6);
206193267Sjkim    ParserState->Aml += ((ACPI_SIZE) ByteCount + 1);
20767754Smsmith
208167802Sjkim    /* Get bytes 3, 2, 1 as needed */
209167802Sjkim
210167802Sjkim    while (ByteCount)
21167754Smsmith    {
212167802Sjkim        /*
213167802Sjkim         * Final bit positions for the package length bytes:
214167802Sjkim         *      Byte3->[20:27]
215167802Sjkim         *      Byte2->[12:19]
216167802Sjkim         *      Byte1->[04:11]
217167802Sjkim         *      Byte0->[00:03]
218167802Sjkim         */
219167802Sjkim        PackageLength |= (Aml[ByteCount] << ((ByteCount << 3) - 4));
22067754Smsmith
221167802Sjkim        ByteZeroMask = 0x0F; /* Use bits [0:3] of byte 0 */
222167802Sjkim        ByteCount--;
223167802Sjkim    }
22467754Smsmith
225167802Sjkim    /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
22667754Smsmith
227167802Sjkim    PackageLength |= (Aml[0] & ByteZeroMask);
228246849Sjkim    return_UINT32 (PackageLength);
22967754Smsmith}
23067754Smsmith
23167754Smsmith
23267754Smsmith/*******************************************************************************
23367754Smsmith *
23467754Smsmith * FUNCTION:    AcpiPsGetNextPackageEnd
23567754Smsmith *
23667754Smsmith * PARAMETERS:  ParserState         - Current parser state object
23767754Smsmith *
23867754Smsmith * RETURN:      Pointer to end-of-package +1
23967754Smsmith *
24067754Smsmith * DESCRIPTION: Get next package length and return a pointer past the end of
241241973Sjkim *              the package. Consumes the package length field
24267754Smsmith *
24367754Smsmith ******************************************************************************/
24467754Smsmith
24567754SmsmithUINT8 *
24667754SmsmithAcpiPsGetNextPackageEnd (
24767754Smsmith    ACPI_PARSE_STATE        *ParserState)
24867754Smsmith{
24967754Smsmith    UINT8                   *Start = ParserState->Aml;
250167802Sjkim    UINT32                  PackageLength;
25167754Smsmith
25267754Smsmith
253167802Sjkim    ACPI_FUNCTION_TRACE (PsGetNextPackageEnd);
25467754Smsmith
25567754Smsmith
256167802Sjkim    /* Function below updates ParserState->Aml */
257107325Siwasaki
258167802Sjkim    PackageLength = AcpiPsGetNextPackageLength (ParserState);
25967754Smsmith
260167802Sjkim    return_PTR (Start + PackageLength); /* end of package */
26167754Smsmith}
26267754Smsmith
26367754Smsmith
26467754Smsmith/*******************************************************************************
26567754Smsmith *
26667754Smsmith * FUNCTION:    AcpiPsGetNextNamestring
26767754Smsmith *
26867754Smsmith * PARAMETERS:  ParserState         - Current parser state object
26967754Smsmith *
27067754Smsmith * RETURN:      Pointer to the start of the name string (pointer points into
27167754Smsmith *              the AML.
27267754Smsmith *
273241973Sjkim * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
274241973Sjkim *              prefix characters. Set parser state to point past the string.
27567754Smsmith *              (Name is consumed from the AML.)
27667754Smsmith *
27767754Smsmith ******************************************************************************/
27867754Smsmith
279114237Snjlchar *
28067754SmsmithAcpiPsGetNextNamestring (
28167754Smsmith    ACPI_PARSE_STATE        *ParserState)
28267754Smsmith{
28399679Siwasaki    UINT8                   *Start = ParserState->Aml;
28499679Siwasaki    UINT8                   *End = ParserState->Aml;
28567754Smsmith
28667754Smsmith
287167802Sjkim    ACPI_FUNCTION_TRACE (PsGetNextNamestring);
28867754Smsmith
28967754Smsmith
290167802Sjkim    /* Point past any namestring prefix characters (backslash or carat) */
29167754Smsmith
292245582Sjkim    while (ACPI_IS_ROOT_PREFIX (*End) ||
293245582Sjkim           ACPI_IS_PARENT_PREFIX (*End))
29467754Smsmith    {
29567754Smsmith        End++;
29667754Smsmith    }
29767754Smsmith
298167802Sjkim    /* Decode the path prefix character */
29967754Smsmith
300167802Sjkim    switch (*End)
30167754Smsmith    {
30267754Smsmith    case 0:
30367754Smsmith
30467754Smsmith        /* NullName */
30567754Smsmith
30667754Smsmith        if (End == Start)
30767754Smsmith        {
30867754Smsmith            Start = NULL;
30967754Smsmith        }
31067754Smsmith        End++;
31167754Smsmith        break;
31267754Smsmith
31367754Smsmith    case AML_DUAL_NAME_PREFIX:
31467754Smsmith
31599679Siwasaki        /* Two name segments */
31667754Smsmith
317107325Siwasaki        End += 1 + (2 * ACPI_NAME_SIZE);
31867754Smsmith        break;
31967754Smsmith
320316303Sjkim    case AML_MULTI_NAME_PREFIX:
32167754Smsmith
322167802Sjkim        /* Multiple name segments, 4 chars each, count in next byte */
32367754Smsmith
324167802Sjkim        End += 2 + (*(End + 1) * ACPI_NAME_SIZE);
32567754Smsmith        break;
32667754Smsmith
32767754Smsmith    default:
32867754Smsmith
32999679Siwasaki        /* Single name segment */
33067754Smsmith
331107325Siwasaki        End += ACPI_NAME_SIZE;
33267754Smsmith        break;
33367754Smsmith    }
33467754Smsmith
335167802Sjkim    ParserState->Aml = End;
336114237Snjl    return_PTR ((char *) Start);
33767754Smsmith}
33867754Smsmith
33967754Smsmith
34067754Smsmith/*******************************************************************************
34167754Smsmith *
34267754Smsmith * FUNCTION:    AcpiPsGetNextNamepath
34367754Smsmith *
34467754Smsmith * PARAMETERS:  ParserState         - Current parser state object
34567754Smsmith *              Arg                 - Where the namepath will be stored
34667754Smsmith *              ArgCount            - If the namepath points to a control method
34767754Smsmith *                                    the method's argument is returned here.
348167802Sjkim *              PossibleMethodCall  - Whether the namepath can possibly be the
349107325Siwasaki *                                    start of a method call
35067754Smsmith *
351102550Siwasaki * RETURN:      Status
35267754Smsmith *
353102550Siwasaki * DESCRIPTION: Get next name (if method call, return # of required args).
354102550Siwasaki *              Names are looked up in the internal namespace to determine
355241973Sjkim *              if the name represents a control method. If a method
35667754Smsmith *              is found, the number of arguments to the method is returned.
35767754Smsmith *              This information is critical for parsing to continue correctly.
35867754Smsmith *
35967754Smsmith ******************************************************************************/
36067754Smsmith
361102550SiwasakiACPI_STATUS
36267754SmsmithAcpiPsGetNextNamepath (
363107325Siwasaki    ACPI_WALK_STATE         *WalkState,
36467754Smsmith    ACPI_PARSE_STATE        *ParserState,
36567754Smsmith    ACPI_PARSE_OBJECT       *Arg,
366167802Sjkim    BOOLEAN                 PossibleMethodCall)
36767754Smsmith{
368193267Sjkim    ACPI_STATUS             Status;
369114237Snjl    char                    *Path;
37067754Smsmith    ACPI_PARSE_OBJECT       *NameOp;
371102550Siwasaki    ACPI_OPERAND_OBJECT     *MethodDesc;
372102550Siwasaki    ACPI_NAMESPACE_NODE     *Node;
373193267Sjkim    UINT8                   *Start = ParserState->Aml;
37467754Smsmith
37567754Smsmith
376167802Sjkim    ACPI_FUNCTION_TRACE (PsGetNextNamepath);
37767754Smsmith
37867754Smsmith
37967754Smsmith    Path = AcpiPsGetNextNamestring (ParserState);
380167802Sjkim    AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
38167754Smsmith
382167802Sjkim    /* Null path case is allowed, just exit */
38367754Smsmith
384167802Sjkim    if (!Path)
38567754Smsmith    {
386167802Sjkim        Arg->Common.Value.Name = Path;
387167802Sjkim        return_ACPI_STATUS (AE_OK);
388167802Sjkim    }
389167802Sjkim
390167802Sjkim    /*
391193267Sjkim     * Lookup the name in the internal namespace, starting with the current
392193267Sjkim     * scope. We don't want to add anything new to the namespace here,
393193267Sjkim     * however, so we use MODE_EXECUTE.
394167802Sjkim     * Allow searching of the parent tree, but don't open a new scope -
395167802Sjkim     * we just want to lookup the object (must be mode EXECUTE to perform
396167802Sjkim     * the upsearch)
397167802Sjkim     */
398193267Sjkim    Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
399298714Sjkim        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
400298714Sjkim        ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
401167802Sjkim
402167802Sjkim    /*
403167802Sjkim     * If this name is a control method invocation, we must
404167802Sjkim     * setup the method call
405167802Sjkim     */
406167802Sjkim    if (ACPI_SUCCESS (Status) &&
407167802Sjkim        PossibleMethodCall &&
408167802Sjkim        (Node->Type == ACPI_TYPE_METHOD))
409167802Sjkim    {
410316303Sjkim        if ((GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) == ARGP_SUPERNAME) ||
411316303Sjkim            (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) == ARGP_TARGET))
412193267Sjkim        {
413193267Sjkim            /*
414316303Sjkim             * AcpiPsGetNextNamestring has increased the AML pointer past
415316303Sjkim             * the method invocation namestring, so we need to restore the
416316303Sjkim             * saved AML pointer back to the original method invocation
417316303Sjkim             * namestring.
418193267Sjkim             */
419193267Sjkim            WalkState->ParserState.Aml = Start;
420193267Sjkim            WalkState->ArgCount = 1;
421193267Sjkim            AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
422193267Sjkim        }
423193267Sjkim
424167802Sjkim        /* This name is actually a control method invocation */
425167802Sjkim
426167802Sjkim        MethodDesc = AcpiNsGetAttachedObject (Node);
427167802Sjkim        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
428316303Sjkim            "Control Method invocation %4.4s - %p Desc %p Path=%p\n",
429316303Sjkim            Node->Name.Ascii, Node, MethodDesc, Path));
430167802Sjkim
431285797Sjkim        NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Start);
432167802Sjkim        if (!NameOp)
43367754Smsmith        {
434167802Sjkim            return_ACPI_STATUS (AE_NO_MEMORY);
43567754Smsmith        }
43667754Smsmith
437167802Sjkim        /* Change Arg into a METHOD CALL and attach name to it */
438151937Sjkim
439167802Sjkim        AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
440167802Sjkim        NameOp->Common.Value.Name = Path;
441102550Siwasaki
442167802Sjkim        /* Point METHODCALL/NAME to the METHOD Node */
44367754Smsmith
444167802Sjkim        NameOp->Common.Node = Node;
445167802Sjkim        AcpiPsAppendArg (Arg, NameOp);
44667754Smsmith
447167802Sjkim        if (!MethodDesc)
448167802Sjkim        {
449167802Sjkim            ACPI_ERROR ((AE_INFO,
450167802Sjkim                "Control Method %p has no attached object",
451167802Sjkim                Node));
452167802Sjkim            return_ACPI_STATUS (AE_AML_INTERNAL);
453167802Sjkim        }
45467754Smsmith
455167802Sjkim        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
456167802Sjkim            "Control Method - %p Args %X\n",
457167802Sjkim            Node, MethodDesc->Method.ParamCount));
45867754Smsmith
459167802Sjkim        /* Get the number of arguments to expect */
460102550Siwasaki
461167802Sjkim        WalkState->ArgCount = MethodDesc->Method.ParamCount;
462167802Sjkim        return_ACPI_STATUS (AE_OK);
463167802Sjkim    }
46467754Smsmith
465167802Sjkim    /*
466167802Sjkim     * Special handling if the name was not found during the lookup -
467167802Sjkim     * some NotFound cases are allowed
468167802Sjkim     */
469167802Sjkim    if (Status == AE_NOT_FOUND)
470167802Sjkim    {
471167802Sjkim        /* 1) NotFound is ok during load pass 1/2 (allow forward references) */
472102550Siwasaki
473167802Sjkim        if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) !=
474298714Sjkim            ACPI_PARSE_EXECUTE)
475167802Sjkim        {
476167802Sjkim            Status = AE_OK;
477167802Sjkim        }
478107325Siwasaki
479167802Sjkim        /* 2) NotFound during a CondRefOf(x) is ok by definition */
48067754Smsmith
481316303Sjkim        else if (WalkState->Op->Common.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)
482167802Sjkim        {
483167802Sjkim            Status = AE_OK;
48467754Smsmith        }
485107325Siwasaki
486167802Sjkim        /*
487167802Sjkim         * 3) NotFound while building a Package is ok at this point, we
488167802Sjkim         * may flag as an error later if slack mode is not enabled.
489167802Sjkim         * (Some ASL code depends on allowing this behavior)
490167802Sjkim         */
491167802Sjkim        else if ((Arg->Common.Parent) &&
492167802Sjkim            ((Arg->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
493316303Sjkim             (Arg->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP)))
494107325Siwasaki        {
495167802Sjkim            Status = AE_OK;
496167802Sjkim        }
497167802Sjkim    }
498107325Siwasaki
499167802Sjkim    /* Final exception check (may have been changed from code above) */
500117521Snjl
501167802Sjkim    if (ACPI_FAILURE (Status))
502167802Sjkim    {
503327557Sjkim        ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo, Path, Status);
504117521Snjl
505167802Sjkim        if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==
506298714Sjkim            ACPI_PARSE_EXECUTE)
507167802Sjkim        {
508167802Sjkim            /* Report a control method execution error */
509117521Snjl
510167802Sjkim            Status = AcpiDsMethodError (Status, WalkState);
511107325Siwasaki        }
51267754Smsmith    }
51367754Smsmith
514167802Sjkim    /* Save the namepath */
515167802Sjkim
51699679Siwasaki    Arg->Common.Value.Name = Path;
517102550Siwasaki    return_ACPI_STATUS (Status);
51867754Smsmith}
51967754Smsmith
52067754Smsmith
52167754Smsmith/*******************************************************************************
52267754Smsmith *
52367754Smsmith * FUNCTION:    AcpiPsGetNextSimpleArg
52467754Smsmith *
52567754Smsmith * PARAMETERS:  ParserState         - Current parser state object
52667754Smsmith *              ArgType             - The argument type (AML_*_ARG)
52767754Smsmith *              Arg                 - Where the argument is returned
52867754Smsmith *
52967754Smsmith * RETURN:      None
53067754Smsmith *
53167754Smsmith * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
53267754Smsmith *
53367754Smsmith ******************************************************************************/
53467754Smsmith
53567754Smsmithvoid
53667754SmsmithAcpiPsGetNextSimpleArg (
53767754Smsmith    ACPI_PARSE_STATE        *ParserState,
53867754Smsmith    UINT32                  ArgType,
53967754Smsmith    ACPI_PARSE_OBJECT       *Arg)
54067754Smsmith{
541167802Sjkim    UINT32                  Length;
542167802Sjkim    UINT16                  Opcode;
543167802Sjkim    UINT8                   *Aml = ParserState->Aml;
54467754Smsmith
54567754Smsmith
546167802Sjkim    ACPI_FUNCTION_TRACE_U32 (PsGetNextSimpleArg, ArgType);
54767754Smsmith
548167802Sjkim
54967754Smsmith    switch (ArgType)
55067754Smsmith    {
55167754Smsmith    case ARGP_BYTEDATA:
55267754Smsmith
553167802Sjkim        /* Get 1 byte from the AML stream */
554167802Sjkim
555167802Sjkim        Opcode = AML_BYTE_OP;
556202771Sjkim        Arg->Common.Value.Integer = (UINT64) *Aml;
557167802Sjkim        Length = 1;
55867754Smsmith        break;
55967754Smsmith
56067754Smsmith    case ARGP_WORDDATA:
56167754Smsmith
56267754Smsmith        /* Get 2 bytes from the AML stream */
56367754Smsmith
564167802Sjkim        Opcode = AML_WORD_OP;
565167802Sjkim        ACPI_MOVE_16_TO_64 (&Arg->Common.Value.Integer, Aml);
566167802Sjkim        Length = 2;
56767754Smsmith        break;
56867754Smsmith
56967754Smsmith    case ARGP_DWORDDATA:
57067754Smsmith
57167754Smsmith        /* Get 4 bytes from the AML stream */
57267754Smsmith
573167802Sjkim        Opcode = AML_DWORD_OP;
574167802Sjkim        ACPI_MOVE_32_TO_64 (&Arg->Common.Value.Integer, Aml);
575167802Sjkim        Length = 4;
57667754Smsmith        break;
57767754Smsmith
57882367Smsmith    case ARGP_QWORDDATA:
57982367Smsmith
58082367Smsmith        /* Get 8 bytes from the AML stream */
58182367Smsmith
582167802Sjkim        Opcode = AML_QWORD_OP;
583167802Sjkim        ACPI_MOVE_64_TO_64 (&Arg->Common.Value.Integer, Aml);
584167802Sjkim        Length = 8;
58582367Smsmith        break;
58682367Smsmith
58767754Smsmith    case ARGP_CHARLIST:
58867754Smsmith
589167802Sjkim        /* Get a pointer to the string, point past the string */
59067754Smsmith
591167802Sjkim        Opcode = AML_STRING_OP;
592167802Sjkim        Arg->Common.Value.String = ACPI_CAST_PTR (char, Aml);
593167802Sjkim
594167802Sjkim        /* Find the null terminator */
595167802Sjkim
596167802Sjkim        Length = 0;
597167802Sjkim        while (Aml[Length])
59867754Smsmith        {
599167802Sjkim            Length++;
60067754Smsmith        }
601167802Sjkim        Length++;
60267754Smsmith        break;
60367754Smsmith
60467754Smsmith    case ARGP_NAME:
60567754Smsmith    case ARGP_NAMESTRING:
60667754Smsmith
60777424Smsmith        AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
60899679Siwasaki        Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
609167802Sjkim        return_VOID;
61099679Siwasaki
61199679Siwasaki    default:
612107325Siwasaki
613204773Sjkim        ACPI_ERROR ((AE_INFO, "Invalid ArgType 0x%X", ArgType));
614167802Sjkim        return_VOID;
61567754Smsmith    }
61667754Smsmith
617167802Sjkim    AcpiPsInitOp (Arg, Opcode);
618167802Sjkim    ParserState->Aml += Length;
61967754Smsmith    return_VOID;
62067754Smsmith}
62167754Smsmith
62267754Smsmith
62367754Smsmith/*******************************************************************************
62467754Smsmith *
62567754Smsmith * FUNCTION:    AcpiPsGetNextField
62667754Smsmith *
62767754Smsmith * PARAMETERS:  ParserState         - Current parser state object
62867754Smsmith *
62967754Smsmith * RETURN:      A newly allocated FIELD op
63067754Smsmith *
63167754Smsmith * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
63267754Smsmith *
63367754Smsmith ******************************************************************************/
63467754Smsmith
635151937Sjkimstatic ACPI_PARSE_OBJECT *
63667754SmsmithAcpiPsGetNextField (
63767754Smsmith    ACPI_PARSE_STATE        *ParserState)
63867754Smsmith{
639285797Sjkim    UINT8                   *Aml;
64067754Smsmith    ACPI_PARSE_OBJECT       *Field;
641228110Sjkim    ACPI_PARSE_OBJECT       *Arg = NULL;
64267754Smsmith    UINT16                  Opcode;
64367754Smsmith    UINT32                  Name;
644228110Sjkim    UINT8                   AccessType;
645228110Sjkim    UINT8                   AccessAttribute;
646228110Sjkim    UINT8                   AccessLength;
647228110Sjkim    UINT32                  PkgLength;
648228110Sjkim    UINT8                   *PkgEnd;
649228110Sjkim    UINT32                  BufferLength;
65067754Smsmith
65167754Smsmith
652167802Sjkim    ACPI_FUNCTION_TRACE (PsGetNextField);
65367754Smsmith
65467754Smsmith
655316303Sjkim    ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
656285797Sjkim    Aml = ParserState->Aml;
657228110Sjkim
658151937Sjkim    /* Determine field type */
65967754Smsmith
66091116Smsmith    switch (ACPI_GET8 (ParserState->Aml))
66167754Smsmith    {
662228110Sjkim    case AML_FIELD_OFFSET_OP:
66367754Smsmith
664228110Sjkim        Opcode = AML_INT_RESERVEDFIELD_OP;
665228110Sjkim        ParserState->Aml++;
66667754Smsmith        break;
66767754Smsmith
668228110Sjkim    case AML_FIELD_ACCESS_OP:
66967754Smsmith
670228110Sjkim        Opcode = AML_INT_ACCESSFIELD_OP;
67167754Smsmith        ParserState->Aml++;
67267754Smsmith        break;
67367754Smsmith
674228110Sjkim    case AML_FIELD_CONNECTION_OP:
67567754Smsmith
676228110Sjkim        Opcode = AML_INT_CONNECTION_OP;
67767754Smsmith        ParserState->Aml++;
67867754Smsmith        break;
679228110Sjkim
680228110Sjkim    case AML_FIELD_EXT_ACCESS_OP:
681228110Sjkim
682228110Sjkim        Opcode = AML_INT_EXTACCESSFIELD_OP;
683228110Sjkim        ParserState->Aml++;
684228110Sjkim        break;
685228110Sjkim
686228110Sjkim    default:
687228110Sjkim
688228110Sjkim        Opcode = AML_INT_NAMEDFIELD_OP;
689228110Sjkim        break;
69067754Smsmith    }
69167754Smsmith
69267754Smsmith    /* Allocate a new field op */
69367754Smsmith
694285797Sjkim    Field = AcpiPsAllocOp (Opcode, Aml);
69599679Siwasaki    if (!Field)
69667754Smsmith    {
69799679Siwasaki        return_PTR (NULL);
69899679Siwasaki    }
69967754Smsmith
70099679Siwasaki    /* Decode the field type */
70167754Smsmith
702316303Sjkim    ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
70399679Siwasaki    switch (Opcode)
70499679Siwasaki    {
70599679Siwasaki    case AML_INT_NAMEDFIELD_OP:
70667754Smsmith
70799679Siwasaki        /* Get the 4-character name */
70867754Smsmith
709117521Snjl        ACPI_MOVE_32_TO_32 (&Name, ParserState->Aml);
71099679Siwasaki        AcpiPsSetName (Field, Name);
711107325Siwasaki        ParserState->Aml += ACPI_NAME_SIZE;
71267754Smsmith
713316303Sjkim
714316303Sjkim        ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
715316303Sjkim
716316303Sjkim#ifdef ACPI_ASL_COMPILER
717316303Sjkim        /*
718316303Sjkim         * Because the package length isn't represented as a parse tree object,
719316303Sjkim         * take comments surrounding this and add to the previously created
720316303Sjkim         * parse node.
721316303Sjkim         */
722316303Sjkim        if (Field->Common.InlineComment)
723316303Sjkim        {
724316303Sjkim            Field->Common.NameComment = Field->Common.InlineComment;
725316303Sjkim        }
726316303Sjkim        Field->Common.InlineComment  = AcpiGbl_CurrentInlineComment;
727316303Sjkim        AcpiGbl_CurrentInlineComment = NULL;
728316303Sjkim#endif
729316303Sjkim
73099679Siwasaki        /* Get the length which is encoded as a package length */
73167754Smsmith
73299679Siwasaki        Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
73399679Siwasaki        break;
73467754Smsmith
73567754Smsmith
73699679Siwasaki    case AML_INT_RESERVEDFIELD_OP:
73767754Smsmith
73899679Siwasaki        /* Get the length which is encoded as a package length */
73967754Smsmith
74099679Siwasaki        Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
74199679Siwasaki        break;
74267754Smsmith
74367754Smsmith
74499679Siwasaki    case AML_INT_ACCESSFIELD_OP:
745228110Sjkim    case AML_INT_EXTACCESSFIELD_OP:
74699679Siwasaki
74799679Siwasaki        /*
74899679Siwasaki         * Get AccessType and AccessAttrib and merge into the field Op
749228110Sjkim         * AccessType is first operand, AccessAttribute is second. stuff
750228110Sjkim         * these bytes into the node integer value for convenience.
75199679Siwasaki         */
752228110Sjkim
753228110Sjkim        /* Get the two bytes (Type/Attribute) */
754228110Sjkim
755228110Sjkim        AccessType = ACPI_GET8 (ParserState->Aml);
75699679Siwasaki        ParserState->Aml++;
757228110Sjkim        AccessAttribute = ACPI_GET8 (ParserState->Aml);
75899679Siwasaki        ParserState->Aml++;
759228110Sjkim
760228110Sjkim        Field->Common.Value.Integer = (UINT8) AccessType;
761228110Sjkim        Field->Common.Value.Integer |= (UINT16) (AccessAttribute << 8);
762228110Sjkim
763228110Sjkim        /* This opcode has a third byte, AccessLength */
764228110Sjkim
765228110Sjkim        if (Opcode == AML_INT_EXTACCESSFIELD_OP)
766228110Sjkim        {
767228110Sjkim            AccessLength = ACPI_GET8 (ParserState->Aml);
768228110Sjkim            ParserState->Aml++;
769228110Sjkim
770228110Sjkim            Field->Common.Value.Integer |= (UINT32) (AccessLength << 16);
771228110Sjkim        }
77299679Siwasaki        break;
77399679Siwasaki
774228110Sjkim
775228110Sjkim    case AML_INT_CONNECTION_OP:
776228110Sjkim
777228110Sjkim        /*
778228110Sjkim         * Argument for Connection operator can be either a Buffer
779228110Sjkim         * (resource descriptor), or a NameString.
780228110Sjkim         */
781285797Sjkim        Aml = ParserState->Aml;
782228110Sjkim        if (ACPI_GET8 (ParserState->Aml) == AML_BUFFER_OP)
783228110Sjkim        {
784228110Sjkim            ParserState->Aml++;
785228110Sjkim
786316303Sjkim            ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
787228110Sjkim            PkgEnd = ParserState->Aml;
788228110Sjkim            PkgLength = AcpiPsGetNextPackageLength (ParserState);
789228110Sjkim            PkgEnd += PkgLength;
790228110Sjkim
791316303Sjkim            ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
792228110Sjkim            if (ParserState->Aml < PkgEnd)
793228110Sjkim            {
794228110Sjkim                /* Non-empty list */
795228110Sjkim
796285797Sjkim                Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP, Aml);
797228110Sjkim                if (!Arg)
798228110Sjkim                {
799233558Sjkim                    AcpiPsFreeOp (Field);
800228110Sjkim                    return_PTR (NULL);
801228110Sjkim                }
802228110Sjkim
803228110Sjkim                /* Get the actual buffer length argument */
804228110Sjkim
805228110Sjkim                Opcode = ACPI_GET8 (ParserState->Aml);
806228110Sjkim                ParserState->Aml++;
807228110Sjkim
808316303Sjkim                ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
809228110Sjkim                switch (Opcode)
810228110Sjkim                {
811228110Sjkim                case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
812250838Sjkim
813228110Sjkim                    BufferLength = ACPI_GET8 (ParserState->Aml);
814228110Sjkim                    ParserState->Aml += 1;
815228110Sjkim                    break;
816228110Sjkim
817228110Sjkim                case AML_WORD_OP:       /* AML_WORDDATA_ARG */
818250838Sjkim
819228110Sjkim                    BufferLength = ACPI_GET16 (ParserState->Aml);
820228110Sjkim                    ParserState->Aml += 2;
821228110Sjkim                    break;
822228110Sjkim
823228110Sjkim                case AML_DWORD_OP:      /* AML_DWORDATA_ARG */
824250838Sjkim
825228110Sjkim                    BufferLength = ACPI_GET32 (ParserState->Aml);
826228110Sjkim                    ParserState->Aml += 4;
827228110Sjkim                    break;
828228110Sjkim
829228110Sjkim                default:
830250838Sjkim
831228110Sjkim                    BufferLength = 0;
832228110Sjkim                    break;
833228110Sjkim                }
834228110Sjkim
835228110Sjkim                /* Fill in bytelist data */
836228110Sjkim
837316303Sjkim                ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);
838228110Sjkim                Arg->Named.Value.Size = BufferLength;
839228110Sjkim                Arg->Named.Data = ParserState->Aml;
840228110Sjkim            }
841228110Sjkim
842228110Sjkim            /* Skip to End of byte data */
843228110Sjkim
844228110Sjkim            ParserState->Aml = PkgEnd;
845228110Sjkim        }
846228110Sjkim        else
847228110Sjkim        {
848285797Sjkim            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Aml);
849228110Sjkim            if (!Arg)
850228110Sjkim            {
851233558Sjkim                AcpiPsFreeOp (Field);
852228110Sjkim                return_PTR (NULL);
853228110Sjkim            }
854228110Sjkim
855228110Sjkim            /* Get the Namestring argument */
856228110Sjkim
857228110Sjkim            Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
858228110Sjkim        }
859228110Sjkim
860228110Sjkim        /* Link the buffer/namestring to parent (CONNECTION_OP) */
861228110Sjkim
862228110Sjkim        AcpiPsAppendArg (Field, Arg);
863228110Sjkim        break;
864228110Sjkim
865228110Sjkim
86699679Siwasaki    default:
867107325Siwasaki
86899679Siwasaki        /* Opcode was set in previous switch */
86999679Siwasaki        break;
87067754Smsmith    }
87167754Smsmith
87267754Smsmith    return_PTR (Field);
87367754Smsmith}
87467754Smsmith
87567754Smsmith
87667754Smsmith/*******************************************************************************
87767754Smsmith *
87867754Smsmith * FUNCTION:    AcpiPsGetNextArg
87967754Smsmith *
880151937Sjkim * PARAMETERS:  WalkState           - Current state
881151937Sjkim *              ParserState         - Current parser state object
88267754Smsmith *              ArgType             - The argument type (AML_*_ARG)
883151937Sjkim *              ReturnArg           - Where the next arg is returned
88467754Smsmith *
885102550Siwasaki * RETURN:      Status, and an op object containing the next argument.
88667754Smsmith *
88767754Smsmith * DESCRIPTION: Get next argument (including complex list arguments that require
88867754Smsmith *              pushing the parser stack)
88967754Smsmith *
89067754Smsmith ******************************************************************************/
89167754Smsmith
892102550SiwasakiACPI_STATUS
89367754SmsmithAcpiPsGetNextArg (
894107325Siwasaki    ACPI_WALK_STATE         *WalkState,
89567754Smsmith    ACPI_PARSE_STATE        *ParserState,
89667754Smsmith    UINT32                  ArgType,
897102550Siwasaki    ACPI_PARSE_OBJECT       **ReturnArg)
89867754Smsmith{
89967754Smsmith    ACPI_PARSE_OBJECT       *Arg = NULL;
90067754Smsmith    ACPI_PARSE_OBJECT       *Prev = NULL;
90167754Smsmith    ACPI_PARSE_OBJECT       *Field;
90267754Smsmith    UINT32                  Subop;
903102550Siwasaki    ACPI_STATUS             Status = AE_OK;
90467754Smsmith
90567754Smsmith
906167802Sjkim    ACPI_FUNCTION_TRACE_PTR (PsGetNextArg, ParserState);
90767754Smsmith
90867754Smsmith
909316303Sjkim    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
910316303Sjkim        "Expected argument type ARGP: %s (%2.2X)\n",
911316303Sjkim        AcpiUtGetArgumentTypeName (ArgType), ArgType));
912316303Sjkim
91367754Smsmith    switch (ArgType)
91467754Smsmith    {
91567754Smsmith    case ARGP_BYTEDATA:
91667754Smsmith    case ARGP_WORDDATA:
91767754Smsmith    case ARGP_DWORDDATA:
91867754Smsmith    case ARGP_CHARLIST:
91967754Smsmith    case ARGP_NAME:
92067754Smsmith    case ARGP_NAMESTRING:
92167754Smsmith
922151937Sjkim        /* Constants, strings, and namestrings are all the same size */
92367754Smsmith
924285797Sjkim        Arg = AcpiPsAllocOp (AML_BYTE_OP, ParserState->Aml);
925102550Siwasaki        if (!Arg)
92667754Smsmith        {
927102550Siwasaki            return_ACPI_STATUS (AE_NO_MEMORY);
92867754Smsmith        }
929298714Sjkim
930102550Siwasaki        AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
93167754Smsmith        break;
93267754Smsmith
93367754Smsmith    case ARGP_PKGLENGTH:
93467754Smsmith
935102550Siwasaki        /* Package length, nothing returned */
93667754Smsmith
93767754Smsmith        ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
93867754Smsmith        break;
93967754Smsmith
94067754Smsmith    case ARGP_FIELDLIST:
94167754Smsmith
94267754Smsmith        if (ParserState->Aml < ParserState->PkgEnd)
94367754Smsmith        {
944102550Siwasaki            /* Non-empty list */
94567754Smsmith
94667754Smsmith            while (ParserState->Aml < ParserState->PkgEnd)
94767754Smsmith            {
94867754Smsmith                Field = AcpiPsGetNextField (ParserState);
94967754Smsmith                if (!Field)
95067754Smsmith                {
951102550Siwasaki                    return_ACPI_STATUS (AE_NO_MEMORY);
95267754Smsmith                }
95367754Smsmith
95467754Smsmith                if (Prev)
95567754Smsmith                {
95699679Siwasaki                    Prev->Common.Next = Field;
95767754Smsmith                }
95867754Smsmith                else
95967754Smsmith                {
96067754Smsmith                    Arg = Field;
96167754Smsmith                }
96267754Smsmith                Prev = Field;
96367754Smsmith            }
96467754Smsmith
965102550Siwasaki            /* Skip to End of byte data */
96667754Smsmith
96767754Smsmith            ParserState->Aml = ParserState->PkgEnd;
96867754Smsmith        }
96967754Smsmith        break;
97067754Smsmith
97167754Smsmith    case ARGP_BYTELIST:
97267754Smsmith
97367754Smsmith        if (ParserState->Aml < ParserState->PkgEnd)
97467754Smsmith        {
975102550Siwasaki            /* Non-empty list */
97667754Smsmith
977285797Sjkim            Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP,
978298714Sjkim                ParserState->Aml);
979102550Siwasaki            if (!Arg)
98067754Smsmith            {
981102550Siwasaki                return_ACPI_STATUS (AE_NO_MEMORY);
98267754Smsmith            }
98367754Smsmith
984102550Siwasaki            /* Fill in bytelist data */
98567754Smsmith
986151937Sjkim            Arg->Common.Value.Size = (UINT32)
987151937Sjkim                ACPI_PTR_DIFF (ParserState->PkgEnd, ParserState->Aml);
988102550Siwasaki            Arg->Named.Data = ParserState->Aml;
989102550Siwasaki
990102550Siwasaki            /* Skip to End of byte data */
991102550Siwasaki
99267754Smsmith            ParserState->Aml = ParserState->PkgEnd;
99367754Smsmith        }
99467754Smsmith        break;
99567754Smsmith
99691116Smsmith    case ARGP_SIMPLENAME:
997298714Sjkim    case ARGP_NAME_OR_REF:
998102550Siwasaki
999316303Sjkim        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
1000316303Sjkim            "**** SimpleName/NameOrRef: %s (%2.2X)\n",
1001316303Sjkim            AcpiUtGetArgumentTypeName (ArgType), ArgType));
1002316303Sjkim
1003102550Siwasaki        Subop = AcpiPsPeekOpcode (ParserState);
1004102550Siwasaki        if (Subop == 0                  ||
1005102550Siwasaki            AcpiPsIsLeadingChar (Subop) ||
1006245582Sjkim            ACPI_IS_ROOT_PREFIX (Subop) ||
1007245582Sjkim            ACPI_IS_PARENT_PREFIX (Subop))
100867754Smsmith        {
1009102550Siwasaki            /* NullName or NameString */
1010102550Siwasaki
1011285797Sjkim            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, ParserState->Aml);
1012102550Siwasaki            if (!Arg)
101367754Smsmith            {
1014102550Siwasaki                return_ACPI_STATUS (AE_NO_MEMORY);
101567754Smsmith            }
101667754Smsmith
1017316303Sjkim            Status = AcpiPsGetNextNamepath (WalkState, ParserState,
1018316303Sjkim                Arg, ACPI_NOT_METHOD_CALL);
1019316303Sjkim        }
1020316303Sjkim        else
1021316303Sjkim        {
1022316303Sjkim            /* Single complex argument, nothing returned */
1023193267Sjkim
1024316303Sjkim            WalkState->ArgCount = 1;
1025316303Sjkim        }
1026316303Sjkim        break;
1027316303Sjkim
1028316303Sjkim    case ARGP_TARGET:
1029316303Sjkim    case ARGP_SUPERNAME:
1030316303Sjkim
1031316303Sjkim        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
1032316303Sjkim            "**** Target/Supername: %s (%2.2X)\n",
1033316303Sjkim            AcpiUtGetArgumentTypeName (ArgType), ArgType));
1034316303Sjkim
1035316303Sjkim        Subop = AcpiPsPeekOpcode (ParserState);
1036316303Sjkim        if (Subop == 0                  ||
1037316303Sjkim            AcpiPsIsLeadingChar (Subop) ||
1038316303Sjkim            ACPI_IS_ROOT_PREFIX (Subop) ||
1039316303Sjkim            ACPI_IS_PARENT_PREFIX (Subop))
1040316303Sjkim        {
1041316303Sjkim            /* NULL target (zero). Convert to a NULL namepath */
1042316303Sjkim
1043316303Sjkim            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, ParserState->Aml);
1044316303Sjkim            if (!Arg)
1045193267Sjkim            {
1046316303Sjkim                return_ACPI_STATUS (AE_NO_MEMORY);
1047316303Sjkim            }
1048193267Sjkim
1049316303Sjkim            Status = AcpiPsGetNextNamepath (WalkState, ParserState,
1050316303Sjkim                Arg, ACPI_POSSIBLE_METHOD_CALL);
1051316303Sjkim
1052316303Sjkim            if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)
1053193267Sjkim            {
1054316303Sjkim                AcpiPsFreeOp (Arg);
1055316303Sjkim                Arg = NULL;
1056316303Sjkim                WalkState->ArgCount = 1;
1057193267Sjkim            }
1058102550Siwasaki        }
1059102550Siwasaki        else
1060102550Siwasaki        {
1061151937Sjkim            /* Single complex argument, nothing returned */
106267754Smsmith
1063107325Siwasaki            WalkState->ArgCount = 1;
106467754Smsmith        }
106567754Smsmith        break;
106667754Smsmith
106767754Smsmith    case ARGP_DATAOBJ:
106867754Smsmith    case ARGP_TERMARG:
106967754Smsmith
1070316303Sjkim
1071316303Sjkim    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
1072316303Sjkim        "**** TermArg/DataObj: %s (%2.2X)\n",
1073316303Sjkim        AcpiUtGetArgumentTypeName (ArgType), ArgType));
1074316303Sjkim
1075151937Sjkim        /* Single complex argument, nothing returned */
107667754Smsmith
1077107325Siwasaki        WalkState->ArgCount = 1;
107867754Smsmith        break;
107967754Smsmith
108067754Smsmith    case ARGP_DATAOBJLIST:
108167754Smsmith    case ARGP_TERMLIST:
108267754Smsmith    case ARGP_OBJLIST:
108367754Smsmith
108467754Smsmith        if (ParserState->Aml < ParserState->PkgEnd)
108567754Smsmith        {
1086151937Sjkim            /* Non-empty list of variable arguments, nothing returned */
108767754Smsmith
1088107325Siwasaki            WalkState->ArgCount = ACPI_VAR_ARGS;
108967754Smsmith        }
109067754Smsmith        break;
109199679Siwasaki
109299679Siwasaki    default:
1093102550Siwasaki
1094204773Sjkim        ACPI_ERROR ((AE_INFO, "Invalid ArgType: 0x%X", ArgType));
1095102550Siwasaki        Status = AE_AML_OPERAND_TYPE;
109699679Siwasaki        break;
109767754Smsmith    }
109867754Smsmith
1099102550Siwasaki    *ReturnArg = Arg;
1100102550Siwasaki    return_ACPI_STATUS (Status);
110167754Smsmith}
1102