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

/*
L
Len Brown 已提交
8
 * Copyright (C) 2000 - 2008, Intel Corp.
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

52 53 54
  /* Local prototypes */
static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *ws);
static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *ws);
L
Linus Torvalds 已提交
55 56 57 58 59 60 61 62 63 64

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_pop
 *
 * PARAMETERS:  Object              - Where to return the popped object
 *              walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
65
 * DESCRIPTION: Pop an object off the top of this walk's result stack
L
Linus Torvalds 已提交
66 67 68 69
 *
 ******************************************************************************/

acpi_status
70 71
acpi_ds_result_pop(union acpi_operand_object **object,
		   struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
72
{
73
	u32 index;
L
Len Brown 已提交
74
	union acpi_generic_state *state;
75
	acpi_status status;
L
Linus Torvalds 已提交
76

B
Bob Moore 已提交
77
	ACPI_FUNCTION_NAME(ds_result_pop);
L
Linus Torvalds 已提交
78 79 80

	state = walk_state->results;

81
	/* Incorrect state of result stack */
L
Linus Torvalds 已提交
82

83 84 85
	if (state && !walk_state->result_count) {
		ACPI_ERROR((AE_INFO, "No results on result stack"));
		return (AE_AML_INTERNAL);
L
Linus Torvalds 已提交
86 87
	}

88 89 90 91
	if (!state && walk_state->result_count) {
		ACPI_ERROR((AE_INFO, "No result state for result stack"));
		return (AE_AML_INTERNAL);
	}
L
Linus Torvalds 已提交
92

93
	/* Empty result stack */
L
Linus Torvalds 已提交
94 95

	if (!state) {
96
		ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
B
Bob Moore 已提交
97
			    walk_state));
L
Linus Torvalds 已提交
98 99 100
		return (AE_AML_NO_RETURN_VALUE);
	}

101
	/* Return object of the top element and clean that top element result stack */
L
Linus Torvalds 已提交
102

103 104
	walk_state->result_count--;
	index = walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
L
Linus Torvalds 已提交
105

106
	*object = state->results.obj_desc[index];
L
Linus Torvalds 已提交
107
	if (!*object) {
B
Bob Moore 已提交
108
		ACPI_ERROR((AE_INFO,
109 110
			    "No result objects on result stack, State=%p",
			    walk_state));
L
Linus Torvalds 已提交
111 112 113
		return (AE_AML_NO_RETURN_VALUE);
	}

114 115 116 117 118 119 120 121 122 123 124
	state->results.obj_desc[index] = NULL;
	if (index == 0) {
		status = acpi_ds_result_stack_pop(walk_state);
		if (ACPI_FAILURE(status)) {
			return (status);
		}
	}

	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
			  "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object,
			  acpi_ut_get_object_type_name(*object),
125
			  index, walk_state, walk_state->result_count));
L
Linus Torvalds 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

	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 已提交
144 145
acpi_ds_result_push(union acpi_operand_object * object,
		    struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
146
{
L
Len Brown 已提交
147
	union acpi_generic_state *state;
148
	acpi_status status;
149
	u32 index;
L
Linus Torvalds 已提交
150

B
Bob Moore 已提交
151
	ACPI_FUNCTION_NAME(ds_result_push);
L
Linus Torvalds 已提交
152

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
	if (walk_state->result_count > walk_state->result_size) {
		ACPI_ERROR((AE_INFO, "Result stack is full"));
		return (AE_AML_INTERNAL);
	} else if (walk_state->result_count == walk_state->result_size) {

		/* Extend the result stack */

		status = acpi_ds_result_stack_push(walk_state);
		if (ACPI_FAILURE(status)) {
			ACPI_ERROR((AE_INFO,
				    "Failed to extend the result stack"));
			return (status);
		}
	}

	if (!(walk_state->result_count < walk_state->result_size)) {
		ACPI_ERROR((AE_INFO, "No free elements in result stack"));
		return (AE_AML_INTERNAL);
	}

L
Linus Torvalds 已提交
173 174
	state = walk_state->results;
	if (!state) {
B
Bob Moore 已提交
175
		ACPI_ERROR((AE_INFO, "No result stack frame during push"));
L
Linus Torvalds 已提交
176 177 178 179
		return (AE_AML_INTERNAL);
	}

	if (!object) {
B
Bob Moore 已提交
180 181
		ACPI_ERROR((AE_INFO,
			    "Null Object! Obj=%p State=%p Num=%X",
182
			    object, walk_state, walk_state->result_count));
L
Linus Torvalds 已提交
183 184 185
		return (AE_BAD_PARAMETER);
	}

186 187 188 189 190
	/* Assign the address of object to the top free element of result stack */

	index = walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
	state->results.obj_desc[index] = object;
	walk_state->result_count++;
L
Linus Torvalds 已提交
191

L
Len Brown 已提交
192 193 194 195
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
			  object,
			  acpi_ut_get_object_type_name((union
							acpi_operand_object *)
196 197
						       object), walk_state,
			  walk_state->result_count,
L
Len Brown 已提交
198
			  walk_state->current_result));
