1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: utstate - state object support procedures
6 ******************************************************************************/
11 #define _COMPONENT ACPI_UTILITIES
12 ACPI_MODULE_NAME("utstate")
14 /*******************************************************************************
16 * FUNCTION: acpi_ut_push_generic_state
18 * PARAMETERS: list_head - Head of the state stack
19 * state - State object to push
23 * DESCRIPTION: Push a state object onto a state stack
25 ******************************************************************************/
27 acpi_ut_push_generic_state(union acpi_generic_state
**list_head
,
28 union acpi_generic_state
*state
)
30 ACPI_FUNCTION_ENTRY();
32 /* Push the state object onto the front of the list (stack) */
34 state
->common
.next
= *list_head
;
39 /*******************************************************************************
41 * FUNCTION: acpi_ut_pop_generic_state
43 * PARAMETERS: list_head - Head of the state stack
45 * RETURN: The popped state object
47 * DESCRIPTION: Pop a state object from a state stack
49 ******************************************************************************/
51 union acpi_generic_state
*acpi_ut_pop_generic_state(union acpi_generic_state
54 union acpi_generic_state
*state
;
56 ACPI_FUNCTION_ENTRY();
58 /* Remove the state object at the head of the list (stack) */
63 /* Update the list head */
65 *list_head
= state
->common
.next
;
71 /*******************************************************************************
73 * FUNCTION: acpi_ut_create_generic_state
77 * RETURN: The new state object. NULL on failure.
79 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
80 * the global state cache; If none available, create a new one.
82 ******************************************************************************/
84 union acpi_generic_state
*acpi_ut_create_generic_state(void)
86 union acpi_generic_state
*state
;
88 ACPI_FUNCTION_ENTRY();
90 state
= acpi_os_acquire_object(acpi_gbl_state_cache
);
94 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE
;
100 /*******************************************************************************
102 * FUNCTION: acpi_ut_create_thread_state
106 * RETURN: New Thread State. NULL on failure
108 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
109 * to track per-thread info during method execution
111 ******************************************************************************/
113 struct acpi_thread_state
*acpi_ut_create_thread_state(void)
115 union acpi_generic_state
*state
;
117 ACPI_FUNCTION_ENTRY();
119 /* Create the generic state object */
121 state
= acpi_ut_create_generic_state();
126 /* Init fields specific to the update struct */
128 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE_THREAD
;
129 state
->thread
.thread_id
= acpi_os_get_thread_id();
131 /* Check for invalid thread ID - zero is very bad, it will break things */
133 if (!state
->thread
.thread_id
) {
134 ACPI_ERROR((AE_INFO
, "Invalid zero ID from AcpiOsGetThreadId"));
135 state
->thread
.thread_id
= (acpi_thread_id
) 1;
138 return ((struct acpi_thread_state
*)state
);
141 /*******************************************************************************
143 * FUNCTION: acpi_ut_create_update_state
145 * PARAMETERS: object - Initial Object to be installed in the state
146 * action - Update action to be performed
148 * RETURN: New state object, null on failure
150 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
151 * to update reference counts and delete complex objects such
154 ******************************************************************************/
156 union acpi_generic_state
*acpi_ut_create_update_state(union acpi_operand_object
159 union acpi_generic_state
*state
;
161 ACPI_FUNCTION_ENTRY();
163 /* Create the generic state object */
165 state
= acpi_ut_create_generic_state();
170 /* Init fields specific to the update struct */
172 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE_UPDATE
;
173 state
->update
.object
= object
;
174 state
->update
.value
= action
;
178 /*******************************************************************************
180 * FUNCTION: acpi_ut_create_pkg_state
182 * PARAMETERS: object - Initial Object to be installed in the state
183 * action - Update action to be performed
185 * RETURN: New state object, null on failure
187 * DESCRIPTION: Create a "Package State"
189 ******************************************************************************/
191 union acpi_generic_state
*acpi_ut_create_pkg_state(void *internal_object
,
192 void *external_object
,
195 union acpi_generic_state
*state
;
197 ACPI_FUNCTION_ENTRY();
199 /* Create the generic state object */
201 state
= acpi_ut_create_generic_state();
206 /* Init fields specific to the update struct */
208 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE_PACKAGE
;
209 state
->pkg
.source_object
= (union acpi_operand_object
*)internal_object
;
210 state
->pkg
.dest_object
= external_object
;
211 state
->pkg
.index
= index
;
212 state
->pkg
.num_packages
= 1;
217 /*******************************************************************************
219 * FUNCTION: acpi_ut_create_control_state
223 * RETURN: New state object, null on failure
225 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
226 * to support nested IF/WHILE constructs in the AML.
228 ******************************************************************************/
230 union acpi_generic_state
*acpi_ut_create_control_state(void)
232 union acpi_generic_state
*state
;
234 ACPI_FUNCTION_ENTRY();
236 /* Create the generic state object */
238 state
= acpi_ut_create_generic_state();
243 /* Init fields specific to the control struct */
245 state
->common
.descriptor_type
= ACPI_DESC_TYPE_STATE_CONTROL
;
246 state
->common
.state
= ACPI_CONTROL_CONDITIONAL_EXECUTING
;
251 /*******************************************************************************
253 * FUNCTION: acpi_ut_delete_generic_state
255 * PARAMETERS: state - The state object to be deleted
259 * DESCRIPTION: Release a state object to the state cache. NULL state objects
262 ******************************************************************************/
264 void acpi_ut_delete_generic_state(union acpi_generic_state
*state
)
266 ACPI_FUNCTION_ENTRY();
268 /* Ignore null state */
271 (void)acpi_os_release_object(acpi_gbl_state_cache
, state
);