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