uteval.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /******************************************************************************
  2. *
  3. * Module Name: uteval - Object evaluation
  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 "acnamesp.h"
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME("uteval")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_ut_evaluate_object
  50. *
  51. * PARAMETERS: prefix_node - Starting node
  52. * path - Path to object from starting node
  53. * expected_return_types - Bitmap of allowed return types
  54. * return_desc - Where a return value is stored
  55. *
  56. * RETURN: Status
  57. *
  58. * DESCRIPTION: Evaluates a namespace object and verifies the type of the
  59. * return object. Common code that simplifies accessing objects
  60. * that have required return objects of fixed types.
  61. *
  62. * NOTE: Internal function, no parameter validation
  63. *
  64. ******************************************************************************/
  65. acpi_status
  66. acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
  67. char *path,
  68. u32 expected_return_btypes,
  69. union acpi_operand_object **return_desc)
  70. {
  71. struct acpi_evaluate_info *info;
  72. acpi_status status;
  73. u32 return_btype;
  74. ACPI_FUNCTION_TRACE(ut_evaluate_object);
  75. /* Allocate the evaluation information block */
  76. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  77. if (!info) {
  78. return_ACPI_STATUS(AE_NO_MEMORY);
  79. }
  80. info->prefix_node = prefix_node;
  81. info->relative_pathname = path;
  82. /* Evaluate the object/method */
  83. status = acpi_ns_evaluate(info);
  84. if (ACPI_FAILURE(status)) {
  85. if (status == AE_NOT_FOUND) {
  86. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  87. "[%4.4s.%s] was not found\n",
  88. acpi_ut_get_node_name(prefix_node),
  89. path));
  90. } else {
  91. ACPI_ERROR_METHOD("Method execution failed",
  92. prefix_node, path, status);
  93. }
  94. goto cleanup;
  95. }
  96. /* Did we get a return object? */
  97. if (!info->return_object) {
  98. if (expected_return_btypes) {
  99. ACPI_ERROR_METHOD("No object was returned from",
  100. prefix_node, path, AE_NOT_EXIST);
  101. status = AE_NOT_EXIST;
  102. }
  103. goto cleanup;
  104. }
  105. /* Map the return object type to the bitmapped type */
  106. switch ((info->return_object)->common.type) {
  107. case ACPI_TYPE_INTEGER:
  108. return_btype = ACPI_BTYPE_INTEGER;
  109. break;
  110. case ACPI_TYPE_BUFFER:
  111. return_btype = ACPI_BTYPE_BUFFER;
  112. break;
  113. case ACPI_TYPE_STRING:
  114. return_btype = ACPI_BTYPE_STRING;
  115. break;
  116. case ACPI_TYPE_PACKAGE:
  117. return_btype = ACPI_BTYPE_PACKAGE;
  118. break;
  119. default:
  120. return_btype = 0;
  121. break;
  122. }
  123. if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
  124. /*
  125. * We received a return object, but one was not expected. This can
  126. * happen frequently if the "implicit return" feature is enabled.
  127. * Just delete the return object and return AE_OK.
  128. */
  129. acpi_ut_remove_reference(info->return_object);
  130. goto cleanup;
  131. }
  132. /* Is the return object one of the expected types? */
  133. if (!(expected_return_btypes & return_btype)) {
  134. ACPI_ERROR_METHOD("Return object type is incorrect",
  135. prefix_node, path, AE_TYPE);
  136. ACPI_ERROR((AE_INFO,
  137. "Type returned from %s was incorrect: %s, expected Btypes: 0x%X",
  138. path,
  139. acpi_ut_get_object_type_name(info->return_object),
  140. expected_return_btypes));
  141. /* On error exit, we must delete the return object */
  142. acpi_ut_remove_reference(info->return_object);
  143. status = AE_TYPE;
  144. goto cleanup;
  145. }
  146. /* Object type is OK, return it */
  147. *return_desc = info->return_object;
  148. cleanup:
  149. ACPI_FREE(info);
  150. return_ACPI_STATUS(status);
  151. }
  152. /*******************************************************************************
  153. *
  154. * FUNCTION: acpi_ut_evaluate_numeric_object
  155. *
  156. * PARAMETERS: object_name - Object name to be evaluated
  157. * device_node - Node for the device
  158. * value - Where the value is returned
  159. *
  160. * RETURN: Status
  161. *
  162. * DESCRIPTION: Evaluates a numeric namespace object for a selected device
  163. * and stores result in *Value.
  164. *
  165. * NOTE: Internal function, no parameter validation
  166. *
  167. ******************************************************************************/
  168. acpi_status
  169. acpi_ut_evaluate_numeric_object(char *object_name,
  170. struct acpi_namespace_node *device_node,
  171. u64 *value)
  172. {
  173. union acpi_operand_object *obj_desc;
  174. acpi_status status;
  175. ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
  176. status = acpi_ut_evaluate_object(device_node, object_name,
  177. ACPI_BTYPE_INTEGER, &obj_desc);
  178. if (ACPI_FAILURE(status)) {
  179. return_ACPI_STATUS(status);
  180. }
  181. /* Get the returned Integer */
  182. *value = obj_desc->integer.value;
  183. /* On exit, we must delete the return object */
  184. acpi_ut_remove_reference(obj_desc);
  185. return_ACPI_STATUS(status);
  186. }
  187. /*******************************************************************************
  188. *
  189. * FUNCTION: acpi_ut_execute_STA
  190. *
  191. * PARAMETERS: device_node - Node for the device
  192. * flags - Where the status flags are returned
  193. *
  194. * RETURN: Status
  195. *
  196. * DESCRIPTION: Executes _STA for selected device and stores results in
  197. * *Flags. If _STA does not exist, then the device is assumed
  198. * to be present/functional/enabled (as per the ACPI spec).
  199. *
  200. * NOTE: Internal function, no parameter validation
  201. *
  202. ******************************************************************************/
  203. acpi_status
  204. acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
  205. {
  206. union acpi_operand_object *obj_desc;
  207. acpi_status status;
  208. ACPI_FUNCTION_TRACE(ut_execute_STA);
  209. status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
  210. ACPI_BTYPE_INTEGER, &obj_desc);
  211. if (ACPI_FAILURE(status)) {
  212. if (AE_NOT_FOUND == status) {
  213. /*
  214. * if _STA does not exist, then (as per the ACPI specification),
  215. * the returned flags will indicate that the device is present,
  216. * functional, and enabled.
  217. */
  218. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  219. "_STA on %4.4s was not found, assuming device is present\n",
  220. acpi_ut_get_node_name(device_node)));
  221. *flags = ACPI_UINT32_MAX;
  222. status = AE_OK;
  223. }
  224. return_ACPI_STATUS(status);
  225. }
  226. /* Extract the status flags */
  227. *flags = (u32) obj_desc->integer.value;
  228. /* On exit, we must delete the return object */
  229. acpi_ut_remove_reference(obj_desc);
  230. return_ACPI_STATUS(status);
  231. }
  232. /*******************************************************************************
  233. *
  234. * FUNCTION: acpi_ut_execute_power_methods
  235. *
  236. * PARAMETERS: device_node - Node for the device
  237. * method_names - Array of power method names
  238. * method_count - Number of methods to execute
  239. * out_values - Where the power method values are returned
  240. *
  241. * RETURN: Status, out_values
  242. *
  243. * DESCRIPTION: Executes the specified power methods for the device and returns
  244. * the result(s).
  245. *
  246. * NOTE: Internal function, no parameter validation
  247. *
  248. ******************************************************************************/
  249. acpi_status
  250. acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node,
  251. const char **method_names,
  252. u8 method_count, u8 *out_values)
  253. {
  254. union acpi_operand_object *obj_desc;
  255. acpi_status status;
  256. acpi_status final_status = AE_NOT_FOUND;
  257. u32 i;
  258. ACPI_FUNCTION_TRACE(ut_execute_power_methods);
  259. for (i = 0; i < method_count; i++) {
  260. /*
  261. * Execute the power method (_sx_d or _sx_w). The only allowable
  262. * return type is an Integer.
  263. */
  264. status = acpi_ut_evaluate_object(device_node,
  265. ACPI_CAST_PTR(char,
  266. method_names[i]),
  267. ACPI_BTYPE_INTEGER, &obj_desc);
  268. if (ACPI_SUCCESS(status)) {
  269. out_values[i] = (u8)obj_desc->integer.value;
  270. /* Delete the return object */
  271. acpi_ut_remove_reference(obj_desc);
  272. final_status = AE_OK; /* At least one value is valid */
  273. continue;
  274. }
  275. out_values[i] = ACPI_UINT8_MAX;
  276. if (status == AE_NOT_FOUND) {
  277. continue; /* Ignore if not found */
  278. }
  279. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  280. "Failed %s on Device %4.4s, %s\n",
  281. ACPI_CAST_PTR(char, method_names[i]),
  282. acpi_ut_get_node_name(device_node),
  283. acpi_format_exception(status)));
  284. }
  285. return_ACPI_STATUS(final_status);
  286. }