Linux 4.19.133
[linux/fpc-iii.git] / drivers / acpi / acpica / utstate.c
bloba2484556a6b5736c6cdacebcaa6477488fdd80cd
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: utstate - state object support procedures
6 ******************************************************************************/
8 #include <acpi/acpi.h>
9 #include "accommon.h"
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
21 * RETURN: None
23 * DESCRIPTION: Push a state object onto a state stack
25 ******************************************************************************/
26 void
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;
35 *list_head = state;
36 return;
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
52 **list_head)
54 union acpi_generic_state *state;
56 ACPI_FUNCTION_ENTRY();
58 /* Remove the state object at the head of the list (stack) */
60 state = *list_head;
61 if (state) {
63 /* Update the list head */
65 *list_head = state->common.next;
68 return (state);
71 /*******************************************************************************
73 * FUNCTION: acpi_ut_create_generic_state
75 * PARAMETERS: None
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);
91 if (state) {
93 /* Initialize */
94 state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
97 return (state);
100 /*******************************************************************************
102 * FUNCTION: acpi_ut_create_thread_state
104 * PARAMETERS: None
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();
122 if (!state) {
123 return (NULL);
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
152 * as packages.
154 ******************************************************************************/
156 union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
157 *object, u16 action)
159 union acpi_generic_state *state;
161 ACPI_FUNCTION_ENTRY();
163 /* Create the generic state object */
165 state = acpi_ut_create_generic_state();
166 if (!state) {
167 return (NULL);
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;
175 return (state);
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,
193 u32 index)
195 union acpi_generic_state *state;
197 ACPI_FUNCTION_ENTRY();
199 /* Create the generic state object */
201 state = acpi_ut_create_generic_state();
202 if (!state) {
203 return (NULL);
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;
214 return (state);
217 /*******************************************************************************
219 * FUNCTION: acpi_ut_create_control_state
221 * PARAMETERS: None
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();
239 if (!state) {
240 return (NULL);
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;
248 return (state);
251 /*******************************************************************************
253 * FUNCTION: acpi_ut_delete_generic_state
255 * PARAMETERS: state - The state object to be deleted
257 * RETURN: None
259 * DESCRIPTION: Release a state object to the state cache. NULL state objects
260 * are ignored.
262 ******************************************************************************/
264 void acpi_ut_delete_generic_state(union acpi_generic_state *state)
266 ACPI_FUNCTION_ENTRY();
268 /* Ignore null state */
270 if (state) {
271 (void)acpi_os_release_object(acpi_gbl_state_cache, state);
274 return;