Blame view

drivers/acpi/acpica/dsmethod.c 19 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
  /******************************************************************************
   *
   * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
   *
   *****************************************************************************/
  
  /*
75a44ce00   Len Brown   ACPICA: update In...
8
   * Copyright (C) 2000 - 2008, Intel Corp.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions, and the following disclaimer,
   *    without modification.
   * 2. Redistributions in binary form must reproduce at minimum a disclaimer
   *    substantially similar to the "NO WARRANTY" disclaimer below
   *    ("Disclaimer") and any redistribution must be conditioned upon
   *    including a substantially similar Disclaimer requirement for further
   *    binary redistribution.
   * 3. Neither the names of the above-listed copyright holders nor the names
   *    of any contributors may be used to endorse or promote products derived
   *    from this software without specific prior written permission.
   *
   * Alternatively, this software may be distributed under the terms of the
   * GNU General Public License ("GPL") version 2 as published by the Free
   * Software Foundation.
   *
   * NO WARRANTY
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   * POSSIBILITY OF SUCH DAMAGES.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  #include <acpi/acpi.h>
e2f7a7772   Len Brown   ACPICA: hide priv...
44
45
46
47
48
  #include "accommon.h"
  #include "amlcode.h"
  #include "acdispat.h"
  #include "acinterp.h"
  #include "acnamesp.h"
5b929aa1a   Len Brown   ACPICA: delete ac...
49
  #ifdef	ACPI_DISASSEMBLER
defba1d8f   Bob Moore   [ACPI] ACPICA 200...
50
  #include <acpi/acdisasm.h>
5b929aa1a   Len Brown   ACPICA: delete ac...
51
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  #define _COMPONENT          ACPI_DISPATCHER
4be44fcd3   Len Brown   [ACPI] Lindent al...
54
  ACPI_MODULE_NAME("dsmethod")
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55

967440e3b   Bob Moore   ACPI: ACPICA 2006...
56
57
58
  /* Local prototypes */
  static acpi_status
  acpi_ds_create_method_mutex(union acpi_operand_object *method_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
  /*******************************************************************************
   *
defba1d8f   Bob Moore   [ACPI] ACPICA 200...
61
62
63
64
65
66
67
68
69
70
71
72
73
   * FUNCTION:    acpi_ds_method_error
   *
   * PARAMETERS:  Status          - Execution status
   *              walk_state      - Current state
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Called on method error. Invoke the global exception handler if
   *              present, dump the method data if the disassembler is configured
   *
   *              Note: Allows the exception handler to change the status code
   *
   ******************************************************************************/
967440e3b   Bob Moore   ACPI: ACPICA 2006...
74

defba1d8f   Bob Moore   [ACPI] ACPICA 200...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  acpi_status
  acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
  {
  	ACPI_FUNCTION_ENTRY();
  
  	/* Ignore AE_OK and control exception codes */
  
  	if (ACPI_SUCCESS(status) || (status & AE_CODE_CONTROL)) {
  		return (status);
  	}
  
  	/* Invoke the global exception handler */
  
  	if (acpi_gbl_exception_handler) {
52fc0b026   Bob Moore   [ACPI] ACPICA 200...
89

defba1d8f   Bob Moore   [ACPI] ACPICA 200...
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  		/* Exit the interpreter, allow handler to execute methods */
  
  		acpi_ex_exit_interpreter();
  
  		/*
  		 * Handler can map the exception code to anything it wants, including
  		 * AE_OK, in which case the executing method will not be aborted.
  		 */
  		status = acpi_gbl_exception_handler(status,
  						    walk_state->method_node ?
  						    walk_state->method_node->
  						    name.integer : 0,
  						    walk_state->opcode,
  						    walk_state->aml_offset,
  						    NULL);
b7f9f0422   Bob Moore   ACPICA: Cosmetic ...
105
  		acpi_ex_enter_interpreter();
defba1d8f   Bob Moore   [ACPI] ACPICA 200...
106
  	}
d8a0ec914   Lin Ming   ACPICA: Fixed a c...
107
108
  
  	acpi_ds_clear_implicit_return(walk_state);
defba1d8f   Bob Moore   [ACPI] ACPICA 200...
109
110
  #ifdef ACPI_DISASSEMBLER
  	if (ACPI_FAILURE(status)) {
52fc0b026   Bob Moore   [ACPI] ACPICA 200...
111

defba1d8f   Bob Moore   [ACPI] ACPICA 200...
112
113
114
115
116
117
118
119
120
121
122
  		/* Display method locals/args if disassembler is present */
  
  		acpi_dm_dump_method_info(status, walk_state, walk_state->op);
  	}
  #endif
  
  	return (status);
  }
  
  /*******************************************************************************
   *
967440e3b   Bob Moore   ACPI: ACPICA 2006...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
   * FUNCTION:    acpi_ds_create_method_mutex
   *
   * PARAMETERS:  obj_desc            - The method object
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Create a mutex object for a serialized control method
   *
   ******************************************************************************/
  
  static acpi_status
  acpi_ds_create_method_mutex(union acpi_operand_object *method_desc)
  {
  	union acpi_operand_object *mutex_desc;
  	acpi_status status;
f6dd9221d   Bob Moore   ACPI: ACPICA 2006...
138
  	ACPI_FUNCTION_TRACE(ds_create_method_mutex);
967440e3b   Bob Moore   ACPI: ACPICA 2006...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  
  	/* Create the new mutex object */
  
  	mutex_desc = acpi_ut_create_internal_object(ACPI_TYPE_MUTEX);
  	if (!mutex_desc) {
  		return_ACPI_STATUS(AE_NO_MEMORY);
  	}
  
  	/* Create the actual OS Mutex */
  
  	status = acpi_os_create_mutex(&mutex_desc->mutex.os_mutex);
  	if (ACPI_FAILURE(status)) {
  		return_ACPI_STATUS(status);
  	}
  
  	mutex_desc->mutex.sync_level = method_desc->method.sync_level;
  	method_desc->method.mutex = mutex_desc;
  	return_ACPI_STATUS(AE_OK);
  }
  
  /*******************************************************************************
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
161
162
163
164
   * FUNCTION:    acpi_ds_begin_method_execution
   *
   * PARAMETERS:  method_node         - Node of the method
   *              obj_desc            - The method object
967440e3b   Bob Moore   ACPI: ACPICA 2006...
165
166
   *              walk_state          - current state, NULL if not yet executing
   *                                    a method.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
167
168
169
170
171
172
173
174
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Prepare a method for execution.  Parses the method if necessary,
   *              increments the thread count, and waits at the method semaphore
   *              for clearance to execute.
   *
   ******************************************************************************/
defba1d8f   Bob Moore   [ACPI] ACPICA 200...
175

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
  acpi_status
967440e3b   Bob Moore   ACPI: ACPICA 2006...
177
178
179
  acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
  			       union acpi_operand_object *obj_desc,
  			       struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
181
  	acpi_status status = AE_OK;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
183
  	ACPI_FUNCTION_TRACE_PTR(ds_begin_method_execution, method_node);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
185
  
  	if (!method_node) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
186
  		return_ACPI_STATUS(AE_NULL_ENTRY);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
  	}
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
188
189
190
  	/* Prevent wraparound of thread count */
  
  	if (obj_desc->method.thread_count == ACPI_UINT8_MAX) {
b8e4d8935   Bob Moore   [ACPI] ACPICA 200...
191
192
  		ACPI_ERROR((AE_INFO,
  			    "Method reached maximum reentrancy limit (255)"));
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
193
194
  		return_ACPI_STATUS(AE_AML_METHOD_LIMIT);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195
  	/*
967440e3b   Bob Moore   ACPI: ACPICA 2006...
196
  	 * If this method is serialized, we need to acquire the method mutex.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
  	 */
967440e3b   Bob Moore   ACPI: ACPICA 2006...
198
  	if (obj_desc->method.method_flags & AML_METHOD_SERIALIZED) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
  		/*
967440e3b   Bob Moore   ACPI: ACPICA 2006...
200
201
202
  		 * Create a mutex for the method if it is defined to be Serialized
  		 * and a mutex has not already been created. We defer the mutex creation
  		 * until a method is actually executed, to minimize the object count
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
203
  		 */
967440e3b   Bob Moore   ACPI: ACPICA 2006...
204
205
206
207
  		if (!obj_desc->method.mutex) {
  			status = acpi_ds_create_method_mutex(obj_desc);
  			if (ACPI_FAILURE(status)) {
  				return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
210
211
  			}
  		}
  
  		/*
967440e3b   Bob Moore   ACPI: ACPICA 2006...
212
213
214
215
216
  		 * The current_sync_level (per-thread) must be less than or equal to
  		 * the sync level of the method. This mechanism provides some
  		 * deadlock prevention
  		 *
  		 * Top-level method invocation has no walk state at this point
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217
  		 */
967440e3b   Bob Moore   ACPI: ACPICA 2006...
218
219
220
221
222
223
224
225
226
  		if (walk_state &&
  		    (walk_state->thread->current_sync_level >
  		     obj_desc->method.mutex->mutex.sync_level)) {
  			ACPI_ERROR((AE_INFO,
  				    "Cannot acquire Mutex for method [%4.4s], current SyncLevel is too large (%d)",
  				    acpi_ut_get_node_name(method_node),
  				    walk_state->thread->current_sync_level));
  
  			return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
227
  		}
967440e3b   Bob Moore   ACPI: ACPICA 2006...
228
229
230
231
232
  
  		/*
  		 * Obtain the method mutex if necessary. Do not acquire mutex for a
  		 * recursive call.
  		 */
262a7a28d   Len Brown   Revert "ACPICA: f...
233
  		if (!walk_state ||
ba886cd4a   Bob Moore   ACPICA: Update fo...
234
235
236
  		    !obj_desc->method.mutex->mutex.thread_id ||
  		    (walk_state->thread->thread_id !=
  		     obj_desc->method.mutex->mutex.thread_id)) {
967440e3b   Bob Moore   ACPI: ACPICA 2006...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
  			/*
  			 * Acquire the method mutex. This releases the interpreter if we
  			 * block (and reacquires it before it returns)
  			 */
  			status =
  			    acpi_ex_system_wait_mutex(obj_desc->method.mutex->
  						      mutex.os_mutex,
  						      ACPI_WAIT_FOREVER);
  			if (ACPI_FAILURE(status)) {
  				return_ACPI_STATUS(status);
  			}
  
  			/* Update the mutex and walk info and save the original sync_level */
  
  			if (walk_state) {
  				obj_desc->method.mutex->mutex.
  				    original_sync_level =
  				    walk_state->thread->current_sync_level;
ba886cd4a   Bob Moore   ACPICA: Update fo...
255
256
  				obj_desc->method.mutex->mutex.thread_id =
  				    walk_state->thread->thread_id;
967440e3b   Bob Moore   ACPI: ACPICA 2006...
257
258
259
260
261
262
263
264
265
266
267
268
  				walk_state->thread->current_sync_level =
  				    obj_desc->method.sync_level;
  			} else {
  				obj_desc->method.mutex->mutex.
  				    original_sync_level =
  				    obj_desc->method.mutex->mutex.sync_level;
  			}
  		}
  
  		/* Always increase acquisition depth */
  
  		obj_desc->method.mutex->mutex.acquisition_depth++;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269
270
271
  	}
  
  	/*
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
272
273
274
275
276
277
278
  	 * Allocate an Owner ID for this method, only if this is the first thread
  	 * to begin concurrent execution. We only need one owner_id, even if the
  	 * method is invoked recursively.
  	 */
  	if (!obj_desc->method.owner_id) {
  		status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
  		if (ACPI_FAILURE(status)) {
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
279
  			goto cleanup;
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
280
281
282
283
  		}
  	}
  
  	/*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
285
286
287
  	 * Increment the method parse tree thread count since it has been
  	 * reentered one more time (even if it is the same thread)
  	 */
  	obj_desc->method.thread_count++;
