psxface.c 10.0 KB

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