utils.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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_PACKAGE:
  137. default:
  138. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  139. "Found unsupported element at index=%d\n",
  140. i));
  141. /* TBD: handle nested packages... */
  142. return AE_SUPPORT;
  143. break;
  144. }
  145. }
  146. /*
  147. * Validate output buffer.
  148. */
  149. if (buffer->length == ACPI_ALLOCATE_BUFFER) {
  150. buffer->pointer = ACPI_ALLOCATE_ZEROED(size_required);
  151. if (!buffer->pointer)
  152. return AE_NO_MEMORY;
  153. buffer->length = size_required;
  154. } else {
  155. if (buffer->length < size_required) {
  156. buffer->length = size_required;
  157. return AE_BUFFER_OVERFLOW;
  158. } else if (buffer->length != size_required ||
  159. !buffer->pointer) {
  160. return AE_BAD_PARAMETER;
  161. }
  162. }
  163. head = buffer->pointer;
  164. tail = buffer->pointer + tail_offset;
  165. /*
  166. * Extract package data.
  167. */
  168. for (i = 0; i < format_count; i++) {
  169. u8 **pointer = NULL;
  170. union acpi_object *element = &(package->package.elements[i]);
  171. if (!element) {
  172. return AE_BAD_DATA;
  173. }
  174. switch (element->type) {
  175. case ACPI_TYPE_INTEGER:
  176. switch (format_string[i]) {
  177. case 'N':
  178. *((u64 *) head) =
  179. element->integer.value;
  180. head += sizeof(u64);
  181. break;
  182. case 'S':
  183. pointer = (u8 **) head;
  184. *pointer = tail;
  185. *((u64 *) tail) =
  186. element->integer.value;
  187. head += sizeof(u64 *);
  188. tail += sizeof(u64);
  189. /* NULL terminate string */
  190. *tail = (char)0;
  191. tail += sizeof(char);
  192. break;
  193. default:
  194. /* Should never get here */
  195. break;
  196. }
  197. break;
  198. case ACPI_TYPE_STRING:
  199. case ACPI_TYPE_BUFFER:
  200. switch (format_string[i]) {
  201. case 'S':
  202. pointer = (u8 **) head;
  203. *pointer = tail;
  204. memcpy(tail, element->string.pointer,
  205. element->string.length);
  206. head += sizeof(char *);
  207. tail += element->string.length * sizeof(char);
  208. /* NULL terminate string */
  209. *tail = (char)0;
  210. tail += sizeof(char);
  211. break;
  212. case 'B':
  213. pointer = (u8 **) head;
  214. *pointer = tail;
  215. memcpy(tail, element->buffer.pointer,
  216. element->buffer.length);
  217. head += sizeof(u8 *);
  218. tail += element->buffer.length * sizeof(u8);
  219. break;
  220. default:
  221. /* Should never get here */
  222. break;
  223. }
  224. break;
  225. case ACPI_TYPE_PACKAGE:
  226. /* TBD: handle nested packages... */
  227. default:
  228. /* Should never get here */
  229. break;
  230. }
  231. }
  232. return AE_OK;
  233. }
  234. EXPORT_SYMBOL(acpi_extract_package);
  235. acpi_status
  236. acpi_evaluate_integer(acpi_handle handle,
  237. acpi_string pathname,
  238. struct acpi_object_list *arguments, unsigned long long *data)
  239. {
  240. acpi_status status = AE_OK;
  241. union acpi_object element;
  242. struct acpi_buffer buffer = { 0, NULL };
  243. if (!data)
  244. return AE_BAD_PARAMETER;
  245. buffer.length = sizeof(union acpi_object);
  246. buffer.pointer = &element;
  247. status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
  248. if (ACPI_FAILURE(status)) {
  249. acpi_util_eval_error(handle, pathname, status);
  250. return status;
  251. }
  252. if (element.type != ACPI_TYPE_INTEGER) {
  253. acpi_util_eval_error(handle, pathname, AE_BAD_DATA);
  254. return AE_BAD_DATA;
  255. }
  256. *data = element.integer.value;
  257. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%llu]\n", *data));
  258. return AE_OK;
  259. }
  260. EXPORT_SYMBOL(acpi_evaluate_integer);
  261. acpi_status
  262. acpi_evaluate_reference(acpi_handle handle,
  263. acpi_string pathname,
  264. struct acpi_object_list *arguments,
  265. struct acpi_handle_list *list)
  266. {
  267. acpi_status status = AE_OK;
  268. union acpi_object *package = NULL;
  269. union acpi_object *element = NULL;
  270. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  271. u32 i = 0;
  272. if (!list) {
  273. return AE_BAD_PARAMETER;
  274. }
  275. /* Evaluate object. */
  276. status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
  277. if (ACPI_FAILURE(status))
  278. goto end;
  279. package = buffer.pointer;
  280. if ((buffer.length == 0) || !package) {
  281. printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n",
  282. (unsigned)buffer.length, package);
  283. status = AE_BAD_DATA;
  284. acpi_util_eval_error(handle, pathname, status);
  285. goto end;
  286. }
  287. if (package->type != ACPI_TYPE_PACKAGE) {
  288. printk(KERN_ERR PREFIX "Expecting a [Package], found type %X\n",
  289. package->type);
  290. status = AE_BAD_DATA;
  291. acpi_util_eval_error(handle, pathname, status);
  292. goto end;
  293. }
  294. if (!package->package.count) {
  295. printk(KERN_ERR PREFIX "[Package] has zero elements (%p)\n",
  296. package);
  297. status = AE_BAD_DATA;
  298. acpi_util_eval_error(handle, pathname, status);
  299. goto end;
  300. }
  301. if (package->package.count > ACPI_MAX_HANDLES) {
  302. return AE_NO_MEMORY;
  303. }
  304. list->count = package->package.count;
  305. /* Extract package data. */
  306. for (i = 0; i < list->count; i++) {
  307. element = &(package->package.elements[i]);
  308. if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
  309. status = AE_BAD_DATA;
  310. printk(KERN_ERR PREFIX
  311. "Expecting a [Reference] package element, found type %X\n",
  312. element->type);
  313. acpi_util_eval_error(handle, pathname, status);
  314. break;
  315. }
  316. if (!element->reference.handle) {
  317. printk(KERN_WARNING PREFIX "Invalid reference in"
  318. " package %s\n", pathname);
  319. status = AE_NULL_ENTRY;
  320. break;
  321. }
  322. /* Get the acpi_handle. */
  323. list->handles[i] = element->reference.handle;
  324. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found reference [%p]\n",
  325. list->handles[i]));
  326. }
  327. end:
  328. if (ACPI_FAILURE(status)) {
  329. list->count = 0;
  330. //kfree(list->handles);
  331. }
  332. kfree(buffer.pointer);
  333. return status;
  334. }
  335. EXPORT_SYMBOL(acpi_evaluate_reference);
  336. acpi_status
  337. acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
  338. {
  339. acpi_status status;
  340. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  341. union acpi_object *output;
  342. status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer);
  343. if (ACPI_FAILURE(status))
  344. return status;
  345. output = buffer.pointer;
  346. if (!output || output->type != ACPI_TYPE_PACKAGE
  347. || !output->package.count
  348. || output->package.elements[0].type != ACPI_TYPE_BUFFER
  349. || output->package.elements[0].buffer.length < ACPI_PLD_REV1_BUFFER_SIZE) {
  350. status = AE_TYPE;
  351. goto out;
  352. }
  353. status = acpi_decode_pld_buffer(
  354. output->package.elements[0].buffer.pointer,
  355. output->package.elements[0].buffer.length,
  356. pld);
  357. out:
  358. kfree(buffer.pointer);
  359. return status;
  360. }
  361. EXPORT_SYMBOL(acpi_get_physical_device_location);
  362. /**
  363. * acpi_evaluate_ost: Evaluate _OST for hotplug operations
  364. * @handle: ACPI device handle
  365. * @source_event: source event code
  366. * @status_code: status code
  367. * @status_buf: optional detailed information (NULL if none)
  368. *
  369. * Evaluate _OST for hotplug operations. All ACPI hotplug handlers
  370. * must call this function when evaluating _OST for hotplug operations.
  371. * When the platform does not support _OST, this function has no effect.
  372. */
  373. acpi_status
  374. acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
  375. struct acpi_buffer *status_buf)
  376. {
  377. union acpi_object params[3] = {
  378. {.type = ACPI_TYPE_INTEGER,},
  379. {.type = ACPI_TYPE_INTEGER,},
  380. {.type = ACPI_TYPE_BUFFER,}
  381. };
  382. struct acpi_object_list arg_list = {3, params};
  383. params[0].integer.value = source_event;
  384. params[1].integer.value = status_code;
  385. if (status_buf != NULL) {
  386. params[2].buffer.pointer = status_buf->pointer;
  387. params[2].buffer.length = status_buf->length;
  388. } else {
  389. params[2].buffer.pointer = NULL;
  390. params[2].buffer.length = 0;
  391. }
  392. return acpi_evaluate_object(handle, "_OST", &arg_list, NULL);
  393. }
  394. EXPORT_SYMBOL(acpi_evaluate_ost);
  395. /**
  396. * acpi_handle_path: Return the object path of handle
  397. *
  398. * Caller must free the returned buffer
  399. */
  400. static char *acpi_handle_path(acpi_handle handle)
  401. {
  402. struct acpi_buffer buffer = {
  403. .length = ACPI_ALLOCATE_BUFFER,
  404. .pointer = NULL
  405. };
  406. if (in_interrupt() ||
  407. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer) != AE_OK)
  408. return NULL;
  409. return buffer.pointer;
  410. }
  411. /**
  412. * acpi_handle_printk: Print message with ACPI prefix and object path
  413. *
  414. * This function is called through acpi_handle_<level> macros and prints
  415. * a message with ACPI prefix and object path. This function acquires
  416. * the global namespace mutex to obtain an object path. In interrupt
  417. * context, it shows the object path as <n/a>.
  418. */
  419. void
  420. acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...)
  421. {
  422. struct va_format vaf;
  423. va_list args;
  424. const char *path;
  425. va_start(args, fmt);
  426. vaf.fmt = fmt;
  427. vaf.va = &args;
  428. path = acpi_handle_path(handle);
  429. printk("%sACPI: %s: %pV", level, path ? path : "<n/a>" , &vaf);
  430. va_end(args);
  431. kfree(path);
  432. }
  433. EXPORT_SYMBOL(acpi_handle_printk);
  434. #if defined(CONFIG_DYNAMIC_DEBUG)
  435. /**
  436. * __acpi_handle_debug: pr_debug with ACPI prefix and object path
  437. *
  438. * This function is called through acpi_handle_debug macro and debug
  439. * prints a message with ACPI prefix and object path. This function
  440. * acquires the global namespace mutex to obtain an object path. In
  441. * interrupt context, it shows the object path as <n/a>.
  442. */
  443. void
  444. __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle,
  445. const char *fmt, ...)
  446. {
  447. struct va_format vaf;
  448. va_list args;
  449. const char *path;
  450. va_start(args, fmt);
  451. vaf.fmt = fmt;
  452. vaf.va = &args;
  453. path = acpi_handle_path(handle);
  454. __dynamic_pr_debug(descriptor, "ACPI: %s: %pV", path ? path : "<n/a>", &vaf);
  455. va_end(args);
  456. kfree(path);
  457. }
  458. EXPORT_SYMBOL(__acpi_handle_debug);
  459. #endif
  460. /**
  461. * acpi_has_method: Check whether @handle has a method named @name
  462. * @handle: ACPI device handle
  463. * @name: name of object or method
  464. *
  465. * Check whether @handle has a method named @name.
  466. */
  467. bool acpi_has_method(acpi_handle handle, char *name)
  468. {
  469. acpi_handle tmp;
  470. return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp));
  471. }
  472. EXPORT_SYMBOL(acpi_has_method);
  473. acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
  474. u64 arg)
  475. {
  476. union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
  477. struct acpi_object_list arg_list = { .count = 1, .pointer = &obj, };
  478. obj.integer.value = arg;
  479. return acpi_evaluate_object(handle, method, &arg_list, NULL);
  480. }
  481. EXPORT_SYMBOL(acpi_execute_simple_method);
  482. /**
  483. * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations
  484. * @handle: ACPI device handle
  485. *
  486. * Evaluate device's _EJ0 method for hotplug operations.
  487. */
  488. acpi_status acpi_evaluate_ej0(acpi_handle handle)
  489. {
  490. acpi_status status;
  491. status = acpi_execute_simple_method(handle, "_EJ0", 1);
  492. if (status == AE_NOT_FOUND)
  493. acpi_handle_warn(handle, "No _EJ0 support for device\n");
  494. else if (ACPI_FAILURE(status))
  495. acpi_handle_warn(handle, "Eject failed (0x%x)\n", status);
  496. return status;
  497. }
  498. /**
  499. * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
  500. * @handle: ACPI device handle
  501. * @lock: lock device if non-zero, otherwise unlock device
  502. *
  503. * Evaluate device's _LCK method if present to lock/unlock device
  504. */
  505. acpi_status acpi_evaluate_lck(acpi_handle handle, int lock)
  506. {
  507. acpi_status status;
  508. status = acpi_execute_simple_method(handle, "_LCK", !!lock);
  509. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  510. if (lock)
  511. acpi_handle_warn(handle,
  512. "Locking device failed (0x%x)\n", status);
  513. else
  514. acpi_handle_warn(handle,
  515. "Unlocking device failed (0x%x)\n", status);
  516. }
  517. return status;
  518. }
  519. /**
  520. * acpi_evaluate_dsm - evaluate device's _DSM method
  521. * @handle: ACPI device handle
  522. * @uuid: UUID of requested functions, should be 16 bytes
  523. * @rev: revision number of requested function
  524. * @func: requested function number
  525. * @argv4: the function specific parameter
  526. *
  527. * Evaluate device's _DSM method with specified UUID, revision id and
  528. * function number. Caller needs to free the returned object.
  529. *
  530. * Though ACPI defines the fourth parameter for _DSM should be a package,
  531. * some old BIOSes do expect a buffer or an integer etc.
  532. */
  533. union acpi_object *
  534. acpi_evaluate_dsm(acpi_handle handle, const u8 *uuid, int rev, int func,
  535. union acpi_object *argv4)
  536. {
  537. acpi_status ret;
  538. struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
  539. union acpi_object params[4];
  540. struct acpi_object_list input = {
  541. .count = 4,
  542. .pointer = params,
  543. };
  544. params[0].type = ACPI_TYPE_BUFFER;
  545. params[0].buffer.length = 16;
  546. params[0].buffer.pointer = (char *)uuid;
  547. params[1].type = ACPI_TYPE_INTEGER;
  548. params[1].integer.value = rev;
  549. params[2].type = ACPI_TYPE_INTEGER;
  550. params[2].integer.value = func;
  551. if (argv4) {
  552. params[3] = *argv4;
  553. } else {
  554. params[3].type = ACPI_TYPE_PACKAGE;
  555. params[3].package.count = 0;
  556. params[3].package.elements = NULL;
  557. }
  558. ret = acpi_evaluate_object(handle, "_DSM", &input, &buf);
  559. if (ACPI_SUCCESS(ret))
  560. return (union acpi_object *)buf.pointer;
  561. if (ret != AE_NOT_FOUND)
  562. acpi_handle_warn(handle,
  563. "failed to evaluate _DSM (0x%x)\n", ret);
  564. return NULL;
  565. }
  566. EXPORT_SYMBOL(acpi_evaluate_dsm);
  567. /**
  568. * acpi_check_dsm - check if _DSM method supports requested functions.
  569. * @handle: ACPI device handle
  570. * @uuid: UUID of requested functions, should be 16 bytes at least
  571. * @rev: revision number of requested functions
  572. * @funcs: bitmap of requested functions
  573. * @exclude: excluding special value, used to support i915 and nouveau
  574. *
  575. * Evaluate device's _DSM method to check whether it supports requested
  576. * functions. Currently only support 64 functions at maximum, should be
  577. * enough for now.
  578. */
  579. bool acpi_check_dsm(acpi_handle handle, const u8 *uuid, int rev, u64 funcs)
  580. {
  581. int i;
  582. u64 mask = 0;
  583. union acpi_object *obj;
  584. if (funcs == 0)
  585. return false;
  586. obj = acpi_evaluate_dsm(handle, uuid, rev, 0, NULL);
  587. if (!obj)
  588. return false;
  589. /* For compatibility, old BIOSes may return an integer */
  590. if (obj->type == ACPI_TYPE_INTEGER)
  591. mask = obj->integer.value;
  592. else if (obj->type == ACPI_TYPE_BUFFER)
  593. for (i = 0; i < obj->buffer.length && i < 8; i++)
  594. mask |= (((u8)obj->buffer.pointer[i]) << (i * 8));
  595. ACPI_FREE(obj);
  596. /*
  597. * Bit 0 indicates whether there's support for any functions other than
  598. * function 0 for the specified UUID and revision.
  599. */
  600. if ((mask & 0x1) && (mask & funcs) == funcs)
  601. return true;
  602. return false;
  603. }
  604. EXPORT_SYMBOL(acpi_check_dsm);