nseval.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*******************************************************************************
  2. *
  3. * Module Name: nseval - Object evaluation, includes control method execution
  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/acinterp.h>
  45. #include <acpi/acnamesp.h>
  46. #define _COMPONENT ACPI_NAMESPACE
  47. ACPI_MODULE_NAME("nseval")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_ns_evaluate
  51. *
  52. * PARAMETERS: Info - Evaluation info block, contains:
  53. * prefix_node - Prefix or Method/Object Node to execute
  54. * Pathname - Name of method to execute, If NULL, the
  55. * Node is the object to execute
  56. * Parameters - List of parameters to pass to the method,
  57. * terminated by NULL. Params itself may be
  58. * NULL if no parameters are being passed.
  59. * return_object - Where to put method's return value (if
  60. * any). If NULL, no value is returned.
  61. * parameter_type - Type of Parameter list
  62. * return_object - Where to put method's return value (if
  63. * any). If NULL, no value is returned.
  64. * Flags - ACPI_IGNORE_RETURN_VALUE to delete return
  65. *
  66. * RETURN: Status
  67. *
  68. * DESCRIPTION: Execute a control method or return the current value of an
  69. * ACPI namespace object.
  70. *
  71. * MUTEX: Locks interpreter
  72. *
  73. ******************************************************************************/
  74. acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info)
  75. {
  76. acpi_status status;
  77. ACPI_FUNCTION_TRACE(ns_evaluate);
  78. if (!info) {
  79. return_ACPI_STATUS(AE_BAD_PARAMETER);
  80. }
  81. /* Initialize the return value to an invalid object */
  82. info->return_object = NULL;
  83. /*
  84. * Get the actual namespace node for the target object. Handles these cases:
  85. *
  86. * 1) Null node, Pathname (absolute path)
  87. * 2) Node, Pathname (path relative to Node)
  88. * 3) Node, Null Pathname
  89. */
  90. status = acpi_ns_get_node(info->prefix_node, info->pathname,
  91. ACPI_NS_NO_UPSEARCH, &info->resolved_node);
  92. if (ACPI_FAILURE(status)) {
  93. return_ACPI_STATUS(status);
  94. }
  95. /*
  96. * For a method alias, we must grab the actual method node so that proper
  97. * scoping context will be established before execution.
  98. */
  99. if (acpi_ns_get_type(info->resolved_node) ==
  100. ACPI_TYPE_LOCAL_METHOD_ALIAS) {
  101. info->resolved_node =
  102. ACPI_CAST_PTR(struct acpi_namespace_node,
  103. info->resolved_node->object);
  104. }
  105. ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n", info->pathname,
  106. info->resolved_node,
  107. acpi_ns_get_attached_object(info->resolved_node)));
  108. /*
  109. * Two major cases here:
  110. *
  111. * 1) The object is a control method -- execute it
  112. * 2) The object is not a method -- just return it's current value
  113. */
  114. if (acpi_ns_get_type(info->resolved_node) == ACPI_TYPE_METHOD) {
  115. /*
  116. * 1) Object is a control method - execute it
  117. */
  118. /* Verify that there is a method object associated with this node */
  119. info->obj_desc =
  120. acpi_ns_get_attached_object(info->resolved_node);
  121. if (!info->obj_desc) {
  122. ACPI_ERROR((AE_INFO,
  123. "Control method has no attached sub-object"));
  124. return_ACPI_STATUS(AE_NULL_OBJECT);
  125. }
  126. /*
  127. * Calculate the number of arguments being passed to the method
  128. */
  129. info->param_count = 0;
  130. if (info->parameters) {
  131. while (info->parameters[info->param_count])
  132. info->param_count++;
  133. }
  134. /* Error if too few arguments were passed in */
  135. if (info->param_count < info->obj_desc->method.param_count) {
  136. ACPI_ERROR((AE_INFO,
  137. "Insufficient arguments - "
  138. "method [%4.4s] needs %d, found %d",
  139. acpi_ut_get_node_name(info->resolved_node),
  140. info->obj_desc->method.param_count,
  141. info->param_count));
  142. return_ACPI_STATUS(AE_MISSING_ARGUMENTS);
  143. }
  144. /* Just a warning if too many arguments */
  145. else if (info->param_count >
  146. info->obj_desc->method.param_count) {
  147. ACPI_WARNING((AE_INFO,
  148. "Excess arguments - "
  149. "method [%4.4s] needs %d, found %d",
  150. acpi_ut_get_node_name(info->
  151. resolved_node),
  152. info->obj_desc->method.param_count,
  153. info->param_count));
  154. }
  155. ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:",
  156. ACPI_LV_INFO, _COMPONENT);
  157. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  158. "Method at AML address %p Length %X\n",
  159. info->obj_desc->method.aml_start + 1,
  160. info->obj_desc->method.aml_length - 1));
  161. /*
  162. * Any namespace deletion must acquire both the namespace and
  163. * interpreter locks to ensure that no thread is using the portion of
  164. * the namespace that is being deleted.
  165. *
  166. * Execute the method via the interpreter. The interpreter is locked
  167. * here before calling into the AML parser
  168. */
  169. acpi_ex_enter_interpreter();
  170. status = acpi_ps_execute_method(info);
  171. acpi_ex_exit_interpreter();
  172. } else {
  173. /*
  174. * 2) Object is not a method, return its current value
  175. */
  176. /*
  177. * Objects require additional resolution steps (e.g., the Node may be
  178. * a field that must be read, etc.) -- we can't just grab the object
  179. * out of the node.
  180. *
  181. * Use resolve_node_to_value() to get the associated value.
  182. *
  183. * NOTE: we can get away with passing in NULL for a walk state because
  184. * resolved_node is guaranteed to not be a reference to either a method
  185. * local or a method argument (because this interface is never called
  186. * from a running method.)
  187. *
  188. * Even though we do not directly invoke the interpreter for object
  189. * resolution, we must lock it because we could access an opregion.
  190. * The opregion access code assumes that the interpreter is locked.
  191. */
  192. acpi_ex_enter_interpreter();
  193. /* Function has a strange interface */
  194. status =
  195. acpi_ex_resolve_node_to_value(&info->resolved_node, NULL);
  196. acpi_ex_exit_interpreter();
  197. /*
  198. * If acpi_ex_resolve_node_to_value() succeeded, the return value was placed
  199. * in resolved_node.
  200. */
  201. if (ACPI_SUCCESS(status)) {
  202. status = AE_CTRL_RETURN_VALUE;
  203. info->return_object =
  204. ACPI_CAST_PTR(union acpi_operand_object,
  205. info->resolved_node);
  206. ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
  207. "Returning object %p [%s]\n",
  208. info->return_object,
  209. acpi_ut_get_object_type_name(info->
  210. return_object)));
  211. }
  212. }
  213. /*
  214. * Check if there is a return value that must be dealt with
  215. */
  216. if (status == AE_CTRL_RETURN_VALUE) {
  217. /* If caller does not want the return value, delete it */
  218. if (info->flags & ACPI_IGNORE_RETURN_VALUE) {
  219. acpi_ut_remove_reference(info->return_object);
  220. info->return_object = NULL;
  221. }
  222. /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
  223. status = AE_OK;
  224. }
  225. ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
  226. "*** Completed evaluation of object %s ***\n",
  227. info->pathname));
  228. /*
  229. * Namespace was unlocked by the handling acpi_ns* function, so we
  230. * just return
  231. */
  232. return_ACPI_STATUS(status);
  233. }