uteval.c 19 KB

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