[ACPI] ACPICA 20050729 from Bob Moore
[deliverable/linux.git] / drivers / acpi / dispatcher / dswstate.c
1 /******************************************************************************
2 *
3 * Module Name: dswstate - Dispatcher parse tree walk management routines
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acnamesp.h>
49
50 #define _COMPONENT ACPI_DISPATCHER
51 ACPI_MODULE_NAME ("dswstate")
52
53 /* Local prototypes */
54
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);
61
62 acpi_status
63 acpi_ds_obj_stack_delete_all (
64 struct acpi_walk_state *walk_state);
65
66 acpi_status
67 acpi_ds_obj_stack_pop_object (
68 union acpi_operand_object **object,
69 struct acpi_walk_state *walk_state);
70
71 void *
72 acpi_ds_obj_stack_get_value (
73 u32 index,
74 struct acpi_walk_state *walk_state);
75 #endif
76
77 #ifdef ACPI_FUTURE_USAGE
78
79 /*******************************************************************************
80 *
81 * FUNCTION: acpi_ds_result_remove
82 *
83 * PARAMETERS: Object - Where to return the popped object
84 * Index - Where to extract the object
85 * walk_state - Current Walk state
86 *
87 * RETURN: Status
88 *
89 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
90 * other words, this is a FIFO.
91 *
92 ******************************************************************************/
93
94 acpi_status
95 acpi_ds_result_remove (
96 union acpi_operand_object **object,
97 u32 index,
98 struct acpi_walk_state *walk_state)
99 {
100 union acpi_generic_state *state;
101
102
103 ACPI_FUNCTION_NAME ("ds_result_remove");
104
105
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);
111 }
112
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));
117 }
118
119 /* Check for a valid result object */
120
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);
126 }
127
128 /* Remove the object */
129
130 state->results.num_results--;
131
132 *object = state->results.obj_desc [index];
133 state->results.obj_desc [index] = NULL;
134
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));
139
140 return (AE_OK);
141 }
142
143 #endif /* ACPI_FUTURE_USAGE */
144
145 /*******************************************************************************
146 *
147 * FUNCTION: acpi_ds_result_pop
148 *
149 * PARAMETERS: Object - Where to return the popped object
150 * walk_state - Current Walk state
151 *
152 * RETURN: Status
153 *
154 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
155 * other words, this is a FIFO.
156 *
157 ******************************************************************************/
158
159 acpi_status
160 acpi_ds_result_pop (
161 union acpi_operand_object **object,
162 struct acpi_walk_state *walk_state)
163 {
164 acpi_native_uint index;
165 union acpi_generic_state *state;
166
167
168 ACPI_FUNCTION_NAME ("ds_result_pop");
169
170
171 state = walk_state->results;
172 if (!state) {
173 return (AE_OK);
174 }
175
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);
180 }
181
182 /* Remove top element */
183
184 state->results.num_results--;
185
186 for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
187 /* Check for a valid result object */
188
189 if (state->results.obj_desc [index -1]) {
190 *object = state->results.obj_desc [index -1];
191 state->results.obj_desc [index -1] = NULL;
192
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));
198
199 return (AE_OK);
200 }
201 }
202
203 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
204 "No result objects! State=%p\n", walk_state));
205 return (AE_AML_NO_RETURN_VALUE);
206 }
207
208
209 /*******************************************************************************
210 *
211 * FUNCTION: acpi_ds_result_pop_from_bottom
212 *
213 * PARAMETERS: Object - Where to return the popped object
214 * walk_state - Current Walk state
215 *
216 * RETURN: Status
217 *
218 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
219 * other words, this is a FIFO.
220 *
221 ******************************************************************************/
222
223 acpi_status
224 acpi_ds_result_pop_from_bottom (
225 union acpi_operand_object **object,
226 struct acpi_walk_state *walk_state)
227 {
228 acpi_native_uint index;
229 union acpi_generic_state *state;
230
231
232 ACPI_FUNCTION_NAME ("ds_result_pop_from_bottom");
233
234
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);
240 }
241
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);
246 }
247
248 /* Remove Bottom element */
249
250 *object = state->results.obj_desc [0];
251
252 /* Push entire stack down one element */
253
254 for (index = 0; index < state->results.num_results; index++) {
255 state->results.obj_desc [index] = state->results.obj_desc [index + 1];
256 }
257
258 state->results.num_results--;
259
260 /* Check for a valid result object */
261
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);
267 }
268
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));
272
273 return (AE_OK);
274 }
275
276
277 /*******************************************************************************
278 *
279 * FUNCTION: acpi_ds_result_push
280 *
281 * PARAMETERS: Object - Where to return the popped object
282 * walk_state - Current Walk state
283 *
284 * RETURN: Status
285 *
286 * DESCRIPTION: Push an object onto the current result stack
287 *
288 ******************************************************************************/
289
290 acpi_status
291 acpi_ds_result_push (
292 union acpi_operand_object *object,
293 struct acpi_walk_state *walk_state)
294 {
295 union acpi_generic_state *state;
296
297
298 ACPI_FUNCTION_NAME ("ds_result_push");
299
300
301 state = walk_state->results;
302 if (!state) {
303 ACPI_REPORT_ERROR (("No result stack frame during push\n"));
304 return (AE_AML_INTERNAL);
305 }
306
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);
312 }
313
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);
319 }
320
321 state->results.obj_desc [state->results.num_results] = object;
322 state->results.num_results++;
323
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));
327
328 return (AE_OK);
329 }
330
331
332 /*******************************************************************************
333 *
334 * FUNCTION: acpi_ds_result_stack_push
335 *
336 * PARAMETERS: walk_state - Current Walk state
337 *
338 * RETURN: Status
339 *
340 * DESCRIPTION: Push an object onto the walk_state result stack.
341 *
342 ******************************************************************************/
343
344 acpi_status
345 acpi_ds_result_stack_push (
346 struct acpi_walk_state *walk_state)
347 {
348 union acpi_generic_state *state;
349
350 ACPI_FUNCTION_NAME ("ds_result_stack_push");
351
352
353 state = acpi_ut_create_generic_state ();
354 if (!state) {
355 return (AE_NO_MEMORY);
356 }
357
358 state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT;
359 acpi_ut_push_generic_state (&walk_state->results, state);
360
361 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
362 state, walk_state));
363
364 return (AE_OK);
365 }
366
367
368 /*******************************************************************************
369 *
370 * FUNCTION: acpi_ds_result_stack_pop
371 *
372 * PARAMETERS: walk_state - Current Walk state
373 *
374 * RETURN: Status
375 *
376 * DESCRIPTION: Pop an object off of the walk_state result stack.
377 *
378 ******************************************************************************/
379
380 acpi_status
381 acpi_ds_result_stack_pop (
382 struct acpi_walk_state *walk_state)
383 {
384 union acpi_generic_state *state;
385
386 ACPI_FUNCTION_NAME ("ds_result_stack_pop");
387
388
389 /* Check for stack underflow */
390
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);
395 }
396
397 state = acpi_ut_pop_generic_state (&walk_state->results);
398
399 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
400 "Result=%p remaining_results=%X State=%p\n",
401 state, state->results.num_results, walk_state));
402
403 acpi_ut_delete_generic_state (state);
404
405 return (AE_OK);
406 }
407
408
409 /*******************************************************************************
410 *
411 * FUNCTION: acpi_ds_obj_stack_push
412 *
413 * PARAMETERS: Object - Object to push
414 * walk_state - Current Walk state
415 *
416 * RETURN: Status
417 *
418 * DESCRIPTION: Push an object onto this walk's object/operand stack
419 *
420 ******************************************************************************/
421
422 acpi_status
423 acpi_ds_obj_stack_push (
424 void *object,
425 struct acpi_walk_state *walk_state)
426 {
427 ACPI_FUNCTION_NAME ("ds_obj_stack_push");
428
429
430 /* Check for stack overflow */
431
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);
437 }
438
439 /* Put the object onto the stack */
440
441 walk_state->operands [walk_state->num_operands] = object;
442 walk_state->num_operands++;
443
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));
447
448 return (AE_OK);
449 }
450
451
452 /*******************************************************************************
453 *
454 * FUNCTION: acpi_ds_obj_stack_pop
455 *
456 * PARAMETERS: pop_count - Number of objects/entries to pop
457 * walk_state - Current Walk state
458 *
459 * RETURN: Status
460 *
461 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
462 * deleted by this routine.
463 *
464 ******************************************************************************/
465
466 acpi_status
467 acpi_ds_obj_stack_pop (
468 u32 pop_count,
469 struct acpi_walk_state *walk_state)
470 {
471 u32 i;
472
473 ACPI_FUNCTION_NAME ("ds_obj_stack_pop");
474
475
476 for (i = 0; i < pop_count; i++) {
477 /* Check for stack underflow */
478
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);
484 }
485
486 /* Just set the stack entry to null */
487
488 walk_state->num_operands--;
489 walk_state->operands [walk_state->num_operands] = NULL;
490 }
491
492 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
493 pop_count, walk_state, walk_state->num_operands));
494
495 return (AE_OK);
496 }
497
498
499 /*******************************************************************************
500 *
501 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
502 *
503 * PARAMETERS: pop_count - Number of objects/entries to pop
504 * walk_state - Current Walk state
505 *
506 * RETURN: Status
507 *
508 * DESCRIPTION: Pop this walk's object stack and delete each object that is
509 * popped off.
510 *
511 ******************************************************************************/
512
513 acpi_status
514 acpi_ds_obj_stack_pop_and_delete (
515 u32 pop_count,
516 struct acpi_walk_state *walk_state)
517 {
518 u32 i;
519 union acpi_operand_object *obj_desc;
520
521
522 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_and_delete");
523
524
525 for (i = 0; i < pop_count; i++) {
526 /* Check for stack underflow */
527
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);
533 }
534
535 /* Pop the stack and delete an object if present in this stack entry */
536
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;
542 }
543 }
544
545 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
546 pop_count, walk_state, walk_state->num_operands));
547
548 return (AE_OK);
549 }
550
551
552 /*******************************************************************************
553 *
554 * FUNCTION: acpi_ds_get_current_walk_state
555 *
556 * PARAMETERS: Thread - Get current active state for this Thread
557 *
558 * RETURN: Pointer to the current walk state
559 *
560 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
561 * walk state.)
562 *
563 ******************************************************************************/
564
565 struct acpi_walk_state *
566 acpi_ds_get_current_walk_state (
567 struct acpi_thread_state *thread)
568
569 {
570 ACPI_FUNCTION_NAME ("ds_get_current_walk_state");
571
572
573 if (!thread) {
574 return (NULL);
575 }
576
577 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current walk_state %p\n",
578 thread->walk_state_list));
579
580 return (thread->walk_state_list);
581 }
582
583
584 /*******************************************************************************
585 *
586 * FUNCTION: acpi_ds_push_walk_state
587 *
588 * PARAMETERS: walk_state - State to push
589 * Thread - Thread state object
590 *
591 * RETURN: None
592 *
593 * DESCRIPTION: Place the Thread state at the head of the state list.
594 *
595 ******************************************************************************/
596
597 void
598 acpi_ds_push_walk_state (
599 struct acpi_walk_state *walk_state,
600 struct acpi_thread_state *thread)
601 {
602 ACPI_FUNCTION_TRACE ("ds_push_walk_state");
603
604
605 walk_state->next = thread->walk_state_list;
606 thread->walk_state_list = walk_state;
607
608 return_VOID;
609 }
610
611
612 /*******************************************************************************
613 *
614 * FUNCTION: acpi_ds_pop_walk_state
615 *
616 * PARAMETERS: Thread - Current thread state
617 *
618 * RETURN: A walk_state object popped from the thread's stack
619 *
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.
623 *
624 ******************************************************************************/
625
626 struct acpi_walk_state *
627 acpi_ds_pop_walk_state (
628 struct acpi_thread_state *thread)
629 {
630 struct acpi_walk_state *walk_state;
631
632
633 ACPI_FUNCTION_TRACE ("ds_pop_walk_state");
634
635
636 walk_state = thread->walk_state_list;
637
638 if (walk_state) {
639 /* Next walk state becomes the current walk state */
640
641 thread->walk_state_list = walk_state->next;
642
643 /*
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;
647 */
648 }
649
650 return_PTR (walk_state);
651 }
652
653
654 /*******************************************************************************
655 *
656 * FUNCTION: acpi_ds_create_walk_state
657 *
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
662 *
663 * RETURN: Pointer to the new walk state.
664 *
665 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
666 * state is set to this new state.
667 *
668 ******************************************************************************/
669
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)
676 {
677 struct acpi_walk_state *walk_state;
678 acpi_status status;
679
680
681 ACPI_FUNCTION_TRACE ("ds_create_walk_state");
682
683
684 walk_state = ACPI_MEM_CALLOCATE (sizeof (struct acpi_walk_state));
685 if (!walk_state) {
686 return_PTR (NULL);
687 }
688
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;
694
695 walk_state->parser_state.start_op = origin;
696
697 /* Init the method args/local */
698
699 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
700 acpi_ds_method_data_init (walk_state);
701 #endif
702
703 /* Create an initial result stack entry */
704
705 status = acpi_ds_result_stack_push (walk_state);
706 if (ACPI_FAILURE (status)) {
707 ACPI_MEM_FREE (walk_state);
708 return_PTR (NULL);
709 }
710
711 /* Put the new state at the head of the walk list */
712
713 if (thread) {
714 acpi_ds_push_walk_state (walk_state, thread);
715 }
716
717 return_PTR (walk_state);
718 }
719
720
721 /*******************************************************************************
722 *
723 * FUNCTION: acpi_ds_init_aml_walk
724 *
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
732 *
733 * RETURN: Status
734 *
735 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
736 *
737 ******************************************************************************/
738
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)
748 {
749 acpi_status status;
750 struct acpi_parse_state *parser_state = &walk_state->parser_state;
751 union acpi_parse_object *extra_op;
752
753
754 ACPI_FUNCTION_TRACE ("ds_init_aml_walk");
755
756
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;
761
762 /* The next_op of the next_walk will be the beginning of the method */
763
764 walk_state->next_op = NULL;
765 walk_state->pass_number = pass_number;
766
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);
771 }
772 else {
773 walk_state->params = info->parameters;
774 walk_state->caller_return_desc = &info->return_object;
775 }
776 }
777
778 status = acpi_ps_init_scope (&walk_state->parser_state, op);
779 if (ACPI_FAILURE (status)) {
780 return_ACPI_STATUS (status);
781 }
782
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);
788
789 /* Push start scope on scope stack and make it current */
790
791 status = acpi_ds_scope_stack_push (method_node, ACPI_TYPE_METHOD, walk_state);
792 if (ACPI_FAILURE (status)) {
793 return_ACPI_STATUS (status);
794 }
795
796 /* Init the method arguments */
797
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);
802 }
803 }
804 else {
805 /*
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.
810 */
811 extra_op = parser_state->start_op;
812 while (extra_op && !extra_op->common.node) {
813 extra_op = extra_op->common.parent;
814 }
815
816 if (!extra_op) {
817 parser_state->start_node = NULL;
818 }
819 else {
820 parser_state->start_node = extra_op->common.node;
821 }
822
823 if (parser_state->start_node) {
824 /* Push start scope on scope stack and make it current */
825
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);
830 }
831 }
832 }
833
834 status = acpi_ds_init_callbacks (walk_state, pass_number);
835 return_ACPI_STATUS (status);
836 }
837
838
839 /*******************************************************************************
840 *
841 * FUNCTION: acpi_ds_delete_walk_state
842 *
843 * PARAMETERS: walk_state - State to delete
844 *
845 * RETURN: Status
846 *
847 * DESCRIPTION: Delete a walk state including all internal data structures
848 *
849 ******************************************************************************/
850
851 void
852 acpi_ds_delete_walk_state (
853 struct acpi_walk_state *walk_state)
854 {
855 union acpi_generic_state *state;
856
857
858 ACPI_FUNCTION_TRACE_PTR ("ds_delete_walk_state", walk_state);
859
860
861 if (!walk_state) {
862 return;
863 }
864
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;
869 }
870
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));
874 }
875
876 /* Always must free any linked control states */
877
878 while (walk_state->control_state) {
879 state = walk_state->control_state;
880 walk_state->control_state = state->common.next;
881
882 acpi_ut_delete_generic_state (state);
883 }
884
885 /* Always must free any linked parse states */
886
887 while (walk_state->scope_info) {
888 state = walk_state->scope_info;
889 walk_state->scope_info = state->common.next;
890
891 acpi_ut_delete_generic_state (state);
892 }
893
894 /* Always must free any stacked result states */
895
896 while (walk_state->results) {
897 state = walk_state->results;
898 walk_state->results = state->common.next;
899
900 acpi_ut_delete_generic_state (state);
901 }
902
903 ACPI_MEM_FREE (walk_state);
904 return_VOID;
905 }
906
907
908 #ifdef ACPI_OBSOLETE_FUNCTIONS
909 /*******************************************************************************
910 *
911 * FUNCTION: acpi_ds_result_insert
912 *
913 * PARAMETERS: Object - Object to push
914 * Index - Where to insert the object
915 * walk_state - Current Walk state
916 *
917 * RETURN: Status
918 *
919 * DESCRIPTION: Insert an object onto this walk's result stack
920 *
921 ******************************************************************************/
922
923 acpi_status
924 acpi_ds_result_insert (
925 void *object,
926 u32 index,
927 struct acpi_walk_state *walk_state)
928 {
929 union acpi_generic_state *state;
930
931
932 ACPI_FUNCTION_NAME ("ds_result_insert");
933
934
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);
940 }
941
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);
947 }
948
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);
954 }
955
956 state->results.obj_desc [index] = object;
957 state->results.num_results++;
958
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));
963
964 return (AE_OK);
965 }
966
967
968 /*******************************************************************************
969 *
970 * FUNCTION: acpi_ds_obj_stack_delete_all
971 *
972 * PARAMETERS: walk_state - Current Walk state
973 *
974 * RETURN: Status
975 *
976 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
977 * Should be used with great care, if at all!
978 *
979 ******************************************************************************/
980
981 acpi_status
982 acpi_ds_obj_stack_delete_all (
983 struct acpi_walk_state *walk_state)
984 {
985 u32 i;
986
987
988 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_delete_all", walk_state);
989
990
991 /* The stack size is configurable, but fixed */
992
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;
997 }
998 }
999
1000 return_ACPI_STATUS (AE_OK);
1001 }
1002
1003
1004 /*******************************************************************************
1005 *
1006 * FUNCTION: acpi_ds_obj_stack_pop_object
1007 *
1008 * PARAMETERS: Object - Where to return the popped object
1009 * walk_state - Current Walk state
1010 *
1011 * RETURN: Status
1012 *
1013 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
1014 * deleted by this routine.
1015 *
1016 ******************************************************************************/
1017
1018 acpi_status
1019 acpi_ds_obj_stack_pop_object (
1020 union acpi_operand_object **object,
1021 struct acpi_walk_state *walk_state)
1022 {
1023 ACPI_FUNCTION_NAME ("ds_obj_stack_pop_object");
1024
1025
1026 /* Check for stack underflow */
1027
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);
1034 }
1035
1036 /* Pop the stack */
1037
1038 walk_state->num_operands--;
1039
1040 /* Check for a valid operand */
1041
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);
1048 }
1049
1050 /* Get operand and set stack entry to null */
1051
1052 *object = walk_state->operands [walk_state->num_operands];
1053 walk_state->operands [walk_state->num_operands] = NULL;
1054
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));
1058
1059 return (AE_OK);
1060 }
1061
1062
1063 /*******************************************************************************
1064 *
1065 * FUNCTION: acpi_ds_obj_stack_get_value
1066 *
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
1070 *
1071 * RETURN: Pointer to the requested operand
1072 *
1073 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1074 * be within the range of the current stack pointer.
1075 *
1076 ******************************************************************************/
1077
1078 void *
1079 acpi_ds_obj_stack_get_value (
1080 u32 index,
1081 struct acpi_walk_state *walk_state)
1082 {
1083
1084 ACPI_FUNCTION_TRACE_PTR ("ds_obj_stack_get_value", walk_state);
1085
1086
1087 /* Can't do it if the stack is empty */
1088
1089 if (walk_state->num_operands == 0) {
1090 return_PTR (NULL);
1091 }
1092
1093 /* or if the index is past the top of the stack */
1094
1095 if (index > (walk_state->num_operands - (u32) 1)) {
1096 return_PTR (NULL);
1097 }
1098
1099 return_PTR (walk_state->operands[(acpi_native_uint)(walk_state->num_operands - 1) -
1100 index]);
1101 }
1102 #endif
1103
1104
This page took 0.056585 seconds and 5 git commands to generate.