nsxfobj.c revision 151600
1179595Sbenno/*******************************************************************************
2179595Sbenno *
3179595Sbenno * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4179595Sbenno *                         ACPI Object oriented interfaces
5179595Sbenno *              $Revision: 117 $
6179595Sbenno *
7179595Sbenno ******************************************************************************/
8179595Sbenno
9179595Sbenno/******************************************************************************
10179595Sbenno *
11179595Sbenno * 1. Copyright Notice
12179595Sbenno *
13179595Sbenno * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
14179595Sbenno * All rights reserved.
15179595Sbenno *
16179595Sbenno * 2. License
17179595Sbenno *
18179595Sbenno * 2.1. This is your license from Intel Corp. under its intellectual property
19179595Sbenno * rights.  You may have additional license terms from the party that provided
20179595Sbenno * you this software, covering your right to use that party's intellectual
21179595Sbenno * property rights.
22179595Sbenno *
23179595Sbenno * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24179595Sbenno * copy of the source code appearing in this file ("Covered Code") an
25179595Sbenno * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26179595Sbenno * base code distributed originally by Intel ("Original Intel Code") to copy,
27179595Sbenno * make derivatives, distribute, use and display any portion of the Covered
28179595Sbenno * Code in any form, with the right to sublicense such rights; and
29179595Sbenno *
30179595Sbenno * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31179595Sbenno * license (with the right to sublicense), under only those claims of Intel
32179595Sbenno * patents that are infringed by the Original Intel Code, to make, use, sell,
33179595Sbenno * offer to sell, and import the Covered Code and derivative works thereof
34179595Sbenno * solely to the minimum extent necessary to exercise the above copyright
35179595Sbenno * license, and in no event shall the patent license extend to any additions
36278613Sian * to or modifications of the Original Intel Code.  No other license or right
37179595Sbenno * is granted directly or by implication, estoppel or otherwise;
38179595Sbenno *
39179595Sbenno * The above copyright and patent license is granted only if the following
40179595Sbenno * conditions are met:
41179595Sbenno *
42179595Sbenno * 3. Conditions
43179595Sbenno *
44179595Sbenno * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45179595Sbenno * Redistribution of source code of any substantial portion of the Covered
46179595Sbenno * Code or modification with rights to further distribute source must include
47179595Sbenno * the above Copyright Notice, the above License, this list of Conditions,
48179595Sbenno * and the following Disclaimer and Export Compliance provision.  In addition,
49179595Sbenno * Licensee must cause all Covered Code to which Licensee contributes to
50179595Sbenno * contain a file documenting the changes Licensee made to create that Covered
51179595Sbenno * Code and the date of any change.  Licensee must include in that file the
52179595Sbenno * documentation of any changes made by any predecessor Licensee.  Licensee
53179595Sbenno * must include a prominent statement that the modification is derived,
54179595Sbenno * directly or indirectly, from Original Intel Code.
55179595Sbenno *
56179595Sbenno * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57179595Sbenno * Redistribution of source code of any substantial portion of the Covered
58179595Sbenno * Code or modification without rights to further distribute source must
59179595Sbenno * include the following Disclaimer and Export Compliance provision in the
60179595Sbenno * documentation and/or other materials provided with distribution.  In
61179595Sbenno * addition, Licensee may not authorize further sublicense of source of any
62179595Sbenno * portion of the Covered Code, and must include terms to the effect that the
63179595Sbenno * license from Licensee to its licensee is limited to the intellectual
64179595Sbenno * property embodied in the software Licensee provides to its licensee, and
65179595Sbenno * not to intellectual property embodied in modifications its licensee may
66179595Sbenno * make.
67179595Sbenno *
68179595Sbenno * 3.3. Redistribution of Executable. Redistribution in executable form of any
69179595Sbenno * substantial portion of the Covered Code or modification must reproduce the
70179595Sbenno * above Copyright Notice, and the following Disclaimer and Export Compliance
71179595Sbenno * provision in the documentation and/or other materials provided with the
72179595Sbenno * distribution.
73179595Sbenno *
74179595Sbenno * 3.4. Intel retains all right, title, and interest in and to the Original
75179595Sbenno * Intel Code.
76179595Sbenno *
77179595Sbenno * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78179595Sbenno * Intel shall be used in advertising or otherwise to promote the sale, use or
79179595Sbenno * other dealings in products derived from or relating to the Covered Code
80179595Sbenno * without prior written authorization from Intel.
81179595Sbenno *
82179595Sbenno * 4. Disclaimer and Export Compliance
83179595Sbenno *
84179595Sbenno * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85179595Sbenno * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86179595Sbenno * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
87179595Sbenno * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
88179595Sbenno * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
89179595Sbenno * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90179595Sbenno * PARTICULAR PURPOSE.
91179595Sbenno *
92179595Sbenno * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93179595Sbenno * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94179595Sbenno * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95179595Sbenno * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96179595Sbenno * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97179595Sbenno * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
98179595Sbenno * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99179595Sbenno * LIMITED REMEDY.
100179595Sbenno *
101179595Sbenno * 4.3. Licensee shall not export, either directly or indirectly, any of this
102179595Sbenno * software or system incorporating such software without first obtaining any
103179595Sbenno * required license or other approval from the U. S. Department of Commerce or
104179595Sbenno * any other agency or department of the United States Government.  In the
105179595Sbenno * event Licensee exports any such software from the United States or
106179595Sbenno * re-exports any such software from a foreign destination, Licensee shall
107179595Sbenno * ensure that the distribution and export/re-export of the software is in
108179595Sbenno * compliance with all laws, regulations, orders, or other restrictions of the
109278613Sian * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110179595Sbenno * any of its subsidiaries will export/re-export any technical data, process,
111179595Sbenno * software, or service, directly or indirectly, to any country for which the
112179595Sbenno * United States government or any agency thereof requires an export license,
113179595Sbenno * other governmental approval, or letter of assurance, without first obtaining
114179595Sbenno * such license, approval or letter.
115179595Sbenno *
116179595Sbenno *****************************************************************************/
117179595Sbenno
118179595Sbenno
119179595Sbenno#define __NSXFOBJ_C__
120179595Sbenno
121179595Sbenno#include <contrib/dev/acpica/acpi.h>
122179595Sbenno#include <contrib/dev/acpica/acnamesp.h>
123179595Sbenno
124179595Sbenno
125179595Sbenno#define _COMPONENT          ACPI_NAMESPACE
126179595Sbenno        ACPI_MODULE_NAME    ("nsxfobj")
127179595Sbenno
128179595Sbenno/*******************************************************************************
129179595Sbenno *
130179595Sbenno * FUNCTION:    AcpiGetType
131179595Sbenno *
132193847Smarcel * PARAMETERS:  Handle          - Handle of object whose type is desired
133179595Sbenno *              *RetType        - Where the type will be placed
134179595Sbenno *
135179595Sbenno * RETURN:      Status
136179595Sbenno *
137179595Sbenno * DESCRIPTION: This routine returns the type associatd with a particular handle
138179595Sbenno *
139179595Sbenno ******************************************************************************/
140179595Sbenno
141179595SbennoACPI_STATUS
142179595SbennoAcpiGetType (
143179595Sbenno    ACPI_HANDLE             Handle,
144179595Sbenno    ACPI_OBJECT_TYPE        *RetType)
145179595Sbenno{
146179595Sbenno    ACPI_NAMESPACE_NODE     *Node;
147179595Sbenno    ACPI_STATUS             Status;
148179595Sbenno
149179595Sbenno
150179595Sbenno    /* Parameter Validation */
151179595Sbenno
152179595Sbenno    if (!RetType)
153179595Sbenno    {
154179595Sbenno        return (AE_BAD_PARAMETER);
155179595Sbenno    }
156179595Sbenno
157179595Sbenno    /*
158179595Sbenno     * Special case for the predefined Root Node
159179595Sbenno     * (return type ANY)
160179595Sbenno     */
161179595Sbenno    if (Handle == ACPI_ROOT_OBJECT)
162179595Sbenno    {
163179595Sbenno        *RetType = ACPI_TYPE_ANY;
164179595Sbenno        return (AE_OK);
165179595Sbenno    }
166179595Sbenno
167179595Sbenno    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
168179595Sbenno    if (ACPI_FAILURE (Status))
169179595Sbenno    {
170179595Sbenno        return (Status);
171179595Sbenno    }
172179595Sbenno
173179595Sbenno    /* Convert and validate the handle */
174179595Sbenno
175179595Sbenno    Node = AcpiNsMapHandleToNode (Handle);
176179595Sbenno    if (!Node)
177179595Sbenno    {
178179595Sbenno        (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
179179595Sbenno        return (AE_BAD_PARAMETER);
180179595Sbenno    }
181179595Sbenno
182179595Sbenno    *RetType = Node->Type;
183179595Sbenno
184179595Sbenno
185179595Sbenno    Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
186179595Sbenno    return (Status);
187179595Sbenno}
188179595Sbenno
189179595Sbenno
190179595Sbenno/*******************************************************************************
191179595Sbenno *
192179595Sbenno * FUNCTION:    AcpiGetParent
193179595Sbenno *
194179595Sbenno * PARAMETERS:  Handle          - Handle of object whose parent is desired
195179595Sbenno *              RetHandle       - Where the parent handle will be placed
196179595Sbenno *
197179595Sbenno * RETURN:      Status
198179595Sbenno *
199179595Sbenno * DESCRIPTION: Returns a handle to the parent of the object represented by
200179595Sbenno *              Handle.
201179595Sbenno *
202179595Sbenno ******************************************************************************/
203179595Sbenno
204179595SbennoACPI_STATUS
205179595SbennoAcpiGetParent (
206179595Sbenno    ACPI_HANDLE             Handle,
207179595Sbenno    ACPI_HANDLE             *RetHandle)
208179595Sbenno{
209179595Sbenno    ACPI_NAMESPACE_NODE     *Node;
210179595Sbenno    ACPI_STATUS             Status;
211179595Sbenno
212179595Sbenno
213179595Sbenno    if (!RetHandle)
214179595Sbenno    {
215179595Sbenno        return (AE_BAD_PARAMETER);
216179595Sbenno    }
217179595Sbenno
218179595Sbenno    /* Special case for the predefined Root Node (no parent) */
219179595Sbenno
220179595Sbenno    if (Handle == ACPI_ROOT_OBJECT)
221179595Sbenno    {
222179595Sbenno        return (AE_NULL_ENTRY);
223179595Sbenno    }
224179595Sbenno
225179595Sbenno    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
226179595Sbenno    if (ACPI_FAILURE (Status))
227179595Sbenno    {
228179595Sbenno        return (Status);
229179595Sbenno    }
230179595Sbenno
231179595Sbenno    /* Convert and validate the handle */
232179595Sbenno
233179595Sbenno    Node = AcpiNsMapHandleToNode (Handle);
234179595Sbenno    if (!Node)
235179595Sbenno    {
236179595Sbenno        Status = AE_BAD_PARAMETER;
237179595Sbenno        goto UnlockAndExit;
238179595Sbenno    }
239179595Sbenno
240179595Sbenno    /* Get the parent entry */
241179595Sbenno
242179595Sbenno    *RetHandle =
243179595Sbenno        AcpiNsConvertEntryToHandle (AcpiNsGetParentNode (Node));
244179595Sbenno
245179595Sbenno    /* Return exception if parent is null */
246179595Sbenno
247179595Sbenno    if (!AcpiNsGetParentNode (Node))
248179595Sbenno    {
249179595Sbenno        Status = AE_NULL_ENTRY;
250179595Sbenno    }
251179595Sbenno
252179595Sbenno
253179595SbennoUnlockAndExit:
254179595Sbenno
255179595Sbenno    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
256179595Sbenno    return (Status);
257179595Sbenno}
258179595Sbenno
259179595Sbenno
260/*******************************************************************************
261 *
262 * FUNCTION:    AcpiGetNextObject
263 *
264 * PARAMETERS:  Type            - Type of object to be searched for
265 *              Parent          - Parent object whose children we are getting
266 *              LastChild       - Previous child that was found.
267 *                                The NEXT child will be returned
268 *              RetHandle       - Where handle to the next object is placed
269 *
270 * RETURN:      Status
271 *
272 * DESCRIPTION: Return the next peer object within the namespace.  If Handle is
273 *              valid, Scope is ignored.  Otherwise, the first object within
274 *              Scope is returned.
275 *
276 ******************************************************************************/
277
278ACPI_STATUS
279AcpiGetNextObject (
280    ACPI_OBJECT_TYPE        Type,
281    ACPI_HANDLE             Parent,
282    ACPI_HANDLE             Child,
283    ACPI_HANDLE             *RetHandle)
284{
285    ACPI_STATUS             Status;
286    ACPI_NAMESPACE_NODE     *Node;
287    ACPI_NAMESPACE_NODE     *ParentNode = NULL;
288    ACPI_NAMESPACE_NODE     *ChildNode = NULL;
289
290
291    /* Parameter validation */
292
293    if (Type > ACPI_TYPE_EXTERNAL_MAX)
294    {
295        return (AE_BAD_PARAMETER);
296    }
297
298    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
299    if (ACPI_FAILURE (Status))
300    {
301        return (Status);
302    }
303
304    /* If null handle, use the parent */
305
306    if (!Child)
307    {
308        /* Start search at the beginning of the specified scope */
309
310        ParentNode = AcpiNsMapHandleToNode (Parent);
311        if (!ParentNode)
312        {
313            Status = AE_BAD_PARAMETER;
314            goto UnlockAndExit;
315        }
316    }
317    else
318    {
319        /* Non-null handle, ignore the parent */
320        /* Convert and validate the handle */
321
322        ChildNode = AcpiNsMapHandleToNode (Child);
323        if (!ChildNode)
324        {
325            Status = AE_BAD_PARAMETER;
326            goto UnlockAndExit;
327        }
328    }
329
330    /* Internal function does the real work */
331
332    Node = AcpiNsGetNextNode (Type, ParentNode, ChildNode);
333    if (!Node)
334    {
335        Status = AE_NOT_FOUND;
336        goto UnlockAndExit;
337    }
338
339    if (RetHandle)
340    {
341        *RetHandle = AcpiNsConvertEntryToHandle (Node);
342    }
343
344
345UnlockAndExit:
346
347    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
348    return (Status);
349}
350
351
352