exoparg6.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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/acinterp.h>
  44. #include <acpi/acparser.h>
  45. #include <acpi/amlcode.h>
  46. #define _COMPONENT ACPI_EXECUTER
  47. ACPI_MODULE_NAME("exoparg6")
  48. /*!
  49. * Naming convention for AML interpreter execution routines.
  50. *
  51. * The routines that begin execution of AML opcodes are named with a common
  52. * convention based upon the number of arguments, the number of target operands,
  53. * and whether or not a value is returned:
  54. *
  55. * AcpiExOpcode_xA_yT_zR
  56. *
  57. * Where:
  58. *
  59. * xA - ARGUMENTS: The number of arguments (input operands) that are
  60. * required for this opcode type (1 through 6 args).
  61. * yT - TARGETS: The number of targets (output operands) that are required
  62. * for this opcode type (0, 1, or 2 targets).
  63. * zR - RETURN VALUE: Indicates whether this opcode type returns a value
  64. * as the function return (0 or 1).
  65. *
  66. * The AcpiExOpcode* functions are called via the Dispatcher component with
  67. * fully resolved operands.
  68. !*/
  69. /* Local prototypes */
  70. static u8
  71. acpi_ex_do_match(u32 match_op,
  72. union acpi_operand_object *package_obj,
  73. union acpi_operand_object *match_obj);
  74. /*******************************************************************************
  75. *
  76. * FUNCTION: acpi_ex_do_match
  77. *
  78. * PARAMETERS: match_op - The AML match operand
  79. * package_obj - Object from the target package
  80. * match_obj - Object to be matched
  81. *
  82. * RETURN: TRUE if the match is successful, FALSE otherwise
  83. *
  84. * DESCRIPTION: Implements the low-level match for the ASL Match operator.
  85. * Package elements will be implicitly converted to the type of
  86. * the match object (Integer/Buffer/String).
  87. *
  88. ******************************************************************************/
  89. static u8
  90. acpi_ex_do_match(u32 match_op,
  91. union acpi_operand_object *package_obj,
  92. union acpi_operand_object *match_obj)
  93. {
  94. u8 logical_result = TRUE;
  95. acpi_status status;
  96. /*
  97. * Note: Since the package_obj/match_obj ordering is opposite to that of
  98. * the standard logical operators, we have to reverse them when we call
  99. * do_logical_op in order to make the implicit conversion rules work
  100. * correctly. However, this means we have to flip the entire equation
  101. * also. A bit ugly perhaps, but overall, better than fussing the
  102. * parameters around at runtime, over and over again.
  103. *
  104. * Below, P[i] refers to the package element, M refers to the Match object.
  105. */
  106. switch (match_op) {
  107. case MATCH_MTR:
  108. /* Always true */
  109. break;
  110. case MATCH_MEQ:
  111. /*
  112. * True if equal: (P[i] == M)
  113. * Change to: (M == P[i])
  114. */
  115. status =
  116. acpi_ex_do_logical_op(AML_LEQUAL_OP, match_obj, package_obj,
  117. &logical_result);
  118. if (ACPI_FAILURE(status)) {
  119. return (FALSE);
  120. }
  121. break;
  122. case MATCH_MLE:
  123. /*
  124. * True if less than or equal: (P[i] <= M) (P[i] not_greater than M)
  125. * Change to: (M >= P[i]) (M not_less than P[i])
  126. */
  127. status =
  128. acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
  129. &logical_result);
  130. if (ACPI_FAILURE(status)) {
  131. return (FALSE);
  132. }
  133. logical_result = (u8) ! logical_result;
  134. break;
  135. case MATCH_MLT:
  136. /*
  137. * True if less than: (P[i] < M)
  138. * Change to: (M > P[i])
  139. */
  140. status =
  141. acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
  142. package_obj, &logical_result);
  143. if (ACPI_FAILURE(status)) {
  144. return (FALSE);
  145. }
  146. break;
  147. case MATCH_MGE:
  148. /*
  149. * True if greater than or equal: (P[i] >= M) (P[i] not_less than M)
  150. * Change to: (M <= P[i]) (M not_greater than P[i])
  151. */
  152. status =
  153. acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
  154. package_obj, &logical_result);
  155. if (ACPI_FAILURE(status)) {
  156. return (FALSE);
  157. }
  158. logical_result = (u8) ! logical_result;
  159. break;
  160. case MATCH_MGT:
  161. /*
  162. * True if greater than: (P[i] > M)
  163. * Change to: (M < P[i])
  164. */
  165. status =
  166. acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
  167. &logical_result);
  168. if (ACPI_FAILURE(status)) {
  169. return (FALSE);
  170. }
  171. break;
  172. default:
  173. /* Undefined */
  174. return (FALSE);
  175. }
  176. return logical_result;
  177. }
  178. /*******************************************************************************
  179. *
  180. * FUNCTION: acpi_ex_opcode_6A_0T_1R
  181. *
  182. * PARAMETERS: walk_state - Current walk state
  183. *
  184. * RETURN: Status
  185. *
  186. * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
  187. *
  188. ******************************************************************************/
  189. acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
  190. {
  191. union acpi_operand_object **operand = &walk_state->operands[0];
  192. union acpi_operand_object *return_desc = NULL;
  193. acpi_status status = AE_OK;
  194. acpi_integer index;
  195. union acpi_operand_object *this_element;
  196. ACPI_FUNCTION_TRACE_STR("ex_opcode_6A_0T_1R",
  197. acpi_ps_get_opcode_name(walk_state->opcode));
  198. switch (walk_state->opcode) {
  199. case AML_MATCH_OP:
  200. /*
  201. * Match (search_pkg[0], match_op1[1], match_obj1[2],
  202. * match_op2[3], match_obj2[4], start_index[5])
  203. */
  204. /* Validate both Match Term Operators (MTR, MEQ, etc.) */
  205. if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) ||
  206. (operand[3]->integer.value > MAX_MATCH_OPERATOR)) {
  207. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  208. "Match operator out of range\n"));
  209. status = AE_AML_OPERAND_VALUE;
  210. goto cleanup;
  211. }
  212. /* Get the package start_index, validate against the package length */
  213. index = operand[5]->integer.value;
  214. if (index >= operand[0]->package.count) {
  215. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  216. "Index (%X%8.8X) beyond package end (%X)\n",
  217. ACPI_FORMAT_UINT64(index),
  218. operand[0]->package.count));
  219. status = AE_AML_PACKAGE_LIMIT;
  220. goto cleanup;
  221. }
  222. /* Create an integer for the return value */
  223. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  224. if (!return_desc) {
  225. status = AE_NO_MEMORY;
  226. goto cleanup;
  227. }
  228. /* Default return value if no match found */
  229. return_desc->integer.value = ACPI_INTEGER_MAX;
  230. /*
  231. * Examine each element until a match is found. Both match conditions
  232. * must be satisfied for a match to occur. Within the loop,
  233. * "continue" signifies that the current element does not match
  234. * and the next should be examined.
  235. *
  236. * Upon finding a match, the loop will terminate via "break" at
  237. * the bottom. If it terminates "normally", match_value will be
  238. * ACPI_INTEGER_MAX (Ones) (its initial value) indicating that no
  239. * match was found.
  240. */
  241. for (; index < operand[0]->package.count; index++) {
  242. /* Get the current package element */
  243. this_element = operand[0]->package.elements[index];
  244. /* Treat any uninitialized (NULL) elements as non-matching */
  245. if (!this_element) {
  246. continue;
  247. }
  248. /*
  249. * Both match conditions must be satisfied. Execution of a continue
  250. * (proceed to next iteration of enclosing for loop) signifies a
  251. * non-match.
  252. */
  253. if (!acpi_ex_do_match((u32) operand[1]->integer.value,
  254. this_element, operand[2])) {
  255. continue;
  256. }
  257. if (!acpi_ex_do_match((u32) operand[3]->integer.value,
  258. this_element, operand[4])) {
  259. continue;
  260. }
  261. /* Match found: Index is the return value */
  262. return_desc->integer.value = index;
  263. break;
  264. }
  265. break;
  266. case AML_LOAD_TABLE_OP:
  267. status = acpi_ex_load_table_op(walk_state, &return_desc);
  268. break;
  269. default:
  270. ACPI_REPORT_ERROR(("acpi_ex_opcode_6A_0T_1R: Unknown opcode %X\n", walk_state->opcode));
  271. status = AE_AML_BAD_OPCODE;
  272. goto cleanup;
  273. }
  274. walk_state->result_obj = return_desc;
  275. cleanup:
  276. /* Delete return object on error */
  277. if (ACPI_FAILURE(status)) {
  278. acpi_ut_remove_reference(return_desc);
  279. }
  280. return_ACPI_STATUS(status);
  281. }