4be44fcd3   Len Brown   [ACPI] Lindent al...
288
  	return_ACPI_STATUS(status);
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
289
290
  
        cleanup:
967440e3b   Bob Moore   ACPI: ACPICA 2006...
291
  	/* On error, must release the method mutex (if present) */
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
292

967440e3b   Bob Moore   ACPI: ACPICA 2006...
293
294
  	if (obj_desc->method.mutex) {
  		acpi_os_release_mutex(obj_desc->method.mutex->mutex.os_mutex);
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
295
296
  	}
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
297
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ds_call_control_method
   *
   * PARAMETERS:  Thread              - Info for this thread
   *              this_walk_state     - Current walk state
   *              Op                  - Current Op to be walked
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Transfer execution to a called control method
   *
   ******************************************************************************/
  
  acpi_status
4be44fcd3   Len Brown   [ACPI] Lindent al...
313
314
315
  acpi_ds_call_control_method(struct acpi_thread_state *thread,
  			    struct acpi_walk_state *this_walk_state,
  			    union acpi_parse_object *op)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
317
318
319
320
  	acpi_status status;
  	struct acpi_namespace_node *method_node;
  	struct acpi_walk_state *next_walk_state = NULL;
  	union acpi_operand_object *obj_desc;
4119532c9   Bob Moore   ACPI: ACPICA 2006...
321
  	struct acpi_evaluate_info *info;
