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