dsargs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 - 2011, 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);
  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);
  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. return_ACPI_STATUS(status);
  204. }
  205. /*******************************************************************************
  206. *
  207. * FUNCTION: acpi_ds_get_buffer_arguments
  208. *
  209. * PARAMETERS: obj_desc - A valid Buffer object
  210. *
  211. * RETURN: Status.
  212. *
  213. * DESCRIPTION: Get Buffer length and initializer byte list. This implements
  214. * the late evaluation of these attributes.
  215. *
  216. ******************************************************************************/
  217. acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc)
  218. {
  219. struct acpi_namespace_node *node;
  220. acpi_status status;
  221. ACPI_FUNCTION_TRACE_PTR(ds_get_buffer_arguments, obj_desc);
  222. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  223. return_ACPI_STATUS(AE_OK);
  224. }
  225. /* Get the Buffer node */
  226. node = obj_desc->buffer.node;
  227. if (!node) {
  228. ACPI_ERROR((AE_INFO,
  229. "No pointer back to namespace node in buffer object %p",
  230. obj_desc));
  231. return_ACPI_STATUS(AE_AML_INTERNAL);
  232. }
  233. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Buffer Arg Init\n"));
  234. /* Execute the AML code for the term_arg arguments */
  235. status = acpi_ds_execute_arguments(node, node,
  236. obj_desc->buffer.aml_length,
  237. obj_desc->buffer.aml_start);
  238. return_ACPI_STATUS(status);
  239. }
  240. /*******************************************************************************
  241. *
  242. * FUNCTION: acpi_ds_get_package_arguments
  243. *
  244. * PARAMETERS: obj_desc - A valid Package object
  245. *
  246. * RETURN: Status.
  247. *
  248. * DESCRIPTION: Get Package length and initializer byte list. This implements
  249. * the late evaluation of these attributes.
  250. *
  251. ******************************************************************************/
  252. acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc)
  253. {
  254. struct acpi_namespace_node *node;
  255. acpi_status status;
  256. ACPI_FUNCTION_TRACE_PTR(ds_get_package_arguments, obj_desc);
  257. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  258. return_ACPI_STATUS(AE_OK);
  259. }
  260. /* Get the Package node */
  261. node = obj_desc->package.node;
  262. if (!node) {
  263. ACPI_ERROR((AE_INFO,
  264. "No pointer back to namespace node in package %p",
  265. obj_desc));
  266. return_ACPI_STATUS(AE_AML_INTERNAL);
  267. }
  268. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Package Arg Init\n"));
  269. /* Execute the AML code for the term_arg arguments */
  270. status = acpi_ds_execute_arguments(node, node,
  271. obj_desc->package.aml_length,
  272. obj_desc->package.aml_start);
  273. return_ACPI_STATUS(status);
  274. }
  275. /*******************************************************************************
  276. *
  277. * FUNCTION: acpi_ds_get_region_arguments
  278. *
  279. * PARAMETERS: obj_desc - A valid region object
  280. *
  281. * RETURN: Status.
  282. *
  283. * DESCRIPTION: Get region address and length. This implements the late
  284. * evaluation of these region attributes.
  285. *
  286. ******************************************************************************/
  287. acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *obj_desc)
  288. {
  289. struct acpi_namespace_node *node;
  290. acpi_status status;
  291. union acpi_operand_object *extra_desc;
  292. ACPI_FUNCTION_TRACE_PTR(ds_get_region_arguments, obj_desc);
  293. if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
  294. return_ACPI_STATUS(AE_OK);
  295. }
  296. extra_desc = acpi_ns_get_secondary_object(obj_desc);
  297. if (!extra_desc) {
  298. return_ACPI_STATUS(AE_NOT_EXIST);
  299. }
  300. /* Get the Region node */
  301. node = obj_desc->region.node;
  302. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
  303. (ACPI_TYPE_REGION, node, NULL));
  304. ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] OpRegion Arg Init at AML %p\n",
  305. acpi_ut_get_node_name(node),
  306. extra_desc->extra.aml_start));
  307. /* Execute the argument AML */
  308. status = acpi_ds_execute_arguments(node, extra_desc->extra.scope_node,
  309. extra_desc->extra.aml_length,
  310. extra_desc->extra.aml_start);
  311. if (ACPI_FAILURE(status)) {
  312. return_ACPI_STATUS(status);
  313. }
  314. /* Validate the region address/length via the host OS */
  315. status = acpi_os_validate_address(obj_desc->region.space_id,
  316. obj_desc->region.address,
  317. (acpi_size) obj_desc->region.length,
  318. acpi_ut_get_node_name(node));
  319. if (ACPI_FAILURE(status)) {
  320. /*
  321. * Invalid address/length. We will emit an error message and mark
  322. * the region as invalid, so that it will cause an additional error if
  323. * it is ever used. Then return AE_OK.
  324. */
  325. ACPI_EXCEPTION((AE_INFO, status,
  326. "During address validation of OpRegion [%4.4s]",
  327. node->name.ascii));
  328. obj_desc->common.flags |= AOPOBJ_INVALID;
  329. status = AE_OK;
  330. }
  331. return_ACPI_STATUS(status);
  332. }