nsobject.c revision 80062
1250079Scarl/*******************************************************************************
2250079Scarl *
3289542Scem * Module Name: nsobject - Utilities for objects attached to namespace
4250079Scarl *                         table entries
5250079Scarl *              $Revision: 56 $
6250079Scarl *
7250079Scarl ******************************************************************************/
8250079Scarl
9250079Scarl/******************************************************************************
10250079Scarl *
11250079Scarl * 1. Copyright Notice
12250079Scarl *
13250079Scarl * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
14250079Scarl * All rights reserved.
15250079Scarl *
16250079Scarl * 2. License
17250079Scarl *
18250079Scarl * 2.1. This is your license from Intel Corp. under its intellectual property
19250079Scarl * rights.  You may have additional license terms from the party that provided
20250079Scarl * you this software, covering your right to use that party's intellectual
21250079Scarl * property rights.
22250079Scarl *
23250079Scarl * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24250079Scarl * copy of the source code appearing in this file ("Covered Code") an
25250079Scarl * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26250079Scarl * base code distributed originally by Intel ("Original Intel Code") to copy,
27250079Scarl * make derivatives, distribute, use and display any portion of the Covered
28250079Scarl * Code in any form, with the right to sublicense such rights; and
29250079Scarl *
30250079Scarl * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31250079Scarl * license (with the right to sublicense), under only those claims of Intel
32250079Scarl * patents that are infringed by the Original Intel Code, to make, use, sell,
33250079Scarl * offer to sell, and import the Covered Code and derivative works thereof
34250079Scarl * solely to the minimum extent necessary to exercise the above copyright
35250079Scarl * license, and in no event shall the patent license extend to any additions
36250079Scarl * to or modifications of the Original Intel Code.  No other license or right
37250079Scarl * is granted directly or by implication, estoppel or otherwise;
38250079Scarl *
39289207Scem * The above copyright and patent license is granted only if the following
40250079Scarl * conditions are met:
41250079Scarl *
42250079Scarl * 3. Conditions
43250079Scarl *
44250079Scarl * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45250079Scarl * Redistribution of source code of any substantial portion of the Covered
46250079Scarl * Code or modification with rights to further distribute source must include
47250079Scarl * the above Copyright Notice, the above License, this list of Conditions,
48250079Scarl * and the following Disclaimer and Export Compliance provision.  In addition,
49250079Scarl * Licensee must cause all Covered Code to which Licensee contributes to
50250079Scarl * contain a file documenting the changes Licensee made to create that Covered
51250079Scarl * Code and the date of any change.  Licensee must include in that file the
52250079Scarl * documentation of any changes made by any predecessor Licensee.  Licensee
53250079Scarl * must include a prominent statement that the modification is derived,
54250079Scarl * directly or indirectly, from Original Intel Code.
55250079Scarl *
56250079Scarl * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57250079Scarl * Redistribution of source code of any substantial portion of the Covered
58250079Scarl * Code or modification without rights to further distribute source must
59250079Scarl * include the following Disclaimer and Export Compliance provision in the
60250079Scarl * documentation and/or other materials provided with distribution.  In
61250079Scarl * addition, Licensee may not authorize further sublicense of source of any
62250079Scarl * portion of the Covered Code, and must include terms to the effect that the
63289538Scem * license from Licensee to its licensee is limited to the intellectual
64250079Scarl * property embodied in the software Licensee provides to its licensee, and
65289539Scem * not to intellectual property embodied in modifications its licensee may
66289539Scem * make.
67250079Scarl *
68250079Scarl * 3.3. Redistribution of Executable. Redistribution in executable form of any
69250079Scarl * substantial portion of the Covered Code or modification must reproduce the
70250079Scarl * above Copyright Notice, and the following Disclaimer and Export Compliance
71250079Scarl * provision in the documentation and/or other materials provided with the
72250079Scarl * distribution.
73250079Scarl *
74250079Scarl * 3.4. Intel retains all right, title, and interest in and to the Original
75289610Scem * Intel Code.
76289610Scem *
77289610Scem * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78289610Scem * Intel shall be used in advertising or otherwise to promote the sale, use or
79289610Scem * other dealings in products derived from or relating to the Covered Code
80289610Scem * without prior written authorization from Intel.
81289610Scem *
82289610Scem * 4. Disclaimer and Export Compliance
83289610Scem *
84289610Scem * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85289610Scem * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86289610Scem * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87289539Scem * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88289539Scem * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89289539Scem * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90289539Scem * PARTICULAR PURPOSE.
91289539Scem *
92289539Scem * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93289539Scem * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94289539Scem * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95255274Scarl * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96255274Scarl * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97255274Scarl * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98255274Scarl * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99250079Scarl * LIMITED REMEDY.
100250079Scarl *
101255274Scarl * 4.3. Licensee shall not export, either directly or indirectly, any of this
102250079Scarl * software or system incorporating such software without first obtaining any
103289397Scem * required license or other approval from the U. S. Department of Commerce or
104250079Scarl * any other agency or department of the United States Government.  In the
105250079Scarl * event Licensee exports any such software from the United States or
106250079Scarl * re-exports any such software from a foreign destination, Licensee shall
107250079Scarl * ensure that the distribution and export/re-export of the software is in
108250079Scarl * compliance with all laws, regulations, orders, or other restrictions of the
109250079Scarl * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110250079Scarl * any of its subsidiaries will export/re-export any technical data, process,
111250079Scarl * software, or service, directly or indirectly, to any country for which the
112250079Scarl * United States government or any agency thereof requires an export license,
113250079Scarl * other governmental approval, or letter of assurance, without first obtaining
114289543Scem * such license, approval or letter.
115289543Scem *
116289543Scem *****************************************************************************/
117289543Scem
118289543Scem
119250079Scarl#define __NSOBJECT_C__
120250079Scarl
121250079Scarl#include "acpi.h"
122250079Scarl#include "amlcode.h"
123250079Scarl#include "acnamesp.h"
124250079Scarl#include "acinterp.h"
125250079Scarl#include "actables.h"
126250079Scarl
127289546Scem
128250079Scarl#define _COMPONENT          ACPI_NAMESPACE
129289546Scem        MODULE_NAME         ("nsobject")
130250079Scarl
131250079Scarl
132289542Scem/*******************************************************************************
133289542Scem *
134289542Scem * FUNCTION:    AcpiNsAttachObject
135289542Scem *
136289542Scem * PARAMETERS:  Node            - Parent Node
137289542Scem *              Object              - Object to be attached
138289542Scem *              Type                - Type of object, or ACPI_TYPE_ANY if not
139289542Scem *                                      known
140289542Scem *
141289542Scem * DESCRIPTION: Record the given object as the value associated with the
142289542Scem *              name whose ACPI_HANDLE is passed.  If Object is NULL
143289542Scem *              and Type is ACPI_TYPE_ANY, set the name as having no value.
144289542Scem *
145289542Scem * MUTEX:       Assumes namespace is locked
146289546Scem *
147289546Scem ******************************************************************************/
148289546Scem
149289546ScemACPI_STATUS
150289546ScemAcpiNsAttachObject (
151289546Scem    ACPI_NAMESPACE_NODE     *Node,
152289546Scem    ACPI_OPERAND_OBJECT     *Object,
153289546Scem    ACPI_OBJECT_TYPE8       Type)
154289546Scem{
155289546Scem    ACPI_OPERAND_OBJECT     *ObjDesc;
156289546Scem    ACPI_OPERAND_OBJECT     *PreviousObjDesc;
157289546Scem    ACPI_OBJECT_TYPE8      ObjType = ACPI_TYPE_ANY;
158289542Scem    UINT8                   Flags;
159289542Scem    UINT16                  Opcode;
160289542Scem
161289542Scem
162289542Scem    FUNCTION_TRACE ("NsAttachObject");
163289542Scem
164289542Scem
165289542Scem    /*
166289542Scem     * Parameter validation
167289542Scem     */
168250079Scarl
169250079Scarl    if (!AcpiGbl_RootNode)
170250079Scarl    {
171255274Scarl        /* Name space not initialized  */
172250079Scarl
173250079Scarl        REPORT_ERROR (("NsAttachObject: Namespace not initialized\n"));
174250079Scarl        return_ACPI_STATUS (AE_NO_NAMESPACE);
175250079Scarl    }
176250079Scarl
177250079Scarl    if (!Node)
178250079Scarl    {
179250079Scarl        /* Invalid handle */
180289546Scem
181289546Scem        REPORT_ERROR (("NsAttachObject: Null NamedObj handle\n"));
182289546Scem        return_ACPI_STATUS (AE_BAD_PARAMETER);
183289546Scem    }
184289546Scem
185289546Scem    if (!Object && (ACPI_TYPE_ANY != Type))
186289546Scem    {
187250079Scarl        /* Null object */
188289610Scem
189289610Scem        REPORT_ERROR (("NsAttachObject: Null object, but type not ACPI_TYPE_ANY\n"));
190289610Scem        return_ACPI_STATUS (AE_BAD_PARAMETER);
191289539Scem    }
192289542Scem
193289542Scem    if (!VALID_DESCRIPTOR_TYPE (Node, ACPI_DESC_TYPE_NAMED))
194289542Scem    {
195289543Scem        /* Not a name handle */
196289542Scem
197289542Scem        REPORT_ERROR (("NsAttachObject: Invalid handle\n"));
198289539Scem        return_ACPI_STATUS (AE_BAD_PARAMETER);
199289539Scem    }
200289539Scem
201289539Scem    /* Check if this object is already attached */
202289539Scem
203289542Scem    if (Node->Object == Object)
204289546Scem    {
205289546Scem        DEBUG_PRINTP (TRACE_EXEC, ("Obj %p already installed in NameObj %p\n",
206289546Scem            Object, Node));
207289546Scem
208289542Scem        return_ACPI_STATUS (AE_OK);
209289542Scem    }
210289546Scem
211289546Scem
212289542Scem    /* Get the current flags field of the Node */
213289542Scem
214289542Scem    Flags = Node->Flags;
215289546Scem    Flags &= ~ANOBJ_AML_ATTACHMENT;
216289542Scem
217289542Scem
218289542Scem    /* If null object, we will just install it */
219289542Scem
220289542Scem    if (!Object)
221289542Scem    {
222289542Scem        ObjDesc = NULL;
223250079Scarl        ObjType = ACPI_TYPE_ANY;
224250079Scarl    }
225289234Scem
226289234Scem    /*
227289234Scem     * If the object is an Node with an attached object,
228289234Scem     * we will use that (attached) object
229289234Scem     */
230289234Scem
231289234Scem    else if (VALID_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_NAMED) &&
232289234Scem            ((ACPI_NAMESPACE_NODE *) Object)->Object)
233289234Scem    {
234289234Scem        /*
235289234Scem         * Value passed is a name handle and that name has a
236289234Scem         * non-null value.  Use that name's value and type.
237289234Scem         */
238289234Scem
239289234Scem        ObjDesc = ((ACPI_NAMESPACE_NODE *) Object)->Object;
240289234Scem        ObjType = ((ACPI_NAMESPACE_NODE *) Object)->Type;
241289234Scem
242289234Scem        /*
243289234Scem         * Copy appropriate flags
244289234Scem         */
245255279Scarl
246255279Scarl        if (((ACPI_NAMESPACE_NODE *) Object)->Flags & ANOBJ_AML_ATTACHMENT)
247255279Scarl        {
248255279Scarl            Flags |= ANOBJ_AML_ATTACHMENT;
249255279Scarl        }
250255279Scarl    }
251255279Scarl
252250079Scarl
253255279Scarl    /*
254289397Scem     * Otherwise, we will use the parameter object, but we must type
255289542Scem     * it first
256255279Scarl     */
257289542Scem
258289397Scem    else
259250079Scarl    {
260250079Scarl        ObjDesc = (ACPI_OPERAND_OBJECT  *) Object;
261250079Scarl
262250079Scarl
263289539Scem        /* If a valid type (non-ANY) was given, just use it */
264289546Scem
265289546Scem        if (ACPI_TYPE_ANY != Type)
266289546Scem        {
267255272Scarl            ObjType = Type;
268289541Scem        }
269255272Scarl
270255272Scarl
271255272Scarl        /*
272250079Scarl         * Type is TYPE_Any, we must try to determinte the
273289344Scem         * actual type of the object
274289540Scem         */
275289342Scem
276289540Scem        /*
277250079Scarl         * Check if value points into the AML code
278289540Scem         */
279289546Scem        else if (AcpiTbSystemTablePointer (Object))
280289546Scem        {
281289546Scem            /*
282289546Scem             * Object points into the AML stream.
283289546Scem             * Set a flag bit in the Node to indicate this
284289546Scem             */
285289546Scem
286250079Scarl            Flags |= ANOBJ_AML_ATTACHMENT;
287289397Scem
288289348Scem            /*
289289348Scem             * The next byte (perhaps the next two bytes)
290289542Scem             * will be the AML opcode
291289542Scem             */
292289272Scem
293255279Scarl            MOVE_UNALIGNED16_TO_16 (&Opcode, Object);
294289543Scem
295289543Scem            /* Check for a recognized Opcode */
296289543Scem
297289543Scem            switch ((UINT8) Opcode)
298289543Scem            {
299289543Scem
300289542Scem            case AML_OP_PREFIX:
301289542Scem
302289546Scem                if (Opcode != AML_REVISION_OP)
303289546Scem                {
304289546Scem                    /*
305289546Scem                     * OpPrefix is unrecognized unless part
306289542Scem                     * of RevisionOp
307289546Scem                     */
308250079Scarl
309289546Scem                    break;
310255274Scarl                }
311250079Scarl
312250079Scarl                /* Else fall through to set type as Number */
313289612Scem
314289612Scem
315289612Scem            case AML_ZERO_OP: case AML_ONES_OP: case AML_ONE_OP:
316289233Scem            case AML_BYTE_OP: case AML_WORD_OP: case AML_DWORD_OP:
317289233Scem
318289538Scem                ObjType = ACPI_TYPE_INTEGER;
319289233Scem                break;
320289538Scem
321289233Scem
322289538Scem            case AML_STRING_OP:
323289538Scem
324289233Scem                ObjType = ACPI_TYPE_STRING;
325289538Scem                break;
326289538Scem
327289233Scem
328289538Scem            case AML_BUFFER_OP:
329289538Scem
330289233Scem                ObjType = ACPI_TYPE_BUFFER;
331255274Scarl                break;
332250079Scarl
333250079Scarl
334289542Scem            case AML_MUTEX_OP:
335289542Scem
336289542Scem                ObjType = ACPI_TYPE_MUTEX;
337289542Scem                break;
338289542Scem
339289542Scem
340289542Scem            case AML_PACKAGE_OP:
341289607Scem
342289607Scem                ObjType = ACPI_TYPE_PACKAGE;
343289607Scem                break;
344289607Scem
345289607Scem
346289607Scem            default:
347289542Scem
348289542Scem                DEBUG_PRINTP (ACPI_ERROR,
349289542Scem                    ("AML Opcode/Type [%x] not supported in attach\n",
350289542Scem                    (UINT8) Opcode));
351289542Scem
352289542Scem                return_ACPI_STATUS (AE_TYPE);
353289542Scem                break;
354289542Scem            }
355289542Scem        }
356289546Scem
357289546Scem        else
358289546Scem        {
359289542Scem            /*
360289546Scem             * Cannot figure out the type -- set to DefAny which
361289542Scem             * will print as an error in the name table dump
362289546Scem             */
363289542Scem
364289546Scem            if (GetDebugLevel () > 0)
365289542Scem            {
366289542Scem                DUMP_PATHNAME (Node,
367289542Scem                    "NsAttachObject confused: setting bogus type for  ",
368289542Scem                    ACPI_INFO, _COMPONENT);
369289542Scem
370289542Scem                if (AcpiTbSystemTablePointer (Object))
371289542Scem                {
372289542Scem                    DEBUG_PRINTP (ACPI_INFO,
373289542Scem                        ("AML-stream code %02x\n", *(UINT8 *) Object));
374289607Scem                }
375289607Scem
376289607Scem                else if (VALID_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_NAMED))
377289607Scem                {
378289607Scem                    DUMP_PATHNAME (Object, "name ", ACPI_INFO, _COMPONENT);
379289607Scem                }
380289542Scem
381289542Scem                else
382289542Scem                {
383289542Scem                    DUMP_PATHNAME (Object, "object ", ACPI_INFO, _COMPONENT);
384289542Scem                    DUMP_STACK_ENTRY (Object);
385289542Scem                }
386289542Scem            }
387289546Scem
388289546Scem            ObjType = INTERNAL_TYPE_DEF_ANY;
389289546Scem        }
390289546Scem    }
391289542Scem
392289546Scem
393289546Scem    DEBUG_PRINTP (TRACE_EXEC, ("Installing obj %p into NameObj %p [%4.4s]\n",
394289546Scem        ObjDesc, Node, &Node->Name));
395289542Scem
396289546Scem
397289546Scem    /*
398289542Scem     * Must increment the new value's reference count
399289542Scem     * (if it is an internal object)
400289614Scem     */
401289542Scem
402289542Scem    AcpiUtAddReference (ObjDesc);
403289542Scem
404289542Scem    /* Save the existing object (if any) for deletion later */
405289542Scem
406289542Scem    PreviousObjDesc = Node->Object;
407289542Scem
408289614Scem    /* Install the object and set the type, flags */
409289542Scem
410289542Scem    Node->Object   = ObjDesc;
411289542Scem    Node->Type     = (UINT8) ObjType;
412289542Scem    Node->Flags    |= Flags;
413289542Scem
414289542Scem
415289542Scem    /*
416289614Scem     * Delete an existing attached object.
417289614Scem     */
418289614Scem
419289614Scem    if (PreviousObjDesc)
420289614Scem    {
421289614Scem        /* One for the attach to the Node */
422289614Scem
423289614Scem        AcpiUtRemoveReference (PreviousObjDesc);
424289614Scem
425289614Scem        /* Now delete */
426289614Scem
427289614Scem        AcpiUtRemoveReference (PreviousObjDesc);
428289614Scem    }
429289614Scem
430289614Scem    return_ACPI_STATUS (AE_OK);
431289614Scem}
432289614Scem
433289614Scem
434289614Scem/*******************************************************************************
435289614Scem *
436289614Scem * FUNCTION:    AcpiNsDetachObject
437289614Scem *
438289614Scem * PARAMETERS:  Node           - An object whose Value will be deleted
439289614Scem *
440289614Scem * RETURN:      None.
441289614Scem *
442289614Scem * DESCRIPTION: Delete the Value associated with a namespace object.  If the
443289614Scem *              Value is an allocated object, it is freed.  Otherwise, the
444289614Scem *              field is simply cleared.
445289614Scem *
446289614Scem ******************************************************************************/
447250079Scarl
448250079Scarlvoid
449250079ScarlAcpiNsDetachObject (
450250079Scarl    ACPI_NAMESPACE_NODE     *Node)
451250079Scarl{
452250079Scarl    ACPI_OPERAND_OBJECT     *ObjDesc;
453250079Scarl
454250079Scarl
455250079Scarl    FUNCTION_TRACE ("NsDetachObject");
456250079Scarl
457250079Scarl    ObjDesc = Node->Object;
458250079Scarl    if (!ObjDesc)
459250079Scarl    {
460250079Scarl        return_VOID;
461250079Scarl    }
462250079Scarl
463250079Scarl    /* Clear the entry in all cases */
464250079Scarl
465250079Scarl    Node->Object = NULL;
466250079Scarl
467250079Scarl    /* Found a valid value */
468250079Scarl
469250079Scarl    DEBUG_PRINTP (ACPI_INFO, ("Object=%p Value=%p Name %4.4s\n",
470289207Scem        Node, ObjDesc, &Node->Name));
471289207Scem
472250079Scarl    /*
473250079Scarl     * Not every value is an object allocated via ACPI_MEM_CALLOCATE,
474250079Scarl     * - must check
475250079Scarl     */
476250079Scarl
477250079Scarl    if (!AcpiTbSystemTablePointer (ObjDesc))
478289209Scem    {
479250079Scarl        /* Attempt to delete the object (and all subobjects) */
480289209Scem
481289209Scem        AcpiUtRemoveReference (ObjDesc);
482250079Scarl    }
483289209Scem
484289209Scem    return_VOID;
485289209Scem}
486250079Scarl
487250079Scarl
488250079Scarl/*******************************************************************************
489250079Scarl *
490250079Scarl * FUNCTION:    AcpiNsGetAttachedObject
491289209Scem *
492289209Scem * PARAMETERS:  Node             - Parent Node to be examined
493250079Scarl *
494250079Scarl * RETURN:      Current value of the object field from the Node whose
495289209Scem *              handle is passed
496289209Scem *
497289209Scem ******************************************************************************/
498250079Scarl
499250079Scarlvoid *
500255274ScarlAcpiNsGetAttachedObject (
501289543Scem    ACPI_NAMESPACE_NODE     *Node)
502250079Scarl{
503250079Scarl    FUNCTION_TRACE_PTR ("NsGetAttachedObject", Node);
504283291Sjkim
505283291Sjkim
506289542Scem    if (!Node)
507289546Scem    {
508250079Scarl        /* handle invalid */
509289348Scem
510289348Scem        DEBUG_PRINTP (ACPI_WARN, ("Null Node ptr\n"));
511289348Scem        return_PTR (NULL);
512289348Scem    }
513289348Scem
514289348Scem    return_PTR (Node->Object);
515289348Scem}
516289397Scem
517289396Scem
518289209Scem