dsmethod.c 17.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 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 43 44 45 46 47 48 49 50 51
/******************************************************************************
 *
 * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
 *
 *****************************************************************************/

/*
 * Copyright (C) 2000 - 2005, R. Byron Moore
 * 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.
 */

#include <acpi/acpi.h>
#include <acpi/acparser.h>
#include <acpi/amlcode.h>
#include <acpi/acdispat.h>
#include <acpi/acinterp.h>
#include <acpi/acnamesp.h>

#define _COMPONENT          ACPI_DISPATCHER
L
Len Brown 已提交
52
ACPI_MODULE_NAME("dsmethod")
L
Linus Torvalds 已提交
53 54 55 56 57

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_parse_method
 *
58
 * PARAMETERS:  Node        - Method node
L
Linus Torvalds 已提交
59 60 61
 *
 * RETURN:      Status
 *
62
 * DESCRIPTION: Parse the AML that is associated with the method.
L
Linus Torvalds 已提交
63 64 65 66
 *
 * MUTEX:       Assumes parser is locked
 *
 ******************************************************************************/
L
Len Brown 已提交
67
acpi_status acpi_ds_parse_method(struct acpi_namespace_node *node)
L
Linus Torvalds 已提交
68
{
L
Len Brown 已提交
69 70 71 72
	acpi_status status;
	union acpi_operand_object *obj_desc;
	union acpi_parse_object *op;
	struct acpi_walk_state *walk_state;
L
Linus Torvalds 已提交
73

L
Len Brown 已提交
74
	ACPI_FUNCTION_TRACE_PTR("ds_parse_method", node);
L
Linus Torvalds 已提交
75 76 77

	/* Parameter Validation */

78
	if (!node) {
L
Len Brown 已提交
79
		return_ACPI_STATUS(AE_NULL_ENTRY);
L
Linus Torvalds 已提交
80 81
	}

L
Len Brown 已提交
82 83 84
	ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
			  "**** Parsing [%4.4s] **** named_obj=%p\n",
			  acpi_ut_get_node_name(node), node));
L
Linus Torvalds 已提交
85 86 87

	/* Extract the method object from the method Node */

L
Len Brown 已提交
88
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
89
	if (!obj_desc) {
L
Len Brown 已提交
90
		return_ACPI_STATUS(AE_NULL_OBJECT);
L
Linus Torvalds 已提交
91 92 93 94 95
	}

	/* Create a mutex for the method if there is a concurrency limit */

	if ((obj_desc->method.concurrency != ACPI_INFINITE_CONCURRENCY) &&
L
Len Brown 已提交
96 97 98 99 100 101
	    (!obj_desc->method.semaphore)) {
		status = acpi_os_create_semaphore(obj_desc->method.concurrency,
						  obj_desc->method.concurrency,
						  &obj_desc->method.semaphore);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
102 103 104 105 106 107 108
		}
	}

	/*
	 * Allocate a new parser op to be the root of the parsed
	 * method tree
	 */
L
Len Brown 已提交
109
	op = acpi_ps_alloc_op(AML_METHOD_OP);
L
Linus Torvalds 已提交
110
	if (!op) {
L
Len Brown 已提交
111
		return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
112 113 114 115
	}

	/* Init new op with the method name and pointer back to the Node */

L
Len Brown 已提交
116
	acpi_ps_set_name(op, node->name.integer);
L
Linus Torvalds 已提交
117 118 119 120 121 122 123
	op->common.node = node;

	/*
	 * Get a new owner_id for objects created by this method. Namespace
	 * objects (such as Operation Regions) can be created during the
	 * first pass parse.
	 */
L
Len Brown 已提交
124 125
	status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
	if (ACPI_FAILURE(status)) {
126 127
		goto cleanup;
	}
L
Linus Torvalds 已提交
128 129 130

	/* Create and initialize a new walk state */

L
Len Brown 已提交
131 132 133
	walk_state =
	    acpi_ds_create_walk_state(obj_desc->method.owner_id, NULL, NULL,
				      NULL);
L
Linus Torvalds 已提交
134
	if (!walk_state) {
135
		status = AE_NO_MEMORY;
136
		goto cleanup2;
L
Linus Torvalds 已提交
137 138
	}

