wmi.c 17 KB

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