exoparg1.c 28 KB

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