Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Module Name: utstate - state object support procedures |
| 4 | * |
| 5 | ******************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2005, R. Byron Moore |
| 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 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | |
| 46 | #define _COMPONENT ACPI_UTILITIES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 47 | ACPI_MODULE_NAME("utstate") |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 48 | |
| 49 | /******************************************************************************* |
| 50 | * |
| 51 | * FUNCTION: acpi_ut_create_pkg_state_and_push |
| 52 | * |
| 53 | * PARAMETERS: Object - Object to be added to the new state |
| 54 | * Action - Increment/Decrement |
| 55 | * state_list - List the state will be added to |
| 56 | * |
| 57 | * RETURN: Status |
| 58 | * |
| 59 | * DESCRIPTION: Create a new state and push it |
| 60 | * |
| 61 | ******************************************************************************/ |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 62 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 63 | acpi_ut_create_pkg_state_and_push(void *internal_object, |
| 64 | void *external_object, |
| 65 | u16 index, |
| 66 | union acpi_generic_state ** state_list) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 67 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 68 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 69 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 70 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 71 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 72 | state = |
| 73 | acpi_ut_create_pkg_state(internal_object, external_object, index); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 74 | if (!state) { |
| 75 | return (AE_NO_MEMORY); |
| 76 | } |
| 77 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 78 | acpi_ut_push_generic_state(state_list, state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 79 | return (AE_OK); |
| 80 | } |
| 81 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 82 | /******************************************************************************* |
| 83 | * |
| 84 | * FUNCTION: acpi_ut_push_generic_state |
| 85 | * |
| 86 | * PARAMETERS: list_head - Head of the state stack |
| 87 | * State - State object to push |
| 88 | * |
| 89 | * RETURN: None |
| 90 | * |
| 91 | * DESCRIPTION: Push a state object onto a state stack |
| 92 | * |
| 93 | ******************************************************************************/ |
| 94 | |
| 95 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 96 | acpi_ut_push_generic_state(union acpi_generic_state **list_head, |
| 97 | union acpi_generic_state *state) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 98 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 99 | ACPI_FUNCTION_TRACE("ut_push_generic_state"); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 100 | |
| 101 | /* Push the state object onto the front of the list (stack) */ |
| 102 | |
| 103 | state->common.next = *list_head; |
| 104 | *list_head = state; |
| 105 | |
| 106 | return_VOID; |
| 107 | } |
| 108 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 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 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 121 | union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state |
| 122 | **list_head) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 123 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 124 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 125 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 126 | ACPI_FUNCTION_TRACE("ut_pop_generic_state"); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 127 | |
| 128 | /* Remove the state object at the head of the list (stack) */ |
| 129 | |
| 130 | state = *list_head; |
| 131 | if (state) { |
| 132 | /* Update the list head */ |
| 133 | |
| 134 | *list_head = state->common.next; |
| 135 | } |
| 136 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 137 | return_PTR(state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 138 | } |
| 139 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 140 | /******************************************************************************* |
| 141 | * |
| 142 | * FUNCTION: acpi_ut_create_generic_state |
| 143 | * |
| 144 | * PARAMETERS: None |
| 145 | * |
| 146 | * RETURN: The new state object. NULL on failure. |
| 147 | * |
| 148 | * DESCRIPTION: Create a generic state object. Attempt to obtain one from |
| 149 | * the global state cache; If none available, create a new one. |
| 150 | * |
| 151 | ******************************************************************************/ |
| 152 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 153 | union acpi_generic_state *acpi_ut_create_generic_state(void) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 154 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 155 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 156 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 157 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 158 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 159 | state = acpi_os_acquire_object(acpi_gbl_state_cache); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 160 | if (state) { |
| 161 | /* Initialize */ |
| 162 | memset(state, 0, sizeof(union acpi_generic_state)); |
| 163 | state->common.data_type = ACPI_DESC_TYPE_STATE; |
| 164 | } |
| 165 | |
| 166 | return (state); |
| 167 | } |
| 168 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 169 | /******************************************************************************* |
| 170 | * |
| 171 | * FUNCTION: acpi_ut_create_thread_state |
| 172 | * |
| 173 | * PARAMETERS: None |
| 174 | * |
| 175 | * RETURN: New Thread State. NULL on failure |
| 176 | * |
| 177 | * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used |
| 178 | * to track per-thread info during method execution |
| 179 | * |
| 180 | ******************************************************************************/ |
| 181 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 182 | struct acpi_thread_state *acpi_ut_create_thread_state(void) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 183 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 184 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 185 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 186 | ACPI_FUNCTION_TRACE("ut_create_thread_state"); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 187 | |
| 188 | /* Create the generic state object */ |
| 189 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 190 | state = acpi_ut_create_generic_state(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 191 | if (!state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 192 | return_PTR(NULL); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /* Init fields specific to the update struct */ |
| 196 | |
| 197 | state->common.data_type = ACPI_DESC_TYPE_STATE_THREAD; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 198 | state->thread.thread_id = acpi_os_get_thread_id(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 199 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 200 | return_PTR((struct acpi_thread_state *)state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 201 | } |
| 202 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 203 | /******************************************************************************* |
| 204 | * |
| 205 | * FUNCTION: acpi_ut_create_update_state |
| 206 | * |
| 207 | * PARAMETERS: Object - Initial Object to be installed in the state |
| 208 | * Action - Update action to be performed |
| 209 | * |
| 210 | * RETURN: New state object, null on failure |
| 211 | * |
| 212 | * DESCRIPTION: Create an "Update State" - a flavor of the generic state used |
| 213 | * to update reference counts and delete complex objects such |
| 214 | * as packages. |
| 215 | * |
| 216 | ******************************************************************************/ |
| 217 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 218 | union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object |
| 219 | *object, u16 action) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 220 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 221 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 222 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 223 | ACPI_FUNCTION_TRACE_PTR("ut_create_update_state", object); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 224 | |
| 225 | /* Create the generic state object */ |
| 226 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 227 | state = acpi_ut_create_generic_state(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 228 | if (!state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 229 | return_PTR(NULL); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /* Init fields specific to the update struct */ |
| 233 | |
| 234 | state->common.data_type = ACPI_DESC_TYPE_STATE_UPDATE; |
| 235 | state->update.object = object; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 236 | state->update.value = action; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 237 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 238 | return_PTR(state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 239 | } |
| 240 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 241 | /******************************************************************************* |
| 242 | * |
| 243 | * FUNCTION: acpi_ut_create_pkg_state |
| 244 | * |
| 245 | * PARAMETERS: Object - Initial Object to be installed in the state |
| 246 | * Action - Update action to be performed |
| 247 | * |
| 248 | * RETURN: New state object, null on failure |
| 249 | * |
| 250 | * DESCRIPTION: Create a "Package State" |
| 251 | * |
| 252 | ******************************************************************************/ |
| 253 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 254 | union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object, |
| 255 | void *external_object, |
| 256 | u16 index) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 257 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 258 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 259 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 260 | ACPI_FUNCTION_TRACE_PTR("ut_create_pkg_state", internal_object); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 261 | |
| 262 | /* Create the generic state object */ |
| 263 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 264 | state = acpi_ut_create_generic_state(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 265 | if (!state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 266 | return_PTR(NULL); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /* Init fields specific to the update struct */ |
| 270 | |
| 271 | state->common.data_type = ACPI_DESC_TYPE_STATE_PACKAGE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 272 | state->pkg.source_object = (union acpi_operand_object *)internal_object; |
| 273 | state->pkg.dest_object = external_object; |
| 274 | state->pkg.index = index; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 275 | state->pkg.num_packages = 1; |
| 276 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 277 | return_PTR(state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 280 | /******************************************************************************* |
| 281 | * |
| 282 | * FUNCTION: acpi_ut_create_control_state |
| 283 | * |
| 284 | * PARAMETERS: None |
| 285 | * |
| 286 | * RETURN: New state object, null on failure |
| 287 | * |
| 288 | * DESCRIPTION: Create a "Control State" - a flavor of the generic state used |
| 289 | * to support nested IF/WHILE constructs in the AML. |
| 290 | * |
| 291 | ******************************************************************************/ |
| 292 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 293 | union acpi_generic_state *acpi_ut_create_control_state(void) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 294 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 295 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 296 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 297 | ACPI_FUNCTION_TRACE("ut_create_control_state"); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 298 | |
| 299 | /* Create the generic state object */ |
| 300 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 301 | state = acpi_ut_create_generic_state(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 302 | if (!state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 303 | return_PTR(NULL); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* Init fields specific to the control struct */ |
| 307 | |
| 308 | state->common.data_type = ACPI_DESC_TYPE_STATE_CONTROL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 309 | state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 310 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 311 | return_PTR(state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 312 | } |
| 313 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 314 | /******************************************************************************* |
| 315 | * |
| 316 | * FUNCTION: acpi_ut_delete_generic_state |
| 317 | * |
| 318 | * PARAMETERS: State - The state object to be deleted |
| 319 | * |
| 320 | * RETURN: None |
| 321 | * |
| 322 | * DESCRIPTION: Put a state object back into the global state cache. The object |
| 323 | * is not actually freed at this time. |
| 324 | * |
| 325 | ******************************************************************************/ |
| 326 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 327 | void acpi_ut_delete_generic_state(union acpi_generic_state *state) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 328 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 329 | ACPI_FUNCTION_TRACE("ut_delete_generic_state"); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 330 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 331 | (void)acpi_os_release_object(acpi_gbl_state_cache, state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 332 | return_VOID; |
| 333 | } |