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