L
Len Brown 已提交
139 140 141 142 143
	status = acpi_ds_init_aml_walk(walk_state, op, node,
				       obj_desc->method.aml_start,
				       obj_desc->method.aml_length, NULL, 1);
	if (ACPI_FAILURE(status)) {
		acpi_ds_delete_walk_state(walk_state);
144
		goto cleanup2;
L
Linus Torvalds 已提交
145 146 147 148 149
	}

	/*
	 * Parse the method, first pass
	 *
R
Robert Moore 已提交
150 151 152 153 154
	 * The first pass load is where newly declared named objects are added into
	 * the namespace.  Actual evaluation of the named objects (what would be
	 * called a "second pass") happens during the actual execution of the
	 * method so that operands to the named objects can take on dynamic
	 * run-time values.
L
Linus Torvalds 已提交
155
	 */
L
Len Brown 已提交
156 157
	status = acpi_ps_parse_aml(walk_state);
	if (ACPI_FAILURE(status)) {
158
		goto cleanup2;
L
Linus Torvalds 已提交
159 160
	}

L
Len Brown 已提交
161 162 163
	ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
			  "**** [%4.4s] Parsed **** named_obj=%p Op=%p\n",
			  acpi_ut_get_node_name(node), node, op));
164 165 166 167 168 169

	/*
	 * Delete the parse tree. We simply re-parse the method for every
	 * execution since there isn't much overhead (compared to keeping lots
	 * of parse trees around)
	 */
L
Len Brown 已提交
170 171
	acpi_ns_delete_namespace_subtree(node);
	acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id);
L
Linus Torvalds 已提交
172

L
Len Brown 已提交
173 174
      cleanup2:
	acpi_ut_release_owner_id(&obj_desc->method.owner_id);
175

L
Len Brown 已提交
176 177 178
      cleanup:
	acpi_ps_delete_parse_tree(op);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_begin_method_execution
 *
 * PARAMETERS:  method_node         - Node of the method
 *              obj_desc            - The method object
 *              calling_method_node - Caller of this method (if non-null)
 *
 * 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.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
198 199 200
acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
			       union acpi_operand_object *obj_desc,
			       struct acpi_namespace_node *calling_method_node)
