nseval.c 9.1 KB

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