exoparg6.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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 "accommon.h"
  44. #include "acinterp.h"
  45. #include "acparser.h"
  46. #include "amlcode.h"
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME("exoparg6")
  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. /* Local prototypes */
  71. static u8
  72. acpi_ex_do_match(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(u32 match_op,
  92. union acpi_operand_object *package_obj,
  93. union acpi_operand_object *match_obj)
  94. {
  95. u8 logical_result = TRUE;
  96. acpi_status status;
  97. /*
  98. * Note: Since the package_obj/match_obj ordering is opposite to that of
  99. * the standard logical operators, we have to reverse them when we call
  100. * do_logical_op in order to make the implicit conversion rules work
  101. * correctly. However, this means we have to flip the entire equation
  102. * also. A bit ugly perhaps, but overall, better than fussing the
  103. * parameters around at runtime, over and over again.
  104. *
  105. * Below, P[i] refers to the package element, M refers to the Match object.
  106. */
  107. switch (match_op) {
  108. case MATCH_MTR:
  109. /* Always true */
  110. break;
  111. case MATCH_MEQ:
  112. /*
  113. * True if equal: (P[i] == M)
  114. * Change to: (M == P[i])
  115. */
  116. status =
  117. 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 =
  129. acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
  130. &logical_result);
  131. if (ACPI_FAILURE(status)) {
  132. return (FALSE);
  133. }
  134. logical_result = (u8) ! logical_result;
  135. break;
  136. case MATCH_MLT:
  137. /*
  138. * True if less than: (P[i] < M)
  139. * Change to: (M > P[i])
  140. */
  141. status =
  142. acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
  143. package_obj, &logical_result);
  144. if (ACPI_FAILURE(status)) {
  145. return (FALSE);
  146. }
  147. break;
  148. case MATCH_MGE:
  149. /*
  150. * True if greater than or equal: (P[i] >= M) (P[i] not_less than M)
  151. * Change to: (M <= P[i]) (M not_greater than P[i])
  152. */
  153. status =
  154. acpi_ex_do_logical_op(AML_LGREATER_OP, match_obj,
  155. package_obj, &logical_result);
  156. if (ACPI_FAILURE(status)) {
  157. return (FALSE);
  158. }
  159. logical_result = (u8) ! logical_result;
  160. break;
  161. case MATCH_MGT:
  162. /*
  163. * True if greater than: (P[i] > M)
  164. * Change to: (M < P[i])
  165. */
  166. status =
  167. acpi_ex_do_logical_op(AML_LLESS_OP, match_obj, package_obj,
  168. &logical_result);
  169. if (ACPI_FAILURE(status)) {
  170. return (FALSE);
  171. }
  172. break;
  173. default:
  174. /* Undefined */
  175. return (FALSE);
  176. }
  177. return (logical_result);
  178. }
  179. /*******************************************************************************
  180. *
  181. * FUNCTION: acpi_ex_opcode_6A_0T_1R
  182. *
  183. * PARAMETERS: walk_state - Current walk state
  184. *
  185. * RETURN: Status
  186. *
  187. * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
  188. *
  189. ******************************************************************************/
  190. acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
  191. {
  192. union acpi_operand_object **operand = &walk_state->operands[0];
  193. union acpi_operand_object *return_desc = NULL;
  194. acpi_status status = AE_OK;
  195. u64 index;
  196. union acpi_operand_object *this_element;
  197. ACPI_FUNCTION_TRACE_STR(ex_opcode_6A_0T_1R,
  198. acpi_ps_get_opcode_name(walk_state->opcode));
  199. switch (walk_state->opcode) {
  200. case AML_MATCH_OP:
  201. /*
  202. * Match (search_pkg[0], match_op1[1], match_obj1[2],
  203. * match_op2[3], match_obj2[4], start_index[5])
  204. */
  205. /* Validate both Match Term Operators (MTR, MEQ, etc.) */
  206. if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) ||
  207. (operand[3]->integer.value > MAX_MATCH_OPERATOR)) {
  208. ACPI_ERROR((AE_INFO, "Match operator out of range"));
  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_ERROR((AE_INFO,
  216. "Index (0x%8.8X%8.8X) beyond package end (0x%X)",
  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. /* Default return value is ACPI_UINT64_MAX if no match found */
  224. return_desc = acpi_ut_create_integer_object(ACPI_UINT64_MAX);
  225. if (!return_desc) {
  226. status = AE_NO_MEMORY;
  227. goto cleanup;
  228. }
  229. /*
  230. * Examine each element until a match is found. Both match conditions
  231. * must be satisfied for a match to occur. Within the loop,
  232. * "continue" signifies that the current element does not match
  233. * and the next should be examined.
  234. *
  235. * Upon finding a match, the loop will terminate via "break" at
  236. * the bottom. If it terminates "normally", match_value will be
  237. * ACPI_UINT64_MAX (Ones) (its initial value) indicating that no
  238. * match was found.
  239. */
  240. for (; index < operand[0]->package.count; index++) {
  241. /* Get the current package element */
  242. this_element = operand[0]->package.elements[index];
  243. /* Treat any uninitialized (NULL) elements as non-matching */
  244. if (!this_element) {
  245. continue;
  246. }
  247. /*
  248. * Both match conditions must be satisfied. Execution of a continue
  249. * (proceed to next iteration of enclosing for loop) signifies a
  250. * non-match.
  251. */
  252. if (!acpi_ex_do_match((u32) operand[1]->integer.value,
  253. this_element, operand[2])) {
  254. continue;
  255. }
  256. if (!acpi_ex_do_match((u32) operand[3]->integer.value,
  257. this_element, operand[4])) {
  258. continue;
  259. }
  260. /* Match found: Index is the return value */
  261. return_desc->integer.value = index;
  262. break;
  263. }
  264. break;
  265. case AML_LOAD_TABLE_OP:
  266. status = acpi_ex_load_table_op(walk_state, &return_desc);
  267. break;
  268. default:
  269. ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
  270. walk_state->opcode));
  271. status = AE_AML_BAD_OPCODE;
  272. goto cleanup;
  273. }
  274. cleanup:
  275. /* Delete return object on error */
  276. if (ACPI_FAILURE(status)) {
  277. acpi_ut_remove_reference(return_desc);
  278. }
  279. /* Save return object on success */
  280. else {
  281. walk_state->result_obj = return_desc;
  282. }
  283. return_ACPI_STATUS(status);
  284. }