exstore.c 17 KB

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