wmi.c 17 KB

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