dsargs.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /******************************************************************************
  2. *
  3. * Module Name: dsargs - Support for execution of dynamic arguments for static
  4. * objects (regions, fields, buffer fields, etc.)
  5. *
  6. *****************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2015, Intel Corp.
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include "acpi.h"
  44. #include "accommon.h"
  45. #include "acparser.h"
  46. #include "amlcode.h"
  47. #include "acdispat.h"
  48. #include "acnamesp.h"
  49. #define _COMPONENT ACPI_DISPATCHER
  50. ACPI_MODULE_NAME ("dsargs")
  51. /* Local prototypes */
  52. static ACPI_STATUS
  53. AcpiDsExecuteArguments (
  54. ACPI_NAMESPACE_NODE *Node,
  55. ACPI_NAMESPACE_NODE *ScopeNode,
  56. UINT32 AmlLength,
  57. UINT8 *AmlStart);
  58. /*******************************************************************************
  59. *
  60. * FUNCTION: AcpiDsExecuteArguments
  61. *
  62. * PARAMETERS: Node - Object NS node
  63. * ScopeNode - Parent NS node
  64. * AmlLength - Length of executable AML
  65. * AmlStart - Pointer to the AML
  66. *
  67. * RETURN: Status.
  68. *
  69. * DESCRIPTION: Late (deferred) execution of region or field arguments
  70. *
  71. ******************************************************************************/
  72. static ACPI_STATUS
  73. AcpiDsExecuteArguments (
  74. ACPI_NAMESPACE_NODE *Node,
  75. ACPI_NAMESPACE_NODE *ScopeNode,
  76. UINT32 AmlLength,
  77. UINT8 *AmlStart)
  78. {
  79. ACPI_STATUS Status;
  80. ACPI_PARSE_OBJECT *Op;
  81. ACPI_WALK_STATE *WalkState;
  82. ACPI_FUNCTION_TRACE (DsExecuteArguments);
  83. /* Allocate a new parser op to be the root of the parsed tree */
  84. Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart);
  85. if (!Op)
  86. {
  87. return_ACPI_STATUS (AE_NO_MEMORY);
  88. }
  89. /* Save the Node for use in AcpiPsParseAml */
  90. Op->Common.Node = ScopeNode;
  91. /* Create and initialize a new parser state */
  92. WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
  93. if (!WalkState)
  94. {
  95. Status = AE_NO_MEMORY;
  96. goto Cleanup;
  97. }
  98. Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
  99. AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
  100. if (ACPI_FAILURE (Status))
  101. {
  102. AcpiDsDeleteWalkState (WalkState);
  103. goto Cleanup;
  104. }
  105. /* Mark this parse as a deferred opcode */
  106. WalkState->ParseFlags = ACPI_PARSE_DEFERRED_OP;
  107. WalkState->DeferredNode = Node;
  108. /* Pass1: Parse the entire declaration */
  109. Status = AcpiPsParseAml (WalkState);
  110. if (ACPI_FAILURE (Status))
  111. {
  112. goto Cleanup;
  113. }
  114. /* Get and init the Op created above */
  115. Op->Common.Node = Node;
  116. AcpiPsDeleteParseTree (Op);
  117. /* Evaluate the deferred arguments */
  118. Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart);
  119. if (!Op)
  120. {
  121. return_ACPI_STATUS (AE_NO_MEMORY);
  122. }
  123. Op->Common.Node = ScopeNode;
  124. /* Create and initialize a new parser state */
  125. WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
  126. if (!WalkState)
  127. {
  128. Status = AE_NO_MEMORY;
  129. goto Cleanup;
  130. }
  131. /* Execute the opcode and arguments */
  132. Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
  133. AmlLength, NULL, ACPI_IMODE_EXECUTE);
  134. if (ACPI_FAILURE (Status))
  135. {
  136. AcpiDsDeleteWalkState (WalkState);
  137. goto Cleanup;
  138. }
  139. /* Mark this execution as a deferred opcode */
  140. WalkState->DeferredNode = Node;
  141. Status = AcpiPsParseAml (WalkState);
  142. Cleanup:
  143. AcpiPsDeleteParseTree (Op);
  144. return_ACPI_STATUS (Status);
  145. }
  146. /*******************************************************************************
  147. *
  148. * FUNCTION: AcpiDsGetBufferFieldArguments
  149. *
  150. * PARAMETERS: ObjDesc - A valid BufferField object
  151. *
  152. * RETURN: Status.
  153. *
  154. * DESCRIPTION: Get BufferField Buffer and Index. This implements the late
  155. * evaluation of these field attributes.
  156. *
  157. ******************************************************************************/
  158. ACPI_STATUS
  159. AcpiDsGetBufferFieldArguments (
  160. ACPI_OPERAND_OBJECT *ObjDesc)
  161. {
  162. ACPI_OPERAND_OBJECT *ExtraDesc;
  163. ACPI_NAMESPACE_NODE *Node;
  164. ACPI_STATUS Status;
  165. ACPI_FUNCTION_TRACE_PTR (DsGetBufferFieldArguments, ObjDesc);
  166. if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
  167. {
  168. return_ACPI_STATUS (AE_OK);
  169. }
  170. /* Get the AML pointer (method object) and BufferField node */
  171. ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
  172. Node = ObjDesc->BufferField.Node;
  173. ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
  174. ACPI_TYPE_BUFFER_FIELD, Node, NULL));
  175. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
  176. AcpiUtGetNodeName (Node)));
  177. /* Execute the AML code for the TermArg arguments */
  178. Status = AcpiDsExecuteArguments (Node, Node->Parent,
  179. ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
  180. return_ACPI_STATUS (Status);
  181. }
  182. /*******************************************************************************
  183. *
  184. * FUNCTION: AcpiDsGetBankFieldArguments
  185. *
  186. * PARAMETERS: ObjDesc - A valid BankField object
  187. *
  188. * RETURN: Status.
  189. *
  190. * DESCRIPTION: Get BankField BankValue. This implements the late
  191. * evaluation of these field attributes.
  192. *
  193. ******************************************************************************/
  194. ACPI_STATUS
  195. AcpiDsGetBankFieldArguments (
  196. ACPI_OPERAND_OBJECT *ObjDesc)
  197. {
  198. ACPI_OPERAND_OBJECT *ExtraDesc;
  199. ACPI_NAMESPACE_NODE *Node;
  200. ACPI_STATUS Status;
  201. ACPI_FUNCTION_TRACE_PTR (DsGetBankFieldArguments, ObjDesc);
  202. if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
  203. {
  204. return_ACPI_STATUS (AE_OK);
  205. }
  206. /* Get the AML pointer (method object) and BankField node */
  207. ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
  208. Node = ObjDesc->BankField.Node;
  209. ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
  210. ACPI_TYPE_LOCAL_BANK_FIELD, Node, NULL));
  211. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n",
  212. AcpiUtGetNodeName (Node)));
  213. /* Execute the AML code for the TermArg arguments */
  214. Status = AcpiDsExecuteArguments (Node, Node->Parent,
  215. ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
  216. return_ACPI_STATUS (Status);
  217. }
  218. /*******************************************************************************
  219. *
  220. * FUNCTION: AcpiDsGetBufferArguments
  221. *
  222. * PARAMETERS: ObjDesc - A valid Buffer object
  223. *
  224. * RETURN: Status.
  225. *
  226. * DESCRIPTION: Get Buffer length and initializer byte list. This implements
  227. * the late evaluation of these attributes.
  228. *
  229. ******************************************************************************/
  230. ACPI_STATUS
  231. AcpiDsGetBufferArguments (
  232. ACPI_OPERAND_OBJECT *ObjDesc)
  233. {
  234. ACPI_NAMESPACE_NODE *Node;
  235. ACPI_STATUS Status;
  236. ACPI_FUNCTION_TRACE_PTR (DsGetBufferArguments, ObjDesc);
  237. if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
  238. {
  239. return_ACPI_STATUS (AE_OK);
  240. }
  241. /* Get the Buffer node */
  242. Node = ObjDesc->Buffer.Node;
  243. if (!Node)
  244. {
  245. ACPI_ERROR ((AE_INFO,
  246. "No pointer back to namespace node in buffer object %p",
  247. ObjDesc));
  248. return_ACPI_STATUS (AE_AML_INTERNAL);
  249. }
  250. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
  251. /* Execute the AML code for the TermArg arguments */
  252. Status = AcpiDsExecuteArguments (Node, Node,
  253. ObjDesc->Buffer.AmlLength, ObjDesc->Buffer.AmlStart);
  254. return_ACPI_STATUS (Status);
  255. }
  256. /*******************************************************************************
  257. *
  258. * FUNCTION: AcpiDsGetPackageArguments
  259. *
  260. * PARAMETERS: ObjDesc - A valid Package object
  261. *
  262. * RETURN: Status.
  263. *
  264. * DESCRIPTION: Get Package length and initializer byte list. This implements
  265. * the late evaluation of these attributes.
  266. *
  267. ******************************************************************************/
  268. ACPI_STATUS
  269. AcpiDsGetPackageArguments (
  270. ACPI_OPERAND_OBJECT *ObjDesc)
  271. {
  272. ACPI_NAMESPACE_NODE *Node;
  273. ACPI_STATUS Status;
  274. ACPI_FUNCTION_TRACE_PTR (DsGetPackageArguments, ObjDesc);
  275. if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
  276. {
  277. return_ACPI_STATUS (AE_OK);
  278. }
  279. /* Get the Package node */
  280. Node = ObjDesc->Package.Node;
  281. if (!Node)
  282. {
  283. ACPI_ERROR ((AE_INFO,
  284. "No pointer back to namespace node in package %p", ObjDesc));
  285. return_ACPI_STATUS (AE_AML_INTERNAL);
  286. }
  287. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
  288. /* Execute the AML code for the TermArg arguments */
  289. Status = AcpiDsExecuteArguments (Node, Node,
  290. ObjDesc->Package.AmlLength, ObjDesc->Package.AmlStart);
  291. return_ACPI_STATUS (Status);
  292. }
  293. /*******************************************************************************
  294. *
  295. * FUNCTION: AcpiDsGetRegionArguments
  296. *
  297. * PARAMETERS: ObjDesc - A valid region object
  298. *
  299. * RETURN: Status.
  300. *
  301. * DESCRIPTION: Get region address and length. This implements the late
  302. * evaluation of these region attributes.
  303. *
  304. ******************************************************************************/
  305. ACPI_STATUS
  306. AcpiDsGetRegionArguments (
  307. ACPI_OPERAND_OBJECT *ObjDesc)
  308. {
  309. ACPI_NAMESPACE_NODE *Node;
  310. ACPI_STATUS Status;
  311. ACPI_OPERAND_OBJECT *ExtraDesc;
  312. ACPI_FUNCTION_TRACE_PTR (DsGetRegionArguments, ObjDesc);
  313. if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
  314. {
  315. return_ACPI_STATUS (AE_OK);
  316. }
  317. ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
  318. if (!ExtraDesc)
  319. {
  320. return_ACPI_STATUS (AE_NOT_EXIST);
  321. }
  322. /* Get the Region node */
  323. Node = ObjDesc->Region.Node;
  324. ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
  325. ACPI_TYPE_REGION, Node, NULL));
  326. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  327. "[%4.4s] OpRegion Arg Init at AML %p\n",
  328. AcpiUtGetNodeName (Node), ExtraDesc->Extra.AmlStart));
  329. /* Execute the argument AML */
  330. Status = AcpiDsExecuteArguments (Node, ExtraDesc->Extra.ScopeNode,
  331. ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
  332. if (ACPI_FAILURE (Status))
  333. {
  334. return_ACPI_STATUS (Status);
  335. }
  336. Status = AcpiUtAddAddressRange (ObjDesc->Region.SpaceId,
  337. ObjDesc->Region.Address, ObjDesc->Region.Length, Node);
  338. return_ACPI_STATUS (Status);
  339. }