]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/acpica/dswstate.c
Merge branches 'for-4.11/upstream-fixes', 'for-4.12/accutouch', 'for-4.12/cp2112...
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / dswstate.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: dswstate - Dispatcher parse tree walk management routines
4 *
5 *****************************************************************************/
6
7/*
7735ca0e 8 * Copyright (C) 2000 - 2017, Intel Corp.
1da177e4
LT
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acparser.h"
47#include "acdispat.h"
48#include "acnamesp.h"
1da177e4
LT
49
50#define _COMPONENT ACPI_DISPATCHER
4be44fcd 51ACPI_MODULE_NAME("dswstate")
1da177e4 52
773069d4 53 /* Local prototypes */
1f86e8c1
LZ
54static acpi_status
55acpi_ds_result_stack_push(struct acpi_walk_state *walk_state);
56static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state);
1da177e4 57
1da177e4
LT
58/*******************************************************************************
59 *
60 * FUNCTION: acpi_ds_result_pop
61 *
ba494bee 62 * PARAMETERS: object - Where to return the popped object
1da177e4
LT
63 * walk_state - Current Walk state
64 *
65 * RETURN: Status
66 *
773069d4 67 * DESCRIPTION: Pop an object off the top of this walk's result stack
1da177e4
LT
68 *
69 ******************************************************************************/
70
71acpi_status
773069d4
BM
72acpi_ds_result_pop(union acpi_operand_object **object,
73 struct acpi_walk_state *walk_state)
1da177e4 74{
67a119f9 75 u32 index;
4be44fcd 76 union acpi_generic_state *state;
773069d4 77 acpi_status status;
1da177e4 78
b229cf92 79 ACPI_FUNCTION_NAME(ds_result_pop);
1da177e4
LT
80
81 state = walk_state->results;
1da177e4 82
773069d4 83 /* Incorrect state of result stack */
1da177e4 84
773069d4
BM
85 if (state && !walk_state->result_count) {
86 ACPI_ERROR((AE_INFO, "No results on result stack"));
87 return (AE_AML_INTERNAL);
1da177e4
LT
88 }
89
773069d4
BM
90 if (!state && walk_state->result_count) {
91 ACPI_ERROR((AE_INFO, "No result state for result stack"));
92 return (AE_AML_INTERNAL);
93 }
1da177e4 94
773069d4 95 /* Empty result stack */
1da177e4 96
1da177e4 97 if (!state) {
773069d4 98 ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
b8e4d893 99 walk_state));
1da177e4
LT
100 return (AE_AML_NO_RETURN_VALUE);
101 }
102
773069d4 103 /* Return object of the top element and clean that top element result stack */
1da177e4 104
773069d4 105 walk_state->result_count--;
ba9c3f55 106 index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
1da177e4 107
773069d4 108 *object = state->results.obj_desc[index];
1da177e4 109 if (!*object) {
b8e4d893 110 ACPI_ERROR((AE_INFO,
773069d4
BM
111 "No result objects on result stack, State=%p",
112 walk_state));
1da177e4
LT
113 return (AE_AML_NO_RETURN_VALUE);
114 }
115
773069d4
BM
116 state->results.obj_desc[index] = NULL;
117 if (index == 0) {
118 status = acpi_ds_result_stack_pop(walk_state);
119 if (ACPI_FAILURE(status)) {
120 return (status);
121 }
122 }
123
124 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
125 "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object,
126 acpi_ut_get_object_type_name(*object),
67a119f9 127 index, walk_state, walk_state->result_count));
1da177e4
LT
128
129 return (AE_OK);
130}
131
1da177e4
LT
132/*******************************************************************************
133 *
134 * FUNCTION: acpi_ds_result_push
135 *
ba494bee 136 * PARAMETERS: object - Where to return the popped object
1da177e4
LT
137 * walk_state - Current Walk state
138 *
139 * RETURN: Status
140 *
141 * DESCRIPTION: Push an object onto the current result stack
142 *
143 ******************************************************************************/
144
145acpi_status
f5c1e1c5
LZ
146acpi_ds_result_push(union acpi_operand_object *object,
147 struct acpi_walk_state *walk_state)
1da177e4 148{
4be44fcd 149 union acpi_generic_state *state;
773069d4 150 acpi_status status;
67a119f9 151 u32 index;
1da177e4 152
b229cf92 153 ACPI_FUNCTION_NAME(ds_result_push);
1da177e4 154
773069d4
BM
155 if (walk_state->result_count > walk_state->result_size) {
156 ACPI_ERROR((AE_INFO, "Result stack is full"));
157 return (AE_AML_INTERNAL);
158 } else if (walk_state->result_count == walk_state->result_size) {
159
160 /* Extend the result stack */
161
162 status = acpi_ds_result_stack_push(walk_state);
163 if (ACPI_FAILURE(status)) {
164 ACPI_ERROR((AE_INFO,
165 "Failed to extend the result stack"));
166 return (status);
167 }
168 }
169
170 if (!(walk_state->result_count < walk_state->result_size)) {
171 ACPI_ERROR((AE_INFO, "No free elements in result stack"));
172 return (AE_AML_INTERNAL);
173 }
174
1da177e4
LT
175 state = walk_state->results;
176 if (!state) {
b8e4d893 177 ACPI_ERROR((AE_INFO, "No result stack frame during push"));
1da177e4
LT
178 return (AE_AML_INTERNAL);
179 }
180
1da177e4 181 if (!object) {
b8e4d893 182 ACPI_ERROR((AE_INFO,
f6a22b0b 183 "Null Object! Obj=%p State=%p Num=%u",
773069d4 184 object, walk_state, walk_state->result_count));
1da177e4
LT
185 return (AE_BAD_PARAMETER);
186 }
187
773069d4
BM
188 /* Assign the address of object to the top free element of result stack */
189
ba9c3f55 190 index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
773069d4
BM
191 state->results.obj_desc[index] = object;
192 walk_state->result_count++;
1da177e4 193
4be44fcd
LB
194 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
195 object,
4be44fcd
LB
196 acpi_ut_get_object_type_name((union
197 acpi_operand_object *)
773069d4
BM
198 object), walk_state,
199 walk_state->result_count,
4be44fcd 200 walk_state->current_result));
1da177e4
LT
201
202 return (AE_OK);
203}
204
1da177e4
LT
205/*******************************************************************************
206 *
207 * FUNCTION: acpi_ds_result_stack_push
208 *
209 * PARAMETERS: walk_state - Current Walk state
210 *
211 * RETURN: Status
212 *
773069d4 213 * DESCRIPTION: Push an object onto the walk_state result stack
1da177e4
LT
214 *
215 ******************************************************************************/
216
773069d4 217static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state)
1da177e4 218{
4be44fcd 219 union acpi_generic_state *state;
1da177e4 220
b229cf92 221 ACPI_FUNCTION_NAME(ds_result_stack_push);
1da177e4 222
773069d4
BM
223 /* Check for stack overflow */
224
b7f9f042 225 if (((u32) walk_state->result_size + ACPI_RESULTS_FRAME_OBJ_NUM) >
773069d4 226 ACPI_RESULTS_OBJ_NUM_MAX) {
f6a22b0b 227 ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%u",
773069d4
BM
228 walk_state, walk_state->result_size));
229 return (AE_STACK_OVERFLOW);
230 }
231
4be44fcd 232 state = acpi_ut_create_generic_state();
1da177e4
LT
233 if (!state) {
234 return (AE_NO_MEMORY);
235 }
236
61686124 237 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT;
4be44fcd 238 acpi_ut_push_generic_state(&walk_state->results, state);
1da177e4 239
773069d4
BM
240 /* Increase the length of the result stack by the length of frame */
241
242 walk_state->result_size += ACPI_RESULTS_FRAME_OBJ_NUM;
243
4be44fcd
LB
244 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
245 state, walk_state));
1da177e4
LT
246
247 return (AE_OK);
248}
249
1da177e4
LT
250/*******************************************************************************
251 *
252 * FUNCTION: acpi_ds_result_stack_pop
253 *
254 * PARAMETERS: walk_state - Current Walk state
255 *
256 * RETURN: Status
257 *
773069d4 258 * DESCRIPTION: Pop an object off of the walk_state result stack
1da177e4
LT
259 *
260 ******************************************************************************/
261
773069d4 262static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state)
1da177e4 263{
4be44fcd 264 union acpi_generic_state *state;
1da177e4 265
b229cf92 266 ACPI_FUNCTION_NAME(ds_result_stack_pop);
1da177e4
LT
267
268 /* Check for stack underflow */
269
270 if (walk_state->results == NULL) {
773069d4
BM
271 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
272 "Result stack underflow - State=%p\n",
4be44fcd 273 walk_state));
1da177e4
LT
274 return (AE_AML_NO_OPERAND);
275 }
276
773069d4
BM
277 if (walk_state->result_size < ACPI_RESULTS_FRAME_OBJ_NUM) {
278 ACPI_ERROR((AE_INFO, "Insufficient result stack size"));
279 return (AE_AML_INTERNAL);
280 }
281
4be44fcd 282 state = acpi_ut_pop_generic_state(&walk_state->results);
773069d4
BM
283 acpi_ut_delete_generic_state(state);
284
285 /* Decrease the length of result stack by the length of frame */
286
287 walk_state->result_size -= ACPI_RESULTS_FRAME_OBJ_NUM;
1da177e4 288
4be44fcd 289 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
b229cf92 290 "Result=%p RemainingResults=%X State=%p\n",
773069d4 291 state, walk_state->result_count, walk_state));
1da177e4
LT
292
293 return (AE_OK);
294}
295
1da177e4
LT
296/*******************************************************************************
297 *
298 * FUNCTION: acpi_ds_obj_stack_push
299 *
ba494bee 300 * PARAMETERS: object - Object to push
1da177e4
LT
301 * walk_state - Current Walk state
302 *
303 * RETURN: Status
304 *
305 * DESCRIPTION: Push an object onto this walk's object/operand stack
306 *
307 ******************************************************************************/
308
309acpi_status
f5c1e1c5 310acpi_ds_obj_stack_push(void *object, struct acpi_walk_state *walk_state)
1da177e4 311{
b229cf92 312 ACPI_FUNCTION_NAME(ds_obj_stack_push);
1da177e4
LT
313
314 /* Check for stack overflow */
315
316 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
b8e4d893 317 ACPI_ERROR((AE_INFO,
f6a22b0b 318 "Object stack overflow! Obj=%p State=%p #Ops=%u",
b8e4d893 319 object, walk_state, walk_state->num_operands));
1da177e4
LT
320 return (AE_STACK_OVERFLOW);
321 }
322
323 /* Put the object onto the stack */
324
773069d4 325 walk_state->operands[walk_state->operand_index] = object;
1da177e4
LT
326 walk_state->num_operands++;
327
773069d4
BM
328 /* For the usual order of filling the operand stack */
329
330 walk_state->operand_index++;
331
4be44fcd
LB
332 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
333 object,
334 acpi_ut_get_object_type_name((union
335 acpi_operand_object *)
336 object), walk_state,
337 walk_state->num_operands));
1da177e4
LT
338
339 return (AE_OK);
340}
341
1da177e4
LT
342/*******************************************************************************
343 *
344 * FUNCTION: acpi_ds_obj_stack_pop
345 *
346 * PARAMETERS: pop_count - Number of objects/entries to pop
347 * walk_state - Current Walk state
348 *
349 * RETURN: Status
350 *
73a3090a 351 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
1da177e4
LT
352 * deleted by this routine.
353 *
354 ******************************************************************************/
355
356acpi_status
f5c1e1c5 357acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state *walk_state)
1da177e4 358{
4be44fcd 359 u32 i;
1da177e4 360
b229cf92 361 ACPI_FUNCTION_NAME(ds_obj_stack_pop);
1da177e4
LT
362
363 for (i = 0; i < pop_count; i++) {
52fc0b02 364
1da177e4
LT
365 /* Check for stack underflow */
366
367 if (walk_state->num_operands == 0) {
b8e4d893 368 ACPI_ERROR((AE_INFO,
f6a22b0b 369 "Object stack underflow! Count=%X State=%p #Ops=%u",
b8e4d893
BM
370 pop_count, walk_state,
371 walk_state->num_operands));
1da177e4
LT
372 return (AE_STACK_UNDERFLOW);
373 }
374
375 /* Just set the stack entry to null */
376
377 walk_state->num_operands--;
4be44fcd 378 walk_state->operands[walk_state->num_operands] = NULL;
1da177e4
LT
379 }
380
f6a22b0b 381 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
1da177e4
LT
382 pop_count, walk_state, walk_state->num_operands));
383
384 return (AE_OK);
385}
386
1da177e4
LT
387/*******************************************************************************
388 *
389 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
390 *
391 * PARAMETERS: pop_count - Number of objects/entries to pop
392 * walk_state - Current Walk state
393 *
394 * RETURN: Status
395 *
396 * DESCRIPTION: Pop this walk's object stack and delete each object that is
397 * popped off.
398 *
399 ******************************************************************************/
400
773069d4 401void
4be44fcd 402acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
773069d4 403 struct acpi_walk_state *walk_state)
1da177e4 404{
67a119f9 405 s32 i;
4be44fcd 406 union acpi_operand_object *obj_desc;
1da177e4 407
b229cf92 408 ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete);
1da177e4 409
773069d4
BM
410 if (pop_count == 0) {
411 return;
412 }
1da177e4 413
f5c1e1c5 414 for (i = (s32)pop_count - 1; i >= 0; i--) {
1da177e4 415 if (walk_state->num_operands == 0) {
773069d4 416 return;
1da177e4
LT
417 }
418
419 /* Pop the stack and delete an object if present in this stack entry */
420
421 walk_state->num_operands--;
773069d4 422 obj_desc = walk_state->operands[i];
1da177e4 423 if (obj_desc) {
773069d4
BM
424 acpi_ut_remove_reference(walk_state->operands[i]);
425 walk_state->operands[i] = NULL;
1da177e4
LT
426 }
427 }
428
4be44fcd 429 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
1da177e4 430 pop_count, walk_state, walk_state->num_operands));
1da177e4
LT
431}
432
1da177e4
LT
433/*******************************************************************************
434 *
435 * FUNCTION: acpi_ds_get_current_walk_state
436 *
ba494bee 437 * PARAMETERS: thread - Get current active state for this Thread
1da177e4
LT
438 *
439 * RETURN: Pointer to the current walk state
440 *
441 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
442 * walk state.)
443 *
444 ******************************************************************************/
445
4be44fcd
LB
446struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
447 *thread)
1da177e4 448{
b229cf92 449 ACPI_FUNCTION_NAME(ds_get_current_walk_state);
1da177e4
LT
450
451 if (!thread) {
452 return (NULL);
453 }
454
b229cf92 455 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current WalkState %p\n",
4be44fcd 456 thread->walk_state_list));
1da177e4
LT
457
458 return (thread->walk_state_list);
459}
460
1da177e4
LT
461/*******************************************************************************
462 *
463 * FUNCTION: acpi_ds_push_walk_state
464 *
465 * PARAMETERS: walk_state - State to push
ba494bee 466 * thread - Thread state object
1da177e4
LT
467 *
468 * RETURN: None
469 *
773069d4 470 * DESCRIPTION: Place the Thread state at the head of the state list
1da177e4
LT
471 *
472 ******************************************************************************/
473
474void
4be44fcd
LB
475acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
476 struct acpi_thread_state *thread)
1da177e4 477{
b229cf92 478 ACPI_FUNCTION_TRACE(ds_push_walk_state);
1da177e4 479
4be44fcd 480 walk_state->next = thread->walk_state_list;
1da177e4
LT
481 thread->walk_state_list = walk_state;
482
483 return_VOID;
484}
485
1da177e4
LT
486/*******************************************************************************
487 *
488 * FUNCTION: acpi_ds_pop_walk_state
489 *
ba494bee 490 * PARAMETERS: thread - Current thread state
1da177e4 491 *
44f6c012 492 * RETURN: A walk_state object popped from the thread's stack
1da177e4
LT
493 *
494 * DESCRIPTION: Remove and return the walkstate object that is at the head of
73a3090a 495 * the walk stack for the given walk list. NULL indicates that
1da177e4
LT
496 * the list is empty.
497 *
498 ******************************************************************************/
499
4be44fcd 500struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
1da177e4 501{
4be44fcd 502 struct acpi_walk_state *walk_state;
1da177e4 503
b229cf92 504 ACPI_FUNCTION_TRACE(ds_pop_walk_state);
1da177e4
LT
505
506 walk_state = thread->walk_state_list;
507
508 if (walk_state) {
52fc0b02 509
1da177e4
LT
510 /* Next walk state becomes the current walk state */
511
512 thread->walk_state_list = walk_state->next;
513
514 /*
515 * Don't clear the NEXT field, this serves as an indicator
516 * that there is a parent WALK STATE
44f6c012 517 * Do Not: walk_state->Next = NULL;
1da177e4
LT
518 */
519 }
520
4be44fcd 521 return_PTR(walk_state);
1da177e4
LT
522}
523
1da177e4
LT
524/*******************************************************************************
525 *
526 * FUNCTION: acpi_ds_create_walk_state
527 *
44f6c012 528 * PARAMETERS: owner_id - ID for object creation
ba494bee 529 * origin - Starting point for this walk
61686124 530 * method_desc - Method object
ba494bee 531 * thread - Current thread state
1da177e4
LT
532 *
533 * RETURN: Pointer to the new walk state.
534 *
73a3090a 535 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
1da177e4
LT
536 * state is set to this new state.
537 *
538 ******************************************************************************/
539
1f86e8c1
LZ
540struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
541 union acpi_parse_object
542 *origin,
543 union acpi_operand_object
544 *method_desc,
545 struct acpi_thread_state
4be44fcd 546 *thread)
1da177e4 547{
4be44fcd 548 struct acpi_walk_state *walk_state;
1da177e4 549
b229cf92 550 ACPI_FUNCTION_TRACE(ds_create_walk_state);
1da177e4 551
8313524a 552 walk_state = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_walk_state));
1da177e4 553 if (!walk_state) {
4be44fcd 554 return_PTR(NULL);
1da177e4
LT
555 }
556
61686124
BM
557 walk_state->descriptor_type = ACPI_DESC_TYPE_WALK;
558 walk_state->method_desc = method_desc;
4be44fcd
LB
559 walk_state->owner_id = owner_id;
560 walk_state->origin = origin;
4be44fcd 561 walk_state->thread = thread;
1da177e4
LT
562
563 walk_state->parser_state.start_op = origin;
564
565 /* Init the method args/local */
566
567#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
4be44fcd 568 acpi_ds_method_data_init(walk_state);
1da177e4
LT
569#endif
570
1da177e4
LT
571 /* Put the new state at the head of the walk list */
572
573 if (thread) {
4be44fcd 574 acpi_ds_push_walk_state(walk_state, thread);
1da177e4
LT
575 }
576
4be44fcd 577 return_PTR(walk_state);
1da177e4
LT
578}
579
1da177e4
LT
580/*******************************************************************************
581 *
582 * FUNCTION: acpi_ds_init_aml_walk
583 *
584 * PARAMETERS: walk_state - New state to be initialized
ba494bee 585 * op - Current parse op
1da177e4
LT
586 * method_node - Control method NS node, if any
587 * aml_start - Start of AML
588 * aml_length - Length of AML
ba494bee 589 * info - Method info block (params, etc.)
1da177e4
LT
590 * pass_number - 1, 2, or 3
591 *
592 * RETURN: Status
593 *
594 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
595 *
596 ******************************************************************************/
597
598acpi_status
4be44fcd
LB
599acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
600 union acpi_parse_object *op,
601 struct acpi_namespace_node *method_node,
602 u8 * aml_start,
603 u32 aml_length,
4119532c 604 struct acpi_evaluate_info *info, u8 pass_number)
1da177e4 605{
4be44fcd
LB
606 acpi_status status;
607 struct acpi_parse_state *parser_state = &walk_state->parser_state;
608 union acpi_parse_object *extra_op;
1da177e4 609
b229cf92 610 ACPI_FUNCTION_TRACE(ds_init_aml_walk);
1da177e4 611
4be44fcd
LB
612 walk_state->parser_state.aml =
613 walk_state->parser_state.aml_start = aml_start;
1da177e4 614 walk_state->parser_state.aml_end =
4be44fcd 615 walk_state->parser_state.pkg_end = aml_start + aml_length;
1da177e4
LT
616
617 /* The next_op of the next_walk will be the beginning of the method */
618
44f6c012 619 walk_state->next_op = NULL;
0c9938cc 620 walk_state->pass_number = pass_number;
1da177e4
LT
621
622 if (info) {
c91d924e
BM
623 walk_state->params = info->parameters;
624 walk_state->caller_return_desc = &info->return_object;
1da177e4
LT
625 }
626
4be44fcd
LB
627 status = acpi_ps_init_scope(&walk_state->parser_state, op);
628 if (ACPI_FAILURE(status)) {
629 return_ACPI_STATUS(status);
1da177e4
LT
630 }
631
632 if (method_node) {
633 walk_state->parser_state.start_node = method_node;
4be44fcd
LB
634 walk_state->walk_type = ACPI_WALK_METHOD;
635 walk_state->method_node = method_node;
636 walk_state->method_desc =
637 acpi_ns_get_attached_object(method_node);
1da177e4
LT
638
639 /* Push start scope on scope stack and make it current */
640
4be44fcd
LB
641 status =
642 acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
643 walk_state);
644 if (ACPI_FAILURE(status)) {
645 return_ACPI_STATUS(status);
1da177e4
LT
646 }
647
648 /* Init the method arguments */
649
4be44fcd
LB
650 status = acpi_ds_method_data_init_args(walk_state->params,
651 ACPI_METHOD_NUM_ARGS,
652 walk_state);
653 if (ACPI_FAILURE(status)) {
654 return_ACPI_STATUS(status);
1da177e4 655 }
4be44fcd 656 } else {
1da177e4
LT
657 /*
658 * Setup the current scope.
659 * Find a Named Op that has a namespace node associated with it.
73a3090a 660 * search upwards from this Op. Current scope is the first
1da177e4
LT
661 * Op with a namespace node.
662 */
663 extra_op = parser_state->start_op;
664 while (extra_op && !extra_op->common.node) {
665 extra_op = extra_op->common.parent;
666 }
667
668 if (!extra_op) {
669 parser_state->start_node = NULL;
4be44fcd 670 } else {
1da177e4
LT
671 parser_state->start_node = extra_op->common.node;
672 }
673
674 if (parser_state->start_node) {
52fc0b02 675
1da177e4
LT
676 /* Push start scope on scope stack and make it current */
677
4be44fcd
LB
678 status =
679 acpi_ds_scope_stack_push(parser_state->start_node,
680 parser_state->start_node->
681 type, walk_state);
682 if (ACPI_FAILURE(status)) {
683 return_ACPI_STATUS(status);
1da177e4
LT
684 }
685 }
686 }
687
4be44fcd
LB
688 status = acpi_ds_init_callbacks(walk_state, pass_number);
689 return_ACPI_STATUS(status);
1da177e4
LT
690}
691
1da177e4
LT
692/*******************************************************************************
693 *
694 * FUNCTION: acpi_ds_delete_walk_state
695 *
696 * PARAMETERS: walk_state - State to delete
697 *
698 * RETURN: Status
699 *
700 * DESCRIPTION: Delete a walk state including all internal data structures
701 *
702 ******************************************************************************/
703
4be44fcd 704void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
1da177e4 705{
4be44fcd 706 union acpi_generic_state *state;
1da177e4 707
b229cf92 708 ACPI_FUNCTION_TRACE_PTR(ds_delete_walk_state, walk_state);
1da177e4
LT
709
710 if (!walk_state) {
68aafc35 711 return_VOID;
1da177e4
LT
712 }
713
61686124 714 if (walk_state->descriptor_type != ACPI_DESC_TYPE_WALK) {
b8e4d893
BM
715 ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
716 walk_state));
68aafc35 717 return_VOID;
1da177e4
LT
718 }
719
4119532c
BM
720 /* There should not be any open scopes */
721
1da177e4 722 if (walk_state->parser_state.scope) {
b8e4d893
BM
723 ACPI_ERROR((AE_INFO, "%p walk still has a scope list",
724 walk_state));
4119532c 725 acpi_ps_cleanup_scope(&walk_state->parser_state);
1da177e4
LT
726 }
727
728 /* Always must free any linked control states */
729
730 while (walk_state->control_state) {
731 state = walk_state->control_state;
732 walk_state->control_state = state->common.next;
733
4be44fcd 734 acpi_ut_delete_generic_state(state);
1da177e4
LT
735 }
736
737 /* Always must free any linked parse states */
738
739 while (walk_state->scope_info) {
740 state = walk_state->scope_info;
741 walk_state->scope_info = state->common.next;
742
4be44fcd 743 acpi_ut_delete_generic_state(state);
1da177e4
LT
744 }
745
746 /* Always must free any stacked result states */
747
748 while (walk_state->results) {
749 state = walk_state->results;
750 walk_state->results = state->common.next;
751
4be44fcd 752 acpi_ut_delete_generic_state(state);
1da177e4
LT
753 }
754
8313524a 755 ACPI_FREE(walk_state);
1da177e4
LT
756 return_VOID;
757}