4be44fcd3   Len Brown   [ACPI] Lindent al...
322
  	u32 i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
323

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
324
  	ACPI_FUNCTION_TRACE_PTR(ds_call_control_method, this_walk_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
325

4be44fcd3   Len Brown   [ACPI] Lindent al...
326
  	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
9bc75cff4   Valery Podrezov   ACPICA: Eliminate...
327
328
  			  "Calling method %p, currentstate=%p
  ",
4be44fcd3   Len Brown   [ACPI] Lindent al...
329
  			  this_walk_state->prev_op, this_walk_state));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
330
331
332
333
334
335
  
  	/*
  	 * Get the namespace entry for the control method we are about to call
  	 */
  	method_node = this_walk_state->method_call_node;
  	if (!method_node) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
336
  		return_ACPI_STATUS(AE_NULL_ENTRY);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
337
  	}
4be44fcd3   Len Brown   [ACPI] Lindent al...
338
  	obj_desc = acpi_ns_get_attached_object(method_node);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339
  	if (!obj_desc) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
340
  		return_ACPI_STATUS(AE_NULL_OBJECT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
341
  	}
967440e3b   Bob Moore   ACPI: ACPICA 2006...
342
  	/* Init for new method, possibly wait on method mutex */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343

4be44fcd3   Len Brown   [ACPI] Lindent al...
344
  	status = acpi_ds_begin_method_execution(method_node, obj_desc,
967440e3b   Bob Moore   ACPI: ACPICA 2006...
345
  						this_walk_state);
