blob: 7817e552267962f56a3cd761f073efc9b8088d7e [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/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 * FUNCTION: acpi_ds_result_remove
72 *
73 * PARAMETERS: Object - Where to return the popped object
74 * Index - Where to extract the object
75 * walk_state - Current Walk state
76 *
77 * RETURN: Status
78 *
79 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
80 * other words, this is a FIFO.
81 *
82 ******************************************************************************/
83
84acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040085acpi_ds_result_remove(union acpi_operand_object **object,
86 u32 index, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Len Brown4be44fc2005-08-05 00:44:28 -040088 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Bob Mooreb229cf92006-04-21 17:15:00 -040090 ACPI_FUNCTION_NAME(ds_result_remove);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 state = walk_state->results;
93 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050094 ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
95 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return (AE_NOT_EXIST);
97 }
98
99 if (index >= ACPI_OBJ_MAX_OPERAND) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500100 ACPI_ERROR((AE_INFO,
101 "Index out of range: %X State=%p Num=%X",
102 index, walk_state, state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
104
105 /* Check for a valid result object */
106
Len Brown4be44fc2005-08-05 00:44:28 -0400107 if (!state->results.obj_desc[index]) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500108 ACPI_ERROR((AE_INFO,
109 "Null operand! State=%p #Ops=%X, Index=%X",
110 walk_state, state->results.num_results, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 return (AE_AML_NO_RETURN_VALUE);
112 }
113
114 /* Remove the object */
115
116 state->results.num_results--;
117
Len Brown4be44fc2005-08-05 00:44:28 -0400118 *object = state->results.obj_desc[index];
119 state->results.obj_desc[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Len Brown4be44fc2005-08-05 00:44:28 -0400121 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
122 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
123 *object,
124 (*object) ? acpi_ut_get_object_type_name(*object) :
125 "NULL", index, walk_state,
126 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 return (AE_OK);
129}
Len Brown4be44fc2005-08-05 00:44:28 -0400130#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/*******************************************************************************
133 *
134 * FUNCTION: acpi_ds_result_pop
135 *
136 * PARAMETERS: Object - Where to return the popped object
137 * walk_state - Current Walk state
138 *
139 * RETURN: Status
140 *
141 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
142 * other words, this is a FIFO.
143 *
144 ******************************************************************************/
145
146acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400147acpi_ds_result_pop(union acpi_operand_object ** object,
148 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Len Brown4be44fc2005-08-05 00:44:28 -0400150 acpi_native_uint index;
151 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Bob Mooreb229cf92006-04-21 17:15:00 -0400153 ACPI_FUNCTION_NAME(ds_result_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 state = walk_state->results;
156 if (!state) {
157 return (AE_OK);
158 }
159
160 if (!state->results.num_results) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500161 ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
162 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return (AE_AML_NO_RETURN_VALUE);
164 }
165
166 /* Remove top element */
167
168 state->results.num_results--;
169
170 for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /* Check for a valid result object */
173
Len Brown4be44fc2005-08-05 00:44:28 -0400174 if (state->results.obj_desc[index - 1]) {
175 *object = state->results.obj_desc[index - 1];
176 state->results.obj_desc[index - 1] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Len Brown4be44fc2005-08-05 00:44:28 -0400178 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
179 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
180 *object,
181 (*object) ?
182 acpi_ut_get_object_type_name(*object)
183 : "NULL", (u32) index - 1, walk_state,
184 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 return (AE_OK);
187 }
188 }
189
Bob Mooreb8e4d892006-01-27 16:43:00 -0500190 ACPI_ERROR((AE_INFO, "No result objects! State=%p", walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 return (AE_AML_NO_RETURN_VALUE);
192}
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194/*******************************************************************************
195 *
196 * FUNCTION: acpi_ds_result_pop_from_bottom
197 *
198 * PARAMETERS: Object - Where to return the popped object
199 * walk_state - Current Walk state
200 *
201 * RETURN: Status
202 *
203 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
204 * other words, this is a FIFO.
205 *
206 ******************************************************************************/
207
208acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400209acpi_ds_result_pop_from_bottom(union acpi_operand_object ** object,
210 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Len Brown4be44fc2005-08-05 00:44:28 -0400212 acpi_native_uint index;
213 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Bob Mooreb229cf92006-04-21 17:15:00 -0400215 ACPI_FUNCTION_NAME(ds_result_pop_from_bottom);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 state = walk_state->results;
218 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500219 ACPI_ERROR((AE_INFO,
220 "No result object pushed! State=%p", walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 return (AE_NOT_EXIST);
222 }
223
224 if (!state->results.num_results) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500225 ACPI_ERROR((AE_INFO, "No result objects! State=%p",
226 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 return (AE_AML_NO_RETURN_VALUE);
228 }
229
230 /* Remove Bottom element */
231
Len Brown4be44fc2005-08-05 00:44:28 -0400232 *object = state->results.obj_desc[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 /* Push entire stack down one element */
235
236 for (index = 0; index < state->results.num_results; index++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400237 state->results.obj_desc[index] =
238 state->results.obj_desc[index + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
240
241 state->results.num_results--;
242
243 /* Check for a valid result object */
244
245 if (!*object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500246 ACPI_ERROR((AE_INFO,
247 "Null operand! State=%p #Ops=%X Index=%X",
248 walk_state, state->results.num_results,
249 (u32) index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return (AE_AML_NO_RETURN_VALUE);
251 }
252
Len Brown4be44fc2005-08-05 00:44:28 -0400253 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n",
254 *object,
255 (*object) ? acpi_ut_get_object_type_name(*object) :
256 "NULL", state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 return (AE_OK);
259}
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261/*******************************************************************************
262 *
263 * FUNCTION: acpi_ds_result_push
264 *
265 * PARAMETERS: Object - Where to return the popped object
266 * walk_state - Current Walk state
267 *
268 * RETURN: Status
269 *
270 * DESCRIPTION: Push an object onto the current result stack
271 *
272 ******************************************************************************/
273
274acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400275acpi_ds_result_push(union acpi_operand_object * object,
276 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
Len Brown4be44fc2005-08-05 00:44:28 -0400278 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Bob Mooreb229cf92006-04-21 17:15:00 -0400280 ACPI_FUNCTION_NAME(ds_result_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282 state = walk_state->results;
283 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500284 ACPI_ERROR((AE_INFO, "No result stack frame during push"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 return (AE_AML_INTERNAL);
286 }
287
288 if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500289 ACPI_ERROR((AE_INFO,
290 "Result stack overflow: Obj=%p State=%p Num=%X",
291 object, walk_state, state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 return (AE_STACK_OVERFLOW);
293 }
294
295 if (!object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500296 ACPI_ERROR((AE_INFO,
297 "Null Object! Obj=%p State=%p Num=%X",
298 object, walk_state, state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 return (AE_BAD_PARAMETER);
300 }
301
Len Brown4be44fc2005-08-05 00:44:28 -0400302 state->results.obj_desc[state->results.num_results] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 state->results.num_results++;
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
306 object,
307 object ?
308 acpi_ut_get_object_type_name((union
309 acpi_operand_object *)
310 object) : "NULL",
311 walk_state, state->results.num_results,
312 walk_state->current_result));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 return (AE_OK);
315}
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317/*******************************************************************************
318 *
319 * FUNCTION: acpi_ds_result_stack_push
320 *
321 * PARAMETERS: walk_state - Current Walk state
322 *
323 * RETURN: Status
324 *
325 * DESCRIPTION: Push an object onto the walk_state result stack.
326 *
327 ******************************************************************************/
328
Len Brown4be44fc2005-08-05 00:44:28 -0400329acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
Len Brown4be44fc2005-08-05 00:44:28 -0400331 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Bob Mooreb229cf92006-04-21 17:15:00 -0400333 ACPI_FUNCTION_NAME(ds_result_stack_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Len Brown4be44fc2005-08-05 00:44:28 -0400335 state = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (!state) {
337 return (AE_NO_MEMORY);
338 }
339
Bob Moore616861242006-03-17 16:44:00 -0500340 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400341 acpi_ut_push_generic_state(&walk_state->results, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
344 state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 return (AE_OK);
347}
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349/*******************************************************************************
350 *
351 * FUNCTION: acpi_ds_result_stack_pop
352 *
353 * PARAMETERS: walk_state - Current Walk state
354 *
355 * RETURN: Status
356 *
357 * DESCRIPTION: Pop an object off of the walk_state result stack.
358 *
359 ******************************************************************************/
360
Len Brown4be44fc2005-08-05 00:44:28 -0400361acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Len Brown4be44fc2005-08-05 00:44:28 -0400363 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Bob Mooreb229cf92006-04-21 17:15:00 -0400365 ACPI_FUNCTION_NAME(ds_result_stack_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 /* Check for stack underflow */
368
369 if (walk_state->results == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400370 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n",
371 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 return (AE_AML_NO_OPERAND);
373 }
374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 state = acpi_ut_pop_generic_state(&walk_state->results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Len Brown4be44fc2005-08-05 00:44:28 -0400377 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400378 "Result=%p RemainingResults=%X State=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400379 state, state->results.num_results, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Len Brown4be44fc2005-08-05 00:44:28 -0400381 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 return (AE_OK);
384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386/*******************************************************************************
387 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 * FUNCTION: acpi_ds_obj_stack_push
389 *
390 * PARAMETERS: Object - Object to push
391 * walk_state - Current Walk state
392 *
393 * RETURN: Status
394 *
395 * DESCRIPTION: Push an object onto this walk's object/operand stack
396 *
397 ******************************************************************************/
398
399acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400400acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Bob Mooreb229cf92006-04-21 17:15:00 -0400402 ACPI_FUNCTION_NAME(ds_obj_stack_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 /* Check for stack overflow */
405
406 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500407 ACPI_ERROR((AE_INFO,
408 "Object stack overflow! Obj=%p State=%p #Ops=%X",
409 object, walk_state, walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 return (AE_STACK_OVERFLOW);
411 }
412
413 /* Put the object onto the stack */
414
Len Brown4be44fc2005-08-05 00:44:28 -0400415 walk_state->operands[walk_state->num_operands] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 walk_state->num_operands++;
417
Len Brown4be44fc2005-08-05 00:44:28 -0400418 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
419 object,
420 acpi_ut_get_object_type_name((union
421 acpi_operand_object *)
422 object), walk_state,
423 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 return (AE_OK);
426}
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428/*******************************************************************************
429 *
430 * FUNCTION: acpi_ds_obj_stack_pop
431 *
432 * PARAMETERS: pop_count - Number of objects/entries to pop
433 * walk_state - Current Walk state
434 *
435 * RETURN: Status
436 *
437 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
438 * deleted by this routine.
439 *
440 ******************************************************************************/
441
442acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400443acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Len Brown4be44fc2005-08-05 00:44:28 -0400445 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Bob Mooreb229cf92006-04-21 17:15:00 -0400447 ACPI_FUNCTION_NAME(ds_obj_stack_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 for (i = 0; i < pop_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 /* Check for stack underflow */
452
453 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500454 ACPI_ERROR((AE_INFO,
455 "Object stack underflow! Count=%X State=%p #Ops=%X",
456 pop_count, walk_state,
457 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return (AE_STACK_UNDERFLOW);
459 }
460
461 /* Just set the stack entry to null */
462
463 walk_state->num_operands--;
Len Brown4be44fc2005-08-05 00:44:28 -0400464 walk_state->operands[walk_state->num_operands] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
466
Len Brown4be44fc2005-08-05 00:44:28 -0400467 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 pop_count, walk_state, walk_state->num_operands));
469
470 return (AE_OK);
471}
472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473/*******************************************************************************
474 *
475 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
476 *
477 * PARAMETERS: pop_count - Number of objects/entries to pop
478 * walk_state - Current Walk state
479 *
480 * RETURN: Status
481 *
482 * DESCRIPTION: Pop this walk's object stack and delete each object that is
483 * popped off.
484 *
485 ******************************************************************************/
486
487acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400488acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
489 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
Len Brown4be44fc2005-08-05 00:44:28 -0400491 u32 i;
492 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Bob Mooreb229cf92006-04-21 17:15:00 -0400494 ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 for (i = 0; i < pop_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /* Check for stack underflow */
499
500 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500501 ACPI_ERROR((AE_INFO,
502 "Object stack underflow! Count=%X State=%p #Ops=%X",
503 pop_count, walk_state,
504 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 return (AE_STACK_UNDERFLOW);
506 }
507
508 /* Pop the stack and delete an object if present in this stack entry */
509
510 walk_state->num_operands--;
Len Brown4be44fc2005-08-05 00:44:28 -0400511 obj_desc = walk_state->operands[walk_state->num_operands];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 if (obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400513 acpi_ut_remove_reference(walk_state->
514 operands[walk_state->
515 num_operands]);
516 walk_state->operands[walk_state->num_operands] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 }
518 }
519
Len Brown4be44fc2005-08-05 00:44:28 -0400520 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 pop_count, walk_state, walk_state->num_operands));
522
523 return (AE_OK);
524}
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526/*******************************************************************************
527 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 * FUNCTION: acpi_ds_get_current_walk_state
529 *
530 * PARAMETERS: Thread - Get current active state for this Thread
531 *
532 * RETURN: Pointer to the current walk state
533 *
534 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
535 * walk state.)
536 *
537 ******************************************************************************/
538
Len Brown4be44fc2005-08-05 00:44:28 -0400539struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
540 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
Bob Mooreb229cf92006-04-21 17:15:00 -0400542 ACPI_FUNCTION_NAME(ds_get_current_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 if (!thread) {
545 return (NULL);
546 }
547
Bob Mooreb229cf92006-04-21 17:15:00 -0400548 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current WalkState %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400549 thread->walk_state_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 return (thread->walk_state_list);
552}
553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554/*******************************************************************************
555 *
556 * FUNCTION: acpi_ds_push_walk_state
557 *
558 * PARAMETERS: walk_state - State to push
Robert Moore44f6c012005-04-18 22:49:35 -0400559 * Thread - Thread state object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 *
561 * RETURN: None
562 *
Robert Moore44f6c012005-04-18 22:49:35 -0400563 * DESCRIPTION: Place the Thread state at the head of the state list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 *
565 ******************************************************************************/
566
567void
Len Brown4be44fc2005-08-05 00:44:28 -0400568acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
569 struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Bob Mooreb229cf92006-04-21 17:15:00 -0400571 ACPI_FUNCTION_TRACE(ds_push_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Len Brown4be44fc2005-08-05 00:44:28 -0400573 walk_state->next = thread->walk_state_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 thread->walk_state_list = walk_state;
575
576 return_VOID;
577}
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579/*******************************************************************************
580 *
581 * FUNCTION: acpi_ds_pop_walk_state
582 *
Robert Moore44f6c012005-04-18 22:49:35 -0400583 * PARAMETERS: Thread - Current thread state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 *
Robert Moore44f6c012005-04-18 22:49:35 -0400585 * RETURN: A walk_state object popped from the thread's stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 *
587 * DESCRIPTION: Remove and return the walkstate object that is at the head of
588 * the walk stack for the given walk list. NULL indicates that
589 * the list is empty.
590 *
591 ******************************************************************************/
592
Len Brown4be44fc2005-08-05 00:44:28 -0400593struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Len Brown4be44fc2005-08-05 00:44:28 -0400595 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Bob Mooreb229cf92006-04-21 17:15:00 -0400597 ACPI_FUNCTION_TRACE(ds_pop_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 walk_state = thread->walk_state_list;
600
601 if (walk_state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 /* Next walk state becomes the current walk state */
604
605 thread->walk_state_list = walk_state->next;
606
607 /*
608 * Don't clear the NEXT field, this serves as an indicator
609 * that there is a parent WALK STATE
Robert Moore44f6c012005-04-18 22:49:35 -0400610 * Do Not: walk_state->Next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 */
612 }
613
Len Brown4be44fc2005-08-05 00:44:28 -0400614 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615}
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617/*******************************************************************************
618 *
619 * FUNCTION: acpi_ds_create_walk_state
620 *
Robert Moore44f6c012005-04-18 22:49:35 -0400621 * PARAMETERS: owner_id - ID for object creation
622 * Origin - Starting point for this walk
Bob Moore616861242006-03-17 16:44:00 -0500623 * method_desc - Method object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 * Thread - Current thread state
625 *
626 * RETURN: Pointer to the new walk state.
627 *
628 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
629 * state is set to this new state.
630 *
631 ******************************************************************************/
632
Len Brown4be44fc2005-08-05 00:44:28 -0400633struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
634 union acpi_parse_object
635 *origin,
636 union acpi_operand_object
Bob Moore616861242006-03-17 16:44:00 -0500637 *method_desc,
Len Brown4be44fc2005-08-05 00:44:28 -0400638 struct acpi_thread_state
639 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
Len Brown4be44fc2005-08-05 00:44:28 -0400641 struct acpi_walk_state *walk_state;
642 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Bob Mooreb229cf92006-04-21 17:15:00 -0400644 ACPI_FUNCTION_TRACE(ds_create_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Bob Moore83135242006-10-03 00:00:00 -0400646 walk_state = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (!walk_state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400648 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650
Bob Moore616861242006-03-17 16:44:00 -0500651 walk_state->descriptor_type = ACPI_DESC_TYPE_WALK;
652 walk_state->method_desc = method_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400653 walk_state->owner_id = owner_id;
654 walk_state->origin = origin;
Len Brown4be44fc2005-08-05 00:44:28 -0400655 walk_state->thread = thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 walk_state->parser_state.start_op = origin;
658
659 /* Init the method args/local */
660
661#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
Len Brown4be44fc2005-08-05 00:44:28 -0400662 acpi_ds_method_data_init(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663#endif
664
665 /* Create an initial result stack entry */
666
Len Brown4be44fc2005-08-05 00:44:28 -0400667 status = acpi_ds_result_stack_push(walk_state);
668 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400669 ACPI_FREE(walk_state);
Len Brown4be44fc2005-08-05 00:44:28 -0400670 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672
673 /* Put the new state at the head of the walk list */
674
675 if (thread) {
Len Brown4be44fc2005-08-05 00:44:28 -0400676 acpi_ds_push_walk_state(walk_state, thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 }
678
Len Brown4be44fc2005-08-05 00:44:28 -0400679 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682/*******************************************************************************
683 *
684 * FUNCTION: acpi_ds_init_aml_walk
685 *
686 * PARAMETERS: walk_state - New state to be initialized
687 * Op - Current parse op
688 * method_node - Control method NS node, if any
689 * aml_start - Start of AML
690 * aml_length - Length of AML
Robert Moore44f6c012005-04-18 22:49:35 -0400691 * Info - Method info block (params, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 * pass_number - 1, 2, or 3
693 *
694 * RETURN: Status
695 *
696 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
697 *
698 ******************************************************************************/
699
700acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400701acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
702 union acpi_parse_object *op,
703 struct acpi_namespace_node *method_node,
704 u8 * aml_start,
705 u32 aml_length,
Bob Moore41195322006-05-26 16:36:00 -0400706 struct acpi_evaluate_info *info, u8 pass_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Len Brown4be44fc2005-08-05 00:44:28 -0400708 acpi_status status;
709 struct acpi_parse_state *parser_state = &walk_state->parser_state;
710 union acpi_parse_object *extra_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Bob Mooreb229cf92006-04-21 17:15:00 -0400712 ACPI_FUNCTION_TRACE(ds_init_aml_walk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Len Brown4be44fc2005-08-05 00:44:28 -0400714 walk_state->parser_state.aml =
715 walk_state->parser_state.aml_start = aml_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 walk_state->parser_state.aml_end =
Len Brown4be44fc2005-08-05 00:44:28 -0400717 walk_state->parser_state.pkg_end = aml_start + aml_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 /* The next_op of the next_walk will be the beginning of the method */
720
Robert Moore44f6c012005-04-18 22:49:35 -0400721 walk_state->next_op = NULL;
Robert Moore0c9938c2005-07-29 15:15:00 -0700722 walk_state->pass_number = pass_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 if (info) {
725 if (info->parameter_type == ACPI_PARAM_GPE) {
Len Brown4be44fc2005-08-05 00:44:28 -0400726 walk_state->gpe_event_info =
727 ACPI_CAST_PTR(struct acpi_gpe_event_info,
728 info->parameters);
729 } else {
730 walk_state->params = info->parameters;
Robert Moore44f6c012005-04-18 22:49:35 -0400731 walk_state->caller_return_desc = &info->return_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 }
733 }
734
Len Brown4be44fc2005-08-05 00:44:28 -0400735 status = acpi_ps_init_scope(&walk_state->parser_state, op);
736 if (ACPI_FAILURE(status)) {
737 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
739
740 if (method_node) {
741 walk_state->parser_state.start_node = method_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400742 walk_state->walk_type = ACPI_WALK_METHOD;
743 walk_state->method_node = method_node;
744 walk_state->method_desc =
745 acpi_ns_get_attached_object(method_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 /* Push start scope on scope stack and make it current */
748
Len Brown4be44fc2005-08-05 00:44:28 -0400749 status =
750 acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
751 walk_state);
752 if (ACPI_FAILURE(status)) {
753 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 }
755
756 /* Init the method arguments */
757
Len Brown4be44fc2005-08-05 00:44:28 -0400758 status = acpi_ds_method_data_init_args(walk_state->params,
759 ACPI_METHOD_NUM_ARGS,
760 walk_state);
761 if (ACPI_FAILURE(status)) {
762 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
Len Brown4be44fc2005-08-05 00:44:28 -0400764 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 /*
766 * Setup the current scope.
767 * Find a Named Op that has a namespace node associated with it.
768 * search upwards from this Op. Current scope is the first
769 * Op with a namespace node.
770 */
771 extra_op = parser_state->start_op;
772 while (extra_op && !extra_op->common.node) {
773 extra_op = extra_op->common.parent;
774 }
775
776 if (!extra_op) {
777 parser_state->start_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400778 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 parser_state->start_node = extra_op->common.node;
780 }
781
782 if (parser_state->start_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 /* Push start scope on scope stack and make it current */
785
Len Brown4be44fc2005-08-05 00:44:28 -0400786 status =
787 acpi_ds_scope_stack_push(parser_state->start_node,
788 parser_state->start_node->
789 type, walk_state);
790 if (ACPI_FAILURE(status)) {
791 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 }
793 }
794 }
795
Len Brown4be44fc2005-08-05 00:44:28 -0400796 status = acpi_ds_init_callbacks(walk_state, pass_number);
797 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800/*******************************************************************************
801 *
802 * FUNCTION: acpi_ds_delete_walk_state
803 *
804 * PARAMETERS: walk_state - State to delete
805 *
806 * RETURN: Status
807 *
808 * DESCRIPTION: Delete a walk state including all internal data structures
809 *
810 ******************************************************************************/
811
Len Brown4be44fc2005-08-05 00:44:28 -0400812void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Len Brown4be44fc2005-08-05 00:44:28 -0400814 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Bob Mooreb229cf92006-04-21 17:15:00 -0400816 ACPI_FUNCTION_TRACE_PTR(ds_delete_walk_state, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 if (!walk_state) {
819 return;
820 }
821
Bob Moore616861242006-03-17 16:44:00 -0500822 if (walk_state->descriptor_type != ACPI_DESC_TYPE_WALK) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500823 ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
824 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 return;
826 }
827
Bob Moore41195322006-05-26 16:36:00 -0400828 /* There should not be any open scopes */
829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 if (walk_state->parser_state.scope) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500831 ACPI_ERROR((AE_INFO, "%p walk still has a scope list",
832 walk_state));
Bob Moore41195322006-05-26 16:36:00 -0400833 acpi_ps_cleanup_scope(&walk_state->parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835
836 /* Always must free any linked control states */
837
838 while (walk_state->control_state) {
839 state = walk_state->control_state;
840 walk_state->control_state = state->common.next;
841
Len Brown4be44fc2005-08-05 00:44:28 -0400842 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
844
845 /* Always must free any linked parse states */
846
847 while (walk_state->scope_info) {
848 state = walk_state->scope_info;
849 walk_state->scope_info = state->common.next;
850
Len Brown4be44fc2005-08-05 00:44:28 -0400851 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 }
853
854 /* Always must free any stacked result states */
855
856 while (walk_state->results) {
857 state = walk_state->results;
858 walk_state->results = state->common.next;
859
Len Brown4be44fc2005-08-05 00:44:28 -0400860 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
862
Bob Moore83135242006-10-03 00:00:00 -0400863 ACPI_FREE(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 return_VOID;
865}
866
Robert Moore44f6c012005-04-18 22:49:35 -0400867#ifdef ACPI_OBSOLETE_FUNCTIONS
868/*******************************************************************************
869 *
870 * FUNCTION: acpi_ds_result_insert
871 *
872 * PARAMETERS: Object - Object to push
873 * Index - Where to insert the object
874 * walk_state - Current Walk state
875 *
876 * RETURN: Status
877 *
878 * DESCRIPTION: Insert an object onto this walk's result stack
879 *
880 ******************************************************************************/
881
882acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400883acpi_ds_result_insert(void *object,
884 u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400885{
Len Brown4be44fc2005-08-05 00:44:28 -0400886 union acpi_generic_state *state;
Robert Moore44f6c012005-04-18 22:49:35 -0400887
Bob Mooreb229cf92006-04-21 17:15:00 -0400888 ACPI_FUNCTION_NAME(ds_result_insert);
Robert Moore44f6c012005-04-18 22:49:35 -0400889
890 state = walk_state->results;
891 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500892 ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
893 walk_state));
Robert Moore44f6c012005-04-18 22:49:35 -0400894 return (AE_NOT_EXIST);
895 }
896
897 if (index >= ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500898 ACPI_ERROR((AE_INFO,
899 "Index out of range: %X Obj=%p State=%p Num=%X",
900 index, object, walk_state,
901 state->results.num_results));
Robert Moore44f6c012005-04-18 22:49:35 -0400902 return (AE_BAD_PARAMETER);
903 }
904
905 if (!object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500906 ACPI_ERROR((AE_INFO,
907 "Null Object! Index=%X Obj=%p State=%p Num=%X",
908 index, object, walk_state,
909 state->results.num_results));
Robert Moore44f6c012005-04-18 22:49:35 -0400910 return (AE_BAD_PARAMETER);
911 }
912
Len Brown4be44fc2005-08-05 00:44:28 -0400913 state->results.obj_desc[index] = object;
Robert Moore44f6c012005-04-18 22:49:35 -0400914 state->results.num_results++;
915
Len Brown4be44fc2005-08-05 00:44:28 -0400916 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
917 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
918 object,
919 object ?
920 acpi_ut_get_object_type_name((union
921 acpi_operand_object *)
922 object) : "NULL",
923 walk_state, state->results.num_results,
924 walk_state->current_result));
Robert Moore44f6c012005-04-18 22:49:35 -0400925
926 return (AE_OK);
927}
928
Robert Moore44f6c012005-04-18 22:49:35 -0400929/*******************************************************************************
930 *
931 * FUNCTION: acpi_ds_obj_stack_delete_all
932 *
933 * PARAMETERS: walk_state - Current Walk state
934 *
935 * RETURN: Status
936 *
937 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
938 * Should be used with great care, if at all!
939 *
940 ******************************************************************************/
941
Len Brown4be44fc2005-08-05 00:44:28 -0400942acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state * walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400943{
Len Brown4be44fc2005-08-05 00:44:28 -0400944 u32 i;
Robert Moore44f6c012005-04-18 22:49:35 -0400945
Bob Mooreb229cf92006-04-21 17:15:00 -0400946 ACPI_FUNCTION_TRACE_PTR(ds_obj_stack_delete_all, walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -0400947
948 /* The stack size is configurable, but fixed */
949
950 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
951 if (walk_state->operands[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400952 acpi_ut_remove_reference(walk_state->operands[i]);
Robert Moore44f6c012005-04-18 22:49:35 -0400953 walk_state->operands[i] = NULL;
954 }
955 }
956
Len Brown4be44fc2005-08-05 00:44:28 -0400957 return_ACPI_STATUS(AE_OK);
Robert Moore44f6c012005-04-18 22:49:35 -0400958}
959
Robert Moore44f6c012005-04-18 22:49:35 -0400960/*******************************************************************************
961 *
962 * FUNCTION: acpi_ds_obj_stack_pop_object
963 *
964 * PARAMETERS: Object - Where to return the popped object
965 * walk_state - Current Walk state
966 *
967 * RETURN: Status
968 *
969 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
970 * deleted by this routine.
971 *
972 ******************************************************************************/
973
974acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400975acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
976 struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400977{
Bob Mooreb229cf92006-04-21 17:15:00 -0400978 ACPI_FUNCTION_NAME(ds_obj_stack_pop_object);
Robert Moore44f6c012005-04-18 22:49:35 -0400979
980 /* Check for stack underflow */
981
982 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500983 ACPI_ERROR((AE_INFO,
984 "Missing operand/stack empty! State=%p #Ops=%X",
985 walk_state, walk_state->num_operands));
Robert Moore44f6c012005-04-18 22:49:35 -0400986 *object = NULL;
987 return (AE_AML_NO_OPERAND);
988 }
989
990 /* Pop the stack */
991
992 walk_state->num_operands--;
993
994 /* Check for a valid operand */
995
Len Brown4be44fc2005-08-05 00:44:28 -0400996 if (!walk_state->operands[walk_state->num_operands]) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500997 ACPI_ERROR((AE_INFO,
998 "Null operand! State=%p #Ops=%X",
999 walk_state, walk_state->num_operands));
Robert Moore44f6c012005-04-18 22:49:35 -04001000 *object = NULL;
1001 return (AE_AML_NO_OPERAND);
1002 }
1003
1004 /* Get operand and set stack entry to null */
1005
Len Brown4be44fc2005-08-05 00:44:28 -04001006 *object = walk_state->operands[walk_state->num_operands];
1007 walk_state->operands[walk_state->num_operands] = NULL;
Robert Moore44f6c012005-04-18 22:49:35 -04001008
Len Brown4be44fc2005-08-05 00:44:28 -04001009 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1010 *object, acpi_ut_get_object_type_name(*object),
Robert Moore44f6c012005-04-18 22:49:35 -04001011 walk_state, walk_state->num_operands));
1012
1013 return (AE_OK);
1014}
1015
Robert Moore44f6c012005-04-18 22:49:35 -04001016/*******************************************************************************
1017 *
1018 * FUNCTION: acpi_ds_obj_stack_get_value
1019 *
1020 * PARAMETERS: Index - Stack index whose value is desired. Based
1021 * on the top of the stack (index=0 == top)
1022 * walk_state - Current Walk state
1023 *
1024 * RETURN: Pointer to the requested operand
1025 *
1026 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1027 * be within the range of the current stack pointer.
1028 *
1029 ******************************************************************************/
1030
Len Brown4be44fc2005-08-05 00:44:28 -04001031void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -04001032{
1033
Bob Mooreb229cf92006-04-21 17:15:00 -04001034 ACPI_FUNCTION_TRACE_PTR(ds_obj_stack_get_value, walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -04001035
1036 /* Can't do it if the stack is empty */
1037
1038 if (walk_state->num_operands == 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001039 return_PTR(NULL);
Robert Moore44f6c012005-04-18 22:49:35 -04001040 }
1041
1042 /* or if the index is past the top of the stack */
1043
1044 if (index > (walk_state->num_operands - (u32) 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001045 return_PTR(NULL);
Robert Moore44f6c012005-04-18 22:49:35 -04001046 }
1047
Len Brown4be44fc2005-08-05 00:44:28 -04001048 return_PTR(walk_state->
1049 operands[(acpi_native_uint) (walk_state->num_operands - 1) -
1050 index]);
Robert Moore44f6c012005-04-18 22:49:35 -04001051}
1052#endif