utils.c 19 KB

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