1 /******************************************************************************
3 * Module Name: dswstate - Dispatcher parse tree walk management routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/acparser.h>
46 #include <acpi/acdispat.h>
47 #include <acpi/acnamesp.h>
49 #define _COMPONENT ACPI_DISPATCHER
50 ACPI_MODULE_NAME("dswstate")
52 /* Local prototypes */
53 #ifdef ACPI_OBSOLETE_FUNCTIONS
55 acpi_ds_result_insert(void *object,
56 u32 index, struct acpi_walk_state *walk_state);
58 acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state *walk_state);
61 acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
62 struct acpi_walk_state *walk_state);
64 void *acpi_ds_obj_stack_get_value(u32 index,
65 struct acpi_walk_state *walk_state);
68 #ifdef ACPI_FUTURE_USAGE
70 /*******************************************************************************
72 * FUNCTION: acpi_ds_result_remove
74 * PARAMETERS: Object - Where to return the popped object
75 * Index - Where to extract the object
76 * walk_state - Current Walk state
80 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
81 * other words, this is a FIFO.
83 ******************************************************************************/
86 acpi_ds_result_remove(union acpi_operand_object **object,
87 u32 index, struct acpi_walk_state *walk_state)
89 union acpi_generic_state *state;
91 ACPI_FUNCTION_NAME("ds_result_remove");
93 state = walk_state->results;
95 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
96 "No result object pushed! State=%p\n",
98 return (AE_NOT_EXIST);
101 if (index >= ACPI_OBJ_MAX_OPERAND) {
102 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
103 "Index out of range: %X State=%p Num=%X\n",
105 state->results.num_results));
108 /* Check for a valid result object */
110 if (!state->results.obj_desc[index]) {
111 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
112 "Null operand! State=%p #Ops=%X, Index=%X\n",
113 walk_state, state->results.num_results,
115 return (AE_AML_NO_RETURN_VALUE);
118 /* Remove the object */
120 state->results.num_results--;
122 *object = state->results.obj_desc[index];
123 state->results.obj_desc[index] = NULL;
125 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
126 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
128 (*object) ? acpi_ut_get_object_type_name(*object) :
129 "NULL", index, walk_state,
130 state->results.num_results));
135 #endif /* ACPI_FUTURE_USAGE */
137 /*******************************************************************************
139 * FUNCTION: acpi_ds_result_pop
141 * PARAMETERS: Object - Where to return the popped object
142 * walk_state - Current Walk state
146 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
147 * other words, this is a FIFO.
149 ******************************************************************************/
152 acpi_ds_result_pop(union acpi_operand_object ** object,
153 struct acpi_walk_state * walk_state)
155 acpi_native_uint index;
156 union acpi_generic_state *state;
158 ACPI_FUNCTION_NAME("ds_result_pop");
160 state = walk_state->results;
165 if (!state->results.num_results) {
166 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
167 "Result stack is empty! State=%p\n",
169 return (AE_AML_NO_RETURN_VALUE);
172 /* Remove top element */
174 state->results.num_results--;
176 for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
177 /* Check for a valid result object */
179 if (state->results.obj_desc[index - 1]) {
180 *object = state->results.obj_desc[index - 1];
181 state->results.obj_desc[index - 1] = NULL;
183 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
184 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
187 acpi_ut_get_object_type_name(*object)
188 : "NULL", (u32) index - 1, walk_state,
189 state->results.num_results));
195 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
196 "No result objects! State=%p\n", walk_state));
197 return (AE_AML_NO_RETURN_VALUE);
200 /*******************************************************************************
202 * FUNCTION: acpi_ds_result_pop_from_bottom
204 * PARAMETERS: Object - Where to return the popped object
205 * walk_state - Current Walk state
209 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
210 * other words, this is a FIFO.
212 ******************************************************************************/
215 acpi_ds_result_pop_from_bottom(union acpi_operand_object ** object,
216 struct acpi_walk_state * walk_state)
218 acpi_native_uint index;
219 union acpi_generic_state *state;
221 ACPI_FUNCTION_NAME("ds_result_pop_from_bottom");
223 state = walk_state->results;
225 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
226 "Warning: No result object pushed! State=%p\n",
228 return (AE_NOT_EXIST);
231 if (!state->results.num_results) {
232 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
233 "No result objects! State=%p\n", walk_state));
234 return (AE_AML_NO_RETURN_VALUE);
237 /* Remove Bottom element */
239 *object = state->results.obj_desc[0];
241 /* Push entire stack down one element */
243 for (index = 0; index < state->results.num_results; index++) {
244 state->results.obj_desc[index] =
245 state->results.obj_desc[index + 1];
248 state->results.num_results--;
250 /* Check for a valid result object */
253 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
254 "Null operand! State=%p #Ops=%X Index=%X\n",
255 walk_state, state->results.num_results,
257 return (AE_AML_NO_RETURN_VALUE);
260 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n",
262 (*object) ? acpi_ut_get_object_type_name(*object) :
263 "NULL", state, walk_state));
268 /*******************************************************************************
270 * FUNCTION: acpi_ds_result_push
272 * PARAMETERS: Object - Where to return the popped object
273 * walk_state - Current Walk state
277 * DESCRIPTION: Push an object onto the current result stack
279 ******************************************************************************/
282 acpi_ds_result_push(union acpi_operand_object * object,
283 struct acpi_walk_state * walk_state)
285 union acpi_generic_state *state;
287 ACPI_FUNCTION_NAME("ds_result_push");
289 state = walk_state->results;
291 ACPI_REPORT_ERROR(("No result stack frame during push\n"));
292 return (AE_AML_INTERNAL);
295 if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
296 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
297 "Result stack overflow: Obj=%p State=%p Num=%X\n",
299 state->results.num_results));
300 return (AE_STACK_OVERFLOW);
304 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
305 "Null Object! Obj=%p State=%p Num=%X\n",
307 state->results.num_results));
308 return (AE_BAD_PARAMETER);
311 state->results.obj_desc[state->results.num_results] = object;
312 state->results.num_results++;
314 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
317 acpi_ut_get_object_type_name((union
318 acpi_operand_object *)
320 walk_state, state->results.num_results,
321 walk_state->current_result));
326 /*******************************************************************************
328 * FUNCTION: acpi_ds_result_stack_push
330 * PARAMETERS: walk_state - Current Walk state
334 * DESCRIPTION: Push an object onto the walk_state result stack.
336 ******************************************************************************/
338 acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state)
340 union acpi_generic_state *state;
342 ACPI_FUNCTION_NAME("ds_result_stack_push");
344 state = acpi_ut_create_generic_state();
346 return (AE_NO_MEMORY);
349 state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT;
350 acpi_ut_push_generic_state(&walk_state->results, state);
352 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
358 /*******************************************************************************
360 * FUNCTION: acpi_ds_result_stack_pop
362 * PARAMETERS: walk_state - Current Walk state
366 * DESCRIPTION: Pop an object off of the walk_state result stack.
368 ******************************************************************************/
370 acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state)
372 union acpi_generic_state *state;
374 ACPI_FUNCTION_NAME("ds_result_stack_pop");
376 /* Check for stack underflow */
378 if (walk_state->results == NULL) {
379 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n",
381 return (AE_AML_NO_OPERAND);
384 state = acpi_ut_pop_generic_state(&walk_state->results);
386 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
387 "Result=%p remaining_results=%X State=%p\n",
388 state, state->results.num_results, walk_state));
390 acpi_ut_delete_generic_state(state);
395 /*******************************************************************************
397 * FUNCTION: acpi_ds_obj_stack_push
399 * PARAMETERS: Object - Object to push
400 * walk_state - Current Walk state
404 * DESCRIPTION: Push an object onto this walk's object/operand stack
406 ******************************************************************************/
409 acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
411 ACPI_FUNCTION_NAME("ds_obj_stack_push");
413 /* Check for stack overflow */
415 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
416 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
417 "overflow! Obj=%p State=%p #Ops=%X\n",
419 walk_state->num_operands));
420 return (AE_STACK_OVERFLOW);
423 /* Put the object onto the stack */
425 walk_state->operands[walk_state->num_operands] = object;
426 walk_state->num_operands++;
428 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
430 acpi_ut_get_object_type_name((union
431 acpi_operand_object *)
433 walk_state->num_operands));
438 /*******************************************************************************
440 * FUNCTION: acpi_ds_obj_stack_pop
442 * PARAMETERS: pop_count - Number of objects/entries to pop
443 * walk_state - Current Walk state
447 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
448 * deleted by this routine.
450 ******************************************************************************/
453 acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
457 ACPI_FUNCTION_NAME("ds_obj_stack_pop");
459 for (i = 0; i < pop_count; i++) {
460 /* Check for stack underflow */
462 if (walk_state->num_operands == 0) {
463 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
464 "Underflow! Count=%X State=%p #Ops=%X\n",
465 pop_count, walk_state,
466 walk_state->num_operands));
467 return (AE_STACK_UNDERFLOW);
470 /* Just set the stack entry to null */
472 walk_state->num_operands--;
473 walk_state->operands[walk_state->num_operands] = NULL;
476 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
477 pop_count, walk_state, walk_state->num_operands));
482 /*******************************************************************************
484 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
486 * PARAMETERS: pop_count - Number of objects/entries to pop
487 * walk_state - Current Walk state
491 * DESCRIPTION: Pop this walk's object stack and delete each object that is
494 ******************************************************************************/
497 acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
498 struct acpi_walk_state * walk_state)
501 union acpi_operand_object *obj_desc;
503 ACPI_FUNCTION_NAME("ds_obj_stack_pop_and_delete");
505 for (i = 0; i < pop_count; i++) {
506 /* Check for stack underflow */
508 if (walk_state->num_operands == 0) {
509 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
510 "Underflow! Count=%X State=%p #Ops=%X\n",
511 pop_count, walk_state,
512 walk_state->num_operands));
513 return (AE_STACK_UNDERFLOW);
516 /* Pop the stack and delete an object if present in this stack entry */
518 walk_state->num_operands--;
519 obj_desc = walk_state->operands[walk_state->num_operands];
521 acpi_ut_remove_reference(walk_state->
522 operands[walk_state->
524 walk_state->operands[walk_state->num_operands] = NULL;
528 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
529 pop_count, walk_state, walk_state->num_operands));
534 /*******************************************************************************
536 * FUNCTION: acpi_ds_get_current_walk_state
538 * PARAMETERS: Thread - Get current active state for this Thread
540 * RETURN: Pointer to the current walk state
542 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
545 ******************************************************************************/
547 struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
550 ACPI_FUNCTION_NAME("ds_get_current_walk_state");
556 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current walk_state %p\n",
557 thread->walk_state_list));
559 return (thread->walk_state_list);
562 /*******************************************************************************
564 * FUNCTION: acpi_ds_push_walk_state
566 * PARAMETERS: walk_state - State to push
567 * Thread - Thread state object
571 * DESCRIPTION: Place the Thread state at the head of the state list.
573 ******************************************************************************/
576 acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
577 struct acpi_thread_state *thread)
579 ACPI_FUNCTION_TRACE("ds_push_walk_state");
581 walk_state->next = thread->walk_state_list;
582 thread->walk_state_list = walk_state;
587 /*******************************************************************************
589 * FUNCTION: acpi_ds_pop_walk_state
591 * PARAMETERS: Thread - Current thread state
593 * RETURN: A walk_state object popped from the thread's stack
595 * DESCRIPTION: Remove and return the walkstate object that is at the head of
596 * the walk stack for the given walk list. NULL indicates that
599 ******************************************************************************/
601 struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
603 struct acpi_walk_state *walk_state;
605 ACPI_FUNCTION_TRACE("ds_pop_walk_state");
607 walk_state = thread->walk_state_list;
610 /* Next walk state becomes the current walk state */
612 thread->walk_state_list = walk_state->next;
615 * Don't clear the NEXT field, this serves as an indicator
616 * that there is a parent WALK STATE
617 * Do Not: walk_state->Next = NULL;
621 return_PTR(walk_state);
624 /*******************************************************************************
626 * FUNCTION: acpi_ds_create_walk_state
628 * PARAMETERS: owner_id - ID for object creation
629 * Origin - Starting point for this walk
630 * mth_desc - Method object
631 * Thread - Current thread state
633 * RETURN: Pointer to the new walk state.
635 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
636 * state is set to this new state.
638 ******************************************************************************/
640 struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
641 union acpi_parse_object
643 union acpi_operand_object
645 struct acpi_thread_state
648 struct acpi_walk_state *walk_state;
651 ACPI_FUNCTION_TRACE("ds_create_walk_state");
653 walk_state = ACPI_MEM_CALLOCATE(sizeof(struct acpi_walk_state));
658 walk_state->data_type = ACPI_DESC_TYPE_WALK;
659 walk_state->owner_id = owner_id;
660 walk_state->origin = origin;
661 walk_state->method_desc = mth_desc;
662 walk_state->thread = thread;
664 walk_state->parser_state.start_op = origin;
666 /* Init the method args/local */
668 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
669 acpi_ds_method_data_init(walk_state);
672 /* Create an initial result stack entry */
674 status = acpi_ds_result_stack_push(walk_state);
675 if (ACPI_FAILURE(status)) {
676 ACPI_MEM_FREE(walk_state);
680 /* Put the new state at the head of the walk list */
683 acpi_ds_push_walk_state(walk_state, thread);
686 return_PTR(walk_state);
689 /*******************************************************************************
691 * FUNCTION: acpi_ds_init_aml_walk
693 * PARAMETERS: walk_state - New state to be initialized
694 * Op - Current parse op
695 * method_node - Control method NS node, if any
696 * aml_start - Start of AML
697 * aml_length - Length of AML
698 * Info - Method info block (params, etc.)
699 * pass_number - 1, 2, or 3
703 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
705 ******************************************************************************/
708 acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
709 union acpi_parse_object *op,
710 struct acpi_namespace_node *method_node,
713 struct acpi_parameter_info *info, u8 pass_number)
716 struct acpi_parse_state *parser_state = &walk_state->parser_state;
717 union acpi_parse_object *extra_op;
719 ACPI_FUNCTION_TRACE("ds_init_aml_walk");
721 walk_state->parser_state.aml =
722 walk_state->parser_state.aml_start = aml_start;
723 walk_state->parser_state.aml_end =
724 walk_state->parser_state.pkg_end = aml_start + aml_length;
726 /* The next_op of the next_walk will be the beginning of the method */
728 walk_state->next_op = NULL;
729 walk_state->pass_number = pass_number;
732 if (info->parameter_type == ACPI_PARAM_GPE) {
733 walk_state->gpe_event_info =
734 ACPI_CAST_PTR(struct acpi_gpe_event_info,
737 walk_state->params = info->parameters;
738 walk_state->caller_return_desc = &info->return_object;
742 status = acpi_ps_init_scope(&walk_state->parser_state, op);
743 if (ACPI_FAILURE(status)) {
744 return_ACPI_STATUS(status);
748 walk_state->parser_state.start_node = method_node;
749 walk_state->walk_type = ACPI_WALK_METHOD;
750 walk_state->method_node = method_node;
751 walk_state->method_desc =
752 acpi_ns_get_attached_object(method_node);
754 /* Push start scope on scope stack and make it current */
757 acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
759 if (ACPI_FAILURE(status)) {
760 return_ACPI_STATUS(status);
763 /* Init the method arguments */
765 status = acpi_ds_method_data_init_args(walk_state->params,
766 ACPI_METHOD_NUM_ARGS,
768 if (ACPI_FAILURE(status)) {
769 return_ACPI_STATUS(status);
773 * Setup the current scope.
774 * Find a Named Op that has a namespace node associated with it.
775 * search upwards from this Op. Current scope is the first
776 * Op with a namespace node.
778 extra_op = parser_state->start_op;
779 while (extra_op && !extra_op->common.node) {
780 extra_op = extra_op->common.parent;
784 parser_state->start_node = NULL;
786 parser_state->start_node = extra_op->common.node;
789 if (parser_state->start_node) {
790 /* Push start scope on scope stack and make it current */
793 acpi_ds_scope_stack_push(parser_state->start_node,
794 parser_state->start_node->
796 if (ACPI_FAILURE(status)) {
797 return_ACPI_STATUS(status);
802 status = acpi_ds_init_callbacks(walk_state, pass_number);
803 return_ACPI_STATUS(status);
806 /*******************************************************************************
808 * FUNCTION: acpi_ds_delete_walk_state
810 * PARAMETERS: walk_state - State to delete
814 * DESCRIPTION: Delete a walk state including all internal data structures
816 ******************************************************************************/
818 void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
820 union acpi_generic_state *state;
822 ACPI_FUNCTION_TRACE_PTR("ds_delete_walk_state", walk_state);
828 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
829 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
830 "%p is not a valid walk state\n",
835 if (walk_state->parser_state.scope) {
836 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
837 "%p walk still has a scope list\n",
841 /* Always must free any linked control states */
843 while (walk_state->control_state) {
844 state = walk_state->control_state;
845 walk_state->control_state = state->common.next;
847 acpi_ut_delete_generic_state(state);
850 /* Always must free any linked parse states */
852 while (walk_state->scope_info) {
853 state = walk_state->scope_info;
854 walk_state->scope_info = state->common.next;
856 acpi_ut_delete_generic_state(state);
859 /* Always must free any stacked result states */
861 while (walk_state->results) {
862 state = walk_state->results;
863 walk_state->results = state->common.next;
865 acpi_ut_delete_generic_state(state);
868 ACPI_MEM_FREE(walk_state);
872 #ifdef ACPI_OBSOLETE_FUNCTIONS
873 /*******************************************************************************
875 * FUNCTION: acpi_ds_result_insert
877 * PARAMETERS: Object - Object to push
878 * Index - Where to insert the object
879 * walk_state - Current Walk state
883 * DESCRIPTION: Insert an object onto this walk's result stack
885 ******************************************************************************/
888 acpi_ds_result_insert(void *object,
889 u32 index, struct acpi_walk_state *walk_state)
891 union acpi_generic_state *state;
893 ACPI_FUNCTION_NAME("ds_result_insert");
895 state = walk_state->results;
897 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
898 "No result object pushed! State=%p\n",
900 return (AE_NOT_EXIST);
903 if (index >= ACPI_OBJ_NUM_OPERANDS) {
904 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
905 "Index out of range: %X Obj=%p State=%p Num=%X\n",
906 index, object, walk_state,
907 state->results.num_results));
908 return (AE_BAD_PARAMETER);
912 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
913 "Null Object! Index=%X Obj=%p State=%p Num=%X\n",
914 index, object, walk_state,
915 state->results.num_results));
916 return (AE_BAD_PARAMETER);
919 state->results.obj_desc[index] = object;
920 state->results.num_results++;
922 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
923 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
926 acpi_ut_get_object_type_name((union
927 acpi_operand_object *)
929 walk_state, state->results.num_results,
930 walk_state->current_result));
935 /*******************************************************************************
937 * FUNCTION: acpi_ds_obj_stack_delete_all
939 * PARAMETERS: walk_state - Current Walk state
943 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
944 * Should be used with great care, if at all!
946 ******************************************************************************/
948 acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state * walk_state)
952 ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_delete_all", walk_state);
954 /* The stack size is configurable, but fixed */
956 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
957 if (walk_state->operands[i]) {
958 acpi_ut_remove_reference(walk_state->operands[i]);
959 walk_state->operands[i] = NULL;
963 return_ACPI_STATUS(AE_OK);
966 /*******************************************************************************
968 * FUNCTION: acpi_ds_obj_stack_pop_object
970 * PARAMETERS: Object - Where to return the popped object
971 * walk_state - Current Walk state
975 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
976 * deleted by this routine.
978 ******************************************************************************/
981 acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
982 struct acpi_walk_state *walk_state)
984 ACPI_FUNCTION_NAME("ds_obj_stack_pop_object");
986 /* Check for stack underflow */
988 if (walk_state->num_operands == 0) {
989 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
990 "Missing operand/stack empty! State=%p #Ops=%X\n",
991 walk_state, walk_state->num_operands));
993 return (AE_AML_NO_OPERAND);
998 walk_state->num_operands--;
1000 /* Check for a valid operand */
1002 if (!walk_state->operands[walk_state->num_operands]) {
1003 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1004 "Null operand! State=%p #Ops=%X\n",
1005 walk_state, walk_state->num_operands));
1007 return (AE_AML_NO_OPERAND);
1010 /* Get operand and set stack entry to null */
1012 *object = walk_state->operands[walk_state->num_operands];
1013 walk_state->operands[walk_state->num_operands] = NULL;
1015 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1016 *object, acpi_ut_get_object_type_name(*object),
1017 walk_state, walk_state->num_operands));
1022 /*******************************************************************************
1024 * FUNCTION: acpi_ds_obj_stack_get_value
1026 * PARAMETERS: Index - Stack index whose value is desired. Based
1027 * on the top of the stack (index=0 == top)
1028 * walk_state - Current Walk state
1030 * RETURN: Pointer to the requested operand
1032 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1033 * be within the range of the current stack pointer.
1035 ******************************************************************************/
1037 void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state)
1040 ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_get_value", walk_state);
1042 /* Can't do it if the stack is empty */
1044 if (walk_state->num_operands == 0) {
1048 /* or if the index is past the top of the stack */
1050 if (index > (walk_state->num_operands - (u32) 1)) {
1054 return_PTR(walk_state->
1055 operands[(acpi_native_uint) (walk_state->num_operands - 1) -