exoparg1.c 34 KB

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