exoparg1.c 27 KB

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