Merge with rsync://fileserver/linux
[linux-2.6] / drivers / acpi / dispatcher / dswstate.c
1 /******************************************************************************
2  *
3  * Module Name: dswstate - Dispatcher parse tree walk management routines
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2005, R. Byron Moore
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
44
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acnamesp.h>
49
50 #define _COMPONENT          ACPI_DISPATCHER
51          ACPI_MODULE_NAME    ("dswstate")
52
53 /* Local prototypes */
54
55 #ifdef ACPI_OBSOLETE_FUNCTIONS
56 acpi_status
57 acpi_ds_result_insert (
58         void                            *object,
59         u32                             index,
60         struct acpi_walk_state          *walk_state);
61
62 acpi_status
63 acpi_ds_obj_stack_delete_all (
64         struct acpi_walk_state          *walk_state);
65
66 acpi_status
67 acpi_ds_obj_stack_pop_object (
68         union acpi_operand_object       **object,
69         struct acpi_walk_state          *walk_state);
70
71 void *
72 acpi_ds_obj_stack_get_value (
73         u32                             index,
74         struct acpi_walk_state          *walk_state);
75 #endif
76
77 #ifdef ACPI_FUTURE_USAGE
78
79 /*******************************************************************************
80  *
81  * FUNCTION:    acpi_ds_result_remove
82  *
83  * PARAMETERS:  Object              - Where to return the popped object
84  *              Index               - Where to extract the object
85  *              walk_state          - Current Walk state
86  *
87  * RETURN:      Status
88  *
89  * DESCRIPTION: Pop an object off the bottom of this walk's result stack.  In
90  *              other words, this is a FIFO.
91  *
92  ******************************************************************************/
93
94 acpi_status
95 acpi_ds_result_remove (
96         union acpi_operand_object       **object,
97         u32                             index,
98         struct acpi_walk_state          *walk_state)
99 {
100         union acpi_generic_state        *state;
101
102
103         ACPI_FUNCTION_NAME ("ds_result_remove");
104
105
106         state = walk_state->results;
107         if (!state) {
108                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
109                         walk_state));
110                 return (AE_NOT_EXIST);
111         }
112
113         if (index >= ACPI_OBJ_MAX_OPERAND) {
114                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
115                         "Index out of range: %X State=%p Num=%X\n",
116                         index, walk_state, state->results.num_results));
117         }
118
119         /* Check for a valid result object */
120
121         if (!state->results.obj_desc [index]) {
122                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
123                         "Null operand! State=%p #Ops=%X, Index=%X\n",
124                         walk_state, state->results.num_results, index));
125                 return (AE_AML_NO_RETURN_VALUE);
126         }
127
128         /* Remove the object */
129
130         state->results.num_results--;
131
132         *object = state->results.obj_desc [index];
133         state->results.obj_desc [index] = NULL;
134
135         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
136                 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
137                 *object, (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
138                 index, walk_state, state->results.num_results));
139
140         return (AE_OK);
141 }
142
143 #endif  /*  ACPI_FUTURE_USAGE  */
144
145 /*******************************************************************************
146  *
147  * FUNCTION:    acpi_ds_result_pop
148  *
149  * PARAMETERS:  Object              - Where to return the popped object
150  *              walk_state          - Current Walk state
151  *
152  * RETURN:      Status
153  *
154  * DESCRIPTION: Pop an object off the bottom of this walk's result stack.  In
155  *              other words, this is a FIFO.
156  *
157  ******************************************************************************/
158
159 acpi_status
160 acpi_ds_result_pop (
161         union acpi_operand_object       **object,
162         struct acpi_walk_state          *walk_state)
163 {
164         acpi_native_uint                index;
165         union acpi_generic_state        *state;
166
167
168         ACPI_FUNCTION_NAME ("ds_result_pop");
169
170
171         state = walk_state->results;
172         if (!state) {
173                 return (AE_OK);
174         }
175
176         if (!state->results.num_results) {
177                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Result stack is empty! State=%p\n",
178                         walk_state));
179                 return (AE_AML_NO_RETURN_VALUE);
180         }
181
182         /* Remove top element */
183
184         state->results.num_results--;
185
186         for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
187                 /* Check for a valid result object */
188
189                 if (state->results.obj_desc [index -1]) {
190                         *object = state->results.obj_desc [index -1];
191                         state->results.obj_desc [index -1] = NULL;
192
193                         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
194                                 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
195                                 *object,
196                                 (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
197                                 (u32) index -1, walk_state, state->results.num_results));
198
199                         return (AE_OK);
200                 }
201         }
202
203         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
204                 "No result objects! State=%p\n", walk_state));
205         return (AE_AML_NO_RETURN_VALUE);
206 }
207
208
209 /*******************************************************************************
210  *
211  * FUNCTION:    acpi_ds_result_pop_from_bottom
212  *
213  * PARAMETERS:  Object              - Where to return the popped object
214  *              walk_state          - Current Walk state
215  *
216  * RETURN:      Status
217  *
218  * DESCRIPTION: Pop an object off the bottom of this walk's result stack.  In
219  *              other words, this is a FIFO.
220  *
221  ******************************************************************************/
222
223 acpi_status
224 acpi_ds_result_pop_from_bottom (
225         union acpi_operand_object       **object,
226         struct acpi_walk_state          *walk_state)
227 {
228         acpi_native_uint                index;
229         union acpi_generic_state        *state;
230
231
232         ACPI_FUNCTION_NAME ("ds_result_pop_from_bottom");
233
234
235         state = walk_state->results;
236         if (!state) {
237                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
238                         "Warning: No result object pushed! State=%p\n", walk_state));
239                 return (AE_NOT_EXIST);
240         }
241
242         if (!state->results.num_results) {
243                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n",
244                         walk_state));
245                 return (AE_AML_NO_RETURN_VALUE);
246         }
247
248         /* Remove Bottom element */
249
250         *object = state->results.obj_desc [0];
251
252         /* Push entire stack down one element */
253
254         for (index = 0; index < state->results.num_results; index++) {
255                 state->results.obj_desc [index] = state->results.obj_desc [index + 1];
256         }
257
258         state->results.num_results--;
259
260         /* Check for a valid result object */
261
262         if (!*object) {
263                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
264                         "Null operand! State=%p #Ops=%X, Index=%X\n",
265                         walk_state, state->results.num_results, (u32) index));
266                 return (AE_AML_NO_RETURN_VALUE);
267         }
268
269         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s], Results=%p State=%p\n",
270                 *object, (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
271                 state, walk_state));
272
273         return (AE_OK);
274 }
275
276
277 /*******************************************************************************
278  *
279  * FUNCTION:    acpi_ds_result_push
280  *
281  * PARAMETERS:  Object              - Where to return the popped object
282  *              walk_state          - Current Walk state
283  *
284  * RETURN:      Status
285  *
286  * DESCRIPTION: Push an object onto the current result stack
287  *
288  ******************************************************************************/
289
290 acpi_status
291 acpi_ds_result_push (
292         union acpi_operand_object       *object,
293         struct acpi_walk_state          *walk_state)
294 {
295         union acpi_generic_state        *state;
296
297
298         ACPI_FUNCTION_NAME ("ds_result_push");
299
300
301         state = walk_state->results;
302         if (!state) {
303                 ACPI_REPORT_ERROR (("No result stack frame during push\n"));
304                 return (AE_AML_INTERNAL);
305         }
306
307         if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
308                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
309                         "Result stack overflow: Obj=%p State=%p Num=%X\n",
310                         object, walk_state, state->results.num_results));
311                 return (AE_STACK_OVERFLOW);
312         }
313
314         if (!object) {
315                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
316                         "Null Object! Obj=%p State=%p Num=%X\n",
317                         object, walk_state, state->results.num_results));
318                 return (AE_BAD_PARAMETER);
319         }
320
321         state->results.obj_desc [state->results.num_results] = object;
322         state->results.num_results++;
323
324         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
325                 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL",
326                 walk_state, state->results.num_results, walk_state->current_result));
327
328         return (AE_OK);
329 }
330
331
332 /*******************************************************************************
333  *
334  * FUNCTION:    acpi_ds_result_stack_push
335  *
336  * PARAMETERS:  walk_state          - Current Walk state
337  *
338  * RETURN:      Status
339  *
340  * DESCRIPTION: Push an object onto the walk_state result stack.
341  *
342  ******************************************************************************/
343
344 acpi_status
345 acpi_ds_result_stack_push (
346         struct acpi_walk_state          *walk_state)
347 {
348         union acpi_generic_state        *state;
349
350         ACPI_FUNCTION_NAME ("ds_result_stack_push");
351
352
353         state = acpi_ut_create_generic_state ();
354         if (!state) {
355                 return (AE_NO_MEMORY);
356         }
357
358         state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT;
359         acpi_ut_push_generic_state (&walk_state->results, state);
360
361         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
362                 state, walk_state));
363
364         return (AE_OK);
365 }
366
367
368 /*******************************************************************************
369  *
370  * FUNCTION:    acpi_ds_result_stack_pop
371  *
372  * PARAMETERS:  walk_state          - Current Walk state
373  *
374  * RETURN:      Status
375  *
376  * DESCRIPTION: Pop an object off of the walk_state result stack.
377  *
378  ******************************************************************************/
379
380 acpi_status
381 acpi_ds_result_stack_pop (
382         struct acpi_walk_state          *walk_state)
383 {
384         union acpi_generic_state        *state;
385
386         ACPI_FUNCTION_NAME ("ds_result_stack_pop");
387
388
389         /* Check for stack underflow */
390
391         if (walk_state->results == NULL) {
392                 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Underflow - State=%p\n",
393                         walk_state));
394                 return (AE_AML_NO_OPERAND);
395         }
396
397         state = acpi_ut_pop_generic_state (&walk_state->results);
398
399         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
400                 "Result=%p remaining_results=%X State=%p\n",
401                 state, state->results.num_results, walk_state));
402
403         acpi_ut_delete_generic_state (state);
404
405         return (AE_OK);
406 }
407
408
409 /*******************************************************************************
410  *
411  * FUNCTION:    acpi_ds_obj_stack_push
412  *
413  * PARAMETERS:  Object              - Object to push
414  *              walk_state          - Current Walk state
415  *
416  * RETURN:      Status
417  *
418  * DESCRIPTION: Push an object onto this walk's object/operand stack
419  *
420  ******************************************************************************/
421
422 acpi_status
423 acpi_ds_obj_stack_push (
424         void                            *object,
425         struct acpi_walk_state          *walk_state)
426 {
427         ACPI_FUNCTION_NAME ("ds_obj_stack_push");
428
429
430         /* Check for stack overflow */
431
432         if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
433                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
434                         "overflow! Obj=%p State=%p #Ops=%X\n",
435                         object, walk_state, walk_state->num_operands));
436                 return (AE_STACK_OVERFLOW);
437         }
438
439         /* Put the object onto the stack */
440
441         walk_state->operands [walk_state->num_operands] = object;
442         walk_state->num_operands++;
443
444         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
445                           object, acpi_ut_get_object_type_name ((union acpi_operand_object *) object),
446                           walk_state, walk_state->num_operands));
447
448         return (AE_OK);
449 }
450
451
452 /*******************************************************************************
453  *
454  * FUNCTION:    acpi_ds_obj_stack_pop
455  *
456  * PARAMETERS:  pop_count           - Number of objects/entries to pop
457  *              walk_state          - Current Walk state
458  *
459  * RETURN:      Status
460  *
461  * DESCRIPTION: Pop this walk's object stack.  Objects on the stack are NOT
462  *              deleted by this routine.
463  *
464  ******************************************************************************/
465
466 acpi_status
467 acpi_ds_obj_stack_pop (
468         u32                             pop_count,
469         struct acpi_walk_state          *walk_state)
470 {
471         u32                             i;
472
473         ACPI_FUNCTION_NAME ("ds_obj_stack_pop");
474
475
476         for (i = 0; i < pop_count; i++) {
477                 /* Check for stack underflow */
478
479                 if (walk_state->num_operands == 0) {
480                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
481                                 "Underflow! Count=%X State=%p #Ops=%X\n",
482                                 pop_count, walk_state, walk_state->num_operands));
483                         return (AE_STACK_UNDERFLOW);
484                 }
485
486                 /* Just set the stack entry to null */
487
488                 walk_state->num_operands--;
489                 walk_state->operands [walk_state->num_operands] = NULL;
490         }
491
492         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
493                           pop_count, walk_state, walk_state->num_operands));
494
495         return (AE_OK);
496 }
497
498
499 /*******************************************************************************
500  *
501  * FUNCTION:    acpi_ds_obj_stack_pop_and_delete
502  *
503  * PARAMETERS:  pop_count           - Number of objects/entries to pop
504  *              walk_state          - Current Walk state
505  *
506  * RETURN:      Status
507  *
508  * DESCRIPTION: Pop this walk's object stack and delete each object that is
509  *              popped off.
510  *
511  ******************************************************************************/
512
513 acpi_status
514 acpi_ds_obj_stack_pop_and_delete (
515         u32                             pop_count,
516         struct acpi_walk_state          *walk_state)
517 {
518         u32                             i;
519         union acpi_operand_object       *obj_desc;
520
521
522         ACPI_FUNCTION_NAME ("ds_obj_stack_pop_and_delete");
523
524
525         for (i = 0; i < pop_count; i++) {
526                 /* Check for stack underflow */
527
528                 if (walk_state->num_operands == 0) {
529                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
530                                 "Underflow! Count=%X State=%p #Ops=%X\n",
531                                 pop_count, walk_state, walk_state->num_operands));
532                         return (AE_STACK_UNDERFLOW);
533                 }
534
535                 /* Pop the stack and delete an object if present in this stack entry */
536
537                 walk_state->num_operands--;
538                 obj_desc = walk_state->operands [walk_state->num_operands];
539                 if (obj_desc) {
540                         acpi_ut_remove_reference (walk_state->operands [walk_state->num_operands]);
541                         walk_state->operands [walk_state->num_operands] = NULL;
542                 }
543         }
544
545         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
546                           pop_count, walk_state, walk_state->num_operands));
547
548         return (AE_OK);
549 }
550
551
552 /*******************************************************************************
553  *
554  * FUNCTION:    acpi_ds_get_current_walk_state
555  *
556  * PARAMETERS:  Thread          - Get current active state for this Thread
557  *
558  * RETURN:      Pointer to the current walk state
559  *
560  * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
561  *              walk state.)
562  *
563  ******************************************************************************/
564
565 struct acpi_walk_state *
566 acpi_ds_get_current_walk_state (
567         struct acpi_thread_state        *thread)
568
569 {
570         ACPI_FUNCTION_NAME ("ds_get_current_walk_state");
571
572
573         if (!thread) {
574                 return (NULL);
575         }
576
577         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current walk_state %p\n",
578                 thread->walk_state_list));
579
580         return (thread->walk_state_list);
581 }
582
583
584 /*******************************************************************************
585  *
586  * FUNCTION:    acpi_ds_push_walk_state
587  *
588  * PARAMETERS:  walk_state      - State to push
589  *              Thread          - Thread state object
590  *
591  * RETURN:      None
592  *
593  * DESCRIPTION: Place the Thread state at the head of the state list.
594  *
595  ******************************************************************************/
596
597 void
598 acpi_ds_push_walk_state (
599         struct acpi_walk_state          *walk_state,
600         struct acpi_thread_state        *thread)
601 {
602         ACPI_FUNCTION_TRACE ("ds_push_walk_state");
603
604
605         walk_state->next      = thread->walk_state_list;
606         thread->walk_state_list = walk_state;
607
608         return_VOID;
609 }
610
611
612 /*******************************************************************************
613  *
614  * FUNCTION:    acpi_ds_pop_walk_state
615  *
616  * PARAMETERS:  Thread      - Current thread state
617  *
618  * RETURN:      A walk_state object popped from the thread's stack
619  *
620  * DESCRIPTION: Remove and return the walkstate object that is at the head of
621  *              the walk stack for the given walk list.  NULL indicates that
622  *              the list is empty.
623  *
624  ******************************************************************************/
625
626 struct acpi_walk_state *
627 acpi_ds_pop_walk_state (
628         struct acpi_thread_state        *thread)
629 {
630         struct acpi_walk_state          *walk_state;
631
632
633         ACPI_FUNCTION_TRACE ("ds_pop_walk_state");
634
635
636         walk_state = thread->walk_state_list;
637
638         if (walk_state) {
639                 /* Next walk state becomes the current walk state */
640
641                 thread->walk_state_list = walk_state->next;
642
643                 /*
644                  * Don't clear the NEXT field, this serves as an indicator
645                  * that there is a parent WALK STATE
646                  * Do Not: walk_state->Next = NULL;
647                  */
648         }
649
650         return_PTR (walk_state);
651 }
652
653
654 /*******************************************************************************
655  *
656  * FUNCTION:    acpi_ds_create_walk_state
657  *
658  * PARAMETERS:  owner_id        - ID for object creation
659  *              Origin          - Starting point for this walk
660  *              mth_desc        - Method object
661  *              Thread          - Current thread state
662  *
663  * RETURN:      Pointer to the new walk state.
664  *
665  * DESCRIPTION: Allocate and initialize a new walk state.  The current walk
666  *              state is set to this new state.
667  *
668  ******************************************************************************/
669
670 struct acpi_walk_state *
671 acpi_ds_create_walk_state (
672         acpi_owner_id                   owner_id,
673         union acpi_parse_object         *origin,
674         union acpi_operand_object       *mth_desc,
675         struct acpi_thread_state        *thread)
676 {
677         struct acpi_walk_state          *walk_state;
678         acpi_status                     status;
679
680
681         ACPI_FUNCTION_TRACE ("ds_create_walk_state");
682
683
684         walk_state = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_WALK);
685         if (!walk_state) {
686                 return_PTR (NULL);
687         }
688
689         walk_state->data_type       = ACPI_DESC_TYPE_WALK;
690         walk_state->owner_id        = owner_id;
691         walk_state->origin          = origin;
692         walk_state->method_desc     = mth_desc;
693         walk_state->thread          = thread;
694
695         walk_state->parser_state.start_op = origin;
696
697         /* Init the method args/local */
698
699 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
700         acpi_ds_method_data_init (walk_state);
701 #endif
702
703         /* Create an initial result stack entry */
704
705         status = acpi_ds_result_stack_push (walk_state);
706         if (ACPI_FAILURE (status)) {
707                 acpi_ut_release_to_cache (ACPI_MEM_LIST_WALK, walk_state);
708                 return_PTR (NULL);
709         }
710
711         /* Put the new state at the head of the walk list */
712
713         if (thread) {
714                 acpi_ds_push_walk_state (walk_state, thread);
715         }
716
717         return_PTR (walk_state);
718 }
719
720
721 /*******************************************************************************
722  *
723  * FUNCTION:    acpi_ds_init_aml_walk
724  *
725  * PARAMETERS:  walk_state      - New state to be initialized
726  *              Op              - Current parse op
727  *              method_node     - Control method NS node, if any
728  *              aml_start       - Start of AML
729  *              aml_length      - Length of AML
730  *              Info            - Method info block (params, etc.)
731  *              pass_number     - 1, 2, or 3
732  *
733  * RETURN:      Status
734  *
735  * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
736  *
737  ******************************************************************************/
738
739 acpi_status
740 acpi_ds_init_aml_walk (
741         struct acpi_walk_state          *walk_state,
742         union acpi_parse_object         *op,
743         struct acpi_namespace_node      *method_node,
744         u8                              *aml_start,
745         u32                             aml_length,
746         struct acpi_parameter_info      *info,
747         u32                             pass_number)
748 {
749         acpi_status                     status;
750         struct acpi_parse_state         *parser_state = &walk_state->parser_state;
751         union acpi_parse_object         *extra_op;
752
753
754         ACPI_FUNCTION_TRACE ("ds_init_aml_walk");
755
756
757         walk_state->parser_state.aml    =
758         walk_state->parser_state.aml_start = aml_start;
759         walk_state->parser_state.aml_end =
760         walk_state->parser_state.pkg_end = aml_start + aml_length;
761
762         /* The next_op of the next_walk will be the beginning of the method */
763
764         walk_state->next_op = NULL;
765
766         if (info) {
767                 if (info->parameter_type == ACPI_PARAM_GPE) {
768                         walk_state->gpe_event_info = ACPI_CAST_PTR (struct acpi_gpe_event_info,
769                                            info->parameters);
770                 }
771                 else {
772                         walk_state->params          = info->parameters;
773                         walk_state->caller_return_desc = &info->return_object;
774                 }
775         }
776
777         status = acpi_ps_init_scope (&walk_state->parser_state, op);
778         if (ACPI_FAILURE (status)) {
779                 return_ACPI_STATUS (status);
780         }
781
782         if (method_node) {
783                 walk_state->parser_state.start_node = method_node;
784                 walk_state->walk_type            = ACPI_WALK_METHOD;
785                 walk_state->method_node          = method_node;
786                 walk_state->method_desc          = acpi_ns_get_attached_object (method_node);
787
788                 /* Push start scope on scope stack and make it current  */
789
790                 status = acpi_ds_scope_stack_push (method_node, ACPI_TYPE_METHOD, walk_state);
791                 if (ACPI_FAILURE (status)) {
792                         return_ACPI_STATUS (status);
793                 }
794
795                 /* Init the method arguments */
796
797                 status = acpi_ds_method_data_init_args (walk_state->params,
798                                  ACPI_METHOD_NUM_ARGS, walk_state);
799                 if (ACPI_FAILURE (status)) {
800                         return_ACPI_STATUS (status);
801                 }
802         }
803         else {
804                 /*
805                  * Setup the current scope.
806                  * Find a Named Op that has a namespace node associated with it.
807                  * search upwards from this Op.  Current scope is the first
808                  * Op with a namespace node.
809                  */
810                 extra_op = parser_state->start_op;
811                 while (extra_op && !extra_op->common.node) {
812                         extra_op = extra_op->common.parent;
813                 }
814
815                 if (!extra_op) {
816                         parser_state->start_node = NULL;
817                 }
818                 else {
819                         parser_state->start_node = extra_op->common.node;
820                 }
821
822                 if (parser_state->start_node) {
823                         /* Push start scope on scope stack and make it current  */
824
825                         status = acpi_ds_scope_stack_push (parser_state->start_node,
826                                           parser_state->start_node->type, walk_state);
827                         if (ACPI_FAILURE (status)) {
828                                 return_ACPI_STATUS (status);
829                         }
830                 }
831         }
832
833         status = acpi_ds_init_callbacks (walk_state, pass_number);
834         return_ACPI_STATUS (status);
835 }
836
837
838 /*******************************************************************************
839  *
840  * FUNCTION:    acpi_ds_delete_walk_state
841  *
842  * PARAMETERS:  walk_state      - State to delete
843  *
844  * RETURN:      Status
845  *
846  * DESCRIPTION: Delete a walk state including all internal data structures
847  *
848  ******************************************************************************/
849
850 void
851 acpi_ds_delete_walk_state (
852         struct acpi_walk_state          *walk_state)
853 {
854         union acpi_generic_state        *state;
855
856
857         ACPI_FUNCTION_TRACE_PTR ("ds_delete_walk_state", walk_state);
858
859
860         if (!walk_state) {
861                 return;
862         }
863
864         if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
865                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p is not a valid walk state\n",
866                         walk_state));
867                 return;
868         }
869
870         if (walk_state->parser_state.scope) {
871                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p walk still has a scope list\n",
872                         walk_state));
873         }
874
875         /* Always must free any linked control states */
876
877         while (walk_state->control_state) {
878                 state = walk_state->control_state;
879                 walk_state->control_state = state->common.next;
880
881                 acpi_ut_delete_generic_state (state);
882         }
883
884         /* Always must free any linked parse states */
885
886         while (walk_state->scope_info) {
887                 state = walk_state->scope_info;
888                 walk_state->scope_info = state->common.next;
889
890                 acpi_ut_delete_generic_state (state);
891         }
892
893         /* Always must free any stacked result states */
894
895         while (walk_state->results) {
896                 state = walk_state->results;
897                 walk_state->results = state->common.next;
898
899                 acpi_ut_delete_generic_state (state);
900         }
901
902         acpi_ut_release_to_cache (ACPI_MEM_LIST_WALK, walk_state);
903         return_VOID;
904 }
905
906
907 #ifdef ACPI_ENABLE_OBJECT_CACHE
908 /******************************************************************************
909  *
910  * FUNCTION:    acpi_ds_delete_walk_state_cache
911  *
912  * PARAMETERS:  None
913  *
914  * RETURN:      None
915  *
916  * DESCRIPTION: Purge the global state object cache.  Used during subsystem
917  *              termination.
918  *
919  ******************************************************************************/
920
921 void
922 acpi_ds_delete_walk_state_cache (
923         void)
924 {
925         ACPI_FUNCTION_TRACE ("ds_delete_walk_state_cache");
926
927
928         acpi_ut_delete_generic_cache (ACPI_MEM_LIST_WALK);
929         return_VOID;
930 }
931 #endif
932
933
934 #ifdef ACPI_OBSOLETE_FUNCTIONS
935 /*******************************************************************************
936  *
937  * FUNCTION:    acpi_ds_result_insert
938  *
939  * PARAMETERS:  Object              - Object to push
940  *              Index               - Where to insert the object
941  *              walk_state          - Current Walk state
942  *
943  * RETURN:      Status
944  *
945  * DESCRIPTION: Insert an object onto this walk's result stack
946  *
947  ******************************************************************************/
948
949 acpi_status
950 acpi_ds_result_insert (
951         void                            *object,
952         u32                             index,
953         struct acpi_walk_state          *walk_state)
954 {
955         union acpi_generic_state        *state;
956
957
958         ACPI_FUNCTION_NAME ("ds_result_insert");
959
960
961         state = walk_state->results;
962         if (!state) {
963                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
964                         walk_state));
965                 return (AE_NOT_EXIST);
966         }
967
968         if (index >= ACPI_OBJ_NUM_OPERANDS) {
969                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
970                         "Index out of range: %X Obj=%p State=%p Num=%X\n",
971                         index, object, walk_state, state->results.num_results));
972                 return (AE_BAD_PARAMETER);
973         }
974
975         if (!object) {
976                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
977                         "Null Object! Index=%X Obj=%p State=%p Num=%X\n",
978                         index, object, walk_state, state->results.num_results));
979                 return (AE_BAD_PARAMETER);
980         }
981
982         state->results.obj_desc [index] = object;
983         state->results.num_results++;
984
985         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
986                 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
987                 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL",
988                 walk_state, state->results.num_results, walk_state->current_result));
989
990         return (AE_OK);
991 }
992
993
994 /*******************************************************************************
995  *
996  * FUNCTION:    acpi_ds_obj_stack_delete_all
997  *
998  * PARAMETERS:  walk_state          - Current Walk state
999  *
1000  * RETURN:      Status
1001  *
1002  * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
1003  *              Should be used with great care, if at all!
1004  *
1005  ******************************************************************************/
1006
1007 acpi_status
1008 acpi_ds_obj_stack_delete_all (
1009         struct acpi_walk_state          *walk_state)
1010 {
1011         u32                             i;
1012
1013
1014         ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_delete_all", walk_state);
1015
1016
1017         /* The stack size is configurable, but fixed */
1018
1019         for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
1020                 if (walk_state->operands[i]) {
1021                         acpi_ut_remove_reference (walk_state->operands[i]);
1022                         walk_state->operands[i] = NULL;
1023                 }
1024         }
1025
1026         return_ACPI_STATUS (AE_OK);
1027 }
1028
1029
1030 /*******************************************************************************
1031  *
1032  * FUNCTION:    acpi_ds_obj_stack_pop_object
1033  *
1034  * PARAMETERS:  Object              - Where to return the popped object
1035  *              walk_state          - Current Walk state
1036  *
1037  * RETURN:      Status
1038  *
1039  * DESCRIPTION: Pop this walk's object stack.  Objects on the stack are NOT
1040  *              deleted by this routine.
1041  *
1042  ******************************************************************************/
1043
1044 acpi_status
1045 acpi_ds_obj_stack_pop_object (
1046         union acpi_operand_object       **object,
1047         struct acpi_walk_state          *walk_state)
1048 {
1049         ACPI_FUNCTION_NAME ("ds_obj_stack_pop_object");
1050
1051
1052         /* Check for stack underflow */
1053
1054         if (walk_state->num_operands == 0) {
1055                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1056                         "Missing operand/stack empty! State=%p #Ops=%X\n",
1057                         walk_state, walk_state->num_operands));
1058                 *object = NULL;
1059                 return (AE_AML_NO_OPERAND);
1060         }
1061
1062         /* Pop the stack */
1063
1064         walk_state->num_operands--;
1065
1066         /* Check for a valid operand */
1067
1068         if (!walk_state->operands [walk_state->num_operands]) {
1069                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1070                         "Null operand! State=%p #Ops=%X\n",
1071                         walk_state, walk_state->num_operands));
1072                 *object = NULL;
1073                 return (AE_AML_NO_OPERAND);
1074         }
1075
1076         /* Get operand and set stack entry to null */
1077
1078         *object = walk_state->operands [walk_state->num_operands];
1079         walk_state->operands [walk_state->num_operands] = NULL;
1080
1081         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1082                           *object, acpi_ut_get_object_type_name (*object),
1083                           walk_state, walk_state->num_operands));
1084
1085         return (AE_OK);
1086 }
1087
1088
1089 /*******************************************************************************
1090  *
1091  * FUNCTION:    acpi_ds_obj_stack_get_value
1092  *
1093  * PARAMETERS:  Index               - Stack index whose value is desired.  Based
1094  *                                    on the top of the stack (index=0 == top)
1095  *              walk_state          - Current Walk state
1096  *
1097  * RETURN:      Pointer to the requested operand
1098  *
1099  * DESCRIPTION: Retrieve an object from this walk's operand stack.  Index must
1100  *              be within the range of the current stack pointer.
1101  *
1102  ******************************************************************************/
1103
1104 void *
1105 acpi_ds_obj_stack_get_value (
1106         u32                             index,
1107         struct acpi_walk_state          *walk_state)
1108 {
1109
1110         ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_get_value", walk_state);
1111
1112
1113         /* Can't do it if the stack is empty */
1114
1115         if (walk_state->num_operands == 0) {
1116                 return_PTR (NULL);
1117         }
1118
1119         /* or if the index is past the top of the stack */
1120
1121         if (index > (walk_state->num_operands - (u32) 1)) {
1122                 return_PTR (NULL);
1123         }
1124
1125         return_PTR (walk_state->operands[(acpi_native_uint)(walk_state->num_operands - 1) -
1126                           index]);
1127 }
1128 #endif
1129
1130