4be44fcd3   Len Brown   [ACPI] Lindent al...
346
  	if (ACPI_FAILURE(status)) {
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
347
  		return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
  	}
9bc75cff4   Valery Podrezov   ACPICA: Eliminate...
349
  	/* Begin method parse/execution. Create a new walk state */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350

4be44fcd3   Len Brown   [ACPI] Lindent al...
351
352
  	next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id,
  						    NULL, obj_desc, thread);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
353
354
355
356
  	if (!next_walk_state) {
  		status = AE_NO_MEMORY;
  		goto cleanup;
  	}
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
357

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
358
359
  	/*
  	 * The resolved arguments were put on the previous walk state's operand
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
360
361
  	 * stack. Operands on the previous walk state stack always
  	 * start at index 0. Also, null terminate the list of arguments
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
362
  	 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
363
  	this_walk_state->operands[this_walk_state->num_operands] = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364

4119532c9   Bob Moore   ACPI: ACPICA 2006...
365
366
367
368
369
370
371
372
373
374
375
  	/*
  	 * Allocate and initialize the evaluation information block
  	 * TBD: this is somewhat inefficient, should change interface to
  	 * ds_init_aml_walk. For now, keeps this struct off the CPU stack
  	 */
  	info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  	if (!info) {
  		return_ACPI_STATUS(AE_NO_MEMORY);
  	}
  
  	info->parameters = &this_walk_state->operands[0];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
