blob: b95bfbbf5617e1973241a1d0accb84bbf5e81563 [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;
Bob Mooree8707b32008-09-28 15:26:17 +080081 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Bob Moore41195322006-05-26 16:36:00 -040083 ACPI_FUNCTION_TRACE(ns_evaluate);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 if (!info) {
Len Brown4be44fc2005-08-05 00:44:28 -040086 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88
89 /* Initialize the return value to an invalid object */
90
91 info->return_object = NULL;
Bob Mooreeeb44372008-11-13 11:19:24 +080092 info->param_count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Bob Moore41195322006-05-26 16:36:00 -040094 /*
95 * Get the actual namespace node for the target object. Handles these cases:
96 *
97 * 1) Null node, Pathname (absolute path)
98 * 2) Node, Pathname (path relative to Node)
99 * 3) Node, Null Pathname
100 */
101 status = acpi_ns_get_node(info->prefix_node, info->pathname,
102 ACPI_NS_NO_UPSEARCH, &info->resolved_node);
Len Brown4be44fc2005-08-05 00:44:28 -0400103 if (ACPI_FAILURE(status)) {
104 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /*
108 * For a method alias, we must grab the actual method node so that proper
109 * scoping context will be established before execution.
110 */
Bob Moore41195322006-05-26 16:36:00 -0400111 if (acpi_ns_get_type(info->resolved_node) ==
112 ACPI_TYPE_LOCAL_METHOD_ALIAS) {
113 info->resolved_node =
Len Brown4be44fc2005-08-05 00:44:28 -0400114 ACPI_CAST_PTR(struct acpi_namespace_node,
Bob Moore41195322006-05-26 16:36:00 -0400115 info->resolved_node->object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117
Bob Moore41195322006-05-26 16:36:00 -0400118 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n", info->pathname,
119 info->resolved_node,
120 acpi_ns_get_attached_object(info->resolved_node)));
121
Bob Mooree8707b32008-09-28 15:26:17 +0800122 node = info->resolved_node;
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /*
125 * Two major cases here:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 *
Bob Moore41195322006-05-26 16:36:00 -0400127 * 1) The object is a control method -- execute it
128 * 2) The object is not a method -- just return it's current value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 */
Bob Moore41195322006-05-26 16:36:00 -0400130 if (acpi_ns_get_type(info->resolved_node) == ACPI_TYPE_METHOD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /*
Bob Moore41195322006-05-26 16:36:00 -0400132 * 1) Object is a control method - execute it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 */
Bob Moore41195322006-05-26 16:36:00 -0400134
135 /* Verify that there is a method object associated with this node */
136
137 info->obj_desc =
138 acpi_ns_get_attached_object(info->resolved_node);
139 if (!info->obj_desc) {
140 ACPI_ERROR((AE_INFO,
141 "Control method has no attached sub-object"));
142 return_ACPI_STATUS(AE_NULL_OBJECT);
143 }
144
Bob Mooreeeb44372008-11-13 11:19:24 +0800145 /* Count the number of arguments being passed to the method */
Bob Mooref3454ae2008-06-10 12:25:42 +0800146
Bob Mooref3454ae2008-06-10 12:25:42 +0800147 if (info->parameters) {
Bob Mooreeeb44372008-11-13 11:19:24 +0800148 while (info->parameters[info->param_count]) {
149 if (info->param_count > ACPI_METHOD_MAX_ARG) {
150 return_ACPI_STATUS(AE_LIMIT);
151 }
Bob Mooref3454ae2008-06-10 12:25:42 +0800152 info->param_count++;
Bob Mooreeeb44372008-11-13 11:19:24 +0800153 }
Bob Mooref3454ae2008-06-10 12:25:42 +0800154 }
155
Bob Mooref3454ae2008-06-10 12:25:42 +0800156
Bob Moore41195322006-05-26 16:36:00 -0400157 ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:",
158 ACPI_LV_INFO, _COMPONENT);
159
160 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
161 "Method at AML address %p Length %X\n",
162 info->obj_desc->method.aml_start + 1,
163 info->obj_desc->method.aml_length - 1));
164
165 /*
166 * Any namespace deletion must acquire both the namespace and
167 * interpreter locks to ensure that no thread is using the portion of
168 * the namespace that is being deleted.
169 *
170 * Execute the method via the interpreter. The interpreter is locked
171 * here before calling into the AML parser
172 */
Len Brown4d2acd92007-05-09 22:56:38 -0400173 acpi_ex_enter_interpreter();
Bob Moore41195322006-05-26 16:36:00 -0400174 status = acpi_ps_execute_method(info);
175 acpi_ex_exit_interpreter();
Len Brown4be44fc2005-08-05 00:44:28 -0400176 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /*
Bob Moore41195322006-05-26 16:36:00 -0400178 * 2) Object is not a method, return its current value
Bob Mooreb68bacf2008-09-27 10:29:31 +0800179 *
180 * Disallow certain object types. For these, "evaluation" is undefined.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 */
Bob Mooreb68bacf2008-09-27 10:29:31 +0800182 switch (info->resolved_node->type) {
183 case ACPI_TYPE_DEVICE:
184 case ACPI_TYPE_EVENT:
185 case ACPI_TYPE_MUTEX:
186 case ACPI_TYPE_REGION:
187 case ACPI_TYPE_THERMAL:
188 case ACPI_TYPE_LOCAL_SCOPE:
189
190 ACPI_ERROR((AE_INFO,
191 "[%4.4s] Evaluation of object type [%s] is not supported",
192 info->resolved_node->name.ascii,
193 acpi_ut_get_type_name(info->resolved_node->
194 type)));
195
196 return_ACPI_STATUS(AE_TYPE);
197
198 default:
199 break;
200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Bob Moore41195322006-05-26 16:36:00 -0400202 /*
203 * Objects require additional resolution steps (e.g., the Node may be
204 * a field that must be read, etc.) -- we can't just grab the object
205 * out of the node.
206 *
207 * Use resolve_node_to_value() to get the associated value.
208 *
209 * NOTE: we can get away with passing in NULL for a walk state because
210 * resolved_node is guaranteed to not be a reference to either a method
211 * local or a method argument (because this interface is never called
212 * from a running method.)
213 *
214 * Even though we do not directly invoke the interpreter for object
215 * resolution, we must lock it because we could access an opregion.
216 * The opregion access code assumes that the interpreter is locked.
217 */
Len Brown4d2acd92007-05-09 22:56:38 -0400218 acpi_ex_enter_interpreter();
Bob Moore52fc0b02006-10-02 00:00:00 -0400219
Bob Moore41195322006-05-26 16:36:00 -0400220 /* Function has a strange interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Bob Moore41195322006-05-26 16:36:00 -0400222 status =
223 acpi_ex_resolve_node_to_value(&info->resolved_node, NULL);
224 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 /*
227 * If acpi_ex_resolve_node_to_value() succeeded, the return value was placed
228 * in resolved_node.
229 */
Len Brown4be44fc2005-08-05 00:44:28 -0400230 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 status = AE_CTRL_RETURN_VALUE;
Bob Moore41195322006-05-26 16:36:00 -0400232 info->return_object =
233 ACPI_CAST_PTR(union acpi_operand_object,
234 info->resolved_node);
235
Len Brown4be44fc2005-08-05 00:44:28 -0400236 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
237 "Returning object %p [%s]\n",
238 info->return_object,
239 acpi_ut_get_object_type_name(info->
240 return_object)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
242 }
243
Bob Mooreeeb44372008-11-13 11:19:24 +0800244 /*
245 * Check input argument count against the ASL-defined count for a method.
246 * Also check predefined names: argument count and return value against
247 * the ACPI specification. Some incorrect return value types are repaired.
248 */
249 (void)acpi_ns_check_predefined_names(node, info->param_count,
250 status, &info->return_object);
Bob Mooree8707b32008-09-28 15:26:17 +0800251
252 /* Check if there is a return value that must be dealt with */
253
Bob Moore41195322006-05-26 16:36:00 -0400254 if (status == AE_CTRL_RETURN_VALUE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Bob Moore41195322006-05-26 16:36:00 -0400256 /* If caller does not want the return value, delete it */
257
258 if (info->flags & ACPI_IGNORE_RETURN_VALUE) {
259 acpi_ut_remove_reference(info->return_object);
260 info->return_object = NULL;
261 }
262
263 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
264
265 status = AE_OK;
266 }
267
268 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
269 "*** Completed evaluation of object %s ***\n",
270 info->pathname));
271
272 /*
273 * Namespace was unlocked by the handling acpi_ns* function, so we
274 * just return
275 */
Len Brown4be44fc2005-08-05 00:44:28 -0400276 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}