167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dsfield - Dispatcher field routines
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/amlcode.h>
155193341Sjkim#include <contrib/dev/acpica/include/acdispat.h>
156193341Sjkim#include <contrib/dev/acpica/include/acinterp.h>
157193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
158193341Sjkim#include <contrib/dev/acpica/include/acparser.h>
15967754Smsmith
16067754Smsmith
16177424Smsmith#define _COMPONENT          ACPI_DISPATCHER
16291116Smsmith        ACPI_MODULE_NAME    ("dsfield")
16367754Smsmith
164151937Sjkim/* Local prototypes */
16567754Smsmith
166235945Sjkim#ifdef ACPI_ASL_COMPILER
167235945Sjkim#include <contrib/dev/acpica/include/acdisasm.h>
168235945Sjkim
169151937Sjkimstatic ACPI_STATUS
170235945SjkimAcpiDsCreateExternalRegion (
171235945Sjkim    ACPI_STATUS             LookupStatus,
172235945Sjkim    ACPI_PARSE_OBJECT       *Op,
173235945Sjkim    char                    *Path,
174235945Sjkim    ACPI_WALK_STATE         *WalkState,
175235945Sjkim    ACPI_NAMESPACE_NODE     **Node);
176235945Sjkim#endif
177235945Sjkim
178235945Sjkimstatic ACPI_STATUS
179151937SjkimAcpiDsGetFieldNames (
180151937Sjkim    ACPI_CREATE_FIELD_INFO  *Info,
181151937Sjkim    ACPI_WALK_STATE         *WalkState,
182151937Sjkim    ACPI_PARSE_OBJECT       *Arg);
183151937Sjkim
184151937Sjkim
185235945Sjkim#ifdef ACPI_ASL_COMPILER
18667754Smsmith/*******************************************************************************
18767754Smsmith *
188235945Sjkim * FUNCTION:    AcpiDsCreateExternalRegion (iASL Disassembler only)
189235945Sjkim *
190235945Sjkim * PARAMETERS:  LookupStatus    - Status from NsLookup operation
191235945Sjkim *              Op              - Op containing the Field definition and args
192235945Sjkim *              Path            - Pathname of the region
193235945Sjkim *  `           WalkState       - Current method state
194235945Sjkim *              Node            - Where the new region node is returned
195235945Sjkim *
196235945Sjkim * RETURN:      Status
197235945Sjkim *
198235945Sjkim * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
199235945Sjkim *              region node/object.
200235945Sjkim *
201235945Sjkim ******************************************************************************/
202235945Sjkim
203235945Sjkimstatic ACPI_STATUS
204235945SjkimAcpiDsCreateExternalRegion (
205235945Sjkim    ACPI_STATUS             LookupStatus,
206235945Sjkim    ACPI_PARSE_OBJECT       *Op,
207235945Sjkim    char                    *Path,
208235945Sjkim    ACPI_WALK_STATE         *WalkState,
209235945Sjkim    ACPI_NAMESPACE_NODE     **Node)
210235945Sjkim{
211235945Sjkim    ACPI_STATUS             Status;
212235945Sjkim    ACPI_OPERAND_OBJECT     *ObjDesc;
213235945Sjkim
214235945Sjkim
215235945Sjkim    if (LookupStatus != AE_NOT_FOUND)
216235945Sjkim    {
217235945Sjkim        return (LookupStatus);
218235945Sjkim    }
219235945Sjkim
220235945Sjkim    /*
221235945Sjkim     * Table disassembly:
222235945Sjkim     * OperationRegion not found. Generate an External for it, and
223235945Sjkim     * insert the name into the namespace.
224235945Sjkim     */
225272444Sjkim    AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_REGION, 0, 0);
226298714Sjkim
227235945Sjkim    Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,
228235945Sjkim       ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);
229235945Sjkim    if (ACPI_FAILURE (Status))
230235945Sjkim    {
231235945Sjkim        return (Status);
232235945Sjkim    }
233235945Sjkim
234235945Sjkim    /* Must create and install a region object for the new node */
235235945Sjkim
236235945Sjkim    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
237235945Sjkim    if (!ObjDesc)
238235945Sjkim    {
239235945Sjkim        return (AE_NO_MEMORY);
240235945Sjkim    }
241235945Sjkim
242235945Sjkim    ObjDesc->Region.Node = *Node;
243235945Sjkim    Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);
244235945Sjkim    return (Status);
245235945Sjkim}
246235945Sjkim#endif
247235945Sjkim
248235945Sjkim
249235945Sjkim/*******************************************************************************
250235945Sjkim *
25185756Smsmith * FUNCTION:    AcpiDsCreateBufferField
25267754Smsmith *
253151937Sjkim * PARAMETERS:  Op                  - Current parse op (CreateXXField)
25485756Smsmith *              WalkState           - Current state
25567754Smsmith *
25667754Smsmith * RETURN:      Status
25767754Smsmith *
25887031Smsmith * DESCRIPTION: Execute the CreateField operators:
25985756Smsmith *              CreateBitFieldOp,
26087031Smsmith *              CreateByteFieldOp,
26187031Smsmith *              CreateWordFieldOp,
262237412Sjkim *              CreateDwordFieldOp,
263237412Sjkim *              CreateQwordFieldOp,
264151937Sjkim *              CreateFieldOp       (all of which define a field in a buffer)
26567754Smsmith *
26667754Smsmith ******************************************************************************/
26767754Smsmith
26867754SmsmithACPI_STATUS
26985756SmsmithAcpiDsCreateBufferField (
27067754Smsmith    ACPI_PARSE_OBJECT       *Op,
27167754Smsmith    ACPI_WALK_STATE         *WalkState)
27267754Smsmith{
27367754Smsmith    ACPI_PARSE_OBJECT       *Arg;
27467754Smsmith    ACPI_NAMESPACE_NODE     *Node;
27585756Smsmith    ACPI_STATUS             Status;
27685756Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
27787031Smsmith    ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
27887031Smsmith    UINT32                  Flags;
27967754Smsmith
28067754Smsmith
281167802Sjkim    ACPI_FUNCTION_TRACE (DsCreateBufferField);
28267754Smsmith
28367754Smsmith
284193267Sjkim    /*
285193267Sjkim     * Get the NameString argument (name of the new BufferField)
286193267Sjkim     */
28799679Siwasaki    if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
28867754Smsmith    {
289193267Sjkim        /* For CreateField, name is the 4th argument */
290193267Sjkim
29185756Smsmith        Arg = AcpiPsGetArg (Op, 3);
29267754Smsmith    }
29385756Smsmith    else
29485756Smsmith    {
295193267Sjkim        /* For all other CreateXXXField operators, name is the 3rd argument */
29667754Smsmith
29785756Smsmith        Arg = AcpiPsGetArg (Op, 2);
29885756Smsmith    }
29967754Smsmith
30085756Smsmith    if (!Arg)
30185756Smsmith    {
30285756Smsmith        return_ACPI_STATUS (AE_AML_NO_OPERAND);
30385756Smsmith    }
30467754Smsmith
305123315Snjl    if (WalkState->DeferredNode)
30687031Smsmith    {
307123315Snjl        Node = WalkState->DeferredNode;
308123315Snjl        Status = AE_OK;
30987031Smsmith    }
31087031Smsmith    else
31187031Smsmith    {
312193267Sjkim        /* Execute flag should always be set when this function is entered */
313193267Sjkim
314193267Sjkim        if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
315123315Snjl        {
316322877Sjkim            ACPI_ERROR ((AE_INFO,
317322877Sjkim                "Parse execute mode is not set"));
318193267Sjkim            return_ACPI_STATUS (AE_AML_INTERNAL);
319123315Snjl        }
320193267Sjkim
321193267Sjkim        /* Creating new namespace node, should not already exist */
322193267Sjkim
323193267Sjkim        Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
324298714Sjkim            ACPI_NS_ERROR_IF_FOUND;
325193267Sjkim
326197104Sjkim        /*
327197104Sjkim         * Mark node temporary if we are executing a normal control
328197104Sjkim         * method. (Don't mark if this is a module-level code method)
329197104Sjkim         */
330197104Sjkim        if (WalkState->MethodNode &&
331197104Sjkim            !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
332123315Snjl        {
333193267Sjkim            Flags |= ACPI_NS_TEMPORARY;
334123315Snjl        }
33587031Smsmith
336193267Sjkim        /* Enter the NameString into the namespace */
337193267Sjkim
338298714Sjkim        Status = AcpiNsLookup (WalkState->ScopeInfo,
339298714Sjkim            Arg->Common.Value.String, ACPI_TYPE_ANY,
340298714Sjkim            ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
341123315Snjl        if (ACPI_FAILURE (Status))
342123315Snjl        {
343327557Sjkim            ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
344327557Sjkim                Arg->Common.Value.String, Status);
345123315Snjl            return_ACPI_STATUS (Status);
346123315Snjl        }
34785756Smsmith    }
34867754Smsmith
349167802Sjkim    /*
350167802Sjkim     * We could put the returned object (Node) on the object stack for later,
351151937Sjkim     * but for now, we will put it in the "op" object that the parser uses,
352193267Sjkim     * so we can get it again at the end of this scope.
35385756Smsmith     */
35499679Siwasaki    Op->Common.Node = Node;
35585756Smsmith
35685756Smsmith    /*
357151937Sjkim     * If there is no object attached to the node, this node was just created
358193267Sjkim     * and we need to create the field object. Otherwise, this was a lookup
359151937Sjkim     * of an existing node and we don't want to create the field object again.
36085756Smsmith     */
36187031Smsmith    ObjDesc = AcpiNsGetAttachedObject (Node);
36287031Smsmith    if (ObjDesc)
36385756Smsmith    {
36485756Smsmith        return_ACPI_STATUS (AE_OK);
36585756Smsmith    }
36685756Smsmith
36785756Smsmith    /*
36885756Smsmith     * The Field definition is not fully parsed at this time.
36985756Smsmith     * (We must save the address of the AML for the buffer and index operands)
37085756Smsmith     */
37185756Smsmith
37285756Smsmith    /* Create the buffer field object */
37385756Smsmith
37485756Smsmith    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
37585756Smsmith    if (!ObjDesc)
37685756Smsmith    {
37785756Smsmith        Status = AE_NO_MEMORY;
37885756Smsmith        goto Cleanup;
37985756Smsmith    }
38085756Smsmith
38185756Smsmith    /*
382298714Sjkim     * Remember location in AML stream of the field unit opcode and operands
383298714Sjkim     * -- since the buffer and index operands must be evaluated.
38485756Smsmith     */
385298714Sjkim    SecondDesc = ObjDesc->Common.NextObject;
386298714Sjkim    SecondDesc->Extra.AmlStart = Op->Named.Data;
38799679Siwasaki    SecondDesc->Extra.AmlLength = Op->Named.Length;
388298714Sjkim    ObjDesc->BufferField.Node = Node;
38985756Smsmith
39087031Smsmith    /* Attach constructed field descriptors to parent node */
39185756Smsmith
39285756Smsmith    Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
39387031Smsmith    if (ACPI_FAILURE (Status))
39487031Smsmith    {
39587031Smsmith        goto Cleanup;
39687031Smsmith    }
39785756Smsmith
39885756Smsmith
39985756SmsmithCleanup:
40085756Smsmith
40185756Smsmith    /* Remove local reference to the object */
40285756Smsmith
40385756Smsmith    AcpiUtRemoveReference (ObjDesc);
40485756Smsmith    return_ACPI_STATUS (Status);
40585756Smsmith}
40685756Smsmith
40785756Smsmith
40885756Smsmith/*******************************************************************************
40985756Smsmith *
41085756Smsmith * FUNCTION:    AcpiDsGetFieldNames
41185756Smsmith *
41285756Smsmith * PARAMETERS:  Info            - CreateField info structure
41385756Smsmith *  `           WalkState       - Current method state
41485756Smsmith *              Arg             - First parser arg for the field name list
41585756Smsmith *
41685756Smsmith * RETURN:      Status
41785756Smsmith *
418241973Sjkim * DESCRIPTION: Process all named fields in a field declaration. Names are
41985756Smsmith *              entered into the namespace.
42085756Smsmith *
42185756Smsmith ******************************************************************************/
42285756Smsmith
423151937Sjkimstatic ACPI_STATUS
42485756SmsmithAcpiDsGetFieldNames (
42585756Smsmith    ACPI_CREATE_FIELD_INFO  *Info,
42685756Smsmith    ACPI_WALK_STATE         *WalkState,
42785756Smsmith    ACPI_PARSE_OBJECT       *Arg)
42885756Smsmith{
42985756Smsmith    ACPI_STATUS             Status;
430202771Sjkim    UINT64                  Position;
431228110Sjkim    ACPI_PARSE_OBJECT       *Child;
43285756Smsmith
43385756Smsmith
434167802Sjkim    ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
43585756Smsmith
43685756Smsmith
43785756Smsmith    /* First field starts at bit zero */
43885756Smsmith
43985756Smsmith    Info->FieldBitPosition = 0;
44085756Smsmith
44185756Smsmith    /* Process all elements in the field list (of parse nodes) */
44285756Smsmith
44367754Smsmith    while (Arg)
44467754Smsmith    {
44585756Smsmith        /*
446228110Sjkim         * Four types of field elements are handled:
447228110Sjkim         * 1) Name - Enters a new named field into the namespace
448228110Sjkim         * 2) Offset - specifies a bit offset
449228110Sjkim         * 3) AccessAs - changes the access mode/attributes
450228110Sjkim         * 4) Connection - Associate a resource template with the field
45185756Smsmith         */
45299679Siwasaki        switch (Arg->Common.AmlOpcode)
45367754Smsmith        {
45477424Smsmith        case AML_INT_RESERVEDFIELD_OP:
45567754Smsmith
456298714Sjkim            Position = (UINT64) Info->FieldBitPosition +
457298714Sjkim                (UINT64) Arg->Common.Value.Size;
45899679Siwasaki
45999679Siwasaki            if (Position > ACPI_UINT32_MAX)
46091116Smsmith            {
461167802Sjkim                ACPI_ERROR ((AE_INFO,
462167802Sjkim                    "Bit offset within field too large (> 0xFFFFFFFF)"));
46391116Smsmith                return_ACPI_STATUS (AE_SUPPORT);
46491116Smsmith            }
46591116Smsmith
46699679Siwasaki            Info->FieldBitPosition = (UINT32) Position;
46767754Smsmith            break;
46867754Smsmith
46977424Smsmith        case AML_INT_ACCESSFIELD_OP:
470228110Sjkim        case AML_INT_EXTACCESSFIELD_OP:
47167754Smsmith            /*
472228110Sjkim             * Get new AccessType, AccessAttribute, and AccessLength fields
473228110Sjkim             * -- to be used for all field units that follow, until the
474228110Sjkim             * end-of-field or another AccessAs keyword is encountered.
475228110Sjkim             * NOTE. These three bytes are encoded in the integer value
476228110Sjkim             * of the parseop for convenience.
47787031Smsmith             *
478151937Sjkim             * In FieldFlags, preserve the flag bits other than the
479228110Sjkim             * ACCESS_TYPE bits.
48067754Smsmith             */
481228110Sjkim
482228110Sjkim            /* AccessType (ByteAcc, WordAcc, etc.) */
483228110Sjkim
484151937Sjkim            Info->FieldFlags = (UINT8)
485151937Sjkim                ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
486228110Sjkim                ((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));
48787031Smsmith
488228110Sjkim            /* AccessAttribute (AttribQuick, AttribByte, etc.) */
489228110Sjkim
490298714Sjkim            Info->Attribute = (UINT8)
491298714Sjkim                ((Arg->Common.Value.Integer >> 8) & 0xFF);
492228110Sjkim
493228110Sjkim            /* AccessLength (for serial/buffer protocols) */
494228110Sjkim
495298714Sjkim            Info->AccessLength = (UINT8)
496298714Sjkim                ((Arg->Common.Value.Integer >> 16) & 0xFF);
49767754Smsmith            break;
49867754Smsmith
499228110Sjkim        case AML_INT_CONNECTION_OP:
500228110Sjkim            /*
501228110Sjkim             * Clear any previous connection. New connection is used for all
502228110Sjkim             * fields that follow, similar to AccessAs
503228110Sjkim             */
504228110Sjkim            Info->ResourceBuffer = NULL;
505228110Sjkim            Info->ConnectionNode = NULL;
506272444Sjkim            Info->PinNumberIndex = 0;
50767754Smsmith
508228110Sjkim            /*
509228110Sjkim             * A Connection() is either an actual resource descriptor (buffer)
510228110Sjkim             * or a named reference to a resource template
511228110Sjkim             */
512228110Sjkim            Child = Arg->Common.Value.Arg;
513228110Sjkim            if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)
514228110Sjkim            {
515228110Sjkim                Info->ResourceBuffer = Child->Named.Data;
516228110Sjkim                Info->ResourceLength = (UINT16) Child->Named.Value.Integer;
517228110Sjkim            }
518228110Sjkim            else
519228110Sjkim            {
520228110Sjkim                /* Lookup the Connection() namepath, it should already exist */
521228110Sjkim
522228110Sjkim                Status = AcpiNsLookup (WalkState->ScopeInfo,
523298714Sjkim                    Child->Common.Value.Name, ACPI_TYPE_ANY,
524298714Sjkim                    ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
525298714Sjkim                    WalkState, &Info->ConnectionNode);
526228110Sjkim                if (ACPI_FAILURE (Status))
527228110Sjkim                {
528327557Sjkim                    ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
529327557Sjkim                        Child->Common.Value.Name, Status);
530228110Sjkim                    return_ACPI_STATUS (Status);
531228110Sjkim                }
532228110Sjkim            }
533228110Sjkim            break;
534228110Sjkim
53577424Smsmith        case AML_INT_NAMEDFIELD_OP:
53667754Smsmith
537193267Sjkim            /* Lookup the name, it should already exist */
53885756Smsmith
53967754Smsmith            Status = AcpiNsLookup (WalkState->ScopeInfo,
540298714Sjkim                (char *) &Arg->Named.Name, Info->FieldType,
541298714Sjkim                ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
542298714Sjkim                WalkState, &Info->FieldNode);
54367754Smsmith            if (ACPI_FAILURE (Status))
54467754Smsmith            {
545327557Sjkim                ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
546327557Sjkim                    (char *) &Arg->Named.Name, Status);
547193267Sjkim                return_ACPI_STATUS (Status);
54867754Smsmith            }
54987031Smsmith            else
55087031Smsmith            {
55199679Siwasaki                Arg->Common.Node = Info->FieldNode;
55299679Siwasaki                Info->FieldBitLength = Arg->Common.Value.Size;
55367754Smsmith
554193267Sjkim                /*
555193267Sjkim                 * If there is no object attached to the node, this node was
556193267Sjkim                 * just created and we need to create the field object.
557193267Sjkim                 * Otherwise, this was a lookup of an existing node and we
558193267Sjkim                 * don't want to create the field object again.
559193267Sjkim                 */
560193267Sjkim                if (!AcpiNsGetAttachedObject (Info->FieldNode))
56187031Smsmith                {
562193267Sjkim                    Status = AcpiExPrepFieldValue (Info);
563193267Sjkim                    if (ACPI_FAILURE (Status))
564193267Sjkim                    {
565193267Sjkim                        return_ACPI_STATUS (Status);
566193267Sjkim                    }
56787031Smsmith                }
56867754Smsmith            }
56967754Smsmith
57085756Smsmith            /* Keep track of bit position for the next field */
57167754Smsmith
572298714Sjkim            Position = (UINT64) Info->FieldBitPosition +
573298714Sjkim                (UINT64) Arg->Common.Value.Size;
57499679Siwasaki
57599679Siwasaki            if (Position > ACPI_UINT32_MAX)
57691116Smsmith            {
577167802Sjkim                ACPI_ERROR ((AE_INFO,
578167802Sjkim                    "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
579167802Sjkim                    ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
58091116Smsmith                return_ACPI_STATUS (AE_SUPPORT);
58191116Smsmith            }
58291116Smsmith
58385756Smsmith            Info->FieldBitPosition += Info->FieldBitLength;
584272444Sjkim            Info->PinNumberIndex++; /* Index relative to previous Connection() */
58567754Smsmith            break;
58685756Smsmith
58785756Smsmith        default:
58885756Smsmith
589167802Sjkim            ACPI_ERROR ((AE_INFO,
590298714Sjkim                "Invalid opcode in field list: 0x%X",
591298714Sjkim                Arg->Common.AmlOpcode));
59299679Siwasaki            return_ACPI_STATUS (AE_AML_BAD_OPCODE);
59367754Smsmith        }
59467754Smsmith
59599679Siwasaki        Arg = Arg->Common.Next;
59667754Smsmith    }
59767754Smsmith
59885756Smsmith    return_ACPI_STATUS (AE_OK);
59985756Smsmith}
60085756Smsmith
60185756Smsmith
60285756Smsmith/*******************************************************************************
60385756Smsmith *
60485756Smsmith * FUNCTION:    AcpiDsCreateField
60585756Smsmith *
60685756Smsmith * PARAMETERS:  Op              - Op containing the Field definition and args
60785756Smsmith *              RegionNode      - Object for the containing Operation Region
60885756Smsmith *  `           WalkState       - Current method state
60985756Smsmith *
61085756Smsmith * RETURN:      Status
61185756Smsmith *
61285756Smsmith * DESCRIPTION: Create a new field in the specified operation region
61385756Smsmith *
61485756Smsmith ******************************************************************************/
61585756Smsmith
61685756SmsmithACPI_STATUS
61785756SmsmithAcpiDsCreateField (
61885756Smsmith    ACPI_PARSE_OBJECT       *Op,
61985756Smsmith    ACPI_NAMESPACE_NODE     *RegionNode,
62085756Smsmith    ACPI_WALK_STATE         *WalkState)
62185756Smsmith{
62299679Siwasaki    ACPI_STATUS             Status;
62385756Smsmith    ACPI_PARSE_OBJECT       *Arg;
62485756Smsmith    ACPI_CREATE_FIELD_INFO  Info;
62585756Smsmith
62685756Smsmith
627167802Sjkim    ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
62885756Smsmith
62985756Smsmith
63085756Smsmith    /* First arg is the name of the parent OpRegion (must already exist) */
63185756Smsmith
63299679Siwasaki    Arg = Op->Common.Value.Arg;
633235945Sjkim
63485756Smsmith    if (!RegionNode)
63585756Smsmith    {
63699679Siwasaki        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
637298714Sjkim            ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
638298714Sjkim            ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
639235945Sjkim#ifdef ACPI_ASL_COMPILER
640235945Sjkim        Status = AcpiDsCreateExternalRegion (Status, Arg,
641235945Sjkim            Arg->Common.Value.Name, WalkState, &RegionNode);
642235945Sjkim#endif
64385756Smsmith        if (ACPI_FAILURE (Status))
64485756Smsmith        {
645327557Sjkim            ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
646327557Sjkim                Arg->Common.Value.Name, Status);
64785756Smsmith            return_ACPI_STATUS (Status);
64885756Smsmith        }
64985756Smsmith    }
65085756Smsmith
651284583Sjkim    memset (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));
652228110Sjkim
65385756Smsmith    /* Second arg is the field flags */
65485756Smsmith
65599679Siwasaki    Arg = Arg->Common.Next;
656117521Snjl    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
65787031Smsmith    Info.Attribute = 0;
65885756Smsmith
65985756Smsmith    /* Each remaining arg is a Named Field */
66085756Smsmith
661107325Siwasaki    Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
66285756Smsmith    Info.RegionNode = RegionNode;
66385756Smsmith
66499679Siwasaki    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
66567754Smsmith    return_ACPI_STATUS (Status);
66667754Smsmith}
66767754Smsmith
66867754Smsmith
66967754Smsmith/*******************************************************************************
67067754Smsmith *
67187031Smsmith * FUNCTION:    AcpiDsInitFieldObjects
67287031Smsmith *
67387031Smsmith * PARAMETERS:  Op              - Op containing the Field definition and args
67487031Smsmith *  `           WalkState       - Current method state
67587031Smsmith *
67687031Smsmith * RETURN:      Status
67787031Smsmith *
67887031Smsmith * DESCRIPTION: For each "Field Unit" name in the argument list that is
67987031Smsmith *              part of the field declaration, enter the name into the
68087031Smsmith *              namespace.
68187031Smsmith *
68287031Smsmith ******************************************************************************/
68387031Smsmith
68487031SmsmithACPI_STATUS
68587031SmsmithAcpiDsInitFieldObjects (
68687031Smsmith    ACPI_PARSE_OBJECT       *Op,
68787031Smsmith    ACPI_WALK_STATE         *WalkState)
68887031Smsmith{
68999679Siwasaki    ACPI_STATUS             Status;
69087031Smsmith    ACPI_PARSE_OBJECT       *Arg = NULL;
69187031Smsmith    ACPI_NAMESPACE_NODE     *Node;
69287031Smsmith    UINT8                   Type = 0;
693193267Sjkim    UINT32                  Flags;
69487031Smsmith
69587031Smsmith
696167802Sjkim    ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
69787031Smsmith
69887031Smsmith
699193267Sjkim    /* Execute flag should always be set when this function is entered */
700193267Sjkim
701193267Sjkim    if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
702193267Sjkim    {
703193267Sjkim        if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
704193267Sjkim        {
705193267Sjkim            /* BankField Op is deferred, just return OK */
706193267Sjkim
707193267Sjkim            return_ACPI_STATUS (AE_OK);
708193267Sjkim        }
709193267Sjkim
710322877Sjkim        ACPI_ERROR ((AE_INFO,
711322877Sjkim            "Parse deferred mode is not set"));
712193267Sjkim        return_ACPI_STATUS (AE_AML_INTERNAL);
713193267Sjkim    }
714193267Sjkim
715193267Sjkim    /*
716193267Sjkim     * Get the FieldList argument for this opcode. This is the start of the
717193267Sjkim     * list of field elements.
718193267Sjkim     */
71987031Smsmith    switch (WalkState->Opcode)
72087031Smsmith    {
72187031Smsmith    case AML_FIELD_OP:
722250838Sjkim
72387031Smsmith        Arg = AcpiPsGetArg (Op, 2);
724107325Siwasaki        Type = ACPI_TYPE_LOCAL_REGION_FIELD;
72587031Smsmith        break;
72687031Smsmith
72787031Smsmith    case AML_BANK_FIELD_OP:
728250838Sjkim
72987031Smsmith        Arg = AcpiPsGetArg (Op, 4);
730107325Siwasaki        Type = ACPI_TYPE_LOCAL_BANK_FIELD;
73187031Smsmith        break;
73287031Smsmith
73387031Smsmith    case AML_INDEX_FIELD_OP:
734250838Sjkim
73587031Smsmith        Arg = AcpiPsGetArg (Op, 3);
736107325Siwasaki        Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
73787031Smsmith        break;
73899679Siwasaki
73999679Siwasaki    default:
740250838Sjkim
74199679Siwasaki        return_ACPI_STATUS (AE_BAD_PARAMETER);
74287031Smsmith    }
74387031Smsmith
744193267Sjkim    /* Creating new namespace node(s), should not already exist */
745193267Sjkim
746193267Sjkim    Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
747298714Sjkim        ACPI_NS_ERROR_IF_FOUND;
748193267Sjkim
749197104Sjkim    /*
750197104Sjkim     * Mark node(s) temporary if we are executing a normal control
751197104Sjkim     * method. (Don't mark if this is a module-level code method)
752197104Sjkim     */
753197104Sjkim    if (WalkState->MethodNode &&
754197104Sjkim        !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
755193267Sjkim    {
756193267Sjkim        Flags |= ACPI_NS_TEMPORARY;
757193267Sjkim    }
758193267Sjkim
75987031Smsmith    /*
76087031Smsmith     * Walk the list of entries in the FieldList
761193267Sjkim     * Note: FieldList can be of zero length. In this case, Arg will be NULL.
76287031Smsmith     */
76387031Smsmith    while (Arg)
76487031Smsmith    {
765193267Sjkim        /*
766228110Sjkim         * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
767228110Sjkim         * in the field names in order to enter them into the namespace.
768193267Sjkim         */
76999679Siwasaki        if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
77087031Smsmith        {
77187031Smsmith            Status = AcpiNsLookup (WalkState->ScopeInfo,
772298714Sjkim                (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
773298714Sjkim                Flags, WalkState, &Node);
77487031Smsmith            if (ACPI_FAILURE (Status))
77587031Smsmith            {
776327557Sjkim                ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
777327557Sjkim                    (char *) &Arg->Named.Name, Status);
77887031Smsmith                if (Status != AE_ALREADY_EXISTS)
77987031Smsmith                {
78087031Smsmith                    return_ACPI_STATUS (Status);
78187031Smsmith                }
78287031Smsmith
78399679Siwasaki                /* Name already exists, just ignore this error */
78499679Siwasaki
78599679Siwasaki                Status = AE_OK;
78687031Smsmith            }
78787031Smsmith
78899679Siwasaki            Arg->Common.Node = Node;
78987031Smsmith        }
79087031Smsmith
791193267Sjkim        /* Get the next field element in the list */
79287031Smsmith
79399679Siwasaki        Arg = Arg->Common.Next;
79487031Smsmith    }
79587031Smsmith
79699679Siwasaki    return_ACPI_STATUS (AE_OK);
79787031Smsmith}
79887031Smsmith
79987031Smsmith
80087031Smsmith/*******************************************************************************
80187031Smsmith *
80267754Smsmith * FUNCTION:    AcpiDsCreateBankField
80367754Smsmith *
80467754Smsmith * PARAMETERS:  Op              - Op containing the Field definition and args
80577424Smsmith *              RegionNode      - Object for the containing Operation Region
806193267Sjkim *              WalkState       - Current method state
80767754Smsmith *
80867754Smsmith * RETURN:      Status
80967754Smsmith *
81067754Smsmith * DESCRIPTION: Create a new bank field in the specified operation region
81167754Smsmith *
81267754Smsmith ******************************************************************************/
81367754Smsmith
81467754SmsmithACPI_STATUS
81567754SmsmithAcpiDsCreateBankField (
81667754Smsmith    ACPI_PARSE_OBJECT       *Op,
81767754Smsmith    ACPI_NAMESPACE_NODE     *RegionNode,
81867754Smsmith    ACPI_WALK_STATE         *WalkState)
81967754Smsmith{
82099679Siwasaki    ACPI_STATUS             Status;
82167754Smsmith    ACPI_PARSE_OBJECT       *Arg;
82285756Smsmith    ACPI_CREATE_FIELD_INFO  Info;
82367754Smsmith
82467754Smsmith
825167802Sjkim    ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
82667754Smsmith
82767754Smsmith
82885756Smsmith    /* First arg is the name of the parent OpRegion (must already exist) */
82967754Smsmith
83099679Siwasaki    Arg = Op->Common.Value.Arg;
83167754Smsmith    if (!RegionNode)
83267754Smsmith    {
83399679Siwasaki        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
834298714Sjkim            ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
835298714Sjkim            ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
836235945Sjkim#ifdef ACPI_ASL_COMPILER
837235945Sjkim        Status = AcpiDsCreateExternalRegion (Status, Arg,
838235945Sjkim            Arg->Common.Value.Name, WalkState, &RegionNode);
839235945Sjkim#endif
84067754Smsmith        if (ACPI_FAILURE (Status))
84167754Smsmith        {
842327557Sjkim            ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
843327557Sjkim                Arg->Common.Value.Name, Status);
84467754Smsmith            return_ACPI_STATUS (Status);
84567754Smsmith        }
84667754Smsmith    }
84767754Smsmith
848107325Siwasaki    /* Second arg is the Bank Register (Field) (must already exist) */
84967754Smsmith
85099679Siwasaki    Arg = Arg->Common.Next;
85199679Siwasaki    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
852298714Sjkim        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
853298714Sjkim        ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
85467754Smsmith    if (ACPI_FAILURE (Status))
85567754Smsmith    {
856327557Sjkim        ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
857327557Sjkim            Arg->Common.Value.String, Status);
85867754Smsmith        return_ACPI_STATUS (Status);
85967754Smsmith    }
86067754Smsmith
861193267Sjkim    /*
862193267Sjkim     * Third arg is the BankValue
863193267Sjkim     * This arg is a TermArg, not a constant
864193267Sjkim     * It will be evaluated later, by AcpiDsEvalBankFieldOperands
865193267Sjkim     */
86699679Siwasaki    Arg = Arg->Common.Next;
86767754Smsmith
86885756Smsmith    /* Fourth arg is the field flags */
86967754Smsmith
87099679Siwasaki    Arg = Arg->Common.Next;
871117521Snjl    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
87267754Smsmith
87367754Smsmith    /* Each remaining arg is a Named Field */
87467754Smsmith
875107325Siwasaki    Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
87685756Smsmith    Info.RegionNode = RegionNode;
87767754Smsmith
878193267Sjkim    /*
879193267Sjkim     * Use Info.DataRegisterNode to store BankField Op
880298714Sjkim     * It's safe because DataRegisterNode will never be used when create
881298714Sjkim     * bank field \we store AmlStart and AmlLength in the BankField Op for
882298714Sjkim     * late evaluation. Used in AcpiExPrepFieldValue(Info)
883193267Sjkim     *
884298714Sjkim     * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like
885298714Sjkim     * "void *ParentOp"?
886193267Sjkim     */
887193267Sjkim    Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
888193267Sjkim
88999679Siwasaki    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
89067754Smsmith    return_ACPI_STATUS (Status);
89167754Smsmith}
89267754Smsmith
89367754Smsmith
89467754Smsmith/*******************************************************************************
89567754Smsmith *
89667754Smsmith * FUNCTION:    AcpiDsCreateIndexField
89767754Smsmith *
89867754Smsmith * PARAMETERS:  Op              - Op containing the Field definition and args
89977424Smsmith *              RegionNode      - Object for the containing Operation Region
90077424Smsmith *  `           WalkState       - Current method state
90167754Smsmith *
90267754Smsmith * RETURN:      Status
90367754Smsmith *
90467754Smsmith * DESCRIPTION: Create a new index field in the specified operation region
90567754Smsmith *
90667754Smsmith ******************************************************************************/
90767754Smsmith
90867754SmsmithACPI_STATUS
90967754SmsmithAcpiDsCreateIndexField (
91067754Smsmith    ACPI_PARSE_OBJECT       *Op,
91177424Smsmith    ACPI_NAMESPACE_NODE     *RegionNode,
91267754Smsmith    ACPI_WALK_STATE         *WalkState)
91367754Smsmith{
91467754Smsmith    ACPI_STATUS             Status;
91567754Smsmith    ACPI_PARSE_OBJECT       *Arg;
91685756Smsmith    ACPI_CREATE_FIELD_INFO  Info;
91767754Smsmith
91867754Smsmith
919167802Sjkim    ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
92067754Smsmith
92167754Smsmith
92285756Smsmith    /* First arg is the name of the Index register (must already exist) */
92385756Smsmith
92499679Siwasaki    Arg = Op->Common.Value.Arg;
92599679Siwasaki    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
926298714Sjkim        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
927298714Sjkim        ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
92867754Smsmith    if (ACPI_FAILURE (Status))
92967754Smsmith    {
930327557Sjkim        ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
931327557Sjkim            Arg->Common.Value.String, Status);
93267754Smsmith        return_ACPI_STATUS (Status);
93367754Smsmith    }
93467754Smsmith
93585756Smsmith    /* Second arg is the data register (must already exist) */
93667754Smsmith
93799679Siwasaki    Arg = Arg->Common.Next;
93899679Siwasaki    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
939298714Sjkim        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
940298714Sjkim        ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
94167754Smsmith    if (ACPI_FAILURE (Status))
94267754Smsmith    {
943327557Sjkim        ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
944327557Sjkim            Arg->Common.Value.String, Status);
94567754Smsmith        return_ACPI_STATUS (Status);
94667754Smsmith    }
94767754Smsmith
94867754Smsmith    /* Next arg is the field flags */
94967754Smsmith
95099679Siwasaki    Arg = Arg->Common.Next;
951117521Snjl    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
95267754Smsmith
95367754Smsmith    /* Each remaining arg is a Named Field */
95467754Smsmith
955107325Siwasaki    Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
95685756Smsmith    Info.RegionNode = RegionNode;
95767754Smsmith
95899679Siwasaki    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
95967754Smsmith    return_ACPI_STATUS (Status);
96067754Smsmith}
961