[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / drivers / acpi / parser / psscope.c
blobdcbed49608b01895abd301c94857b01d7bf2028a
1 /******************************************************************************
3 * Module Name: psscope - Parser scope stack management routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
48 #define _COMPONENT ACPI_PARSER
49 ACPI_MODULE_NAME ("psscope")
52 /*******************************************************************************
54 * FUNCTION: acpi_ps_get_parent_scope
56 * PARAMETERS: parser_state - Current parser state object
58 * RETURN: Pointer to an Op object
60 * DESCRIPTION: Get parent of current op being parsed
62 ******************************************************************************/
64 union acpi_parse_object *
65 acpi_ps_get_parent_scope (
66 struct acpi_parse_state *parser_state)
68 return (parser_state->scope->parse_scope.op);
72 /*******************************************************************************
74 * FUNCTION: acpi_ps_has_completed_scope
76 * PARAMETERS: parser_state - Current parser state object
78 * RETURN: Boolean, TRUE = scope completed.
80 * DESCRIPTION: Is parsing of current argument complete? Determined by
81 * 1) AML pointer is at or beyond the end of the scope
82 * 2) The scope argument count has reached zero.
84 ******************************************************************************/
87 acpi_ps_has_completed_scope (
88 struct acpi_parse_state *parser_state)
90 return ((u8) ((parser_state->aml >= parser_state->scope->parse_scope.arg_end ||
91 !parser_state->scope->parse_scope.arg_count)));
95 /*******************************************************************************
97 * FUNCTION: acpi_ps_init_scope
99 * PARAMETERS: parser_state - Current parser state object
100 * Root - the Root Node of this new scope
102 * RETURN: Status
104 * DESCRIPTION: Allocate and init a new scope object
106 ******************************************************************************/
108 acpi_status
109 acpi_ps_init_scope (
110 struct acpi_parse_state *parser_state,
111 union acpi_parse_object *root_op)
113 union acpi_generic_state *scope;
116 ACPI_FUNCTION_TRACE_PTR ("ps_init_scope", root_op);
119 scope = acpi_ut_create_generic_state ();
120 if (!scope) {
121 return_ACPI_STATUS (AE_NO_MEMORY);
124 scope->common.data_type = ACPI_DESC_TYPE_STATE_RPSCOPE;
125 scope->parse_scope.op = root_op;
126 scope->parse_scope.arg_count = ACPI_VAR_ARGS;
127 scope->parse_scope.arg_end = parser_state->aml_end;
128 scope->parse_scope.pkg_end = parser_state->aml_end;
130 parser_state->scope = scope;
131 parser_state->start_op = root_op;
133 return_ACPI_STATUS (AE_OK);
137 /*******************************************************************************
139 * FUNCTION: acpi_ps_push_scope
141 * PARAMETERS: parser_state - Current parser state object
142 * Op - Current op to be pushed
143 * remaining_args - List of args remaining
144 * arg_count - Fixed or variable number of args
146 * RETURN: Status
148 * DESCRIPTION: Push current op to begin parsing its argument
150 ******************************************************************************/
152 acpi_status
153 acpi_ps_push_scope (
154 struct acpi_parse_state *parser_state,
155 union acpi_parse_object *op,
156 u32 remaining_args,
157 u32 arg_count)
159 union acpi_generic_state *scope;
162 ACPI_FUNCTION_TRACE_PTR ("ps_push_scope", op);
165 scope = acpi_ut_create_generic_state ();
166 if (!scope) {
167 return_ACPI_STATUS (AE_NO_MEMORY);
170 scope->common.data_type = ACPI_DESC_TYPE_STATE_PSCOPE;
171 scope->parse_scope.op = op;
172 scope->parse_scope.arg_list = remaining_args;
173 scope->parse_scope.arg_count = arg_count;
174 scope->parse_scope.pkg_end = parser_state->pkg_end;
176 /* Push onto scope stack */
178 acpi_ut_push_generic_state (&parser_state->scope, scope);
180 if (arg_count == ACPI_VAR_ARGS) {
181 /* multiple arguments */
183 scope->parse_scope.arg_end = parser_state->pkg_end;
185 else {
186 /* single argument */
188 scope->parse_scope.arg_end = ACPI_TO_POINTER (ACPI_MAX_PTR);
191 return_ACPI_STATUS (AE_OK);
195 /*******************************************************************************
197 * FUNCTION: acpi_ps_pop_scope
199 * PARAMETERS: parser_state - Current parser state object
200 * Op - Where the popped op is returned
201 * arg_list - Where the popped "next argument" is
202 * returned
203 * arg_count - Count of objects in arg_list
205 * RETURN: Status
207 * DESCRIPTION: Return to parsing a previous op
209 ******************************************************************************/
211 void
212 acpi_ps_pop_scope (
213 struct acpi_parse_state *parser_state,
214 union acpi_parse_object **op,
215 u32 *arg_list,
216 u32 *arg_count)
218 union acpi_generic_state *scope = parser_state->scope;
221 ACPI_FUNCTION_TRACE ("ps_pop_scope");
225 * Only pop the scope if there is in fact a next scope
227 if (scope->common.next) {
228 scope = acpi_ut_pop_generic_state (&parser_state->scope);
230 /* return to parsing previous op */
232 *op = scope->parse_scope.op;
233 *arg_list = scope->parse_scope.arg_list;
234 *arg_count = scope->parse_scope.arg_count;
235 parser_state->pkg_end = scope->parse_scope.pkg_end;
237 /* All done with this scope state structure */
239 acpi_ut_delete_generic_state (scope);
241 else {
242 /* empty parse stack, prepare to fetch next opcode */
244 *op = NULL;
245 *arg_list = 0;
246 *arg_count = 0;
249 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped Op %p Args %X\n", *op, *arg_count));
250 return_VOID;
254 /*******************************************************************************
256 * FUNCTION: acpi_ps_cleanup_scope
258 * PARAMETERS: parser_state - Current parser state object
260 * RETURN: Status
262 * DESCRIPTION: Destroy available list, remaining stack levels, and return
263 * root scope
265 ******************************************************************************/
267 void
268 acpi_ps_cleanup_scope (
269 struct acpi_parse_state *parser_state)
271 union acpi_generic_state *scope;
274 ACPI_FUNCTION_TRACE_PTR ("ps_cleanup_scope", parser_state);
277 if (!parser_state) {
278 return_VOID;
281 /* Delete anything on the scope stack */
283 while (parser_state->scope) {
284 scope = acpi_ut_pop_generic_state (&parser_state->scope);
285 acpi_ut_delete_generic_state (scope);
288 return_VOID;