dsargs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /******************************************************************************
  2. *
  3. * Module Name: dsargs - Support for execution of dynamic arguments for static
  4. * objects (regions, fields, buffer fields, etc.)
  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 "acparser.h"
  46. #include "amlcode.h"
  47. #include "acdispat.h"
  48. #include "acnamesp.h"
  49. #define _COMPONENT ACPI_DISPATCHER
  50. ACPI_MODULE_NAME("dsargs")
  51. /* Local prototypes */
  52. static acpi_status
  53. acpi_ds_execute_arguments(struct acpi_namespace_node *node,
  54. struct acpi_namespace_node *scope_node,
  55. u32 aml_length, u8 *aml_start);
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: acpi_ds_execute_arguments
  59. *
  60. * PARAMETERS: node - Object NS node
  61. * scope_node - Parent NS node
  62. * aml_length - Length of executable AML
  63. * aml_start - Pointer to the AML
  64. *
  65. * RETURN: Status.
  66. *
  67. * DESCRIPTION: Late (deferred) execution of region or field arguments
  68. *
  69. ******************************************************************************/
  70. static acpi_status
  71. acpi_ds_execute_arguments(struct acpi_namespace_node *node,
  72. struct acpi_namespace_node *scope_node,
  73. u32 aml_length, u8 *aml_start)
  74. {
  75. acpi_status status;
  76. union acpi_parse_object *op;
  77. struct acpi_walk_state *walk_state;
  78. ACPI_FUNCTION_TRACE(ds_execute_arguments);
  79. /* Allocate a new parser op to be the root of the parsed tree */
  80. op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP, aml_start);
  81. if (!op) {
  82. return_ACPI_STATUS(AE_NO_MEMORY);
  83. }
  84. /* Save the Node for use in acpi_ps_parse_aml */
  85. op->common.node = scope_node;
  86. /* Create and initialize a new parser state */
  87. walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
  88. if (!walk_state) {
  89. status = AE_NO_MEMORY;
  90. goto cleanup;
  91. }
  92. status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
  93. aml_length, NULL, ACPI_IMODE_LOAD_PASS1);
  94. if (ACPI_FAILURE(status)) {
  95. acpi_ds_delete_walk_state(walk_state);
  96. goto cleanup;
  97. }
  98. /* Mark this parse as a deferred opcode */
  99. walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
  100. walk_state->deferred_node = node;
  101. /* Pass1: Parse the entire declaration */
  102. status = acpi_ps_parse_aml(walk_state);
  103. if (ACPI_FAILURE(status)) {
  104. goto cleanup;
  105. }
  106. /* Get and init the Op created above */
  107. op->common.node = node;
  108. acpi_ps_delete_parse_tree(op);
  109. /* Evaluate the deferred arguments */
  110. op = acpi_ps_alloc_op(AML_INT_EVAL_SUBTREE_OP, aml_start);
  111. if (!op) {
  112. return_ACPI_STATUS(AE_NO_MEMORY);
  113. }
  114. op->common.node = scope_node;
  115. /* Create and initialize a new parser state */
  116. walk_state = acpi_ds_create_walk_state(0, NULL, NULL, NULL);
  117. if (!walk_state) {
  118. status = AE_NO_MEMORY;
  119. goto cleanup;
  120. }
  121. /* Execute the opcode and arguments */
  122. status = acpi_ds_init_aml_walk(walk_state, op, NULL, aml_start,
  123. aml_length, NULL, ACPI_IMODE_EXECUTE);
  124. if (ACPI_FAILURE(status)) {
  125. acpi_ds_delete_walk_state(walk_state);
  126. goto cleanup;
  127. }
  128. /* Mark this execution as a deferred opcode */
  129. walk_state->deferred_node = node;
  130. status = acpi_ps_parse_aml(walk_state);
  131. cleanup:
  132. acpi_ps_delete_parse_tree(op);
  133. return_ACPI_STATUS(status);
  134. }
  135. /*******************************************************************************
  136. *
  137. * FUNCTION: acpi_ds_get_buffer_field_arguments
  138. *
  139. * PARAMETERS: obj_desc - A valid buffer_field object
  140. *
  141. * RETURN: Status.
  142. *
  143. * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
  144. * evaluation of these field attributes.
  145. *
  146. ******************************************************************************/
  147. acpi_status
  148. acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc)
  149. {
  150. union acpi_operand_object *extra_desc;
  151. struct acpi_namespace_node *node;
  152. acpi_status status;
  153. ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_field_arguments, obj_desc);
  154. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  155. return_ACPI_STATUS(AE_OK);
  156. }
  157. /* Get the AML pointer (method object) and buffer_field node */
  158. extra_desc = acpi_ns_get_secondary_object(obj_desc);
  159. node = obj_desc->buffer_field.node;
  160. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname(ACPI_TYPE_BUFFER_FIELD,
  161. node, NULL));
  162. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
  163. acpi_ut_get_node_name(node)));
  164. /* Execute the AML code for the term_arg arguments */
  165. status = acpi_ds_execute_arguments(node, node->parent,
  166. extra_desc->extra.aml_length,
  167. extra_desc->extra.aml_start);
  168. return_ACPI_STATUS(status);
  169. }
  170. /*******************************************************************************
  171. *
  172. * FUNCTION: acpi_ds_get_bank_field_arguments
  173. *
  174. * PARAMETERS: obj_desc - A valid bank_field object
  175. *
  176. * RETURN: Status.
  177. *
  178. * DESCRIPTION: Get bank_field bank_value. This implements the late
  179. * evaluation of these field attributes.
  180. *
  181. ******************************************************************************/
  182. acpi_status
  183. acpi_ds_get_bank_field_arguments(union acpi_operand_object *obj_desc)
  184. {
  185. union acpi_operand_object *extra_desc;
  186. struct acpi_namespace_node *node;
  187. acpi_status status;
  188. ACPI_FUNCTION_TRACE_PTR(ds_get_bank_field_arguments, obj_desc);
  189. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  190. return_ACPI_STATUS(AE_OK);
  191. }
  192. /* Get the AML pointer (method object) and bank_field node */
  193. extra_desc = acpi_ns_get_secondary_object(obj_desc);
  194. node = obj_desc->bank_field.node;
  195. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  196. (ACPI_TYPE_LOCAL_BANK_FIELD, node, NULL));
  197. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n",
  198. acpi_ut_get_node_name(node)));
  199. /* Execute the AML code for the term_arg arguments */
  200. status = acpi_ds_execute_arguments(node, node->parent,
  201. extra_desc->extra.aml_length,
  202. extra_desc->extra.aml_start);
  203. if (ACPI_FAILURE(status)) {
  204. return_ACPI_STATUS(status);
  205. }
  206. status = acpi_ut_add_address_range(obj_desc->region.space_id,
  207. obj_desc->region.address,
  208. obj_desc->region.length, node);
  209. return_ACPI_STATUS(status);
  210. }
  211. /*******************************************************************************
  212. *
  213. * FUNCTION: acpi_ds_get_buffer_arguments
  214. *
  215. * PARAMETERS: obj_desc - A valid Buffer object
  216. *
  217. * RETURN: Status.
  218. *
  219. * DESCRIPTION: Get Buffer length and initializer byte list. This implements
  220. * the late evaluation of these attributes.
  221. *
  222. ******************************************************************************/
  223. acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc)
  224. {
  225. struct acpi_namespace_node *node;
  226. acpi_status status;
  227. ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments, obj_desc);
  228. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  229. return_ACPI_STATUS(AE_OK);
  230. }
  231. /* Get the Buffer node */
  232. node = obj_desc->buffer.node;
  233. if (!node) {
  234. ACPI_ERROR((AE_INFO,
  235. "No pointer back to namespace node in buffer object %p",
  236. obj_desc));
  237. return_ACPI_STATUS(AE_AML_INTERNAL);
  238. }
  239. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n"));
  240. /* Execute the AML code for the term_arg arguments */
  241. status = acpi_ds_execute_arguments(node, node,
  242. obj_desc->buffer.aml_length,
  243. obj_desc->buffer.aml_start);
  244. return_ACPI_STATUS(status);
  245. }
  246. /*******************************************************************************
  247. *
  248. * FUNCTION: acpi_ds_get_package_arguments
  249. *
  250. * PARAMETERS: obj_desc - A valid Package object
  251. *
  252. * RETURN: Status.
  253. *
  254. * DESCRIPTION: Get Package length and initializer byte list. This implements
  255. * the late evaluation of these attributes.
  256. *
  257. ******************************************************************************/
  258. acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc)
  259. {
  260. struct acpi_namespace_node *node;
  261. acpi_status status;
  262. ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments, obj_desc);
  263. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  264. return_ACPI_STATUS(AE_OK);
  265. }
  266. /* Get the Package node */
  267. node = obj_desc->package.node;
  268. if (!node) {
  269. ACPI_ERROR((AE_INFO,
  270. "No pointer back to namespace node in package %p",
  271. obj_desc));
  272. return_ACPI_STATUS(AE_AML_INTERNAL);
  273. }
  274. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n"));
  275. /* Execute the AML code for the term_arg arguments */
  276. status = acpi_ds_execute_arguments(node, node,
  277. obj_desc->package.aml_length,
  278. obj_desc->package.aml_start);
  279. return_ACPI_STATUS(status);
  280. }
  281. /*******************************************************************************
  282. *
  283. * FUNCTION: acpi_ds_get_region_arguments
  284. *
  285. * PARAMETERS: obj_desc - A valid region object
  286. *
  287. * RETURN: Status.
  288. *
  289. * DESCRIPTION: Get region address and length. This implements the late
  290. * evaluation of these region attributes.
  291. *
  292. ******************************************************************************/
  293. acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc)
  294. {
  295. struct acpi_namespace_node *node;
  296. acpi_status status;
  297. union acpi_operand_object *extra_desc;
  298. ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments, obj_desc);
  299. if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
  300. return_ACPI_STATUS(AE_OK);
  301. }
  302. extra_desc = acpi_ns_get_secondary_object(obj_desc);
  303. if (!extra_desc) {
  304. return_ACPI_STATUS(AE_NOT_EXIST);
  305. }
  306. /* Get the Region node */
  307. node = obj_desc->region.node;
  308. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  309. (ACPI_TYPE_REGION, node, NULL));
  310. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
  311. acpi_ut_get_node_name(node),
  312. extra_desc->extra.aml_start));
  313. /* Execute the argument AML */
  314. status = acpi_ds_execute_arguments(node, extra_desc->extra.scope_node,
  315. extra_desc->extra.aml_length,
  316. extra_desc->extra.aml_start);
  317. if (ACPI_FAILURE(status)) {
  318. return_ACPI_STATUS(status);
  319. }
  320. status = acpi_ut_add_address_range(obj_desc->region.space_id,
  321. obj_desc->region.address,
  322. obj_desc->region.length, node);
  323. return_ACPI_STATUS(status);
  324. }