L
Linus Torvalds 已提交
199 200 201 202 203 204 205 206 207 208 209 210

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_stack_push
 *
 * PARAMETERS:  walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
211
 * DESCRIPTION: Push an object onto the walk_state result stack
L
Linus Torvalds 已提交
212 213 214
 *
 ******************************************************************************/

215
static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
216
{
L
Len Brown 已提交
217
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
218

B
Bob Moore 已提交
219
	ACPI_FUNCTION_NAME(ds_result_stack_push);
L
Linus Torvalds 已提交
220

221 222
	/* Check for stack overflow */

223
	if (((u32) walk_state->result_size + ACPI_RESULTS_FRAME_OBJ_NUM) >
224 225 226 227 228 229
	    ACPI_RESULTS_OBJ_NUM_MAX) {
		ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%X",
			    walk_state, walk_state->result_size));
		return (AE_STACK_OVERFLOW);
	}

L
Len Brown 已提交
230
	state = acpi_ut_create_generic_state();
L
Linus Torvalds 已提交
231 232 233 234
	if (!state) {
		return (AE_NO_MEMORY);
	}

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

238 239 240 241
	/* Increase the length of the result stack by the length of frame */

	walk_state->result_size += ACPI_RESULTS_FRAME_OBJ_NUM;

L
Len Brown 已提交
242 243
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
			  state, walk_state));
L
Linus Torvalds 已提交
244 245 246 247 248 249 250 251 252 253 254 255

	return (AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_result_stack_pop
 *
 * PARAMETERS:  walk_state          - Current Walk state
 *
 * RETURN:      Status
 *
256
 * DESCRIPTION: Pop an object off of the walk_state result stack
L
Linus Torvalds 已提交
257 258 259
 *
 ******************************************************************************/

260
static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
261
{
L
Len Brown 已提交
262
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
263

B
Bob Moore 已提交
264
	ACPI_FUNCTION_NAME(ds_result_stack_pop);
L
Linus Torvalds 已提交
265 266 267 268

	/* Check for stack underflow */

	if (walk_state->results == NULL) {
269 270
		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
				  "Result stack underflow - State=%p\n",
L
Len Brown 已提交
271
				  walk_state));
L
Linus Torvalds 已提交
272 273 274
		return (AE_AML_NO_OPERAND);
	}

275 276 277 278 279
	if (walk_state->result_size < ACPI_RESULTS_FRAME_OBJ_NUM) {
		ACPI_ERROR((AE_INFO, "Insufficient result stack size"));
		return (AE_AML_INTERNAL);
	}

L
Len Brown 已提交
280
	state = acpi_ut_pop_generic_state(&walk_state->results);
281 282 283 284 285
	acpi_ut_delete_generic_state(state);

	/* Decrease the length of result stack by the length of frame */

	walk_state->result_size -= ACPI_RESULTS_FRAME_OBJ_NUM;
L
Linus Torvalds 已提交
286

L
Len Brown 已提交
287
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
B
Bob Moore 已提交
288
			  "Result=%p RemainingResults=%X State=%p\n",
289
			  state, walk_state->result_count, walk_state));
L
Linus Torvalds 已提交
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307

	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 已提交