376

4be44fcd3   Len Brown   [ACPI] Lindent al...
377
378
  	status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,
  				       obj_desc->method.aml_start,
ec3153fb0   Bob Moore   ACPICA: Use manif...
379
380
  				       obj_desc->method.aml_length, info,
  				       ACPI_IMODE_EXECUTE);
4119532c9   Bob Moore   ACPI: ACPICA 2006...
381
382
  
  	ACPI_FREE(info);
4be44fcd3   Len Brown   [ACPI] Lindent al...
383
  	if (ACPI_FAILURE(status)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
384
385
386
387
388
389
390
391
  		goto cleanup;
  	}
  
  	/*
  	 * Delete the operands on the previous walkstate operand stack
  	 * (they were copied to new objects)
  	 */
  	for (i = 0; i < obj_desc->method.param_count; i++) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
392
393
  		acpi_ut_remove_reference(this_walk_state->operands[i]);
  		this_walk_state->operands[i] = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
394
395
396
397
398
  	}
  
  	/* Clear the operand stack */
  
  	this_walk_state->num_operands = 0;
4be44fcd3   Len Brown   [ACPI] Lindent al...
399
  	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
9bc75cff4   Valery Podrezov   ACPICA: Eliminate...
400
401
402
  			  "**** Begin nested execution of [%4.4s] **** WalkState=%p
  ",
  			  method_node->name.ascii, next_walk_state));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
403

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
404
  	/* Invoke an internal method if necessary */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
405
  	if (obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY) {
e31c32cfe   Lin Ming   ACPICA: Module-le...
406
  		status = obj_desc->method.extra.implementation(next_walk_state);
a8fadc923   Bob Moore   ACPICA: Add suppo...
407
408
409
  		if (status == AE_OK) {
  			status = AE_CTRL_TERMINATE;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
410
  	}
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
411
  	return_ACPI_STATUS(status);
a94f18810   Len Brown   [ACPI] revert own...
412
413
  
        cleanup:
a94f18810   Len Brown   [ACPI] revert own...
414

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
415
  	/* On error, we must terminate the method properly */
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
416

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
417
418
419
420
  	acpi_ds_terminate_control_method(obj_desc, next_walk_state);
  	if (next_walk_state) {
  		acpi_ds_delete_walk_state(next_walk_state);
  	}
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
421

4be44fcd3   Len Brown   [ACPI] Lindent al...
422
  	return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
423
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ds_restart_control_method
   *
   * PARAMETERS:  walk_state          - State for preempted method (caller)
   *              return_desc         - Return value from the called method
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Restart a method that was preempted by another (nested) method
   *              invocation.  Handle the return value (if any) from the callee.
   *
   ******************************************************************************/
  
  acpi_status
4be44fcd3   Len Brown   [ACPI] Lindent al...
439
440
  acpi_ds_restart_control_method(struct acpi_walk_state *walk_state,
  			       union acpi_operand_object *return_desc)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
441
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
442
  	acpi_status status;
958dd242b   Bob Moore   ACPI: ACPICA 2006...
443
  	int same_as_implicit_return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
444

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
445
  	ACPI_FUNCTION_TRACE_PTR(ds_restart_control_method, walk_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
446

4be44fcd3   Len Brown   [ACPI] Lindent al...
447
  	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
448
449
  			  "****Restart [%4.4s] Op %p ReturnValueFromCallee %p
  ",
f6dd9221d   Bob Moore   ACPI: ACPICA 2006...
450
  			  acpi_ut_get_node_name(walk_state->method_node),
4be44fcd3   Len Brown   [ACPI] Lindent al...
451
  			  walk_state->method_call_op, return_desc));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
452

4be44fcd3   Len Brown   [ACPI] Lindent al...
453
  	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
454
455
  			  "    ReturnFromThisMethodUsed?=%X ResStack %p Walk %p
  ",
4be44fcd3   Len Brown   [ACPI] Lindent al...
456
457
  			  walk_state->return_used,
  			  walk_state->results, walk_state));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
