| 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 | /* | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 10 |  * Copyright (C) 2000 - 2006, R. Byron Moore | 
| 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> | 
 | 47 | #include <acpi/acinterp.h> | 
 | 48 | #include <acpi/amlcode.h> | 
 | 49 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define _COMPONENT          ACPI_EXECUTER | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("exstoren") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 |  | 
 | 53 | /******************************************************************************* | 
 | 54 |  * | 
 | 55 |  * FUNCTION:    acpi_ex_resolve_object | 
 | 56 |  * | 
 | 57 |  * PARAMETERS:  source_desc_ptr     - Pointer to the source object | 
 | 58 |  *              target_type         - Current type of the target | 
 | 59 |  *              walk_state          - Current walk state | 
 | 60 |  * | 
 | 61 |  * RETURN:      Status, resolved object in source_desc_ptr. | 
 | 62 |  * | 
 | 63 |  * DESCRIPTION: Resolve an object.  If the object is a reference, dereference | 
 | 64 |  *              it and return the actual object in the source_desc_ptr. | 
 | 65 |  * | 
 | 66 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 68 | acpi_ex_resolve_object(union acpi_operand_object **source_desc_ptr, | 
 | 69 | 		       acpi_object_type target_type, | 
 | 70 | 		       struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | 	union acpi_operand_object *source_desc = *source_desc_ptr; | 
 | 73 | 	acpi_status status = AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 75 | 	ACPI_FUNCTION_TRACE(ex_resolve_object); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 77 | 	/* Ensure we have a Target that can be stored to */ | 
 | 78 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | 	switch (target_type) { | 
 | 80 | 	case ACPI_TYPE_BUFFER_FIELD: | 
 | 81 | 	case ACPI_TYPE_LOCAL_REGION_FIELD: | 
 | 82 | 	case ACPI_TYPE_LOCAL_BANK_FIELD: | 
 | 83 | 	case ACPI_TYPE_LOCAL_INDEX_FIELD: | 
 | 84 | 		/* | 
 | 85 | 		 * These cases all require only Integers or values that | 
 | 86 | 		 * can be converted to Integers (Strings or Buffers) | 
 | 87 | 		 */ | 
 | 88 |  | 
 | 89 | 	case ACPI_TYPE_INTEGER: | 
 | 90 | 	case ACPI_TYPE_STRING: | 
 | 91 | 	case ACPI_TYPE_BUFFER: | 
 | 92 |  | 
 | 93 | 		/* | 
 | 94 | 		 * Stores into a Field/Region or into a Integer/Buffer/String | 
 | 95 | 		 * are all essentially the same.  This case handles the | 
 | 96 | 		 * "interchangeable" types Integer, String, and Buffer. | 
 | 97 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | 		if (ACPI_GET_OBJECT_TYPE(source_desc) == | 
 | 99 | 		    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 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | 		if ((ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) && | 
 | 120 | 		    (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) && | 
 | 121 | 		    (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) && | 
 | 122 | 		    !((ACPI_GET_OBJECT_TYPE(source_desc) == | 
 | 123 | 		       ACPI_TYPE_LOCAL_REFERENCE) | 
 | 124 | 		      && (source_desc->reference.opcode == AML_LOAD_OP))) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 125 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 126 | 			/* Conversion successful but still not a valid type */ | 
 | 127 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 128 | 			ACPI_ERROR((AE_INFO, | 
 | 129 | 				    "Cannot assign type %s to %s (must be type Int/Str/Buf)", | 
 | 130 | 				    acpi_ut_get_object_type_name(source_desc), | 
 | 131 | 				    acpi_ut_get_type_name(target_type))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | 			status = AE_AML_OPERAND_TYPE; | 
 | 133 | 		} | 
 | 134 | 		break; | 
 | 135 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | 	case ACPI_TYPE_LOCAL_ALIAS: | 
 | 137 | 	case ACPI_TYPE_LOCAL_METHOD_ALIAS: | 
 | 138 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 139 | 		/* | 
 | 140 | 		 * All aliases should have been resolved earlier, during the | 
 | 141 | 		 * operand resolution phase. | 
 | 142 | 		 */ | 
 | 143 | 		ACPI_ERROR((AE_INFO, "Store into an unresolved Alias object")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | 		status = AE_AML_INTERNAL; | 
 | 145 | 		break; | 
 | 146 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | 	case ACPI_TYPE_PACKAGE: | 
 | 148 | 	default: | 
 | 149 |  | 
 | 150 | 		/* | 
 | 151 | 		 * All other types than Alias and the various Fields come here, | 
 | 152 | 		 * including the untyped case - ACPI_TYPE_ANY. | 
 | 153 | 		 */ | 
 | 154 | 		break; | 
 | 155 | 	} | 
 | 156 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } | 
 | 159 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /******************************************************************************* | 
 | 161 |  * | 
 | 162 |  * FUNCTION:    acpi_ex_store_object_to_object | 
 | 163 |  * | 
 | 164 |  * PARAMETERS:  source_desc         - Object to store | 
 | 165 |  *              dest_desc           - Object to receive a copy of the source | 
 | 166 |  *              new_desc            - New object if dest_desc is obsoleted | 
 | 167 |  *              walk_state          - Current walk state | 
 | 168 |  * | 
 | 169 |  * RETURN:      Status | 
 | 170 |  * | 
 | 171 |  * DESCRIPTION: "Store" an object to another object.  This may include | 
 | 172 |  *              converting the source type to the target type (implicit | 
 | 173 |  *              conversion), and a copy of the value of the source to | 
 | 174 |  *              the target. | 
 | 175 |  * | 
 | 176 |  *              The Assignment of an object to another (not named) object | 
 | 177 |  *              is handled here. | 
 | 178 |  *              The Source passed in will replace the current value (if any) | 
 | 179 |  *              with the input value. | 
 | 180 |  * | 
 | 181 |  *              When storing into an object the data is converted to the | 
 | 182 |  *              target object type then stored in the object.  This means | 
 | 183 |  *              that the target object type (for an initialized target) will | 
 | 184 |  *              not be changed by a store operation. | 
 | 185 |  * | 
 | 186 |  *              This module allows destination types of Number, String, | 
 | 187 |  *              Buffer, and Package. | 
 | 188 |  * | 
 | 189 |  *              Assumes parameters are already validated.  NOTE: source_desc | 
 | 190 |  *              resolution (from a reference object) must be performed by | 
 | 191 |  *              the caller if necessary. | 
 | 192 |  * | 
 | 193 |  ******************************************************************************/ | 
 | 194 |  | 
 | 195 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | acpi_ex_store_object_to_object(union acpi_operand_object *source_desc, | 
 | 197 | 			       union acpi_operand_object *dest_desc, | 
 | 198 | 			       union acpi_operand_object **new_desc, | 
 | 199 | 			       struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | 	union acpi_operand_object *actual_src_desc; | 
 | 202 | 	acpi_status status = AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 204 | 	ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_object, source_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 |  | 
 | 206 | 	actual_src_desc = source_desc; | 
 | 207 | 	if (!dest_desc) { | 
 | 208 | 		/* | 
 | 209 | 		 * There is no destination object (An uninitialized node or | 
 | 210 | 		 * package element), so we can simply copy the source object | 
 | 211 | 		 * creating a new destination object | 
 | 212 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | 		status = | 
 | 214 | 		    acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc, | 
 | 215 | 						    walk_state); | 
 | 216 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | 	} | 
 | 218 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | 	if (ACPI_GET_OBJECT_TYPE(source_desc) != | 
 | 220 | 	    ACPI_GET_OBJECT_TYPE(dest_desc)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | 		/* | 
 | 222 | 		 * The source type does not match the type of the destination. | 
 | 223 | 		 * Perform the "implicit conversion" of the source to the current type | 
 | 224 | 		 * of the target as per the ACPI specification. | 
 | 225 | 		 * | 
 | 226 | 		 * If no conversion performed, actual_src_desc = source_desc. | 
 | 227 | 		 * Otherwise, actual_src_desc is a temporary object to hold the | 
 | 228 | 		 * converted object. | 
 | 229 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | 		status = | 
 | 231 | 		    acpi_ex_convert_to_target_type(ACPI_GET_OBJECT_TYPE | 
 | 232 | 						   (dest_desc), source_desc, | 
 | 233 | 						   &actual_src_desc, | 
 | 234 | 						   walk_state); | 
 | 235 | 		if (ACPI_FAILURE(status)) { | 
 | 236 | 			return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | 		} | 
 | 238 |  | 
 | 239 | 		if (source_desc == actual_src_desc) { | 
 | 240 | 			/* | 
 | 241 | 			 * No conversion was performed. Return the source_desc as the | 
 | 242 | 			 * new object. | 
 | 243 | 			 */ | 
 | 244 | 			*new_desc = source_desc; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | 			return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | 		} | 
 | 247 | 	} | 
 | 248 |  | 
 | 249 | 	/* | 
 | 250 | 	 * We now have two objects of identical types, and we can perform a | 
 | 251 | 	 * copy of the *value* of the source object. | 
 | 252 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | 	switch (ACPI_GET_OBJECT_TYPE(dest_desc)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | 	case ACPI_TYPE_INTEGER: | 
 | 255 |  | 
 | 256 | 		dest_desc->integer.value = actual_src_desc->integer.value; | 
 | 257 |  | 
 | 258 | 		/* Truncate value if we are executing from a 32-bit ACPI table */ | 
 | 259 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | 		acpi_ex_truncate_for32bit_table(dest_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | 		break; | 
 | 262 |  | 
 | 263 | 	case ACPI_TYPE_STRING: | 
 | 264 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 265 | 		status = | 
 | 266 | 		    acpi_ex_store_string_to_string(actual_src_desc, dest_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | 		break; | 
 | 268 |  | 
 | 269 | 	case ACPI_TYPE_BUFFER: | 
 | 270 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | 		status = | 
 | 272 | 		    acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | 		break; | 
 | 274 |  | 
 | 275 | 	case ACPI_TYPE_PACKAGE: | 
 | 276 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 277 | 		status = | 
 | 278 | 		    acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc, | 
 | 279 | 						    walk_state); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | 		break; | 
 | 281 |  | 
 | 282 | 	default: | 
 | 283 | 		/* | 
 | 284 | 		 * All other types come here. | 
 | 285 | 		 */ | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 286 | 		ACPI_WARNING((AE_INFO, "Store into type %s not implemented", | 
 | 287 | 			      acpi_ut_get_object_type_name(dest_desc))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 |  | 
 | 289 | 		status = AE_NOT_IMPLEMENTED; | 
 | 290 | 		break; | 
 | 291 | 	} | 
 | 292 |  | 
 | 293 | 	if (actual_src_desc != source_desc) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 294 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | 		/* Delete the intermediate (temporary) source object */ | 
 | 296 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | 		acpi_ut_remove_reference(actual_src_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | 	} | 
 | 299 |  | 
 | 300 | 	*new_desc = dest_desc; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 301 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } |