PageRenderTime 68ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/acpi/acpica/exstore.c

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