wmi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. /*
  191. * Exported WMI functions
  192. */
  193. /**
  194. * wmi_evaluate_method - Evaluate a WMI method
  195. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  196. * @instance: Instance index
  197. * @method_id: Method ID to call
  198. * &in: Buffer containing input for the method call
  199. * &out: Empty buffer to return the method results
  200. *
  201. * Call an ACPI-WMI method
  202. */
  203. acpi_status wmi_evaluate_method(const char *guid_string, u8 instance,
  204. u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)
  205. {
  206. struct guid_block *block = NULL;
  207. struct wmi_block *wblock = NULL;
  208. acpi_handle handle;
  209. acpi_status status;
  210. struct acpi_object_list input;
  211. union acpi_object params[3];
  212. char method[4] = "WM";
  213. if (!find_guid(guid_string, &wblock))
  214. return AE_BAD_ADDRESS;
  215. block = &wblock->gblock;
  216. handle = wblock->handle;
  217. if (!(block->flags & ACPI_WMI_METHOD))
  218. return AE_BAD_DATA;
  219. if (block->instance_count < instance)
  220. return AE_BAD_PARAMETER;
  221. input.count = 2;
  222. input.pointer = params;
  223. params[0].type = ACPI_TYPE_INTEGER;
  224. params[0].integer.value = instance;
  225. params[1].type = ACPI_TYPE_INTEGER;
  226. params[1].integer.value = method_id;
  227. if (in) {
  228. input.count = 3;
  229. if (block->flags & ACPI_WMI_STRING) {
  230. params[2].type = ACPI_TYPE_STRING;
  231. } else {
  232. params[2].type = ACPI_TYPE_BUFFER;
  233. }
  234. params[2].buffer.length = in->length;
  235. params[2].buffer.pointer = in->pointer;
  236. }
  237. strncat(method, block->object_id, 2);
  238. status = acpi_evaluate_object(handle, method, &input, out);
  239. return status;
  240. }
  241. EXPORT_SYMBOL_GPL(wmi_evaluate_method);
  242. /**
  243. * wmi_query_block - Return contents of a WMI block
  244. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  245. * @instance: Instance index
  246. * &out: Empty buffer to return the contents of the data block to
  247. *
  248. * Return the contents of an ACPI-WMI data block to a buffer
  249. */
  250. acpi_status wmi_query_block(const char *guid_string, u8 instance,
  251. struct acpi_buffer *out)
  252. {
  253. struct guid_block *block = NULL;
  254. struct wmi_block *wblock = NULL;
  255. acpi_handle handle, wc_handle;
  256. acpi_status status, wc_status = AE_ERROR;
  257. struct acpi_object_list input, wc_input;
  258. union acpi_object wc_params[1], wq_params[1];
  259. char method[4];
  260. char wc_method[4] = "WC";
  261. if (!guid_string || !out)
  262. return AE_BAD_PARAMETER;
  263. if (!find_guid(guid_string, &wblock))
  264. return AE_BAD_ADDRESS;
  265. block = &wblock->gblock;
  266. handle = wblock->handle;
  267. if (block->instance_count < instance)
  268. return AE_BAD_PARAMETER;
  269. /* Check GUID is a data block */
  270. if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD))
  271. return AE_BAD_ADDRESS;
  272. input.count = 1;
  273. input.pointer = wq_params;
  274. wq_params[0].type = ACPI_TYPE_INTEGER;
  275. wq_params[0].integer.value = instance;
  276. /*
  277. * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method first to
  278. * enable collection.
  279. */
  280. if (block->flags & ACPI_WMI_EXPENSIVE) {
  281. wc_input.count = 1;
  282. wc_input.pointer = wc_params;
  283. wc_params[0].type = ACPI_TYPE_INTEGER;
  284. wc_params[0].integer.value = 1;
  285. strncat(wc_method, block->object_id, 2);
  286. /*
  287. * Some GUIDs break the specification by declaring themselves
  288. * expensive, but have no corresponding WCxx method. So we
  289. * should not fail if this happens.
  290. */
  291. wc_status = acpi_get_handle(handle, wc_method, &wc_handle);
  292. if (ACPI_SUCCESS(wc_status))
  293. wc_status = acpi_evaluate_object(handle, wc_method,
  294. &wc_input, NULL);
  295. }
  296. strcpy(method, "WQ");
  297. strncat(method, block->object_id, 2);
  298. status = acpi_evaluate_object(handle, method, &input, out);
  299. /*
  300. * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method, even if
  301. * the WQxx method failed - we should disable collection anyway.
  302. */
  303. if ((block->flags & ACPI_WMI_EXPENSIVE) && ACPI_SUCCESS(wc_status)) {
  304. wc_params[0].integer.value = 0;
  305. status = acpi_evaluate_object(handle,
  306. wc_method, &wc_input, NULL);
  307. }
  308. return status;
  309. }
  310. EXPORT_SYMBOL_GPL(wmi_query_block);
  311. /**
  312. * wmi_set_block - Write to a WMI block
  313. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  314. * @instance: Instance index
  315. * &in: Buffer containing new values for the data block
  316. *
  317. * Write the contents of the input buffer to an ACPI-WMI data block
  318. */
  319. acpi_status wmi_set_block(const char *guid_string, u8 instance,
  320. const struct acpi_buffer *in)
  321. {
  322. struct guid_block *block = NULL;
  323. struct wmi_block *wblock = NULL;
  324. acpi_handle handle;
  325. struct acpi_object_list input;
  326. union acpi_object params[2];
  327. char method[4] = "WS";
  328. if (!guid_string || !in)
  329. return AE_BAD_DATA;
  330. if (!find_guid(guid_string, &wblock))
  331. return AE_BAD_ADDRESS;
  332. block = &wblock->gblock;
  333. handle = wblock->handle;
  334. if (block->instance_count < instance)
  335. return AE_BAD_PARAMETER;
  336. /* Check GUID is a data block */
  337. if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD))
  338. return AE_BAD_ADDRESS;
  339. input.count = 2;
  340. input.pointer = params;
  341. params[0].type = ACPI_TYPE_INTEGER;
  342. params[0].integer.value = instance;
  343. if (block->flags & ACPI_WMI_STRING) {
  344. params[1].type = ACPI_TYPE_STRING;
  345. } else {
  346. params[1].type = ACPI_TYPE_BUFFER;
  347. }
  348. params[1].buffer.length = in->length;
  349. params[1].buffer.pointer = in->pointer;
  350. strncat(method, block->object_id, 2);
  351. return acpi_evaluate_object(handle, method, &input, NULL);
  352. }
  353. EXPORT_SYMBOL_GPL(wmi_set_block);
  354. /**
  355. * wmi_install_notify_handler - Register handler for WMI events
  356. * @handler: Function to handle notifications
  357. * @data: Data to be returned to handler when event is fired
  358. *
  359. * Register a handler for events sent to the ACPI-WMI mapper device.
  360. */
  361. acpi_status wmi_install_notify_handler(const char *guid,
  362. wmi_notify_handler handler, void *data)
  363. {
  364. struct wmi_block *block;
  365. if (!guid || !handler)
  366. return AE_BAD_PARAMETER;
  367. find_guid(guid, &block);
  368. if (!block)
  369. return AE_NOT_EXIST;
  370. if (block->handler)
  371. return AE_ALREADY_ACQUIRED;
  372. block->handler = handler;
  373. block->handler_data = data;
  374. return AE_OK;
  375. }
  376. EXPORT_SYMBOL_GPL(wmi_install_notify_handler);
  377. /**
  378. * wmi_uninstall_notify_handler - Unregister handler for WMI events
  379. *
  380. * Unregister handler for events sent to the ACPI-WMI mapper device.
  381. */
  382. acpi_status wmi_remove_notify_handler(const char *guid)
  383. {
  384. struct wmi_block *block;
  385. if (!guid)
  386. return AE_BAD_PARAMETER;
  387. find_guid(guid, &block);
  388. if (!block)
  389. return AE_NOT_EXIST;
  390. if (!block->handler)
  391. return AE_NULL_ENTRY;
  392. block->handler = NULL;
  393. block->handler_data = NULL;
  394. return AE_OK;
  395. }
  396. EXPORT_SYMBOL_GPL(wmi_remove_notify_handler);
  397. /**
  398. * wmi_get_event_data - Get WMI data associated with an event
  399. *
  400. * @event - Event to find
  401. * &out - Buffer to hold event data
  402. *
  403. * Returns extra data associated with an event in WMI.
  404. */
  405. acpi_status wmi_get_event_data(u32 event, struct acpi_buffer *out)
  406. {
  407. struct acpi_object_list input;
  408. union acpi_object params[1];
  409. struct guid_block *gblock;
  410. struct wmi_block *wblock;
  411. struct list_head *p;
  412. input.count = 1;
  413. input.pointer = params;
  414. params[0].type = ACPI_TYPE_INTEGER;
  415. params[0].integer.value = event;
  416. list_for_each(p, &wmi_blocks.list) {
  417. wblock = list_entry(p, struct wmi_block, list);
  418. gblock = &wblock->gblock;
  419. if ((gblock->flags & ACPI_WMI_EVENT) &&
  420. (gblock->notify_id == event))
  421. return acpi_evaluate_object(wblock->handle, "_WED",
  422. &input, out);
  423. }
  424. return AE_NOT_FOUND;
  425. }
  426. EXPORT_SYMBOL_GPL(wmi_get_event_data);
  427. /**
  428. * wmi_has_guid - Check if a GUID is available
  429. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  430. *
  431. * Check if a given GUID is defined by _WDG
  432. */
  433. bool wmi_has_guid(const char *guid_string)
  434. {
  435. return find_guid(guid_string, NULL);
  436. }
  437. EXPORT_SYMBOL_GPL(wmi_has_guid);
  438. /*
  439. * Parse the _WDG method for the GUID data blocks
  440. */
  441. static __init acpi_status parse_wdg(acpi_handle handle)
  442. {
  443. struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
  444. union acpi_object *obj;
  445. struct guid_block *gblock;
  446. struct wmi_block *wblock;
  447. acpi_status status;
  448. u32 i, total;
  449. status = acpi_evaluate_object(handle, "_WDG", NULL, &out);
  450. if (ACPI_FAILURE(status))
  451. return status;
  452. obj = (union acpi_object *) out.pointer;
  453. if (obj->type != ACPI_TYPE_BUFFER)
  454. return AE_ERROR;
  455. total = obj->buffer.length / sizeof(struct guid_block);
  456. gblock = kzalloc(obj->buffer.length, GFP_KERNEL);
  457. if (!gblock)
  458. return AE_NO_MEMORY;
  459. memcpy(gblock, obj->buffer.pointer, obj->buffer.length);
  460. for (i = 0; i < total; i++) {
  461. wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
  462. if (!wblock)
  463. return AE_NO_MEMORY;
  464. wblock->gblock = gblock[i];
  465. wblock->handle = handle;
  466. list_add_tail(&wblock->list, &wmi_blocks.list);
  467. }
  468. kfree(out.pointer);
  469. kfree(gblock);
  470. return status;
  471. }
  472. /*
  473. * WMI can have EmbeddedControl access regions. In which case, we just want to
  474. * hand these off to the EC driver.
  475. */
  476. static acpi_status
  477. acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address,
  478. u32 bits, acpi_integer * value,
  479. void *handler_context, void *region_context)
  480. {
  481. int result = 0, i = 0;
  482. u8 temp = 0;
  483. if ((address > 0xFF) || !value)
  484. return AE_BAD_PARAMETER;
  485. if (function != ACPI_READ && function != ACPI_WRITE)
  486. return AE_BAD_PARAMETER;
  487. if (bits != 8)
  488. return AE_BAD_PARAMETER;
  489. if (function == ACPI_READ) {
  490. result = ec_read(address, &temp);
  491. (*value) |= ((acpi_integer)temp) << i;
  492. } else {
  493. temp = 0xff & ((*value) >> i);
  494. result = ec_write(address, temp);
  495. }
  496. switch (result) {
  497. case -EINVAL:
  498. return AE_BAD_PARAMETER;
  499. break;
  500. case -ENODEV:
  501. return AE_NOT_FOUND;
  502. break;
  503. case -ETIME:
  504. return AE_TIME;
  505. break;
  506. default:
  507. return AE_OK;
  508. }
  509. }
  510. static void acpi_wmi_notify(acpi_handle handle, u32 event, void *data)
  511. {
  512. struct guid_block *block;
  513. struct wmi_block *wblock;
  514. struct list_head *p;
  515. struct acpi_device *device = data;
  516. list_for_each(p, &wmi_blocks.list) {
  517. wblock = list_entry(p, struct wmi_block, list);
  518. block = &wblock->gblock;
  519. if ((block->flags & ACPI_WMI_EVENT) &&
  520. (block->notify_id == event)) {
  521. if (wblock->handler)
  522. wblock->handler(event, wblock->handler_data);
  523. acpi_bus_generate_netlink_event(
  524. device->pnp.device_class, device->dev.bus_id,
  525. event, 0);
  526. break;
  527. }
  528. }
  529. }
  530. static int acpi_wmi_remove(struct acpi_device *device, int type)
  531. {
  532. acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  533. acpi_wmi_notify);
  534. acpi_remove_address_space_handler(device->handle,
  535. ACPI_ADR_SPACE_EC, &acpi_wmi_ec_space_handler);
  536. return 0;
  537. }
  538. static int __init acpi_wmi_add(struct acpi_device *device)
  539. {
  540. acpi_status status;
  541. int result = 0;
  542. status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  543. acpi_wmi_notify, device);
  544. if (ACPI_FAILURE(status)) {
  545. printk(KERN_ERR PREFIX "Error installing notify handler\n");
  546. return -ENODEV;
  547. }
  548. status = acpi_install_address_space_handler(device->handle,
  549. ACPI_ADR_SPACE_EC,
  550. &acpi_wmi_ec_space_handler,
  551. NULL, NULL);
  552. if (ACPI_FAILURE(status))
  553. return -ENODEV;
  554. status = parse_wdg(device->handle);
  555. if (ACPI_FAILURE(status)) {
  556. printk(KERN_ERR PREFIX "Error installing EC region handler\n");
  557. return -ENODEV;
  558. }
  559. return result;
  560. }
  561. static int __init acpi_wmi_init(void)
  562. {
  563. acpi_status result;
  564. INIT_LIST_HEAD(&wmi_blocks.list);
  565. if (acpi_disabled)
  566. return -ENODEV;
  567. result = acpi_bus_register_driver(&acpi_wmi_driver);
  568. if (result < 0) {
  569. printk(KERN_INFO PREFIX "Error loading mapper\n");
  570. } else {
  571. printk(KERN_INFO PREFIX "Mapper loaded\n");
  572. }
  573. return result;
  574. }
  575. static void __exit acpi_wmi_exit(void)
  576. {
  577. struct list_head *p, *tmp;
  578. struct wmi_block *wblock;
  579. acpi_bus_unregister_driver(&acpi_wmi_driver);
  580. list_for_each_safe(p, tmp, &wmi_blocks.list) {
  581. wblock = list_entry(p, struct wmi_block, list);
  582. list_del(p);
  583. kfree(wblock);
  584. }
  585. printk(KERN_INFO PREFIX "Mapper unloaded\n");
  586. }
  587. subsys_initcall(acpi_wmi_init);
  588. module_exit(acpi_wmi_exit);