blob: dae9401be7a2d6cef946f4d3ca3fab173165cea6 [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 Moorefbb7a2d2014-02-08 09:42:25 +08009 * Copyright (C) 2000 - 2014, 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
Lv Zheng839e9282013-10-29 09:29:51 +080045#define EXPORT_ACPI_INTERFACES
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050048#include "accommon.h"
49#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040052ACPI_MODULE_NAME("nsxfobj")
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/*******************************************************************************
55 *
John Keller0f0fe1a2006-12-19 12:56:19 -080056 * FUNCTION: acpi_get_id
57 *
58 * PARAMETERS: Handle - Handle of object whose id is desired
59 * ret_id - Where the id will be placed
60 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: This routine returns the owner id associated with a handle
64 *
65 ******************************************************************************/
66acpi_status acpi_get_id(acpi_handle handle, acpi_owner_id * ret_id)
67{
68 struct acpi_namespace_node *node;
69 acpi_status status;
70
71 /* Parameter Validation */
72
73 if (!ret_id) {
74 return (AE_BAD_PARAMETER);
75 }
76
77 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
78 if (ACPI_FAILURE(status)) {
79 return (status);
80 }
81
82 /* Convert and validate the handle */
83
Bob Mooref24b6642009-12-11 14:57:00 +080084 node = acpi_ns_validate_handle(handle);
John Keller0f0fe1a2006-12-19 12:56:19 -080085 if (!node) {
86 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
87 return (AE_BAD_PARAMETER);
88 }
89
90 *ret_id = node->owner_id;
91
92 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
93 return (status);
94}
95
96ACPI_EXPORT_SYMBOL(acpi_get_id)
97
98/*******************************************************************************
99 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 * FUNCTION: acpi_get_type
101 *
Bob Mooreba494be2012-07-12 09:40:10 +0800102 * PARAMETERS: handle - Handle of object whose type is desired
Robert Moore44f6c012005-04-18 22:49:35 -0400103 * ret_type - Where the type will be placed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 *
105 * RETURN: Status
106 *
107 * DESCRIPTION: This routine returns the type associatd with a particular handle
108 *
109 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400110acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Len Brown4be44fc2005-08-05 00:44:28 -0400112 struct acpi_namespace_node *node;
113 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* Parameter Validation */
116
117 if (!ret_type) {
118 return (AE_BAD_PARAMETER);
119 }
120
121 /*
122 * Special case for the predefined Root Node
123 * (return type ANY)
124 */
125 if (handle == ACPI_ROOT_OBJECT) {
126 *ret_type = ACPI_TYPE_ANY;
127 return (AE_OK);
128 }
129
Len Brown4be44fc2005-08-05 00:44:28 -0400130 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
131 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return (status);
133 }
134
135 /* Convert and validate the handle */
136
Bob Mooref24b6642009-12-11 14:57:00 +0800137 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400139 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return (AE_BAD_PARAMETER);
141 }
142
143 *ret_type = node->type;
144
Len Brown4be44fc2005-08-05 00:44:28 -0400145 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return (status);
147}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Bob Moore83135242006-10-03 00:00:00 -0400149ACPI_EXPORT_SYMBOL(acpi_get_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151/*******************************************************************************
152 *
153 * FUNCTION: acpi_get_parent
154 *
Bob Mooreba494be2012-07-12 09:40:10 +0800155 * PARAMETERS: handle - Handle of object whose parent is desired
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 * ret_handle - Where the parent handle will be placed
157 *
158 * RETURN: Status
159 *
160 * DESCRIPTION: Returns a handle to the parent of the object represented by
161 * Handle.
162 *
163 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400164acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Len Brown4be44fc2005-08-05 00:44:28 -0400166 struct acpi_namespace_node *node;
Alex Chiangc446eed2009-05-21 10:59:15 +0800167 struct acpi_namespace_node *parent_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400168 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 if (!ret_handle) {
171 return (AE_BAD_PARAMETER);
172 }
173
174 /* Special case for the predefined Root Node (no parent) */
175
176 if (handle == ACPI_ROOT_OBJECT) {
177 return (AE_NULL_ENTRY);
178 }
179
Len Brown4be44fc2005-08-05 00:44:28 -0400180 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
181 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 return (status);
183 }
184
185 /* Convert and validate the handle */
186
Bob Mooref24b6642009-12-11 14:57:00 +0800187 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 if (!node) {
189 status = AE_BAD_PARAMETER;
190 goto unlock_and_exit;
191 }
192
193 /* Get the parent entry */
194
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800195 parent_node = node->parent;
Bob Mooref24b6642009-12-11 14:57:00 +0800196 *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 /* Return exception if parent is null */
199
Alex Chiangc446eed2009-05-21 10:59:15 +0800200 if (!parent_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 status = AE_NULL_ENTRY;
202 }
203
Lv Zheng10622bf2013-10-29 09:30:02 +0800204unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Len Brown4be44fc2005-08-05 00:44:28 -0400206 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 return (status);
208}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Bob Moore83135242006-10-03 00:00:00 -0400210ACPI_EXPORT_SYMBOL(acpi_get_parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212/*******************************************************************************
213 *
214 * FUNCTION: acpi_get_next_object
215 *
Bob Mooreba494be2012-07-12 09:40:10 +0800216 * PARAMETERS: type - Type of object to be searched for
217 * parent - Parent object whose children we are getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 * last_child - Previous child that was found.
219 * The NEXT child will be returned
220 * ret_handle - Where handle to the next object is placed
221 *
222 * RETURN: Status
223 *
Bob Moore73a30902012-10-31 02:26:55 +0000224 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
225 * valid, Scope is ignored. Otherwise, the first object within
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 * Scope is returned.
227 *
228 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400230acpi_get_next_object(acpi_object_type type,
231 acpi_handle parent,
232 acpi_handle child, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Len Brown4be44fc2005-08-05 00:44:28 -0400234 acpi_status status;
235 struct acpi_namespace_node *node;
236 struct acpi_namespace_node *parent_node = NULL;
237 struct acpi_namespace_node *child_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 /* Parameter validation */
240
241 if (type > ACPI_TYPE_EXTERNAL_MAX) {
242 return (AE_BAD_PARAMETER);
243 }
244
Len Brown4be44fc2005-08-05 00:44:28 -0400245 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
246 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 return (status);
248 }
249
250 /* If null handle, use the parent */
251
252 if (!child) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 /* Start search at the beginning of the specified scope */
255
Bob Mooref24b6642009-12-11 14:57:00 +0800256 parent_node = acpi_ns_validate_handle(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 if (!parent_node) {
258 status = AE_BAD_PARAMETER;
259 goto unlock_and_exit;
260 }
Len Brown4be44fc2005-08-05 00:44:28 -0400261 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 /* Non-null handle, ignore the parent */
263 /* Convert and validate the handle */
264
Bob Mooref24b6642009-12-11 14:57:00 +0800265 child_node = acpi_ns_validate_handle(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 if (!child_node) {
267 status = AE_BAD_PARAMETER;
268 goto unlock_and_exit;
269 }
270 }
271
272 /* Internal function does the real work */
273
Bob Moore8c725bf2009-05-21 10:27:51 +0800274 node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if (!node) {
276 status = AE_NOT_FOUND;
277 goto unlock_and_exit;
278 }
279
280 if (ret_handle) {
Bob Mooref24b6642009-12-11 14:57:00 +0800281 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 }
283
Lv Zheng10622bf2013-10-29 09:30:02 +0800284unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Len Brown4be44fc2005-08-05 00:44:28 -0400286 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 return (status);
288}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Bob Moore83135242006-10-03 00:00:00 -0400290ACPI_EXPORT_SYMBOL(acpi_get_next_object)