blob: 0440c958f5a47fc9cc001b4b459d967bbc68e07b [file] [log] [blame]
Robert Moore73459f72005-06-24 00:00:00 -04001/*******************************************************************************
2 *
3 * Module Name: utstate - state object support procedures
4 *
5 ******************************************************************************/
6
7/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, 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 *
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
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
88 * State - State object to push
89 *
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 Mooreb229cf92006-04-21 17:15:00 -0400100 ACPI_FUNCTION_TRACE(ut_push_generic_state);
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;
106
107 return_VOID;
108}
109
Robert Moore73459f72005-06-24 00:00:00 -0400110/*******************************************************************************
111 *
112 * FUNCTION: acpi_ut_pop_generic_state
113 *
114 * PARAMETERS: list_head - Head of the state stack
115 *
116 * RETURN: The popped state object
117 *
118 * DESCRIPTION: Pop a state object from a state stack
119 *
120 ******************************************************************************/
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
123 **list_head)
Robert Moore73459f72005-06-24 00:00:00 -0400124{
Len Brown4be44fc2005-08-05 00:44:28 -0400125 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400126
Bob Mooreb229cf92006-04-21 17:15:00 -0400127 ACPI_FUNCTION_TRACE(ut_pop_generic_state);
Robert Moore73459f72005-06-24 00:00:00 -0400128
129 /* Remove the state object at the head of the list (stack) */
130
131 state = *list_head;
132 if (state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400133
Robert Moore73459f72005-06-24 00:00:00 -0400134 /* Update the list head */
135
136 *list_head = state->common.next;
137 }
138
Len Brown4be44fc2005-08-05 00:44:28 -0400139 return_PTR(state);
Robert Moore73459f72005-06-24 00:00:00 -0400140}
141
Robert Moore73459f72005-06-24 00:00:00 -0400142/*******************************************************************************
143 *
144 * FUNCTION: acpi_ut_create_generic_state
145 *
146 * PARAMETERS: None
147 *
148 * RETURN: The new state object. NULL on failure.
149 *
150 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
151 * the global state cache; If none available, create a new one.
152 *
153 ******************************************************************************/
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155union acpi_generic_state *acpi_ut_create_generic_state(void)
Robert Moore73459f72005-06-24 00:00:00 -0400156{
Len Brown4be44fc2005-08-05 00:44:28 -0400157 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 ACPI_FUNCTION_ENTRY();
Robert Moore73459f72005-06-24 00:00:00 -0400160
Len Brown4be44fc2005-08-05 00:44:28 -0400161 state = acpi_os_acquire_object(acpi_gbl_state_cache);
Robert Moore73459f72005-06-24 00:00:00 -0400162 if (state) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400163
Robert Moore73459f72005-06-24 00:00:00 -0400164 /* Initialize */
165 memset(state, 0, sizeof(union acpi_generic_state));
Bob Moore616861242006-03-17 16:44:00 -0500166 state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
Robert Moore73459f72005-06-24 00:00:00 -0400167 }
168
169 return (state);
170}
171
Robert Moore73459f72005-06-24 00:00:00 -0400172/*******************************************************************************
173 *
174 * FUNCTION: acpi_ut_create_thread_state
175 *
176 * PARAMETERS: None
177 *
178 * RETURN: New Thread State. NULL on failure
179 *
180 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
181 * to track per-thread info during method execution
182 *
183 ******************************************************************************/
184
Len Brown4be44fc2005-08-05 00:44:28 -0400185struct acpi_thread_state *acpi_ut_create_thread_state(void)
Robert Moore73459f72005-06-24 00:00:00 -0400186{
Len Brown4be44fc2005-08-05 00:44:28 -0400187 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400188
Bob Mooreb229cf92006-04-21 17:15:00 -0400189 ACPI_FUNCTION_TRACE(ut_create_thread_state);
Robert Moore73459f72005-06-24 00:00:00 -0400190
191 /* Create the generic state object */
192
Len Brown4be44fc2005-08-05 00:44:28 -0400193 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400194 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400195 return_PTR(NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400196 }
197
198 /* Init fields specific to the update struct */
199
Bob Moore616861242006-03-17 16:44:00 -0500200 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
Len Brown4be44fc2005-08-05 00:44:28 -0400201 state->thread.thread_id = acpi_os_get_thread_id();
Robert Moore73459f72005-06-24 00:00:00 -0400202
Bob Mooref6dd9222006-07-07 20:44:38 -0400203 /* Check for invalid thread ID - zero is very bad, it will break things */
204
205 if (!state->thread.thread_id) {
206 ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
207 state->thread.thread_id = (acpi_thread_id) 1;
208 }
209
Len Brown4be44fc2005-08-05 00:44:28 -0400210 return_PTR((struct acpi_thread_state *)state);
Robert Moore73459f72005-06-24 00:00:00 -0400211}
212
Robert Moore73459f72005-06-24 00:00:00 -0400213/*******************************************************************************
214 *
215 * FUNCTION: acpi_ut_create_update_state
216 *
217 * PARAMETERS: Object - Initial Object to be installed in the state
218 * Action - Update action to be performed
219 *
220 * RETURN: New state object, null on failure
221 *
222 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
223 * to update reference counts and delete complex objects such
224 * as packages.
225 *
226 ******************************************************************************/
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
229 *object, u16 action)
Robert Moore73459f72005-06-24 00:00:00 -0400230{
Len Brown4be44fc2005-08-05 00:44:28 -0400231 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400232
Bob Mooreb229cf92006-04-21 17:15:00 -0400233 ACPI_FUNCTION_TRACE_PTR(ut_create_update_state, object);
Robert Moore73459f72005-06-24 00:00:00 -0400234
235 /* Create the generic state object */
236
Len Brown4be44fc2005-08-05 00:44:28 -0400237 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400238 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400239 return_PTR(NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400240 }
241
242 /* Init fields specific to the update struct */
243
Bob Moore616861242006-03-17 16:44:00 -0500244 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
Robert Moore73459f72005-06-24 00:00:00 -0400245 state->update.object = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400246 state->update.value = action;
Robert Moore73459f72005-06-24 00:00:00 -0400247
Len Brown4be44fc2005-08-05 00:44:28 -0400248 return_PTR(state);
Robert Moore73459f72005-06-24 00:00:00 -0400249}
250
Robert Moore73459f72005-06-24 00:00:00 -0400251/*******************************************************************************
252 *
253 * FUNCTION: acpi_ut_create_pkg_state
254 *
255 * PARAMETERS: Object - Initial Object to be installed in the state
256 * Action - Update action to be performed
257 *
258 * RETURN: New state object, null on failure
259 *
260 * DESCRIPTION: Create a "Package State"
261 *
262 ******************************************************************************/
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
265 void *external_object,
266 u16 index)
Robert Moore73459f72005-06-24 00:00:00 -0400267{
Len Brown4be44fc2005-08-05 00:44:28 -0400268 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400269
Bob Mooreb229cf92006-04-21 17:15:00 -0400270 ACPI_FUNCTION_TRACE_PTR(ut_create_pkg_state, internal_object);
Robert Moore73459f72005-06-24 00:00:00 -0400271
272 /* Create the generic state object */
273
Len Brown4be44fc2005-08-05 00:44:28 -0400274 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400275 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400276 return_PTR(NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400277 }
278
279 /* Init fields specific to the update struct */
280
Bob Moore616861242006-03-17 16:44:00 -0500281 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
Len Brown4be44fc2005-08-05 00:44:28 -0400282 state->pkg.source_object = (union acpi_operand_object *)internal_object;
283 state->pkg.dest_object = external_object;
284 state->pkg.index = index;
Robert Moore73459f72005-06-24 00:00:00 -0400285 state->pkg.num_packages = 1;
286
Len Brown4be44fc2005-08-05 00:44:28 -0400287 return_PTR(state);
Robert Moore73459f72005-06-24 00:00:00 -0400288}
289
Robert Moore73459f72005-06-24 00:00:00 -0400290/*******************************************************************************
291 *
292 * FUNCTION: acpi_ut_create_control_state
293 *
294 * PARAMETERS: None
295 *
296 * RETURN: New state object, null on failure
297 *
298 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
299 * to support nested IF/WHILE constructs in the AML.
300 *
301 ******************************************************************************/
302
Len Brown4be44fc2005-08-05 00:44:28 -0400303union acpi_generic_state *acpi_ut_create_control_state(void)
Robert Moore73459f72005-06-24 00:00:00 -0400304{
Len Brown4be44fc2005-08-05 00:44:28 -0400305 union acpi_generic_state *state;
Robert Moore73459f72005-06-24 00:00:00 -0400306
Bob Mooreb229cf92006-04-21 17:15:00 -0400307 ACPI_FUNCTION_TRACE(ut_create_control_state);
Robert Moore73459f72005-06-24 00:00:00 -0400308
309 /* Create the generic state object */
310
Len Brown4be44fc2005-08-05 00:44:28 -0400311 state = acpi_ut_create_generic_state();
Robert Moore73459f72005-06-24 00:00:00 -0400312 if (!state) {
Len Brown4be44fc2005-08-05 00:44:28 -0400313 return_PTR(NULL);
Robert Moore73459f72005-06-24 00:00:00 -0400314 }
315
316 /* Init fields specific to the control struct */
317
Bob Moore616861242006-03-17 16:44:00 -0500318 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
Len Brown4be44fc2005-08-05 00:44:28 -0400319 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
Robert Moore73459f72005-06-24 00:00:00 -0400320
Len Brown4be44fc2005-08-05 00:44:28 -0400321 return_PTR(state);
Robert Moore73459f72005-06-24 00:00:00 -0400322}
323
Robert Moore73459f72005-06-24 00:00:00 -0400324/*******************************************************************************
325 *
326 * FUNCTION: acpi_ut_delete_generic_state
327 *
328 * PARAMETERS: State - The state object to be deleted
329 *
330 * RETURN: None
331 *
Bob Moore793c2382006-03-31 00:00:00 -0500332 * DESCRIPTION: Release a state object to the state cache. NULL state objects
333 * are ignored.
Robert Moore73459f72005-06-24 00:00:00 -0400334 *
335 ******************************************************************************/
336
Len Brown4be44fc2005-08-05 00:44:28 -0400337void acpi_ut_delete_generic_state(union acpi_generic_state *state)
Robert Moore73459f72005-06-24 00:00:00 -0400338{
Bob Mooreb229cf92006-04-21 17:15:00 -0400339 ACPI_FUNCTION_TRACE(ut_delete_generic_state);
Robert Moore73459f72005-06-24 00:00:00 -0400340
Bob Moore793c2382006-03-31 00:00:00 -0500341 /* Ignore null state */
342
343 if (state) {
344 (void)acpi_os_release_object(acpi_gbl_state_cache, state);
345 }
Robert Moore73459f72005-06-24 00:00:00 -0400346 return_VOID;
347}