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