blob: 7d68a5aaf3c43bb6423b1d8a33dfdb54bc625840 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acparser.h>
46#include <acpi/acdispat.h>
47#include <acpi/acnamesp.h>
48
49#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("dswstate")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040053#ifdef ACPI_OBSOLETE_FUNCTIONS
Linus Torvalds1da177e2005-04-16 15:20:36 -070054acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040055acpi_ds_result_insert(void *object,
56 u32 index, struct acpi_walk_state *walk_state);
57
58acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state *walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Robert Moore44f6c012005-04-18 22:49:35 -040060acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040061acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
62 struct acpi_walk_state *walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Len Brown4be44fc2005-08-05 00:44:28 -040064void *acpi_ds_obj_stack_get_value(u32 index,
65 struct acpi_walk_state *walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -040066#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Robert Moore44f6c012005-04-18 22:49:35 -040068#ifdef ACPI_FUTURE_USAGE
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/*******************************************************************************
71 *
72 * FUNCTION: acpi_ds_result_remove
73 *
74 * PARAMETERS: Object - Where to return the popped object
75 * Index - Where to extract the object
76 * walk_state - Current Walk state
77 *
78 * RETURN: Status
79 *
80 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
81 * other words, this is a FIFO.
82 *
83 ******************************************************************************/
84
85acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040086acpi_ds_result_remove(union acpi_operand_object **object,
87 u32 index, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Len Brown4be44fc2005-08-05 00:44:28 -040089 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Len Brown4be44fc2005-08-05 00:44:28 -040091 ACPI_FUNCTION_NAME("ds_result_remove");
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 state = walk_state->results;
94 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -040095 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
96 "No result object pushed! State=%p\n",
97 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return (AE_NOT_EXIST);
99 }
100
101 if (index >= ACPI_OBJ_MAX_OPERAND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400102 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
103 "Index out of range: %X State=%p Num=%X\n",
104 index, walk_state,
105 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 }
107
108 /* Check for a valid result object */
109
Len Brown4be44fc2005-08-05 00:44:28 -0400110 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,
114 index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 return (AE_AML_NO_RETURN_VALUE);
116 }
117
118 /* Remove the object */
119
120 state->results.num_results--;
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122 *object = state->results.obj_desc[index];
123 state->results.obj_desc[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Len Brown4be44fc2005-08-05 00:44:28 -0400125 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
126 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
127 *object,
128 (*object) ? acpi_ut_get_object_type_name(*object) :
129 "NULL", index, walk_state,
130 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 return (AE_OK);
133}
134
Len Brown4be44fc2005-08-05 00:44:28 -0400135#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137/*******************************************************************************
138 *
139 * FUNCTION: acpi_ds_result_pop
140 *
141 * PARAMETERS: Object - Where to return the popped object
142 * walk_state - Current Walk state
143 *
144 * RETURN: Status
145 *
146 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
147 * other words, this is a FIFO.
148 *
149 ******************************************************************************/
150
151acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400152acpi_ds_result_pop(union acpi_operand_object ** object,
153 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Len Brown4be44fc2005-08-05 00:44:28 -0400155 acpi_native_uint index;
156 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 ACPI_FUNCTION_NAME("ds_result_pop");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160 state = walk_state->results;
161 if (!state) {
162 return (AE_OK);
163 }
164
165 if (!state->results.num_results) {
Len Brown4be44fc2005-08-05 00:44:28 -0400166 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
167 "Result stack is empty! State=%p\n",
168 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return (AE_AML_NO_RETURN_VALUE);
170 }
171
172 /* Remove top element */
173
174 state->results.num_results--;
175
176 for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
177 /* Check for a valid result object */
178
Len Brown4be44fc2005-08-05 00:44:28 -0400179 if (state->results.obj_desc[index - 1]) {
180 *object = state->results.obj_desc[index - 1];
181 state->results.obj_desc[index - 1] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Len Brown4be44fc2005-08-05 00:44:28 -0400183 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
184 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
185 *object,
186 (*object) ?
187 acpi_ut_get_object_type_name(*object)
188 : "NULL", (u32) index - 1, walk_state,
189 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 return (AE_OK);
192 }
193 }
194
Len Brown4be44fc2005-08-05 00:44:28 -0400195 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
196 "No result objects! State=%p\n", walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 return (AE_AML_NO_RETURN_VALUE);
198}
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200/*******************************************************************************
201 *
202 * FUNCTION: acpi_ds_result_pop_from_bottom
203 *
204 * PARAMETERS: Object - Where to return the popped object
205 * walk_state - Current Walk state
206 *
207 * RETURN: Status
208 *
209 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
210 * other words, this is a FIFO.
211 *
212 ******************************************************************************/
213
214acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400215acpi_ds_result_pop_from_bottom(union acpi_operand_object ** object,
216 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Len Brown4be44fc2005-08-05 00:44:28 -0400218 acpi_native_uint index;
219 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Len Brown4be44fc2005-08-05 00:44:28 -0400221 ACPI_FUNCTION_NAME("ds_result_pop_from_bottom");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 state = walk_state->results;
224 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400225 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
226 "Warning: No result object pushed! State=%p\n",
227 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return (AE_NOT_EXIST);
229 }
230
231 if (!state->results.num_results) {
Len Brown4be44fc2005-08-05 00:44:28 -0400232 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
233 "No result objects! State=%p\n", walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return (AE_AML_NO_RETURN_VALUE);
235 }
236
237 /* Remove Bottom element */
238
Len Brown4be44fc2005-08-05 00:44:28 -0400239 *object = state->results.obj_desc[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 /* Push entire stack down one element */
242
243 for (index = 0; index < state->results.num_results; index++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400244 state->results.obj_desc[index] =
245 state->results.obj_desc[index + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247
248 state->results.num_results--;
249
250 /* Check for a valid result object */
251
252 if (!*object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400253 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
254 "Null operand! State=%p #Ops=%X Index=%X\n",
255 walk_state, state->results.num_results,
256 (u32) index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return (AE_AML_NO_RETURN_VALUE);
258 }
259
Len Brown4be44fc2005-08-05 00:44:28 -0400260 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n",
261 *object,
262 (*object) ? acpi_ut_get_object_type_name(*object) :
263 "NULL", state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 return (AE_OK);
266}
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268/*******************************************************************************
269 *
270 * FUNCTION: acpi_ds_result_push
271 *
272 * PARAMETERS: Object - Where to return the popped object
273 * walk_state - Current Walk state
274 *
275 * RETURN: Status
276 *
277 * DESCRIPTION: Push an object onto the current result stack
278 *
279 ******************************************************************************/
280
281acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400282acpi_ds_result_push(union acpi_operand_object * object,
283 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Len Brown4be44fc2005-08-05 00:44:28 -0400285 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Len Brown4be44fc2005-08-05 00:44:28 -0400287 ACPI_FUNCTION_NAME("ds_result_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 state = walk_state->results;
290 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400291 ACPI_REPORT_ERROR(("No result stack frame during push\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 return (AE_AML_INTERNAL);
293 }
294
295 if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
Len Brown4be44fc2005-08-05 00:44:28 -0400296 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
297 "Result stack overflow: Obj=%p State=%p Num=%X\n",
298 object, walk_state,
299 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return (AE_STACK_OVERFLOW);
301 }
302
303 if (!object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400304 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
305 "Null Object! Obj=%p State=%p Num=%X\n",
306 object, walk_state,
307 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 return (AE_BAD_PARAMETER);
309 }
310
Len Brown4be44fc2005-08-05 00:44:28 -0400311 state->results.obj_desc[state->results.num_results] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 state->results.num_results++;
313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
315 object,
316 object ?
317 acpi_ut_get_object_type_name((union
318 acpi_operand_object *)
319 object) : "NULL",
320 walk_state, state->results.num_results,
321 walk_state->current_result));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 return (AE_OK);
324}
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326/*******************************************************************************
327 *
328 * FUNCTION: acpi_ds_result_stack_push
329 *
330 * PARAMETERS: walk_state - Current Walk state
331 *
332 * RETURN: Status
333 *
334 * DESCRIPTION: Push an object onto the walk_state result stack.
335 *
336 ******************************************************************************/
337
Len Brown4be44fc2005-08-05 00:44:28 -0400338acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
Len Brown4be44fc2005-08-05 00:44:28 -0400340 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Len Brown4be44fc2005-08-05 00:44:28 -0400342 ACPI_FUNCTION_NAME("ds_result_stack_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Len Brown4be44fc2005-08-05 00:44:28 -0400344 state = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 if (!state) {
346 return (AE_NO_MEMORY);
347 }
348
349 state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400350 acpi_ut_push_generic_state(&walk_state->results, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Len Brown4be44fc2005-08-05 00:44:28 -0400352 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
353 state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 return (AE_OK);
356}
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358/*******************************************************************************
359 *
360 * FUNCTION: acpi_ds_result_stack_pop
361 *
362 * PARAMETERS: walk_state - Current Walk state
363 *
364 * RETURN: Status
365 *
366 * DESCRIPTION: Pop an object off of the walk_state result stack.
367 *
368 ******************************************************************************/
369
Len Brown4be44fc2005-08-05 00:44:28 -0400370acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Len Brown4be44fc2005-08-05 00:44:28 -0400372 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Len Brown4be44fc2005-08-05 00:44:28 -0400374 ACPI_FUNCTION_NAME("ds_result_stack_pop");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 /* Check for stack underflow */
377
378 if (walk_state->results == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400379 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n",
380 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return (AE_AML_NO_OPERAND);
382 }
383
Len Brown4be44fc2005-08-05 00:44:28 -0400384 state = acpi_ut_pop_generic_state(&walk_state->results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Len Brown4be44fc2005-08-05 00:44:28 -0400386 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
387 "Result=%p remaining_results=%X State=%p\n",
388 state, state->results.num_results, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Len Brown4be44fc2005-08-05 00:44:28 -0400390 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 return (AE_OK);
393}
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395/*******************************************************************************
396 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 * FUNCTION: acpi_ds_obj_stack_push
398 *
399 * PARAMETERS: Object - Object to push
400 * walk_state - Current Walk state
401 *
402 * RETURN: Status
403 *
404 * DESCRIPTION: Push an object onto this walk's object/operand stack
405 *
406 ******************************************************************************/
407
408acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400409acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Len Brown4be44fc2005-08-05 00:44:28 -0400411 ACPI_FUNCTION_NAME("ds_obj_stack_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 /* Check for stack overflow */
414
415 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
Len Brown4be44fc2005-08-05 00:44:28 -0400416 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
417 "overflow! Obj=%p State=%p #Ops=%X\n",
418 object, walk_state,
419 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return (AE_STACK_OVERFLOW);
421 }
422
423 /* Put the object onto the stack */
424
Len Brown4be44fc2005-08-05 00:44:28 -0400425 walk_state->operands[walk_state->num_operands] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 walk_state->num_operands++;
427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
429 object,
430 acpi_ut_get_object_type_name((union
431 acpi_operand_object *)
432 object), walk_state,
433 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 return (AE_OK);
436}
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438/*******************************************************************************
439 *
440 * FUNCTION: acpi_ds_obj_stack_pop
441 *
442 * PARAMETERS: pop_count - Number of objects/entries to pop
443 * walk_state - Current Walk state
444 *
445 * RETURN: Status
446 *
447 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
448 * deleted by this routine.
449 *
450 ******************************************************************************/
451
452acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400453acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Len Brown4be44fc2005-08-05 00:44:28 -0400455 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Len Brown4be44fc2005-08-05 00:44:28 -0400457 ACPI_FUNCTION_NAME("ds_obj_stack_pop");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 for (i = 0; i < pop_count; i++) {
460 /* Check for stack underflow */
461
462 if (walk_state->num_operands == 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400463 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 return (AE_STACK_UNDERFLOW);
468 }
469
470 /* Just set the stack entry to null */
471
472 walk_state->num_operands--;
Len Brown4be44fc2005-08-05 00:44:28 -0400473 walk_state->operands[walk_state->num_operands] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475
Len Brown4be44fc2005-08-05 00:44:28 -0400476 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 pop_count, walk_state, walk_state->num_operands));
478
479 return (AE_OK);
480}
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482/*******************************************************************************
483 *
484 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
485 *
486 * PARAMETERS: pop_count - Number of objects/entries to pop
487 * walk_state - Current Walk state
488 *
489 * RETURN: Status
490 *
491 * DESCRIPTION: Pop this walk's object stack and delete each object that is
492 * popped off.
493 *
494 ******************************************************************************/
495
496acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400497acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
498 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Len Brown4be44fc2005-08-05 00:44:28 -0400500 u32 i;
501 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Len Brown4be44fc2005-08-05 00:44:28 -0400503 ACPI_FUNCTION_NAME("ds_obj_stack_pop_and_delete");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 for (i = 0; i < pop_count; i++) {
506 /* Check for stack underflow */
507
508 if (walk_state->num_operands == 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400509 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 return (AE_STACK_UNDERFLOW);
514 }
515
516 /* Pop the stack and delete an object if present in this stack entry */
517
518 walk_state->num_operands--;
Len Brown4be44fc2005-08-05 00:44:28 -0400519 obj_desc = walk_state->operands[walk_state->num_operands];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400521 acpi_ut_remove_reference(walk_state->
522 operands[walk_state->
523 num_operands]);
524 walk_state->operands[walk_state->num_operands] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 }
526 }
527
Len Brown4be44fc2005-08-05 00:44:28 -0400528 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 pop_count, walk_state, walk_state->num_operands));
530
531 return (AE_OK);
532}
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534/*******************************************************************************
535 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 * FUNCTION: acpi_ds_get_current_walk_state
537 *
538 * PARAMETERS: Thread - Get current active state for this Thread
539 *
540 * RETURN: Pointer to the current walk state
541 *
542 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
543 * walk state.)
544 *
545 ******************************************************************************/
546
Len Brown4be44fc2005-08-05 00:44:28 -0400547struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
548 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Len Brown4be44fc2005-08-05 00:44:28 -0400550 ACPI_FUNCTION_NAME("ds_get_current_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 if (!thread) {
553 return (NULL);
554 }
555
Len Brown4be44fc2005-08-05 00:44:28 -0400556 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current walk_state %p\n",
557 thread->walk_state_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559 return (thread->walk_state_list);
560}
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562/*******************************************************************************
563 *
564 * FUNCTION: acpi_ds_push_walk_state
565 *
566 * PARAMETERS: walk_state - State to push
Robert Moore44f6c012005-04-18 22:49:35 -0400567 * Thread - Thread state object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 *
569 * RETURN: None
570 *
Robert Moore44f6c012005-04-18 22:49:35 -0400571 * DESCRIPTION: Place the Thread state at the head of the state list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 *
573 ******************************************************************************/
574
575void
Len Brown4be44fc2005-08-05 00:44:28 -0400576acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
577 struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Len Brown4be44fc2005-08-05 00:44:28 -0400579 ACPI_FUNCTION_TRACE("ds_push_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Len Brown4be44fc2005-08-05 00:44:28 -0400581 walk_state->next = thread->walk_state_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 thread->walk_state_list = walk_state;
583
584 return_VOID;
585}
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587/*******************************************************************************
588 *
589 * FUNCTION: acpi_ds_pop_walk_state
590 *
Robert Moore44f6c012005-04-18 22:49:35 -0400591 * PARAMETERS: Thread - Current thread state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 *
Robert Moore44f6c012005-04-18 22:49:35 -0400593 * RETURN: A walk_state object popped from the thread's stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 *
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
597 * the list is empty.
598 *
599 ******************************************************************************/
600
Len Brown4be44fc2005-08-05 00:44:28 -0400601struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Len Brown4be44fc2005-08-05 00:44:28 -0400603 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Len Brown4be44fc2005-08-05 00:44:28 -0400605 ACPI_FUNCTION_TRACE("ds_pop_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 walk_state = thread->walk_state_list;
608
609 if (walk_state) {
610 /* Next walk state becomes the current walk state */
611
612 thread->walk_state_list = walk_state->next;
613
614 /*
615 * Don't clear the NEXT field, this serves as an indicator
616 * that there is a parent WALK STATE
Robert Moore44f6c012005-04-18 22:49:35 -0400617 * Do Not: walk_state->Next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 */
619 }
620
Len Brown4be44fc2005-08-05 00:44:28 -0400621 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624/*******************************************************************************
625 *
626 * FUNCTION: acpi_ds_create_walk_state
627 *
Robert Moore44f6c012005-04-18 22:49:35 -0400628 * PARAMETERS: owner_id - ID for object creation
629 * Origin - Starting point for this walk
630 * mth_desc - Method object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 * Thread - Current thread state
632 *
633 * RETURN: Pointer to the new walk state.
634 *
635 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
636 * state is set to this new state.
637 *
638 ******************************************************************************/
639
Len Brown4be44fc2005-08-05 00:44:28 -0400640struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
641 union acpi_parse_object
642 *origin,
643 union acpi_operand_object
644 *mth_desc,
645 struct acpi_thread_state
646 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
Len Brown4be44fc2005-08-05 00:44:28 -0400648 struct acpi_walk_state *walk_state;
649 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Len Brown4be44fc2005-08-05 00:44:28 -0400651 ACPI_FUNCTION_TRACE("ds_create_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Len Brown4be44fc2005-08-05 00:44:28 -0400653 walk_state = ACPI_MEM_CALLOCATE(sizeof(struct acpi_walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 if (!walk_state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400655 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 }
657
Len Brown4be44fc2005-08-05 00:44:28 -0400658 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 walk_state->parser_state.start_op = origin;
665
666 /* Init the method args/local */
667
668#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
Len Brown4be44fc2005-08-05 00:44:28 -0400669 acpi_ds_method_data_init(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670#endif
671
672 /* Create an initial result stack entry */
673
Len Brown4be44fc2005-08-05 00:44:28 -0400674 status = acpi_ds_result_stack_push(walk_state);
675 if (ACPI_FAILURE(status)) {
676 ACPI_MEM_FREE(walk_state);
677 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 }
679
680 /* Put the new state at the head of the walk list */
681
682 if (thread) {
Len Brown4be44fc2005-08-05 00:44:28 -0400683 acpi_ds_push_walk_state(walk_state, thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685
Len Brown4be44fc2005-08-05 00:44:28 -0400686 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689/*******************************************************************************
690 *
691 * FUNCTION: acpi_ds_init_aml_walk
692 *
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
Robert Moore44f6c012005-04-18 22:49:35 -0400698 * Info - Method info block (params, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 * pass_number - 1, 2, or 3
700 *
701 * RETURN: Status
702 *
703 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
704 *
705 ******************************************************************************/
706
707acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400708acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
709 union acpi_parse_object *op,
710 struct acpi_namespace_node *method_node,
711 u8 * aml_start,
712 u32 aml_length,
713 struct acpi_parameter_info *info, u8 pass_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714{
Len Brown4be44fc2005-08-05 00:44:28 -0400715 acpi_status status;
716 struct acpi_parse_state *parser_state = &walk_state->parser_state;
717 union acpi_parse_object *extra_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Len Brown4be44fc2005-08-05 00:44:28 -0400719 ACPI_FUNCTION_TRACE("ds_init_aml_walk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Len Brown4be44fc2005-08-05 00:44:28 -0400721 walk_state->parser_state.aml =
722 walk_state->parser_state.aml_start = aml_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 walk_state->parser_state.aml_end =
Len Brown4be44fc2005-08-05 00:44:28 -0400724 walk_state->parser_state.pkg_end = aml_start + aml_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726 /* The next_op of the next_walk will be the beginning of the method */
727
Robert Moore44f6c012005-04-18 22:49:35 -0400728 walk_state->next_op = NULL;
Robert Moore0c9938c2005-07-29 15:15:00 -0700729 walk_state->pass_number = pass_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 if (info) {
732 if (info->parameter_type == ACPI_PARAM_GPE) {
Len Brown4be44fc2005-08-05 00:44:28 -0400733 walk_state->gpe_event_info =
734 ACPI_CAST_PTR(struct acpi_gpe_event_info,
735 info->parameters);
736 } else {
737 walk_state->params = info->parameters;
Robert Moore44f6c012005-04-18 22:49:35 -0400738 walk_state->caller_return_desc = &info->return_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 }
740 }
741
Len Brown4be44fc2005-08-05 00:44:28 -0400742 status = acpi_ps_init_scope(&walk_state->parser_state, op);
743 if (ACPI_FAILURE(status)) {
744 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 }
746
747 if (method_node) {
748 walk_state->parser_state.start_node = method_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400749 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 /* Push start scope on scope stack and make it current */
755
Len Brown4be44fc2005-08-05 00:44:28 -0400756 status =
757 acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
758 walk_state);
759 if (ACPI_FAILURE(status)) {
760 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 }
762
763 /* Init the method arguments */
764
Len Brown4be44fc2005-08-05 00:44:28 -0400765 status = acpi_ds_method_data_init_args(walk_state->params,
766 ACPI_METHOD_NUM_ARGS,
767 walk_state);
768 if (ACPI_FAILURE(status)) {
769 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 }
Len Brown4be44fc2005-08-05 00:44:28 -0400771 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 /*
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.
777 */
778 extra_op = parser_state->start_op;
779 while (extra_op && !extra_op->common.node) {
780 extra_op = extra_op->common.parent;
781 }
782
783 if (!extra_op) {
784 parser_state->start_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400785 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 parser_state->start_node = extra_op->common.node;
787 }
788
789 if (parser_state->start_node) {
790 /* Push start scope on scope stack and make it current */
791
Len Brown4be44fc2005-08-05 00:44:28 -0400792 status =
793 acpi_ds_scope_stack_push(parser_state->start_node,
794 parser_state->start_node->
795 type, walk_state);
796 if (ACPI_FAILURE(status)) {
797 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
799 }
800 }
801
Len Brown4be44fc2005-08-05 00:44:28 -0400802 status = acpi_ds_init_callbacks(walk_state, pass_number);
803 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804}
805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806/*******************************************************************************
807 *
808 * FUNCTION: acpi_ds_delete_walk_state
809 *
810 * PARAMETERS: walk_state - State to delete
811 *
812 * RETURN: Status
813 *
814 * DESCRIPTION: Delete a walk state including all internal data structures
815 *
816 ******************************************************************************/
817
Len Brown4be44fc2005-08-05 00:44:28 -0400818void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819{
Len Brown4be44fc2005-08-05 00:44:28 -0400820 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Len Brown4be44fc2005-08-05 00:44:28 -0400822 ACPI_FUNCTION_TRACE_PTR("ds_delete_walk_state", walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 if (!walk_state) {
825 return;
826 }
827
828 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
Len Brown4be44fc2005-08-05 00:44:28 -0400829 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
830 "%p is not a valid walk state\n",
831 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 return;
833 }
834
835 if (walk_state->parser_state.scope) {
Len Brown4be44fc2005-08-05 00:44:28 -0400836 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
837 "%p walk still has a scope list\n",
838 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 }
840
841 /* Always must free any linked control states */
842
843 while (walk_state->control_state) {
844 state = walk_state->control_state;
845 walk_state->control_state = state->common.next;
846
Len Brown4be44fc2005-08-05 00:44:28 -0400847 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 }
849
850 /* Always must free any linked parse states */
851
852 while (walk_state->scope_info) {
853 state = walk_state->scope_info;
854 walk_state->scope_info = state->common.next;
855
Len Brown4be44fc2005-08-05 00:44:28 -0400856 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 }
858
859 /* Always must free any stacked result states */
860
861 while (walk_state->results) {
862 state = walk_state->results;
863 walk_state->results = state->common.next;
864
Len Brown4be44fc2005-08-05 00:44:28 -0400865 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
867
Len Brown4be44fc2005-08-05 00:44:28 -0400868 ACPI_MEM_FREE(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 return_VOID;
870}
871
Robert Moore44f6c012005-04-18 22:49:35 -0400872#ifdef ACPI_OBSOLETE_FUNCTIONS
873/*******************************************************************************
874 *
875 * FUNCTION: acpi_ds_result_insert
876 *
877 * PARAMETERS: Object - Object to push
878 * Index - Where to insert the object
879 * walk_state - Current Walk state
880 *
881 * RETURN: Status
882 *
883 * DESCRIPTION: Insert an object onto this walk's result stack
884 *
885 ******************************************************************************/
886
887acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400888acpi_ds_result_insert(void *object,
889 u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400890{
Len Brown4be44fc2005-08-05 00:44:28 -0400891 union acpi_generic_state *state;
Robert Moore44f6c012005-04-18 22:49:35 -0400892
Len Brown4be44fc2005-08-05 00:44:28 -0400893 ACPI_FUNCTION_NAME("ds_result_insert");
Robert Moore44f6c012005-04-18 22:49:35 -0400894
895 state = walk_state->results;
896 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400897 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
898 "No result object pushed! State=%p\n",
899 walk_state));
Robert Moore44f6c012005-04-18 22:49:35 -0400900 return (AE_NOT_EXIST);
901 }
902
903 if (index >= ACPI_OBJ_NUM_OPERANDS) {
Len Brown4be44fc2005-08-05 00:44:28 -0400904 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));
Robert Moore44f6c012005-04-18 22:49:35 -0400908 return (AE_BAD_PARAMETER);
909 }
910
911 if (!object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400912 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));
Robert Moore44f6c012005-04-18 22:49:35 -0400916 return (AE_BAD_PARAMETER);
917 }
918
Len Brown4be44fc2005-08-05 00:44:28 -0400919 state->results.obj_desc[index] = object;
Robert Moore44f6c012005-04-18 22:49:35 -0400920 state->results.num_results++;
921
Len Brown4be44fc2005-08-05 00:44:28 -0400922 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
923 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
924 object,
925 object ?
926 acpi_ut_get_object_type_name((union
927 acpi_operand_object *)
928 object) : "NULL",
929 walk_state, state->results.num_results,
930 walk_state->current_result));
Robert Moore44f6c012005-04-18 22:49:35 -0400931
932 return (AE_OK);
933}
934
Robert Moore44f6c012005-04-18 22:49:35 -0400935/*******************************************************************************
936 *
937 * FUNCTION: acpi_ds_obj_stack_delete_all
938 *
939 * PARAMETERS: walk_state - Current Walk state
940 *
941 * RETURN: Status
942 *
943 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
944 * Should be used with great care, if at all!
945 *
946 ******************************************************************************/
947
Len Brown4be44fc2005-08-05 00:44:28 -0400948acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state * walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400949{
Len Brown4be44fc2005-08-05 00:44:28 -0400950 u32 i;
Robert Moore44f6c012005-04-18 22:49:35 -0400951
Len Brown4be44fc2005-08-05 00:44:28 -0400952 ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_delete_all", walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -0400953
954 /* The stack size is configurable, but fixed */
955
956 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
957 if (walk_state->operands[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400958 acpi_ut_remove_reference(walk_state->operands[i]);
Robert Moore44f6c012005-04-18 22:49:35 -0400959 walk_state->operands[i] = NULL;
960 }
961 }
962
Len Brown4be44fc2005-08-05 00:44:28 -0400963 return_ACPI_STATUS(AE_OK);
Robert Moore44f6c012005-04-18 22:49:35 -0400964}
965
Robert Moore44f6c012005-04-18 22:49:35 -0400966/*******************************************************************************
967 *
968 * FUNCTION: acpi_ds_obj_stack_pop_object
969 *
970 * PARAMETERS: Object - Where to return the popped object
971 * walk_state - Current Walk state
972 *
973 * RETURN: Status
974 *
975 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
976 * deleted by this routine.
977 *
978 ******************************************************************************/
979
980acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400981acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
982 struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400983{
Len Brown4be44fc2005-08-05 00:44:28 -0400984 ACPI_FUNCTION_NAME("ds_obj_stack_pop_object");
Robert Moore44f6c012005-04-18 22:49:35 -0400985
986 /* Check for stack underflow */
987
988 if (walk_state->num_operands == 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400989 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
990 "Missing operand/stack empty! State=%p #Ops=%X\n",
991 walk_state, walk_state->num_operands));
Robert Moore44f6c012005-04-18 22:49:35 -0400992 *object = NULL;
993 return (AE_AML_NO_OPERAND);
994 }
995
996 /* Pop the stack */
997
998 walk_state->num_operands--;
999
1000 /* Check for a valid operand */
1001
Len Brown4be44fc2005-08-05 00:44:28 -04001002 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));
Robert Moore44f6c012005-04-18 22:49:35 -04001006 *object = NULL;
1007 return (AE_AML_NO_OPERAND);
1008 }
1009
1010 /* Get operand and set stack entry to null */
1011
Len Brown4be44fc2005-08-05 00:44:28 -04001012 *object = walk_state->operands[walk_state->num_operands];
1013 walk_state->operands[walk_state->num_operands] = NULL;
Robert Moore44f6c012005-04-18 22:49:35 -04001014
Len Brown4be44fc2005-08-05 00:44:28 -04001015 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1016 *object, acpi_ut_get_object_type_name(*object),
Robert Moore44f6c012005-04-18 22:49:35 -04001017 walk_state, walk_state->num_operands));
1018
1019 return (AE_OK);
1020}
1021
Robert Moore44f6c012005-04-18 22:49:35 -04001022/*******************************************************************************
1023 *
1024 * FUNCTION: acpi_ds_obj_stack_get_value
1025 *
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
1029 *
1030 * RETURN: Pointer to the requested operand
1031 *
1032 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1033 * be within the range of the current stack pointer.
1034 *
1035 ******************************************************************************/
1036
Len Brown4be44fc2005-08-05 00:44:28 -04001037void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -04001038{
1039
Len Brown4be44fc2005-08-05 00:44:28 -04001040 ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_get_value", walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -04001041
1042 /* Can't do it if the stack is empty */
1043
1044 if (walk_state->num_operands == 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001045 return_PTR(NULL);
Robert Moore44f6c012005-04-18 22:49:35 -04001046 }
1047
1048 /* or if the index is past the top of the stack */
1049
1050 if (index > (walk_state->num_operands - (u32) 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001051 return_PTR(NULL);
Robert Moore44f6c012005-04-18 22:49:35 -04001052 }
1053
Len Brown4be44fc2005-08-05 00:44:28 -04001054 return_PTR(walk_state->
1055 operands[(acpi_native_uint) (walk_state->num_operands - 1) -
1056 index]);
Robert Moore44f6c012005-04-18 22:49:35 -04001057}
1058#endif