- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / parser / psscope.c
blob2e8926ad159b205f22f945d21a7eeea9e9b9f8a5
1 /******************************************************************************
3 * Module Name: psscope - Parser scope stack management routines
4 * $Revision: 22 $
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "acpi.h"
28 #include "acparser.h"
30 #define _COMPONENT PARSER
31 MODULE_NAME ("psscope")
34 /*******************************************************************************
36 * FUNCTION: Acpi_ps_get_parent_scope
38 * PARAMETERS: Parser_state - Current parser state object
40 * RETURN: Pointer to an Op object
42 * DESCRIPTION: Get parent of current op being parsed
44 ******************************************************************************/
46 ACPI_PARSE_OBJECT *
47 acpi_ps_get_parent_scope (
48 ACPI_PARSE_STATE *parser_state)
50 return (parser_state->scope->parse_scope.op);
54 /*******************************************************************************
56 * FUNCTION: Acpi_ps_has_completed_scope
58 * PARAMETERS: Parser_state - Current parser state object
60 * RETURN: Boolean, TRUE = scope completed.
62 * DESCRIPTION: Is parsing of current argument complete? Determined by
63 * 1) AML pointer is at or beyond the end of the scope
64 * 2) The scope argument count has reached zero.
66 ******************************************************************************/
69 acpi_ps_has_completed_scope (
70 ACPI_PARSE_STATE *parser_state)
72 return ((u8) ((parser_state->aml >= parser_state->scope->parse_scope.arg_end ||
73 !parser_state->scope->parse_scope.arg_count)));
77 /*******************************************************************************
79 * FUNCTION: Acpi_ps_init_scope
81 * PARAMETERS: Parser_state - Current parser state object
82 * Root - the Root Node of this new scope
84 * RETURN: Status
86 * DESCRIPTION: Allocate and init a new scope object
88 ******************************************************************************/
90 ACPI_STATUS
91 acpi_ps_init_scope (
92 ACPI_PARSE_STATE *parser_state,
93 ACPI_PARSE_OBJECT *root_op)
95 ACPI_GENERIC_STATE *scope;
98 scope = acpi_cm_create_generic_state ();
99 if (!scope) {
100 return (AE_NO_MEMORY);
103 scope->parse_scope.op = root_op;
104 scope->parse_scope.arg_count = ACPI_VAR_ARGS;
105 scope->parse_scope.arg_end = parser_state->aml_end;
106 scope->parse_scope.pkg_end = parser_state->aml_end;
108 parser_state->scope = scope;
109 parser_state->start_op = root_op;
111 return (AE_OK);
115 /*******************************************************************************
117 * FUNCTION: Acpi_ps_push_scope
119 * PARAMETERS: Parser_state - Current parser state object
120 * Op - Current op to be pushed
121 * Remaining_args - List of args remaining
122 * Arg_count - Fixed or variable number of args
124 * RETURN: Status
126 * DESCRIPTION: Push current op to begin parsing its argument
128 ******************************************************************************/
130 ACPI_STATUS
131 acpi_ps_push_scope (
132 ACPI_PARSE_STATE *parser_state,
133 ACPI_PARSE_OBJECT *op,
134 u32 remaining_args,
135 u32 arg_count)
137 ACPI_GENERIC_STATE *scope;
140 scope = acpi_cm_create_generic_state ();
141 if (!scope) {
142 return (AE_NO_MEMORY);
146 scope->parse_scope.op = op;
147 scope->parse_scope.arg_list = remaining_args;
148 scope->parse_scope.arg_count = arg_count;
149 scope->parse_scope.pkg_end = parser_state->pkg_end;
151 /* Push onto scope stack */
153 acpi_cm_push_generic_state (&parser_state->scope, scope);
156 if (arg_count == ACPI_VAR_ARGS) {
157 /* multiple arguments */
159 scope->parse_scope.arg_end = parser_state->pkg_end;
162 else {
163 /* single argument */
165 scope->parse_scope.arg_end = ACPI_MAX_AML;
168 return (AE_OK);
172 /*******************************************************************************
174 * FUNCTION: Acpi_ps_pop_scope
176 * PARAMETERS: Parser_state - Current parser state object
177 * Op - Where the popped op is returned
178 * Arg_list - Where the popped "next argument" is
179 * returned
180 * Arg_count - Count of objects in Arg_list
182 * RETURN: Status
184 * DESCRIPTION: Return to parsing a previous op
186 ******************************************************************************/
188 void
189 acpi_ps_pop_scope (
190 ACPI_PARSE_STATE *parser_state,
191 ACPI_PARSE_OBJECT **op,
192 u32 *arg_list,
193 u32 *arg_count)
195 ACPI_GENERIC_STATE *scope = parser_state->scope;
199 * Only pop the scope if there is in fact a next scope
201 if (scope->common.next) {
202 scope = acpi_cm_pop_generic_state (&parser_state->scope);
205 /* return to parsing previous op */
207 *op = scope->parse_scope.op;
208 *arg_list = scope->parse_scope.arg_list;
209 *arg_count = scope->parse_scope.arg_count;
210 parser_state->pkg_end = scope->parse_scope.pkg_end;
212 /* All done with this scope state structure */
214 acpi_cm_delete_generic_state (scope);
217 else {
218 /* empty parse stack, prepare to fetch next opcode */
220 *op = NULL;
221 *arg_list = 0;
222 *arg_count = 0;
226 return;
230 /*******************************************************************************
232 * FUNCTION: Acpi_ps_cleanup_scope
234 * PARAMETERS: Parser_state - Current parser state object
236 * RETURN: Status
238 * DESCRIPTION: Destroy available list, remaining stack levels, and return
239 * root scope
241 ******************************************************************************/
243 void
244 acpi_ps_cleanup_scope (
245 ACPI_PARSE_STATE *parser_state)
247 ACPI_GENERIC_STATE *scope;
250 if (!parser_state) {
251 return;
255 /* Delete anything on the scope stack */
257 while (parser_state->scope) {
258 scope = acpi_cm_pop_generic_state (&parser_state->scope);
259 acpi_cm_delete_generic_state (scope);
262 return;