diff options
Diffstat (limited to 'drivers/acpi/utilities/utstate.c')
-rw-r--r-- | drivers/acpi/utilities/utstate.c | 376 |
1 files changed, 376 insertions, 0 deletions
diff --git a/drivers/acpi/utilities/utstate.c b/drivers/acpi/utilities/utstate.c new file mode 100644 index 000000000000..192e7ac95690 --- /dev/null +++ b/drivers/acpi/utilities/utstate.c | |||
@@ -0,0 +1,376 @@ | |||
1 | /******************************************************************************* | ||
2 | * | ||
3 | * Module Name: utstate - state object support procedures | ||
4 | * | ||
5 | ******************************************************************************/ | ||
6 | |||
7 | /* | ||
8 | * Copyright (C) 2000 - 2005, R. Byron Moore | ||
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 | |||
44 | |||
45 | #include <acpi/acpi.h> | ||
46 | |||
47 | #define _COMPONENT ACPI_UTILITIES | ||
48 | ACPI_MODULE_NAME ("utstate") | ||
49 | |||
50 | |||
51 | /******************************************************************************* | ||
52 | * | ||
53 | * FUNCTION: acpi_ut_create_pkg_state_and_push | ||
54 | * | ||
55 | * PARAMETERS: Object - Object to be added to the new state | ||
56 | * Action - Increment/Decrement | ||
57 | * state_list - List the state will be added to | ||
58 | * | ||
59 | * RETURN: Status | ||
60 | * | ||
61 | * DESCRIPTION: Create a new state and push it | ||
62 | * | ||
63 | ******************************************************************************/ | ||
64 | |||
65 | acpi_status | ||
66 | acpi_ut_create_pkg_state_and_push ( | ||
67 | void *internal_object, | ||
68 | void *external_object, | ||
69 | u16 index, | ||
70 | union acpi_generic_state **state_list) | ||
71 | { | ||
72 | union acpi_generic_state *state; | ||
73 | |||
74 | |||
75 | ACPI_FUNCTION_ENTRY (); | ||
76 | |||
77 | |||
78 | state = acpi_ut_create_pkg_state (internal_object, external_object, index); | ||
79 | if (!state) { | ||
80 | return (AE_NO_MEMORY); | ||
81 | } | ||
82 | |||
83 | acpi_ut_push_generic_state (state_list, state); | ||
84 | return (AE_OK); | ||
85 | } | ||
86 | |||
87 | |||
88 | /******************************************************************************* | ||
89 | * | ||
90 | * FUNCTION: acpi_ut_push_generic_state | ||
91 | * | ||
92 | * PARAMETERS: list_head - Head of the state stack | ||
93 | * State - State object to push | ||
94 | * | ||
95 | * RETURN: None | ||
96 | * | ||
97 | * DESCRIPTION: Push a state object onto a state stack | ||
98 | * | ||
99 | ******************************************************************************/ | ||
100 | |||
101 | void | ||
102 | acpi_ut_push_generic_state ( | ||
103 | union acpi_generic_state **list_head, | ||
104 | union acpi_generic_state *state) | ||
105 | { | ||
106 | ACPI_FUNCTION_TRACE ("ut_push_generic_state"); | ||
107 | |||
108 | |||
109 | /* Push the state object onto the front of the list (stack) */ | ||
110 | |||
111 | state->common.next = *list_head; | ||
112 | *list_head = state; | ||
113 | |||
114 | return_VOID; | ||
115 | } | ||
116 | |||
117 | |||
118 | /******************************************************************************* | ||
119 | * | ||
120 | * FUNCTION: acpi_ut_pop_generic_state | ||
121 | * | ||
122 | * PARAMETERS: list_head - Head of the state stack | ||
123 | * | ||
124 | * RETURN: The popped state object | ||
125 | * | ||
126 | * DESCRIPTION: Pop a state object from a state stack | ||
127 | * | ||
128 | ******************************************************************************/ | ||
129 | |||
130 | union acpi_generic_state * | ||
131 | acpi_ut_pop_generic_state ( | ||
132 | union acpi_generic_state **list_head) | ||
133 | { | ||
134 | union acpi_generic_state *state; | ||
135 | |||
136 | |||
137 | ACPI_FUNCTION_TRACE ("ut_pop_generic_state"); | ||
138 | |||
139 | |||
140 | /* Remove the state object at the head of the list (stack) */ | ||
141 | |||
142 | state = *list_head; | ||
143 | if (state) { | ||
144 | /* Update the list head */ | ||
145 | |||
146 | *list_head = state->common.next; | ||
147 | } | ||
148 | |||
149 | return_PTR (state); | ||
150 | } | ||
151 | |||
152 | |||
153 | /******************************************************************************* | ||
154 | * | ||
155 | * FUNCTION: acpi_ut_create_generic_state | ||
156 | * | ||
157 | * PARAMETERS: None | ||
158 | * | ||
159 | * RETURN: The new state object. NULL on failure. | ||
160 | * | ||
161 | * DESCRIPTION: Create a generic state object. Attempt to obtain one from | ||
162 | * the global state cache; If none available, create a new one. | ||
163 | * | ||
164 | ******************************************************************************/ | ||
165 | |||
166 | union acpi_generic_state * | ||
167 | acpi_ut_create_generic_state ( | ||
168 | void) | ||
169 | { | ||
170 | union acpi_generic_state *state; | ||
171 | |||
172 | |||
173 | ACPI_FUNCTION_ENTRY (); | ||
174 | |||
175 | |||
176 | state = acpi_os_acquire_object (acpi_gbl_state_cache); | ||
177 | if (state) { | ||
178 | /* Initialize */ | ||
179 | memset(state, 0, sizeof(union acpi_generic_state)); | ||
180 | state->common.data_type = ACPI_DESC_TYPE_STATE; | ||
181 | } | ||
182 | |||
183 | return (state); | ||
184 | } | ||
185 | |||
186 | |||
187 | /******************************************************************************* | ||
188 | * | ||
189 | * FUNCTION: acpi_ut_create_thread_state | ||
190 | * | ||
191 | * PARAMETERS: None | ||
192 | * | ||
193 | * RETURN: New Thread State. NULL on failure | ||
194 | * | ||
195 | * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used | ||
196 | * to track per-thread info during method execution | ||
197 | * | ||
198 | ******************************************************************************/ | ||
199 | |||
200 | struct acpi_thread_state * | ||
201 | acpi_ut_create_thread_state ( | ||
202 | void) | ||
203 | { | ||
204 | union acpi_generic_state *state; | ||
205 | |||
206 | |||
207 | ACPI_FUNCTION_TRACE ("ut_create_thread_state"); | ||
208 | |||
209 | |||
210 | /* Create the generic state object */ | ||
211 | |||
212 | state = acpi_ut_create_generic_state (); | ||
213 | if (!state) { | ||
214 | return_PTR (NULL); | ||
215 | } | ||
216 | |||
217 | /* Init fields specific to the update struct */ | ||
218 | |||
219 | state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD; | ||
220 | state->thread.thread_id = acpi_os_get_thread_id (); | ||
221 | |||
222 | return_PTR ((struct acpi_thread_state *) state); | ||
223 | } | ||
224 | |||
225 | |||
226 | /******************************************************************************* | ||
227 | * | ||
228 | * FUNCTION: acpi_ut_create_update_state | ||
229 | * | ||
230 | * PARAMETERS: Object - Initial Object to be installed in the state | ||
231 | * Action - Update action to be performed | ||
232 | * | ||
233 | * RETURN: New state object, null on failure | ||
234 | * | ||
235 | * DESCRIPTION: Create an "Update State" - a flavor of the generic state used | ||
236 | * to update reference counts and delete complex objects such | ||
237 | * as packages. | ||
238 | * | ||
239 | ******************************************************************************/ | ||
240 | |||
241 | union acpi_generic_state * | ||
242 | acpi_ut_create_update_state ( | ||
243 | union acpi_operand_object *object, | ||
244 | u16 action) | ||
245 | { | ||
246 | union acpi_generic_state *state; | ||
247 | |||
248 | |||
249 | ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object); | ||
250 | |||
251 | |||
252 | /* Create the generic state object */ | ||
253 | |||
254 | state = acpi_ut_create_generic_state (); | ||
255 | if (!state) { | ||
256 | return_PTR (NULL); | ||
257 | } | ||
258 | |||
259 | /* Init fields specific to the update struct */ | ||
260 | |||
261 | state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE; | ||
262 | state->update.object = object; | ||
263 | state->update.value = action; | ||
264 | |||
265 | return_PTR (state); | ||
266 | } | ||
267 | |||
268 | |||
269 | /******************************************************************************* | ||
270 | * | ||
271 | * FUNCTION: acpi_ut_create_pkg_state | ||
272 | * | ||
273 | * PARAMETERS: Object - Initial Object to be installed in the state | ||
274 | * Action - Update action to be performed | ||
275 | * | ||
276 | * RETURN: New state object, null on failure | ||
277 | * | ||
278 | * DESCRIPTION: Create a "Package State" | ||
279 | * | ||
280 | ******************************************************************************/ | ||
281 | |||
282 | union acpi_generic_state * | ||
283 | acpi_ut_create_pkg_state ( | ||
284 | void *internal_object, | ||
285 | void *external_object, | ||
286 | u16 index) | ||
287 | { | ||
288 | union acpi_generic_state *state; | ||
289 | |||
290 | |||
291 | ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object); | ||
292 | |||
293 | |||
294 | /* Create the generic state object */ | ||
295 | |||
296 | state = acpi_ut_create_generic_state (); | ||
297 | if (!state) { | ||
298 | return_PTR (NULL); | ||
299 | } | ||
300 | |||
301 | /* Init fields specific to the update struct */ | ||
302 | |||
303 | state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE; | ||
304 | state->pkg.source_object = (union acpi_operand_object *) internal_object; | ||
305 | state->pkg.dest_object = external_object; | ||
306 | state->pkg.index = index; | ||
307 | state->pkg.num_packages = 1; | ||
308 | |||
309 | return_PTR (state); | ||
310 | } | ||
311 | |||
312 | |||
313 | /******************************************************************************* | ||
314 | * | ||
315 | * FUNCTION: acpi_ut_create_control_state | ||
316 | * | ||
317 | * PARAMETERS: None | ||
318 | * | ||
319 | * RETURN: New state object, null on failure | ||
320 | * | ||
321 | * DESCRIPTION: Create a "Control State" - a flavor of the generic state used | ||
322 | * to support nested IF/WHILE constructs in the AML. | ||
323 | * | ||
324 | ******************************************************************************/ | ||
325 | |||
326 | union acpi_generic_state * | ||
327 | acpi_ut_create_control_state ( | ||
328 | void) | ||
329 | { | ||
330 | union acpi_generic_state *state; | ||
331 | |||
332 | |||
333 | ACPI_FUNCTION_TRACE ("ut_create_control_state"); | ||
334 | |||
335 | |||
336 | /* Create the generic state object */ | ||
337 | |||
338 | state = acpi_ut_create_generic_state (); | ||
339 | if (!state) { | ||
340 | return_PTR (NULL); | ||
341 | } | ||
342 | |||
343 | /* Init fields specific to the control struct */ | ||
344 | |||
345 | state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL; | ||
346 | state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING; | ||
347 | |||
348 | return_PTR (state); | ||
349 | } | ||
350 | |||
351 | |||
352 | /******************************************************************************* | ||
353 | * | ||
354 | * FUNCTION: acpi_ut_delete_generic_state | ||
355 | * | ||
356 | * PARAMETERS: State - The state object to be deleted | ||
357 | * | ||
358 | * RETURN: None | ||
359 | * | ||
360 | * DESCRIPTION: Put a state object back into the global state cache. The object | ||
361 | * is not actually freed at this time. | ||
362 | * | ||
363 | ******************************************************************************/ | ||
364 | |||
365 | void | ||
366 | acpi_ut_delete_generic_state ( | ||
367 | union acpi_generic_state *state) | ||
368 | { | ||
369 | ACPI_FUNCTION_TRACE ("ut_delete_generic_state"); | ||
370 | |||
371 | |||
372 | (void) acpi_os_release_object (acpi_gbl_state_cache, state); | ||
373 | return_VOID; | ||
374 | } | ||
375 | |||
376 | |||