utils.c 19 KB

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