Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /******************************************************************************* |
2 | * | |
4119532c | 3 | * Module Name: nseval - Object evaluation, includes control method execution |
1da177e4 LT |
4 | * |
5 | ******************************************************************************/ | |
6 | ||
7 | /* | |
75a44ce0 | 8 | * Copyright (C) 2000 - 2008, Intel Corp. |
1da177e4 LT |
9 | * 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 | ||
1da177e4 LT |
44 | #include <acpi/acpi.h> |
45 | #include <acpi/acparser.h> | |
46 | #include <acpi/acinterp.h> | |
47 | #include <acpi/acnamesp.h> | |
48 | ||
1da177e4 | 49 | #define _COMPONENT ACPI_NAMESPACE |
4be44fcd | 50 | ACPI_MODULE_NAME("nseval") |
1da177e4 | 51 | |
1da177e4 LT |
52 | /******************************************************************************* |
53 | * | |
4119532c | 54 | * FUNCTION: acpi_ns_evaluate |
1da177e4 | 55 | * |
4119532c BM |
56 | * 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 | |
44f6c012 RM |
60 | * Parameters - List of parameters to pass to the method, |
61 | * terminated by NULL. Params itself may be | |
1da177e4 | 62 | * NULL if no parameters are being passed. |
44f6c012 RM |
63 | * 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. | |
4119532c | 68 | * Flags - ACPI_IGNORE_RETURN_VALUE to delete return |
1da177e4 LT |
69 | * |
70 | * RETURN: Status | |
71 | * | |
4119532c BM |
72 | * DESCRIPTION: Execute a control method or return the current value of an |
73 | * ACPI namespace object. | |
1da177e4 | 74 | * |
4119532c | 75 | * MUTEX: Locks interpreter |
1da177e4 LT |
76 | * |
77 | ******************************************************************************/ | |
fd350943 | 78 | acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info) |
1da177e4 | 79 | { |
4be44fcd | 80 | acpi_status status; |
1da177e4 | 81 | |
4119532c | 82 | ACPI_FUNCTION_TRACE(ns_evaluate); |
1da177e4 LT |
83 | |
84 | if (!info) { | |
4be44fcd | 85 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
86 | } |
87 | ||
88 | /* Initialize the return value to an invalid object */ | |
89 | ||
90 | info->return_object = NULL; | |
91 | ||
4119532c BM |
92 | /* |
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); | |
4be44fcd LB |
101 | if (ACPI_FAILURE(status)) { |
102 | return_ACPI_STATUS(status); | |
1da177e4 LT |
103 | } |
104 | ||
1da177e4 LT |
105 | /* |
106 | * For a method alias, we must grab the actual method node so that proper | |
107 | * scoping context will be established before execution. | |
108 | */ | |
4119532c BM |
109 | if (acpi_ns_get_type(info->resolved_node) == |
110 | ACPI_TYPE_LOCAL_METHOD_ALIAS) { | |
111 | info->resolved_node = | |
4be44fcd | 112 | ACPI_CAST_PTR(struct acpi_namespace_node, |
4119532c | 113 | info->resolved_node->object); |
1da177e4 LT |
114 | } |
115 | ||
4119532c BM |
116 | 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 | ||
1da177e4 LT |
120 | /* |
121 | * Two major cases here: | |
1da177e4 | 122 | * |
4119532c BM |
123 | * 1) The object is a control method -- execute it |
124 | * 2) The object is not a method -- just return it's current value | |
1da177e4 | 125 | */ |
4119532c | 126 | if (acpi_ns_get_type(info->resolved_node) == ACPI_TYPE_METHOD) { |
1da177e4 | 127 | /* |
4119532c | 128 | * 1) Object is a control method - execute it |
1da177e4 | 129 | */ |
1da177e4 | 130 | |
4119532c | 131 | /* Verify that there is a method object associated with this node */ |
1da177e4 | 132 | |
4119532c BM |
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 | } | |
1da177e4 | 140 | |
f3454ae8 BM |
141 | /* |
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 | ||
151 | /* Error if too few arguments were passed in */ | |
152 | ||
153 | if (info->param_count < info->obj_desc->method.param_count) { | |
154 | ACPI_ERROR((AE_INFO, | |
155 | "Insufficient arguments - " | |
156 | "method [%4.4s] needs %d, found %d", | |
157 | acpi_ut_get_node_name(info->resolved_node), | |
158 | info->obj_desc->method.param_count, | |
159 | info->param_count)); | |
160 | return_ACPI_STATUS(AE_MISSING_ARGUMENTS); | |
161 | } | |
162 | ||
163 | /* Just a warning if too many arguments */ | |
164 | ||
165 | else if (info->param_count > | |
166 | info->obj_desc->method.param_count) { | |
167 | ACPI_WARNING((AE_INFO, | |
168 | "Excess arguments - " | |
169 | "method [%4.4s] needs %d, found %d", | |
170 | acpi_ut_get_node_name(info-> | |
171 | resolved_node), | |
172 | info->obj_desc->method.param_count, | |
173 | info->param_count)); | |
174 | } | |
175 | ||
4119532c BM |
176 | ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:", |
177 | ACPI_LV_INFO, _COMPONENT); | |
1da177e4 | 178 | |
4119532c BM |
179 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
180 | "Method at AML address %p Length %X\n", | |
181 | info->obj_desc->method.aml_start + 1, | |
182 | info->obj_desc->method.aml_length - 1)); | |
1da177e4 | 183 | |
4119532c BM |
184 | /* |
185 | * Any namespace deletion must acquire both the namespace and | |
186 | * interpreter locks to ensure that no thread is using the portion of | |
187 | * the namespace that is being deleted. | |
188 | * | |
189 | * Execute the method via the interpreter. The interpreter is locked | |
190 | * here before calling into the AML parser | |
191 | */ | |
4d2acd9e | 192 | acpi_ex_enter_interpreter(); |
4119532c BM |
193 | status = acpi_ps_execute_method(info); |
194 | acpi_ex_exit_interpreter(); | |
195 | } else { | |
196 | /* | |
197 | * 2) Object is not a method, return its current value | |
198 | */ | |
1da177e4 | 199 | |
4119532c BM |
200 | /* |
201 | * Objects require additional resolution steps (e.g., the Node may be | |
202 | * a field that must be read, etc.) -- we can't just grab the object | |
203 | * out of the node. | |
204 | * | |
205 | * Use resolve_node_to_value() to get the associated value. | |
206 | * | |
207 | * NOTE: we can get away with passing in NULL for a walk state because | |
208 | * resolved_node is guaranteed to not be a reference to either a method | |
209 | * local or a method argument (because this interface is never called | |
210 | * from a running method.) | |
211 | * | |
212 | * Even though we do not directly invoke the interpreter for object | |
213 | * resolution, we must lock it because we could access an opregion. | |
214 | * The opregion access code assumes that the interpreter is locked. | |
215 | */ | |
4d2acd9e | 216 | acpi_ex_enter_interpreter(); |
1da177e4 | 217 | |
4119532c | 218 | /* Function has a strange interface */ |
1da177e4 | 219 | |
4119532c BM |
220 | status = |
221 | acpi_ex_resolve_node_to_value(&info->resolved_node, NULL); | |
222 | acpi_ex_exit_interpreter(); | |
1da177e4 | 223 | |
1da177e4 LT |
224 | /* |
225 | * If acpi_ex_resolve_node_to_value() succeeded, the return value was placed | |
226 | * in resolved_node. | |
227 | */ | |
4be44fcd | 228 | if (ACPI_SUCCESS(status)) { |
1da177e4 | 229 | status = AE_CTRL_RETURN_VALUE; |
4119532c BM |
230 | info->return_object = |
231 | ACPI_CAST_PTR(union acpi_operand_object, | |
232 | info->resolved_node); | |
233 | ||
4be44fcd LB |
234 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
235 | "Returning object %p [%s]\n", | |
236 | info->return_object, | |
237 | acpi_ut_get_object_type_name(info-> | |
238 | return_object))); | |
1da177e4 LT |
239 | } |
240 | } | |
241 | ||
4119532c BM |
242 | /* |
243 | * Check if there is a return value that must be dealt with | |
244 | */ | |
245 | if (status == AE_CTRL_RETURN_VALUE) { | |
246 | ||
247 | /* If caller does not want the return value, delete it */ | |
1da177e4 | 248 | |
4119532c BM |
249 | if (info->flags & ACPI_IGNORE_RETURN_VALUE) { |
250 | acpi_ut_remove_reference(info->return_object); | |
251 | info->return_object = NULL; | |
252 | } | |
253 | ||
254 | /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */ | |
255 | ||
256 | status = AE_OK; | |
257 | } | |
258 | ||
259 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, | |
260 | "*** Completed evaluation of object %s ***\n", | |
261 | info->pathname)); | |
262 | ||
263 | /* | |
264 | * Namespace was unlocked by the handling acpi_ns* function, so we | |
265 | * just return | |
266 | */ | |
4be44fcd | 267 | return_ACPI_STATUS(status); |
1da177e4 | 268 | } |