psxface.c 11 KB

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