blob: e3338698e56bf6ed0b56313fd8346b3b25481af2 [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 Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, 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 */
Lv Zheng1f86e8c2012-10-31 02:25:45 +000054static acpi_status
55acpi_ds_result_stack_push(struct acpi_walk_state *walk_state);
56static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/*******************************************************************************
59 *
60 * FUNCTION: acpi_ds_result_pop
61 *
Bob Mooreba494be2012-07-12 09:40:10 +080062 * PARAMETERS: object - Where to return the popped object
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * walk_state - Current Walk state
64 *
65 * RETURN: Status
66 *
Bob Moore773069d2008-04-10 19:06:36 +040067 * DESCRIPTION: Pop an object off the top of this walk's result stack
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 *
69 ******************************************************************************/
70
71acpi_status
Bob Moore773069d2008-04-10 19:06:36 +040072acpi_ds_result_pop(union acpi_operand_object **object,
73 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Bob Moore67a119f2008-06-10 13:42:13 +080075 u32 index;
Len Brown4be44fc2005-08-05 00:44:28 -040076 union acpi_generic_state *state;
Bob Moore773069d2008-04-10 19:06:36 +040077 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Bob Mooreb229cf92006-04-21 17:15:00 -040079 ACPI_FUNCTION_NAME(ds_result_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81 state = walk_state->results;
Bob Moore773069d2008-04-10 19:06:36 +040082
83 /* Incorrect state of result stack */
84
85 if (state && !walk_state->result_count) {
86 ACPI_ERROR((AE_INFO, "No results on result stack"));
87 return (AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
Bob Moore773069d2008-04-10 19:06:36 +040090 if (!state && walk_state->result_count) {
91 ACPI_ERROR((AE_INFO, "No result state for result stack"));
92 return (AE_AML_INTERNAL);
93 }
94
95 /* Empty result stack */
96
97 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -050098 ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
99 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return (AE_AML_NO_RETURN_VALUE);
101 }
102
Bob Moore773069d2008-04-10 19:06:36 +0400103 /* Return object of the top element and clean that top element result stack */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Bob Moore773069d2008-04-10 19:06:36 +0400105 walk_state->result_count--;
Bob Mooreba9c3f52009-04-22 13:13:48 +0800106 index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Bob Moore773069d2008-04-10 19:06:36 +0400108 *object = state->results.obj_desc[index];
109 if (!*object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500110 ACPI_ERROR((AE_INFO,
Bob Moore773069d2008-04-10 19:06:36 +0400111 "No result objects on result stack, State=%p",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500112 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return (AE_AML_NO_RETURN_VALUE);
114 }
115
Bob Moore773069d2008-04-10 19:06:36 +0400116 state->results.obj_desc[index] = NULL;
117 if (index == 0) {
118 status = acpi_ds_result_stack_pop(walk_state);
119 if (ACPI_FAILURE(status)) {
120 return (status);
121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
Bob Moore773069d2008-04-10 19:06:36 +0400124 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
125 "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object,
126 acpi_ut_get_object_type_name(*object),
Bob Moore67a119f2008-06-10 13:42:13 +0800127 index, walk_state, walk_state->result_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 return (AE_OK);
130}
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/*******************************************************************************
133 *
134 * FUNCTION: acpi_ds_result_push
135 *
Bob Mooreba494be2012-07-12 09:40:10 +0800136 * PARAMETERS: object - Where to return the popped object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 * walk_state - Current Walk state
138 *
139 * RETURN: Status
140 *
141 * DESCRIPTION: Push an object onto the current result stack
142 *
143 ******************************************************************************/
144
145acpi_status
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800146acpi_ds_result_push(union acpi_operand_object *object,
147 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Len Brown4be44fc2005-08-05 00:44:28 -0400149 union acpi_generic_state *state;
Bob Moore773069d2008-04-10 19:06:36 +0400150 acpi_status status;
Bob Moore67a119f2008-06-10 13:42:13 +0800151 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Bob Mooreb229cf92006-04-21 17:15:00 -0400153 ACPI_FUNCTION_NAME(ds_result_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Bob Moore773069d2008-04-10 19:06:36 +0400155 if (walk_state->result_count > walk_state->result_size) {
156 ACPI_ERROR((AE_INFO, "Result stack is full"));
157 return (AE_AML_INTERNAL);
158 } else if (walk_state->result_count == walk_state->result_size) {
159
160 /* Extend the result stack */
161
162 status = acpi_ds_result_stack_push(walk_state);
163 if (ACPI_FAILURE(status)) {
164 ACPI_ERROR((AE_INFO,
165 "Failed to extend the result stack"));
166 return (status);
167 }
168 }
169
170 if (!(walk_state->result_count < walk_state->result_size)) {
171 ACPI_ERROR((AE_INFO, "No free elements in result stack"));
172 return (AE_AML_INTERNAL);
173 }
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 state = walk_state->results;
176 if (!state) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500177 ACPI_ERROR((AE_INFO, "No result stack frame during push"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return (AE_AML_INTERNAL);
179 }
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 if (!object) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500182 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800183 "Null Object! Obj=%p State=%p Num=%u",
Bob Moore773069d2008-04-10 19:06:36 +0400184 object, walk_state, walk_state->result_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return (AE_BAD_PARAMETER);
186 }
187
Bob Moore773069d2008-04-10 19:06:36 +0400188 /* Assign the address of object to the top free element of result stack */
189
Bob Mooreba9c3f52009-04-22 13:13:48 +0800190 index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
Bob Moore773069d2008-04-10 19:06:36 +0400191 state->results.obj_desc[index] = object;
192 walk_state->result_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Len Brown4be44fc2005-08-05 00:44:28 -0400194 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
195 object,
Len Brown4be44fc2005-08-05 00:44:28 -0400196 acpi_ut_get_object_type_name((union
197 acpi_operand_object *)
Bob Moore773069d2008-04-10 19:06:36 +0400198 object), walk_state,
199 walk_state->result_count,
Len Brown4be44fc2005-08-05 00:44:28 -0400200 walk_state->current_result));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 return (AE_OK);
203}
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205/*******************************************************************************
206 *
207 * FUNCTION: acpi_ds_result_stack_push
208 *
209 * PARAMETERS: walk_state - Current Walk state
210 *
211 * RETURN: Status
212 *
Bob Moore773069d2008-04-10 19:06:36 +0400213 * DESCRIPTION: Push an object onto the walk_state result stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 *
215 ******************************************************************************/
216
Bob Moore773069d2008-04-10 19:06:36 +0400217static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Len Brown4be44fc2005-08-05 00:44:28 -0400219 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Bob Mooreb229cf92006-04-21 17:15:00 -0400221 ACPI_FUNCTION_NAME(ds_result_stack_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Bob Moore773069d2008-04-10 19:06:36 +0400223 /* Check for stack overflow */
224
Bob Mooreb7f9f042008-04-10 19:06:40 +0400225 if (((u32) walk_state->result_size + ACPI_RESULTS_FRAME_OBJ_NUM) >
Bob Moore773069d2008-04-10 19:06:36 +0400226 ACPI_RESULTS_OBJ_NUM_MAX) {
Bob Mooref6a22b02010-03-05 17:56:40 +0800227 ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%u",
Bob Moore773069d2008-04-10 19:06:36 +0400228 walk_state, walk_state->result_size));
229 return (AE_STACK_OVERFLOW);
230 }
231
Len Brown4be44fc2005-08-05 00:44:28 -0400232 state = acpi_ut_create_generic_state();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 if (!state) {
234 return (AE_NO_MEMORY);
235 }
236
Bob Moore616861242006-03-17 16:44:00 -0500237 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT;
Len Brown4be44fc2005-08-05 00:44:28 -0400238 acpi_ut_push_generic_state(&walk_state->results, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Bob Moore773069d2008-04-10 19:06:36 +0400240 /* Increase the length of the result stack by the length of frame */
241
242 walk_state->result_size += ACPI_RESULTS_FRAME_OBJ_NUM;
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
245 state, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 return (AE_OK);
248}
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250/*******************************************************************************
251 *
252 * FUNCTION: acpi_ds_result_stack_pop
253 *
254 * PARAMETERS: walk_state - Current Walk state
255 *
256 * RETURN: Status
257 *
Bob Moore773069d2008-04-10 19:06:36 +0400258 * DESCRIPTION: Pop an object off of the walk_state result stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 *
260 ******************************************************************************/
261
Bob Moore773069d2008-04-10 19:06:36 +0400262static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Len Brown4be44fc2005-08-05 00:44:28 -0400264 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Bob Mooreb229cf92006-04-21 17:15:00 -0400266 ACPI_FUNCTION_NAME(ds_result_stack_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 /* Check for stack underflow */
269
270 if (walk_state->results == NULL) {
Bob Moore773069d2008-04-10 19:06:36 +0400271 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
272 "Result stack underflow - State=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400273 walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 return (AE_AML_NO_OPERAND);
275 }
276
Bob Moore773069d2008-04-10 19:06:36 +0400277 if (walk_state->result_size < ACPI_RESULTS_FRAME_OBJ_NUM) {
278 ACPI_ERROR((AE_INFO, "Insufficient result stack size"));
279 return (AE_AML_INTERNAL);
280 }
281
Len Brown4be44fc2005-08-05 00:44:28 -0400282 state = acpi_ut_pop_generic_state(&walk_state->results);
Bob Moore773069d2008-04-10 19:06:36 +0400283 acpi_ut_delete_generic_state(state);
284
285 /* Decrease the length of result stack by the length of frame */
286
287 walk_state->result_size -= ACPI_RESULTS_FRAME_OBJ_NUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400290 "Result=%p RemainingResults=%X State=%p\n",
Bob Moore773069d2008-04-10 19:06:36 +0400291 state, walk_state->result_count, walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 return (AE_OK);
294}
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296/*******************************************************************************
297 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 * FUNCTION: acpi_ds_obj_stack_push
299 *
Bob Mooreba494be2012-07-12 09:40:10 +0800300 * PARAMETERS: object - Object to push
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 * walk_state - Current Walk state
302 *
303 * RETURN: Status
304 *
305 * DESCRIPTION: Push an object onto this walk's object/operand stack
306 *
307 ******************************************************************************/
308
309acpi_status
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800310acpi_ds_obj_stack_push(void *object, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Bob Mooreb229cf92006-04-21 17:15:00 -0400312 ACPI_FUNCTION_NAME(ds_obj_stack_push);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 /* Check for stack overflow */
315
316 if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500317 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800318 "Object stack overflow! Obj=%p State=%p #Ops=%u",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500319 object, walk_state, walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 return (AE_STACK_OVERFLOW);
321 }
322
323 /* Put the object onto the stack */
324
Bob Moore773069d2008-04-10 19:06:36 +0400325 walk_state->operands[walk_state->operand_index] = object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 walk_state->num_operands++;
327
Bob Moore773069d2008-04-10 19:06:36 +0400328 /* For the usual order of filling the operand stack */
329
330 walk_state->operand_index++;
331
Len Brown4be44fc2005-08-05 00:44:28 -0400332 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
333 object,
334 acpi_ut_get_object_type_name((union
335 acpi_operand_object *)
336 object), walk_state,
337 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 return (AE_OK);
340}
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342/*******************************************************************************
343 *
344 * FUNCTION: acpi_ds_obj_stack_pop
345 *
346 * PARAMETERS: pop_count - Number of objects/entries to pop
347 * walk_state - Current Walk state
348 *
349 * RETURN: Status
350 *
Bob Moore73a30902012-10-31 02:26:55 +0000351 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 * deleted by this routine.
353 *
354 ******************************************************************************/
355
356acpi_status
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800357acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Len Brown4be44fc2005-08-05 00:44:28 -0400359 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Bob Mooreb229cf92006-04-21 17:15:00 -0400361 ACPI_FUNCTION_NAME(ds_obj_stack_pop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363 for (i = 0; i < pop_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 /* Check for stack underflow */
366
367 if (walk_state->num_operands == 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500368 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800369 "Object stack underflow! Count=%X State=%p #Ops=%u",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500370 pop_count, walk_state,
371 walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 return (AE_STACK_UNDERFLOW);
373 }
374
375 /* Just set the stack entry to null */
376
377 walk_state->num_operands--;
Len Brown4be44fc2005-08-05 00:44:28 -0400378 walk_state->operands[walk_state->num_operands] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 }
380
Bob Mooref6a22b02010-03-05 17:56:40 +0800381 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 pop_count, walk_state, walk_state->num_operands));
383
384 return (AE_OK);
385}
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387/*******************************************************************************
388 *
389 * FUNCTION: acpi_ds_obj_stack_pop_and_delete
390 *
391 * PARAMETERS: pop_count - Number of objects/entries to pop
392 * walk_state - Current Walk state
393 *
394 * RETURN: Status
395 *
396 * DESCRIPTION: Pop this walk's object stack and delete each object that is
397 * popped off.
398 *
399 ******************************************************************************/
400
Bob Moore773069d2008-04-10 19:06:36 +0400401void
Len Brown4be44fc2005-08-05 00:44:28 -0400402acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
Bob Moore773069d2008-04-10 19:06:36 +0400403 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Bob Moore67a119f2008-06-10 13:42:13 +0800405 s32 i;
Len Brown4be44fc2005-08-05 00:44:28 -0400406 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Bob Mooreb229cf92006-04-21 17:15:00 -0400408 ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Bob Moore773069d2008-04-10 19:06:36 +0400410 if (pop_count == 0) {
411 return;
412 }
Bob Moore52fc0b02006-10-02 00:00:00 -0400413
Lv Zhengf5c1e1c2016-05-05 12:57:53 +0800414 for (i = (s32)pop_count - 1; i >= 0; i--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 if (walk_state->num_operands == 0) {
Bob Moore773069d2008-04-10 19:06:36 +0400416 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
418
419 /* Pop the stack and delete an object if present in this stack entry */
420
421 walk_state->num_operands--;
Bob Moore773069d2008-04-10 19:06:36 +0400422 obj_desc = walk_state->operands[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 if (obj_desc) {
Bob Moore773069d2008-04-10 19:06:36 +0400424 acpi_ut_remove_reference(walk_state->operands[i]);
425 walk_state->operands[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
427 }
428
Len Brown4be44fc2005-08-05 00:44:28 -0400429 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 pop_count, walk_state, walk_state->num_operands));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433/*******************************************************************************
434 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 * FUNCTION: acpi_ds_get_current_walk_state
436 *
Bob Mooreba494be2012-07-12 09:40:10 +0800437 * PARAMETERS: thread - Get current active state for this Thread
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 *
439 * RETURN: Pointer to the current walk state
440 *
441 * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
442 * walk state.)
443 *
444 ******************************************************************************/
445
Len Brown4be44fc2005-08-05 00:44:28 -0400446struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
447 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
Bob Mooreb229cf92006-04-21 17:15:00 -0400449 ACPI_FUNCTION_NAME(ds_get_current_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 if (!thread) {
452 return (NULL);
453 }
454
Bob Mooreb229cf92006-04-21 17:15:00 -0400455 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current WalkState %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400456 thread->walk_state_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 return (thread->walk_state_list);
459}
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461/*******************************************************************************
462 *
463 * FUNCTION: acpi_ds_push_walk_state
464 *
465 * PARAMETERS: walk_state - State to push
Bob Mooreba494be2012-07-12 09:40:10 +0800466 * thread - Thread state object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 *
468 * RETURN: None
469 *
Bob Moore773069d2008-04-10 19:06:36 +0400470 * DESCRIPTION: Place the Thread state at the head of the state list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 *
472 ******************************************************************************/
473
474void
Len Brown4be44fc2005-08-05 00:44:28 -0400475acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
476 struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Bob Mooreb229cf92006-04-21 17:15:00 -0400478 ACPI_FUNCTION_TRACE(ds_push_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Len Brown4be44fc2005-08-05 00:44:28 -0400480 walk_state->next = thread->walk_state_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 thread->walk_state_list = walk_state;
482
483 return_VOID;
484}
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486/*******************************************************************************
487 *
488 * FUNCTION: acpi_ds_pop_walk_state
489 *
Bob Mooreba494be2012-07-12 09:40:10 +0800490 * PARAMETERS: thread - Current thread state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 *
Robert Moore44f6c012005-04-18 22:49:35 -0400492 * RETURN: A walk_state object popped from the thread's stack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 *
494 * DESCRIPTION: Remove and return the walkstate object that is at the head of
Bob Moore73a30902012-10-31 02:26:55 +0000495 * the walk stack for the given walk list. NULL indicates that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 * the list is empty.
497 *
498 ******************************************************************************/
499
Len Brown4be44fc2005-08-05 00:44:28 -0400500struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Len Brown4be44fc2005-08-05 00:44:28 -0400502 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Bob Mooreb229cf92006-04-21 17:15:00 -0400504 ACPI_FUNCTION_TRACE(ds_pop_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 walk_state = thread->walk_state_list;
507
508 if (walk_state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 /* Next walk state becomes the current walk state */
511
512 thread->walk_state_list = walk_state->next;
513
514 /*
515 * Don't clear the NEXT field, this serves as an indicator
516 * that there is a parent WALK STATE
Robert Moore44f6c012005-04-18 22:49:35 -0400517 * Do Not: walk_state->Next = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 */
519 }
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524/*******************************************************************************
525 *
526 * FUNCTION: acpi_ds_create_walk_state
527 *
Robert Moore44f6c012005-04-18 22:49:35 -0400528 * PARAMETERS: owner_id - ID for object creation
Bob Mooreba494be2012-07-12 09:40:10 +0800529 * origin - Starting point for this walk
Bob Moore616861242006-03-17 16:44:00 -0500530 * method_desc - Method object
Bob Mooreba494be2012-07-12 09:40:10 +0800531 * thread - Current thread state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 *
533 * RETURN: Pointer to the new walk state.
534 *
Bob Moore73a30902012-10-31 02:26:55 +0000535 * DESCRIPTION: Allocate and initialize a new walk state. The current walk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 * state is set to this new state.
537 *
538 ******************************************************************************/
539
Lv Zheng1f86e8c2012-10-31 02:25:45 +0000540struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id,
541 union acpi_parse_object
542 *origin,
543 union acpi_operand_object
544 *method_desc,
545 struct acpi_thread_state
Len Brown4be44fc2005-08-05 00:44:28 -0400546 *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
Len Brown4be44fc2005-08-05 00:44:28 -0400548 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Bob Mooreb229cf92006-04-21 17:15:00 -0400550 ACPI_FUNCTION_TRACE(ds_create_walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Bob Moore83135242006-10-03 00:00:00 -0400552 walk_state = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_walk_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 if (!walk_state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400554 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
556
Bob Moore616861242006-03-17 16:44:00 -0500557 walk_state->descriptor_type = ACPI_DESC_TYPE_WALK;
558 walk_state->method_desc = method_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400559 walk_state->owner_id = owner_id;
560 walk_state->origin = origin;
Len Brown4be44fc2005-08-05 00:44:28 -0400561 walk_state->thread = thread;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 walk_state->parser_state.start_op = origin;
564
565 /* Init the method args/local */
566
567#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
Len Brown4be44fc2005-08-05 00:44:28 -0400568 acpi_ds_method_data_init(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#endif
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 /* Put the new state at the head of the walk list */
572
573 if (thread) {
Len Brown4be44fc2005-08-05 00:44:28 -0400574 acpi_ds_push_walk_state(walk_state, thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 }
576
Len Brown4be44fc2005-08-05 00:44:28 -0400577 return_PTR(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578}
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580/*******************************************************************************
581 *
582 * FUNCTION: acpi_ds_init_aml_walk
583 *
584 * PARAMETERS: walk_state - New state to be initialized
Bob Mooreba494be2012-07-12 09:40:10 +0800585 * op - Current parse op
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 * method_node - Control method NS node, if any
587 * aml_start - Start of AML
588 * aml_length - Length of AML
Bob Mooreba494be2012-07-12 09:40:10 +0800589 * info - Method info block (params, etc.)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 * pass_number - 1, 2, or 3
591 *
592 * RETURN: Status
593 *
594 * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
595 *
596 ******************************************************************************/
597
598acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400599acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
600 union acpi_parse_object *op,
601 struct acpi_namespace_node *method_node,
602 u8 * aml_start,
603 u32 aml_length,
Bob Moore41195322006-05-26 16:36:00 -0400604 struct acpi_evaluate_info *info, u8 pass_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605{
Len Brown4be44fc2005-08-05 00:44:28 -0400606 acpi_status status;
607 struct acpi_parse_state *parser_state = &walk_state->parser_state;
608 union acpi_parse_object *extra_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Bob Mooreb229cf92006-04-21 17:15:00 -0400610 ACPI_FUNCTION_TRACE(ds_init_aml_walk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Len Brown4be44fc2005-08-05 00:44:28 -0400612 walk_state->parser_state.aml =
613 walk_state->parser_state.aml_start = aml_start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 walk_state->parser_state.aml_end =
Len Brown4be44fc2005-08-05 00:44:28 -0400615 walk_state->parser_state.pkg_end = aml_start + aml_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 /* The next_op of the next_walk will be the beginning of the method */
618
Robert Moore44f6c012005-04-18 22:49:35 -0400619 walk_state->next_op = NULL;
Robert Moore0c9938c2005-07-29 15:15:00 -0700620 walk_state->pass_number = pass_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 if (info) {
Bob Moorec91d9242008-06-10 12:38:10 +0800623 walk_state->params = info->parameters;
624 walk_state->caller_return_desc = &info->return_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
626
Len Brown4be44fc2005-08-05 00:44:28 -0400627 status = acpi_ps_init_scope(&walk_state->parser_state, op);
628 if (ACPI_FAILURE(status)) {
629 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631
632 if (method_node) {
633 walk_state->parser_state.start_node = method_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400634 walk_state->walk_type = ACPI_WALK_METHOD;
635 walk_state->method_node = method_node;
636 walk_state->method_desc =
637 acpi_ns_get_attached_object(method_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 /* Push start scope on scope stack and make it current */
640
Len Brown4be44fc2005-08-05 00:44:28 -0400641 status =
642 acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD,
643 walk_state);
644 if (ACPI_FAILURE(status)) {
645 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 }
647
648 /* Init the method arguments */
649
Len Brown4be44fc2005-08-05 00:44:28 -0400650 status = acpi_ds_method_data_init_args(walk_state->params,
651 ACPI_METHOD_NUM_ARGS,
652 walk_state);
653 if (ACPI_FAILURE(status)) {
654 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 }
Len Brown4be44fc2005-08-05 00:44:28 -0400656 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /*
658 * Setup the current scope.
659 * Find a Named Op that has a namespace node associated with it.
Bob Moore73a30902012-10-31 02:26:55 +0000660 * search upwards from this Op. Current scope is the first
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 * Op with a namespace node.
662 */
663 extra_op = parser_state->start_op;
664 while (extra_op && !extra_op->common.node) {
665 extra_op = extra_op->common.parent;
666 }
667
668 if (!extra_op) {
669 parser_state->start_node = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400670 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 parser_state->start_node = extra_op->common.node;
672 }
673
674 if (parser_state->start_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 /* Push start scope on scope stack and make it current */
677
Len Brown4be44fc2005-08-05 00:44:28 -0400678 status =
679 acpi_ds_scope_stack_push(parser_state->start_node,
680 parser_state->start_node->
681 type, walk_state);
682 if (ACPI_FAILURE(status)) {
683 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685 }
686 }
687
Len Brown4be44fc2005-08-05 00:44:28 -0400688 status = acpi_ds_init_callbacks(walk_state, pass_number);
689 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690}
691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692/*******************************************************************************
693 *
694 * FUNCTION: acpi_ds_delete_walk_state
695 *
696 * PARAMETERS: walk_state - State to delete
697 *
698 * RETURN: Status
699 *
700 * DESCRIPTION: Delete a walk state including all internal data structures
701 *
702 ******************************************************************************/
703
Len Brown4be44fc2005-08-05 00:44:28 -0400704void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Len Brown4be44fc2005-08-05 00:44:28 -0400706 union acpi_generic_state *state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Bob Mooreb229cf92006-04-21 17:15:00 -0400708 ACPI_FUNCTION_TRACE_PTR(ds_delete_walk_state, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 if (!walk_state) {
Bob Moore68aafc32012-10-31 02:26:01 +0000711 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
713
Bob Moore616861242006-03-17 16:44:00 -0500714 if (walk_state->descriptor_type != ACPI_DESC_TYPE_WALK) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500715 ACPI_ERROR((AE_INFO, "%p is not a valid walk state",
716 walk_state));
Bob Moore68aafc32012-10-31 02:26:01 +0000717 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 }
719
Bob Moore41195322006-05-26 16:36:00 -0400720 /* There should not be any open scopes */
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 if (walk_state->parser_state.scope) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500723 ACPI_ERROR((AE_INFO, "%p walk still has a scope list",
724 walk_state));
Bob Moore41195322006-05-26 16:36:00 -0400725 acpi_ps_cleanup_scope(&walk_state->parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 }
727
728 /* Always must free any linked control states */
729
730 while (walk_state->control_state) {
731 state = walk_state->control_state;
732 walk_state->control_state = state->common.next;
733
Len Brown4be44fc2005-08-05 00:44:28 -0400734 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 }
736
737 /* Always must free any linked parse states */
738
739 while (walk_state->scope_info) {
740 state = walk_state->scope_info;
741 walk_state->scope_info = state->common.next;
742
Len Brown4be44fc2005-08-05 00:44:28 -0400743 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 }
745
746 /* Always must free any stacked result states */
747
748 while (walk_state->results) {
749 state = walk_state->results;
750 walk_state->results = state->common.next;
751
Len Brown4be44fc2005-08-05 00:44:28 -0400752 acpi_ut_delete_generic_state(state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 }
754
Bob Moore83135242006-10-03 00:00:00 -0400755 ACPI_FREE(walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 return_VOID;
757}