308
acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
309
{
B
Bob Moore 已提交
310
	ACPI_FUNCTION_NAME(ds_obj_stack_push);
L
Linus Torvalds 已提交
311 312 313 314

	/* Check for stack overflow */

	if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
B
Bob Moore 已提交
315 316 317
		ACPI_ERROR((AE_INFO,
			    "Object stack overflow! Obj=%p State=%p #Ops=%X",
			    object, walk_state, walk_state->num_operands));
L
Linus Torvalds 已提交
318 319 320 321 322
		return (AE_STACK_OVERFLOW);
	}

	/* Put the object onto the stack */

323
	walk_state->operands[walk_state->operand_index] = object;
L
Linus Torvalds 已提交
324 325
	walk_state->num_operands++;

326 327 328 329
	/* For the usual order of filling the operand stack */

	walk_state->operand_index++;

L
Len Brown 已提交
330 331 332 333 334 335
	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 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354

	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 已提交
355
acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
L
Linus Torvalds 已提交
356
{
L
Len Brown 已提交
357
	u32 i;
L
Linus Torvalds 已提交
358

B
Bob Moore 已提交
359
	ACPI_FUNCTION_NAME(ds_obj_stack_pop);
L
Linus Torvalds 已提交
360 361

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

L
Linus Torvalds 已提交
363 364 365
		/* Check for stack underflow */

		if (walk_state->num_operands == 0) {
B
Bob Moore 已提交
366 367 368 369
			ACPI_ERROR((AE_INFO,
				    "Object stack underflow! Count=%X State=%p #Ops=%X",
				    pop_count, walk_state,
				    walk_state->num_operands));
L
Linus Torvalds 已提交
370 371 372 373 374 375
			return (AE_STACK_UNDERFLOW);
		}

		/* Just set the stack entry to null */

		walk_state->num_operands--;
L
Len Brown 已提交
376
		walk_state->operands[walk_state->num_operands] = NULL;
L
Linus Torvalds 已提交
377 378
	}

L
Len Brown 已提交
379
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
L
Linus Torvalds 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
			  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.
 *
 ******************************************************************************/

399
void
L
Len Brown 已提交
400
acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
401
				 struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
402
{
403
	s32 i;
L
Len Brown 已提交
404
	union acpi_operand_object *obj_desc;
L
Linus Torvalds 已提交
405

B
Bob Moore 已提交
406
	ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete);
L
Linus Torvalds 已提交
407

408 409 410
	if (pop_count == 0) {
		return;
	}
L
Linus Torvalds 已提交
411

412
	for (i = (s32) pop_count - 1; i >= 0; i--) {
L
Linus Torvalds 已提交
413
		if (walk_state->num_operands == 0) {
414
			return;
L
Linus Torvalds 已提交
415 416 417 418 419
		}

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

		walk_state->num_operands--;
420
		obj_desc = walk_state->operands[i];
L
Linus Torvalds 已提交
421
		if (obj_desc) {
422 423
			acpi_ut_remove_reference(walk_state->operands[i]);
			walk_state->operands[i] = NULL;
L
Linus Torvalds 已提交
424 425 426
		}
	}

L
Len Brown 已提交
427
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
L
Linus Torvalds 已提交
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
			  pop_count, walk_state, walk_state->num_operands));
}

/*******************************************************************************
 *
 * 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 已提交
444 445
struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
						       *thread)
L
Linus Torvalds 已提交
446
{
B
Bob Moore 已提交
447
	ACPI_FUNCTION_NAME(ds_get_current_walk_state);
L
Linus Torvalds 已提交
448 449 450 451 452

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

B
Bob Moore 已提交
453
	ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current WalkState %p\n",
L
Len Brown 已提交
454
			  thread->walk_state_list));
L
Linus Torvalds 已提交
455 456 457 458 459 460 461 462 463

	return (thread->walk_state_list);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_push_walk_state
 *
 * PARAMETERS:  walk_state      - State to push
R
Robert Moore 已提交
464
 *              Thread          - Thread state object
L
Linus Torvalds 已提交
465 466 467
 *
 * RETURN:      None
 *
468
 * DESCRIPTION: Place the Thread state at the head of the state list
L
Linus Torvalds 已提交
469 470 471 472
 *
 ******************************************************************************/

