exoparg2.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/acparser.h>
  44. #include <acpi/acinterp.h>
  45. #include <acpi/acevents.h>
  46. #include <acpi/amlcode.h>
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME("exoparg2")
  49. /*!
  50. * Naming convention for AML interpreter execution routines.
  51. *
  52. * The routines that begin execution of AML opcodes are named with a common
  53. * convention based upon the number of arguments, the number of target operands,
  54. * and whether or not a value is returned:
  55. *
  56. * AcpiExOpcode_xA_yT_zR
  57. *
  58. * Where:
  59. *
  60. * xA - ARGUMENTS: The number of arguments (input operands) that are
  61. * required for this opcode type (1 through 6 args).
  62. * yT - TARGETS: The number of targets (output operands) that are required
  63. * for this opcode type (0, 1, or 2 targets).
  64. * zR - RETURN VALUE: Indicates whether this opcode type returns a value
  65. * as the function return (0 or 1).
  66. *
  67. * The AcpiExOpcode* functions are called via the Dispatcher component with
  68. * fully resolved operands.
  69. !*/
  70. /*******************************************************************************
  71. *
  72. * FUNCTION: acpi_ex_opcode_2A_0T_0R
  73. *
  74. * PARAMETERS: walk_state - Current walk state
  75. *
  76. * RETURN: Status
  77. *
  78. * DESCRIPTION: Execute opcode with two arguments, no target, and no return
  79. * value.
  80. *
  81. * ALLOCATION: Deletes both operands
  82. *
  83. ******************************************************************************/
  84. acpi_status acpi_ex_opcode_2A_0T_0R(struct acpi_walk_state *walk_state)
  85. {
  86. union acpi_operand_object **operand = &walk_state->operands[0];
  87. struct acpi_namespace_node *node;
  88. u32 value;
  89. acpi_status status = AE_OK;
  90. ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_0T_0R,
  91. acpi_ps_get_opcode_name(walk_state->opcode));
  92. /* Examine the opcode */
  93. switch (walk_state->opcode) {
  94. case AML_NOTIFY_OP: /* Notify (notify_object, notify_value) */
  95. /* The first operand is a namespace node */
  96. node = (struct acpi_namespace_node *)operand[0];
  97. /* Second value is the notify value */
  98. value = (u32) operand[1]->integer.value;
  99. /* Are notifies allowed on this object? */
  100. if (!acpi_ev_is_notify_object(node)) {
  101. ACPI_ERROR((AE_INFO,
  102. "Unexpected notify object type [%s]",
  103. acpi_ut_get_type_name(node->type)));
  104. status = AE_AML_OPERAND_TYPE;
  105. break;
  106. }
  107. #ifdef ACPI_GPE_NOTIFY_CHECK
  108. /*
  109. * GPE method wake/notify check. Here, we want to ensure that we
  110. * don't receive any "DeviceWake" Notifies from a GPE _Lxx or _Exx
  111. * GPE method during system runtime. If we do, the GPE is marked
  112. * as "wake-only" and disabled.
  113. *
  114. * 1) Is the Notify() value == device_wake?
  115. * 2) Is this a GPE deferred method? (An _Lxx or _Exx method)
  116. * 3) Did the original GPE happen at system runtime?
  117. * (versus during wake)
  118. *
  119. * If all three cases are true, this is a wake-only GPE that should
  120. * be disabled at runtime.
  121. */
  122. if (value == 2) { /* device_wake */
  123. status =
  124. acpi_ev_check_for_wake_only_gpe(walk_state->
  125. gpe_event_info);
  126. if (ACPI_FAILURE(status)) {
  127. /* AE_WAKE_ONLY_GPE only error, means ignore this notify */
  128. return_ACPI_STATUS(AE_OK)
  129. }
  130. }
  131. #endif
  132. /*
  133. * Dispatch the notify to the appropriate handler
  134. * NOTE: the request is queued for execution after this method
  135. * completes. The notify handlers are NOT invoked synchronously
  136. * from this thread -- because handlers may in turn run other
  137. * control methods.
  138. */
  139. status = acpi_ev_queue_notify_request(node, value);
  140. break;
  141. default:
  142. ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
  143. walk_state->opcode));
  144. status = AE_AML_BAD_OPCODE;
  145. }
  146. return_ACPI_STATUS(status);
  147. }
  148. /*******************************************************************************
  149. *
  150. * FUNCTION: acpi_ex_opcode_2A_2T_1R
  151. *
  152. * PARAMETERS: walk_state - Current walk state
  153. *
  154. * RETURN: Status
  155. *
  156. * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
  157. * and one implicit return value.
  158. *
  159. ******************************************************************************/
  160. acpi_status acpi_ex_opcode_2A_2T_1R(struct acpi_walk_state *walk_state)
  161. {
  162. union acpi_operand_object **operand = &walk_state->operands[0];
  163. union acpi_operand_object *return_desc1 = NULL;
  164. union acpi_operand_object *return_desc2 = NULL;
  165. acpi_status status;
  166. ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_2T_1R,
  167. acpi_ps_get_opcode_name(walk_state->opcode));
  168. /* Execute the opcode */
  169. switch (walk_state->opcode) {
  170. case AML_DIVIDE_OP:
  171. /* Divide (Dividend, Divisor, remainder_result quotient_result) */
  172. return_desc1 =
  173. acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  174. if (!return_desc1) {
  175. status = AE_NO_MEMORY;
  176. goto cleanup;
  177. }
  178. return_desc2 =
  179. acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  180. if (!return_desc2) {
  181. status = AE_NO_MEMORY;
  182. goto cleanup;
  183. }
  184. /* Quotient to return_desc1, remainder to return_desc2 */
  185. status = acpi_ut_divide(operand[0]->integer.value,
  186. operand[1]->integer.value,
  187. &return_desc1->integer.value,
  188. &return_desc2->integer.value);
  189. if (ACPI_FAILURE(status)) {
  190. goto cleanup;
  191. }
  192. break;
  193. default:
  194. ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
  195. walk_state->opcode));
  196. status = AE_AML_BAD_OPCODE;
  197. goto cleanup;
  198. }
  199. /* Store the results to the target reference operands */
  200. status = acpi_ex_store(return_desc2, operand[2], walk_state);
  201. if (ACPI_FAILURE(status)) {
  202. goto cleanup;
  203. }
  204. status = acpi_ex_store(return_desc1, operand[3], walk_state);
  205. if (ACPI_FAILURE(status)) {
  206. goto cleanup;
  207. }
  208. cleanup:
  209. /*
  210. * Since the remainder is not returned indirectly, remove a reference to
  211. * it. Only the quotient is returned indirectly.
  212. */
  213. acpi_ut_remove_reference(return_desc2);
  214. if (ACPI_FAILURE(status)) {
  215. /* Delete the return object */
  216. acpi_ut_remove_reference(return_desc1);
  217. }
  218. /* Save return object (the remainder) on success */
  219. else {
  220. walk_state->result_obj = return_desc1;
  221. }
  222. return_ACPI_STATUS(status);
  223. }
  224. /*******************************************************************************
  225. *
  226. * FUNCTION: acpi_ex_opcode_2A_1T_1R
  227. *
  228. * PARAMETERS: walk_state - Current walk state
  229. *
  230. * RETURN: Status
  231. *
  232. * DESCRIPTION: Execute opcode with two arguments, one target, and a return
  233. * value.
  234. *
  235. ******************************************************************************/
  236. acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
  237. {
  238. union acpi_operand_object **operand = &walk_state->operands[0];
  239. union acpi_operand_object *return_desc = NULL;
  240. acpi_integer index;
  241. acpi_status status = AE_OK;
  242. acpi_size length;
  243. ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_1T_1R,
  244. acpi_ps_get_opcode_name(walk_state->opcode));
  245. /* Execute the opcode */
  246. if (walk_state->op_info->flags & AML_MATH) {
  247. /* All simple math opcodes (add, etc.) */
  248. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  249. if (!return_desc) {
  250. status = AE_NO_MEMORY;
  251. goto cleanup;
  252. }
  253. return_desc->integer.value =
  254. acpi_ex_do_math_op(walk_state->opcode,
  255. operand[0]->integer.value,
  256. operand[1]->integer.value);
  257. goto store_result_to_target;
  258. }
  259. switch (walk_state->opcode) {
  260. case AML_MOD_OP: /* Mod (Dividend, Divisor, remainder_result (ACPI 2.0) */
  261. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  262. if (!return_desc) {
  263. status = AE_NO_MEMORY;
  264. goto cleanup;
  265. }
  266. /* return_desc will contain the remainder */
  267. status = acpi_ut_divide(operand[0]->integer.value,
  268. operand[1]->integer.value,
  269. NULL, &return_desc->integer.value);
  270. break;
  271. case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
  272. status = acpi_ex_do_concatenate(operand[0], operand[1],
  273. &return_desc, walk_state);
  274. break;
  275. case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */
  276. /*
  277. * Input object is guaranteed to be a buffer at this point (it may have
  278. * been converted.) Copy the raw buffer data to a new object of
  279. * type String.
  280. */
  281. /*
  282. * Get the length of the new string. It is the smallest of:
  283. * 1) Length of the input buffer
  284. * 2) Max length as specified in the to_string operator
  285. * 3) Length of input buffer up to a zero byte (null terminator)
  286. *
  287. * NOTE: A length of zero is ok, and will create a zero-length, null
  288. * terminated string.
  289. */
  290. length = 0;
  291. while ((length < operand[0]->buffer.length) &&
  292. (length < operand[1]->integer.value) &&
  293. (operand[0]->buffer.pointer[length])) {
  294. length++;
  295. }
  296. /* Allocate a new string object */
  297. return_desc = acpi_ut_create_string_object(length);
  298. if (!return_desc) {
  299. status = AE_NO_MEMORY;
  300. goto cleanup;
  301. }
  302. /*
  303. * Copy the raw buffer data with no transform.
  304. * (NULL terminated already)
  305. */
  306. ACPI_MEMCPY(return_desc->string.pointer,
  307. operand[0]->buffer.pointer, length);
  308. break;
  309. case AML_CONCAT_RES_OP:
  310. /* concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */
  311. status = acpi_ex_concat_template(operand[0], operand[1],
  312. &return_desc, walk_state);
  313. break;
  314. case AML_INDEX_OP: /* Index (Source Index Result) */
  315. /* Create the internal return object */
  316. return_desc =
  317. acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
  318. if (!return_desc) {
  319. status = AE_NO_MEMORY;
  320. goto cleanup;
  321. }
  322. /* Initialize the Index reference object */
  323. index = operand[1]->integer.value;
  324. return_desc->reference.offset = (u32) index;
  325. return_desc->reference.opcode = AML_INDEX_OP;
  326. /*
  327. * At this point, the Source operand is a String, Buffer, or Package.
  328. * Verify that the index is within range.
  329. */
  330. switch (ACPI_GET_OBJECT_TYPE(operand[0])) {
  331. case ACPI_TYPE_STRING:
  332. if (index >= operand[0]->string.length) {
  333. status = AE_AML_STRING_LIMIT;
  334. }
  335. return_desc->reference.target_type =
  336. ACPI_TYPE_BUFFER_FIELD;
  337. break;
  338. case ACPI_TYPE_BUFFER:
  339. if (index >= operand[0]->buffer.length) {
  340. status = AE_AML_BUFFER_LIMIT;
  341. }
  342. return_desc->reference.target_type =
  343. ACPI_TYPE_BUFFER_FIELD;
  344. break;
  345. case ACPI_TYPE_PACKAGE:
  346. if (index >= operand[0]->package.count) {
  347. status = AE_AML_PACKAGE_LIMIT;
  348. }
  349. return_desc->reference.target_type = ACPI_TYPE_PACKAGE;
  350. return_desc->reference.where =
  351. &operand[0]->package.elements[index];
  352. break;
  353. default:
  354. status = AE_AML_INTERNAL;
  355. goto cleanup;
  356. }
  357. /* Failure means that the Index was beyond the end of the object */
  358. if (ACPI_FAILURE(status)) {
  359. ACPI_EXCEPTION((AE_INFO, status,
  360. "Index (%X%8.8X) is beyond end of object",
  361. ACPI_FORMAT_UINT64(index)));
  362. goto cleanup;
  363. }
  364. /*
  365. * Save the target object and add a reference to it for the life
  366. * of the index
  367. */
  368. return_desc->reference.object = operand[0];
  369. acpi_ut_add_reference(operand[0]);
  370. /* Store the reference to the Target */
  371. status = acpi_ex_store(return_desc, operand[2], walk_state);
  372. /* Return the reference */
  373. walk_state->result_obj = return_desc;
  374. goto cleanup;
  375. default:
  376. ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
  377. walk_state->opcode));
  378. status = AE_AML_BAD_OPCODE;
  379. break;
  380. }
  381. store_result_to_target:
  382. if (ACPI_SUCCESS(status)) {
  383. /*
  384. * Store the result of the operation (which is now in return_desc) into
  385. * the Target descriptor.
  386. */
  387. status = acpi_ex_store(return_desc, operand[2], walk_state);
  388. if (ACPI_FAILURE(status)) {
  389. goto cleanup;
  390. }
  391. if (!walk_state->result_obj) {
  392. walk_state->result_obj = return_desc;
  393. }
  394. }
  395. cleanup:
  396. /* Delete return object on error */
  397. if (ACPI_FAILURE(status)) {
  398. acpi_ut_remove_reference(return_desc);
  399. walk_state->result_obj = NULL;
  400. }
  401. return_ACPI_STATUS(status);
  402. }
  403. /*******************************************************************************
  404. *
  405. * FUNCTION: acpi_ex_opcode_2A_0T_1R
  406. *
  407. * PARAMETERS: walk_state - Current walk state
  408. *
  409. * RETURN: Status
  410. *
  411. * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
  412. *
  413. ******************************************************************************/
  414. acpi_status acpi_ex_opcode_2A_0T_1R(struct acpi_walk_state *walk_state)
  415. {
  416. union acpi_operand_object **operand = &walk_state->operands[0];
  417. union acpi_operand_object *return_desc = NULL;
  418. acpi_status status = AE_OK;
  419. u8 logical_result = FALSE;
  420. ACPI_FUNCTION_TRACE_STR(ex_opcode_2A_0T_1R,
  421. acpi_ps_get_opcode_name(walk_state->opcode));
  422. /* Create the internal return object */
  423. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  424. if (!return_desc) {
  425. status = AE_NO_MEMORY;
  426. goto cleanup;
  427. }
  428. /* Execute the Opcode */
  429. if (walk_state->op_info->flags & AML_LOGICAL_NUMERIC) {
  430. /* logical_op (Operand0, Operand1) */
  431. status = acpi_ex_do_logical_numeric_op(walk_state->opcode,
  432. operand[0]->integer.
  433. value,
  434. operand[1]->integer.
  435. value, &logical_result);
  436. goto store_logical_result;
  437. } else if (walk_state->op_info->flags & AML_LOGICAL) {
  438. /* logical_op (Operand0, Operand1) */
  439. status = acpi_ex_do_logical_op(walk_state->opcode, operand[0],
  440. operand[1], &logical_result);
  441. goto store_logical_result;
  442. }
  443. switch (walk_state->opcode) {
  444. case AML_ACQUIRE_OP: /* Acquire (mutex_object, Timeout) */
  445. status =
  446. acpi_ex_acquire_mutex(operand[1], operand[0], walk_state);
  447. if (status == AE_TIME) {
  448. logical_result = TRUE; /* TRUE = Acquire timed out */
  449. status = AE_OK;
  450. }
  451. break;
  452. case AML_WAIT_OP: /* Wait (event_object, Timeout) */
  453. status = acpi_ex_system_wait_event(operand[1], operand[0]);
  454. if (status == AE_TIME) {
  455. logical_result = TRUE; /* TRUE, Wait timed out */
  456. status = AE_OK;
  457. }
  458. break;
  459. default:
  460. ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
  461. walk_state->opcode));
  462. status = AE_AML_BAD_OPCODE;
  463. goto cleanup;
  464. }
  465. store_logical_result:
  466. /*
  467. * Set return value to according to logical_result. logical TRUE (all ones)
  468. * Default is FALSE (zero)
  469. */
  470. if (logical_result) {
  471. return_desc->integer.value = ACPI_INTEGER_MAX;
  472. }
  473. cleanup:
  474. /* Delete return object on error */
  475. if (ACPI_FAILURE(status)) {
  476. acpi_ut_remove_reference(return_desc);
  477. }
  478. /* Save return object on success */
  479. else {
  480. walk_state->result_obj = return_desc;
  481. }
  482. return_ACPI_STATUS(status);
  483. }