1433d6423SLionel Sambuc /*******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4433d6423SLionel Sambuc * ACPI Object oriented interfaces
5433d6423SLionel Sambuc *
6433d6423SLionel Sambuc ******************************************************************************/
7433d6423SLionel Sambuc
8*29492bb7SDavid van Moolenbroek /*
9*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
10433d6423SLionel Sambuc * All rights reserved.
11433d6423SLionel Sambuc *
12*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
13*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
14*29492bb7SDavid van Moolenbroek * are met:
15*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
16*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
17*29492bb7SDavid van Moolenbroek * without modification.
18*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
20*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
21*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
22*29492bb7SDavid van Moolenbroek * binary redistribution.
23*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
24*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
25*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
26433d6423SLionel Sambuc *
27*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
28*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
29*29492bb7SDavid van Moolenbroek * Software Foundation.
30433d6423SLionel Sambuc *
31*29492bb7SDavid van Moolenbroek * NO WARRANTY
32*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
43*29492bb7SDavid van Moolenbroek */
44433d6423SLionel Sambuc
45*29492bb7SDavid van Moolenbroek #define EXPORT_ACPI_INTERFACES
46433d6423SLionel Sambuc
47433d6423SLionel Sambuc #include "acpi.h"
48433d6423SLionel Sambuc #include "accommon.h"
49433d6423SLionel Sambuc #include "acnamesp.h"
50433d6423SLionel Sambuc
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc #define _COMPONENT ACPI_NAMESPACE
53433d6423SLionel Sambuc ACPI_MODULE_NAME ("nsxfobj")
54433d6423SLionel Sambuc
55433d6423SLionel Sambuc /*******************************************************************************
56433d6423SLionel Sambuc *
57433d6423SLionel Sambuc * FUNCTION: AcpiGetType
58433d6423SLionel Sambuc *
59433d6423SLionel Sambuc * PARAMETERS: Handle - Handle of object whose type is desired
60433d6423SLionel Sambuc * RetType - Where the type will be placed
61433d6423SLionel Sambuc *
62433d6423SLionel Sambuc * RETURN: Status
63433d6423SLionel Sambuc *
64433d6423SLionel Sambuc * DESCRIPTION: This routine returns the type associatd with a particular handle
65433d6423SLionel Sambuc *
66433d6423SLionel Sambuc ******************************************************************************/
67433d6423SLionel Sambuc
68433d6423SLionel Sambuc ACPI_STATUS
AcpiGetType(ACPI_HANDLE Handle,ACPI_OBJECT_TYPE * RetType)69433d6423SLionel Sambuc AcpiGetType (
70433d6423SLionel Sambuc ACPI_HANDLE Handle,
71433d6423SLionel Sambuc ACPI_OBJECT_TYPE *RetType)
72433d6423SLionel Sambuc {
73433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
74433d6423SLionel Sambuc ACPI_STATUS Status;
75433d6423SLionel Sambuc
76433d6423SLionel Sambuc
77433d6423SLionel Sambuc /* Parameter Validation */
78433d6423SLionel Sambuc
79433d6423SLionel Sambuc if (!RetType)
80433d6423SLionel Sambuc {
81433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
82433d6423SLionel Sambuc }
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc /*
85433d6423SLionel Sambuc * Special case for the predefined Root Node
86433d6423SLionel Sambuc * (return type ANY)
87433d6423SLionel Sambuc */
88433d6423SLionel Sambuc if (Handle == ACPI_ROOT_OBJECT)
89433d6423SLionel Sambuc {
90433d6423SLionel Sambuc *RetType = ACPI_TYPE_ANY;
91433d6423SLionel Sambuc return (AE_OK);
92433d6423SLionel Sambuc }
93433d6423SLionel Sambuc
94433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
95433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
96433d6423SLionel Sambuc {
97433d6423SLionel Sambuc return (Status);
98433d6423SLionel Sambuc }
99433d6423SLionel Sambuc
100433d6423SLionel Sambuc /* Convert and validate the handle */
101433d6423SLionel Sambuc
102433d6423SLionel Sambuc Node = AcpiNsValidateHandle (Handle);
103433d6423SLionel Sambuc if (!Node)
104433d6423SLionel Sambuc {
105433d6423SLionel Sambuc (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
106433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
107433d6423SLionel Sambuc }
108433d6423SLionel Sambuc
109433d6423SLionel Sambuc *RetType = Node->Type;
110433d6423SLionel Sambuc
111433d6423SLionel Sambuc
112433d6423SLionel Sambuc Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
113433d6423SLionel Sambuc return (Status);
114433d6423SLionel Sambuc }
115433d6423SLionel Sambuc
ACPI_EXPORT_SYMBOL(AcpiGetType)116433d6423SLionel Sambuc ACPI_EXPORT_SYMBOL (AcpiGetType)
117433d6423SLionel Sambuc
118433d6423SLionel Sambuc
119433d6423SLionel Sambuc /*******************************************************************************
120433d6423SLionel Sambuc *
121433d6423SLionel Sambuc * FUNCTION: AcpiGetParent
122433d6423SLionel Sambuc *
123433d6423SLionel Sambuc * PARAMETERS: Handle - Handle of object whose parent is desired
124433d6423SLionel Sambuc * RetHandle - Where the parent handle will be placed
125433d6423SLionel Sambuc *
126433d6423SLionel Sambuc * RETURN: Status
127433d6423SLionel Sambuc *
128433d6423SLionel Sambuc * DESCRIPTION: Returns a handle to the parent of the object represented by
129433d6423SLionel Sambuc * Handle.
130433d6423SLionel Sambuc *
131433d6423SLionel Sambuc ******************************************************************************/
132433d6423SLionel Sambuc
133433d6423SLionel Sambuc ACPI_STATUS
134433d6423SLionel Sambuc AcpiGetParent (
135433d6423SLionel Sambuc ACPI_HANDLE Handle,
136433d6423SLionel Sambuc ACPI_HANDLE *RetHandle)
137433d6423SLionel Sambuc {
138433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
139433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ParentNode;
140433d6423SLionel Sambuc ACPI_STATUS Status;
141433d6423SLionel Sambuc
142433d6423SLionel Sambuc
143433d6423SLionel Sambuc if (!RetHandle)
144433d6423SLionel Sambuc {
145433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
146433d6423SLionel Sambuc }
147433d6423SLionel Sambuc
148433d6423SLionel Sambuc /* Special case for the predefined Root Node (no parent) */
149433d6423SLionel Sambuc
150433d6423SLionel Sambuc if (Handle == ACPI_ROOT_OBJECT)
151433d6423SLionel Sambuc {
152433d6423SLionel Sambuc return (AE_NULL_ENTRY);
153433d6423SLionel Sambuc }
154433d6423SLionel Sambuc
155433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
156433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
157433d6423SLionel Sambuc {
158433d6423SLionel Sambuc return (Status);
159433d6423SLionel Sambuc }
160433d6423SLionel Sambuc
161433d6423SLionel Sambuc /* Convert and validate the handle */
162433d6423SLionel Sambuc
163433d6423SLionel Sambuc Node = AcpiNsValidateHandle (Handle);
164433d6423SLionel Sambuc if (!Node)
165433d6423SLionel Sambuc {
166433d6423SLionel Sambuc Status = AE_BAD_PARAMETER;
167433d6423SLionel Sambuc goto UnlockAndExit;
168433d6423SLionel Sambuc }
169433d6423SLionel Sambuc
170433d6423SLionel Sambuc /* Get the parent entry */
171433d6423SLionel Sambuc
172433d6423SLionel Sambuc ParentNode = Node->Parent;
173433d6423SLionel Sambuc *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode);
174433d6423SLionel Sambuc
175433d6423SLionel Sambuc /* Return exception if parent is null */
176433d6423SLionel Sambuc
177433d6423SLionel Sambuc if (!ParentNode)
178433d6423SLionel Sambuc {
179433d6423SLionel Sambuc Status = AE_NULL_ENTRY;
180433d6423SLionel Sambuc }
181433d6423SLionel Sambuc
182433d6423SLionel Sambuc
183433d6423SLionel Sambuc UnlockAndExit:
184433d6423SLionel Sambuc
185433d6423SLionel Sambuc (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
186433d6423SLionel Sambuc return (Status);
187433d6423SLionel Sambuc }
188433d6423SLionel Sambuc
ACPI_EXPORT_SYMBOL(AcpiGetParent)189433d6423SLionel Sambuc ACPI_EXPORT_SYMBOL (AcpiGetParent)
190433d6423SLionel Sambuc
191433d6423SLionel Sambuc
192433d6423SLionel Sambuc /*******************************************************************************
193433d6423SLionel Sambuc *
194433d6423SLionel Sambuc * FUNCTION: AcpiGetNextObject
195433d6423SLionel Sambuc *
196433d6423SLionel Sambuc * PARAMETERS: Type - Type of object to be searched for
197433d6423SLionel Sambuc * Parent - Parent object whose children we are getting
198433d6423SLionel Sambuc * LastChild - Previous child that was found.
199433d6423SLionel Sambuc * The NEXT child will be returned
200433d6423SLionel Sambuc * RetHandle - Where handle to the next object is placed
201433d6423SLionel Sambuc *
202433d6423SLionel Sambuc * RETURN: Status
203433d6423SLionel Sambuc *
204433d6423SLionel Sambuc * DESCRIPTION: Return the next peer object within the namespace. If Handle is
205433d6423SLionel Sambuc * valid, Scope is ignored. Otherwise, the first object within
206433d6423SLionel Sambuc * Scope is returned.
207433d6423SLionel Sambuc *
208433d6423SLionel Sambuc ******************************************************************************/
209433d6423SLionel Sambuc
210433d6423SLionel Sambuc ACPI_STATUS
211433d6423SLionel Sambuc AcpiGetNextObject (
212433d6423SLionel Sambuc ACPI_OBJECT_TYPE Type,
213433d6423SLionel Sambuc ACPI_HANDLE Parent,
214433d6423SLionel Sambuc ACPI_HANDLE Child,
215433d6423SLionel Sambuc ACPI_HANDLE *RetHandle)
216433d6423SLionel Sambuc {
217433d6423SLionel Sambuc ACPI_STATUS Status;
218433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node;
219433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ParentNode = NULL;
220433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *ChildNode = NULL;
221433d6423SLionel Sambuc
222433d6423SLionel Sambuc
223433d6423SLionel Sambuc /* Parameter validation */
224433d6423SLionel Sambuc
225433d6423SLionel Sambuc if (Type > ACPI_TYPE_EXTERNAL_MAX)
226433d6423SLionel Sambuc {
227433d6423SLionel Sambuc return (AE_BAD_PARAMETER);
228433d6423SLionel Sambuc }
229433d6423SLionel Sambuc
230433d6423SLionel Sambuc Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
231433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
232433d6423SLionel Sambuc {
233433d6423SLionel Sambuc return (Status);
234433d6423SLionel Sambuc }
235433d6423SLionel Sambuc
236433d6423SLionel Sambuc /* If null handle, use the parent */
237433d6423SLionel Sambuc
238433d6423SLionel Sambuc if (!Child)
239433d6423SLionel Sambuc {
240433d6423SLionel Sambuc /* Start search at the beginning of the specified scope */
241433d6423SLionel Sambuc
242433d6423SLionel Sambuc ParentNode = AcpiNsValidateHandle (Parent);
243433d6423SLionel Sambuc if (!ParentNode)
244433d6423SLionel Sambuc {
245433d6423SLionel Sambuc Status = AE_BAD_PARAMETER;
246433d6423SLionel Sambuc goto UnlockAndExit;
247433d6423SLionel Sambuc }
248433d6423SLionel Sambuc }
249433d6423SLionel Sambuc else
250433d6423SLionel Sambuc {
251433d6423SLionel Sambuc /* Non-null handle, ignore the parent */
252433d6423SLionel Sambuc /* Convert and validate the handle */
253433d6423SLionel Sambuc
254433d6423SLionel Sambuc ChildNode = AcpiNsValidateHandle (Child);
255433d6423SLionel Sambuc if (!ChildNode)
256433d6423SLionel Sambuc {
257433d6423SLionel Sambuc Status = AE_BAD_PARAMETER;
258433d6423SLionel Sambuc goto UnlockAndExit;
259433d6423SLionel Sambuc }
260433d6423SLionel Sambuc }
261433d6423SLionel Sambuc
262433d6423SLionel Sambuc /* Internal function does the real work */
263433d6423SLionel Sambuc
264433d6423SLionel Sambuc Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode);
265433d6423SLionel Sambuc if (!Node)
266433d6423SLionel Sambuc {
267433d6423SLionel Sambuc Status = AE_NOT_FOUND;
268433d6423SLionel Sambuc goto UnlockAndExit;
269433d6423SLionel Sambuc }
270433d6423SLionel Sambuc
271433d6423SLionel Sambuc if (RetHandle)
272433d6423SLionel Sambuc {
273433d6423SLionel Sambuc *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
274433d6423SLionel Sambuc }
275433d6423SLionel Sambuc
276433d6423SLionel Sambuc
277433d6423SLionel Sambuc UnlockAndExit:
278433d6423SLionel Sambuc
279433d6423SLionel Sambuc (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
280433d6423SLionel Sambuc return (Status);
281433d6423SLionel Sambuc }
282433d6423SLionel Sambuc
283433d6423SLionel Sambuc ACPI_EXPORT_SYMBOL (AcpiGetNextObject)
284