Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: exstoren - AML Interpreter object store support, |
| 5 | * Store to Node (namespace object) |
| 6 | * |
| 7 | *****************************************************************************/ |
| 8 | |
| 9 | /* |
Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 10 | * Copyright (C) 2000 - 2008, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * All rights reserved. |
| 12 | * |
| 13 | * Redistribution and use in source and binary forms, with or without |
| 14 | * modification, are permitted provided that the following conditions |
| 15 | * are met: |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions, and the following disclaimer, |
| 18 | * without modification. |
| 19 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 20 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 21 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 22 | * including a substantially similar Disclaimer requirement for further |
| 23 | * binary redistribution. |
| 24 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 25 | * of any contributors may be used to endorse or promote products derived |
| 26 | * from this software without specific prior written permission. |
| 27 | * |
| 28 | * Alternatively, this software may be distributed under the terms of the |
| 29 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 30 | * Software Foundation. |
| 31 | * |
| 32 | * NO WARRANTY |
| 33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 37 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 38 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 39 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 40 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 41 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 42 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 43 | * POSSIBILITY OF SUCH DAMAGES. |
| 44 | */ |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 47 | #include "accommon.h" |
| 48 | #include "acinterp.h" |
| 49 | #include "amlcode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("exstoren") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /******************************************************************************* |
| 55 | * |
| 56 | * FUNCTION: acpi_ex_resolve_object |
| 57 | * |
| 58 | * PARAMETERS: source_desc_ptr - Pointer to the source object |
| 59 | * target_type - Current type of the target |
| 60 | * walk_state - Current walk state |
| 61 | * |
| 62 | * RETURN: Status, resolved object in source_desc_ptr. |
| 63 | * |
| 64 | * DESCRIPTION: Resolve an object. If the object is a reference, dereference |
| 65 | * it and return the actual object in the source_desc_ptr. |
| 66 | * |
| 67 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr, |
| 70 | acpi_object_type target_type, |
| 71 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 73 | union acpi_operand_object *source_desc = *source_desc_ptr; |
| 74 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 76 | ACPI_FUNCTION_TRACE(ex_resolve_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 78 | /* Ensure we have a Target that can be stored to */ |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | switch (target_type) { |
| 81 | case ACPI_TYPE_BUFFER_FIELD: |
| 82 | case ACPI_TYPE_LOCAL_REGION_FIELD: |
| 83 | case ACPI_TYPE_LOCAL_BANK_FIELD: |
| 84 | case ACPI_TYPE_LOCAL_INDEX_FIELD: |
| 85 | /* |
| 86 | * These cases all require only Integers or values that |
| 87 | * can be converted to Integers (Strings or Buffers) |
| 88 | */ |
| 89 | |
| 90 | case ACPI_TYPE_INTEGER: |
| 91 | case ACPI_TYPE_STRING: |
| 92 | case ACPI_TYPE_BUFFER: |
| 93 | |
| 94 | /* |
| 95 | * Stores into a Field/Region or into a Integer/Buffer/String |
| 96 | * are all essentially the same. This case handles the |
| 97 | * "interchangeable" types Integer, String, and Buffer. |
| 98 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 99 | if (source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /* Resolve a reference object first */ |
| 102 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 103 | status = |
| 104 | acpi_ex_resolve_to_value(source_desc_ptr, |
| 105 | walk_state); |
| 106 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | break; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /* For copy_object, no further validation necessary */ |
| 112 | |
| 113 | if (walk_state->opcode == AML_COPY_OP) { |
| 114 | break; |
| 115 | } |
| 116 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 117 | /* Must have a Integer, Buffer, or String */ |
| 118 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 119 | if ((source_desc->common.type != ACPI_TYPE_INTEGER) && |
| 120 | (source_desc->common.type != ACPI_TYPE_BUFFER) && |
| 121 | (source_desc->common.type != ACPI_TYPE_STRING) && |
| 122 | !((source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) && |
| 123 | (source_desc->reference.class == ACPI_REFCLASS_TABLE))) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 124 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 125 | /* Conversion successful but still not a valid type */ |
| 126 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 127 | ACPI_ERROR((AE_INFO, |
| 128 | "Cannot assign type %s to %s (must be type Int/Str/Buf)", |
| 129 | acpi_ut_get_object_type_name(source_desc), |
| 130 | acpi_ut_get_type_name(target_type))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | status = AE_AML_OPERAND_TYPE; |
| 132 | } |
| 133 | break; |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | case ACPI_TYPE_LOCAL_ALIAS: |
| 136 | case ACPI_TYPE_LOCAL_METHOD_ALIAS: |
| 137 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 138 | /* |
| 139 | * All aliases should have been resolved earlier, during the |
| 140 | * operand resolution phase. |
| 141 | */ |
| 142 | ACPI_ERROR((AE_INFO, "Store into an unresolved Alias object")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | status = AE_AML_INTERNAL; |
| 144 | break; |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | case ACPI_TYPE_PACKAGE: |
| 147 | default: |
| 148 | |
| 149 | /* |
| 150 | * All other types than Alias and the various Fields come here, |
| 151 | * including the untyped case - ACPI_TYPE_ANY. |
| 152 | */ |
| 153 | break; |
| 154 | } |
| 155 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /******************************************************************************* |
| 160 | * |
| 161 | * FUNCTION: acpi_ex_store_object_to_object |
| 162 | * |
| 163 | * PARAMETERS: source_desc - Object to store |
| 164 | * dest_desc - Object to receive a copy of the source |
| 165 | * new_desc - New object if dest_desc is obsoleted |
| 166 | * walk_state - Current walk state |
| 167 | * |
| 168 | * RETURN: Status |
| 169 | * |
| 170 | * DESCRIPTION: "Store" an object to another object. This may include |
| 171 | * converting the source type to the target type (implicit |
| 172 | * conversion), and a copy of the value of the source to |
| 173 | * the target. |
| 174 | * |
| 175 | * The Assignment of an object to another (not named) object |
| 176 | * is handled here. |
| 177 | * The Source passed in will replace the current value (if any) |
| 178 | * with the input value. |
| 179 | * |
| 180 | * When storing into an object the data is converted to the |
| 181 | * target object type then stored in the object. This means |
| 182 | * that the target object type (for an initialized target) will |
| 183 | * not be changed by a store operation. |
| 184 | * |
| 185 | * This module allows destination types of Number, String, |
| 186 | * Buffer, and Package. |
| 187 | * |
| 188 | * Assumes parameters are already validated. NOTE: source_desc |
| 189 | * resolution (from a reference object) must be performed by |
| 190 | * the caller if necessary. |
| 191 | * |
| 192 | ******************************************************************************/ |
| 193 | |
| 194 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | acpi_ex_store_object_to_object(union acpi_operand_object *source_desc, |
| 196 | union acpi_operand_object *dest_desc, |
| 197 | union acpi_operand_object **new_desc, |
| 198 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | union acpi_operand_object *actual_src_desc; |
| 201 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 203 | ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_object, source_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | actual_src_desc = source_desc; |
| 206 | if (!dest_desc) { |
| 207 | /* |
| 208 | * There is no destination object (An uninitialized node or |
| 209 | * package element), so we can simply copy the source object |
| 210 | * creating a new destination object |
| 211 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | status = |
| 213 | acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc, |
| 214 | walk_state); |
| 215 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 218 | if (source_desc->common.type != dest_desc->common.type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | /* |
| 220 | * The source type does not match the type of the destination. |
| 221 | * Perform the "implicit conversion" of the source to the current type |
| 222 | * of the target as per the ACPI specification. |
| 223 | * |
| 224 | * If no conversion performed, actual_src_desc = source_desc. |
| 225 | * Otherwise, actual_src_desc is a temporary object to hold the |
| 226 | * converted object. |
| 227 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 228 | status = acpi_ex_convert_to_target_type(dest_desc->common.type, |
| 229 | source_desc, |
| 230 | &actual_src_desc, |
| 231 | walk_state); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | if (ACPI_FAILURE(status)) { |
| 233 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | if (source_desc == actual_src_desc) { |
| 237 | /* |
| 238 | * No conversion was performed. Return the source_desc as the |
| 239 | * new object. |
| 240 | */ |
| 241 | *new_desc = source_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | * We now have two objects of identical types, and we can perform a |
| 248 | * copy of the *value* of the source object. |
| 249 | */ |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 250 | switch (dest_desc->common.type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | case ACPI_TYPE_INTEGER: |
| 252 | |
| 253 | dest_desc->integer.value = actual_src_desc->integer.value; |
| 254 | |
| 255 | /* Truncate value if we are executing from a 32-bit ACPI table */ |
| 256 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | acpi_ex_truncate_for32bit_table(dest_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | break; |
| 259 | |
| 260 | case ACPI_TYPE_STRING: |
| 261 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 262 | status = |
| 263 | acpi_ex_store_string_to_string(actual_src_desc, dest_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | break; |
| 265 | |
| 266 | case ACPI_TYPE_BUFFER: |
| 267 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 268 | status = |
| 269 | acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | break; |
| 271 | |
| 272 | case ACPI_TYPE_PACKAGE: |
| 273 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | status = |
| 275 | acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc, |
| 276 | walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | break; |
| 278 | |
| 279 | default: |
| 280 | /* |
| 281 | * All other types come here. |
| 282 | */ |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 283 | ACPI_WARNING((AE_INFO, "Store into type %s not implemented", |
| 284 | acpi_ut_get_object_type_name(dest_desc))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | status = AE_NOT_IMPLEMENTED; |
| 287 | break; |
| 288 | } |
| 289 | |
| 290 | if (actual_src_desc != source_desc) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | /* Delete the intermediate (temporary) source object */ |
| 293 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | acpi_ut_remove_reference(actual_src_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | *new_desc = dest_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |