]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/acpica/utstate.c
ACPICA: exmutex: General cleanup, restructured some code
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / utstate.c
CommitLineData
73459f73
RM
1/*******************************************************************************
2 *
3 * Module Name: utstate - state object support procedures
4 *
5 ******************************************************************************/
6
7/*
82a80941 8 * Copyright (C) 2000 - 2015, Intel Corp.
73459f73
RM
9 * 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
73459f73 44#include <acpi/acpi.h>
e2f7a777 45#include "accommon.h"
73459f73
RM
46
47#define _COMPONENT ACPI_UTILITIES
4be44fcd 48ACPI_MODULE_NAME("utstate")
73459f73 49
73459f73
RM
50/*******************************************************************************
51 *
52 * FUNCTION: acpi_ut_push_generic_state
53 *
54 * PARAMETERS: list_head - Head of the state stack
ba494bee 55 * state - State object to push
73459f73
RM
56 *
57 * RETURN: None
58 *
59 * DESCRIPTION: Push a state object onto a state stack
60 *
61 ******************************************************************************/
73459f73 62void
4be44fcd
LB
63acpi_ut_push_generic_state(union acpi_generic_state **list_head,
64 union acpi_generic_state *state)
73459f73 65{
0e770b32 66 ACPI_FUNCTION_ENTRY();
73459f73
RM
67
68 /* Push the state object onto the front of the list (stack) */
69
70 state->common.next = *list_head;
71 *list_head = state;
0e770b32 72 return;
73459f73
RM
73}
74
73459f73
RM
75/*******************************************************************************
76 *
77 * FUNCTION: acpi_ut_pop_generic_state
78 *
79 * PARAMETERS: list_head - Head of the state stack
80 *
81 * RETURN: The popped state object
82 *
83 * DESCRIPTION: Pop a state object from a state stack
84 *
85 ******************************************************************************/
86
4be44fcd
LB
87union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
88 **list_head)
73459f73 89{
4be44fcd 90 union acpi_generic_state *state;
73459f73 91
0e770b32 92 ACPI_FUNCTION_ENTRY();
73459f73
RM
93
94 /* Remove the state object at the head of the list (stack) */
95
96 state = *list_head;
97 if (state) {
52fc0b02 98
73459f73
RM
99 /* Update the list head */
100
101 *list_head = state->common.next;
102 }
103
0e770b32 104 return (state);
73459f73
RM
105}
106
73459f73
RM
107/*******************************************************************************
108 *
109 * FUNCTION: acpi_ut_create_generic_state
110 *
111 * PARAMETERS: None
112 *
113 * RETURN: The new state object. NULL on failure.
114 *
73a3090a 115 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
73459f73
RM
116 * the global state cache; If none available, create a new one.
117 *
118 ******************************************************************************/
119
4be44fcd 120union acpi_generic_state *acpi_ut_create_generic_state(void)
73459f73 121{
4be44fcd 122 union acpi_generic_state *state;
73459f73 123
4be44fcd 124 ACPI_FUNCTION_ENTRY();
73459f73 125
4be44fcd 126 state = acpi_os_acquire_object(acpi_gbl_state_cache);
73459f73 127 if (state) {
52fc0b02 128
73459f73 129 /* Initialize */
61686124 130 state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
73459f73
RM
131 }
132
133 return (state);
134}
135
73459f73
RM
136/*******************************************************************************
137 *
138 * FUNCTION: acpi_ut_create_thread_state
139 *
140 * PARAMETERS: None
141 *
142 * RETURN: New Thread State. NULL on failure
143 *
144 * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used
145 * to track per-thread info during method execution
146 *
147 ******************************************************************************/
148
4be44fcd 149struct acpi_thread_state *acpi_ut_create_thread_state(void)
73459f73 150{
4be44fcd 151 union acpi_generic_state *state;
73459f73 152
0e770b32 153 ACPI_FUNCTION_ENTRY();
73459f73
RM
154
155 /* Create the generic state object */
156
4be44fcd 157 state = acpi_ut_create_generic_state();
73459f73 158 if (!state) {
0e770b32 159 return (NULL);
73459f73
RM
160 }
161
162 /* Init fields specific to the update struct */
163
61686124 164 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
4be44fcd 165 state->thread.thread_id = acpi_os_get_thread_id();
73459f73 166
f6dd9221
BM
167 /* Check for invalid thread ID - zero is very bad, it will break things */
168
169 if (!state->thread.thread_id) {
170 ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId"));
171 state->thread.thread_id = (acpi_thread_id) 1;
172 }
173
0e770b32 174 return ((struct acpi_thread_state *)state);
73459f73
RM
175}
176
73459f73
RM
177/*******************************************************************************
178 *
179 * FUNCTION: acpi_ut_create_update_state
180 *
ba494bee
BM
181 * PARAMETERS: object - Initial Object to be installed in the state
182 * action - Update action to be performed
73459f73
RM
183 *
184 * RETURN: New state object, null on failure
185 *
186 * DESCRIPTION: Create an "Update State" - a flavor of the generic state used
187 * to update reference counts and delete complex objects such
188 * as packages.
189 *
190 ******************************************************************************/
191
4be44fcd
LB
192union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
193 *object, u16 action)
73459f73 194{
4be44fcd 195 union acpi_generic_state *state;
73459f73 196
0e770b32 197 ACPI_FUNCTION_ENTRY();
73459f73
RM
198
199 /* Create the generic state object */
200
4be44fcd 201 state = acpi_ut_create_generic_state();
73459f73 202 if (!state) {
0e770b32 203 return (NULL);
73459f73
RM
204 }
205
206 /* Init fields specific to the update struct */
207
61686124 208 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
73459f73 209 state->update.object = object;
4be44fcd 210 state->update.value = action;
0e770b32 211 return (state);
73459f73
RM
212}
213
73459f73
RM
214/*******************************************************************************
215 *
216 * FUNCTION: acpi_ut_create_pkg_state
217 *
ba494bee
BM
218 * PARAMETERS: object - Initial Object to be installed in the state
219 * action - Update action to be performed
73459f73
RM
220 *
221 * RETURN: New state object, null on failure
222 *
223 * DESCRIPTION: Create a "Package State"
224 *
225 ******************************************************************************/
226
4be44fcd
LB
227union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
228 void *external_object,
229 u16 index)
73459f73 230{
4be44fcd 231 union acpi_generic_state *state;
73459f73 232
0e770b32 233 ACPI_FUNCTION_ENTRY();
73459f73
RM
234
235 /* Create the generic state object */
236
4be44fcd 237 state = acpi_ut_create_generic_state();
73459f73 238 if (!state) {
0e770b32 239 return (NULL);
73459f73
RM
240 }
241
242 /* Init fields specific to the update struct */
243
61686124 244 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
4be44fcd
LB
245 state->pkg.source_object = (union acpi_operand_object *)internal_object;
246 state->pkg.dest_object = external_object;
247 state->pkg.index = index;
73459f73 248 state->pkg.num_packages = 1;
0e770b32 249 return (state);
73459f73
RM
250}
251
73459f73
RM
252/*******************************************************************************
253 *
254 * FUNCTION: acpi_ut_create_control_state
255 *
256 * PARAMETERS: None
257 *
258 * RETURN: New state object, null on failure
259 *
260 * DESCRIPTION: Create a "Control State" - a flavor of the generic state used
261 * to support nested IF/WHILE constructs in the AML.
262 *
263 ******************************************************************************/
264
4be44fcd 265union acpi_generic_state *acpi_ut_create_control_state(void)
73459f73 266{
4be44fcd 267 union acpi_generic_state *state;
73459f73 268
0e770b32 269 ACPI_FUNCTION_ENTRY();
73459f73
RM
270
271 /* Create the generic state object */
272
4be44fcd 273 state = acpi_ut_create_generic_state();
73459f73 274 if (!state) {
0e770b32 275 return (NULL);
73459f73
RM
276 }
277
278 /* Init fields specific to the control struct */
279
61686124 280 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
4be44fcd 281 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
0e770b32 282 return (state);
73459f73
RM
283}
284
73459f73
RM
285/*******************************************************************************
286 *
287 * FUNCTION: acpi_ut_delete_generic_state
288 *
ba494bee 289 * PARAMETERS: state - The state object to be deleted
73459f73
RM
290 *
291 * RETURN: None
292 *
793c2388
BM
293 * DESCRIPTION: Release a state object to the state cache. NULL state objects
294 * are ignored.
73459f73
RM
295 *
296 ******************************************************************************/
297
4be44fcd 298void acpi_ut_delete_generic_state(union acpi_generic_state *state)
73459f73 299{
0e770b32 300 ACPI_FUNCTION_ENTRY();
73459f73 301
793c2388
BM
302 /* Ignore null state */
303
304 if (state) {
305 (void)acpi_os_release_object(acpi_gbl_state_cache, state);
306 }
0e770b32 307 return;
73459f73 308}