uteval.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /******************************************************************************
  2. *
  3. * Module Name: uteval - Object evaluation
  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 "acnamesp.h"
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME("uteval")
  47. /*
  48. * Strings supported by the _OSI predefined (internal) method.
  49. *
  50. * March 2009: Removed "Linux" as this host no longer wants to respond true
  51. * for this string. Basically, the only safe OS strings are windows-related
  52. * and in many or most cases represent the only test path within the
  53. * BIOS-provided ASL code.
  54. *
  55. * The second element of each entry is used to track the newest version of
  56. * Windows that the BIOS has requested.
  57. */
  58. static struct acpi_interface_info acpi_interfaces_supported[] = {
  59. /* Operating System Vendor Strings */
  60. {"Windows 2000", ACPI_OSI_WIN_2000}, /* Windows 2000 */
  61. {"Windows 2001", ACPI_OSI_WIN_XP}, /* Windows XP */
  62. {"Windows 2001 SP1", ACPI_OSI_WIN_XP_SP1}, /* Windows XP SP1 */
  63. {"Windows 2001.1", ACPI_OSI_WINSRV_2003}, /* Windows Server 2003 */
  64. {"Windows 2001 SP2", ACPI_OSI_WIN_XP_SP2}, /* Windows XP SP2 */
  65. {"Windows 2001.1 SP1", ACPI_OSI_WINSRV_2003_SP1}, /* Windows Server 2003 SP1 - Added 03/2006 */
  66. {"Windows 2006", ACPI_OSI_WIN_VISTA}, /* Windows Vista - Added 03/2006 */
  67. /* Feature Group Strings */
  68. {"Extended Address Space Descriptor", 0}
  69. /*
  70. * All "optional" feature group strings (features that are implemented
  71. * by the host) should be implemented in the host version of
  72. * acpi_os_validate_interface and should not be added here.
  73. */
  74. };
  75. /*******************************************************************************
  76. *
  77. * FUNCTION: acpi_ut_osi_implementation
  78. *
  79. * PARAMETERS: walk_state - Current walk state
  80. *
  81. * RETURN: Status
  82. *
  83. * DESCRIPTION: Implementation of the _OSI predefined control method
  84. *
  85. ******************************************************************************/
  86. acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
  87. {
  88. acpi_status status;
  89. union acpi_operand_object *string_desc;
  90. union acpi_operand_object *return_desc;
  91. u32 return_value;
  92. u32 i;
  93. ACPI_FUNCTION_TRACE(ut_osi_implementation);
  94. /* Validate the string input argument */
  95. string_desc = walk_state->arguments[0].object;
  96. if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
  97. return_ACPI_STATUS(AE_TYPE);
  98. }
  99. /* Create a return object */
  100. return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
  101. if (!return_desc) {
  102. return_ACPI_STATUS(AE_NO_MEMORY);
  103. }
  104. /* Default return value is 0, NOT SUPPORTED */
  105. return_value = 0;
  106. /* Compare input string to static table of supported interfaces */
  107. for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
  108. if (!ACPI_STRCMP(string_desc->string.pointer,
  109. acpi_interfaces_supported[i].name)) {
  110. /*
  111. * The interface is supported.
  112. * Update the osi_data if necessary. We keep track of the latest
  113. * version of Windows that has been requested by the BIOS.
  114. */
  115. if (acpi_interfaces_supported[i].value >
  116. acpi_gbl_osi_data) {
  117. acpi_gbl_osi_data =
  118. acpi_interfaces_supported[i].value;
  119. }
  120. return_value = ACPI_UINT32_MAX;
  121. goto exit;
  122. }
  123. }
  124. /*
  125. * Did not match the string in the static table, call the host OSL to
  126. * check for a match with one of the optional strings (such as
  127. * "Module Device", "3.0 Thermal Model", etc.)
  128. */
  129. status = acpi_os_validate_interface(string_desc->string.pointer);
  130. if (ACPI_SUCCESS(status)) {
  131. /* The interface is supported */
  132. return_value = ACPI_UINT32_MAX;
  133. }
  134. exit:
  135. ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
  136. "ACPI: BIOS _OSI(%s) is %ssupported\n",
  137. string_desc->string.pointer, return_value == 0 ? "not " : ""));
  138. /* Complete the return value */
  139. return_desc->integer.value = return_value;
  140. walk_state->return_desc = return_desc;
  141. return_ACPI_STATUS (AE_OK);
  142. }
  143. /*******************************************************************************
  144. *
  145. * FUNCTION: acpi_osi_invalidate
  146. *
  147. * PARAMETERS: interface_string
  148. *
  149. * RETURN: Status
  150. *
  151. * DESCRIPTION: invalidate string in pre-defiend _OSI string list
  152. *
  153. ******************************************************************************/
  154. acpi_status acpi_osi_invalidate(char *interface)
  155. {
  156. int i;
  157. for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
  158. if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i].name)) {
  159. *acpi_interfaces_supported[i].name = '\0';
  160. return AE_OK;
  161. }
  162. }
  163. return AE_NOT_FOUND;
  164. }
  165. /*******************************************************************************
  166. *
  167. * FUNCTION: acpi_ut_evaluate_object
  168. *
  169. * PARAMETERS: prefix_node - Starting node
  170. * Path - Path to object from starting node
  171. * expected_return_types - Bitmap of allowed return types
  172. * return_desc - Where a return value is stored
  173. *
  174. * RETURN: Status
  175. *
  176. * DESCRIPTION: Evaluates a namespace object and verifies the type of the
  177. * return object. Common code that simplifies accessing objects
  178. * that have required return objects of fixed types.
  179. *
  180. * NOTE: Internal function, no parameter validation
  181. *
  182. ******************************************************************************/
  183. acpi_status
  184. acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
  185. char *path,
  186. u32 expected_return_btypes,
  187. union acpi_operand_object **return_desc)
  188. {
  189. struct acpi_evaluate_info *info;
  190. acpi_status status;
  191. u32 return_btype;
  192. ACPI_FUNCTION_TRACE(ut_evaluate_object);
  193. /* Allocate the evaluation information block */
  194. info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
  195. if (!info) {
  196. return_ACPI_STATUS(AE_NO_MEMORY);
  197. }
  198. info->prefix_node = prefix_node;
  199. info->pathname = path;
  200. /* Evaluate the object/method */
  201. status = acpi_ns_evaluate(info);
  202. if (ACPI_FAILURE(status)) {
  203. if (status == AE_NOT_FOUND) {
  204. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  205. "[%4.4s.%s] was not found\n",
  206. acpi_ut_get_node_name(prefix_node),
  207. path));
  208. } else {
  209. ACPI_ERROR_METHOD("Method execution failed",
  210. prefix_node, path, status);
  211. }
  212. goto cleanup;
  213. }
  214. /* Did we get a return object? */
  215. if (!info->return_object) {
  216. if (expected_return_btypes) {
  217. ACPI_ERROR_METHOD("No object was returned from",
  218. prefix_node, path, AE_NOT_EXIST);
  219. status = AE_NOT_EXIST;
  220. }
  221. goto cleanup;
  222. }
  223. /* Map the return object type to the bitmapped type */
  224. switch ((info->return_object)->common.type) {
  225. case ACPI_TYPE_INTEGER:
  226. return_btype = ACPI_BTYPE_INTEGER;
  227. break;
  228. case ACPI_TYPE_BUFFER:
  229. return_btype = ACPI_BTYPE_BUFFER;
  230. break;
  231. case ACPI_TYPE_STRING:
  232. return_btype = ACPI_BTYPE_STRING;
  233. break;
  234. case ACPI_TYPE_PACKAGE:
  235. return_btype = ACPI_BTYPE_PACKAGE;
  236. break;
  237. default:
  238. return_btype = 0;
  239. break;
  240. }
  241. if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
  242. /*
  243. * We received a return object, but one was not expected. This can
  244. * happen frequently if the "implicit return" feature is enabled.
  245. * Just delete the return object and return AE_OK.
  246. */
  247. acpi_ut_remove_reference(info->return_object);
  248. goto cleanup;
  249. }
  250. /* Is the return object one of the expected types? */
  251. if (!(expected_return_btypes & return_btype)) {
  252. ACPI_ERROR_METHOD("Return object type is incorrect",
  253. prefix_node, path, AE_TYPE);
  254. ACPI_ERROR((AE_INFO,
  255. "Type returned from %s was incorrect: %s, expected Btypes: %X",
  256. path,
  257. acpi_ut_get_object_type_name(info->return_object),
  258. expected_return_btypes));
  259. /* On error exit, we must delete the return object */
  260. acpi_ut_remove_reference(info->return_object);
  261. status = AE_TYPE;
  262. goto cleanup;
  263. }
  264. /* Object type is OK, return it */
  265. *return_desc = info->return_object;
  266. cleanup:
  267. ACPI_FREE(info);
  268. return_ACPI_STATUS(status);
  269. }
  270. /*******************************************************************************
  271. *
  272. * FUNCTION: acpi_ut_evaluate_numeric_object
  273. *
  274. * PARAMETERS: object_name - Object name to be evaluated
  275. * device_node - Node for the device
  276. * Value - Where the value is returned
  277. *
  278. * RETURN: Status
  279. *
  280. * DESCRIPTION: Evaluates a numeric namespace object for a selected device
  281. * and stores result in *Value.
  282. *
  283. * NOTE: Internal function, no parameter validation
  284. *
  285. ******************************************************************************/
  286. acpi_status
  287. acpi_ut_evaluate_numeric_object(char *object_name,
  288. struct acpi_namespace_node *device_node,
  289. acpi_integer *value)
  290. {
  291. union acpi_operand_object *obj_desc;
  292. acpi_status status;
  293. ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
  294. status = acpi_ut_evaluate_object(device_node, object_name,
  295. ACPI_BTYPE_INTEGER, &obj_desc);
  296. if (ACPI_FAILURE(status)) {
  297. return_ACPI_STATUS(status);
  298. }
  299. /* Get the returned Integer */
  300. *value = obj_desc->integer.value;
  301. /* On exit, we must delete the return object */
  302. acpi_ut_remove_reference(obj_desc);
  303. return_ACPI_STATUS(status);
  304. }
  305. /*******************************************************************************
  306. *
  307. * FUNCTION: acpi_ut_execute_STA
  308. *
  309. * PARAMETERS: device_node - Node for the device
  310. * Flags - Where the status flags are returned
  311. *
  312. * RETURN: Status
  313. *
  314. * DESCRIPTION: Executes _STA for selected device and stores results in
  315. * *Flags.
  316. *
  317. * NOTE: Internal function, no parameter validation
  318. *
  319. ******************************************************************************/
  320. acpi_status
  321. acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
  322. {
  323. union acpi_operand_object *obj_desc;
  324. acpi_status status;
  325. ACPI_FUNCTION_TRACE(ut_execute_STA);
  326. status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
  327. ACPI_BTYPE_INTEGER, &obj_desc);
  328. if (ACPI_FAILURE(status)) {
  329. if (AE_NOT_FOUND == status) {
  330. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  331. "_STA on %4.4s was not found, assuming device is present\n",
  332. acpi_ut_get_node_name(device_node)));
  333. *flags = ACPI_UINT32_MAX;
  334. status = AE_OK;
  335. }
  336. return_ACPI_STATUS(status);
  337. }
  338. /* Extract the status flags */
  339. *flags = (u32) obj_desc->integer.value;
  340. /* On exit, we must delete the return object */
  341. acpi_ut_remove_reference(obj_desc);
  342. return_ACPI_STATUS(status);
  343. }
  344. /*******************************************************************************
  345. *
  346. * FUNCTION: acpi_ut_execute_power_methods
  347. *
  348. * PARAMETERS: device_node - Node for the device
  349. * method_names - Array of power method names
  350. * method_count - Number of methods to execute
  351. * out_values - Where the power method values are returned
  352. *
  353. * RETURN: Status, out_values
  354. *
  355. * DESCRIPTION: Executes the specified power methods for the device and returns
  356. * the result(s).
  357. *
  358. * NOTE: Internal function, no parameter validation
  359. *
  360. ******************************************************************************/
  361. acpi_status
  362. acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node,
  363. const char **method_names,
  364. u8 method_count, u8 *out_values)
  365. {
  366. union acpi_operand_object *obj_desc;
  367. acpi_status status;
  368. acpi_status final_status = AE_NOT_FOUND;
  369. u32 i;
  370. ACPI_FUNCTION_TRACE(ut_execute_power_methods);
  371. for (i = 0; i < method_count; i++) {
  372. /*
  373. * Execute the power method (_sx_d or _sx_w). The only allowable
  374. * return type is an Integer.
  375. */
  376. status = acpi_ut_evaluate_object(device_node,
  377. ACPI_CAST_PTR(char,
  378. method_names[i]),
  379. ACPI_BTYPE_INTEGER, &obj_desc);
  380. if (ACPI_SUCCESS(status)) {
  381. out_values[i] = (u8)obj_desc->integer.value;
  382. /* Delete the return object */
  383. acpi_ut_remove_reference(obj_desc);
  384. final_status = AE_OK; /* At least one value is valid */
  385. continue;
  386. }
  387. out_values[i] = ACPI_UINT8_MAX;
  388. if (status == AE_NOT_FOUND) {
  389. continue; /* Ignore if not found */
  390. }
  391. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  392. "Failed %s on Device %4.4s, %s\n",
  393. ACPI_CAST_PTR(char, method_names[i]),
  394. acpi_ut_get_node_name(device_node),
  395. acpi_format_exception(status)));
  396. }
  397. return_ACPI_STATUS(final_status);
  398. }