exoparg1.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg1 - AML execution - opcodes with 1 argument
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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 =
  388. acpi_ex_convert_to_string(operand[0], &return_desc,
  389. ACPI_EXPLICIT_CONVERT_DECIMAL);
  390. if (return_desc == operand[0]) {
  391. /* No conversion performed, add ref to handle return value */
  392. acpi_ut_add_reference(return_desc);
  393. }
  394. break;
  395. case AML_TO_HEXSTRING_OP: /* to_hex_string (Data, Result) */
  396. status =
  397. acpi_ex_convert_to_string(operand[0], &return_desc,
  398. ACPI_EXPLICIT_CONVERT_HEX);
  399. if (return_desc == operand[0]) {
  400. /* No conversion performed, add ref to handle return value */
  401. acpi_ut_add_reference(return_desc);
  402. }
  403. break;
  404. case AML_TO_BUFFER_OP: /* to_buffer (Data, Result) */
  405. status = acpi_ex_convert_to_buffer(operand[0], &return_desc);
  406. if (return_desc == operand[0]) {
  407. /* No conversion performed, add ref to handle return value */
  408. acpi_ut_add_reference(return_desc);
  409. }
  410. break;
  411. case AML_TO_INTEGER_OP: /* to_integer (Data, Result) */
  412. /* Perform "explicit" conversion */
  413. status =
  414. acpi_ex_convert_to_integer(operand[0], &return_desc, 0);
  415. if (return_desc == operand[0]) {
  416. /* No conversion performed, add ref to handle return value */
  417. acpi_ut_add_reference(return_desc);
  418. }
  419. break;
  420. case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */
  421. case AML_SHIFT_RIGHT_BIT_OP: /* shift_right_bit (Source, bit_num) */
  422. /* These are two obsolete opcodes */
  423. ACPI_ERROR((AE_INFO,
  424. "%s is obsolete and not implemented",
  425. acpi_ps_get_opcode_name(walk_state->opcode)));
  426. status = AE_SUPPORT;
  427. goto cleanup;
  428. default: /* Unknown opcode */
  429. ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
  430. walk_state->opcode));
  431. status = AE_AML_BAD_OPCODE;
  432. goto cleanup;
  433. }
  434. if (ACPI_SUCCESS(status)) {
  435. /* Store the return value computed above into the target object */
  436. status = acpi_ex_store(return_desc, operand[1], walk_state);
  437. }
  438. cleanup:
  439. /* Delete return object on error */
  440. if (ACPI_FAILURE(status)) {
  441. acpi_ut_remove_reference(return_desc);
  442. }
  443. /* Save return object on success */
  444. else if (!walk_state->result_obj) {
  445. walk_state->result_obj = return_desc;
  446. }
  447. return_ACPI_STATUS(status);
  448. }
  449. /*******************************************************************************
  450. *
  451. * FUNCTION: acpi_ex_opcode_1A_0T_1R
  452. *
  453. * PARAMETERS: walk_state - Current state (contains AML opcode)
  454. *
  455. * RETURN: Status
  456. *
  457. * DESCRIPTION: Execute opcode with one argument, no target, and a return value
  458. *
  459. ******************************************************************************/
  460. acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
  461. {
  462. union acpi_operand_object **operand = &walk_state->operands[0];
  463. union acpi_operand_object *temp_desc;
  464. union acpi_operand_object *return_desc = NULL;
  465. acpi_status status = AE_OK;
  466. u32 type;
  467. u64 value;
  468. ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_1R,
  469. acpi_ps_get_opcode_name(walk_state->opcode));
  470. /* Examine the AML opcode */
  471. switch (walk_state->opcode) {
  472. case AML_LNOT_OP: /* LNot (Operand) */
  473. return_desc = acpi_ut_create_integer_object((u64) 0);
  474. if (!return_desc) {
  475. status = AE_NO_MEMORY;
  476. goto cleanup;
  477. }
  478. /*
  479. * Set result to ONES (TRUE) if Value == 0. Note:
  480. * return_desc->Integer.Value is initially == 0 (FALSE) from above.
  481. */
  482. if (!operand[0]->integer.value) {
  483. return_desc->integer.value = ACPI_UINT64_MAX;
  484. }
  485. break;
  486. case AML_DECREMENT_OP: /* Decrement (Operand) */
  487. case AML_INCREMENT_OP: /* Increment (Operand) */
  488. /*
  489. * Create a new integer. Can't just get the base integer and
  490. * increment it because it may be an Arg or Field.
  491. */
  492. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  493. if (!return_desc) {
  494. status = AE_NO_MEMORY;
  495. goto cleanup;
  496. }
  497. /*
  498. * Since we are expecting a Reference operand, it can be either a
  499. * NS Node or an internal object.
  500. */
  501. temp_desc = operand[0];
  502. if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) ==
  503. ACPI_DESC_TYPE_OPERAND) {
  504. /* Internal reference object - prevent deletion */
  505. acpi_ut_add_reference(temp_desc);
  506. }
  507. /*
  508. * Convert the Reference operand to an Integer (This removes a
  509. * reference on the Operand[0] object)
  510. *
  511. * NOTE: We use LNOT_OP here in order to force resolution of the
  512. * reference operand to an actual integer.
  513. */
  514. status =
  515. acpi_ex_resolve_operands(AML_LNOT_OP, &temp_desc,
  516. walk_state);
  517. if (ACPI_FAILURE(status)) {
  518. ACPI_EXCEPTION((AE_INFO, status,
  519. "While resolving operands for [%s]",
  520. acpi_ps_get_opcode_name(walk_state->
  521. opcode)));
  522. goto cleanup;
  523. }
  524. /*
  525. * temp_desc is now guaranteed to be an Integer object --
  526. * Perform the actual increment or decrement
  527. */
  528. if (walk_state->opcode == AML_INCREMENT_OP) {
  529. return_desc->integer.value =
  530. temp_desc->integer.value + 1;
  531. } else {
  532. return_desc->integer.value =
  533. temp_desc->integer.value - 1;
  534. }
  535. /* Finished with this Integer object */
  536. acpi_ut_remove_reference(temp_desc);
  537. /*
  538. * Store the result back (indirectly) through the original
  539. * Reference object
  540. */
  541. status = acpi_ex_store(return_desc, operand[0], walk_state);
  542. break;
  543. case AML_OBJECT_TYPE_OP: /* object_type (source_object) */
  544. /*
  545. * Note: The operand is not resolved at this point because we want to
  546. * get the associated object, not its value. For example, we don't
  547. * want to resolve a field_unit to its value, we want the actual
  548. * field_unit object.
  549. */
  550. /* Get the type of the base object */
  551. status =
  552. acpi_ex_resolve_multiple(walk_state, operand[0], &type,
  553. NULL);
  554. if (ACPI_FAILURE(status)) {
  555. goto cleanup;
  556. }
  557. /* Allocate a descriptor to hold the type. */
  558. return_desc = acpi_ut_create_integer_object((u64) type);
  559. if (!return_desc) {
  560. status = AE_NO_MEMORY;
  561. goto cleanup;
  562. }
  563. break;
  564. case AML_SIZE_OF_OP: /* size_of (source_object) */
  565. /*
  566. * Note: The operand is not resolved at this point because we want to
  567. * get the associated object, not its value.
  568. */
  569. /* Get the base object */
  570. status =
  571. acpi_ex_resolve_multiple(walk_state, operand[0], &type,
  572. &temp_desc);
  573. if (ACPI_FAILURE(status)) {
  574. goto cleanup;
  575. }
  576. /*
  577. * The type of the base object must be integer, buffer, string, or
  578. * package. All others are not supported.
  579. *
  580. * NOTE: Integer is not specifically supported by the ACPI spec,
  581. * but is supported implicitly via implicit operand conversion.
  582. * rather than bother with conversion, we just use the byte width
  583. * global (4 or 8 bytes).
  584. */
  585. switch (type) {
  586. case ACPI_TYPE_INTEGER:
  587. value = acpi_gbl_integer_byte_width;
  588. break;
  589. case ACPI_TYPE_STRING:
  590. value = temp_desc->string.length;
  591. break;
  592. case ACPI_TYPE_BUFFER:
  593. /* Buffer arguments may not be evaluated at this point */
  594. status = acpi_ds_get_buffer_arguments(temp_desc);
  595. value = temp_desc->buffer.length;
  596. break;
  597. case ACPI_TYPE_PACKAGE:
  598. /* Package arguments may not be evaluated at this point */
  599. status = acpi_ds_get_package_arguments(temp_desc);
  600. value = temp_desc->package.count;
  601. break;
  602. default:
  603. ACPI_ERROR((AE_INFO,
  604. "Operand must be Buffer/Integer/String/Package"
  605. " - found type %s",
  606. acpi_ut_get_type_name(type)));
  607. status = AE_AML_OPERAND_TYPE;
  608. goto cleanup;
  609. }
  610. if (ACPI_FAILURE(status)) {
  611. goto cleanup;
  612. }
  613. /*
  614. * Now that we have the size of the object, create a result
  615. * object to hold the value
  616. */
  617. return_desc = acpi_ut_create_integer_object(value);
  618. if (!return_desc) {
  619. status = AE_NO_MEMORY;
  620. goto cleanup;
  621. }
  622. break;
  623. case AML_REF_OF_OP: /* ref_of (source_object) */
  624. status =
  625. acpi_ex_get_object_reference(operand[0], &return_desc,
  626. walk_state);
  627. if (ACPI_FAILURE(status)) {
  628. goto cleanup;
  629. }
  630. break;
  631. case AML_DEREF_OF_OP: /* deref_of (obj_reference | String) */
  632. /* Check for a method local or argument, or standalone String */
  633. if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
  634. ACPI_DESC_TYPE_NAMED) {
  635. temp_desc =
  636. acpi_ns_get_attached_object((struct
  637. acpi_namespace_node *)
  638. operand[0]);
  639. if (temp_desc
  640. && ((temp_desc->common.type == ACPI_TYPE_STRING)
  641. || (temp_desc->common.type ==
  642. ACPI_TYPE_LOCAL_REFERENCE))) {
  643. operand[0] = temp_desc;
  644. acpi_ut_add_reference(temp_desc);
  645. } else {
  646. status = AE_AML_OPERAND_TYPE;
  647. goto cleanup;
  648. }
  649. } else {
  650. switch ((operand[0])->common.type) {
  651. case ACPI_TYPE_LOCAL_REFERENCE:
  652. /*
  653. * This is a deref_of (local_x | arg_x)
  654. *
  655. * Must resolve/dereference the local/arg reference first
  656. */
  657. switch (operand[0]->reference.class) {
  658. case ACPI_REFCLASS_LOCAL:
  659. case ACPI_REFCLASS_ARG:
  660. /* Set Operand[0] to the value of the local/arg */
  661. status =
  662. acpi_ds_method_data_get_value
  663. (operand[0]->reference.class,
  664. operand[0]->reference.value,
  665. walk_state, &temp_desc);
  666. if (ACPI_FAILURE(status)) {
  667. goto cleanup;
  668. }
  669. /*
  670. * Delete our reference to the input object and
  671. * point to the object just retrieved
  672. */
  673. acpi_ut_remove_reference(operand[0]);
  674. operand[0] = temp_desc;
  675. break;
  676. case ACPI_REFCLASS_REFOF:
  677. /* Get the object to which the reference refers */
  678. temp_desc =
  679. operand[0]->reference.object;
  680. acpi_ut_remove_reference(operand[0]);
  681. operand[0] = temp_desc;
  682. break;
  683. default:
  684. /* Must be an Index op - handled below */
  685. break;
  686. }
  687. break;
  688. case ACPI_TYPE_STRING:
  689. break;
  690. default:
  691. status = AE_AML_OPERAND_TYPE;
  692. goto cleanup;
  693. }
  694. }
  695. if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) !=
  696. ACPI_DESC_TYPE_NAMED) {
  697. if ((operand[0])->common.type == ACPI_TYPE_STRING) {
  698. /*
  699. * This is a deref_of (String). The string is a reference
  700. * to a named ACPI object.
  701. *
  702. * 1) Find the owning Node
  703. * 2) Dereference the node to an actual object. Could be a
  704. * Field, so we need to resolve the node to a value.
  705. */
  706. status =
  707. acpi_ns_get_node_unlocked(walk_state->
  708. scope_info->scope.
  709. node,
  710. operand[0]->
  711. string.pointer,
  712. ACPI_NS_SEARCH_PARENT,
  713. ACPI_CAST_INDIRECT_PTR
  714. (struct
  715. acpi_namespace_node,
  716. &return_desc));
  717. if (ACPI_FAILURE(status)) {
  718. goto cleanup;
  719. }
  720. status =
  721. acpi_ex_resolve_node_to_value
  722. (ACPI_CAST_INDIRECT_PTR
  723. (struct acpi_namespace_node, &return_desc),
  724. walk_state);
  725. goto cleanup;
  726. }
  727. }
  728. /* Operand[0] may have changed from the code above */
  729. if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
  730. ACPI_DESC_TYPE_NAMED) {
  731. /*
  732. * This is a deref_of (object_reference)
  733. * Get the actual object from the Node (This is the dereference).
  734. * This case may only happen when a local_x or arg_x is
  735. * dereferenced above.
  736. */
  737. return_desc = acpi_ns_get_attached_object((struct
  738. acpi_namespace_node
  739. *)
  740. operand[0]);
  741. acpi_ut_add_reference(return_desc);
  742. } else {
  743. /*
  744. * This must be a reference object produced by either the
  745. * Index() or ref_of() operator
  746. */
  747. switch (operand[0]->reference.class) {
  748. case ACPI_REFCLASS_INDEX:
  749. /*
  750. * The target type for the Index operator must be
  751. * either a Buffer or a Package
  752. */
  753. switch (operand[0]->reference.target_type) {
  754. case ACPI_TYPE_BUFFER_FIELD:
  755. temp_desc =
  756. operand[0]->reference.object;
  757. /*
  758. * Create a new object that contains one element of the
  759. * buffer -- the element pointed to by the index.
  760. *
  761. * NOTE: index into a buffer is NOT a pointer to a
  762. * sub-buffer of the main buffer, it is only a pointer to a
  763. * single element (byte) of the buffer!
  764. *
  765. * Since we are returning the value of the buffer at the
  766. * indexed location, we don't need to add an additional
  767. * reference to the buffer itself.
  768. */
  769. return_desc =
  770. acpi_ut_create_integer_object((u64)
  771. temp_desc->buffer.pointer[operand[0]->reference.value]);
  772. if (!return_desc) {
  773. status = AE_NO_MEMORY;
  774. goto cleanup;
  775. }
  776. break;
  777. case ACPI_TYPE_PACKAGE:
  778. /*
  779. * Return the referenced element of the package. We must
  780. * add another reference to the referenced object, however.
  781. */
  782. return_desc =
  783. *(operand[0]->reference.where);
  784. if (!return_desc) {
  785. /*
  786. * Element is NULL, do not allow the dereference.
  787. * This provides compatibility with other ACPI
  788. * implementations.
  789. */
  790. return_ACPI_STATUS
  791. (AE_AML_UNINITIALIZED_ELEMENT);
  792. }
  793. acpi_ut_add_reference(return_desc);
  794. break;
  795. default:
  796. ACPI_ERROR((AE_INFO,
  797. "Unknown Index TargetType 0x%X in reference object %p",
  798. operand[0]->reference.
  799. target_type, operand[0]));
  800. status = AE_AML_OPERAND_TYPE;
  801. goto cleanup;
  802. }
  803. break;
  804. case ACPI_REFCLASS_REFOF:
  805. return_desc = operand[0]->reference.object;
  806. if (ACPI_GET_DESCRIPTOR_TYPE(return_desc) ==
  807. ACPI_DESC_TYPE_NAMED) {
  808. return_desc =
  809. acpi_ns_get_attached_object((struct
  810. acpi_namespace_node
  811. *)
  812. return_desc);
  813. if (!return_desc) {
  814. break;
  815. }
  816. /*
  817. * June 2013:
  818. * buffer_fields/field_units require additional resolution
  819. */
  820. switch (return_desc->common.type) {
  821. case ACPI_TYPE_BUFFER_FIELD:
  822. case ACPI_TYPE_LOCAL_REGION_FIELD:
  823. case ACPI_TYPE_LOCAL_BANK_FIELD:
  824. case ACPI_TYPE_LOCAL_INDEX_FIELD:
  825. status =
  826. acpi_ex_read_data_from_field
  827. (walk_state, return_desc,
  828. &temp_desc);
  829. if (ACPI_FAILURE(status)) {
  830. goto cleanup;
  831. }
  832. return_desc = temp_desc;
  833. break;
  834. default:
  835. /* Add another reference to the object */
  836. acpi_ut_add_reference
  837. (return_desc);
  838. break;
  839. }
  840. }
  841. break;
  842. default:
  843. ACPI_ERROR((AE_INFO,
  844. "Unknown class in reference(%p) - 0x%2.2X",
  845. operand[0],
  846. operand[0]->reference.class));
  847. status = AE_TYPE;
  848. goto cleanup;
  849. }
  850. }
  851. break;
  852. default:
  853. ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
  854. walk_state->opcode));
  855. status = AE_AML_BAD_OPCODE;
  856. goto cleanup;
  857. }
  858. cleanup:
  859. /* Delete return object on error */
  860. if (ACPI_FAILURE(status)) {
  861. acpi_ut_remove_reference(return_desc);
  862. }
  863. /* Save return object on success */
  864. else {
  865. walk_state->result_obj = return_desc;
  866. }
  867. return_ACPI_STATUS(status);
  868. }