exstore.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /******************************************************************************
  2. *
  3. * Module Name: exstore - AML Interpreter object store support
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/acdispat.h>
  44. #include <acpi/acinterp.h>
  45. #include <acpi/amlcode.h>
  46. #include <acpi/acnamesp.h>
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME ("exstore")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_ex_store
  52. *
  53. * PARAMETERS: *source_desc - Value to be stored
  54. * *dest_desc - Where to store it. Must be an NS node
  55. * or an union acpi_operand_object of type
  56. * Reference;
  57. * walk_state - Current walk state
  58. *
  59. * RETURN: Status
  60. *
  61. * DESCRIPTION: Store the value described by source_desc into the location
  62. * described by dest_desc. Called by various interpreter
  63. * functions to store the result of an operation into
  64. * the destination operand -- not just simply the actual "Store"
  65. * ASL operator.
  66. *
  67. ******************************************************************************/
  68. acpi_status
  69. acpi_ex_store (
  70. union acpi_operand_object *source_desc,
  71. union acpi_operand_object *dest_desc,
  72. struct acpi_walk_state *walk_state)
  73. {
  74. acpi_status status = AE_OK;
  75. union acpi_operand_object *ref_desc = dest_desc;
  76. ACPI_FUNCTION_TRACE_PTR ("ex_store", dest_desc);
  77. /* Validate parameters */
  78. if (!source_desc || !dest_desc) {
  79. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null parameter\n"));
  80. return_ACPI_STATUS (AE_AML_NO_OPERAND);
  81. }
  82. /* dest_desc can be either a namespace node or an ACPI object */
  83. if (ACPI_GET_DESCRIPTOR_TYPE (dest_desc) == ACPI_DESC_TYPE_NAMED) {
  84. /*
  85. * Dest is a namespace node,
  86. * Storing an object into a Named node.
  87. */
  88. status = acpi_ex_store_object_to_node (source_desc,
  89. (struct acpi_namespace_node *) dest_desc, walk_state,
  90. ACPI_IMPLICIT_CONVERSION);
  91. return_ACPI_STATUS (status);
  92. }
  93. /* Destination object must be a Reference or a Constant object */
  94. switch (ACPI_GET_OBJECT_TYPE (dest_desc)) {
  95. case ACPI_TYPE_LOCAL_REFERENCE:
  96. break;
  97. case ACPI_TYPE_INTEGER:
  98. /* Allow stores to Constants -- a Noop as per ACPI spec */
  99. if (dest_desc->common.flags & AOPOBJ_AML_CONSTANT) {
  100. return_ACPI_STATUS (AE_OK);
  101. }
  102. /*lint -fallthrough */
  103. default:
  104. /* Destination is not a Reference object */
  105. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  106. "Target is not a Reference or Constant object - %s [%p]\n",
  107. acpi_ut_get_object_type_name (dest_desc), dest_desc));
  108. ACPI_DUMP_STACK_ENTRY (source_desc);
  109. ACPI_DUMP_STACK_ENTRY (dest_desc);
  110. ACPI_DUMP_OPERANDS (&dest_desc, ACPI_IMODE_EXECUTE, "ex_store",
  111. 2, "Target is not a Reference or Constant object");
  112. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  113. }
  114. /*
  115. * Examine the Reference opcode. These cases are handled:
  116. *
  117. * 1) Store to Name (Change the object associated with a name)
  118. * 2) Store to an indexed area of a Buffer or Package
  119. * 3) Store to a Method Local or Arg
  120. * 4) Store to the debug object
  121. */
  122. switch (ref_desc->reference.opcode) {
  123. case AML_NAME_OP:
  124. case AML_REF_OF_OP:
  125. /* Storing an object into a Name "container" */
  126. status = acpi_ex_store_object_to_node (source_desc, ref_desc->reference.object,
  127. walk_state, ACPI_IMPLICIT_CONVERSION);
  128. break;
  129. case AML_INDEX_OP:
  130. /* Storing to an Index (pointer into a packager or buffer) */
  131. status = acpi_ex_store_object_to_index (source_desc, ref_desc, walk_state);
  132. break;
  133. case AML_LOCAL_OP:
  134. case AML_ARG_OP:
  135. /* Store to a method local/arg */
  136. status = acpi_ds_store_object_to_local (ref_desc->reference.opcode,
  137. ref_desc->reference.offset, source_desc, walk_state);
  138. break;
  139. case AML_DEBUG_OP:
  140. /*
  141. * Storing to the Debug object causes the value stored to be
  142. * displayed and otherwise has no effect -- see ACPI Specification
  143. */
  144. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  145. "**** Write to Debug Object: Object %p %s ****:\n\n",
  146. source_desc, acpi_ut_get_object_type_name (source_desc)));
  147. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %s: ",
  148. acpi_ut_get_object_type_name (source_desc)));
  149. if (!acpi_ut_valid_internal_object (source_desc)) {
  150. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT,
  151. "%p, Invalid Internal Object!\n", source_desc));
  152. break;
  153. }
  154. switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
  155. case ACPI_TYPE_INTEGER:
  156. if (acpi_gbl_integer_byte_width == 4) {
  157. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
  158. (u32) source_desc->integer.value));
  159. }
  160. else {
  161. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n",
  162. ACPI_FORMAT_UINT64 (source_desc->integer.value)));
  163. }
  164. break;
  165. case ACPI_TYPE_BUFFER:
  166. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]",
  167. (u32) source_desc->buffer.length));
  168. ACPI_DUMP_BUFFER (source_desc->buffer.pointer,
  169. (source_desc->buffer.length < 32) ? source_desc->buffer.length : 32);
  170. break;
  171. case ACPI_TYPE_STRING:
  172. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
  173. source_desc->string.length, source_desc->string.pointer));
  174. break;
  175. case ACPI_TYPE_PACKAGE:
  176. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] Elements Ptr - %p\n",
  177. source_desc->package.count, source_desc->package.elements));
  178. break;
  179. default:
  180. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p\n",
  181. source_desc));
  182. break;
  183. }
  184. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
  185. break;
  186. default:
  187. ACPI_REPORT_ERROR (("ex_store: Unknown Reference opcode %X\n",
  188. ref_desc->reference.opcode));
  189. ACPI_DUMP_ENTRY (ref_desc, ACPI_LV_ERROR);
  190. status = AE_AML_INTERNAL;
  191. break;
  192. }
  193. return_ACPI_STATUS (status);
  194. }
  195. /*******************************************************************************
  196. *
  197. * FUNCTION: acpi_ex_store_object_to_index
  198. *
  199. * PARAMETERS: *source_desc - Value to be stored
  200. * *dest_desc - Named object to receive the value
  201. * walk_state - Current walk state
  202. *
  203. * RETURN: Status
  204. *
  205. * DESCRIPTION: Store the object to indexed Buffer or Package element
  206. *
  207. ******************************************************************************/
  208. acpi_status
  209. acpi_ex_store_object_to_index (
  210. union acpi_operand_object *source_desc,
  211. union acpi_operand_object *index_desc,
  212. struct acpi_walk_state *walk_state)
  213. {
  214. acpi_status status = AE_OK;
  215. union acpi_operand_object *obj_desc;
  216. union acpi_operand_object *new_desc;
  217. u8 value = 0;
  218. u32 i;
  219. ACPI_FUNCTION_TRACE ("ex_store_object_to_index");
  220. /*
  221. * Destination must be a reference pointer, and
  222. * must point to either a buffer or a package
  223. */
  224. switch (index_desc->reference.target_type) {
  225. case ACPI_TYPE_PACKAGE:
  226. /*
  227. * Storing to a package element. Copy the object and replace
  228. * any existing object with the new object. No implicit
  229. * conversion is performed.
  230. *
  231. * The object at *(index_desc->Reference.Where) is the
  232. * element within the package that is to be modified.
  233. * The parent package object is at index_desc->Reference.Object
  234. */
  235. obj_desc = *(index_desc->reference.where);
  236. status = acpi_ut_copy_iobject_to_iobject (source_desc, &new_desc, walk_state);
  237. if (ACPI_FAILURE (status)) {
  238. return_ACPI_STATUS (status);
  239. }
  240. if (obj_desc) {
  241. /* Decrement reference count by the ref count of the parent package */
  242. for (i = 0; i < ((union acpi_operand_object *) index_desc->reference.object)->common.reference_count; i++) {
  243. acpi_ut_remove_reference (obj_desc);
  244. }
  245. }
  246. *(index_desc->reference.where) = new_desc;
  247. /* Increment reference count by the ref count of the parent package -1 */
  248. for (i = 1; i < ((union acpi_operand_object *) index_desc->reference.object)->common.reference_count; i++) {
  249. acpi_ut_add_reference (new_desc);
  250. }
  251. break;
  252. case ACPI_TYPE_BUFFER_FIELD:
  253. /*
  254. * Store into a Buffer or String (not actually a real buffer_field)
  255. * at a location defined by an Index.
  256. *
  257. * The first 8-bit element of the source object is written to the
  258. * 8-bit Buffer location defined by the Index destination object,
  259. * according to the ACPI 2.0 specification.
  260. */
  261. /*
  262. * Make sure the target is a Buffer or String. An error should
  263. * not happen here, since the reference_object was constructed
  264. * by the INDEX_OP code.
  265. */
  266. obj_desc = index_desc->reference.object;
  267. if ((ACPI_GET_OBJECT_TYPE (obj_desc) != ACPI_TYPE_BUFFER) &&
  268. (ACPI_GET_OBJECT_TYPE (obj_desc) != ACPI_TYPE_STRING)) {
  269. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  270. }
  271. /*
  272. * The assignment of the individual elements will be slightly
  273. * different for each source type.
  274. */
  275. switch (ACPI_GET_OBJECT_TYPE (source_desc)) {
  276. case ACPI_TYPE_INTEGER:
  277. /* Use the least-significant byte of the integer */
  278. value = (u8) (source_desc->integer.value);
  279. break;
  280. case ACPI_TYPE_BUFFER:
  281. case ACPI_TYPE_STRING:
  282. /* Note: Takes advantage of common string/buffer fields */
  283. value = source_desc->buffer.pointer[0];
  284. break;
  285. default:
  286. /* All other types are invalid */
  287. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  288. "Source must be Integer/Buffer/String type, not %s\n",
  289. acpi_ut_get_object_type_name (source_desc)));
  290. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  291. }
  292. /* Store the source value into the target buffer byte */
  293. obj_desc->buffer.pointer[index_desc->reference.offset] = value;
  294. break;
  295. default:
  296. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  297. "Target is not a Package or buffer_field\n"));
  298. status = AE_AML_OPERAND_TYPE;
  299. break;
  300. }
  301. return_ACPI_STATUS (status);
  302. }
  303. /*******************************************************************************
  304. *
  305. * FUNCTION: acpi_ex_store_object_to_node
  306. *
  307. * PARAMETERS: source_desc - Value to be stored
  308. * Node - Named object to receive the value
  309. * walk_state - Current walk state
  310. * implicit_conversion - Perform implicit conversion (yes/no)
  311. *
  312. * RETURN: Status
  313. *
  314. * DESCRIPTION: Store the object to the named object.
  315. *
  316. * The Assignment of an object to a named object is handled here
  317. * The value passed in will replace the current value (if any)
  318. * with the input value.
  319. *
  320. * When storing into an object the data is converted to the
  321. * target object type then stored in the object. This means
  322. * that the target object type (for an initialized target) will
  323. * not be changed by a store operation.
  324. *
  325. * Assumes parameters are already validated.
  326. *
  327. ******************************************************************************/
  328. acpi_status
  329. acpi_ex_store_object_to_node (
  330. union acpi_operand_object *source_desc,
  331. struct acpi_namespace_node *node,
  332. struct acpi_walk_state *walk_state,
  333. u8 implicit_conversion)
  334. {
  335. acpi_status status = AE_OK;
  336. union acpi_operand_object *target_desc;
  337. union acpi_operand_object *new_desc;
  338. acpi_object_type target_type;
  339. ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_node", source_desc);
  340. /*
  341. * Get current type of the node, and object attached to Node
  342. */
  343. target_type = acpi_ns_get_type (node);
  344. target_desc = acpi_ns_get_attached_object (node);
  345. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
  346. source_desc, acpi_ut_get_object_type_name (source_desc),
  347. node, acpi_ut_get_type_name (target_type)));
  348. /*
  349. * Resolve the source object to an actual value
  350. * (If it is a reference object)
  351. */
  352. status = acpi_ex_resolve_object (&source_desc, target_type, walk_state);
  353. if (ACPI_FAILURE (status)) {
  354. return_ACPI_STATUS (status);
  355. }
  356. /* If no implicit conversion, drop into the default case below */
  357. if (!implicit_conversion) {
  358. /* Force execution of default (no implicit conversion) */
  359. target_type = ACPI_TYPE_ANY;
  360. }
  361. /*
  362. * Do the actual store operation
  363. */
  364. switch (target_type) {
  365. case ACPI_TYPE_BUFFER_FIELD:
  366. case ACPI_TYPE_LOCAL_REGION_FIELD:
  367. case ACPI_TYPE_LOCAL_BANK_FIELD:
  368. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  369. /*
  370. * For fields, copy the source data to the target field.
  371. */
  372. status = acpi_ex_write_data_to_field (source_desc, target_desc, &walk_state->result_obj);
  373. break;
  374. case ACPI_TYPE_INTEGER:
  375. case ACPI_TYPE_STRING:
  376. case ACPI_TYPE_BUFFER:
  377. /*
  378. * These target types are all of type Integer/String/Buffer, and
  379. * therefore support implicit conversion before the store.
  380. *
  381. * Copy and/or convert the source object to a new target object
  382. */
  383. status = acpi_ex_store_object_to_object (source_desc, target_desc, &new_desc, walk_state);
  384. if (ACPI_FAILURE (status)) {
  385. return_ACPI_STATUS (status);
  386. }
  387. if (new_desc != target_desc) {
  388. /*
  389. * Store the new new_desc as the new value of the Name, and set
  390. * the Name's type to that of the value being stored in it.
  391. * source_desc reference count is incremented by attach_object.
  392. *
  393. * Note: This may change the type of the node if an explicit store
  394. * has been performed such that the node/object type has been
  395. * changed.
  396. */
  397. status = acpi_ns_attach_object (node, new_desc, new_desc->common.type);
  398. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  399. "Store %s into %s via Convert/Attach\n",
  400. acpi_ut_get_object_type_name (source_desc),
  401. acpi_ut_get_object_type_name (new_desc)));
  402. }
  403. break;
  404. default:
  405. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  406. "Storing %s (%p) directly into node (%p), no implicit conversion\n",
  407. acpi_ut_get_object_type_name (source_desc), source_desc, node));
  408. /* No conversions for all other types. Just attach the source object */
  409. status = acpi_ns_attach_object (node, source_desc, ACPI_GET_OBJECT_TYPE (source_desc));
  410. break;
  411. }
  412. return_ACPI_STATUS (status);
  413. }