| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** | 
 | 2 |  * | 
 | 3 |  * Module Name: exstore - AML Interpreter object store support | 
 | 4 |  * | 
 | 5 |  *****************************************************************************/ | 
 | 6 |  | 
 | 7 | /* | 
| Bob Moore | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame] | 8 |  * Copyright (C) 2000 - 2012, Intel Corp. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> | 
| Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" | 
 | 46 | #include "acdispat.h" | 
 | 47 | #include "acinterp.h" | 
 | 48 | #include "amlcode.h" | 
 | 49 | #include "acnamesp.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("exstore") | 
| 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_ex_store_object_to_index(union acpi_operand_object *val_desc, | 
 | 57 | 			      union acpi_operand_object *dest_desc, | 
 | 58 | 			      struct acpi_walk_state *walk_state); | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 59 |  | 
 | 60 | /******************************************************************************* | 
 | 61 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 |  * FUNCTION:    acpi_ex_store | 
 | 63 |  * | 
 | 64 |  * PARAMETERS:  *source_desc        - Value to be stored | 
 | 65 |  *              *dest_desc          - Where to store it.  Must be an NS node | 
| Frederik Schwarzer | 0211a9c | 2008-12-29 22:14:56 +0100 | [diff] [blame] | 66 |  *                                    or a union acpi_operand_object of type | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 |  *                                    Reference; | 
 | 68 |  *              walk_state          - Current walk state | 
 | 69 |  * | 
 | 70 |  * RETURN:      Status | 
 | 71 |  * | 
 | 72 |  * DESCRIPTION: Store the value described by source_desc into the location | 
 | 73 |  *              described by dest_desc. Called by various interpreter | 
 | 74 |  *              functions to store the result of an operation into | 
 | 75 |  *              the destination operand -- not just simply the actual "Store" | 
 | 76 |  *              ASL operator. | 
 | 77 |  * | 
 | 78 |  ******************************************************************************/ | 
 | 79 |  | 
 | 80 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | acpi_ex_store(union acpi_operand_object *source_desc, | 
 | 82 | 	      union acpi_operand_object *dest_desc, | 
 | 83 | 	      struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | 	acpi_status status = AE_OK; | 
 | 86 | 	union acpi_operand_object *ref_desc = dest_desc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 88 | 	ACPI_FUNCTION_TRACE_PTR(ex_store, dest_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 |  | 
 | 90 | 	/* Validate parameters */ | 
 | 91 |  | 
 | 92 | 	if (!source_desc || !dest_desc) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 93 | 		ACPI_ERROR((AE_INFO, "Null parameter")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | 		return_ACPI_STATUS(AE_AML_NO_OPERAND); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | 	} | 
 | 96 |  | 
 | 97 | 	/* dest_desc can be either a namespace node or an ACPI object */ | 
 | 98 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | 	if (ACPI_GET_DESCRIPTOR_TYPE(dest_desc) == ACPI_DESC_TYPE_NAMED) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | 		/* | 
 | 101 | 		 * Dest is a namespace node, | 
 | 102 | 		 * Storing an object into a Named node. | 
 | 103 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | 		status = acpi_ex_store_object_to_node(source_desc, | 
 | 105 | 						      (struct | 
 | 106 | 						       acpi_namespace_node *) | 
 | 107 | 						      dest_desc, walk_state, | 
 | 108 | 						      ACPI_IMPLICIT_CONVERSION); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | 	} | 
 | 112 |  | 
 | 113 | 	/* Destination object must be a Reference or a Constant object */ | 
 | 114 |  | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 115 | 	switch (dest_desc->common.type) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | 	case ACPI_TYPE_LOCAL_REFERENCE: | 
 | 117 | 		break; | 
 | 118 |  | 
 | 119 | 	case ACPI_TYPE_INTEGER: | 
 | 120 |  | 
 | 121 | 		/* Allow stores to Constants -- a Noop as per ACPI spec */ | 
 | 122 |  | 
 | 123 | 		if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | 			return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | 		} | 
 | 126 |  | 
 | 127 | 		/*lint -fallthrough */ | 
 | 128 |  | 
 | 129 | 	default: | 
 | 130 |  | 
 | 131 | 		/* Destination is not a Reference object */ | 
 | 132 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 133 | 		ACPI_ERROR((AE_INFO, | 
 | 134 | 			    "Target is not a Reference or Constant object - %s [%p]", | 
 | 135 | 			    acpi_ut_get_object_type_name(dest_desc), | 
 | 136 | 			    dest_desc)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | 		return_ACPI_STATUS(AE_AML_OPERAND_TYPE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | 	} | 
 | 140 |  | 
 | 141 | 	/* | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 142 | 	 * Examine the Reference class. These cases are handled: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | 	 * | 
 | 144 | 	 * 1) Store to Name (Change the object associated with a name) | 
 | 145 | 	 * 2) Store to an indexed area of a Buffer or Package | 
 | 146 | 	 * 3) Store to a Method Local or Arg | 
 | 147 | 	 * 4) Store to the debug object | 
 | 148 | 	 */ | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 149 | 	switch (ref_desc->reference.class) { | 
 | 150 | 	case ACPI_REFCLASS_REFOF: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 |  | 
 | 152 | 		/* Storing an object into a Name "container" */ | 
 | 153 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | 		status = acpi_ex_store_object_to_node(source_desc, | 
 | 155 | 						      ref_desc->reference. | 
 | 156 | 						      object, walk_state, | 
 | 157 | 						      ACPI_IMPLICIT_CONVERSION); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | 		break; | 
 | 159 |  | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 160 | 	case ACPI_REFCLASS_INDEX: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 |  | 
 | 162 | 		/* Storing to an Index (pointer into a packager or buffer) */ | 
 | 163 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | 		status = | 
 | 165 | 		    acpi_ex_store_object_to_index(source_desc, ref_desc, | 
 | 166 | 						  walk_state); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | 		break; | 
 | 168 |  | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 169 | 	case ACPI_REFCLASS_LOCAL: | 
 | 170 | 	case ACPI_REFCLASS_ARG: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 |  | 
 | 172 | 		/* Store to a method local/arg  */ | 
 | 173 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | 		status = | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 175 | 		    acpi_ds_store_object_to_local(ref_desc->reference.class, | 
 | 176 | 						  ref_desc->reference.value, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | 						  source_desc, walk_state); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | 		break; | 
 | 179 |  | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 180 | 	case ACPI_REFCLASS_DEBUG: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 |  | 
 | 182 | 		/* | 
 | 183 | 		 * Storing to the Debug object causes the value stored to be | 
 | 184 | 		 * displayed and otherwise has no effect -- see ACPI Specification | 
 | 185 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | 		ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 
 | 187 | 				  "**** Write to Debug Object: Object %p %s ****:\n\n", | 
 | 188 | 				  source_desc, | 
 | 189 | 				  acpi_ut_get_object_type_name(source_desc))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 |  | 
| Lin Ming | 4cdf1a5 | 2010-03-03 16:28:28 +0800 | [diff] [blame] | 191 | 		ACPI_DEBUG_OBJECT(source_desc, 0, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | 		break; | 
 | 193 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | 	default: | 
 | 195 |  | 
| Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 196 | 		ACPI_ERROR((AE_INFO, "Unknown Reference Class 0x%2.2X", | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 197 | 			    ref_desc->reference.class)); | 
| Bob Moore | 23d3e05 | 2008-09-28 15:00:47 +0800 | [diff] [blame] | 198 | 		ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_INFO); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 |  | 
 | 200 | 		status = AE_AML_INTERNAL; | 
 | 201 | 		break; | 
 | 202 | 	} | 
 | 203 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } | 
 | 206 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | /******************************************************************************* | 
 | 208 |  * | 
 | 209 |  * FUNCTION:    acpi_ex_store_object_to_index | 
 | 210 |  * | 
 | 211 |  * PARAMETERS:  *source_desc            - Value to be stored | 
 | 212 |  *              *dest_desc              - Named object to receive the value | 
 | 213 |  *              walk_state              - Current walk state | 
 | 214 |  * | 
 | 215 |  * RETURN:      Status | 
 | 216 |  * | 
 | 217 |  * DESCRIPTION: Store the object to indexed Buffer or Package element | 
 | 218 |  * | 
 | 219 |  ******************************************************************************/ | 
 | 220 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 221 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 222 | acpi_ex_store_object_to_index(union acpi_operand_object *source_desc, | 
 | 223 | 			      union acpi_operand_object *index_desc, | 
 | 224 | 			      struct acpi_walk_state *walk_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 226 | 	acpi_status status = AE_OK; | 
 | 227 | 	union acpi_operand_object *obj_desc; | 
 | 228 | 	union acpi_operand_object *new_desc; | 
 | 229 | 	u8 value = 0; | 
 | 230 | 	u32 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 232 | 	ACPI_FUNCTION_TRACE(ex_store_object_to_index); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 |  | 
 | 234 | 	/* | 
 | 235 | 	 * Destination must be a reference pointer, and | 
 | 236 | 	 * must point to either a buffer or a package | 
 | 237 | 	 */ | 
 | 238 | 	switch (index_desc->reference.target_type) { | 
 | 239 | 	case ACPI_TYPE_PACKAGE: | 
 | 240 | 		/* | 
 | 241 | 		 * Storing to a package element. Copy the object and replace | 
 | 242 | 		 * any existing object with the new object. No implicit | 
 | 243 | 		 * conversion is performed. | 
 | 244 | 		 * | 
 | 245 | 		 * The object at *(index_desc->Reference.Where) is the | 
 | 246 | 		 * element within the package that is to be modified. | 
 | 247 | 		 * The parent package object is at index_desc->Reference.Object | 
 | 248 | 		 */ | 
 | 249 | 		obj_desc = *(index_desc->reference.where); | 
 | 250 |  | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 251 | 		if (source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE && | 
 | 252 | 		    source_desc->reference.class == ACPI_REFCLASS_TABLE) { | 
| Lin Ming | bc7a36a | 2008-04-10 19:06:42 +0400 | [diff] [blame] | 253 |  | 
 | 254 | 			/* This is a DDBHandle, just add a reference to it */ | 
 | 255 |  | 
 | 256 | 			acpi_ut_add_reference(source_desc); | 
 | 257 | 			new_desc = source_desc; | 
 | 258 | 		} else { | 
 | 259 | 			/* Normal object, copy it */ | 
 | 260 |  | 
 | 261 | 			status = | 
 | 262 | 			    acpi_ut_copy_iobject_to_iobject(source_desc, | 
 | 263 | 							    &new_desc, | 
 | 264 | 							    walk_state); | 
 | 265 | 			if (ACPI_FAILURE(status)) { | 
 | 266 | 				return_ACPI_STATUS(status); | 
 | 267 | 			} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | 		} | 
 | 269 |  | 
 | 270 | 		if (obj_desc) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 271 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | 			/* Decrement reference count by the ref count of the parent package */ | 
 | 273 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | 			for (i = 0; i < ((union acpi_operand_object *) | 
 | 275 | 					 index_desc->reference.object)->common. | 
 | 276 | 			     reference_count; i++) { | 
 | 277 | 				acpi_ut_remove_reference(obj_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | 			} | 
 | 279 | 		} | 
 | 280 |  | 
 | 281 | 		*(index_desc->reference.where) = new_desc; | 
 | 282 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 283 | 		/* Increment ref count by the ref count of the parent package-1 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | 		for (i = 1; i < ((union acpi_operand_object *) | 
 | 286 | 				 index_desc->reference.object)->common. | 
 | 287 | 		     reference_count; i++) { | 
 | 288 | 			acpi_ut_add_reference(new_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | 		} | 
 | 290 |  | 
 | 291 | 		break; | 
 | 292 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | 	case ACPI_TYPE_BUFFER_FIELD: | 
 | 294 |  | 
 | 295 | 		/* | 
 | 296 | 		 * Store into a Buffer or String (not actually a real buffer_field) | 
 | 297 | 		 * at a location defined by an Index. | 
 | 298 | 		 * | 
 | 299 | 		 * The first 8-bit element of the source object is written to the | 
 | 300 | 		 * 8-bit Buffer location defined by the Index destination object, | 
 | 301 | 		 * according to the ACPI 2.0 specification. | 
 | 302 | 		 */ | 
 | 303 |  | 
 | 304 | 		/* | 
 | 305 | 		 * Make sure the target is a Buffer or String. An error should | 
 | 306 | 		 * not happen here, since the reference_object was constructed | 
 | 307 | 		 * by the INDEX_OP code. | 
 | 308 | 		 */ | 
 | 309 | 		obj_desc = index_desc->reference.object; | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 310 | 		if ((obj_desc->common.type != ACPI_TYPE_BUFFER) && | 
 | 311 | 		    (obj_desc->common.type != ACPI_TYPE_STRING)) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | 			return_ACPI_STATUS(AE_AML_OPERAND_TYPE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | 		} | 
 | 314 |  | 
 | 315 | 		/* | 
 | 316 | 		 * The assignment of the individual elements will be slightly | 
 | 317 | 		 * different for each source type. | 
 | 318 | 		 */ | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 319 | 		switch (source_desc->common.type) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | 		case ACPI_TYPE_INTEGER: | 
 | 321 |  | 
 | 322 | 			/* Use the least-significant byte of the integer */ | 
 | 323 |  | 
 | 324 | 			value = (u8) (source_desc->integer.value); | 
 | 325 | 			break; | 
 | 326 |  | 
 | 327 | 		case ACPI_TYPE_BUFFER: | 
 | 328 | 		case ACPI_TYPE_STRING: | 
 | 329 |  | 
 | 330 | 			/* Note: Takes advantage of common string/buffer fields */ | 
 | 331 |  | 
 | 332 | 			value = source_desc->buffer.pointer[0]; | 
 | 333 | 			break; | 
 | 334 |  | 
 | 335 | 		default: | 
 | 336 |  | 
 | 337 | 			/* All other types are invalid */ | 
 | 338 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 339 | 			ACPI_ERROR((AE_INFO, | 
 | 340 | 				    "Source must be Integer/Buffer/String type, not %s", | 
 | 341 | 				    acpi_ut_get_object_type_name(source_desc))); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | 			return_ACPI_STATUS(AE_AML_OPERAND_TYPE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | 		} | 
 | 344 |  | 
 | 345 | 		/* Store the source value into the target buffer byte */ | 
 | 346 |  | 
| Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 347 | 		obj_desc->buffer.pointer[index_desc->reference.value] = value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | 		break; | 
 | 349 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | 	default: | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 351 | 		ACPI_ERROR((AE_INFO, "Target is not a Package or BufferField")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | 		status = AE_AML_OPERAND_TYPE; | 
 | 353 | 		break; | 
 | 354 | 	} | 
 | 355 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 356 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } | 
 | 358 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | /******************************************************************************* | 
 | 360 |  * | 
 | 361 |  * FUNCTION:    acpi_ex_store_object_to_node | 
 | 362 |  * | 
 | 363 |  * PARAMETERS:  source_desc             - Value to be stored | 
 | 364 |  *              Node                    - Named object to receive the value | 
 | 365 |  *              walk_state              - Current walk state | 
 | 366 |  *              implicit_conversion     - Perform implicit conversion (yes/no) | 
 | 367 |  * | 
 | 368 |  * RETURN:      Status | 
 | 369 |  * | 
 | 370 |  * DESCRIPTION: Store the object to the named object. | 
 | 371 |  * | 
 | 372 |  *              The Assignment of an object to a named object is handled here | 
 | 373 |  *              The value passed in will replace the current value (if any) | 
 | 374 |  *              with the input value. | 
 | 375 |  * | 
 | 376 |  *              When storing into an object the data is converted to the | 
 | 377 |  *              target object type then stored in the object.  This means | 
 | 378 |  *              that the target object type (for an initialized target) will | 
 | 379 |  *              not be changed by a store operation. | 
 | 380 |  * | 
 | 381 |  *              Assumes parameters are already validated. | 
 | 382 |  * | 
 | 383 |  ******************************************************************************/ | 
 | 384 |  | 
 | 385 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | acpi_ex_store_object_to_node(union acpi_operand_object *source_desc, | 
 | 387 | 			     struct acpi_namespace_node *node, | 
 | 388 | 			     struct acpi_walk_state *walk_state, | 
 | 389 | 			     u8 implicit_conversion) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | 	acpi_status status = AE_OK; | 
 | 392 | 	union acpi_operand_object *target_desc; | 
 | 393 | 	union acpi_operand_object *new_desc; | 
 | 394 | 	acpi_object_type target_type; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 396 | 	ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_node, source_desc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 398 | 	/* Get current type of the node, and object attached to Node */ | 
 | 399 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | 	target_type = acpi_ns_get_type(node); | 
 | 401 | 	target_desc = acpi_ns_get_attached_object(node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | 	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n", | 
 | 404 | 			  source_desc, | 
 | 405 | 			  acpi_ut_get_object_type_name(source_desc), node, | 
 | 406 | 			  acpi_ut_get_type_name(target_type))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 |  | 
 | 408 | 	/* | 
 | 409 | 	 * Resolve the source object to an actual value | 
 | 410 | 	 * (If it is a reference object) | 
 | 411 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | 	status = acpi_ex_resolve_object(&source_desc, target_type, walk_state); | 
 | 413 | 	if (ACPI_FAILURE(status)) { | 
 | 414 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | 	} | 
 | 416 |  | 
 | 417 | 	/* If no implicit conversion, drop into the default case below */ | 
 | 418 |  | 
| Lin Ming | a3df4da | 2008-04-10 19:06:43 +0400 | [diff] [blame] | 419 | 	if ((!implicit_conversion) || | 
 | 420 | 	    ((walk_state->opcode == AML_COPY_OP) && | 
 | 421 | 	     (target_type != ACPI_TYPE_LOCAL_REGION_FIELD) && | 
 | 422 | 	     (target_type != ACPI_TYPE_LOCAL_BANK_FIELD) && | 
 | 423 | 	     (target_type != ACPI_TYPE_LOCAL_INDEX_FIELD))) { | 
 | 424 | 		/* | 
 | 425 | 		 * Force execution of default (no implicit conversion). Note: | 
 | 426 | 		 * copy_object does not perform an implicit conversion, as per the ACPI | 
 | 427 | 		 * spec -- except in case of region/bank/index fields -- because these | 
 | 428 | 		 * objects must retain their original type permanently. | 
 | 429 | 		 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | 		target_type = ACPI_TYPE_ANY; | 
 | 431 | 	} | 
 | 432 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 433 | 	/* Do the actual store operation */ | 
 | 434 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | 	switch (target_type) { | 
 | 436 | 	case ACPI_TYPE_BUFFER_FIELD: | 
 | 437 | 	case ACPI_TYPE_LOCAL_REGION_FIELD: | 
 | 438 | 	case ACPI_TYPE_LOCAL_BANK_FIELD: | 
 | 439 | 	case ACPI_TYPE_LOCAL_INDEX_FIELD: | 
 | 440 |  | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 441 | 		/* For fields, copy the source data to the target field. */ | 
 | 442 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 443 | 		status = acpi_ex_write_data_to_field(source_desc, target_desc, | 
 | 444 | 						     &walk_state->result_obj); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | 		break; | 
 | 446 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | 	case ACPI_TYPE_INTEGER: | 
 | 448 | 	case ACPI_TYPE_STRING: | 
 | 449 | 	case ACPI_TYPE_BUFFER: | 
 | 450 |  | 
 | 451 | 		/* | 
 | 452 | 		 * These target types are all of type Integer/String/Buffer, and | 
 | 453 | 		 * therefore support implicit conversion before the store. | 
 | 454 | 		 * | 
 | 455 | 		 * Copy and/or convert the source object to a new target object | 
 | 456 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | 		status = | 
 | 458 | 		    acpi_ex_store_object_to_object(source_desc, target_desc, | 
 | 459 | 						   &new_desc, walk_state); | 
 | 460 | 		if (ACPI_FAILURE(status)) { | 
 | 461 | 			return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | 		} | 
 | 463 |  | 
 | 464 | 		if (new_desc != target_desc) { | 
 | 465 | 			/* | 
 | 466 | 			 * Store the new new_desc as the new value of the Name, and set | 
 | 467 | 			 * the Name's type to that of the value being stored in it. | 
 | 468 | 			 * source_desc reference count is incremented by attach_object. | 
 | 469 | 			 * | 
 | 470 | 			 * Note: This may change the type of the node if an explicit store | 
 | 471 | 			 * has been performed such that the node/object type has been | 
 | 472 | 			 * changed. | 
 | 473 | 			 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 474 | 			status = | 
 | 475 | 			    acpi_ns_attach_object(node, new_desc, | 
 | 476 | 						  new_desc->common.type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 478 | 			ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 
 | 479 | 					  "Store %s into %s via Convert/Attach\n", | 
 | 480 | 					  acpi_ut_get_object_type_name | 
 | 481 | 					  (source_desc), | 
 | 482 | 					  acpi_ut_get_object_type_name | 
 | 483 | 					  (new_desc))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | 		} | 
 | 485 | 		break; | 
 | 486 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | 	default: | 
 | 488 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 489 | 		ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 
 | 490 | 				  "Storing %s (%p) directly into node (%p) with no implicit conversion\n", | 
 | 491 | 				  acpi_ut_get_object_type_name(source_desc), | 
 | 492 | 				  source_desc, node)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 |  | 
 | 494 | 		/* No conversions for all other types.  Just attach the source object */ | 
 | 495 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 496 | 		status = acpi_ns_attach_object(node, source_desc, | 
| Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 497 | 					       source_desc->common.type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | 		break; | 
 | 499 | 	} | 
 | 500 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 501 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } |