dswstate.c 28.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: dswstate - Dispatcher parse tree walk management routines
 *
 *****************************************************************************/

/*
B
Bob Moore 已提交
8
 * Copyright (C) 2000 - 2006, R. Byron Moore
L
Linus Torvalds 已提交
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
 * 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/acdispat.h>
#include <acpi/acnamesp.h>

#define _COMPONENT          ACPI_DISPATCHER
L
Len Brown 已提交
50
ACPI_MODULE_NAME("dswstate")
L
Linus Torvalds 已提交
51

R
Robert Moore 已提交
52 53
/* Local prototypes */
#ifdef ACPI_OBSOLETE_FUNCTIONS
L
Linus Torvalds 已提交
54
acpi_status
L
Len Brown 已提交
55 56
acpi_ds_result_insert(void *object,
		      u32 index, struct acpi_walk_state *walk_state);
L
Linus Torvalds 已提交
57

L
Len Brown 已提交
58
acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state *walk_state);
L
Linus Torvalds 已提交
59

R
Robert Moore 已提交
60
acpi_status
L
Len Brown 已提交
61 62 63 64 65
acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
			     struct acpi_walk_state *walk_state);

void *acpi_ds_obj_stack_get_value(u32 index,
				  struct acpi_walk_state *walk_state);
R
Robert Moore 已提交
66
#endif
L
Linus Torvalds 已提交
67

R
Robert Moore 已提交
68
#ifdef ACPI_FUTURE_USAGE
L
Linus Torvalds 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_remove
 *
 * PARAMETERS:  Object              - Where to return the popped object
 *              Index               - Where to extract the object
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Pop an object off the bottom of this walk's result stack.  In
 *              other words, this is a FIFO.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
85 86
acpi_ds_result_remove(union acpi_operand_object **object,
		      u32 index, struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
87
{
L
Len Brown 已提交
88
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
89

B
Bob Moore 已提交
90
	ACPI_FUNCTION_NAME(ds_result_remove);
L
Linus Torvalds 已提交
91 92 93

	state = walk_state->results;
	if (!state) {
B
Bob Moore 已提交
94 95
		ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
			    walk_state));
L
Linus Torvalds 已提交
96 97 98 99
		return (AE_NOT_EXIST);
	}

	if (index >= ACPI_OBJ_MAX_OPERAND) {
B
Bob Moore 已提交
100 101 102
		ACPI_ERROR((AE_INFO,
			    "Index out of range: %X State=%p Num=%X",
			    index, walk_state, state->results.num_results));
L
Linus Torvalds 已提交
103 104 105 106
	}

	/* Check for a valid result object */

L
Len Brown 已提交
107
	if (!state->results.obj_desc[index]) {
B
Bob Moore 已提交
108 109 110
		ACPI_ERROR((AE_INFO,
			    "Null operand! State=%p #Ops=%X, Index=%X",
			    walk_state, state->results.num_results, index));
L
Linus Torvalds 已提交
111 112 113 114 115 116 117
		return (AE_AML_NO_RETURN_VALUE);
	}

	/* Remove the object */

	state->results.num_results--;

L
Len Brown 已提交
118 119
	*object = state->results.obj_desc[index];
	state->results.obj_desc[index] = NULL;
L
Linus Torvalds 已提交
120

L
Len Brown 已提交
121 122 123 124 125 126
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
			  "Obj=%p [%s] Index=%X State=%p Num=%X\n",
			  *object,
			  (*object) ? acpi_ut_get_object_type_name(*object) :
			  "NULL", index, walk_state,
			  state->results.num_results));
L
Linus Torvalds 已提交
127 128 129

	return (AE_OK);
}
L
Len Brown 已提交
130
#endif				/*  ACPI_FUTURE_USAGE  */
L
Linus Torvalds 已提交
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_pop
 *
 * PARAMETERS:  Object              - Where to return the popped object
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Pop an object off the bottom of this walk's result stack.  In
 *              other words, this is a FIFO.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
147 148
acpi_ds_result_pop(union acpi_operand_object ** object,
		   struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
149
{
L
Len Brown 已提交
150 151
	acpi_native_uint index;
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
152

B
Bob Moore 已提交
153
	ACPI_FUNCTION_NAME(ds_result_pop);
L
Linus Torvalds 已提交
154 155 156 157 158 159 160

	state = walk_state->results;
	if (!state) {
		return (AE_OK);
	}

	if (!state->results.num_results) {
B
Bob Moore 已提交
161 162
		ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
			    walk_state));
L
Linus Torvalds 已提交
163 164 165 166 167 168 169 170
		return (AE_AML_NO_RETURN_VALUE);
	}

	/* Remove top element */

	state->results.num_results--;

	for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
