uteval.c 14 KB

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