exstoren.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /******************************************************************************
  2. *
  3. * Module Name: exstoren - AML Interpreter object store support,
  4. * Store to Node (namespace object)
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2015, 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 "accommon.h"
  45. #include "acinterp.h"
  46. #include "amlcode.h"
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME("exstoren")
  49. /*******************************************************************************
  50. *
  51. * FUNCTION: acpi_ex_resolve_object
  52. *
  53. * PARAMETERS: source_desc_ptr - Pointer to the source object
  54. * target_type - Current type of the target
  55. * walk_state - Current walk state
  56. *
  57. * RETURN: Status, resolved object in source_desc_ptr.
  58. *
  59. * DESCRIPTION: Resolve an object. If the object is a reference, dereference
  60. * it and return the actual object in the source_desc_ptr.
  61. *
  62. ******************************************************************************/
  63. acpi_status
  64. acpi_ex_resolve_object(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 (source_desc->common.type == 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 ((source_desc->common.type != ACPI_TYPE_INTEGER) &&
  104. (source_desc->common.type != ACPI_TYPE_BUFFER) &&
  105. (source_desc->common.type != ACPI_TYPE_STRING) &&
  106. !((source_desc->common.type == ACPI_TYPE_LOCAL_REFERENCE) &&
  107. (source_desc->reference.class == ACPI_REFCLASS_TABLE))) {
  108. /* Conversion successful but still not a valid type */
  109. ACPI_ERROR((AE_INFO,
  110. "Cannot assign type [%s] to [%s] (must be type Int/Str/Buf)",
  111. acpi_ut_get_object_type_name(source_desc),
  112. acpi_ut_get_type_name(target_type)));
  113. status = AE_AML_OPERAND_TYPE;
  114. }
  115. break;
  116. case ACPI_TYPE_LOCAL_ALIAS:
  117. case ACPI_TYPE_LOCAL_METHOD_ALIAS:
  118. /*
  119. * All aliases should have been resolved earlier, during the
  120. * operand resolution phase.
  121. */
  122. ACPI_ERROR((AE_INFO, "Store into an unresolved Alias object"));
  123. status = AE_AML_INTERNAL;
  124. break;
  125. case ACPI_TYPE_PACKAGE:
  126. default:
  127. /*
  128. * All other types than Alias and the various Fields come here,
  129. * including the untyped case - ACPI_TYPE_ANY.
  130. */
  131. break;
  132. }
  133. return_ACPI_STATUS(status);
  134. }
  135. /*******************************************************************************
  136. *
  137. * FUNCTION: acpi_ex_store_object_to_object
  138. *
  139. * PARAMETERS: source_desc - Object to store
  140. * dest_desc - Object to receive a copy of the source
  141. * new_desc - New object if dest_desc is obsoleted
  142. * walk_state - Current walk state
  143. *
  144. * RETURN: Status
  145. *
  146. * DESCRIPTION: "Store" an object to another object. This may include
  147. * converting the source type to the target type (implicit
  148. * conversion), and a copy of the value of the source to
  149. * the target.
  150. *
  151. * The Assignment of an object to another (not named) object
  152. * is handled here.
  153. * The Source passed in will replace the current value (if any)
  154. * with the input value.
  155. *
  156. * When storing into an object the data is converted to the
  157. * target object type then stored in the object. This means
  158. * that the target object type (for an initialized target) will
  159. * not be changed by a store operation.
  160. *
  161. * This module allows destination types of Number, String,
  162. * Buffer, and Package.
  163. *
  164. * Assumes parameters are already validated. NOTE: source_desc
  165. * resolution (from a reference object) must be performed by
  166. * the caller if necessary.
  167. *
  168. ******************************************************************************/
  169. acpi_status
  170. acpi_ex_store_object_to_object(union acpi_operand_object *source_desc,
  171. union acpi_operand_object *dest_desc,
  172. union acpi_operand_object **new_desc,
  173. struct acpi_walk_state *walk_state)
  174. {
  175. union acpi_operand_object *actual_src_desc;
  176. acpi_status status = AE_OK;
  177. ACPI_FUNCTION_TRACE_PTR(ex_store_object_to_object, source_desc);
  178. actual_src_desc = source_desc;
  179. if (!dest_desc) {
  180. /*
  181. * There is no destination object (An uninitialized node or
  182. * package element), so we can simply copy the source object
  183. * creating a new destination object
  184. */
  185. status =
  186. acpi_ut_copy_iobject_to_iobject(actual_src_desc, new_desc,
  187. walk_state);
  188. return_ACPI_STATUS(status);
  189. }
  190. if (source_desc->common.type != dest_desc->common.type) {
  191. /*
  192. * The source type does not match the type of the destination.
  193. * Perform the "implicit conversion" of the source to the current type
  194. * of the target as per the ACPI specification.
  195. *
  196. * If no conversion performed, actual_src_desc = source_desc.
  197. * Otherwise, actual_src_desc is a temporary object to hold the
  198. * converted object.
  199. */
  200. status = acpi_ex_convert_to_target_type(dest_desc->common.type,
  201. source_desc,
  202. &actual_src_desc,
  203. walk_state);
  204. if (ACPI_FAILURE(status)) {
  205. return_ACPI_STATUS(status);
  206. }
  207. if (source_desc == actual_src_desc) {
  208. /*
  209. * No conversion was performed. Return the source_desc as the
  210. * new object.
  211. */
  212. *new_desc = source_desc;
  213. return_ACPI_STATUS(AE_OK);
  214. }
  215. }
  216. /*
  217. * We now have two objects of identical types, and we can perform a
  218. * copy of the *value* of the source object.
  219. */
  220. switch (dest_desc->common.type) {
  221. case ACPI_TYPE_INTEGER:
  222. dest_desc->integer.value = actual_src_desc->integer.value;
  223. /* Truncate value if we are executing from a 32-bit ACPI table */
  224. (void)acpi_ex_truncate_for32bit_table(dest_desc);
  225. break;
  226. case ACPI_TYPE_STRING:
  227. status =
  228. acpi_ex_store_string_to_string(actual_src_desc, dest_desc);
  229. break;
  230. case ACPI_TYPE_BUFFER:
  231. status =
  232. acpi_ex_store_buffer_to_buffer(actual_src_desc, dest_desc);
  233. break;
  234. case ACPI_TYPE_PACKAGE:
  235. status =
  236. acpi_ut_copy_iobject_to_iobject(actual_src_desc, &dest_desc,
  237. walk_state);
  238. break;
  239. default:
  240. /*
  241. * All other types come here.
  242. */
  243. ACPI_WARNING((AE_INFO, "Store into type [%s] not implemented",
  244. acpi_ut_get_object_type_name(dest_desc)));
  245. status = AE_NOT_IMPLEMENTED;
  246. break;
  247. }
  248. if (actual_src_desc != source_desc) {
  249. /* Delete the intermediate (temporary) source object */
  250. acpi_ut_remove_reference(actual_src_desc);
  251. }
  252. *new_desc = dest_desc;
  253. return_ACPI_STATUS(status);
  254. }