nsxfobj.c revision 259065
1258945Sroberto/*******************************************************************************
2280849Scy *
3258945Sroberto * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4258945Sroberto *                         ACPI Object oriented interfaces
5258945Sroberto *
6258945Sroberto ******************************************************************************/
7258945Sroberto
8258945Sroberto/*
9258945Sroberto * Copyright (C) 2000 - 2013, Intel Corp.
10258945Sroberto * All rights reserved.
11258945Sroberto *
12258945Sroberto * Redistribution and use in source and binary forms, with or without
13258945Sroberto * modification, are permitted provided that the following conditions
14258945Sroberto * are met:
15258945Sroberto * 1. Redistributions of source code must retain the above copyright
16258945Sroberto *    notice, this list of conditions, and the following disclaimer,
17258945Sroberto *    without modification.
18280849Scy * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19258945Sroberto *    substantially similar to the "NO WARRANTY" disclaimer below
20258945Sroberto *    ("Disclaimer") and any redistribution must be conditioned upon
21258945Sroberto *    including a substantially similar Disclaimer requirement for further
22258945Sroberto *    binary redistribution.
23258945Sroberto * 3. Neither the names of the above-listed copyright holders nor the names
24258945Sroberto *    of any contributors may be used to endorse or promote products derived
25258945Sroberto *    from this software without specific prior written permission.
26258945Sroberto *
27258945Sroberto * Alternatively, this software may be distributed under the terms of the
28258945Sroberto * GNU General Public License ("GPL") version 2 as published by the Free
29258945Sroberto * Software Foundation.
30258945Sroberto *
31258945Sroberto * NO WARRANTY
32258945Sroberto * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33258945Sroberto * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34258945Sroberto * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35258945Sroberto * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36258945Sroberto * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37258945Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38258945Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39258945Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40280849Scy * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41258945Sroberto * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42258945Sroberto * POSSIBILITY OF SUCH DAMAGES.
43258945Sroberto */
44258945Sroberto
45280849Scy
46258945Sroberto#define __NSXFOBJ_C__
47258945Sroberto
48258945Sroberto#include <contrib/dev/acpica/include/acpi.h>
49258945Sroberto#include <contrib/dev/acpica/include/accommon.h>
50258945Sroberto#include <contrib/dev/acpica/include/acnamesp.h>
51280849Scy
52258945Sroberto
53258945Sroberto#define _COMPONENT          ACPI_NAMESPACE
54258945Sroberto        ACPI_MODULE_NAME    ("nsxfobj")
55258945Sroberto
56258945Sroberto/*******************************************************************************
57258945Sroberto *
58258945Sroberto * FUNCTION:    AcpiGetType
59258945Sroberto *
60258945Sroberto * PARAMETERS:  Handle          - Handle of object whose type is desired
61258945Sroberto *              RetType         - Where the type will be placed
62258945Sroberto *
63258945Sroberto * RETURN:      Status
64258945Sroberto *
65258945Sroberto * DESCRIPTION: This routine returns the type associatd with a particular handle
66258945Sroberto *
67258945Sroberto ******************************************************************************/
68280849Scy
69258945SrobertoACPI_STATUS
70258945SrobertoAcpiGetType (
71258945Sroberto    ACPI_HANDLE             Handle,
72258945Sroberto    ACPI_OBJECT_TYPE        *RetType)
73258945Sroberto{
74258945Sroberto    ACPI_NAMESPACE_NODE     *Node;
75258945Sroberto    ACPI_STATUS             Status;
76258945Sroberto
77258945Sroberto
78258945Sroberto    /* Parameter Validation */
79258945Sroberto
80258945Sroberto    if (!RetType)
81258945Sroberto    {
82258945Sroberto        return (AE_BAD_PARAMETER);
83258945Sroberto    }
84258945Sroberto
85258945Sroberto    /*
86258945Sroberto     * Special case for the predefined Root Node
87258945Sroberto     * (return type ANY)
88258945Sroberto     */
89258945Sroberto    if (Handle == ACPI_ROOT_OBJECT)
90258945Sroberto    {
91258945Sroberto        *RetType = ACPI_TYPE_ANY;
92258945Sroberto        return (AE_OK);
93258945Sroberto    }
94258945Sroberto
95258945Sroberto    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
96258945Sroberto    if (ACPI_FAILURE (Status))
97258945Sroberto    {
98258945Sroberto        return (Status);
99258945Sroberto    }
100258945Sroberto
101    /* Convert and validate the handle */
102
103    Node = AcpiNsValidateHandle (Handle);
104    if (!Node)
105    {
106        (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
107        return (AE_BAD_PARAMETER);
108    }
109
110    *RetType = Node->Type;
111
112
113    Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
114    return (Status);
115}
116
117ACPI_EXPORT_SYMBOL (AcpiGetType)
118
119
120/*******************************************************************************
121 *
122 * FUNCTION:    AcpiGetParent
123 *
124 * PARAMETERS:  Handle          - Handle of object whose parent is desired
125 *              RetHandle       - Where the parent handle will be placed
126 *
127 * RETURN:      Status
128 *
129 * DESCRIPTION: Returns a handle to the parent of the object represented by
130 *              Handle.
131 *
132 ******************************************************************************/
133
134ACPI_STATUS
135AcpiGetParent (
136    ACPI_HANDLE             Handle,
137    ACPI_HANDLE             *RetHandle)
138{
139    ACPI_NAMESPACE_NODE     *Node;
140    ACPI_NAMESPACE_NODE     *ParentNode;
141    ACPI_STATUS             Status;
142
143
144    if (!RetHandle)
145    {
146        return (AE_BAD_PARAMETER);
147    }
148
149    /* Special case for the predefined Root Node (no parent) */
150
151    if (Handle == ACPI_ROOT_OBJECT)
152    {
153        return (AE_NULL_ENTRY);
154    }
155
156    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
157    if (ACPI_FAILURE (Status))
158    {
159        return (Status);
160    }
161
162    /* Convert and validate the handle */
163
164    Node = AcpiNsValidateHandle (Handle);
165    if (!Node)
166    {
167        Status = AE_BAD_PARAMETER;
168        goto UnlockAndExit;
169    }
170
171    /* Get the parent entry */
172
173    ParentNode = Node->Parent;
174    *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode);
175
176    /* Return exception if parent is null */
177
178    if (!ParentNode)
179    {
180        Status = AE_NULL_ENTRY;
181    }
182
183
184UnlockAndExit:
185
186    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
187    return (Status);
188}
189
190ACPI_EXPORT_SYMBOL (AcpiGetParent)
191
192
193/*******************************************************************************
194 *
195 * FUNCTION:    AcpiGetNextObject
196 *
197 * PARAMETERS:  Type            - Type of object to be searched for
198 *              Parent          - Parent object whose children we are getting
199 *              LastChild       - Previous child that was found.
200 *                                The NEXT child will be returned
201 *              RetHandle       - Where handle to the next object is placed
202 *
203 * RETURN:      Status
204 *
205 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
206 *              valid, Scope is ignored. Otherwise, the first object within
207 *              Scope is returned.
208 *
209 ******************************************************************************/
210
211ACPI_STATUS
212AcpiGetNextObject (
213    ACPI_OBJECT_TYPE        Type,
214    ACPI_HANDLE             Parent,
215    ACPI_HANDLE             Child,
216    ACPI_HANDLE             *RetHandle)
217{
218    ACPI_STATUS             Status;
219    ACPI_NAMESPACE_NODE     *Node;
220    ACPI_NAMESPACE_NODE     *ParentNode = NULL;
221    ACPI_NAMESPACE_NODE     *ChildNode = NULL;
222
223
224    /* Parameter validation */
225
226    if (Type > ACPI_TYPE_EXTERNAL_MAX)
227    {
228        return (AE_BAD_PARAMETER);
229    }
230
231    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
232    if (ACPI_FAILURE (Status))
233    {
234        return (Status);
235    }
236
237    /* If null handle, use the parent */
238
239    if (!Child)
240    {
241        /* Start search at the beginning of the specified scope */
242
243        ParentNode = AcpiNsValidateHandle (Parent);
244        if (!ParentNode)
245        {
246            Status = AE_BAD_PARAMETER;
247            goto UnlockAndExit;
248        }
249    }
250    else
251    {
252        /* Non-null handle, ignore the parent */
253        /* Convert and validate the handle */
254
255        ChildNode = AcpiNsValidateHandle (Child);
256        if (!ChildNode)
257        {
258            Status = AE_BAD_PARAMETER;
259            goto UnlockAndExit;
260        }
261    }
262
263    /* Internal function does the real work */
264
265    Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode);
266    if (!Node)
267    {
268        Status = AE_NOT_FOUND;
269        goto UnlockAndExit;
270    }
271
272    if (RetHandle)
273    {
274        *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
275    }
276
277
278UnlockAndExit:
279
280    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
281    return (Status);
282}
283
284ACPI_EXPORT_SYMBOL (AcpiGetNextObject)
285