B
Bob Moore 已提交
171

L
Linus Torvalds 已提交
172 173
		/* Check for a valid result object */

L
Len Brown 已提交
174 175 176
		if (state->results.obj_desc[index - 1]) {
			*object = state->results.obj_desc[index - 1];
			state->results.obj_desc[index - 1] = NULL;
L
Linus Torvalds 已提交
177

L
Len Brown 已提交
178 179 180 181 182 183 184
			ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
					  "Obj=%p [%s] Index=%X State=%p Num=%X\n",
					  *object,
					  (*object) ?
					  acpi_ut_get_object_type_name(*object)
					  : "NULL", (u32) index - 1, walk_state,
					  state->results.num_results));
L
Linus Torvalds 已提交
185 186 187 188 189

			return (AE_OK);
		}
	}

B
Bob Moore 已提交
190
	ACPI_ERROR((AE_INFO, "No result objects! State=%p", walk_state));
L
Linus Torvalds 已提交
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
	return (AE_AML_NO_RETURN_VALUE);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_pop_from_bottom
 *
 * PARAMETERS:  Object              - Where to return the popped object
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Pop an object off the bottom of this walk's result stack.  In
 *              other words, this is a FIFO.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
209 210
acpi_ds_result_pop_from_bottom(union acpi_operand_object ** object,
			       struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
211
{
L
Len Brown 已提交
212 213
	acpi_native_uint index;
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
214

B
Bob Moore 已提交
215
	ACPI_FUNCTION_NAME(ds_result_pop_from_bottom);
L
Linus Torvalds 已提交
216 217 218

	state = walk_state->results;
	if (!state) {
B
Bob Moore 已提交
219 220
		ACPI_ERROR((AE_INFO,
			    "No result object pushed! State=%p", walk_state));
L
Linus Torvalds 已提交
221 222 223 224
		return (AE_NOT_EXIST);
	}

	if (!state->results.num_results) {
B
Bob Moore 已提交
225 226
		ACPI_ERROR((AE_INFO, "No result objects! State=%p",
			    walk_state));
L
Linus Torvalds 已提交
227 228 229 230 231
		return (AE_AML_NO_RETURN_VALUE);
	}

	/* Remove Bottom element */

L
Len Brown 已提交
232
	*object = state->results.obj_desc[0];
L
Linus Torvalds 已提交
233 234 235 236

	/* Push entire stack down one element */

	for (index = 0; index < state->results.num_results; index++) {
L
Len Brown 已提交
237 238
		state->results.obj_desc[index] =
		    state->results.obj_desc[index + 1];
L
Linus Torvalds 已提交
239 240 241 242 243 244 245
	}

	state->results.num_results--;

	/* Check for a valid result object */

	if (!*object) {
B
Bob Moore 已提交
246 247 248 249
		ACPI_ERROR((AE_INFO,
			    "Null operand! State=%p #Ops=%X Index=%X",
			    walk_state, state->results.num_results,
			    (u32) index));
L
Linus Torvalds 已提交
250 251 252
		return (AE_AML_NO_RETURN_VALUE);
	}

L
Len Brown 已提交
253 254 255 256
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n",
			  *object,
			  (*object) ? acpi_ut_get_object_type_name(*object) :
			  "NULL", state, walk_state));
L
Linus Torvalds 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_push
 *
 * PARAMETERS:  Object              - Where to return the popped object
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Push an object onto the current result stack
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
275 276
acpi_ds_result_push(union acpi_operand_object * object,
		    struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
277
{
L
Len Brown 已提交
278
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
279

B
Bob Moore 已提交
280
	ACPI_FUNCTION_NAME(ds_result_push);
L
Linus Torvalds 已提交
281 282 283

	state = walk_state->results;
	if (!state) {
B
Bob Moore 已提交
284
		ACPI_ERROR((AE_INFO, "No result stack frame during push"));
L
Linus Torvalds 已提交
285 286 287 288
		return (AE_AML_INTERNAL);
	}

	if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
B
Bob Moore 已提交
289 290 291
		ACPI_ERROR((AE_INFO,
			    "Result stack overflow: Obj=%p State=%p Num=%X",
			    object, walk_state, state->results.num_results));
L
Linus Torvalds 已提交
292 293 294 295
		return (AE_STACK_OVERFLOW);
	}

	if (!object) {
B
Bob Moore 已提交
296 297 298
		ACPI_ERROR((AE_INFO,
			    "Null Object! Obj=%p State=%p Num=%X",
			    object, walk_state, state->results.num_results));
L
Linus Torvalds 已提交
299 300 301
		return (AE_BAD_PARAMETER);
	}

L
Len Brown 已提交
302
	state->results.obj_desc[state->results.num_results] = object;
L
Linus Torvalds 已提交
303 304
	state->results.num_results++;

L
Len Brown 已提交
305 306 307 308 309 310 311 312
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
			  object,
			  object ?
			  acpi_ut_get_object_type_name((union
							acpi_operand_object *)
						       object) : "NULL",
			  walk_state, state->results.num_results,
			  walk_state->current_result));
