wmi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /*
  2. * ACPI-WMI mapping driver
  3. *
  4. * Copyright (C) 2007-2008 Carlos Corbacho <carlos@strangeworlds.co.uk>
  5. *
  6. * GUID parsing code from ldm.c is:
  7. * Copyright (C) 2001,2002 Richard Russon <ldm@flatcap.org>
  8. * Copyright (c) 2001-2007 Anton Altaparmakov
  9. * Copyright (C) 2001,2002 Jakob Kemi <jakob.kemi@telia.com>
  10. *
  11. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or (at
  16. * your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful, but
  19. * WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  26. *
  27. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. */
  29. #include <linux/kernel.h>
  30. #include <linux/init.h>
  31. #include <linux/types.h>
  32. #include <linux/list.h>
  33. #include <linux/acpi.h>
  34. #include <acpi/acpi_bus.h>
  35. #include <acpi/acpi_drivers.h>
  36. ACPI_MODULE_NAME("wmi");
  37. MODULE_AUTHOR("Carlos Corbacho");
  38. MODULE_DESCRIPTION("ACPI-WMI Mapping Driver");
  39. MODULE_LICENSE("GPL");
  40. #define ACPI_WMI_CLASS "wmi"
  41. #undef PREFIX
  42. #define PREFIX "ACPI: WMI: "
  43. static DEFINE_MUTEX(wmi_data_lock);
  44. struct guid_block {
  45. char guid[16];
  46. union {
  47. char object_id[2];
  48. struct {
  49. unsigned char notify_id;
  50. unsigned char reserved;
  51. };
  52. };
  53. u8 instance_count;
  54. u8 flags;
  55. };
  56. struct wmi_block {
  57. struct list_head list;
  58. struct guid_block gblock;
  59. acpi_handle handle;
  60. wmi_notify_handler handler;
  61. void *handler_data;
  62. };
  63. static struct wmi_block wmi_blocks;
  64. /*
  65. * If the GUID data block is marked as expensive, we must enable and
  66. * explicitily disable data collection.
  67. */
  68. #define ACPI_WMI_EXPENSIVE 0x1
  69. #define ACPI_WMI_METHOD 0x2 /* GUID is a method */
  70. #define ACPI_WMI_STRING 0x4 /* GUID takes & returns a string */
  71. #define ACPI_WMI_EVENT 0x8 /* GUID is an event */
  72. static int acpi_wmi_remove(struct acpi_device *device, int type);
  73. static int acpi_wmi_add(struct acpi_device *device);
  74. static const struct acpi_device_id wmi_device_ids[] = {
  75. {"PNP0C14", 0},
  76. {"pnp0c14", 0},
  77. {"", 0},
  78. };
  79. MODULE_DEVICE_TABLE(acpi, wmi_device_ids);
  80. static struct acpi_driver acpi_wmi_driver = {
  81. .name = "wmi",
  82. .class = ACPI_WMI_CLASS,
  83. .ids = wmi_device_ids,
  84. .ops = {
  85. .add = acpi_wmi_add,
  86. .remove = acpi_wmi_remove,
  87. },
  88. };
  89. /*
  90. * GUID parsing functions
  91. */
  92. /**
  93. * wmi_parse_hexbyte - Convert a ASCII hex number to a byte
  94. * @src: Pointer to at least 2 characters to convert.
  95. *
  96. * Convert a two character ASCII hex string to a number.
  97. *
  98. * Return: 0-255 Success, the byte was parsed correctly
  99. * -1 Error, an invalid character was supplied
  100. */
  101. static int wmi_parse_hexbyte(const u8 *src)
  102. {
  103. unsigned int x; /* For correct wrapping */
  104. int h;
  105. /* high part */
  106. x = src[0];
  107. if (x - '0' <= '9' - '0') {
  108. h = x - '0';
  109. } else if (x - 'a' <= 'f' - 'a') {
  110. h = x - 'a' + 10;
  111. } else if (x - 'A' <= 'F' - 'A') {
  112. h = x - 'A' + 10;
  113. } else {
  114. return -1;
  115. }
  116. h <<= 4;
  117. /* low part */
  118. x = src[1];
  119. if (x - '0' <= '9' - '0')
  120. return h | (x - '0');
  121. if (x - 'a' <= 'f' - 'a')
  122. return h | (x - 'a' + 10);
  123. if (x - 'A' <= 'F' - 'A')
  124. return h | (x - 'A' + 10);
  125. return -1;
  126. }
  127. /**
  128. * wmi_swap_bytes - Rearrange GUID bytes to match GUID binary
  129. * @src: Memory block holding binary GUID (16 bytes)
  130. * @dest: Memory block to hold byte swapped binary GUID (16 bytes)
  131. *
  132. * Byte swap a binary GUID to match it's real GUID value
  133. */
  134. static void wmi_swap_bytes(u8 *src, u8 *dest)
  135. {
  136. int i;
  137. for (i = 0; i <= 3; i++)
  138. memcpy(dest + i, src + (3 - i), 1);
  139. for (i = 0; i <= 1; i++)
  140. memcpy(dest + 4 + i, src + (5 - i), 1);
  141. for (i = 0; i <= 1; i++)
  142. memcpy(dest + 6 + i, src + (7 - i), 1);
  143. memcpy(dest + 8, src + 8, 8);
  144. }
  145. /**
  146. * wmi_parse_guid - Convert GUID from ASCII to binary
  147. * @src: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  148. * @dest: Memory block to hold binary GUID (16 bytes)
  149. *
  150. * N.B. The GUID need not be NULL terminated.
  151. *
  152. * Return: 'true' @dest contains binary GUID
  153. * 'false' @dest contents are undefined
  154. */
  155. static bool wmi_parse_guid(const u8 *src, u8 *dest)
  156. {
  157. static const int size[] = { 4, 2, 2, 2, 6 };
  158. int i, j, v;
  159. if (src[8] != '-' || src[13] != '-' ||
  160. src[18] != '-' || src[23] != '-')
  161. return false;
  162. for (j = 0; j < 5; j++, src++) {
  163. for (i = 0; i < size[j]; i++, src += 2, *dest++ = v) {
  164. v = wmi_parse_hexbyte(src);
  165. if (v < 0)
  166. return false;
  167. }
  168. }
  169. return true;
  170. }
  171. static bool find_guid(const char *guid_string, struct wmi_block **out)
  172. {
  173. char tmp[16], guid_input[16];
  174. struct wmi_block *wblock;
  175. struct guid_block *block;
  176. struct list_head *p;
  177. wmi_parse_guid(guid_string, tmp);
  178. wmi_swap_bytes(tmp, guid_input);
  179. list_for_each(p, &wmi_blocks.list) {
  180. wblock = list_entry(p, struct wmi_block, list);
  181. block = &wblock->gblock;
  182. if (memcmp(block->guid, guid_input, 16) == 0) {
  183. if (out)
  184. *out = wblock;
  185. return 1;
  186. }
  187. }
  188. return 0;
  189. }
  190. static acpi_status wmi_method_enable(struct wmi_block *wblock, int enable)
  191. {
  192. struct guid_block *block = NULL;
  193. char method[5];
  194. struct acpi_object_list input;
  195. union acpi_object params[1];
  196. acpi_status status;
  197. acpi_handle handle;
  198. block = &wblock->gblock;
  199. handle = wblock->handle;
  200. if (!block)
  201. return AE_NOT_EXIST;
  202. input.count = 1;
  203. input.pointer = params;
  204. params[0].type = ACPI_TYPE_INTEGER;
  205. params[0].integer.value = enable;
  206. snprintf(method, 5, "WE%02X", block->notify_id);
  207. status = acpi_evaluate_object(handle, method, &input, NULL);
  208. if (status != AE_OK && status != AE_NOT_FOUND)
  209. return status;
  210. else
  211. return AE_OK;
  212. }
  213. /*
  214. * Exported WMI functions
  215. */
  216. /**
  217. * wmi_evaluate_method - Evaluate a WMI method
  218. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  219. * @instance: Instance index
  220. * @method_id: Method ID to call
  221. * &in: Buffer containing input for the method call
  222. * &out: Empty buffer to return the method results
  223. *
  224. * Call an ACPI-WMI method
  225. */
  226. acpi_status wmi_evaluate_method(const char *guid_string, u8 instance,
  227. u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)
  228. {
  229. struct guid_block *block = NULL;
  230. struct wmi_block *wblock = NULL;
  231. acpi_handle handle;
  232. acpi_status status;
  233. struct acpi_object_list input;
  234. union acpi_object params[3];
  235. char method[4] = "WM";
  236. if (!find_guid(guid_string, &wblock))
  237. return AE_ERROR;
  238. block = &wblock->gblock;
  239. handle = wblock->handle;
  240. if (!(block->flags & ACPI_WMI_METHOD))
  241. return AE_BAD_DATA;
  242. if (block->instance_count < instance)
  243. return AE_BAD_PARAMETER;
  244. input.count = 2;
  245. input.pointer = params;
  246. params[0].type = ACPI_TYPE_INTEGER;
  247. params[0].integer.value = instance;
  248. params[1].type = ACPI_TYPE_INTEGER;
  249. params[1].integer.value = method_id;
  250. if (in) {
  251. input.count = 3;
  252. if (block->flags & ACPI_WMI_STRING) {
  253. params[2].type = ACPI_TYPE_STRING;
  254. } else {
  255. params[2].type = ACPI_TYPE_BUFFER;
  256. }
  257. params[2].buffer.length = in->length;
  258. params[2].buffer.pointer = in->pointer;
  259. }
  260. strncat(method, block->object_id, 2);
  261. status = acpi_evaluate_object(handle, method, &input, out);
  262. return status;
  263. }
  264. EXPORT_SYMBOL_GPL(wmi_evaluate_method);
  265. /**
  266. * wmi_query_block - Return contents of a WMI block
  267. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  268. * @instance: Instance index
  269. * &out: Empty buffer to return the contents of the data block to
  270. *
  271. * Return the contents of an ACPI-WMI data block to a buffer
  272. */
  273. acpi_status wmi_query_block(const char *guid_string, u8 instance,
  274. struct acpi_buffer *out)
  275. {
  276. struct guid_block *block = NULL;
  277. struct wmi_block *wblock = NULL;
  278. acpi_handle handle, wc_handle;
  279. acpi_status status, wc_status = AE_ERROR;
  280. struct acpi_object_list input, wc_input;
  281. union acpi_object wc_params[1], wq_params[1];
  282. char method[4];
  283. char wc_method[4] = "WC";
  284. if (!guid_string || !out)
  285. return AE_BAD_PARAMETER;
  286. if (!find_guid(guid_string, &wblock))
  287. return AE_ERROR;
  288. block = &wblock->gblock;
  289. handle = wblock->handle;
  290. if (block->instance_count < instance)
  291. return AE_BAD_PARAMETER;
  292. /* Check GUID is a data block */
  293. if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD))
  294. return AE_ERROR;
  295. input.count = 1;
  296. input.pointer = wq_params;
  297. wq_params[0].type = ACPI_TYPE_INTEGER;
  298. wq_params[0].integer.value = instance;
  299. /*
  300. * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method first to
  301. * enable collection.
  302. */
  303. if (block->flags & ACPI_WMI_EXPENSIVE) {
  304. wc_input.count = 1;
  305. wc_input.pointer = wc_params;
  306. wc_params[0].type = ACPI_TYPE_INTEGER;
  307. wc_params[0].integer.value = 1;
  308. strncat(wc_method, block->object_id, 2);
  309. /*
  310. * Some GUIDs break the specification by declaring themselves
  311. * expensive, but have no corresponding WCxx method. So we
  312. * should not fail if this happens.
  313. */
  314. wc_status = acpi_get_handle(handle, wc_method, &wc_handle);
  315. if (ACPI_SUCCESS(wc_status))
  316. wc_status = acpi_evaluate_object(handle, wc_method,
  317. &wc_input, NULL);
  318. }
  319. strcpy(method, "WQ");
  320. strncat(method, block->object_id, 2);
  321. status = acpi_evaluate_object(handle, method, &input, out);
  322. /*
  323. * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method, even if
  324. * the WQxx method failed - we should disable collection anyway.
  325. */
  326. if ((block->flags & ACPI_WMI_EXPENSIVE) && ACPI_SUCCESS(wc_status)) {
  327. wc_params[0].integer.value = 0;
  328. status = acpi_evaluate_object(handle,
  329. wc_method, &wc_input, NULL);
  330. }
  331. return status;
  332. }
  333. EXPORT_SYMBOL_GPL(wmi_query_block);
  334. /**
  335. * wmi_set_block - Write to a WMI block
  336. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  337. * @instance: Instance index
  338. * &in: Buffer containing new values for the data block
  339. *
  340. * Write the contents of the input buffer to an ACPI-WMI data block
  341. */
  342. acpi_status wmi_set_block(const char *guid_string, u8 instance,
  343. const struct acpi_buffer *in)
  344. {
  345. struct guid_block *block = NULL;
  346. struct wmi_block *wblock = NULL;
  347. acpi_handle handle;
  348. struct acpi_object_list input;
  349. union acpi_object params[2];
  350. char method[4] = "WS";
  351. if (!guid_string || !in)
  352. return AE_BAD_DATA;
  353. if (!find_guid(guid_string, &wblock))
  354. return AE_ERROR;
  355. block = &wblock->gblock;
  356. handle = wblock->handle;
  357. if (block->instance_count < instance)
  358. return AE_BAD_PARAMETER;
  359. /* Check GUID is a data block */
  360. if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD))
  361. return AE_ERROR;
  362. input.count = 2;
  363. input.pointer = params;
  364. params[0].type = ACPI_TYPE_INTEGER;
  365. params[0].integer.value = instance;
  366. if (block->flags & ACPI_WMI_STRING) {
  367. params[1].type = ACPI_TYPE_STRING;
  368. } else {
  369. params[1].type = ACPI_TYPE_BUFFER;
  370. }
  371. params[1].buffer.length = in->length;
  372. params[1].buffer.pointer = in->pointer;
  373. strncat(method, block->object_id, 2);
  374. return acpi_evaluate_object(handle, method, &input, NULL);
  375. }
  376. EXPORT_SYMBOL_GPL(wmi_set_block);
  377. /**
  378. * wmi_install_notify_handler - Register handler for WMI events
  379. * @handler: Function to handle notifications
  380. * @data: Data to be returned to handler when event is fired
  381. *
  382. * Register a handler for events sent to the ACPI-WMI mapper device.
  383. */
  384. acpi_status wmi_install_notify_handler(const char *guid,
  385. wmi_notify_handler handler, void *data)
  386. {
  387. struct wmi_block *block;
  388. acpi_status status;
  389. if (!guid || !handler)
  390. return AE_BAD_PARAMETER;
  391. find_guid(guid, &block);
  392. if (!block)
  393. return AE_NOT_EXIST;
  394. if (block->handler)
  395. return AE_ALREADY_ACQUIRED;
  396. block->handler = handler;
  397. block->handler_data = data;
  398. status = wmi_method_enable(block, 1);
  399. return status;
  400. }
  401. EXPORT_SYMBOL_GPL(wmi_install_notify_handler);
  402. /**
  403. * wmi_uninstall_notify_handler - Unregister handler for WMI events
  404. *
  405. * Unregister handler for events sent to the ACPI-WMI mapper device.
  406. */
  407. acpi_status wmi_remove_notify_handler(const char *guid)
  408. {
  409. struct wmi_block *block;
  410. acpi_status status;
  411. if (!guid)
  412. return AE_BAD_PARAMETER;
  413. find_guid(guid, &block);
  414. if (!block)
  415. return AE_NOT_EXIST;
  416. if (!block->handler)
  417. return AE_NULL_ENTRY;
  418. status = wmi_method_enable(block, 0);
  419. block->handler = NULL;
  420. block->handler_data = NULL;
  421. return status;
  422. }
  423. EXPORT_SYMBOL_GPL(wmi_remove_notify_handler);
  424. /**
  425. * wmi_get_event_data - Get WMI data associated with an event
  426. *
  427. * @event - Event to find
  428. * &out - Buffer to hold event data
  429. *
  430. * Returns extra data associated with an event in WMI.
  431. */
  432. acpi_status wmi_get_event_data(u32 event, struct acpi_buffer *out)
  433. {
  434. struct acpi_object_list input;
  435. union acpi_object params[1];
  436. struct guid_block *gblock;
  437. struct wmi_block *wblock;
  438. struct list_head *p;
  439. input.count = 1;
  440. input.pointer = params;
  441. params[0].type = ACPI_TYPE_INTEGER;
  442. params[0].integer.value = event;
  443. list_for_each(p, &wmi_blocks.list) {
  444. wblock = list_entry(p, struct wmi_block, list);
  445. gblock = &wblock->gblock;
  446. if ((gblock->flags & ACPI_WMI_EVENT) &&
  447. (gblock->notify_id == event))
  448. return acpi_evaluate_object(wblock->handle, "_WED",
  449. &input, out);
  450. }
  451. return AE_NOT_FOUND;
  452. }
  453. EXPORT_SYMBOL_GPL(wmi_get_event_data);
  454. /**
  455. * wmi_has_guid - Check if a GUID is available
  456. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  457. *
  458. * Check if a given GUID is defined by _WDG
  459. */
  460. bool wmi_has_guid(const char *guid_string)
  461. {
  462. return find_guid(guid_string, NULL);
  463. }
  464. EXPORT_SYMBOL_GPL(wmi_has_guid);
  465. /*
  466. * Parse the _WDG method for the GUID data blocks
  467. */
  468. static __init acpi_status parse_wdg(acpi_handle handle)
  469. {
  470. struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
  471. union acpi_object *obj;
  472. struct guid_block *gblock;
  473. struct wmi_block *wblock;
  474. acpi_status status;
  475. u32 i, total;
  476. status = acpi_evaluate_object(handle, "_WDG", NULL, &out);
  477. if (ACPI_FAILURE(status))
  478. return status;
  479. obj = (union acpi_object *) out.pointer;
  480. if (obj->type != ACPI_TYPE_BUFFER)
  481. return AE_ERROR;
  482. total = obj->buffer.length / sizeof(struct guid_block);
  483. gblock = kzalloc(obj->buffer.length, GFP_KERNEL);
  484. if (!gblock)
  485. return AE_NO_MEMORY;
  486. memcpy(gblock, obj->buffer.pointer, obj->buffer.length);
  487. for (i = 0; i < total; i++) {
  488. wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
  489. if (!wblock)
  490. return AE_NO_MEMORY;
  491. wblock->gblock = gblock[i];
  492. wblock->handle = handle;
  493. list_add_tail(&wblock->list, &wmi_blocks.list);
  494. }
  495. kfree(out.pointer);
  496. kfree(gblock);
  497. return status;
  498. }
  499. /*
  500. * WMI can have EmbeddedControl access regions. In which case, we just want to
  501. * hand these off to the EC driver.
  502. */
  503. static acpi_status
  504. acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address,
  505. u32 bits, acpi_integer * value,
  506. void *handler_context, void *region_context)
  507. {
  508. int result = 0, i = 0;
  509. u8 temp = 0;
  510. if ((address > 0xFF) || !value)
  511. return AE_BAD_PARAMETER;
  512. if (function != ACPI_READ && function != ACPI_WRITE)
  513. return AE_BAD_PARAMETER;
  514. if (bits != 8)
  515. return AE_BAD_PARAMETER;
  516. if (function == ACPI_READ) {
  517. result = ec_read(address, &temp);
  518. (*value) |= ((acpi_integer)temp) << i;
  519. } else {
  520. temp = 0xff & ((*value) >> i);
  521. result = ec_write(address, temp);
  522. }
  523. switch (result) {
  524. case -EINVAL:
  525. return AE_BAD_PARAMETER;
  526. break;
  527. case -ENODEV:
  528. return AE_NOT_FOUND;
  529. break;
  530. case -ETIME:
  531. return AE_TIME;
  532. break;
  533. default:
  534. return AE_OK;
  535. }
  536. }
  537. static void acpi_wmi_notify(acpi_handle handle, u32 event, void *data)
  538. {
  539. struct guid_block *block;
  540. struct wmi_block *wblock;
  541. struct list_head *p;
  542. struct acpi_device *device = data;
  543. list_for_each(p, &wmi_blocks.list) {
  544. wblock = list_entry(p, struct wmi_block, list);
  545. block = &wblock->gblock;
  546. if ((block->flags & ACPI_WMI_EVENT) &&
  547. (block->notify_id == event)) {
  548. if (wblock->handler)
  549. wblock->handler(event, wblock->handler_data);
  550. acpi_bus_generate_netlink_event(
  551. device->pnp.device_class, dev_name(&device->dev),
  552. event, 0);
  553. break;
  554. }
  555. }
  556. }
  557. static int acpi_wmi_remove(struct acpi_device *device, int type)
  558. {
  559. acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  560. acpi_wmi_notify);
  561. acpi_remove_address_space_handler(device->handle,
  562. ACPI_ADR_SPACE_EC, &acpi_wmi_ec_space_handler);
  563. return 0;
  564. }
  565. static int __init acpi_wmi_add(struct acpi_device *device)
  566. {
  567. acpi_status status;
  568. int result = 0;
  569. status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  570. acpi_wmi_notify, device);
  571. if (ACPI_FAILURE(status)) {
  572. printk(KERN_ERR PREFIX "Error installing notify handler\n");
  573. return -ENODEV;
  574. }
  575. status = acpi_install_address_space_handler(device->handle,
  576. ACPI_ADR_SPACE_EC,
  577. &acpi_wmi_ec_space_handler,
  578. NULL, NULL);
  579. if (ACPI_FAILURE(status))
  580. return -ENODEV;
  581. status = parse_wdg(device->handle);
  582. if (ACPI_FAILURE(status)) {
  583. printk(KERN_ERR PREFIX "Error installing EC region handler\n");
  584. return -ENODEV;
  585. }
  586. return result;
  587. }
  588. static int __init acpi_wmi_init(void)
  589. {
  590. int result;
  591. INIT_LIST_HEAD(&wmi_blocks.list);
  592. if (acpi_disabled)
  593. return -ENODEV;
  594. result = acpi_bus_register_driver(&acpi_wmi_driver);
  595. if (result < 0) {
  596. printk(KERN_INFO PREFIX "Error loading mapper\n");
  597. } else {
  598. printk(KERN_INFO PREFIX "Mapper loaded\n");
  599. }
  600. return result;
  601. }
  602. static void __exit acpi_wmi_exit(void)
  603. {
  604. struct list_head *p, *tmp;
  605. struct wmi_block *wblock;
  606. acpi_bus_unregister_driver(&acpi_wmi_driver);
  607. list_for_each_safe(p, tmp, &wmi_blocks.list) {
  608. wblock = list_entry(p, struct wmi_block, list);
  609. list_del(p);
  610. kfree(wblock);
  611. }
  612. printk(KERN_INFO PREFIX "Mapper unloaded\n");
  613. }
  614. subsys_initcall(acpi_wmi_init);
  615. module_exit(acpi_wmi_exit);