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