PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/acpi/acpica/exresop.c

https://github.com/mstsirkin/kvm
C | 700 lines | 361 code | 145 blank | 194 comment | 63 complexity | 9b394cbe031a047af0fcf79e7efa6d8a MD5 | raw file
  1. /******************************************************************************
  2. *
  3. * Module Name: exresop - AML Interpreter operand/object resolution
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, 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 "amlcode.h"
  45. #include "acparser.h"
  46. #include "acinterp.h"
  47. #include "acnamesp.h"
  48. #define _COMPONENT ACPI_EXECUTER
  49. ACPI_MODULE_NAME("exresop")
  50. /* Local prototypes */
  51. static acpi_status
  52. acpi_ex_check_object_type(acpi_object_type type_needed,
  53. acpi_object_type this_type, void *object);
  54. /*******************************************************************************
  55. *
  56. * FUNCTION: acpi_ex_check_object_type
  57. *
  58. * PARAMETERS: type_needed Object type needed
  59. * this_type Actual object type
  60. * Object Object pointer
  61. *
  62. * RETURN: Status
  63. *
  64. * DESCRIPTION: Check required type against actual type
  65. *
  66. ******************************************************************************/
  67. static acpi_status
  68. acpi_ex_check_object_type(acpi_object_type type_needed,
  69. acpi_object_type this_type, void *object)
  70. {
  71. ACPI_FUNCTION_ENTRY();
  72. if (type_needed == ACPI_TYPE_ANY) {
  73. /* All types OK, so we don't perform any typechecks */
  74. return (AE_OK);
  75. }
  76. if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
  77. /*
  78. * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
  79. * objects and thus allow them to be targets. (As per the ACPI
  80. * specification, a store to a constant is a noop.)
  81. */
  82. if ((this_type == ACPI_TYPE_INTEGER) &&
  83. (((union acpi_operand_object *)object)->common.
  84. flags & AOPOBJ_AML_CONSTANT)) {
  85. return (AE_OK);
  86. }
  87. }
  88. if (type_needed != this_type) {
  89. ACPI_ERROR((AE_INFO,
  90. "Needed type [%s], found [%s] %p",
  91. acpi_ut_get_type_name(type_needed),
  92. acpi_ut_get_type_name(this_type), object));
  93. return (AE_AML_OPERAND_TYPE);
  94. }
  95. return (AE_OK);
  96. }
  97. /*******************************************************************************
  98. *
  99. * FUNCTION: acpi_ex_resolve_operands
  100. *
  101. * PARAMETERS: Opcode - Opcode being interpreted
  102. * stack_ptr - Pointer to the operand stack to be
  103. * resolved
  104. * walk_state - Current state
  105. *
  106. * RETURN: Status
  107. *
  108. * DESCRIPTION: Convert multiple input operands to the types required by the
  109. * target operator.
  110. *
  111. * Each 5-bit group in arg_types represents one required
  112. * operand and indicates the required Type. The corresponding operand
  113. * will be converted to the required type if possible, otherwise we
  114. * abort with an exception.
  115. *
  116. ******************************************************************************/
  117. acpi_status
  118. acpi_ex_resolve_operands(u16 opcode,
  119. union acpi_operand_object ** stack_ptr,
  120. struct acpi_walk_state * walk_state)
  121. {
  122. union acpi_operand_object *obj_desc;
  123. acpi_status status = AE_OK;
  124. u8 object_type;
  125. u32 arg_types;
  126. const struct acpi_opcode_info *op_info;
  127. u32 this_arg_type;
  128. acpi_object_type type_needed;
  129. u16 target_op = 0;
  130. ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode);
  131. op_info = acpi_ps_get_opcode_info(opcode);
  132. if (op_info->class == AML_CLASS_UNKNOWN) {
  133. return_ACPI_STATUS(AE_AML_BAD_OPCODE);
  134. }
  135. arg_types = op_info->runtime_args;
  136. if (arg_types == ARGI_INVALID_OPCODE) {
  137. ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", opcode));
  138. return_ACPI_STATUS(AE_AML_INTERNAL);
  139. }
  140. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  141. "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
  142. opcode, op_info->name, arg_types));
  143. /*
  144. * Normal exit is with (arg_types == 0) at end of argument list.
  145. * Function will return an exception from within the loop upon
  146. * finding an entry which is not (or cannot be converted
  147. * to) the required type; if stack underflows; or upon
  148. * finding a NULL stack entry (which should not happen).
  149. */
  150. while (GET_CURRENT_ARG_TYPE(arg_types)) {
  151. if (!stack_ptr || !*stack_ptr) {
  152. ACPI_ERROR((AE_INFO, "Null stack entry at %p",
  153. stack_ptr));
  154. return_ACPI_STATUS(AE_AML_INTERNAL);
  155. }
  156. /* Extract useful items */
  157. obj_desc = *stack_ptr;
  158. /* Decode the descriptor type */
  159. switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
  160. case ACPI_DESC_TYPE_NAMED:
  161. /* Namespace Node */
  162. object_type =
  163. ((struct acpi_namespace_node *)obj_desc)->type;
  164. /*
  165. * Resolve an alias object. The construction of these objects
  166. * guarantees that there is only one level of alias indirection;
  167. * thus, the attached object is always the aliased namespace node
  168. */
  169. if (object_type == ACPI_TYPE_LOCAL_ALIAS) {
  170. obj_desc =
  171. acpi_ns_get_attached_object((struct
  172. acpi_namespace_node
  173. *)obj_desc);
  174. *stack_ptr = obj_desc;
  175. object_type =
  176. ((struct acpi_namespace_node *)obj_desc)->
  177. type;
  178. }
  179. break;
  180. case ACPI_DESC_TYPE_OPERAND:
  181. /* ACPI internal object */
  182. object_type = obj_desc->common.type;
  183. /* Check for bad acpi_object_type */
  184. if (!acpi_ut_valid_object_type(object_type)) {
  185. ACPI_ERROR((AE_INFO,
  186. "Bad operand object type [0x%X]",
  187. object_type));
  188. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  189. }
  190. if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
  191. /* Validate the Reference */
  192. switch (obj_desc->reference.class) {
  193. case ACPI_REFCLASS_DEBUG:
  194. target_op = AML_DEBUG_OP;
  195. /*lint -fallthrough */
  196. case ACPI_REFCLASS_ARG:
  197. case ACPI_REFCLASS_LOCAL:
  198. case ACPI_REFCLASS_INDEX:
  199. case ACPI_REFCLASS_REFOF:
  200. case ACPI_REFCLASS_TABLE: /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
  201. case ACPI_REFCLASS_NAME: /* Reference to a named object */
  202. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  203. "Operand is a Reference, Class [%s] %2.2X\n",
  204. acpi_ut_get_reference_name
  205. (obj_desc),
  206. obj_desc->reference.
  207. class));
  208. break;
  209. default:
  210. ACPI_ERROR((AE_INFO,
  211. "Unknown Reference Class 0x%2.2X in %p",
  212. obj_desc->reference.class,
  213. obj_desc));
  214. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  215. }
  216. }
  217. break;
  218. default:
  219. /* Invalid descriptor */
  220. ACPI_ERROR((AE_INFO, "Invalid descriptor %p [%s]",
  221. obj_desc,
  222. acpi_ut_get_descriptor_name(obj_desc)));
  223. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  224. }
  225. /* Get one argument type, point to the next */
  226. this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
  227. INCREMENT_ARG_LIST(arg_types);
  228. /*
  229. * Handle cases where the object does not need to be
  230. * resolved to a value
  231. */
  232. switch (this_arg_type) {
  233. case ARGI_REF_OR_STRING: /* Can be a String or Reference */
  234. if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
  235. ACPI_DESC_TYPE_OPERAND)
  236. && (obj_desc->common.type == ACPI_TYPE_STRING)) {
  237. /*
  238. * String found - the string references a named object and
  239. * must be resolved to a node
  240. */
  241. goto next_operand;
  242. }
  243. /*
  244. * Else not a string - fall through to the normal Reference
  245. * case below
  246. */
  247. /*lint -fallthrough */
  248. case ARGI_REFERENCE: /* References: */
  249. case ARGI_INTEGER_REF:
  250. case ARGI_OBJECT_REF:
  251. case ARGI_DEVICE_REF:
  252. case ARGI_TARGETREF: /* Allows implicit conversion rules before store */
  253. case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
  254. case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */
  255. /*
  256. * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
  257. * A Namespace Node is OK as-is
  258. */
  259. if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
  260. ACPI_DESC_TYPE_NAMED) {
  261. goto next_operand;
  262. }
  263. status =
  264. acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
  265. object_type, obj_desc);
  266. if (ACPI_FAILURE(status)) {
  267. return_ACPI_STATUS(status);
  268. }
  269. goto next_operand;
  270. case ARGI_DATAREFOBJ: /* Store operator only */
  271. /*
  272. * We don't want to resolve index_op reference objects during
  273. * a store because this would be an implicit de_ref_of operation.
  274. * Instead, we just want to store the reference object.
  275. * -- All others must be resolved below.
  276. */
  277. if ((opcode == AML_STORE_OP) &&
  278. ((*stack_ptr)->common.type ==
  279. ACPI_TYPE_LOCAL_REFERENCE)
  280. && ((*stack_ptr)->reference.class == ACPI_REFCLASS_INDEX)) {
  281. goto next_operand;
  282. }
  283. break;
  284. default:
  285. /* All cases covered above */
  286. break;
  287. }
  288. /*
  289. * Resolve this object to a value
  290. */
  291. status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
  292. if (ACPI_FAILURE(status)) {
  293. return_ACPI_STATUS(status);
  294. }
  295. /* Get the resolved object */
  296. obj_desc = *stack_ptr;
  297. /*
  298. * Check the resulting object (value) type
  299. */
  300. switch (this_arg_type) {
  301. /*
  302. * For the simple cases, only one type of resolved object
  303. * is allowed
  304. */
  305. case ARGI_MUTEX:
  306. /* Need an operand of type ACPI_TYPE_MUTEX */
  307. type_needed = ACPI_TYPE_MUTEX;
  308. break;
  309. case ARGI_EVENT:
  310. /* Need an operand of type ACPI_TYPE_EVENT */
  311. type_needed = ACPI_TYPE_EVENT;
  312. break;
  313. case ARGI_PACKAGE: /* Package */
  314. /* Need an operand of type ACPI_TYPE_PACKAGE */
  315. type_needed = ACPI_TYPE_PACKAGE;
  316. break;
  317. case ARGI_ANYTYPE:
  318. /* Any operand type will do */
  319. type_needed = ACPI_TYPE_ANY;
  320. break;
  321. case ARGI_DDBHANDLE:
  322. /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
  323. type_needed = ACPI_TYPE_LOCAL_REFERENCE;
  324. break;
  325. /*
  326. * The more complex cases allow multiple resolved object types
  327. */
  328. case ARGI_INTEGER:
  329. /*
  330. * Need an operand of type ACPI_TYPE_INTEGER,
  331. * But we can implicitly convert from a STRING or BUFFER
  332. * Aka - "Implicit Source Operand Conversion"
  333. */
  334. status =
  335. acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16);
  336. if (ACPI_FAILURE(status)) {
  337. if (status == AE_TYPE) {
  338. ACPI_ERROR((AE_INFO,
  339. "Needed [Integer/String/Buffer], found [%s] %p",
  340. acpi_ut_get_object_type_name
  341. (obj_desc), obj_desc));
  342. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  343. }
  344. return_ACPI_STATUS(status);
  345. }
  346. if (obj_desc != *stack_ptr) {
  347. acpi_ut_remove_reference(obj_desc);
  348. }
  349. goto next_operand;
  350. case ARGI_BUFFER:
  351. /*
  352. * Need an operand of type ACPI_TYPE_BUFFER,
  353. * But we can implicitly convert from a STRING or INTEGER
  354. * Aka - "Implicit Source Operand Conversion"
  355. */
  356. status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
  357. if (ACPI_FAILURE(status)) {
  358. if (status == AE_TYPE) {
  359. ACPI_ERROR((AE_INFO,
  360. "Needed [Integer/String/Buffer], found [%s] %p",
  361. acpi_ut_get_object_type_name
  362. (obj_desc), obj_desc));
  363. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  364. }
  365. return_ACPI_STATUS(status);
  366. }
  367. if (obj_desc != *stack_ptr) {
  368. acpi_ut_remove_reference(obj_desc);
  369. }
  370. goto next_operand;
  371. case ARGI_STRING:
  372. /*
  373. * Need an operand of type ACPI_TYPE_STRING,
  374. * But we can implicitly convert from a BUFFER or INTEGER
  375. * Aka - "Implicit Source Operand Conversion"
  376. */
  377. status = acpi_ex_convert_to_string(obj_desc, stack_ptr,
  378. ACPI_IMPLICIT_CONVERT_HEX);
  379. if (ACPI_FAILURE(status)) {
  380. if (status == AE_TYPE) {
  381. ACPI_ERROR((AE_INFO,
  382. "Needed [Integer/String/Buffer], found [%s] %p",
  383. acpi_ut_get_object_type_name
  384. (obj_desc), obj_desc));
  385. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  386. }
  387. return_ACPI_STATUS(status);
  388. }
  389. if (obj_desc != *stack_ptr) {
  390. acpi_ut_remove_reference(obj_desc);
  391. }
  392. goto next_operand;
  393. case ARGI_COMPUTEDATA:
  394. /* Need an operand of type INTEGER, STRING or BUFFER */
  395. switch (obj_desc->common.type) {
  396. case ACPI_TYPE_INTEGER:
  397. case ACPI_TYPE_STRING:
  398. case ACPI_TYPE_BUFFER:
  399. /* Valid operand */
  400. break;
  401. default:
  402. ACPI_ERROR((AE_INFO,
  403. "Needed [Integer/String/Buffer], found [%s] %p",
  404. acpi_ut_get_object_type_name
  405. (obj_desc), obj_desc));
  406. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  407. }
  408. goto next_operand;
  409. case ARGI_BUFFER_OR_STRING:
  410. /* Need an operand of type STRING or BUFFER */
  411. switch (obj_desc->common.type) {
  412. case ACPI_TYPE_STRING:
  413. case ACPI_TYPE_BUFFER:
  414. /* Valid operand */
  415. break;
  416. case ACPI_TYPE_INTEGER:
  417. /* Highest priority conversion is to type Buffer */
  418. status =
  419. acpi_ex_convert_to_buffer(obj_desc,
  420. stack_ptr);
  421. if (ACPI_FAILURE(status)) {
  422. return_ACPI_STATUS(status);
  423. }
  424. if (obj_desc != *stack_ptr) {
  425. acpi_ut_remove_reference(obj_desc);
  426. }
  427. break;
  428. default:
  429. ACPI_ERROR((AE_INFO,
  430. "Needed [Integer/String/Buffer], found [%s] %p",
  431. acpi_ut_get_object_type_name
  432. (obj_desc), obj_desc));
  433. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  434. }
  435. goto next_operand;
  436. case ARGI_DATAOBJECT:
  437. /*
  438. * ARGI_DATAOBJECT is only used by the size_of operator.
  439. * Need a buffer, string, package, or ref_of reference.
  440. *
  441. * The only reference allowed here is a direct reference to
  442. * a namespace node.
  443. */
  444. switch (obj_desc->common.type) {
  445. case ACPI_TYPE_PACKAGE:
  446. case ACPI_TYPE_STRING:
  447. case ACPI_TYPE_BUFFER:
  448. case ACPI_TYPE_LOCAL_REFERENCE:
  449. /* Valid operand */
  450. break;
  451. default:
  452. ACPI_ERROR((AE_INFO,
  453. "Needed [Buffer/String/Package/Reference], found [%s] %p",
  454. acpi_ut_get_object_type_name
  455. (obj_desc), obj_desc));
  456. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  457. }
  458. goto next_operand;
  459. case ARGI_COMPLEXOBJ:
  460. /* Need a buffer or package or (ACPI 2.0) String */
  461. switch (obj_desc->common.type) {
  462. case ACPI_TYPE_PACKAGE:
  463. case ACPI_TYPE_STRING:
  464. case ACPI_TYPE_BUFFER:
  465. /* Valid operand */
  466. break;
  467. default:
  468. ACPI_ERROR((AE_INFO,
  469. "Needed [Buffer/String/Package], found [%s] %p",
  470. acpi_ut_get_object_type_name
  471. (obj_desc), obj_desc));
  472. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  473. }
  474. goto next_operand;
  475. case ARGI_REGION_OR_BUFFER: /* Used by Load() only */
  476. /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
  477. switch (obj_desc->common.type) {
  478. case ACPI_TYPE_BUFFER:
  479. case ACPI_TYPE_REGION:
  480. /* Valid operand */
  481. break;
  482. default:
  483. ACPI_ERROR((AE_INFO,
  484. "Needed [Region/Buffer], found [%s] %p",
  485. acpi_ut_get_object_type_name
  486. (obj_desc), obj_desc));
  487. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  488. }
  489. goto next_operand;
  490. case ARGI_DATAREFOBJ:
  491. /* Used by the Store() operator only */
  492. switch (obj_desc->common.type) {
  493. case ACPI_TYPE_INTEGER:
  494. case ACPI_TYPE_PACKAGE:
  495. case ACPI_TYPE_STRING:
  496. case ACPI_TYPE_BUFFER:
  497. case ACPI_TYPE_BUFFER_FIELD:
  498. case ACPI_TYPE_LOCAL_REFERENCE:
  499. case ACPI_TYPE_LOCAL_REGION_FIELD:
  500. case ACPI_TYPE_LOCAL_BANK_FIELD:
  501. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  502. case ACPI_TYPE_DDB_HANDLE:
  503. /* Valid operand */
  504. break;
  505. default:
  506. if (acpi_gbl_enable_interpreter_slack) {
  507. /*
  508. * Enable original behavior of Store(), allowing any and all
  509. * objects as the source operand. The ACPI spec does not
  510. * allow this, however.
  511. */
  512. break;
  513. }
  514. if (target_op == AML_DEBUG_OP) {
  515. /* Allow store of any object to the Debug object */
  516. break;
  517. }
  518. ACPI_ERROR((AE_INFO,
  519. "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
  520. acpi_ut_get_object_type_name
  521. (obj_desc), obj_desc));
  522. return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
  523. }
  524. goto next_operand;
  525. default:
  526. /* Unknown type */
  527. ACPI_ERROR((AE_INFO,
  528. "Internal - Unknown ARGI (required operand) type 0x%X",
  529. this_arg_type));
  530. return_ACPI_STATUS(AE_BAD_PARAMETER);
  531. }
  532. /*
  533. * Make sure that the original object was resolved to the
  534. * required object type (Simple cases only).
  535. */
  536. status = acpi_ex_check_object_type(type_needed,
  537. (*stack_ptr)->common.type,
  538. *stack_ptr);
  539. if (ACPI_FAILURE(status)) {
  540. return_ACPI_STATUS(status);
  541. }
  542. next_operand:
  543. /*
  544. * If more operands needed, decrement stack_ptr to point
  545. * to next operand on stack
  546. */
  547. if (GET_CURRENT_ARG_TYPE(arg_types)) {
  548. stack_ptr--;
  549. }
  550. }
  551. ACPI_DUMP_OPERANDS(walk_state->operands,
  552. acpi_ps_get_opcode_name(opcode),
  553. walk_state->num_operands);
  554. return_ACPI_STATUS(status);
  555. }