blob: 42dae12f2ef87d899f5431f7132c2b476db517ad [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
Bob Moore41195322006-05-26 16:36:00 -04003 * Module Name: nseval - Object evaluation, includes control method execution
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 ******************************************************************************/
6
7/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acparser.h>
46#include <acpi/acinterp.h>
47#include <acpi/acnamesp.h>
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("nseval")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052/*******************************************************************************
53 *
Bob Moore41195322006-05-26 16:36:00 -040054 * FUNCTION: acpi_ns_evaluate
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 *
Bob Moore41195322006-05-26 16:36:00 -040056 * PARAMETERS: Info - Evaluation info block, contains:
57 * prefix_node - Prefix or Method/Object Node to execute
58 * Pathname - Name of method to execute, If NULL, the
59 * Node is the object to execute
Robert Moore44f6c012005-04-18 22:49:35 -040060 * Parameters - List of parameters to pass to the method,
61 * terminated by NULL. Params itself may be
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * NULL if no parameters are being passed.
Robert Moore44f6c012005-04-18 22:49:35 -040063 * return_object - Where to put method's return value (if
64 * any). If NULL, no value is returned.
65 * parameter_type - Type of Parameter list
66 * return_object - Where to put method's return value (if
67 * any). If NULL, no value is returned.
Bob Moore41195322006-05-26 16:36:00 -040068 * Flags - ACPI_IGNORE_RETURN_VALUE to delete return
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 *
70 * RETURN: Status
71 *
Bob Moore41195322006-05-26 16:36:00 -040072 * DESCRIPTION: Execute a control method or return the current value of an
73 * ACPI namespace object.
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 *
Bob Moore41195322006-05-26 16:36:00 -040075 * MUTEX: Locks interpreter
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 *
77 ******************************************************************************/
Len Brownfd350942007-05-09 23:34:35 -040078acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Len Brown4be44fc2005-08-05 00:44:28 -040080 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Bob Moore41195322006-05-26 16:36:00 -040082 ACPI_FUNCTION_TRACE(ns_evaluate);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 if (!info) {
Len Brown4be44fc2005-08-05 00:44:28 -040085 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 }
87
88 /* Initialize the return value to an invalid object */
89
90 info->return_object = NULL;
91
Bob Moore41195322006-05-26 16:36:00 -040092 /*
93 * Get the actual namespace node for the target object. Handles these cases:
94 *
95 * 1) Null node, Pathname (absolute path)
96 * 2) Node, Pathname (path relative to Node)
97 * 3) Node, Null Pathname
98 */
99 status = acpi_ns_get_node(info->prefix_node, info->pathname,
100 ACPI_NS_NO_UPSEARCH, &info->resolved_node);
Len Brown4be44fc2005-08-05 00:44:28 -0400101 if (ACPI_FAILURE(status)) {
102 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /*
106 * For a method alias, we must grab the actual method node so that proper
107 * scoping context will be established before execution.
108 */
Bob Moore41195322006-05-26 16:36:00 -0400109 if (acpi_ns_get_type(info->resolved_node) ==
110 ACPI_TYPE_LOCAL_METHOD_ALIAS) {
111 info->resolved_node =
Len Brown4be44fc2005-08-05 00:44:28 -0400112 ACPI_CAST_PTR(struct acpi_namespace_node,
Bob Moore41195322006-05-26 16:36:00 -0400113 info->resolved_node->object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115
Bob Moore41195322006-05-26 16:36:00 -0400116 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n", info->pathname,
117 info->resolved_node,
118 acpi_ns_get_attached_object(info->resolved_node)));
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 /*
121 * Two major cases here:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 *
Bob Moore41195322006-05-26 16:36:00 -0400123 * 1) The object is a control method -- execute it
124 * 2) The object is not a method -- just return it's current value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 */
Bob Moore41195322006-05-26 16:36:00 -0400126 if (acpi_ns_get_type(info->resolved_node) == ACPI_TYPE_METHOD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /*
Bob Moore41195322006-05-26 16:36:00 -0400128 * 1) Object is a control method - execute it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 */
Bob Moore41195322006-05-26 16:36:00 -0400130
131 /* Verify that there is a method object associated with this node */
132
133 info->obj_desc =
134 acpi_ns_get_attached_object(info->resolved_node);
135 if (!info->obj_desc) {
136 ACPI_ERROR((AE_INFO,
137 "Control method has no attached sub-object"));
138 return_ACPI_STATUS(AE_NULL_OBJECT);
139 }
140
Bob Mooref3454ae2008-06-10 12:25:42 +0800141 /*
142 * Calculate the number of arguments being passed to the method
143 */
144
145 info->param_count = 0;
146 if (info->parameters) {
147 while (info->parameters[info->param_count])
148 info->param_count++;
149 }
150
Lin Ming93851b42008-09-27 10:38:07 +0800151 /*
152 * Warning if too few or too many arguments have been passed by the
153 * caller. We don't want to abort here with an error because an
154 * incorrect number of arguments may not cause the method to fail.
155 * However, the method will fail if there are too few arguments passed
156 * and the method attempts to use one of the missing ones.
157 */
Bob Mooref3454ae2008-06-10 12:25:42 +0800158
159 if (info->param_count < info->obj_desc->method.param_count) {
Lin Ming93851b42008-09-27 10:38:07 +0800160 ACPI_WARNING((AE_INFO,
Bob Mooref3454ae2008-06-10 12:25:42 +0800161 "Insufficient arguments - "
162 "method [%4.4s] needs %d, found %d",
163 acpi_ut_get_node_name(info->resolved_node),
164 info->obj_desc->method.param_count,
165 info->param_count));
Lin Ming93851b42008-09-27 10:38:07 +0800166 } else if (info->param_count >
Bob Mooref3454ae2008-06-10 12:25:42 +0800167 info->obj_desc->method.param_count) {
168 ACPI_WARNING((AE_INFO,
169 "Excess arguments - "
170 "method [%4.4s] needs %d, found %d",
171 acpi_ut_get_node_name(info->
172 resolved_node),
173 info->obj_desc->method.param_count,
174 info->param_count));
175 }
176
Bob Moore41195322006-05-26 16:36:00 -0400177 ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:",
178 ACPI_LV_INFO, _COMPONENT);
179
180 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
181 "Method at AML address %p Length %X\n",
182 info->obj_desc->method.aml_start + 1,
183 info->obj_desc->method.aml_length - 1));
184
185 /*
186 * Any namespace deletion must acquire both the namespace and
187 * interpreter locks to ensure that no thread is using the portion of
188 * the namespace that is being deleted.
189 *
190 * Execute the method via the interpreter. The interpreter is locked
191 * here before calling into the AML parser
192 */
Len Brown4d2acd92007-05-09 22:56:38 -0400193 acpi_ex_enter_interpreter();
Bob Moore41195322006-05-26 16:36:00 -0400194 status = acpi_ps_execute_method(info);
195 acpi_ex_exit_interpreter();
Len Brown4be44fc2005-08-05 00:44:28 -0400196 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 /*
Bob Moore41195322006-05-26 16:36:00 -0400198 * 2) Object is not a method, return its current value
Bob Mooreb68bacf2008-09-27 10:29:31 +0800199 *
200 * Disallow certain object types. For these, "evaluation" is undefined.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 */
Bob Mooreb68bacf2008-09-27 10:29:31 +0800202 switch (info->resolved_node->type) {
203 case ACPI_TYPE_DEVICE:
204 case ACPI_TYPE_EVENT:
205 case ACPI_TYPE_MUTEX:
206 case ACPI_TYPE_REGION:
207 case ACPI_TYPE_THERMAL:
208 case ACPI_TYPE_LOCAL_SCOPE:
209
210 ACPI_ERROR((AE_INFO,
211 "[%4.4s] Evaluation of object type [%s] is not supported",
212 info->resolved_node->name.ascii,
213 acpi_ut_get_type_name(info->resolved_node->
214 type)));
215
216 return_ACPI_STATUS(AE_TYPE);
217
218 default:
219 break;
220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Bob Moore41195322006-05-26 16:36:00 -0400222 /*
223 * Objects require additional resolution steps (e.g., the Node may be
224 * a field that must be read, etc.) -- we can't just grab the object
225 * out of the node.
226 *
227 * Use resolve_node_to_value() to get the associated value.
228 *
229 * NOTE: we can get away with passing in NULL for a walk state because
230 * resolved_node is guaranteed to not be a reference to either a method
231 * local or a method argument (because this interface is never called
232 * from a running method.)
233 *
234 * Even though we do not directly invoke the interpreter for object
235 * resolution, we must lock it because we could access an opregion.
236 * The opregion access code assumes that the interpreter is locked.
237 */
Len Brown4d2acd92007-05-09 22:56:38 -0400238 acpi_ex_enter_interpreter();
Bob Moore52fc0b02006-10-02 00:00:00 -0400239
Bob Moore41195322006-05-26 16:36:00 -0400240 /* Function has a strange interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Bob Moore41195322006-05-26 16:36:00 -0400242 status =
243 acpi_ex_resolve_node_to_value(&info->resolved_node, NULL);
244 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 /*
247 * If acpi_ex_resolve_node_to_value() succeeded, the return value was placed
248 * in resolved_node.
249 */
Len Brown4be44fc2005-08-05 00:44:28 -0400250 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 status = AE_CTRL_RETURN_VALUE;
Bob Moore41195322006-05-26 16:36:00 -0400252 info->return_object =
253 ACPI_CAST_PTR(union acpi_operand_object,
254 info->resolved_node);
255
Len Brown4be44fc2005-08-05 00:44:28 -0400256 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
257 "Returning object %p [%s]\n",
258 info->return_object,
259 acpi_ut_get_object_type_name(info->
260 return_object)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
262 }
263
Bob Moore41195322006-05-26 16:36:00 -0400264 /*
265 * Check if there is a return value that must be dealt with
266 */
267 if (status == AE_CTRL_RETURN_VALUE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Bob Moore41195322006-05-26 16:36:00 -0400269 /* If caller does not want the return value, delete it */
270
271 if (info->flags & ACPI_IGNORE_RETURN_VALUE) {
272 acpi_ut_remove_reference(info->return_object);
273 info->return_object = NULL;
274 }
275
276 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
277
278 status = AE_OK;
279 }
280
281 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
282 "*** Completed evaluation of object %s ***\n",
283 info->pathname));
284
285 /*
286 * Namespace was unlocked by the handling acpi_ns* function, so we
287 * just return
288 */
Len Brown4be44fc2005-08-05 00:44:28 -0400289 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}