L
Linus Torvalds 已提交
201
{
L
Len Brown 已提交
202
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
203

L
Len Brown 已提交
204
	ACPI_FUNCTION_TRACE_PTR("ds_begin_method_execution", method_node);
L
Linus Torvalds 已提交
205 206

	if (!method_node) {
L
Len Brown 已提交
207
		return_ACPI_STATUS(AE_NULL_ENTRY);
L
Linus Torvalds 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
	}

	/*
	 * If there is a concurrency limit on this method, we need to
	 * obtain a unit from the method semaphore.
	 */
	if (obj_desc->method.semaphore) {
		/*
		 * Allow recursive method calls, up to the reentrancy/concurrency
		 * limit imposed by the SERIALIZED rule and the sync_level method
		 * parameter.
		 *
		 * The point of this code is to avoid permanently blocking a
		 * thread that is making recursive method calls.
		 */
		if (method_node == calling_method_node) {
L
Len Brown 已提交
224 225 226
			if (obj_desc->method.thread_count >=
			    obj_desc->method.concurrency) {
				return_ACPI_STATUS(AE_AML_METHOD_LIMIT);
L
Linus Torvalds 已提交
227 228 229 230 231 232 233
			}
		}

		/*
		 * Get a unit from the method semaphore. This releases the
		 * interpreter if we block
		 */
L
Len Brown 已提交
234 235 236
		status =
		    acpi_ex_system_wait_semaphore(obj_desc->method.semaphore,
						  ACPI_WAIT_FOREVER);
L
Linus Torvalds 已提交
237 238 239 240 241 242 243
	}

	/*
	 * 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++;
L
Len Brown 已提交
244
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
}

/*******************************************************************************
 *
 * 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
L
Len Brown 已提交
262 263 264
acpi_ds_call_control_method(struct acpi_thread_state *thread,
			    struct acpi_walk_state *this_walk_state,
			    union acpi_parse_object *op)
L
Linus Torvalds 已提交
265
{
L
Len Brown 已提交
266 267 268 269 270 271
	acpi_status status;
	struct acpi_namespace_node *method_node;
	struct acpi_walk_state *next_walk_state = NULL;
	union acpi_operand_object *obj_desc;
	struct acpi_parameter_info info;
	u32 i;
L
Linus Torvalds 已提交
272

L
Len Brown 已提交
273
	ACPI_FUNCTION_TRACE_PTR("ds_call_control_method", this_walk_state);
L
Linus Torvalds 已提交
274

L
Len Brown 已提交
275 276 277
	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
			  "Execute method %p, currentstate=%p\n",
			  this_walk_state->prev_op, this_walk_state));
L
Linus Torvalds 已提交
278 279 280 281 282 283

	/*
	 * Get the namespace entry for the control method we are about to call
	 */
	method_node = this_walk_state->method_call_node;
	if (!method_node) {
L
Len Brown 已提交
284
		return_ACPI_STATUS(AE_NULL_ENTRY);
L
Linus Torvalds 已提交
285 286
	}

L
Len Brown 已提交
287
	obj_desc = acpi_ns_get_attached_object(method_node);
L
Linus Torvalds 已提交
288
	if (!obj_desc) {
L
Len Brown 已提交
289
		return_ACPI_STATUS(AE_NULL_OBJECT);
L
Linus Torvalds 已提交
290 291
	}

L
Len Brown 已提交
292 293 294 295 296
	status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

L
Linus Torvalds 已提交
297 298
	/* Init for new method, wait on concurrency semaphore */

L
Len Brown 已提交
299 300 301
	status = acpi_ds_begin_method_execution(method_node, obj_desc,
						this_walk_state->method_node);
	if (ACPI_FAILURE(status)) {
302
		goto cleanup;
L
Linus Torvalds 已提交
303 304 305 306 307
	}

	if (!(obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY)) {
		/* 1) Parse: Create a new walk state for the preempting walk */

L
Len Brown 已提交
308 309 310
		next_walk_state =
		    acpi_ds_create_walk_state(obj_desc->method.owner_id, op,
					      obj_desc, NULL);
L
Linus Torvalds 已提交
311
		if (!next_walk_state) {
L
Len Brown 已提交
312
			return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
313 314 315 316
		}

		/* Create and init a Root Node */

L
Len Brown 已提交
317
		op = acpi_ps_create_scope_op();
L
Linus Torvalds 已提交
318 319 320 321 322
		if (!op) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}

L
Len Brown 已提交
323 324 325 326 327 328
		status = acpi_ds_init_aml_walk(next_walk_state, op, method_node,
					       obj_desc->method.aml_start,
					       obj_desc->method.aml_length,
					       NULL, 1);
		if (ACPI_FAILURE(status)) {
			acpi_ds_delete_walk_state(next_walk_state);
L
Linus Torvalds 已提交
329 330 331 332 333
			goto cleanup;
		}

		/* Begin AML parse */

L
Len Brown 已提交
334 335
		status = acpi_ps_parse_aml(next_walk_state);
		acpi_ps_delete_parse_tree(op);
L
Linus Torvalds 已提交
336 337 338 339
	}

	/* 2) Execute: Create a new state for the preempting walk */

L
Len Brown 已提交
340 341
	next_walk_state = acpi_ds_create_walk_state(obj_desc->method.owner_id,
						    NULL, obj_desc, thread);
L
Linus Torvalds 已提交
342 343 344 345 346 347 348 349 350 351
	if (!next_walk_state) {
		status = AE_NO_MEMORY;
		goto cleanup;
	}
	/*
	 * The resolved arguments were put on the previous walk state's operand
	 * stack.  Operands on the previous walk state stack always
	 * start at index 0.
	 * Null terminate the list of arguments
	 */
L
Len Brown 已提交
352
	this_walk_state->operands[this_walk_state->num_operands] = NULL;
L
Linus Torvalds 已提交
353 354 355 356

	info.parameters = &this_walk_state->operands[0];
	info.parameter_type = ACPI_PARAM_ARGS;

L
Len Brown 已提交
357 358 359 360
	status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node,
				       obj_desc->method.aml_start,
				       obj_desc->method.aml_length, &info, 3);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
361 362 363 364 365 366 367 368
		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++) {
L
Len Brown 已提交
369 370
		acpi_ut_remove_reference(this_walk_state->operands[i]);
		this_walk_state->operands[i] = NULL;
L
Linus Torvalds 已提交
371 372 373 374 375 376
	}

	/* Clear the operand stack */

	this_walk_state->num_operands = 0;

