blob: fa78cb74ee367eb69ea4a359d681e1448ee146f5 [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--) {
173 /* Check for a valid result object */
174
Len Brown4be44fc2005-08-05 00:44:28 -0400175 if (state->results.obj_desc[index - 1]) {
176 *object = state->results.obj_desc[index - 1];
177 state->results.obj_desc[index - 1] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Len Brown4be44fc2005-08-05 00:44:28 -0400179 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
180 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
181 *object,
182 (*object) ?
183 acpi_ut_get_object_type_name(*object)
184 : "NULL", (u32) index - 1, walk_state,
185 state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 return (AE_OK);
188 }
189 }
190
Bob Mooreb8e4d892006-01-27 16:43:00 -0500191 ACPI_ERROR((AE_INFO, "No result objects! State=%p", walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return (AE_AML_NO_RETURN_VALUE);
193}
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195/*******************************************************************************
196 *
197 * FUNCTION: acpi_ds_result_pop_from_bottom
198 *
199 * PARAMETERS: Object - Where to return the popped object
200 * walk_state - Current Walk state
201 *
202 * RETURN: Status
203 *
204 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
205 * other words, this is a FIFO.
206 *
207 ******************************************************************************/
208
209acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400210acpi_ds_result_pop_from_bottom(union acpi_operand_object ** object,
211 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
Len Brown4be44fc2005-08-05 00:44:28 -0400213 acpi_native_uint index;
214 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Len Brown4be44fc2005-08-05 00:44:28 -0400216 ACPI_FUNCTION_NAME("ds_result_pop_from_bottom");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218 state = walk_state->results;
219 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500220 ACPI_ERROR((AE_INFO,
221 "No result object pushed! State=%p", walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 return (AE_NOT_EXIST);
223 }
224
225 if (!state->results.num_results) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500226 ACPI_ERROR((AE_INFO, "No result objects! State=%p",
227 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return (AE_AML_NO_RETURN_VALUE);
229 }
230
231 /* Remove Bottom element */
232
Len Brown4be44fc2005-08-05 00:44:28 -0400233 *object = state->results.obj_desc[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 /* Push entire stack down one element */
236
237 for (index = 0; index < state->results.num_results; index++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400238 state->results.obj_desc[index] =
239 state->results.obj_desc[index + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 }
241
242 state->results.num_results--;
243
244 /* Check for a valid result object */
245
246 if (!*object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500247 ACPI_ERROR((AE_INFO,
248 "Null operand! State=%p #Ops=%X Index=%X",
249 walk_state, state->results.num_results,
250 (u32) index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return (AE_AML_NO_RETURN_VALUE);
252 }
253
Len Brown4be44fc2005-08-05 00:44:28 -0400254 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n",
255 *object,
256 (*object) ? acpi_ut_get_object_type_name(*object) :
257 "NULL", state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 return (AE_OK);
260}
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262/*******************************************************************************
263 *
264 * FUNCTION: acpi_ds_result_push
265 *
266 * PARAMETERS: Object - Where to return the popped object
267 * walk_state - Current Walk state
268 *
269 * RETURN: Status
270 *
271 * DESCRIPTION: Push an object onto the current result stack
272 *
273 ******************************************************************************/
274
275acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400276acpi_ds_result_push(union acpi_operand_object * object,
277 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Len Brown4be44fc2005-08-05 00:44:28 -0400279 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Len Brown4be44fc2005-08-05 00:44:28 -0400281 ACPI_FUNCTION_NAME("ds_result_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 state = walk_state->results;
284 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500285 ACPI_ERROR((AE_INFO, "No result stack frame during push"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 return (AE_AML_INTERNAL);
287 }
288
289 if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500290 ACPI_ERROR((AE_INFO,
291 "Result stack overflow: Obj=%p State=%p Num=%X",
292 object, walk_state, state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 return (AE_STACK_OVERFLOW);
294 }
295
296 if (!object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500297 ACPI_ERROR((AE_INFO,
298 "Null Object! Obj=%p State=%p Num=%X",
299 object, walk_state, state->results.num_results));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return (AE_BAD_PARAMETER);
301 }
302
Len Brown4be44fc2005-08-05 00:44:28 -0400303 state->results.obj_desc[state->results.num_results] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 state->results.num_results++;
305
Len Brown4be44fc2005-08-05 00:44:28 -0400306 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
307 object,
308 object ?
309 acpi_ut_get_object_type_name((union
310 acpi_operand_object *)
311 object) : "NULL",
312 walk_state, state->results.num_results,
313 walk_state->current_result));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 return (AE_OK);
316}
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318/*******************************************************************************
319 *
320 * FUNCTION: acpi_ds_result_stack_push
321 *
322 * PARAMETERS: walk_state - Current Walk state
323 *
324 * RETURN: Status
325 *
326 * DESCRIPTION: Push an object onto the walk_state result stack.
327 *
328 ******************************************************************************/
329
Len Brown4be44fc2005-08-05 00:44:28 -0400330acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Len Brown4be44fc2005-08-05 00:44:28 -0400332 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Len Brown4be44fc2005-08-05 00:44:28 -0400334 ACPI_FUNCTION_NAME("ds_result_stack_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Len Brown4be44fc2005-08-05 00:44:28 -0400336 state = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 if (!state) {
338 return (AE_NO_MEMORY);
339 }
340
341 state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400342 acpi_ut_push_generic_state(&walk_state->results, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Len Brown4be44fc2005-08-05 00:44:28 -0400344 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
345 state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 return (AE_OK);
348}
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350/*******************************************************************************
351 *
352 * FUNCTION: acpi_ds_result_stack_pop
353 *
354 * PARAMETERS: walk_state - Current Walk state
355 *
356 * RETURN: Status
357 *
358 * DESCRIPTION: Pop an object off of the walk_state result stack.
359 *
360 ******************************************************************************/
361
Len Brown4be44fc2005-08-05 00:44:28 -0400362acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Len Brown4be44fc2005-08-05 00:44:28 -0400364 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Len Brown4be44fc2005-08-05 00:44:28 -0400366 ACPI_FUNCTION_NAME("ds_result_stack_pop");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 /* Check for stack underflow */
369
370 if (walk_state->results == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400371 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n",
372 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 return (AE_AML_NO_OPERAND);
374 }
375
Len Brown4be44fc2005-08-05 00:44:28 -0400376 state = acpi_ut_pop_generic_state(&walk_state->results);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Len Brown4be44fc2005-08-05 00:44:28 -0400378 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
379 "Result=%p remaining_results=%X State=%p\n",
380 state, state->results.num_results, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Len Brown4be44fc2005-08-05 00:44:28 -0400382 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 return (AE_OK);
385}
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387/*******************************************************************************
388 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 * FUNCTION: acpi_ds_obj_stack_push
390 *
391 * PARAMETERS: Object - Object to push
392 * walk_state - Current Walk state
393 *
394 * RETURN: Status
395 *
396 * DESCRIPTION: Push an object onto this walk's object/operand stack
397 *
398 ******************************************************************************/
399
400acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400401acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
Len Brown4be44fc2005-08-05 00:44:28 -0400403 ACPI_FUNCTION_NAME("ds_obj_stack_push");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405 /* Check for stack overflow */
406
407 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500408 ACPI_ERROR((AE_INFO,
409 "Object stack overflow! Obj=%p State=%p #Ops=%X",
410 object, walk_state, walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 return (AE_STACK_OVERFLOW);
412 }
413
414 /* Put the object onto the stack */
415
Len Brown4be44fc2005-08-05 00:44:28 -0400416 walk_state->operands[walk_state->num_operands] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 walk_state->num_operands++;
418
Len Brown4be44fc2005-08-05 00:44:28 -0400419 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
420 object,
421 acpi_ut_get_object_type_name((union
422 acpi_operand_object *)
423 object), walk_state,
424 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 return (AE_OK);
427}
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429/*******************************************************************************
430 *
431 * FUNCTION: acpi_ds_obj_stack_pop
432 *
433 * PARAMETERS: pop_count - Number of objects/entries to pop
434 * walk_state - Current Walk state
435 *
436 * RETURN: Status
437 *
438 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
439 * deleted by this routine.
440 *
441 ******************************************************************************/
442
443acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400444acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Len Brown4be44fc2005-08-05 00:44:28 -0400446 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Len Brown4be44fc2005-08-05 00:44:28 -0400448 ACPI_FUNCTION_NAME("ds_obj_stack_pop");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 for (i = 0; i < pop_count; i++) {
451 /* 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
Len Brown4be44fc2005-08-05 00:44:28 -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++) {
497 /* Check for stack underflow */
498
499 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500500 ACPI_ERROR((AE_INFO,
501 "Object stack underflow! Count=%X State=%p #Ops=%X",
502 pop_count, walk_state,
503 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 return (AE_STACK_UNDERFLOW);
505 }
506
507 /* Pop the stack and delete an object if present in this stack entry */
508
509 walk_state->num_operands--;
Len Brown4be44fc2005-08-05 00:44:28 -0400510 obj_desc = walk_state->operands[walk_state->num_operands];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 if (obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400512 acpi_ut_remove_reference(walk_state->
513 operands[walk_state->
514 num_operands]);
515 walk_state->operands[walk_state->num_operands] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517 }
518
Len Brown4be44fc2005-08-05 00:44:28 -0400519 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 pop_count, walk_state, walk_state->num_operands));
521
522 return (AE_OK);
523}
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525/*******************************************************************************
526 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 * FUNCTION: acpi_ds_get_current_walk_state
528 *
529 * PARAMETERS: Thread - Get current active state for this Thread
530 *
531 * RETURN: Pointer to the current walk state
532 *
533 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
534 * walk state.)
535 *
536 ******************************************************************************/
537
Len Brown4be44fc2005-08-05 00:44:28 -0400538struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
539 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
Len Brown4be44fc2005-08-05 00:44:28 -0400541 ACPI_FUNCTION_NAME("ds_get_current_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 if (!thread) {
544 return (NULL);
545 }
546
Len Brown4be44fc2005-08-05 00:44:28 -0400547 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current walk_state %p\n",
548 thread->walk_state_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 return (thread->walk_state_list);
551}
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553/*******************************************************************************
554 *
555 * FUNCTION: acpi_ds_push_walk_state
556 *
557 * PARAMETERS: walk_state - State to push
Robert Moore44f6c012005-04-18 22:49:35 -0400558 * Thread - Thread state object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 *
560 * RETURN: None
561 *
Robert Moore44f6c012005-04-18 22:49:35 -0400562 * DESCRIPTION: Place the Thread state at the head of the state list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 *
564 ******************************************************************************/
565
566void
Len Brown4be44fc2005-08-05 00:44:28 -0400567acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
568 struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
Len Brown4be44fc2005-08-05 00:44:28 -0400570 ACPI_FUNCTION_TRACE("ds_push_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 walk_state->next = thread->walk_state_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 thread->walk_state_list = walk_state;
574
575 return_VOID;
576}
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578/*******************************************************************************
579 *
580 * FUNCTION: acpi_ds_pop_walk_state
581 *
Robert Moore44f6c012005-04-18 22:49:35 -0400582 * PARAMETERS: Thread - Current thread state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 *
Robert Moore44f6c012005-04-18 22:49:35 -0400584 * RETURN: A walk_state object popped from the thread's stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 *
586 * DESCRIPTION: Remove and return the walkstate object that is at the head of
587 * the walk stack for the given walk list. NULL indicates that
588 * the list is empty.
589 *
590 ******************************************************************************/
591
Len Brown4be44fc2005-08-05 00:44:28 -0400592struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Len Brown4be44fc2005-08-05 00:44:28 -0400594 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Len Brown4be44fc2005-08-05 00:44:28 -0400596 ACPI_FUNCTION_TRACE("ds_pop_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 walk_state = thread->walk_state_list;
599
600 if (walk_state) {
601 /* Next walk state becomes the current walk state */
602
603 thread->walk_state_list = walk_state->next;
604
605 /*
606 * Don't clear the NEXT field, this serves as an indicator
607 * that there is a parent WALK STATE
Robert Moore44f6c012005-04-18 22:49:35 -0400608 * Do Not: walk_state->Next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 */
610 }
611
Len Brown4be44fc2005-08-05 00:44:28 -0400612 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613}
614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615/*******************************************************************************
616 *
617 * FUNCTION: acpi_ds_create_walk_state
618 *
Robert Moore44f6c012005-04-18 22:49:35 -0400619 * PARAMETERS: owner_id - ID for object creation
620 * Origin - Starting point for this walk
621 * mth_desc - Method object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 * Thread - Current thread state
623 *
624 * RETURN: Pointer to the new walk state.
625 *
626 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
627 * state is set to this new state.
628 *
629 ******************************************************************************/
630
Len Brown4be44fc2005-08-05 00:44:28 -0400631struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
632 union acpi_parse_object
633 *origin,
634 union acpi_operand_object
635 *mth_desc,
636 struct acpi_thread_state
637 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638{
Len Brown4be44fc2005-08-05 00:44:28 -0400639 struct acpi_walk_state *walk_state;
640 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Len Brown4be44fc2005-08-05 00:44:28 -0400642 ACPI_FUNCTION_TRACE("ds_create_walk_state");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Len Brown4be44fc2005-08-05 00:44:28 -0400644 walk_state = ACPI_MEM_CALLOCATE(sizeof(struct acpi_walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (!walk_state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400646 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648
Len Brown4be44fc2005-08-05 00:44:28 -0400649 walk_state->data_type = ACPI_DESC_TYPE_WALK;
650 walk_state->owner_id = owner_id;
651 walk_state->origin = origin;
652 walk_state->method_desc = mth_desc;
653 walk_state->thread = thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655 walk_state->parser_state.start_op = origin;
656
657 /* Init the method args/local */
658
659#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
Len Brown4be44fc2005-08-05 00:44:28 -0400660 acpi_ds_method_data_init(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#endif
662
663 /* Create an initial result stack entry */
664
Len Brown4be44fc2005-08-05 00:44:28 -0400665 status = acpi_ds_result_stack_push(walk_state);
666 if (ACPI_FAILURE(status)) {
667 ACPI_MEM_FREE(walk_state);
668 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 }
670
671 /* Put the new state at the head of the walk list */
672
673 if (thread) {
Len Brown4be44fc2005-08-05 00:44:28 -0400674 acpi_ds_push_walk_state(walk_state, thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
676
Len Brown4be44fc2005-08-05 00:44:28 -0400677 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680/*******************************************************************************
681 *
682 * FUNCTION: acpi_ds_init_aml_walk
683 *
684 * PARAMETERS: walk_state - New state to be initialized
685 * Op - Current parse op
686 * method_node - Control method NS node, if any
687 * aml_start - Start of AML
688 * aml_length - Length of AML
Robert Moore44f6c012005-04-18 22:49:35 -0400689 * Info - Method info block (params, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 * pass_number - 1, 2, or 3
691 *
692 * RETURN: Status
693 *
694 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
695 *
696 ******************************************************************************/
697
698acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400699acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
700 union acpi_parse_object *op,
701 struct acpi_namespace_node *method_node,
702 u8 * aml_start,
703 u32 aml_length,
704 struct acpi_parameter_info *info, u8 pass_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Len Brown4be44fc2005-08-05 00:44:28 -0400706 acpi_status status;
707 struct acpi_parse_state *parser_state = &walk_state->parser_state;
708 union acpi_parse_object *extra_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Len Brown4be44fc2005-08-05 00:44:28 -0400710 ACPI_FUNCTION_TRACE("ds_init_aml_walk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Len Brown4be44fc2005-08-05 00:44:28 -0400712 walk_state->parser_state.aml =
713 walk_state->parser_state.aml_start = aml_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 walk_state->parser_state.aml_end =
Len Brown4be44fc2005-08-05 00:44:28 -0400715 walk_state->parser_state.pkg_end = aml_start + aml_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 /* The next_op of the next_walk will be the beginning of the method */
718
Robert Moore44f6c012005-04-18 22:49:35 -0400719 walk_state->next_op = NULL;
Robert Moore0c9938c2005-07-29 15:15:00 -0700720 walk_state->pass_number = pass_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 if (info) {
723 if (info->parameter_type == ACPI_PARAM_GPE) {
Len Brown4be44fc2005-08-05 00:44:28 -0400724 walk_state->gpe_event_info =
725 ACPI_CAST_PTR(struct acpi_gpe_event_info,
726 info->parameters);
727 } else {
728 walk_state->params = info->parameters;
Robert Moore44f6c012005-04-18 22:49:35 -0400729 walk_state->caller_return_desc = &info->return_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 }
731 }
732
Len Brown4be44fc2005-08-05 00:44:28 -0400733 status = acpi_ps_init_scope(&walk_state->parser_state, op);
734 if (ACPI_FAILURE(status)) {
735 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737
738 if (method_node) {
739 walk_state->parser_state.start_node = method_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400740 walk_state->walk_type = ACPI_WALK_METHOD;
741 walk_state->method_node = method_node;
742 walk_state->method_desc =
743 acpi_ns_get_attached_object(method_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 /* Push start scope on scope stack and make it current */
746
Len Brown4be44fc2005-08-05 00:44:28 -0400747 status =
748 acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
749 walk_state);
750 if (ACPI_FAILURE(status)) {
751 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
753
754 /* Init the method arguments */
755
Len Brown4be44fc2005-08-05 00:44:28 -0400756 status = acpi_ds_method_data_init_args(walk_state->params,
757 ACPI_METHOD_NUM_ARGS,
758 walk_state);
759 if (ACPI_FAILURE(status)) {
760 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 }
Len Brown4be44fc2005-08-05 00:44:28 -0400762 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 /*
764 * Setup the current scope.
765 * Find a Named Op that has a namespace node associated with it.
766 * search upwards from this Op. Current scope is the first
767 * Op with a namespace node.
768 */
769 extra_op = parser_state->start_op;
770 while (extra_op && !extra_op->common.node) {
771 extra_op = extra_op->common.parent;
772 }
773
774 if (!extra_op) {
775 parser_state->start_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400776 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 parser_state->start_node = extra_op->common.node;
778 }
779
780 if (parser_state->start_node) {
781 /* Push start scope on scope stack and make it current */
782
Len Brown4be44fc2005-08-05 00:44:28 -0400783 status =
784 acpi_ds_scope_stack_push(parser_state->start_node,
785 parser_state->start_node->
786 type, walk_state);
787 if (ACPI_FAILURE(status)) {
788 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 }
790 }
791 }
792
Len Brown4be44fc2005-08-05 00:44:28 -0400793 status = acpi_ds_init_callbacks(walk_state, pass_number);
794 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795}
796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797/*******************************************************************************
798 *
799 * FUNCTION: acpi_ds_delete_walk_state
800 *
801 * PARAMETERS: walk_state - State to delete
802 *
803 * RETURN: Status
804 *
805 * DESCRIPTION: Delete a walk state including all internal data structures
806 *
807 ******************************************************************************/
808
Len Brown4be44fc2005-08-05 00:44:28 -0400809void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Len Brown4be44fc2005-08-05 00:44:28 -0400811 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
Len Brown4be44fc2005-08-05 00:44:28 -0400813 ACPI_FUNCTION_TRACE_PTR("ds_delete_walk_state", walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 if (!walk_state) {
816 return;
817 }
818
819 if (walk_state->data_type != ACPI_DESC_TYPE_WALK) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500820 ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
821 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 return;
823 }
824
825 if (walk_state->parser_state.scope) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500826 ACPI_ERROR((AE_INFO, "%p walk still has a scope list",
827 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
829
830 /* Always must free any linked control states */
831
832 while (walk_state->control_state) {
833 state = walk_state->control_state;
834 walk_state->control_state = state->common.next;
835
Len Brown4be44fc2005-08-05 00:44:28 -0400836 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
838
839 /* Always must free any linked parse states */
840
841 while (walk_state->scope_info) {
842 state = walk_state->scope_info;
843 walk_state->scope_info = state->common.next;
844
Len Brown4be44fc2005-08-05 00:44:28 -0400845 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 }
847
848 /* Always must free any stacked result states */
849
850 while (walk_state->results) {
851 state = walk_state->results;
852 walk_state->results = state->common.next;
853
Len Brown4be44fc2005-08-05 00:44:28 -0400854 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 }
856
Len Brown4be44fc2005-08-05 00:44:28 -0400857 ACPI_MEM_FREE(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 return_VOID;
859}
860
Robert Moore44f6c012005-04-18 22:49:35 -0400861#ifdef ACPI_OBSOLETE_FUNCTIONS
862/*******************************************************************************
863 *
864 * FUNCTION: acpi_ds_result_insert
865 *
866 * PARAMETERS: Object - Object to push
867 * Index - Where to insert the object
868 * walk_state - Current Walk state
869 *
870 * RETURN: Status
871 *
872 * DESCRIPTION: Insert an object onto this walk's result stack
873 *
874 ******************************************************************************/
875
876acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400877acpi_ds_result_insert(void *object,
878 u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400879{
Len Brown4be44fc2005-08-05 00:44:28 -0400880 union acpi_generic_state *state;
Robert Moore44f6c012005-04-18 22:49:35 -0400881
Len Brown4be44fc2005-08-05 00:44:28 -0400882 ACPI_FUNCTION_NAME("ds_result_insert");
Robert Moore44f6c012005-04-18 22:49:35 -0400883
884 state = walk_state->results;
885 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500886 ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
887 walk_state));
Robert Moore44f6c012005-04-18 22:49:35 -0400888 return (AE_NOT_EXIST);
889 }
890
891 if (index >= ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500892 ACPI_ERROR((AE_INFO,
893 "Index out of range: %X Obj=%p State=%p Num=%X",
894 index, object, walk_state,
895 state->results.num_results));
Robert Moore44f6c012005-04-18 22:49:35 -0400896 return (AE_BAD_PARAMETER);
897 }
898
899 if (!object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500900 ACPI_ERROR((AE_INFO,
901 "Null Object! Index=%X Obj=%p State=%p Num=%X",
902 index, object, walk_state,
903 state->results.num_results));
Robert Moore44f6c012005-04-18 22:49:35 -0400904 return (AE_BAD_PARAMETER);
905 }
906
Len Brown4be44fc2005-08-05 00:44:28 -0400907 state->results.obj_desc[index] = object;
Robert Moore44f6c012005-04-18 22:49:35 -0400908 state->results.num_results++;
909
Len Brown4be44fc2005-08-05 00:44:28 -0400910 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
911 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
912 object,
913 object ?
914 acpi_ut_get_object_type_name((union
915 acpi_operand_object *)
916 object) : "NULL",
917 walk_state, state->results.num_results,
918 walk_state->current_result));
Robert Moore44f6c012005-04-18 22:49:35 -0400919
920 return (AE_OK);
921}
922
Robert Moore44f6c012005-04-18 22:49:35 -0400923/*******************************************************************************
924 *
925 * FUNCTION: acpi_ds_obj_stack_delete_all
926 *
927 * PARAMETERS: walk_state - Current Walk state
928 *
929 * RETURN: Status
930 *
931 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
932 * Should be used with great care, if at all!
933 *
934 ******************************************************************************/
935
Len Brown4be44fc2005-08-05 00:44:28 -0400936acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state * walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400937{
Len Brown4be44fc2005-08-05 00:44:28 -0400938 u32 i;
Robert Moore44f6c012005-04-18 22:49:35 -0400939
Len Brown4be44fc2005-08-05 00:44:28 -0400940 ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_delete_all", walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -0400941
942 /* The stack size is configurable, but fixed */
943
944 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
945 if (walk_state->operands[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400946 acpi_ut_remove_reference(walk_state->operands[i]);
Robert Moore44f6c012005-04-18 22:49:35 -0400947 walk_state->operands[i] = NULL;
948 }
949 }
950
Len Brown4be44fc2005-08-05 00:44:28 -0400951 return_ACPI_STATUS(AE_OK);
Robert Moore44f6c012005-04-18 22:49:35 -0400952}
953
Robert Moore44f6c012005-04-18 22:49:35 -0400954/*******************************************************************************
955 *
956 * FUNCTION: acpi_ds_obj_stack_pop_object
957 *
958 * PARAMETERS: Object - Where to return the popped object
959 * walk_state - Current Walk state
960 *
961 * RETURN: Status
962 *
963 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
964 * deleted by this routine.
965 *
966 ******************************************************************************/
967
968acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400969acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
970 struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400971{
Len Brown4be44fc2005-08-05 00:44:28 -0400972 ACPI_FUNCTION_NAME("ds_obj_stack_pop_object");
Robert Moore44f6c012005-04-18 22:49:35 -0400973
974 /* Check for stack underflow */
975
976 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500977 ACPI_ERROR((AE_INFO,
978 "Missing operand/stack empty! State=%p #Ops=%X",
979 walk_state, walk_state->num_operands));
Robert Moore44f6c012005-04-18 22:49:35 -0400980 *object = NULL;
981 return (AE_AML_NO_OPERAND);
982 }
983
984 /* Pop the stack */
985
986 walk_state->num_operands--;
987
988 /* Check for a valid operand */
989
Len Brown4be44fc2005-08-05 00:44:28 -0400990 if (!walk_state->operands[walk_state->num_operands]) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500991 ACPI_ERROR((AE_INFO,
992 "Null operand! State=%p #Ops=%X",
993 walk_state, walk_state->num_operands));
Robert Moore44f6c012005-04-18 22:49:35 -0400994 *object = NULL;
995 return (AE_AML_NO_OPERAND);
996 }
997
998 /* Get operand and set stack entry to null */
999
Len Brown4be44fc2005-08-05 00:44:28 -04001000 *object = walk_state->operands[walk_state->num_operands];
1001 walk_state->operands[walk_state->num_operands] = NULL;
Robert Moore44f6c012005-04-18 22:49:35 -04001002
Len Brown4be44fc2005-08-05 00:44:28 -04001003 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1004 *object, acpi_ut_get_object_type_name(*object),
Robert Moore44f6c012005-04-18 22:49:35 -04001005 walk_state, walk_state->num_operands));
1006
1007 return (AE_OK);
1008}
1009
Robert Moore44f6c012005-04-18 22:49:35 -04001010/*******************************************************************************
1011 *
1012 * FUNCTION: acpi_ds_obj_stack_get_value
1013 *
1014 * PARAMETERS: Index - Stack index whose value is desired. Based
1015 * on the top of the stack (index=0 == top)
1016 * walk_state - Current Walk state
1017 *
1018 * RETURN: Pointer to the requested operand
1019 *
1020 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1021 * be within the range of the current stack pointer.
1022 *
1023 ******************************************************************************/
1024
Len Brown4be44fc2005-08-05 00:44:28 -04001025void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -04001026{
1027
Len Brown4be44fc2005-08-05 00:44:28 -04001028 ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_get_value", walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -04001029
1030 /* Can't do it if the stack is empty */
1031
1032 if (walk_state->num_operands == 0) {
Len Brown4be44fc2005-08-05 00:44:28 -04001033 return_PTR(NULL);
Robert Moore44f6c012005-04-18 22:49:35 -04001034 }
1035
1036 /* or if the index is past the top of the stack */
1037
1038 if (index > (walk_state->num_operands - (u32) 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001039 return_PTR(NULL);
Robert Moore44f6c012005-04-18 22:49:35 -04001040 }
1041
Len Brown4be44fc2005-08-05 00:44:28 -04001042 return_PTR(walk_state->
1043 operands[(acpi_native_uint) (walk_state->num_operands - 1) -
1044 index]);
Robert Moore44f6c012005-04-18 22:49:35 -04001045}
1046#endif