initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / dispatcher / dswstate.c
blob81c6b46acda065b8f94785e2a82f41321fcfc42b
1 /******************************************************************************
3 * Module Name: dswstate - Dispatcher parse tree walk management routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2004, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acnamesp.h>
50 #define _COMPONENT ACPI_DISPATCHER
51 ACPI_MODULE_NAME ("dswstate")
54 /*******************************************************************************
56 * FUNCTION: acpi_ds_result_insert
58 * PARAMETERS: Object - Object to push
59 * Index - Where to insert the object
60 * walk_state - Current Walk state
62 * RETURN: Status
64 * DESCRIPTION: Insert an object onto this walk's result stack
66 ******************************************************************************/
68 acpi_status
69 acpi_ds_result_insert (
70 void *object,
71 u32 index,
72 struct acpi_walk_state *walk_state)
74 union acpi_generic_state *state;
77 ACPI_FUNCTION_NAME ("ds_result_insert");
80 state = walk_state->results;
81 if (!state) {
82 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
83 walk_state));
84 return (AE_NOT_EXIST);
87 if (index >= ACPI_OBJ_NUM_OPERANDS) {
88 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
89 "Index out of range: %X Obj=%p State=%p Num=%X\n",
90 index, object, walk_state, state->results.num_results));
91 return (AE_BAD_PARAMETER);
94 if (!object) {
95 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
96 "Null Object! Index=%X Obj=%p State=%p Num=%X\n",
97 index, object, walk_state, state->results.num_results));
98 return (AE_BAD_PARAMETER);
101 state->results.obj_desc [index] = object;
102 state->results.num_results++;
104 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
105 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
106 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL",
107 walk_state, state->results.num_results, walk_state->current_result));
109 return (AE_OK);
113 /*******************************************************************************
115 * FUNCTION: acpi_ds_result_remove
117 * PARAMETERS: Object - Where to return the popped object
118 * Index - Where to extract the object
119 * walk_state - Current Walk state
121 * RETURN: Status
123 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
124 * other words, this is a FIFO.
126 ******************************************************************************/
128 acpi_status
129 acpi_ds_result_remove (
130 union acpi_operand_object **object,
131 u32 index,
132 struct acpi_walk_state *walk_state)
134 union acpi_generic_state *state;
137 ACPI_FUNCTION_NAME ("ds_result_remove");
140 state = walk_state->results;
141 if (!state) {
142 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
143 walk_state));
144 return (AE_NOT_EXIST);
147 if (index >= ACPI_OBJ_MAX_OPERAND) {
148 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
149 "Index out of range: %X State=%p Num=%X\n",
150 index, walk_state, state->results.num_results));
153 /* Check for a valid result object */
155 if (!state->results.obj_desc [index]) {
156 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
157 "Null operand! State=%p #Ops=%X, Index=%X\n",
158 walk_state, state->results.num_results, index));
159 return (AE_AML_NO_RETURN_VALUE);
162 /* Remove the object */
164 state->results.num_results--;
166 *object = state->results.obj_desc [index];
167 state->results.obj_desc [index] = NULL;
169 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
170 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
171 *object, (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
172 index, walk_state, state->results.num_results));
174 return (AE_OK);
178 /*******************************************************************************
180 * FUNCTION: acpi_ds_result_pop
182 * PARAMETERS: Object - Where to return the popped object
183 * walk_state - Current Walk state
185 * RETURN: Status
187 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
188 * other words, this is a FIFO.
190 ******************************************************************************/
192 acpi_status
193 acpi_ds_result_pop (
194 union acpi_operand_object **object,
195 struct acpi_walk_state *walk_state)
197 acpi_native_uint index;
198 union acpi_generic_state *state;
201 ACPI_FUNCTION_NAME ("ds_result_pop");
204 state = walk_state->results;
205 if (!state) {
206 return (AE_OK);
209 if (!state->results.num_results) {
210 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Result stack is empty! State=%p\n",
211 walk_state));
212 return (AE_AML_NO_RETURN_VALUE);
215 /* Remove top element */
217 state->results.num_results--;
219 for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
220 /* Check for a valid result object */
222 if (state->results.obj_desc [index -1]) {
223 *object = state->results.obj_desc [index -1];
224 state->results.obj_desc [index -1] = NULL;
226 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] Index=%X State=%p Num=%X\n",
227 *object, (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
228 (u32) index -1, walk_state, state->results.num_results));
230 return (AE_OK);
234 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n", walk_state));
235 return (AE_AML_NO_RETURN_VALUE);
239 /*******************************************************************************
241 * FUNCTION: acpi_ds_result_pop_from_bottom
243 * PARAMETERS: Object - Where to return the popped object
244 * walk_state - Current Walk state
246 * RETURN: Status
248 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
249 * other words, this is a FIFO.
251 ******************************************************************************/
253 acpi_status
254 acpi_ds_result_pop_from_bottom (
255 union acpi_operand_object **object,
256 struct acpi_walk_state *walk_state)
258 acpi_native_uint index;
259 union acpi_generic_state *state;
262 ACPI_FUNCTION_NAME ("ds_result_pop_from_bottom");
265 state = walk_state->results;
266 if (!state) {
267 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
268 "Warning: No result object pushed! State=%p\n", walk_state));
269 return (AE_NOT_EXIST);
272 if (!state->results.num_results) {
273 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n", walk_state));
274 return (AE_AML_NO_RETURN_VALUE);
277 /* Remove Bottom element */
279 *object = state->results.obj_desc [0];
281 /* Push entire stack down one element */
283 for (index = 0; index < state->results.num_results; index++) {
284 state->results.obj_desc [index] = state->results.obj_desc [index + 1];
287 state->results.num_results--;
289 /* Check for a valid result object */
291 if (!*object) {
292 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null operand! State=%p #Ops=%X, Index=%X\n",
293 walk_state, state->results.num_results, (u32) index));
294 return (AE_AML_NO_RETURN_VALUE);
297 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s], Results=%p State=%p\n",
298 *object, (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
299 state, walk_state));
301 return (AE_OK);
305 /*******************************************************************************
307 * FUNCTION: acpi_ds_result_push
309 * PARAMETERS: Object - Where to return the popped object
310 * walk_state - Current Walk state
312 * RETURN: Status
314 * DESCRIPTION: Push an object onto the current result stack
316 ******************************************************************************/
318 acpi_status
319 acpi_ds_result_push (
320 union acpi_operand_object *object,
321 struct acpi_walk_state *walk_state)
323 union acpi_generic_state *state;
326 ACPI_FUNCTION_NAME ("ds_result_push");
329 state = walk_state->results;
330 if (!state) {
331 ACPI_REPORT_ERROR (("No result stack frame during push\n"));
332 return (AE_AML_INTERNAL);
335 if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
336 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
337 "Result stack overflow: Obj=%p State=%p Num=%X\n",
338 object, walk_state, state->results.num_results));
339 return (AE_STACK_OVERFLOW);
342 if (!object) {
343 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Object! Obj=%p State=%p Num=%X\n",
344 object, walk_state, state->results.num_results));
345 return (AE_BAD_PARAMETER);
348 state->results.obj_desc [state->results.num_results] = object;
349 state->results.num_results++;
351 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
352 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL",
353 walk_state, state->results.num_results, walk_state->current_result));
355 return (AE_OK);
359 /*******************************************************************************
361 * FUNCTION: acpi_ds_result_stack_push
363 * PARAMETERS: walk_state - Current Walk state
365 * RETURN: Status
367 * DESCRIPTION: Push an object onto the walk_state result stack.
369 ******************************************************************************/
371 acpi_status
372 acpi_ds_result_stack_push (
373 struct acpi_walk_state *walk_state)
375 union acpi_generic_state *state;
377 ACPI_FUNCTION_NAME ("ds_result_stack_push");
380 state = acpi_ut_create_generic_state ();
381 if (!state) {
382 return (AE_NO_MEMORY);
385 state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT;
386 acpi_ut_push_generic_state (&walk_state->results, state);
388 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
389 state, walk_state));
391 return (AE_OK);
395 /*******************************************************************************
397 * FUNCTION: acpi_ds_result_stack_pop
399 * PARAMETERS: walk_state - Current Walk state
401 * RETURN: Status
403 * DESCRIPTION: Pop an object off of the walk_state result stack.
405 ******************************************************************************/
407 acpi_status
408 acpi_ds_result_stack_pop (
409 struct acpi_walk_state *walk_state)
411 union acpi_generic_state *state;
413 ACPI_FUNCTION_NAME ("ds_result_stack_pop");
416 /* Check for stack underflow */
418 if (walk_state->results == NULL) {
419 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Underflow - State=%p\n",
420 walk_state));
421 return (AE_AML_NO_OPERAND);
424 state = acpi_ut_pop_generic_state (&walk_state->results);
426 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
427 "Result=%p remaining_results=%X State=%p\n",
428 state, state->results.num_results, walk_state));
430 acpi_ut_delete_generic_state (state);
432 return (AE_OK);
436 /*******************************************************************************
438 * FUNCTION: acpi_ds_obj_stack_delete_all
440 * PARAMETERS: walk_state - Current Walk state
442 * RETURN: Status
444 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
445 * Should be used with great care, if at all!
447 ******************************************************************************/
449 acpi_status
450 acpi_ds_obj_stack_delete_all (
451 struct acpi_walk_state *walk_state)
453 u32 i;
456 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_delete_all", walk_state);
459 /* The stack size is configurable, but fixed */
461 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
462 if (walk_state->operands[i]) {
463 acpi_ut_remove_reference (walk_state->operands[i]);
464 walk_state->operands[i] = NULL;
468 return_ACPI_STATUS (AE_OK);
472 /*******************************************************************************
474 * FUNCTION: acpi_ds_obj_stack_push
476 * PARAMETERS: Object - Object to push
477 * walk_state - Current Walk state
479 * RETURN: Status
481 * DESCRIPTION: Push an object onto this walk's object/operand stack
483 ******************************************************************************/
485 acpi_status
486 acpi_ds_obj_stack_push (
487 void *object,
488 struct acpi_walk_state *walk_state)
490 ACPI_FUNCTION_NAME ("ds_obj_stack_push");
493 /* Check for stack overflow */
495 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
496 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
497 "overflow! Obj=%p State=%p #Ops=%X\n",
498 object, walk_state, walk_state->num_operands));
499 return (AE_STACK_OVERFLOW);
502 /* Put the object onto the stack */
504 walk_state->operands [walk_state->num_operands] = object;
505 walk_state->num_operands++;
507 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
508 object, acpi_ut_get_object_type_name ((union acpi_operand_object *) object),
509 walk_state, walk_state->num_operands));
511 return (AE_OK);
515 #if 0
516 /*******************************************************************************
518 * FUNCTION: acpi_ds_obj_stack_pop_object
520 * PARAMETERS: pop_count - Number of objects/entries to pop
521 * walk_state - Current Walk state
523 * RETURN: Status
525 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
526 * deleted by this routine.
528 ******************************************************************************/
530 acpi_status
531 acpi_ds_obj_stack_pop_object (
532 union acpi_operand_object **object,
533 struct acpi_walk_state *walk_state)
535 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_object");
538 /* Check for stack underflow */
540 if (walk_state->num_operands == 0) {
541 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
542 "Missing operand/stack empty! State=%p #Ops=%X\n",
543 walk_state, walk_state->num_operands));
544 *object = NULL;
545 return (AE_AML_NO_OPERAND);
548 /* Pop the stack */
550 walk_state->num_operands--;
552 /* Check for a valid operand */
554 if (!walk_state->operands [walk_state->num_operands]) {
555 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
556 "Null operand! State=%p #Ops=%X\n",
557 walk_state, walk_state->num_operands));
558 *object = NULL;
559 return (AE_AML_NO_OPERAND);
562 /* Get operand and set stack entry to null */
564 *object = walk_state->operands [walk_state->num_operands];
565 walk_state->operands [walk_state->num_operands] = NULL;
567 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
568 *object, acpi_ut_get_object_type_name (*object),
569 walk_state, walk_state->num_operands));
571 return (AE_OK);
573 #endif
576 /*******************************************************************************
578 * FUNCTION: acpi_ds_obj_stack_pop
580 * PARAMETERS: pop_count - Number of objects/entries to pop
581 * walk_state - Current Walk state
583 * RETURN: Status
585 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
586 * deleted by this routine.
588 ******************************************************************************/
590 acpi_status
591 acpi_ds_obj_stack_pop (
592 u32 pop_count,
593 struct acpi_walk_state *walk_state)
595 u32 i;
597 ACPI_FUNCTION_NAME ("ds_obj_stack_pop");
600 for (i = 0; i < pop_count; i++) {
601 /* Check for stack underflow */
603 if (walk_state->num_operands == 0) {
604 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
605 "Underflow! Count=%X State=%p #Ops=%X\n",
606 pop_count, walk_state, walk_state->num_operands));
607 return (AE_STACK_UNDERFLOW);
610 /* Just set the stack entry to null */
612 walk_state->num_operands--;
613 walk_state->operands [walk_state->num_operands] = NULL;
616 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
617 pop_count, walk_state, walk_state->num_operands));
619 return (AE_OK);
623 /*******************************************************************************
625 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
627 * PARAMETERS: pop_count - Number of objects/entries to pop
628 * walk_state - Current Walk state
630 * RETURN: Status
632 * DESCRIPTION: Pop this walk's object stack and delete each object that is
633 * popped off.
635 ******************************************************************************/
637 acpi_status
638 acpi_ds_obj_stack_pop_and_delete (
639 u32 pop_count,
640 struct acpi_walk_state *walk_state)
642 u32 i;
643 union acpi_operand_object *obj_desc;
646 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_and_delete");
649 for (i = 0; i < pop_count; i++) {
650 /* Check for stack underflow */
652 if (walk_state->num_operands == 0) {
653 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
654 "Underflow! Count=%X State=%p #Ops=%X\n",
655 pop_count, walk_state, walk_state->num_operands));
656 return (AE_STACK_UNDERFLOW);
659 /* Pop the stack and delete an object if present in this stack entry */
661 walk_state->num_operands--;
662 obj_desc = walk_state->operands [walk_state->num_operands];
663 if (obj_desc) {
664 acpi_ut_remove_reference (walk_state->operands [walk_state->num_operands]);
665 walk_state->operands [walk_state->num_operands] = NULL;
669 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
670 pop_count, walk_state, walk_state->num_operands));
672 return (AE_OK);
676 /*******************************************************************************
678 * FUNCTION: acpi_ds_obj_stack_get_value
680 * PARAMETERS: Index - Stack index whose value is desired. Based
681 * on the top of the stack (index=0 == top)
682 * walk_state - Current Walk state
684 * RETURN: Status
686 * DESCRIPTION: Retrieve an object from this walk's object stack. Index must
687 * be within the range of the current stack pointer.
689 ******************************************************************************/
691 void *
692 acpi_ds_obj_stack_get_value (
693 u32 index,
694 struct acpi_walk_state *walk_state)
697 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_get_value", walk_state);
700 /* Can't do it if the stack is empty */
702 if (walk_state->num_operands == 0) {
703 return_PTR (NULL);
706 /* or if the index is past the top of the stack */
708 if (index > (walk_state->num_operands - (u32) 1)) {
709 return_PTR (NULL);
712 return_PTR (walk_state->operands[(acpi_native_uint)(walk_state->num_operands - 1) -
713 index]);
717 /*******************************************************************************
719 * FUNCTION: acpi_ds_get_current_walk_state
721 * PARAMETERS: Thread - Get current active state for this Thread
723 * RETURN: Pointer to the current walk state
725 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
726 * walk state.)
728 ******************************************************************************/
730 struct acpi_walk_state *
731 acpi_ds_get_current_walk_state (
732 struct acpi_thread_state *thread)
735 ACPI_FUNCTION_NAME ("ds_get_current_walk_state");
738 if (!thread) {
739 return (NULL);
742 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current walk_state %p\n",
743 thread->walk_state_list));
745 return (thread->walk_state_list);
749 /*******************************************************************************
751 * FUNCTION: acpi_ds_push_walk_state
753 * PARAMETERS: walk_state - State to push
754 * walk_list - The list that owns the walk stack
756 * RETURN: None
758 * DESCRIPTION: Place the walk_state at the head of the state list.
760 ******************************************************************************/
762 void
763 acpi_ds_push_walk_state (
764 struct acpi_walk_state *walk_state,
765 struct acpi_thread_state *thread)
767 ACPI_FUNCTION_TRACE ("ds_push_walk_state");
770 walk_state->next = thread->walk_state_list;
771 thread->walk_state_list = walk_state;
773 return_VOID;
777 /*******************************************************************************
779 * FUNCTION: acpi_ds_pop_walk_state
781 * PARAMETERS: walk_list - The list that owns the walk stack
783 * RETURN: A walk_state object popped from the stack
785 * DESCRIPTION: Remove and return the walkstate object that is at the head of
786 * the walk stack for the given walk list. NULL indicates that
787 * the list is empty.
789 ******************************************************************************/
791 struct acpi_walk_state *
792 acpi_ds_pop_walk_state (
793 struct acpi_thread_state *thread)
795 struct acpi_walk_state *walk_state;
798 ACPI_FUNCTION_TRACE ("ds_pop_walk_state");
801 walk_state = thread->walk_state_list;
803 if (walk_state) {
804 /* Next walk state becomes the current walk state */
806 thread->walk_state_list = walk_state->next;
809 * Don't clear the NEXT field, this serves as an indicator
810 * that there is a parent WALK STATE
811 * NO: walk_state->Next = NULL;
815 return_PTR (walk_state);
819 /*******************************************************************************
821 * FUNCTION: acpi_ds_create_walk_state
823 * PARAMETERS: Origin - Starting point for this walk
824 * Thread - Current thread state
826 * RETURN: Pointer to the new walk state.
828 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
829 * state is set to this new state.
831 ******************************************************************************/
833 struct acpi_walk_state *
834 acpi_ds_create_walk_state (
835 acpi_owner_id owner_id,
836 union acpi_parse_object *origin,
837 union acpi_operand_object *mth_desc,
838 struct acpi_thread_state *thread)
840 struct acpi_walk_state *walk_state;
841 acpi_status status;
844 ACPI_FUNCTION_TRACE ("ds_create_walk_state");
847 walk_state = acpi_ut_acquire_from_cache (ACPI_MEM_LIST_WALK);
848 if (!walk_state) {
849 return_PTR (NULL);
852 walk_state->data_type = ACPI_DESC_TYPE_WALK;
853 walk_state->owner_id = owner_id;
854 walk_state->origin = origin;
855 walk_state->method_desc = mth_desc;
856 walk_state->thread = thread;
858 walk_state->parser_state.start_op = origin;
860 /* Init the method args/local */
862 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
863 acpi_ds_method_data_init (walk_state);
864 #endif
866 /* Create an initial result stack entry */
868 status = acpi_ds_result_stack_push (walk_state);
869 if (ACPI_FAILURE (status)) {
870 return_PTR (NULL);
873 /* Put the new state at the head of the walk list */
875 if (thread) {
876 acpi_ds_push_walk_state (walk_state, thread);
879 return_PTR (walk_state);
883 /*******************************************************************************
885 * FUNCTION: acpi_ds_init_aml_walk
887 * PARAMETERS: walk_state - New state to be initialized
888 * Op - Current parse op
889 * method_node - Control method NS node, if any
890 * aml_start - Start of AML
891 * aml_length - Length of AML
892 * Params - Method args, if any
893 * return_obj_desc - Where to store a return object, if any
894 * pass_number - 1, 2, or 3
896 * RETURN: Status
898 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
900 ******************************************************************************/
902 acpi_status
903 acpi_ds_init_aml_walk (
904 struct acpi_walk_state *walk_state,
905 union acpi_parse_object *op,
906 struct acpi_namespace_node *method_node,
907 u8 *aml_start,
908 u32 aml_length,
909 struct acpi_parameter_info *info,
910 u32 pass_number)
912 acpi_status status;
913 struct acpi_parse_state *parser_state = &walk_state->parser_state;
914 union acpi_parse_object *extra_op;
917 ACPI_FUNCTION_TRACE ("ds_init_aml_walk");
920 walk_state->parser_state.aml =
921 walk_state->parser_state.aml_start = aml_start;
922 walk_state->parser_state.aml_end =
923 walk_state->parser_state.pkg_end = aml_start + aml_length;
925 /* The next_op of the next_walk will be the beginning of the method */
927 walk_state->next_op = NULL;
929 if (info) {
930 if (info->parameter_type == ACPI_PARAM_GPE) {
931 walk_state->gpe_event_info = ACPI_CAST_PTR (struct acpi_gpe_event_info,
932 info->parameters);
934 else {
935 walk_state->params = info->parameters;
936 walk_state->caller_return_desc = &info->return_object;
940 status = acpi_ps_init_scope (&walk_state->parser_state, op);
941 if (ACPI_FAILURE (status)) {
942 return_ACPI_STATUS (status);
945 if (method_node) {
946 walk_state->parser_state.start_node = method_node;
947 walk_state->walk_type = ACPI_WALK_METHOD;
948 walk_state->method_node = method_node;
949 walk_state->method_desc = acpi_ns_get_attached_object (method_node);
951 /* Push start scope on scope stack and make it current */
953 status = acpi_ds_scope_stack_push (method_node, ACPI_TYPE_METHOD, walk_state);
954 if (ACPI_FAILURE (status)) {
955 return_ACPI_STATUS (status);
958 /* Init the method arguments */
960 status = acpi_ds_method_data_init_args (walk_state->params, ACPI_METHOD_NUM_ARGS, walk_state);
961 if (ACPI_FAILURE (status)) {
962 return_ACPI_STATUS (status);
965 else {
967 * Setup the current scope.
968 * Find a Named Op that has a namespace node associated with it.
969 * search upwards from this Op. Current scope is the first
970 * Op with a namespace node.
972 extra_op = parser_state->start_op;
973 while (extra_op && !extra_op->common.node) {
974 extra_op = extra_op->common.parent;
977 if (!extra_op) {
978 parser_state->start_node = NULL;
980 else {
981 parser_state->start_node = extra_op->common.node;
984 if (parser_state->start_node) {
985 /* Push start scope on scope stack and make it current */
987 status = acpi_ds_scope_stack_push (parser_state->start_node,
988 parser_state->start_node->type, walk_state);
989 if (ACPI_FAILURE (status)) {
990 return_ACPI_STATUS (status);
995 status = acpi_ds_init_callbacks (walk_state, pass_number);
996 return_ACPI_STATUS (status);
1000 /*******************************************************************************
1002 * FUNCTION: acpi_ds_delete_walk_state
1004 * PARAMETERS: walk_state - State to delete
1006 * RETURN: Status
1008 * DESCRIPTION: Delete a walk state including all internal data structures
1010 ******************************************************************************/
1012 void
1013 acpi_ds_delete_walk_state (
1014 struct acpi_walk_state *walk_state)
1016 union acpi_generic_state *state;
1019 ACPI_FUNCTION_TRACE_PTR ("ds_delete_walk_state", walk_state);
1022 if (!walk_state) {
1023 return;
1026 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
1027 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p is not a valid walk state\n", walk_state));
1028 return;
1031 if (walk_state->parser_state.scope) {
1032 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p walk still has a scope list\n", walk_state));
1035 /* Always must free any linked control states */
1037 while (walk_state->control_state) {
1038 state = walk_state->control_state;
1039 walk_state->control_state = state->common.next;
1041 acpi_ut_delete_generic_state (state);
1044 /* Always must free any linked parse states */
1046 while (walk_state->scope_info) {
1047 state = walk_state->scope_info;
1048 walk_state->scope_info = state->common.next;
1050 acpi_ut_delete_generic_state (state);
1053 /* Always must free any stacked result states */
1055 while (walk_state->results) {
1056 state = walk_state->results;
1057 walk_state->results = state->common.next;
1059 acpi_ut_delete_generic_state (state);
1062 acpi_ut_release_to_cache (ACPI_MEM_LIST_WALK, walk_state);
1063 return_VOID;
1067 /******************************************************************************
1069 * FUNCTION: acpi_ds_delete_walk_state_cache
1071 * PARAMETERS: None
1073 * RETURN: Status
1075 * DESCRIPTION: Purge the global state object cache. Used during subsystem
1076 * termination.
1078 ******************************************************************************/
1080 void
1081 acpi_ds_delete_walk_state_cache (
1082 void)
1084 ACPI_FUNCTION_TRACE ("ds_delete_walk_state_cache");
1087 acpi_ut_delete_generic_cache (ACPI_MEM_LIST_WALK);
1088 return_VOID;