Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: dsmethod - Parser/Interpreter interface - control method parsing |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2005, R. Byron Moore |
| 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/amlcode.h> |
| 47 | #include <acpi/acdispat.h> |
| 48 | #include <acpi/acinterp.h> |
| 49 | #include <acpi/acnamesp.h> |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define _COMPONENT ACPI_DISPATCHER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("dsmethod") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /******************************************************************************* |
| 55 | * |
| 56 | * FUNCTION: acpi_ds_parse_method |
| 57 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 58 | * PARAMETERS: Node - Method node |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | * |
| 60 | * RETURN: Status |
| 61 | * |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 62 | * DESCRIPTION: Parse the AML that is associated with the method. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * |
| 64 | * MUTEX: Assumes parser is locked |
| 65 | * |
| 66 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | acpi_status status; |
| 70 | union acpi_operand_object *obj_desc; |
| 71 | union acpi_parse_object *op; |
| 72 | struct acpi_walk_state *walk_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | ACPI_FUNCTION_TRACE_PTR("ds_parse_method", node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /* Parameter Validation */ |
| 77 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 78 | if (!node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 79 | return_ACPI_STATUS(AE_NULL_ENTRY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 82 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 83 | "**** Parsing [%4.4s] **** named_obj=%p\n", |
| 84 | acpi_ut_get_node_name(node), node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | /* Extract the method object from the method Node */ |
| 87 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | return_ACPI_STATUS(AE_NULL_OBJECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* Create a mutex for the method if there is a concurrency limit */ |
| 94 | |
| 95 | if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 96 | (!obj_desc->method.semaphore)) { |
| 97 | status = acpi_os_create_semaphore(obj_desc->method.concurrency, |
| 98 | obj_desc->method.concurrency, |
| 99 | &obj_desc->method.semaphore); |
| 100 | if (ACPI_FAILURE(status)) { |
| 101 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Allocate a new parser op to be the root of the parsed |
| 107 | * method tree |
| 108 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | op = acpi_ps_alloc_op(AML_METHOD_OP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | if (!op) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* Init new op with the method name and pointer back to the Node */ |
| 115 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | acpi_ps_set_name(op, node->name.integer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | op->common.node = node; |
| 118 | |
| 119 | /* |
| 120 | * Get a new owner_id for objects created by this method. Namespace |
| 121 | * objects (such as Operation Regions) can be created during the |
| 122 | * first pass parse. |
| 123 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id); |
| 125 | if (ACPI_FAILURE(status)) { |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 126 | goto cleanup; |
| 127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* Create and initialize a new walk state */ |
| 130 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | walk_state = |
| 132 | acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL, |
| 133 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | if (!walk_state) { |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame] | 135 | status = AE_NO_MEMORY; |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 136 | goto cleanup2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | status = acpi_ds_init_aml_walk(walk_state, op, node, |
| 140 | obj_desc->method.aml_start, |
| 141 | obj_desc->method.aml_length, NULL, 1); |
| 142 | if (ACPI_FAILURE(status)) { |
| 143 | acpi_ds_delete_walk_state(walk_state); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 144 | goto cleanup2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* |
| 148 | * Parse the method, first pass |
| 149 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 150 | * The first pass load is where newly declared named objects are added into |
| 151 | * the namespace. Actual evaluation of the named objects (what would be |
| 152 | * called a "second pass") happens during the actual execution of the |
| 153 | * method so that operands to the named objects can take on dynamic |
| 154 | * run-time values. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | status = acpi_ps_parse_aml(walk_state); |
| 157 | if (ACPI_FAILURE(status)) { |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 158 | goto cleanup2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 162 | "**** [%4.4s] Parsed **** named_obj=%p Op=%p\n", |
| 163 | acpi_ut_get_node_name(node), node, op)); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | * Delete the parse tree. We simply re-parse the method for every |
| 167 | * execution since there isn't much overhead (compared to keeping lots |
| 168 | * of parse trees around) |
| 169 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | acpi_ns_delete_namespace_subtree(node); |
| 171 | acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | cleanup2: |
| 174 | acpi_ut_release_owner_id(&obj_desc->method.owner_id); |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 175 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | cleanup: |
| 177 | acpi_ps_delete_parse_tree(op); |
| 178 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /******************************************************************************* |
| 182 | * |
| 183 | * FUNCTION: acpi_ds_begin_method_execution |
| 184 | * |
| 185 | * PARAMETERS: method_node - Node of the method |
| 186 | * obj_desc - The method object |
| 187 | * calling_method_node - Caller of this method (if non-null) |
| 188 | * |
| 189 | * RETURN: Status |
| 190 | * |
| 191 | * DESCRIPTION: Prepare a method for execution. Parses the method if necessary, |
| 192 | * increments the thread count, and waits at the method semaphore |
| 193 | * for clearance to execute. |
| 194 | * |
| 195 | ******************************************************************************/ |
| 196 | |
| 197 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node, |
| 199 | union acpi_operand_object *obj_desc, |
| 200 | struct acpi_namespace_node *calling_method_node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | ACPI_FUNCTION_TRACE_PTR("ds_begin_method_execution", method_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | if (!method_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 207 | return_ACPI_STATUS(AE_NULL_ENTRY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /* |
| 211 | * If there is a concurrency limit on this method, we need to |
| 212 | * obtain a unit from the method semaphore. |
| 213 | */ |
| 214 | if (obj_desc->method.semaphore) { |
| 215 | /* |
| 216 | * Allow recursive method calls, up to the reentrancy/concurrency |
| 217 | * limit imposed by the SERIALIZED rule and the sync_level method |
| 218 | * parameter. |
| 219 | * |
| 220 | * The point of this code is to avoid permanently blocking a |
| 221 | * thread that is making recursive method calls. |
| 222 | */ |
| 223 | if (method_node == calling_method_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | if (obj_desc->method.thread_count >= |
| 225 | obj_desc->method.concurrency) { |
| 226 | return_ACPI_STATUS(AE_AML_METHOD_LIMIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * Get a unit from the method semaphore. This releases the |
| 232 | * interpreter if we block |
| 233 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 234 | status = |
| 235 | acpi_ex_system_wait_semaphore(obj_desc->method.semaphore, |
| 236 | ACPI_WAIT_FOREVER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | /* |
| 240 | * Increment the method parse tree thread count since it has been |
| 241 | * reentered one more time (even if it is the same thread) |
| 242 | */ |
| 243 | obj_desc->method.thread_count++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | /******************************************************************************* |
| 248 | * |
| 249 | * FUNCTION: acpi_ds_call_control_method |
| 250 | * |
| 251 | * PARAMETERS: Thread - Info for this thread |
| 252 | * this_walk_state - Current walk state |
| 253 | * Op - Current Op to be walked |
| 254 | * |
| 255 | * RETURN: Status |
| 256 | * |
| 257 | * DESCRIPTION: Transfer execution to a called control method |
| 258 | * |
| 259 | ******************************************************************************/ |
| 260 | |
| 261 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 262 | acpi_ds_call_control_method(struct acpi_thread_state *thread, |
| 263 | struct acpi_walk_state *this_walk_state, |
| 264 | union acpi_parse_object *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 266 | acpi_status status; |
| 267 | struct acpi_namespace_node *method_node; |
| 268 | struct acpi_walk_state *next_walk_state = NULL; |
| 269 | union acpi_operand_object *obj_desc; |
| 270 | struct acpi_parameter_info info; |
| 271 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | ACPI_FUNCTION_TRACE_PTR("ds_call_control_method", this_walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 275 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 276 | "Execute method %p, currentstate=%p\n", |
| 277 | this_walk_state->prev_op, this_walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | /* |
| 280 | * Get the namespace entry for the control method we are about to call |
| 281 | */ |
| 282 | method_node = this_walk_state->method_call_node; |
| 283 | if (!method_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | return_ACPI_STATUS(AE_NULL_ENTRY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | obj_desc = acpi_ns_get_attached_object(method_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | return_ACPI_STATUS(AE_NULL_OBJECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 292 | status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id); |
| 293 | if (ACPI_FAILURE(status)) { |
| 294 | return_ACPI_STATUS(status); |
| 295 | } |
| 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | /* Init for new method, wait on concurrency semaphore */ |
| 298 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | status = acpi_ds_begin_method_execution(method_node, obj_desc, |
| 300 | this_walk_state->method_node); |
| 301 | if (ACPI_FAILURE(status)) { |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 302 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | if (!(obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY)) { |
| 306 | /* 1) Parse: Create a new walk state for the preempting walk */ |
| 307 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | next_walk_state = |
| 309 | acpi_ds_create_walk_state(obj_desc->method.owner_id, op, |
| 310 | obj_desc, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (!next_walk_state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /* Create and init a Root Node */ |
| 316 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | op = acpi_ps_create_scope_op(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (!op) { |
| 319 | status = AE_NO_MEMORY; |
| 320 | goto cleanup; |
| 321 | } |
| 322 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 323 | status = acpi_ds_init_aml_walk(next_walk_state, op, method_node, |
| 324 | obj_desc->method.aml_start, |
| 325 | obj_desc->method.aml_length, |
| 326 | NULL, 1); |
| 327 | if (ACPI_FAILURE(status)) { |
| 328 | acpi_ds_delete_walk_state(next_walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | goto cleanup; |
| 330 | } |
| 331 | |
| 332 | /* Begin AML parse */ |
| 333 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 334 | status = acpi_ps_parse_aml(next_walk_state); |
| 335 | acpi_ps_delete_parse_tree(op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | /* 2) Execute: Create a new state for the preempting walk */ |
| 339 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id, |
| 341 | NULL, obj_desc, thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (!next_walk_state) { |
| 343 | status = AE_NO_MEMORY; |
| 344 | goto cleanup; |
| 345 | } |
| 346 | /* |
| 347 | * The resolved arguments were put on the previous walk state's operand |
| 348 | * stack. Operands on the previous walk state stack always |
| 349 | * start at index 0. |
| 350 | * Null terminate the list of arguments |
| 351 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 352 | this_walk_state->operands[this_walk_state->num_operands] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | info.parameters = &this_walk_state->operands[0]; |
| 355 | info.parameter_type = ACPI_PARAM_ARGS; |
| 356 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node, |
| 358 | obj_desc->method.aml_start, |
| 359 | obj_desc->method.aml_length, &info, 3); |
| 360 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | goto cleanup; |
| 362 | } |
| 363 | |
| 364 | /* |
| 365 | * Delete the operands on the previous walkstate operand stack |
| 366 | * (they were copied to new objects) |
| 367 | */ |
| 368 | for (i = 0; i < obj_desc->method.param_count; i++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 369 | acpi_ut_remove_reference(this_walk_state->operands[i]); |
| 370 | this_walk_state->operands[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /* Clear the operand stack */ |
| 374 | |
| 375 | this_walk_state->num_operands = 0; |
| 376 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 377 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 378 | "Starting nested execution, newstate=%p\n", |
| 379 | next_walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
| 381 | if (obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | status = obj_desc->method.implementation(next_walk_state); |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 383 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 386 | return_ACPI_STATUS(AE_OK); |
| 387 | |
| 388 | /* On error, we must delete the new walk state */ |
| 389 | |
| 390 | cleanup: |
| 391 | acpi_ut_release_owner_id(&obj_desc->method.owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | if (next_walk_state && (next_walk_state->method_desc)) { |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 393 | /* Decrement the thread count on the method parse tree */ |
| 394 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | next_walk_state->method_desc->method.thread_count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 397 | (void)acpi_ds_terminate_control_method(next_walk_state); |
| 398 | acpi_ds_delete_walk_state(next_walk_state); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | /******************************************************************************* |
| 403 | * |
| 404 | * FUNCTION: acpi_ds_restart_control_method |
| 405 | * |
| 406 | * PARAMETERS: walk_state - State for preempted method (caller) |
| 407 | * return_desc - Return value from the called method |
| 408 | * |
| 409 | * RETURN: Status |
| 410 | * |
| 411 | * DESCRIPTION: Restart a method that was preempted by another (nested) method |
| 412 | * invocation. Handle the return value (if any) from the callee. |
| 413 | * |
| 414 | ******************************************************************************/ |
| 415 | |
| 416 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 417 | acpi_ds_restart_control_method(struct acpi_walk_state *walk_state, |
| 418 | union acpi_operand_object *return_desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | ACPI_FUNCTION_TRACE_PTR("ds_restart_control_method", walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 424 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 425 | "****Restart [%4.4s] Op %p return_value_from_callee %p\n", |
| 426 | (char *)&walk_state->method_node->name, |
| 427 | walk_state->method_call_op, return_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 429 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 430 | " return_from_this_method_used?=%X res_stack %p Walk %p\n", |
| 431 | walk_state->return_used, |
| 432 | walk_state->results, walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | /* Did the called method return a value? */ |
| 435 | |
| 436 | if (return_desc) { |
| 437 | /* Are we actually going to use the return value? */ |
| 438 | |
| 439 | if (walk_state->return_used) { |
| 440 | /* Save the return value from the previous method */ |
| 441 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 442 | status = acpi_ds_result_push(return_desc, walk_state); |
| 443 | if (ACPI_FAILURE(status)) { |
| 444 | acpi_ut_remove_reference(return_desc); |
| 445 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* |
| 449 | * Save as THIS method's return value in case it is returned |
| 450 | * immediately to yet another method |
| 451 | */ |
| 452 | walk_state->return_desc = return_desc; |
| 453 | } |
| 454 | |
| 455 | /* |
| 456 | * The following code is the |
| 457 | * optional support for a so-called "implicit return". Some AML code |
| 458 | * assumes that the last value of the method is "implicitly" returned |
| 459 | * to the caller. Just save the last result as the return value. |
| 460 | * NOTE: this is optional because the ASL language does not actually |
| 461 | * support this behavior. |
| 462 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | else if (!acpi_ds_do_implicit_return |
| 464 | (return_desc, walk_state, FALSE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | /* |
| 466 | * Delete the return value if it will not be used by the |
| 467 | * calling method |
| 468 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 469 | acpi_ut_remove_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 473 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | /******************************************************************************* |
| 477 | * |
| 478 | * FUNCTION: acpi_ds_terminate_control_method |
| 479 | * |
| 480 | * PARAMETERS: walk_state - State of the method |
| 481 | * |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 482 | * RETURN: Status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | * |
| 484 | * DESCRIPTION: Terminate a control method. Delete everything that the method |
| 485 | * created, delete all locals and arguments, and delete the parse |
| 486 | * tree if requested. |
| 487 | * |
| 488 | ******************************************************************************/ |
| 489 | |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 490 | acpi_status acpi_ds_terminate_control_method(struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | union acpi_operand_object *obj_desc; |
| 493 | struct acpi_namespace_node *method_node; |
| 494 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | ACPI_FUNCTION_TRACE_PTR("ds_terminate_control_method", walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
| 498 | if (!walk_state) { |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 499 | return (AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /* The current method object was saved in the walk state */ |
| 503 | |
| 504 | obj_desc = walk_state->method_desc; |
| 505 | if (!obj_desc) { |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 506 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /* Delete all arguments and locals */ |
| 510 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 511 | acpi_ds_method_data_delete_all(walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | /* |
| 514 | * Lock the parser while we terminate this method. |
| 515 | * If this is the last thread executing the method, |
| 516 | * we have additional cleanup to perform |
| 517 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 518 | status = acpi_ut_acquire_mutex(ACPI_MTX_PARSER); |
| 519 | if (ACPI_FAILURE(status)) { |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 520 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /* Signal completion of the execution of this method if necessary */ |
| 524 | |
| 525 | if (walk_state->method_desc->method.semaphore) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 526 | status = |
| 527 | acpi_os_signal_semaphore(walk_state->method_desc->method. |
| 528 | semaphore, 1); |
| 529 | if (ACPI_FAILURE(status)) { |
| 530 | ACPI_REPORT_ERROR(("Could not signal method semaphore\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | status = AE_OK; |
| 532 | |
| 533 | /* Ignore error and continue cleanup */ |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | if (walk_state->method_desc->method.thread_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 538 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 539 | "*** Not deleting method namespace, there are still %d threads\n", |
| 540 | walk_state->method_desc->method. |
| 541 | thread_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | if (!walk_state->method_desc->method.thread_count) { |
| 545 | /* |
| 546 | * Support to dynamically change a method from not_serialized to |
| 547 | * Serialized if it appears that the method is written foolishly and |
| 548 | * does not support multiple thread execution. The best example of this |
| 549 | * is if such a method creates namespace objects and blocks. A second |
| 550 | * thread will fail with an AE_ALREADY_EXISTS exception |
| 551 | * |
| 552 | * This code is here because we must wait until the last thread exits |
| 553 | * before creating the synchronization semaphore. |
| 554 | */ |
| 555 | if ((walk_state->method_desc->method.concurrency == 1) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 556 | (!walk_state->method_desc->method.semaphore)) { |
| 557 | status = acpi_os_create_semaphore(1, 1, |
| 558 | &walk_state-> |
| 559 | method_desc->method. |
| 560 | semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | /* |
| 564 | * There are no more threads executing this method. Perform |
| 565 | * additional cleanup. |
| 566 | * |
| 567 | * The method Node is stored in the walk state |
| 568 | */ |
| 569 | method_node = walk_state->method_node; |
| 570 | |
| 571 | /* |
| 572 | * Delete any namespace entries created immediately underneath |
| 573 | * the method |
| 574 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 575 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 576 | if (ACPI_FAILURE(status)) { |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 577 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | if (method_node->child) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 581 | acpi_ns_delete_namespace_subtree(method_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /* |
| 585 | * Delete any namespace entries created anywhere else within |
| 586 | * the namespace |
| 587 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 588 | acpi_ns_delete_namespace_by_owner(walk_state->method_desc-> |
| 589 | method.owner_id); |
| 590 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 591 | acpi_ut_release_owner_id(&walk_state->method_desc->method. |
| 592 | owner_id); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 593 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 594 | if (ACPI_FAILURE(status)) { |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 595 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
| 597 | } |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame^] | 598 | |
| 599 | status = acpi_ut_release_mutex(ACPI_MTX_PARSER); |
| 600 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } |