psxface.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /******************************************************************************
  2. *
  3. * Module Name: psxface - Parser external interfaces
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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 "acnamesp.h"
  49. #define _COMPONENT ACPI_PARSER
  50. ACPI_MODULE_NAME("psxface")
  51. /* Local Prototypes */
  52. static void
  53. acpi_ps_update_parameter_list(struct acpi_evaluate_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(const 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. acpi_gbl_trace_method_name = name;
  78. acpi_gbl_trace_flags = flags;
  79. acpi_gbl_trace_dbg_level = debug_level;
  80. acpi_gbl_trace_dbg_layer = debug_layer;
  81. status = AE_OK;
  82. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  83. return (status);
  84. }
  85. /*******************************************************************************
  86. *
  87. * FUNCTION: acpi_ps_execute_method
  88. *
  89. * PARAMETERS: info - Method info block, contains:
  90. * node - Method Node to execute
  91. * obj_desc - Method object
  92. * parameters - List of parameters to pass to the method,
  93. * terminated by NULL. Params itself may be
  94. * NULL if no parameters are being passed.
  95. * return_object - Where to put method's return value (if
  96. * any). If NULL, no value is returned.
  97. * parameter_type - Type of Parameter list
  98. * return_object - Where to put method's return value (if
  99. * any). If NULL, no value is returned.
  100. * pass_number - Parse or execute pass
  101. *
  102. * RETURN: Status
  103. *
  104. * DESCRIPTION: Execute a control method
  105. *
  106. ******************************************************************************/
  107. acpi_status acpi_ps_execute_method(struct acpi_evaluate_info * info)
  108. {
  109. acpi_status status;
  110. union acpi_parse_object *op;
  111. struct acpi_walk_state *walk_state;
  112. ACPI_FUNCTION_TRACE(ps_execute_method);
  113. /* Quick validation of DSDT header */
  114. acpi_tb_check_dsdt_header();
  115. /* Validate the Info and method Node */
  116. if (!info || !info->node) {
  117. return_ACPI_STATUS(AE_NULL_ENTRY);
  118. }
  119. /* Init for new method, wait on concurrency semaphore */
  120. status =
  121. acpi_ds_begin_method_execution(info->node, info->obj_desc, NULL);
  122. if (ACPI_FAILURE(status)) {
  123. return_ACPI_STATUS(status);
  124. }
  125. /*
  126. * The caller "owns" the parameters, so give each one an extra reference
  127. */
  128. acpi_ps_update_parameter_list(info, REF_INCREMENT);
  129. /*
  130. * Execute the method. Performs parse simultaneously
  131. */
  132. ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
  133. "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
  134. info->node->name.ascii, info->node, info->obj_desc));
  135. /* Create and init a Root Node */
  136. op = acpi_ps_create_scope_op(info->obj_desc->method.aml_start);
  137. if (!op) {
  138. status = AE_NO_MEMORY;
  139. goto cleanup;
  140. }
  141. /* Create and initialize a new walk state */
  142. info->pass_number = ACPI_IMODE_EXECUTE;
  143. walk_state =
  144. acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
  145. NULL, NULL);
  146. if (!walk_state) {
  147. status = AE_NO_MEMORY;
  148. goto cleanup;
  149. }
  150. status = acpi_ds_init_aml_walk(walk_state, op, info->node,
  151. info->obj_desc->method.aml_start,
  152. info->obj_desc->method.aml_length, info,
  153. info->pass_number);
  154. if (ACPI_FAILURE(status)) {
  155. acpi_ds_delete_walk_state(walk_state);
  156. goto cleanup;
  157. }
  158. if (info->obj_desc->method.info_flags & ACPI_METHOD_MODULE_LEVEL) {
  159. walk_state->parse_flags |= ACPI_PARSE_MODULE_LEVEL;
  160. }
  161. /* Invoke an internal method if necessary */
  162. if (info->obj_desc->method.info_flags & ACPI_METHOD_INTERNAL_ONLY) {
  163. status =
  164. info->obj_desc->method.dispatch.implementation(walk_state);
  165. info->return_object = walk_state->return_desc;
  166. /* Cleanup states */
  167. acpi_ds_scope_stack_clear(walk_state);
  168. acpi_ps_cleanup_scope(&walk_state->parser_state);
  169. acpi_ds_terminate_control_method(walk_state->method_desc,
  170. walk_state);
  171. acpi_ds_delete_walk_state(walk_state);
  172. goto cleanup;
  173. }
  174. /*
  175. * Start method evaluation with an implicit return of zero.
  176. * This is done for Windows compatibility.
  177. */
  178. if (acpi_gbl_enable_interpreter_slack) {
  179. walk_state->implicit_return_obj =
  180. acpi_ut_create_integer_object((u64) 0);
  181. if (!walk_state->implicit_return_obj) {
  182. status = AE_NO_MEMORY;
  183. acpi_ds_delete_walk_state(walk_state);
  184. goto cleanup;
  185. }
  186. }
  187. /* Parse the AML */
  188. status = acpi_ps_parse_aml(walk_state);
  189. /* walk_state was deleted by parse_aml */
  190. cleanup:
  191. acpi_ps_delete_parse_tree(op);
  192. /* Take away the extra reference that we gave the parameters above */
  193. acpi_ps_update_parameter_list(info, REF_DECREMENT);
  194. /* Exit now if error above */
  195. if (ACPI_FAILURE(status)) {
  196. return_ACPI_STATUS(status);
  197. }
  198. /*
  199. * If the method has returned an object, signal this to the caller with
  200. * a control exception code
  201. */
  202. if (info->return_object) {
  203. ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Method returned ObjDesc=%p\n",
  204. info->return_object));
  205. ACPI_DUMP_STACK_ENTRY(info->return_object);
  206. status = AE_CTRL_RETURN_VALUE;
  207. }
  208. return_ACPI_STATUS(status);
  209. }
  210. /*******************************************************************************
  211. *
  212. * FUNCTION: acpi_ps_update_parameter_list
  213. *
  214. * PARAMETERS: info - See struct acpi_evaluate_info
  215. * (Used: parameter_type and Parameters)
  216. * action - Add or Remove reference
  217. *
  218. * RETURN: Status
  219. *
  220. * DESCRIPTION: Update reference count on all method parameter objects
  221. *
  222. ******************************************************************************/
  223. static void
  224. acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action)
  225. {
  226. u32 i;
  227. if (info->parameters) {
  228. /* Update reference count for each parameter */
  229. for (i = 0; info->parameters[i]; i++) {
  230. /* Ignore errors, just do them all */
  231. (void)acpi_ut_update_object_reference(info->
  232. parameters[i],
  233. action);
  234. }
  235. }
  236. }