Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * |
| 4 | * Module Name: utstate - state object support procedures |
| 5 | * |
| 6 | ******************************************************************************/ |
| 7 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 8 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 9 | #include "accommon.h" |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 10 | |
| 11 | #define _COMPONENT ACPI_UTILITIES |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 12 | ACPI_MODULE_NAME("utstate") |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 13 | |
| 14 | /******************************************************************************* |
| 15 | * |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 16 | * FUNCTION: acpi_ut_push_generic_state |
| 17 | * |
| 18 | * PARAMETERS: list_head - Head of the state stack |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 19 | * state - State object to push |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 20 | * |
| 21 | * RETURN: None |
| 22 | * |
| 23 | * DESCRIPTION: Push a state object onto a state stack |
| 24 | * |
| 25 | ******************************************************************************/ |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 26 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 27 | acpi_ut_push_generic_state(union acpi_generic_state **list_head, |
| 28 | union acpi_generic_state *state) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 29 | { |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 30 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 31 | |
| 32 | /* Push the state object onto the front of the list (stack) */ |
| 33 | |
| 34 | state->common.next = *list_head; |
| 35 | *list_head = state; |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 36 | return; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 37 | } |
| 38 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 39 | /******************************************************************************* |
| 40 | * |
| 41 | * FUNCTION: acpi_ut_pop_generic_state |
| 42 | * |
| 43 | * PARAMETERS: list_head - Head of the state stack |
| 44 | * |
| 45 | * RETURN: The popped state object |
| 46 | * |
| 47 | * DESCRIPTION: Pop a state object from a state stack |
| 48 | * |
| 49 | ******************************************************************************/ |
| 50 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | union acpi_generic_state *acpi_ut_pop_generic_state(union acpi_generic_state |
| 52 | **list_head) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 53 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 55 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 56 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 57 | |
| 58 | /* Remove the state object at the head of the list (stack) */ |
| 59 | |
| 60 | state = *list_head; |
| 61 | if (state) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 62 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 63 | /* Update the list head */ |
| 64 | |
| 65 | *list_head = state->common.next; |
| 66 | } |
| 67 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 68 | return (state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 69 | } |
| 70 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 71 | /******************************************************************************* |
| 72 | * |
| 73 | * FUNCTION: acpi_ut_create_generic_state |
| 74 | * |
| 75 | * PARAMETERS: None |
| 76 | * |
| 77 | * RETURN: The new state object. NULL on failure. |
| 78 | * |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 79 | * DESCRIPTION: Create a generic state object. Attempt to obtain one from |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 80 | * the global state cache; If none available, create a new one. |
| 81 | * |
| 82 | ******************************************************************************/ |
| 83 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | union acpi_generic_state *acpi_ut_create_generic_state(void) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 85 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 87 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 89 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | state = acpi_os_acquire_object(acpi_gbl_state_cache); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 91 | if (state) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 92 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 93 | /* Initialize */ |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 94 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | return (state); |
| 98 | } |
| 99 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 100 | /******************************************************************************* |
| 101 | * |
| 102 | * FUNCTION: acpi_ut_create_thread_state |
| 103 | * |
| 104 | * PARAMETERS: None |
| 105 | * |
| 106 | * RETURN: New Thread State. NULL on failure |
| 107 | * |
| 108 | * DESCRIPTION: Create a "Thread State" - a flavor of the generic state used |
| 109 | * to track per-thread info during method execution |
| 110 | * |
| 111 | ******************************************************************************/ |
| 112 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | struct acpi_thread_state *acpi_ut_create_thread_state(void) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 114 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 115 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 116 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 117 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 118 | |
| 119 | /* Create the generic state object */ |
| 120 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | state = acpi_ut_create_generic_state(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 122 | if (!state) { |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 123 | return (NULL); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* Init fields specific to the update struct */ |
| 127 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 128 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE_THREAD; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | state->thread.thread_id = acpi_os_get_thread_id(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 130 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 131 | /* Check for invalid thread ID - zero is very bad, it will break things */ |
| 132 | |
| 133 | if (!state->thread.thread_id) { |
| 134 | ACPI_ERROR((AE_INFO, "Invalid zero ID from AcpiOsGetThreadId")); |
| 135 | state->thread.thread_id = (acpi_thread_id) 1; |
| 136 | } |
| 137 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 138 | return ((struct acpi_thread_state *)state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 139 | } |
| 140 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 141 | /******************************************************************************* |
| 142 | * |
| 143 | * FUNCTION: acpi_ut_create_update_state |
| 144 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 145 | * PARAMETERS: object - Initial Object to be installed in the state |
| 146 | * action - Update action to be performed |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 147 | * |
| 148 | * RETURN: New state object, null on failure |
| 149 | * |
| 150 | * DESCRIPTION: Create an "Update State" - a flavor of the generic state used |
| 151 | * to update reference counts and delete complex objects such |
| 152 | * as packages. |
| 153 | * |
| 154 | ******************************************************************************/ |
| 155 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | union acpi_generic_state *acpi_ut_create_update_state(union acpi_operand_object |
| 157 | *object, u16 action) |
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 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 160 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 161 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 162 | |
| 163 | /* Create the generic state object */ |
| 164 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | state = acpi_ut_create_generic_state(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 166 | if (!state) { |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 167 | return (NULL); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* Init fields specific to the update struct */ |
| 171 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 172 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE_UPDATE; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 173 | state->update.object = object; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | state->update.value = action; |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 175 | return (state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 176 | } |
| 177 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 178 | /******************************************************************************* |
| 179 | * |
| 180 | * FUNCTION: acpi_ut_create_pkg_state |
| 181 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 182 | * PARAMETERS: object - Initial Object to be installed in the state |
| 183 | * action - Update action to be performed |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 184 | * |
| 185 | * RETURN: New state object, null on failure |
| 186 | * |
| 187 | * DESCRIPTION: Create a "Package State" |
| 188 | * |
| 189 | ******************************************************************************/ |
| 190 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 191 | union acpi_generic_state *acpi_ut_create_pkg_state(void *internal_object, |
| 192 | void *external_object, |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 193 | u32 index) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 194 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 196 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 197 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 198 | |
| 199 | /* Create the generic state object */ |
| 200 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | state = acpi_ut_create_generic_state(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 202 | if (!state) { |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 203 | return (NULL); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /* Init fields specific to the update struct */ |
| 207 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 208 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE_PACKAGE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | state->pkg.source_object = (union acpi_operand_object *)internal_object; |
| 210 | state->pkg.dest_object = external_object; |
| 211 | state->pkg.index = index; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 212 | state->pkg.num_packages = 1; |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 213 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 214 | return (state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 215 | } |
| 216 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 217 | /******************************************************************************* |
| 218 | * |
| 219 | * FUNCTION: acpi_ut_create_control_state |
| 220 | * |
| 221 | * PARAMETERS: None |
| 222 | * |
| 223 | * RETURN: New state object, null on failure |
| 224 | * |
| 225 | * DESCRIPTION: Create a "Control State" - a flavor of the generic state used |
| 226 | * to support nested IF/WHILE constructs in the AML. |
| 227 | * |
| 228 | ******************************************************************************/ |
| 229 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | union acpi_generic_state *acpi_ut_create_control_state(void) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 231 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | union acpi_generic_state *state; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 233 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 234 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 235 | |
| 236 | /* Create the generic state object */ |
| 237 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 238 | state = acpi_ut_create_generic_state(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 239 | if (!state) { |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 240 | return (NULL); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* Init fields specific to the control struct */ |
| 244 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 245 | state->common.descriptor_type = ACPI_DESC_TYPE_STATE_CONTROL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 246 | state->common.state = ACPI_CONTROL_CONDITIONAL_EXECUTING; |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 247 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 248 | return (state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 249 | } |
| 250 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 251 | /******************************************************************************* |
| 252 | * |
| 253 | * FUNCTION: acpi_ut_delete_generic_state |
| 254 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 255 | * PARAMETERS: state - The state object to be deleted |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 256 | * |
| 257 | * RETURN: None |
| 258 | * |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 259 | * DESCRIPTION: Release a state object to the state cache. NULL state objects |
| 260 | * are ignored. |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 261 | * |
| 262 | ******************************************************************************/ |
| 263 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | void acpi_ut_delete_generic_state(union acpi_generic_state *state) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 265 | { |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 266 | ACPI_FUNCTION_ENTRY(); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 267 | |
Bob Moore | 793c238 | 2006-03-31 00:00:00 -0500 | [diff] [blame] | 268 | /* Ignore null state */ |
| 269 | |
| 270 | if (state) { |
| 271 | (void)acpi_os_release_object(acpi_gbl_state_cache, state); |
| 272 | } |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 273 | |
Bob Moore | 0e770b3 | 2012-12-19 05:37:59 +0000 | [diff] [blame] | 274 | return; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 275 | } |