L
Linus Torvalds 已提交
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_stack_push
 *
 * PARAMETERS:  walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Push an object onto the walk_state result stack.
 *
 ******************************************************************************/

L
Len Brown 已提交
329
acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
330
{
L
Len Brown 已提交
331
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
332

B
Bob Moore 已提交
333
	ACPI_FUNCTION_NAME(ds_result_stack_push);
L
Linus Torvalds 已提交
334

L
Len Brown 已提交
335
	state = acpi_ut_create_generic_state();
L
Linus Torvalds 已提交
336 337 338 339
	if (!state) {
		return (AE_NO_MEMORY);
	}

B
Bob Moore 已提交
340
	state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT;
L
Len Brown 已提交
341
	acpi_ut_push_generic_state(&walk_state->results, state);
L
Linus Torvalds 已提交
342

L
Len Brown 已提交
343 344
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
			  state, walk_state));
L
Linus Torvalds 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_stack_pop
 *
 * PARAMETERS:  walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Pop an object off of the walk_state result stack.
 *
 ******************************************************************************/

L
Len Brown 已提交
361
acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
362
{
L
Len Brown 已提交
363
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
364

B
Bob Moore 已提交
365
	ACPI_FUNCTION_NAME(ds_result_stack_pop);
L
Linus Torvalds 已提交
366 367 368 369

	/* Check for stack underflow */

	if (walk_state->results == NULL) {
L
Len Brown 已提交
370 371
		ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n",
				  walk_state));
L
Linus Torvalds 已提交
372 373 374
		return (AE_AML_NO_OPERAND);
	}

L
Len Brown 已提交
375
	state = acpi_ut_pop_generic_state(&walk_state->results);
L
Linus Torvalds 已提交
376

L
Len Brown 已提交
377
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
B
Bob Moore 已提交
378
			  "Result=%p RemainingResults=%X State=%p\n",
L
Len Brown 已提交
379
			  state, state->results.num_results, walk_state));
L
Linus Torvalds 已提交
380

L
Len Brown 已提交
381
	acpi_ut_delete_generic_state(state);
L
Linus Torvalds 已提交
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_obj_stack_push
 *
 * PARAMETERS:  Object              - Object to push
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Push an object onto this walk's object/operand stack
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
400
acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
401
{
B
Bob Moore 已提交
402
	ACPI_FUNCTION_NAME(ds_obj_stack_push);
L
Linus Torvalds 已提交
403 404 405 406

	/* Check for stack overflow */

	if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
B
Bob Moore 已提交
407 408 409
		ACPI_ERROR((AE_INFO,
			    "Object stack overflow! Obj=%p State=%p #Ops=%X",
			    object, walk_state, walk_state->num_operands));
L
Linus Torvalds 已提交
410 411 412 413 414
		return (AE_STACK_OVERFLOW);
	}

	/* Put the object onto the stack */

L
Len Brown 已提交
415
	walk_state->operands[walk_state->num_operands] = object;
L
Linus Torvalds 已提交
416 417
	walk_state->num_operands++;

L
Len Brown 已提交
418 419 420 421 422 423
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
			  object,
			  acpi_ut_get_object_type_name((union
							acpi_operand_object *)
						       object), walk_state,
			  walk_state->num_operands));
L
Linus Torvalds 已提交
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_obj_stack_pop
 *
 * PARAMETERS:  pop_count           - Number of objects/entries to pop
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Pop this walk's object stack.  Objects on the stack are NOT
 *              deleted by this routine.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
