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