dsopcode.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. /******************************************************************************
  2. *
  3. * Module Name: dsopcode - Dispatcher Op Region support and handling of
  4. * "control" opcodes
  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/acparser.h>
  45. #include <acpi/amlcode.h>
  46. #include <acpi/acdispat.h>
  47. #include <acpi/acinterp.h>
  48. #include <acpi/acnamesp.h>
  49. #include <acpi/acevents.h>
  50. #define _COMPONENT ACPI_DISPATCHER
  51. ACPI_MODULE_NAME ("dsopcode")
  52. /* Local prototypes */
  53. static acpi_status
  54. acpi_ds_execute_arguments (
  55. struct acpi_namespace_node *node,
  56. struct acpi_namespace_node *scope_node,
  57. u32 aml_length,
  58. u8 *aml_start);
  59. static acpi_status
  60. acpi_ds_init_buffer_field (
  61. u16 aml_opcode,
  62. union acpi_operand_object *obj_desc,
  63. union acpi_operand_object *buffer_desc,
  64. union acpi_operand_object *offset_desc,
  65. union acpi_operand_object *length_desc,
  66. union acpi_operand_object *result_desc);
  67. /*******************************************************************************
  68. *
  69. * FUNCTION: acpi_ds_execute_arguments
  70. *
  71. * PARAMETERS: Node - Object NS node
  72. * scope_node - Parent NS node
  73. * aml_length - Length of executable AML
  74. * aml_start - Pointer to the AML
  75. *
  76. * RETURN: Status.
  77. *
  78. * DESCRIPTION: Late (deferred) execution of region or field arguments
  79. *
  80. ******************************************************************************/
  81. static acpi_status
  82. acpi_ds_execute_arguments (
  83. struct acpi_namespace_node *node,
  84. struct acpi_namespace_node *scope_node,
  85. u32 aml_length,
  86. u8 *aml_start)
  87. {
  88. acpi_status status;
  89. union acpi_parse_object *op;
  90. struct acpi_walk_state *walk_state;
  91. ACPI_FUNCTION_TRACE ("ds_execute_arguments");
  92. /*
  93. * Allocate a new parser op to be the root of the parsed tree
  94. */
  95. op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP);
  96. if (!op) {
  97. return_ACPI_STATUS (AE_NO_MEMORY);
  98. }
  99. /* Save the Node for use in acpi_ps_parse_aml */
  100. op->common.node = scope_node;
  101. /* Create and initialize a new parser state */
  102. walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
  103. if (!walk_state) {
  104. return_ACPI_STATUS (AE_NO_MEMORY);
  105. }
  106. status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start,
  107. aml_length, NULL, 1);
  108. if (ACPI_FAILURE (status)) {
  109. acpi_ds_delete_walk_state (walk_state);
  110. return_ACPI_STATUS (status);
  111. }
  112. /* Mark this parse as a deferred opcode */
  113. walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP;
  114. walk_state->deferred_node = node;
  115. /* Pass1: Parse the entire declaration */
  116. status = acpi_ps_parse_aml (walk_state);
  117. if (ACPI_FAILURE (status)) {
  118. acpi_ps_delete_parse_tree (op);
  119. return_ACPI_STATUS (status);
  120. }
  121. /* Get and init the Op created above */
  122. op->common.node = node;
  123. acpi_ps_delete_parse_tree (op);
  124. /* Evaluate the deferred arguments */
  125. op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP);
  126. if (!op) {
  127. return_ACPI_STATUS (AE_NO_MEMORY);
  128. }
  129. op->common.node = scope_node;
  130. /* Create and initialize a new parser state */
  131. walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
  132. if (!walk_state) {
  133. return_ACPI_STATUS (AE_NO_MEMORY);
  134. }
  135. /* Execute the opcode and arguments */
  136. status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start,
  137. aml_length, NULL, 3);
  138. if (ACPI_FAILURE (status)) {
  139. acpi_ds_delete_walk_state (walk_state);
  140. return_ACPI_STATUS (status);
  141. }
  142. /* Mark this execution as a deferred opcode */
  143. walk_state->deferred_node = node;
  144. status = acpi_ps_parse_aml (walk_state);
  145. acpi_ps_delete_parse_tree (op);
  146. return_ACPI_STATUS (status);
  147. }
  148. /*******************************************************************************
  149. *
  150. * FUNCTION: acpi_ds_get_buffer_field_arguments
  151. *
  152. * PARAMETERS: obj_desc - A valid buffer_field object
  153. *
  154. * RETURN: Status.
  155. *
  156. * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late
  157. * evaluation of these field attributes.
  158. *
  159. ******************************************************************************/
  160. acpi_status
  161. acpi_ds_get_buffer_field_arguments (
  162. union acpi_operand_object *obj_desc)
  163. {
  164. union acpi_operand_object *extra_desc;
  165. struct acpi_namespace_node *node;
  166. acpi_status status;
  167. ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_field_arguments", obj_desc);
  168. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  169. return_ACPI_STATUS (AE_OK);
  170. }
  171. /* Get the AML pointer (method object) and buffer_field node */
  172. extra_desc = acpi_ns_get_secondary_object (obj_desc);
  173. node = obj_desc->buffer_field.node;
  174. ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_BUFFER_FIELD, node, NULL));
  175. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] buffer_field Arg Init\n",
  176. acpi_ut_get_node_name (node)));
  177. /* Execute the AML code for the term_arg arguments */
  178. status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node),
  179. extra_desc->extra.aml_length, extra_desc->extra.aml_start);
  180. return_ACPI_STATUS (status);
  181. }
  182. /*******************************************************************************
  183. *
  184. * FUNCTION: acpi_ds_get_buffer_arguments
  185. *
  186. * PARAMETERS: obj_desc - A valid Buffer object
  187. *
  188. * RETURN: Status.
  189. *
  190. * DESCRIPTION: Get Buffer length and initializer byte list. This implements
  191. * the late evaluation of these attributes.
  192. *
  193. ******************************************************************************/
  194. acpi_status
  195. acpi_ds_get_buffer_arguments (
  196. union acpi_operand_object *obj_desc)
  197. {
  198. struct acpi_namespace_node *node;
  199. acpi_status status;
  200. ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_arguments", obj_desc);
  201. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  202. return_ACPI_STATUS (AE_OK);
  203. }
  204. /* Get the Buffer node */
  205. node = obj_desc->buffer.node;
  206. if (!node) {
  207. ACPI_REPORT_ERROR ((
  208. "No pointer back to NS node in buffer obj %p\n", obj_desc));
  209. return_ACPI_STATUS (AE_AML_INTERNAL);
  210. }
  211. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
  212. /* Execute the AML code for the term_arg arguments */
  213. status = acpi_ds_execute_arguments (node, node,
  214. obj_desc->buffer.aml_length, obj_desc->buffer.aml_start);
  215. return_ACPI_STATUS (status);
  216. }
  217. /*******************************************************************************
  218. *
  219. * FUNCTION: acpi_ds_get_package_arguments
  220. *
  221. * PARAMETERS: obj_desc - A valid Package object
  222. *
  223. * RETURN: Status.
  224. *
  225. * DESCRIPTION: Get Package length and initializer byte list. This implements
  226. * the late evaluation of these attributes.
  227. *
  228. ******************************************************************************/
  229. acpi_status
  230. acpi_ds_get_package_arguments (
  231. union acpi_operand_object *obj_desc)
  232. {
  233. struct acpi_namespace_node *node;
  234. acpi_status status;
  235. ACPI_FUNCTION_TRACE_PTR ("ds_get_package_arguments", obj_desc);
  236. if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
  237. return_ACPI_STATUS (AE_OK);
  238. }
  239. /* Get the Package node */
  240. node = obj_desc->package.node;
  241. if (!node) {
  242. ACPI_REPORT_ERROR ((
  243. "No pointer back to NS node in package %p\n", obj_desc));
  244. return_ACPI_STATUS (AE_AML_INTERNAL);
  245. }
  246. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
  247. /* Execute the AML code for the term_arg arguments */
  248. status = acpi_ds_execute_arguments (node, node,
  249. obj_desc->package.aml_length, obj_desc->package.aml_start);
  250. return_ACPI_STATUS (status);
  251. }
  252. /*****************************************************************************
  253. *
  254. * FUNCTION: acpi_ds_get_region_arguments
  255. *
  256. * PARAMETERS: obj_desc - A valid region object
  257. *
  258. * RETURN: Status.
  259. *
  260. * DESCRIPTION: Get region address and length. This implements the late
  261. * evaluation of these region attributes.
  262. *
  263. ****************************************************************************/
  264. acpi_status
  265. acpi_ds_get_region_arguments (
  266. union acpi_operand_object *obj_desc)
  267. {
  268. struct acpi_namespace_node *node;
  269. acpi_status status;
  270. union acpi_operand_object *extra_desc;
  271. ACPI_FUNCTION_TRACE_PTR ("ds_get_region_arguments", obj_desc);
  272. if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
  273. return_ACPI_STATUS (AE_OK);
  274. }
  275. extra_desc = acpi_ns_get_secondary_object (obj_desc);
  276. if (!extra_desc) {
  277. return_ACPI_STATUS (AE_NOT_EXIST);
  278. }
  279. /* Get the Region node */
  280. node = obj_desc->region.node;
  281. ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_REGION, node, NULL));
  282. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] op_region Arg Init at AML %p\n",
  283. acpi_ut_get_node_name (node), extra_desc->extra.aml_start));
  284. /* Execute the argument AML */
  285. status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node),
  286. extra_desc->extra.aml_length, extra_desc->extra.aml_start);
  287. return_ACPI_STATUS (status);
  288. }
  289. /*******************************************************************************
  290. *
  291. * FUNCTION: acpi_ds_initialize_region
  292. *
  293. * PARAMETERS: obj_handle - Region namespace node
  294. *
  295. * RETURN: Status
  296. *
  297. * DESCRIPTION: Front end to ev_initialize_region
  298. *
  299. ******************************************************************************/
  300. acpi_status
  301. acpi_ds_initialize_region (
  302. acpi_handle obj_handle)
  303. {
  304. union acpi_operand_object *obj_desc;
  305. acpi_status status;
  306. obj_desc = acpi_ns_get_attached_object (obj_handle);
  307. /* Namespace is NOT locked */
  308. status = acpi_ev_initialize_region (obj_desc, FALSE);
  309. return (status);
  310. }
  311. /*******************************************************************************
  312. *
  313. * FUNCTION: acpi_ds_init_buffer_field
  314. *
  315. * PARAMETERS: aml_opcode - create_xxx_field
  316. * obj_desc - buffer_field object
  317. * buffer_desc - Host Buffer
  318. * offset_desc - Offset into buffer
  319. * length_desc - Length of field (CREATE_FIELD_OP only)
  320. * result_desc - Where to store the result
  321. *
  322. * RETURN: Status
  323. *
  324. * DESCRIPTION: Perform actual initialization of a buffer field
  325. *
  326. ******************************************************************************/
  327. static acpi_status
  328. acpi_ds_init_buffer_field (
  329. u16 aml_opcode,
  330. union acpi_operand_object *obj_desc,
  331. union acpi_operand_object *buffer_desc,
  332. union acpi_operand_object *offset_desc,
  333. union acpi_operand_object *length_desc,
  334. union acpi_operand_object *result_desc)
  335. {
  336. u32 offset;
  337. u32 bit_offset;
  338. u32 bit_count;
  339. u8 field_flags;
  340. acpi_status status;
  341. ACPI_FUNCTION_TRACE_PTR ("ds_init_buffer_field", obj_desc);
  342. /* Host object must be a Buffer */
  343. if (ACPI_GET_OBJECT_TYPE (buffer_desc) != ACPI_TYPE_BUFFER) {
  344. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  345. "Target of Create Field is not a Buffer object - %s\n",
  346. acpi_ut_get_object_type_name (buffer_desc)));
  347. status = AE_AML_OPERAND_TYPE;
  348. goto cleanup;
  349. }
  350. /*
  351. * The last parameter to all of these opcodes (result_desc) started
  352. * out as a name_string, and should therefore now be a NS node
  353. * after resolution in acpi_ex_resolve_operands().
  354. */
  355. if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) {
  356. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  357. "(%s) destination not a NS Node [%s]\n",
  358. acpi_ps_get_opcode_name (aml_opcode),
  359. acpi_ut_get_descriptor_name (result_desc)));
  360. status = AE_AML_OPERAND_TYPE;
  361. goto cleanup;
  362. }
  363. offset = (u32) offset_desc->integer.value;
  364. /*
  365. * Setup the Bit offsets and counts, according to the opcode
  366. */
  367. switch (aml_opcode) {
  368. case AML_CREATE_FIELD_OP:
  369. /* Offset is in bits, count is in bits */
  370. field_flags = AML_FIELD_ACCESS_BYTE;
  371. bit_offset = offset;
  372. bit_count = (u32) length_desc->integer.value;
  373. /* Must have a valid (>0) bit count */
  374. if (bit_count == 0) {
  375. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  376. "Attempt to create_field of length 0\n"));
  377. status = AE_AML_OPERAND_VALUE;
  378. goto cleanup;
  379. }
  380. break;
  381. case AML_CREATE_BIT_FIELD_OP:
  382. /* Offset is in bits, Field is one bit */
  383. bit_offset = offset;
  384. bit_count = 1;
  385. field_flags = AML_FIELD_ACCESS_BYTE;
  386. break;
  387. case AML_CREATE_BYTE_FIELD_OP:
  388. /* Offset is in bytes, field is one byte */
  389. bit_offset = 8 * offset;
  390. bit_count = 8;
  391. field_flags = AML_FIELD_ACCESS_BYTE;
  392. break;
  393. case AML_CREATE_WORD_FIELD_OP:
  394. /* Offset is in bytes, field is one word */
  395. bit_offset = 8 * offset;
  396. bit_count = 16;
  397. field_flags = AML_FIELD_ACCESS_WORD;
  398. break;
  399. case AML_CREATE_DWORD_FIELD_OP:
  400. /* Offset is in bytes, field is one dword */
  401. bit_offset = 8 * offset;
  402. bit_count = 32;
  403. field_flags = AML_FIELD_ACCESS_DWORD;
  404. break;
  405. case AML_CREATE_QWORD_FIELD_OP:
  406. /* Offset is in bytes, field is one qword */
  407. bit_offset = 8 * offset;
  408. bit_count = 64;
  409. field_flags = AML_FIELD_ACCESS_QWORD;
  410. break;
  411. default:
  412. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  413. "Unknown field creation opcode %02x\n",
  414. aml_opcode));
  415. status = AE_AML_BAD_OPCODE;
  416. goto cleanup;
  417. }
  418. /* Entire field must fit within the current length of the buffer */
  419. if ((bit_offset + bit_count) >
  420. (8 * (u32) buffer_desc->buffer.length)) {
  421. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  422. "Field [%4.4s] size %d exceeds Buffer [%4.4s] size %d (bits)\n",
  423. acpi_ut_get_node_name (result_desc),
  424. bit_offset + bit_count,
  425. acpi_ut_get_node_name (buffer_desc->buffer.node),
  426. 8 * (u32) buffer_desc->buffer.length));
  427. status = AE_AML_BUFFER_LIMIT;
  428. goto cleanup;
  429. }
  430. /*
  431. * Initialize areas of the field object that are common to all fields
  432. * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
  433. * UPDATE_RULE = 0 (UPDATE_PRESERVE)
  434. */
  435. status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0,
  436. bit_offset, bit_count);
  437. if (ACPI_FAILURE (status)) {
  438. goto cleanup;
  439. }
  440. obj_desc->buffer_field.buffer_obj = buffer_desc;
  441. /* Reference count for buffer_desc inherits obj_desc count */
  442. buffer_desc->common.reference_count = (u16)
  443. (buffer_desc->common.reference_count + obj_desc->common.reference_count);
  444. cleanup:
  445. /* Always delete the operands */
  446. acpi_ut_remove_reference (offset_desc);
  447. acpi_ut_remove_reference (buffer_desc);
  448. if (aml_opcode == AML_CREATE_FIELD_OP) {
  449. acpi_ut_remove_reference (length_desc);
  450. }
  451. /* On failure, delete the result descriptor */
  452. if (ACPI_FAILURE (status)) {
  453. acpi_ut_remove_reference (result_desc); /* Result descriptor */
  454. }
  455. else {
  456. /* Now the address and length are valid for this buffer_field */
  457. obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
  458. }
  459. return_ACPI_STATUS (status);
  460. }
  461. /*******************************************************************************
  462. *
  463. * FUNCTION: acpi_ds_eval_buffer_field_operands
  464. *
  465. * PARAMETERS: walk_state - Current walk
  466. * Op - A valid buffer_field Op object
  467. *
  468. * RETURN: Status
  469. *
  470. * DESCRIPTION: Get buffer_field Buffer and Index
  471. * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
  472. *
  473. ******************************************************************************/
  474. acpi_status
  475. acpi_ds_eval_buffer_field_operands (
  476. struct acpi_walk_state *walk_state,
  477. union acpi_parse_object *op)
  478. {
  479. acpi_status status;
  480. union acpi_operand_object *obj_desc;
  481. struct acpi_namespace_node *node;
  482. union acpi_parse_object *next_op;
  483. ACPI_FUNCTION_TRACE_PTR ("ds_eval_buffer_field_operands", op);
  484. /*
  485. * This is where we evaluate the address and length fields of the
  486. * create_xxx_field declaration
  487. */
  488. node = op->common.node;
  489. /* next_op points to the op that holds the Buffer */
  490. next_op = op->common.value.arg;
  491. /* Evaluate/create the address and length operands */
  492. status = acpi_ds_create_operands (walk_state, next_op);
  493. if (ACPI_FAILURE (status)) {
  494. return_ACPI_STATUS (status);
  495. }
  496. obj_desc = acpi_ns_get_attached_object (node);
  497. if (!obj_desc) {
  498. return_ACPI_STATUS (AE_NOT_EXIST);
  499. }
  500. /* Resolve the operands */
  501. status = acpi_ex_resolve_operands (op->common.aml_opcode,
  502. ACPI_WALK_OPERANDS, walk_state);
  503. ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
  504. acpi_ps_get_opcode_name (op->common.aml_opcode),
  505. walk_state->num_operands, "after acpi_ex_resolve_operands");
  506. if (ACPI_FAILURE (status)) {
  507. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) bad operand(s) (%X)\n",
  508. acpi_ps_get_opcode_name (op->common.aml_opcode), status));
  509. return_ACPI_STATUS (status);
  510. }
  511. /* Initialize the Buffer Field */
  512. if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
  513. /* NOTE: Slightly different operands for this opcode */
  514. status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc,
  515. walk_state->operands[0], walk_state->operands[1],
  516. walk_state->operands[2], walk_state->operands[3]);
  517. }
  518. else {
  519. /* All other, create_xxx_field opcodes */
  520. status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc,
  521. walk_state->operands[0], walk_state->operands[1],
  522. NULL, walk_state->operands[2]);
  523. }
  524. return_ACPI_STATUS (status);
  525. }
  526. /*******************************************************************************
  527. *
  528. * FUNCTION: acpi_ds_eval_region_operands
  529. *
  530. * PARAMETERS: walk_state - Current walk
  531. * Op - A valid region Op object
  532. *
  533. * RETURN: Status
  534. *
  535. * DESCRIPTION: Get region address and length
  536. * Called from acpi_ds_exec_end_op during op_region parse tree walk
  537. *
  538. ******************************************************************************/
  539. acpi_status
  540. acpi_ds_eval_region_operands (
  541. struct acpi_walk_state *walk_state,
  542. union acpi_parse_object *op)
  543. {
  544. acpi_status status;
  545. union acpi_operand_object *obj_desc;
  546. union acpi_operand_object *operand_desc;
  547. struct acpi_namespace_node *node;
  548. union acpi_parse_object *next_op;
  549. ACPI_FUNCTION_TRACE_PTR ("ds_eval_region_operands", op);
  550. /*
  551. * This is where we evaluate the address and length fields of the
  552. * op_region declaration
  553. */
  554. node = op->common.node;
  555. /* next_op points to the op that holds the space_iD */
  556. next_op = op->common.value.arg;
  557. /* next_op points to address op */
  558. next_op = next_op->common.next;
  559. /* Evaluate/create the address and length operands */
  560. status = acpi_ds_create_operands (walk_state, next_op);
  561. if (ACPI_FAILURE (status)) {
  562. return_ACPI_STATUS (status);
  563. }
  564. /* Resolve the length and address operands to numbers */
  565. status = acpi_ex_resolve_operands (op->common.aml_opcode,
  566. ACPI_WALK_OPERANDS, walk_state);
  567. if (ACPI_FAILURE (status)) {
  568. return_ACPI_STATUS (status);
  569. }
  570. ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
  571. acpi_ps_get_opcode_name (op->common.aml_opcode),
  572. 1, "after acpi_ex_resolve_operands");
  573. obj_desc = acpi_ns_get_attached_object (node);
  574. if (!obj_desc) {
  575. return_ACPI_STATUS (AE_NOT_EXIST);
  576. }
  577. /*
  578. * Get the length operand and save it
  579. * (at Top of stack)
  580. */
  581. operand_desc = walk_state->operands[walk_state->num_operands - 1];
  582. obj_desc->region.length = (u32) operand_desc->integer.value;
  583. acpi_ut_remove_reference (operand_desc);
  584. /*
  585. * Get the address and save it
  586. * (at top of stack - 1)
  587. */
  588. operand_desc = walk_state->operands[walk_state->num_operands - 2];
  589. obj_desc->region.address = (acpi_physical_address)
  590. operand_desc->integer.value;
  591. acpi_ut_remove_reference (operand_desc);
  592. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n",
  593. obj_desc,
  594. ACPI_FORMAT_UINT64 (obj_desc->region.address),
  595. obj_desc->region.length));
  596. /* Now the address and length are valid for this opregion */
  597. obj_desc->region.flags |= AOPOBJ_DATA_VALID;
  598. return_ACPI_STATUS (status);
  599. }
  600. /*******************************************************************************
  601. *
  602. * FUNCTION: acpi_ds_eval_data_object_operands
  603. *
  604. * PARAMETERS: walk_state - Current walk
  605. * Op - A valid data_object Op object
  606. * obj_desc - data_object
  607. *
  608. * RETURN: Status
  609. *
  610. * DESCRIPTION: Get the operands and complete the following data object types:
  611. * Buffer, Package.
  612. *
  613. ******************************************************************************/
  614. acpi_status
  615. acpi_ds_eval_data_object_operands (
  616. struct acpi_walk_state *walk_state,
  617. union acpi_parse_object *op,
  618. union acpi_operand_object *obj_desc)
  619. {
  620. acpi_status status;
  621. union acpi_operand_object *arg_desc;
  622. u32 length;
  623. ACPI_FUNCTION_TRACE ("ds_eval_data_object_operands");
  624. /* The first operand (for all of these data objects) is the length */
  625. status = acpi_ds_create_operand (walk_state, op->common.value.arg, 1);
  626. if (ACPI_FAILURE (status)) {
  627. return_ACPI_STATUS (status);
  628. }
  629. status = acpi_ex_resolve_operands (walk_state->opcode,
  630. &(walk_state->operands [walk_state->num_operands -1]),
  631. walk_state);
  632. if (ACPI_FAILURE (status)) {
  633. return_ACPI_STATUS (status);
  634. }
  635. /* Extract length operand */
  636. arg_desc = walk_state->operands [walk_state->num_operands - 1];
  637. length = (u32) arg_desc->integer.value;
  638. /* Cleanup for length operand */
  639. status = acpi_ds_obj_stack_pop (1, walk_state);
  640. if (ACPI_FAILURE (status)) {
  641. return_ACPI_STATUS (status);
  642. }
  643. acpi_ut_remove_reference (arg_desc);
  644. /*
  645. * Create the actual data object
  646. */
  647. switch (op->common.aml_opcode) {
  648. case AML_BUFFER_OP:
  649. status = acpi_ds_build_internal_buffer_obj (walk_state, op, length, &obj_desc);
  650. break;
  651. case AML_PACKAGE_OP:
  652. case AML_VAR_PACKAGE_OP:
  653. status = acpi_ds_build_internal_package_obj (walk_state, op, length, &obj_desc);
  654. break;
  655. default:
  656. return_ACPI_STATUS (AE_AML_BAD_OPCODE);
  657. }
  658. if (ACPI_SUCCESS (status)) {
  659. /*
  660. * Return the object in the walk_state, unless the parent is a package -
  661. * in this case, the return object will be stored in the parse tree
  662. * for the package.
  663. */
  664. if ((!op->common.parent) ||
  665. ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
  666. (op->common.parent->common.aml_opcode != AML_VAR_PACKAGE_OP) &&
  667. (op->common.parent->common.aml_opcode != AML_NAME_OP))) {
  668. walk_state->result_obj = obj_desc;
  669. }
  670. }
  671. return_ACPI_STATUS (status);
  672. }
  673. /*******************************************************************************
  674. *
  675. * FUNCTION: acpi_ds_exec_begin_control_op
  676. *
  677. * PARAMETERS: walk_list - The list that owns the walk stack
  678. * Op - The control Op
  679. *
  680. * RETURN: Status
  681. *
  682. * DESCRIPTION: Handles all control ops encountered during control method
  683. * execution.
  684. *
  685. ******************************************************************************/
  686. acpi_status
  687. acpi_ds_exec_begin_control_op (
  688. struct acpi_walk_state *walk_state,
  689. union acpi_parse_object *op)
  690. {
  691. acpi_status status = AE_OK;
  692. union acpi_generic_state *control_state;
  693. ACPI_FUNCTION_NAME ("ds_exec_begin_control_op");
  694. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op,
  695. op->common.aml_opcode, walk_state));
  696. switch (op->common.aml_opcode) {
  697. case AML_IF_OP:
  698. case AML_WHILE_OP:
  699. /*
  700. * IF/WHILE: Create a new control state to manage these
  701. * constructs. We need to manage these as a stack, in order
  702. * to handle nesting.
  703. */
  704. control_state = acpi_ut_create_control_state ();
  705. if (!control_state) {
  706. status = AE_NO_MEMORY;
  707. break;
  708. }
  709. /*
  710. * Save a pointer to the predicate for multiple executions
  711. * of a loop
  712. */
  713. control_state->control.aml_predicate_start = walk_state->parser_state.aml - 1;
  714. control_state->control.package_end = walk_state->parser_state.pkg_end;
  715. control_state->control.opcode = op->common.aml_opcode;
  716. /* Push the control state on this walk's control stack */
  717. acpi_ut_push_generic_state (&walk_state->control_state, control_state);
  718. break;
  719. case AML_ELSE_OP:
  720. /* Predicate is in the state object */
  721. /* If predicate is true, the IF was executed, ignore ELSE part */
  722. if (walk_state->last_predicate) {
  723. status = AE_CTRL_TRUE;
  724. }
  725. break;
  726. case AML_RETURN_OP:
  727. break;
  728. default:
  729. break;
  730. }
  731. return (status);
  732. }
  733. /*******************************************************************************
  734. *
  735. * FUNCTION: acpi_ds_exec_end_control_op
  736. *
  737. * PARAMETERS: walk_list - The list that owns the walk stack
  738. * Op - The control Op
  739. *
  740. * RETURN: Status
  741. *
  742. * DESCRIPTION: Handles all control ops encountered during control method
  743. * execution.
  744. *
  745. ******************************************************************************/
  746. acpi_status
  747. acpi_ds_exec_end_control_op (
  748. struct acpi_walk_state *walk_state,
  749. union acpi_parse_object *op)
  750. {
  751. acpi_status status = AE_OK;
  752. union acpi_generic_state *control_state;
  753. ACPI_FUNCTION_NAME ("ds_exec_end_control_op");
  754. switch (op->common.aml_opcode) {
  755. case AML_IF_OP:
  756. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op));
  757. /*
  758. * Save the result of the predicate in case there is an
  759. * ELSE to come
  760. */
  761. walk_state->last_predicate =
  762. (u8) walk_state->control_state->common.value;
  763. /*
  764. * Pop the control state that was created at the start
  765. * of the IF and free it
  766. */
  767. control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
  768. acpi_ut_delete_generic_state (control_state);
  769. break;
  770. case AML_ELSE_OP:
  771. break;
  772. case AML_WHILE_OP:
  773. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op));
  774. if (walk_state->control_state->common.value) {
  775. /* Predicate was true, go back and evaluate it again! */
  776. status = AE_CTRL_PENDING;
  777. }
  778. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  779. "[WHILE_OP] termination! Op=%p\n",op));
  780. /* Pop this control state and free it */
  781. control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
  782. walk_state->aml_last_while = control_state->control.aml_predicate_start;
  783. acpi_ut_delete_generic_state (control_state);
  784. break;
  785. case AML_RETURN_OP:
  786. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  787. "[RETURN_OP] Op=%p Arg=%p\n",op, op->common.value.arg));
  788. /*
  789. * One optional operand -- the return value
  790. * It can be either an immediate operand or a result that
  791. * has been bubbled up the tree
  792. */
  793. if (op->common.value.arg) {
  794. /* Since we have a real Return(), delete any implicit return */
  795. acpi_ds_clear_implicit_return (walk_state);
  796. /* Return statement has an immediate operand */
  797. status = acpi_ds_create_operands (walk_state, op->common.value.arg);
  798. if (ACPI_FAILURE (status)) {
  799. return (status);
  800. }
  801. /*
  802. * If value being returned is a Reference (such as
  803. * an arg or local), resolve it now because it may
  804. * cease to exist at the end of the method.
  805. */
  806. status = acpi_ex_resolve_to_value (&walk_state->operands [0], walk_state);
  807. if (ACPI_FAILURE (status)) {
  808. return (status);
  809. }
  810. /*
  811. * Get the return value and save as the last result
  812. * value. This is the only place where walk_state->return_desc
  813. * is set to anything other than zero!
  814. */
  815. walk_state->return_desc = walk_state->operands[0];
  816. }
  817. else if ((walk_state->results) &&
  818. (walk_state->results->results.num_results > 0)) {
  819. /* Since we have a real Return(), delete any implicit return */
  820. acpi_ds_clear_implicit_return (walk_state);
  821. /*
  822. * The return value has come from a previous calculation.
  823. *
  824. * If value being returned is a Reference (such as
  825. * an arg or local), resolve it now because it may
  826. * cease to exist at the end of the method.
  827. *
  828. * Allow references created by the Index operator to return unchanged.
  829. */
  830. if ((ACPI_GET_DESCRIPTOR_TYPE (walk_state->results->results.obj_desc[0]) == ACPI_DESC_TYPE_OPERAND) &&
  831. (ACPI_GET_OBJECT_TYPE (walk_state->results->results.obj_desc [0]) == ACPI_TYPE_LOCAL_REFERENCE) &&
  832. ((walk_state->results->results.obj_desc [0])->reference.opcode != AML_INDEX_OP)) {
  833. status = acpi_ex_resolve_to_value (&walk_state->results->results.obj_desc [0], walk_state);
  834. if (ACPI_FAILURE (status)) {
  835. return (status);
  836. }
  837. }
  838. walk_state->return_desc = walk_state->results->results.obj_desc [0];
  839. }
  840. else {
  841. /* No return operand */
  842. if (walk_state->num_operands) {
  843. acpi_ut_remove_reference (walk_state->operands [0]);
  844. }
  845. walk_state->operands [0] = NULL;
  846. walk_state->num_operands = 0;
  847. walk_state->return_desc = NULL;
  848. }
  849. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  850. "Completed RETURN_OP State=%p, ret_val=%p\n",
  851. walk_state, walk_state->return_desc));
  852. /* End the control method execution right now */
  853. status = AE_CTRL_TERMINATE;
  854. break;
  855. case AML_NOOP_OP:
  856. /* Just do nothing! */
  857. break;
  858. case AML_BREAK_POINT_OP:
  859. /* Call up to the OS service layer to handle this */
  860. status = acpi_os_signal (ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode");
  861. /* If and when it returns, all done. */
  862. break;
  863. case AML_BREAK_OP:
  864. case AML_CONTINUE_OP: /* ACPI 2.0 */
  865. /* Pop and delete control states until we find a while */
  866. while (walk_state->control_state &&
  867. (walk_state->control_state->control.opcode != AML_WHILE_OP)) {
  868. control_state = acpi_ut_pop_generic_state (&walk_state->control_state);
  869. acpi_ut_delete_generic_state (control_state);
  870. }
  871. /* No while found? */
  872. if (!walk_state->control_state) {
  873. return (AE_AML_NO_WHILE);
  874. }
  875. /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */
  876. walk_state->aml_last_while = walk_state->control_state->control.package_end;
  877. /* Return status depending on opcode */
  878. if (op->common.aml_opcode == AML_BREAK_OP) {
  879. status = AE_CTRL_BREAK;
  880. }
  881. else {
  882. status = AE_CTRL_CONTINUE;
  883. }
  884. break;
  885. default:
  886. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown control opcode=%X Op=%p\n",
  887. op->common.aml_opcode, op));
  888. status = AE_AML_BAD_OPCODE;
  889. break;
  890. }
  891. return (status);
  892. }