443
acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
444
{
L
Len Brown 已提交
445
	u32 i;
L
Linus Torvalds 已提交
446

B
Bob Moore 已提交
447
	ACPI_FUNCTION_NAME(ds_obj_stack_pop);
L
Linus Torvalds 已提交
448 449

	for (i = 0; i < pop_count; i++) {
B
Bob Moore 已提交
450

L
Linus Torvalds 已提交
451 452 453
		/* Check for stack underflow */

		if (walk_state->num_operands == 0) {
B
Bob Moore 已提交
454 455 456 457
			ACPI_ERROR((AE_INFO,
				    "Object stack underflow! Count=%X State=%p #Ops=%X",
				    pop_count, walk_state,
				    walk_state->num_operands));
L
Linus Torvalds 已提交
458 459 460 461 462 463
			return (AE_STACK_UNDERFLOW);
		}

		/* Just set the stack entry to null */

		walk_state->num_operands--;
L
Len Brown 已提交
464
		walk_state->operands[walk_state->num_operands] = NULL;
L
Linus Torvalds 已提交
465 466
	}

L
Len Brown 已提交
467
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
L
Linus Torvalds 已提交
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
			  pop_count, walk_state, walk_state->num_operands));

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_obj_stack_pop_and_delete
 *
 * PARAMETERS:  pop_count           - Number of objects/entries to pop
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Pop this walk's object stack and delete each object that is
 *              popped off.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
488 489
acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
				 struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
490
{
L
Len Brown 已提交
491 492
	u32 i;
	union acpi_operand_object *obj_desc;
L
Linus Torvalds 已提交
493

B
Bob Moore 已提交
494
	ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete);
L
Linus Torvalds 已提交
495 496

	for (i = 0; i < pop_count; i++) {
B
Bob Moore 已提交
497

L
Linus Torvalds 已提交
498 499 500
		/* Check for stack underflow */

		if (walk_state->num_operands == 0) {
B
Bob Moore 已提交
501 502 503 504
			ACPI_ERROR((AE_INFO,
				    "Object stack underflow! Count=%X State=%p #Ops=%X",
				    pop_count, walk_state,
				    walk_state->num_operands));
L
Linus Torvalds 已提交
505 506 507 508 509 510
			return (AE_STACK_UNDERFLOW);
		}

		/* Pop the stack and delete an object if present in this stack entry */

		walk_state->num_operands--;
L
Len Brown 已提交
511
		obj_desc = walk_state->operands[walk_state->num_operands];
L
Linus Torvalds 已提交
512
		if (obj_desc) {
L
Len Brown 已提交
513 514 515 516
			acpi_ut_remove_reference(walk_state->
						 operands[walk_state->
							  num_operands]);
			walk_state->operands[walk_state->num_operands] = NULL;
L
Linus Torvalds 已提交
517 518 519
		}
	}

L
Len Brown 已提交
520
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
L
Linus Torvalds 已提交
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
			  pop_count, walk_state, walk_state->num_operands));

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_get_current_walk_state
 *
 * PARAMETERS:  Thread          - Get current active state for this Thread
 *
 * RETURN:      Pointer to the current walk state
 *
 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
 *              walk state.)
 *
 ******************************************************************************/

L
Len Brown 已提交
539 540
struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
						       *thread)
L
Linus Torvalds 已提交
541
{
B
Bob Moore 已提交
542
	ACPI_FUNCTION_NAME(ds_get_current_walk_state);
L
Linus Torvalds 已提交
543 544 545 546 547

	if (!thread) {
		return (NULL);
	}

B
Bob Moore 已提交
548
	ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current WalkState %p\n",
L
Len Brown 已提交
549
			  thread->walk_state_list));
L
Linus Torvalds 已提交
550 551 552 553 554 555 556 557 558

	return (thread->walk_state_list);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_push_walk_state
 *
 * PARAMETERS:  walk_state      - State to push
R
Robert Moore 已提交
559
 *              Thread          - Thread state object
L
Linus Torvalds 已提交
560 561 562
 *
 * RETURN:      None
 *
R
Robert Moore 已提交
563
 * DESCRIPTION: Place the Thread state at the head of the state list.
L
Linus Torvalds 已提交
564 565 566 567
 *
 ******************************************************************************/

void
L
Len Brown 已提交
568 569
acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
			struct acpi_thread_state *thread)
