nsxfobj.c revision 87031
167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
467754Smsmith *                         ACPI Object oriented interfaces
587031Smsmith *              $Revision: 98 $
667754Smsmith *
767754Smsmith ******************************************************************************/
867754Smsmith
967754Smsmith/******************************************************************************
1067754Smsmith *
1167754Smsmith * 1. Copyright Notice
1267754Smsmith *
1371867Smsmith * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
1470243Smsmith * All rights reserved.
1567754Smsmith *
1667754Smsmith * 2. License
1767754Smsmith *
1867754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1967754Smsmith * rights.  You may have additional license terms from the party that provided
2067754Smsmith * you this software, covering your right to use that party's intellectual
2167754Smsmith * property rights.
2267754Smsmith *
2367754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2467754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2567754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2667754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2767754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2867754Smsmith * Code in any form, with the right to sublicense such rights; and
2967754Smsmith *
3067754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3167754Smsmith * license (with the right to sublicense), under only those claims of Intel
3267754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3367754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3467754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3567754Smsmith * license, and in no event shall the patent license extend to any additions
3667754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3767754Smsmith * is granted directly or by implication, estoppel or otherwise;
3867754Smsmith *
3967754Smsmith * The above copyright and patent license is granted only if the following
4067754Smsmith * conditions are met:
4167754Smsmith *
4267754Smsmith * 3. Conditions
4367754Smsmith *
4467754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4567754Smsmith * Redistribution of source code of any substantial portion of the Covered
4667754Smsmith * Code or modification with rights to further distribute source must include
4767754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4867754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4967754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
5067754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5167754Smsmith * Code and the date of any change.  Licensee must include in that file the
5267754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5367754Smsmith * must include a prominent statement that the modification is derived,
5467754Smsmith * directly or indirectly, from Original Intel Code.
5567754Smsmith *
5667754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5767754Smsmith * Redistribution of source code of any substantial portion of the Covered
5867754Smsmith * Code or modification without rights to further distribute source must
5967754Smsmith * include the following Disclaimer and Export Compliance provision in the
6067754Smsmith * documentation and/or other materials provided with distribution.  In
6167754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6267754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6367754Smsmith * license from Licensee to its licensee is limited to the intellectual
6467754Smsmith * property embodied in the software Licensee provides to its licensee, and
6567754Smsmith * not to intellectual property embodied in modifications its licensee may
6667754Smsmith * make.
6767754Smsmith *
6867754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6967754Smsmith * substantial portion of the Covered Code or modification must reproduce the
7067754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7167754Smsmith * provision in the documentation and/or other materials provided with the
7267754Smsmith * distribution.
7367754Smsmith *
7467754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7567754Smsmith * Intel Code.
7667754Smsmith *
7767754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7867754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7967754Smsmith * other dealings in products derived from or relating to the Covered Code
8067754Smsmith * without prior written authorization from Intel.
8167754Smsmith *
8267754Smsmith * 4. Disclaimer and Export Compliance
8367754Smsmith *
8467754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8567754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8667754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8767754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8867754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8967754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9067754Smsmith * PARTICULAR PURPOSE.
9167754Smsmith *
9267754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9367754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9467754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9567754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9667754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9767754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9867754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9967754Smsmith * LIMITED REMEDY.
10067754Smsmith *
10167754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10267754Smsmith * software or system incorporating such software without first obtaining any
10367754Smsmith * required license or other approval from the U. S. Department of Commerce or
10467754Smsmith * any other agency or department of the United States Government.  In the
10567754Smsmith * event Licensee exports any such software from the United States or
10667754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10767754Smsmith * ensure that the distribution and export/re-export of the software is in
10867754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10967754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11067754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11167754Smsmith * software, or service, directly or indirectly, to any country for which the
11267754Smsmith * United States government or any agency thereof requires an export license,
11367754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11467754Smsmith * such license, approval or letter.
11567754Smsmith *
11667754Smsmith *****************************************************************************/
11767754Smsmith
11867754Smsmith
11967754Smsmith#define __NSXFOBJ_C__
12067754Smsmith
12167754Smsmith#include "acpi.h"
12267754Smsmith#include "acinterp.h"
12367754Smsmith#include "acnamesp.h"
12467754Smsmith#include "acdispat.h"
12567754Smsmith
12667754Smsmith
12777424Smsmith#define _COMPONENT          ACPI_NAMESPACE
12867754Smsmith        MODULE_NAME         ("nsxfobj")
12967754Smsmith
13067754Smsmith
13167754Smsmith/*******************************************************************************
13267754Smsmith *
13367754Smsmith * FUNCTION:    AcpiEvaluateObject
13467754Smsmith *
13567754Smsmith * PARAMETERS:  Handle              - Object handle (optional)
13667754Smsmith *              *Pathname           - Object pathname (optional)
13787031Smsmith *              **ExternalParams    - List of parameters to pass to method,
13884491Smsmith *                                    terminated by NULL.  May be NULL
13984491Smsmith *                                    if no parameters are being passed.
14084491Smsmith *              *ReturnBuffer       - Where to put method's return value (if
14167754Smsmith *                                    any).  If NULL, no value is returned.
14267754Smsmith *
14367754Smsmith * RETURN:      Status
14467754Smsmith *
14567754Smsmith * DESCRIPTION: Find and evaluate the given object, passing the given
14667754Smsmith *              parameters if necessary.  One of "Handle" or "Pathname" must
14767754Smsmith *              be valid (non-null)
14867754Smsmith *
14967754Smsmith ******************************************************************************/
15067754Smsmith
15167754SmsmithACPI_STATUS
15267754SmsmithAcpiEvaluateObject (
15367754Smsmith    ACPI_HANDLE             Handle,
15467754Smsmith    ACPI_STRING             Pathname,
15584491Smsmith    ACPI_OBJECT_LIST        *ExternalParams,
15667754Smsmith    ACPI_BUFFER             *ReturnBuffer)
15767754Smsmith{
15867754Smsmith    ACPI_STATUS             Status;
15984491Smsmith    ACPI_OPERAND_OBJECT     **InternalParams = NULL;
16084491Smsmith    ACPI_OPERAND_OBJECT     *InternalReturnObj = NULL;
16167754Smsmith    UINT32                  BufferSpaceNeeded;
16267754Smsmith    UINT32                  UserBufferLength;
16367754Smsmith    UINT32                  i;
16467754Smsmith
16567754Smsmith
16667754Smsmith    FUNCTION_TRACE ("AcpiEvaluateObject");
16767754Smsmith
16867754Smsmith
16967754Smsmith    /*
17067754Smsmith     * If there are parameters to be passed to the object
17167754Smsmith     * (which must be a control method), the external objects
17267754Smsmith     * must be converted to internal objects
17367754Smsmith     */
17484491Smsmith    if (ExternalParams && ExternalParams->Count)
17567754Smsmith    {
17667754Smsmith        /*
17767754Smsmith         * Allocate a new parameter block for the internal objects
17867754Smsmith         * Add 1 to count to allow for null terminated internal list
17967754Smsmith         */
18084491Smsmith        InternalParams = ACPI_MEM_CALLOCATE ((ExternalParams->Count + 1) * sizeof (void *));
18184491Smsmith        if (!InternalParams)
18267754Smsmith        {
18367754Smsmith            return_ACPI_STATUS (AE_NO_MEMORY);
18467754Smsmith        }
18567754Smsmith
18667754Smsmith
18767754Smsmith        /*
18867754Smsmith         * Convert each external object in the list to an
18967754Smsmith         * internal object
19067754Smsmith         */
19184491Smsmith        for (i = 0; i < ExternalParams->Count; i++)
19267754Smsmith        {
19384491Smsmith            Status = AcpiUtCopyEobjectToIobject (&ExternalParams->Pointer[i],
19484491Smsmith                                                &InternalParams[i]);
19567754Smsmith
19667754Smsmith            if (ACPI_FAILURE (Status))
19767754Smsmith            {
19884491Smsmith                AcpiUtDeleteInternalObjectList (InternalParams);
19967754Smsmith                return_ACPI_STATUS (Status);
20067754Smsmith            }
20167754Smsmith        }
20284491Smsmith        InternalParams[ExternalParams->Count] = NULL;
20367754Smsmith    }
20467754Smsmith
20567754Smsmith
20667754Smsmith    /*
20767754Smsmith     * Three major cases:
20867754Smsmith     * 1) Fully qualified pathname
20967754Smsmith     * 2) No handle, not fully qualified pathname (error)
21067754Smsmith     * 3) Valid handle
21167754Smsmith     */
21267754Smsmith    if ((Pathname) &&
21367754Smsmith        (AcpiNsValidRootPrefix (Pathname[0])))
21467754Smsmith    {
21567754Smsmith        /*
21667754Smsmith         *  The path is fully qualified, just evaluate by name
21767754Smsmith         */
21884491Smsmith        Status = AcpiNsEvaluateByName (Pathname, InternalParams, &InternalReturnObj);
21967754Smsmith    }
22067754Smsmith
22167754Smsmith    else if (!Handle)
22267754Smsmith    {
22367754Smsmith        /*
22467754Smsmith         * A handle is optional iff a fully qualified pathname
22567754Smsmith         * is specified.  Since we've already handled fully
22667754Smsmith         * qualified names above, this is an error
22767754Smsmith         */
22867754Smsmith        if (!Pathname)
22967754Smsmith        {
23082367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Both Handle and Pathname are NULL\n"));
23167754Smsmith        }
23267754Smsmith
23367754Smsmith        else
23467754Smsmith        {
23582367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Handle is NULL and Pathname is relative\n"));
23667754Smsmith        }
23767754Smsmith
23867754Smsmith        Status = AE_BAD_PARAMETER;
23967754Smsmith    }
24067754Smsmith
24167754Smsmith    else
24267754Smsmith    {
24367754Smsmith        /*
24467754Smsmith         * We get here if we have a handle -- and if we have a
24567754Smsmith         * pathname it is relative.  The handle will be validated
24667754Smsmith         * in the lower procedures
24767754Smsmith         */
24867754Smsmith        if (!Pathname)
24967754Smsmith        {
25067754Smsmith            /*
25167754Smsmith             * The null pathname case means the handle is for
25267754Smsmith             * the actual object to be evaluated
25367754Smsmith             */
25484491Smsmith            Status = AcpiNsEvaluateByHandle (Handle, InternalParams, &InternalReturnObj);
25567754Smsmith        }
25667754Smsmith
25767754Smsmith        else
25867754Smsmith        {
25967754Smsmith           /*
26067754Smsmith            * Both a Handle and a relative Pathname
26167754Smsmith            */
26284491Smsmith            Status = AcpiNsEvaluateRelative (Handle, Pathname, InternalParams,
26384491Smsmith                                                &InternalReturnObj);
26467754Smsmith        }
26567754Smsmith    }
26667754Smsmith
26767754Smsmith
26867754Smsmith    /*
26967754Smsmith     * If we are expecting a return value, and all went well above,
27067754Smsmith     * copy the return value to an external object.
27167754Smsmith     */
27267754Smsmith
27367754Smsmith    if (ReturnBuffer)
27467754Smsmith    {
27567754Smsmith        UserBufferLength = ReturnBuffer->Length;
27667754Smsmith        ReturnBuffer->Length = 0;
27767754Smsmith
27884491Smsmith        if (InternalReturnObj)
27967754Smsmith        {
28084491Smsmith            if (VALID_DESCRIPTOR_TYPE (InternalReturnObj, ACPI_DESC_TYPE_NAMED))
28167754Smsmith            {
28267754Smsmith                /*
28367754Smsmith                 * If we got an Node as a return object,
28467754Smsmith                 * this means the object we are evaluating
28567754Smsmith                 * has nothing interesting to return (such
28667754Smsmith                 * as a mutex, etc.)  We return an error
28767754Smsmith                 * because these types are essentially
28867754Smsmith                 * unsupported by this interface.  We
28967754Smsmith                 * don't check up front because this makes
29067754Smsmith                 * it easier to add support for various
29167754Smsmith                 * types at a later date if necessary.
29267754Smsmith                 */
29367754Smsmith                Status = AE_TYPE;
29484491Smsmith                InternalReturnObj = NULL;   /* No need to delete an Node */
29567754Smsmith            }
29667754Smsmith
29767754Smsmith            if (ACPI_SUCCESS (Status))
29867754Smsmith            {
29967754Smsmith                /*
30067754Smsmith                 * Find out how large a buffer is needed
30167754Smsmith                 * to contain the returned object
30267754Smsmith                 */
30384491Smsmith                Status = AcpiUtGetObjectSize (InternalReturnObj,
30467754Smsmith                                                &BufferSpaceNeeded);
30567754Smsmith                if (ACPI_SUCCESS (Status))
30667754Smsmith                {
30767754Smsmith                    /*
30867754Smsmith                     * Check if there is enough room in the
30967754Smsmith                     * caller's buffer
31067754Smsmith                     */
31167754Smsmith                    if (UserBufferLength < BufferSpaceNeeded)
31267754Smsmith                    {
31367754Smsmith                        /*
31467754Smsmith                         * Caller's buffer is too small, can't
31567754Smsmith                         * give him partial results fail the call
31667754Smsmith                         * but return the buffer size needed
31767754Smsmith                         */
31882367Smsmith                        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
31982367Smsmith                            "Needed buffer size %X, received %X\n",
32067754Smsmith                            BufferSpaceNeeded, UserBufferLength));
32167754Smsmith
32267754Smsmith                        ReturnBuffer->Length = BufferSpaceNeeded;
32367754Smsmith                        Status = AE_BUFFER_OVERFLOW;
32467754Smsmith                    }
32567754Smsmith
32667754Smsmith                    else
32767754Smsmith                    {
32867754Smsmith                        /*
32967754Smsmith                         *  We have enough space for the object, build it
33067754Smsmith                         */
33184491Smsmith                        Status = AcpiUtCopyIobjectToEobject (InternalReturnObj,
33267754Smsmith                                        ReturnBuffer);
33367754Smsmith                        ReturnBuffer->Length = BufferSpaceNeeded;
33467754Smsmith                    }
33567754Smsmith                }
33667754Smsmith            }
33767754Smsmith        }
33867754Smsmith    }
33967754Smsmith
34067754Smsmith
34167754Smsmith    /* Delete the return and parameter objects */
34267754Smsmith
34384491Smsmith    if (InternalReturnObj)
34467754Smsmith    {
34567754Smsmith        /*
34667754Smsmith         * Delete the internal return object. (Or at least
34767754Smsmith         * decrement the reference count by one)
34867754Smsmith         */
34984491Smsmith        AcpiUtRemoveReference (InternalReturnObj);
35067754Smsmith    }
35167754Smsmith
35267754Smsmith    /*
35367754Smsmith     * Free the input parameter list (if we created one),
35467754Smsmith     */
35584491Smsmith    if (InternalParams)
35667754Smsmith    {
35767754Smsmith        /* Free the allocated parameter block */
35867754Smsmith
35984491Smsmith        AcpiUtDeleteInternalObjectList (InternalParams);
36067754Smsmith    }
36167754Smsmith
36267754Smsmith    return_ACPI_STATUS (Status);
36367754Smsmith}
36467754Smsmith
36567754Smsmith
36667754Smsmith/*******************************************************************************
36767754Smsmith *
36867754Smsmith * FUNCTION:    AcpiGetNextObject
36967754Smsmith *
37067754Smsmith * PARAMETERS:  Type            - Type of object to be searched for
37167754Smsmith *              Parent          - Parent object whose children we are getting
37267754Smsmith *              LastChild       - Previous child that was found.
37367754Smsmith *                                The NEXT child will be returned
37467754Smsmith *              RetHandle       - Where handle to the next object is placed
37567754Smsmith *
37667754Smsmith * RETURN:      Status
37767754Smsmith *
37867754Smsmith * DESCRIPTION: Return the next peer object within the namespace.  If Handle is
37967754Smsmith *              valid, Scope is ignored.  Otherwise, the first object within
38067754Smsmith *              Scope is returned.
38167754Smsmith *
38267754Smsmith ******************************************************************************/
38367754Smsmith
38467754SmsmithACPI_STATUS
38567754SmsmithAcpiGetNextObject (
38667754Smsmith    ACPI_OBJECT_TYPE        Type,
38767754Smsmith    ACPI_HANDLE             Parent,
38867754Smsmith    ACPI_HANDLE             Child,
38967754Smsmith    ACPI_HANDLE             *RetHandle)
39067754Smsmith{
39167754Smsmith    ACPI_STATUS             Status = AE_OK;
39267754Smsmith    ACPI_NAMESPACE_NODE     *Node;
39367754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode = NULL;
39467754Smsmith    ACPI_NAMESPACE_NODE     *ChildNode = NULL;
39567754Smsmith
39667754Smsmith
39767754Smsmith    /* Parameter validation */
39867754Smsmith
39967754Smsmith    if (Type > ACPI_TYPE_MAX)
40067754Smsmith    {
40167754Smsmith        return (AE_BAD_PARAMETER);
40267754Smsmith    }
40367754Smsmith
40477424Smsmith    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
40567754Smsmith
40667754Smsmith    /* If null handle, use the parent */
40767754Smsmith
40867754Smsmith    if (!Child)
40967754Smsmith    {
41067754Smsmith        /* Start search at the beginning of the specified scope */
41167754Smsmith
41285756Smsmith        ParentNode = AcpiNsMapHandleToNode (Parent);
41367754Smsmith        if (!ParentNode)
41467754Smsmith        {
41567754Smsmith            Status = AE_BAD_PARAMETER;
41667754Smsmith            goto UnlockAndExit;
41767754Smsmith        }
41867754Smsmith    }
41967754Smsmith
42067754Smsmith    /* Non-null handle, ignore the parent */
42167754Smsmith
42267754Smsmith    else
42367754Smsmith    {
42467754Smsmith        /* Convert and validate the handle */
42567754Smsmith
42685756Smsmith        ChildNode = AcpiNsMapHandleToNode (Child);
42767754Smsmith        if (!ChildNode)
42867754Smsmith        {
42967754Smsmith            Status = AE_BAD_PARAMETER;
43067754Smsmith            goto UnlockAndExit;
43167754Smsmith        }
43267754Smsmith    }
43367754Smsmith
43467754Smsmith
43567754Smsmith    /* Internal function does the real work */
43667754Smsmith
43785756Smsmith    Node = AcpiNsGetNextNode ((ACPI_OBJECT_TYPE8) Type,
43867754Smsmith                                    ParentNode, ChildNode);
43967754Smsmith    if (!Node)
44067754Smsmith    {
44167754Smsmith        Status = AE_NOT_FOUND;
44267754Smsmith        goto UnlockAndExit;
44367754Smsmith    }
44467754Smsmith
44567754Smsmith    if (RetHandle)
44667754Smsmith    {
44767754Smsmith        *RetHandle = AcpiNsConvertEntryToHandle (Node);
44867754Smsmith    }
44967754Smsmith
45067754Smsmith
45167754SmsmithUnlockAndExit:
45267754Smsmith
45377424Smsmith    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
45467754Smsmith    return (Status);
45567754Smsmith}
45667754Smsmith
45767754Smsmith
45867754Smsmith/*******************************************************************************
45967754Smsmith *
46067754Smsmith * FUNCTION:    AcpiGetType
46167754Smsmith *
46267754Smsmith * PARAMETERS:  Handle          - Handle of object whose type is desired
46367754Smsmith *              *RetType        - Where the type will be placed
46467754Smsmith *
46567754Smsmith * RETURN:      Status
46667754Smsmith *
46767754Smsmith * DESCRIPTION: This routine returns the type associatd with a particular handle
46867754Smsmith *
46967754Smsmith ******************************************************************************/
47067754Smsmith
47167754SmsmithACPI_STATUS
47267754SmsmithAcpiGetType (
47367754Smsmith    ACPI_HANDLE             Handle,
47467754Smsmith    ACPI_OBJECT_TYPE        *RetType)
47567754Smsmith{
47667754Smsmith    ACPI_NAMESPACE_NODE     *Node;
47767754Smsmith
47867754Smsmith
47967754Smsmith    /* Parameter Validation */
48067754Smsmith
48167754Smsmith    if (!RetType)
48267754Smsmith    {
48367754Smsmith        return (AE_BAD_PARAMETER);
48467754Smsmith    }
48567754Smsmith
48667754Smsmith    /*
48767754Smsmith     * Special case for the predefined Root Node
48867754Smsmith     * (return type ANY)
48967754Smsmith     */
49067754Smsmith    if (Handle == ACPI_ROOT_OBJECT)
49167754Smsmith    {
49267754Smsmith        *RetType = ACPI_TYPE_ANY;
49367754Smsmith        return (AE_OK);
49467754Smsmith    }
49567754Smsmith
49677424Smsmith    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
49767754Smsmith
49867754Smsmith    /* Convert and validate the handle */
49967754Smsmith
50085756Smsmith    Node = AcpiNsMapHandleToNode (Handle);
50167754Smsmith    if (!Node)
50267754Smsmith    {
50377424Smsmith        AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
50467754Smsmith        return (AE_BAD_PARAMETER);
50567754Smsmith    }
50667754Smsmith
50767754Smsmith    *RetType = Node->Type;
50867754Smsmith
50967754Smsmith
51077424Smsmith    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
51167754Smsmith    return (AE_OK);
51267754Smsmith}
51367754Smsmith
51467754Smsmith
51567754Smsmith/*******************************************************************************
51667754Smsmith *
51767754Smsmith * FUNCTION:    AcpiGetParent
51867754Smsmith *
51967754Smsmith * PARAMETERS:  Handle          - Handle of object whose parent is desired
52067754Smsmith *              RetHandle       - Where the parent handle will be placed
52167754Smsmith *
52267754Smsmith * RETURN:      Status
52367754Smsmith *
52467754Smsmith * DESCRIPTION: Returns a handle to the parent of the object represented by
52567754Smsmith *              Handle.
52667754Smsmith *
52767754Smsmith ******************************************************************************/
52867754Smsmith
52967754SmsmithACPI_STATUS
53067754SmsmithAcpiGetParent (
53167754Smsmith    ACPI_HANDLE             Handle,
53267754Smsmith    ACPI_HANDLE             *RetHandle)
53367754Smsmith{
53467754Smsmith    ACPI_NAMESPACE_NODE     *Node;
53567754Smsmith    ACPI_STATUS             Status = AE_OK;
53667754Smsmith
53767754Smsmith
53867754Smsmith    if (!RetHandle)
53967754Smsmith    {
54067754Smsmith        return (AE_BAD_PARAMETER);
54167754Smsmith    }
54267754Smsmith
54367754Smsmith    /* Special case for the predefined Root Node (no parent) */
54467754Smsmith
54567754Smsmith    if (Handle == ACPI_ROOT_OBJECT)
54667754Smsmith    {
54767754Smsmith        return (AE_NULL_ENTRY);
54867754Smsmith    }
54967754Smsmith
55067754Smsmith
55177424Smsmith    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
55267754Smsmith
55367754Smsmith    /* Convert and validate the handle */
55467754Smsmith
55585756Smsmith    Node = AcpiNsMapHandleToNode (Handle);
55667754Smsmith    if (!Node)
55767754Smsmith    {
55867754Smsmith        Status = AE_BAD_PARAMETER;
55967754Smsmith        goto UnlockAndExit;
56067754Smsmith    }
56167754Smsmith
56267754Smsmith
56367754Smsmith    /* Get the parent entry */
56467754Smsmith
56567754Smsmith    *RetHandle =
56667754Smsmith        AcpiNsConvertEntryToHandle (AcpiNsGetParentObject (Node));
56767754Smsmith
56867754Smsmith    /* Return exeption if parent is null */
56967754Smsmith
57067754Smsmith    if (!AcpiNsGetParentObject (Node))
57167754Smsmith    {
57267754Smsmith        Status = AE_NULL_ENTRY;
57367754Smsmith    }
57467754Smsmith
57567754Smsmith
57667754SmsmithUnlockAndExit:
57767754Smsmith
57877424Smsmith    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
57967754Smsmith    return (Status);
58067754Smsmith}
58167754Smsmith
58267754Smsmith
58367754Smsmith/*******************************************************************************
58467754Smsmith *
58567754Smsmith * FUNCTION:    AcpiWalkNamespace
58667754Smsmith *
58767754Smsmith * PARAMETERS:  Type                - ACPI_OBJECT_TYPE to search for
58867754Smsmith *              StartObject         - Handle in namespace where search begins
58967754Smsmith *              MaxDepth            - Depth to which search is to reach
59067754Smsmith *              UserFunction        - Called when an object of "Type" is found
59167754Smsmith *              Context             - Passed to user function
59267754Smsmith *              ReturnValue         - Location where return value of
59367754Smsmith *                                    UserFunction is put if terminated early
59467754Smsmith *
59567754Smsmith * RETURNS      Return value from the UserFunction if terminated early.
59667754Smsmith *              Otherwise, returns NULL.
59767754Smsmith *
59867754Smsmith * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
59967754Smsmith *              starting (and ending) at the object specified by StartHandle.
60067754Smsmith *              The UserFunction is called whenever an object that matches
60167754Smsmith *              the type parameter is found.  If the user function returns
60267754Smsmith *              a non-zero value, the search is terminated immediately and this
60367754Smsmith *              value is returned to the caller.
60467754Smsmith *
60567754Smsmith *              The point of this procedure is to provide a generic namespace
60667754Smsmith *              walk routine that can be called from multiple places to
60767754Smsmith *              provide multiple services;  the User Function can be tailored
60867754Smsmith *              to each task, whether it is a print function, a compare
60967754Smsmith *              function, etc.
61067754Smsmith *
61167754Smsmith ******************************************************************************/
61267754Smsmith
61367754SmsmithACPI_STATUS
61467754SmsmithAcpiWalkNamespace (
61567754Smsmith    ACPI_OBJECT_TYPE        Type,
61667754Smsmith    ACPI_HANDLE             StartObject,
61767754Smsmith    UINT32                  MaxDepth,
61877424Smsmith    ACPI_WALK_CALLBACK      UserFunction,
61967754Smsmith    void                    *Context,
62067754Smsmith    void                    **ReturnValue)
62167754Smsmith{
62267754Smsmith    ACPI_STATUS             Status;
62367754Smsmith
62467754Smsmith
62567754Smsmith    FUNCTION_TRACE ("AcpiWalkNamespace");
62667754Smsmith
62767754Smsmith
62867754Smsmith    /* Parameter validation */
62967754Smsmith
63067754Smsmith    if ((Type > ACPI_TYPE_MAX)  ||
63167754Smsmith        (!MaxDepth)             ||
63267754Smsmith        (!UserFunction))
63367754Smsmith    {
63467754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
63567754Smsmith    }
63667754Smsmith
63767754Smsmith    /*
63867754Smsmith     * Lock the namespace around the walk.
63967754Smsmith     * The namespace will be unlocked/locked around each call
64067754Smsmith     * to the user function - since this function
64167754Smsmith     * must be allowed to make Acpi calls itself.
64267754Smsmith     */
64377424Smsmith    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
64487031Smsmith    Status = AcpiNsWalkNamespace ((ACPI_OBJECT_TYPE8) Type, StartObject,
64587031Smsmith                    MaxDepth, NS_WALK_UNLOCK, UserFunction, Context,
64684491Smsmith                    ReturnValue);
64767754Smsmith
64877424Smsmith    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
64967754Smsmith
65067754Smsmith    return_ACPI_STATUS (Status);
65167754Smsmith}
65267754Smsmith
65367754Smsmith
65467754Smsmith/*******************************************************************************
65567754Smsmith *
65667754Smsmith * FUNCTION:    AcpiNsGetDeviceCallback
65767754Smsmith *
65867754Smsmith * PARAMETERS:  Callback from AcpiGetDevice
65967754Smsmith *
66067754Smsmith * RETURN:      Status
66167754Smsmith *
66267754Smsmith * DESCRIPTION: Takes callbacks from WalkNamespace and filters out all non-
66367754Smsmith *              present devices, or if they specified a HID, it filters based
66467754Smsmith *              on that.
66567754Smsmith *
66667754Smsmith ******************************************************************************/
66767754Smsmith
66867754Smsmithstatic ACPI_STATUS
66967754SmsmithAcpiNsGetDeviceCallback (
67067754Smsmith    ACPI_HANDLE             ObjHandle,
67167754Smsmith    UINT32                  NestingLevel,
67267754Smsmith    void                    *Context,
67367754Smsmith    void                    **ReturnValue)
67467754Smsmith{
67567754Smsmith    ACPI_STATUS             Status;
67667754Smsmith    ACPI_NAMESPACE_NODE     *Node;
67767754Smsmith    UINT32                  Flags;
67887031Smsmith    ACPI_DEVICE_ID          Hid;
67987031Smsmith    ACPI_DEVICE_ID          Cid;
68067754Smsmith    ACPI_GET_DEVICES_INFO   *Info;
68167754Smsmith
68267754Smsmith
68367754Smsmith    Info = Context;
68467754Smsmith
68577424Smsmith    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
68685756Smsmith    Node = AcpiNsMapHandleToNode (ObjHandle);
68777424Smsmith    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
68873561Smsmith
68967754Smsmith    if (!Node)
69067754Smsmith    {
69167754Smsmith        return (AE_BAD_PARAMETER);
69267754Smsmith    }
69367754Smsmith
69467754Smsmith    /*
69567754Smsmith     * Run _STA to determine if device is present
69667754Smsmith     */
69777424Smsmith    Status = AcpiUtExecute_STA (Node, &Flags);
69867754Smsmith    if (ACPI_FAILURE (Status))
69967754Smsmith    {
70077424Smsmith        return (AE_CTRL_DEPTH);
70167754Smsmith    }
70267754Smsmith
70367754Smsmith    if (!(Flags & 0x01))
70467754Smsmith    {
70587031Smsmith        /* Don't return at the device or children of the device if not there */
70667754Smsmith        return (AE_CTRL_DEPTH);
70767754Smsmith    }
70867754Smsmith
70967754Smsmith    /*
71087031Smsmith     * Filter based on device HID & CID
71167754Smsmith     */
71267754Smsmith    if (Info->Hid != NULL)
71367754Smsmith    {
71487031Smsmith        Status = AcpiUtExecute_HID (Node, &Hid);
71567754Smsmith        if (Status == AE_NOT_FOUND)
71667754Smsmith        {
71767754Smsmith            return (AE_OK);
71867754Smsmith        }
71967754Smsmith
72067754Smsmith        else if (ACPI_FAILURE (Status))
72167754Smsmith        {
72277424Smsmith            return (AE_CTRL_DEPTH);
72367754Smsmith        }
72467754Smsmith
72587031Smsmith        if (STRNCMP (Hid.Buffer, Info->Hid, sizeof (Hid.Buffer)) != 0)
72667754Smsmith        {
72787031Smsmith            Status = AcpiUtExecute_CID (Node, &Cid);
72887031Smsmith            if (Status == AE_NOT_FOUND)
72987031Smsmith            {
73087031Smsmith                return (AE_OK);
73187031Smsmith            }
73287031Smsmith
73387031Smsmith            else if (ACPI_FAILURE (Status))
73487031Smsmith            {
73587031Smsmith                return (AE_CTRL_DEPTH);
73687031Smsmith            }
73787031Smsmith
73887031Smsmith            /* TBD: Handle CID packages */
73987031Smsmith
74087031Smsmith            if (STRNCMP (Cid.Buffer, Info->Hid, sizeof (Cid.Buffer)) != 0)
74187031Smsmith            {
74287031Smsmith                return (AE_OK);
74387031Smsmith            }
74467754Smsmith        }
74567754Smsmith    }
74667754Smsmith
74767754Smsmith    Info->UserFunction (ObjHandle, NestingLevel, Info->Context, ReturnValue);
74867754Smsmith    return (AE_OK);
74967754Smsmith}
75067754Smsmith
75167754Smsmith
75267754Smsmith/*******************************************************************************
75367754Smsmith *
75467754Smsmith * FUNCTION:    AcpiGetDevices
75567754Smsmith *
75667754Smsmith * PARAMETERS:  HID                 - HID to search for. Can be NULL.
75767754Smsmith *              UserFunction        - Called when a matching object is found
75867754Smsmith *              Context             - Passed to user function
75967754Smsmith *              ReturnValue         - Location where return value of
76067754Smsmith *                                    UserFunction is put if terminated early
76167754Smsmith *
76267754Smsmith * RETURNS      Return value from the UserFunction if terminated early.
76367754Smsmith *              Otherwise, returns NULL.
76467754Smsmith *
76567754Smsmith * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
76667754Smsmith *              starting (and ending) at the object specified by StartHandle.
76767754Smsmith *              The UserFunction is called whenever an object that matches
76867754Smsmith *              the type parameter is found.  If the user function returns
76967754Smsmith *              a non-zero value, the search is terminated immediately and this
77067754Smsmith *              value is returned to the caller.
77167754Smsmith *
77267754Smsmith *              This is a wrapper for WalkNamespace, but the callback performs
77367754Smsmith *              additional filtering. Please see AcpiGetDeviceCallback.
77467754Smsmith *
77567754Smsmith ******************************************************************************/
77667754Smsmith
77767754SmsmithACPI_STATUS
77867754SmsmithAcpiGetDevices (
77967754Smsmith    NATIVE_CHAR             *HID,
78077424Smsmith    ACPI_WALK_CALLBACK      UserFunction,
78167754Smsmith    void                    *Context,
78267754Smsmith    void                    **ReturnValue)
78367754Smsmith{
78467754Smsmith    ACPI_STATUS             Status;
78567754Smsmith    ACPI_GET_DEVICES_INFO   Info;
78667754Smsmith
78767754Smsmith
78867754Smsmith    FUNCTION_TRACE ("AcpiGetDevices");
78967754Smsmith
79067754Smsmith
79167754Smsmith    /* Parameter validation */
79267754Smsmith
79367754Smsmith    if (!UserFunction)
79467754Smsmith    {
79567754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
79667754Smsmith    }
79767754Smsmith
79867754Smsmith    /*
79967754Smsmith     * We're going to call their callback from OUR callback, so we need
80067754Smsmith     * to know what it is, and their context parameter.
80167754Smsmith     */
80267754Smsmith    Info.Context      = Context;
80367754Smsmith    Info.UserFunction = UserFunction;
80467754Smsmith    Info.Hid          = HID;
80567754Smsmith
80667754Smsmith    /*
80767754Smsmith     * Lock the namespace around the walk.
80867754Smsmith     * The namespace will be unlocked/locked around each call
80967754Smsmith     * to the user function - since this function
81067754Smsmith     * must be allowed to make Acpi calls itself.
81167754Smsmith     */
81277424Smsmith    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
81367754Smsmith    Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE,
81467754Smsmith                                    ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
81567754Smsmith                                    NS_WALK_UNLOCK,
81667754Smsmith                                    AcpiNsGetDeviceCallback, &Info,
81767754Smsmith                                    ReturnValue);
81867754Smsmith
81977424Smsmith    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
82067754Smsmith
82167754Smsmith    return_ACPI_STATUS (Status);
82269450Smsmith}
82387031Smsmith
82487031Smsmith
82587031Smsmith/*******************************************************************************
82687031Smsmith *
82787031Smsmith * FUNCTION:    AcpiAttachData
82887031Smsmith *
82987031Smsmith * PARAMETERS:
83087031Smsmith *
83187031Smsmith * RETURN:      Status
83287031Smsmith *
83387031Smsmith * DESCRIPTION:
83487031Smsmith *
83587031Smsmith ******************************************************************************/
83687031Smsmith
83787031SmsmithACPI_STATUS
83887031SmsmithAcpiAttachData (
83987031Smsmith    ACPI_HANDLE             ObjHandle,
84087031Smsmith    ACPI_OBJECT_HANDLER     Handler,
84187031Smsmith    void                    *Data)
84287031Smsmith{
84387031Smsmith    ACPI_NAMESPACE_NODE     *Node;
84487031Smsmith    ACPI_STATUS             Status;
84587031Smsmith
84687031Smsmith
84787031Smsmith    /* Parameter validation */
84887031Smsmith
84987031Smsmith    if (!ObjHandle  ||
85087031Smsmith        !Handler    ||
85187031Smsmith        !Data)
85287031Smsmith    {
85387031Smsmith        return (AE_BAD_PARAMETER);
85487031Smsmith    }
85587031Smsmith
85687031Smsmith
85787031Smsmith    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
85887031Smsmith
85987031Smsmith    /* Convert and validate the handle */
86087031Smsmith
86187031Smsmith    Node = AcpiNsMapHandleToNode (ObjHandle);
86287031Smsmith    if (!Node)
86387031Smsmith    {
86487031Smsmith        Status = AE_BAD_PARAMETER;
86587031Smsmith        goto UnlockAndExit;
86687031Smsmith    }
86787031Smsmith
86887031Smsmith    Status = AcpiNsAttachData (Node, Handler, Data);
86987031Smsmith
87087031SmsmithUnlockAndExit:
87187031Smsmith
87287031Smsmith    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
87387031Smsmith    return (Status);
87487031Smsmith}
87587031Smsmith
87687031Smsmith
87787031Smsmith/*******************************************************************************
87887031Smsmith *
87987031Smsmith * FUNCTION:    AcpiDetachData
88087031Smsmith *
88187031Smsmith * PARAMETERS:
88287031Smsmith *
88387031Smsmith * RETURN:      Status
88487031Smsmith *
88587031Smsmith * DESCRIPTION:
88687031Smsmith *
88787031Smsmith ******************************************************************************/
88887031Smsmith
88987031SmsmithACPI_STATUS
89087031SmsmithAcpiDetachData (
89187031Smsmith    ACPI_HANDLE             ObjHandle,
89287031Smsmith    ACPI_OBJECT_HANDLER     Handler)
89387031Smsmith{
89487031Smsmith    ACPI_NAMESPACE_NODE     *Node;
89587031Smsmith    ACPI_STATUS             Status;
89687031Smsmith
89787031Smsmith
89887031Smsmith    /* Parameter validation */
89987031Smsmith
90087031Smsmith    if (!ObjHandle  ||
90187031Smsmith        !Handler)
90287031Smsmith    {
90387031Smsmith        return (AE_BAD_PARAMETER);
90487031Smsmith    }
90587031Smsmith
90687031Smsmith    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
90787031Smsmith
90887031Smsmith    /* Convert and validate the handle */
90987031Smsmith
91087031Smsmith    Node = AcpiNsMapHandleToNode (ObjHandle);
91187031Smsmith    if (!Node)
91287031Smsmith    {
91387031Smsmith        Status = AE_BAD_PARAMETER;
91487031Smsmith        goto UnlockAndExit;
91587031Smsmith    }
91687031Smsmith
91787031Smsmith    Status = AcpiNsDetachData (Node, Handler);
91887031Smsmith
91987031SmsmithUnlockAndExit:
92087031Smsmith
92187031Smsmith    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
92287031Smsmith    return (Status);
92387031Smsmith}
92487031Smsmith
92587031Smsmith
92687031Smsmith/*******************************************************************************
92787031Smsmith *
92887031Smsmith * FUNCTION:    AcpiGetData
92987031Smsmith *
93087031Smsmith * PARAMETERS:
93187031Smsmith *
93287031Smsmith * RETURN:      Status
93387031Smsmith *
93487031Smsmith * DESCRIPTION:
93587031Smsmith *
93687031Smsmith ******************************************************************************/
93787031Smsmith
93887031SmsmithACPI_STATUS
93987031SmsmithAcpiGetData (
94087031Smsmith    ACPI_HANDLE             ObjHandle,
94187031Smsmith    ACPI_OBJECT_HANDLER     Handler,
94287031Smsmith    void                    **Data)
94387031Smsmith{
94487031Smsmith    ACPI_NAMESPACE_NODE     *Node;
94587031Smsmith    ACPI_STATUS             Status;
94687031Smsmith
94787031Smsmith
94887031Smsmith    /* Parameter validation */
94987031Smsmith
95087031Smsmith    if (!ObjHandle  ||
95187031Smsmith        !Handler    ||
95287031Smsmith        !Data)
95387031Smsmith    {
95487031Smsmith        return (AE_BAD_PARAMETER);
95587031Smsmith    }
95687031Smsmith
95787031Smsmith    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
95887031Smsmith
95987031Smsmith    /* Convert and validate the handle */
96087031Smsmith
96187031Smsmith    Node = AcpiNsMapHandleToNode (ObjHandle);
96287031Smsmith    if (!Node)
96387031Smsmith    {
96487031Smsmith        Status = AE_BAD_PARAMETER;
96587031Smsmith        goto UnlockAndExit;
96687031Smsmith    }
96787031Smsmith
96887031Smsmith    Status = AcpiNsGetAttachedData (Node, Handler, Data);
96987031Smsmith
97087031SmsmithUnlockAndExit:
97187031Smsmith
97287031Smsmith    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
97387031Smsmith    return (Status);
97487031Smsmith}
97587031Smsmith
97687031Smsmith
97787031Smsmith
978