exoparg6.c 9.9 KB

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