L
Linus Torvalds 已提交
570
{
B
Bob Moore 已提交
571
	ACPI_FUNCTION_TRACE(ds_push_walk_state);
L
Linus Torvalds 已提交
572

L
Len Brown 已提交
573
	walk_state->next = thread->walk_state_list;
L
Linus Torvalds 已提交
574 575 576 577 578 579 580 581 582
	thread->walk_state_list = walk_state;

	return_VOID;
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_pop_walk_state
 *
R
Robert Moore 已提交
583
 * PARAMETERS:  Thread      - Current thread state
L
Linus Torvalds 已提交
584
 *
R
Robert Moore 已提交
585
 * RETURN:      A walk_state object popped from the thread's stack
L
Linus Torvalds 已提交
586 587 588 589 590 591 592
 *
 * DESCRIPTION: Remove and return the walkstate object that is at the head of
 *              the walk stack for the given walk list.  NULL indicates that
 *              the list is empty.
 *
 ******************************************************************************/

L
Len Brown 已提交
593
struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
L
Linus Torvalds 已提交
594
{
L
Len Brown 已提交
595
	struct acpi_walk_state *walk_state;
L
Linus Torvalds 已提交
596

B
Bob Moore 已提交
597
	ACPI_FUNCTION_TRACE(ds_pop_walk_state);
L
Linus Torvalds 已提交
598 599 600 601

	walk_state = thread->walk_state_list;

	if (walk_state) {
B
Bob Moore 已提交
602

L
Linus Torvalds 已提交
603 604 605 606 607 608 609
		/* Next walk state becomes the current walk state */

		thread->walk_state_list = walk_state->next;

		/*
		 * Don't clear the NEXT field, this serves as an indicator
		 * that there is a parent WALK STATE
R
Robert Moore 已提交
610
		 * Do Not: walk_state->Next = NULL;
L
Linus Torvalds 已提交
611 612 613
		 */
	}

L
Len Brown 已提交
614
	return_PTR(walk_state);
L
Linus Torvalds 已提交
615 616 617 618 619 620
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_walk_state
 *
R
Robert Moore 已提交
621 622
 * PARAMETERS:  owner_id        - ID for object creation
 *              Origin          - Starting point for this walk
B
Bob Moore 已提交
623
 *              method_desc     - Method object
L
Linus Torvalds 已提交
624 625 626 627 628 629 630 631 632
 *              Thread          - Current thread state
 *
 * RETURN:      Pointer to the new walk state.
 *
 * DESCRIPTION: Allocate and initialize a new walk state.  The current walk
 *              state is set to this new state.
 *
 ******************************************************************************/

L
Len Brown 已提交
633 634 635 636
struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
						  union acpi_parse_object
						  *origin,
						  union acpi_operand_object
B
Bob Moore 已提交
637
						  *method_desc,
L
Len Brown 已提交
638 639
						  struct acpi_thread_state
						  *thread)
L
Linus Torvalds 已提交
640
{
L
Len Brown 已提交
641 642
	struct acpi_walk_state *walk_state;
	acpi_status status;
L
Linus Torvalds 已提交
643

B
Bob Moore 已提交
644
	ACPI_FUNCTION_TRACE(ds_create_walk_state);
L
Linus Torvalds 已提交
645

B
Bob Moore 已提交
646
	walk_state = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_walk_state));
L
Linus Torvalds 已提交
647
	if (!walk_state) {
L
Len Brown 已提交
648
		return_PTR(NULL);
L
Linus Torvalds 已提交
649 650
	}

B
Bob Moore 已提交
651 652
	walk_state->descriptor_type = ACPI_DESC_TYPE_WALK;
	walk_state->method_desc = method_desc;
L
Len Brown 已提交
653 654 655
	walk_state->owner_id = owner_id;
	walk_state->origin = origin;
	walk_state->thread = thread;
L
Linus Torvalds 已提交
656 657 658 659 660 661

	walk_state->parser_state.start_op = origin;

	/* Init the method args/local */

#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
L
Len Brown 已提交
662
	acpi_ds_method_data_init(walk_state);
L
Linus Torvalds 已提交
663 664 665 666
#endif

	/* Create an initial result stack entry */

L
Len Brown 已提交
667 668
	status = acpi_ds_result_stack_push(walk_state);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
669
		ACPI_FREE(walk_state);
L
Len Brown 已提交
670
		return_PTR(NULL);
L
Linus Torvalds 已提交
671 672 673 674 675
	}

	/* Put the new state at the head of the walk list */

	if (thread) {
L
Len Brown 已提交
676
		acpi_ds_push_walk_state(walk_state, thread);
L
Linus Torvalds 已提交
677 678
	}

