dsopcode.c 32 KB

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