psxface.c 11 KB

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