[ACPI] ACPICA 20050729 from Bob Moore
[linux-2.6.22.y-op.git] / drivers / acpi / dispatcher / dswstate.c
blob5621665991b51bb0eacdf3f04796dba1ba5f2cb5
1 /******************************************************************************
3 * Module Name: dswstate - Dispatcher parse tree walk management routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, 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")
53 /* Local prototypes */
55 #ifdef ACPI_OBSOLETE_FUNCTIONS
56 acpi_status
57 acpi_ds_result_insert (
58 void *object,
59 u32 index,
60 struct acpi_walk_state *walk_state);
62 acpi_status
63 acpi_ds_obj_stack_delete_all (
64 struct acpi_walk_state *walk_state);
66 acpi_status
67 acpi_ds_obj_stack_pop_object (
68 union acpi_operand_object **object,
69 struct acpi_walk_state *walk_state);
71 void *
72 acpi_ds_obj_stack_get_value (
73 u32 index,
74 struct acpi_walk_state *walk_state);
75 #endif
77 #ifdef ACPI_FUTURE_USAGE
79 /*******************************************************************************
81 * FUNCTION: acpi_ds_result_remove
83 * PARAMETERS: Object - Where to return the popped object
84 * Index - Where to extract the object
85 * walk_state - Current Walk state
87 * RETURN: Status
89 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
90 * other words, this is a FIFO.
92 ******************************************************************************/
94 acpi_status
95 acpi_ds_result_remove (
96 union acpi_operand_object **object,
97 u32 index,
98 struct acpi_walk_state *walk_state)
100 union acpi_generic_state *state;
103 ACPI_FUNCTION_NAME ("ds_result_remove");
106 state = walk_state->results;
107 if (!state) {
108 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
109 walk_state));
110 return (AE_NOT_EXIST);
113 if (index >= ACPI_OBJ_MAX_OPERAND) {
114 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
115 "Index out of range: %X State=%p Num=%X\n",
116 index, walk_state, state->results.num_results));
119 /* Check for a valid result object */
121 if (!state->results.obj_desc [index]) {
122 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
123 "Null operand! State=%p #Ops=%X, Index=%X\n",
124 walk_state, state->results.num_results, index));
125 return (AE_AML_NO_RETURN_VALUE);
128 /* Remove the object */
130 state->results.num_results--;
132 *object = state->results.obj_desc [index];
133 state->results.obj_desc [index] = NULL;
135 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
136 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
137 *object, (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
138 index, walk_state, state->results.num_results));
140 return (AE_OK);
143 #endif /* ACPI_FUTURE_USAGE */
145 /*******************************************************************************
147 * FUNCTION: acpi_ds_result_pop
149 * PARAMETERS: Object - Where to return the popped object
150 * walk_state - Current Walk state
152 * RETURN: Status
154 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
155 * other words, this is a FIFO.
157 ******************************************************************************/
159 acpi_status
160 acpi_ds_result_pop (
161 union acpi_operand_object **object,
162 struct acpi_walk_state *walk_state)
164 acpi_native_uint index;
165 union acpi_generic_state *state;
168 ACPI_FUNCTION_NAME ("ds_result_pop");
171 state = walk_state->results;
172 if (!state) {
173 return (AE_OK);
176 if (!state->results.num_results) {
177 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Result stack is empty! State=%p\n",
178 walk_state));
179 return (AE_AML_NO_RETURN_VALUE);
182 /* Remove top element */
184 state->results.num_results--;
186 for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
187 /* Check for a valid result object */
189 if (state->results.obj_desc [index -1]) {
190 *object = state->results.obj_desc [index -1];
191 state->results.obj_desc [index -1] = NULL;
193 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
194 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
195 *object,
196 (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
197 (u32) index -1, walk_state, state->results.num_results));
199 return (AE_OK);
203 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
204 "No result objects! State=%p\n", walk_state));
205 return (AE_AML_NO_RETURN_VALUE);
209 /*******************************************************************************
211 * FUNCTION: acpi_ds_result_pop_from_bottom
213 * PARAMETERS: Object - Where to return the popped object
214 * walk_state - Current Walk state
216 * RETURN: Status
218 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
219 * other words, this is a FIFO.
221 ******************************************************************************/
223 acpi_status
224 acpi_ds_result_pop_from_bottom (
225 union acpi_operand_object **object,
226 struct acpi_walk_state *walk_state)
228 acpi_native_uint index;
229 union acpi_generic_state *state;
232 ACPI_FUNCTION_NAME ("ds_result_pop_from_bottom");
235 state = walk_state->results;
236 if (!state) {
237 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
238 "Warning: No result object pushed! State=%p\n", walk_state));
239 return (AE_NOT_EXIST);
242 if (!state->results.num_results) {
243 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result objects! State=%p\n",
244 walk_state));
245 return (AE_AML_NO_RETURN_VALUE);
248 /* Remove Bottom element */
250 *object = state->results.obj_desc [0];
252 /* Push entire stack down one element */
254 for (index = 0; index < state->results.num_results; index++) {
255 state->results.obj_desc [index] = state->results.obj_desc [index + 1];
258 state->results.num_results--;
260 /* Check for a valid result object */
262 if (!*object) {
263 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
264 "Null operand! State=%p #Ops=%X Index=%X\n",
265 walk_state, state->results.num_results, (u32) index));
266 return (AE_AML_NO_RETURN_VALUE);
269 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n",
270 *object, (*object) ? acpi_ut_get_object_type_name (*object) : "NULL",
271 state, walk_state));
273 return (AE_OK);
277 /*******************************************************************************
279 * FUNCTION: acpi_ds_result_push
281 * PARAMETERS: Object - Where to return the popped object
282 * walk_state - Current Walk state
284 * RETURN: Status
286 * DESCRIPTION: Push an object onto the current result stack
288 ******************************************************************************/
290 acpi_status
291 acpi_ds_result_push (
292 union acpi_operand_object *object,
293 struct acpi_walk_state *walk_state)
295 union acpi_generic_state *state;
298 ACPI_FUNCTION_NAME ("ds_result_push");
301 state = walk_state->results;
302 if (!state) {
303 ACPI_REPORT_ERROR (("No result stack frame during push\n"));
304 return (AE_AML_INTERNAL);
307 if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
308 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
309 "Result stack overflow: Obj=%p State=%p Num=%X\n",
310 object, walk_state, state->results.num_results));
311 return (AE_STACK_OVERFLOW);
314 if (!object) {
315 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
316 "Null Object! Obj=%p State=%p Num=%X\n",
317 object, walk_state, state->results.num_results));
318 return (AE_BAD_PARAMETER);
321 state->results.obj_desc [state->results.num_results] = object;
322 state->results.num_results++;
324 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
325 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL",
326 walk_state, state->results.num_results, walk_state->current_result));
328 return (AE_OK);
332 /*******************************************************************************
334 * FUNCTION: acpi_ds_result_stack_push
336 * PARAMETERS: walk_state - Current Walk state
338 * RETURN: Status
340 * DESCRIPTION: Push an object onto the walk_state result stack.
342 ******************************************************************************/
344 acpi_status
345 acpi_ds_result_stack_push (
346 struct acpi_walk_state *walk_state)
348 union acpi_generic_state *state;
350 ACPI_FUNCTION_NAME ("ds_result_stack_push");
353 state = acpi_ut_create_generic_state ();
354 if (!state) {
355 return (AE_NO_MEMORY);
358 state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT;
359 acpi_ut_push_generic_state (&walk_state->results, state);
361 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
362 state, walk_state));
364 return (AE_OK);
368 /*******************************************************************************
370 * FUNCTION: acpi_ds_result_stack_pop
372 * PARAMETERS: walk_state - Current Walk state
374 * RETURN: Status
376 * DESCRIPTION: Pop an object off of the walk_state result stack.
378 ******************************************************************************/
380 acpi_status
381 acpi_ds_result_stack_pop (
382 struct acpi_walk_state *walk_state)
384 union acpi_generic_state *state;
386 ACPI_FUNCTION_NAME ("ds_result_stack_pop");
389 /* Check for stack underflow */
391 if (walk_state->results == NULL) {
392 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Underflow - State=%p\n",
393 walk_state));
394 return (AE_AML_NO_OPERAND);
397 state = acpi_ut_pop_generic_state (&walk_state->results);
399 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
400 "Result=%p remaining_results=%X State=%p\n",
401 state, state->results.num_results, walk_state));
403 acpi_ut_delete_generic_state (state);
405 return (AE_OK);
409 /*******************************************************************************
411 * FUNCTION: acpi_ds_obj_stack_push
413 * PARAMETERS: Object - Object to push
414 * walk_state - Current Walk state
416 * RETURN: Status
418 * DESCRIPTION: Push an object onto this walk's object/operand stack
420 ******************************************************************************/
422 acpi_status
423 acpi_ds_obj_stack_push (
424 void *object,
425 struct acpi_walk_state *walk_state)
427 ACPI_FUNCTION_NAME ("ds_obj_stack_push");
430 /* Check for stack overflow */
432 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
433 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
434 "overflow! Obj=%p State=%p #Ops=%X\n",
435 object, walk_state, walk_state->num_operands));
436 return (AE_STACK_OVERFLOW);
439 /* Put the object onto the stack */
441 walk_state->operands [walk_state->num_operands] = object;
442 walk_state->num_operands++;
444 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
445 object, acpi_ut_get_object_type_name ((union acpi_operand_object *) object),
446 walk_state, walk_state->num_operands));
448 return (AE_OK);
452 /*******************************************************************************
454 * FUNCTION: acpi_ds_obj_stack_pop
456 * PARAMETERS: pop_count - Number of objects/entries to pop
457 * walk_state - Current Walk state
459 * RETURN: Status
461 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
462 * deleted by this routine.
464 ******************************************************************************/
466 acpi_status
467 acpi_ds_obj_stack_pop (
468 u32 pop_count,
469 struct acpi_walk_state *walk_state)
471 u32 i;
473 ACPI_FUNCTION_NAME ("ds_obj_stack_pop");
476 for (i = 0; i < pop_count; i++) {
477 /* Check for stack underflow */
479 if (walk_state->num_operands == 0) {
480 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
481 "Underflow! Count=%X State=%p #Ops=%X\n",
482 pop_count, walk_state, walk_state->num_operands));
483 return (AE_STACK_UNDERFLOW);
486 /* Just set the stack entry to null */
488 walk_state->num_operands--;
489 walk_state->operands [walk_state->num_operands] = NULL;
492 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
493 pop_count, walk_state, walk_state->num_operands));
495 return (AE_OK);
499 /*******************************************************************************
501 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
503 * PARAMETERS: pop_count - Number of objects/entries to pop
504 * walk_state - Current Walk state
506 * RETURN: Status
508 * DESCRIPTION: Pop this walk's object stack and delete each object that is
509 * popped off.
511 ******************************************************************************/
513 acpi_status
514 acpi_ds_obj_stack_pop_and_delete (
515 u32 pop_count,
516 struct acpi_walk_state *walk_state)
518 u32 i;
519 union acpi_operand_object *obj_desc;
522 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_and_delete");
525 for (i = 0; i < pop_count; i++) {
526 /* Check for stack underflow */
528 if (walk_state->num_operands == 0) {
529 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
530 "Underflow! Count=%X State=%p #Ops=%X\n",
531 pop_count, walk_state, walk_state->num_operands));
532 return (AE_STACK_UNDERFLOW);
535 /* Pop the stack and delete an object if present in this stack entry */
537 walk_state->num_operands--;
538 obj_desc = walk_state->operands [walk_state->num_operands];
539 if (obj_desc) {
540 acpi_ut_remove_reference (walk_state->operands [walk_state->num_operands]);
541 walk_state->operands [walk_state->num_operands] = NULL;
545 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
546 pop_count, walk_state, walk_state->num_operands));
548 return (AE_OK);
552 /*******************************************************************************
554 * FUNCTION: acpi_ds_get_current_walk_state
556 * PARAMETERS: Thread - Get current active state for this Thread
558 * RETURN: Pointer to the current walk state
560 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
561 * walk state.)
563 ******************************************************************************/
565 struct acpi_walk_state *
566 acpi_ds_get_current_walk_state (
567 struct acpi_thread_state *thread)
570 ACPI_FUNCTION_NAME ("ds_get_current_walk_state");
573 if (!thread) {
574 return (NULL);
577 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current walk_state %p\n",
578 thread->walk_state_list));
580 return (thread->walk_state_list);
584 /*******************************************************************************
586 * FUNCTION: acpi_ds_push_walk_state
588 * PARAMETERS: walk_state - State to push
589 * Thread - Thread state object
591 * RETURN: None
593 * DESCRIPTION: Place the Thread state at the head of the state list.
595 ******************************************************************************/
597 void
598 acpi_ds_push_walk_state (
599 struct acpi_walk_state *walk_state,
600 struct acpi_thread_state *thread)
602 ACPI_FUNCTION_TRACE ("ds_push_walk_state");
605 walk_state->next = thread->walk_state_list;
606 thread->walk_state_list = walk_state;
608 return_VOID;
612 /*******************************************************************************
614 * FUNCTION: acpi_ds_pop_walk_state
616 * PARAMETERS: Thread - Current thread state
618 * RETURN: A walk_state object popped from the thread's stack
620 * DESCRIPTION: Remove and return the walkstate object that is at the head of
621 * the walk stack for the given walk list. NULL indicates that
622 * the list is empty.
624 ******************************************************************************/
626 struct acpi_walk_state *
627 acpi_ds_pop_walk_state (
628 struct acpi_thread_state *thread)
630 struct acpi_walk_state *walk_state;
633 ACPI_FUNCTION_TRACE ("ds_pop_walk_state");
636 walk_state = thread->walk_state_list;
638 if (walk_state) {
639 /* Next walk state becomes the current walk state */
641 thread->walk_state_list = walk_state->next;
644 * Don't clear the NEXT field, this serves as an indicator
645 * that there is a parent WALK STATE
646 * Do Not: walk_state->Next = NULL;
650 return_PTR (walk_state);
654 /*******************************************************************************
656 * FUNCTION: acpi_ds_create_walk_state
658 * PARAMETERS: owner_id - ID for object creation
659 * Origin - Starting point for this walk
660 * mth_desc - Method object
661 * Thread - Current thread state
663 * RETURN: Pointer to the new walk state.
665 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
666 * state is set to this new state.
668 ******************************************************************************/
670 struct acpi_walk_state *
671 acpi_ds_create_walk_state (
672 acpi_owner_id owner_id,
673 union acpi_parse_object *origin,
674 union acpi_operand_object *mth_desc,
675 struct acpi_thread_state *thread)
677 struct acpi_walk_state *walk_state;
678 acpi_status status;
681 ACPI_FUNCTION_TRACE ("ds_create_walk_state");
684 walk_state = ACPI_MEM_CALLOCATE (sizeof (struct acpi_walk_state));
685 if (!walk_state) {
686 return_PTR (NULL);
689 walk_state->data_type = ACPI_DESC_TYPE_WALK;
690 walk_state->owner_id = owner_id;
691 walk_state->origin = origin;
692 walk_state->method_desc = mth_desc;
693 walk_state->thread = thread;
695 walk_state->parser_state.start_op = origin;
697 /* Init the method args/local */
699 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
700 acpi_ds_method_data_init (walk_state);
701 #endif
703 /* Create an initial result stack entry */
705 status = acpi_ds_result_stack_push (walk_state);
706 if (ACPI_FAILURE (status)) {
707 ACPI_MEM_FREE (walk_state);
708 return_PTR (NULL);
711 /* Put the new state at the head of the walk list */
713 if (thread) {
714 acpi_ds_push_walk_state (walk_state, thread);
717 return_PTR (walk_state);
721 /*******************************************************************************
723 * FUNCTION: acpi_ds_init_aml_walk
725 * PARAMETERS: walk_state - New state to be initialized
726 * Op - Current parse op
727 * method_node - Control method NS node, if any
728 * aml_start - Start of AML
729 * aml_length - Length of AML
730 * Info - Method info block (params, etc.)
731 * pass_number - 1, 2, or 3
733 * RETURN: Status
735 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
737 ******************************************************************************/
739 acpi_status
740 acpi_ds_init_aml_walk (
741 struct acpi_walk_state *walk_state,
742 union acpi_parse_object *op,
743 struct acpi_namespace_node *method_node,
744 u8 *aml_start,
745 u32 aml_length,
746 struct acpi_parameter_info *info,
747 u8 pass_number)
749 acpi_status status;
750 struct acpi_parse_state *parser_state = &walk_state->parser_state;
751 union acpi_parse_object *extra_op;
754 ACPI_FUNCTION_TRACE ("ds_init_aml_walk");
757 walk_state->parser_state.aml =
758 walk_state->parser_state.aml_start = aml_start;
759 walk_state->parser_state.aml_end =
760 walk_state->parser_state.pkg_end = aml_start + aml_length;
762 /* The next_op of the next_walk will be the beginning of the method */
764 walk_state->next_op = NULL;
765 walk_state->pass_number = pass_number;
767 if (info) {
768 if (info->parameter_type == ACPI_PARAM_GPE) {
769 walk_state->gpe_event_info = ACPI_CAST_PTR (struct acpi_gpe_event_info,
770 info->parameters);
772 else {
773 walk_state->params = info->parameters;
774 walk_state->caller_return_desc = &info->return_object;
778 status = acpi_ps_init_scope (&walk_state->parser_state, op);
779 if (ACPI_FAILURE (status)) {
780 return_ACPI_STATUS (status);
783 if (method_node) {
784 walk_state->parser_state.start_node = method_node;
785 walk_state->walk_type = ACPI_WALK_METHOD;
786 walk_state->method_node = method_node;
787 walk_state->method_desc = acpi_ns_get_attached_object (method_node);
789 /* Push start scope on scope stack and make it current */
791 status = acpi_ds_scope_stack_push (method_node, ACPI_TYPE_METHOD, walk_state);
792 if (ACPI_FAILURE (status)) {
793 return_ACPI_STATUS (status);
796 /* Init the method arguments */
798 status = acpi_ds_method_data_init_args (walk_state->params,
799 ACPI_METHOD_NUM_ARGS, walk_state);
800 if (ACPI_FAILURE (status)) {
801 return_ACPI_STATUS (status);
804 else {
806 * Setup the current scope.
807 * Find a Named Op that has a namespace node associated with it.
808 * search upwards from this Op. Current scope is the first
809 * Op with a namespace node.
811 extra_op = parser_state->start_op;
812 while (extra_op && !extra_op->common.node) {
813 extra_op = extra_op->common.parent;
816 if (!extra_op) {
817 parser_state->start_node = NULL;
819 else {
820 parser_state->start_node = extra_op->common.node;
823 if (parser_state->start_node) {
824 /* Push start scope on scope stack and make it current */
826 status = acpi_ds_scope_stack_push (parser_state->start_node,
827 parser_state->start_node->type, walk_state);
828 if (ACPI_FAILURE (status)) {
829 return_ACPI_STATUS (status);
834 status = acpi_ds_init_callbacks (walk_state, pass_number);
835 return_ACPI_STATUS (status);
839 /*******************************************************************************
841 * FUNCTION: acpi_ds_delete_walk_state
843 * PARAMETERS: walk_state - State to delete
845 * RETURN: Status
847 * DESCRIPTION: Delete a walk state including all internal data structures
849 ******************************************************************************/
851 void
852 acpi_ds_delete_walk_state (
853 struct acpi_walk_state *walk_state)
855 union acpi_generic_state *state;
858 ACPI_FUNCTION_TRACE_PTR ("ds_delete_walk_state", walk_state);
861 if (!walk_state) {
862 return;
865 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
866 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p is not a valid walk state\n",
867 walk_state));
868 return;
871 if (walk_state->parser_state.scope) {
872 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%p walk still has a scope list\n",
873 walk_state));
876 /* Always must free any linked control states */
878 while (walk_state->control_state) {
879 state = walk_state->control_state;
880 walk_state->control_state = state->common.next;
882 acpi_ut_delete_generic_state (state);
885 /* Always must free any linked parse states */
887 while (walk_state->scope_info) {
888 state = walk_state->scope_info;
889 walk_state->scope_info = state->common.next;
891 acpi_ut_delete_generic_state (state);
894 /* Always must free any stacked result states */
896 while (walk_state->results) {
897 state = walk_state->results;
898 walk_state->results = state->common.next;
900 acpi_ut_delete_generic_state (state);
903 ACPI_MEM_FREE (walk_state);
904 return_VOID;
908 #ifdef ACPI_OBSOLETE_FUNCTIONS
909 /*******************************************************************************
911 * FUNCTION: acpi_ds_result_insert
913 * PARAMETERS: Object - Object to push
914 * Index - Where to insert the object
915 * walk_state - Current Walk state
917 * RETURN: Status
919 * DESCRIPTION: Insert an object onto this walk's result stack
921 ******************************************************************************/
923 acpi_status
924 acpi_ds_result_insert (
925 void *object,
926 u32 index,
927 struct acpi_walk_state *walk_state)
929 union acpi_generic_state *state;
932 ACPI_FUNCTION_NAME ("ds_result_insert");
935 state = walk_state->results;
936 if (!state) {
937 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No result object pushed! State=%p\n",
938 walk_state));
939 return (AE_NOT_EXIST);
942 if (index >= ACPI_OBJ_NUM_OPERANDS) {
943 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
944 "Index out of range: %X Obj=%p State=%p Num=%X\n",
945 index, object, walk_state, state->results.num_results));
946 return (AE_BAD_PARAMETER);
949 if (!object) {
950 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
951 "Null Object! Index=%X Obj=%p State=%p Num=%X\n",
952 index, object, walk_state, state->results.num_results));
953 return (AE_BAD_PARAMETER);
956 state->results.obj_desc [index] = object;
957 state->results.num_results++;
959 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
960 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
961 object, object ? acpi_ut_get_object_type_name ((union acpi_operand_object *) object) : "NULL",
962 walk_state, state->results.num_results, walk_state->current_result));
964 return (AE_OK);
968 /*******************************************************************************
970 * FUNCTION: acpi_ds_obj_stack_delete_all
972 * PARAMETERS: walk_state - Current Walk state
974 * RETURN: Status
976 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
977 * Should be used with great care, if at all!
979 ******************************************************************************/
981 acpi_status
982 acpi_ds_obj_stack_delete_all (
983 struct acpi_walk_state *walk_state)
985 u32 i;
988 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_delete_all", walk_state);
991 /* The stack size is configurable, but fixed */
993 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
994 if (walk_state->operands[i]) {
995 acpi_ut_remove_reference (walk_state->operands[i]);
996 walk_state->operands[i] = NULL;
1000 return_ACPI_STATUS (AE_OK);
1004 /*******************************************************************************
1006 * FUNCTION: acpi_ds_obj_stack_pop_object
1008 * PARAMETERS: Object - Where to return the popped object
1009 * walk_state - Current Walk state
1011 * RETURN: Status
1013 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
1014 * deleted by this routine.
1016 ******************************************************************************/
1018 acpi_status
1019 acpi_ds_obj_stack_pop_object (
1020 union acpi_operand_object **object,
1021 struct acpi_walk_state *walk_state)
1023 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_object");
1026 /* Check for stack underflow */
1028 if (walk_state->num_operands == 0) {
1029 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1030 "Missing operand/stack empty! State=%p #Ops=%X\n",
1031 walk_state, walk_state->num_operands));
1032 *object = NULL;
1033 return (AE_AML_NO_OPERAND);
1036 /* Pop the stack */
1038 walk_state->num_operands--;
1040 /* Check for a valid operand */
1042 if (!walk_state->operands [walk_state->num_operands]) {
1043 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1044 "Null operand! State=%p #Ops=%X\n",
1045 walk_state, walk_state->num_operands));
1046 *object = NULL;
1047 return (AE_AML_NO_OPERAND);
1050 /* Get operand and set stack entry to null */
1052 *object = walk_state->operands [walk_state->num_operands];
1053 walk_state->operands [walk_state->num_operands] = NULL;
1055 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1056 *object, acpi_ut_get_object_type_name (*object),
1057 walk_state, walk_state->num_operands));
1059 return (AE_OK);
1063 /*******************************************************************************
1065 * FUNCTION: acpi_ds_obj_stack_get_value
1067 * PARAMETERS: Index - Stack index whose value is desired. Based
1068 * on the top of the stack (index=0 == top)
1069 * walk_state - Current Walk state
1071 * RETURN: Pointer to the requested operand
1073 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1074 * be within the range of the current stack pointer.
1076 ******************************************************************************/
1078 void *
1079 acpi_ds_obj_stack_get_value (
1080 u32 index,
1081 struct acpi_walk_state *walk_state)
1084 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_get_value", walk_state);
1087 /* Can't do it if the stack is empty */
1089 if (walk_state->num_operands == 0) {
1090 return_PTR (NULL);
1093 /* or if the index is past the top of the stack */
1095 if (index > (walk_state->num_operands - (u32) 1)) {
1096 return_PTR (NULL);
1099 return_PTR (walk_state->operands[(acpi_native_uint)(walk_state->num_operands - 1) -
1100 index]);
1102 #endif