Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: psscope - Parser scope stack management routines |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/acparser.h> |
| 46 | |
| 47 | #define _COMPONENT ACPI_PARSER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | ACPI_MODULE_NAME("psscope") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | /******************************************************************************* |
| 51 | * |
| 52 | * FUNCTION: acpi_ps_get_parent_scope |
| 53 | * |
| 54 | * PARAMETERS: parser_state - Current parser state object |
| 55 | * |
| 56 | * RETURN: Pointer to an Op object |
| 57 | * |
| 58 | * DESCRIPTION: Get parent of current op being parsed |
| 59 | * |
| 60 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 61 | union acpi_parse_object *acpi_ps_get_parent_scope(struct acpi_parse_state |
| 62 | *parser_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | return (parser_state->scope->parse_scope.op); |
| 66 | } |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /******************************************************************************* |
| 69 | * |
| 70 | * FUNCTION: acpi_ps_has_completed_scope |
| 71 | * |
| 72 | * PARAMETERS: parser_state - Current parser state object |
| 73 | * |
| 74 | * RETURN: Boolean, TRUE = scope completed. |
| 75 | * |
| 76 | * DESCRIPTION: Is parsing of current argument complete? Determined by |
| 77 | * 1) AML pointer is at or beyond the end of the scope |
| 78 | * 2) The scope argument count has reached zero. |
| 79 | * |
| 80 | ******************************************************************************/ |
| 81 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 82 | u8 acpi_ps_has_completed_scope(struct acpi_parse_state * parser_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 84 | |
| 85 | return ((u8) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | ((parser_state->aml >= parser_state->scope->parse_scope.arg_end |
| 87 | || !parser_state->scope->parse_scope.arg_count))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /******************************************************************************* |
| 91 | * |
| 92 | * FUNCTION: acpi_ps_init_scope |
| 93 | * |
| 94 | * PARAMETERS: parser_state - Current parser state object |
| 95 | * Root - the Root Node of this new scope |
| 96 | * |
| 97 | * RETURN: Status |
| 98 | * |
| 99 | * DESCRIPTION: Allocate and init a new scope object |
| 100 | * |
| 101 | ******************************************************************************/ |
| 102 | |
| 103 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | acpi_ps_init_scope(struct acpi_parse_state * parser_state, |
| 105 | union acpi_parse_object * root_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | union acpi_generic_state *scope; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | ACPI_FUNCTION_TRACE_PTR("ps_init_scope", root_op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | scope = acpi_ut_create_generic_state(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | if (!scope) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | scope->common.data_type = ACPI_DESC_TYPE_STATE_RPSCOPE; |
| 117 | scope->parse_scope.op = root_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | scope->parse_scope.arg_count = ACPI_VAR_ARGS; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | scope->parse_scope.arg_end = parser_state->aml_end; |
| 120 | scope->parse_scope.pkg_end = parser_state->aml_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | parser_state->scope = scope; |
| 123 | parser_state->start_op = root_op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /******************************************************************************* |
| 129 | * |
| 130 | * FUNCTION: acpi_ps_push_scope |
| 131 | * |
| 132 | * PARAMETERS: parser_state - Current parser state object |
| 133 | * Op - Current op to be pushed |
| 134 | * remaining_args - List of args remaining |
| 135 | * arg_count - Fixed or variable number of args |
| 136 | * |
| 137 | * RETURN: Status |
| 138 | * |
| 139 | * DESCRIPTION: Push current op to begin parsing its argument |
| 140 | * |
| 141 | ******************************************************************************/ |
| 142 | |
| 143 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | acpi_ps_push_scope(struct acpi_parse_state *parser_state, |
| 145 | union acpi_parse_object *op, |
| 146 | u32 remaining_args, u32 arg_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | union acpi_generic_state *scope; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | ACPI_FUNCTION_TRACE_PTR("ps_push_scope", op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | scope = acpi_ut_create_generic_state(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | if (!scope) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | scope->common.data_type = ACPI_DESC_TYPE_STATE_PSCOPE; |
| 158 | scope->parse_scope.op = op; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 159 | scope->parse_scope.arg_list = remaining_args; |
| 160 | scope->parse_scope.arg_count = arg_count; |
| 161 | scope->parse_scope.pkg_end = parser_state->pkg_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | /* Push onto scope stack */ |
| 164 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | acpi_ut_push_generic_state(&parser_state->scope, scope); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | if (arg_count == ACPI_VAR_ARGS) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 168 | /* Multiple arguments */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | scope->parse_scope.arg_end = parser_state->pkg_end; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | } else { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 172 | /* Single argument */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | scope->parse_scope.arg_end = ACPI_TO_POINTER(ACPI_MAX_PTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | /******************************************************************************* |
| 181 | * |
| 182 | * FUNCTION: acpi_ps_pop_scope |
| 183 | * |
| 184 | * PARAMETERS: parser_state - Current parser state object |
| 185 | * Op - Where the popped op is returned |
| 186 | * arg_list - Where the popped "next argument" is |
| 187 | * returned |
| 188 | * arg_count - Count of objects in arg_list |
| 189 | * |
| 190 | * RETURN: Status |
| 191 | * |
| 192 | * DESCRIPTION: Return to parsing a previous op |
| 193 | * |
| 194 | ******************************************************************************/ |
| 195 | |
| 196 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | acpi_ps_pop_scope(struct acpi_parse_state *parser_state, |
| 198 | union acpi_parse_object **op, u32 * arg_list, u32 * arg_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | union acpi_generic_state *scope = parser_state->scope; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | ACPI_FUNCTION_TRACE("ps_pop_scope"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 204 | /* Only pop the scope if there is in fact a next scope */ |
| 205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | if (scope->common.next) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 207 | scope = acpi_ut_pop_generic_state(&parser_state->scope); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* return to parsing previous op */ |
| 210 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | *op = scope->parse_scope.op; |
| 212 | *arg_list = scope->parse_scope.arg_list; |
| 213 | *arg_count = scope->parse_scope.arg_count; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 214 | parser_state->pkg_end = scope->parse_scope.pkg_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | /* All done with this scope state structure */ |
| 217 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | acpi_ut_delete_generic_state(scope); |
| 219 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | /* empty parse stack, prepare to fetch next opcode */ |
| 221 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 222 | *op = NULL; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 223 | *arg_list = 0; |
| 224 | *arg_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 228 | "Popped Op %p Args %X\n", *op, *arg_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | return_VOID; |
| 230 | } |
| 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | /******************************************************************************* |
| 233 | * |
| 234 | * FUNCTION: acpi_ps_cleanup_scope |
| 235 | * |
| 236 | * PARAMETERS: parser_state - Current parser state object |
| 237 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 238 | * RETURN: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | * |
| 240 | * DESCRIPTION: Destroy available list, remaining stack levels, and return |
| 241 | * root scope |
| 242 | * |
| 243 | ******************************************************************************/ |
| 244 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | void acpi_ps_cleanup_scope(struct acpi_parse_state *parser_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 247 | union acpi_generic_state *scope; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 249 | ACPI_FUNCTION_TRACE_PTR("ps_cleanup_scope", parser_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | if (!parser_state) { |
| 252 | return_VOID; |
| 253 | } |
| 254 | |
| 255 | /* Delete anything on the scope stack */ |
| 256 | |
| 257 | while (parser_state->scope) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | scope = acpi_ut_pop_generic_state(&parser_state->scope); |
| 259 | acpi_ut_delete_generic_state(scope); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | return_VOID; |
| 263 | } |