dsopcode.c 31 KB

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