1
1

exoparg2.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /******************************************************************************
  2. *
  3. * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
  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 "acinterp.h"
  46. #include "acevents.h"
  47. #include "amlcode.h"
  48. #define _COMPONENT ACPI_EXECUTER
  49. ACPI_MODULE_NAME ("exoparg2")
  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 (1 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: AcpiExOpcode_2A_0T_0R
  74. *
  75. * PARAMETERS: WalkState - Current walk state
  76. *
  77. * RETURN: Status
  78. *
  79. * DESCRIPTION: Execute opcode with two arguments, no target, and no return
  80. * value.
  81. *
  82. * ALLOCATION: Deletes both operands
  83. *
  84. ******************************************************************************/
  85. ACPI_STATUS
  86. AcpiExOpcode_2A_0T_0R (
  87. ACPI_WALK_STATE *WalkState)
  88. {
  89. ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
  90. ACPI_NAMESPACE_NODE *Node;
  91. UINT32 Value;
  92. ACPI_STATUS Status = AE_OK;
  93. ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_0R,
  94. AcpiPsGetOpcodeName (WalkState->Opcode));
  95. /* Examine the opcode */
  96. switch (WalkState->Opcode)
  97. {
  98. case AML_NOTIFY_OP: /* Notify (NotifyObject, NotifyValue) */
  99. /* The first operand is a namespace node */
  100. Node = (ACPI_NAMESPACE_NODE *) Operand[0];
  101. /* Second value is the notify value */
  102. Value = (UINT32) Operand[1]->Integer.Value;
  103. /* Are notifies allowed on this object? */
  104. if (!AcpiEvIsNotifyObject (Node))
  105. {
  106. ACPI_ERROR ((AE_INFO,
  107. "Unexpected notify object type [%s]",
  108. AcpiUtGetTypeName (Node->Type)));
  109. Status = AE_AML_OPERAND_TYPE;
  110. break;
  111. }
  112. /*
  113. * Dispatch the notify to the appropriate handler
  114. * NOTE: the request is queued for execution after this method
  115. * completes. The notify handlers are NOT invoked synchronously
  116. * from this thread -- because handlers may in turn run other
  117. * control methods.
  118. */
  119. Status = AcpiEvQueueNotifyRequest (Node, Value);
  120. break;
  121. default:
  122. ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
  123. WalkState->Opcode));
  124. Status = AE_AML_BAD_OPCODE;
  125. }
  126. return_ACPI_STATUS (Status);
  127. }
  128. /*******************************************************************************
  129. *
  130. * FUNCTION: AcpiExOpcode_2A_2T_1R
  131. *
  132. * PARAMETERS: WalkState - Current walk state
  133. *
  134. * RETURN: Status
  135. *
  136. * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
  137. * and one implicit return value.
  138. *
  139. ******************************************************************************/
  140. ACPI_STATUS
  141. AcpiExOpcode_2A_2T_1R (
  142. ACPI_WALK_STATE *WalkState)
  143. {
  144. ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
  145. ACPI_OPERAND_OBJECT *ReturnDesc1 = NULL;
  146. ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
  147. ACPI_STATUS Status;
  148. ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_2T_1R,
  149. AcpiPsGetOpcodeName (WalkState->Opcode));
  150. /* Execute the opcode */
  151. switch (WalkState->Opcode)
  152. {
  153. case AML_DIVIDE_OP:
  154. /* Divide (Dividend, Divisor, RemainderResult QuotientResult) */
  155. ReturnDesc1 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
  156. if (!ReturnDesc1)
  157. {
  158. Status = AE_NO_MEMORY;
  159. goto Cleanup;
  160. }
  161. ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
  162. if (!ReturnDesc2)
  163. {
  164. Status = AE_NO_MEMORY;
  165. goto Cleanup;
  166. }
  167. /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
  168. Status = AcpiUtDivide (
  169. Operand[0]->Integer.Value,
  170. Operand[1]->Integer.Value,
  171. &ReturnDesc1->Integer.Value,
  172. &ReturnDesc2->Integer.Value);
  173. if (ACPI_FAILURE (Status))
  174. {
  175. goto Cleanup;
  176. }
  177. break;
  178. default:
  179. ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
  180. WalkState->Opcode));
  181. Status = AE_AML_BAD_OPCODE;
  182. goto Cleanup;
  183. }
  184. /* Store the results to the target reference operands */
  185. Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
  186. if (ACPI_FAILURE (Status))
  187. {
  188. goto Cleanup;
  189. }
  190. Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
  191. if (ACPI_FAILURE (Status))
  192. {
  193. goto Cleanup;
  194. }
  195. Cleanup:
  196. /*
  197. * Since the remainder is not returned indirectly, remove a reference to
  198. * it. Only the quotient is returned indirectly.
  199. */
  200. AcpiUtRemoveReference (ReturnDesc2);
  201. if (ACPI_FAILURE (Status))
  202. {
  203. /* Delete the return object */
  204. AcpiUtRemoveReference (ReturnDesc1);
  205. }
  206. /* Save return object (the remainder) on success */
  207. else
  208. {
  209. WalkState->ResultObj = ReturnDesc1;
  210. }
  211. return_ACPI_STATUS (Status);
  212. }
  213. /*******************************************************************************
  214. *
  215. * FUNCTION: AcpiExOpcode_2A_1T_1R
  216. *
  217. * PARAMETERS: WalkState - Current walk state
  218. *
  219. * RETURN: Status
  220. *
  221. * DESCRIPTION: Execute opcode with two arguments, one target, and a return
  222. * value.
  223. *
  224. ******************************************************************************/
  225. ACPI_STATUS
  226. AcpiExOpcode_2A_1T_1R (
  227. ACPI_WALK_STATE *WalkState)
  228. {
  229. ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
  230. ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
  231. UINT64 Index;
  232. ACPI_STATUS Status = AE_OK;
  233. ACPI_SIZE Length = 0;
  234. ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
  235. AcpiPsGetOpcodeName (WalkState->Opcode));
  236. /* Execute the opcode */
  237. if (WalkState->OpInfo->Flags & AML_MATH)
  238. {
  239. /* All simple math opcodes (add, etc.) */
  240. ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
  241. if (!ReturnDesc)
  242. {
  243. Status = AE_NO_MEMORY;
  244. goto Cleanup;
  245. }
  246. ReturnDesc->Integer.Value = AcpiExDoMathOp (
  247. WalkState->Opcode,
  248. Operand[0]->Integer.Value,
  249. Operand[1]->Integer.Value);
  250. goto StoreResultToTarget;
  251. }
  252. switch (WalkState->Opcode)
  253. {
  254. case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
  255. ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
  256. if (!ReturnDesc)
  257. {
  258. Status = AE_NO_MEMORY;
  259. goto Cleanup;
  260. }
  261. /* ReturnDesc will contain the remainder */
  262. Status = AcpiUtDivide (
  263. Operand[0]->Integer.Value,
  264. Operand[1]->Integer.Value,
  265. NULL,
  266. &ReturnDesc->Integer.Value);
  267. break;
  268. case AML_CONCATENATE_OP: /* Concatenate (Data1, Data2, Result) */
  269. Status = AcpiExDoConcatenate (
  270. Operand[0], Operand[1], &ReturnDesc, WalkState);
  271. break;
  272. case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
  273. /*
  274. * Input object is guaranteed to be a buffer at this point (it may have
  275. * been converted.) Copy the raw buffer data to a new object of
  276. * type String.
  277. */
  278. /*
  279. * Get the length of the new string. It is the smallest of:
  280. * 1) Length of the input buffer
  281. * 2) Max length as specified in the ToString operator
  282. * 3) Length of input buffer up to a zero byte (null terminator)
  283. *
  284. * NOTE: A length of zero is ok, and will create a zero-length, null
  285. * terminated string.
  286. */
  287. while ((Length < Operand[0]->Buffer.Length) && /* Length of input buffer */
  288. (Length < Operand[1]->Integer.Value) && /* Length operand */
  289. (Operand[0]->Buffer.Pointer[Length])) /* Null terminator */
  290. {
  291. Length++;
  292. }
  293. /* Allocate a new string object */
  294. ReturnDesc = AcpiUtCreateStringObject (Length);
  295. if (!ReturnDesc)
  296. {
  297. Status = AE_NO_MEMORY;
  298. goto Cleanup;
  299. }
  300. /*
  301. * Copy the raw buffer data with no transform.
  302. * (NULL terminated already)
  303. */
  304. memcpy (ReturnDesc->String.Pointer,
  305. Operand[0]->Buffer.Pointer, Length);
  306. break;
  307. case AML_CONCATENATE_TEMPLATE_OP:
  308. /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
  309. Status = AcpiExConcatTemplate (
  310. Operand[0], Operand[1], &ReturnDesc, WalkState);
  311. break;
  312. case AML_INDEX_OP: /* Index (Source Index Result) */
  313. /* Create the internal return object */
  314. ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
  315. if (!ReturnDesc)
  316. {
  317. Status = AE_NO_MEMORY;
  318. goto Cleanup;
  319. }
  320. /* Initialize the Index reference object */
  321. Index = Operand[1]->Integer.Value;
  322. ReturnDesc->Reference.Value = (UINT32) Index;
  323. ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
  324. /*
  325. * At this point, the Source operand is a String, Buffer, or Package.
  326. * Verify that the index is within range.
  327. */
  328. switch ((Operand[0])->Common.Type)
  329. {
  330. case ACPI_TYPE_STRING:
  331. if (Index >= Operand[0]->String.Length)
  332. {
  333. Length = Operand[0]->String.Length;
  334. Status = AE_AML_STRING_LIMIT;
  335. }
  336. ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
  337. ReturnDesc->Reference.IndexPointer =
  338. &(Operand[0]->Buffer.Pointer [Index]);
  339. break;
  340. case ACPI_TYPE_BUFFER:
  341. if (Index >= Operand[0]->Buffer.Length)
  342. {
  343. Length = Operand[0]->Buffer.Length;
  344. Status = AE_AML_BUFFER_LIMIT;
  345. }
  346. ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
  347. ReturnDesc->Reference.IndexPointer =
  348. &(Operand[0]->Buffer.Pointer [Index]);
  349. break;
  350. case ACPI_TYPE_PACKAGE:
  351. if (Index >= Operand[0]->Package.Count)
  352. {
  353. Length = Operand[0]->Package.Count;
  354. Status = AE_AML_PACKAGE_LIMIT;
  355. }
  356. ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
  357. ReturnDesc->Reference.Where =
  358. &Operand[0]->Package.Elements [Index];
  359. break;
  360. default:
  361. ACPI_ERROR ((AE_INFO,
  362. "Invalid object type: %X", (Operand[0])->Common.Type));
  363. Status = AE_AML_INTERNAL;
  364. goto Cleanup;
  365. }
  366. /* Failure means that the Index was beyond the end of the object */
  367. if (ACPI_FAILURE (Status))
  368. {
  369. ACPI_BIOS_EXCEPTION ((AE_INFO, Status,
  370. "Index (0x%X%8.8X) is beyond end of object (length 0x%X)",
  371. ACPI_FORMAT_UINT64 (Index), (UINT32) Length));
  372. goto Cleanup;
  373. }
  374. /*
  375. * Save the target object and add a reference to it for the life
  376. * of the index
  377. */
  378. ReturnDesc->Reference.Object = Operand[0];
  379. AcpiUtAddReference (Operand[0]);
  380. /* Store the reference to the Target */
  381. Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
  382. /* Return the reference */
  383. WalkState->ResultObj = ReturnDesc;
  384. goto Cleanup;
  385. default:
  386. ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
  387. WalkState->Opcode));
  388. Status = AE_AML_BAD_OPCODE;
  389. break;
  390. }
  391. StoreResultToTarget:
  392. if (ACPI_SUCCESS (Status))
  393. {
  394. /*
  395. * Store the result of the operation (which is now in ReturnDesc) into
  396. * the Target descriptor.
  397. */
  398. Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
  399. if (ACPI_FAILURE (Status))
  400. {
  401. goto Cleanup;
  402. }
  403. if (!WalkState->ResultObj)
  404. {
  405. WalkState->ResultObj = ReturnDesc;
  406. }
  407. }
  408. Cleanup:
  409. /* Delete return object on error */
  410. if (ACPI_FAILURE (Status))
  411. {
  412. AcpiUtRemoveReference (ReturnDesc);
  413. WalkState->ResultObj = NULL;
  414. }
  415. return_ACPI_STATUS (Status);
  416. }
  417. /*******************************************************************************
  418. *
  419. * FUNCTION: AcpiExOpcode_2A_0T_1R
  420. *
  421. * PARAMETERS: WalkState - Current walk state
  422. *
  423. * RETURN: Status
  424. *
  425. * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
  426. *
  427. ******************************************************************************/
  428. ACPI_STATUS
  429. AcpiExOpcode_2A_0T_1R (
  430. ACPI_WALK_STATE *WalkState)
  431. {
  432. ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
  433. ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
  434. ACPI_STATUS Status = AE_OK;
  435. BOOLEAN LogicalResult = FALSE;
  436. ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_1R,
  437. AcpiPsGetOpcodeName (WalkState->Opcode));
  438. /* Create the internal return object */
  439. ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
  440. if (!ReturnDesc)
  441. {
  442. Status = AE_NO_MEMORY;
  443. goto Cleanup;
  444. }
  445. /* Execute the Opcode */
  446. if (WalkState->OpInfo->Flags & AML_LOGICAL_NUMERIC)
  447. {
  448. /* LogicalOp (Operand0, Operand1) */
  449. Status = AcpiExDoLogicalNumericOp (WalkState->Opcode,
  450. Operand[0]->Integer.Value, Operand[1]->Integer.Value,
  451. &LogicalResult);
  452. goto StoreLogicalResult;
  453. }
  454. else if (WalkState->OpInfo->Flags & AML_LOGICAL)
  455. {
  456. /* LogicalOp (Operand0, Operand1) */
  457. Status = AcpiExDoLogicalOp (WalkState->Opcode, Operand[0],
  458. Operand[1], &LogicalResult);
  459. goto StoreLogicalResult;
  460. }
  461. switch (WalkState->Opcode)
  462. {
  463. case AML_ACQUIRE_OP: /* Acquire (MutexObject, Timeout) */
  464. Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
  465. if (Status == AE_TIME)
  466. {
  467. LogicalResult = TRUE; /* TRUE = Acquire timed out */
  468. Status = AE_OK;
  469. }
  470. break;
  471. case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
  472. Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
  473. if (Status == AE_TIME)
  474. {
  475. LogicalResult = TRUE; /* TRUE, Wait timed out */
  476. Status = AE_OK;
  477. }
  478. break;
  479. default:
  480. ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
  481. WalkState->Opcode));
  482. Status = AE_AML_BAD_OPCODE;
  483. goto Cleanup;
  484. }
  485. StoreLogicalResult:
  486. /*
  487. * Set return value to according to LogicalResult. logical TRUE (all ones)
  488. * Default is FALSE (zero)
  489. */
  490. if (LogicalResult)
  491. {
  492. ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
  493. }
  494. Cleanup:
  495. /* Delete return object on error */
  496. if (ACPI_FAILURE (Status))
  497. {
  498. AcpiUtRemoveReference (ReturnDesc);
  499. }
  500. /* Save return object on success */
  501. else
  502. {
  503. WalkState->ResultObj = ReturnDesc;
  504. }
  505. return_ACPI_STATUS (Status);
  506. }