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