utils.c 18 KB

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