uteval.c 19 KB

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