exoparg1.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg1 - AML execution - opcodes with 1 argument
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/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. #if ACPI_MACHINE_WIDTH != 16
  98. return_desc->integer.value = acpi_os_get_timer();
  99. #endif
  100. break;
  101. default: /* Unknown opcode */
  102. ACPI_REPORT_ERROR(("acpi_ex_opcode_0A_0T_1R: Unknown opcode %X\n", 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. } else {
  111. /* Save the return value */
  112. walk_state->result_obj = return_desc;
  113. }
  114. return_ACPI_STATUS(status);
  115. }
  116. /*******************************************************************************
  117. *
  118. * FUNCTION: acpi_ex_opcode_1A_0T_0R
  119. *
  120. * PARAMETERS: walk_state - Current state (contains AML opcode)
  121. *
  122. * RETURN: Status
  123. *
  124. * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
  125. * object stack
  126. *
  127. ******************************************************************************/
  128. acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state)
  129. {
  130. union acpi_operand_object **operand = &walk_state->operands[0];
  131. acpi_status status = AE_OK;
  132. ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_0T_0R",
  133. acpi_ps_get_opcode_name(walk_state->opcode));
  134. /* Examine the AML opcode */
  135. switch (walk_state->opcode) {
  136. case AML_RELEASE_OP: /* Release (mutex_object) */
  137. status = acpi_ex_release_mutex(operand[0], walk_state);
  138. break;
  139. case AML_RESET_OP: /* Reset (event_object) */
  140. status = acpi_ex_system_reset_event(operand[0]);
  141. break;
  142. case AML_SIGNAL_OP: /* Signal (event_object) */
  143. status = acpi_ex_system_signal_event(operand[0]);
  144. break;
  145. case AML_SLEEP_OP: /* Sleep (msec_time) */
  146. status = acpi_ex_system_do_suspend(operand[0]->integer.value);
  147. break;
  148. case AML_STALL_OP: /* Stall (usec_time) */
  149. status =
  150. acpi_ex_system_do_stall((u32) operand[0]->integer.value);
  151. break;
  152. case AML_UNLOAD_OP: /* Unload (Handle) */
  153. status = acpi_ex_unload_table(operand[0]);
  154. break;
  155. default: /* Unknown opcode */
  156. ACPI_REPORT_ERROR(("acpi_ex_opcode_1A_0T_0R: Unknown opcode %X\n", 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_REPORT_ERROR(("acpi_ex_opcode_1A_1T_0R: Unknown opcode %X\n", walk_state->opcode));
  187. status = AE_AML_BAD_OPCODE;
  188. goto cleanup;
  189. }
  190. cleanup:
  191. return_ACPI_STATUS(status);
  192. }
  193. /*******************************************************************************
  194. *
  195. * FUNCTION: acpi_ex_opcode_1A_1T_1R
  196. *
  197. * PARAMETERS: walk_state - Current state (contains AML opcode)
  198. *
  199. * RETURN: Status
  200. *
  201. * DESCRIPTION: Execute opcode with one argument, one target, and a
  202. * return value.
  203. *
  204. ******************************************************************************/
  205. acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
  206. {
  207. acpi_status status = AE_OK;
  208. union acpi_operand_object **operand = &walk_state->operands[0];
  209. union acpi_operand_object *return_desc = NULL;
  210. union acpi_operand_object *return_desc2 = NULL;
  211. u32 temp32;
  212. u32 i;
  213. acpi_integer power_of_ten;
  214. acpi_integer digit;
  215. ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_1T_1R",
  216. acpi_ps_get_opcode_name(walk_state->opcode));
  217. /* Examine the AML opcode */
  218. switch (walk_state->opcode) {
  219. case AML_BIT_NOT_OP:
  220. case AML_FIND_SET_LEFT_BIT_OP:
  221. case AML_FIND_SET_RIGHT_BIT_OP:
  222. case AML_FROM_BCD_OP:
  223. case AML_TO_BCD_OP:
  224. case AML_COND_REF_OF_OP:
  225. /* Create a return object of type Integer for these opcodes */
  226. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  227. if (!return_desc) {
  228. status = AE_NO_MEMORY;
  229. goto cleanup;
  230. }
  231. switch (walk_state->opcode) {
  232. case AML_BIT_NOT_OP: /* Not (Operand, Result) */
  233. return_desc->integer.value = ~operand[0]->integer.value;
  234. break;
  235. case AML_FIND_SET_LEFT_BIT_OP: /* find_set_left_bit (Operand, Result) */
  236. return_desc->integer.value = operand[0]->integer.value;
  237. /*
  238. * Acpi specification describes Integer type as a little
  239. * endian unsigned value, so this boundary condition is valid.
  240. */
  241. for (temp32 = 0; return_desc->integer.value &&
  242. temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
  243. return_desc->integer.value >>= 1;
  244. }
  245. return_desc->integer.value = temp32;
  246. break;
  247. case AML_FIND_SET_RIGHT_BIT_OP: /* find_set_right_bit (Operand, Result) */
  248. return_desc->integer.value = operand[0]->integer.value;
  249. /*
  250. * The Acpi specification describes Integer type as a little
  251. * endian unsigned value, so this boundary condition is valid.
  252. */
  253. for (temp32 = 0; return_desc->integer.value &&
  254. temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
  255. return_desc->integer.value <<= 1;
  256. }
  257. /* Since the bit position is one-based, subtract from 33 (65) */
  258. return_desc->integer.value = temp32 == 0 ? 0 :
  259. (ACPI_INTEGER_BIT_SIZE + 1) - temp32;
  260. break;
  261. case AML_FROM_BCD_OP: /* from_bcd (BCDValue, Result) */
  262. /*
  263. * The 64-bit ACPI integer can hold 16 4-bit BCD characters
  264. * (if table is 32-bit, integer can hold 8 BCD characters)
  265. * Convert each 4-bit BCD value
  266. */
  267. power_of_ten = 1;
  268. return_desc->integer.value = 0;
  269. digit = operand[0]->integer.value;
  270. /* Convert each BCD digit (each is one nybble wide) */
  271. for (i = 0;
  272. (i < acpi_gbl_integer_nybble_width) && (digit > 0);
  273. i++) {
  274. /* Get the least significant 4-bit BCD digit */
  275. temp32 = ((u32) digit) & 0xF;
  276. /* Check the range of the digit */
  277. if (temp32 > 9) {
  278. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  279. "BCD digit too large (not decimal): 0x%X\n",
  280. temp32));
  281. status = AE_AML_NUMERIC_OVERFLOW;
  282. goto cleanup;
  283. }
  284. /* Sum the digit into the result with the current power of 10 */
  285. return_desc->integer.value +=
  286. (((acpi_integer) temp32) * power_of_ten);
  287. /* Shift to next BCD digit */
  288. digit >>= 4;
  289. /* Next power of 10 */
  290. power_of_ten *= 10;
  291. }
  292. break;
  293. case AML_TO_BCD_OP: /* to_bcd (Operand, Result) */
  294. return_desc->integer.value = 0;
  295. digit = operand[0]->integer.value;
  296. /* Each BCD digit is one nybble wide */
  297. for (i = 0;
  298. (i < acpi_gbl_integer_nybble_width) && (digit > 0);
  299. i++) {
  300. (void)acpi_ut_short_divide(digit, 10, &digit,
  301. &temp32);
  302. /*
  303. * Insert the BCD digit that resides in the
  304. * remainder from above
  305. */
  306. return_desc->integer.value |=
  307. (((acpi_integer) temp32) << ACPI_MUL_4(i));
  308. }
  309. /* Overflow if there is any data left in Digit */
  310. if (digit > 0) {
  311. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  312. "Integer too large to convert to BCD: %8.8X%8.8X\n",
  313. ACPI_FORMAT_UINT64(operand
  314. [0]->
  315. integer.
  316. 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_DEBUG_PRINT((ACPI_DB_ERROR,
  419. "%s is obsolete and not implemented\n",
  420. acpi_ps_get_opcode_name(walk_state->opcode)));
  421. status = AE_SUPPORT;
  422. goto cleanup;
  423. default: /* Unknown opcode */
  424. ACPI_REPORT_ERROR(("acpi_ex_opcode_1A_1T_1R: Unknown opcode %X\n", walk_state->opcode));
  425. status = AE_AML_BAD_OPCODE;
  426. goto cleanup;
  427. }
  428. if (ACPI_SUCCESS(status)) {
  429. /* Store the return value computed above into the target object */
  430. status = acpi_ex_store(return_desc, operand[1], walk_state);
  431. }
  432. cleanup:
  433. if (!walk_state->result_obj) {
  434. walk_state->result_obj = return_desc;
  435. }
  436. /* Delete return object on error */
  437. if (ACPI_FAILURE(status)) {
  438. acpi_ut_remove_reference(return_desc);
  439. }
  440. return_ACPI_STATUS(status);
  441. }
  442. /*******************************************************************************
  443. *
  444. * FUNCTION: acpi_ex_opcode_1A_0T_1R
  445. *
  446. * PARAMETERS: walk_state - Current state (contains AML opcode)
  447. *
  448. * RETURN: Status
  449. *
  450. * DESCRIPTION: Execute opcode with one argument, no target, and a return value
  451. *
  452. ******************************************************************************/
  453. acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
  454. {
  455. union acpi_operand_object **operand = &walk_state->operands[0];
  456. union acpi_operand_object *temp_desc;
  457. union acpi_operand_object *return_desc = NULL;
  458. acpi_status status = AE_OK;
  459. u32 type;
  460. acpi_integer value;
  461. ACPI_FUNCTION_TRACE_STR("ex_opcode_1A_0T_1R",
  462. acpi_ps_get_opcode_name(walk_state->opcode));
  463. /* Examine the AML opcode */
  464. switch (walk_state->opcode) {
  465. case AML_LNOT_OP: /* LNot (Operand) */
  466. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  467. if (!return_desc) {
  468. status = AE_NO_MEMORY;
  469. goto cleanup;
  470. }
  471. /*
  472. * Set result to ONES (TRUE) if Value == 0. Note:
  473. * return_desc->Integer.Value is initially == 0 (FALSE) from above.
  474. */
  475. if (!operand[0]->integer.value) {
  476. return_desc->integer.value = ACPI_INTEGER_MAX;
  477. }
  478. break;
  479. case AML_DECREMENT_OP: /* Decrement (Operand) */
  480. case AML_INCREMENT_OP: /* Increment (Operand) */
  481. /*
  482. * Create a new integer. Can't just get the base integer and
  483. * increment it because it may be an Arg or Field.
  484. */
  485. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  486. if (!return_desc) {
  487. status = AE_NO_MEMORY;
  488. goto cleanup;
  489. }
  490. /*
  491. * Since we are expecting a Reference operand, it can be either a
  492. * NS Node or an internal object.
  493. */
  494. temp_desc = operand[0];
  495. if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) ==
  496. ACPI_DESC_TYPE_OPERAND) {
  497. /* Internal reference object - prevent deletion */
  498. acpi_ut_add_reference(temp_desc);
  499. }
  500. /*
  501. * Convert the Reference operand to an Integer (This removes a
  502. * reference on the Operand[0] object)
  503. *
  504. * NOTE: We use LNOT_OP here in order to force resolution of the
  505. * reference operand to an actual integer.
  506. */
  507. status =
  508. acpi_ex_resolve_operands(AML_LNOT_OP, &temp_desc,
  509. walk_state);
  510. if (ACPI_FAILURE(status)) {
  511. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  512. "%s: bad operand(s) %s\n",
  513. acpi_ps_get_opcode_name(walk_state->
  514. opcode),
  515. acpi_format_exception(status)));
  516. goto cleanup;
  517. }
  518. /*
  519. * temp_desc is now guaranteed to be an Integer object --
  520. * Perform the actual increment or decrement
  521. */
  522. if (walk_state->opcode == AML_INCREMENT_OP) {
  523. return_desc->integer.value =
  524. temp_desc->integer.value + 1;
  525. } else {
  526. return_desc->integer.value =
  527. temp_desc->integer.value - 1;
  528. }
  529. /* Finished with this Integer object */
  530. acpi_ut_remove_reference(temp_desc);
  531. /*
  532. * Store the result back (indirectly) through the original
  533. * Reference object
  534. */
  535. status = acpi_ex_store(return_desc, operand[0], walk_state);
  536. break;
  537. case AML_TYPE_OP: /* object_type (source_object) */
  538. /*
  539. * Note: The operand is not resolved at this point because we want to
  540. * get the associated object, not its value. For example, we don't
  541. * want to resolve a field_unit to its value, we want the actual
  542. * field_unit object.
  543. */
  544. /* Get the type of the base object */
  545. status =
  546. acpi_ex_resolve_multiple(walk_state, operand[0], &type,
  547. NULL);
  548. if (ACPI_FAILURE(status)) {
  549. goto cleanup;
  550. }
  551. /* Allocate a descriptor to hold the type. */
  552. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  553. if (!return_desc) {
  554. status = AE_NO_MEMORY;
  555. goto cleanup;
  556. }
  557. return_desc->integer.value = type;
  558. break;
  559. case AML_SIZE_OF_OP: /* size_of (source_object) */
  560. /*
  561. * Note: The operand is not resolved at this point because we want to
  562. * get the associated object, not its value.
  563. */
  564. /* Get the base object */
  565. status = acpi_ex_resolve_multiple(walk_state,
  566. operand[0], &type,
  567. &temp_desc);
  568. if (ACPI_FAILURE(status)) {
  569. goto cleanup;
  570. }
  571. /*
  572. * The type of the base object must be integer, buffer, string, or
  573. * package. All others are not supported.
  574. *
  575. * NOTE: Integer is not specifically supported by the ACPI spec,
  576. * but is supported implicitly via implicit operand conversion.
  577. * rather than bother with conversion, we just use the byte width
  578. * global (4 or 8 bytes).
  579. */
  580. switch (type) {
  581. case ACPI_TYPE_INTEGER:
  582. value = acpi_gbl_integer_byte_width;
  583. break;
  584. case ACPI_TYPE_BUFFER:
  585. value = temp_desc->buffer.length;
  586. break;
  587. case ACPI_TYPE_STRING:
  588. value = temp_desc->string.length;
  589. break;
  590. case ACPI_TYPE_PACKAGE:
  591. value = temp_desc->package.count;
  592. break;
  593. default:
  594. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  595. "size_of - Operand is not Buf/Int/Str/Pkg - found type %s\n",
  596. acpi_ut_get_type_name(type)));
  597. status = AE_AML_OPERAND_TYPE;
  598. goto cleanup;
  599. }
  600. /*
  601. * Now that we have the size of the object, create a result
  602. * object to hold the value
  603. */
  604. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  605. if (!return_desc) {
  606. status = AE_NO_MEMORY;
  607. goto cleanup;
  608. }
  609. return_desc->integer.value = value;
  610. break;
  611. case AML_REF_OF_OP: /* ref_of (source_object) */
  612. status =
  613. acpi_ex_get_object_reference(operand[0], &return_desc,
  614. walk_state);
  615. if (ACPI_FAILURE(status)) {
  616. goto cleanup;
  617. }
  618. break;
  619. case AML_DEREF_OF_OP: /* deref_of (obj_reference | String) */
  620. /* Check for a method local or argument, or standalone String */
  621. if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) !=
  622. ACPI_DESC_TYPE_NAMED) {
  623. switch (ACPI_GET_OBJECT_TYPE(operand[0])) {
  624. case ACPI_TYPE_LOCAL_REFERENCE:
  625. /*
  626. * This is a deref_of (local_x | arg_x)
  627. *
  628. * Must resolve/dereference the local/arg reference first
  629. */
  630. switch (operand[0]->reference.opcode) {
  631. case AML_LOCAL_OP:
  632. case AML_ARG_OP:
  633. /* Set Operand[0] to the value of the local/arg */
  634. status =
  635. acpi_ds_method_data_get_value
  636. (operand[0]->reference.opcode,
  637. operand[0]->reference.offset,
  638. walk_state, &temp_desc);
  639. if (ACPI_FAILURE(status)) {
  640. goto cleanup;
  641. }
  642. /*
  643. * Delete our reference to the input object and
  644. * point to the object just retrieved
  645. */
  646. acpi_ut_remove_reference(operand[0]);
  647. operand[0] = temp_desc;
  648. break;
  649. case AML_REF_OF_OP:
  650. /* Get the object to which the reference refers */
  651. temp_desc =
  652. operand[0]->reference.object;
  653. acpi_ut_remove_reference(operand[0]);
  654. operand[0] = temp_desc;
  655. break;
  656. default:
  657. /* Must be an Index op - handled below */
  658. break;
  659. }
  660. break;
  661. case ACPI_TYPE_STRING:
  662. /*
  663. * This is a deref_of (String). The string is a reference
  664. * to a named ACPI object.
  665. *
  666. * 1) Find the owning Node
  667. * 2) Dereference the node to an actual object. Could be a
  668. * Field, so we need to resolve the node to a value.
  669. */
  670. status =
  671. acpi_ns_get_node_by_path(operand[0]->string.
  672. pointer,
  673. walk_state->
  674. scope_info->scope.
  675. node,
  676. ACPI_NS_SEARCH_PARENT,
  677. ACPI_CAST_INDIRECT_PTR
  678. (struct
  679. acpi_namespace_node,
  680. &return_desc));
  681. if (ACPI_FAILURE(status)) {
  682. goto cleanup;
  683. }
  684. status =
  685. acpi_ex_resolve_node_to_value
  686. (ACPI_CAST_INDIRECT_PTR
  687. (struct acpi_namespace_node, &return_desc),
  688. walk_state);
  689. goto cleanup;
  690. default:
  691. status = AE_AML_OPERAND_TYPE;
  692. goto cleanup;
  693. }
  694. }
  695. /* Operand[0] may have changed from the code above */
  696. if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
  697. ACPI_DESC_TYPE_NAMED) {
  698. /*
  699. * This is a deref_of (object_reference)
  700. * Get the actual object from the Node (This is the dereference).
  701. * This case may only happen when a local_x or arg_x is
  702. * dereferenced above.
  703. */
  704. return_desc = acpi_ns_get_attached_object((struct
  705. acpi_namespace_node
  706. *)
  707. operand[0]);
  708. acpi_ut_add_reference(return_desc);
  709. } else {
  710. /*
  711. * This must be a reference object produced by either the
  712. * Index() or ref_of() operator
  713. */
  714. switch (operand[0]->reference.opcode) {
  715. case AML_INDEX_OP:
  716. /*
  717. * The target type for the Index operator must be
  718. * either a Buffer or a Package
  719. */
  720. switch (operand[0]->reference.target_type) {
  721. case ACPI_TYPE_BUFFER_FIELD:
  722. temp_desc =
  723. operand[0]->reference.object;
  724. /*
  725. * Create a new object that contains one element of the
  726. * buffer -- the element pointed to by the index.
  727. *
  728. * NOTE: index into a buffer is NOT a pointer to a
  729. * sub-buffer of the main buffer, it is only a pointer to a
  730. * single element (byte) of the buffer!
  731. */
  732. return_desc =
  733. acpi_ut_create_internal_object
  734. (ACPI_TYPE_INTEGER);
  735. if (!return_desc) {
  736. status = AE_NO_MEMORY;
  737. goto cleanup;
  738. }
  739. /*
  740. * Since we are returning the value of the buffer at the
  741. * indexed location, we don't need to add an additional
  742. * reference to the buffer itself.
  743. */
  744. return_desc->integer.value =
  745. temp_desc->buffer.
  746. pointer[operand[0]->reference.
  747. offset];
  748. break;
  749. case ACPI_TYPE_PACKAGE:
  750. /*
  751. * Return the referenced element of the package. We must
  752. * add another reference to the referenced object, however.
  753. */
  754. return_desc =
  755. *(operand[0]->reference.where);
  756. if (return_desc) {
  757. acpi_ut_add_reference
  758. (return_desc);
  759. }
  760. break;
  761. default:
  762. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  763. "Unknown Index target_type %X in obj %p\n",
  764. operand[0]->reference.
  765. target_type,
  766. operand[0]));
  767. status = AE_AML_OPERAND_TYPE;
  768. goto cleanup;
  769. }
  770. break;
  771. case AML_REF_OF_OP:
  772. return_desc = operand[0]->reference.object;
  773. if (ACPI_GET_DESCRIPTOR_TYPE(return_desc) ==
  774. ACPI_DESC_TYPE_NAMED) {
  775. return_desc =
  776. acpi_ns_get_attached_object((struct
  777. acpi_namespace_node
  778. *)
  779. return_desc);
  780. }
  781. /* Add another reference to the object! */
  782. acpi_ut_add_reference(return_desc);
  783. break;
  784. default:
  785. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  786. "Unknown opcode in ref(%p) - %X\n",
  787. operand[0],
  788. operand[0]->reference.
  789. opcode));
  790. status = AE_TYPE;
  791. goto cleanup;
  792. }
  793. }
  794. break;
  795. default:
  796. ACPI_REPORT_ERROR(("acpi_ex_opcode_1A_0T_1R: Unknown opcode %X\n", walk_state->opcode));
  797. status = AE_AML_BAD_OPCODE;
  798. goto cleanup;
  799. }
  800. cleanup:
  801. /* Delete return object on error */
  802. if (ACPI_FAILURE(status)) {
  803. acpi_ut_remove_reference(return_desc);
  804. }
  805. walk_state->result_obj = return_desc;
  806. return_ACPI_STATUS(status);
  807. }