asloperands.c revision 167802
1118611Snjl
2118611Snjl/******************************************************************************
3118611Snjl *
4118611Snjl * Module Name: asloperands - AML operand processing
5167802Sjkim *              $Revision: 1.61 $
6118611Snjl *
7118611Snjl *****************************************************************************/
8118611Snjl
9118611Snjl/******************************************************************************
10118611Snjl *
11118611Snjl * 1. Copyright Notice
12118611Snjl *
13167802Sjkim * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
14118611Snjl * All rights reserved.
15118611Snjl *
16118611Snjl * 2. License
17118611Snjl *
18118611Snjl * 2.1. This is your license from Intel Corp. under its intellectual property
19118611Snjl * rights.  You may have additional license terms from the party that provided
20118611Snjl * you this software, covering your right to use that party's intellectual
21118611Snjl * property rights.
22118611Snjl *
23118611Snjl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24118611Snjl * copy of the source code appearing in this file ("Covered Code") an
25118611Snjl * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26118611Snjl * base code distributed originally by Intel ("Original Intel Code") to copy,
27118611Snjl * make derivatives, distribute, use and display any portion of the Covered
28118611Snjl * Code in any form, with the right to sublicense such rights; and
29118611Snjl *
30118611Snjl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31118611Snjl * license (with the right to sublicense), under only those claims of Intel
32118611Snjl * patents that are infringed by the Original Intel Code, to make, use, sell,
33118611Snjl * offer to sell, and import the Covered Code and derivative works thereof
34118611Snjl * solely to the minimum extent necessary to exercise the above copyright
35118611Snjl * license, and in no event shall the patent license extend to any additions
36118611Snjl * to or modifications of the Original Intel Code.  No other license or right
37118611Snjl * is granted directly or by implication, estoppel or otherwise;
38118611Snjl *
39118611Snjl * The above copyright and patent license is granted only if the following
40118611Snjl * conditions are met:
41118611Snjl *
42118611Snjl * 3. Conditions
43118611Snjl *
44118611Snjl * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45118611Snjl * Redistribution of source code of any substantial portion of the Covered
46118611Snjl * Code or modification with rights to further distribute source must include
47118611Snjl * the above Copyright Notice, the above License, this list of Conditions,
48118611Snjl * and the following Disclaimer and Export Compliance provision.  In addition,
49118611Snjl * Licensee must cause all Covered Code to which Licensee contributes to
50118611Snjl * contain a file documenting the changes Licensee made to create that Covered
51118611Snjl * Code and the date of any change.  Licensee must include in that file the
52118611Snjl * documentation of any changes made by any predecessor Licensee.  Licensee
53118611Snjl * must include a prominent statement that the modification is derived,
54118611Snjl * directly or indirectly, from Original Intel Code.
55118611Snjl *
56118611Snjl * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57118611Snjl * Redistribution of source code of any substantial portion of the Covered
58118611Snjl * Code or modification without rights to further distribute source must
59118611Snjl * include the following Disclaimer and Export Compliance provision in the
60118611Snjl * documentation and/or other materials provided with distribution.  In
61118611Snjl * addition, Licensee may not authorize further sublicense of source of any
62118611Snjl * portion of the Covered Code, and must include terms to the effect that the
63118611Snjl * license from Licensee to its licensee is limited to the intellectual
64118611Snjl * property embodied in the software Licensee provides to its licensee, and
65118611Snjl * not to intellectual property embodied in modifications its licensee may
66118611Snjl * make.
67118611Snjl *
68118611Snjl * 3.3. Redistribution of Executable. Redistribution in executable form of any
69118611Snjl * substantial portion of the Covered Code or modification must reproduce the
70118611Snjl * above Copyright Notice, and the following Disclaimer and Export Compliance
71118611Snjl * provision in the documentation and/or other materials provided with the
72118611Snjl * distribution.
73118611Snjl *
74118611Snjl * 3.4. Intel retains all right, title, and interest in and to the Original
75118611Snjl * Intel Code.
76118611Snjl *
77118611Snjl * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78118611Snjl * Intel shall be used in advertising or otherwise to promote the sale, use or
79118611Snjl * other dealings in products derived from or relating to the Covered Code
80118611Snjl * without prior written authorization from Intel.
81118611Snjl *
82118611Snjl * 4. Disclaimer and Export Compliance
83118611Snjl *
84118611Snjl * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85118611Snjl * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86118611Snjl * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87118611Snjl * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88118611Snjl * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89118611Snjl * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90118611Snjl * PARTICULAR PURPOSE.
91118611Snjl *
92118611Snjl * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93118611Snjl * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94118611Snjl * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95118611Snjl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96118611Snjl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97118611Snjl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98118611Snjl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99118611Snjl * LIMITED REMEDY.
100118611Snjl *
101118611Snjl * 4.3. Licensee shall not export, either directly or indirectly, any of this
102118611Snjl * software or system incorporating such software without first obtaining any
103118611Snjl * required license or other approval from the U. S. Department of Commerce or
104118611Snjl * any other agency or department of the United States Government.  In the
105118611Snjl * event Licensee exports any such software from the United States or
106118611Snjl * re-exports any such software from a foreign destination, Licensee shall
107118611Snjl * ensure that the distribution and export/re-export of the software is in
108118611Snjl * compliance with all laws, regulations, orders, or other restrictions of the
109118611Snjl * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110118611Snjl * any of its subsidiaries will export/re-export any technical data, process,
111118611Snjl * software, or service, directly or indirectly, to any country for which the
112118611Snjl * United States government or any agency thereof requires an export license,
113118611Snjl * other governmental approval, or letter of assurance, without first obtaining
114118611Snjl * such license, approval or letter.
115118611Snjl *
116118611Snjl *****************************************************************************/
117118611Snjl
118118611Snjl
119151937Sjkim#include <contrib/dev/acpica/compiler/aslcompiler.h>
120118611Snjl#include "aslcompiler.y.h"
121151937Sjkim#include <contrib/dev/acpica/amlcode.h>
122118611Snjl
123118611Snjl#define _COMPONENT          ACPI_COMPILER
124118611Snjl        ACPI_MODULE_NAME    ("asloperands")
125118611Snjl
126151937Sjkim/* Local prototypes */
127118611Snjl
128151937Sjkimstatic void
129151937SjkimOpnDoField (
130151937Sjkim    ACPI_PARSE_OBJECT       *Op);
131151937Sjkim
132151937Sjkimstatic void
133151937SjkimOpnDoBankField (
134151937Sjkim    ACPI_PARSE_OBJECT       *Op);
135151937Sjkim
136151937Sjkimstatic void
137151937SjkimOpnDoBuffer (
138151937Sjkim    ACPI_PARSE_OBJECT       *Op);
139151937Sjkim
140151937Sjkimstatic void
141151937SjkimOpnDoDefinitionBlock (
142151937Sjkim    ACPI_PARSE_OBJECT       *Op);
143151937Sjkim
144151937Sjkimstatic void
145151937SjkimOpnDoFieldCommon (
146151937Sjkim    ACPI_PARSE_OBJECT       *FieldOp,
147151937Sjkim    ACPI_PARSE_OBJECT       *Op);
148151937Sjkim
149151937Sjkimstatic void
150151937SjkimOpnDoIndexField (
151151937Sjkim    ACPI_PARSE_OBJECT       *Op);
152151937Sjkim
153151937Sjkimstatic void
154151937SjkimOpnDoLoadTable (
155151937Sjkim    ACPI_PARSE_OBJECT       *Op);
156151937Sjkim
157151937Sjkimstatic void
158151937SjkimOpnDoMethod (
159151937Sjkim    ACPI_PARSE_OBJECT       *Op);
160151937Sjkim
161151937Sjkimstatic void
162151937SjkimOpnDoMutex (
163151937Sjkim    ACPI_PARSE_OBJECT       *Op);
164151937Sjkim
165151937Sjkimstatic void
166151937SjkimOpnDoRegion (
167151937Sjkim    ACPI_PARSE_OBJECT       *Op);
168151937Sjkim
169151937Sjkimstatic void
170151937SjkimOpnAttachNameToNode (
171151937Sjkim    ACPI_PARSE_OBJECT       *Op);
172151937Sjkim
173151937Sjkim
174118611Snjl/*******************************************************************************
175118611Snjl *
176151937Sjkim * FUNCTION:    OpnDoMutex
177151937Sjkim *
178151937Sjkim * PARAMETERS:  Op        - The parent parse node
179151937Sjkim *
180151937Sjkim * RETURN:      None
181151937Sjkim *
182151937Sjkim * DESCRIPTION: Construct the operands for the MUTEX ASL keyword.
183151937Sjkim *
184151937Sjkim ******************************************************************************/
185151937Sjkim
186151937Sjkimstatic void
187151937SjkimOpnDoMutex (
188151937Sjkim    ACPI_PARSE_OBJECT       *Op)
189151937Sjkim{
190151937Sjkim    ACPI_PARSE_OBJECT       *Next;
191151937Sjkim
192151937Sjkim
193151937Sjkim    Next = Op->Asl.Child;
194151937Sjkim    Next = Next->Asl.Next;
195151937Sjkim
196151937Sjkim    if (Next->Asl.Value.Integer > 15)
197151937Sjkim    {
198151937Sjkim        AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
199151937Sjkim    }
200151937Sjkim    return;
201151937Sjkim}
202151937Sjkim
203151937Sjkim
204151937Sjkim/*******************************************************************************
205151937Sjkim *
206118611Snjl * FUNCTION:    OpnDoMethod
207118611Snjl *
208118611Snjl * PARAMETERS:  Op        - The parent parse node
209118611Snjl *
210118611Snjl * RETURN:      None
211118611Snjl *
212118611Snjl * DESCRIPTION: Construct the operands for the METHOD ASL keyword.
213118611Snjl *
214118611Snjl ******************************************************************************/
215118611Snjl
216151937Sjkimstatic void
217118611SnjlOpnDoMethod (
218118611Snjl    ACPI_PARSE_OBJECT       *Op)
219118611Snjl{
220118611Snjl    ACPI_PARSE_OBJECT       *Next;
221118611Snjl
222118611Snjl    /* Optional arguments for this opcode with defaults */
223118611Snjl
224118611Snjl    UINT8                   NumArgs = 0;
225118611Snjl    UINT8                   Serialized = 0;
226118611Snjl    UINT8                   Concurrency = 0;
227118611Snjl    UINT8                   MethodFlags;
228118611Snjl
229118611Snjl
230118611Snjl    /* Opcode and package length first */
231118611Snjl    /* Method name */
232118611Snjl
233118611Snjl    Next = Op->Asl.Child;
234118611Snjl
235118611Snjl    /* Num args */
236118611Snjl
237118611Snjl    Next = Next->Asl.Next;
238118611Snjl    if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
239118611Snjl    {
240118611Snjl        NumArgs = (UINT8) Next->Asl.Value.Integer;
241118611Snjl        Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
242118611Snjl    }
243118611Snjl
244118611Snjl    /* Serialized Flag */
245118611Snjl
246118611Snjl    Next = Next->Asl.Next;
247118611Snjl    if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
248118611Snjl    {
249118611Snjl        Serialized = (UINT8) Next->Asl.Value.Integer;
250118611Snjl        Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
251118611Snjl    }
252118611Snjl
253151937Sjkim    /* Concurrency value (valid values are 0-15) */
254118611Snjl
255118611Snjl    Next = Next->Asl.Next;
256118611Snjl    if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
257118611Snjl    {
258151937Sjkim        if (Next->Asl.Value.Integer > 15)
259151937Sjkim        {
260151937Sjkim            AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL);
261151937Sjkim        }
262118611Snjl        Concurrency = (UINT8) Next->Asl.Value.Integer;
263118611Snjl    }
264118611Snjl
265118611Snjl    /* Put the bits in their proper places */
266118611Snjl
267118611Snjl    MethodFlags = (UINT8) ((NumArgs & 0x7) |
268118611Snjl                          ((Serialized & 0x1) << 3) |
269118611Snjl                          ((Concurrency & 0xF) << 4));
270118611Snjl
271118611Snjl    /* Use the last node for the combined flags byte */
272118611Snjl
273118611Snjl    Next->Asl.Value.Integer = MethodFlags;
274118611Snjl    Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
275118611Snjl    Next->Asl.AmlLength = 1;
276118611Snjl    Next->Asl.ParseOpcode = PARSEOP_RAW_DATA;
277118611Snjl
278118611Snjl    /* Save the arg count in the first node */
279118611Snjl
280118611Snjl    Op->Asl.Extra = NumArgs;
281118611Snjl}
282118611Snjl
283118611Snjl
284118611Snjl/*******************************************************************************
285118611Snjl *
286118611Snjl * FUNCTION:    OpnDoFieldCommon
287118611Snjl *
288118611Snjl * PARAMETERS:  FieldOp       - Node for an ASL field
289118611Snjl *              Op            - The parent parse node
290118611Snjl *
291118611Snjl * RETURN:      None
292118611Snjl *
293118611Snjl * DESCRIPTION: Construct the AML operands for the various field keywords,
294118611Snjl *              FIELD, BANKFIELD, INDEXFIELD
295118611Snjl *
296118611Snjl ******************************************************************************/
297118611Snjl
298151937Sjkimstatic void
299118611SnjlOpnDoFieldCommon (
300118611Snjl    ACPI_PARSE_OBJECT       *FieldOp,
301118611Snjl    ACPI_PARSE_OBJECT       *Op)
302118611Snjl{
303118611Snjl    ACPI_PARSE_OBJECT       *Next;
304118611Snjl    ACPI_PARSE_OBJECT       *PkgLengthNode;
305118611Snjl    UINT32                  CurrentBitOffset;
306118611Snjl    UINT32                  NewBitOffset;
307118611Snjl    UINT8                   AccessType;
308118611Snjl    UINT8                   LockRule;
309118611Snjl    UINT8                   UpdateRule;
310118611Snjl    UINT8                   FieldFlags;
311118611Snjl    UINT32                  MinimumLength;
312118611Snjl
313118611Snjl
314118611Snjl    /* AccessType -- not optional, so no need to check for DEFAULT_ARG */
315118611Snjl
316118611Snjl    AccessType = (UINT8) Op->Asl.Value.Integer;
317118611Snjl    Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
318118611Snjl
319118611Snjl    /* Set the access type in the parent (field) node for use later */
320118611Snjl
321118611Snjl    FieldOp->Asl.Value.Integer = AccessType;
322118611Snjl
323118611Snjl    /* LockRule -- not optional, so no need to check for DEFAULT_ARG */
324118611Snjl
325118611Snjl    Next = Op->Asl.Next;
326118611Snjl    LockRule = (UINT8) Next->Asl.Value.Integer;
327118611Snjl    Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
328118611Snjl
329118611Snjl    /* UpdateRule -- not optional, so no need to check for DEFAULT_ARG */
330118611Snjl
331118611Snjl    Next = Next->Asl.Next;
332118611Snjl    UpdateRule = (UINT8) Next->Asl.Value.Integer;
333118611Snjl
334118611Snjl    /*
335118611Snjl     * Generate the flags byte.  The various fields are already
336118611Snjl     * in the right bit position via translation from the
337118611Snjl     * keywords by the parser.
338118611Snjl     */
339118611Snjl    FieldFlags = (UINT8) (AccessType | LockRule | UpdateRule);
340118611Snjl
341118611Snjl    /* Use the previous node to be the FieldFlags node */
342118611Snjl
343118611Snjl    /* Set the node to RAW_DATA */
344118611Snjl
345118611Snjl    Next->Asl.Value.Integer = FieldFlags;
346118611Snjl    Next->Asl.AmlOpcode     = AML_RAW_DATA_BYTE;
347118611Snjl    Next->Asl.AmlLength     = 1;
348118611Snjl    Next->Asl.ParseOpcode   = PARSEOP_RAW_DATA;
349118611Snjl
350118611Snjl    /* Process the FieldUnitList */
351118611Snjl
352118611Snjl    Next = Next->Asl.Next;
353118611Snjl    CurrentBitOffset = 0;
354118611Snjl
355118611Snjl    while (Next)
356118611Snjl    {
357118611Snjl        /* Save the offset of this field unit */
358118611Snjl
359118611Snjl        Next->Asl.ExtraValue = CurrentBitOffset;
360118611Snjl
361118611Snjl        switch (Next->Asl.ParseOpcode)
362118611Snjl        {
363118611Snjl        case PARSEOP_ACCESSAS:
364118611Snjl
365118611Snjl            PkgLengthNode = Next->Asl.Child;
366118611Snjl            AccessType = (UINT8) PkgLengthNode->Asl.Value.Integer;
367118611Snjl
368118611Snjl            /* Nothing additional to do */
369118611Snjl            break;
370118611Snjl
371118611Snjl
372118611Snjl        case PARSEOP_OFFSET:
373118611Snjl
374118611Snjl            /* New offset into the field */
375118611Snjl
376118611Snjl            PkgLengthNode = Next->Asl.Child;
377118611Snjl            NewBitOffset = ((UINT32) PkgLengthNode->Asl.Value.Integer) * 8;
378118611Snjl
379118611Snjl            /*
380118611Snjl             * Examine the specified offset in relation to the
381118611Snjl             * current offset counter.
382118611Snjl             */
383118611Snjl            if (NewBitOffset < CurrentBitOffset)
384118611Snjl            {
385118611Snjl                /*
386118611Snjl                 * Not allowed to specify a backwards offset!
387118611Snjl                 * Issue error and ignore this node.
388118611Snjl                 */
389151937Sjkim                AslError (ASL_ERROR, ASL_MSG_BACKWARDS_OFFSET, PkgLengthNode,
390151937Sjkim                    NULL);
391118611Snjl                Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
392118611Snjl                PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
393118611Snjl            }
394118611Snjl            else if (NewBitOffset == CurrentBitOffset)
395118611Snjl            {
396118611Snjl                /*
397118611Snjl                 * Offset is redundant; we don't need to output an
398118611Snjl                 * offset opcode.  Just set these nodes to default
399118611Snjl                 */
400118611Snjl                Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
401118611Snjl                PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
402118611Snjl            }
403118611Snjl            else
404118611Snjl            {
405118611Snjl                /*
406118611Snjl                 * Valid new offset - set the value to be inserted into the AML
407118611Snjl                 * and update the offset counter.
408118611Snjl                 */
409151937Sjkim                PkgLengthNode->Asl.Value.Integer =
410151937Sjkim                    NewBitOffset - CurrentBitOffset;
411118611Snjl                CurrentBitOffset = NewBitOffset;
412118611Snjl            }
413118611Snjl            break;
414118611Snjl
415118611Snjl
416118611Snjl        case PARSEOP_NAMESEG:
417118611Snjl        case PARSEOP_RESERVED_BYTES:
418118611Snjl
419118611Snjl            /* Named or reserved field entry */
420118611Snjl
421118611Snjl            PkgLengthNode     = Next->Asl.Child;
422118611Snjl            NewBitOffset      = (UINT32) PkgLengthNode->Asl.Value.Integer;
423118611Snjl            CurrentBitOffset += NewBitOffset;
424118611Snjl
425118611Snjl            /* Save the current AccessAs value for error checking later */
426118611Snjl
427118611Snjl            switch (AccessType)
428118611Snjl            {
429118611Snjl                case AML_FIELD_ACCESS_ANY:
430118611Snjl                case AML_FIELD_ACCESS_BYTE:
431118611Snjl                case AML_FIELD_ACCESS_BUFFER:
432118611Snjl                default:
433118611Snjl                    MinimumLength = 8;
434118611Snjl                    break;
435118611Snjl
436118611Snjl                case AML_FIELD_ACCESS_WORD:
437118611Snjl                    MinimumLength = 16;
438118611Snjl                    break;
439118611Snjl
440118611Snjl                case AML_FIELD_ACCESS_DWORD:
441118611Snjl                    MinimumLength = 32;
442118611Snjl                    break;
443118611Snjl
444118611Snjl                case AML_FIELD_ACCESS_QWORD:
445118611Snjl                    MinimumLength = 64;
446118611Snjl                    break;
447118611Snjl            }
448118611Snjl
449118611Snjl            PkgLengthNode->Asl.ExtraValue = MinimumLength;
450118611Snjl            break;
451118611Snjl
452118611Snjl        default:
453118611Snjl            /* All supported field opcodes must appear above */
454118611Snjl            break;
455118611Snjl        }
456118611Snjl
457118611Snjl        /* Move on to next entry in the field list */
458118611Snjl
459118611Snjl        Next = Next->Asl.Next;
460118611Snjl    }
461118611Snjl}
462118611Snjl
463118611Snjl
464118611Snjl/*******************************************************************************
465118611Snjl *
466118611Snjl * FUNCTION:    OpnDoField
467118611Snjl *
468118611Snjl * PARAMETERS:  Op        - The parent parse node
469118611Snjl *
470118611Snjl * RETURN:      None
471118611Snjl *
472118611Snjl * DESCRIPTION: Construct the AML operands for the FIELD ASL keyword
473118611Snjl *
474118611Snjl ******************************************************************************/
475118611Snjl
476151937Sjkimstatic void
477118611SnjlOpnDoField (
478118611Snjl    ACPI_PARSE_OBJECT       *Op)
479118611Snjl{
480118611Snjl    ACPI_PARSE_OBJECT       *Next;
481118611Snjl
482118611Snjl
483118611Snjl    /* Opcode is parent node */
484118611Snjl    /* First child is field name */
485118611Snjl
486118611Snjl    Next = Op->Asl.Child;
487118611Snjl
488118611Snjl    /* Second child is the AccessType */
489118611Snjl
490118611Snjl    OpnDoFieldCommon (Op, Next->Asl.Next);
491118611Snjl}
492118611Snjl
493118611Snjl
494118611Snjl/*******************************************************************************
495118611Snjl *
496118611Snjl * FUNCTION:    OpnDoIndexField
497118611Snjl *
498118611Snjl * PARAMETERS:  Op        - The parent parse node
499118611Snjl *
500118611Snjl * RETURN:      None
501118611Snjl *
502118611Snjl * DESCRIPTION: Construct the AML operands for the INDEXFIELD ASL keyword
503118611Snjl *
504118611Snjl ******************************************************************************/
505118611Snjl
506151937Sjkimstatic void
507118611SnjlOpnDoIndexField (
508118611Snjl    ACPI_PARSE_OBJECT       *Op)
509118611Snjl{
510118611Snjl    ACPI_PARSE_OBJECT       *Next;
511118611Snjl
512118611Snjl
513118611Snjl    /* Opcode is parent node */
514118611Snjl    /* First child is the index name */
515118611Snjl
516118611Snjl    Next = Op->Asl.Child;
517118611Snjl
518118611Snjl    /* Second child is the data name */
519118611Snjl
520118611Snjl    Next = Next->Asl.Next;
521118611Snjl
522118611Snjl    /* Third child is the AccessType */
523118611Snjl
524118611Snjl    OpnDoFieldCommon (Op, Next->Asl.Next);
525118611Snjl}
526118611Snjl
527118611Snjl
528118611Snjl/*******************************************************************************
529118611Snjl *
530118611Snjl * FUNCTION:    OpnDoBankField
531118611Snjl *
532118611Snjl * PARAMETERS:  Op        - The parent parse node
533118611Snjl *
534118611Snjl * RETURN:      None
535118611Snjl *
536118611Snjl * DESCRIPTION: Construct the AML operands for the BANKFIELD ASL keyword
537118611Snjl *
538118611Snjl ******************************************************************************/
539118611Snjl
540151937Sjkimstatic void
541118611SnjlOpnDoBankField (
542118611Snjl    ACPI_PARSE_OBJECT       *Op)
543118611Snjl{
544118611Snjl    ACPI_PARSE_OBJECT       *Next;
545118611Snjl
546118611Snjl
547118611Snjl    /* Opcode is parent node */
548118611Snjl    /* First child is the region name */
549118611Snjl
550118611Snjl    Next = Op->Asl.Child;
551118611Snjl
552118611Snjl    /* Second child is the bank name */
553118611Snjl
554118611Snjl    Next = Next->Asl.Next;
555118611Snjl
556118611Snjl    /* Third child is the bank value */
557118611Snjl
558118611Snjl    Next = Next->Asl.Next;
559118611Snjl
560118611Snjl    /* Fourth child is the AccessType */
561118611Snjl
562118611Snjl    OpnDoFieldCommon (Op, Next->Asl.Next);
563118611Snjl}
564118611Snjl
565118611Snjl
566118611Snjl/*******************************************************************************
567118611Snjl *
568118611Snjl * FUNCTION:    OpnDoRegion
569118611Snjl *
570118611Snjl * PARAMETERS:  Op        - The parent parse node
571118611Snjl *
572118611Snjl * RETURN:      None
573118611Snjl *
574118611Snjl * DESCRIPTION: Tries to get the length of the region.  Can only do this at
575118611Snjl *              compile time if the length is a constant.
576118611Snjl *
577118611Snjl ******************************************************************************/
578118611Snjl
579151937Sjkimstatic void
580118611SnjlOpnDoRegion (
581118611Snjl    ACPI_PARSE_OBJECT       *Op)
582118611Snjl{
583118611Snjl    ACPI_PARSE_OBJECT       *Next;
584118611Snjl
585118611Snjl
586118611Snjl    /* Opcode is parent node */
587118611Snjl    /* First child is the region name */
588118611Snjl
589118611Snjl    Next = Op->Asl.Child;
590118611Snjl
591118611Snjl    /* Second child is the space ID*/
592118611Snjl
593118611Snjl    Next = Next->Asl.Next;
594118611Snjl
595118611Snjl    /* Third child is the region offset */
596118611Snjl
597118611Snjl    Next = Next->Asl.Next;
598118611Snjl
599118611Snjl    /* Fourth child is the region length */
600118611Snjl
601118611Snjl    Next = Next->Asl.Next;
602118611Snjl    if (Next->Asl.ParseOpcode == PARSEOP_INTEGER)
603118611Snjl    {
604118611Snjl        Op->Asl.Value.Integer = Next->Asl.Value.Integer;
605118611Snjl    }
606118611Snjl    else
607118611Snjl    {
608118611Snjl        Op->Asl.Value.Integer = ACPI_INTEGER_MAX;
609118611Snjl    }
610118611Snjl}
611118611Snjl
612118611Snjl
613118611Snjl/*******************************************************************************
614118611Snjl *
615118611Snjl * FUNCTION:    OpnDoBuffer
616118611Snjl *
617118611Snjl * PARAMETERS:  Op        - The parent parse node
618118611Snjl *
619118611Snjl * RETURN:      None
620118611Snjl *
621118611Snjl * DESCRIPTION: Construct the AML operands for the BUFFER ASL keyword.  We
622118611Snjl *              build a single raw byte buffer from the initialization nodes,
623118611Snjl *              each parse node contains a buffer byte.
624118611Snjl *
625118611Snjl ******************************************************************************/
626118611Snjl
627151937Sjkimstatic void
628118611SnjlOpnDoBuffer (
629118611Snjl    ACPI_PARSE_OBJECT       *Op)
630118611Snjl{
631118611Snjl    ACPI_PARSE_OBJECT       *InitializerOp;
632118611Snjl    ACPI_PARSE_OBJECT       *BufferLengthOp;
633118611Snjl
634118611Snjl    /* Optional arguments for this opcode with defaults */
635118611Snjl
636118611Snjl    UINT32                  BufferLength = 0;
637118611Snjl
638118611Snjl
639118611Snjl    /* Opcode and package length first */
640118611Snjl    /* Buffer Length is next, followed by the initializer list */
641118611Snjl
642118611Snjl    BufferLengthOp = Op->Asl.Child;
643118611Snjl    InitializerOp = BufferLengthOp->Asl.Next;
644118611Snjl
645118611Snjl    /*
646118611Snjl     * If the BufferLength is not an INTEGER or was not specified in the ASL
647118611Snjl     * (DEFAULT_ARG), it is a TermArg that is
648118611Snjl     * evaluated at run-time, and we are therefore finished.
649118611Snjl     */
650118611Snjl    if ((BufferLengthOp->Asl.ParseOpcode != PARSEOP_INTEGER) &&
651118611Snjl        (BufferLengthOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))
652118611Snjl    {
653118611Snjl        return;
654118611Snjl    }
655118611Snjl
656118611Snjl    /*
657118611Snjl     * We want to count the number of items in the initializer list, because if
658118611Snjl     * it is larger than the buffer length, we will define the buffer size
659118611Snjl     * to be the size of the initializer list (as per the ACPI Specification)
660118611Snjl     */
661118611Snjl    switch (InitializerOp->Asl.ParseOpcode)
662118611Snjl    {
663118611Snjl    case PARSEOP_INTEGER:
664118611Snjl    case PARSEOP_BYTECONST:
665118611Snjl    case PARSEOP_WORDCONST:
666118611Snjl    case PARSEOP_DWORDCONST:
667118611Snjl
668118611Snjl        /* The peer list contains the byte list (if any...) */
669118611Snjl
670118611Snjl        while (InitializerOp)
671118611Snjl        {
672118611Snjl            /* For buffers, this is a list of raw bytes */
673118611Snjl
674118611Snjl            InitializerOp->Asl.AmlOpcode      = AML_RAW_DATA_BYTE;
675118611Snjl            InitializerOp->Asl.AmlLength      = 1;
676118611Snjl            InitializerOp->Asl.ParseOpcode    = PARSEOP_RAW_DATA;
677118611Snjl
678118611Snjl            BufferLength++;
679118611Snjl            InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
680118611Snjl        }
681118611Snjl        break;
682118611Snjl
683118611Snjl
684118611Snjl    case PARSEOP_STRING_LITERAL:
685118611Snjl
686118611Snjl        /*
687118611Snjl         * Only one initializer, the string.  Buffer must be big enough to hold
688118611Snjl         * the string plus the null termination byte
689118611Snjl         */
690118611Snjl        BufferLength = strlen (InitializerOp->Asl.Value.String) + 1;
691118611Snjl
692118611Snjl        InitializerOp->Asl.AmlOpcode      = AML_RAW_DATA_BUFFER;
693118611Snjl        InitializerOp->Asl.AmlLength      = BufferLength;
694118611Snjl        InitializerOp->Asl.ParseOpcode    = PARSEOP_RAW_DATA;
695118611Snjl        break;
696118611Snjl
697118611Snjl
698118611Snjl    case PARSEOP_RAW_DATA:
699118611Snjl
700118611Snjl        /* Buffer nodes are already initialized (e.g. Unicode operator) */
701118611Snjl        return;
702118611Snjl
703118611Snjl
704118611Snjl    case PARSEOP_DEFAULT_ARG:
705118611Snjl        break;
706118611Snjl
707118611Snjl
708118611Snjl    default:
709118611Snjl        AslError (ASL_ERROR, ASL_MSG_INVALID_OPERAND, InitializerOp,
710118611Snjl            "Unknown buffer initializer opcode");
711118611Snjl        printf ("Unknown buffer initializer opcode [%s]\n",
712118611Snjl                        UtGetOpName (InitializerOp->Asl.ParseOpcode));
713118611Snjl        return;
714118611Snjl    }
715118611Snjl
716118611Snjl    /* Check if initializer list is longer than the buffer length */
717118611Snjl
718118611Snjl    if (BufferLengthOp->Asl.Value.Integer > BufferLength)
719118611Snjl    {
720118611Snjl        BufferLength = (UINT32) BufferLengthOp->Asl.Value.Integer;
721118611Snjl    }
722118611Snjl
723118611Snjl    if (!BufferLength)
724118611Snjl    {
725151937Sjkim        /* No length AND no items -- issue notice */
726118611Snjl
727151937Sjkim        AslError (ASL_REMARK, ASL_MSG_BUFFER_LENGTH, BufferLengthOp, NULL);
728118611Snjl
729118611Snjl        /* But go ahead and put the buffer length of zero into the AML */
730118611Snjl    }
731118611Snjl
732118611Snjl    /*
733118611Snjl     * Just set the buffer size node to be the buffer length, regardless
734118611Snjl     * of whether it was previously an integer or a default_arg placeholder
735118611Snjl     */
736118611Snjl    BufferLengthOp->Asl.ParseOpcode   = PARSEOP_INTEGER;
737118611Snjl    BufferLengthOp->Asl.AmlOpcode     = AML_DWORD_OP;
738118611Snjl    BufferLengthOp->Asl.Value.Integer = BufferLength;
739118611Snjl
740118611Snjl    (void) OpcSetOptimalIntegerSize (BufferLengthOp);
741118611Snjl
742118611Snjl    /* Remaining nodes are handled via the tree walk */
743118611Snjl}
744118611Snjl
745118611Snjl
746118611Snjl/*******************************************************************************
747118611Snjl *
748118611Snjl * FUNCTION:    OpnDoPackage
749118611Snjl *
750118611Snjl * PARAMETERS:  Op        - The parent parse node
751118611Snjl *
752118611Snjl * RETURN:      None
753118611Snjl *
754151937Sjkim * DESCRIPTION: Construct the AML operands for the PACKAGE ASL keyword.  NOTE:
755151937Sjkim *              can only be called after constants have been folded, to ensure
756151937Sjkim *              that the PackageLength operand has been fully reduced.
757118611Snjl *
758118611Snjl ******************************************************************************/
759118611Snjl
760118611Snjlvoid
761118611SnjlOpnDoPackage (
762118611Snjl    ACPI_PARSE_OBJECT       *Op)
763118611Snjl{
764118611Snjl    ACPI_PARSE_OBJECT       *InitializerOp;
765118611Snjl    ACPI_PARSE_OBJECT       *PackageLengthOp;
766151937Sjkim    UINT32                  PackageLength = 0;
767118611Snjl
768118611Snjl
769151937Sjkim    /* Opcode and package length first, followed by the initializer list */
770118611Snjl
771118611Snjl    PackageLengthOp = Op->Asl.Child;
772118611Snjl    InitializerOp = PackageLengthOp->Asl.Next;
773118611Snjl
774151937Sjkim    /* Count the number of items in the initializer list */
775151937Sjkim
776118611Snjl    if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
777118611Snjl    {
778118611Snjl        /* The peer list contains the byte list (if any...) */
779118611Snjl
780118611Snjl        while (InitializerOp)
781118611Snjl        {
782118611Snjl            PackageLength++;
783118611Snjl            InitializerOp = InitializerOp->Asl.Next;
784118611Snjl        }
785118611Snjl    }
786118611Snjl
787151937Sjkim    /* If package length is a constant, compare to the initializer list */
788118611Snjl
789118611Snjl    if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER)      ||
790151937Sjkim        (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST))
791118611Snjl    {
792151937Sjkim        if (PackageLengthOp->Asl.Value.Integer >= PackageLength)
793118611Snjl        {
794151937Sjkim            /* Allow package to be longer than the initializer list */
795151937Sjkim
796118611Snjl            PackageLength = (UINT32) PackageLengthOp->Asl.Value.Integer;
797118611Snjl        }
798151937Sjkim        else
799151937Sjkim        {
800151937Sjkim            /*
801151937Sjkim             * Initializer list is longer than the package length. This
802151937Sjkim             * is an error as per the ACPI spec.
803151937Sjkim             */
804151937Sjkim            AslError (ASL_ERROR, ASL_MSG_LIST_LENGTH,
805151937Sjkim                PackageLengthOp->Asl.Next, NULL);
806151937Sjkim        }
807118611Snjl    }
808118611Snjl
809151937Sjkim    if (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
810151937Sjkim    {
811151937Sjkim        /*
812151937Sjkim         * This is the case if the PackageLength was left empty - Package()
813151937Sjkim         * The package length becomes the length of the initializer list
814151937Sjkim         */
815151937Sjkim        Op->Asl.Child->Asl.ParseOpcode = PARSEOP_INTEGER;
816151937Sjkim        Op->Asl.Child->Asl.Value.Integer = PackageLength;
817151937Sjkim
818151937Sjkim        /* Set the AML opcode */
819151937Sjkim
820151937Sjkim        (void) OpcSetOptimalIntegerSize (Op->Asl.Child);
821151937Sjkim    }
822151937Sjkim
823151937Sjkim    /* If not a variable-length package, check for a zero package length */
824151937Sjkim
825118611Snjl    if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER)      ||
826151937Sjkim        (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST)   ||
827118611Snjl        (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG))
828118611Snjl    {
829118611Snjl        if (!PackageLength)
830118611Snjl        {
831151937Sjkim            /* No length AND no initializer list -- issue a remark */
832118611Snjl
833151937Sjkim            AslError (ASL_REMARK, ASL_MSG_PACKAGE_LENGTH,
834151937Sjkim                PackageLengthOp, NULL);
835118611Snjl
836118611Snjl            /* But go ahead and put the buffer length of zero into the AML */
837118611Snjl        }
838118611Snjl    }
839118611Snjl
840118611Snjl    /*
841151937Sjkim     * If the PackageLength is a constant <= 255, we can change the
842151937Sjkim     * AML opcode from VarPackage to a simple (ACPI 1.0) Package opcode.
843118611Snjl     */
844151937Sjkim    if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) &&
845151937Sjkim        (Op->Asl.Child->Asl.Value.Integer <= 255))
846151937Sjkim    {
847151937Sjkim        Op->Asl.AmlOpcode = AML_PACKAGE_OP;
848151937Sjkim        Op->Asl.ParseOpcode = PARSEOP_PACKAGE;
849118611Snjl
850151937Sjkim        /*
851151937Sjkim         * Just set the package size node to be the package length, regardless
852151937Sjkim         * of whether it was previously an integer or a default_arg placeholder
853151937Sjkim         */
854151937Sjkim        PackageLengthOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE;
855151937Sjkim        PackageLengthOp->Asl.AmlLength = 1;
856151937Sjkim        PackageLengthOp->Asl.ParseOpcode = PARSEOP_RAW_DATA;
857151937Sjkim        PackageLengthOp->Asl.Value.Integer = PackageLength;
858151937Sjkim    }
859151937Sjkim
860118611Snjl    /* Remaining nodes are handled via the tree walk */
861118611Snjl}
862118611Snjl
863118611Snjl
864118611Snjl/*******************************************************************************
865118611Snjl *
866118611Snjl * FUNCTION:    OpnDoLoadTable
867118611Snjl *
868118611Snjl * PARAMETERS:  Op        - The parent parse node
869118611Snjl *
870118611Snjl * RETURN:      None
871118611Snjl *
872118611Snjl * DESCRIPTION: Construct the AML operands for the LOADTABLE ASL keyword.
873118611Snjl *
874118611Snjl ******************************************************************************/
875118611Snjl
876151937Sjkimstatic void
877118611SnjlOpnDoLoadTable (
878118611Snjl    ACPI_PARSE_OBJECT       *Op)
879118611Snjl{
880118611Snjl    ACPI_PARSE_OBJECT       *Next;
881118611Snjl
882118611Snjl
883118611Snjl    /* Opcode is parent node */
884118611Snjl    /* First child is the table signature */
885118611Snjl
886118611Snjl    Next = Op->Asl.Child;
887118611Snjl
888118611Snjl    /* Second child is the OEM ID*/
889118611Snjl
890118611Snjl    Next = Next->Asl.Next;
891118611Snjl
892118611Snjl    /* Third child is the OEM table ID */
893118611Snjl
894118611Snjl    Next = Next->Asl.Next;
895118611Snjl
896118611Snjl    /* Fourth child is the RootPath string */
897118611Snjl
898118611Snjl    Next = Next->Asl.Next;
899118611Snjl    if (Next->Asl.ParseOpcode == PARSEOP_ZERO)
900118611Snjl    {
901118611Snjl        Next->Asl.ParseOpcode    = PARSEOP_STRING_LITERAL;
902118611Snjl        Next->Asl.Value.String   = "\\";
903118611Snjl        Next->Asl.AmlLength      = 2;
904118611Snjl        OpcGenerateAmlOpcode (Next);
905118611Snjl    }
906118611Snjl
907151937Sjkim#ifdef ASL_FUTURE_IMPLEMENTATION
908151937Sjkim
909151937Sjkim    /* TBD: NOT IMPLEMENTED */
910118611Snjl    /* Fifth child is the [optional] ParameterPathString */
911118611Snjl    /* Sixth child is the [optional] ParameterData */
912118611Snjl
913118611Snjl    Next = Next->Asl.Next;
914118611Snjl    if (Next->Asl.ParseOpcode == DEFAULT_ARG)
915118611Snjl    {
916118611Snjl        Next->Asl.AmlLength = 1;
917118611Snjl        Next->Asl.ParseOpcode = ZERO;
918118611Snjl        OpcGenerateAmlOpcode (Next);
919118611Snjl    }
920118611Snjl
921118611Snjl
922118611Snjl    Next = Next->Asl.Next;
923118611Snjl    if (Next->Asl.ParseOpcode == DEFAULT_ARG)
924118611Snjl    {
925118611Snjl        Next->Asl.AmlLength = 1;
926118611Snjl        Next->Asl.ParseOpcode = ZERO;
927118611Snjl        OpcGenerateAmlOpcode (Next);
928118611Snjl    }
929151937Sjkim#endif
930118611Snjl}
931118611Snjl
932118611Snjl
933118611Snjl/*******************************************************************************
934118611Snjl *
935118611Snjl * FUNCTION:    OpnDoDefinitionBlock
936118611Snjl *
937118611Snjl * PARAMETERS:  Op        - The parent parse node
938118611Snjl *
939118611Snjl * RETURN:      None
940118611Snjl *
941118611Snjl * DESCRIPTION: Construct the AML operands for the DEFINITIONBLOCK ASL keyword
942118611Snjl *
943118611Snjl ******************************************************************************/
944118611Snjl
945151937Sjkimstatic void
946118611SnjlOpnDoDefinitionBlock (
947118611Snjl    ACPI_PARSE_OBJECT       *Op)
948118611Snjl{
949118611Snjl    ACPI_PARSE_OBJECT       *Child;
950118611Snjl    ACPI_SIZE               Length;
951118611Snjl    ACPI_NATIVE_UINT        i;
952118611Snjl
953118611Snjl
954118611Snjl    /*
955118611Snjl     * These nodes get stuffed into the table header.  They are special
956118611Snjl     * cased when the table is written to the output file.
957118611Snjl     *
958118611Snjl     * Mark all of these nodes as non-usable so they won't get output
959118611Snjl     * as AML opcodes!
960118611Snjl     */
961118611Snjl
962167802Sjkim    /* Get AML filename. Use it if non-null */
963118611Snjl
964118611Snjl    Child = Op->Asl.Child;
965167802Sjkim    if (Child->Asl.Value.Buffer  &&
966167802Sjkim        *Child->Asl.Value.Buffer &&
967167802Sjkim        (Gbl_UseDefaultAmlFilename))
968118611Snjl    {
969118611Snjl        Gbl_OutputFilenamePrefix = (char *) Child->Asl.Value.Buffer;
970118611Snjl    }
971118611Snjl    Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
972118611Snjl
973118611Snjl    /* Signature */
974118611Snjl
975118611Snjl    Child = Child->Asl.Next;
976118611Snjl    Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
977118611Snjl    if (Child->Asl.Value.String)
978118611Snjl    {
979118611Snjl        Gbl_TableSignature = Child->Asl.Value.String;
980118611Snjl        if (ACPI_STRLEN (Gbl_TableSignature) != 4)
981118611Snjl        {
982151937Sjkim            AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
983151937Sjkim                "Length not exactly 4");
984118611Snjl        }
985118611Snjl
986118611Snjl        for (i = 0; i < 4; i++)
987118611Snjl        {
988118611Snjl            if (!isalnum (Gbl_TableSignature[i]))
989118611Snjl            {
990151937Sjkim                AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child,
991151937Sjkim                    "Contains non-alphanumeric characters");
992118611Snjl            }
993118611Snjl        }
994118611Snjl    }
995118611Snjl
996118611Snjl    /* Revision */
997118611Snjl
998118611Snjl    Child = Child->Asl.Next;
999118611Snjl    Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1000167802Sjkim    /*
1001167802Sjkim     * We used the revision to set the integer width earlier
1002167802Sjkim     */
1003118611Snjl
1004118611Snjl    /* OEMID */
1005118611Snjl
1006118611Snjl    Child = Child->Asl.Next;
1007118611Snjl    Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1008118611Snjl
1009118611Snjl    /* OEM TableID */
1010118611Snjl
1011118611Snjl    Child = Child->Asl.Next;
1012118611Snjl    Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1013118611Snjl    if (Child->Asl.Value.String)
1014118611Snjl    {
1015118611Snjl        Length = ACPI_STRLEN (Child->Asl.Value.String);
1016118611Snjl        Gbl_TableId = AcpiOsAllocate (Length + 1);
1017118611Snjl        ACPI_STRCPY (Gbl_TableId, Child->Asl.Value.String);
1018118611Snjl
1019118611Snjl        for (i = 0; i < Length; i++)
1020118611Snjl        {
1021118611Snjl            if (Gbl_TableId[i] == ' ')
1022118611Snjl            {
1023118611Snjl                Gbl_TableId[i] = 0;
1024118611Snjl                break;
1025118611Snjl            }
1026118611Snjl        }
1027118611Snjl    }
1028118611Snjl
1029118611Snjl    /* OEM Revision */
1030118611Snjl
1031118611Snjl    Child = Child->Asl.Next;
1032118611Snjl    Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
1033118611Snjl}
1034118611Snjl
1035118611Snjl
1036118611Snjl/*******************************************************************************
1037118611Snjl *
1038118611Snjl * FUNCTION:    UtGetArg
1039118611Snjl *
1040118611Snjl * PARAMETERS:  Op              - Get an argument for this op
1041118611Snjl *              Argn            - Nth argument to get
1042118611Snjl *
1043118611Snjl * RETURN:      The argument (as an Op object).  NULL if argument does not exist
1044118611Snjl *
1045118611Snjl * DESCRIPTION: Get the specified op's argument (peer)
1046118611Snjl *
1047118611Snjl ******************************************************************************/
1048118611Snjl
1049118611SnjlACPI_PARSE_OBJECT *
1050118611SnjlUtGetArg (
1051118611Snjl    ACPI_PARSE_OBJECT       *Op,
1052118611Snjl    UINT32                  Argn)
1053118611Snjl{
1054118611Snjl    ACPI_PARSE_OBJECT       *Arg = NULL;
1055118611Snjl
1056118611Snjl
1057118611Snjl    /* Get the requested argument object */
1058118611Snjl
1059118611Snjl    Arg = Op->Asl.Child;
1060118611Snjl    while (Arg && Argn)
1061118611Snjl    {
1062118611Snjl        Argn--;
1063118611Snjl        Arg = Arg->Asl.Next;
1064118611Snjl    }
1065118611Snjl
1066118611Snjl    return (Arg);
1067118611Snjl}
1068118611Snjl
1069118611Snjl
1070118611Snjl/*******************************************************************************
1071118611Snjl *
1072118611Snjl * FUNCTION:    OpnAttachNameToNode
1073118611Snjl *
1074118611Snjl * PARAMETERS:  Op        - The parent parse node
1075118611Snjl *
1076118611Snjl * RETURN:      None
1077118611Snjl *
1078118611Snjl * DESCRIPTION: For the named ASL/AML operators, get the actual name from the
1079118611Snjl *              argument list and attach it to the parent node so that we
1080118611Snjl *              can get to it quickly later.
1081118611Snjl *
1082118611Snjl ******************************************************************************/
1083118611Snjl
1084151937Sjkimstatic void
1085118611SnjlOpnAttachNameToNode (
1086118611Snjl    ACPI_PARSE_OBJECT       *Op)
1087118611Snjl{
1088118611Snjl    ACPI_PARSE_OBJECT       *Child = NULL;
1089118611Snjl
1090118611Snjl
1091118611Snjl    if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)
1092118611Snjl    {
1093118611Snjl        Child = UtGetArg (Op, 0);
1094118611Snjl    }
1095118611Snjl    else switch (Op->Asl.AmlOpcode)
1096118611Snjl    {
1097118611Snjl    case AML_DATA_REGION_OP:
1098118611Snjl    case AML_DEVICE_OP:
1099118611Snjl    case AML_EVENT_OP:
1100118611Snjl    case AML_METHOD_OP:
1101118611Snjl    case AML_MUTEX_OP:
1102118611Snjl    case AML_REGION_OP:
1103118611Snjl    case AML_POWER_RES_OP:
1104118611Snjl    case AML_PROCESSOR_OP:
1105118611Snjl    case AML_THERMAL_ZONE_OP:
1106118611Snjl    case AML_NAME_OP:
1107118611Snjl    case AML_SCOPE_OP:
1108118611Snjl
1109118611Snjl        Child = UtGetArg (Op, 0);
1110118611Snjl        break;
1111118611Snjl
1112118611Snjl    case AML_ALIAS_OP:
1113118611Snjl
1114118611Snjl        Child = UtGetArg (Op, 1);
1115118611Snjl        break;
1116118611Snjl
1117118611Snjl    case AML_CREATE_BIT_FIELD_OP:
1118118611Snjl    case AML_CREATE_BYTE_FIELD_OP:
1119118611Snjl    case AML_CREATE_WORD_FIELD_OP:
1120118611Snjl    case AML_CREATE_DWORD_FIELD_OP:
1121118611Snjl    case AML_CREATE_QWORD_FIELD_OP:
1122118611Snjl
1123118611Snjl        Child = UtGetArg (Op, 2);
1124118611Snjl        break;
1125118611Snjl
1126118611Snjl    case AML_CREATE_FIELD_OP:
1127118611Snjl
1128118611Snjl        Child = UtGetArg (Op, 3);
1129118611Snjl        break;
1130118611Snjl
1131118611Snjl    case AML_BANK_FIELD_OP:
1132118611Snjl    case AML_INDEX_FIELD_OP:
1133118611Snjl    case AML_FIELD_OP:
1134118611Snjl
1135118611Snjl        return;
1136118611Snjl
1137118611Snjl    default:
1138118611Snjl        return;
1139118611Snjl    }
1140118611Snjl
1141118611Snjl    if (Child)
1142118611Snjl    {
1143118611Snjl        UtAttachNamepathToOwner (Op, Child);
1144118611Snjl    }
1145118611Snjl}
1146118611Snjl
1147118611Snjl
1148118611Snjl/*******************************************************************************
1149118611Snjl *
1150118611Snjl * FUNCTION:    OpnGenerateAmlOperands
1151118611Snjl *
1152118611Snjl * PARAMETERS:  Op        - The parent parse node
1153118611Snjl *
1154118611Snjl * RETURN:      None
1155118611Snjl *
1156118611Snjl * DESCRIPTION: Prepare nodes to be output as AML data and operands.  The more
1157118611Snjl *              complex AML opcodes require processing of the child nodes
1158118611Snjl *              (arguments/operands).
1159118611Snjl *
1160118611Snjl ******************************************************************************/
1161118611Snjl
1162118611Snjlvoid
1163118611SnjlOpnGenerateAmlOperands (
1164118611Snjl    ACPI_PARSE_OBJECT       *Op)
1165118611Snjl{
1166118611Snjl
1167118611Snjl
1168118611Snjl    if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE)
1169118611Snjl    {
1170118611Snjl        return;
1171118611Snjl    }
1172118611Snjl
1173118611Snjl    switch (Op->Asl.ParseOpcode)
1174118611Snjl    {
1175118611Snjl    case PARSEOP_DEFINITIONBLOCK:
1176118611Snjl        OpnDoDefinitionBlock (Op);
1177118611Snjl        break;
1178118611Snjl
1179118611Snjl    case PARSEOP_METHOD:
1180118611Snjl        OpnDoMethod (Op);
1181118611Snjl        break;
1182118611Snjl
1183151937Sjkim    case PARSEOP_MUTEX:
1184151937Sjkim        OpnDoMutex (Op);
1185151937Sjkim        break;
1186151937Sjkim
1187118611Snjl    case PARSEOP_FIELD:
1188118611Snjl        OpnDoField (Op);
1189118611Snjl        break;
1190118611Snjl
1191118611Snjl    case PARSEOP_INDEXFIELD:
1192118611Snjl        OpnDoIndexField (Op);
1193118611Snjl        break;
1194118611Snjl
1195118611Snjl    case PARSEOP_BANKFIELD:
1196118611Snjl        OpnDoBankField (Op);
1197118611Snjl        break;
1198118611Snjl
1199118611Snjl    case PARSEOP_BUFFER:
1200118611Snjl        OpnDoBuffer (Op);
1201118611Snjl        break;
1202118611Snjl
1203118611Snjl    case PARSEOP_LOADTABLE:
1204118611Snjl        OpnDoLoadTable (Op);
1205118611Snjl        break;
1206118611Snjl
1207118611Snjl    case PARSEOP_OPERATIONREGION:
1208118611Snjl        OpnDoRegion (Op);
1209118611Snjl        break;
1210118611Snjl
1211118611Snjl    case PARSEOP_RESOURCETEMPLATE:
1212118611Snjl        RsDoResourceTemplate (Op);
1213118611Snjl        break;
1214118611Snjl
1215118611Snjl    case PARSEOP_NAMESEG:
1216118611Snjl    case PARSEOP_NAMESTRING:
1217118611Snjl    case PARSEOP_METHODCALL:
1218118611Snjl    case PARSEOP_STRING_LITERAL:
1219118611Snjl        break;
1220118611Snjl
1221118611Snjl    default:
1222118611Snjl        break;
1223118611Snjl    }
1224118611Snjl
1225118611Snjl    /* TBD: move */
1226118611Snjl
1227118611Snjl    OpnAttachNameToNode (Op);
1228118611Snjl}
1229118611Snjl
1230118611Snjl
1231