Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 3 | * Module Name: nseval - Object evaluation, includes control method execution |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | ******************************************************************************/ |
| 6 | |
| 7 | /* |
Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2008, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/acparser.h> |
| 46 | #include <acpi/acinterp.h> |
| 47 | #include <acpi/acnamesp.h> |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define _COMPONENT ACPI_NAMESPACE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("nseval") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | /******************************************************************************* |
| 53 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 54 | * FUNCTION: acpi_ns_evaluate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 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 |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 60 | * Parameters - List of parameters to pass to the method, |
| 61 | * terminated by NULL. Params itself may be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * NULL if no parameters are being passed. |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 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. |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 68 | * Flags - ACPI_IGNORE_RETURN_VALUE to delete return |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | * |
| 70 | * RETURN: Status |
| 71 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 72 | * DESCRIPTION: Execute a control method or return the current value of an |
| 73 | * ACPI namespace object. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 75 | * MUTEX: Locks interpreter |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | * |
| 77 | ******************************************************************************/ |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 78 | acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | acpi_status status; |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 81 | struct acpi_namespace_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 83 | ACPI_FUNCTION_TRACE(ns_evaluate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | if (!info) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* Initialize the return value to an invalid object */ |
| 90 | |
| 91 | info->return_object = NULL; |
| 92 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 93 | /* |
| 94 | * Get the actual namespace node for the target object. Handles these cases: |
| 95 | * |
| 96 | * 1) Null node, Pathname (absolute path) |
| 97 | * 2) Node, Pathname (path relative to Node) |
| 98 | * 3) Node, Null Pathname |
| 99 | */ |
| 100 | status = acpi_ns_get_node(info->prefix_node, info->pathname, |
| 101 | ACPI_NS_NO_UPSEARCH, &info->resolved_node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | if (ACPI_FAILURE(status)) { |
| 103 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /* |
| 107 | * For a method alias, we must grab the actual method node so that proper |
| 108 | * scoping context will be established before execution. |
| 109 | */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 110 | if (acpi_ns_get_type(info->resolved_node) == |
| 111 | ACPI_TYPE_LOCAL_METHOD_ALIAS) { |
| 112 | info->resolved_node = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | ACPI_CAST_PTR(struct acpi_namespace_node, |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 114 | info->resolved_node->object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 117 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n", info->pathname, |
| 118 | info->resolved_node, |
| 119 | acpi_ns_get_attached_object(info->resolved_node))); |
| 120 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 121 | node = info->resolved_node; |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | /* |
| 124 | * Two major cases here: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 126 | * 1) The object is a control method -- execute it |
| 127 | * 2) The object is not a method -- just return it's current value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 129 | if (acpi_ns_get_type(info->resolved_node) == ACPI_TYPE_METHOD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | /* |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 131 | * 1) Object is a control method - execute it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | */ |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 133 | |
| 134 | /* Verify that there is a method object associated with this node */ |
| 135 | |
| 136 | info->obj_desc = |
| 137 | acpi_ns_get_attached_object(info->resolved_node); |
| 138 | if (!info->obj_desc) { |
| 139 | ACPI_ERROR((AE_INFO, |
| 140 | "Control method has no attached sub-object")); |
| 141 | return_ACPI_STATUS(AE_NULL_OBJECT); |
| 142 | } |
| 143 | |
Bob Moore | f3454ae | 2008-06-10 12:25:42 +0800 | [diff] [blame] | 144 | /* |
| 145 | * Calculate the number of arguments being passed to the method |
| 146 | */ |
| 147 | |
| 148 | info->param_count = 0; |
| 149 | if (info->parameters) { |
| 150 | while (info->parameters[info->param_count]) |
| 151 | info->param_count++; |
| 152 | } |
| 153 | |
Lin Ming | 93851b4 | 2008-09-27 10:38:07 +0800 | [diff] [blame] | 154 | /* |
| 155 | * Warning if too few or too many arguments have been passed by the |
| 156 | * caller. We don't want to abort here with an error because an |
| 157 | * incorrect number of arguments may not cause the method to fail. |
| 158 | * However, the method will fail if there are too few arguments passed |
| 159 | * and the method attempts to use one of the missing ones. |
| 160 | */ |
Bob Moore | f3454ae | 2008-06-10 12:25:42 +0800 | [diff] [blame] | 161 | |
| 162 | if (info->param_count < info->obj_desc->method.param_count) { |
Lin Ming | 93851b4 | 2008-09-27 10:38:07 +0800 | [diff] [blame] | 163 | ACPI_WARNING((AE_INFO, |
Bob Moore | f3454ae | 2008-06-10 12:25:42 +0800 | [diff] [blame] | 164 | "Insufficient arguments - " |
| 165 | "method [%4.4s] needs %d, found %d", |
| 166 | acpi_ut_get_node_name(info->resolved_node), |
| 167 | info->obj_desc->method.param_count, |
| 168 | info->param_count)); |
Lin Ming | 93851b4 | 2008-09-27 10:38:07 +0800 | [diff] [blame] | 169 | } else if (info->param_count > |
Bob Moore | f3454ae | 2008-06-10 12:25:42 +0800 | [diff] [blame] | 170 | info->obj_desc->method.param_count) { |
| 171 | ACPI_WARNING((AE_INFO, |
| 172 | "Excess arguments - " |
| 173 | "method [%4.4s] needs %d, found %d", |
| 174 | acpi_ut_get_node_name(info-> |
| 175 | resolved_node), |
| 176 | info->obj_desc->method.param_count, |
| 177 | info->param_count)); |
| 178 | } |
| 179 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 180 | ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:", |
| 181 | ACPI_LV_INFO, _COMPONENT); |
| 182 | |
| 183 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 184 | "Method at AML address %p Length %X\n", |
| 185 | info->obj_desc->method.aml_start + 1, |
| 186 | info->obj_desc->method.aml_length - 1)); |
| 187 | |
| 188 | /* |
| 189 | * Any namespace deletion must acquire both the namespace and |
| 190 | * interpreter locks to ensure that no thread is using the portion of |
| 191 | * the namespace that is being deleted. |
| 192 | * |
| 193 | * Execute the method via the interpreter. The interpreter is locked |
| 194 | * here before calling into the AML parser |
| 195 | */ |
Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 196 | acpi_ex_enter_interpreter(); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 197 | status = acpi_ps_execute_method(info); |
| 198 | acpi_ex_exit_interpreter(); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | /* |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 201 | * 2) Object is not a method, return its current value |
Bob Moore | b68bacf | 2008-09-27 10:29:31 +0800 | [diff] [blame] | 202 | * |
| 203 | * Disallow certain object types. For these, "evaluation" is undefined. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | */ |
Bob Moore | b68bacf | 2008-09-27 10:29:31 +0800 | [diff] [blame] | 205 | switch (info->resolved_node->type) { |
| 206 | case ACPI_TYPE_DEVICE: |
| 207 | case ACPI_TYPE_EVENT: |
| 208 | case ACPI_TYPE_MUTEX: |
| 209 | case ACPI_TYPE_REGION: |
| 210 | case ACPI_TYPE_THERMAL: |
| 211 | case ACPI_TYPE_LOCAL_SCOPE: |
| 212 | |
| 213 | ACPI_ERROR((AE_INFO, |
| 214 | "[%4.4s] Evaluation of object type [%s] is not supported", |
| 215 | info->resolved_node->name.ascii, |
| 216 | acpi_ut_get_type_name(info->resolved_node-> |
| 217 | type))); |
| 218 | |
| 219 | return_ACPI_STATUS(AE_TYPE); |
| 220 | |
| 221 | default: |
| 222 | break; |
| 223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 225 | /* |
| 226 | * Objects require additional resolution steps (e.g., the Node may be |
| 227 | * a field that must be read, etc.) -- we can't just grab the object |
| 228 | * out of the node. |
| 229 | * |
| 230 | * Use resolve_node_to_value() to get the associated value. |
| 231 | * |
| 232 | * NOTE: we can get away with passing in NULL for a walk state because |
| 233 | * resolved_node is guaranteed to not be a reference to either a method |
| 234 | * local or a method argument (because this interface is never called |
| 235 | * from a running method.) |
| 236 | * |
| 237 | * Even though we do not directly invoke the interpreter for object |
| 238 | * resolution, we must lock it because we could access an opregion. |
| 239 | * The opregion access code assumes that the interpreter is locked. |
| 240 | */ |
Len Brown | 4d2acd9 | 2007-05-09 22:56:38 -0400 | [diff] [blame] | 241 | acpi_ex_enter_interpreter(); |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 242 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 243 | /* Function has a strange interface */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 245 | status = |
| 246 | acpi_ex_resolve_node_to_value(&info->resolved_node, NULL); |
| 247 | acpi_ex_exit_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | /* |
| 250 | * If acpi_ex_resolve_node_to_value() succeeded, the return value was placed |
| 251 | * in resolved_node. |
| 252 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | if (ACPI_SUCCESS(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | status = AE_CTRL_RETURN_VALUE; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 255 | info->return_object = |
| 256 | ACPI_CAST_PTR(union acpi_operand_object, |
| 257 | info->resolved_node); |
| 258 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 260 | "Returning object %p [%s]\n", |
| 261 | info->return_object, |
| 262 | acpi_ut_get_object_type_name(info-> |
| 263 | return_object))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
Bob Moore | e8707b3 | 2008-09-28 15:26:17 +0800 | [diff] [blame] | 267 | /* Validation of return values for ACPI-predefined methods and objects */ |
| 268 | |
| 269 | if ((status == AE_OK) || (status == AE_CTRL_RETURN_VALUE)) { |
| 270 | /* |
| 271 | * If this is the first evaluation, check the return value. This |
| 272 | * ensures that any warnings will only be emitted during the very |
| 273 | * first evaluation of the object. |
| 274 | */ |
| 275 | if (!(node->flags & ANOBJ_EVALUATED)) { |
| 276 | /* |
| 277 | * Check for a predefined ACPI name. If found, validate the |
| 278 | * returned object. |
| 279 | * |
| 280 | * Note: Ignore return status for now, emit warnings if there are |
| 281 | * problems with the returned object. May change later to abort |
| 282 | * the method on invalid return object. |
| 283 | */ |
| 284 | (void)acpi_ns_check_predefined_names(node, |
| 285 | info-> |
| 286 | return_object); |
| 287 | } |
| 288 | |
| 289 | /* Mark the node as having been evaluated */ |
| 290 | |
| 291 | node->flags |= ANOBJ_EVALUATED; |
| 292 | } |
| 293 | |
| 294 | /* Check if there is a return value that must be dealt with */ |
| 295 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 296 | if (status == AE_CTRL_RETURN_VALUE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 298 | /* If caller does not want the return value, delete it */ |
| 299 | |
| 300 | if (info->flags & ACPI_IGNORE_RETURN_VALUE) { |
| 301 | acpi_ut_remove_reference(info->return_object); |
| 302 | info->return_object = NULL; |
| 303 | } |
| 304 | |
| 305 | /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */ |
| 306 | |
| 307 | status = AE_OK; |
| 308 | } |
| 309 | |
| 310 | ACPI_DEBUG_PRINT((ACPI_DB_NAMES, |
| 311 | "*** Completed evaluation of object %s ***\n", |
| 312 | info->pathname)); |
| 313 | |
| 314 | /* |
| 315 | * Namespace was unlocked by the handling acpi_ns* function, so we |
| 316 | * just return |
| 317 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 318 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |