psxface.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /******************************************************************************
  2. *
  3. * Module Name: psxface - Parser external interfaces
  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 "actables.h"
  48. #include "acnamesp.h"
  49. #define _COMPONENT ACPI_PARSER
  50. ACPI_MODULE_NAME ("psxface")
  51. /* Local Prototypes */
  52. static void
  53. AcpiPsUpdateParameterList (
  54. ACPI_EVALUATE_INFO *Info,
  55. UINT16 Action);
  56. /*******************************************************************************
  57. *
  58. * FUNCTION: AcpiDebugTrace
  59. *
  60. * PARAMETERS: MethodName - Valid ACPI name string
  61. * DebugLevel - Optional level mask. 0 to use default
  62. * DebugLayer - Optional layer mask. 0 to use default
  63. * Flags - bit 1: one shot(1) or persistent(0)
  64. *
  65. * RETURN: Status
  66. *
  67. * DESCRIPTION: External interface to enable debug tracing during control
  68. * method execution
  69. *
  70. ******************************************************************************/
  71. ACPI_STATUS
  72. AcpiDebugTrace (
  73. const char *Name,
  74. UINT32 DebugLevel,
  75. UINT32 DebugLayer,
  76. UINT32 Flags)
  77. {
  78. ACPI_STATUS Status;
  79. Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
  80. if (ACPI_FAILURE (Status))
  81. {
  82. return (Status);
  83. }
  84. AcpiGbl_TraceMethodName = Name;
  85. AcpiGbl_TraceFlags = Flags;
  86. AcpiGbl_TraceDbgLevel = DebugLevel;
  87. AcpiGbl_TraceDbgLayer = DebugLayer;
  88. Status = AE_OK;
  89. (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
  90. return (Status);
  91. }
  92. /*******************************************************************************
  93. *
  94. * FUNCTION: AcpiPsExecuteMethod
  95. *
  96. * PARAMETERS: Info - Method info block, contains:
  97. * Node - Method Node to execute
  98. * ObjDesc - Method object
  99. * Parameters - List of parameters to pass to the method,
  100. * terminated by NULL. Params itself may be
  101. * NULL if no parameters are being passed.
  102. * ReturnObject - Where to put method's return value (if
  103. * any). If NULL, no value is returned.
  104. * ParameterType - Type of Parameter list
  105. * ReturnObject - Where to put method's return value (if
  106. * any). If NULL, no value is returned.
  107. * PassNumber - Parse or execute pass
  108. *
  109. * RETURN: Status
  110. *
  111. * DESCRIPTION: Execute a control method
  112. *
  113. ******************************************************************************/
  114. ACPI_STATUS
  115. AcpiPsExecuteMethod (
  116. ACPI_EVALUATE_INFO *Info)
  117. {
  118. ACPI_STATUS Status;
  119. ACPI_PARSE_OBJECT *Op;
  120. ACPI_WALK_STATE *WalkState;
  121. ACPI_FUNCTION_TRACE (PsExecuteMethod);
  122. /* Quick validation of DSDT header */
  123. AcpiTbCheckDsdtHeader ();
  124. /* Validate the Info and method Node */
  125. if (!Info || !Info->Node)
  126. {
  127. return_ACPI_STATUS (AE_NULL_ENTRY);
  128. }
  129. /* Init for new method, wait on concurrency semaphore */
  130. Status = AcpiDsBeginMethodExecution (Info->Node, Info->ObjDesc, NULL);
  131. if (ACPI_FAILURE (Status))
  132. {
  133. return_ACPI_STATUS (Status);
  134. }
  135. /*
  136. * The caller "owns" the parameters, so give each one an extra reference
  137. */
  138. AcpiPsUpdateParameterList (Info, REF_INCREMENT);
  139. /*
  140. * Execute the method. Performs parse simultaneously
  141. */
  142. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
  143. "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
  144. Info->Node->Name.Ascii, Info->Node, Info->ObjDesc));
  145. /* Create and init a Root Node */
  146. Op = AcpiPsCreateScopeOp (Info->ObjDesc->Method.AmlStart);
  147. if (!Op)
  148. {
  149. Status = AE_NO_MEMORY;
  150. goto Cleanup;
  151. }
  152. /* Create and initialize a new walk state */
  153. Info->PassNumber = ACPI_IMODE_EXECUTE;
  154. WalkState = AcpiDsCreateWalkState (
  155. Info->ObjDesc->Method.OwnerId, NULL, NULL, NULL);
  156. if (!WalkState)
  157. {
  158. Status = AE_NO_MEMORY;
  159. goto Cleanup;
  160. }
  161. Status = AcpiDsInitAmlWalk (WalkState, Op, Info->Node,
  162. Info->ObjDesc->Method.AmlStart,
  163. Info->ObjDesc->Method.AmlLength, Info, Info->PassNumber);
  164. if (ACPI_FAILURE (Status))
  165. {
  166. AcpiDsDeleteWalkState (WalkState);
  167. goto Cleanup;
  168. }
  169. WalkState->MethodPathname = Info->FullPathname;
  170. WalkState->MethodIsNested = FALSE;
  171. if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)
  172. {
  173. WalkState->ParseFlags |= ACPI_PARSE_MODULE_LEVEL;
  174. }
  175. /* Invoke an internal method if necessary */
  176. if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)
  177. {
  178. Status = Info->ObjDesc->Method.Dispatch.Implementation (WalkState);
  179. Info->ReturnObject = WalkState->ReturnDesc;
  180. /* Cleanup states */
  181. AcpiDsScopeStackClear (WalkState);
  182. AcpiPsCleanupScope (&WalkState->ParserState);
  183. AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState);
  184. AcpiDsDeleteWalkState (WalkState);
  185. goto Cleanup;
  186. }
  187. /*
  188. * Start method evaluation with an implicit return of zero.
  189. * This is done for Windows compatibility.
  190. */
  191. if (AcpiGbl_EnableInterpreterSlack)
  192. {
  193. WalkState->ImplicitReturnObj =
  194. AcpiUtCreateIntegerObject ((UINT64) 0);
  195. if (!WalkState->ImplicitReturnObj)
  196. {
  197. Status = AE_NO_MEMORY;
  198. AcpiDsDeleteWalkState (WalkState);
  199. goto Cleanup;
  200. }
  201. }
  202. /* Parse the AML */
  203. Status = AcpiPsParseAml (WalkState);
  204. /* WalkState was deleted by ParseAml */
  205. Cleanup:
  206. AcpiPsDeleteParseTree (Op);
  207. /* Take away the extra reference that we gave the parameters above */
  208. AcpiPsUpdateParameterList (Info, REF_DECREMENT);
  209. /* Exit now if error above */
  210. if (ACPI_FAILURE (Status))
  211. {
  212. return_ACPI_STATUS (Status);
  213. }
  214. /*
  215. * If the method has returned an object, signal this to the caller with
  216. * a control exception code
  217. */
  218. if (Info->ReturnObject)
  219. {
  220. ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned ObjDesc=%p\n",
  221. Info->ReturnObject));
  222. ACPI_DUMP_STACK_ENTRY (Info->ReturnObject);
  223. Status = AE_CTRL_RETURN_VALUE;
  224. }
  225. return_ACPI_STATUS (Status);
  226. }
  227. /*******************************************************************************
  228. *
  229. * FUNCTION: AcpiPsExecuteTable
  230. *
  231. * PARAMETERS: Info - Method info block, contains:
  232. * Node - Node to where the is entered into the
  233. * namespace
  234. * ObjDesc - Pseudo method object describing the AML
  235. * code of the entire table
  236. * PassNumber - Parse or execute pass
  237. *
  238. * RETURN: Status
  239. *
  240. * DESCRIPTION: Execute a table
  241. *
  242. ******************************************************************************/
  243. ACPI_STATUS
  244. AcpiPsExecuteTable (
  245. ACPI_EVALUATE_INFO *Info)
  246. {
  247. ACPI_STATUS Status;
  248. ACPI_PARSE_OBJECT *Op = NULL;
  249. ACPI_WALK_STATE *WalkState = NULL;
  250. ACPI_FUNCTION_TRACE (PsExecuteTable);
  251. /* Create and init a Root Node */
  252. Op = AcpiPsCreateScopeOp (Info->ObjDesc->Method.AmlStart);
  253. if (!Op)
  254. {
  255. Status = AE_NO_MEMORY;
  256. goto Cleanup;
  257. }
  258. /* Create and initialize a new walk state */
  259. WalkState = AcpiDsCreateWalkState (
  260. Info->ObjDesc->Method.OwnerId, NULL, NULL, NULL);
  261. if (!WalkState)
  262. {
  263. Status = AE_NO_MEMORY;
  264. goto Cleanup;
  265. }
  266. Status = AcpiDsInitAmlWalk (WalkState, Op, Info->Node,
  267. Info->ObjDesc->Method.AmlStart,
  268. Info->ObjDesc->Method.AmlLength, Info, Info->PassNumber);
  269. if (ACPI_FAILURE (Status))
  270. {
  271. goto Cleanup;
  272. }
  273. WalkState->MethodPathname = Info->FullPathname;
  274. WalkState->MethodIsNested = FALSE;
  275. if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)
  276. {
  277. WalkState->ParseFlags |= ACPI_PARSE_MODULE_LEVEL;
  278. }
  279. /* Info->Node is the default location to load the table */
  280. if (Info->Node && Info->Node != AcpiGbl_RootNode)
  281. {
  282. Status = AcpiDsScopeStackPush (
  283. Info->Node, ACPI_TYPE_METHOD, WalkState);
  284. if (ACPI_FAILURE (Status))
  285. {
  286. goto Cleanup;
  287. }
  288. }
  289. /*
  290. * Parse the AML, WalkState will be deleted by ParseAml
  291. */
  292. AcpiExEnterInterpreter ();
  293. Status = AcpiPsParseAml (WalkState);
  294. AcpiExExitInterpreter ();
  295. WalkState = NULL;
  296. Cleanup:
  297. if (WalkState)
  298. {
  299. AcpiDsDeleteWalkState (WalkState);
  300. }
  301. if (Op)
  302. {
  303. AcpiPsDeleteParseTree (Op);
  304. }
  305. return_ACPI_STATUS (Status);
  306. }
  307. /*******************************************************************************
  308. *
  309. * FUNCTION: AcpiPsUpdateParameterList
  310. *
  311. * PARAMETERS: Info - See ACPI_EVALUATE_INFO
  312. * (Used: ParameterType and Parameters)
  313. * Action - Add or Remove reference
  314. *
  315. * RETURN: Status
  316. *
  317. * DESCRIPTION: Update reference count on all method parameter objects
  318. *
  319. ******************************************************************************/
  320. static void
  321. AcpiPsUpdateParameterList (
  322. ACPI_EVALUATE_INFO *Info,
  323. UINT16 Action)
  324. {
  325. UINT32 i;
  326. if (Info->Parameters)
  327. {
  328. /* Update reference count for each parameter */
  329. for (i = 0; Info->Parameters[i]; i++)
  330. {
  331. /* Ignore errors, just do them all */
  332. (void) AcpiUtUpdateObjectReference (
  333. Info->Parameters[i], Action);
  334. }
  335. }
  336. }