L
Len Brown 已提交
679
	return_PTR(walk_state);
L
Linus Torvalds 已提交
680 681 682 683 684 685 686 687 688 689 690
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_init_aml_walk
 *
 * PARAMETERS:  walk_state      - New state to be initialized
 *              Op              - Current parse op
 *              method_node     - Control method NS node, if any
 *              aml_start       - Start of AML
 *              aml_length      - Length of AML
R
Robert Moore 已提交
691
 *              Info            - Method info block (params, etc.)
L
Linus Torvalds 已提交
692 693 694 695 696 697 698 699 700
 *              pass_number     - 1, 2, or 3
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
701 702 703 704 705 706
acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
		      union acpi_parse_object *op,
		      struct acpi_namespace_node *method_node,
		      u8 * aml_start,
		      u32 aml_length,
		      struct acpi_parameter_info *info, u8 pass_number)
L
Linus Torvalds 已提交
707
{
L
Len Brown 已提交
708 709 710
	acpi_status status;
	struct acpi_parse_state *parser_state = &walk_state->parser_state;
	union acpi_parse_object *extra_op;
L
Linus Torvalds 已提交
711

B
Bob Moore 已提交
712
	ACPI_FUNCTION_TRACE(ds_init_aml_walk);
L
Linus Torvalds 已提交
713

L
Len Brown 已提交
714 715
	walk_state->parser_state.aml =
	    walk_state->parser_state.aml_start = aml_start;
L
Linus Torvalds 已提交
716
	walk_state->parser_state.aml_end =
L
Len Brown 已提交
717
	    walk_state->parser_state.pkg_end = aml_start + aml_length;
L
Linus Torvalds 已提交
718 719 720

	/* The next_op of the next_walk will be the beginning of the method */

R
Robert Moore 已提交
721
	walk_state->next_op = NULL;
722
	walk_state->pass_number = pass_number;
L
Linus Torvalds 已提交
723 724 725

	if (info) {
		if (info->parameter_type == ACPI_PARAM_GPE) {
L
Len Brown 已提交
726 727 728 729 730
			walk_state->gpe_event_info =
			    ACPI_CAST_PTR(struct acpi_gpe_event_info,
					  info->parameters);
		} else {
			walk_state->params = info->parameters;
R
Robert Moore 已提交
731
			walk_state->caller_return_desc = &info->return_object;
L
Linus Torvalds 已提交
732 733 734
		}
	}

L
Len Brown 已提交
735 736 737
	status = acpi_ps_init_scope(&walk_state->parser_state, op);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
738 739 740 741
	}

	if (method_node) {
		walk_state->parser_state.start_node = method_node;
L
Len Brown 已提交
742 743 744 745
		walk_state->walk_type = ACPI_WALK_METHOD;
		walk_state->method_node = method_node;
		walk_state->method_desc =
		    acpi_ns_get_attached_object(method_node);
L
Linus Torvalds 已提交
746 747 748

		/* Push start scope on scope stack and make it current  */

L
Len Brown 已提交
749 750 751 752 753
		status =
		    acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
					     walk_state);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
754 755 756 757
		}

		/* Init the method arguments */

L
Len Brown 已提交
758 759 760 761 762
		status = acpi_ds_method_data_init_args(walk_state->params,
						       ACPI_METHOD_NUM_ARGS,
						       walk_state);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
763
		}
L
Len Brown 已提交
764
	} else {
L
Linus Torvalds 已提交
765 766 767 768 769 770 771 772 773 774 775 776 777
		/*
		 * Setup the current scope.
		 * Find a Named Op that has a namespace node associated with it.
		 * search upwards from this Op.  Current scope is the first
		 * Op with a namespace node.
		 */
		extra_op = parser_state->start_op;
		while (extra_op && !extra_op->common.node) {
			extra_op = extra_op->common.parent;
		}

		if (!extra_op) {
			parser_state->start_node = NULL;
L
Len Brown 已提交
778
		} else {
L
Linus Torvalds 已提交
779 780 781 782
			parser_state->start_node = extra_op->common.node;
		}

		if (parser_state->start_node) {
B
Bob Moore 已提交
783

L
Linus Torvalds 已提交
784 785
			/* Push start scope on scope stack and make it current  */

L
Len Brown 已提交
786 787 788 789 790 791
			status =
			    acpi_ds_scope_stack_push(parser_state->start_node,
						     parser_state->start_node->
						     type, walk_state);
			if (ACPI_FAILURE(status)) {
				return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
792 793 794 795
			}
		}
	}

