]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: dswstate - Dispatcher parse tree walk management routines | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | |
9 | * 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 | ||
1da177e4 LT |
44 | #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 | |
4be44fcd | 50 | ACPI_MODULE_NAME("dswstate") |
1da177e4 | 51 | |
44f6c012 | 52 | /* Local prototypes */ |
44f6c012 | 53 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
1da177e4 | 54 | acpi_status |
4be44fcd LB |
55 | acpi_ds_result_insert(void *object, |
56 | u32 index, struct acpi_walk_state *walk_state); | |
1da177e4 | 57 | |
4be44fcd | 58 | acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state *walk_state); |
1da177e4 | 59 | |
44f6c012 | 60 | acpi_status |
4be44fcd LB |
61 | acpi_ds_obj_stack_pop_object(union acpi_operand_object **object, |
62 | struct acpi_walk_state *walk_state); | |
63 | ||
64 | void *acpi_ds_obj_stack_get_value(u32 index, | |
65 | struct acpi_walk_state *walk_state); | |
44f6c012 | 66 | #endif |
1da177e4 | 67 | |
44f6c012 | 68 | #ifdef ACPI_FUTURE_USAGE |
1da177e4 LT |
69 | |
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 | ||
85 | acpi_status | |
4be44fcd LB |
86 | acpi_ds_result_remove(union acpi_operand_object **object, |
87 | u32 index, struct acpi_walk_state *walk_state) | |
1da177e4 | 88 | { |
4be44fcd | 89 | union acpi_generic_state *state; |
1da177e4 | 90 | |
4be44fcd | 91 | ACPI_FUNCTION_NAME("ds_result_remove"); |
1da177e4 LT |
92 | |
93 | state = walk_state->results; | |
94 | if (!state) { | |
4be44fcd LB |
95 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
96 | "No result object pushed! State=%p\n", | |
97 | walk_state)); | |
1da177e4 LT |
98 | return (AE_NOT_EXIST); |
99 | } | |
100 | ||
101 | if (index >= ACPI_OBJ_MAX_OPERAND) { | |
4be44fcd LB |
102 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
103 | "Index out of range: %X State=%p Num=%X\n", | |
104 | index, walk_state, | |
105 | state->results.num_results)); | |
1da177e4 LT |
106 | } |
107 | ||
108 | /* Check for a valid result object */ | |
109 | ||
4be44fcd LB |
110 | if (!state->results.obj_desc[index]) { |
111 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
112 | "Null operand! State=%p #Ops=%X, Index=%X\n", | |
113 | walk_state, state->results.num_results, | |
114 | index)); | |
1da177e4 LT |
115 | return (AE_AML_NO_RETURN_VALUE); |
116 | } | |
117 | ||
118 | /* Remove the object */ | |
119 | ||
120 | state->results.num_results--; | |
121 | ||
4be44fcd LB |
122 | *object = state->results.obj_desc[index]; |
123 | state->results.obj_desc[index] = NULL; | |
1da177e4 | 124 | |
4be44fcd LB |
125 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
126 | "Obj=%p [%s] Index=%X State=%p Num=%X\n", | |
127 | *object, | |
128 | (*object) ? acpi_ut_get_object_type_name(*object) : | |
129 | "NULL", index, walk_state, | |
130 | state->results.num_results)); | |
1da177e4 LT |
131 | |
132 | return (AE_OK); | |
133 | } | |
134 | ||
4be44fcd | 135 | #endif /* ACPI_FUTURE_USAGE */ |
1da177e4 | 136 | |
1da177e4 LT |
137 | /******************************************************************************* |
138 | * | |
139 | * FUNCTION: acpi_ds_result_pop | |
140 | * | |
141 | * PARAMETERS: Object - Where to return the popped object | |
142 | * walk_state - Current Walk state | |
143 | * | |
144 | * RETURN: Status | |
145 | * | |
146 | * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In | |
147 | * other words, this is a FIFO. | |
148 | * | |
149 | ******************************************************************************/ | |
150 | ||
151 | acpi_status | |
4be44fcd LB |
152 | acpi_ds_result_pop(union acpi_operand_object ** object, |
153 | struct acpi_walk_state * walk_state) | |
1da177e4 | 154 | { |
4be44fcd LB |
155 | acpi_native_uint index; |
156 | union acpi_generic_state *state; | |
1da177e4 | 157 | |
4be44fcd | 158 | ACPI_FUNCTION_NAME("ds_result_pop"); |
1da177e4 LT |
159 | |
160 | state = walk_state->results; | |
161 | if (!state) { | |
162 | return (AE_OK); | |
163 | } | |
164 | ||
165 | if (!state->results.num_results) { | |
4be44fcd LB |
166 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
167 | "Result stack is empty! State=%p\n", | |
168 | walk_state)); | |
1da177e4 LT |
169 | return (AE_AML_NO_RETURN_VALUE); |
170 | } | |
171 | ||
172 | /* Remove top element */ | |
173 | ||
174 | state->results.num_results--; | |
175 | ||
176 | for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) { | |
177 | /* Check for a valid result object */ | |
178 | ||
4be44fcd LB |
179 | if (state->results.obj_desc[index - 1]) { |
180 | *object = state->results.obj_desc[index - 1]; | |
181 | state->results.obj_desc[index - 1] = NULL; | |
1da177e4 | 182 | |
4be44fcd LB |
183 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
184 | "Obj=%p [%s] Index=%X State=%p Num=%X\n", | |
185 | *object, | |
186 | (*object) ? | |
187 | acpi_ut_get_object_type_name(*object) | |
188 | : "NULL", (u32) index - 1, walk_state, | |
189 | state->results.num_results)); | |
1da177e4 LT |
190 | |
191 | return (AE_OK); | |
192 | } | |
193 | } | |
194 | ||
4be44fcd LB |
195 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
196 | "No result objects! State=%p\n", walk_state)); | |
1da177e4 LT |
197 | return (AE_AML_NO_RETURN_VALUE); |
198 | } | |
199 | ||
1da177e4 LT |
200 | /******************************************************************************* |
201 | * | |
202 | * FUNCTION: acpi_ds_result_pop_from_bottom | |
203 | * | |
204 | * PARAMETERS: Object - Where to return the popped object | |
205 | * walk_state - Current Walk state | |
206 | * | |
207 | * RETURN: Status | |
208 | * | |
209 | * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In | |
210 | * other words, this is a FIFO. | |
211 | * | |
212 | ******************************************************************************/ | |
213 | ||
214 | acpi_status | |
4be44fcd LB |
215 | acpi_ds_result_pop_from_bottom(union acpi_operand_object ** object, |
216 | struct acpi_walk_state * walk_state) | |
1da177e4 | 217 | { |
4be44fcd LB |
218 | acpi_native_uint index; |
219 | union acpi_generic_state *state; | |
1da177e4 | 220 | |
4be44fcd | 221 | ACPI_FUNCTION_NAME("ds_result_pop_from_bottom"); |
1da177e4 LT |
222 | |
223 | state = walk_state->results; | |
224 | if (!state) { | |
4be44fcd LB |
225 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
226 | "Warning: No result object pushed! State=%p\n", | |
227 | walk_state)); | |
1da177e4 LT |
228 | return (AE_NOT_EXIST); |
229 | } | |
230 | ||
231 | if (!state->results.num_results) { | |
4be44fcd LB |
232 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
233 | "No result objects! State=%p\n", walk_state)); | |
1da177e4 LT |
234 | return (AE_AML_NO_RETURN_VALUE); |
235 | } | |
236 | ||
237 | /* Remove Bottom element */ | |
238 | ||
4be44fcd | 239 | *object = state->results.obj_desc[0]; |
1da177e4 LT |
240 | |
241 | /* Push entire stack down one element */ | |
242 | ||
243 | for (index = 0; index < state->results.num_results; index++) { | |
4be44fcd LB |
244 | state->results.obj_desc[index] = |
245 | state->results.obj_desc[index + 1]; | |
1da177e4 LT |
246 | } |
247 | ||
248 | state->results.num_results--; | |
249 | ||
250 | /* Check for a valid result object */ | |
251 | ||
252 | if (!*object) { | |
4be44fcd LB |
253 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
254 | "Null operand! State=%p #Ops=%X Index=%X\n", | |
255 | walk_state, state->results.num_results, | |
256 | (u32) index)); | |
1da177e4 LT |
257 | return (AE_AML_NO_RETURN_VALUE); |
258 | } | |
259 | ||
4be44fcd LB |
260 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n", |
261 | *object, | |
262 | (*object) ? acpi_ut_get_object_type_name(*object) : | |
263 | "NULL", state, walk_state)); | |
1da177e4 LT |
264 | |
265 | return (AE_OK); | |
266 | } | |
267 | ||
1da177e4 LT |
268 | /******************************************************************************* |
269 | * | |
270 | * FUNCTION: acpi_ds_result_push | |
271 | * | |
272 | * PARAMETERS: Object - Where to return the popped object | |
273 | * walk_state - Current Walk state | |
274 | * | |
275 | * RETURN: Status | |
276 | * | |
277 | * DESCRIPTION: Push an object onto the current result stack | |
278 | * | |
279 | ******************************************************************************/ | |
280 | ||
281 | acpi_status | |
4be44fcd LB |
282 | acpi_ds_result_push(union acpi_operand_object * object, |
283 | struct acpi_walk_state * walk_state) | |
1da177e4 | 284 | { |
4be44fcd | 285 | union acpi_generic_state *state; |
1da177e4 | 286 | |
4be44fcd | 287 | ACPI_FUNCTION_NAME("ds_result_push"); |
1da177e4 LT |
288 | |
289 | state = walk_state->results; | |
290 | if (!state) { | |
4be44fcd | 291 | ACPI_REPORT_ERROR(("No result stack frame during push\n")); |
1da177e4 LT |
292 | return (AE_AML_INTERNAL); |
293 | } | |
294 | ||
295 | if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) { | |
4be44fcd LB |
296 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
297 | "Result stack overflow: Obj=%p State=%p Num=%X\n", | |
298 | object, walk_state, | |
299 | state->results.num_results)); | |
1da177e4 LT |
300 | return (AE_STACK_OVERFLOW); |
301 | } | |
302 | ||
303 | if (!object) { | |
4be44fcd LB |
304 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
305 | "Null Object! Obj=%p State=%p Num=%X\n", | |
306 | object, walk_state, | |
307 | state->results.num_results)); | |
1da177e4 LT |
308 | return (AE_BAD_PARAMETER); |
309 | } | |
310 | ||
4be44fcd | 311 | state->results.obj_desc[state->results.num_results] = object; |
1da177e4 LT |
312 | state->results.num_results++; |
313 | ||
4be44fcd LB |
314 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n", |
315 | object, | |
316 | object ? | |
317 | acpi_ut_get_object_type_name((union | |
318 | acpi_operand_object *) | |
319 | object) : "NULL", | |
320 | walk_state, state->results.num_results, | |
321 | walk_state->current_result)); | |
1da177e4 LT |
322 | |
323 | return (AE_OK); | |
324 | } | |
325 | ||
1da177e4 LT |
326 | /******************************************************************************* |
327 | * | |
328 | * FUNCTION: acpi_ds_result_stack_push | |
329 | * | |
330 | * PARAMETERS: walk_state - Current Walk state | |
331 | * | |
332 | * RETURN: Status | |
333 | * | |
334 | * DESCRIPTION: Push an object onto the walk_state result stack. | |
335 | * | |
336 | ******************************************************************************/ | |
337 | ||
4be44fcd | 338 | acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state) |
1da177e4 | 339 | { |
4be44fcd | 340 | union acpi_generic_state *state; |
1da177e4 | 341 | |
4be44fcd | 342 | ACPI_FUNCTION_NAME("ds_result_stack_push"); |
1da177e4 | 343 | |
4be44fcd | 344 | state = acpi_ut_create_generic_state(); |
1da177e4 LT |
345 | if (!state) { |
346 | return (AE_NO_MEMORY); | |
347 | } | |
348 | ||
349 | state->common.data_type = ACPI_DESC_TYPE_STATE_RESULT; | |
4be44fcd | 350 | acpi_ut_push_generic_state(&walk_state->results, state); |
1da177e4 | 351 | |
4be44fcd LB |
352 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n", |
353 | state, walk_state)); | |
1da177e4 LT |
354 | |
355 | return (AE_OK); | |
356 | } | |
357 | ||
1da177e4 LT |
358 | /******************************************************************************* |
359 | * | |
360 | * FUNCTION: acpi_ds_result_stack_pop | |
361 | * | |
362 | * PARAMETERS: walk_state - Current Walk state | |
363 | * | |
364 | * RETURN: Status | |
365 | * | |
366 | * DESCRIPTION: Pop an object off of the walk_state result stack. | |
367 | * | |
368 | ******************************************************************************/ | |
369 | ||
4be44fcd | 370 | acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state) |
1da177e4 | 371 | { |
4be44fcd | 372 | union acpi_generic_state *state; |
1da177e4 | 373 | |
4be44fcd | 374 | ACPI_FUNCTION_NAME("ds_result_stack_pop"); |
1da177e4 LT |
375 | |
376 | /* Check for stack underflow */ | |
377 | ||
378 | if (walk_state->results == NULL) { | |
4be44fcd LB |
379 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n", |
380 | walk_state)); | |
1da177e4 LT |
381 | return (AE_AML_NO_OPERAND); |
382 | } | |
383 | ||
4be44fcd | 384 | state = acpi_ut_pop_generic_state(&walk_state->results); |
1da177e4 | 385 | |
4be44fcd LB |
386 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
387 | "Result=%p remaining_results=%X State=%p\n", | |
388 | state, state->results.num_results, walk_state)); | |
1da177e4 | 389 | |
4be44fcd | 390 | acpi_ut_delete_generic_state(state); |
1da177e4 LT |
391 | |
392 | return (AE_OK); | |
393 | } | |
394 | ||
1da177e4 LT |
395 | /******************************************************************************* |
396 | * | |
397 | * FUNCTION: acpi_ds_obj_stack_push | |
398 | * | |
399 | * PARAMETERS: Object - Object to push | |
400 | * walk_state - Current Walk state | |
401 | * | |
402 | * RETURN: Status | |
403 | * | |
404 | * DESCRIPTION: Push an object onto this walk's object/operand stack | |
405 | * | |
406 | ******************************************************************************/ | |
407 | ||
408 | acpi_status | |
4be44fcd | 409 | acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state) |
1da177e4 | 410 | { |
4be44fcd | 411 | ACPI_FUNCTION_NAME("ds_obj_stack_push"); |
1da177e4 LT |
412 | |
413 | /* Check for stack overflow */ | |
414 | ||
415 | if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) { | |
4be44fcd LB |
416 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
417 | "overflow! Obj=%p State=%p #Ops=%X\n", | |
418 | object, walk_state, | |
419 | walk_state->num_operands)); | |
1da177e4 LT |
420 | return (AE_STACK_OVERFLOW); |
421 | } | |
422 | ||
423 | /* Put the object onto the stack */ | |
424 | ||
4be44fcd | 425 | walk_state->operands[walk_state->num_operands] = object; |
1da177e4 LT |
426 | walk_state->num_operands++; |
427 | ||
4be44fcd LB |
428 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n", |
429 | object, | |
430 | acpi_ut_get_object_type_name((union | |
431 | acpi_operand_object *) | |
432 | object), walk_state, | |
433 | walk_state->num_operands)); | |
1da177e4 LT |
434 | |
435 | return (AE_OK); | |
436 | } | |
437 | ||
1da177e4 LT |
438 | /******************************************************************************* |
439 | * | |
440 | * FUNCTION: acpi_ds_obj_stack_pop | |
441 | * | |
442 | * PARAMETERS: pop_count - Number of objects/entries to pop | |
443 | * walk_state - Current Walk state | |
444 | * | |
445 | * RETURN: Status | |
446 | * | |
447 | * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT | |
448 | * deleted by this routine. | |
449 | * | |
450 | ******************************************************************************/ | |
451 | ||
452 | acpi_status | |
4be44fcd | 453 | acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state) |
1da177e4 | 454 | { |
4be44fcd | 455 | u32 i; |
1da177e4 | 456 | |
4be44fcd | 457 | ACPI_FUNCTION_NAME("ds_obj_stack_pop"); |
1da177e4 LT |
458 | |
459 | for (i = 0; i < pop_count; i++) { | |
460 | /* Check for stack underflow */ | |
461 | ||
462 | if (walk_state->num_operands == 0) { | |
4be44fcd LB |
463 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
464 | "Underflow! Count=%X State=%p #Ops=%X\n", | |
465 | pop_count, walk_state, | |
466 | walk_state->num_operands)); | |
1da177e4 LT |
467 | return (AE_STACK_UNDERFLOW); |
468 | } | |
469 | ||
470 | /* Just set the stack entry to null */ | |
471 | ||
472 | walk_state->num_operands--; | |
4be44fcd | 473 | walk_state->operands[walk_state->num_operands] = NULL; |
1da177e4 LT |
474 | } |
475 | ||
4be44fcd | 476 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n", |
1da177e4 LT |
477 | pop_count, walk_state, walk_state->num_operands)); |
478 | ||
479 | return (AE_OK); | |
480 | } | |
481 | ||
1da177e4 LT |
482 | /******************************************************************************* |
483 | * | |
484 | * FUNCTION: acpi_ds_obj_stack_pop_and_delete | |
485 | * | |
486 | * PARAMETERS: pop_count - Number of objects/entries to pop | |
487 | * walk_state - Current Walk state | |
488 | * | |
489 | * RETURN: Status | |
490 | * | |
491 | * DESCRIPTION: Pop this walk's object stack and delete each object that is | |
492 | * popped off. | |
493 | * | |
494 | ******************************************************************************/ | |
495 | ||
496 | acpi_status | |
4be44fcd LB |
497 | acpi_ds_obj_stack_pop_and_delete(u32 pop_count, |
498 | struct acpi_walk_state * walk_state) | |
1da177e4 | 499 | { |
4be44fcd LB |
500 | u32 i; |
501 | union acpi_operand_object *obj_desc; | |
1da177e4 | 502 | |
4be44fcd | 503 | ACPI_FUNCTION_NAME("ds_obj_stack_pop_and_delete"); |
1da177e4 LT |
504 | |
505 | for (i = 0; i < pop_count; i++) { | |
506 | /* Check for stack underflow */ | |
507 | ||
508 | if (walk_state->num_operands == 0) { | |
4be44fcd LB |
509 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
510 | "Underflow! Count=%X State=%p #Ops=%X\n", | |
511 | pop_count, walk_state, | |
512 | walk_state->num_operands)); | |
1da177e4 LT |
513 | return (AE_STACK_UNDERFLOW); |
514 | } | |
515 | ||
516 | /* Pop the stack and delete an object if present in this stack entry */ | |
517 | ||
518 | walk_state->num_operands--; | |
4be44fcd | 519 | obj_desc = walk_state->operands[walk_state->num_operands]; |
1da177e4 | 520 | if (obj_desc) { |
4be44fcd LB |
521 | acpi_ut_remove_reference(walk_state-> |
522 | operands[walk_state-> | |
523 | num_operands]); | |
524 | walk_state->operands[walk_state->num_operands] = NULL; | |
1da177e4 LT |
525 | } |
526 | } | |
527 | ||
4be44fcd | 528 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n", |
1da177e4 LT |
529 | pop_count, walk_state, walk_state->num_operands)); |
530 | ||
531 | return (AE_OK); | |
532 | } | |
533 | ||
1da177e4 LT |
534 | /******************************************************************************* |
535 | * | |
536 | * FUNCTION: acpi_ds_get_current_walk_state | |
537 | * | |
538 | * PARAMETERS: Thread - Get current active state for this Thread | |
539 | * | |
540 | * RETURN: Pointer to the current walk state | |
541 | * | |
542 | * DESCRIPTION: Get the walk state that is at the head of the list (the "current" | |
543 | * walk state.) | |
544 | * | |
545 | ******************************************************************************/ | |
546 | ||
4be44fcd LB |
547 | struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state |
548 | *thread) | |
1da177e4 | 549 | { |
4be44fcd | 550 | ACPI_FUNCTION_NAME("ds_get_current_walk_state"); |
1da177e4 LT |
551 | |
552 | if (!thread) { | |
553 | return (NULL); | |
554 | } | |
555 | ||
4be44fcd LB |
556 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current walk_state %p\n", |
557 | thread->walk_state_list)); | |
1da177e4 LT |
558 | |
559 | return (thread->walk_state_list); | |
560 | } | |
561 | ||
1da177e4 LT |
562 | /******************************************************************************* |
563 | * | |
564 | * FUNCTION: acpi_ds_push_walk_state | |
565 | * | |
566 | * PARAMETERS: walk_state - State to push | |
44f6c012 | 567 | * Thread - Thread state object |
1da177e4 LT |
568 | * |
569 | * RETURN: None | |
570 | * | |
44f6c012 | 571 | * DESCRIPTION: Place the Thread state at the head of the state list. |
1da177e4 LT |
572 | * |
573 | ******************************************************************************/ | |
574 | ||
575 | void | |
4be44fcd LB |
576 | acpi_ds_push_walk_state(struct acpi_walk_state *walk_state, |
577 | struct acpi_thread_state *thread) | |
1da177e4 | 578 | { |
4be44fcd | 579 | ACPI_FUNCTION_TRACE("ds_push_walk_state"); |
1da177e4 | 580 | |
4be44fcd | 581 | walk_state->next = thread->walk_state_list; |
1da177e4 LT |
582 | thread->walk_state_list = walk_state; |
583 | ||
584 | return_VOID; | |
585 | } | |
586 | ||
1da177e4 LT |
587 | /******************************************************************************* |
588 | * | |
589 | * FUNCTION: acpi_ds_pop_walk_state | |
590 | * | |
44f6c012 | 591 | * PARAMETERS: Thread - Current thread state |
1da177e4 | 592 | * |
44f6c012 | 593 | * RETURN: A walk_state object popped from the thread's stack |
1da177e4 LT |
594 | * |
595 | * DESCRIPTION: Remove and return the walkstate object that is at the head of | |
596 | * the walk stack for the given walk list. NULL indicates that | |
597 | * the list is empty. | |
598 | * | |
599 | ******************************************************************************/ | |
600 | ||
4be44fcd | 601 | struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread) |
1da177e4 | 602 | { |
4be44fcd | 603 | struct acpi_walk_state *walk_state; |
1da177e4 | 604 | |
4be44fcd | 605 | ACPI_FUNCTION_TRACE("ds_pop_walk_state"); |
1da177e4 LT |
606 | |
607 | walk_state = thread->walk_state_list; | |
608 | ||
609 | if (walk_state) { | |
610 | /* Next walk state becomes the current walk state */ | |
611 | ||
612 | thread->walk_state_list = walk_state->next; | |
613 | ||
614 | /* | |
615 | * Don't clear the NEXT field, this serves as an indicator | |
616 | * that there is a parent WALK STATE | |
44f6c012 | 617 | * Do Not: walk_state->Next = NULL; |
1da177e4 LT |
618 | */ |
619 | } | |
620 | ||
4be44fcd | 621 | return_PTR(walk_state); |
1da177e4 LT |
622 | } |
623 | ||
1da177e4 LT |
624 | /******************************************************************************* |
625 | * | |
626 | * FUNCTION: acpi_ds_create_walk_state | |
627 | * | |
44f6c012 RM |
628 | * PARAMETERS: owner_id - ID for object creation |
629 | * Origin - Starting point for this walk | |
630 | * mth_desc - Method object | |
1da177e4 LT |
631 | * Thread - Current thread state |
632 | * | |
633 | * RETURN: Pointer to the new walk state. | |
634 | * | |
635 | * DESCRIPTION: Allocate and initialize a new walk state. The current walk | |
636 | * state is set to this new state. | |
637 | * | |
638 | ******************************************************************************/ | |
639 | ||
4be44fcd LB |
640 | struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id, |
641 | union acpi_parse_object | |
642 | *origin, | |
643 | union acpi_operand_object | |
644 | *mth_desc, | |
645 | struct acpi_thread_state | |
646 | *thread) | |
1da177e4 | 647 | { |
4be44fcd LB |
648 | struct acpi_walk_state *walk_state; |
649 | acpi_status status; | |
1da177e4 | 650 | |
4be44fcd | 651 | ACPI_FUNCTION_TRACE("ds_create_walk_state"); |
1da177e4 | 652 | |
4be44fcd | 653 | walk_state = ACPI_MEM_CALLOCATE(sizeof(struct acpi_walk_state)); |
1da177e4 | 654 | if (!walk_state) { |
4be44fcd | 655 | return_PTR(NULL); |
1da177e4 LT |
656 | } |
657 | ||
4be44fcd LB |
658 | walk_state->data_type = ACPI_DESC_TYPE_WALK; |
659 | walk_state->owner_id = owner_id; | |
660 | walk_state->origin = origin; | |
661 | walk_state->method_desc = mth_desc; | |
662 | walk_state->thread = thread; | |
1da177e4 LT |
663 | |
664 | walk_state->parser_state.start_op = origin; | |
665 | ||
666 | /* Init the method args/local */ | |
667 | ||
668 | #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) | |
4be44fcd | 669 | acpi_ds_method_data_init(walk_state); |
1da177e4 LT |
670 | #endif |
671 | ||
672 | /* Create an initial result stack entry */ | |
673 | ||
4be44fcd LB |
674 | status = acpi_ds_result_stack_push(walk_state); |
675 | if (ACPI_FAILURE(status)) { | |
676 | ACPI_MEM_FREE(walk_state); | |
677 | return_PTR(NULL); | |
1da177e4 LT |
678 | } |
679 | ||
680 | /* Put the new state at the head of the walk list */ | |
681 | ||
682 | if (thread) { | |
4be44fcd | 683 | acpi_ds_push_walk_state(walk_state, thread); |
1da177e4 LT |
684 | } |
685 | ||
4be44fcd | 686 | return_PTR(walk_state); |
1da177e4 LT |
687 | } |
688 | ||
1da177e4 LT |
689 | /******************************************************************************* |
690 | * | |
691 | * FUNCTION: acpi_ds_init_aml_walk | |
692 | * | |
693 | * PARAMETERS: walk_state - New state to be initialized | |
694 | * Op - Current parse op | |
695 | * method_node - Control method NS node, if any | |
696 | * aml_start - Start of AML | |
697 | * aml_length - Length of AML | |
44f6c012 | 698 | * Info - Method info block (params, etc.) |
1da177e4 LT |
699 | * pass_number - 1, 2, or 3 |
700 | * | |
701 | * RETURN: Status | |
702 | * | |
703 | * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk | |
704 | * | |
705 | ******************************************************************************/ | |
706 | ||
707 | acpi_status | |
4be44fcd LB |
708 | acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state, |
709 | union acpi_parse_object *op, | |
710 | struct acpi_namespace_node *method_node, | |
711 | u8 * aml_start, | |
712 | u32 aml_length, | |
713 | struct acpi_parameter_info *info, u8 pass_number) | |
1da177e4 | 714 | { |
4be44fcd LB |
715 | acpi_status status; |
716 | struct acpi_parse_state *parser_state = &walk_state->parser_state; | |
717 | union acpi_parse_object *extra_op; | |
1da177e4 | 718 | |
4be44fcd | 719 | ACPI_FUNCTION_TRACE("ds_init_aml_walk"); |
1da177e4 | 720 | |
4be44fcd LB |
721 | walk_state->parser_state.aml = |
722 | walk_state->parser_state.aml_start = aml_start; | |
1da177e4 | 723 | walk_state->parser_state.aml_end = |
4be44fcd | 724 | walk_state->parser_state.pkg_end = aml_start + aml_length; |
1da177e4 LT |
725 | |
726 | /* The next_op of the next_walk will be the beginning of the method */ | |
727 | ||
44f6c012 | 728 | walk_state->next_op = NULL; |
0c9938cc | 729 | walk_state->pass_number = pass_number; |
1da177e4 LT |
730 | |
731 | if (info) { | |
732 | if (info->parameter_type == ACPI_PARAM_GPE) { | |
4be44fcd LB |
733 | walk_state->gpe_event_info = |
734 | ACPI_CAST_PTR(struct acpi_gpe_event_info, | |
735 | info->parameters); | |
736 | } else { | |
737 | walk_state->params = info->parameters; | |
44f6c012 | 738 | walk_state->caller_return_desc = &info->return_object; |
1da177e4 LT |
739 | } |
740 | } | |
741 | ||
4be44fcd LB |
742 | status = acpi_ps_init_scope(&walk_state->parser_state, op); |
743 | if (ACPI_FAILURE(status)) { | |
744 | return_ACPI_STATUS(status); | |
1da177e4 LT |
745 | } |
746 | ||
747 | if (method_node) { | |
748 | walk_state->parser_state.start_node = method_node; | |
4be44fcd LB |
749 | walk_state->walk_type = ACPI_WALK_METHOD; |
750 | walk_state->method_node = method_node; | |
751 | walk_state->method_desc = | |
752 | acpi_ns_get_attached_object(method_node); | |
1da177e4 LT |
753 | |
754 | /* Push start scope on scope stack and make it current */ | |
755 | ||
4be44fcd LB |
756 | status = |
757 | acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD, | |
758 | walk_state); | |
759 | if (ACPI_FAILURE(status)) { | |
760 | return_ACPI_STATUS(status); | |
1da177e4 LT |
761 | } |
762 | ||
763 | /* Init the method arguments */ | |
764 | ||
4be44fcd LB |
765 | status = acpi_ds_method_data_init_args(walk_state->params, |
766 | ACPI_METHOD_NUM_ARGS, | |
767 | walk_state); | |
768 | if (ACPI_FAILURE(status)) { | |
769 | return_ACPI_STATUS(status); | |
1da177e4 | 770 | } |
4be44fcd | 771 | } else { |
1da177e4 LT |
772 | /* |
773 | * Setup the current scope. | |
774 | * Find a Named Op that has a namespace node associated with it. | |
775 | * search upwards from this Op. Current scope is the first | |
776 | * Op with a namespace node. | |
777 | */ | |
778 | extra_op = parser_state->start_op; | |
779 | while (extra_op && !extra_op->common.node) { | |
780 | extra_op = extra_op->common.parent; | |
781 | } | |
782 | ||
783 | if (!extra_op) { | |
784 | parser_state->start_node = NULL; | |
4be44fcd | 785 | } else { |
1da177e4 LT |
786 | parser_state->start_node = extra_op->common.node; |
787 | } | |
788 | ||
789 | if (parser_state->start_node) { | |
790 | /* Push start scope on scope stack and make it current */ | |
791 | ||
4be44fcd LB |
792 | status = |
793 | acpi_ds_scope_stack_push(parser_state->start_node, | |
794 | parser_state->start_node-> | |
795 | type, walk_state); | |
796 | if (ACPI_FAILURE(status)) { | |
797 | return_ACPI_STATUS(status); | |
1da177e4 LT |
798 | } |
799 | } | |
800 | } | |
801 | ||
4be44fcd LB |
802 | status = acpi_ds_init_callbacks(walk_state, pass_number); |
803 | return_ACPI_STATUS(status); | |
1da177e4 LT |
804 | } |
805 | ||
1da177e4 LT |
806 | /******************************************************************************* |
807 | * | |
808 | * FUNCTION: acpi_ds_delete_walk_state | |
809 | * | |
810 | * PARAMETERS: walk_state - State to delete | |
811 | * | |
812 | * RETURN: Status | |
813 | * | |
814 | * DESCRIPTION: Delete a walk state including all internal data structures | |
815 | * | |
816 | ******************************************************************************/ | |
817 | ||
4be44fcd | 818 | void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state) |
1da177e4 | 819 | { |
4be44fcd | 820 | union acpi_generic_state *state; |
1da177e4 | 821 | |
4be44fcd | 822 | ACPI_FUNCTION_TRACE_PTR("ds_delete_walk_state", walk_state); |
1da177e4 LT |
823 | |
824 | if (!walk_state) { | |
825 | return; | |
826 | } | |
827 | ||
828 | if (walk_state->data_type != ACPI_DESC_TYPE_WALK) { | |
4be44fcd LB |
829 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
830 | "%p is not a valid walk state\n", | |
831 | walk_state)); | |
1da177e4 LT |
832 | return; |
833 | } | |
834 | ||
835 | if (walk_state->parser_state.scope) { | |
4be44fcd LB |
836 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
837 | "%p walk still has a scope list\n", | |
838 | walk_state)); | |
1da177e4 LT |
839 | } |
840 | ||
841 | /* Always must free any linked control states */ | |
842 | ||
843 | while (walk_state->control_state) { | |
844 | state = walk_state->control_state; | |
845 | walk_state->control_state = state->common.next; | |
846 | ||
4be44fcd | 847 | acpi_ut_delete_generic_state(state); |
1da177e4 LT |
848 | } |
849 | ||
850 | /* Always must free any linked parse states */ | |
851 | ||
852 | while (walk_state->scope_info) { | |
853 | state = walk_state->scope_info; | |
854 | walk_state->scope_info = state->common.next; | |
855 | ||
4be44fcd | 856 | acpi_ut_delete_generic_state(state); |
1da177e4 LT |
857 | } |
858 | ||
859 | /* Always must free any stacked result states */ | |
860 | ||
861 | while (walk_state->results) { | |
862 | state = walk_state->results; | |
863 | walk_state->results = state->common.next; | |
864 | ||
4be44fcd | 865 | acpi_ut_delete_generic_state(state); |
1da177e4 LT |
866 | } |
867 | ||
4be44fcd | 868 | ACPI_MEM_FREE(walk_state); |
1da177e4 LT |
869 | return_VOID; |
870 | } | |
871 | ||
44f6c012 RM |
872 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
873 | /******************************************************************************* | |
874 | * | |
875 | * FUNCTION: acpi_ds_result_insert | |
876 | * | |
877 | * PARAMETERS: Object - Object to push | |
878 | * Index - Where to insert the object | |
879 | * walk_state - Current Walk state | |
880 | * | |
881 | * RETURN: Status | |
882 | * | |
883 | * DESCRIPTION: Insert an object onto this walk's result stack | |
884 | * | |
885 | ******************************************************************************/ | |
886 | ||
887 | acpi_status | |
4be44fcd LB |
888 | acpi_ds_result_insert(void *object, |
889 | u32 index, struct acpi_walk_state *walk_state) | |
44f6c012 | 890 | { |
4be44fcd | 891 | union acpi_generic_state *state; |
44f6c012 | 892 | |
4be44fcd | 893 | ACPI_FUNCTION_NAME("ds_result_insert"); |
44f6c012 RM |
894 | |
895 | state = walk_state->results; | |
896 | if (!state) { | |
4be44fcd LB |
897 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
898 | "No result object pushed! State=%p\n", | |
899 | walk_state)); | |
44f6c012 RM |
900 | return (AE_NOT_EXIST); |
901 | } | |
902 | ||
903 | if (index >= ACPI_OBJ_NUM_OPERANDS) { | |
4be44fcd LB |
904 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
905 | "Index out of range: %X Obj=%p State=%p Num=%X\n", | |
906 | index, object, walk_state, | |
907 | state->results.num_results)); | |
44f6c012 RM |
908 | return (AE_BAD_PARAMETER); |
909 | } | |
910 | ||
911 | if (!object) { | |
4be44fcd LB |
912 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
913 | "Null Object! Index=%X Obj=%p State=%p Num=%X\n", | |
914 | index, object, walk_state, | |
915 | state->results.num_results)); | |
44f6c012 RM |
916 | return (AE_BAD_PARAMETER); |
917 | } | |
918 | ||
4be44fcd | 919 | state->results.obj_desc[index] = object; |
44f6c012 RM |
920 | state->results.num_results++; |
921 | ||
4be44fcd LB |
922 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
923 | "Obj=%p [%s] State=%p Num=%X Cur=%X\n", | |
924 | object, | |
925 | object ? | |
926 | acpi_ut_get_object_type_name((union | |
927 | acpi_operand_object *) | |
928 | object) : "NULL", | |
929 | walk_state, state->results.num_results, | |
930 | walk_state->current_result)); | |
44f6c012 RM |
931 | |
932 | return (AE_OK); | |
933 | } | |
934 | ||
44f6c012 RM |
935 | /******************************************************************************* |
936 | * | |
937 | * FUNCTION: acpi_ds_obj_stack_delete_all | |
938 | * | |
939 | * PARAMETERS: walk_state - Current Walk state | |
940 | * | |
941 | * RETURN: Status | |
942 | * | |
943 | * DESCRIPTION: Clear the object stack by deleting all objects that are on it. | |
944 | * Should be used with great care, if at all! | |
945 | * | |
946 | ******************************************************************************/ | |
947 | ||
4be44fcd | 948 | acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state * walk_state) |
44f6c012 | 949 | { |
4be44fcd | 950 | u32 i; |
44f6c012 | 951 | |
4be44fcd | 952 | ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_delete_all", walk_state); |
44f6c012 RM |
953 | |
954 | /* The stack size is configurable, but fixed */ | |
955 | ||
956 | for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) { | |
957 | if (walk_state->operands[i]) { | |
4be44fcd | 958 | acpi_ut_remove_reference(walk_state->operands[i]); |
44f6c012 RM |
959 | walk_state->operands[i] = NULL; |
960 | } | |
961 | } | |
962 | ||
4be44fcd | 963 | return_ACPI_STATUS(AE_OK); |
44f6c012 RM |
964 | } |
965 | ||
44f6c012 RM |
966 | /******************************************************************************* |
967 | * | |
968 | * FUNCTION: acpi_ds_obj_stack_pop_object | |
969 | * | |
970 | * PARAMETERS: Object - Where to return the popped object | |
971 | * walk_state - Current Walk state | |
972 | * | |
973 | * RETURN: Status | |
974 | * | |
975 | * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT | |
976 | * deleted by this routine. | |
977 | * | |
978 | ******************************************************************************/ | |
979 | ||
980 | acpi_status | |
4be44fcd LB |
981 | acpi_ds_obj_stack_pop_object(union acpi_operand_object **object, |
982 | struct acpi_walk_state *walk_state) | |
44f6c012 | 983 | { |
4be44fcd | 984 | ACPI_FUNCTION_NAME("ds_obj_stack_pop_object"); |
44f6c012 RM |
985 | |
986 | /* Check for stack underflow */ | |
987 | ||
988 | if (walk_state->num_operands == 0) { | |
4be44fcd LB |
989 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
990 | "Missing operand/stack empty! State=%p #Ops=%X\n", | |
991 | walk_state, walk_state->num_operands)); | |
44f6c012 RM |
992 | *object = NULL; |
993 | return (AE_AML_NO_OPERAND); | |
994 | } | |
995 | ||
996 | /* Pop the stack */ | |
997 | ||
998 | walk_state->num_operands--; | |
999 | ||
1000 | /* Check for a valid operand */ | |
1001 | ||
4be44fcd LB |
1002 | if (!walk_state->operands[walk_state->num_operands]) { |
1003 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
1004 | "Null operand! State=%p #Ops=%X\n", | |
1005 | walk_state, walk_state->num_operands)); | |
44f6c012 RM |
1006 | *object = NULL; |
1007 | return (AE_AML_NO_OPERAND); | |
1008 | } | |
1009 | ||
1010 | /* Get operand and set stack entry to null */ | |
1011 | ||
4be44fcd LB |
1012 | *object = walk_state->operands[walk_state->num_operands]; |
1013 | walk_state->operands[walk_state->num_operands] = NULL; | |
44f6c012 | 1014 | |
4be44fcd LB |
1015 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n", |
1016 | *object, acpi_ut_get_object_type_name(*object), | |
44f6c012 RM |
1017 | walk_state, walk_state->num_operands)); |
1018 | ||
1019 | return (AE_OK); | |
1020 | } | |
1021 | ||
44f6c012 RM |
1022 | /******************************************************************************* |
1023 | * | |
1024 | * FUNCTION: acpi_ds_obj_stack_get_value | |
1025 | * | |
1026 | * PARAMETERS: Index - Stack index whose value is desired. Based | |
1027 | * on the top of the stack (index=0 == top) | |
1028 | * walk_state - Current Walk state | |
1029 | * | |
1030 | * RETURN: Pointer to the requested operand | |
1031 | * | |
1032 | * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must | |
1033 | * be within the range of the current stack pointer. | |
1034 | * | |
1035 | ******************************************************************************/ | |
1036 | ||
4be44fcd | 1037 | void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state) |
44f6c012 RM |
1038 | { |
1039 | ||
4be44fcd | 1040 | ACPI_FUNCTION_TRACE_PTR("ds_obj_stack_get_value", walk_state); |
44f6c012 RM |
1041 | |
1042 | /* Can't do it if the stack is empty */ | |
1043 | ||
1044 | if (walk_state->num_operands == 0) { | |
4be44fcd | 1045 | return_PTR(NULL); |
44f6c012 RM |
1046 | } |
1047 | ||
1048 | /* or if the index is past the top of the stack */ | |
1049 | ||
1050 | if (index > (walk_state->num_operands - (u32) 1)) { | |
4be44fcd | 1051 | return_PTR(NULL); |
44f6c012 RM |
1052 | } |
1053 | ||
4be44fcd LB |
1054 | return_PTR(walk_state-> |
1055 | operands[(acpi_native_uint) (walk_state->num_operands - 1) - | |
1056 | index]); | |
44f6c012 RM |
1057 | } |
1058 | #endif |