Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: dsfield - Dispatcher field routines |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/amlcode.h> |
| 46 | #include <acpi/acdispat.h> |
| 47 | #include <acpi/acinterp.h> |
| 48 | #include <acpi/acnamesp.h> |
| 49 | #include <acpi/acparser.h> |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define _COMPONENT ACPI_DISPATCHER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("dsfield") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 54 | /* Local prototypes */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 56 | acpi_ds_get_field_names(struct acpi_create_field_info *info, |
| 57 | struct acpi_walk_state *walk_state, |
| 58 | union acpi_parse_object *arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /******************************************************************************* |
| 61 | * |
| 62 | * FUNCTION: acpi_ds_create_buffer_field |
| 63 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 64 | * PARAMETERS: Op - Current parse op (create_xXField) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | * walk_state - Current state |
| 66 | * |
| 67 | * RETURN: Status |
| 68 | * |
| 69 | * DESCRIPTION: Execute the create_field operators: |
| 70 | * create_bit_field_op, |
| 71 | * create_byte_field_op, |
| 72 | * create_word_field_op, |
| 73 | * create_dword_field_op, |
| 74 | * create_qword_field_op, |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 75 | * create_field_op (all of which define a field in a buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | * |
| 77 | ******************************************************************************/ |
| 78 | |
| 79 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | acpi_ds_create_buffer_field(union acpi_parse_object *op, |
| 81 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | union acpi_parse_object *arg; |
| 84 | struct acpi_namespace_node *node; |
| 85 | acpi_status status; |
| 86 | union acpi_operand_object *obj_desc; |
| 87 | union acpi_operand_object *second_desc = NULL; |
| 88 | u32 flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | ACPI_FUNCTION_TRACE("ds_create_buffer_field"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /* Get the name_string argument */ |
| 93 | |
| 94 | if (op->common.aml_opcode == AML_CREATE_FIELD_OP) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 95 | arg = acpi_ps_get_arg(op, 3); |
| 96 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* Create Bit/Byte/Word/Dword field */ |
| 98 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | arg = acpi_ps_get_arg(op, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | if (!arg) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | return_ACPI_STATUS(AE_AML_NO_OPERAND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | if (walk_state->deferred_node) { |
| 107 | node = walk_state->deferred_node; |
| 108 | status = AE_OK; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* |
| 111 | * During the load phase, we want to enter the name of the field into |
| 112 | * the namespace. During the execute phase (when we evaluate the size |
| 113 | * operand), we want to lookup the name |
| 114 | */ |
| 115 | if (walk_state->parse_flags & ACPI_PARSE_EXECUTE) { |
| 116 | flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | } else { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 118 | flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | ACPI_NS_ERROR_IF_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Enter the name_string into the namespace |
| 124 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | status = |
| 126 | acpi_ns_lookup(walk_state->scope_info, |
| 127 | arg->common.value.string, ACPI_TYPE_ANY, |
| 128 | ACPI_IMODE_LOAD_PASS1, flags, walk_state, |
| 129 | &(node)); |
| 130 | if (ACPI_FAILURE(status)) { |
| 131 | ACPI_REPORT_NSERROR(arg->common.value.string, status); |
| 132 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 136 | /* We could put the returned object (Node) on the object stack for later, |
| 137 | * but for now, we will put it in the "op" object that the parser uses, |
| 138 | * so we can get it again at the end of this scope |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | */ |
| 140 | op->common.node = node; |
| 141 | |
| 142 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 143 | * If there is no object attached to the node, this node was just created |
| 144 | * and we need to create the field object. Otherwise, this was a lookup |
| 145 | * of an existing node and we don't want to create the field object again. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | if (obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* |
| 153 | * The Field definition is not fully parsed at this time. |
| 154 | * (We must save the address of the AML for the buffer and index operands) |
| 155 | */ |
| 156 | |
| 157 | /* Create the buffer field object */ |
| 158 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (!obj_desc) { |
| 161 | status = AE_NO_MEMORY; |
| 162 | goto cleanup; |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * Remember location in AML stream of the field unit |
| 167 | * opcode and operands -- since the buffer and index |
| 168 | * operands must be evaluated. |
| 169 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | second_desc = obj_desc->common.next_object; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | second_desc->extra.aml_start = op->named.data; |
| 172 | second_desc->extra.aml_length = op->named.length; |
| 173 | obj_desc->buffer_field.node = node; |
| 174 | |
| 175 | /* Attach constructed field descriptors to parent node */ |
| 176 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD); |
| 178 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | goto cleanup; |
| 180 | } |
| 181 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | /* Remove local reference to the object */ |
| 185 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | acpi_ut_remove_reference(obj_desc); |
| 187 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | /******************************************************************************* |
| 191 | * |
| 192 | * FUNCTION: acpi_ds_get_field_names |
| 193 | * |
| 194 | * PARAMETERS: Info - create_field info structure |
| 195 | * ` walk_state - Current method state |
| 196 | * Arg - First parser arg for the field name list |
| 197 | * |
| 198 | * RETURN: Status |
| 199 | * |
| 200 | * DESCRIPTION: Process all named fields in a field declaration. Names are |
| 201 | * entered into the namespace. |
| 202 | * |
| 203 | ******************************************************************************/ |
| 204 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 205 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | acpi_ds_get_field_names(struct acpi_create_field_info *info, |
| 207 | struct acpi_walk_state *walk_state, |
| 208 | union acpi_parse_object *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | acpi_status status; |
| 211 | acpi_integer position; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | ACPI_FUNCTION_TRACE_PTR("ds_get_field_names", info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | /* First field starts at bit zero */ |
| 216 | |
| 217 | info->field_bit_position = 0; |
| 218 | |
| 219 | /* Process all elements in the field list (of parse nodes) */ |
| 220 | |
| 221 | while (arg) { |
| 222 | /* |
| 223 | * Three types of field elements are handled: |
| 224 | * 1) Offset - specifies a bit offset |
| 225 | * 2) access_as - changes the access mode |
| 226 | * 3) Name - Enters a new named field into the namespace |
| 227 | */ |
| 228 | switch (arg->common.aml_opcode) { |
| 229 | case AML_INT_RESERVEDFIELD_OP: |
| 230 | |
| 231 | position = (acpi_integer) info->field_bit_position |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | + (acpi_integer) arg->common.value.size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | if (position > ACPI_UINT32_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | ACPI_REPORT_ERROR(("Bit offset within field too large (> 0xFFFFFFFF)\n")); |
| 236 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | info->field_bit_position = (u32) position; |
| 240 | break; |
| 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | case AML_INT_ACCESSFIELD_OP: |
| 243 | |
| 244 | /* |
| 245 | * Get a new access_type and access_attribute -- to be used for all |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 246 | * field units that follow, until field end or another access_as |
| 247 | * keyword. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 249 | * In field_flags, preserve the flag bits other than the |
| 250 | * ACCESS_TYPE bits |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 252 | info->field_flags = (u8) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | ((info-> |
| 254 | field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) | |
| 255 | ((u8) ((u32) arg->common.value.integer >> 8))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | info->attribute = (u8) (arg->common.value.integer); |
| 258 | break; |
| 259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | case AML_INT_NAMEDFIELD_OP: |
| 261 | |
| 262 | /* Lookup the name */ |
| 263 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | status = acpi_ns_lookup(walk_state->scope_info, |
| 265 | (char *)&arg->named.name, |
| 266 | info->field_type, |
| 267 | ACPI_IMODE_EXECUTE, |
| 268 | ACPI_NS_DONT_OPEN_SCOPE, |
| 269 | walk_state, &info->field_node); |
| 270 | if (ACPI_FAILURE(status)) { |
| 271 | ACPI_REPORT_NSERROR((char *)&arg->named.name, |
| 272 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (status != AE_ALREADY_EXISTS) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /* Already exists, ignore error */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | arg->common.node = info->field_node; |
| 280 | info->field_bit_length = arg->common.value.size; |
| 281 | |
| 282 | /* Create and initialize an object for the new Field Node */ |
| 283 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | status = acpi_ex_prep_field_value(info); |
| 285 | if (ACPI_FAILURE(status)) { |
| 286 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | /* Keep track of bit position for the next field */ |
| 291 | |
| 292 | position = (acpi_integer) info->field_bit_position |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | + (acpi_integer) arg->common.value.size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | if (position > ACPI_UINT32_MAX) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | ACPI_REPORT_ERROR(("Field [%4.4s] bit offset too large (> 0xFFFFFFFF)\n", (char *)&info->field_node->name)); |
| 297 | return_ACPI_STATUS(AE_SUPPORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | info->field_bit_position += info->field_bit_length; |
| 301 | break; |
| 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | default: |
| 304 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 305 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 306 | "Invalid opcode in field list: %X\n", |
| 307 | arg->common.aml_opcode)); |
| 308 | return_ACPI_STATUS(AE_AML_BAD_OPCODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | arg = arg->common.next; |
| 312 | } |
| 313 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | /******************************************************************************* |
| 318 | * |
| 319 | * FUNCTION: acpi_ds_create_field |
| 320 | * |
| 321 | * PARAMETERS: Op - Op containing the Field definition and args |
| 322 | * region_node - Object for the containing Operation Region |
| 323 | * ` walk_state - Current method state |
| 324 | * |
| 325 | * RETURN: Status |
| 326 | * |
| 327 | * DESCRIPTION: Create a new field in the specified operation region |
| 328 | * |
| 329 | ******************************************************************************/ |
| 330 | |
| 331 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | acpi_ds_create_field(union acpi_parse_object *op, |
| 333 | struct acpi_namespace_node *region_node, |
| 334 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 336 | acpi_status status; |
| 337 | union acpi_parse_object *arg; |
| 338 | struct acpi_create_field_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | ACPI_FUNCTION_TRACE_PTR("ds_create_field", op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | /* First arg is the name of the parent op_region (must already exist) */ |
| 343 | |
| 344 | arg = op->common.value.arg; |
| 345 | if (!region_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 346 | status = |
| 347 | acpi_ns_lookup(walk_state->scope_info, |
| 348 | arg->common.value.name, ACPI_TYPE_REGION, |
| 349 | ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, |
| 350 | walk_state, ®ion_node); |
| 351 | if (ACPI_FAILURE(status)) { |
| 352 | ACPI_REPORT_NSERROR(arg->common.value.name, status); |
| 353 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
| 357 | /* Second arg is the field flags */ |
| 358 | |
| 359 | arg = arg->common.next; |
| 360 | info.field_flags = (u8) arg->common.value.integer; |
| 361 | info.attribute = 0; |
| 362 | |
| 363 | /* Each remaining arg is a Named Field */ |
| 364 | |
| 365 | info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD; |
| 366 | info.region_node = region_node; |
| 367 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | status = acpi_ds_get_field_names(&info, walk_state, arg->common.next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 370 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | /******************************************************************************* |
| 374 | * |
| 375 | * FUNCTION: acpi_ds_init_field_objects |
| 376 | * |
| 377 | * PARAMETERS: Op - Op containing the Field definition and args |
| 378 | * ` walk_state - Current method state |
| 379 | * |
| 380 | * RETURN: Status |
| 381 | * |
| 382 | * DESCRIPTION: For each "Field Unit" name in the argument list that is |
| 383 | * part of the field declaration, enter the name into the |
| 384 | * namespace. |
| 385 | * |
| 386 | ******************************************************************************/ |
| 387 | |
| 388 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | acpi_ds_init_field_objects(union acpi_parse_object *op, |
| 390 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | acpi_status status; |
| 393 | union acpi_parse_object *arg = NULL; |
| 394 | struct acpi_namespace_node *node; |
| 395 | u8 type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 397 | ACPI_FUNCTION_TRACE_PTR("ds_init_field_objects", op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | switch (walk_state->opcode) { |
| 400 | case AML_FIELD_OP: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 401 | arg = acpi_ps_get_arg(op, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | type = ACPI_TYPE_LOCAL_REGION_FIELD; |
| 403 | break; |
| 404 | |
| 405 | case AML_BANK_FIELD_OP: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | arg = acpi_ps_get_arg(op, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | type = ACPI_TYPE_LOCAL_BANK_FIELD; |
| 408 | break; |
| 409 | |
| 410 | case AML_INDEX_FIELD_OP: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 411 | arg = acpi_ps_get_arg(op, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | type = ACPI_TYPE_LOCAL_INDEX_FIELD; |
| 413 | break; |
| 414 | |
| 415 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* |
| 420 | * Walk the list of entries in the field_list |
| 421 | */ |
| 422 | while (arg) { |
| 423 | /* Ignore OFFSET and ACCESSAS terms here */ |
| 424 | |
| 425 | if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 426 | status = acpi_ns_lookup(walk_state->scope_info, |
| 427 | (char *)&arg->named.name, |
| 428 | type, ACPI_IMODE_LOAD_PASS1, |
| 429 | ACPI_NS_NO_UPSEARCH | |
| 430 | ACPI_NS_DONT_OPEN_SCOPE | |
| 431 | ACPI_NS_ERROR_IF_FOUND, |
| 432 | walk_state, &node); |
| 433 | if (ACPI_FAILURE(status)) { |
| 434 | ACPI_REPORT_NSERROR((char *)&arg->named.name, |
| 435 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | if (status != AE_ALREADY_EXISTS) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /* Name already exists, just ignore this error */ |
| 441 | |
| 442 | status = AE_OK; |
| 443 | } |
| 444 | |
| 445 | arg->common.node = node; |
| 446 | } |
| 447 | |
| 448 | /* Move to next field in the list */ |
| 449 | |
| 450 | arg = arg->common.next; |
| 451 | } |
| 452 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 453 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /******************************************************************************* |
| 457 | * |
| 458 | * FUNCTION: acpi_ds_create_bank_field |
| 459 | * |
| 460 | * PARAMETERS: Op - Op containing the Field definition and args |
| 461 | * region_node - Object for the containing Operation Region |
| 462 | * ` walk_state - Current method state |
| 463 | * |
| 464 | * RETURN: Status |
| 465 | * |
| 466 | * DESCRIPTION: Create a new bank field in the specified operation region |
| 467 | * |
| 468 | ******************************************************************************/ |
| 469 | |
| 470 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 471 | acpi_ds_create_bank_field(union acpi_parse_object *op, |
| 472 | struct acpi_namespace_node *region_node, |
| 473 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 475 | acpi_status status; |
| 476 | union acpi_parse_object *arg; |
| 477 | struct acpi_create_field_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 479 | ACPI_FUNCTION_TRACE_PTR("ds_create_bank_field", op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
| 481 | /* First arg is the name of the parent op_region (must already exist) */ |
| 482 | |
| 483 | arg = op->common.value.arg; |
| 484 | if (!region_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 485 | status = |
| 486 | acpi_ns_lookup(walk_state->scope_info, |
| 487 | arg->common.value.name, ACPI_TYPE_REGION, |
| 488 | ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, |
| 489 | walk_state, ®ion_node); |
| 490 | if (ACPI_FAILURE(status)) { |
| 491 | ACPI_REPORT_NSERROR(arg->common.value.name, status); |
| 492 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
| 496 | /* Second arg is the Bank Register (Field) (must already exist) */ |
| 497 | |
| 498 | arg = arg->common.next; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 499 | status = |
| 500 | acpi_ns_lookup(walk_state->scope_info, arg->common.value.string, |
| 501 | ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, |
| 502 | ACPI_NS_SEARCH_PARENT, walk_state, |
| 503 | &info.register_node); |
| 504 | if (ACPI_FAILURE(status)) { |
| 505 | ACPI_REPORT_NSERROR(arg->common.value.string, status); |
| 506 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /* Third arg is the bank_value */ |
| 510 | |
| 511 | arg = arg->common.next; |
| 512 | info.bank_value = (u32) arg->common.value.integer; |
| 513 | |
| 514 | /* Fourth arg is the field flags */ |
| 515 | |
| 516 | arg = arg->common.next; |
| 517 | info.field_flags = (u8) arg->common.value.integer; |
| 518 | |
| 519 | /* Each remaining arg is a Named Field */ |
| 520 | |
| 521 | info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD; |
| 522 | info.region_node = region_node; |
| 523 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 524 | status = acpi_ds_get_field_names(&info, walk_state, arg->common.next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 526 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | /******************************************************************************* |
| 530 | * |
| 531 | * FUNCTION: acpi_ds_create_index_field |
| 532 | * |
| 533 | * PARAMETERS: Op - Op containing the Field definition and args |
| 534 | * region_node - Object for the containing Operation Region |
| 535 | * ` walk_state - Current method state |
| 536 | * |
| 537 | * RETURN: Status |
| 538 | * |
| 539 | * DESCRIPTION: Create a new index field in the specified operation region |
| 540 | * |
| 541 | ******************************************************************************/ |
| 542 | |
| 543 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 544 | acpi_ds_create_index_field(union acpi_parse_object *op, |
| 545 | struct acpi_namespace_node *region_node, |
| 546 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 548 | acpi_status status; |
| 549 | union acpi_parse_object *arg; |
| 550 | struct acpi_create_field_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 552 | ACPI_FUNCTION_TRACE_PTR("ds_create_index_field", op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | /* First arg is the name of the Index register (must already exist) */ |
| 555 | |
| 556 | arg = op->common.value.arg; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 557 | status = |
| 558 | acpi_ns_lookup(walk_state->scope_info, arg->common.value.string, |
| 559 | ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, |
| 560 | ACPI_NS_SEARCH_PARENT, walk_state, |
| 561 | &info.register_node); |
| 562 | if (ACPI_FAILURE(status)) { |
| 563 | ACPI_REPORT_NSERROR(arg->common.value.string, status); |
| 564 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /* Second arg is the data register (must already exist) */ |
| 568 | |
| 569 | arg = arg->common.next; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 570 | status = |
| 571 | acpi_ns_lookup(walk_state->scope_info, arg->common.value.string, |
| 572 | ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, |
| 573 | ACPI_NS_SEARCH_PARENT, walk_state, |
| 574 | &info.data_register_node); |
| 575 | if (ACPI_FAILURE(status)) { |
| 576 | ACPI_REPORT_NSERROR(arg->common.value.string, status); |
| 577 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /* Next arg is the field flags */ |
| 581 | |
| 582 | arg = arg->common.next; |
| 583 | info.field_flags = (u8) arg->common.value.integer; |
| 584 | |
| 585 | /* Each remaining arg is a Named Field */ |
| 586 | |
| 587 | info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD; |
| 588 | info.region_node = region_node; |
| 589 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 590 | status = acpi_ds_get_field_names(&info, walk_state, arg->common.next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 592 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |