exoparg1.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg1 - AML execution - opcodes with 1 argument
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2007, 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/acparser.h>
  44. #include <acpi/acdispat.h>
  45. #include <acpi/acinterp.h>
  46. #include <acpi/amlcode.h>
  47. #include <acpi/acnamesp.h>
  48. #define _COMPONENT ACPI_EXECUTER
  49. ACPI_MODULE_NAME("exoparg1")
  50. /*!
  51. * Naming convention for AML interpreter execution routines.
  52. *
  53. * The routines that begin execution of AML opcodes are named with a common
  54. * convention based upon the number of arguments, the number of target operands,
  55. * and whether or not a value is returned:
  56. *
  57. * AcpiExOpcode_xA_yT_zR
  58. *
  59. * Where:
  60. *
  61. * xA - ARGUMENTS: The number of arguments (input operands) that are
  62. * required for this opcode type (0 through 6 args).
  63. * yT - TARGETS: The number of targets (output operands) that are required
  64. * for this opcode type (0, 1, or 2 targets).
  65. * zR - RETURN VALUE: Indicates whether this opcode type returns a value
  66. * as the function return (0 or 1).
  67. *
  68. * The AcpiExOpcode* functions are called via the Dispatcher component with
  69. * fully resolved operands.
  70. !*/
  71. /*******************************************************************************
  72. *
  73. * FUNCTION: acpi_ex_opcode_0A_0T_1R
  74. *
  75. * PARAMETERS: walk_state - Current state (contains AML opcode)
  76. *
  77. * RETURN: Status
  78. *
  79. * DESCRIPTION: Execute operator with no operands, one return value
  80. *
  81. ******************************************************************************/
  82. acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
  83. {
  84. acpi_status status = AE_OK;
  85. union acpi_operand_object *return_desc = NULL;
  86. ACPI_FUNCTION_TRACE_STR(ex_opcode_0A_0T_1R,
  87. acpi_ps_get_opcode_name(walk_state->opcode));
  88. /* Examine the AML opcode */
  89. switch (walk_state->opcode) {
  90. case AML_TIMER_OP: /* Timer () */
  91. /* Create a return object of type Integer */
  92. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  93. if (!return_desc) {
  94. status = AE_NO_MEMORY;
  95. goto cleanup;
  96. }
  97. return_desc->integer.value = acpi_os_get_timer();
  98. break;
  99. default: /* Unknown opcode */
  100. ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
  101. walk_state->opcode));
  102. status = AE_AML_BAD_OPCODE;
  103. break;
  104. }
  105. cleanup:
  106. /* Delete return object on error */
  107. if ((ACPI_FAILURE(status)) || walk_state->result_obj) {
  108. acpi_ut_remove_reference(return_desc);
  109. } else {
  110. /* Save the return value */
  111. walk_state->result_obj = return_desc;
  112. }
  113. return_ACPI_STATUS(status);
  114. }
  115. /*******************************************************************************
  116. *
  117. * FUNCTION: acpi_ex_opcode_1A_0T_0R
  118. *
  119. * PARAMETERS: walk_state - Current state (contains AML opcode)
  120. *
  121. * RETURN: Status
  122. *
  123. * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
  124. * object stack
  125. *
  126. ******************************************************************************/
  127. acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state)
  128. {
  129. union acpi_operand_object **operand = &walk_state->operands[0];
  130. acpi_status status = AE_OK;
  131. ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_0R,
  132. acpi_ps_get_opcode_name(walk_state->opcode));
  133. /* Examine the AML opcode */
  134. switch (walk_state->opcode) {
  135. case AML_RELEASE_OP: /* Release (mutex_object) */
  136. status = acpi_ex_release_mutex(operand[0], walk_state);
  137. break;
  138. case AML_RESET_OP: /* Reset (event_object) */
  139. status = acpi_ex_system_reset_event(operand[0]);
  140. break;
  141. case AML_SIGNAL_OP: /* Signal (event_object) */
  142. status = acpi_ex_system_signal_event(operand[0]);
  143. break;
  144. case AML_SLEEP_OP: /* Sleep (msec_time) */
  145. status = acpi_ex_system_do_suspend(operand[0]->integer.value);
  146. break;
  147. case AML_STALL_OP: /* Stall (usec_time) */
  148. status =
  149. acpi_ex_system_do_stall((u32) operand[0]->integer.value);
  150. break;
  151. case AML_UNLOAD_OP: /* Unload (Handle) */
  152. status = acpi_ex_unload_table(operand[0]);
  153. break;
  154. default: /* Unknown opcode */
  155. ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
  156. walk_state->opcode));
  157. status = AE_AML_BAD_OPCODE;
  158. break;
  159. }
  160. return_ACPI_STATUS(status);
  161. }
  162. /*******************************************************************************
  163. *
  164. * FUNCTION: acpi_ex_opcode_1A_1T_0R
  165. *
  166. * PARAMETERS: walk_state - Current state (contains AML opcode)
  167. *
  168. * RETURN: Status
  169. *
  170. * DESCRIPTION: Execute opcode with one argument, one target, and no
  171. * return value.
  172. *
  173. ******************************************************************************/
  174. acpi_status acpi_ex_opcode_1A_1T_0R(struct acpi_walk_state *walk_state)
  175. {
  176. acpi_status status = AE_OK;
  177. union acpi_operand_object **operand = &walk_state->operands[0];
  178. ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_0R,
  179. acpi_ps_get_opcode_name(walk_state->opcode));
  180. /* Examine the AML opcode */
  181. switch (walk_state->opcode) {
  182. case AML_LOAD_OP:
  183. status = acpi_ex_load_op(operand[0], operand[1], walk_state);
  184. break;
  185. default: /* Unknown opcode */
  186. ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
  187. walk_state->opcode));
  188. status = AE_AML_BAD_OPCODE;
  189. goto cleanup;
  190. }
  191. cleanup:
  192. return_ACPI_STATUS(status);
  193. }
  194. /*******************************************************************************
  195. *
  196. * FUNCTION: acpi_ex_opcode_1A_1T_1R
  197. *
  198. * PARAMETERS: walk_state - Current state (contains AML opcode)
  199. *
  200. * RETURN: Status
  201. *
  202. * DESCRIPTION: Execute opcode with one argument, one target, and a
  203. * return value.
  204. *
  205. ******************************************************************************/
  206. acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
  207. {
  208. acpi_status status = AE_OK;
  209. union acpi_operand_object **operand = &walk_state->operands[0];
  210. union acpi_operand_object *return_desc = NULL;
  211. union acpi_operand_object *return_desc2 = NULL;
  212. u32 temp32;
  213. u32 i;
  214. acpi_integer power_of_ten;
  215. acpi_integer digit;
  216. ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_1R,
  217. acpi_ps_get_opcode_name(walk_state->opcode));
  218. /* Examine the AML opcode */
  219. switch (walk_state->opcode) {
  220. case AML_BIT_NOT_OP:
  221. case AML_FIND_SET_LEFT_BIT_OP:
  222. case AML_FIND_SET_RIGHT_BIT_OP:
  223. case AML_FROM_BCD_OP:
  224. case AML_TO_BCD_OP:
  225. case AML_COND_REF_OF_OP:
  226. /* Create a return object of type Integer for these opcodes */
  227. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  228. if (!return_desc) {
  229. status = AE_NO_MEMORY;
  230. goto cleanup;
  231. }
  232. switch (walk_state->opcode) {
  233. case AML_BIT_NOT_OP: /* Not (Operand, Result) */
  234. return_desc->integer.value = ~operand[0]->integer.value;
  235. break;
  236. case AML_FIND_SET_LEFT_BIT_OP: /* find_set_left_bit (Operand, Result) */
  237. return_desc->integer.value = operand[0]->integer.value;
  238. /*
  239. * Acpi specification describes Integer type as a little
  240. * endian unsigned value, so this boundary condition is valid.
  241. */
  242. for (temp32 = 0; return_desc->integer.value &&
  243. temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
  244. return_desc->integer.value >>= 1;
  245. }
  246. return_desc->integer.value = temp32;
  247. break;
  248. case AML_FIND_SET_RIGHT_BIT_OP: /* find_set_right_bit (Operand, Result) */
  249. return_desc->integer.value = operand[0]->integer.value;
  250. /*
  251. * The Acpi specification describes Integer type as a little
  252. * endian unsigned value, so this boundary condition is valid.
  253. */
  254. for (temp32 = 0; return_desc->integer.value &&
  255. temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
  256. return_desc->integer.value <<= 1;
  257. }
  258. /* Since the bit position is one-based, subtract from 33 (65) */
  259. return_desc->integer.value =
  260. temp32 ==
  261. 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - temp32;
  262. break;
  263. case AML_FROM_BCD_OP: /* from_bcd (BCDValue, Result) */
  264. /*
  265. * The 64-bit ACPI integer can hold 16 4-bit BCD characters
  266. * (if table is 32-bit, integer can hold 8 BCD characters)
  267. * Convert each 4-bit BCD value
  268. */
  269. power_of_ten = 1;
  270. return_desc->integer.value = 0;
  271. digit = operand[0]->integer.value;
  272. /* Convert each BCD digit (each is one nybble wide) */
  273. for (i = 0;
  274. (i < acpi_gbl_integer_nybble_width) && (digit > 0);
  275. i++) {
  276. /* Get the least significant 4-bit BCD digit */
  277. temp32 = ((u32) digit) & 0xF;
  278. /* Check the range of the digit */
  279. if (temp32 > 9) {
  280. ACPI_ERROR((AE_INFO,
  281. "BCD digit too large (not decimal): 0x%X",
  282. temp32));
  283. status = AE_AML_NUMERIC_OVERFLOW;
  284. goto cleanup;
  285. }
  286. /* Sum the digit into the result with the current power of 10 */
  287. return_desc->integer.value +=
  288. (((acpi_integer) temp32) * power_of_ten);
  289. /* Shift to next BCD digit */
  290. digit >>= 4;
  291. /* Next power of 10 */
  292. power_of_ten *= 10;
  293. }
  294. break;
  295. case AML_TO_BCD_OP: /* to_bcd (Operand, Result) */
  296. return_desc->integer.value = 0;
  297. digit = operand[0]->integer.value;
  298. /* Each BCD digit is one nybble wide */
  299. for (i = 0;
  300. (i < acpi_gbl_integer_nybble_width) && (digit > 0);
  301. i++) {
  302. (void)acpi_ut_short_divide(digit, 10, &digit,
  303. &temp32);
  304. /*
  305. * Insert the BCD digit that resides in the
  306. * remainder from above
  307. */
  308. return_desc->integer.value |=
  309. (((acpi_integer) temp32) << ACPI_MUL_4(i));
  310. }
  311. /* Overflow if there is any data left in Digit */
  312. if (digit > 0) {
  313. ACPI_ERROR((AE_INFO,
  314. "Integer too large to convert to BCD: %8.8X%8.8X",
  315. ACPI_FORMAT_UINT64(operand[0]->
  316. integer.value)));
  317. status = AE_AML_NUMERIC_OVERFLOW;
  318. goto cleanup;
  319. }
  320. break;
  321. case AML_COND_REF_OF_OP: /* cond_ref_of (source_object, Result) */
  322. /*
  323. * This op is a little strange because the internal return value is
  324. * different than the return value stored in the result descriptor
  325. * (There are really two return values)
  326. */
  327. if ((struct acpi_namespace_node *)operand[0] ==
  328. acpi_gbl_root_node) {
  329. /*
  330. * This means that the object does not exist in the namespace,
  331. * return FALSE
  332. */
  333. return_desc->integer.value = 0;
  334. goto cleanup;
  335. }
  336. /* Get the object reference, store it, and remove our reference */
  337. status = acpi_ex_get_object_reference(operand[0],
  338. &return_desc2,
  339. walk_state);
  340. if (ACPI_FAILURE(status)) {
  341. goto cleanup;
  342. }
  343. status =
  344. acpi_ex_store(return_desc2, operand[1], walk_state);
  345. acpi_ut_remove_reference(return_desc2);
  346. /* The object exists in the namespace, return TRUE */
  347. return_desc->integer.value = ACPI_INTEGER_MAX;
  348. goto cleanup;
  349. default:
  350. /* No other opcodes get here */
  351. break;
  352. }
  353. break;
  354. case AML_STORE_OP: /* Store (Source, Target) */
  355. /*
  356. * A store operand is typically a number, string, buffer or lvalue
  357. * Be careful about deleting the source object,
  358. * since the object itself may have been stored.
  359. */
  360. status = acpi_ex_store(operand[0], operand[1], walk_state);
  361. if (ACPI_FAILURE(status)) {
  362. return_ACPI_STATUS(status);
  363. }
  364. /* It is possible that the Store already produced a return object */
  365. if (!walk_state->result_obj) {
  366. /*
  367. * Normally, we would remove a reference on the Operand[0]
  368. * parameter; But since it is being used as the internal return
  369. * object (meaning we would normally increment it), the two
  370. * cancel out, and we simply don't do anything.
  371. */
  372. walk_state->result_obj = operand[0];
  373. walk_state->operands[0] = NULL; /* Prevent deletion */
  374. }
  375. return_ACPI_STATUS(status);
  376. /*
  377. * ACPI 2.0 Opcodes
  378. */
  379. case AML_COPY_OP: /* Copy (Source, Target) */
  380. status =
  381. acpi_ut_copy_iobject_to_iobject(operand[0], &return_desc,
  382. walk_state);
  383. break;
  384. case AML_TO_DECSTRING_OP: /* to_decimal_string (Data, Result) */
  385. status = acpi_ex_convert_to_string(operand[0], &return_desc,
  386. ACPI_EXPLICIT_CONVERT_DECIMAL);
  387. if (return_desc == operand[0]) {
  388. /* No conversion performed, add ref to handle return value */
  389. acpi_ut_add_reference(return_desc);
  390. }
  391. break;
  392. case AML_TO_HEXSTRING_OP: /* to_hex_string (Data, Result) */
  393. status = acpi_ex_convert_to_string(operand[0], &return_desc,
  394. ACPI_EXPLICIT_CONVERT_HEX);
  395. if (return_desc == operand[0]) {
  396. /* No conversion performed, add ref to handle return value */
  397. acpi_ut_add_reference(return_desc);
  398. }
  399. break;
  400. case AML_TO_BUFFER_OP: /* to_buffer (Data, Result) */
  401. status = acpi_ex_convert_to_buffer(operand[0], &return_desc);
  402. if (return_desc == operand[0]) {
  403. /* No conversion performed, add ref to handle return value */
  404. acpi_ut_add_reference(return_desc);
  405. }
  406. break;
  407. case AML_TO_INTEGER_OP: /* to_integer (Data, Result) */
  408. status = acpi_ex_convert_to_integer(operand[0], &return_desc,
  409. ACPI_ANY_BASE);
  410. if (return_desc == operand[0]) {
  411. /* No conversion performed, add ref to handle return value */
  412. acpi_ut_add_reference(return_desc);
  413. }
  414. break;
  415. case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */
  416. case AML_SHIFT_RIGHT_BIT_OP: /* shift_right_bit (Source, bit_num) */
  417. /* These are two obsolete opcodes */
  418. ACPI_ERROR((AE_INFO,
  419. "%s is obsolete and not implemented",
  420. acpi_ps_get_opcode_name(walk_state->opcode)));
  421. status = AE_SUPPORT;
  422. goto cleanup;
  423. default: /* Unknown opcode */
  424. ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
  425. walk_state->opcode));
  426. status = AE_AML_BAD_OPCODE;
  427. goto cleanup;
  428. }
  429. if (ACPI_SUCCESS(status)) {
  430. /* Store the return value computed above into the target object */
  431. status = acpi_ex_store(return_desc, operand[1], walk_state);
  432. }
  433. cleanup:
  434. /* Delete return object on error */
  435. if (ACPI_FAILURE(status)) {
  436. acpi_ut_remove_reference(return_desc);
  437. }
  438. /* Save return object on success */
  439. else if (!walk_state->result_obj) {
  440. walk_state->result_obj = return_desc;
  441. }
  442. return_ACPI_STATUS(status);
  443. }
  444. /*******************************************************************************
  445. *
  446. * FUNCTION: acpi_ex_opcode_1A_0T_1R
  447. *
  448. * PARAMETERS: walk_state - Current state (contains AML opcode)
  449. *
  450. * RETURN: Status
  451. *
  452. * DESCRIPTION: Execute opcode with one argument, no target, and a return value
  453. *
  454. ******************************************************************************/
  455. acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
  456. {
  457. union acpi_operand_object **operand = &walk_state->operands[0];
  458. union acpi_operand_object *temp_desc;
  459. union acpi_operand_object *return_desc = NULL;
  460. acpi_status status = AE_OK;
  461. u32 type;
  462. acpi_integer value;
  463. ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_1R,
  464. acpi_ps_get_opcode_name(walk_state->opcode));
  465. /* Examine the AML opcode */
  466. switch (walk_state->opcode) {
  467. case AML_LNOT_OP: /* LNot (Operand) */
  468. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  469. if (!return_desc) {
  470. status = AE_NO_MEMORY;
  471. goto cleanup;
  472. }
  473. /*
  474. * Set result to ONES (TRUE) if Value == 0. Note:
  475. * return_desc->Integer.Value is initially == 0 (FALSE) from above.
  476. */
  477. if (!operand[0]->integer.value) {
  478. return_desc->integer.value = ACPI_INTEGER_MAX;
  479. }
  480. break;
  481. case AML_DECREMENT_OP: /* Decrement (Operand) */
  482. case AML_INCREMENT_OP: /* Increment (Operand) */
  483. /*
  484. * Create a new integer. Can't just get the base integer and
  485. * increment it because it may be an Arg or Field.
  486. */
  487. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  488. if (!return_desc) {
  489. status = AE_NO_MEMORY;
  490. goto cleanup;
  491. }
  492. /*
  493. * Since we are expecting a Reference operand, it can be either a
  494. * NS Node or an internal object.
  495. */
  496. temp_desc = operand[0];
  497. if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) ==
  498. ACPI_DESC_TYPE_OPERAND) {
  499. /* Internal reference object - prevent deletion */
  500. acpi_ut_add_reference(temp_desc);
  501. }
  502. /*
  503. * Convert the Reference operand to an Integer (This removes a
  504. * reference on the Operand[0] object)
  505. *
  506. * NOTE: We use LNOT_OP here in order to force resolution of the
  507. * reference operand to an actual integer.
  508. */
  509. status =
  510. acpi_ex_resolve_operands(AML_LNOT_OP, &temp_desc,
  511. walk_state);
  512. if (ACPI_FAILURE(status)) {
  513. ACPI_EXCEPTION((AE_INFO, status,
  514. "While resolving operands for [%s]",
  515. acpi_ps_get_opcode_name(walk_state->
  516. opcode)));
  517. goto cleanup;
  518. }
  519. /*
  520. * temp_desc is now guaranteed to be an Integer object --
  521. * Perform the actual increment or decrement
  522. */
  523. if (walk_state->opcode == AML_INCREMENT_OP) {
  524. return_desc->integer.value =
  525. temp_desc->integer.value + 1;
  526. } else {
  527. return_desc->integer.value =
  528. temp_desc->integer.value - 1;
  529. }
  530. /* Finished with this Integer object */
  531. acpi_ut_remove_reference(temp_desc);
  532. /*
  533. * Store the result back (indirectly) through the original
  534. * Reference object
  535. */
  536. status = acpi_ex_store(return_desc, operand[0], walk_state);
  537. break;
  538. case AML_TYPE_OP: /* object_type (source_object) */
  539. /*
  540. * Note: The operand is not resolved at this point because we want to
  541. * get the associated object, not its value. For example, we don't
  542. * want to resolve a field_unit to its value, we want the actual
  543. * field_unit object.
  544. */
  545. /* Get the type of the base object */
  546. status =
  547. acpi_ex_resolve_multiple(walk_state, operand[0], &type,
  548. NULL);
  549. if (ACPI_FAILURE(status)) {
  550. goto cleanup;
  551. }
  552. /* Allocate a descriptor to hold the type. */
  553. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  554. if (!return_desc) {
  555. status = AE_NO_MEMORY;
  556. goto cleanup;
  557. }
  558. return_desc->integer.value = type;
  559. break;
  560. case AML_SIZE_OF_OP: /* size_of (source_object) */
  561. /*
  562. * Note: The operand is not resolved at this point because we want to
  563. * get the associated object, not its value.
  564. */
  565. /* Get the base object */
  566. status = acpi_ex_resolve_multiple(walk_state,
  567. operand[0], &type,
  568. &temp_desc);
  569. if (ACPI_FAILURE(status)) {
  570. goto cleanup;
  571. }
  572. /*
  573. * The type of the base object must be integer, buffer, string, or
  574. * package. All others are not supported.
  575. *
  576. * NOTE: Integer is not specifically supported by the ACPI spec,
  577. * but is supported implicitly via implicit operand conversion.
  578. * rather than bother with conversion, we just use the byte width
  579. * global (4 or 8 bytes).
  580. */
  581. switch (type) {
  582. case ACPI_TYPE_INTEGER:
  583. value = acpi_gbl_integer_byte_width;
  584. break;
  585. case ACPI_TYPE_BUFFER:
  586. value = temp_desc->buffer.length;
  587. break;
  588. case ACPI_TYPE_STRING:
  589. value = temp_desc->string.length;
  590. break;
  591. case ACPI_TYPE_PACKAGE:
  592. value = temp_desc->package.count;
  593. break;
  594. default:
  595. ACPI_ERROR((AE_INFO,
  596. "Operand is not Buf/Int/Str/Pkg - found type %s",
  597. acpi_ut_get_type_name(type)));
  598. status = AE_AML_OPERAND_TYPE;
  599. goto cleanup;
  600. }
  601. /*
  602. * Now that we have the size of the object, create a result
  603. * object to hold the value
  604. */
  605. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  606. if (!return_desc) {
  607. status = AE_NO_MEMORY;
  608. goto cleanup;
  609. }
  610. return_desc->integer.value = value;
  611. break;
  612. case AML_REF_OF_OP: /* ref_of (source_object) */
  613. status =
  614. acpi_ex_get_object_reference(operand[0], &return_desc,
  615. walk_state);
  616. if (ACPI_FAILURE(status)) {
  617. goto cleanup;
  618. }
  619. break;
  620. case AML_DEREF_OF_OP: /* deref_of (obj_reference | String) */
  621. /* Check for a method local or argument, or standalone String */
  622. if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
  623. ACPI_DESC_TYPE_NAMED) {
  624. temp_desc =
  625. acpi_ns_get_attached_object((struct
  626. acpi_namespace_node *)
  627. operand[0]);
  628. if (temp_desc
  629. &&
  630. ((ACPI_GET_OBJECT_TYPE(temp_desc) ==
  631. ACPI_TYPE_STRING)
  632. || (ACPI_GET_OBJECT_TYPE(temp_desc) ==
  633. ACPI_TYPE_LOCAL_REFERENCE))) {
  634. operand[0] = temp_desc;
  635. acpi_ut_add_reference(temp_desc);
  636. } else {
  637. status = AE_AML_OPERAND_TYPE;
  638. goto cleanup;
  639. }
  640. } else {
  641. switch (ACPI_GET_OBJECT_TYPE(operand[0])) {
  642. case ACPI_TYPE_LOCAL_REFERENCE:
  643. /*
  644. * This is a deref_of (local_x | arg_x)
  645. *
  646. * Must resolve/dereference the local/arg reference first
  647. */
  648. switch (operand[0]->reference.opcode) {
  649. case AML_LOCAL_OP:
  650. case AML_ARG_OP:
  651. /* Set Operand[0] to the value of the local/arg */
  652. status =
  653. acpi_ds_method_data_get_value
  654. (operand[0]->reference.opcode,
  655. operand[0]->reference.offset,
  656. walk_state, &temp_desc);
  657. if (ACPI_FAILURE(status)) {
  658. goto cleanup;
  659. }
  660. /*
  661. * Delete our reference to the input object and
  662. * point to the object just retrieved
  663. */
  664. acpi_ut_remove_reference(operand[0]);
  665. operand[0] = temp_desc;
  666. break;
  667. case AML_REF_OF_OP:
  668. /* Get the object to which the reference refers */
  669. temp_desc =
  670. operand[0]->reference.object;
  671. acpi_ut_remove_reference(operand[0]);
  672. operand[0] = temp_desc;
  673. break;
  674. default:
  675. /* Must be an Index op - handled below */
  676. break;
  677. }
  678. break;
  679. case ACPI_TYPE_STRING:
  680. break;
  681. default:
  682. status = AE_AML_OPERAND_TYPE;
  683. goto cleanup;
  684. }
  685. }
  686. if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) !=
  687. ACPI_DESC_TYPE_NAMED) {
  688. if (ACPI_GET_OBJECT_TYPE(operand[0]) ==
  689. ACPI_TYPE_STRING) {
  690. /*
  691. * This is a deref_of (String). The string is a reference
  692. * to a named ACPI object.
  693. *
  694. * 1) Find the owning Node
  695. * 2) Dereference the node to an actual object. Could be a
  696. * Field, so we need to resolve the node to a value.
  697. */
  698. status =
  699. acpi_ns_get_node(walk_state->scope_info->
  700. scope.node,
  701. operand[0]->string.pointer,
  702. ACPI_NS_SEARCH_PARENT,
  703. ACPI_CAST_INDIRECT_PTR
  704. (struct
  705. acpi_namespace_node,
  706. &return_desc));
  707. if (ACPI_FAILURE(status)) {
  708. goto cleanup;
  709. }
  710. status =
  711. acpi_ex_resolve_node_to_value
  712. (ACPI_CAST_INDIRECT_PTR
  713. (struct acpi_namespace_node, &return_desc),
  714. walk_state);
  715. goto cleanup;
  716. }
  717. }
  718. /* Operand[0] may have changed from the code above */
  719. if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
  720. ACPI_DESC_TYPE_NAMED) {
  721. /*
  722. * This is a deref_of (object_reference)
  723. * Get the actual object from the Node (This is the dereference).
  724. * This case may only happen when a local_x or arg_x is
  725. * dereferenced above.
  726. */
  727. return_desc = acpi_ns_get_attached_object((struct
  728. acpi_namespace_node
  729. *)
  730. operand[0]);
  731. acpi_ut_add_reference(return_desc);
  732. } else {
  733. /*
  734. * This must be a reference object produced by either the
  735. * Index() or ref_of() operator
  736. */
  737. switch (operand[0]->reference.opcode) {
  738. case AML_INDEX_OP:
  739. /*
  740. * The target type for the Index operator must be
  741. * either a Buffer or a Package
  742. */
  743. switch (operand[0]->reference.target_type) {
  744. case ACPI_TYPE_BUFFER_FIELD:
  745. temp_desc =
  746. operand[0]->reference.object;
  747. /*
  748. * Create a new object that contains one element of the
  749. * buffer -- the element pointed to by the index.
  750. *
  751. * NOTE: index into a buffer is NOT a pointer to a
  752. * sub-buffer of the main buffer, it is only a pointer to a
  753. * single element (byte) of the buffer!
  754. */
  755. return_desc =
  756. acpi_ut_create_internal_object
  757. (ACPI_TYPE_INTEGER);
  758. if (!return_desc) {
  759. status = AE_NO_MEMORY;
  760. goto cleanup;
  761. }
  762. /*
  763. * Since we are returning the value of the buffer at the
  764. * indexed location, we don't need to add an additional
  765. * reference to the buffer itself.
  766. */
  767. return_desc->integer.value =
  768. temp_desc->buffer.
  769. pointer[operand[0]->reference.
  770. offset];
  771. break;
  772. case ACPI_TYPE_PACKAGE:
  773. /*
  774. * Return the referenced element of the package. We must
  775. * add another reference to the referenced object, however.
  776. */
  777. return_desc =
  778. *(operand[0]->reference.where);
  779. if (return_desc) {
  780. acpi_ut_add_reference
  781. (return_desc);
  782. }
  783. break;
  784. default:
  785. ACPI_ERROR((AE_INFO,
  786. "Unknown Index TargetType %X in obj %p",
  787. operand[0]->reference.
  788. target_type, operand[0]));
  789. status = AE_AML_OPERAND_TYPE;
  790. goto cleanup;
  791. }
  792. break;
  793. case AML_REF_OF_OP:
  794. return_desc = operand[0]->reference.object;
  795. if (ACPI_GET_DESCRIPTOR_TYPE(return_desc) ==
  796. ACPI_DESC_TYPE_NAMED) {
  797. return_desc =
  798. acpi_ns_get_attached_object((struct
  799. acpi_namespace_node
  800. *)
  801. return_desc);
  802. }
  803. /* Add another reference to the object! */
  804. acpi_ut_add_reference(return_desc);
  805. break;
  806. default:
  807. ACPI_ERROR((AE_INFO,
  808. "Unknown opcode in reference(%p) - %X",
  809. operand[0],
  810. operand[0]->reference.opcode));
  811. status = AE_TYPE;
  812. goto cleanup;
  813. }
  814. }
  815. break;
  816. default:
  817. ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
  818. walk_state->opcode));
  819. status = AE_AML_BAD_OPCODE;
  820. goto cleanup;
  821. }
  822. cleanup:
  823. /* Delete return object on error */
  824. if (ACPI_FAILURE(status)) {
  825. acpi_ut_remove_reference(return_desc);
  826. }
  827. /* Save return object on success */
  828. else {
  829. walk_state->result_obj = return_desc;
  830. }
  831. return_ACPI_STATUS(status);
  832. }