Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: dswstate - Dispatcher parse tree walk management routines |
| 5 | * |
Bob Moore | 800ba7c | 2020-01-10 11:31:49 -0800 | [diff] [blame] | 6 | * Copyright (C) 2000 - 2020, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "acparser.h" |
| 13 | #include "acdispat.h" |
| 14 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #define _COMPONENT ACPI_DISPATCHER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 17 | ACPI_MODULE_NAME("dswstate") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 19 | /* Local prototypes */ |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 20 | static acpi_status |
| 21 | acpi_ds_result_stack_push(struct acpi_walk_state *walk_state); |
| 22 | static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | /******************************************************************************* |
| 25 | * |
| 26 | * FUNCTION: acpi_ds_result_pop |
| 27 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 28 | * PARAMETERS: object - Where to return the popped object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * walk_state - Current Walk state |
| 30 | * |
| 31 | * RETURN: Status |
| 32 | * |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 33 | * DESCRIPTION: Pop an object off the top of this walk's result stack |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * |
| 35 | ******************************************************************************/ |
| 36 | |
| 37 | acpi_status |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 38 | acpi_ds_result_pop(union acpi_operand_object **object, |
| 39 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 41 | u32 index; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 42 | union acpi_generic_state *state; |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 43 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 45 | ACPI_FUNCTION_NAME(ds_result_pop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | state = walk_state->results; |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 48 | |
| 49 | /* Incorrect state of result stack */ |
| 50 | |
| 51 | if (state && !walk_state->result_count) { |
| 52 | ACPI_ERROR((AE_INFO, "No results on result stack")); |
| 53 | return (AE_AML_INTERNAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 56 | if (!state && walk_state->result_count) { |
| 57 | ACPI_ERROR((AE_INFO, "No result state for result stack")); |
| 58 | return (AE_AML_INTERNAL); |
| 59 | } |
| 60 | |
| 61 | /* Empty result stack */ |
| 62 | |
| 63 | if (!state) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 64 | ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p", |
| 65 | walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return (AE_AML_NO_RETURN_VALUE); |
| 67 | } |
| 68 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 69 | /* Return object of the top element and clean that top element result stack */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 71 | walk_state->result_count--; |
Bob Moore | ba9c3f5 | 2009-04-22 13:13:48 +0800 | [diff] [blame] | 72 | index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 74 | *object = state->results.obj_desc[index]; |
| 75 | if (!*object) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 76 | ACPI_ERROR((AE_INFO, |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 77 | "No result objects on result stack, State=%p", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 78 | walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return (AE_AML_NO_RETURN_VALUE); |
| 80 | } |
| 81 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 82 | state->results.obj_desc[index] = NULL; |
| 83 | if (index == 0) { |
| 84 | status = acpi_ds_result_stack_pop(walk_state); |
| 85 | if (ACPI_FAILURE(status)) { |
| 86 | return (status); |
| 87 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 90 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 91 | "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object, |
| 92 | acpi_ut_get_object_type_name(*object), |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 93 | index, walk_state, walk_state->result_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | return (AE_OK); |
| 96 | } |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /******************************************************************************* |
| 99 | * |
| 100 | * FUNCTION: acpi_ds_result_push |
| 101 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 102 | * PARAMETERS: object - Where to return the popped object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | * walk_state - Current Walk state |
| 104 | * |
| 105 | * RETURN: Status |
| 106 | * |
| 107 | * DESCRIPTION: Push an object onto the current result stack |
| 108 | * |
| 109 | ******************************************************************************/ |
| 110 | |
| 111 | acpi_status |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 112 | acpi_ds_result_push(union acpi_operand_object *object, |
| 113 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 115 | union acpi_generic_state *state; |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 116 | acpi_status status; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 117 | u32 index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 119 | ACPI_FUNCTION_NAME(ds_result_push); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 121 | if (walk_state->result_count > walk_state->result_size) { |
| 122 | ACPI_ERROR((AE_INFO, "Result stack is full")); |
| 123 | return (AE_AML_INTERNAL); |
| 124 | } else if (walk_state->result_count == walk_state->result_size) { |
| 125 | |
| 126 | /* Extend the result stack */ |
| 127 | |
| 128 | status = acpi_ds_result_stack_push(walk_state); |
| 129 | if (ACPI_FAILURE(status)) { |
| 130 | ACPI_ERROR((AE_INFO, |
| 131 | "Failed to extend the result stack")); |
| 132 | return (status); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if (!(walk_state->result_count < walk_state->result_size)) { |
| 137 | ACPI_ERROR((AE_INFO, "No free elements in result stack")); |
| 138 | return (AE_AML_INTERNAL); |
| 139 | } |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | state = walk_state->results; |
| 142 | if (!state) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 143 | ACPI_ERROR((AE_INFO, "No result stack frame during push")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return (AE_AML_INTERNAL); |
| 145 | } |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | if (!object) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 148 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 149 | "Null Object! Obj=%p State=%p Num=%u", |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 150 | object, walk_state, walk_state->result_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | return (AE_BAD_PARAMETER); |
| 152 | } |
| 153 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 154 | /* Assign the address of object to the top free element of result stack */ |
| 155 | |
Bob Moore | ba9c3f5 | 2009-04-22 13:13:48 +0800 | [diff] [blame] | 156 | index = (u32)walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM; |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 157 | state->results.obj_desc[index] = object; |
| 158 | walk_state->result_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n", |
| 161 | object, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | acpi_ut_get_object_type_name((union |
| 163 | acpi_operand_object *) |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 164 | object), walk_state, |
| 165 | walk_state->result_count, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | walk_state->current_result)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | return (AE_OK); |
| 169 | } |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /******************************************************************************* |
| 172 | * |
| 173 | * FUNCTION: acpi_ds_result_stack_push |
| 174 | * |
| 175 | * PARAMETERS: walk_state - Current Walk state |
| 176 | * |
| 177 | * RETURN: Status |
| 178 | * |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 179 | * DESCRIPTION: Push an object onto the walk_state result stack |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | * |
| 181 | ******************************************************************************/ |
| 182 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 183 | static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | union acpi_generic_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 187 | ACPI_FUNCTION_NAME(ds_result_stack_push); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 189 | /* Check for stack overflow */ |
| 190 | |
Bob Moore | b7f9f04 | 2008-04-10 19:06:40 +0400 | [diff] [blame] | 191 | if (((u32) walk_state->result_size + ACPI_RESULTS_FRAME_OBJ_NUM) > |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 192 | ACPI_RESULTS_OBJ_NUM_MAX) { |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 193 | ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%u", |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 194 | walk_state, walk_state->result_size)); |
| 195 | return (AE_STACK_OVERFLOW); |
| 196 | } |
| 197 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | state = acpi_ut_create_generic_state(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (!state) { |
| 200 | return (AE_NO_MEMORY); |
| 201 | } |
| 202 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 203 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | acpi_ut_push_generic_state(&walk_state->results, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 206 | /* Increase the length of the result stack by the length of frame */ |
| 207 | |
| 208 | walk_state->result_size += ACPI_RESULTS_FRAME_OBJ_NUM; |
| 209 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n", |
| 211 | state, walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | return (AE_OK); |
| 214 | } |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /******************************************************************************* |
| 217 | * |
| 218 | * FUNCTION: acpi_ds_result_stack_pop |
| 219 | * |
| 220 | * PARAMETERS: walk_state - Current Walk state |
| 221 | * |
| 222 | * RETURN: Status |
| 223 | * |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 224 | * DESCRIPTION: Pop an object off of the walk_state result stack |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | * |
| 226 | ******************************************************************************/ |
| 227 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 228 | static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | union acpi_generic_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 232 | ACPI_FUNCTION_NAME(ds_result_stack_pop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | /* Check for stack underflow */ |
| 235 | |
| 236 | if (walk_state->results == NULL) { |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 237 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 238 | "Result stack underflow - State=%p\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 239 | walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | return (AE_AML_NO_OPERAND); |
| 241 | } |
| 242 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 243 | if (walk_state->result_size < ACPI_RESULTS_FRAME_OBJ_NUM) { |
| 244 | ACPI_ERROR((AE_INFO, "Insufficient result stack size")); |
| 245 | return (AE_AML_INTERNAL); |
| 246 | } |
| 247 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | state = acpi_ut_pop_generic_state(&walk_state->results); |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 249 | acpi_ut_delete_generic_state(state); |
| 250 | |
| 251 | /* Decrease the length of result stack by the length of frame */ |
| 252 | |
| 253 | walk_state->result_size -= ACPI_RESULTS_FRAME_OBJ_NUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 256 | "Result=%p RemainingResults=%X State=%p\n", |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 257 | state, walk_state->result_count, walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | return (AE_OK); |
| 260 | } |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | /******************************************************************************* |
| 263 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | * FUNCTION: acpi_ds_obj_stack_push |
| 265 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 266 | * PARAMETERS: object - Object to push |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | * walk_state - Current Walk state |
| 268 | * |
| 269 | * RETURN: Status |
| 270 | * |
| 271 | * DESCRIPTION: Push an object onto this walk's object/operand stack |
| 272 | * |
| 273 | ******************************************************************************/ |
| 274 | |
| 275 | acpi_status |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 276 | acpi_ds_obj_stack_push(void *object, struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 278 | ACPI_FUNCTION_NAME(ds_obj_stack_push); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | /* Check for stack overflow */ |
| 281 | |
| 282 | if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 283 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 284 | "Object stack overflow! Obj=%p State=%p #Ops=%u", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 285 | object, walk_state, walk_state->num_operands)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | return (AE_STACK_OVERFLOW); |
| 287 | } |
| 288 | |
| 289 | /* Put the object onto the stack */ |
| 290 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 291 | walk_state->operands[walk_state->operand_index] = object; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | walk_state->num_operands++; |
| 293 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 294 | /* For the usual order of filling the operand stack */ |
| 295 | |
| 296 | walk_state->operand_index++; |
| 297 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n", |
| 299 | object, |
| 300 | acpi_ut_get_object_type_name((union |
| 301 | acpi_operand_object *) |
| 302 | object), walk_state, |
| 303 | walk_state->num_operands)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | return (AE_OK); |
| 306 | } |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | /******************************************************************************* |
| 309 | * |
| 310 | * FUNCTION: acpi_ds_obj_stack_pop |
| 311 | * |
| 312 | * PARAMETERS: pop_count - Number of objects/entries to pop |
| 313 | * walk_state - Current Walk state |
| 314 | * |
| 315 | * RETURN: Status |
| 316 | * |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 317 | * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | * deleted by this routine. |
| 319 | * |
| 320 | ******************************************************************************/ |
| 321 | |
| 322 | acpi_status |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 323 | acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 327 | ACPI_FUNCTION_NAME(ds_obj_stack_pop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | for (i = 0; i < pop_count; i++) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | /* Check for stack underflow */ |
| 332 | |
| 333 | if (walk_state->num_operands == 0) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 334 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 335 | "Object stack underflow! Count=%X State=%p #Ops=%u", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 336 | pop_count, walk_state, |
| 337 | walk_state->num_operands)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | return (AE_STACK_UNDERFLOW); |
| 339 | } |
| 340 | |
| 341 | /* Just set the stack entry to null */ |
| 342 | |
| 343 | walk_state->num_operands--; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 344 | walk_state->operands[walk_state->num_operands] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 347 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | pop_count, walk_state, walk_state->num_operands)); |
| 349 | |
| 350 | return (AE_OK); |
| 351 | } |
| 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | /******************************************************************************* |
| 354 | * |
| 355 | * FUNCTION: acpi_ds_obj_stack_pop_and_delete |
| 356 | * |
| 357 | * PARAMETERS: pop_count - Number of objects/entries to pop |
| 358 | * walk_state - Current Walk state |
| 359 | * |
| 360 | * RETURN: Status |
| 361 | * |
| 362 | * DESCRIPTION: Pop this walk's object stack and delete each object that is |
| 363 | * popped off. |
| 364 | * |
| 365 | ******************************************************************************/ |
| 366 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 367 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | acpi_ds_obj_stack_pop_and_delete(u32 pop_count, |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 369 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 371 | s32 i; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | union acpi_operand_object *obj_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 374 | ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 376 | if (pop_count == 0) { |
| 377 | return; |
| 378 | } |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 379 | |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 380 | for (i = (s32)pop_count - 1; i >= 0; i--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | if (walk_state->num_operands == 0) { |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 382 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /* Pop the stack and delete an object if present in this stack entry */ |
| 386 | |
| 387 | walk_state->num_operands--; |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 388 | obj_desc = walk_state->operands[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | if (obj_desc) { |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 390 | acpi_ut_remove_reference(walk_state->operands[i]); |
| 391 | walk_state->operands[i] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | pop_count, walk_state, walk_state->num_operands)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | /******************************************************************************* |
| 400 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | * FUNCTION: acpi_ds_get_current_walk_state |
| 402 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 403 | * PARAMETERS: thread - Get current active state for this Thread |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | * |
| 405 | * RETURN: Pointer to the current walk state |
| 406 | * |
| 407 | * DESCRIPTION: Get the walk state that is at the head of the list (the "current" |
| 408 | * walk state.) |
| 409 | * |
| 410 | ******************************************************************************/ |
| 411 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state |
| 413 | *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 415 | ACPI_FUNCTION_NAME(ds_get_current_walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | if (!thread) { |
| 418 | return (NULL); |
| 419 | } |
| 420 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 421 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Current WalkState %p\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | thread->walk_state_list)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | return (thread->walk_state_list); |
| 425 | } |
| 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | /******************************************************************************* |
| 428 | * |
| 429 | * FUNCTION: acpi_ds_push_walk_state |
| 430 | * |
| 431 | * PARAMETERS: walk_state - State to push |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 432 | * thread - Thread state object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | * |
| 434 | * RETURN: None |
| 435 | * |
Bob Moore | 773069d | 2008-04-10 19:06:36 +0400 | [diff] [blame] | 436 | * DESCRIPTION: Place the Thread state at the head of the state list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | * |
| 438 | ******************************************************************************/ |
| 439 | |
| 440 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 441 | acpi_ds_push_walk_state(struct acpi_walk_state *walk_state, |
| 442 | struct acpi_thread_state *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 444 | ACPI_FUNCTION_TRACE(ds_push_walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 446 | walk_state->next = thread->walk_state_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | thread->walk_state_list = walk_state; |
| 448 | |
| 449 | return_VOID; |
| 450 | } |
| 451 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | /******************************************************************************* |
| 453 | * |
| 454 | * FUNCTION: acpi_ds_pop_walk_state |
| 455 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 456 | * PARAMETERS: thread - Current thread state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 458 | * RETURN: A walk_state object popped from the thread's stack |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | * |
| 460 | * DESCRIPTION: Remove and return the walkstate object that is at the head of |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 461 | * the walk stack for the given walk list. NULL indicates that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | * the list is empty. |
| 463 | * |
| 464 | ******************************************************************************/ |
| 465 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 466 | struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | struct acpi_walk_state *walk_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 470 | ACPI_FUNCTION_TRACE(ds_pop_walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
| 472 | walk_state = thread->walk_state_list; |
| 473 | |
| 474 | if (walk_state) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | /* Next walk state becomes the current walk state */ |
| 477 | |
| 478 | thread->walk_state_list = walk_state->next; |
| 479 | |
| 480 | /* |
| 481 | * Don't clear the NEXT field, this serves as an indicator |
| 482 | * that there is a parent WALK STATE |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 483 | * Do Not: walk_state->Next = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | */ |
| 485 | } |
| 486 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 487 | return_PTR(walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | /******************************************************************************* |
| 491 | * |
| 492 | * FUNCTION: acpi_ds_create_walk_state |
| 493 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 494 | * PARAMETERS: owner_id - ID for object creation |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 495 | * origin - Starting point for this walk |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 496 | * method_desc - Method object |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 497 | * thread - Current thread state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | * |
| 499 | * RETURN: Pointer to the new walk state. |
| 500 | * |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 501 | * DESCRIPTION: Allocate and initialize a new walk state. The current walk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | * state is set to this new state. |
| 503 | * |
| 504 | ******************************************************************************/ |
| 505 | |
Lv Zheng | 1f86e8c | 2012-10-31 02:25:45 +0000 | [diff] [blame] | 506 | struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id, |
| 507 | union acpi_parse_object |
| 508 | *origin, |
| 509 | union acpi_operand_object |
| 510 | *method_desc, |
| 511 | struct acpi_thread_state |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | struct acpi_walk_state *walk_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 516 | ACPI_FUNCTION_TRACE(ds_create_walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 518 | walk_state = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (!walk_state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 520 | return_PTR(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 523 | walk_state->descriptor_type = ACPI_DESC_TYPE_WALK; |
| 524 | walk_state->method_desc = method_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 525 | walk_state->owner_id = owner_id; |
| 526 | walk_state->origin = origin; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 527 | walk_state->thread = thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | walk_state->parser_state.start_op = origin; |
| 530 | |
| 531 | /* Init the method args/local */ |
| 532 | |
Erik Schmauss | 178a0f6 | 2018-12-13 12:30:27 -0800 | [diff] [blame] | 533 | #ifndef ACPI_CONSTANT_EVAL_ONLY |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 534 | acpi_ds_method_data_init(walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | #endif |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* Put the new state at the head of the walk list */ |
| 538 | |
| 539 | if (thread) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 540 | acpi_ds_push_walk_state(walk_state, thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 543 | return_PTR(walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | /******************************************************************************* |
| 547 | * |
| 548 | * FUNCTION: acpi_ds_init_aml_walk |
| 549 | * |
| 550 | * PARAMETERS: walk_state - New state to be initialized |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 551 | * op - Current parse op |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | * method_node - Control method NS node, if any |
| 553 | * aml_start - Start of AML |
| 554 | * aml_length - Length of AML |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 555 | * info - Method info block (params, etc.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | * pass_number - 1, 2, or 3 |
| 557 | * |
| 558 | * RETURN: Status |
| 559 | * |
| 560 | * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk |
| 561 | * |
| 562 | ******************************************************************************/ |
| 563 | |
| 564 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 565 | acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state, |
| 566 | union acpi_parse_object *op, |
| 567 | struct acpi_namespace_node *method_node, |
| 568 | u8 * aml_start, |
| 569 | u32 aml_length, |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 570 | struct acpi_evaluate_info *info, u8 pass_number) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 572 | acpi_status status; |
| 573 | struct acpi_parse_state *parser_state = &walk_state->parser_state; |
| 574 | union acpi_parse_object *extra_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 576 | ACPI_FUNCTION_TRACE(ds_init_aml_walk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 578 | walk_state->parser_state.aml = |
| 579 | walk_state->parser_state.aml_start = aml_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | walk_state->parser_state.aml_end = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 581 | walk_state->parser_state.pkg_end = aml_start + aml_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | /* The next_op of the next_walk will be the beginning of the method */ |
| 584 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 585 | walk_state->next_op = NULL; |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 586 | walk_state->pass_number = pass_number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
| 588 | if (info) { |
Bob Moore | c91d924 | 2008-06-10 12:38:10 +0800 | [diff] [blame] | 589 | walk_state->params = info->parameters; |
| 590 | walk_state->caller_return_desc = &info->return_object; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 593 | status = acpi_ps_init_scope(&walk_state->parser_state, op); |
| 594 | if (ACPI_FAILURE(status)) { |
| 595 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | if (method_node) { |
| 599 | walk_state->parser_state.start_node = method_node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 600 | walk_state->walk_type = ACPI_WALK_METHOD; |
| 601 | walk_state->method_node = method_node; |
| 602 | walk_state->method_desc = |
| 603 | acpi_ns_get_attached_object(method_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | /* Push start scope on scope stack and make it current */ |
| 606 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 607 | status = |
| 608 | acpi_ds_scope_stack_push(method_node, ACPI_TYPE_METHOD, |
| 609 | walk_state); |
| 610 | if (ACPI_FAILURE(status)) { |
| 611 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /* Init the method arguments */ |
| 615 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 616 | status = acpi_ds_method_data_init_args(walk_state->params, |
| 617 | ACPI_METHOD_NUM_ARGS, |
| 618 | walk_state); |
| 619 | if (ACPI_FAILURE(status)) { |
| 620 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | /* |
| 624 | * Setup the current scope. |
| 625 | * Find a Named Op that has a namespace node associated with it. |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 626 | * search upwards from this Op. Current scope is the first |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | * Op with a namespace node. |
| 628 | */ |
| 629 | extra_op = parser_state->start_op; |
| 630 | while (extra_op && !extra_op->common.node) { |
| 631 | extra_op = extra_op->common.parent; |
| 632 | } |
| 633 | |
| 634 | if (!extra_op) { |
| 635 | parser_state->start_node = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 636 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | parser_state->start_node = extra_op->common.node; |
| 638 | } |
| 639 | |
| 640 | if (parser_state->start_node) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | /* Push start scope on scope stack and make it current */ |
| 643 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 644 | status = |
| 645 | acpi_ds_scope_stack_push(parser_state->start_node, |
| 646 | parser_state->start_node-> |
| 647 | type, walk_state); |
| 648 | if (ACPI_FAILURE(status)) { |
| 649 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 654 | status = acpi_ds_init_callbacks(walk_state, pass_number); |
| 655 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | /******************************************************************************* |
| 659 | * |
| 660 | * FUNCTION: acpi_ds_delete_walk_state |
| 661 | * |
| 662 | * PARAMETERS: walk_state - State to delete |
| 663 | * |
| 664 | * RETURN: Status |
| 665 | * |
| 666 | * DESCRIPTION: Delete a walk state including all internal data structures |
| 667 | * |
| 668 | ******************************************************************************/ |
| 669 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 670 | void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 672 | union acpi_generic_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 674 | ACPI_FUNCTION_TRACE_PTR(ds_delete_walk_state, walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
| 676 | if (!walk_state) { |
Bob Moore | 68aafc3 | 2012-10-31 02:26:01 +0000 | [diff] [blame] | 677 | return_VOID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 680 | if (walk_state->descriptor_type != ACPI_DESC_TYPE_WALK) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 681 | ACPI_ERROR((AE_INFO, "%p is not a valid walk state", |
| 682 | walk_state)); |
Bob Moore | 68aafc3 | 2012-10-31 02:26:01 +0000 | [diff] [blame] | 683 | return_VOID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 686 | /* There should not be any open scopes */ |
| 687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | if (walk_state->parser_state.scope) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 689 | ACPI_ERROR((AE_INFO, "%p walk still has a scope list", |
| 690 | walk_state)); |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 691 | acpi_ps_cleanup_scope(&walk_state->parser_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /* Always must free any linked control states */ |
| 695 | |
| 696 | while (walk_state->control_state) { |
| 697 | state = walk_state->control_state; |
| 698 | walk_state->control_state = state->common.next; |
| 699 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 700 | acpi_ut_delete_generic_state(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /* Always must free any linked parse states */ |
| 704 | |
| 705 | while (walk_state->scope_info) { |
| 706 | state = walk_state->scope_info; |
| 707 | walk_state->scope_info = state->common.next; |
| 708 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 709 | acpi_ut_delete_generic_state(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /* Always must free any stacked result states */ |
| 713 | |
| 714 | while (walk_state->results) { |
| 715 | state = walk_state->results; |
| 716 | walk_state->results = state->common.next; |
| 717 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 718 | acpi_ut_delete_generic_state(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 721 | ACPI_FREE(walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | return_VOID; |
| 723 | } |