uteval.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /******************************************************************************
  2. *
  3. * Module Name: uteval - Object evaluation
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  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/acnamesp.h>
  44. #include <acpi/acinterp.h>
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME ("uteval")
  47. /*******************************************************************************
  48. *
  49. * FUNCTION: acpi_ut_osi_implementation
  50. *
  51. * PARAMETERS: walk_state - Current walk state
  52. *
  53. * RETURN: Status
  54. *
  55. * DESCRIPTION: Implementation of _OSI predefined control method
  56. * Supported = _OSI (String)
  57. *
  58. ******************************************************************************/
  59. acpi_status
  60. acpi_ut_osi_implementation (
  61. struct acpi_walk_state *walk_state)
  62. {
  63. union acpi_operand_object *string_desc;
  64. union acpi_operand_object *return_desc;
  65. acpi_native_uint i;
  66. ACPI_FUNCTION_TRACE ("ut_osi_implementation");
  67. /* Validate the string input argument */
  68. string_desc = walk_state->arguments[0].object;
  69. if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
  70. return_ACPI_STATUS (AE_TYPE);
  71. }
  72. /* Create a return object (Default value = 0) */
  73. return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
  74. if (!return_desc) {
  75. return_ACPI_STATUS (AE_NO_MEMORY);
  76. }
  77. /* Compare input string to table of supported strings */
  78. for (i = 0; i < ACPI_NUM_OSI_STRINGS; i++) {
  79. if (!ACPI_STRCMP (string_desc->string.pointer,
  80. (char *) acpi_gbl_valid_osi_strings[i])) {
  81. /* This string is supported */
  82. return_desc->integer.value = 0xFFFFFFFF;
  83. break;
  84. }
  85. }
  86. walk_state->return_desc = return_desc;
  87. return_ACPI_STATUS (AE_CTRL_TERMINATE);
  88. }
  89. /*******************************************************************************
  90. *
  91. * FUNCTION: acpi_ut_evaluate_object
  92. *
  93. * PARAMETERS: prefix_node - Starting node
  94. * Path - Path to object from starting node
  95. * expected_return_types - Bitmap of allowed return types
  96. * return_desc - Where a return value is stored
  97. *
  98. * RETURN: Status
  99. *
  100. * DESCRIPTION: Evaluates a namespace object and verifies the type of the
  101. * return object. Common code that simplifies accessing objects
  102. * that have required return objects of fixed types.
  103. *
  104. * NOTE: Internal function, no parameter validation
  105. *
  106. ******************************************************************************/
  107. acpi_status
  108. acpi_ut_evaluate_object (
  109. struct acpi_namespace_node *prefix_node,
  110. char *path,
  111. u32 expected_return_btypes,
  112. union acpi_operand_object **return_desc)
  113. {
  114. struct acpi_parameter_info info;
  115. acpi_status status;
  116. u32 return_btype;
  117. ACPI_FUNCTION_TRACE ("ut_evaluate_object");
  118. info.node = prefix_node;
  119. info.parameters = NULL;
  120. info.parameter_type = ACPI_PARAM_ARGS;
  121. /* Evaluate the object/method */
  122. status = acpi_ns_evaluate_relative (path, &info);
  123. if (ACPI_FAILURE (status)) {
  124. if (status == AE_NOT_FOUND) {
  125. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
  126. acpi_ut_get_node_name (prefix_node), path));
  127. }
  128. else {
  129. ACPI_REPORT_METHOD_ERROR ("Method execution failed",
  130. prefix_node, path, status);
  131. }
  132. return_ACPI_STATUS (status);
  133. }
  134. /* Did we get a return object? */
  135. if (!info.return_object) {
  136. if (expected_return_btypes) {
  137. ACPI_REPORT_METHOD_ERROR ("No object was returned from",
  138. prefix_node, path, AE_NOT_EXIST);
  139. return_ACPI_STATUS (AE_NOT_EXIST);
  140. }
  141. return_ACPI_STATUS (AE_OK);
  142. }
  143. /* Map the return object type to the bitmapped type */
  144. switch (ACPI_GET_OBJECT_TYPE (info.return_object)) {
  145. case ACPI_TYPE_INTEGER:
  146. return_btype = ACPI_BTYPE_INTEGER;
  147. break;
  148. case ACPI_TYPE_BUFFER:
  149. return_btype = ACPI_BTYPE_BUFFER;
  150. break;
  151. case ACPI_TYPE_STRING:
  152. return_btype = ACPI_BTYPE_STRING;
  153. break;
  154. case ACPI_TYPE_PACKAGE:
  155. return_btype = ACPI_BTYPE_PACKAGE;
  156. break;
  157. default:
  158. return_btype = 0;
  159. break;
  160. }
  161. if ((acpi_gbl_enable_interpreter_slack) &&
  162. (!expected_return_btypes)) {
  163. /*
  164. * We received a return object, but one was not expected. This can
  165. * happen frequently if the "implicit return" feature is enabled.
  166. * Just delete the return object and return AE_OK.
  167. */
  168. acpi_ut_remove_reference (info.return_object);
  169. return_ACPI_STATUS (AE_OK);
  170. }
  171. /* Is the return object one of the expected types? */
  172. if (!(expected_return_btypes & return_btype)) {
  173. ACPI_REPORT_METHOD_ERROR ("Return object type is incorrect",
  174. prefix_node, path, AE_TYPE);
  175. ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
  176. "Type returned from %s was incorrect: %s, expected Btypes: %X\n",
  177. path, acpi_ut_get_object_type_name (info.return_object),
  178. expected_return_btypes));
  179. /* On error exit, we must delete the return object */
  180. acpi_ut_remove_reference (info.return_object);
  181. return_ACPI_STATUS (AE_TYPE);
  182. }
  183. /* Object type is OK, return it */
  184. *return_desc = info.return_object;
  185. return_ACPI_STATUS (AE_OK);
  186. }
  187. /*******************************************************************************
  188. *
  189. * FUNCTION: acpi_ut_evaluate_numeric_object
  190. *
  191. * PARAMETERS: *object_name - Object name to be evaluated
  192. * device_node - Node for the device
  193. * *Address - Where the value is returned
  194. *
  195. * RETURN: Status
  196. *
  197. * DESCRIPTION: Evaluates a numeric namespace object for a selected device
  198. * and stores result in *Address.
  199. *
  200. * NOTE: Internal function, no parameter validation
  201. *
  202. ******************************************************************************/
  203. acpi_status
  204. acpi_ut_evaluate_numeric_object (
  205. char *object_name,
  206. struct acpi_namespace_node *device_node,
  207. acpi_integer *address)
  208. {
  209. union acpi_operand_object *obj_desc;
  210. acpi_status status;
  211. ACPI_FUNCTION_TRACE ("ut_evaluate_numeric_object");
  212. status = acpi_ut_evaluate_object (device_node, object_name,
  213. ACPI_BTYPE_INTEGER, &obj_desc);
  214. if (ACPI_FAILURE (status)) {
  215. return_ACPI_STATUS (status);
  216. }
  217. /* Get the returned Integer */
  218. *address = obj_desc->integer.value;
  219. /* On exit, we must delete the return object */
  220. acpi_ut_remove_reference (obj_desc);
  221. return_ACPI_STATUS (status);
  222. }
  223. /*******************************************************************************
  224. *
  225. * FUNCTION: acpi_ut_copy_id_string
  226. *
  227. * PARAMETERS: Destination - Where to copy the string
  228. * Source - Source string
  229. * max_length - Length of the destination buffer
  230. *
  231. * RETURN: None
  232. *
  233. * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
  234. * Performs removal of a leading asterisk if present -- workaround
  235. * for a known issue on a bunch of machines.
  236. *
  237. ******************************************************************************/
  238. static void
  239. acpi_ut_copy_id_string (
  240. char *destination,
  241. char *source,
  242. acpi_size max_length)
  243. {
  244. /*
  245. * Workaround for ID strings that have a leading asterisk. This construct
  246. * is not allowed by the ACPI specification (ID strings must be
  247. * alphanumeric), but enough existing machines have this embedded in their
  248. * ID strings that the following code is useful.
  249. */
  250. if (*source == '*') {
  251. source++;
  252. }
  253. /* Do the actual copy */
  254. ACPI_STRNCPY (destination, source, max_length);
  255. }
  256. /*******************************************************************************
  257. *
  258. * FUNCTION: acpi_ut_execute_HID
  259. *
  260. * PARAMETERS: device_node - Node for the device
  261. * *Hid - Where the HID is returned
  262. *
  263. * RETURN: Status
  264. *
  265. * DESCRIPTION: Executes the _HID control method that returns the hardware
  266. * ID of the device.
  267. *
  268. * NOTE: Internal function, no parameter validation
  269. *
  270. ******************************************************************************/
  271. acpi_status
  272. acpi_ut_execute_HID (
  273. struct acpi_namespace_node *device_node,
  274. struct acpi_device_id *hid)
  275. {
  276. union acpi_operand_object *obj_desc;
  277. acpi_status status;
  278. ACPI_FUNCTION_TRACE ("ut_execute_HID");
  279. status = acpi_ut_evaluate_object (device_node, METHOD_NAME__HID,
  280. ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &obj_desc);
  281. if (ACPI_FAILURE (status)) {
  282. return_ACPI_STATUS (status);
  283. }
  284. if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
  285. /* Convert the Numeric HID to string */
  286. acpi_ex_eisa_id_to_string ((u32) obj_desc->integer.value, hid->value);
  287. }
  288. else {
  289. /* Copy the String HID from the returned object */
  290. acpi_ut_copy_id_string (hid->value, obj_desc->string.pointer,
  291. sizeof (hid->value));
  292. }
  293. /* On exit, we must delete the return object */
  294. acpi_ut_remove_reference (obj_desc);
  295. return_ACPI_STATUS (status);
  296. }
  297. /*******************************************************************************
  298. *
  299. * FUNCTION: acpi_ut_translate_one_cid
  300. *
  301. * PARAMETERS: obj_desc - _CID object, must be integer or string
  302. * one_cid - Where the CID string is returned
  303. *
  304. * RETURN: Status
  305. *
  306. * DESCRIPTION: Return a numeric or string _CID value as a string.
  307. * (Compatible ID)
  308. *
  309. * NOTE: Assumes a maximum _CID string length of
  310. * ACPI_MAX_CID_LENGTH.
  311. *
  312. ******************************************************************************/
  313. static acpi_status
  314. acpi_ut_translate_one_cid (
  315. union acpi_operand_object *obj_desc,
  316. struct acpi_compatible_id *one_cid)
  317. {
  318. switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
  319. case ACPI_TYPE_INTEGER:
  320. /* Convert the Numeric CID to string */
  321. acpi_ex_eisa_id_to_string ((u32) obj_desc->integer.value, one_cid->value);
  322. return (AE_OK);
  323. case ACPI_TYPE_STRING:
  324. if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
  325. return (AE_AML_STRING_LIMIT);
  326. }
  327. /* Copy the String CID from the returned object */
  328. acpi_ut_copy_id_string (one_cid->value, obj_desc->string.pointer,
  329. ACPI_MAX_CID_LENGTH);
  330. return (AE_OK);
  331. default:
  332. return (AE_TYPE);
  333. }
  334. }
  335. /*******************************************************************************
  336. *
  337. * FUNCTION: acpi_ut_execute_CID
  338. *
  339. * PARAMETERS: device_node - Node for the device
  340. * *Cid - Where the CID is returned
  341. *
  342. * RETURN: Status
  343. *
  344. * DESCRIPTION: Executes the _CID control method that returns one or more
  345. * compatible hardware IDs for the device.
  346. *
  347. * NOTE: Internal function, no parameter validation
  348. *
  349. ******************************************************************************/
  350. acpi_status
  351. acpi_ut_execute_CID (
  352. struct acpi_namespace_node *device_node,
  353. struct acpi_compatible_id_list **return_cid_list)
  354. {
  355. union acpi_operand_object *obj_desc;
  356. acpi_status status;
  357. u32 count;
  358. u32 size;
  359. struct acpi_compatible_id_list *cid_list;
  360. acpi_native_uint i;
  361. ACPI_FUNCTION_TRACE ("ut_execute_CID");
  362. /* Evaluate the _CID method for this device */
  363. status = acpi_ut_evaluate_object (device_node, METHOD_NAME__CID,
  364. ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
  365. &obj_desc);
  366. if (ACPI_FAILURE (status)) {
  367. return_ACPI_STATUS (status);
  368. }
  369. /* Get the number of _CIDs returned */
  370. count = 1;
  371. if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_PACKAGE) {
  372. count = obj_desc->package.count;
  373. }
  374. /* Allocate a worst-case buffer for the _CIDs */
  375. size = (((count - 1) * sizeof (struct acpi_compatible_id)) +
  376. sizeof (struct acpi_compatible_id_list));
  377. cid_list = ACPI_MEM_CALLOCATE ((acpi_size) size);
  378. if (!cid_list) {
  379. return_ACPI_STATUS (AE_NO_MEMORY);
  380. }
  381. /* Init CID list */
  382. cid_list->count = count;
  383. cid_list->size = size;
  384. /*
  385. * A _CID can return either a single compatible ID or a package of compatible
  386. * IDs. Each compatible ID can be one of the following:
  387. * -- Number (32 bit compressed EISA ID) or
  388. * -- String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss").
  389. */
  390. /* The _CID object can be either a single CID or a package (list) of CIDs */
  391. if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_PACKAGE) {
  392. /* Translate each package element */
  393. for (i = 0; i < count; i++) {
  394. status = acpi_ut_translate_one_cid (obj_desc->package.elements[i],
  395. &cid_list->id[i]);
  396. if (ACPI_FAILURE (status)) {
  397. break;
  398. }
  399. }
  400. }
  401. else {
  402. /* Only one CID, translate to a string */
  403. status = acpi_ut_translate_one_cid (obj_desc, cid_list->id);
  404. }
  405. /* Cleanup on error */
  406. if (ACPI_FAILURE (status)) {
  407. ACPI_MEM_FREE (cid_list);
  408. }
  409. else {
  410. *return_cid_list = cid_list;
  411. }
  412. /* On exit, we must delete the _CID return object */
  413. acpi_ut_remove_reference (obj_desc);
  414. return_ACPI_STATUS (status);
  415. }
  416. /*******************************************************************************
  417. *
  418. * FUNCTION: acpi_ut_execute_UID
  419. *
  420. * PARAMETERS: device_node - Node for the device
  421. * *Uid - Where the UID is returned
  422. *
  423. * RETURN: Status
  424. *
  425. * DESCRIPTION: Executes the _UID control method that returns the hardware
  426. * ID of the device.
  427. *
  428. * NOTE: Internal function, no parameter validation
  429. *
  430. ******************************************************************************/
  431. acpi_status
  432. acpi_ut_execute_UID (
  433. struct acpi_namespace_node *device_node,
  434. struct acpi_device_id *uid)
  435. {
  436. union acpi_operand_object *obj_desc;
  437. acpi_status status;
  438. ACPI_FUNCTION_TRACE ("ut_execute_UID");
  439. status = acpi_ut_evaluate_object (device_node, METHOD_NAME__UID,
  440. ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &obj_desc);
  441. if (ACPI_FAILURE (status)) {
  442. return_ACPI_STATUS (status);
  443. }
  444. if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
  445. /* Convert the Numeric UID to string */
  446. acpi_ex_unsigned_integer_to_string (obj_desc->integer.value, uid->value);
  447. }
  448. else {
  449. /* Copy the String UID from the returned object */
  450. acpi_ut_copy_id_string (uid->value, obj_desc->string.pointer,
  451. sizeof (uid->value));
  452. }
  453. /* On exit, we must delete the return object */
  454. acpi_ut_remove_reference (obj_desc);
  455. return_ACPI_STATUS (status);
  456. }
  457. /*******************************************************************************
  458. *
  459. * FUNCTION: acpi_ut_execute_STA
  460. *
  461. * PARAMETERS: device_node - Node for the device
  462. * *Flags - Where the status flags are returned
  463. *
  464. * RETURN: Status
  465. *
  466. * DESCRIPTION: Executes _STA for selected device and stores results in
  467. * *Flags.
  468. *
  469. * NOTE: Internal function, no parameter validation
  470. *
  471. ******************************************************************************/
  472. acpi_status
  473. acpi_ut_execute_STA (
  474. struct acpi_namespace_node *device_node,
  475. u32 *flags)
  476. {
  477. union acpi_operand_object *obj_desc;
  478. acpi_status status;
  479. ACPI_FUNCTION_TRACE ("ut_execute_STA");
  480. status = acpi_ut_evaluate_object (device_node, METHOD_NAME__STA,
  481. ACPI_BTYPE_INTEGER, &obj_desc);
  482. if (ACPI_FAILURE (status)) {
  483. if (AE_NOT_FOUND == status) {
  484. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  485. "_STA on %4.4s was not found, assuming device is present\n",
  486. acpi_ut_get_node_name (device_node)));
  487. *flags = 0x0F;
  488. status = AE_OK;
  489. }
  490. return_ACPI_STATUS (status);
  491. }
  492. /* Extract the status flags */
  493. *flags = (u32) obj_desc->integer.value;
  494. /* On exit, we must delete the return object */
  495. acpi_ut_remove_reference (obj_desc);
  496. return_ACPI_STATUS (status);
  497. }
  498. /*******************************************************************************
  499. *
  500. * FUNCTION: acpi_ut_execute_Sxds
  501. *
  502. * PARAMETERS: device_node - Node for the device
  503. * *Flags - Where the status flags are returned
  504. *
  505. * RETURN: Status
  506. *
  507. * DESCRIPTION: Executes _STA for selected device and stores results in
  508. * *Flags.
  509. *
  510. * NOTE: Internal function, no parameter validation
  511. *
  512. ******************************************************************************/
  513. acpi_status
  514. acpi_ut_execute_sxds (
  515. struct acpi_namespace_node *device_node,
  516. u8 *highest)
  517. {
  518. union acpi_operand_object *obj_desc;
  519. acpi_status status;
  520. u32 i;
  521. ACPI_FUNCTION_TRACE ("ut_execute_Sxds");
  522. for (i = 0; i < 4; i++) {
  523. highest[i] = 0xFF;
  524. status = acpi_ut_evaluate_object (device_node,
  525. (char *) acpi_gbl_highest_dstate_names[i],
  526. ACPI_BTYPE_INTEGER, &obj_desc);
  527. if (ACPI_FAILURE (status)) {
  528. if (status != AE_NOT_FOUND) {
  529. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  530. "%s on Device %4.4s, %s\n",
  531. (char *) acpi_gbl_highest_dstate_names[i],
  532. acpi_ut_get_node_name (device_node),
  533. acpi_format_exception (status)));
  534. return_ACPI_STATUS (status);
  535. }
  536. }
  537. else {
  538. /* Extract the Dstate value */
  539. highest[i] = (u8) obj_desc->integer.value;
  540. /* Delete the return object */
  541. acpi_ut_remove_reference (obj_desc);
  542. }
  543. }
  544. return_ACPI_STATUS (AE_OK);
  545. }