blob: c312cd490450d2db64761bfa637a9e2339f8c293 [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 Moorec8100dc2016-01-15 08:17:03 +08009 * Copyright (C) 2000 - 2016, 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 *
56 * FUNCTION: acpi_get_type
57 *
Bob Mooreba494be2012-07-12 09:40:10 +080058 * PARAMETERS: handle - Handle of object whose type is desired
Robert Moore44f6c012005-04-18 22:49:35 -040059 * ret_type - Where the type will be placed
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: This routine returns the type associatd with a particular handle
64 *
65 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040066acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Len Brown4be44fc2005-08-05 00:44:28 -040068 struct acpi_namespace_node *node;
69 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 /* Parameter Validation */
72
73 if (!ret_type) {
74 return (AE_BAD_PARAMETER);
75 }
76
Bob Moore1fad8732015-12-29 13:54:36 +080077 /* Special case for the predefined Root Node (return type ANY) */
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 if (handle == ACPI_ROOT_OBJECT) {
80 *ret_type = ACPI_TYPE_ANY;
81 return (AE_OK);
82 }
83
Len Brown4be44fc2005-08-05 00:44:28 -040084 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
85 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return (status);
87 }
88
89 /* Convert and validate the handle */
90
Bob Mooref24b6642009-12-11 14:57:00 +080091 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -040093 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return (AE_BAD_PARAMETER);
95 }
96
97 *ret_type = node->type;
98
Len Brown4be44fc2005-08-05 00:44:28 -040099 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return (status);
101}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Bob Moore83135242006-10-03 00:00:00 -0400103ACPI_EXPORT_SYMBOL(acpi_get_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105/*******************************************************************************
106 *
107 * FUNCTION: acpi_get_parent
108 *
Bob Mooreba494be2012-07-12 09:40:10 +0800109 * PARAMETERS: handle - Handle of object whose parent is desired
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 * ret_handle - Where the parent handle will be placed
111 *
112 * RETURN: Status
113 *
114 * DESCRIPTION: Returns a handle to the parent of the object represented by
115 * Handle.
116 *
117 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400118acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Len Brown4be44fc2005-08-05 00:44:28 -0400120 struct acpi_namespace_node *node;
Alex Chiangc446eed2009-05-21 10:59:15 +0800121 struct acpi_namespace_node *parent_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400122 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 if (!ret_handle) {
125 return (AE_BAD_PARAMETER);
126 }
127
128 /* Special case for the predefined Root Node (no parent) */
129
130 if (handle == ACPI_ROOT_OBJECT) {
131 return (AE_NULL_ENTRY);
132 }
133
Len Brown4be44fc2005-08-05 00:44:28 -0400134 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
135 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return (status);
137 }
138
139 /* Convert and validate the handle */
140
Bob Mooref24b6642009-12-11 14:57:00 +0800141 node = acpi_ns_validate_handle(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 if (!node) {
143 status = AE_BAD_PARAMETER;
144 goto unlock_and_exit;
145 }
146
147 /* Get the parent entry */
148
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800149 parent_node = node->parent;
Bob Mooref24b6642009-12-11 14:57:00 +0800150 *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 /* Return exception if parent is null */
153
Alex Chiangc446eed2009-05-21 10:59:15 +0800154 if (!parent_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 status = AE_NULL_ENTRY;
156 }
157
Lv Zheng10622bf2013-10-29 09:30:02 +0800158unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return (status);
162}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Bob Moore83135242006-10-03 00:00:00 -0400164ACPI_EXPORT_SYMBOL(acpi_get_parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166/*******************************************************************************
167 *
168 * FUNCTION: acpi_get_next_object
169 *
Bob Mooreba494be2012-07-12 09:40:10 +0800170 * PARAMETERS: type - Type of object to be searched for
171 * parent - Parent object whose children we are getting
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 * last_child - Previous child that was found.
173 * The NEXT child will be returned
174 * ret_handle - Where handle to the next object is placed
175 *
176 * RETURN: Status
177 *
Bob Moore73a30902012-10-31 02:26:55 +0000178 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
179 * valid, Scope is ignored. Otherwise, the first object within
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 * Scope is returned.
181 *
182 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400184acpi_get_next_object(acpi_object_type type,
185 acpi_handle parent,
186 acpi_handle child, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Len Brown4be44fc2005-08-05 00:44:28 -0400188 acpi_status status;
189 struct acpi_namespace_node *node;
190 struct acpi_namespace_node *parent_node = NULL;
191 struct acpi_namespace_node *child_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 /* Parameter validation */
194
195 if (type > ACPI_TYPE_EXTERNAL_MAX) {
196 return (AE_BAD_PARAMETER);
197 }
198
Len Brown4be44fc2005-08-05 00:44:28 -0400199 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
200 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return (status);
202 }
203
204 /* If null handle, use the parent */
205
206 if (!child) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 /* Start search at the beginning of the specified scope */
209
Bob Mooref24b6642009-12-11 14:57:00 +0800210 parent_node = acpi_ns_validate_handle(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 if (!parent_node) {
212 status = AE_BAD_PARAMETER;
213 goto unlock_and_exit;
214 }
Len Brown4be44fc2005-08-05 00:44:28 -0400215 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 /* Non-null handle, ignore the parent */
217 /* Convert and validate the handle */
218
Bob Mooref24b6642009-12-11 14:57:00 +0800219 child_node = acpi_ns_validate_handle(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 if (!child_node) {
221 status = AE_BAD_PARAMETER;
222 goto unlock_and_exit;
223 }
224 }
225
226 /* Internal function does the real work */
227
Bob Moore8c725bf2009-05-21 10:27:51 +0800228 node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if (!node) {
230 status = AE_NOT_FOUND;
231 goto unlock_and_exit;
232 }
233
234 if (ret_handle) {
Bob Mooref24b6642009-12-11 14:57:00 +0800235 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
237
Lv Zheng10622bf2013-10-29 09:30:02 +0800238unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Len Brown4be44fc2005-08-05 00:44:28 -0400240 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return (status);
242}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Bob Moore83135242006-10-03 00:00:00 -0400244ACPI_EXPORT_SYMBOL(acpi_get_next_object)