Blame view

drivers/acpi/acpica/psscope.c 8.16 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
  /******************************************************************************
   *
   * Module Name: psscope - Parser scope stack management routines
   *
   *****************************************************************************/
  
  /*
75a44ce00   Len Brown   ACPICA: update In...
8
   * Copyright (C) 2000 - 2008, Intel Corp.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions, and the following disclaimer,
   *    without modification.
   * 2. Redistributions in binary form must reproduce at minimum a disclaimer
   *    substantially similar to the "NO WARRANTY" disclaimer below
   *    ("Disclaimer") and any redistribution must be conditioned upon
   *    including a substantially similar Disclaimer requirement for further
   *    binary redistribution.
   * 3. Neither the names of the above-listed copyright holders nor the names
   *    of any contributors may be used to endorse or promote products derived
   *    from this software without specific prior written permission.
   *
   * Alternatively, this software may be distributed under the terms of the
   * GNU General Public License ("GPL") version 2 as published by the Free
   * Software Foundation.
   *
   * NO WARRANTY
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   * POSSIBILITY OF SUCH DAMAGES.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  #include <acpi/acpi.h>
e2f7a7772   Len Brown   ACPICA: hide priv...
44
45
  #include "accommon.h"
  #include "acparser.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
  
  #define _COMPONENT          ACPI_PARSER
4be44fcd3   Len Brown   [ACPI] Lindent al...
48
  ACPI_MODULE_NAME("psscope")
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
51
52
53
54
55
56
57
58
59
60
  
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ps_get_parent_scope
   *
   * PARAMETERS:  parser_state        - Current parser state object
   *
   * RETURN:      Pointer to an Op object
   *
   * DESCRIPTION: Get parent of current op being parsed
   *
   ******************************************************************************/
4be44fcd3   Len Brown   [ACPI] Lindent al...
61
62
  union acpi_parse_object *acpi_ps_get_parent_scope(struct acpi_parse_state
  						  *parser_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
  {
44f6c0124   Robert Moore   ACPICA 20050408 f...
64

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
  	return (parser_state->scope->parse_scope.op);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
68
69
70
71
72
73
74
75
76
77
78
79
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ps_has_completed_scope
   *
   * PARAMETERS:  parser_state        - Current parser state object
   *
   * RETURN:      Boolean, TRUE = scope completed.
   *
   * DESCRIPTION: Is parsing of current argument complete?  Determined by
   *              1) AML pointer is at or beyond the end of the scope
   *              2) The scope argument count has reached zero.
   *
   ******************************************************************************/
