blob: c9c2ac13e7cc926d977ad8cb3052af532416badc [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 Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, Intel Corp.
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>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acparser.h"
47#include "acdispat.h"
48#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("dswstate")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Bob Moore773069d2008-04-10 19:06:36 +040053 /* Local prototypes */
54static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *ws);
55static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *ws);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*******************************************************************************
58 *
59 * FUNCTION: acpi_ds_result_pop
60 *
61 * PARAMETERS: Object - Where to return the popped object
62 * walk_state - Current Walk state
63 *
64 * RETURN: Status
65 *
Bob Moore773069d2008-04-10 19:06:36 +040066 * DESCRIPTION: Pop an object off the top of this walk's result stack
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 *
68 ******************************************************************************/
69
70acpi_status
Bob Moore773069d2008-04-10 19:06:36 +040071acpi_ds_result_pop(union acpi_operand_object **object,
72 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Bob Moore67a119f2008-06-10 13:42:13 +080074 u32 index;
Len Brown4be44fc2005-08-05 00:44:28 -040075 union acpi_generic_state *state;
Bob Moore773069d2008-04-10 19:06:36 +040076 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Bob Mooreb229cf92006-04-21 17:15:00 -040078 ACPI_FUNCTION_NAME(ds_result_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 state = walk_state->results;
Bob Moore773069d2008-04-10 19:06:36 +040081
82 /* Incorrect state of result stack */
83
84 if (state && !walk_state->result_count) {
85 ACPI_ERROR((AE_INFO, "No results on result stack"));
86 return (AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88
Bob Moore773069d2008-04-10 19:06:36 +040089 if (!state && walk_state->result_count) {
90 ACPI_ERROR((AE_INFO, "No result state for result stack"));
91 return (AE_AML_INTERNAL);
92 }
93
94 /* Empty result stack */
95
96 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050097 ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
98 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return (AE_AML_NO_RETURN_VALUE);
100 }
101
Bob Moore773069d2008-04-10 19:06:36 +0400102 /* Return object of the top element and clean that top element result stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Bob Moore773069d2008-04-10 19:06:36 +0400104 walk_state->result_count--;
Bob Mooreba9c3f52009-04-22 13:13:48 +0800105 index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Bob Moore773069d2008-04-10 19:06:36 +0400107 *object = state->results.obj_desc[index];
108 if (!*object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500109 ACPI_ERROR((AE_INFO,
Bob Moore773069d2008-04-10 19:06:36 +0400110 "No result objects on result stack, State=%p",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500111 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return (AE_AML_NO_RETURN_VALUE);
113 }
114
Bob Moore773069d2008-04-10 19:06:36 +0400115 state->results.obj_desc[index] = NULL;
116 if (index == 0) {
117 status = acpi_ds_result_stack_pop(walk_state);
118 if (ACPI_FAILURE(status)) {
119 return (status);
120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122
Bob Moore773069d2008-04-10 19:06:36 +0400123 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
124 "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object,
125 acpi_ut_get_object_type_name(*object),
Bob Moore67a119f2008-06-10 13:42:13 +0800126 index, walk_state, walk_state->result_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 return (AE_OK);
129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/*******************************************************************************
132 *
133 * FUNCTION: acpi_ds_result_push
134 *
135 * PARAMETERS: Object - Where to return the popped object
136 * walk_state - Current Walk state
137 *
138 * RETURN: Status
139 *
140 * DESCRIPTION: Push an object onto the current result stack
141 *
142 ******************************************************************************/
143
144acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400145acpi_ds_result_push(union acpi_operand_object * object,
146 struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Len Brown4be44fc2005-08-05 00:44:28 -0400148 union acpi_generic_state *state;
Bob Moore773069d2008-04-10 19:06:36 +0400149 acpi_status status;
Bob Moore67a119f2008-06-10 13:42:13 +0800150 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Bob Mooreb229cf92006-04-21 17:15:00 -0400152 ACPI_FUNCTION_NAME(ds_result_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Bob Moore773069d2008-04-10 19:06:36 +0400154 if (walk_state->result_count > walk_state->result_size) {
155 ACPI_ERROR((AE_INFO, "Result stack is full"));
156 return (AE_AML_INTERNAL);
157 } else if (walk_state->result_count == walk_state->result_size) {
158
159 /* Extend the result stack */
160
161 status = acpi_ds_result_stack_push(walk_state);
162 if (ACPI_FAILURE(status)) {
163 ACPI_ERROR((AE_INFO,
164 "Failed to extend the result stack"));
165 return (status);
166 }
167 }
168
169 if (!(walk_state->result_count < walk_state->result_size)) {
170 ACPI_ERROR((AE_INFO, "No free elements in result stack"));
171 return (AE_AML_INTERNAL);
172 }
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 state = walk_state->results;
175 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500176 ACPI_ERROR((AE_INFO, "No result stack frame during push"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return (AE_AML_INTERNAL);
178 }
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 if (!object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500181 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800182 "Null Object! Obj=%p State=%p Num=%u",
Bob Moore773069d2008-04-10 19:06:36 +0400183 object, walk_state, walk_state->result_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 return (AE_BAD_PARAMETER);
185 }
186
Bob Moore773069d2008-04-10 19:06:36 +0400187 /* Assign the address of object to the top free element of result stack */
188
Bob Mooreba9c3f52009-04-22 13:13:48 +0800189 index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
Bob Moore773069d2008-04-10 19:06:36 +0400190 state->results.obj_desc[index] = object;
191 walk_state->result_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Len Brown4be44fc2005-08-05 00:44:28 -0400193 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
194 object,
Len Brown4be44fc2005-08-05 00:44:28 -0400195 acpi_ut_get_object_type_name((union
196 acpi_operand_object *)
Bob Moore773069d2008-04-10 19:06:36 +0400197 object), walk_state,
198 walk_state->result_count,
Len Brown4be44fc2005-08-05 00:44:28 -0400199 walk_state->current_result));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 return (AE_OK);
202}
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204/*******************************************************************************
205 *
206 * FUNCTION: acpi_ds_result_stack_push
207 *
208 * PARAMETERS: walk_state - Current Walk state
209 *
210 * RETURN: Status
211 *
Bob Moore773069d2008-04-10 19:06:36 +0400212 * DESCRIPTION: Push an object onto the walk_state result stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 *
214 ******************************************************************************/
215
Bob Moore773069d2008-04-10 19:06:36 +0400216static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Len Brown4be44fc2005-08-05 00:44:28 -0400218 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Bob Mooreb229cf92006-04-21 17:15:00 -0400220 ACPI_FUNCTION_NAME(ds_result_stack_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Bob Moore773069d2008-04-10 19:06:36 +0400222 /* Check for stack overflow */
223
Bob Mooreb7f9f042008-04-10 19:06:40 +0400224 if (((u32) walk_state->result_size + ACPI_RESULTS_FRAME_OBJ_NUM) >
Bob Moore773069d2008-04-10 19:06:36 +0400225 ACPI_RESULTS_OBJ_NUM_MAX) {
Bob Mooref6a22b02010-03-05 17:56:40 +0800226 ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%u",
Bob Moore773069d2008-04-10 19:06:36 +0400227 walk_state, walk_state->result_size));
228 return (AE_STACK_OVERFLOW);
229 }
230
Len Brown4be44fc2005-08-05 00:44:28 -0400231 state = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 if (!state) {
233 return (AE_NO_MEMORY);
234 }
235
Bob Moore616861242006-03-17 16:44:00 -0500236 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400237 acpi_ut_push_generic_state(&walk_state->results, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Bob Moore773069d2008-04-10 19:06:36 +0400239 /* Increase the length of the result stack by the length of frame */
240
241 walk_state->result_size += ACPI_RESULTS_FRAME_OBJ_NUM;
242
Len Brown4be44fc2005-08-05 00:44:28 -0400243 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
244 state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 return (AE_OK);
247}
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249/*******************************************************************************
250 *
251 * FUNCTION: acpi_ds_result_stack_pop
252 *
253 * PARAMETERS: walk_state - Current Walk state
254 *
255 * RETURN: Status
256 *
Bob Moore773069d2008-04-10 19:06:36 +0400257 * DESCRIPTION: Pop an object off of the walk_state result stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 *
259 ******************************************************************************/
260
Bob Moore773069d2008-04-10 19:06:36 +0400261static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Len Brown4be44fc2005-08-05 00:44:28 -0400263 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Bob Mooreb229cf92006-04-21 17:15:00 -0400265 ACPI_FUNCTION_NAME(ds_result_stack_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 /* Check for stack underflow */
268
269 if (walk_state->results == NULL) {
Bob Moore773069d2008-04-10 19:06:36 +0400270 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
271 "Result stack underflow - State=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400272 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return (AE_AML_NO_OPERAND);
274 }
275
Bob Moore773069d2008-04-10 19:06:36 +0400276 if (walk_state->result_size < ACPI_RESULTS_FRAME_OBJ_NUM) {
277 ACPI_ERROR((AE_INFO, "Insufficient result stack size"));
278 return (AE_AML_INTERNAL);
279 }
280
Len Brown4be44fc2005-08-05 00:44:28 -0400281 state = acpi_ut_pop_generic_state(&walk_state->results);
Bob Moore773069d2008-04-10 19:06:36 +0400282 acpi_ut_delete_generic_state(state);
283
284 /* Decrease the length of result stack by the length of frame */
285
286 walk_state->result_size -= ACPI_RESULTS_FRAME_OBJ_NUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Len Brown4be44fc2005-08-05 00:44:28 -0400288 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400289 "Result=%p RemainingResults=%X State=%p\n",
Bob Moore773069d2008-04-10 19:06:36 +0400290 state, walk_state->result_count, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 return (AE_OK);
293}
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295/*******************************************************************************
296 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 * FUNCTION: acpi_ds_obj_stack_push
298 *
299 * PARAMETERS: Object - Object to push
300 * walk_state - Current Walk state
301 *
302 * RETURN: Status
303 *
304 * DESCRIPTION: Push an object onto this walk's object/operand stack
305 *
306 ******************************************************************************/
307
308acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400309acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Bob Mooreb229cf92006-04-21 17:15:00 -0400311 ACPI_FUNCTION_NAME(ds_obj_stack_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 /* Check for stack overflow */
314
315 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500316 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800317 "Object stack overflow! Obj=%p State=%p #Ops=%u",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500318 object, walk_state, walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return (AE_STACK_OVERFLOW);
320 }
321
322 /* Put the object onto the stack */
323
Bob Moore773069d2008-04-10 19:06:36 +0400324 walk_state->operands[walk_state->operand_index] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 walk_state->num_operands++;
326
Bob Moore773069d2008-04-10 19:06:36 +0400327 /* For the usual order of filling the operand stack */
328
329 walk_state->operand_index++;
330
Len Brown4be44fc2005-08-05 00:44:28 -0400331 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
332 object,
333 acpi_ut_get_object_type_name((union
334 acpi_operand_object *)
335 object), walk_state,
336 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 return (AE_OK);
339}
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341/*******************************************************************************
342 *
343 * FUNCTION: acpi_ds_obj_stack_pop
344 *
345 * PARAMETERS: pop_count - Number of objects/entries to pop
346 * walk_state - Current Walk state
347 *
348 * RETURN: Status
349 *
350 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
351 * deleted by this routine.
352 *
353 ******************************************************************************/
354
355acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400356acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Len Brown4be44fc2005-08-05 00:44:28 -0400358 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Bob Mooreb229cf92006-04-21 17:15:00 -0400360 ACPI_FUNCTION_NAME(ds_obj_stack_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 for (i = 0; i < pop_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 /* Check for stack underflow */
365
366 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500367 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800368 "Object stack underflow! Count=%X State=%p #Ops=%u",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500369 pop_count, walk_state,
370 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return (AE_STACK_UNDERFLOW);
372 }
373
374 /* Just set the stack entry to null */
375
376 walk_state->num_operands--;
Len Brown4be44fc2005-08-05 00:44:28 -0400377 walk_state->operands[walk_state->num_operands] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 }
379
Bob Mooref6a22b02010-03-05 17:56:40 +0800380 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 pop_count, walk_state, walk_state->num_operands));
382
383 return (AE_OK);
384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386/*******************************************************************************
387 *
388 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
389 *
390 * PARAMETERS: pop_count - Number of objects/entries to pop
391 * walk_state - Current Walk state
392 *
393 * RETURN: Status
394 *
395 * DESCRIPTION: Pop this walk's object stack and delete each object that is
396 * popped off.
397 *
398 ******************************************************************************/
399
Bob Moore773069d2008-04-10 19:06:36 +0400400void
Len Brown4be44fc2005-08-05 00:44:28 -0400401acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
Bob Moore773069d2008-04-10 19:06:36 +0400402 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Bob Moore67a119f2008-06-10 13:42:13 +0800404 s32 i;
Len Brown4be44fc2005-08-05 00:44:28 -0400405 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Bob Mooreb229cf92006-04-21 17:15:00 -0400407 ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Bob Moore773069d2008-04-10 19:06:36 +0400409 if (pop_count == 0) {
410 return;
411 }
Bob Moore52fc0b02006-10-02 00:00:00 -0400412
Bob Moore67a119f2008-06-10 13:42:13 +0800413 for (i = (s32) pop_count - 1; i >= 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 if (walk_state->num_operands == 0) {
Bob Moore773069d2008-04-10 19:06:36 +0400415 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417
418 /* Pop the stack and delete an object if present in this stack entry */
419
420 walk_state->num_operands--;
Bob Moore773069d2008-04-10 19:06:36 +0400421 obj_desc = walk_state->operands[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 if (obj_desc) {
Bob Moore773069d2008-04-10 19:06:36 +0400423 acpi_ut_remove_reference(walk_state->operands[i]);
424 walk_state->operands[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
426 }
427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 pop_count, walk_state, walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432/*******************************************************************************
433 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 * FUNCTION: acpi_ds_get_current_walk_state
435 *
436 * PARAMETERS: Thread - Get current active state for this Thread
437 *
438 * RETURN: Pointer to the current walk state
439 *
440 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
441 * walk state.)
442 *
443 ******************************************************************************/
444
Len Brown4be44fc2005-08-05 00:44:28 -0400445struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
446 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Bob Mooreb229cf92006-04-21 17:15:00 -0400448 ACPI_FUNCTION_NAME(ds_get_current_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 if (!thread) {
451 return (NULL);
452 }
453
Bob Mooreb229cf92006-04-21 17:15:00 -0400454 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current WalkState %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400455 thread->walk_state_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 return (thread->walk_state_list);
458}
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460/*******************************************************************************
461 *
462 * FUNCTION: acpi_ds_push_walk_state
463 *
464 * PARAMETERS: walk_state - State to push
Robert Moore44f6c012005-04-18 22:49:35 -0400465 * Thread - Thread state object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 *
467 * RETURN: None
468 *
Bob Moore773069d2008-04-10 19:06:36 +0400469 * DESCRIPTION: Place the Thread state at the head of the state list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 *
471 ******************************************************************************/
472
473void
Len Brown4be44fc2005-08-05 00:44:28 -0400474acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
475 struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
Bob Mooreb229cf92006-04-21 17:15:00 -0400477 ACPI_FUNCTION_TRACE(ds_push_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Len Brown4be44fc2005-08-05 00:44:28 -0400479 walk_state->next = thread->walk_state_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 thread->walk_state_list = walk_state;
481
482 return_VOID;
483}
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485/*******************************************************************************
486 *
487 * FUNCTION: acpi_ds_pop_walk_state
488 *
Robert Moore44f6c012005-04-18 22:49:35 -0400489 * PARAMETERS: Thread - Current thread state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 *
Robert Moore44f6c012005-04-18 22:49:35 -0400491 * RETURN: A walk_state object popped from the thread's stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 *
493 * DESCRIPTION: Remove and return the walkstate object that is at the head of
494 * the walk stack for the given walk list. NULL indicates that
495 * the list is empty.
496 *
497 ******************************************************************************/
498
Len Brown4be44fc2005-08-05 00:44:28 -0400499struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Len Brown4be44fc2005-08-05 00:44:28 -0400501 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Bob Mooreb229cf92006-04-21 17:15:00 -0400503 ACPI_FUNCTION_TRACE(ds_pop_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 walk_state = thread->walk_state_list;
506
507 if (walk_state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 /* Next walk state becomes the current walk state */
510
511 thread->walk_state_list = walk_state->next;
512
513 /*
514 * Don't clear the NEXT field, this serves as an indicator
515 * that there is a parent WALK STATE
Robert Moore44f6c012005-04-18 22:49:35 -0400516 * Do Not: walk_state->Next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 */
518 }
519
Len Brown4be44fc2005-08-05 00:44:28 -0400520 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523/*******************************************************************************
524 *
525 * FUNCTION: acpi_ds_create_walk_state
526 *
Robert Moore44f6c012005-04-18 22:49:35 -0400527 * PARAMETERS: owner_id - ID for object creation
528 * Origin - Starting point for this walk
Bob Moore616861242006-03-17 16:44:00 -0500529 * method_desc - Method object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 * Thread - Current thread state
531 *
532 * RETURN: Pointer to the new walk state.
533 *
534 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
535 * state is set to this new state.
536 *
537 ******************************************************************************/
538
Len Brownfd350942007-05-09 23:34:35 -0400539struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id, union acpi_parse_object
540 *origin, union acpi_operand_object
541 *method_desc, struct acpi_thread_state
Len Brown4be44fc2005-08-05 00:44:28 -0400542 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Len Brown4be44fc2005-08-05 00:44:28 -0400544 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Bob Mooreb229cf92006-04-21 17:15:00 -0400546 ACPI_FUNCTION_TRACE(ds_create_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Bob Moore83135242006-10-03 00:00:00 -0400548 walk_state = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (!walk_state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400550 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 }
552
Bob Moore616861242006-03-17 16:44:00 -0500553 walk_state->descriptor_type = ACPI_DESC_TYPE_WALK;
554 walk_state->method_desc = method_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400555 walk_state->owner_id = owner_id;
556 walk_state->origin = origin;
Len Brown4be44fc2005-08-05 00:44:28 -0400557 walk_state->thread = thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559 walk_state->parser_state.start_op = origin;
560
561 /* Init the method args/local */
562
563#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
Len Brown4be44fc2005-08-05 00:44:28 -0400564 acpi_ds_method_data_init(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#endif
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 /* Put the new state at the head of the walk list */
568
569 if (thread) {
Len Brown4be44fc2005-08-05 00:44:28 -0400570 acpi_ds_push_walk_state(walk_state, thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 }
572
Len Brown4be44fc2005-08-05 00:44:28 -0400573 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576/*******************************************************************************
577 *
578 * FUNCTION: acpi_ds_init_aml_walk
579 *
580 * PARAMETERS: walk_state - New state to be initialized
581 * Op - Current parse op
582 * method_node - Control method NS node, if any
583 * aml_start - Start of AML
584 * aml_length - Length of AML
Robert Moore44f6c012005-04-18 22:49:35 -0400585 * Info - Method info block (params, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 * pass_number - 1, 2, or 3
587 *
588 * RETURN: Status
589 *
590 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
591 *
592 ******************************************************************************/
593
594acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400595acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
596 union acpi_parse_object *op,
597 struct acpi_namespace_node *method_node,
598 u8 * aml_start,
599 u32 aml_length,
Bob Moore41195322006-05-26 16:36:00 -0400600 struct acpi_evaluate_info *info, u8 pass_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Len Brown4be44fc2005-08-05 00:44:28 -0400602 acpi_status status;
603 struct acpi_parse_state *parser_state = &walk_state->parser_state;
604 union acpi_parse_object *extra_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Bob Mooreb229cf92006-04-21 17:15:00 -0400606 ACPI_FUNCTION_TRACE(ds_init_aml_walk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Len Brown4be44fc2005-08-05 00:44:28 -0400608 walk_state->parser_state.aml =
609 walk_state->parser_state.aml_start = aml_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 walk_state->parser_state.aml_end =
Len Brown4be44fc2005-08-05 00:44:28 -0400611 walk_state->parser_state.pkg_end = aml_start + aml_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 /* The next_op of the next_walk will be the beginning of the method */
614
Robert Moore44f6c012005-04-18 22:49:35 -0400615 walk_state->next_op = NULL;
Robert Moore0c9938c2005-07-29 15:15:00 -0700616 walk_state->pass_number = pass_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 if (info) {
Bob Moorec91d9242008-06-10 12:38:10 +0800619 walk_state->params = info->parameters;
620 walk_state->caller_return_desc = &info->return_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 }
622
Len Brown4be44fc2005-08-05 00:44:28 -0400623 status = acpi_ps_init_scope(&walk_state->parser_state, op);
624 if (ACPI_FAILURE(status)) {
625 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 }
627
628 if (method_node) {
629 walk_state->parser_state.start_node = method_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400630 walk_state->walk_type = ACPI_WALK_METHOD;
631 walk_state->method_node = method_node;
632 walk_state->method_desc =
633 acpi_ns_get_attached_object(method_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635 /* Push start scope on scope stack and make it current */
636
Len Brown4be44fc2005-08-05 00:44:28 -0400637 status =
638 acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
639 walk_state);
640 if (ACPI_FAILURE(status)) {
641 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643
644 /* Init the method arguments */
645
Len Brown4be44fc2005-08-05 00:44:28 -0400646 status = acpi_ds_method_data_init_args(walk_state->params,
647 ACPI_METHOD_NUM_ARGS,
648 walk_state);
649 if (ACPI_FAILURE(status)) {
650 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 }
Len Brown4be44fc2005-08-05 00:44:28 -0400652 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /*
654 * Setup the current scope.
655 * Find a Named Op that has a namespace node associated with it.
656 * search upwards from this Op. Current scope is the first
657 * Op with a namespace node.
658 */
659 extra_op = parser_state->start_op;
660 while (extra_op && !extra_op->common.node) {
661 extra_op = extra_op->common.parent;
662 }
663
664 if (!extra_op) {
665 parser_state->start_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400666 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 parser_state->start_node = extra_op->common.node;
668 }
669
670 if (parser_state->start_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400671
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 /* Push start scope on scope stack and make it current */
673
Len Brown4be44fc2005-08-05 00:44:28 -0400674 status =
675 acpi_ds_scope_stack_push(parser_state->start_node,
676 parser_state->start_node->
677 type, walk_state);
678 if (ACPI_FAILURE(status)) {
679 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 }
681 }
682 }
683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 status = acpi_ds_init_callbacks(walk_state, pass_number);
685 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688/*******************************************************************************
689 *
690 * FUNCTION: acpi_ds_delete_walk_state
691 *
692 * PARAMETERS: walk_state - State to delete
693 *
694 * RETURN: Status
695 *
696 * DESCRIPTION: Delete a walk state including all internal data structures
697 *
698 ******************************************************************************/
699
Len Brown4be44fc2005-08-05 00:44:28 -0400700void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Len Brown4be44fc2005-08-05 00:44:28 -0400702 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Bob Mooreb229cf92006-04-21 17:15:00 -0400704 ACPI_FUNCTION_TRACE_PTR(ds_delete_walk_state, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706 if (!walk_state) {
707 return;
708 }
709
Bob Moore616861242006-03-17 16:44:00 -0500710 if (walk_state->descriptor_type != ACPI_DESC_TYPE_WALK) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500711 ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
712 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 return;
714 }
715
Bob Moore41195322006-05-26 16:36:00 -0400716 /* There should not be any open scopes */
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 if (walk_state->parser_state.scope) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500719 ACPI_ERROR((AE_INFO, "%p walk still has a scope list",
720 walk_state));
Bob Moore41195322006-05-26 16:36:00 -0400721 acpi_ps_cleanup_scope(&walk_state->parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 }
723
724 /* Always must free any linked control states */
725
726 while (walk_state->control_state) {
727 state = walk_state->control_state;
728 walk_state->control_state = state->common.next;
729
Len Brown4be44fc2005-08-05 00:44:28 -0400730 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 }
732
733 /* Always must free any linked parse states */
734
735 while (walk_state->scope_info) {
736 state = walk_state->scope_info;
737 walk_state->scope_info = state->common.next;
738
Len Brown4be44fc2005-08-05 00:44:28 -0400739 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741
742 /* Always must free any stacked result states */
743
744 while (walk_state->results) {
745 state = walk_state->results;
746 walk_state->results = state->common.next;
747
Len Brown4be44fc2005-08-05 00:44:28 -0400748 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 }
750
Bob Moore83135242006-10-03 00:00:00 -0400751 ACPI_FREE(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 return_VOID;
753}