dsopcode.c 31 KB

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