1 /*******************************************************************************
3 * Module Name: utstate - state object support procedures
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
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.
44 #include <acpi/acpi.h>
47 #define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME("utstate")
50 /*******************************************************************************
52 * FUNCTION: acpi_ut_create_pkg_state_and_push
54 * PARAMETERS: object - Object to be added to the new state
55 * action - Increment/Decrement
56 * state_list - List the state will be added to
60 * DESCRIPTION: Create a new state and push it
62 ******************************************************************************/
64 acpi_ut_create_pkg_state_and_push(void *internal_object
,
65 void *external_object
,
67 union acpi_generic_state
**state_list
)
69 union acpi_generic_state
*state
;
71 ACPI_FUNCTION_ENTRY();
74 acpi_ut_create_pkg_state(internal_object
, external_object
, index
);
76 return (AE_NO_MEMORY
);
79 acpi_ut_push_generic_state(state_list
, state
);
83 /*******************************************************************************
85 * FUNCTION: acpi_ut_push_generic_state
87 * PARAMETERS: list_head - Head of the state stack
88 * state - State object to push
92 * DESCRIPTION: Push a state object onto a state stack
94 ******************************************************************************/
97 acpi_ut_push_generic_state(union acpi_generic_state
**list_head
,
98 union acpi_generic_state
*state
)
100 ACPI_FUNCTION_ENTRY();
102 /* Push the state object onto the front of the list (stack) */
104 state
->common
.next
= *list_head
;
109 /*******************************************************************************
111 * FUNCTION: acpi_ut_pop_generic_state
113 * PARAMETERS: list_head - Head of the state stack
115 * RETURN: The popped state object
117 * DESCRIPTION: Pop a state object from a state stack
119 ******************************************************************************/
121 union acpi_generic_state
*acpi_ut_pop_generic_state(union acpi_generic_state
124 union acpi_generic_state
*state
;
126 ACPI_FUNCTION_ENTRY();
128 /* Remove the state object at the head of the list (stack) */
133 /* Update the list head */
135 *list_head
= state
->common
.next
;
141 /*******************************************************************************
143 * FUNCTION: acpi_ut_create_generic_state
147 * RETURN: The new state object. NULL on failure.
149 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
150 * the global state cache; If none available, create a new one.
152 ******************************************************************************/
154 union acpi_generic_state
*acpi_ut_create_generic_state(void)
156 union acpi_generic_state
*state
;
158 ACPI_FUNCTION_ENTRY();
160 state
= acpi_os_acquire_object(acpi_gbl_state_cache
);
164 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE
;
170 /*******************************************************************************
172 * FUNCTION: acpi_ut_create_thread_state
176 * RETURN: New Thread State. NULL on failure
178 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
179 * to track per-thread info during method execution
181 ******************************************************************************/
183 struct acpi_thread_state
*acpi_ut_create_thread_state(void)
185 union acpi_generic_state
*state
;
187 ACPI_FUNCTION_ENTRY();
189 /* Create the generic state object */
191 state
= acpi_ut_create_generic_state();
196 /* Init fields specific to the update struct */
198 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE_THREAD
;
199 state
->thread
.thread_id
= acpi_os_get_thread_id();
201 /* Check for invalid thread ID - zero is very bad, it will break things */
203 if (!state
->thread
.thread_id
) {
204 ACPI_ERROR((AE_INFO
, "Invalid zero ID from AcpiOsGetThreadId"));
205 state
->thread
.thread_id
= (acpi_thread_id
) 1;
208 return ((struct acpi_thread_state
*)state
);
211 /*******************************************************************************
213 * FUNCTION: acpi_ut_create_update_state
215 * PARAMETERS: object - Initial Object to be installed in the state
216 * action - Update action to be performed
218 * RETURN: New state object, null on failure
220 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
221 * to update reference counts and delete complex objects such
224 ******************************************************************************/
226 union acpi_generic_state
*acpi_ut_create_update_state(union acpi_operand_object
229 union acpi_generic_state
*state
;
231 ACPI_FUNCTION_ENTRY();
233 /* Create the generic state object */
235 state
= acpi_ut_create_generic_state();
240 /* Init fields specific to the update struct */
242 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE_UPDATE
;
243 state
->update
.object
= object
;
244 state
->update
.value
= action
;
248 /*******************************************************************************
250 * FUNCTION: acpi_ut_create_pkg_state
252 * PARAMETERS: object - Initial Object to be installed in the state
253 * action - Update action to be performed
255 * RETURN: New state object, null on failure
257 * DESCRIPTION: Create a "Package State"
259 ******************************************************************************/
261 union acpi_generic_state
*acpi_ut_create_pkg_state(void *internal_object
,
262 void *external_object
,
265 union acpi_generic_state
*state
;
267 ACPI_FUNCTION_ENTRY();
269 /* Create the generic state object */
271 state
= acpi_ut_create_generic_state();
276 /* Init fields specific to the update struct */
278 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE_PACKAGE
;
279 state
->pkg
.source_object
= (union acpi_operand_object
*)internal_object
;
280 state
->pkg
.dest_object
= external_object
;
281 state
->pkg
.index
= index
;
282 state
->pkg
.num_packages
= 1;
286 /*******************************************************************************
288 * FUNCTION: acpi_ut_create_control_state
292 * RETURN: New state object, null on failure
294 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
295 * to support nested IF/WHILE constructs in the AML.
297 ******************************************************************************/
299 union acpi_generic_state
*acpi_ut_create_control_state(void)
301 union acpi_generic_state
*state
;
303 ACPI_FUNCTION_ENTRY();
305 /* Create the generic state object */
307 state
= acpi_ut_create_generic_state();
312 /* Init fields specific to the control struct */
314 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE_CONTROL
;
315 state
->common
.state
= ACPI_CONTROL_CONDITIONAL_EXECUTING
;
319 /*******************************************************************************
321 * FUNCTION: acpi_ut_delete_generic_state
323 * PARAMETERS: state - The state object to be deleted
327 * DESCRIPTION: Release a state object to the state cache. NULL state objects
330 ******************************************************************************/
332 void acpi_ut_delete_generic_state(union acpi_generic_state
*state
)
334 ACPI_FUNCTION_ENTRY();
336 /* Ignore null state */
339 (void)acpi_os_release_object(acpi_gbl_state_cache
, state
);