4be44fcd3   Len Brown   [ACPI] Lindent al...
80
  u8 acpi_ps_has_completed_scope(struct acpi_parse_state * parser_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
  {
44f6c0124   Robert Moore   ACPICA 20050408 f...
82
83
  
  	return ((u8)
4be44fcd3   Len Brown   [ACPI] Lindent al...
84
85
  		((parser_state->aml >= parser_state->scope->parse_scope.arg_end
  		  || !parser_state->scope->parse_scope.arg_count)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ps_init_scope
   *
   * PARAMETERS:  parser_state        - Current parser state object
   *              Root                - the Root Node of this new scope
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Allocate and init a new scope object
   *
   ******************************************************************************/
  
  acpi_status
4be44fcd3   Len Brown   [ACPI] Lindent al...
101
102
  acpi_ps_init_scope(struct acpi_parse_state * parser_state,
  		   union acpi_parse_object * root_op)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
104
  	union acpi_generic_state *scope;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
106
  	ACPI_FUNCTION_TRACE_PTR(ps_init_scope, root_op);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107

4be44fcd3   Len Brown   [ACPI] Lindent al...
108
  	scope = acpi_ut_create_generic_state();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  	if (!scope) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
110
  		return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
  	}
61686124f   Bob Moore   [ACPI] ACPICA 200...
112
  	scope->common.descriptor_type = ACPI_DESC_TYPE_STATE_RPSCOPE;
4be44fcd3   Len Brown   [ACPI] Lindent al...
113
  	scope->parse_scope.op = root_op;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
  	scope->parse_scope.arg_count = ACPI_VAR_ARGS;
4be44fcd3   Len Brown   [ACPI] Lindent al...
115
116
  	scope->parse_scope.arg_end = parser_state->aml_end;
  	scope->parse_scope.pkg_end = parser_state->aml_end;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117

4be44fcd3   Len Brown   [ACPI] Lindent al...
118
119
  	parser_state->scope = scope;
  	parser_state->start_op = root_op;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120

4be44fcd3   Len Brown   [ACPI] Lindent al...
121
  	return_ACPI_STATUS(AE_OK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ps_push_scope
   *
   * PARAMETERS:  parser_state        - Current parser state object
   *              Op                  - Current op to be pushed
   *              remaining_args      - List of args remaining
   *              arg_count           - Fixed or variable number of args
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Push current op to begin parsing its argument
   *
   ******************************************************************************/
  
  acpi_status
4be44fcd3   Len Brown   [ACPI] Lindent al...
139
140
  acpi_ps_push_scope(struct acpi_parse_state *parser_state,
  		   union acpi_parse_object *op,
793c2388c   Bob Moore   ACPI: ACPICA 2006...
141
  		   u32 remaining_args, u32 arg_count)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
143
  	union acpi_generic_state *scope;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
144

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
145
  	ACPI_FUNCTION_TRACE_PTR(ps_push_scope, op);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146

4be44fcd3   Len Brown   [ACPI] Lindent al...
147
  	scope = acpi_ut_create_generic_state();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
  	if (!scope) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
149
  		return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150
  	}
61686124f   Bob Moore   [ACPI] ACPICA 200...
151
  	scope->common.descriptor_type = ACPI_DESC_TYPE_STATE_PSCOPE;
4be44fcd3   Len Brown   [ACPI] Lindent al...
152
  	scope->parse_scope.op = op;
44f6c0124   Robert Moore   ACPICA 20050408 f...
153
154
155
  	scope->parse_scope.arg_list = remaining_args;
  	scope->parse_scope.arg_count = arg_count;
  	scope->parse_scope.pkg_end = parser_state->pkg_end;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
  
  	/* Push onto scope stack */
4be44fcd3   Len Brown   [ACPI] Lindent al...
158
  	acpi_ut_push_generic_state(&parser_state->scope, scope);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159
160
  
  	if (arg_count == ACPI_VAR_ARGS) {
52fc0b026   Bob Moore   [ACPI] ACPICA 200...
161

44f6c0124   Robert Moore   ACPICA 20050408 f...
162
  		/* Multiple arguments */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
163
164
  
  		scope->parse_scope.arg_end = parser_state->pkg_end;
4be44fcd3   Len Brown   [ACPI] Lindent al...
165
  	} else {
44f6c0124   Robert Moore   ACPICA 20050408 f...
166
  		/* Single argument */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
167

4be44fcd3   Len Brown   [ACPI] Lindent al...
168
  		scope->parse_scope.arg_end = ACPI_TO_POINTER(ACPI_MAX_PTR);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
  	}
4be44fcd3   Len Brown   [ACPI] Lindent al...
170
  	return_ACPI_STATUS(AE_OK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ps_pop_scope
   *
   * PARAMETERS:  parser_state        - Current parser state object
   *              Op                  - Where the popped op is returned
   *              arg_list            - Where the popped "next argument" is
   *                                    returned
   *              arg_count           - Count of objects in arg_list
   *
   * RETURN:      Status
   *
   * DESCRIPTION: Return to parsing a previous op
   *
   ******************************************************************************/
  
  void
4be44fcd3   Len Brown   [ACPI] Lindent al...
189
  acpi_ps_pop_scope(struct acpi_parse_state *parser_state,
793c2388c   Bob Moore   ACPI: ACPICA 2006...
190
  		  union acpi_parse_object **op, u32 * arg_list, u32 * arg_count)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
191
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
192
  	union acpi_generic_state *scope = parser_state->scope;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
194
  	ACPI_FUNCTION_TRACE(ps_pop_scope);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195

44f6c0124   Robert Moore   ACPICA 20050408 f...
196
  	/* Only pop the scope if there is in fact a next scope */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
  	if (scope->common.next) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
198
  		scope = acpi_ut_pop_generic_state(&parser_state->scope);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199

61686124f   Bob Moore   [ACPI] ACPICA 200...
200
  		/* Return to parsing previous op */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
201

4be44fcd3   Len Brown   [ACPI] Lindent al...
202
203
204
  		*op = scope->parse_scope.op;
  		*arg_list = scope->parse_scope.arg_list;
  		*arg_count = scope->parse_scope.arg_count;
44f6c0124   Robert Moore   ACPICA 20050408 f...
205
  		parser_state->pkg_end = scope->parse_scope.pkg_end;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
206
207
  
  		/* All done with this scope state structure */
4be44fcd3   Len Brown   [ACPI] Lindent al...
208
209
  		acpi_ut_delete_generic_state(scope);
  	} else {
61686124f   Bob Moore   [ACPI] ACPICA 200...
210
  		/* Empty parse stack, prepare to fetch next opcode */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211

4be44fcd3   Len Brown   [ACPI] Lindent al...
212
  		*op = NULL;
44f6c0124   Robert Moore   ACPICA 20050408 f...
213
214
  		*arg_list = 0;
  		*arg_count = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
215
  	}
4be44fcd3   Len Brown   [ACPI] Lindent al...
216
217
218
  	ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  			  "Popped Op %p Args %X
  ", *op, *arg_count));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219
220
  	return_VOID;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221
222
223
224
225
226
  /*******************************************************************************
   *
   * FUNCTION:    acpi_ps_cleanup_scope
   *
   * PARAMETERS:  parser_state        - Current parser state object
   *
44f6c0124   Robert Moore   ACPICA 20050408 f...
227
   * RETURN:      None
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
228
229
230
231
232
   *
   * DESCRIPTION: Destroy available list, remaining stack levels, and return
   *              root scope
   *
   ******************************************************************************/
4be44fcd3   Len Brown   [ACPI] Lindent al...
233
  void acpi_ps_cleanup_scope(struct acpi_parse_state *parser_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
235
  	union acpi_generic_state *scope;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
236

b229cf92e   Bob Moore   ACPI: ACPICA 2006...
237
  	ACPI_FUNCTION_TRACE_PTR(ps_cleanup_scope, parser_state);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
238
239
240
241
242
243
244
245
  
  	if (!parser_state) {
  		return_VOID;
  	}
  
  	/* Delete anything on the scope stack */
  
  	while (parser_state->scope) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
246
247
  		scope = acpi_ut_pop_generic_state(&parser_state->scope);
  		acpi_ut_delete_generic_state(scope);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
248
249
250
251
  	}
  
  	return_VOID;
  }