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