1 /*******************************************************************************
3 * Module Name: utstate - state object support procedures
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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
61 * DESCRIPTION: Create a new state and push it
63 ******************************************************************************/
66 acpi_ut_create_pkg_state_and_push (
67 void *internal_object
,
68 void *external_object
,
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
);
80 return (AE_NO_MEMORY
);
83 acpi_ut_push_generic_state (state_list
, state
);
88 /*******************************************************************************
90 * FUNCTION: acpi_ut_push_generic_state
92 * PARAMETERS: list_head - Head of the state stack
93 * State - State object to push
97 * DESCRIPTION: Push a state object onto a state stack
99 ******************************************************************************/
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
;
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) */
144 /* Update the list head */
146 *list_head
= state
->common
.next
;
153 /*******************************************************************************
155 * FUNCTION: acpi_ut_create_generic_state
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 (
170 union acpi_generic_state
*state
;
173 ACPI_FUNCTION_ENTRY ();
176 state
= acpi_os_acquire_object (acpi_gbl_state_cache
);
179 memset(state
, 0, sizeof(union acpi_generic_state
));
180 state
->common
.data_type
= ACPI_DESC_TYPE_STATE
;
187 /*******************************************************************************
189 * FUNCTION: acpi_ut_create_thread_state
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 (
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 ();
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
239 ******************************************************************************/
241 union acpi_generic_state
*
242 acpi_ut_create_update_state (
243 union acpi_operand_object
*object
,
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 ();
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
;
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
,
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 ();
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;
313 /*******************************************************************************
315 * FUNCTION: acpi_ut_create_control_state
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 (
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 ();
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
;
352 /*******************************************************************************
354 * FUNCTION: acpi_ut_delete_generic_state
356 * PARAMETERS: State - The state object to be deleted
360 * DESCRIPTION: Put a state object back into the global state cache. The object
361 * is not actually freed at this time.
363 ******************************************************************************/
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
);