psxface.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /******************************************************************************
  2. *
  3. * Module Name: psxface - Parser external interfaces
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2012, 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 "accommon.h"
  44. #include "acparser.h"
  45. #include "acdispat.h"
  46. #include "acinterp.h"
  47. #include "actables.h"
  48. #define _COMPONENT ACPI_PARSER
  49. ACPI_MODULE_NAME("psxface")
  50. /* Local Prototypes */
  51. static void acpi_ps_start_trace(struct acpi_evaluate_info *info);
  52. static void acpi_ps_stop_trace(struct acpi_evaluate_info *info);
  53. static void
  54. acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action);
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_debug_trace
  58. *
  59. * PARAMETERS: method_name - Valid ACPI name string
  60. * debug_level - Optional level mask. 0 to use default
  61. * debug_layer - Optional layer mask. 0 to use default
  62. * Flags - bit 1: one shot(1) or persistent(0)
  63. *
  64. * RETURN: Status
  65. *
  66. * DESCRIPTION: External interface to enable debug tracing during control
  67. * method execution
  68. *
  69. ******************************************************************************/
  70. acpi_status
  71. acpi_debug_trace(char *name, u32 debug_level, u32 debug_layer, u32 flags)
  72. {
  73. acpi_status status;
  74. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  75. if (ACPI_FAILURE(status)) {
  76. return (status);
  77. }
  78. /* TBDs: Validate name, allow full path or just nameseg */
  79. acpi_gbl_trace_method_name = *ACPI_CAST_PTR(u32, name);
  80. acpi_gbl_trace_flags = flags;
  81. if (debug_level) {
  82. acpi_gbl_trace_dbg_level = debug_level;
  83. }
  84. if (debug_layer) {
  85. acpi_gbl_trace_dbg_layer = debug_layer;
  86. }
  87. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  88. return (AE_OK);
  89. }
  90. /*******************************************************************************
  91. *
  92. * FUNCTION: acpi_ps_start_trace
  93. *
  94. * PARAMETERS: Info - Method info struct
  95. *
  96. * RETURN: None
  97. *
  98. * DESCRIPTION: Start control method execution trace
  99. *
  100. ******************************************************************************/
  101. static void acpi_ps_start_trace(struct acpi_evaluate_info *info)
  102. {
  103. acpi_status status;
  104. ACPI_FUNCTION_ENTRY();
  105. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  106. if (ACPI_FAILURE(status)) {
  107. return;
  108. }
  109. if ((!acpi_gbl_trace_method_name) ||
  110. (acpi_gbl_trace_method_name != info->resolved_node->name.integer)) {
  111. goto exit;
  112. }
  113. acpi_gbl_original_dbg_level = acpi_dbg_level;
  114. acpi_gbl_original_dbg_layer = acpi_dbg_layer;
  115. acpi_dbg_level = 0x00FFFFFF;
  116. acpi_dbg_layer = ACPI_UINT32_MAX;
  117. if (acpi_gbl_trace_dbg_level) {
  118. acpi_dbg_level = acpi_gbl_trace_dbg_level;
  119. }
  120. if (acpi_gbl_trace_dbg_layer) {
  121. acpi_dbg_layer = acpi_gbl_trace_dbg_layer;
  122. }
  123. exit:
  124. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  125. }
  126. /*******************************************************************************
  127. *
  128. * FUNCTION: acpi_ps_stop_trace
  129. *
  130. * PARAMETERS: Info - Method info struct
  131. *
  132. * RETURN: None
  133. *
  134. * DESCRIPTION: Stop control method execution trace
  135. *
  136. ******************************************************************************/
  137. static void acpi_ps_stop_trace(struct acpi_evaluate_info *info)
  138. {
  139. acpi_status status;
  140. ACPI_FUNCTION_ENTRY();
  141. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  142. if (ACPI_FAILURE(status)) {
  143. return;
  144. }
  145. if ((!acpi_gbl_trace_method_name) ||
  146. (acpi_gbl_trace_method_name != info->resolved_node->name.integer)) {
  147. goto exit;
  148. }
  149. /* Disable further tracing if type is one-shot */
  150. if (acpi_gbl_trace_flags & 1) {
  151. acpi_gbl_trace_method_name = 0;
  152. acpi_gbl_trace_dbg_level = 0;
  153. acpi_gbl_trace_dbg_layer = 0;
  154. }
  155. acpi_dbg_level = acpi_gbl_original_dbg_level;
  156. acpi_dbg_layer = acpi_gbl_original_dbg_layer;
  157. exit:
  158. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  159. }
  160. /*******************************************************************************
  161. *
  162. * FUNCTION: acpi_ps_execute_method
  163. *
  164. * PARAMETERS: Info - Method info block, contains:
  165. * Node - Method Node to execute
  166. * obj_desc - Method object
  167. * Parameters - List of parameters to pass to the method,
  168. * terminated by NULL. Params itself may be
  169. * NULL if no parameters are being passed.
  170. * return_object - Where to put method's return value (if
  171. * any). If NULL, no value is returned.
  172. * parameter_type - Type of Parameter list
  173. * return_object - Where to put method's return value (if
  174. * any). If NULL, no value is returned.
  175. * pass_number - Parse or execute pass
  176. *
  177. * RETURN: Status
  178. *
  179. * DESCRIPTION: Execute a control method
  180. *
  181. ******************************************************************************/
  182. acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
  183. {
  184. acpi_status status;
  185. union acpi_parse_object *op;
  186. struct acpi_walk_state *walk_state;
  187. ACPI_FUNCTION_TRACE(ps_execute_method);
  188. /* Quick validation of DSDT header */
  189. acpi_tb_check_dsdt_header();
  190. /* Validate the Info and method Node */
  191. if (!info || !info->resolved_node) {
  192. return_ACPI_STATUS(AE_NULL_ENTRY);
  193. }
  194. /* Init for new method, wait on concurrency semaphore */
  195. status =
  196. acpi_ds_begin_method_execution(info->resolved_node, info->obj_desc,
  197. NULL);
  198. if (ACPI_FAILURE(status)) {
  199. return_ACPI_STATUS(status);
  200. }
  201. /*
  202. * The caller "owns" the parameters, so give each one an extra reference
  203. */
  204. acpi_ps_update_parameter_list(info, REF_INCREMENT);
  205. /* Begin tracing if requested */
  206. acpi_ps_start_trace(info);
  207. /*
  208. * Execute the method. Performs parse simultaneously
  209. */
  210. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  211. "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
  212. info->resolved_node->name.ascii, info->resolved_node,
  213. info->obj_desc));
  214. /* Create and init a Root Node */
  215. op = acpi_ps_create_scope_op();
  216. if (!op) {
  217. status = AE_NO_MEMORY;
  218. goto cleanup;
  219. }
  220. /* Create and initialize a new walk state */
  221. info->pass_number = ACPI_IMODE_EXECUTE;
  222. walk_state =
  223. acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
  224. NULL, NULL);
  225. if (!walk_state) {
  226. status = AE_NO_MEMORY;
  227. goto cleanup;
  228. }
  229. status = acpi_ds_init_aml_walk(walk_state, op, info->resolved_node,
  230. info->obj_desc->method.aml_start,
  231. info->obj_desc->method.aml_length, info,
  232. info->pass_number);
  233. if (ACPI_FAILURE(status)) {
  234. acpi_ds_delete_walk_state(walk_state);
  235. goto cleanup;
  236. }
  237. if (info->obj_desc->method.info_flags & ACPI_METHOD_MODULE_LEVEL) {
  238. walk_state->parse_flags |= ACPI_PARSE_MODULE_LEVEL;
  239. }
  240. /* Invoke an internal method if necessary */
  241. if (info->obj_desc->method.info_flags & ACPI_METHOD_INTERNAL_ONLY) {
  242. status =
  243. info->obj_desc->method.dispatch.implementation(walk_state);
  244. info->return_object = walk_state->return_desc;
  245. /* Cleanup states */
  246. acpi_ds_scope_stack_clear(walk_state);
  247. acpi_ps_cleanup_scope(&walk_state->parser_state);
  248. acpi_ds_terminate_control_method(walk_state->method_desc,
  249. walk_state);
  250. acpi_ds_delete_walk_state(walk_state);
  251. goto cleanup;
  252. }
  253. /*
  254. * Start method evaluation with an implicit return of zero.
  255. * This is done for Windows compatibility.
  256. */
  257. if (acpi_gbl_enable_interpreter_slack) {
  258. walk_state->implicit_return_obj =
  259. acpi_ut_create_integer_object((u64) 0);
  260. if (!walk_state->implicit_return_obj) {
  261. status = AE_NO_MEMORY;
  262. acpi_ds_delete_walk_state(walk_state);
  263. goto cleanup;
  264. }
  265. }
  266. /* Parse the AML */
  267. status = acpi_ps_parse_aml(walk_state);
  268. /* walk_state was deleted by parse_aml */
  269. cleanup:
  270. acpi_ps_delete_parse_tree(op);
  271. /* End optional tracing */
  272. acpi_ps_stop_trace(info);
  273. /* Take away the extra reference that we gave the parameters above */
  274. acpi_ps_update_parameter_list(info, REF_DECREMENT);
  275. /* Exit now if error above */
  276. if (ACPI_FAILURE(status)) {
  277. return_ACPI_STATUS(status);
  278. }
  279. /*
  280. * If the method has returned an object, signal this to the caller with
  281. * a control exception code
  282. */
  283. if (info->return_object) {
  284. ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Method returned ObjDesc=%p\n",
  285. info->return_object));
  286. ACPI_DUMP_STACK_ENTRY(info->return_object);
  287. status = AE_CTRL_RETURN_VALUE;
  288. }
  289. return_ACPI_STATUS(status);
  290. }
  291. /*******************************************************************************
  292. *
  293. * FUNCTION: acpi_ps_update_parameter_list
  294. *
  295. * PARAMETERS: Info - See struct acpi_evaluate_info
  296. * (Used: parameter_type and Parameters)
  297. * Action - Add or Remove reference
  298. *
  299. * RETURN: Status
  300. *
  301. * DESCRIPTION: Update reference count on all method parameter objects
  302. *
  303. ******************************************************************************/
  304. static void
  305. acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action)
  306. {
  307. u32 i;
  308. if (info->parameters) {
  309. /* Update reference count for each parameter */
  310. for (i = 0; info->parameters[i]; i++) {
  311. /* Ignore errors, just do them all */
  312. (void)acpi_ut_update_object_reference(info->
  313. parameters[i],
  314. action);
  315. }
  316. }
  317. }