blob: dd33d8b53d6d261c1960b11ef3c348c40fd6478a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4 * ACPI Object oriented interfaces
5 *
6 ******************************************************************************/
7
8/*
Len Brown75a44ce2008-04-23 23:00:13 -04009 * Copyright (C) 2000 - 2008, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
47#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("nsxfobj")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/*******************************************************************************
53 *
John Keller0f0fe1a2006-12-19 12:56:19 -080054 * FUNCTION: acpi_get_id
55 *
56 * PARAMETERS: Handle - Handle of object whose id is desired
57 * ret_id - Where the id will be placed
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: This routine returns the owner id associated with a handle
62 *
63 ******************************************************************************/
64acpi_status acpi_get_id(acpi_handle handle, acpi_owner_id * ret_id)
65{
66 struct acpi_namespace_node *node;
67 acpi_status status;
68
69 /* Parameter Validation */
70
71 if (!ret_id) {
72 return (AE_BAD_PARAMETER);
73 }
74
75 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
76 if (ACPI_FAILURE(status)) {
77 return (status);
78 }
79
80 /* Convert and validate the handle */
81
82 node = acpi_ns_map_handle_to_node(handle);
83 if (!node) {
84 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
85 return (AE_BAD_PARAMETER);
86 }
87
88 *ret_id = node->owner_id;
89
90 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
91 return (status);
92}
93
94ACPI_EXPORT_SYMBOL(acpi_get_id)
95
96/*******************************************************************************
97 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 * FUNCTION: acpi_get_type
99 *
100 * PARAMETERS: Handle - Handle of object whose type is desired
Robert Moore44f6c012005-04-18 22:49:35 -0400101 * ret_type - Where the type will be placed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 *
103 * RETURN: Status
104 *
105 * DESCRIPTION: This routine returns the type associatd with a particular handle
106 *
107 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400108acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Len Brown4be44fc2005-08-05 00:44:28 -0400110 struct acpi_namespace_node *node;
111 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 /* Parameter Validation */
114
115 if (!ret_type) {
116 return (AE_BAD_PARAMETER);
117 }
118
119 /*
120 * Special case for the predefined Root Node
121 * (return type ANY)
122 */
123 if (handle == ACPI_ROOT_OBJECT) {
124 *ret_type = ACPI_TYPE_ANY;
125 return (AE_OK);
126 }
127
Len Brown4be44fc2005-08-05 00:44:28 -0400128 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
129 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return (status);
131 }
132
133 /* Convert and validate the handle */
134
Len Brown4be44fc2005-08-05 00:44:28 -0400135 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400137 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return (AE_BAD_PARAMETER);
139 }
140
141 *ret_type = node->type;
142
Len Brown4be44fc2005-08-05 00:44:28 -0400143 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return (status);
145}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Bob Moore83135242006-10-03 00:00:00 -0400147ACPI_EXPORT_SYMBOL(acpi_get_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149/*******************************************************************************
150 *
151 * FUNCTION: acpi_get_parent
152 *
153 * PARAMETERS: Handle - Handle of object whose parent is desired
154 * ret_handle - Where the parent handle will be placed
155 *
156 * RETURN: Status
157 *
158 * DESCRIPTION: Returns a handle to the parent of the object represented by
159 * Handle.
160 *
161 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400162acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
Len Brown4be44fc2005-08-05 00:44:28 -0400164 struct acpi_namespace_node *node;
165 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 if (!ret_handle) {
168 return (AE_BAD_PARAMETER);
169 }
170
171 /* Special case for the predefined Root Node (no parent) */
172
173 if (handle == ACPI_ROOT_OBJECT) {
174 return (AE_NULL_ENTRY);
175 }
176
Len Brown4be44fc2005-08-05 00:44:28 -0400177 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
178 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 return (status);
180 }
181
182 /* Convert and validate the handle */
183
Len Brown4be44fc2005-08-05 00:44:28 -0400184 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (!node) {
186 status = AE_BAD_PARAMETER;
187 goto unlock_and_exit;
188 }
189
190 /* Get the parent entry */
191
192 *ret_handle =
Len Brown4be44fc2005-08-05 00:44:28 -0400193 acpi_ns_convert_entry_to_handle(acpi_ns_get_parent_node(node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 /* Return exception if parent is null */
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 if (!acpi_ns_get_parent_node(node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 status = AE_NULL_ENTRY;
199 }
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return (status);
205}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Bob Moore83135242006-10-03 00:00:00 -0400207ACPI_EXPORT_SYMBOL(acpi_get_parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209/*******************************************************************************
210 *
211 * FUNCTION: acpi_get_next_object
212 *
213 * PARAMETERS: Type - Type of object to be searched for
214 * Parent - Parent object whose children we are getting
215 * last_child - Previous child that was found.
216 * The NEXT child will be returned
217 * ret_handle - Where handle to the next object is placed
218 *
219 * RETURN: Status
220 *
221 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
222 * valid, Scope is ignored. Otherwise, the first object within
223 * Scope is returned.
224 *
225 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400227acpi_get_next_object(acpi_object_type type,
228 acpi_handle parent,
229 acpi_handle child, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Len Brown4be44fc2005-08-05 00:44:28 -0400231 acpi_status status;
232 struct acpi_namespace_node *node;
233 struct acpi_namespace_node *parent_node = NULL;
234 struct acpi_namespace_node *child_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 /* Parameter validation */
237
238 if (type > ACPI_TYPE_EXTERNAL_MAX) {
239 return (AE_BAD_PARAMETER);
240 }
241
Len Brown4be44fc2005-08-05 00:44:28 -0400242 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
243 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return (status);
245 }
246
247 /* If null handle, use the parent */
248
249 if (!child) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 /* Start search at the beginning of the specified scope */
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253 parent_node = acpi_ns_map_handle_to_node(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 if (!parent_node) {
255 status = AE_BAD_PARAMETER;
256 goto unlock_and_exit;
257 }
Len Brown4be44fc2005-08-05 00:44:28 -0400258 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 /* Non-null handle, ignore the parent */
260 /* Convert and validate the handle */
261
Len Brown4be44fc2005-08-05 00:44:28 -0400262 child_node = acpi_ns_map_handle_to_node(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 if (!child_node) {
264 status = AE_BAD_PARAMETER;
265 goto unlock_and_exit;
266 }
267 }
268
269 /* Internal function does the real work */
270
Bob Moore8c725bf2009-05-21 10:27:51 +0800271 node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (!node) {
273 status = AE_NOT_FOUND;
274 goto unlock_and_exit;
275 }
276
277 if (ret_handle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400278 *ret_handle = acpi_ns_convert_entry_to_handle(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
280
Len Brown4be44fc2005-08-05 00:44:28 -0400281 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Len Brown4be44fc2005-08-05 00:44:28 -0400283 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 return (status);
285}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Bob Moore83135242006-10-03 00:00:00 -0400287ACPI_EXPORT_SYMBOL(acpi_get_next_object)