dsopcode.c 31 KB

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