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 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -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 |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 173 | * interpreter if we block (then reacquires it) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 178 | if (ACPI_FAILURE(status)) { |
| 179 | return_ACPI_STATUS(status); |
| 180 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 184 | * Allocate an Owner ID for this method, only if this is the first thread |
| 185 | * to begin concurrent execution. We only need one owner_id, even if the |
| 186 | * method is invoked recursively. |
| 187 | */ |
| 188 | if (!obj_desc->method.owner_id) { |
| 189 | status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id); |
| 190 | if (ACPI_FAILURE(status)) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 191 | goto cleanup; |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
| 195 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * Increment the method parse tree thread count since it has been |
| 197 | * reentered one more time (even if it is the same thread) |
| 198 | */ |
| 199 | obj_desc->method.thread_count++; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | return_ACPI_STATUS(status); |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 201 | |
| 202 | cleanup: |
| 203 | /* On error, must signal the method semaphore if present */ |
| 204 | |
| 205 | if (obj_desc->method.semaphore) { |
| 206 | (void)acpi_os_signal_semaphore(obj_desc->method.semaphore, 1); |
| 207 | } |
| 208 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /******************************************************************************* |
| 212 | * |
| 213 | * FUNCTION: acpi_ds_call_control_method |
| 214 | * |
| 215 | * PARAMETERS: Thread - Info for this thread |
| 216 | * this_walk_state - Current walk state |
| 217 | * Op - Current Op to be walked |
| 218 | * |
| 219 | * RETURN: Status |
| 220 | * |
| 221 | * DESCRIPTION: Transfer execution to a called control method |
| 222 | * |
| 223 | ******************************************************************************/ |
| 224 | |
| 225 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 226 | acpi_ds_call_control_method(struct acpi_thread_state *thread, |
| 227 | struct acpi_walk_state *this_walk_state, |
| 228 | union acpi_parse_object *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | acpi_status status; |
| 231 | struct acpi_namespace_node *method_node; |
| 232 | struct acpi_walk_state *next_walk_state = NULL; |
| 233 | union acpi_operand_object *obj_desc; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame^] | 234 | struct acpi_evaluate_info *info; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 237 | ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 239 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 240 | "Execute method %p, currentstate=%p\n", |
| 241 | this_walk_state->prev_op, this_walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | /* |
| 244 | * Get the namespace entry for the control method we are about to call |
| 245 | */ |
| 246 | method_node = this_walk_state->method_call_node; |
| 247 | if (!method_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | return_ACPI_STATUS(AE_NULL_ENTRY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | obj_desc = acpi_ns_get_attached_object(method_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | return_ACPI_STATUS(AE_NULL_OBJECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 256 | /* Init for new method, possibly wait on concurrency semaphore */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | status = acpi_ds_begin_method_execution(method_node, obj_desc, |
| 259 | this_walk_state->method_node); |
| 260 | if (ACPI_FAILURE(status)) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 261 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 264 | /* |
| 265 | * 1) Parse the method. All "normal" methods are parsed for each execution. |
| 266 | * Internal methods (_OSI, etc.) do not require parsing. |
| 267 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (!(obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 269 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 270 | /* Create a new walk state for the parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 272 | next_walk_state = |
| 273 | acpi_ds_create_walk_state(obj_desc->method.owner_id, op, |
| 274 | obj_desc, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (!next_walk_state) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 276 | status = AE_NO_MEMORY; |
| 277 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 280 | /* Create and init a parse tree root */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 282 | op = acpi_ps_create_scope_op(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | if (!op) { |
| 284 | status = AE_NO_MEMORY; |
| 285 | goto cleanup; |
| 286 | } |
| 287 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | status = acpi_ds_init_aml_walk(next_walk_state, op, method_node, |
| 289 | obj_desc->method.aml_start, |
| 290 | obj_desc->method.aml_length, |
| 291 | NULL, 1); |
| 292 | if (ACPI_FAILURE(status)) { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 293 | acpi_ps_delete_parse_tree(op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | goto cleanup; |
| 295 | } |
| 296 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 297 | /* Begin AML parse (deletes next_walk_state) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | status = acpi_ps_parse_aml(next_walk_state); |
| 300 | acpi_ps_delete_parse_tree(op); |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 301 | if (ACPI_FAILURE(status)) { |
| 302 | goto cleanup; |
| 303 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 306 | /* 2) Begin method execution. Create a new walk state */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id, |
| 309 | NULL, obj_desc, thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (!next_walk_state) { |
| 311 | status = AE_NO_MEMORY; |
| 312 | goto cleanup; |
| 313 | } |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /* |
| 316 | * The resolved arguments were put on the previous walk state's operand |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 317 | * stack. Operands on the previous walk state stack always |
| 318 | * start at index 0. Also, null terminate the list of arguments |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | this_walk_state->operands[this_walk_state->num_operands] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame^] | 322 | /* |
| 323 | * Allocate and initialize the evaluation information block |
| 324 | * TBD: this is somewhat inefficient, should change interface to |
| 325 | * ds_init_aml_walk. For now, keeps this struct off the CPU stack |
| 326 | */ |
| 327 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
| 328 | if (!info) { |
| 329 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 330 | } |
| 331 | |
| 332 | info->parameters = &this_walk_state->operands[0]; |
| 333 | info->parameter_type = ACPI_PARAM_ARGS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 | status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node, |
| 336 | obj_desc->method.aml_start, |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame^] | 337 | obj_desc->method.aml_length, info, 3); |
| 338 | |
| 339 | ACPI_FREE(info); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | goto cleanup; |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Delete the operands on the previous walkstate operand stack |
| 346 | * (they were copied to new objects) |
| 347 | */ |
| 348 | for (i = 0; i < obj_desc->method.param_count; i++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 349 | acpi_ut_remove_reference(this_walk_state->operands[i]); |
| 350 | this_walk_state->operands[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /* Clear the operand stack */ |
| 354 | |
| 355 | this_walk_state->num_operands = 0; |
| 356 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
| 358 | "Starting nested execution, newstate=%p\n", |
| 359 | next_walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 361 | /* Invoke an internal method if necessary */ |
| 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 364 | status = obj_desc->method.implementation(next_walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 367 | return_ACPI_STATUS(status); |
| 368 | |
| 369 | cleanup: |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 370 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 371 | /* On error, we must terminate the method properly */ |
| 372 | |
| 373 | acpi_ds_terminate_control_method(obj_desc, next_walk_state); |
| 374 | if (next_walk_state) { |
| 375 | acpi_ds_delete_walk_state(next_walk_state); |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 376 | } |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame] | 377 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 378 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | /******************************************************************************* |
| 382 | * |
| 383 | * FUNCTION: acpi_ds_restart_control_method |
| 384 | * |
| 385 | * PARAMETERS: walk_state - State for preempted method (caller) |
| 386 | * return_desc - Return value from the called method |
| 387 | * |
| 388 | * RETURN: Status |
| 389 | * |
| 390 | * DESCRIPTION: Restart a method that was preempted by another (nested) method |
| 391 | * invocation. Handle the return value (if any) from the callee. |
| 392 | * |
| 393 | ******************************************************************************/ |
| 394 | |
| 395 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | acpi_ds_restart_control_method(struct acpi_walk_state *walk_state, |
| 397 | union acpi_operand_object *return_desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | acpi_status status; |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 400 | int same_as_implicit_return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 402 | ACPI_FUNCTION_TRACE_PTR(ds_restart_control_method, walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 405 | "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | (char *)&walk_state->method_node->name, |
| 407 | walk_state->method_call_op, return_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 409 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 410 | " ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 411 | walk_state->return_used, |
| 412 | walk_state->results, walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
| 414 | /* Did the called method return a value? */ |
| 415 | |
| 416 | if (return_desc) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 417 | |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 418 | /* Is the implicit return object the same as the return desc? */ |
| 419 | |
| 420 | same_as_implicit_return = |
| 421 | (walk_state->implicit_return_obj == return_desc); |
| 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | /* Are we actually going to use the return value? */ |
| 424 | |
| 425 | if (walk_state->return_used) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | /* Save the return value from the previous method */ |
| 428 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 429 | status = acpi_ds_result_push(return_desc, walk_state); |
| 430 | if (ACPI_FAILURE(status)) { |
| 431 | acpi_ut_remove_reference(return_desc); |
| 432 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /* |
| 436 | * Save as THIS method's return value in case it is returned |
| 437 | * immediately to yet another method |
| 438 | */ |
| 439 | walk_state->return_desc = return_desc; |
| 440 | } |
| 441 | |
| 442 | /* |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 443 | * The following code is the optional support for the so-called |
| 444 | * "implicit return". Some AML code assumes that the last value of the |
| 445 | * method is "implicitly" returned to the caller, in the absence of an |
| 446 | * explicit return value. |
| 447 | * |
| 448 | * Just save the last result of the method as the return value. |
| 449 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | * NOTE: this is optional because the ASL language does not actually |
| 451 | * support this behavior. |
| 452 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 453 | else if (!acpi_ds_do_implicit_return |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 454 | (return_desc, walk_state, FALSE) |
| 455 | || same_as_implicit_return) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /* |
| 457 | * Delete the return value if it will not be used by the |
Bob Moore | 958dd24 | 2006-05-12 17:12:00 -0400 | [diff] [blame] | 458 | * calling method or remove one reference if the explicit return |
| 459 | * is the same as the implicit return value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | acpi_ut_remove_reference(return_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 465 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | /******************************************************************************* |
| 469 | * |
| 470 | * FUNCTION: acpi_ds_terminate_control_method |
| 471 | * |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 472 | * PARAMETERS: method_desc - Method object |
| 473 | * walk_state - State associated with the method |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | * |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 475 | * RETURN: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | * |
| 477 | * DESCRIPTION: Terminate a control method. Delete everything that the method |
| 478 | * created, delete all locals and arguments, and delete the parse |
| 479 | * tree if requested. |
| 480 | * |
| 481 | ******************************************************************************/ |
| 482 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 483 | void |
| 484 | acpi_ds_terminate_control_method(union acpi_operand_object *method_desc, |
| 485 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 487 | struct acpi_namespace_node *method_node; |
| 488 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 490 | ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 492 | /* method_desc is required, walk_state is optional */ |
| 493 | |
| 494 | if (!method_desc) { |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 495 | return_VOID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 498 | if (walk_state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 500 | /* Delete all arguments and locals */ |
| 501 | |
| 502 | acpi_ds_method_data_delete_all(walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | /* |
| 506 | * Lock the parser while we terminate this method. |
| 507 | * If this is the last thread executing the method, |
| 508 | * we have additional cleanup to perform |
| 509 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 510 | status = acpi_ut_acquire_mutex(ACPI_MTX_PARSER); |
| 511 | if (ACPI_FAILURE(status)) { |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 512 | return_VOID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /* Signal completion of the execution of this method if necessary */ |
| 516 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 517 | if (method_desc->method.semaphore) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 518 | status = |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 519 | acpi_os_signal_semaphore(method_desc->method.semaphore, 1); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 520 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 522 | /* Ignore error and continue */ |
| 523 | |
| 524 | ACPI_EXCEPTION((AE_INFO, status, |
| 525 | "Could not signal method semaphore")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 529 | if (walk_state) { |
| 530 | /* |
| 531 | * Delete any objects created by this method during execution. |
| 532 | * The method Node is stored in the walk state |
| 533 | */ |
| 534 | method_node = walk_state->method_node; |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 535 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 536 | /* Lock namespace for possible update */ |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 537 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 538 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 539 | if (ACPI_FAILURE(status)) { |
| 540 | goto exit; |
| 541 | } |
| 542 | |
| 543 | /* |
| 544 | * Delete any namespace entries created immediately underneath |
| 545 | * the method |
| 546 | */ |
| 547 | if (method_node && method_node->child) { |
| 548 | acpi_ns_delete_namespace_subtree(method_node); |
| 549 | } |
| 550 | |
| 551 | /* |
| 552 | * Delete any namespace entries created anywhere else within |
| 553 | * the namespace by the execution of this method |
| 554 | */ |
| 555 | acpi_ns_delete_namespace_by_owner(method_desc->method.owner_id); |
| 556 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 557 | } |
| 558 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 559 | /* Decrement the thread count on the method */ |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 560 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 561 | if (method_desc->method.thread_count) { |
| 562 | method_desc->method.thread_count--; |
| 563 | } else { |
| 564 | ACPI_ERROR((AE_INFO, "Invalid zero thread count in method")); |
| 565 | } |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 566 | |
| 567 | /* Are there any other threads currently executing this method? */ |
| 568 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 569 | if (method_desc->method.thread_count) { |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 570 | /* |
| 571 | * Additional threads. Do not release the owner_id in this case, |
| 572 | * we immediately reuse it for the next thread executing this method |
| 573 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 574 | ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 575 | "*** Completed execution of one thread, %d threads remaining\n", |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 576 | method_desc->method.thread_count)); |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 577 | } else { |
| 578 | /* This is the only executing thread for this method */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | /* |
| 581 | * Support to dynamically change a method from not_serialized to |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 582 | * Serialized if it appears that the method is incorrectly written and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | * does not support multiple thread execution. The best example of this |
| 584 | * is if such a method creates namespace objects and blocks. A second |
| 585 | * thread will fail with an AE_ALREADY_EXISTS exception |
| 586 | * |
| 587 | * This code is here because we must wait until the last thread exits |
| 588 | * before creating the synchronization semaphore. |
| 589 | */ |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 590 | if ((method_desc->method.concurrency == 1) && |
| 591 | (!method_desc->method.semaphore)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 592 | status = acpi_os_create_semaphore(1, 1, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 593 | &method_desc->method. |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 594 | semaphore); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 597 | /* No more threads, we can free the owner_id */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 599 | acpi_ut_release_owner_id(&method_desc->method.owner_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
Len Brown | a94f188 | 2005-09-03 00:09:12 -0400 | [diff] [blame] | 601 | |
Robert Moore | aff8c27 | 2005-09-02 17:24:17 -0400 | [diff] [blame] | 602 | exit: |
| 603 | (void)acpi_ut_release_mutex(ACPI_MTX_PARSER); |
| 604 | return_VOID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 606 | |
| 607 | #ifdef ACPI_INIT_PARSE_METHODS |
| 608 | /* |
| 609 | * Note 11/2005: Removed this code to parse all methods during table |
| 610 | * load because it causes problems if there are any errors during the |
| 611 | * parse. Also, it seems like overkill and we probably don't want to |
| 612 | * abort a table load because of an issue with a single method. |
| 613 | */ |
| 614 | |
| 615 | /******************************************************************************* |
| 616 | * |
| 617 | * FUNCTION: acpi_ds_parse_method |
| 618 | * |
| 619 | * PARAMETERS: Node - Method node |
| 620 | * |
| 621 | * RETURN: Status |
| 622 | * |
| 623 | * DESCRIPTION: Parse the AML that is associated with the method. |
| 624 | * |
| 625 | * MUTEX: Assumes parser is locked |
| 626 | * |
| 627 | ******************************************************************************/ |
| 628 | |
| 629 | acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node) |
| 630 | { |
| 631 | acpi_status status; |
| 632 | union acpi_operand_object *obj_desc; |
| 633 | union acpi_parse_object *op; |
| 634 | struct acpi_walk_state *walk_state; |
| 635 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 636 | ACPI_FUNCTION_TRACE_PTR(ds_parse_method, node); |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 637 | |
| 638 | /* Parameter Validation */ |
| 639 | |
| 640 | if (!node) { |
| 641 | return_ACPI_STATUS(AE_NULL_ENTRY); |
| 642 | } |
| 643 | |
| 644 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 645 | "**** Parsing [%4.4s] **** NamedObj=%p\n", |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 646 | acpi_ut_get_node_name(node), node)); |
| 647 | |
| 648 | /* Extract the method object from the method Node */ |
| 649 | |
| 650 | obj_desc = acpi_ns_get_attached_object(node); |
| 651 | if (!obj_desc) { |
| 652 | return_ACPI_STATUS(AE_NULL_OBJECT); |
| 653 | } |
| 654 | |
| 655 | /* Create a mutex for the method if there is a concurrency limit */ |
| 656 | |
| 657 | if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) && |
| 658 | (!obj_desc->method.semaphore)) { |
| 659 | status = acpi_os_create_semaphore(obj_desc->method.concurrency, |
| 660 | obj_desc->method.concurrency, |
| 661 | &obj_desc->method.semaphore); |
| 662 | if (ACPI_FAILURE(status)) { |
| 663 | return_ACPI_STATUS(status); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | /* |
| 668 | * Allocate a new parser op to be the root of the parsed |
| 669 | * method tree |
| 670 | */ |
| 671 | op = acpi_ps_alloc_op(AML_METHOD_OP); |
| 672 | if (!op) { |
| 673 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 674 | } |
| 675 | |
| 676 | /* Init new op with the method name and pointer back to the Node */ |
| 677 | |
| 678 | acpi_ps_set_name(op, node->name.integer); |
| 679 | op->common.node = node; |
| 680 | |
| 681 | /* |
| 682 | * Get a new owner_id for objects created by this method. Namespace |
| 683 | * objects (such as Operation Regions) can be created during the |
| 684 | * first pass parse. |
| 685 | */ |
| 686 | status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id); |
| 687 | if (ACPI_FAILURE(status)) { |
| 688 | goto cleanup; |
| 689 | } |
| 690 | |
| 691 | /* Create and initialize a new walk state */ |
| 692 | |
| 693 | walk_state = |
| 694 | acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL, |
| 695 | NULL); |
| 696 | if (!walk_state) { |
| 697 | status = AE_NO_MEMORY; |
| 698 | goto cleanup2; |
| 699 | } |
| 700 | |
| 701 | status = acpi_ds_init_aml_walk(walk_state, op, node, |
| 702 | obj_desc->method.aml_start, |
| 703 | obj_desc->method.aml_length, NULL, 1); |
| 704 | if (ACPI_FAILURE(status)) { |
| 705 | acpi_ds_delete_walk_state(walk_state); |
| 706 | goto cleanup2; |
| 707 | } |
| 708 | |
| 709 | /* |
| 710 | * Parse the method, first pass |
| 711 | * |
| 712 | * The first pass load is where newly declared named objects are added into |
| 713 | * the namespace. Actual evaluation of the named objects (what would be |
| 714 | * called a "second pass") happens during the actual execution of the |
| 715 | * method so that operands to the named objects can take on dynamic |
| 716 | * run-time values. |
| 717 | */ |
| 718 | status = acpi_ps_parse_aml(walk_state); |
| 719 | if (ACPI_FAILURE(status)) { |
| 720 | goto cleanup2; |
| 721 | } |
| 722 | |
| 723 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 724 | "**** [%4.4s] Parsed **** NamedObj=%p Op=%p\n", |
Bob Moore | 28f55eb | 2005-12-02 18:27:00 -0500 | [diff] [blame] | 725 | acpi_ut_get_node_name(node), node, op)); |
| 726 | |
| 727 | /* |
| 728 | * Delete the parse tree. We simply re-parse the method for every |
| 729 | * execution since there isn't much overhead (compared to keeping lots |
| 730 | * of parse trees around) |
| 731 | */ |
| 732 | acpi_ns_delete_namespace_subtree(node); |
| 733 | acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id); |
| 734 | |
| 735 | cleanup2: |
| 736 | acpi_ut_release_owner_id(&obj_desc->method.owner_id); |
| 737 | |
| 738 | cleanup: |
| 739 | acpi_ps_delete_parse_tree(op); |
| 740 | return_ACPI_STATUS(status); |
| 741 | } |
| 742 | #endif |