L
Len Brown 已提交
377 378 379
	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
			  "Starting nested execution, newstate=%p\n",
			  next_walk_state));
L
Linus Torvalds 已提交
380 381

	if (obj_desc->method.method_flags & AML_METHOD_INTERNAL_ONLY) {
L
Len Brown 已提交
382
		status = obj_desc->method.implementation(next_walk_state);
L
Len Brown 已提交
383
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
384 385
	}

L
Len Brown 已提交
386 387 388 389 390 391
	return_ACPI_STATUS(AE_OK);

	/* On error, we must delete the new walk state */

      cleanup:
	acpi_ut_release_owner_id(&obj_desc->method.owner_id);
L
Linus Torvalds 已提交
392
	if (next_walk_state && (next_walk_state->method_desc)) {
L
Len Brown 已提交
393 394
		/* Decrement the thread count on the method parse tree */

L
Len Brown 已提交
395
		next_walk_state->method_desc->method.thread_count--;
L
Linus Torvalds 已提交
396
	}
L
Len Brown 已提交
397 398
	(void)acpi_ds_terminate_control_method(next_walk_state);
	acpi_ds_delete_walk_state(next_walk_state);
L
Len Brown 已提交
399
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
}

/*******************************************************************************
 *
 * 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
L
Len Brown 已提交
417 418
acpi_ds_restart_control_method(struct acpi_walk_state *walk_state,
			       union acpi_operand_object *return_desc)
L
Linus Torvalds 已提交
419
{
L
Len Brown 已提交
420
	acpi_status status;
L
Linus Torvalds 已提交
421

L
Len Brown 已提交
422
	ACPI_FUNCTION_TRACE_PTR("ds_restart_control_method", walk_state);
L
Linus Torvalds 已提交
423

L
Len Brown 已提交
424 425 426 427
	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
			  "****Restart [%4.4s] Op %p return_value_from_callee %p\n",
			  (char *)&walk_state->method_node->name,
			  walk_state->method_call_op, return_desc));
L
Linus Torvalds 已提交
428

L
Len Brown 已提交
429 430 431 432
	ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
			  "    return_from_this_method_used?=%X res_stack %p Walk %p\n",
			  walk_state->return_used,
			  walk_state->results, walk_state));
L
Linus Torvalds 已提交
433 434 435 436 437 438 439 440 441

	/* Did the called method return a value? */

	if (return_desc) {
		/* Are we actually going to use the return value? */

		if (walk_state->return_used) {
			/* Save the return value from the previous method */

L
Len Brown 已提交
442 443 444 445
			status = acpi_ds_result_push(return_desc, walk_state);
			if (ACPI_FAILURE(status)) {
				acpi_ut_remove_reference(return_desc);
				return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
			}

			/*
			 * Save as THIS method's return value in case it is returned
			 * immediately to yet another method
			 */
			walk_state->return_desc = return_desc;
		}

		/*
		 * The following code is the
		 * optional support for a so-called "implicit return". Some AML code
		 * assumes that the last value of the method is "implicitly" returned
		 * to the caller. Just save the last result as the return value.
		 * NOTE: this is optional because the ASL language does not actually
		 * support this behavior.
		 */
L
Len Brown 已提交
463 464
		else if (!acpi_ds_do_implicit_return
			 (return_desc, walk_state, FALSE)) {
L
Linus Torvalds 已提交
465 466 467 468
			/*
			 * Delete the return value if it will not be used by the
			 * calling method
			 */
L
Len Brown 已提交
469
			acpi_ut_remove_reference(return_desc);
L
Linus Torvalds 已提交
470 471 472
		}
	}

L
Len Brown 已提交
473
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
474 475 476 477 478 479 480 481
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_terminate_control_method
 *
 * PARAMETERS:  walk_state          - State of the method
 *
L
Len Brown 已提交
482
 * RETURN:      Status
L
Linus Torvalds 已提交
483 484 485 486 487 488 489
 *
 * DESCRIPTION: Terminate a control method.  Delete everything that the method
 *              created, delete all locals and arguments, and delete the parse
 *              tree if requested.
 *
 ******************************************************************************/