void
L
Len Brown 已提交
473 474
acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
			struct acpi_thread_state *thread)
L
Linus Torvalds 已提交
475
{
B
Bob Moore 已提交
476
	ACPI_FUNCTION_TRACE(ds_push_walk_state);
L
Linus Torvalds 已提交
477

L
Len Brown 已提交
478
	walk_state->next = thread->walk_state_list;
L
Linus Torvalds 已提交
479 480 481 482 483 484 485 486 487
	thread->walk_state_list = walk_state;

	return_VOID;
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_pop_walk_state
 *
R
Robert Moore 已提交
488
 * PARAMETERS:  Thread      - Current thread state
L
Linus Torvalds 已提交
489
 *
R
Robert Moore 已提交
490
 * RETURN:      A walk_state object popped from the thread's stack
L
Linus Torvalds 已提交
491 492 493 494 495 496 497
 *
 * 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 已提交
498
struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
L
Linus Torvalds 已提交
499
{
L
Len Brown 已提交
500
	struct acpi_walk_state *walk_state;
L
Linus Torvalds 已提交
501

B
Bob Moore 已提交
502
	ACPI_FUNCTION_TRACE(ds_pop_walk_state);
L
Linus Torvalds 已提交
503 504 505 506

	walk_state = thread->walk_state_list;

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

L
Linus Torvalds 已提交
508 509 510 511 512 513 514
		/* 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 已提交
515
		 * Do Not: walk_state->Next = NULL;
L
Linus Torvalds 已提交
516 517 518
		 */
	}

L
Len Brown 已提交
519
	return_PTR(walk_state);
L
Linus Torvalds 已提交
520 521 522 523 524 525
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_create_walk_state
 *
R
Robert Moore 已提交
526 527
 * PARAMETERS:  owner_id        - ID for object creation
 *              Origin          - Starting point for this walk
B
Bob Moore 已提交
528
 *              method_desc     - Method object
L
Linus Torvalds 已提交
529 530 531 532 533 534 535 536 537
 *              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 已提交
538 539 540
struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id, union acpi_parse_object
						  *origin, union acpi_operand_object
						  *method_desc, struct acpi_thread_state
L
Len Brown 已提交
541
						  *thread)
L
Linus Torvalds 已提交
542
{
L
Len Brown 已提交
543
	struct acpi_walk_state *walk_state;
L
Linus Torvalds 已提交
544

B
Bob Moore 已提交
545
	ACPI_FUNCTION_TRACE(ds_create_walk_state);
L
Linus Torvalds 已提交
546

B
Bob Moore 已提交
547
	walk_state = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_walk_state));
L
Linus Torvalds 已提交
548
	if (!walk_state) {
L
Len Brown 已提交
549
		return_PTR(NULL);
L
Linus Torvalds 已提交
550 551
	}

B
Bob Moore 已提交
552 553
	walk_state->descriptor_type = ACPI_DESC_TYPE_WALK;
	walk_state->method_desc = method_desc;
L
Len Brown 已提交
554 555 556
	walk_state->owner_id = owner_id;
	walk_state->origin = origin;
	walk_state->thread = thread;
L
Linus Torvalds 已提交
557 558 559 560 561 562

	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 已提交
563
	acpi_ds_method_data_init(walk_state);
L
Linus Torvalds 已提交
564 565 566 567 568
#endif

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

	if (thread) {
L
Len Brown 已提交
569
		acpi_ds_push_walk_state(walk_state, thread);
L
Linus Torvalds 已提交
570 571
	}

L
Len Brown 已提交
572
	return_PTR(walk_state);
L
Linus Torvalds 已提交
573 574 575 576 577 578 579 580 581 582 583
}

