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