xref: /titanic_51/usr/src/uts/intel/io/acpica/namespace/nsxfobj.c (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
1ae115bc7Smrj /*******************************************************************************
2ae115bc7Smrj  *
3ae115bc7Smrj  * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4ae115bc7Smrj  *                         ACPI Object oriented interfaces
5ae115bc7Smrj  *
6ae115bc7Smrj  ******************************************************************************/
7ae115bc7Smrj 
826f3cdf0SGordon Ross /*
9*385cc6b4SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
10ae115bc7Smrj  * All rights reserved.
11ae115bc7Smrj  *
1226f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
1326f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
1426f3cdf0SGordon Ross  * are met:
1526f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
1626f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
1726f3cdf0SGordon Ross  *    without modification.
1826f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1926f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
2026f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
2126f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
2226f3cdf0SGordon Ross  *    binary redistribution.
2326f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
2426f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
2526f3cdf0SGordon Ross  *    from this software without specific prior written permission.
26ae115bc7Smrj  *
2726f3cdf0SGordon Ross  * Alternatively, this software may be distributed under the terms of the
2826f3cdf0SGordon Ross  * GNU General Public License ("GPL") version 2 as published by the Free
2926f3cdf0SGordon Ross  * Software Foundation.
30ae115bc7Smrj  *
3126f3cdf0SGordon Ross  * NO WARRANTY
3226f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3326f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3426f3cdf0SGordon Ross  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3526f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3626f3cdf0SGordon Ross  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3726f3cdf0SGordon Ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3826f3cdf0SGordon Ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3926f3cdf0SGordon Ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4026f3cdf0SGordon Ross  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4126f3cdf0SGordon Ross  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4226f3cdf0SGordon Ross  * POSSIBILITY OF SUCH DAMAGES.
4326f3cdf0SGordon Ross  */
44ae115bc7Smrj 
45*385cc6b4SJerry Jelinek #define EXPORT_ACPI_INTERFACES
46ae115bc7Smrj 
47ae115bc7Smrj #include "acpi.h"
48aa2aa9a6SDana Myers #include "accommon.h"
49ae115bc7Smrj #include "acnamesp.h"
50ae115bc7Smrj 
51ae115bc7Smrj 
52ae115bc7Smrj #define _COMPONENT          ACPI_NAMESPACE
53ae115bc7Smrj         ACPI_MODULE_NAME    ("nsxfobj")
54ae115bc7Smrj 
55ae115bc7Smrj /*******************************************************************************
56ae115bc7Smrj  *
57ae115bc7Smrj  * FUNCTION:    AcpiGetType
58ae115bc7Smrj  *
59ae115bc7Smrj  * PARAMETERS:  Handle          - Handle of object whose type is desired
60ae115bc7Smrj  *              RetType         - Where the type will be placed
61ae115bc7Smrj  *
62ae115bc7Smrj  * RETURN:      Status
63ae115bc7Smrj  *
64ae115bc7Smrj  * DESCRIPTION: This routine returns the type associatd with a particular handle
65ae115bc7Smrj  *
66ae115bc7Smrj  ******************************************************************************/
67ae115bc7Smrj 
68ae115bc7Smrj ACPI_STATUS
69ae115bc7Smrj AcpiGetType (
70ae115bc7Smrj     ACPI_HANDLE             Handle,
71ae115bc7Smrj     ACPI_OBJECT_TYPE        *RetType)
72ae115bc7Smrj {
73ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node;
74ae115bc7Smrj     ACPI_STATUS             Status;
75ae115bc7Smrj 
76ae115bc7Smrj 
77ae115bc7Smrj     /* Parameter Validation */
78ae115bc7Smrj 
79ae115bc7Smrj     if (!RetType)
80ae115bc7Smrj     {
81ae115bc7Smrj         return (AE_BAD_PARAMETER);
82ae115bc7Smrj     }
83ae115bc7Smrj 
84*385cc6b4SJerry Jelinek     /* Special case for the predefined Root Node (return type ANY) */
85*385cc6b4SJerry Jelinek 
86ae115bc7Smrj     if (Handle == ACPI_ROOT_OBJECT)
87ae115bc7Smrj     {
88ae115bc7Smrj         *RetType = ACPI_TYPE_ANY;
89ae115bc7Smrj         return (AE_OK);
90ae115bc7Smrj     }
91ae115bc7Smrj 
92ae115bc7Smrj     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
93ae115bc7Smrj     if (ACPI_FAILURE (Status))
94ae115bc7Smrj     {
95ae115bc7Smrj         return (Status);
96ae115bc7Smrj     }
97ae115bc7Smrj 
98ae115bc7Smrj     /* Convert and validate the handle */
99ae115bc7Smrj 
10026f3cdf0SGordon Ross     Node = AcpiNsValidateHandle (Handle);
101ae115bc7Smrj     if (!Node)
102ae115bc7Smrj     {
103ae115bc7Smrj         (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
104ae115bc7Smrj         return (AE_BAD_PARAMETER);
105ae115bc7Smrj     }
106ae115bc7Smrj 
107ae115bc7Smrj     *RetType = Node->Type;
108ae115bc7Smrj 
109ae115bc7Smrj     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
110ae115bc7Smrj     return (Status);
111ae115bc7Smrj }
112ae115bc7Smrj 
113ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiGetType)
114ae115bc7Smrj 
115ae115bc7Smrj 
116ae115bc7Smrj /*******************************************************************************
117ae115bc7Smrj  *
118ae115bc7Smrj  * FUNCTION:    AcpiGetParent
119ae115bc7Smrj  *
120ae115bc7Smrj  * PARAMETERS:  Handle          - Handle of object whose parent is desired
121ae115bc7Smrj  *              RetHandle       - Where the parent handle will be placed
122ae115bc7Smrj  *
123ae115bc7Smrj  * RETURN:      Status
124ae115bc7Smrj  *
125ae115bc7Smrj  * DESCRIPTION: Returns a handle to the parent of the object represented by
126ae115bc7Smrj  *              Handle.
127ae115bc7Smrj  *
128ae115bc7Smrj  ******************************************************************************/
129ae115bc7Smrj 
130ae115bc7Smrj ACPI_STATUS
131ae115bc7Smrj AcpiGetParent (
132ae115bc7Smrj     ACPI_HANDLE             Handle,
133ae115bc7Smrj     ACPI_HANDLE             *RetHandle)
134ae115bc7Smrj {
135ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node;
136aa2aa9a6SDana Myers     ACPI_NAMESPACE_NODE     *ParentNode;
137ae115bc7Smrj     ACPI_STATUS             Status;
138ae115bc7Smrj 
139ae115bc7Smrj 
140ae115bc7Smrj     if (!RetHandle)
141ae115bc7Smrj     {
142ae115bc7Smrj         return (AE_BAD_PARAMETER);
143ae115bc7Smrj     }
144ae115bc7Smrj 
145ae115bc7Smrj     /* Special case for the predefined Root Node (no parent) */
146ae115bc7Smrj 
147ae115bc7Smrj     if (Handle == ACPI_ROOT_OBJECT)
148ae115bc7Smrj     {
149ae115bc7Smrj         return (AE_NULL_ENTRY);
150ae115bc7Smrj     }
151ae115bc7Smrj 
152ae115bc7Smrj     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
153ae115bc7Smrj     if (ACPI_FAILURE (Status))
154ae115bc7Smrj     {
155ae115bc7Smrj         return (Status);
156ae115bc7Smrj     }
157ae115bc7Smrj 
158ae115bc7Smrj     /* Convert and validate the handle */
159ae115bc7Smrj 
16026f3cdf0SGordon Ross     Node = AcpiNsValidateHandle (Handle);
161ae115bc7Smrj     if (!Node)
162ae115bc7Smrj     {
163ae115bc7Smrj         Status = AE_BAD_PARAMETER;
164ae115bc7Smrj         goto UnlockAndExit;
165ae115bc7Smrj     }
166ae115bc7Smrj 
167ae115bc7Smrj     /* Get the parent entry */
168ae115bc7Smrj 
16926f3cdf0SGordon Ross     ParentNode = Node->Parent;
17026f3cdf0SGordon Ross     *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode);
171ae115bc7Smrj 
172ae115bc7Smrj     /* Return exception if parent is null */
173ae115bc7Smrj 
174aa2aa9a6SDana Myers     if (!ParentNode)
175ae115bc7Smrj     {
176ae115bc7Smrj         Status = AE_NULL_ENTRY;
177ae115bc7Smrj     }
178ae115bc7Smrj 
179ae115bc7Smrj 
180ae115bc7Smrj UnlockAndExit:
181ae115bc7Smrj 
182ae115bc7Smrj     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
183ae115bc7Smrj     return (Status);
184ae115bc7Smrj }
185ae115bc7Smrj 
186ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiGetParent)
187ae115bc7Smrj 
188ae115bc7Smrj 
189ae115bc7Smrj /*******************************************************************************
190ae115bc7Smrj  *
191ae115bc7Smrj  * FUNCTION:    AcpiGetNextObject
192ae115bc7Smrj  *
193ae115bc7Smrj  * PARAMETERS:  Type            - Type of object to be searched for
194ae115bc7Smrj  *              Parent          - Parent object whose children we are getting
195ae115bc7Smrj  *              LastChild       - Previous child that was found.
196ae115bc7Smrj  *                                The NEXT child will be returned
197ae115bc7Smrj  *              RetHandle       - Where handle to the next object is placed
198ae115bc7Smrj  *
199ae115bc7Smrj  * RETURN:      Status
200ae115bc7Smrj  *
201ae115bc7Smrj  * DESCRIPTION: Return the next peer object within the namespace. If Handle is
202ae115bc7Smrj  *              valid, Scope is ignored. Otherwise, the first object within
203ae115bc7Smrj  *              Scope is returned.
204ae115bc7Smrj  *
205ae115bc7Smrj  ******************************************************************************/
206ae115bc7Smrj 
207ae115bc7Smrj ACPI_STATUS
208ae115bc7Smrj AcpiGetNextObject (
209ae115bc7Smrj     ACPI_OBJECT_TYPE        Type,
210ae115bc7Smrj     ACPI_HANDLE             Parent,
211ae115bc7Smrj     ACPI_HANDLE             Child,
212ae115bc7Smrj     ACPI_HANDLE             *RetHandle)
213ae115bc7Smrj {
214ae115bc7Smrj     ACPI_STATUS             Status;
215ae115bc7Smrj     ACPI_NAMESPACE_NODE     *Node;
216ae115bc7Smrj     ACPI_NAMESPACE_NODE     *ParentNode = NULL;
217ae115bc7Smrj     ACPI_NAMESPACE_NODE     *ChildNode = NULL;
218ae115bc7Smrj 
219ae115bc7Smrj 
220ae115bc7Smrj     /* Parameter validation */
221ae115bc7Smrj 
222ae115bc7Smrj     if (Type > ACPI_TYPE_EXTERNAL_MAX)
223ae115bc7Smrj     {
224ae115bc7Smrj         return (AE_BAD_PARAMETER);
225ae115bc7Smrj     }
226ae115bc7Smrj 
227ae115bc7Smrj     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
228ae115bc7Smrj     if (ACPI_FAILURE (Status))
229ae115bc7Smrj     {
230ae115bc7Smrj         return (Status);
231ae115bc7Smrj     }
232ae115bc7Smrj 
233ae115bc7Smrj     /* If null handle, use the parent */
234ae115bc7Smrj 
235ae115bc7Smrj     if (!Child)
236ae115bc7Smrj     {
237ae115bc7Smrj         /* Start search at the beginning of the specified scope */
238ae115bc7Smrj 
23926f3cdf0SGordon Ross         ParentNode = AcpiNsValidateHandle (Parent);
240ae115bc7Smrj         if (!ParentNode)
241ae115bc7Smrj         {
242ae115bc7Smrj             Status = AE_BAD_PARAMETER;
243ae115bc7Smrj             goto UnlockAndExit;
244ae115bc7Smrj         }
245ae115bc7Smrj     }
246ae115bc7Smrj     else
247ae115bc7Smrj     {
248ae115bc7Smrj         /* Non-null handle, ignore the parent */
249ae115bc7Smrj         /* Convert and validate the handle */
250ae115bc7Smrj 
25126f3cdf0SGordon Ross         ChildNode = AcpiNsValidateHandle (Child);
252ae115bc7Smrj         if (!ChildNode)
253ae115bc7Smrj         {
254ae115bc7Smrj             Status = AE_BAD_PARAMETER;
255ae115bc7Smrj             goto UnlockAndExit;
256ae115bc7Smrj         }
257ae115bc7Smrj     }
258ae115bc7Smrj 
259ae115bc7Smrj     /* Internal function does the real work */
260ae115bc7Smrj 
261aa2aa9a6SDana Myers     Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode);
262ae115bc7Smrj     if (!Node)
263ae115bc7Smrj     {
264ae115bc7Smrj         Status = AE_NOT_FOUND;
265ae115bc7Smrj         goto UnlockAndExit;
266ae115bc7Smrj     }
267ae115bc7Smrj 
268ae115bc7Smrj     if (RetHandle)
269ae115bc7Smrj     {
27026f3cdf0SGordon Ross         *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
271ae115bc7Smrj     }
272ae115bc7Smrj 
273ae115bc7Smrj 
274ae115bc7Smrj UnlockAndExit:
275ae115bc7Smrj 
276ae115bc7Smrj     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
277ae115bc7Smrj     return (Status);
278ae115bc7Smrj }
279ae115bc7Smrj 
280ae115bc7Smrj ACPI_EXPORT_SYMBOL (AcpiGetNextObject)
281