L
Len Brown 已提交
796 797
	status = acpi_ds_init_callbacks(walk_state, pass_number);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
798 799 800 801 802 803 804 805 806 807 808 809 810 811
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_delete_walk_state
 *
 * PARAMETERS:  walk_state      - State to delete
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Delete a walk state including all internal data structures
 *
 ******************************************************************************/

L
Len Brown 已提交
812
void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
813
{
L
Len Brown 已提交
814
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
815

B
Bob Moore 已提交
816
	ACPI_FUNCTION_TRACE_PTR(ds_delete_walk_state, walk_state);
L
Linus Torvalds 已提交
817 818 819 820 821

	if (!walk_state) {
		return;
	}

B
Bob Moore 已提交
822
	if (walk_state->descriptor_type != ACPI_DESC_TYPE_WALK) {
B
Bob Moore 已提交
823 824
		ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
			    walk_state));
L
Linus Torvalds 已提交
825 826 827 828
		return;
	}

	if (walk_state->parser_state.scope) {
B
Bob Moore 已提交
829 830
		ACPI_ERROR((AE_INFO, "%p walk still has a scope list",
			    walk_state));
L
Linus Torvalds 已提交
831 832 833 834 835 836 837 838
	}

	/* Always must free any linked control states */

	while (walk_state->control_state) {
		state = walk_state->control_state;
		walk_state->control_state = state->common.next;

L
Len Brown 已提交
839
		acpi_ut_delete_generic_state(state);
L
Linus Torvalds 已提交
840 841 842 843 844 845 846 847
	}

	/* Always must free any linked parse states */

	while (walk_state->scope_info) {
		state = walk_state->scope_info;
		walk_state->scope_info = state->common.next;

L
Len Brown 已提交
848
		acpi_ut_delete_generic_state(state);
L
Linus Torvalds 已提交
849 850 851 852 853 854 855 856
	}

	/* Always must free any stacked result states */

	while (walk_state->results) {
		state = walk_state->results;
		walk_state->results = state->common.next;

L
Len Brown 已提交
857
		acpi_ut_delete_generic_state(state);
L
Linus Torvalds 已提交
858 859
	}

B
Bob Moore 已提交
860
	ACPI_FREE(walk_state);
L
Linus Torvalds 已提交
861 862 863
	return_VOID;
}

R
Robert Moore 已提交
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
#ifdef ACPI_OBSOLETE_FUNCTIONS
/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_insert
 *
 * PARAMETERS:  Object              - Object to push
 *              Index               - Where to insert the object
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Insert an object onto this walk's result stack
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
880 881
acpi_ds_result_insert(void *object,
		      u32 index, struct acpi_walk_state *walk_state)
R
Robert Moore 已提交
882
{
L
Len Brown 已提交
883
	union acpi_generic_state *state;
R
Robert Moore 已提交
884

B
Bob Moore 已提交
885
	ACPI_FUNCTION_NAME(ds_result_insert);
R
Robert Moore 已提交
886 887 888

	state = walk_state->results;
	if (!state) {
B
Bob Moore 已提交
889 890
		ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
			    walk_state));
R
Robert Moore 已提交
891 892 893 894
		return (AE_NOT_EXIST);
	}

	if (index >= ACPI_OBJ_NUM_OPERANDS) {
B
Bob Moore 已提交
895 896 897 898
		ACPI_ERROR((AE_INFO,
			    "Index out of range: %X Obj=%p State=%p Num=%X",
			    index, object, walk_state,
			    state->results.num_results));
R
Robert Moore 已提交
899 900 901 902
		return (AE_BAD_PARAMETER);
	}

	if (!object) {
B
Bob Moore 已提交
903 904 905 906
		ACPI_ERROR((AE_INFO,
			    "Null Object! Index=%X Obj=%p State=%p Num=%X",
			    index, object, walk_state,
			    state->results.num_results));
R
Robert Moore 已提交
907 908 909
		return (AE_BAD_PARAMETER);
	}

L
Len Brown 已提交
910
	state->results.obj_desc[index] = object;
R
Robert Moore 已提交
911 912
	state->results.num_results++;

L
Len Brown 已提交
913 914 915 916 917 918 919 920 921
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
			  "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
			  object,
			  object ?
			  acpi_ut_get_object_type_name((union
							acpi_operand_object *)
						       object) : "NULL",
			  walk_state, state->results.num_results,
			  walk_state->current_result));
