blob: 880a605cee20e24b59d8173c0010c9ed456b11c2 [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/*
Bob Moore77848132012-01-12 13:27:23 +08009 * Copyright (C) 2000 - 2012, 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
Paul Gortmaker214f2c92011-10-26 16:22:14 -040045#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050047#include "accommon.h"
48#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("nsxfobj")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
John Keller0f0fe1a2006-12-19 12:56:19 -080055 * FUNCTION: acpi_get_id
56 *
57 * PARAMETERS: Handle - Handle of object whose id is desired
58 * ret_id - Where the id will be placed
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: This routine returns the owner id associated with a handle
63 *
64 ******************************************************************************/
65acpi_status acpi_get_id(acpi_handle handle, acpi_owner_id * ret_id)
66{
67 struct acpi_namespace_node *node;
68 acpi_status status;
69
70 /* Parameter Validation */
71
72 if (!ret_id) {
73 return (AE_BAD_PARAMETER);
74 }
75
76 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
77 if (ACPI_FAILURE(status)) {
78 return (status);
79 }
80
81 /* Convert and validate the handle */
82
Bob Mooref24b6642009-12-11 14:57:00 +080083 node = acpi_ns_validate_handle(handle);
John Keller0f0fe1a2006-12-19 12:56:19 -080084 if (!node) {
85 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
86 return (AE_BAD_PARAMETER);
87 }
88
89 *ret_id = node->owner_id;
90
91 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
92 return (status);
93}
94
95ACPI_EXPORT_SYMBOL(acpi_get_id)
96
97/*******************************************************************************
98 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 * FUNCTION: acpi_get_type
100 *
101 * PARAMETERS: Handle - Handle of object whose type is desired
Robert Moore44f6c012005-04-18 22:49:35 -0400102 * ret_type - Where the type will be placed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 *
104 * RETURN: Status
105 *
106 * DESCRIPTION: This routine returns the type associatd with a particular handle
107 *
108 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400109acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Len Brown4be44fc2005-08-05 00:44:28 -0400111 struct acpi_namespace_node *node;
112 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 /* Parameter Validation */
115
116 if (!ret_type) {
117 return (AE_BAD_PARAMETER);
118 }
119
120 /*
121 * Special case for the predefined Root Node
122 * (return type ANY)
123 */
124 if (handle == ACPI_ROOT_OBJECT) {
125 *ret_type = ACPI_TYPE_ANY;
126 return (AE_OK);
127 }
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
130 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return (status);
132 }
133
134 /* Convert and validate the handle */
135
Bob Mooref24b6642009-12-11 14:57:00 +0800136 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400138 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 return (AE_BAD_PARAMETER);
140 }
141
142 *ret_type = node->type;
143
Len Brown4be44fc2005-08-05 00:44:28 -0400144 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return (status);
146}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Bob Moore83135242006-10-03 00:00:00 -0400148ACPI_EXPORT_SYMBOL(acpi_get_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150/*******************************************************************************
151 *
152 * FUNCTION: acpi_get_parent
153 *
154 * PARAMETERS: Handle - Handle of object whose parent is desired
155 * ret_handle - Where the parent handle will be placed
156 *
157 * RETURN: Status
158 *
159 * DESCRIPTION: Returns a handle to the parent of the object represented by
160 * Handle.
161 *
162 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400163acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Len Brown4be44fc2005-08-05 00:44:28 -0400165 struct acpi_namespace_node *node;
Alex Chiangc446eed2009-05-21 10:59:15 +0800166 struct acpi_namespace_node *parent_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400167 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 if (!ret_handle) {
170 return (AE_BAD_PARAMETER);
171 }
172
173 /* Special case for the predefined Root Node (no parent) */
174
175 if (handle == ACPI_ROOT_OBJECT) {
176 return (AE_NULL_ENTRY);
177 }
178
Len Brown4be44fc2005-08-05 00:44:28 -0400179 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
180 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return (status);
182 }
183
184 /* Convert and validate the handle */
185
Bob Mooref24b6642009-12-11 14:57:00 +0800186 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 if (!node) {
188 status = AE_BAD_PARAMETER;
189 goto unlock_and_exit;
190 }
191
192 /* Get the parent entry */
193
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800194 parent_node = node->parent;
Bob Mooref24b6642009-12-11 14:57:00 +0800195 *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 /* Return exception if parent is null */
198
Alex Chiangc446eed2009-05-21 10:59:15 +0800199 if (!parent_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 status = AE_NULL_ENTRY;
201 }
202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Len Brown4be44fc2005-08-05 00:44:28 -0400205 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return (status);
207}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Bob Moore83135242006-10-03 00:00:00 -0400209ACPI_EXPORT_SYMBOL(acpi_get_parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211/*******************************************************************************
212 *
213 * FUNCTION: acpi_get_next_object
214 *
215 * PARAMETERS: Type - Type of object to be searched for
216 * Parent - Parent object whose children we are getting
217 * last_child - Previous child that was found.
218 * The NEXT child will be returned
219 * ret_handle - Where handle to the next object is placed
220 *
221 * RETURN: Status
222 *
223 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
224 * valid, Scope is ignored. Otherwise, the first object within
225 * Scope is returned.
226 *
227 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400229acpi_get_next_object(acpi_object_type type,
230 acpi_handle parent,
231 acpi_handle child, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Len Brown4be44fc2005-08-05 00:44:28 -0400233 acpi_status status;
234 struct acpi_namespace_node *node;
235 struct acpi_namespace_node *parent_node = NULL;
236 struct acpi_namespace_node *child_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 /* Parameter validation */
239
240 if (type > ACPI_TYPE_EXTERNAL_MAX) {
241 return (AE_BAD_PARAMETER);
242 }
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
245 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 return (status);
247 }
248
249 /* If null handle, use the parent */
250
251 if (!child) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 /* Start search at the beginning of the specified scope */
254
Bob Mooref24b6642009-12-11 14:57:00 +0800255 parent_node = acpi_ns_validate_handle(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 if (!parent_node) {
257 status = AE_BAD_PARAMETER;
258 goto unlock_and_exit;
259 }
Len Brown4be44fc2005-08-05 00:44:28 -0400260 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 /* Non-null handle, ignore the parent */
262 /* Convert and validate the handle */
263
Bob Mooref24b6642009-12-11 14:57:00 +0800264 child_node = acpi_ns_validate_handle(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (!child_node) {
266 status = AE_BAD_PARAMETER;
267 goto unlock_and_exit;
268 }
269 }
270
271 /* Internal function does the real work */
272
Bob Moore8c725bf2009-05-21 10:27:51 +0800273 node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (!node) {
275 status = AE_NOT_FOUND;
276 goto unlock_and_exit;
277 }
278
279 if (ret_handle) {
Bob Mooref24b6642009-12-11 14:57:00 +0800280 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282
Len Brown4be44fc2005-08-05 00:44:28 -0400283 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Len Brown4be44fc2005-08-05 00:44:28 -0400285 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 return (status);
287}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Bob Moore83135242006-10-03 00:00:00 -0400289ACPI_EXPORT_SYMBOL(acpi_get_next_object)