utils.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. status = AE_BAD_DATA;
  309. acpi_util_eval_error(handle, pathname, status);
  310. goto end;
  311. }
  312. if (package->type != ACPI_TYPE_PACKAGE) {
  313. status = AE_BAD_DATA;
  314. acpi_util_eval_error(handle, pathname, status);
  315. goto end;
  316. }
  317. if (!package->package.count) {
  318. status = AE_BAD_DATA;
  319. acpi_util_eval_error(handle, pathname, status);
  320. goto end;
  321. }
  322. if (package->package.count > ACPI_MAX_HANDLES) {
  323. return AE_NO_MEMORY;
  324. }
  325. list->count = package->package.count;
  326. /* Extract package data. */
  327. for (i = 0; i < list->count; i++) {
  328. element = &(package->package.elements[i]);
  329. if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
  330. status = AE_BAD_DATA;
  331. acpi_util_eval_error(handle, pathname, status);
  332. break;
  333. }
  334. if (!element->reference.handle) {
  335. status = AE_NULL_ENTRY;
  336. acpi_util_eval_error(handle, pathname, status);
  337. break;
  338. }
  339. /* Get the acpi_handle. */
  340. list->handles[i] = element->reference.handle;
  341. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found reference [%p]\n",
  342. list->handles[i]));
  343. }
  344. end:
  345. if (ACPI_FAILURE(status)) {
  346. list->count = 0;
  347. //kfree(list->handles);
  348. }
  349. kfree(buffer.pointer);
  350. return status;
  351. }
  352. EXPORT_SYMBOL(acpi_evaluate_reference);
  353. acpi_status
  354. acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
  355. {
  356. acpi_status status;
  357. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  358. union acpi_object *output;
  359. status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer);
  360. if (ACPI_FAILURE(status))
  361. return status;
  362. output = buffer.pointer;
  363. if (!output || output->type != ACPI_TYPE_PACKAGE
  364. || !output->package.count
  365. || output->package.elements[0].type != ACPI_TYPE_BUFFER
  366. || output->package.elements[0].buffer.length < ACPI_PLD_REV1_BUFFER_SIZE) {
  367. status = AE_TYPE;
  368. goto out;
  369. }
  370. status = acpi_decode_pld_buffer(
  371. output->package.elements[0].buffer.pointer,
  372. output->package.elements[0].buffer.length,
  373. pld);
  374. out:
  375. kfree(buffer.pointer);
  376. return status;
  377. }
  378. EXPORT_SYMBOL(acpi_get_physical_device_location);
  379. /**
  380. * acpi_evaluate_ost: Evaluate _OST for hotplug operations
  381. * @handle: ACPI device handle
  382. * @source_event: source event code
  383. * @status_code: status code
  384. * @status_buf: optional detailed information (NULL if none)
  385. *
  386. * Evaluate _OST for hotplug operations. All ACPI hotplug handlers
  387. * must call this function when evaluating _OST for hotplug operations.
  388. * When the platform does not support _OST, this function has no effect.
  389. */
  390. acpi_status
  391. acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
  392. struct acpi_buffer *status_buf)
  393. {
  394. union acpi_object params[3] = {
  395. {.type = ACPI_TYPE_INTEGER,},
  396. {.type = ACPI_TYPE_INTEGER,},
  397. {.type = ACPI_TYPE_BUFFER,}
  398. };
  399. struct acpi_object_list arg_list = {3, params};
  400. params[0].integer.value = source_event;
  401. params[1].integer.value = status_code;
  402. if (status_buf != NULL) {
  403. params[2].buffer.pointer = status_buf->pointer;
  404. params[2].buffer.length = status_buf->length;
  405. } else {
  406. params[2].buffer.pointer = NULL;
  407. params[2].buffer.length = 0;
  408. }
  409. return acpi_evaluate_object(handle, "_OST", &arg_list, NULL);
  410. }
  411. EXPORT_SYMBOL(acpi_evaluate_ost);
  412. /**
  413. * acpi_handle_path: Return the object path of handle
  414. *
  415. * Caller must free the returned buffer
  416. */
  417. static char *acpi_handle_path(acpi_handle handle)
  418. {
  419. struct acpi_buffer buffer = {
  420. .length = ACPI_ALLOCATE_BUFFER,
  421. .pointer = NULL
  422. };
  423. if (in_interrupt() ||
  424. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer) != AE_OK)
  425. return NULL;
  426. return buffer.pointer;
  427. }
  428. /**
  429. * acpi_handle_printk: Print message with ACPI prefix and object path
  430. *
  431. * This function is called through acpi_handle_<level> macros and prints
  432. * a message with ACPI prefix and object path. This function acquires
  433. * the global namespace mutex to obtain an object path. In interrupt
  434. * context, it shows the object path as <n/a>.
  435. */
  436. void
  437. acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...)
  438. {
  439. struct va_format vaf;
  440. va_list args;
  441. const char *path;
  442. va_start(args, fmt);
  443. vaf.fmt = fmt;
  444. vaf.va = &args;
  445. path = acpi_handle_path(handle);
  446. printk("%sACPI: %s: %pV", level, path ? path : "<n/a>" , &vaf);
  447. va_end(args);
  448. kfree(path);
  449. }
  450. EXPORT_SYMBOL(acpi_handle_printk);
  451. #if defined(CONFIG_DYNAMIC_DEBUG)
  452. /**
  453. * __acpi_handle_debug: pr_debug with ACPI prefix and object path
  454. *
  455. * This function is called through acpi_handle_debug macro and debug
  456. * prints a message with ACPI prefix and object path. This function
  457. * acquires the global namespace mutex to obtain an object path. In
  458. * interrupt context, it shows the object path as <n/a>.
  459. */
  460. void
  461. __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle,
  462. const char *fmt, ...)
  463. {
  464. struct va_format vaf;
  465. va_list args;
  466. const char *path;
  467. va_start(args, fmt);
  468. vaf.fmt = fmt;
  469. vaf.va = &args;
  470. path = acpi_handle_path(handle);
  471. __dynamic_pr_debug(descriptor, "ACPI: %s: %pV", path ? path : "<n/a>", &vaf);
  472. va_end(args);
  473. kfree(path);
  474. }
  475. EXPORT_SYMBOL(__acpi_handle_debug);
  476. #endif
  477. /**
  478. * acpi_has_method: Check whether @handle has a method named @name
  479. * @handle: ACPI device handle
  480. * @name: name of object or method
  481. *
  482. * Check whether @handle has a method named @name.
  483. */
  484. bool acpi_has_method(acpi_handle handle, char *name)
  485. {
  486. acpi_handle tmp;
  487. return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp));
  488. }
  489. EXPORT_SYMBOL(acpi_has_method);
  490. acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
  491. u64 arg)
  492. {
  493. union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
  494. struct acpi_object_list arg_list = { .count = 1, .pointer = &obj, };
  495. obj.integer.value = arg;
  496. return acpi_evaluate_object(handle, method, &arg_list, NULL);
  497. }
  498. EXPORT_SYMBOL(acpi_execute_simple_method);
  499. /**
  500. * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations
  501. * @handle: ACPI device handle
  502. *
  503. * Evaluate device's _EJ0 method for hotplug operations.
  504. */
  505. acpi_status acpi_evaluate_ej0(acpi_handle handle)
  506. {
  507. acpi_status status;
  508. status = acpi_execute_simple_method(handle, "_EJ0", 1);
  509. if (status == AE_NOT_FOUND)
  510. acpi_handle_warn(handle, "No _EJ0 support for device\n");
  511. else if (ACPI_FAILURE(status))
  512. acpi_handle_warn(handle, "Eject failed (0x%x)\n", status);
  513. return status;
  514. }
  515. /**
  516. * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
  517. * @handle: ACPI device handle
  518. * @lock: lock device if non-zero, otherwise unlock device
  519. *
  520. * Evaluate device's _LCK method if present to lock/unlock device
  521. */
  522. acpi_status acpi_evaluate_lck(acpi_handle handle, int lock)
  523. {
  524. acpi_status status;
  525. status = acpi_execute_simple_method(handle, "_LCK", !!lock);
  526. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  527. if (lock)
  528. acpi_handle_warn(handle,
  529. "Locking device failed (0x%x)\n", status);
  530. else
  531. acpi_handle_warn(handle,
  532. "Unlocking device failed (0x%x)\n", status);
  533. }
  534. return status;
  535. }
  536. /**
  537. * acpi_evaluate_dsm - evaluate device's _DSM method
  538. * @handle: ACPI device handle
  539. * @uuid: UUID of requested functions, should be 16 bytes
  540. * @rev: revision number of requested function
  541. * @func: requested function number
  542. * @argv4: the function specific parameter
  543. *
  544. * Evaluate device's _DSM method with specified UUID, revision id and
  545. * function number. Caller needs to free the returned object.
  546. *
  547. * Though ACPI defines the fourth parameter for _DSM should be a package,
  548. * some old BIOSes do expect a buffer or an integer etc.
  549. */
  550. union acpi_object *
  551. acpi_evaluate_dsm(acpi_handle handle, const u8 *uuid, int rev, int func,
  552. union acpi_object *argv4)
  553. {
  554. acpi_status ret;
  555. struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
  556. union acpi_object params[4];
  557. struct acpi_object_list input = {
  558. .count = 4,
  559. .pointer = params,
  560. };
  561. params[0].type = ACPI_TYPE_BUFFER;
  562. params[0].buffer.length = 16;
  563. params[0].buffer.pointer = (char *)uuid;
  564. params[1].type = ACPI_TYPE_INTEGER;
  565. params[1].integer.value = rev;
  566. params[2].type = ACPI_TYPE_INTEGER;
  567. params[2].integer.value = func;
  568. if (argv4) {
  569. params[3] = *argv4;
  570. } else {
  571. params[3].type = ACPI_TYPE_PACKAGE;
  572. params[3].package.count = 0;
  573. params[3].package.elements = NULL;
  574. }
  575. ret = acpi_evaluate_object(handle, "_DSM", &input, &buf);
  576. if (ACPI_SUCCESS(ret))
  577. return (union acpi_object *)buf.pointer;
  578. if (ret != AE_NOT_FOUND)
  579. acpi_handle_warn(handle,
  580. "failed to evaluate _DSM (0x%x)\n", ret);
  581. return NULL;
  582. }
  583. EXPORT_SYMBOL(acpi_evaluate_dsm);
  584. /**
  585. * acpi_check_dsm - check if _DSM method supports requested functions.
  586. * @handle: ACPI device handle
  587. * @uuid: UUID of requested functions, should be 16 bytes at least
  588. * @rev: revision number of requested functions
  589. * @funcs: bitmap of requested functions
  590. *
  591. * Evaluate device's _DSM method to check whether it supports requested
  592. * functions. Currently only support 64 functions at maximum, should be
  593. * enough for now.
  594. */
  595. bool acpi_check_dsm(acpi_handle handle, const u8 *uuid, int rev, u64 funcs)
  596. {
  597. int i;
  598. u64 mask = 0;
  599. union acpi_object *obj;
  600. if (funcs == 0)
  601. return false;
  602. obj = acpi_evaluate_dsm(handle, uuid, rev, 0, NULL);
  603. if (!obj)
  604. return false;
  605. /* For compatibility, old BIOSes may return an integer */
  606. if (obj->type == ACPI_TYPE_INTEGER)
  607. mask = obj->integer.value;
  608. else if (obj->type == ACPI_TYPE_BUFFER)
  609. for (i = 0; i < obj->buffer.length && i < 8; i++)
  610. mask |= (((u8)obj->buffer.pointer[i]) << (i * 8));
  611. ACPI_FREE(obj);
  612. /*
  613. * Bit 0 indicates whether there's support for any functions other than
  614. * function 0 for the specified UUID and revision.
  615. */
  616. if ((mask & 0x1) && (mask & funcs) == funcs)
  617. return true;
  618. return false;
  619. }
  620. EXPORT_SYMBOL(acpi_check_dsm);