blob: a2484556a6b5736c6cdacebcaa6477488fdd80cd [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Robert Moore73459f72005-06-24 00:00:00 -04002/*******************************************************************************
3 *
4 * Module Name: utstate - state object support procedures
5 *
6 ******************************************************************************/
7
Robert Moore73459f72005-06-24 00:00:00 -04008#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -05009#include "accommon.h"
Robert Moore73459f72005-06-24 00:00:00 -040010
11#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040012ACPI_MODULE_NAME("utstate")
Robert Moore73459f72005-06-24 00:00:00 -040013
14/*******************************************************************************
15 *
Robert Moore73459f72005-06-24 00:00:00 -040016 * FUNCTION: acpi_ut_push_generic_state
17 *
18 * PARAMETERS: list_head - Head of the state stack
Bob Mooreba494be2012-07-12 09:40:10 +080019 * state - State object to push
Robert Moore73459f72005-06-24 00:00:00 -040020 *
21 * RETURN: None
22 *
23 * DESCRIPTION: Push a state object onto a state stack
24 *
25 ******************************************************************************/
Robert Moore73459f72005-06-24 00:00:00 -040026void
Len Brown4be44fc2005-08-05 00:44:28 -040027acpi_ut_push_generic_state(union acpi_generic_state **list_head,
28 union acpi_generic_state *state)
Robert Moore73459f72005-06-24 00:00:00 -040029{
Bob Moore0e770b32012-12-19 05:37:59 +000030 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -040031
32 /* Push the state object onto the front of the list (stack) */
33
34 state->common.next = *list_head;
35 *list_head = state;
Bob Moore0e770b32012-12-19 05:37:59 +000036 return;
Robert Moore73459f72005-06-24 00:00:00 -040037}
38
Robert Moore73459f72005-06-24 00:00:00 -040039/*******************************************************************************
40 *
41 * FUNCTION: acpi_ut_pop_generic_state
42 *
43 * PARAMETERS: list_head - Head of the state stack
44 *
45 * RETURN: The popped state object
46 *
47 * DESCRIPTION: Pop a state object from a state stack
48 *
49 ******************************************************************************/
50
Len Brown4be44fc2005-08-05 00:44:28 -040051union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
52 **list_head)
Robert Moore73459f72005-06-24 00:00:00 -040053{
Len Brown4be44fc2005-08-05 00:44:28 -040054 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -040055
Bob Moore0e770b32012-12-19 05:37:59 +000056 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -040057
58 /* Remove the state object at the head of the list (stack) */
59
60 state = *list_head;
61 if (state) {
Bob Moore52fc0b02006-10-02 00:00:00 -040062
Robert Moore73459f72005-06-24 00:00:00 -040063 /* Update the list head */
64
65 *list_head = state->common.next;
66 }
67
Bob Moore0e770b32012-12-19 05:37:59 +000068 return (state);
Robert Moore73459f72005-06-24 00:00:00 -040069}
70
Robert Moore73459f72005-06-24 00:00:00 -040071/*******************************************************************************
72 *
73 * FUNCTION: acpi_ut_create_generic_state
74 *
75 * PARAMETERS: None
76 *
77 * RETURN: The new state object. NULL on failure.
78 *
Bob Moore73a30902012-10-31 02:26:55 +000079 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
Robert Moore73459f72005-06-24 00:00:00 -040080 * the global state cache; If none available, create a new one.
81 *
82 ******************************************************************************/
83
Len Brown4be44fc2005-08-05 00:44:28 -040084union acpi_generic_state *acpi_ut_create_generic_state(void)
Robert Moore73459f72005-06-24 00:00:00 -040085{
Len Brown4be44fc2005-08-05 00:44:28 -040086 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -040087
Len Brown4be44fc2005-08-05 00:44:28 -040088 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -040089
Len Brown4be44fc2005-08-05 00:44:28 -040090 state = acpi_os_acquire_object(acpi_gbl_state_cache);
Robert Moore73459f72005-06-24 00:00:00 -040091 if (state) {
Bob Moore52fc0b02006-10-02 00:00:00 -040092
Robert Moore73459f72005-06-24 00:00:00 -040093 /* Initialize */
Bob Moore616861242006-03-17 16:44:00 -050094 state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
Robert Moore73459f72005-06-24 00:00:00 -040095 }
96
97 return (state);
98}
99
Robert Moore73459f72005-06-24 00:00:00 -0400100/*******************************************************************************
101 *
102 * FUNCTION: acpi_ut_create_thread_state
103 *
104 * PARAMETERS: None
105 *
106 * RETURN: New Thread State. NULL on failure
107 *
108 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
109 * to track per-thread info during method execution
110 *
111 ******************************************************************************/
112
Len Brown4be44fc2005-08-05 00:44:28 -0400113struct acpi_thread_state *acpi_ut_create_thread_state(void)
Robert Moore73459f72005-06-24 00:00:00 -0400114{
Len Brown4be44fc2005-08-05 00:44:28 -0400115 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400116
Bob Moore0e770b32012-12-19 05:37:59 +0000117 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400118
119 /* Create the generic state object */
120
Len Brown4be44fc2005-08-05 00:44:28 -0400121 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400122 if (!state) {
Bob Moore0e770b32012-12-19 05:37:59 +0000123 return (NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400124 }
125
126 /* Init fields specific to the update struct */
127
Bob Moore616861242006-03-17 16:44:00 -0500128 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
Len Brown4be44fc2005-08-05 00:44:28 -0400129 state->thread.thread_id = acpi_os_get_thread_id();
Robert Moore73459f72005-06-24 00:00:00 -0400130
Bob Mooref6dd9222006-07-07 20:44:38 -0400131 /* Check for invalid thread ID - zero is very bad, it will break things */
132
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;
136 }
137
Bob Moore0e770b32012-12-19 05:37:59 +0000138 return ((struct acpi_thread_state *)state);
Robert Moore73459f72005-06-24 00:00:00 -0400139}
140
Robert Moore73459f72005-06-24 00:00:00 -0400141/*******************************************************************************
142 *
143 * FUNCTION: acpi_ut_create_update_state
144 *
Bob Mooreba494be2012-07-12 09:40:10 +0800145 * PARAMETERS: object - Initial Object to be installed in the state
146 * action - Update action to be performed
Robert Moore73459f72005-06-24 00:00:00 -0400147 *
148 * RETURN: New state object, null on failure
149 *
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.
153 *
154 ******************************************************************************/
155
Len Brown4be44fc2005-08-05 00:44:28 -0400156union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
157 *object, u16 action)
Robert Moore73459f72005-06-24 00:00:00 -0400158{
Len Brown4be44fc2005-08-05 00:44:28 -0400159 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400160
Bob Moore0e770b32012-12-19 05:37:59 +0000161 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400162
163 /* Create the generic state object */
164
Len Brown4be44fc2005-08-05 00:44:28 -0400165 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400166 if (!state) {
Bob Moore0e770b32012-12-19 05:37:59 +0000167 return (NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400168 }
169
170 /* Init fields specific to the update struct */
171
Bob Moore616861242006-03-17 16:44:00 -0500172 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
Robert Moore73459f72005-06-24 00:00:00 -0400173 state->update.object = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400174 state->update.value = action;
Bob Moore0e770b32012-12-19 05:37:59 +0000175 return (state);
Robert Moore73459f72005-06-24 00:00:00 -0400176}
177
Robert Moore73459f72005-06-24 00:00:00 -0400178/*******************************************************************************
179 *
180 * FUNCTION: acpi_ut_create_pkg_state
181 *
Bob Mooreba494be2012-07-12 09:40:10 +0800182 * PARAMETERS: object - Initial Object to be installed in the state
183 * action - Update action to be performed
Robert Moore73459f72005-06-24 00:00:00 -0400184 *
185 * RETURN: New state object, null on failure
186 *
187 * DESCRIPTION: Create a "Package State"
188 *
189 ******************************************************************************/
190
Len Brown4be44fc2005-08-05 00:44:28 -0400191union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
192 void *external_object,
Bob Moorea62a7112017-08-03 14:27:22 +0800193 u32 index)
Robert Moore73459f72005-06-24 00:00:00 -0400194{
Len Brown4be44fc2005-08-05 00:44:28 -0400195 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400196
Bob Moore0e770b32012-12-19 05:37:59 +0000197 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400198
199 /* Create the generic state object */
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400202 if (!state) {
Bob Moore0e770b32012-12-19 05:37:59 +0000203 return (NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400204 }
205
206 /* Init fields specific to the update struct */
207
Bob Moore616861242006-03-17 16:44:00 -0500208 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
Len Brown4be44fc2005-08-05 00:44:28 -0400209 state->pkg.source_object = (union acpi_operand_object *)internal_object;
210 state->pkg.dest_object = external_object;
211 state->pkg.index = index;
Robert Moore73459f72005-06-24 00:00:00 -0400212 state->pkg.num_packages = 1;
Bob Moore1fad8732015-12-29 13:54:36 +0800213
Bob Moore0e770b32012-12-19 05:37:59 +0000214 return (state);
Robert Moore73459f72005-06-24 00:00:00 -0400215}
216
Robert Moore73459f72005-06-24 00:00:00 -0400217/*******************************************************************************
218 *
219 * FUNCTION: acpi_ut_create_control_state
220 *
221 * PARAMETERS: None
222 *
223 * RETURN: New state object, null on failure
224 *
225 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
226 * to support nested IF/WHILE constructs in the AML.
227 *
228 ******************************************************************************/
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230union acpi_generic_state *acpi_ut_create_control_state(void)
Robert Moore73459f72005-06-24 00:00:00 -0400231{
Len Brown4be44fc2005-08-05 00:44:28 -0400232 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400233
Bob Moore0e770b32012-12-19 05:37:59 +0000234 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400235
236 /* Create the generic state object */
237
Len Brown4be44fc2005-08-05 00:44:28 -0400238 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400239 if (!state) {
Bob Moore0e770b32012-12-19 05:37:59 +0000240 return (NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400241 }
242
243 /* Init fields specific to the control struct */
244
Bob Moore616861242006-03-17 16:44:00 -0500245 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
Len Brown4be44fc2005-08-05 00:44:28 -0400246 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
Bob Moore1fad8732015-12-29 13:54:36 +0800247
Bob Moore0e770b32012-12-19 05:37:59 +0000248 return (state);
Robert Moore73459f72005-06-24 00:00:00 -0400249}
250
Robert Moore73459f72005-06-24 00:00:00 -0400251/*******************************************************************************
252 *
253 * FUNCTION: acpi_ut_delete_generic_state
254 *
Bob Mooreba494be2012-07-12 09:40:10 +0800255 * PARAMETERS: state - The state object to be deleted
Robert Moore73459f72005-06-24 00:00:00 -0400256 *
257 * RETURN: None
258 *
Bob Moore793c2382006-03-31 00:00:00 -0500259 * DESCRIPTION: Release a state object to the state cache. NULL state objects
260 * are ignored.
Robert Moore73459f72005-06-24 00:00:00 -0400261 *
262 ******************************************************************************/
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264void acpi_ut_delete_generic_state(union acpi_generic_state *state)
Robert Moore73459f72005-06-24 00:00:00 -0400265{
Bob Moore0e770b32012-12-19 05:37:59 +0000266 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400267
Bob Moore793c2382006-03-31 00:00:00 -0500268 /* Ignore null state */
269
270 if (state) {
271 (void)acpi_os_release_object(acpi_gbl_state_cache, state);
272 }
Bob Moore1fad8732015-12-29 13:54:36 +0800273
Bob Moore0e770b32012-12-19 05:37:59 +0000274 return;
Robert Moore73459f72005-06-24 00:00:00 -0400275}