dsobject.c revision 1.1.1.1
1/******************************************************************************
2 *
3 * Module Name: dsobject - Dispatcher object management routines
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights.  You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code.  No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision.  In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change.  Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee.  Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution.  In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government.  In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************/
115
116#define __DSOBJECT_C__
117
118#include "acpi.h"
119#include "accommon.h"
120#include "acparser.h"
121#include "amlcode.h"
122#include "acdispat.h"
123#include "acnamesp.h"
124#include "acinterp.h"
125
126#define _COMPONENT          ACPI_DISPATCHER
127        ACPI_MODULE_NAME    ("dsobject")
128
129/* Local prototypes */
130
131static ACPI_STATUS
132AcpiDsBuildInternalObject (
133    ACPI_WALK_STATE         *WalkState,
134    ACPI_PARSE_OBJECT       *Op,
135    ACPI_OPERAND_OBJECT     **ObjDescPtr);
136
137
138#ifndef ACPI_NO_METHOD_EXECUTION
139/*******************************************************************************
140 *
141 * FUNCTION:    AcpiDsBuildInternalObject
142 *
143 * PARAMETERS:  WalkState       - Current walk state
144 *              Op              - Parser object to be translated
145 *              ObjDescPtr      - Where the ACPI internal object is returned
146 *
147 * RETURN:      Status
148 *
149 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
150 *              Simple objects are any objects other than a package object!
151 *
152 ******************************************************************************/
153
154static ACPI_STATUS
155AcpiDsBuildInternalObject (
156    ACPI_WALK_STATE         *WalkState,
157    ACPI_PARSE_OBJECT       *Op,
158    ACPI_OPERAND_OBJECT     **ObjDescPtr)
159{
160    ACPI_OPERAND_OBJECT     *ObjDesc;
161    ACPI_STATUS             Status;
162
163
164    ACPI_FUNCTION_TRACE (DsBuildInternalObject);
165
166
167    *ObjDescPtr = NULL;
168    if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
169    {
170        /*
171         * This is a named object reference. If this name was
172         * previously looked up in the namespace, it was stored in this op.
173         * Otherwise, go ahead and look it up now
174         */
175        if (!Op->Common.Node)
176        {
177            Status = AcpiNsLookup (WalkState->ScopeInfo,
178                        Op->Common.Value.String,
179                        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
180                        ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
181                        ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &(Op->Common.Node)));
182            if (ACPI_FAILURE (Status))
183            {
184                /* Check if we are resolving a named reference within a package */
185
186                if ((Status == AE_NOT_FOUND) && (AcpiGbl_EnableInterpreterSlack) &&
187
188                    ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
189                     (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
190                {
191                    /*
192                     * We didn't find the target and we are populating elements
193                     * of a package - ignore if slack enabled. Some ASL code
194                     * contains dangling invalid references in packages and
195                     * expects that no exception will be issued. Leave the
196                     * element as a null element. It cannot be used, but it
197                     * can be overwritten by subsequent ASL code - this is
198                     * typically the case.
199                     */
200                    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
201                        "Ignoring unresolved reference in package [%4.4s]\n",
202                        WalkState->ScopeInfo->Scope.Node->Name.Ascii));
203
204                    return_ACPI_STATUS (AE_OK);
205                }
206                else
207                {
208                    ACPI_ERROR_NAMESPACE (Op->Common.Value.String, Status);
209                }
210
211                return_ACPI_STATUS (Status);
212            }
213        }
214
215        /* Special object resolution for elements of a package */
216
217        if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
218            (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
219        {
220            /*
221             * Attempt to resolve the node to a value before we insert it into
222             * the package. If this is a reference to a common data type,
223             * resolve it immediately. According to the ACPI spec, package
224             * elements can only be "data objects" or method references.
225             * Attempt to resolve to an Integer, Buffer, String or Package.
226             * If cannot, return the named reference (for things like Devices,
227             * Methods, etc.) Buffer Fields and Fields will resolve to simple
228             * objects (int/buf/str/pkg).
229             *
230             * NOTE: References to things like Devices, Methods, Mutexes, etc.
231             * will remain as named references. This behavior is not described
232             * in the ACPI spec, but it appears to be an oversight.
233             */
234            ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Op->Common.Node);
235
236            Status = AcpiExResolveNodeToValue (
237                        ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc),
238                        WalkState);
239            if (ACPI_FAILURE (Status))
240            {
241                return_ACPI_STATUS (Status);
242            }
243
244            switch (Op->Common.Node->Type)
245            {
246            /*
247             * For these types, we need the actual node, not the subobject.
248             * However, the subobject did not get an extra reference count above.
249             *
250             * TBD: should ExResolveNodeToValue be changed to fix this?
251             */
252            case ACPI_TYPE_DEVICE:
253            case ACPI_TYPE_THERMAL:
254
255                AcpiUtAddReference (Op->Common.Node->Object);
256
257                /*lint -fallthrough */
258            /*
259             * For these types, we need the actual node, not the subobject.
260             * The subobject got an extra reference count in ExResolveNodeToValue.
261             */
262            case ACPI_TYPE_MUTEX:
263            case ACPI_TYPE_METHOD:
264            case ACPI_TYPE_POWER:
265            case ACPI_TYPE_PROCESSOR:
266            case ACPI_TYPE_EVENT:
267            case ACPI_TYPE_REGION:
268
269                /* We will create a reference object for these types below */
270                break;
271
272            default:
273                /*
274                 * All other types - the node was resolved to an actual
275                 * object, we are done.
276                 */
277                goto Exit;
278            }
279        }
280    }
281
282    /* Create and init a new internal ACPI object */
283
284    ObjDesc = AcpiUtCreateInternalObject (
285                (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType);
286    if (!ObjDesc)
287    {
288        return_ACPI_STATUS (AE_NO_MEMORY);
289    }
290
291    Status = AcpiDsInitObjectFromOp (WalkState, Op, Op->Common.AmlOpcode,
292                &ObjDesc);
293    if (ACPI_FAILURE (Status))
294    {
295        AcpiUtRemoveReference (ObjDesc);
296        return_ACPI_STATUS (Status);
297    }
298
299Exit:
300    *ObjDescPtr = ObjDesc;
301    return_ACPI_STATUS (Status);
302}
303
304
305/*******************************************************************************
306 *
307 * FUNCTION:    AcpiDsBuildInternalBufferObj
308 *
309 * PARAMETERS:  WalkState       - Current walk state
310 *              Op              - Parser object to be translated
311 *              BufferLength    - Length of the buffer
312 *              ObjDescPtr      - Where the ACPI internal object is returned
313 *
314 * RETURN:      Status
315 *
316 * DESCRIPTION: Translate a parser Op package object to the equivalent
317 *              namespace object
318 *
319 ******************************************************************************/
320
321ACPI_STATUS
322AcpiDsBuildInternalBufferObj (
323    ACPI_WALK_STATE         *WalkState,
324    ACPI_PARSE_OBJECT       *Op,
325    UINT32                  BufferLength,
326    ACPI_OPERAND_OBJECT     **ObjDescPtr)
327{
328    ACPI_PARSE_OBJECT       *Arg;
329    ACPI_OPERAND_OBJECT     *ObjDesc;
330    ACPI_PARSE_OBJECT       *ByteList;
331    UINT32                  ByteListLength = 0;
332
333
334    ACPI_FUNCTION_TRACE (DsBuildInternalBufferObj);
335
336
337    /*
338     * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
339     * The buffer object already exists (from the NS node), otherwise it must
340     * be created.
341     */
342    ObjDesc = *ObjDescPtr;
343    if (!ObjDesc)
344    {
345        /* Create a new buffer object */
346
347        ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
348        *ObjDescPtr = ObjDesc;
349        if (!ObjDesc)
350        {
351            return_ACPI_STATUS (AE_NO_MEMORY);
352        }
353    }
354
355    /*
356     * Second arg is the buffer data (optional) ByteList can be either
357     * individual bytes or a string initializer.  In either case, a
358     * ByteList appears in the AML.
359     */
360    Arg = Op->Common.Value.Arg;         /* skip first arg */
361
362    ByteList = Arg->Named.Next;
363    if (ByteList)
364    {
365        if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP)
366        {
367            ACPI_ERROR ((AE_INFO,
368                "Expecting bytelist, found AML opcode 0x%X in op %p",
369                ByteList->Common.AmlOpcode, ByteList));
370
371            AcpiUtRemoveReference (ObjDesc);
372            return (AE_TYPE);
373        }
374
375        ByteListLength = (UINT32) ByteList->Common.Value.Integer;
376    }
377
378    /*
379     * The buffer length (number of bytes) will be the larger of:
380     * 1) The specified buffer length and
381     * 2) The length of the initializer byte list
382     */
383    ObjDesc->Buffer.Length = BufferLength;
384    if (ByteListLength > BufferLength)
385    {
386        ObjDesc->Buffer.Length = ByteListLength;
387    }
388
389    /* Allocate the buffer */
390
391    if (ObjDesc->Buffer.Length == 0)
392    {
393        ObjDesc->Buffer.Pointer = NULL;
394        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
395            "Buffer defined with zero length in AML, creating\n"));
396    }
397    else
398    {
399        ObjDesc->Buffer.Pointer = ACPI_ALLOCATE_ZEROED (
400                                        ObjDesc->Buffer.Length);
401        if (!ObjDesc->Buffer.Pointer)
402        {
403            AcpiUtDeleteObjectDesc (ObjDesc);
404            return_ACPI_STATUS (AE_NO_MEMORY);
405        }
406
407        /* Initialize buffer from the ByteList (if present) */
408
409        if (ByteList)
410        {
411            ACPI_MEMCPY (ObjDesc->Buffer.Pointer, ByteList->Named.Data,
412                         ByteListLength);
413        }
414    }
415
416    ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
417    Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
418    return_ACPI_STATUS (AE_OK);
419}
420
421
422/*******************************************************************************
423 *
424 * FUNCTION:    AcpiDsBuildInternalPackageObj
425 *
426 * PARAMETERS:  WalkState       - Current walk state
427 *              Op              - Parser object to be translated
428 *              ElementCount    - Number of elements in the package - this is
429 *                                the NumElements argument to Package()
430 *              ObjDescPtr      - Where the ACPI internal object is returned
431 *
432 * RETURN:      Status
433 *
434 * DESCRIPTION: Translate a parser Op package object to the equivalent
435 *              namespace object
436 *
437 * NOTE: The number of elements in the package will be always be the NumElements
438 * count, regardless of the number of elements in the package list. If
439 * NumElements is smaller, only that many package list elements are used.
440 * if NumElements is larger, the Package object is padded out with
441 * objects of type Uninitialized (as per ACPI spec.)
442 *
443 * Even though the ASL compilers do not allow NumElements to be smaller
444 * than the Package list length (for the fixed length package opcode), some
445 * BIOS code modifies the AML on the fly to adjust the NumElements, and
446 * this code compensates for that. This also provides compatibility with
447 * other AML interpreters.
448 *
449 ******************************************************************************/
450
451ACPI_STATUS
452AcpiDsBuildInternalPackageObj (
453    ACPI_WALK_STATE         *WalkState,
454    ACPI_PARSE_OBJECT       *Op,
455    UINT32                  ElementCount,
456    ACPI_OPERAND_OBJECT     **ObjDescPtr)
457{
458    ACPI_PARSE_OBJECT       *Arg;
459    ACPI_PARSE_OBJECT       *Parent;
460    ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
461    ACPI_STATUS             Status = AE_OK;
462    UINT32                  i;
463    UINT16                  Index;
464    UINT16                  ReferenceCount;
465
466
467    ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
468
469
470    /* Find the parent of a possibly nested package */
471
472    Parent = Op->Common.Parent;
473    while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
474           (Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
475    {
476        Parent = Parent->Common.Parent;
477    }
478
479    /*
480     * If we are evaluating a Named package object "Name (xxxx, Package)",
481     * the package object already exists, otherwise it must be created.
482     */
483    ObjDesc = *ObjDescPtr;
484    if (!ObjDesc)
485    {
486        ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
487        *ObjDescPtr = ObjDesc;
488        if (!ObjDesc)
489        {
490            return_ACPI_STATUS (AE_NO_MEMORY);
491        }
492
493        ObjDesc->Package.Node = Parent->Common.Node;
494    }
495
496    /*
497     * Allocate the element array (array of pointers to the individual
498     * objects) based on the NumElements parameter. Add an extra pointer slot
499     * so that the list is always null terminated.
500     */
501    ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
502        ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
503
504    if (!ObjDesc->Package.Elements)
505    {
506        AcpiUtDeleteObjectDesc (ObjDesc);
507        return_ACPI_STATUS (AE_NO_MEMORY);
508    }
509
510    ObjDesc->Package.Count = ElementCount;
511
512    /*
513     * Initialize the elements of the package, up to the NumElements count.
514     * Package is automatically padded with uninitialized (NULL) elements
515     * if NumElements is greater than the package list length. Likewise,
516     * Package is truncated if NumElements is less than the list length.
517     */
518    Arg = Op->Common.Value.Arg;
519    Arg = Arg->Common.Next;
520    for (i = 0; Arg && (i < ElementCount); i++)
521    {
522        if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
523        {
524            if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
525            {
526                /*
527                 * A method reference "looks" to the parser to be a method
528                 * invocation, so we special case it here
529                 */
530                Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
531                Status = AcpiDsBuildInternalObject (WalkState, Arg,
532                            &ObjDesc->Package.Elements[i]);
533            }
534            else
535            {
536                /* This package element is already built, just get it */
537
538                ObjDesc->Package.Elements[i] =
539                    ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
540            }
541        }
542        else
543        {
544            Status = AcpiDsBuildInternalObject (WalkState, Arg,
545                        &ObjDesc->Package.Elements[i]);
546        }
547
548        if (*ObjDescPtr)
549        {
550            /* Existing package, get existing reference count */
551
552            ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
553            if (ReferenceCount > 1)
554            {
555                /* Make new element ref count match original ref count */
556
557                for (Index = 0; Index < (ReferenceCount - 1); Index++)
558                {
559                    AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
560                }
561            }
562        }
563
564        Arg = Arg->Common.Next;
565    }
566
567    /* Check for match between NumElements and actual length of PackageList */
568
569    if (Arg)
570    {
571        /*
572         * NumElements was exhausted, but there are remaining elements in the
573         * PackageList. Truncate the package to NumElements.
574         *
575         * Note: technically, this is an error, from ACPI spec: "It is an error
576         * for NumElements to be less than the number of elements in the
577         * PackageList". However, we just print a message and
578         * no exception is returned. This provides Windows compatibility. Some
579         * BIOSs will alter the NumElements on the fly, creating this type
580         * of ill-formed package object.
581         */
582        while (Arg)
583        {
584            /*
585             * We must delete any package elements that were created earlier
586             * and are not going to be used because of the package truncation.
587             */
588            if (Arg->Common.Node)
589            {
590                AcpiUtRemoveReference (
591                    ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
592                Arg->Common.Node = NULL;
593            }
594
595            /* Find out how many elements there really are */
596
597            i++;
598            Arg = Arg->Common.Next;
599        }
600
601        ACPI_INFO ((AE_INFO,
602            "Actual Package length (%u) is larger than NumElements field (%u), truncated\n",
603            i, ElementCount));
604    }
605    else if (i < ElementCount)
606    {
607        /*
608         * Arg list (elements) was exhausted, but we did not reach NumElements count.
609         * Note: this is not an error, the package is padded out with NULLs.
610         */
611        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
612            "Package List length (%u) smaller than NumElements count (%u), padded with null elements\n",
613            i, ElementCount));
614    }
615
616    ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
617    Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
618    return_ACPI_STATUS (Status);
619}
620
621
622/*******************************************************************************
623 *
624 * FUNCTION:    AcpiDsCreateNode
625 *
626 * PARAMETERS:  WalkState       - Current walk state
627 *              Node            - NS Node to be initialized
628 *              Op              - Parser object to be translated
629 *
630 * RETURN:      Status
631 *
632 * DESCRIPTION: Create the object to be associated with a namespace node
633 *
634 ******************************************************************************/
635
636ACPI_STATUS
637AcpiDsCreateNode (
638    ACPI_WALK_STATE         *WalkState,
639    ACPI_NAMESPACE_NODE     *Node,
640    ACPI_PARSE_OBJECT       *Op)
641{
642    ACPI_STATUS             Status;
643    ACPI_OPERAND_OBJECT     *ObjDesc;
644
645
646    ACPI_FUNCTION_TRACE_PTR (DsCreateNode, Op);
647
648
649    /*
650     * Because of the execution pass through the non-control-method
651     * parts of the table, we can arrive here twice.  Only init
652     * the named object node the first time through
653     */
654    if (AcpiNsGetAttachedObject (Node))
655    {
656        return_ACPI_STATUS (AE_OK);
657    }
658
659    if (!Op->Common.Value.Arg)
660    {
661        /* No arguments, there is nothing to do */
662
663        return_ACPI_STATUS (AE_OK);
664    }
665
666    /* Build an internal object for the argument(s) */
667
668    Status = AcpiDsBuildInternalObject (WalkState, Op->Common.Value.Arg,
669                &ObjDesc);
670    if (ACPI_FAILURE (Status))
671    {
672        return_ACPI_STATUS (Status);
673    }
674
675    /* Re-type the object according to its argument */
676
677    Node->Type = ObjDesc->Common.Type;
678
679    /* Attach obj to node */
680
681    Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type);
682
683    /* Remove local reference to the object */
684
685    AcpiUtRemoveReference (ObjDesc);
686    return_ACPI_STATUS (Status);
687}
688
689#endif /* ACPI_NO_METHOD_EXECUTION */
690
691
692/*******************************************************************************
693 *
694 * FUNCTION:    AcpiDsInitObjectFromOp
695 *
696 * PARAMETERS:  WalkState       - Current walk state
697 *              Op              - Parser op used to init the internal object
698 *              Opcode          - AML opcode associated with the object
699 *              RetObjDesc      - Namespace object to be initialized
700 *
701 * RETURN:      Status
702 *
703 * DESCRIPTION: Initialize a namespace object from a parser Op and its
704 *              associated arguments.  The namespace object is a more compact
705 *              representation of the Op and its arguments.
706 *
707 ******************************************************************************/
708
709ACPI_STATUS
710AcpiDsInitObjectFromOp (
711    ACPI_WALK_STATE         *WalkState,
712    ACPI_PARSE_OBJECT       *Op,
713    UINT16                  Opcode,
714    ACPI_OPERAND_OBJECT     **RetObjDesc)
715{
716    const ACPI_OPCODE_INFO  *OpInfo;
717    ACPI_OPERAND_OBJECT     *ObjDesc;
718    ACPI_STATUS             Status = AE_OK;
719
720
721    ACPI_FUNCTION_TRACE (DsInitObjectFromOp);
722
723
724    ObjDesc = *RetObjDesc;
725    OpInfo = AcpiPsGetOpcodeInfo (Opcode);
726    if (OpInfo->Class == AML_CLASS_UNKNOWN)
727    {
728        /* Unknown opcode */
729
730        return_ACPI_STATUS (AE_TYPE);
731    }
732
733    /* Perform per-object initialization */
734
735    switch (ObjDesc->Common.Type)
736    {
737    case ACPI_TYPE_BUFFER:
738
739        /*
740         * Defer evaluation of Buffer TermArg operand
741         */
742        ObjDesc->Buffer.Node      = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
743                                        WalkState->Operands[0]);
744        ObjDesc->Buffer.AmlStart  = Op->Named.Data;
745        ObjDesc->Buffer.AmlLength = Op->Named.Length;
746        break;
747
748
749    case ACPI_TYPE_PACKAGE:
750
751        /*
752         * Defer evaluation of Package TermArg operand
753         */
754        ObjDesc->Package.Node      = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
755                                        WalkState->Operands[0]);
756        ObjDesc->Package.AmlStart  = Op->Named.Data;
757        ObjDesc->Package.AmlLength = Op->Named.Length;
758        break;
759
760
761    case ACPI_TYPE_INTEGER:
762
763        switch (OpInfo->Type)
764        {
765        case AML_TYPE_CONSTANT:
766            /*
767             * Resolve AML Constants here - AND ONLY HERE!
768             * All constants are integers.
769             * We mark the integer with a flag that indicates that it started
770             * life as a constant -- so that stores to constants will perform
771             * as expected (noop). ZeroOp is used as a placeholder for optional
772             * target operands.
773             */
774            ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT;
775
776            switch (Opcode)
777            {
778            case AML_ZERO_OP:
779
780                ObjDesc->Integer.Value = 0;
781                break;
782
783            case AML_ONE_OP:
784
785                ObjDesc->Integer.Value = 1;
786                break;
787
788            case AML_ONES_OP:
789
790                ObjDesc->Integer.Value = ACPI_UINT64_MAX;
791
792                /* Truncate value if we are executing from a 32-bit ACPI table */
793
794#ifndef ACPI_NO_METHOD_EXECUTION
795                AcpiExTruncateFor32bitTable (ObjDesc);
796#endif
797                break;
798
799            case AML_REVISION_OP:
800
801                ObjDesc->Integer.Value = ACPI_CA_VERSION;
802                break;
803
804            default:
805
806                ACPI_ERROR ((AE_INFO,
807                    "Unknown constant opcode 0x%X", Opcode));
808                Status = AE_AML_OPERAND_TYPE;
809                break;
810            }
811            break;
812
813
814        case AML_TYPE_LITERAL:
815
816            ObjDesc->Integer.Value = Op->Common.Value.Integer;
817#ifndef ACPI_NO_METHOD_EXECUTION
818            AcpiExTruncateFor32bitTable (ObjDesc);
819#endif
820            break;
821
822
823        default:
824            ACPI_ERROR ((AE_INFO, "Unknown Integer type 0x%X",
825                OpInfo->Type));
826            Status = AE_AML_OPERAND_TYPE;
827            break;
828        }
829        break;
830
831
832    case ACPI_TYPE_STRING:
833
834        ObjDesc->String.Pointer = Op->Common.Value.String;
835        ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Op->Common.Value.String);
836
837        /*
838         * The string is contained in the ACPI table, don't ever try
839         * to delete it
840         */
841        ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
842        break;
843
844
845    case ACPI_TYPE_METHOD:
846        break;
847
848
849    case ACPI_TYPE_LOCAL_REFERENCE:
850
851        switch (OpInfo->Type)
852        {
853        case AML_TYPE_LOCAL_VARIABLE:
854
855            /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
856
857            ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_LOCAL_OP;
858            ObjDesc->Reference.Class = ACPI_REFCLASS_LOCAL;
859
860#ifndef ACPI_NO_METHOD_EXECUTION
861            Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_LOCAL,
862                        ObjDesc->Reference.Value, WalkState,
863                        ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
864                            &ObjDesc->Reference.Object));
865#endif
866            break;
867
868
869        case AML_TYPE_METHOD_ARGUMENT:
870
871            /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
872
873            ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_ARG_OP;
874            ObjDesc->Reference.Class = ACPI_REFCLASS_ARG;
875
876#ifndef ACPI_NO_METHOD_EXECUTION
877            Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_ARG,
878                        ObjDesc->Reference.Value, WalkState,
879                        ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
880                            &ObjDesc->Reference.Object));
881#endif
882            break;
883
884        default: /* Object name or Debug object */
885
886            switch (Op->Common.AmlOpcode)
887            {
888            case AML_INT_NAMEPATH_OP:
889
890                /* Node was saved in Op */
891
892                ObjDesc->Reference.Node = Op->Common.Node;
893                ObjDesc->Reference.Object = Op->Common.Node->Object;
894                ObjDesc->Reference.Class = ACPI_REFCLASS_NAME;
895                break;
896
897            case AML_DEBUG_OP:
898
899                ObjDesc->Reference.Class = ACPI_REFCLASS_DEBUG;
900                break;
901
902            default:
903
904                ACPI_ERROR ((AE_INFO,
905                    "Unimplemented reference type for AML opcode: 0x%4.4X", Opcode));
906                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
907            }
908            break;
909        }
910        break;
911
912
913    default:
914
915        ACPI_ERROR ((AE_INFO, "Unimplemented data type: 0x%X",
916            ObjDesc->Common.Type));
917
918        Status = AE_AML_OPERAND_TYPE;
919        break;
920    }
921
922    return_ACPI_STATUS (Status);
923}
924
925
926