exstoren.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /******************************************************************************
  2. *
  3. * Module Name: exstoren - AML Interpreter object store support,
  4. * Store to Node (namespace object)
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2005, R. Byron Moore
  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. #include <acpi/acpi.h>
  44. #include <acpi/acinterp.h>
  45. #include <acpi/amlcode.h>
  46. #define _COMPONENT ACPI_EXECUTER
  47. ACPI_MODULE_NAME ("exstoren")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_ex_resolve_object
  51. *
  52. * PARAMETERS: source_desc_ptr - Pointer to the source object
  53. * target_type - Current type of the target
  54. * walk_state - Current walk state
  55. *
  56. * RETURN: Status, resolved object in source_desc_ptr.
  57. *
  58. * DESCRIPTION: Resolve an object. If the object is a reference, dereference
  59. * it and return the actual object in the source_desc_ptr.
  60. *
  61. ******************************************************************************/
  62. acpi_status
  63. acpi_ex_resolve_object (
  64. union acpi_operand_object **source_desc_ptr,
  65. acpi_object_type target_type,
  66. struct acpi_walk_state *walk_state)
  67. {
  68. union acpi_operand_object *source_desc = *source_desc_ptr;
  69. acpi_status status = AE_OK;
  70. ACPI_FUNCTION_TRACE ("ex_resolve_object");
  71. /* Ensure we have a Target that can be stored to */
  72. switch (target_type) {
  73. case ACPI_TYPE_BUFFER_FIELD:
  74. case ACPI_TYPE_LOCAL_REGION_FIELD:
  75. case ACPI_TYPE_LOCAL_BANK_FIELD:
  76. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  77. /*
  78. * These cases all require only Integers or values that
  79. * can be converted to Integers (Strings or Buffers)
  80. */
  81. case ACPI_TYPE_INTEGER:
  82. case ACPI_TYPE_STRING:
  83. case ACPI_TYPE_BUFFER:
  84. /*
  85. * Stores into a Field/Region or into a Integer/Buffer/String
  86. * are all essentially the same. This case handles the
  87. * "interchangeable" types Integer, String, and Buffer.
  88. */
  89. if (ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_LOCAL_REFERENCE) {
  90. /* Resolve a reference object first */
  91. status = acpi_ex_resolve_to_value (source_desc_ptr, walk_state);
  92. if (ACPI_FAILURE (status)) {
  93. break;
  94. }
  95. }
  96. /* For copy_object, no further validation necessary */
  97. if (walk_state->opcode == AML_COPY_OP) {
  98. break;
  99. }
  100. /* Must have a Integer, Buffer, or String */
  101. if ((ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_INTEGER) &&
  102. (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_BUFFER) &&
  103. (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_TYPE_STRING) &&
  104. !((ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_LOCAL_REFERENCE) && (source_desc->reference.opcode == AML_LOAD_OP))) {
  105. /* Conversion successful but still not a valid type */
  106. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  107. "Cannot assign type %s to %s (must be type Int/Str/Buf)\n",
  108. acpi_ut_get_object_type_name (source_desc),
  109. acpi_ut_get_type_name (target_type)));
  110. status = AE_AML_OPERAND_TYPE;
  111. }
  112. break;
  113. case ACPI_TYPE_LOCAL_ALIAS:
  114. case ACPI_TYPE_LOCAL_METHOD_ALIAS:
  115. /* Aliases are resolved by acpi_ex_prep_operands */
  116. ACPI_REPORT_ERROR (("Store into Alias - should never happen\n"));
  117. status = AE_AML_INTERNAL;
  118. break;
  119. case ACPI_TYPE_PACKAGE:
  120. default:
  121. /*
  122. * All other types than Alias and the various Fields come here,
  123. * including the untyped case - ACPI_TYPE_ANY.
  124. */
  125. break;
  126. }
  127. return_ACPI_STATUS (status);
  128. }
  129. /*******************************************************************************
  130. *
  131. * FUNCTION: acpi_ex_store_object_to_object
  132. *
  133. * PARAMETERS: source_desc - Object to store
  134. * dest_desc - Object to receive a copy of the source
  135. * new_desc - New object if dest_desc is obsoleted
  136. * walk_state - Current walk state
  137. *
  138. * RETURN: Status
  139. *
  140. * DESCRIPTION: "Store" an object to another object. This may include
  141. * converting the source type to the target type (implicit
  142. * conversion), and a copy of the value of the source to
  143. * the target.
  144. *
  145. * The Assignment of an object to another (not named) object
  146. * is handled here.
  147. * The Source passed in will replace the current value (if any)
  148. * with the input value.
  149. *
  150. * When storing into an object the data is converted to the
  151. * target object type then stored in the object. This means
  152. * that the target object type (for an initialized target) will
  153. * not be changed by a store operation.
  154. *
  155. * This module allows destination types of Number, String,
  156. * Buffer, and Package.
  157. *
  158. * Assumes parameters are already validated. NOTE: source_desc
  159. * resolution (from a reference object) must be performed by
  160. * the caller if necessary.
  161. *
  162. ******************************************************************************/
  163. acpi_status
  164. acpi_ex_store_object_to_object (
  165. union acpi_operand_object *source_desc,
  166. union acpi_operand_object *dest_desc,
  167. union acpi_operand_object **new_desc,
  168. struct acpi_walk_state *walk_state)
  169. {
  170. union acpi_operand_object *actual_src_desc;
  171. acpi_status status = AE_OK;
  172. ACPI_FUNCTION_TRACE_PTR ("ex_store_object_to_object", source_desc);
  173. actual_src_desc = source_desc;
  174. if (!dest_desc) {
  175. /*
  176. * There is no destination object (An uninitialized node or
  177. * package element), so we can simply copy the source object
  178. * creating a new destination object
  179. */
  180. status = acpi_ut_copy_iobject_to_iobject (actual_src_desc, new_desc, walk_state);
  181. return_ACPI_STATUS (status);
  182. }
  183. if (ACPI_GET_OBJECT_TYPE (source_desc) != ACPI_GET_OBJECT_TYPE (dest_desc)) {
  184. /*
  185. * The source type does not match the type of the destination.
  186. * Perform the "implicit conversion" of the source to the current type
  187. * of the target as per the ACPI specification.
  188. *
  189. * If no conversion performed, actual_src_desc = source_desc.
  190. * Otherwise, actual_src_desc is a temporary object to hold the
  191. * converted object.
  192. */
  193. status = acpi_ex_convert_to_target_type (ACPI_GET_OBJECT_TYPE (dest_desc),
  194. source_desc, &actual_src_desc, walk_state);
  195. if (ACPI_FAILURE (status)) {
  196. return_ACPI_STATUS (status);
  197. }
  198. if (source_desc == actual_src_desc) {
  199. /*
  200. * No conversion was performed. Return the source_desc as the
  201. * new object.
  202. */
  203. *new_desc = source_desc;
  204. return_ACPI_STATUS (AE_OK);
  205. }
  206. }
  207. /*
  208. * We now have two objects of identical types, and we can perform a
  209. * copy of the *value* of the source object.
  210. */
  211. switch (ACPI_GET_OBJECT_TYPE (dest_desc)) {
  212. case ACPI_TYPE_INTEGER:
  213. dest_desc->integer.value = actual_src_desc->integer.value;
  214. /* Truncate value if we are executing from a 32-bit ACPI table */
  215. acpi_ex_truncate_for32bit_table (dest_desc);
  216. break;
  217. case ACPI_TYPE_STRING:
  218. status = acpi_ex_store_string_to_string (actual_src_desc, dest_desc);
  219. break;
  220. case ACPI_TYPE_BUFFER:
  221. /*
  222. * Note: There is different store behavior depending on the original
  223. * source type
  224. */
  225. status = acpi_ex_store_buffer_to_buffer (actual_src_desc, dest_desc);
  226. break;
  227. case ACPI_TYPE_PACKAGE:
  228. status = acpi_ut_copy_iobject_to_iobject (actual_src_desc, &dest_desc,
  229. walk_state);
  230. break;
  231. default:
  232. /*
  233. * All other types come here.
  234. */
  235. ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Store into type %s not implemented\n",
  236. acpi_ut_get_object_type_name (dest_desc)));
  237. status = AE_NOT_IMPLEMENTED;
  238. break;
  239. }
  240. if (actual_src_desc != source_desc) {
  241. /* Delete the intermediate (temporary) source object */
  242. acpi_ut_remove_reference (actual_src_desc);
  243. }
  244. *new_desc = dest_desc;
  245. return_ACPI_STATUS (status);
  246. }