/*******************************************************************************
 *
 * 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 已提交
584
 *              Info            - Method info block (params, etc.)
L
Linus Torvalds 已提交
585 586 587 588 589 590 591 592 593
 *              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 已提交
594 595 596 597 598
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,
B
Bob Moore 已提交
599
		      struct acpi_evaluate_info *info, u8 pass_number)
L
Linus Torvalds 已提交
600
{
L
Len Brown 已提交
601 602 603
	acpi_status status;
	struct acpi_parse_state *parser_state = &walk_state->parser_state;
	union acpi_parse_object *extra_op;
L
Linus Torvalds 已提交
604

B
Bob Moore 已提交
605
	ACPI_FUNCTION_TRACE(ds_init_aml_walk);
L
Linus Torvalds 已提交
606

L
Len Brown 已提交
607 608
	walk_state->parser_state.aml =
	    walk_state->parser_state.aml_start = aml_start;
L
Linus Torvalds 已提交
609
	walk_state->parser_state.aml_end =
L
Len Brown 已提交
610
	    walk_state->parser_state.pkg_end = aml_start + aml_length;
L
Linus Torvalds 已提交
611 612 613

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

R
Robert Moore 已提交
614
	walk_state->next_op = NULL;
615
	walk_state->pass_number = pass_number;
L
Linus Torvalds 已提交
616 617

	if (info) {
618 619
		walk_state->params = info->parameters;
		walk_state->caller_return_desc = &info->return_object;
L
Linus Torvalds 已提交
620 621
	}

L
Len Brown 已提交
622 623 624
	status = acpi_ps_init_scope(&walk_state->parser_state, op);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
625 626 627 628
	}

	if (method_node) {
		walk_state->parser_state.start_node = method_node;
L
Len Brown 已提交
629 630 631 632
		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 已提交
633 634 635

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

L
Len Brown 已提交
636 637 638 639 640
		status =
		    acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
					     walk_state);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
641 642 643 644
		}

		/* Init the method arguments */

L
Len Brown 已提交
645 646 647 648 649
		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 已提交
650
		}
L
Len Brown 已提交
651
	} else {
L
Linus Torvalds 已提交
652 653 654 655 656 657 658 659 660 661 662 663 664
		/*
		 * 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 已提交
665
		} else {
L
Linus Torvalds 已提交
666 667 668 669
			parser_state->start_node = extra_op->common.node;
		}

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

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

L
Len Brown 已提交
673 674 675 676 677 678
			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 已提交
679 680 681 682
			}
		}
	}

L
Len Brown 已提交
683 684
	status = acpi_ds_init_callbacks(walk_state, pass_number);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
685 686 687 688 689 690 691 692 693 694 695 696 697 698
}

/*******************************************************************************
 *
 * 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 已提交
699
void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
700
{
L
Len Brown 已提交
701
	union acpi_generic_state *state;
L
Linus Torvalds 已提交
702

B
Bob Moore 已提交
703
	ACPI_FUNCTION_TRACE_PTR(ds_delete_walk_state, walk_state);
L
Linus Torvalds 已提交
704 705 706 707 708

	if (!walk_state) {
		return;
	}

B
Bob Moore 已提交
709
	if (walk_state->descriptor_type != ACPI_DESC_TYPE_WALK) {
B
Bob Moore 已提交
710 711
		ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
			    walk_state));
L
Linus Torvalds 已提交
712 713 714
		return;
	}

B
Bob Moore 已提交
715 716
	/* There should not be any open scopes */

L
Linus Torvalds 已提交
717
	if (walk_state->parser_state.scope) {
B
Bob Moore 已提交
718 719
		ACPI_ERROR((AE_INFO, "%p walk still has a scope list",
			    walk_state));
B
Bob Moore 已提交
720
		acpi_ps_cleanup_scope(&walk_state->parser_state);
L
Linus Torvalds 已提交
721 722 723 724 725 726 727 728
	}

	/* 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 已提交
729
		acpi_ut_delete_generic_state(state);
L
Linus Torvalds 已提交
730 731 732 733 734 735 736 737
	}

	/* 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 已提交
738
		acpi_ut_delete_generic_state(state);
L
Linus Torvalds 已提交
739 740 741 742 743 744 745 746
	}

	/* Always must free any stacked result states */

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

L
Len Brown 已提交
747
		acpi_ut_delete_generic_state(state);
L
Linus Torvalds 已提交
748 749
	}

B
Bob Moore 已提交
750
	ACPI_FREE(walk_state);
L
Linus Torvalds 已提交
751 752
	return_VOID;
}