blob: 26a0c23c3f4b1b29143e315eec2d98888860f371 [file] [log] [blame]
Robert Moore73459f72005-06-24 00:00:00 -04001/*******************************************************************************
2 *
3 * Module Name: utstate - state object support procedures
4 *
5 ******************************************************************************/
6
7/*
Bob Moore77848132012-01-12 13:27:23 +08008 * Copyright (C) 2000 - 2012, Intel Corp.
Robert Moore73459f72005-06-24 00:00:00 -04009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
Robert Moore73459f72005-06-24 00:00:00 -040044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
Robert Moore73459f72005-06-24 00:00:00 -040046
47#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("utstate")
Robert Moore73459f72005-06-24 00:00:00 -040049
50/*******************************************************************************
51 *
52 * FUNCTION: acpi_ut_create_pkg_state_and_push
53 *
Bob Mooreba494be2012-07-12 09:40:10 +080054 * PARAMETERS: object - Object to be added to the new state
55 * action - Increment/Decrement
Robert Moore73459f72005-06-24 00:00:00 -040056 * state_list - List the state will be added to
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: Create a new state and push it
61 *
62 ******************************************************************************/
Robert Moore73459f72005-06-24 00:00:00 -040063acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040064acpi_ut_create_pkg_state_and_push(void *internal_object,
65 void *external_object,
66 u16 index,
Bob Moore96db2552005-11-02 00:00:00 -050067 union acpi_generic_state **state_list)
Robert Moore73459f72005-06-24 00:00:00 -040068{
Len Brown4be44fc2005-08-05 00:44:28 -040069 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -040070
Len Brown4be44fc2005-08-05 00:44:28 -040071 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -040072
Len Brown4be44fc2005-08-05 00:44:28 -040073 state =
74 acpi_ut_create_pkg_state(internal_object, external_object, index);
Robert Moore73459f72005-06-24 00:00:00 -040075 if (!state) {
76 return (AE_NO_MEMORY);
77 }
78
Len Brown4be44fc2005-08-05 00:44:28 -040079 acpi_ut_push_generic_state(state_list, state);
Robert Moore73459f72005-06-24 00:00:00 -040080 return (AE_OK);
81}
82
Robert Moore73459f72005-06-24 00:00:00 -040083/*******************************************************************************
84 *
85 * FUNCTION: acpi_ut_push_generic_state
86 *
87 * PARAMETERS: list_head - Head of the state stack
Bob Mooreba494be2012-07-12 09:40:10 +080088 * state - State object to push
Robert Moore73459f72005-06-24 00:00:00 -040089 *
90 * RETURN: None
91 *
92 * DESCRIPTION: Push a state object onto a state stack
93 *
94 ******************************************************************************/
95
96void
Len Brown4be44fc2005-08-05 00:44:28 -040097acpi_ut_push_generic_state(union acpi_generic_state **list_head,
98 union acpi_generic_state *state)
Robert Moore73459f72005-06-24 00:00:00 -040099{
Bob Moore0e770b32012-12-19 05:37:59 +0000100 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400101
102 /* Push the state object onto the front of the list (stack) */
103
104 state->common.next = *list_head;
105 *list_head = state;
Bob Moore0e770b32012-12-19 05:37:59 +0000106 return;
Robert Moore73459f72005-06-24 00:00:00 -0400107}
108
Robert Moore73459f72005-06-24 00:00:00 -0400109/*******************************************************************************
110 *
111 * FUNCTION: acpi_ut_pop_generic_state
112 *
113 * PARAMETERS: list_head - Head of the state stack
114 *
115 * RETURN: The popped state object
116 *
117 * DESCRIPTION: Pop a state object from a state stack
118 *
119 ******************************************************************************/
120
Len Brown4be44fc2005-08-05 00:44:28 -0400121union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
122 **list_head)
Robert Moore73459f72005-06-24 00:00:00 -0400123{
Len Brown4be44fc2005-08-05 00:44:28 -0400124 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400125
Bob Moore0e770b32012-12-19 05:37:59 +0000126 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400127
128 /* Remove the state object at the head of the list (stack) */
129
130 state = *list_head;
131 if (state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400132
Robert Moore73459f72005-06-24 00:00:00 -0400133 /* Update the list head */
134
135 *list_head = state->common.next;
136 }
137
Bob Moore0e770b32012-12-19 05:37:59 +0000138 return (state);
Robert Moore73459f72005-06-24 00:00:00 -0400139}
140
Robert Moore73459f72005-06-24 00:00:00 -0400141/*******************************************************************************
142 *
143 * FUNCTION: acpi_ut_create_generic_state
144 *
145 * PARAMETERS: None
146 *
147 * RETURN: The new state object. NULL on failure.
148 *
Bob Moore73a30902012-10-31 02:26:55 +0000149 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
Robert Moore73459f72005-06-24 00:00:00 -0400150 * the global state cache; If none available, create a new one.
151 *
152 ******************************************************************************/
153
Len Brown4be44fc2005-08-05 00:44:28 -0400154union acpi_generic_state *acpi_ut_create_generic_state(void)
Robert Moore73459f72005-06-24 00:00:00 -0400155{
Len Brown4be44fc2005-08-05 00:44:28 -0400156 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400159
Len Brown4be44fc2005-08-05 00:44:28 -0400160 state = acpi_os_acquire_object(acpi_gbl_state_cache);
Robert Moore73459f72005-06-24 00:00:00 -0400161 if (state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400162
Robert Moore73459f72005-06-24 00:00:00 -0400163 /* Initialize */
164 memset(state, 0, sizeof(union acpi_generic_state));
Bob Moore616861242006-03-17 16:44:00 -0500165 state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
Robert Moore73459f72005-06-24 00:00:00 -0400166 }
167
168 return (state);
169}
170
Robert Moore73459f72005-06-24 00:00:00 -0400171/*******************************************************************************
172 *
173 * FUNCTION: acpi_ut_create_thread_state
174 *
175 * PARAMETERS: None
176 *
177 * RETURN: New Thread State. NULL on failure
178 *
179 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
180 * to track per-thread info during method execution
181 *
182 ******************************************************************************/
183
Len Brown4be44fc2005-08-05 00:44:28 -0400184struct acpi_thread_state *acpi_ut_create_thread_state(void)
Robert Moore73459f72005-06-24 00:00:00 -0400185{
Len Brown4be44fc2005-08-05 00:44:28 -0400186 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400187
Bob Moore0e770b32012-12-19 05:37:59 +0000188 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400189
190 /* Create the generic state object */
191
Len Brown4be44fc2005-08-05 00:44:28 -0400192 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400193 if (!state) {
Bob Moore0e770b32012-12-19 05:37:59 +0000194 return (NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400195 }
196
197 /* Init fields specific to the update struct */
198
Bob Moore616861242006-03-17 16:44:00 -0500199 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
Len Brown4be44fc2005-08-05 00:44:28 -0400200 state->thread.thread_id = acpi_os_get_thread_id();
Robert Moore73459f72005-06-24 00:00:00 -0400201
Bob Mooref6dd9222006-07-07 20:44:38 -0400202 /* Check for invalid thread ID - zero is very bad, it will break things */
203
204 if (!state->thread.thread_id) {
205 ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
206 state->thread.thread_id = (acpi_thread_id) 1;
207 }
208
Bob Moore0e770b32012-12-19 05:37:59 +0000209 return ((struct acpi_thread_state *)state);
Robert Moore73459f72005-06-24 00:00:00 -0400210}
211
Robert Moore73459f72005-06-24 00:00:00 -0400212/*******************************************************************************
213 *
214 * FUNCTION: acpi_ut_create_update_state
215 *
Bob Mooreba494be2012-07-12 09:40:10 +0800216 * PARAMETERS: object - Initial Object to be installed in the state
217 * action - Update action to be performed
Robert Moore73459f72005-06-24 00:00:00 -0400218 *
219 * RETURN: New state object, null on failure
220 *
221 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
222 * to update reference counts and delete complex objects such
223 * as packages.
224 *
225 ******************************************************************************/
226
Len Brown4be44fc2005-08-05 00:44:28 -0400227union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
228 *object, u16 action)
Robert Moore73459f72005-06-24 00:00:00 -0400229{
Len Brown4be44fc2005-08-05 00:44:28 -0400230 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400231
Bob Moore0e770b32012-12-19 05:37:59 +0000232 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400233
234 /* Create the generic state object */
235
Len Brown4be44fc2005-08-05 00:44:28 -0400236 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400237 if (!state) {
Bob Moore0e770b32012-12-19 05:37:59 +0000238 return (NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400239 }
240
241 /* Init fields specific to the update struct */
242
Bob Moore616861242006-03-17 16:44:00 -0500243 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
Robert Moore73459f72005-06-24 00:00:00 -0400244 state->update.object = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400245 state->update.value = action;
Bob Moore0e770b32012-12-19 05:37:59 +0000246 return (state);
Robert Moore73459f72005-06-24 00:00:00 -0400247}
248
Robert Moore73459f72005-06-24 00:00:00 -0400249/*******************************************************************************
250 *
251 * FUNCTION: acpi_ut_create_pkg_state
252 *
Bob Mooreba494be2012-07-12 09:40:10 +0800253 * PARAMETERS: object - Initial Object to be installed in the state
254 * action - Update action to be performed
Robert Moore73459f72005-06-24 00:00:00 -0400255 *
256 * RETURN: New state object, null on failure
257 *
258 * DESCRIPTION: Create a "Package State"
259 *
260 ******************************************************************************/
261
Len Brown4be44fc2005-08-05 00:44:28 -0400262union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
263 void *external_object,
264 u16 index)
Robert Moore73459f72005-06-24 00:00:00 -0400265{
Len Brown4be44fc2005-08-05 00:44:28 -0400266 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400267
Bob Moore0e770b32012-12-19 05:37:59 +0000268 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400269
270 /* Create the generic state object */
271
Len Brown4be44fc2005-08-05 00:44:28 -0400272 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400273 if (!state) {
Bob Moore0e770b32012-12-19 05:37:59 +0000274 return (NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400275 }
276
277 /* Init fields specific to the update struct */
278
Bob Moore616861242006-03-17 16:44:00 -0500279 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
Len Brown4be44fc2005-08-05 00:44:28 -0400280 state->pkg.source_object = (union acpi_operand_object *)internal_object;
281 state->pkg.dest_object = external_object;
282 state->pkg.index = index;
Robert Moore73459f72005-06-24 00:00:00 -0400283 state->pkg.num_packages = 1;
Bob Moore0e770b32012-12-19 05:37:59 +0000284 return (state);
Robert Moore73459f72005-06-24 00:00:00 -0400285}
286
Robert Moore73459f72005-06-24 00:00:00 -0400287/*******************************************************************************
288 *
289 * FUNCTION: acpi_ut_create_control_state
290 *
291 * PARAMETERS: None
292 *
293 * RETURN: New state object, null on failure
294 *
295 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
296 * to support nested IF/WHILE constructs in the AML.
297 *
298 ******************************************************************************/
299
Len Brown4be44fc2005-08-05 00:44:28 -0400300union acpi_generic_state *acpi_ut_create_control_state(void)
Robert Moore73459f72005-06-24 00:00:00 -0400301{
Len Brown4be44fc2005-08-05 00:44:28 -0400302 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400303
Bob Moore0e770b32012-12-19 05:37:59 +0000304 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400305
306 /* Create the generic state object */
307
Len Brown4be44fc2005-08-05 00:44:28 -0400308 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400309 if (!state) {
Bob Moore0e770b32012-12-19 05:37:59 +0000310 return (NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400311 }
312
313 /* Init fields specific to the control struct */
314
Bob Moore616861242006-03-17 16:44:00 -0500315 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
Len Brown4be44fc2005-08-05 00:44:28 -0400316 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
Bob Moore0e770b32012-12-19 05:37:59 +0000317 return (state);
Robert Moore73459f72005-06-24 00:00:00 -0400318}
319
Robert Moore73459f72005-06-24 00:00:00 -0400320/*******************************************************************************
321 *
322 * FUNCTION: acpi_ut_delete_generic_state
323 *
Bob Mooreba494be2012-07-12 09:40:10 +0800324 * PARAMETERS: state - The state object to be deleted
Robert Moore73459f72005-06-24 00:00:00 -0400325 *
326 * RETURN: None
327 *
Bob Moore793c2382006-03-31 00:00:00 -0500328 * DESCRIPTION: Release a state object to the state cache. NULL state objects
329 * are ignored.
Robert Moore73459f72005-06-24 00:00:00 -0400330 *
331 ******************************************************************************/
332
Len Brown4be44fc2005-08-05 00:44:28 -0400333void acpi_ut_delete_generic_state(union acpi_generic_state *state)
Robert Moore73459f72005-06-24 00:00:00 -0400334{
Bob Moore0e770b32012-12-19 05:37:59 +0000335 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400336
Bob Moore793c2382006-03-31 00:00:00 -0500337 /* Ignore null state */
338
339 if (state) {
340 (void)acpi_os_release_object(acpi_gbl_state_cache, state);
341 }
Bob Moore0e770b32012-12-19 05:37:59 +0000342 return;
Robert Moore73459f72005-06-24 00:00:00 -0400343}