utils.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. * acpi_utils.c - ACPI Utility Functions ($Revision: 10 $)
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  22. *
  23. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/slab.h>
  28. #include <linux/init.h>
  29. #include <linux/types.h>
  30. #include <linux/hardirq.h>
  31. #include <linux/acpi.h>
  32. #include <linux/dynamic_debug.h>
  33. #include "internal.h"
  34. #define _COMPONENT ACPI_BUS_COMPONENT
  35. ACPI_MODULE_NAME("utils");
  36. /* --------------------------------------------------------------------------
  37. Object Evaluation Helpers
  38. -------------------------------------------------------------------------- */
  39. static void
  40. acpi_util_eval_error(acpi_handle h, acpi_string p, acpi_status s)
  41. {
  42. #ifdef ACPI_DEBUG_OUTPUT
  43. char prefix[80] = {'\0'};
  44. struct acpi_buffer buffer = {sizeof(prefix), prefix};
  45. acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);
  46. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate [%s.%s]: %s\n",
  47. (char *) prefix, p, acpi_format_exception(s)));
  48. #else
  49. return;
  50. #endif
  51. }
  52. acpi_status
  53. acpi_extract_package(union acpi_object *package,
  54. struct acpi_buffer *format, struct acpi_buffer *buffer)
  55. {
  56. u32 size_required = 0;
  57. u32 tail_offset = 0;
  58. char *format_string = NULL;
  59. u32 format_count = 0;
  60. u32 i = 0;
  61. u8 *head = NULL;
  62. u8 *tail = NULL;
  63. if (!package || (package->type != ACPI_TYPE_PACKAGE)
  64. || (package->package.count < 1)) {
  65. printk(KERN_WARNING PREFIX "Invalid package argument\n");
  66. return AE_BAD_PARAMETER;
  67. }
  68. if (!format || !format->pointer || (format->length < 1)) {
  69. printk(KERN_WARNING PREFIX "Invalid format argument\n");
  70. return AE_BAD_PARAMETER;
  71. }
  72. if (!buffer) {
  73. printk(KERN_WARNING PREFIX "Invalid buffer argument\n");
  74. return AE_BAD_PARAMETER;
  75. }
  76. format_count = (format->length / sizeof(char)) - 1;
  77. if (format_count > package->package.count) {
  78. printk(KERN_WARNING PREFIX "Format specifies more objects [%d]"
  79. " than exist in package [%d].\n",
  80. format_count, package->package.count);
  81. return AE_BAD_DATA;
  82. }
  83. format_string = format->pointer;
  84. /*
  85. * Calculate size_required.
  86. */
  87. for (i = 0; i < format_count; i++) {
  88. union acpi_object *element = &(package->package.elements[i]);
  89. switch (element->type) {
  90. case ACPI_TYPE_INTEGER:
  91. switch (format_string[i]) {
  92. case 'N':
  93. size_required += sizeof(u64);
  94. tail_offset += sizeof(u64);
  95. break;
  96. case 'S':
  97. size_required +=
  98. sizeof(char *) + sizeof(u64) +
  99. sizeof(char);
  100. tail_offset += sizeof(char *);
  101. break;
  102. default:
  103. printk(KERN_WARNING PREFIX "Invalid package element"
  104. " [%d]: got number, expecting"
  105. " [%c]\n",
  106. i, format_string[i]);
  107. return AE_BAD_DATA;
  108. break;
  109. }
  110. break;
  111. case ACPI_TYPE_STRING:
  112. case ACPI_TYPE_BUFFER:
  113. switch (format_string[i]) {
  114. case 'S':
  115. size_required +=
  116. sizeof(char *) +
  117. (element->string.length * sizeof(char)) +
  118. sizeof(char);
  119. tail_offset += sizeof(char *);
  120. break;
  121. case 'B':
  122. size_required +=
  123. sizeof(u8 *) +
  124. (element->buffer.length * sizeof(u8));
  125. tail_offset += sizeof(u8 *);
  126. break;
  127. default:
  128. printk(KERN_WARNING PREFIX "Invalid package element"
  129. " [%d] got string/buffer,"
  130. " expecting [%c]\n",
  131. i, format_string[i]);
  132. return AE_BAD_DATA;
  133. break;
  134. }
  135. break;
  136. case ACPI_TYPE_LOCAL_REFERENCE:
  137. switch (format_string[i]) {
  138. case 'R':
  139. size_required += sizeof(void *);
  140. tail_offset += sizeof(void *);
  141. break;
  142. default:
  143. printk(KERN_WARNING PREFIX "Invalid package element"
  144. " [%d] got reference,"
  145. " expecting [%c]\n",
  146. i, format_string[i]);
  147. return AE_BAD_DATA;
  148. break;
  149. }
  150. break;
  151. case ACPI_TYPE_PACKAGE:
  152. default:
  153. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  154. "Found unsupported element at index=%d\n",
  155. i));
  156. /* TBD: handle nested packages... */
  157. return AE_SUPPORT;
  158. break;
  159. }
  160. }
  161. /*
  162. * Validate output buffer.
  163. */
  164. if (buffer->length == ACPI_ALLOCATE_BUFFER) {
  165. buffer->pointer = ACPI_ALLOCATE_ZEROED(size_required);
  166. if (!buffer->pointer)
  167. return AE_NO_MEMORY;
  168. buffer->length = size_required;
  169. } else {
  170. if (buffer->length < size_required) {
  171. buffer->length = size_required;
  172. return AE_BUFFER_OVERFLOW;
  173. } else if (buffer->length != size_required ||
  174. !buffer->pointer) {
  175. return AE_BAD_PARAMETER;
  176. }
  177. }
  178. head = buffer->pointer;
  179. tail = buffer->pointer + tail_offset;
  180. /*
  181. * Extract package data.
  182. */
  183. for (i = 0; i < format_count; i++) {
  184. u8 **pointer = NULL;
  185. union acpi_object *element = &(package->package.elements[i]);
  186. if (!element) {
  187. return AE_BAD_DATA;
  188. }
  189. switch (element->type) {
  190. case ACPI_TYPE_INTEGER:
  191. switch (format_string[i]) {
  192. case 'N':
  193. *((u64 *) head) =
  194. element->integer.value;
  195. head += sizeof(u64);
  196. break;
  197. case 'S':
  198. pointer = (u8 **) head;
  199. *pointer = tail;
  200. *((u64 *) tail) =
  201. element->integer.value;
  202. head += sizeof(u64 *);
  203. tail += sizeof(u64);
  204. /* NULL terminate string */
  205. *tail = (char)0;
  206. tail += sizeof(char);
  207. break;
  208. default:
  209. /* Should never get here */
  210. break;
  211. }
  212. break;
  213. case ACPI_TYPE_STRING:
  214. case ACPI_TYPE_BUFFER:
  215. switch (format_string[i]) {
  216. case 'S':
  217. pointer = (u8 **) head;
  218. *pointer = tail;
  219. memcpy(tail, element->string.pointer,
  220. element->string.length);
  221. head += sizeof(char *);
  222. tail += element->string.length * sizeof(char);
  223. /* NULL terminate string */
  224. *tail = (char)0;
  225. tail += sizeof(char);
  226. break;
  227. case 'B':
  228. pointer = (u8 **) head;
  229. *pointer = tail;
  230. memcpy(tail, element->buffer.pointer,
  231. element->buffer.length);
  232. head += sizeof(u8 *);
  233. tail += element->buffer.length * sizeof(u8);
  234. break;
  235. default:
  236. /* Should never get here */
  237. break;
  238. }
  239. break;
  240. case ACPI_TYPE_LOCAL_REFERENCE:
  241. switch (format_string[i]) {
  242. case 'R':
  243. *(void **)head =
  244. (void *)element->reference.handle;
  245. head += sizeof(void *);
  246. break;
  247. default:
  248. /* Should never get here */
  249. break;
  250. }
  251. break;
  252. case ACPI_TYPE_PACKAGE:
  253. /* TBD: handle nested packages... */
  254. default:
  255. /* Should never get here */
  256. break;
  257. }
  258. }
  259. return AE_OK;
  260. }
  261. EXPORT_SYMBOL(acpi_extract_package);
  262. acpi_status
  263. acpi_evaluate_integer(acpi_handle handle,
  264. acpi_string pathname,
  265. struct acpi_object_list *arguments, unsigned long long *data)
  266. {
  267. acpi_status status = AE_OK;
  268. union acpi_object element;
  269. struct acpi_buffer buffer = { 0, NULL };
  270. if (!data)
  271. return AE_BAD_PARAMETER;
  272. buffer.length = sizeof(union acpi_object);
  273. buffer.pointer = &element;
  274. status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
  275. if (ACPI_FAILURE(status)) {
  276. acpi_util_eval_error(handle, pathname, status);
  277. return status;
  278. }
  279. if (element.type != ACPI_TYPE_INTEGER) {
  280. acpi_util_eval_error(handle, pathname, AE_BAD_DATA);
  281. return AE_BAD_DATA;
  282. }
  283. *data = element.integer.value;
  284. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%llu]\n", *data));
  285. return AE_OK;
  286. }
  287. EXPORT_SYMBOL(acpi_evaluate_integer);
  288. acpi_status
  289. acpi_evaluate_reference(acpi_handle handle,
  290. acpi_string pathname,
  291. struct acpi_object_list *arguments,
  292. struct acpi_handle_list *list)
  293. {
  294. acpi_status status = AE_OK;
  295. union acpi_object *package = NULL;
  296. union acpi_object *element = NULL;
  297. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  298. u32 i = 0;
  299. if (!list) {
  300. return AE_BAD_PARAMETER;
  301. }
  302. /* Evaluate object. */
  303. status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
  304. if (ACPI_FAILURE(status))
  305. goto end;
  306. package = buffer.pointer;
  307. if ((buffer.length == 0) || !package) {
  308. printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n",
  309. (unsigned)buffer.length, package);
  310. status = AE_BAD_DATA;
  311. acpi_util_eval_error(handle, pathname, status);
  312. goto end;
  313. }
  314. if (package->type != ACPI_TYPE_PACKAGE) {
  315. printk(KERN_ERR PREFIX "Expecting a [Package], found type %X\n",
  316. package->type);
  317. status = AE_BAD_DATA;
  318. acpi_util_eval_error(handle, pathname, status);
  319. goto end;
  320. }
  321. if (!package->package.count) {
  322. printk(KERN_ERR PREFIX "[Package] has zero elements (%p)\n",
  323. package);
  324. status = AE_BAD_DATA;
  325. acpi_util_eval_error(handle, pathname, status);
  326. goto end;
  327. }
  328. if (package->package.count > ACPI_MAX_HANDLES) {
  329. return AE_NO_MEMORY;
  330. }
  331. list->count = package->package.count;
  332. /* Extract package data. */
  333. for (i = 0; i < list->count; i++) {
  334. element = &(package->package.elements[i]);
  335. if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
  336. status = AE_BAD_DATA;
  337. printk(KERN_ERR PREFIX
  338. "Expecting a [Reference] package element, found type %X\n",
  339. element->type);
  340. acpi_util_eval_error(handle, pathname, status);
  341. break;
  342. }
  343. if (!element->reference.handle) {
  344. printk(KERN_WARNING PREFIX "Invalid reference in"
  345. " package %s\n", pathname);
  346. status = AE_NULL_ENTRY;
  347. break;
  348. }
  349. /* Get the acpi_handle. */
  350. list->handles[i] = element->reference.handle;
  351. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found reference [%p]\n",
  352. list->handles[i]));
  353. }
  354. end:
  355. if (ACPI_FAILURE(status)) {
  356. list->count = 0;
  357. //kfree(list->handles);
  358. }
  359. kfree(buffer.pointer);
  360. return status;
  361. }
  362. EXPORT_SYMBOL(acpi_evaluate_reference);
  363. acpi_status
  364. acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
  365. {
  366. acpi_status status;
  367. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  368. union acpi_object *output;
  369. status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer);
  370. if (ACPI_FAILURE(status))
  371. return status;
  372. output = buffer.pointer;
  373. if (!output || output->type != ACPI_TYPE_PACKAGE
  374. || !output->package.count
  375. || output->package.elements[0].type != ACPI_TYPE_BUFFER
  376. || output->package.elements[0].buffer.length < ACPI_PLD_REV1_BUFFER_SIZE) {
  377. status = AE_TYPE;
  378. goto out;
  379. }
  380. status = acpi_decode_pld_buffer(
  381. output->package.elements[0].buffer.pointer,
  382. output->package.elements[0].buffer.length,
  383. pld);
  384. out:
  385. kfree(buffer.pointer);
  386. return status;
  387. }
  388. EXPORT_SYMBOL(acpi_get_physical_device_location);
  389. /**
  390. * acpi_evaluate_ost: Evaluate _OST for hotplug operations
  391. * @handle: ACPI device handle
  392. * @source_event: source event code
  393. * @status_code: status code
  394. * @status_buf: optional detailed information (NULL if none)
  395. *
  396. * Evaluate _OST for hotplug operations. All ACPI hotplug handlers
  397. * must call this function when evaluating _OST for hotplug operations.
  398. * When the platform does not support _OST, this function has no effect.
  399. */
  400. acpi_status
  401. acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
  402. struct acpi_buffer *status_buf)
  403. {
  404. union acpi_object params[3] = {
  405. {.type = ACPI_TYPE_INTEGER,},
  406. {.type = ACPI_TYPE_INTEGER,},
  407. {.type = ACPI_TYPE_BUFFER,}
  408. };
  409. struct acpi_object_list arg_list = {3, params};
  410. params[0].integer.value = source_event;
  411. params[1].integer.value = status_code;
  412. if (status_buf != NULL) {
  413. params[2].buffer.pointer = status_buf->pointer;
  414. params[2].buffer.length = status_buf->length;
  415. } else {
  416. params[2].buffer.pointer = NULL;
  417. params[2].buffer.length = 0;
  418. }
  419. return acpi_evaluate_object(handle, "_OST", &arg_list, NULL);
  420. }
  421. EXPORT_SYMBOL(acpi_evaluate_ost);
  422. /**
  423. * acpi_handle_path: Return the object path of handle
  424. *
  425. * Caller must free the returned buffer
  426. */
  427. static char *acpi_handle_path(acpi_handle handle)
  428. {
  429. struct acpi_buffer buffer = {
  430. .length = ACPI_ALLOCATE_BUFFER,
  431. .pointer = NULL
  432. };
  433. if (in_interrupt() ||
  434. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer) != AE_OK)
  435. return NULL;
  436. return buffer.pointer;
  437. }
  438. /**
  439. * acpi_handle_printk: Print message with ACPI prefix and object path
  440. *
  441. * This function is called through acpi_handle_<level> macros and prints
  442. * a message with ACPI prefix and object path. This function acquires
  443. * the global namespace mutex to obtain an object path. In interrupt
  444. * context, it shows the object path as <n/a>.
  445. */
  446. void
  447. acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...)
  448. {
  449. struct va_format vaf;
  450. va_list args;
  451. const char *path;
  452. va_start(args, fmt);
  453. vaf.fmt = fmt;
  454. vaf.va = &args;
  455. path = acpi_handle_path(handle);
  456. printk("%sACPI: %s: %pV", level, path ? path : "<n/a>" , &vaf);
  457. va_end(args);
  458. kfree(path);
  459. }
  460. EXPORT_SYMBOL(acpi_handle_printk);
  461. #if defined(CONFIG_DYNAMIC_DEBUG)
  462. /**
  463. * __acpi_handle_debug: pr_debug with ACPI prefix and object path
  464. *
  465. * This function is called through acpi_handle_debug macro and debug
  466. * prints a message with ACPI prefix and object path. This function
  467. * acquires the global namespace mutex to obtain an object path. In
  468. * interrupt context, it shows the object path as <n/a>.
  469. */
  470. void
  471. __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle,
  472. const char *fmt, ...)
  473. {
  474. struct va_format vaf;
  475. va_list args;
  476. const char *path;
  477. va_start(args, fmt);
  478. vaf.fmt = fmt;
  479. vaf.va = &args;
  480. path = acpi_handle_path(handle);
  481. __dynamic_pr_debug(descriptor, "ACPI: %s: %pV", path ? path : "<n/a>", &vaf);
  482. va_end(args);
  483. kfree(path);
  484. }
  485. EXPORT_SYMBOL(__acpi_handle_debug);
  486. #endif
  487. /**
  488. * acpi_has_method: Check whether @handle has a method named @name
  489. * @handle: ACPI device handle
  490. * @name: name of object or method
  491. *
  492. * Check whether @handle has a method named @name.
  493. */
  494. bool acpi_has_method(acpi_handle handle, char *name)
  495. {
  496. acpi_handle tmp;
  497. return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp));
  498. }
  499. EXPORT_SYMBOL(acpi_has_method);
  500. acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
  501. u64 arg)
  502. {
  503. union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
  504. struct acpi_object_list arg_list = { .count = 1, .pointer = &obj, };
  505. obj.integer.value = arg;
  506. return acpi_evaluate_object(handle, method, &arg_list, NULL);
  507. }
  508. EXPORT_SYMBOL(acpi_execute_simple_method);
  509. /**
  510. * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations
  511. * @handle: ACPI device handle
  512. *
  513. * Evaluate device's _EJ0 method for hotplug operations.
  514. */
  515. acpi_status acpi_evaluate_ej0(acpi_handle handle)
  516. {
  517. acpi_status status;
  518. status = acpi_execute_simple_method(handle, "_EJ0", 1);
  519. if (status == AE_NOT_FOUND)
  520. acpi_handle_warn(handle, "No _EJ0 support for device\n");
  521. else if (ACPI_FAILURE(status))
  522. acpi_handle_warn(handle, "Eject failed (0x%x)\n", status);
  523. return status;
  524. }
  525. /**
  526. * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
  527. * @handle: ACPI device handle
  528. * @lock: lock device if non-zero, otherwise unlock device
  529. *
  530. * Evaluate device's _LCK method if present to lock/unlock device
  531. */
  532. acpi_status acpi_evaluate_lck(acpi_handle handle, int lock)
  533. {
  534. acpi_status status;
  535. status = acpi_execute_simple_method(handle, "_LCK", !!lock);
  536. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  537. if (lock)
  538. acpi_handle_warn(handle,
  539. "Locking device failed (0x%x)\n", status);
  540. else
  541. acpi_handle_warn(handle,
  542. "Unlocking device failed (0x%x)\n", status);
  543. }
  544. return status;
  545. }
  546. /**
  547. * acpi_evaluate_dsm - evaluate device's _DSM method
  548. * @handle: ACPI device handle
  549. * @uuid: UUID of requested functions, should be 16 bytes
  550. * @rev: revision number of requested function
  551. * @func: requested function number
  552. * @argv4: the function specific parameter
  553. *
  554. * Evaluate device's _DSM method with specified UUID, revision id and
  555. * function number. Caller needs to free the returned object.
  556. *
  557. * Though ACPI defines the fourth parameter for _DSM should be a package,
  558. * some old BIOSes do expect a buffer or an integer etc.
  559. */
  560. union acpi_object *
  561. acpi_evaluate_dsm(acpi_handle handle, const u8 *uuid, int rev, int func,
  562. union acpi_object *argv4)
  563. {
  564. acpi_status ret;
  565. struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
  566. union acpi_object params[4];
  567. struct acpi_object_list input = {
  568. .count = 4,
  569. .pointer = params,
  570. };
  571. params[0].type = ACPI_TYPE_BUFFER;
  572. params[0].buffer.length = 16;
  573. params[0].buffer.pointer = (char *)uuid;
  574. params[1].type = ACPI_TYPE_INTEGER;
  575. params[1].integer.value = rev;
  576. params[2].type = ACPI_TYPE_INTEGER;
  577. params[2].integer.value = func;
  578. if (argv4) {
  579. params[3] = *argv4;
  580. } else {
  581. params[3].type = ACPI_TYPE_PACKAGE;
  582. params[3].package.count = 0;
  583. params[3].package.elements = NULL;
  584. }
  585. ret = acpi_evaluate_object(handle, "_DSM", &input, &buf);
  586. if (ACPI_SUCCESS(ret))
  587. return (union acpi_object *)buf.pointer;
  588. if (ret != AE_NOT_FOUND)
  589. acpi_handle_warn(handle,
  590. "failed to evaluate _DSM (0x%x)\n", ret);
  591. return NULL;
  592. }
  593. EXPORT_SYMBOL(acpi_evaluate_dsm);
  594. /**
  595. * acpi_check_dsm - check if _DSM method supports requested functions.
  596. * @handle: ACPI device handle
  597. * @uuid: UUID of requested functions, should be 16 bytes at least
  598. * @rev: revision number of requested functions
  599. * @funcs: bitmap of requested functions
  600. *
  601. * Evaluate device's _DSM method to check whether it supports requested
  602. * functions. Currently only support 64 functions at maximum, should be
  603. * enough for now.
  604. */
  605. bool acpi_check_dsm(acpi_handle handle, const u8 *uuid, int rev, u64 funcs)
  606. {
  607. int i;
  608. u64 mask = 0;
  609. union acpi_object *obj;
  610. if (funcs == 0)
  611. return false;
  612. obj = acpi_evaluate_dsm(handle, uuid, rev, 0, NULL);
  613. if (!obj)
  614. return false;
  615. /* For compatibility, old BIOSes may return an integer */
  616. if (obj->type == ACPI_TYPE_INTEGER)
  617. mask = obj->integer.value;
  618. else if (obj->type == ACPI_TYPE_BUFFER)
  619. for (i = 0; i < obj->buffer.length && i < 8; i++)
  620. mask |= (((u8)obj->buffer.pointer[i]) << (i * 8));
  621. ACPI_FREE(obj);
  622. /*
  623. * Bit 0 indicates whether there's support for any functions other than
  624. * function 0 for the specified UUID and revision.
  625. */
  626. if ((mask & 0x1) && (mask & funcs) == funcs)
  627. return true;
  628. return false;
  629. }
  630. EXPORT_SYMBOL(acpi_check_dsm);