167754Smsmith/*******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
467754Smsmith *                         ACPI Object oriented interfaces
567754Smsmith *
667754Smsmith ******************************************************************************/
767754Smsmith
8217365Sjkim/*
9306536Sjkim * Copyright (C) 2000 - 2016, 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
45281075Sdim#define EXPORT_ACPI_INTERFACES
4667754Smsmith
47193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
48193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
49193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
5067754Smsmith
5167754Smsmith
5277424Smsmith#define _COMPONENT          ACPI_NAMESPACE
5391116Smsmith        ACPI_MODULE_NAME    ("nsxfobj")
5467754Smsmith
5567754Smsmith/*******************************************************************************
5667754Smsmith *
5767754Smsmith * FUNCTION:    AcpiGetType
5867754Smsmith *
5967754Smsmith * PARAMETERS:  Handle          - Handle of object whose type is desired
60151937Sjkim *              RetType         - Where the type will be placed
6167754Smsmith *
6267754Smsmith * RETURN:      Status
6367754Smsmith *
6467754Smsmith * DESCRIPTION: This routine returns the type associatd with a particular handle
6567754Smsmith *
6667754Smsmith ******************************************************************************/
6767754Smsmith
6867754SmsmithACPI_STATUS
6967754SmsmithAcpiGetType (
7067754Smsmith    ACPI_HANDLE             Handle,
7167754Smsmith    ACPI_OBJECT_TYPE        *RetType)
7267754Smsmith{
7367754Smsmith    ACPI_NAMESPACE_NODE     *Node;
7491116Smsmith    ACPI_STATUS             Status;
7567754Smsmith
7667754Smsmith
7767754Smsmith    /* Parameter Validation */
7867754Smsmith
7967754Smsmith    if (!RetType)
8067754Smsmith    {
8167754Smsmith        return (AE_BAD_PARAMETER);
8267754Smsmith    }
8367754Smsmith
84306536Sjkim    /* Special case for the predefined Root Node (return type ANY) */
85306536Sjkim
8667754Smsmith    if (Handle == ACPI_ROOT_OBJECT)
8767754Smsmith    {
8867754Smsmith        *RetType = ACPI_TYPE_ANY;
8967754Smsmith        return (AE_OK);
9067754Smsmith    }
9167754Smsmith
9291116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
9391116Smsmith    if (ACPI_FAILURE (Status))
9491116Smsmith    {
9591116Smsmith        return (Status);
9691116Smsmith    }
9767754Smsmith
9867754Smsmith    /* Convert and validate the handle */
9967754Smsmith
100200553Sjkim    Node = AcpiNsValidateHandle (Handle);
10167754Smsmith    if (!Node)
10267754Smsmith    {
10391116Smsmith        (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
10467754Smsmith        return (AE_BAD_PARAMETER);
10567754Smsmith    }
10667754Smsmith
10767754Smsmith    *RetType = Node->Type;
10867754Smsmith
10991116Smsmith    Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
11091116Smsmith    return (Status);
11167754Smsmith}
11267754Smsmith
113167802SjkimACPI_EXPORT_SYMBOL (AcpiGetType)
11467754Smsmith
115167802Sjkim
11667754Smsmith/*******************************************************************************
11767754Smsmith *
11867754Smsmith * FUNCTION:    AcpiGetParent
11967754Smsmith *
12067754Smsmith * PARAMETERS:  Handle          - Handle of object whose parent is desired
12167754Smsmith *              RetHandle       - Where the parent handle will be placed
12267754Smsmith *
12367754Smsmith * RETURN:      Status
12467754Smsmith *
12567754Smsmith * DESCRIPTION: Returns a handle to the parent of the object represented by
12667754Smsmith *              Handle.
12767754Smsmith *
12867754Smsmith ******************************************************************************/
12967754Smsmith
13067754SmsmithACPI_STATUS
13167754SmsmithAcpiGetParent (
13267754Smsmith    ACPI_HANDLE             Handle,
13367754Smsmith    ACPI_HANDLE             *RetHandle)
13467754Smsmith{
13567754Smsmith    ACPI_NAMESPACE_NODE     *Node;
136193267Sjkim    ACPI_NAMESPACE_NODE     *ParentNode;
13791116Smsmith    ACPI_STATUS             Status;
13867754Smsmith
13967754Smsmith
14067754Smsmith    if (!RetHandle)
14167754Smsmith    {
14267754Smsmith        return (AE_BAD_PARAMETER);
14367754Smsmith    }
14467754Smsmith
14567754Smsmith    /* Special case for the predefined Root Node (no parent) */
14667754Smsmith
14767754Smsmith    if (Handle == ACPI_ROOT_OBJECT)
14867754Smsmith    {
14967754Smsmith        return (AE_NULL_ENTRY);
15067754Smsmith    }
15167754Smsmith
15291116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
15391116Smsmith    if (ACPI_FAILURE (Status))
15491116Smsmith    {
15591116Smsmith        return (Status);
15691116Smsmith    }
15767754Smsmith
15867754Smsmith    /* Convert and validate the handle */
15967754Smsmith
160200553Sjkim    Node = AcpiNsValidateHandle (Handle);
16167754Smsmith    if (!Node)
16267754Smsmith    {
16367754Smsmith        Status = AE_BAD_PARAMETER;
16467754Smsmith        goto UnlockAndExit;
16567754Smsmith    }
16667754Smsmith
16767754Smsmith    /* Get the parent entry */
16867754Smsmith
169209746Sjkim    ParentNode = Node->Parent;
170200553Sjkim    *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode);
17167754Smsmith
172114237Snjl    /* Return exception if parent is null */
17367754Smsmith
174193267Sjkim    if (!ParentNode)
17567754Smsmith    {
17667754Smsmith        Status = AE_NULL_ENTRY;
17767754Smsmith    }
17867754Smsmith
17967754Smsmith
18067754SmsmithUnlockAndExit:
18167754Smsmith
18291116Smsmith    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
18367754Smsmith    return (Status);
18467754Smsmith}
18567754Smsmith
186167802SjkimACPI_EXPORT_SYMBOL (AcpiGetParent)
18767754Smsmith
188167802Sjkim
18967754Smsmith/*******************************************************************************
19067754Smsmith *
191100966Siwasaki * FUNCTION:    AcpiGetNextObject
19267754Smsmith *
193100966Siwasaki * PARAMETERS:  Type            - Type of object to be searched for
194100966Siwasaki *              Parent          - Parent object whose children we are getting
195100966Siwasaki *              LastChild       - Previous child that was found.
196100966Siwasaki *                                The NEXT child will be returned
197100966Siwasaki *              RetHandle       - Where handle to the next object is placed
19867754Smsmith *
199100966Siwasaki * RETURN:      Status
20067754Smsmith *
201241973Sjkim * DESCRIPTION: Return the next peer object within the namespace. If Handle is
202241973Sjkim *              valid, Scope is ignored. Otherwise, the first object within
203100966Siwasaki *              Scope is returned.
20467754Smsmith *
20567754Smsmith ******************************************************************************/
20667754Smsmith
20767754SmsmithACPI_STATUS
208100966SiwasakiAcpiGetNextObject (
20967754Smsmith    ACPI_OBJECT_TYPE        Type,
210100966Siwasaki    ACPI_HANDLE             Parent,
211100966Siwasaki    ACPI_HANDLE             Child,
212100966Siwasaki    ACPI_HANDLE             *RetHandle)
21367754Smsmith{
21467754Smsmith    ACPI_STATUS             Status;
215100966Siwasaki    ACPI_NAMESPACE_NODE     *Node;
216100966Siwasaki    ACPI_NAMESPACE_NODE     *ParentNode = NULL;
217100966Siwasaki    ACPI_NAMESPACE_NODE     *ChildNode = NULL;
21867754Smsmith
21967754Smsmith
22067754Smsmith    /* Parameter validation */
22167754Smsmith
222107325Siwasaki    if (Type > ACPI_TYPE_EXTERNAL_MAX)
22367754Smsmith    {
224100966Siwasaki        return (AE_BAD_PARAMETER);
22567754Smsmith    }
22667754Smsmith
22791116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
22891116Smsmith    if (ACPI_FAILURE (Status))
22991116Smsmith    {
23091116Smsmith        return (Status);
23191116Smsmith    }
23291116Smsmith
233100966Siwasaki    /* If null handle, use the parent */
23473561Smsmith
235100966Siwasaki    if (!Child)
23667754Smsmith    {
237100966Siwasaki        /* Start search at the beginning of the specified scope */
23867754Smsmith
239200553Sjkim        ParentNode = AcpiNsValidateHandle (Parent);
240100966Siwasaki        if (!ParentNode)
241100966Siwasaki        {
242100966Siwasaki            Status = AE_BAD_PARAMETER;
243100966Siwasaki            goto UnlockAndExit;
244100966Siwasaki        }
24567754Smsmith    }
246100966Siwasaki    else
24767754Smsmith    {
248100966Siwasaki        /* Non-null handle, ignore the parent */
249100966Siwasaki        /* Convert and validate the handle */
25067754Smsmith
251200553Sjkim        ChildNode = AcpiNsValidateHandle (Child);
252100966Siwasaki        if (!ChildNode)
25367754Smsmith        {
254100966Siwasaki            Status = AE_BAD_PARAMETER;
255100966Siwasaki            goto UnlockAndExit;
25667754Smsmith        }
25767754Smsmith    }
25867754Smsmith
259100966Siwasaki    /* Internal function does the real work */
26067754Smsmith
261193267Sjkim    Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode);
26287031Smsmith    if (!Node)
26387031Smsmith    {
264100966Siwasaki        Status = AE_NOT_FOUND;
26587031Smsmith        goto UnlockAndExit;
26687031Smsmith    }
26787031Smsmith
268100966Siwasaki    if (RetHandle)
26987031Smsmith    {
270200553Sjkim        *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
27187031Smsmith    }
27287031Smsmith
27387031Smsmith
27487031SmsmithUnlockAndExit:
27587031Smsmith
27691116Smsmith    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
27787031Smsmith    return (Status);
27887031Smsmith}
27987031Smsmith
280167802SjkimACPI_EXPORT_SYMBOL (AcpiGetNextObject)
281