R
Robert Moore 已提交
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_obj_stack_delete_all
 *
 * PARAMETERS:  walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
 *              Should be used with great care, if at all!
 *
 ******************************************************************************/

L
Len Brown 已提交
939
acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state * walk_state)
R
Robert Moore 已提交
940
{
L
Len Brown 已提交
941
	u32 i;
R
Robert Moore 已提交
942

B
Bob Moore 已提交
943
	ACPI_FUNCTION_TRACE_PTR(ds_obj_stack_delete_all, walk_state);
R
Robert Moore 已提交
944 945 946 947 948

	/* The stack size is configurable, but fixed */

	for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
		if (walk_state->operands[i]) {
L
Len Brown 已提交
949
			acpi_ut_remove_reference(walk_state->operands[i]);
R
Robert Moore 已提交
950 951 952 953
			walk_state->operands[i] = NULL;
		}
	}

L
Len Brown 已提交
954
	return_ACPI_STATUS(AE_OK);
R
Robert Moore 已提交
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_obj_stack_pop_object
 *
 * PARAMETERS:  Object              - Where to return the popped object
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Pop this walk's object stack.  Objects on the stack are NOT
 *              deleted by this routine.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
972 973
acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
			     struct acpi_walk_state *walk_state)
R
Robert Moore 已提交
974
{
B
Bob Moore 已提交
975
	ACPI_FUNCTION_NAME(ds_obj_stack_pop_object);
R
Robert Moore 已提交
976 977 978 979

	/* Check for stack underflow */

	if (walk_state->num_operands == 0) {
B
Bob Moore 已提交
980 981 982
		ACPI_ERROR((AE_INFO,
			    "Missing operand/stack empty! State=%p #Ops=%X",
			    walk_state, walk_state->num_operands));
R
Robert Moore 已提交
983 984 985 986 987 988 989 990 991 992
		*object = NULL;
		return (AE_AML_NO_OPERAND);
	}

	/* Pop the stack */

	walk_state->num_operands--;

	/* Check for a valid operand */

L
Len Brown 已提交
993
	if (!walk_state->operands[walk_state->num_operands]) {
B
Bob Moore 已提交
994 995 996
		ACPI_ERROR((AE_INFO,
			    "Null operand! State=%p #Ops=%X",
			    walk_state, walk_state->num_operands));
R
Robert Moore 已提交
997 998 999 1000 1001 1002
		*object = NULL;
		return (AE_AML_NO_OPERAND);
	}

	/* Get operand and set stack entry to null */

L
Len Brown 已提交
1003 1004
	*object = walk_state->operands[walk_state->num_operands];
	walk_state->operands[walk_state->num_operands] = NULL;
R
Robert Moore 已提交
1005

L
Len Brown 已提交
1006 1007
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
			  *object, acpi_ut_get_object_type_name(*object),
R
Robert Moore 已提交
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
			  walk_state, walk_state->num_operands));

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_obj_stack_get_value
 *
 * PARAMETERS:  Index               - Stack index whose value is desired.  Based
 *                                    on the top of the stack (index=0 == top)
 *              walk_state          - Current Walk state
 *
 * RETURN:      Pointer to the requested operand
 *
 * DESCRIPTION: Retrieve an object from this walk's operand stack.  Index must
 *              be within the range of the current stack pointer.
 *
 ******************************************************************************/

L
Len Brown 已提交
1028
void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state)
R
Robert Moore 已提交
1029 1030
{

B
Bob Moore 已提交
1031
	ACPI_FUNCTION_TRACE_PTR(ds_obj_stack_get_value, walk_state);
R
Robert Moore 已提交
1032 1033 1034 1035

	/* Can't do it if the stack is empty */

	if (walk_state->num_operands == 0) {
L
Len Brown 已提交
1036
		return_PTR(NULL);
R
Robert Moore 已提交
1037 1038 1039 1040 1041
	}

	/* or if the index is past the top of the stack */

	if (index > (walk_state->num_operands - (u32) 1)) {
L
Len Brown 已提交
1042
		return_PTR(NULL);
R
Robert Moore 已提交
1043 1044
	}

L
Len Brown 已提交
1045 1046 1047
	return_PTR(walk_state->
		   operands[(acpi_native_uint) (walk_state->num_operands - 1) -
			    index]);
R
Robert Moore 已提交
1048 1049
}
#endif