blob: 5bc340b1b286ce04d30f1b1a902d96540dafcc0d [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 *
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) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050095 ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
96 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return (AE_NOT_EXIST);
98 }
99
100 if (index >= ACPI_OBJ_MAX_OPERAND) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500101 ACPI_ERROR((AE_INFO,
102 "Index out of range: %X State=%p Num=%X",
103 index, walk_state, state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
106 /* Check for a valid result object */
107
Len Brown4be44fc2005-08-05 00:44:28 -0400108 if (!state->results.obj_desc[index]) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500109 ACPI_ERROR((AE_INFO,
110 "Null operand! State=%p #Ops=%X, Index=%X",
111 walk_state, state->results.num_results, index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return (AE_AML_NO_RETURN_VALUE);
113 }
114
115 /* Remove the object */
116
117 state->results.num_results--;
118
Len Brown4be44fc2005-08-05 00:44:28 -0400119 *object = state->results.obj_desc[index];
120 state->results.obj_desc[index] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Len Brown4be44fc2005-08-05 00:44:28 -0400122 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
123 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
124 *object,
125 (*object) ? acpi_ut_get_object_type_name(*object) :
126 "NULL", index, walk_state,
127 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 return (AE_OK);
130}
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132#endif /* ACPI_FUTURE_USAGE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134/*******************************************************************************
135 *
136 * FUNCTION: acpi_ds_result_pop
137 *
138 * PARAMETERS: Object - Where to return the popped object
139 * walk_state - Current Walk state
140 *
141 * RETURN: Status
142 *
143 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
144 * other words, this is a FIFO.
145 *
146 ******************************************************************************/
147
148acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400149acpi_ds_result_pop(union acpi_operand_object ** object,
150 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Len Brown4be44fc2005-08-05 00:44:28 -0400152 acpi_native_uint index;
153 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 ACPI_FUNCTION_NAME("ds_result_pop");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 state = walk_state->results;
158 if (!state) {
159 return (AE_OK);
160 }
161
162 if (!state->results.num_results) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500163 ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
164 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 return (AE_AML_NO_RETURN_VALUE);
166 }
167
168 /* Remove top element */
169
170 state->results.num_results--;
171
172 for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 /* Check for a valid result object */
175
Len Brown4be44fc2005-08-05 00:44:28 -0400176 if (state->results.obj_desc[index - 1]) {
177 *object = state->results.obj_desc[index - 1];
178 state->results.obj_desc[index - 1] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Len Brown4be44fc2005-08-05 00:44:28 -0400180 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
181 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
182 *object,
183 (*object) ?
184 acpi_ut_get_object_type_name(*object)
185 : "NULL", (u32) index - 1, walk_state,
186 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 return (AE_OK);
189 }
190 }
191
Bob Mooreb8e4d892006-01-27 16:43:00 -0500192 ACPI_ERROR((AE_INFO, "No result objects! State=%p", walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return (AE_AML_NO_RETURN_VALUE);
194}
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196/*******************************************************************************
197 *
198 * FUNCTION: acpi_ds_result_pop_from_bottom
199 *
200 * PARAMETERS: Object - Where to return the popped object
201 * walk_state - Current Walk state
202 *
203 * RETURN: Status
204 *
205 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
206 * other words, this is a FIFO.
207 *
208 ******************************************************************************/
209
210acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400211acpi_ds_result_pop_from_bottom(union acpi_operand_object ** object,
212 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Len Brown4be44fc2005-08-05 00:44:28 -0400214 acpi_native_uint index;
215 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Len Brown4be44fc2005-08-05 00:44:28 -0400217 ACPI_FUNCTION_NAME("ds_result_pop_from_bottom");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 state = walk_state->results;
220 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500221 ACPI_ERROR((AE_INFO,
222 "No result object pushed! State=%p", walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 return (AE_NOT_EXIST);
224 }
225
226 if (!state->results.num_results) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500227 ACPI_ERROR((AE_INFO, "No result objects! State=%p",
228 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 return (AE_AML_NO_RETURN_VALUE);
230 }
231
232 /* Remove Bottom element */
233
Len Brown4be44fc2005-08-05 00:44:28 -0400234 *object = state->results.obj_desc[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 /* Push entire stack down one element */
237
238 for (index = 0; index < state->results.num_results; index++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400239 state->results.obj_desc[index] =
240 state->results.obj_desc[index + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
242
243 state->results.num_results--;
244
245 /* Check for a valid result object */
246
247 if (!*object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500248 ACPI_ERROR((AE_INFO,
249 "Null operand! State=%p #Ops=%X Index=%X",
250 walk_state, state->results.num_results,
251 (u32) index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return (AE_AML_NO_RETURN_VALUE);
253 }
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n",
256 *object,
257 (*object) ? acpi_ut_get_object_type_name(*object) :
258 "NULL", state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 return (AE_OK);
261}
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263/*******************************************************************************
264 *
265 * FUNCTION: acpi_ds_result_push
266 *
267 * PARAMETERS: Object - Where to return the popped object
268 * walk_state - Current Walk state
269 *
270 * RETURN: Status
271 *
272 * DESCRIPTION: Push an object onto the current result stack
273 *
274 ******************************************************************************/
275
276acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400277acpi_ds_result_push(union acpi_operand_object * object,
278 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Len Brown4be44fc2005-08-05 00:44:28 -0400280 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Len Brown4be44fc2005-08-05 00:44:28 -0400282 ACPI_FUNCTION_NAME("ds_result_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 state = walk_state->results;
285 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500286 ACPI_ERROR((AE_INFO, "No result stack frame during push"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 return (AE_AML_INTERNAL);
288 }
289
290 if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500291 ACPI_ERROR((AE_INFO,
292 "Result stack overflow: Obj=%p State=%p Num=%X",
293 object, walk_state, state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 return (AE_STACK_OVERFLOW);
295 }
296
297 if (!object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500298 ACPI_ERROR((AE_INFO,
299 "Null Object! Obj=%p State=%p Num=%X",
300 object, walk_state, state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 return (AE_BAD_PARAMETER);
302 }
303
Len Brown4be44fc2005-08-05 00:44:28 -0400304 state->results.obj_desc[state->results.num_results] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 state->results.num_results++;
306
Len Brown4be44fc2005-08-05 00:44:28 -0400307 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
308 object,
309 object ?
310 acpi_ut_get_object_type_name((union
311 acpi_operand_object *)
312 object) : "NULL",
313 walk_state, state->results.num_results,
314 walk_state->current_result));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 return (AE_OK);
317}
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319/*******************************************************************************
320 *
321 * FUNCTION: acpi_ds_result_stack_push
322 *
323 * PARAMETERS: walk_state - Current Walk state
324 *
325 * RETURN: Status
326 *
327 * DESCRIPTION: Push an object onto the walk_state result stack.
328 *
329 ******************************************************************************/
330
Len Brown4be44fc2005-08-05 00:44:28 -0400331acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Len Brown4be44fc2005-08-05 00:44:28 -0400333 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Len Brown4be44fc2005-08-05 00:44:28 -0400335 ACPI_FUNCTION_NAME("ds_result_stack_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Len Brown4be44fc2005-08-05 00:44:28 -0400337 state = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if (!state) {
339 return (AE_NO_MEMORY);
340 }
341
342 state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400343 acpi_ut_push_generic_state(&walk_state->results, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Len Brown4be44fc2005-08-05 00:44:28 -0400345 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
346 state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 return (AE_OK);
349}
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351/*******************************************************************************
352 *
353 * FUNCTION: acpi_ds_result_stack_pop
354 *
355 * PARAMETERS: walk_state - Current Walk state
356 *
357 * RETURN: Status
358 *
359 * DESCRIPTION: Pop an object off of the walk_state result stack.
360 *
361 ******************************************************************************/
362
Len Brown4be44fc2005-08-05 00:44:28 -0400363acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Len Brown4be44fc2005-08-05 00:44:28 -0400365 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Len Brown4be44fc2005-08-05 00:44:28 -0400367 ACPI_FUNCTION_NAME("ds_result_stack_pop");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
369 /* Check for stack underflow */
370
371 if (walk_state->results == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400372 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n",
373 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 return (AE_AML_NO_OPERAND);
375 }
376
Len Brown4be44fc2005-08-05 00:44:28 -0400377 state = acpi_ut_pop_generic_state(&walk_state->results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
380 "Result=%p remaining_results=%X State=%p\n",
381 state, state->results.num_results, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Len Brown4be44fc2005-08-05 00:44:28 -0400383 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 return (AE_OK);
386}
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388/*******************************************************************************
389 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 * FUNCTION: acpi_ds_obj_stack_push
391 *
392 * PARAMETERS: Object - Object to push
393 * walk_state - Current Walk state
394 *
395 * RETURN: Status
396 *
397 * DESCRIPTION: Push an object onto this walk's object/operand stack
398 *
399 ******************************************************************************/
400
401acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400402acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Len Brown4be44fc2005-08-05 00:44:28 -0400404 ACPI_FUNCTION_NAME("ds_obj_stack_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 /* Check for stack overflow */
407
408 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500409 ACPI_ERROR((AE_INFO,
410 "Object stack overflow! Obj=%p State=%p #Ops=%X",
411 object, walk_state, walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return (AE_STACK_OVERFLOW);
413 }
414
415 /* Put the object onto the stack */
416
Len Brown4be44fc2005-08-05 00:44:28 -0400417 walk_state->operands[walk_state->num_operands] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 walk_state->num_operands++;
419
Len Brown4be44fc2005-08-05 00:44:28 -0400420 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
421 object,
422 acpi_ut_get_object_type_name((union
423 acpi_operand_object *)
424 object), walk_state,
425 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 return (AE_OK);
428}
429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430/*******************************************************************************
431 *
432 * FUNCTION: acpi_ds_obj_stack_pop
433 *
434 * PARAMETERS: pop_count - Number of objects/entries to pop
435 * walk_state - Current Walk state
436 *
437 * RETURN: Status
438 *
439 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
440 * deleted by this routine.
441 *
442 ******************************************************************************/
443
444acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400445acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
Len Brown4be44fc2005-08-05 00:44:28 -0400447 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Len Brown4be44fc2005-08-05 00:44:28 -0400449 ACPI_FUNCTION_NAME("ds_obj_stack_pop");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 for (i = 0; i < pop_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 /* Check for stack underflow */
454
455 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500456 ACPI_ERROR((AE_INFO,
457 "Object stack underflow! Count=%X State=%p #Ops=%X",
458 pop_count, walk_state,
459 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 return (AE_STACK_UNDERFLOW);
461 }
462
463 /* Just set the stack entry to null */
464
465 walk_state->num_operands--;
Len Brown4be44fc2005-08-05 00:44:28 -0400466 walk_state->operands[walk_state->num_operands] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468
Len Brown4be44fc2005-08-05 00:44:28 -0400469 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 pop_count, walk_state, walk_state->num_operands));
471
472 return (AE_OK);
473}
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475/*******************************************************************************
476 *
477 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
478 *
479 * PARAMETERS: pop_count - Number of objects/entries to pop
480 * walk_state - Current Walk state
481 *
482 * RETURN: Status
483 *
484 * DESCRIPTION: Pop this walk's object stack and delete each object that is
485 * popped off.
486 *
487 ******************************************************************************/
488
489acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400490acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
491 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
Len Brown4be44fc2005-08-05 00:44:28 -0400493 u32 i;
494 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Len Brown4be44fc2005-08-05 00:44:28 -0400496 ACPI_FUNCTION_NAME("ds_obj_stack_pop_and_delete");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 for (i = 0; i < pop_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 /* Check for stack underflow */
501
502 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500503 ACPI_ERROR((AE_INFO,
504 "Object stack underflow! Count=%X State=%p #Ops=%X",
505 pop_count, walk_state,
506 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 return (AE_STACK_UNDERFLOW);
508 }
509
510 /* Pop the stack and delete an object if present in this stack entry */
511
512 walk_state->num_operands--;
Len Brown4be44fc2005-08-05 00:44:28 -0400513 obj_desc = walk_state->operands[walk_state->num_operands];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 if (obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400515 acpi_ut_remove_reference(walk_state->
516 operands[walk_state->
517 num_operands]);
518 walk_state->operands[walk_state->num_operands] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 }
520 }
521
Len Brown4be44fc2005-08-05 00:44:28 -0400522 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 pop_count, walk_state, walk_state->num_operands));
524
525 return (AE_OK);
526}
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528/*******************************************************************************
529 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 * FUNCTION: acpi_ds_get_current_walk_state
531 *
532 * PARAMETERS: Thread - Get current active state for this Thread
533 *
534 * RETURN: Pointer to the current walk state
535 *
536 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
537 * walk state.)
538 *
539 ******************************************************************************/
540
Len Brown4be44fc2005-08-05 00:44:28 -0400541struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
542 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Len Brown4be44fc2005-08-05 00:44:28 -0400544 ACPI_FUNCTION_NAME("ds_get_current_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 if (!thread) {
547 return (NULL);
548 }
549
Len Brown4be44fc2005-08-05 00:44:28 -0400550 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current walk_state %p\n",
551 thread->walk_state_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 return (thread->walk_state_list);
554}
555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556/*******************************************************************************
557 *
558 * FUNCTION: acpi_ds_push_walk_state
559 *
560 * PARAMETERS: walk_state - State to push
Robert Moore44f6c012005-04-18 22:49:35 -0400561 * Thread - Thread state object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 *
563 * RETURN: None
564 *
Robert Moore44f6c012005-04-18 22:49:35 -0400565 * DESCRIPTION: Place the Thread state at the head of the state list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 *
567 ******************************************************************************/
568
569void
Len Brown4be44fc2005-08-05 00:44:28 -0400570acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
571 struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
Len Brown4be44fc2005-08-05 00:44:28 -0400573 ACPI_FUNCTION_TRACE("ds_push_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Len Brown4be44fc2005-08-05 00:44:28 -0400575 walk_state->next = thread->walk_state_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 thread->walk_state_list = walk_state;
577
578 return_VOID;
579}
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581/*******************************************************************************
582 *
583 * FUNCTION: acpi_ds_pop_walk_state
584 *
Robert Moore44f6c012005-04-18 22:49:35 -0400585 * PARAMETERS: Thread - Current thread state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 *
Robert Moore44f6c012005-04-18 22:49:35 -0400587 * RETURN: A walk_state object popped from the thread's stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 *
589 * DESCRIPTION: Remove and return the walkstate object that is at the head of
590 * the walk stack for the given walk list. NULL indicates that
591 * the list is empty.
592 *
593 ******************************************************************************/
594
Len Brown4be44fc2005-08-05 00:44:28 -0400595struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Len Brown4be44fc2005-08-05 00:44:28 -0400597 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Len Brown4be44fc2005-08-05 00:44:28 -0400599 ACPI_FUNCTION_TRACE("ds_pop_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 walk_state = thread->walk_state_list;
602
603 if (walk_state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 /* Next walk state becomes the current walk state */
606
607 thread->walk_state_list = walk_state->next;
608
609 /*
610 * Don't clear the NEXT field, this serves as an indicator
611 * that there is a parent WALK STATE
Robert Moore44f6c012005-04-18 22:49:35 -0400612 * Do Not: walk_state->Next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 */
614 }
615
Len Brown4be44fc2005-08-05 00:44:28 -0400616 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619/*******************************************************************************
620 *
621 * FUNCTION: acpi_ds_create_walk_state
622 *
Robert Moore44f6c012005-04-18 22:49:35 -0400623 * PARAMETERS: owner_id - ID for object creation
624 * Origin - Starting point for this walk
625 * mth_desc - Method object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 * Thread - Current thread state
627 *
628 * RETURN: Pointer to the new walk state.
629 *
630 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
631 * state is set to this new state.
632 *
633 ******************************************************************************/
634
Len Brown4be44fc2005-08-05 00:44:28 -0400635struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
636 union acpi_parse_object
637 *origin,
638 union acpi_operand_object
639 *mth_desc,
640 struct acpi_thread_state
641 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642{
Len Brown4be44fc2005-08-05 00:44:28 -0400643 struct acpi_walk_state *walk_state;
644 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Len Brown4be44fc2005-08-05 00:44:28 -0400646 ACPI_FUNCTION_TRACE("ds_create_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Len Brown4be44fc2005-08-05 00:44:28 -0400648 walk_state = ACPI_MEM_CALLOCATE(sizeof(struct acpi_walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 if (!walk_state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400650 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 }
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653 walk_state->data_type = ACPI_DESC_TYPE_WALK;
654 walk_state->owner_id = owner_id;
655 walk_state->origin = origin;
656 walk_state->method_desc = mth_desc;
657 walk_state->thread = thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 walk_state->parser_state.start_op = origin;
660
661 /* Init the method args/local */
662
663#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
Len Brown4be44fc2005-08-05 00:44:28 -0400664 acpi_ds_method_data_init(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#endif
666
667 /* Create an initial result stack entry */
668
Len Brown4be44fc2005-08-05 00:44:28 -0400669 status = acpi_ds_result_stack_push(walk_state);
670 if (ACPI_FAILURE(status)) {
671 ACPI_MEM_FREE(walk_state);
672 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674
675 /* Put the new state at the head of the walk list */
676
677 if (thread) {
Len Brown4be44fc2005-08-05 00:44:28 -0400678 acpi_ds_push_walk_state(walk_state, thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 }
680
Len Brown4be44fc2005-08-05 00:44:28 -0400681 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682}
683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684/*******************************************************************************
685 *
686 * FUNCTION: acpi_ds_init_aml_walk
687 *
688 * PARAMETERS: walk_state - New state to be initialized
689 * Op - Current parse op
690 * method_node - Control method NS node, if any
691 * aml_start - Start of AML
692 * aml_length - Length of AML
Robert Moore44f6c012005-04-18 22:49:35 -0400693 * Info - Method info block (params, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 * pass_number - 1, 2, or 3
695 *
696 * RETURN: Status
697 *
698 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
699 *
700 ******************************************************************************/
701
702acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400703acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
704 union acpi_parse_object *op,
705 struct acpi_namespace_node *method_node,
706 u8 * aml_start,
707 u32 aml_length,
708 struct acpi_parameter_info *info, u8 pass_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709{
Len Brown4be44fc2005-08-05 00:44:28 -0400710 acpi_status status;
711 struct acpi_parse_state *parser_state = &walk_state->parser_state;
712 union acpi_parse_object *extra_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Len Brown4be44fc2005-08-05 00:44:28 -0400714 ACPI_FUNCTION_TRACE("ds_init_aml_walk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Len Brown4be44fc2005-08-05 00:44:28 -0400716 walk_state->parser_state.aml =
717 walk_state->parser_state.aml_start = aml_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 walk_state->parser_state.aml_end =
Len Brown4be44fc2005-08-05 00:44:28 -0400719 walk_state->parser_state.pkg_end = aml_start + aml_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721 /* The next_op of the next_walk will be the beginning of the method */
722
Robert Moore44f6c012005-04-18 22:49:35 -0400723 walk_state->next_op = NULL;
Robert Moore0c9938c2005-07-29 15:15:00 -0700724 walk_state->pass_number = pass_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726 if (info) {
727 if (info->parameter_type == ACPI_PARAM_GPE) {
Len Brown4be44fc2005-08-05 00:44:28 -0400728 walk_state->gpe_event_info =
729 ACPI_CAST_PTR(struct acpi_gpe_event_info,
730 info->parameters);
731 } else {
732 walk_state->params = info->parameters;
Robert Moore44f6c012005-04-18 22:49:35 -0400733 walk_state->caller_return_desc = &info->return_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
735 }
736
Len Brown4be44fc2005-08-05 00:44:28 -0400737 status = acpi_ps_init_scope(&walk_state->parser_state, op);
738 if (ACPI_FAILURE(status)) {
739 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741
742 if (method_node) {
743 walk_state->parser_state.start_node = method_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400744 walk_state->walk_type = ACPI_WALK_METHOD;
745 walk_state->method_node = method_node;
746 walk_state->method_desc =
747 acpi_ns_get_attached_object(method_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 /* Push start scope on scope stack and make it current */
750
Len Brown4be44fc2005-08-05 00:44:28 -0400751 status =
752 acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
753 walk_state);
754 if (ACPI_FAILURE(status)) {
755 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757
758 /* Init the method arguments */
759
Len Brown4be44fc2005-08-05 00:44:28 -0400760 status = acpi_ds_method_data_init_args(walk_state->params,
761 ACPI_METHOD_NUM_ARGS,
762 walk_state);
763 if (ACPI_FAILURE(status)) {
764 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 }
Len Brown4be44fc2005-08-05 00:44:28 -0400766 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 /*
768 * Setup the current scope.
769 * Find a Named Op that has a namespace node associated with it.
770 * search upwards from this Op. Current scope is the first
771 * Op with a namespace node.
772 */
773 extra_op = parser_state->start_op;
774 while (extra_op && !extra_op->common.node) {
775 extra_op = extra_op->common.parent;
776 }
777
778 if (!extra_op) {
779 parser_state->start_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400780 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 parser_state->start_node = extra_op->common.node;
782 }
783
784 if (parser_state->start_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 /* Push start scope on scope stack and make it current */
787
Len Brown4be44fc2005-08-05 00:44:28 -0400788 status =
789 acpi_ds_scope_stack_push(parser_state->start_node,
790 parser_state->start_node->
791 type, walk_state);
792 if (ACPI_FAILURE(status)) {
793 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
795 }
796 }
797
Len Brown4be44fc2005-08-05 00:44:28 -0400798 status = acpi_ds_init_callbacks(walk_state, pass_number);
799 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800}
801
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802/*******************************************************************************
803 *
804 * FUNCTION: acpi_ds_delete_walk_state
805 *
806 * PARAMETERS: walk_state - State to delete
807 *
808 * RETURN: Status
809 *
810 * DESCRIPTION: Delete a walk state including all internal data structures
811 *
812 ******************************************************************************/
813
Len Brown4be44fc2005-08-05 00:44:28 -0400814void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Len Brown4be44fc2005-08-05 00:44:28 -0400816 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Len Brown4be44fc2005-08-05 00:44:28 -0400818 ACPI_FUNCTION_TRACE_PTR("ds_delete_walk_state", walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 if (!walk_state) {
821 return;
822 }
823
824 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500825 ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
826 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return;
828 }
829
830 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 }
834
835 /* Always must free any linked control states */
836
837 while (walk_state->control_state) {
838 state = walk_state->control_state;
839 walk_state->control_state = state->common.next;
840
Len Brown4be44fc2005-08-05 00:44:28 -0400841 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 }
843
844 /* Always must free any linked parse states */
845
846 while (walk_state->scope_info) {
847 state = walk_state->scope_info;
848 walk_state->scope_info = state->common.next;
849
Len Brown4be44fc2005-08-05 00:44:28 -0400850 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 }
852
853 /* Always must free any stacked result states */
854
855 while (walk_state->results) {
856 state = walk_state->results;
857 walk_state->results = state->common.next;
858
Len Brown4be44fc2005-08-05 00:44:28 -0400859 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 }
861
Len Brown4be44fc2005-08-05 00:44:28 -0400862 ACPI_MEM_FREE(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 return_VOID;
864}
865
Robert Moore44f6c012005-04-18 22:49:35 -0400866#ifdef ACPI_OBSOLETE_FUNCTIONS
867/*******************************************************************************
868 *
869 * FUNCTION: acpi_ds_result_insert
870 *
871 * PARAMETERS: Object - Object to push
872 * Index - Where to insert the object
873 * walk_state - Current Walk state
874 *
875 * RETURN: Status
876 *
877 * DESCRIPTION: Insert an object onto this walk's result stack
878 *
879 ******************************************************************************/
880
881acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400882acpi_ds_result_insert(void *object,
883 u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400884{
Len Brown4be44fc2005-08-05 00:44:28 -0400885 union acpi_generic_state *state;
Robert Moore44f6c012005-04-18 22:49:35 -0400886
Len Brown4be44fc2005-08-05 00:44:28 -0400887 ACPI_FUNCTION_NAME("ds_result_insert");
Robert Moore44f6c012005-04-18 22:49:35 -0400888
889 state = walk_state->results;
890 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500891 ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
892 walk_state));
Robert Moore44f6c012005-04-18 22:49:35 -0400893 return (AE_NOT_EXIST);
894 }
895
896 if (index >= ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500897 ACPI_ERROR((AE_INFO,
898 "Index out of range: %X Obj=%p State=%p Num=%X",
899 index, object, walk_state,
900 state->results.num_results));
Robert Moore44f6c012005-04-18 22:49:35 -0400901 return (AE_BAD_PARAMETER);
902 }
903
904 if (!object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500905 ACPI_ERROR((AE_INFO,
906 "Null Object! Index=%X Obj=%p State=%p Num=%X",
907 index, object, walk_state,
908 state->results.num_results));
Robert Moore44f6c012005-04-18 22:49:35 -0400909 return (AE_BAD_PARAMETER);
910 }
911
Len Brown4be44fc2005-08-05 00:44:28 -0400912 state->results.obj_desc[index] = object;
Robert Moore44f6c012005-04-18 22:49:35 -0400913 state->results.num_results++;
914
Len Brown4be44fc2005-08-05 00:44:28 -0400915 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
916 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
917 object,
918 object ?
919 acpi_ut_get_object_type_name((union
920 acpi_operand_object *)
921 object) : "NULL",
922 walk_state, state->results.num_results,
923 walk_state->current_result));
Robert Moore44f6c012005-04-18 22:49:35 -0400924
925 return (AE_OK);
926}
927
Robert Moore44f6c012005-04-18 22:49:35 -0400928/*******************************************************************************
929 *
930 * FUNCTION: acpi_ds_obj_stack_delete_all
931 *
932 * PARAMETERS: walk_state - Current Walk state
933 *
934 * RETURN: Status
935 *
936 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
937 * Should be used with great care, if at all!
938 *
939 ******************************************************************************/
940
Len Brown4be44fc2005-08-05 00:44:28 -0400941acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state * walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400942{
Len Brown4be44fc2005-08-05 00:44:28 -0400943 u32 i;
Robert Moore44f6c012005-04-18 22:49:35 -0400944
Len Brown4be44fc2005-08-05 00:44:28 -0400945 ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_delete_all", walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -0400946
947 /* The stack size is configurable, but fixed */
948
949 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
950 if (walk_state->operands[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400951 acpi_ut_remove_reference(walk_state->operands[i]);
Robert Moore44f6c012005-04-18 22:49:35 -0400952 walk_state->operands[i] = NULL;
953 }
954 }
955
Len Brown4be44fc2005-08-05 00:44:28 -0400956 return_ACPI_STATUS(AE_OK);
Robert Moore44f6c012005-04-18 22:49:35 -0400957}
958
Robert Moore44f6c012005-04-18 22:49:35 -0400959/*******************************************************************************
960 *
961 * FUNCTION: acpi_ds_obj_stack_pop_object
962 *
963 * PARAMETERS: Object - Where to return the popped object
964 * walk_state - Current Walk state
965 *
966 * RETURN: Status
967 *
968 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
969 * deleted by this routine.
970 *
971 ******************************************************************************/
972
973acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400974acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
975 struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400976{
Len Brown4be44fc2005-08-05 00:44:28 -0400977 ACPI_FUNCTION_NAME("ds_obj_stack_pop_object");
Robert Moore44f6c012005-04-18 22:49:35 -0400978
979 /* Check for stack underflow */
980
981 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500982 ACPI_ERROR((AE_INFO,
983 "Missing operand/stack empty! State=%p #Ops=%X",
984 walk_state, walk_state->num_operands));
Robert Moore44f6c012005-04-18 22:49:35 -0400985 *object = NULL;
986 return (AE_AML_NO_OPERAND);
987 }
988
989 /* Pop the stack */
990
991 walk_state->num_operands--;
992
993 /* Check for a valid operand */
994
Len Brown4be44fc2005-08-05 00:44:28 -0400995 if (!walk_state->operands[walk_state->num_operands]) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500996 ACPI_ERROR((AE_INFO,
997 "Null operand! State=%p #Ops=%X",
998 walk_state, walk_state->num_operands));
Robert Moore44f6c012005-04-18 22:49:35 -0400999 *object = NULL;
1000 return (AE_AML_NO_OPERAND);
1001 }
1002
1003 /* Get operand and set stack entry to null */
1004
Len Brown4be44fc2005-08-05 00:44:28 -04001005 *object = walk_state->operands[walk_state->num_operands];
1006 walk_state->operands[walk_state->num_operands] = NULL;
Robert Moore44f6c012005-04-18 22:49:35 -04001007
Len Brown4be44fc2005-08-05 00:44:28 -04001008 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1009 *object, acpi_ut_get_object_type_name(*object),
Robert Moore44f6c012005-04-18 22:49:35 -04001010 walk_state, walk_state->num_operands));
1011
1012 return (AE_OK);
1013}
1014
Robert Moore44f6c012005-04-18 22:49:35 -04001015/*******************************************************************************
1016 *
1017 * FUNCTION: acpi_ds_obj_stack_get_value
1018 *
1019 * PARAMETERS: Index - Stack index whose value is desired. Based
1020 * on the top of the stack (index=0 == top)
1021 * walk_state - Current Walk state
1022 *
1023 * RETURN: Pointer to the requested operand
1024 *
1025 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1026 * be within the range of the current stack pointer.
1027 *
1028 ******************************************************************************/
1029
Len Brown4be44fc2005-08-05 00:44:28 -04001030void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -04001031{
1032
Len Brown4be44fc2005-08-05 00:44:28 -04001033 ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_get_value", walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -04001034
1035 /* Can't do it if the stack is empty */
1036
1037 if (walk_state->num_operands == 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001038 return_PTR(NULL);
Robert Moore44f6c012005-04-18 22:49:35 -04001039 }
1040
1041 /* or if the index is past the top of the stack */
1042
1043 if (index > (walk_state->num_operands - (u32) 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001044 return_PTR(NULL);
Robert Moore44f6c012005-04-18 22:49:35 -04001045 }
1046
Len Brown4be44fc2005-08-05 00:44:28 -04001047 return_PTR(walk_state->
1048 operands[(acpi_native_uint) (walk_state->num_operands - 1) -
1049 index]);
Robert Moore44f6c012005-04-18 22:49:35 -04001050}
1051#endif