nseval.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. struct acpi_namespace_node *node;
  78. ACPI_FUNCTION_TRACE(ns_evaluate);
  79. if (!info) {
  80. return_ACPI_STATUS(AE_BAD_PARAMETER);
  81. }
  82. /* Initialize the return value to an invalid object */
  83. info->return_object = NULL;
  84. /*
  85. * Get the actual namespace node for the target object. Handles these cases:
  86. *
  87. * 1) Null node, Pathname (absolute path)
  88. * 2) Node, Pathname (path relative to Node)
  89. * 3) Node, Null Pathname
  90. */
  91. status = acpi_ns_get_node(info->prefix_node, info->pathname,
  92. ACPI_NS_NO_UPSEARCH, &info->resolved_node);
  93. if (ACPI_FAILURE(status)) {
  94. return_ACPI_STATUS(status);
  95. }
  96. /*
  97. * For a method alias, we must grab the actual method node so that proper
  98. * scoping context will be established before execution.
  99. */
  100. if (acpi_ns_get_type(info->resolved_node) ==
  101. ACPI_TYPE_LOCAL_METHOD_ALIAS) {
  102. info->resolved_node =
  103. ACPI_CAST_PTR(struct acpi_namespace_node,
  104. info->resolved_node->object);
  105. }
  106. ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n", info->pathname,
  107. info->resolved_node,
  108. acpi_ns_get_attached_object(info->resolved_node)));
  109. node = info->resolved_node;
  110. /*
  111. * Two major cases here:
  112. *
  113. * 1) The object is a control method -- execute it
  114. * 2) The object is not a method -- just return it's current value
  115. */
  116. if (acpi_ns_get_type(info->resolved_node) == ACPI_TYPE_METHOD) {
  117. /*
  118. * 1) Object is a control method - execute it
  119. */
  120. /* Verify that there is a method object associated with this node */
  121. info->obj_desc =
  122. acpi_ns_get_attached_object(info->resolved_node);
  123. if (!info->obj_desc) {
  124. ACPI_ERROR((AE_INFO,
  125. "Control method has no attached sub-object"));
  126. return_ACPI_STATUS(AE_NULL_OBJECT);
  127. }
  128. /*
  129. * Calculate the number of arguments being passed to the method
  130. */
  131. info->param_count = 0;
  132. if (info->parameters) {
  133. while (info->parameters[info->param_count])
  134. info->param_count++;
  135. }
  136. /*
  137. * Warning if too few or too many arguments have been passed by the
  138. * caller. We don't want to abort here with an error because an
  139. * incorrect number of arguments may not cause the method to fail.
  140. * However, the method will fail if there are too few arguments passed
  141. * and the method attempts to use one of the missing ones.
  142. */
  143. if (info->param_count < info->obj_desc->method.param_count) {
  144. ACPI_WARNING((AE_INFO,
  145. "Insufficient arguments - "
  146. "method [%4.4s] needs %d, found %d",
  147. acpi_ut_get_node_name(info->resolved_node),
  148. info->obj_desc->method.param_count,
  149. info->param_count));
  150. } else if (info->param_count >
  151. info->obj_desc->method.param_count) {
  152. ACPI_WARNING((AE_INFO,
  153. "Excess arguments - "
  154. "method [%4.4s] needs %d, found %d",
  155. acpi_ut_get_node_name(info->
  156. resolved_node),
  157. info->obj_desc->method.param_count,
  158. info->param_count));
  159. }
  160. ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:",
  161. ACPI_LV_INFO, _COMPONENT);
  162. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  163. "Method at AML address %p Length %X\n",
  164. info->obj_desc->method.aml_start + 1,
  165. info->obj_desc->method.aml_length - 1));
  166. /*
  167. * Any namespace deletion must acquire both the namespace and
  168. * interpreter locks to ensure that no thread is using the portion of
  169. * the namespace that is being deleted.
  170. *
  171. * Execute the method via the interpreter. The interpreter is locked
  172. * here before calling into the AML parser
  173. */
  174. acpi_ex_enter_interpreter();
  175. status = acpi_ps_execute_method(info);
  176. acpi_ex_exit_interpreter();
  177. } else {
  178. /*
  179. * 2) Object is not a method, return its current value
  180. *
  181. * Disallow certain object types. For these, "evaluation" is undefined.
  182. */
  183. switch (info->resolved_node->type) {
  184. case ACPI_TYPE_DEVICE:
  185. case ACPI_TYPE_EVENT:
  186. case ACPI_TYPE_MUTEX:
  187. case ACPI_TYPE_REGION:
  188. case ACPI_TYPE_THERMAL:
  189. case ACPI_TYPE_LOCAL_SCOPE:
  190. ACPI_ERROR((AE_INFO,
  191. "[%4.4s] Evaluation of object type [%s] is not supported",
  192. info->resolved_node->name.ascii,
  193. acpi_ut_get_type_name(info->resolved_node->
  194. type)));
  195. return_ACPI_STATUS(AE_TYPE);
  196. default:
  197. break;
  198. }
  199. /*
  200. * Objects require additional resolution steps (e.g., the Node may be
  201. * a field that must be read, etc.) -- we can't just grab the object
  202. * out of the node.
  203. *
  204. * Use resolve_node_to_value() to get the associated value.
  205. *
  206. * NOTE: we can get away with passing in NULL for a walk state because
  207. * resolved_node is guaranteed to not be a reference to either a method
  208. * local or a method argument (because this interface is never called
  209. * from a running method.)
  210. *
  211. * Even though we do not directly invoke the interpreter for object
  212. * resolution, we must lock it because we could access an opregion.
  213. * The opregion access code assumes that the interpreter is locked.
  214. */
  215. acpi_ex_enter_interpreter();
  216. /* Function has a strange interface */
  217. status =
  218. acpi_ex_resolve_node_to_value(&info->resolved_node, NULL);
  219. acpi_ex_exit_interpreter();
  220. /*
  221. * If acpi_ex_resolve_node_to_value() succeeded, the return value was placed
  222. * in resolved_node.
  223. */
  224. if (ACPI_SUCCESS(status)) {
  225. status = AE_CTRL_RETURN_VALUE;
  226. info->return_object =
  227. ACPI_CAST_PTR(union acpi_operand_object,
  228. info->resolved_node);
  229. ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
  230. "Returning object %p [%s]\n",
  231. info->return_object,
  232. acpi_ut_get_object_type_name(info->
  233. return_object)));
  234. }
  235. }
  236. /* Validation of return values for ACPI-predefined methods and objects */
  237. if ((status == AE_OK) || (status == AE_CTRL_RETURN_VALUE)) {
  238. /*
  239. * If this is the first evaluation, check the return value. This
  240. * ensures that any warnings will only be emitted during the very
  241. * first evaluation of the object.
  242. */
  243. if (!(node->flags & ANOBJ_EVALUATED)) {
  244. /*
  245. * Check for a predefined ACPI name. If found, validate the
  246. * returned object.
  247. *
  248. * Note: Ignore return status for now, emit warnings if there are
  249. * problems with the returned object. May change later to abort
  250. * the method on invalid return object.
  251. */
  252. (void)acpi_ns_check_predefined_names(node,
  253. info->
  254. return_object);
  255. }
  256. /* Mark the node as having been evaluated */
  257. node->flags |= ANOBJ_EVALUATED;
  258. }
  259. /* Check if there is a return value that must be dealt with */
  260. if (status == AE_CTRL_RETURN_VALUE) {
  261. /* If caller does not want the return value, delete it */
  262. if (info->flags & ACPI_IGNORE_RETURN_VALUE) {
  263. acpi_ut_remove_reference(info->return_object);
  264. info->return_object = NULL;
  265. }
  266. /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
  267. status = AE_OK;
  268. }
  269. ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
  270. "*** Completed evaluation of object %s ***\n",
  271. info->pathname));
  272. /*
  273. * Namespace was unlocked by the handling acpi_ns* function, so we
  274. * just return
  275. */
  276. return_ACPI_STATUS(status);
  277. }