exoparg1.c 27 KB

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