ACPICA 20050708 from Bob Moore <robert.moore@intel.com>
[linux-2.6/verdex.git] / drivers / acpi / utilities / utstate.c
blob192e7ac95690d8794b13fab26c3d73f39238ac5f
1 /*******************************************************************************
3 * Module Name: utstate - state object support procedures
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>
47 #define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utstate")
51 /*******************************************************************************
53 * FUNCTION: acpi_ut_create_pkg_state_and_push
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
59 * RETURN: Status
61 * DESCRIPTION: Create a new state and push it
63 ******************************************************************************/
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)
72 union acpi_generic_state *state;
75 ACPI_FUNCTION_ENTRY ();
78 state = acpi_ut_create_pkg_state (internal_object, external_object, index);
79 if (!state) {
80 return (AE_NO_MEMORY);
83 acpi_ut_push_generic_state (state_list, state);
84 return (AE_OK);
88 /*******************************************************************************
90 * FUNCTION: acpi_ut_push_generic_state
92 * PARAMETERS: list_head - Head of the state stack
93 * State - State object to push
95 * RETURN: None
97 * DESCRIPTION: Push a state object onto a state stack
99 ******************************************************************************/
101 void
102 acpi_ut_push_generic_state (
103 union acpi_generic_state **list_head,
104 union acpi_generic_state *state)
106 ACPI_FUNCTION_TRACE ("ut_push_generic_state");
109 /* Push the state object onto the front of the list (stack) */
111 state->common.next = *list_head;
112 *list_head = state;
114 return_VOID;
118 /*******************************************************************************
120 * FUNCTION: acpi_ut_pop_generic_state
122 * PARAMETERS: list_head - Head of the state stack
124 * RETURN: The popped state object
126 * DESCRIPTION: Pop a state object from a state stack
128 ******************************************************************************/
130 union acpi_generic_state *
131 acpi_ut_pop_generic_state (
132 union acpi_generic_state **list_head)
134 union acpi_generic_state *state;
137 ACPI_FUNCTION_TRACE ("ut_pop_generic_state");
140 /* Remove the state object at the head of the list (stack) */
142 state = *list_head;
143 if (state) {
144 /* Update the list head */
146 *list_head = state->common.next;
149 return_PTR (state);
153 /*******************************************************************************
155 * FUNCTION: acpi_ut_create_generic_state
157 * PARAMETERS: None
159 * RETURN: The new state object. NULL on failure.
161 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
162 * the global state cache; If none available, create a new one.
164 ******************************************************************************/
166 union acpi_generic_state *
167 acpi_ut_create_generic_state (
168 void)
170 union acpi_generic_state *state;
173 ACPI_FUNCTION_ENTRY ();
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;
183 return (state);
187 /*******************************************************************************
189 * FUNCTION: acpi_ut_create_thread_state
191 * PARAMETERS: None
193 * RETURN: New Thread State. NULL on failure
195 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
196 * to track per-thread info during method execution
198 ******************************************************************************/
200 struct acpi_thread_state *
201 acpi_ut_create_thread_state (
202 void)
204 union acpi_generic_state *state;
207 ACPI_FUNCTION_TRACE ("ut_create_thread_state");
210 /* Create the generic state object */
212 state = acpi_ut_create_generic_state ();
213 if (!state) {
214 return_PTR (NULL);
217 /* Init fields specific to the update struct */
219 state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD;
220 state->thread.thread_id = acpi_os_get_thread_id ();
222 return_PTR ((struct acpi_thread_state *) state);
226 /*******************************************************************************
228 * FUNCTION: acpi_ut_create_update_state
230 * PARAMETERS: Object - Initial Object to be installed in the state
231 * Action - Update action to be performed
233 * RETURN: New state object, null on failure
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.
239 ******************************************************************************/
241 union acpi_generic_state *
242 acpi_ut_create_update_state (
243 union acpi_operand_object *object,
244 u16 action)
246 union acpi_generic_state *state;
249 ACPI_FUNCTION_TRACE_PTR ("ut_create_update_state", object);
252 /* Create the generic state object */
254 state = acpi_ut_create_generic_state ();
255 if (!state) {
256 return_PTR (NULL);
259 /* Init fields specific to the update struct */
261 state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE;
262 state->update.object = object;
263 state->update.value = action;
265 return_PTR (state);
269 /*******************************************************************************
271 * FUNCTION: acpi_ut_create_pkg_state
273 * PARAMETERS: Object - Initial Object to be installed in the state
274 * Action - Update action to be performed
276 * RETURN: New state object, null on failure
278 * DESCRIPTION: Create a "Package State"
280 ******************************************************************************/
282 union acpi_generic_state *
283 acpi_ut_create_pkg_state (
284 void *internal_object,
285 void *external_object,
286 u16 index)
288 union acpi_generic_state *state;
291 ACPI_FUNCTION_TRACE_PTR ("ut_create_pkg_state", internal_object);
294 /* Create the generic state object */
296 state = acpi_ut_create_generic_state ();
297 if (!state) {
298 return_PTR (NULL);
301 /* Init fields specific to the update struct */
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;
309 return_PTR (state);
313 /*******************************************************************************
315 * FUNCTION: acpi_ut_create_control_state
317 * PARAMETERS: None
319 * RETURN: New state object, null on failure
321 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
322 * to support nested IF/WHILE constructs in the AML.
324 ******************************************************************************/
326 union acpi_generic_state *
327 acpi_ut_create_control_state (
328 void)
330 union acpi_generic_state *state;
333 ACPI_FUNCTION_TRACE ("ut_create_control_state");
336 /* Create the generic state object */
338 state = acpi_ut_create_generic_state ();
339 if (!state) {
340 return_PTR (NULL);
343 /* Init fields specific to the control struct */
345 state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL;
346 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
348 return_PTR (state);
352 /*******************************************************************************
354 * FUNCTION: acpi_ut_delete_generic_state
356 * PARAMETERS: State - The state object to be deleted
358 * RETURN: None
360 * DESCRIPTION: Put a state object back into the global state cache. The object
361 * is not actually freed at this time.
363 ******************************************************************************/
365 void
366 acpi_ut_delete_generic_state (
367 union acpi_generic_state *state)
369 ACPI_FUNCTION_TRACE ("ut_delete_generic_state");
372 (void) acpi_os_release_object (acpi_gbl_state_cache, state);
373 return_VOID;