167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
467754Smsmith *                         ACPI Object oriented interfaces
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
8217365Sjkim/*
9245582Sjkim * Copyright (C) 2000 - 2013, Intel Corp.
1070243Smsmith * All rights reserved.
1167754Smsmith *
12217365Sjkim * Redistribution and use in source and binary forms, with or without
13217365Sjkim * modification, are permitted provided that the following conditions
14217365Sjkim * are met:
15217365Sjkim * 1. Redistributions of source code must retain the above copyright
16217365Sjkim *    notice, this list of conditions, and the following disclaimer,
17217365Sjkim *    without modification.
18217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
20217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
21217365Sjkim *    including a substantially similar Disclaimer requirement for further
22217365Sjkim *    binary redistribution.
23217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
24217365Sjkim *    of any contributors may be used to endorse or promote products derived
25217365Sjkim *    from this software without specific prior written permission.
2667754Smsmith *
27217365Sjkim * Alternatively, this software may be distributed under the terms of the
28217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
29217365Sjkim * Software Foundation.
3067754Smsmith *
31217365Sjkim * NO WARRANTY
32217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
43217365Sjkim */
4467754Smsmith
4567754Smsmith
4667754Smsmith#define __NSXFOBJ_C__
4767754Smsmith
48193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
49193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
50193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
5167754Smsmith
5267754Smsmith
5377424Smsmith#define _COMPONENT          ACPI_NAMESPACE
5491116Smsmith        ACPI_MODULE_NAME    ("nsxfobj")
5567754Smsmith
5667754Smsmith/*******************************************************************************
5767754Smsmith *
5867754Smsmith * FUNCTION:    AcpiGetType
5967754Smsmith *
6067754Smsmith * PARAMETERS:  Handle          - Handle of object whose type is desired
61151937Sjkim *              RetType         - Where the type will be placed
6267754Smsmith *
6367754Smsmith * RETURN:      Status
6467754Smsmith *
6567754Smsmith * DESCRIPTION: This routine returns the type associatd with a particular handle
6667754Smsmith *
6767754Smsmith ******************************************************************************/
6867754Smsmith
6967754SmsmithACPI_STATUS
7067754SmsmithAcpiGetType (
7167754Smsmith    ACPI_HANDLE             Handle,
7267754Smsmith    ACPI_OBJECT_TYPE        *RetType)
7367754Smsmith{
7467754Smsmith    ACPI_NAMESPACE_NODE     *Node;
7591116Smsmith    ACPI_STATUS             Status;
7667754Smsmith
7767754Smsmith
7867754Smsmith    /* Parameter Validation */
7967754Smsmith
8067754Smsmith    if (!RetType)
8167754Smsmith    {
8267754Smsmith        return (AE_BAD_PARAMETER);
8367754Smsmith    }
8467754Smsmith
8567754Smsmith    /*
8667754Smsmith     * Special case for the predefined Root Node
8767754Smsmith     * (return type ANY)
8867754Smsmith     */
8967754Smsmith    if (Handle == ACPI_ROOT_OBJECT)
9067754Smsmith    {
9167754Smsmith        *RetType = ACPI_TYPE_ANY;
9267754Smsmith        return (AE_OK);
9367754Smsmith    }
9467754Smsmith
9591116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
9691116Smsmith    if (ACPI_FAILURE (Status))
9791116Smsmith    {
9891116Smsmith        return (Status);
9991116Smsmith    }
10067754Smsmith
10167754Smsmith    /* Convert and validate the handle */
10267754Smsmith
103200553Sjkim    Node = AcpiNsValidateHandle (Handle);
10467754Smsmith    if (!Node)
10567754Smsmith    {
10691116Smsmith        (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
10767754Smsmith        return (AE_BAD_PARAMETER);
10867754Smsmith    }
10967754Smsmith
11067754Smsmith    *RetType = Node->Type;
11167754Smsmith
11267754Smsmith
11391116Smsmith    Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
11491116Smsmith    return (Status);
11567754Smsmith}
11667754Smsmith
117167802SjkimACPI_EXPORT_SYMBOL (AcpiGetType)
11867754Smsmith
119167802Sjkim
12067754Smsmith/*******************************************************************************
12167754Smsmith *
12267754Smsmith * FUNCTION:    AcpiGetParent
12367754Smsmith *
12467754Smsmith * PARAMETERS:  Handle          - Handle of object whose parent is desired
12567754Smsmith *              RetHandle       - Where the parent handle will be placed
12667754Smsmith *
12767754Smsmith * RETURN:      Status
12867754Smsmith *
12967754Smsmith * DESCRIPTION: Returns a handle to the parent of the object represented by
13067754Smsmith *              Handle.
13167754Smsmith *
13267754Smsmith ******************************************************************************/
13367754Smsmith
13467754SmsmithACPI_STATUS
13567754SmsmithAcpiGetParent (
13667754Smsmith    ACPI_HANDLE             Handle,
13767754Smsmith    ACPI_HANDLE             *RetHandle)
13867754Smsmith{
13967754Smsmith    ACPI_NAMESPACE_NODE     *Node;
140193267Sjkim    ACPI_NAMESPACE_NODE     *ParentNode;
14191116Smsmith    ACPI_STATUS             Status;
14267754Smsmith
14367754Smsmith
14467754Smsmith    if (!RetHandle)
14567754Smsmith    {
14667754Smsmith        return (AE_BAD_PARAMETER);
14767754Smsmith    }
14867754Smsmith
14967754Smsmith    /* Special case for the predefined Root Node (no parent) */
15067754Smsmith
15167754Smsmith    if (Handle == ACPI_ROOT_OBJECT)
15267754Smsmith    {
15367754Smsmith        return (AE_NULL_ENTRY);
15467754Smsmith    }
15567754Smsmith
15691116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
15791116Smsmith    if (ACPI_FAILURE (Status))
15891116Smsmith    {
15991116Smsmith        return (Status);
16091116Smsmith    }
16167754Smsmith
16267754Smsmith    /* Convert and validate the handle */
16367754Smsmith
164200553Sjkim    Node = AcpiNsValidateHandle (Handle);
16567754Smsmith    if (!Node)
16667754Smsmith    {
16767754Smsmith        Status = AE_BAD_PARAMETER;
16867754Smsmith        goto UnlockAndExit;
16967754Smsmith    }
17067754Smsmith
17167754Smsmith    /* Get the parent entry */
17267754Smsmith
173209746Sjkim    ParentNode = Node->Parent;
174200553Sjkim    *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode);
17567754Smsmith
176114237Snjl    /* Return exception if parent is null */
17767754Smsmith
178193267Sjkim    if (!ParentNode)
17967754Smsmith    {
18067754Smsmith        Status = AE_NULL_ENTRY;
18167754Smsmith    }
18267754Smsmith
18367754Smsmith
18467754SmsmithUnlockAndExit:
18567754Smsmith
18691116Smsmith    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
18767754Smsmith    return (Status);
18867754Smsmith}
18967754Smsmith
190167802SjkimACPI_EXPORT_SYMBOL (AcpiGetParent)
19167754Smsmith
192167802Sjkim
19367754Smsmith/*******************************************************************************
19467754Smsmith *
195100966Siwasaki * FUNCTION:    AcpiGetNextObject
19667754Smsmith *
197100966Siwasaki * PARAMETERS:  Type            - Type of object to be searched for
198100966Siwasaki *              Parent          - Parent object whose children we are getting
199100966Siwasaki *              LastChild       - Previous child that was found.
200100966Siwasaki *                                The NEXT child will be returned
201100966Siwasaki *              RetHandle       - Where handle to the next object is placed
20267754Smsmith *
203100966Siwasaki * RETURN:      Status
20467754Smsmith *
205241973Sjkim * DESCRIPTION: Return the next peer object within the namespace. If Handle is
206241973Sjkim *              valid, Scope is ignored. Otherwise, the first object within
207100966Siwasaki *              Scope is returned.
20867754Smsmith *
20967754Smsmith ******************************************************************************/
21067754Smsmith
21167754SmsmithACPI_STATUS
212100966SiwasakiAcpiGetNextObject (
21367754Smsmith    ACPI_OBJECT_TYPE        Type,
214100966Siwasaki    ACPI_HANDLE             Parent,
215100966Siwasaki    ACPI_HANDLE             Child,
216100966Siwasaki    ACPI_HANDLE             *RetHandle)
21767754Smsmith{
21867754Smsmith    ACPI_STATUS             Status;
219100966Siwasaki    ACPI_NAMESPACE_NODE     *Node;
220100966Siwasaki    ACPI_NAMESPACE_NODE     *ParentNode = NULL;
221100966Siwasaki    ACPI_NAMESPACE_NODE     *ChildNode = NULL;
22267754Smsmith
22367754Smsmith
22467754Smsmith    /* Parameter validation */
22567754Smsmith
226107325Siwasaki    if (Type > ACPI_TYPE_EXTERNAL_MAX)
22767754Smsmith    {
228100966Siwasaki        return (AE_BAD_PARAMETER);
22967754Smsmith    }
23067754Smsmith
23191116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
23291116Smsmith    if (ACPI_FAILURE (Status))
23391116Smsmith    {
23491116Smsmith        return (Status);
23591116Smsmith    }
23691116Smsmith
237100966Siwasaki    /* If null handle, use the parent */
23873561Smsmith
239100966Siwasaki    if (!Child)
24067754Smsmith    {
241100966Siwasaki        /* Start search at the beginning of the specified scope */
24267754Smsmith
243200553Sjkim        ParentNode = AcpiNsValidateHandle (Parent);
244100966Siwasaki        if (!ParentNode)
245100966Siwasaki        {
246100966Siwasaki            Status = AE_BAD_PARAMETER;
247100966Siwasaki            goto UnlockAndExit;
248100966Siwasaki        }
24967754Smsmith    }
250100966Siwasaki    else
25167754Smsmith    {
252100966Siwasaki        /* Non-null handle, ignore the parent */
253100966Siwasaki        /* Convert and validate the handle */
25467754Smsmith
255200553Sjkim        ChildNode = AcpiNsValidateHandle (Child);
256100966Siwasaki        if (!ChildNode)
25767754Smsmith        {
258100966Siwasaki            Status = AE_BAD_PARAMETER;
259100966Siwasaki            goto UnlockAndExit;
26067754Smsmith        }
26167754Smsmith    }
26267754Smsmith
263100966Siwasaki    /* Internal function does the real work */
26467754Smsmith
265193267Sjkim    Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode);
26687031Smsmith    if (!Node)
26787031Smsmith    {
268100966Siwasaki        Status = AE_NOT_FOUND;
26987031Smsmith        goto UnlockAndExit;
27087031Smsmith    }
27187031Smsmith
272100966Siwasaki    if (RetHandle)
27387031Smsmith    {
274200553Sjkim        *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
27587031Smsmith    }
27687031Smsmith
27787031Smsmith
27887031SmsmithUnlockAndExit:
27987031Smsmith
28091116Smsmith    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
28187031Smsmith    return (Status);
28287031Smsmith}
28387031Smsmith
284167802SjkimACPI_EXPORT_SYMBOL (AcpiGetNextObject)
285