L
Len Brown 已提交
490
acpi_status acpi_ds_terminate_control_method(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
491
{
L
Len Brown 已提交
492 493 494
	union acpi_operand_object *obj_desc;
	struct acpi_namespace_node *method_node;
	acpi_status status;
L
Linus Torvalds 已提交
495

L
Len Brown 已提交
496
	ACPI_FUNCTION_TRACE_PTR("ds_terminate_control_method", walk_state);
L
Linus Torvalds 已提交
497 498

	if (!walk_state) {
L
Len Brown 已提交
499
		return (AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
500 501 502 503 504 505
	}

	/* The current method object was saved in the walk state */

	obj_desc = walk_state->method_desc;
	if (!obj_desc) {
L
Len Brown 已提交
506
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
507 508 509 510
	}

	/* Delete all arguments and locals */

L
Len Brown 已提交
511
	acpi_ds_method_data_delete_all(walk_state);
L
Linus Torvalds 已提交
512 513 514 515 516 517

	/*
	 * Lock the parser while we terminate this method.
	 * If this is the last thread executing the method,
	 * we have additional cleanup to perform
	 */
L
Len Brown 已提交
518 519
	status = acpi_ut_acquire_mutex(ACPI_MTX_PARSER);
	if (ACPI_FAILURE(status)) {
L
Len Brown 已提交
520
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
521 522 523 524 525
	}

	/* Signal completion of the execution of this method if necessary */

	if (walk_state->method_desc->method.semaphore) {
L
Len Brown 已提交
526 527 528 529 530
		status =
		    acpi_os_signal_semaphore(walk_state->method_desc->method.
					     semaphore, 1);
		if (ACPI_FAILURE(status)) {
			ACPI_REPORT_ERROR(("Could not signal method semaphore\n"));
L
Linus Torvalds 已提交
531 532 533 534 535 536 537
			status = AE_OK;

			/* Ignore error and continue cleanup */
		}
	}

	if (walk_state->method_desc->method.thread_count) {
L
Len Brown 已提交
538 539 540 541
		ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
				  "*** Not deleting method namespace, there are still %d threads\n",
				  walk_state->method_desc->method.
				  thread_count));
L
Linus Torvalds 已提交
542 543 544 545 546 547 548 549 550 551 552 553 554 555
	}

	if (!walk_state->method_desc->method.thread_count) {
		/*
		 * Support to dynamically change a method from not_serialized to
		 * Serialized if it appears that the method is written foolishly and
		 * does not support multiple thread execution.  The best example of this
		 * is if such a method creates namespace objects and blocks.  A second
		 * 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.
		 */
		if ((walk_state->method_desc->method.concurrency == 1) &&
L
Len Brown 已提交
556 557 558 559 560
		    (!walk_state->method_desc->method.semaphore)) {
			status = acpi_os_create_semaphore(1, 1,
							  &walk_state->
							  method_desc->method.
							  semaphore);
L
Linus Torvalds 已提交
561 562 563 564 565 566 567 568 569 570 571 572 573 574
		}

		/*
		 * There are no more threads executing this method.  Perform
		 * additional cleanup.
		 *
		 * The method Node is stored in the walk state
		 */
		method_node = walk_state->method_node;

		/*
		 * Delete any namespace entries created immediately underneath
		 * the method
		 */
L
Len Brown 已提交
575 576
		status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
		if (ACPI_FAILURE(status)) {
L
Len Brown 已提交
577
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
578 579 580
		}

		if (method_node->child) {
L
Len Brown 已提交
581
			acpi_ns_delete_namespace_subtree(method_node);
L
Linus Torvalds 已提交
582 583 584 585 586 587
		}

		/*
		 * Delete any namespace entries created anywhere else within
		 * the namespace
		 */
L
Len Brown 已提交
588 589 590 591 592 593 594
		acpi_ns_delete_namespace_by_owner(walk_state->method_desc->
						  method.owner_id);
		status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
		acpi_ut_release_owner_id(&walk_state->method_desc->method.
					 owner_id);

		if (ACPI_FAILURE(status)) {
L
Len Brown 已提交
595
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
596 597
		}
	}
L
Len Brown 已提交
598 599 600

	status = acpi_ut_release_mutex(ACPI_MTX_PARSER);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
601
}