Merge tag 'please-pull-pstore' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / acpica / utstate.c
CommitLineData
73459f73
RM
1/*******************************************************************************
2 *
3 * Module Name: utstate - state object support procedures
4 *
5 ******************************************************************************/
6
7/*
25f044e6 8 * Copyright (C) 2000 - 2013, 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
RM
49
50/*******************************************************************************
51 *
52 * FUNCTION: acpi_ut_create_pkg_state_and_push
53 *
ba494bee
BM
54 * PARAMETERS: object - Object to be added to the new state
55 * action - Increment/Decrement
73459f73
RM
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 ******************************************************************************/
73459f73 63acpi_status
4be44fcd
LB
64acpi_ut_create_pkg_state_and_push(void *internal_object,
65 void *external_object,
66 u16 index,
96db255c 67 union acpi_generic_state **state_list)
73459f73 68{
4be44fcd 69 union acpi_generic_state *state;
73459f73 70
4be44fcd 71 ACPI_FUNCTION_ENTRY();
73459f73 72
4be44fcd
LB
73 state =
74 acpi_ut_create_pkg_state(internal_object, external_object, index);
73459f73
RM
75 if (!state) {
76 return (AE_NO_MEMORY);
77 }
78
4be44fcd 79 acpi_ut_push_generic_state(state_list, state);
73459f73
RM
80 return (AE_OK);
81}
82
73459f73
RM
83/*******************************************************************************
84 *
85 * FUNCTION: acpi_ut_push_generic_state
86 *
87 * PARAMETERS: list_head - Head of the state stack
ba494bee 88 * state - State object to push
73459f73
RM
89 *
90 * RETURN: None
91 *
92 * DESCRIPTION: Push a state object onto a state stack
93 *
94 ******************************************************************************/
95
96void
4be44fcd
LB
97acpi_ut_push_generic_state(union acpi_generic_state **list_head,
98 union acpi_generic_state *state)
73459f73 99{
0e770b32 100 ACPI_FUNCTION_ENTRY();
73459f73
RM
101
102 /* Push the state object onto the front of the list (stack) */
103
104 state->common.next = *list_head;
105 *list_head = state;
0e770b32 106 return;
73459f73
RM
107}
108
73459f73
RM
109/*******************************************************************************
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
4be44fcd
LB
121union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state
122 **list_head)
73459f73 123{
4be44fcd 124 union acpi_generic_state *state;
73459f73 125
0e770b32 126 ACPI_FUNCTION_ENTRY();
73459f73
RM
127
128 /* Remove the state object at the head of the list (stack) */
129
130 state = *list_head;
131 if (state) {
52fc0b02 132
73459f73
RM
133 /* Update the list head */
134
135 *list_head = state->common.next;
136 }
137
0e770b32 138 return (state);
73459f73
RM
139}
140
73459f73
RM
141/*******************************************************************************
142 *
143 * FUNCTION: acpi_ut_create_generic_state
144 *
145 * PARAMETERS: None
146 *
147 * RETURN: The new state object. NULL on failure.
148 *
73a3090a 149 * DESCRIPTION: Create a generic state object. Attempt to obtain one from
73459f73
RM
150 * the global state cache; If none available, create a new one.
151 *
152 ******************************************************************************/
153
4be44fcd 154union acpi_generic_state *acpi_ut_create_generic_state(void)
73459f73 155{
4be44fcd 156 union acpi_generic_state *state;
73459f73 157
4be44fcd 158 ACPI_FUNCTION_ENTRY();
73459f73 159
4be44fcd 160 state = acpi_os_acquire_object(acpi_gbl_state_cache);
73459f73 161 if (state) {
52fc0b02 162
73459f73
RM
163 /* Initialize */
164 memset(state, 0, sizeof(union acpi_generic_state));
61686124 165 state->common.descriptor_type = ACPI_DESC_TYPE_STATE;
73459f73
RM
166 }
167
168 return (state);
169}
170
73459f73
RM
171/*******************************************************************************
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
4be44fcd 184struct acpi_thread_state *acpi_ut_create_thread_state(void)
73459f73 185{
4be44fcd 186 union acpi_generic_state *state;
73459f73 187
0e770b32 188 ACPI_FUNCTION_ENTRY();
73459f73
RM
189
190 /* Create the generic state object */
191
4be44fcd 192 state = acpi_ut_create_generic_state();
73459f73 193 if (!state) {
0e770b32 194 return (NULL);
73459f73
RM
195 }
196
197 /* Init fields specific to the update struct */
198
61686124 199 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD;
4be44fcd 200 state->thread.thread_id = acpi_os_get_thread_id();
73459f73 201
f6dd9221
BM
202 /* 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
0e770b32 209 return ((struct acpi_thread_state *)state);
73459f73
RM
210}
211
73459f73
RM
212/*******************************************************************************
213 *
214 * FUNCTION: acpi_ut_create_update_state
215 *
ba494bee
BM
216 * PARAMETERS: object - Initial Object to be installed in the state
217 * action - Update action to be performed
73459f73
RM
218 *
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
4be44fcd
LB
227union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object
228 *object, u16 action)
73459f73 229{
4be44fcd 230 union acpi_generic_state *state;
73459f73 231
0e770b32 232 ACPI_FUNCTION_ENTRY();
73459f73
RM
233
234 /* Create the generic state object */
235
4be44fcd 236 state = acpi_ut_create_generic_state();
73459f73 237 if (!state) {
0e770b32 238 return (NULL);
73459f73
RM
239 }
240
241 /* Init fields specific to the update struct */
242
61686124 243 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE;
73459f73 244 state->update.object = object;
4be44fcd 245 state->update.value = action;
0e770b32 246 return (state);
73459f73
RM
247}
248
73459f73
RM
249/*******************************************************************************
250 *
251 * FUNCTION: acpi_ut_create_pkg_state
252 *
ba494bee
BM
253 * PARAMETERS: object - Initial Object to be installed in the state
254 * action - Update action to be performed
73459f73
RM
255 *
256 * RETURN: New state object, null on failure
257 *
258 * DESCRIPTION: Create a "Package State"
259 *
260 ******************************************************************************/
261
4be44fcd
LB
262union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object,
263 void *external_object,
264 u16 index)
73459f73 265{
4be44fcd 266 union acpi_generic_state *state;
73459f73 267
0e770b32 268 ACPI_FUNCTION_ENTRY();
73459f73
RM
269
270 /* Create the generic state object */
271
4be44fcd 272 state = acpi_ut_create_generic_state();
73459f73 273 if (!state) {
0e770b32 274 return (NULL);
73459f73
RM
275 }
276
277 /* Init fields specific to the update struct */
278
61686124 279 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE;
4be44fcd
LB
280 state->pkg.source_object = (union acpi_operand_object *)internal_object;
281 state->pkg.dest_object = external_object;
282 state->pkg.index = index;
73459f73 283 state->pkg.num_packages = 1;
0e770b32 284 return (state);
73459f73
RM
285}
286
73459f73
RM
287/*******************************************************************************
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
4be44fcd 300union acpi_generic_state *acpi_ut_create_control_state(void)
73459f73 301{
4be44fcd 302 union acpi_generic_state *state;
73459f73 303
0e770b32 304 ACPI_FUNCTION_ENTRY();
73459f73
RM
305
306 /* Create the generic state object */
307
4be44fcd 308 state = acpi_ut_create_generic_state();
73459f73 309 if (!state) {
0e770b32 310 return (NULL);
73459f73
RM
311 }
312
313 /* Init fields specific to the control struct */
314
61686124 315 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL;
4be44fcd 316 state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING;
0e770b32 317 return (state);
73459f73
RM
318}
319
73459f73
RM
320/*******************************************************************************
321 *
322 * FUNCTION: acpi_ut_delete_generic_state
323 *
ba494bee 324 * PARAMETERS: state - The state object to be deleted
73459f73
RM
325 *
326 * RETURN: None
327 *
793c2388
BM
328 * DESCRIPTION: Release a state object to the state cache. NULL state objects
329 * are ignored.
73459f73
RM
330 *
331 ******************************************************************************/
332
4be44fcd 333void acpi_ut_delete_generic_state(union acpi_generic_state *state)
73459f73 334{
0e770b32 335 ACPI_FUNCTION_ENTRY();
73459f73 336
793c2388
BM
337 /* Ignore null state */
338
339 if (state) {
340 (void)acpi_os_release_object(acpi_gbl_state_cache, state);
341 }
0e770b32 342 return;
73459f73 343}