458
459
460
461
  
  	/* Did the called method return a value? */
  
  	if (return_desc) {
52fc0b026   Bob Moore   [ACPI] ACPICA 200...
462

958dd242b   Bob Moore   ACPI: ACPICA 2006...
463
464
465
466
  		/* Is the implicit return object the same as the return desc? */
  
  		same_as_implicit_return =
  		    (walk_state->implicit_return_obj == return_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
467
468
469
  		/* Are we actually going to use the return value? */
  
  		if (walk_state->return_used) {
52fc0b026   Bob Moore   [ACPI] ACPICA 200...
470

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
471
  			/* Save the return value from the previous method */
4be44fcd3   Len Brown   [ACPI] Lindent al...
472
473
474
475
  			status = acpi_ds_result_push(return_desc, walk_state);
  			if (ACPI_FAILURE(status)) {
  				acpi_ut_remove_reference(return_desc);
  				return_ACPI_STATUS(status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
476
477
478
479
480
481
482
483
484
485
  			}
  
  			/*
  			 * Save as THIS method's return value in case it is returned
  			 * immediately to yet another method
  			 */
  			walk_state->return_desc = return_desc;
  		}
  
  		/*
958dd242b   Bob Moore   ACPI: ACPICA 2006...
486
487
488
489
490
491
492
  		 * The following code is the optional support for the so-called
  		 * "implicit return". Some AML code assumes that the last value of the
  		 * method is "implicitly" returned to the caller, in the absence of an
  		 * explicit return value.
  		 *
  		 * Just save the last result of the method as the return value.
  		 *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
493
494
495
  		 * NOTE: this is optional because the ASL language does not actually
  		 * support this behavior.
  		 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
496
  		else if (!acpi_ds_do_implicit_return
958dd242b   Bob Moore   ACPI: ACPICA 2006...
497
498
  			 (return_desc, walk_state, FALSE)
  			 || same_as_implicit_return) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
499
500
  			/*
  			 * Delete the return value if it will not be used by the
958dd242b   Bob Moore   ACPI: ACPICA 2006...
501
502
  			 * calling method or remove one reference if the explicit return
  			 * is the same as the implicit return value.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
503
  			 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
504
  			acpi_ut_remove_reference(return_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
505
506
  		}
  	}
4be44fcd3   Len Brown   [ACPI] Lindent al...
507
  	return_ACPI_STATUS(AE_OK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
509
510
511
512
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ds_terminate_control_method
   *
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
513
514
   * PARAMETERS:  method_desc         - Method object
   *              walk_state          - State associated with the method
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
   *
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
516
   * RETURN:      None
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
517
518
519
520
521
   *
   * DESCRIPTION: Terminate a control method.  Delete everything that the method
   *              created, delete all locals and arguments, and delete the parse
   *              tree if requested.
   *
967440e3b   Bob Moore   ACPI: ACPICA 2006...
522
523
   * MUTEX:       Interpreter is locked
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
524
   ******************************************************************************/
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
525
526
527
  void
  acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
  				 struct acpi_walk_state *walk_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
528
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
529

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
530
  	ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
531

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
532
  	/* method_desc is required, walk_state is optional */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
533

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
534
  	if (!method_desc) {
aff8c2777   Robert Moore   [ACPI] ACPICA 200...
535
  		return_VOID;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
536
  	}
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
537
  	if (walk_state) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
538

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
539
540
541
  		/* Delete all arguments and locals */
  
  		acpi_ds_method_data_delete_all(walk_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
542

b7f9f0422   Bob Moore   ACPICA: Cosmetic ...
543
544
545
546
547
  		/*
  		 * If method is serialized, release the mutex and restore the
  		 * current sync level for this thread
  		 */
  		if (method_desc->method.mutex) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
548

b7f9f0422   Bob Moore   ACPICA: Cosmetic ...
549
  			/* Acquisition Depth handles recursive calls */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
550

b7f9f0422   Bob Moore   ACPICA: Cosmetic ...
551
552
553
554
555
  			method_desc->method.mutex->mutex.acquisition_depth--;
  			if (!method_desc->method.mutex->mutex.acquisition_depth) {
  				walk_state->thread->current_sync_level =
  				    method_desc->method.mutex->mutex.
  				    original_sync_level;
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
556

b7f9f0422   Bob Moore   ACPICA: Cosmetic ...
557
558
  				acpi_os_release_mutex(method_desc->method.
  						      mutex->mutex.os_mutex);
b62151de4   Harvey Harrison   acpi: fix integer...
559
  				method_desc->method.mutex->mutex.thread_id = NULL;
b7f9f0422   Bob Moore   ACPICA: Cosmetic ...
560
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
561
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
562

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
563
  		/*
7f0c826a4   Lin Ming   ACPICA: Add suppo...
564
565
566
567
  		 * Delete any namespace objects created anywhere within the
  		 * namespace by the execution of this method. Unless this method
  		 * is a module-level executable code method, in which case we
  		 * want make the objects permanent.
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
568
  		 */
7f0c826a4   Lin Ming   ACPICA: Add suppo...
569
570
571
572
  		if (!(method_desc->method.flags & AOPOBJ_MODULE_LEVEL)) {
  			acpi_ns_delete_namespace_by_owner(method_desc->method.
  							  owner_id);
  		}
28f55ebce   Bob Moore   [ACPI] ACPICA 200...
573
  	}
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
574
575
576
577
578
579
580
  	/* Decrement the thread count on the method */
  
  	if (method_desc->method.thread_count) {
  		method_desc->method.thread_count--;
  	} else {
  		ACPI_ERROR((AE_INFO, "Invalid zero thread count in method"));
  	}
28f55ebce   Bob Moore   [ACPI] ACPICA 200...
581
582
  
  	/* Are there any other threads currently executing this method? */
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
583
  	if (method_desc->method.thread_count) {
28f55ebce   Bob Moore   [ACPI] ACPICA 200...
584
585
586
587
  		/*
  		 * Additional threads. Do not release the owner_id in this case,
  		 * we immediately reuse it for the next thread executing this method
  		 */
4be44fcd3   Len Brown   [ACPI] Lindent al...
588
  		ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
28f55ebce   Bob Moore   [ACPI] ACPICA 200...
589
590
  				  "*** Completed execution of one thread, %d threads remaining
  ",
b229cf92e   Bob Moore   ACPI: ACPICA 2006...
591
  				  method_desc->method.thread_count));
28f55ebce   Bob Moore   [ACPI] ACPICA 200...
592
593
  	} else {
  		/* This is the only executing thread for this method */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
594

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
595
596
  		/*
  		 * Support to dynamically change a method from not_serialized to
28f55ebce   Bob Moore   [ACPI] ACPICA 200...
597
  		 * Serialized if it appears that the method is incorrectly written and
967440e3b   Bob Moore   ACPI: ACPICA 2006...
598
599
  		 * does not support multiple thread execution. The best example of this
  		 * is if such a method creates namespace objects and blocks. A second
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
600
601
602
603
604
  		 * thread will fail with an AE_ALREADY_EXISTS exception
  		 *
  		 * This code is here because we must wait until the last thread exits
  		 * before creating the synchronization semaphore.
  		 */
967440e3b   Bob Moore   ACPI: ACPICA 2006...
605
606
  		if ((method_desc->method.method_flags & AML_METHOD_SERIALIZED)
  		    && (!method_desc->method.mutex)) {
b7f9f0422   Bob Moore   ACPICA: Cosmetic ...
607
  			(void)acpi_ds_create_method_mutex(method_desc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
608
  		}
28f55ebce   Bob Moore   [ACPI] ACPICA 200...
609
  		/* No more threads, we can free the owner_id */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
610

7f0c826a4   Lin Ming   ACPICA: Add suppo...
611
612
613
  		if (!(method_desc->method.flags & AOPOBJ_MODULE_LEVEL)) {
  			acpi_ut_release_owner_id(&method_desc->method.owner_id);
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
614
  	}
a94f18810   Len Brown   [ACPI] revert own...
615

aff8c2777   Robert Moore   [ACPI] ACPICA 200...
616
  	return_VOID;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
617
  }