exoparg1.c 27 KB

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