]>
Commit | Line | Data |
---|---|---|
73459f73 RM |
1 | /******************************************************************************* |
2 | * | |
3 | * Module Name: utstate - state object support procedures | |
4 | * | |
5 | ******************************************************************************/ | |
6 | ||
7 | /* | |
75a44ce0 | 8 | * Copyright (C) 2000 - 2008, 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 | 48 | ACPI_MODULE_NAME("utstate") |
73459f73 RM |
49 | |
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 | ******************************************************************************/ | |
73459f73 | 63 | acpi_status |
4be44fcd LB |
64 | acpi_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 | |
88 | * State - State object to push | |
89 | * | |
90 | * RETURN: None | |
91 | * | |
92 | * DESCRIPTION: Push a state object onto a state stack | |
93 | * | |
94 | ******************************************************************************/ | |
95 | ||
96 | void | |
4be44fcd LB |
97 | acpi_ut_push_generic_state(union acpi_generic_state **list_head, |
98 | union acpi_generic_state *state) | |
73459f73 | 99 | { |
b229cf92 | 100 | ACPI_FUNCTION_TRACE(ut_push_generic_state); |
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; | |
106 | ||
107 | return_VOID; | |
108 | } | |
109 | ||
73459f73 RM |
110 | /******************************************************************************* |
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 | ||
4be44fcd LB |
122 | union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state |
123 | **list_head) | |
73459f73 | 124 | { |
4be44fcd | 125 | union acpi_generic_state *state; |
73459f73 | 126 | |
b229cf92 | 127 | ACPI_FUNCTION_TRACE(ut_pop_generic_state); |
73459f73 RM |
128 | |
129 | /* Remove the state object at the head of the list (stack) */ | |
130 | ||
131 | state = *list_head; | |
132 | if (state) { | |
52fc0b02 | 133 | |
73459f73 RM |
134 | /* Update the list head */ |
135 | ||
136 | *list_head = state->common.next; | |
137 | } | |
138 | ||
4be44fcd | 139 | return_PTR(state); |
73459f73 RM |
140 | } |
141 | ||
73459f73 RM |
142 | /******************************************************************************* |
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 | ||
4be44fcd | 155 | union acpi_generic_state *acpi_ut_create_generic_state(void) |
73459f73 | 156 | { |
4be44fcd | 157 | union acpi_generic_state *state; |
73459f73 | 158 | |
4be44fcd | 159 | ACPI_FUNCTION_ENTRY(); |
73459f73 | 160 | |
4be44fcd | 161 | state = acpi_os_acquire_object(acpi_gbl_state_cache); |
73459f73 | 162 | if (state) { |
52fc0b02 | 163 | |
73459f73 RM |
164 | /* Initialize */ |
165 | memset(state, 0, sizeof(union acpi_generic_state)); | |
61686124 | 166 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE; |
73459f73 RM |
167 | } |
168 | ||
169 | return (state); | |
170 | } | |
171 | ||
73459f73 RM |
172 | /******************************************************************************* |
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 | ||
4be44fcd | 185 | struct acpi_thread_state *acpi_ut_create_thread_state(void) |
73459f73 | 186 | { |
4be44fcd | 187 | union acpi_generic_state *state; |
73459f73 | 188 | |
b229cf92 | 189 | ACPI_FUNCTION_TRACE(ut_create_thread_state); |
73459f73 RM |
190 | |
191 | /* Create the generic state object */ | |
192 | ||
4be44fcd | 193 | state = acpi_ut_create_generic_state(); |
73459f73 | 194 | if (!state) { |
4be44fcd | 195 | return_PTR(NULL); |
73459f73 RM |
196 | } |
197 | ||
198 | /* Init fields specific to the update struct */ | |
199 | ||
61686124 | 200 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD; |
4be44fcd | 201 | state->thread.thread_id = acpi_os_get_thread_id(); |
73459f73 | 202 | |
f6dd9221 BM |
203 | /* 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 | ||
4be44fcd | 210 | return_PTR((struct acpi_thread_state *)state); |
73459f73 RM |
211 | } |
212 | ||
73459f73 RM |
213 | /******************************************************************************* |
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 | ||
4be44fcd LB |
228 | union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object |
229 | *object, u16 action) | |
73459f73 | 230 | { |
4be44fcd | 231 | union acpi_generic_state *state; |
73459f73 | 232 | |
b229cf92 | 233 | ACPI_FUNCTION_TRACE_PTR(ut_create_update_state, object); |
73459f73 RM |
234 | |
235 | /* Create the generic state object */ | |
236 | ||
4be44fcd | 237 | state = acpi_ut_create_generic_state(); |
73459f73 | 238 | if (!state) { |
4be44fcd | 239 | return_PTR(NULL); |
73459f73 RM |
240 | } |
241 | ||
242 | /* Init fields specific to the update struct */ | |
243 | ||
61686124 | 244 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE; |
73459f73 | 245 | state->update.object = object; |
4be44fcd | 246 | state->update.value = action; |
73459f73 | 247 | |
4be44fcd | 248 | return_PTR(state); |
73459f73 RM |
249 | } |
250 | ||
73459f73 RM |
251 | /******************************************************************************* |
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 | ||
4be44fcd LB |
264 | union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object, |
265 | void *external_object, | |
266 | u16 index) | |
73459f73 | 267 | { |
4be44fcd | 268 | union acpi_generic_state *state; |
73459f73 | 269 | |
b229cf92 | 270 | ACPI_FUNCTION_TRACE_PTR(ut_create_pkg_state, internal_object); |
73459f73 RM |
271 | |
272 | /* Create the generic state object */ | |
273 | ||
4be44fcd | 274 | state = acpi_ut_create_generic_state(); |
73459f73 | 275 | if (!state) { |
4be44fcd | 276 | return_PTR(NULL); |
73459f73 RM |
277 | } |
278 | ||
279 | /* Init fields specific to the update struct */ | |
280 | ||
61686124 | 281 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE; |
4be44fcd LB |
282 | state->pkg.source_object = (union acpi_operand_object *)internal_object; |
283 | state->pkg.dest_object = external_object; | |
284 | state->pkg.index = index; | |
73459f73 RM |
285 | state->pkg.num_packages = 1; |
286 | ||
4be44fcd | 287 | return_PTR(state); |
73459f73 RM |
288 | } |
289 | ||
73459f73 RM |
290 | /******************************************************************************* |
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 | ||
4be44fcd | 303 | union acpi_generic_state *acpi_ut_create_control_state(void) |
73459f73 | 304 | { |
4be44fcd | 305 | union acpi_generic_state *state; |
73459f73 | 306 | |
b229cf92 | 307 | ACPI_FUNCTION_TRACE(ut_create_control_state); |
73459f73 RM |
308 | |
309 | /* Create the generic state object */ | |
310 | ||
4be44fcd | 311 | state = acpi_ut_create_generic_state(); |
73459f73 | 312 | if (!state) { |
4be44fcd | 313 | return_PTR(NULL); |
73459f73 RM |
314 | } |
315 | ||
316 | /* Init fields specific to the control struct */ | |
317 | ||
61686124 | 318 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL; |
4be44fcd | 319 | state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING; |
73459f73 | 320 | |
4be44fcd | 321 | return_PTR(state); |
73459f73 RM |
322 | } |
323 | ||
73459f73 RM |
324 | /******************************************************************************* |
325 | * | |
326 | * FUNCTION: acpi_ut_delete_generic_state | |
327 | * | |
328 | * PARAMETERS: State - The state object to be deleted | |
329 | * | |
330 | * RETURN: None | |
331 | * | |
793c2388 BM |
332 | * DESCRIPTION: Release a state object to the state cache. NULL state objects |
333 | * are ignored. | |
73459f73 RM |
334 | * |
335 | ******************************************************************************/ | |
336 | ||
4be44fcd | 337 | void acpi_ut_delete_generic_state(union acpi_generic_state *state) |
73459f73 | 338 | { |
b229cf92 | 339 | ACPI_FUNCTION_TRACE(ut_delete_generic_state); |
73459f73 | 340 | |
793c2388 BM |
341 | /* Ignore null state */ |
342 | ||
343 | if (state) { | |
344 | (void)acpi_os_release_object(acpi_gbl_state_cache, state); | |
345 | } | |
73459f73 RM |
346 | return_VOID; |
347 | } |