wmi.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ACPI-WMI mapping driver
  4. *
  5. * Copyright (C) 2007-2008 Carlos Corbacho <carlos@strangeworlds.co.uk>
  6. *
  7. * GUID parsing code from ldm.c is:
  8. * Copyright (C) 2001,2002 Richard Russon <ldm@flatcap.org>
  9. * Copyright (c) 2001-2007 Anton Altaparmakov
  10. * Copyright (C) 2001,2002 Jakob Kemi <jakob.kemi@telia.com>
  11. *
  12. * WMI bus infrastructure by Andrew Lutomirski and Darren Hart:
  13. * Copyright (C) 2015 Andrew Lutomirski
  14. * Copyright (C) 2017 VMware, Inc. All Rights Reserved.
  15. */
  16. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/acpi.h>
  18. #include <linux/bits.h>
  19. #include <linux/build_bug.h>
  20. #include <linux/device.h>
  21. #include <linux/init.h>
  22. #include <linux/kernel.h>
  23. #include <linux/list.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/rwsem.h>
  27. #include <linux/slab.h>
  28. #include <linux/sysfs.h>
  29. #include <linux/types.h>
  30. #include <linux/uuid.h>
  31. #include <linux/wmi.h>
  32. #include <linux/fs.h>
  33. MODULE_AUTHOR("Carlos Corbacho");
  34. MODULE_DESCRIPTION("ACPI-WMI Mapping Driver");
  35. MODULE_LICENSE("GPL");
  36. static LIST_HEAD(wmi_block_list);
  37. struct guid_block {
  38. guid_t guid;
  39. union {
  40. char object_id[2];
  41. struct {
  42. unsigned char notify_id;
  43. unsigned char reserved;
  44. };
  45. };
  46. u8 instance_count;
  47. u8 flags;
  48. } __packed;
  49. static_assert(sizeof(typeof_member(struct guid_block, guid)) == 16);
  50. static_assert(sizeof(struct guid_block) == 20);
  51. static_assert(__alignof__(struct guid_block) == 1);
  52. enum { /* wmi_block flags */
  53. WMI_READ_TAKES_NO_ARGS,
  54. WMI_GUID_DUPLICATED,
  55. WMI_NO_EVENT_DATA,
  56. };
  57. struct wmi_block {
  58. struct wmi_device dev;
  59. struct list_head list;
  60. struct guid_block gblock;
  61. struct acpi_device *acpi_device;
  62. struct rw_semaphore notify_lock; /* Protects notify callback add/remove */
  63. wmi_notify_handler handler;
  64. void *handler_data;
  65. bool driver_ready;
  66. unsigned long flags;
  67. };
  68. /*
  69. * If the GUID data block is marked as expensive, we must enable and
  70. * explicitily disable data collection.
  71. */
  72. #define ACPI_WMI_EXPENSIVE BIT(0)
  73. #define ACPI_WMI_METHOD BIT(1) /* GUID is a method */
  74. #define ACPI_WMI_STRING BIT(2) /* GUID takes & returns a string */
  75. #define ACPI_WMI_EVENT BIT(3) /* GUID is an event */
  76. static const struct acpi_device_id wmi_device_ids[] = {
  77. {"PNP0C14", 0},
  78. {"pnp0c14", 0},
  79. { }
  80. };
  81. MODULE_DEVICE_TABLE(acpi, wmi_device_ids);
  82. #define dev_to_wblock(__dev) container_of_const(__dev, struct wmi_block, dev.dev)
  83. #define dev_to_wdev(__dev) container_of_const(__dev, struct wmi_device, dev)
  84. /*
  85. * GUID parsing functions
  86. */
  87. static bool guid_parse_and_compare(const char *string, const guid_t *guid)
  88. {
  89. guid_t guid_input;
  90. if (guid_parse(string, &guid_input))
  91. return false;
  92. return guid_equal(&guid_input, guid);
  93. }
  94. static const void *find_guid_context(struct wmi_block *wblock,
  95. struct wmi_driver *wdriver)
  96. {
  97. const struct wmi_device_id *id;
  98. id = wdriver->id_table;
  99. if (!id)
  100. return NULL;
  101. while (*id->guid_string) {
  102. if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid))
  103. return id->context;
  104. id++;
  105. }
  106. return NULL;
  107. }
  108. static acpi_status wmi_method_enable(struct wmi_block *wblock, bool enable)
  109. {
  110. struct guid_block *block;
  111. char method[5];
  112. acpi_status status;
  113. acpi_handle handle;
  114. block = &wblock->gblock;
  115. handle = wblock->acpi_device->handle;
  116. snprintf(method, 5, "WE%02X", block->notify_id);
  117. status = acpi_execute_simple_method(handle, method, enable);
  118. if (status == AE_NOT_FOUND)
  119. return AE_OK;
  120. return status;
  121. }
  122. #define WMI_ACPI_METHOD_NAME_SIZE 5
  123. static inline void get_acpi_method_name(const struct wmi_block *wblock,
  124. const char method,
  125. char buffer[static WMI_ACPI_METHOD_NAME_SIZE])
  126. {
  127. static_assert(ARRAY_SIZE(wblock->gblock.object_id) == 2);
  128. static_assert(WMI_ACPI_METHOD_NAME_SIZE >= 5);
  129. buffer[0] = 'W';
  130. buffer[1] = method;
  131. buffer[2] = wblock->gblock.object_id[0];
  132. buffer[3] = wblock->gblock.object_id[1];
  133. buffer[4] = '\0';
  134. }
  135. static inline acpi_object_type get_param_acpi_type(const struct wmi_block *wblock)
  136. {
  137. if (wblock->gblock.flags & ACPI_WMI_STRING)
  138. return ACPI_TYPE_STRING;
  139. else
  140. return ACPI_TYPE_BUFFER;
  141. }
  142. static int wmidev_match_guid(struct device *dev, const void *data)
  143. {
  144. struct wmi_block *wblock = dev_to_wblock(dev);
  145. const guid_t *guid = data;
  146. /* Legacy GUID-based functions are restricted to only see
  147. * a single WMI device for each GUID.
  148. */
  149. if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags))
  150. return 0;
  151. if (guid_equal(guid, &wblock->gblock.guid))
  152. return 1;
  153. return 0;
  154. }
  155. static const struct bus_type wmi_bus_type;
  156. static struct wmi_device *wmi_find_device_by_guid(const char *guid_string)
  157. {
  158. struct device *dev;
  159. guid_t guid;
  160. int ret;
  161. ret = guid_parse(guid_string, &guid);
  162. if (ret < 0)
  163. return ERR_PTR(ret);
  164. dev = bus_find_device(&wmi_bus_type, NULL, &guid, wmidev_match_guid);
  165. if (!dev)
  166. return ERR_PTR(-ENODEV);
  167. return dev_to_wdev(dev);
  168. }
  169. static void wmi_device_put(struct wmi_device *wdev)
  170. {
  171. put_device(&wdev->dev);
  172. }
  173. /*
  174. * Exported WMI functions
  175. */
  176. /**
  177. * wmi_instance_count - Get number of WMI object instances
  178. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  179. *
  180. * Get the number of WMI object instances.
  181. *
  182. * Returns: Number of WMI object instances or negative error code.
  183. */
  184. int wmi_instance_count(const char *guid_string)
  185. {
  186. struct wmi_device *wdev;
  187. int ret;
  188. wdev = wmi_find_device_by_guid(guid_string);
  189. if (IS_ERR(wdev))
  190. return PTR_ERR(wdev);
  191. ret = wmidev_instance_count(wdev);
  192. wmi_device_put(wdev);
  193. return ret;
  194. }
  195. EXPORT_SYMBOL_GPL(wmi_instance_count);
  196. /**
  197. * wmidev_instance_count - Get number of WMI object instances
  198. * @wdev: A wmi bus device from a driver
  199. *
  200. * Get the number of WMI object instances.
  201. *
  202. * Returns: Number of WMI object instances.
  203. */
  204. u8 wmidev_instance_count(struct wmi_device *wdev)
  205. {
  206. struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev);
  207. return wblock->gblock.instance_count;
  208. }
  209. EXPORT_SYMBOL_GPL(wmidev_instance_count);
  210. /**
  211. * wmi_evaluate_method - Evaluate a WMI method (deprecated)
  212. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  213. * @instance: Instance index
  214. * @method_id: Method ID to call
  215. * @in: Mandatory buffer containing input for the method call
  216. * @out: Empty buffer to return the method results
  217. *
  218. * Call an ACPI-WMI method, the caller must free @out.
  219. *
  220. * Return: acpi_status signaling success or error.
  221. */
  222. acpi_status wmi_evaluate_method(const char *guid_string, u8 instance, u32 method_id,
  223. const struct acpi_buffer *in, struct acpi_buffer *out)
  224. {
  225. struct wmi_device *wdev;
  226. acpi_status status;
  227. wdev = wmi_find_device_by_guid(guid_string);
  228. if (IS_ERR(wdev))
  229. return AE_ERROR;
  230. status = wmidev_evaluate_method(wdev, instance, method_id, in, out);
  231. wmi_device_put(wdev);
  232. return status;
  233. }
  234. EXPORT_SYMBOL_GPL(wmi_evaluate_method);
  235. /**
  236. * wmidev_evaluate_method - Evaluate a WMI method
  237. * @wdev: A wmi bus device from a driver
  238. * @instance: Instance index
  239. * @method_id: Method ID to call
  240. * @in: Mandatory buffer containing input for the method call
  241. * @out: Empty buffer to return the method results
  242. *
  243. * Call an ACPI-WMI method, the caller must free @out.
  244. *
  245. * Return: acpi_status signaling success or error.
  246. */
  247. acpi_status wmidev_evaluate_method(struct wmi_device *wdev, u8 instance, u32 method_id,
  248. const struct acpi_buffer *in, struct acpi_buffer *out)
  249. {
  250. struct guid_block *block;
  251. struct wmi_block *wblock;
  252. acpi_handle handle;
  253. struct acpi_object_list input;
  254. union acpi_object params[3];
  255. char method[WMI_ACPI_METHOD_NAME_SIZE];
  256. wblock = container_of(wdev, struct wmi_block, dev);
  257. block = &wblock->gblock;
  258. handle = wblock->acpi_device->handle;
  259. if (!in)
  260. return AE_BAD_DATA;
  261. if (!(block->flags & ACPI_WMI_METHOD))
  262. return AE_BAD_DATA;
  263. if (block->instance_count <= instance)
  264. return AE_BAD_PARAMETER;
  265. input.count = 3;
  266. input.pointer = params;
  267. params[0].type = ACPI_TYPE_INTEGER;
  268. params[0].integer.value = instance;
  269. params[1].type = ACPI_TYPE_INTEGER;
  270. params[1].integer.value = method_id;
  271. params[2].type = get_param_acpi_type(wblock);
  272. params[2].buffer.length = in->length;
  273. params[2].buffer.pointer = in->pointer;
  274. get_acpi_method_name(wblock, 'M', method);
  275. return acpi_evaluate_object(handle, method, &input, out);
  276. }
  277. EXPORT_SYMBOL_GPL(wmidev_evaluate_method);
  278. static acpi_status __query_block(struct wmi_block *wblock, u8 instance,
  279. struct acpi_buffer *out)
  280. {
  281. struct guid_block *block;
  282. acpi_handle handle;
  283. acpi_status status, wc_status = AE_ERROR;
  284. struct acpi_object_list input;
  285. union acpi_object wq_params[1];
  286. char wc_method[WMI_ACPI_METHOD_NAME_SIZE];
  287. char method[WMI_ACPI_METHOD_NAME_SIZE];
  288. if (!out)
  289. return AE_BAD_PARAMETER;
  290. block = &wblock->gblock;
  291. handle = wblock->acpi_device->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. if (instance == 0 && test_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags))
  302. input.count = 0;
  303. /*
  304. * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method first to
  305. * enable collection.
  306. */
  307. if (block->flags & ACPI_WMI_EXPENSIVE) {
  308. get_acpi_method_name(wblock, 'C', wc_method);
  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_execute_simple_method(handle, wc_method, 1);
  315. }
  316. get_acpi_method_name(wblock, 'Q', method);
  317. status = acpi_evaluate_object(handle, method, &input, out);
  318. /*
  319. * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method, even if
  320. * the WQxx method failed - we should disable collection anyway.
  321. */
  322. if ((block->flags & ACPI_WMI_EXPENSIVE) && ACPI_SUCCESS(wc_status)) {
  323. /*
  324. * Ignore whether this WCxx call succeeds or not since
  325. * the previously executed WQxx method call might have
  326. * succeeded, and returning the failing status code
  327. * of this call would throw away the result of the WQxx
  328. * call, potentially leaking memory.
  329. */
  330. acpi_execute_simple_method(handle, wc_method, 0);
  331. }
  332. return status;
  333. }
  334. /**
  335. * wmi_query_block - Return contents of a WMI block (deprecated)
  336. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  337. * @instance: Instance index
  338. * @out: Empty buffer to return the contents of the data block to
  339. *
  340. * Query a ACPI-WMI block, the caller must free @out.
  341. *
  342. * Return: ACPI object containing the content of the WMI block.
  343. */
  344. acpi_status wmi_query_block(const char *guid_string, u8 instance,
  345. struct acpi_buffer *out)
  346. {
  347. struct wmi_block *wblock;
  348. struct wmi_device *wdev;
  349. acpi_status status;
  350. wdev = wmi_find_device_by_guid(guid_string);
  351. if (IS_ERR(wdev))
  352. return AE_ERROR;
  353. wblock = container_of(wdev, struct wmi_block, dev);
  354. status = __query_block(wblock, instance, out);
  355. wmi_device_put(wdev);
  356. return status;
  357. }
  358. EXPORT_SYMBOL_GPL(wmi_query_block);
  359. /**
  360. * wmidev_block_query - Return contents of a WMI block
  361. * @wdev: A wmi bus device from a driver
  362. * @instance: Instance index
  363. *
  364. * Query an ACPI-WMI block, the caller must free the result.
  365. *
  366. * Return: ACPI object containing the content of the WMI block.
  367. */
  368. union acpi_object *wmidev_block_query(struct wmi_device *wdev, u8 instance)
  369. {
  370. struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
  371. struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev);
  372. if (ACPI_FAILURE(__query_block(wblock, instance, &out)))
  373. return NULL;
  374. return out.pointer;
  375. }
  376. EXPORT_SYMBOL_GPL(wmidev_block_query);
  377. /**
  378. * wmi_set_block - Write to a WMI block (deprecated)
  379. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  380. * @instance: Instance index
  381. * @in: Buffer containing new values for the data block
  382. *
  383. * Write the contents of the input buffer to an ACPI-WMI data block.
  384. *
  385. * Return: acpi_status signaling success or error.
  386. */
  387. acpi_status wmi_set_block(const char *guid_string, u8 instance, const struct acpi_buffer *in)
  388. {
  389. struct wmi_device *wdev;
  390. acpi_status status;
  391. wdev = wmi_find_device_by_guid(guid_string);
  392. if (IS_ERR(wdev))
  393. return AE_ERROR;
  394. status = wmidev_block_set(wdev, instance, in);
  395. wmi_device_put(wdev);
  396. return status;
  397. }
  398. EXPORT_SYMBOL_GPL(wmi_set_block);
  399. /**
  400. * wmidev_block_set - Write to a WMI block
  401. * @wdev: A wmi bus device from a driver
  402. * @instance: Instance index
  403. * @in: Buffer containing new values for the data block
  404. *
  405. * Write contents of the input buffer to an ACPI-WMI data block.
  406. *
  407. * Return: acpi_status signaling success or error.
  408. */
  409. acpi_status wmidev_block_set(struct wmi_device *wdev, u8 instance, const struct acpi_buffer *in)
  410. {
  411. struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev);
  412. acpi_handle handle = wblock->acpi_device->handle;
  413. struct guid_block *block = &wblock->gblock;
  414. char method[WMI_ACPI_METHOD_NAME_SIZE];
  415. struct acpi_object_list input;
  416. union acpi_object params[2];
  417. if (!in)
  418. return AE_BAD_DATA;
  419. if (block->instance_count <= instance)
  420. return AE_BAD_PARAMETER;
  421. /* Check GUID is a data block */
  422. if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD))
  423. return AE_ERROR;
  424. input.count = 2;
  425. input.pointer = params;
  426. params[0].type = ACPI_TYPE_INTEGER;
  427. params[0].integer.value = instance;
  428. params[1].type = get_param_acpi_type(wblock);
  429. params[1].buffer.length = in->length;
  430. params[1].buffer.pointer = in->pointer;
  431. get_acpi_method_name(wblock, 'S', method);
  432. return acpi_evaluate_object(handle, method, &input, NULL);
  433. }
  434. EXPORT_SYMBOL_GPL(wmidev_block_set);
  435. /**
  436. * wmi_install_notify_handler - Register handler for WMI events (deprecated)
  437. * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  438. * @handler: Function to handle notifications
  439. * @data: Data to be returned to handler when event is fired
  440. *
  441. * Register a handler for events sent to the ACPI-WMI mapper device.
  442. *
  443. * Return: acpi_status signaling success or error.
  444. */
  445. acpi_status wmi_install_notify_handler(const char *guid,
  446. wmi_notify_handler handler,
  447. void *data)
  448. {
  449. struct wmi_block *wblock;
  450. struct wmi_device *wdev;
  451. acpi_status status;
  452. wdev = wmi_find_device_by_guid(guid);
  453. if (IS_ERR(wdev))
  454. return AE_ERROR;
  455. wblock = container_of(wdev, struct wmi_block, dev);
  456. down_write(&wblock->notify_lock);
  457. if (wblock->handler) {
  458. status = AE_ALREADY_ACQUIRED;
  459. } else {
  460. wblock->handler = handler;
  461. wblock->handler_data = data;
  462. if (ACPI_FAILURE(wmi_method_enable(wblock, true)))
  463. dev_warn(&wblock->dev.dev, "Failed to enable device\n");
  464. status = AE_OK;
  465. }
  466. up_write(&wblock->notify_lock);
  467. wmi_device_put(wdev);
  468. return status;
  469. }
  470. EXPORT_SYMBOL_GPL(wmi_install_notify_handler);
  471. /**
  472. * wmi_remove_notify_handler - Unregister handler for WMI events (deprecated)
  473. * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  474. *
  475. * Unregister handler for events sent to the ACPI-WMI mapper device.
  476. *
  477. * Return: acpi_status signaling success or error.
  478. */
  479. acpi_status wmi_remove_notify_handler(const char *guid)
  480. {
  481. struct wmi_block *wblock;
  482. struct wmi_device *wdev;
  483. acpi_status status;
  484. wdev = wmi_find_device_by_guid(guid);
  485. if (IS_ERR(wdev))
  486. return AE_ERROR;
  487. wblock = container_of(wdev, struct wmi_block, dev);
  488. down_write(&wblock->notify_lock);
  489. if (!wblock->handler) {
  490. status = AE_NULL_ENTRY;
  491. } else {
  492. if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
  493. dev_warn(&wblock->dev.dev, "Failed to disable device\n");
  494. wblock->handler = NULL;
  495. wblock->handler_data = NULL;
  496. status = AE_OK;
  497. }
  498. up_write(&wblock->notify_lock);
  499. wmi_device_put(wdev);
  500. return status;
  501. }
  502. EXPORT_SYMBOL_GPL(wmi_remove_notify_handler);
  503. /**
  504. * wmi_has_guid - Check if a GUID is available
  505. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  506. *
  507. * Check if a given GUID is defined by _WDG.
  508. *
  509. * Return: True if GUID is available, false otherwise.
  510. */
  511. bool wmi_has_guid(const char *guid_string)
  512. {
  513. struct wmi_device *wdev;
  514. wdev = wmi_find_device_by_guid(guid_string);
  515. if (IS_ERR(wdev))
  516. return false;
  517. wmi_device_put(wdev);
  518. return true;
  519. }
  520. EXPORT_SYMBOL_GPL(wmi_has_guid);
  521. /**
  522. * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID (deprecated)
  523. * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
  524. *
  525. * Find the _UID of ACPI device associated with this WMI GUID.
  526. *
  527. * Return: The ACPI _UID field value or NULL if the WMI GUID was not found.
  528. */
  529. char *wmi_get_acpi_device_uid(const char *guid_string)
  530. {
  531. struct wmi_block *wblock;
  532. struct wmi_device *wdev;
  533. char *uid;
  534. wdev = wmi_find_device_by_guid(guid_string);
  535. if (IS_ERR(wdev))
  536. return NULL;
  537. wblock = container_of(wdev, struct wmi_block, dev);
  538. uid = acpi_device_uid(wblock->acpi_device);
  539. wmi_device_put(wdev);
  540. return uid;
  541. }
  542. EXPORT_SYMBOL_GPL(wmi_get_acpi_device_uid);
  543. #define drv_to_wdrv(__drv) container_of_const(__drv, struct wmi_driver, driver)
  544. /*
  545. * sysfs interface
  546. */
  547. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
  548. char *buf)
  549. {
  550. struct wmi_block *wblock = dev_to_wblock(dev);
  551. return sysfs_emit(buf, "wmi:%pUL\n", &wblock->gblock.guid);
  552. }
  553. static DEVICE_ATTR_RO(modalias);
  554. static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
  555. char *buf)
  556. {
  557. struct wmi_block *wblock = dev_to_wblock(dev);
  558. return sysfs_emit(buf, "%pUL\n", &wblock->gblock.guid);
  559. }
  560. static DEVICE_ATTR_RO(guid);
  561. static ssize_t instance_count_show(struct device *dev,
  562. struct device_attribute *attr, char *buf)
  563. {
  564. struct wmi_block *wblock = dev_to_wblock(dev);
  565. return sysfs_emit(buf, "%d\n", (int)wblock->gblock.instance_count);
  566. }
  567. static DEVICE_ATTR_RO(instance_count);
  568. static ssize_t expensive_show(struct device *dev,
  569. struct device_attribute *attr, char *buf)
  570. {
  571. struct wmi_block *wblock = dev_to_wblock(dev);
  572. return sysfs_emit(buf, "%d\n",
  573. (wblock->gblock.flags & ACPI_WMI_EXPENSIVE) != 0);
  574. }
  575. static DEVICE_ATTR_RO(expensive);
  576. static ssize_t driver_override_show(struct device *dev, struct device_attribute *attr,
  577. char *buf)
  578. {
  579. struct wmi_device *wdev = to_wmi_device(dev);
  580. ssize_t ret;
  581. device_lock(dev);
  582. ret = sysfs_emit(buf, "%s\n", wdev->driver_override);
  583. device_unlock(dev);
  584. return ret;
  585. }
  586. static ssize_t driver_override_store(struct device *dev, struct device_attribute *attr,
  587. const char *buf, size_t count)
  588. {
  589. struct wmi_device *wdev = to_wmi_device(dev);
  590. int ret;
  591. ret = driver_set_override(dev, &wdev->driver_override, buf, count);
  592. if (ret < 0)
  593. return ret;
  594. return count;
  595. }
  596. static DEVICE_ATTR_RW(driver_override);
  597. static struct attribute *wmi_attrs[] = {
  598. &dev_attr_modalias.attr,
  599. &dev_attr_guid.attr,
  600. &dev_attr_instance_count.attr,
  601. &dev_attr_expensive.attr,
  602. &dev_attr_driver_override.attr,
  603. NULL
  604. };
  605. ATTRIBUTE_GROUPS(wmi);
  606. static ssize_t notify_id_show(struct device *dev, struct device_attribute *attr,
  607. char *buf)
  608. {
  609. struct wmi_block *wblock = dev_to_wblock(dev);
  610. return sysfs_emit(buf, "%02X\n", (unsigned int)wblock->gblock.notify_id);
  611. }
  612. static DEVICE_ATTR_RO(notify_id);
  613. static struct attribute *wmi_event_attrs[] = {
  614. &dev_attr_notify_id.attr,
  615. NULL
  616. };
  617. ATTRIBUTE_GROUPS(wmi_event);
  618. static ssize_t object_id_show(struct device *dev, struct device_attribute *attr,
  619. char *buf)
  620. {
  621. struct wmi_block *wblock = dev_to_wblock(dev);
  622. return sysfs_emit(buf, "%c%c\n", wblock->gblock.object_id[0],
  623. wblock->gblock.object_id[1]);
  624. }
  625. static DEVICE_ATTR_RO(object_id);
  626. static ssize_t setable_show(struct device *dev, struct device_attribute *attr,
  627. char *buf)
  628. {
  629. struct wmi_device *wdev = dev_to_wdev(dev);
  630. return sysfs_emit(buf, "%d\n", (int)wdev->setable);
  631. }
  632. static DEVICE_ATTR_RO(setable);
  633. static struct attribute *wmi_data_attrs[] = {
  634. &dev_attr_object_id.attr,
  635. &dev_attr_setable.attr,
  636. NULL
  637. };
  638. ATTRIBUTE_GROUPS(wmi_data);
  639. static struct attribute *wmi_method_attrs[] = {
  640. &dev_attr_object_id.attr,
  641. NULL
  642. };
  643. ATTRIBUTE_GROUPS(wmi_method);
  644. static int wmi_dev_uevent(const struct device *dev, struct kobj_uevent_env *env)
  645. {
  646. const struct wmi_block *wblock = dev_to_wblock(dev);
  647. if (add_uevent_var(env, "MODALIAS=wmi:%pUL", &wblock->gblock.guid))
  648. return -ENOMEM;
  649. if (add_uevent_var(env, "WMI_GUID=%pUL", &wblock->gblock.guid))
  650. return -ENOMEM;
  651. return 0;
  652. }
  653. static void wmi_dev_release(struct device *dev)
  654. {
  655. struct wmi_block *wblock = dev_to_wblock(dev);
  656. kfree(wblock->dev.driver_override);
  657. kfree(wblock);
  658. }
  659. static int wmi_dev_match(struct device *dev, const struct device_driver *driver)
  660. {
  661. const struct wmi_driver *wmi_driver = drv_to_wdrv(driver);
  662. struct wmi_block *wblock = dev_to_wblock(dev);
  663. const struct wmi_device_id *id = wmi_driver->id_table;
  664. /* When driver_override is set, only bind to the matching driver */
  665. if (wblock->dev.driver_override)
  666. return !strcmp(wblock->dev.driver_override, driver->name);
  667. if (id == NULL)
  668. return 0;
  669. while (*id->guid_string) {
  670. if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid))
  671. return 1;
  672. id++;
  673. }
  674. return 0;
  675. }
  676. static int wmi_dev_probe(struct device *dev)
  677. {
  678. struct wmi_block *wblock = dev_to_wblock(dev);
  679. struct wmi_driver *wdriver = drv_to_wdrv(dev->driver);
  680. int ret = 0;
  681. /* Some older WMI drivers will break if instantiated multiple times,
  682. * so they are blocked from probing WMI devices with a duplicated GUID.
  683. *
  684. * New WMI drivers should support being instantiated multiple times.
  685. */
  686. if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) {
  687. dev_warn(dev, "Legacy driver %s cannot be instantiated multiple times\n",
  688. dev->driver->name);
  689. return -ENODEV;
  690. }
  691. if (wdriver->notify) {
  692. if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data)
  693. return -ENODEV;
  694. }
  695. if (ACPI_FAILURE(wmi_method_enable(wblock, true)))
  696. dev_warn(dev, "failed to enable device -- probing anyway\n");
  697. if (wdriver->probe) {
  698. ret = wdriver->probe(dev_to_wdev(dev),
  699. find_guid_context(wblock, wdriver));
  700. if (ret) {
  701. if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
  702. dev_warn(dev, "Failed to disable device\n");
  703. return ret;
  704. }
  705. }
  706. down_write(&wblock->notify_lock);
  707. wblock->driver_ready = true;
  708. up_write(&wblock->notify_lock);
  709. return 0;
  710. }
  711. static void wmi_dev_remove(struct device *dev)
  712. {
  713. struct wmi_block *wblock = dev_to_wblock(dev);
  714. struct wmi_driver *wdriver = drv_to_wdrv(dev->driver);
  715. down_write(&wblock->notify_lock);
  716. wblock->driver_ready = false;
  717. up_write(&wblock->notify_lock);
  718. if (wdriver->remove)
  719. wdriver->remove(dev_to_wdev(dev));
  720. if (ACPI_FAILURE(wmi_method_enable(wblock, false)))
  721. dev_warn(dev, "failed to disable device\n");
  722. }
  723. static struct class wmi_bus_class = {
  724. .name = "wmi_bus",
  725. };
  726. static const struct bus_type wmi_bus_type = {
  727. .name = "wmi",
  728. .dev_groups = wmi_groups,
  729. .match = wmi_dev_match,
  730. .uevent = wmi_dev_uevent,
  731. .probe = wmi_dev_probe,
  732. .remove = wmi_dev_remove,
  733. };
  734. static const struct device_type wmi_type_event = {
  735. .name = "event",
  736. .groups = wmi_event_groups,
  737. .release = wmi_dev_release,
  738. };
  739. static const struct device_type wmi_type_method = {
  740. .name = "method",
  741. .groups = wmi_method_groups,
  742. .release = wmi_dev_release,
  743. };
  744. static const struct device_type wmi_type_data = {
  745. .name = "data",
  746. .groups = wmi_data_groups,
  747. .release = wmi_dev_release,
  748. };
  749. /*
  750. * _WDG is a static list that is only parsed at startup,
  751. * so it's safe to count entries without extra protection.
  752. */
  753. static int guid_count(const guid_t *guid)
  754. {
  755. struct wmi_block *wblock;
  756. int count = 0;
  757. list_for_each_entry(wblock, &wmi_block_list, list) {
  758. if (guid_equal(&wblock->gblock.guid, guid))
  759. count++;
  760. }
  761. return count;
  762. }
  763. static int wmi_create_device(struct device *wmi_bus_dev,
  764. struct wmi_block *wblock,
  765. struct acpi_device *device)
  766. {
  767. char method[WMI_ACPI_METHOD_NAME_SIZE];
  768. struct acpi_device_info *info;
  769. acpi_handle method_handle;
  770. acpi_status status;
  771. uint count;
  772. if (wblock->gblock.flags & ACPI_WMI_EVENT) {
  773. wblock->dev.dev.type = &wmi_type_event;
  774. goto out_init;
  775. }
  776. if (wblock->gblock.flags & ACPI_WMI_METHOD) {
  777. get_acpi_method_name(wblock, 'M', method);
  778. if (!acpi_has_method(device->handle, method)) {
  779. dev_warn(wmi_bus_dev,
  780. FW_BUG "%s method block execution control method not found\n",
  781. method);
  782. return -ENXIO;
  783. }
  784. wblock->dev.dev.type = &wmi_type_method;
  785. goto out_init;
  786. }
  787. /*
  788. * Data Block Query Control Method (WQxx by convention) is
  789. * required per the WMI documentation. If it is not present,
  790. * we ignore this data block.
  791. */
  792. get_acpi_method_name(wblock, 'Q', method);
  793. status = acpi_get_handle(device->handle, method, &method_handle);
  794. if (ACPI_FAILURE(status)) {
  795. dev_warn(wmi_bus_dev,
  796. FW_BUG "%s data block query control method not found\n",
  797. method);
  798. return -ENXIO;
  799. }
  800. status = acpi_get_object_info(method_handle, &info);
  801. if (ACPI_FAILURE(status))
  802. return -EIO;
  803. wblock->dev.dev.type = &wmi_type_data;
  804. /*
  805. * The Microsoft documentation specifically states:
  806. *
  807. * Data blocks registered with only a single instance
  808. * can ignore the parameter.
  809. *
  810. * ACPICA will get mad at us if we call the method with the wrong number
  811. * of arguments, so check what our method expects. (On some Dell
  812. * laptops, WQxx may not be a method at all.)
  813. */
  814. if (info->type != ACPI_TYPE_METHOD || info->param_count == 0)
  815. set_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags);
  816. kfree(info);
  817. get_acpi_method_name(wblock, 'S', method);
  818. if (acpi_has_method(device->handle, method))
  819. wblock->dev.setable = true;
  820. out_init:
  821. init_rwsem(&wblock->notify_lock);
  822. wblock->driver_ready = false;
  823. wblock->dev.dev.bus = &wmi_bus_type;
  824. wblock->dev.dev.parent = wmi_bus_dev;
  825. count = guid_count(&wblock->gblock.guid);
  826. if (count) {
  827. dev_set_name(&wblock->dev.dev, "%pUL-%d", &wblock->gblock.guid, count);
  828. set_bit(WMI_GUID_DUPLICATED, &wblock->flags);
  829. } else {
  830. dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid);
  831. }
  832. device_initialize(&wblock->dev.dev);
  833. return 0;
  834. }
  835. static int wmi_add_device(struct platform_device *pdev, struct wmi_device *wdev)
  836. {
  837. struct device_link *link;
  838. /*
  839. * Many aggregate WMI drivers do not use -EPROBE_DEFER when they
  840. * are unable to find a WMI device during probe, instead they require
  841. * all WMI devices associated with an platform device to become available
  842. * at once. This device link thus prevents WMI drivers from probing until
  843. * the associated platform device has finished probing (and has registered
  844. * all discovered WMI devices).
  845. */
  846. link = device_link_add(&wdev->dev, &pdev->dev, DL_FLAG_AUTOREMOVE_SUPPLIER);
  847. if (!link)
  848. return -EINVAL;
  849. return device_add(&wdev->dev);
  850. }
  851. /*
  852. * Parse the _WDG method for the GUID data blocks
  853. */
  854. static int parse_wdg(struct device *wmi_bus_dev, struct platform_device *pdev)
  855. {
  856. struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
  857. struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
  858. const struct guid_block *gblock;
  859. bool event_data_available;
  860. struct wmi_block *wblock;
  861. union acpi_object *obj;
  862. acpi_status status;
  863. u32 i, total;
  864. int retval;
  865. status = acpi_evaluate_object(device->handle, "_WDG", NULL, &out);
  866. if (ACPI_FAILURE(status))
  867. return -ENXIO;
  868. obj = out.pointer;
  869. if (!obj)
  870. return -ENXIO;
  871. if (obj->type != ACPI_TYPE_BUFFER) {
  872. kfree(obj);
  873. return -ENXIO;
  874. }
  875. event_data_available = acpi_has_method(device->handle, "_WED");
  876. gblock = (const struct guid_block *)obj->buffer.pointer;
  877. total = obj->buffer.length / sizeof(struct guid_block);
  878. for (i = 0; i < total; i++) {
  879. if (!gblock[i].instance_count) {
  880. dev_info(wmi_bus_dev, FW_INFO "%pUL has zero instances\n", &gblock[i].guid);
  881. continue;
  882. }
  883. wblock = kzalloc(sizeof(*wblock), GFP_KERNEL);
  884. if (!wblock)
  885. continue;
  886. wblock->acpi_device = device;
  887. wblock->gblock = gblock[i];
  888. if (gblock[i].flags & ACPI_WMI_EVENT && !event_data_available)
  889. set_bit(WMI_NO_EVENT_DATA, &wblock->flags);
  890. retval = wmi_create_device(wmi_bus_dev, wblock, device);
  891. if (retval) {
  892. kfree(wblock);
  893. continue;
  894. }
  895. list_add_tail(&wblock->list, &wmi_block_list);
  896. retval = wmi_add_device(pdev, &wblock->dev);
  897. if (retval) {
  898. dev_err(wmi_bus_dev, "failed to register %pUL\n",
  899. &wblock->gblock.guid);
  900. list_del(&wblock->list);
  901. put_device(&wblock->dev.dev);
  902. }
  903. }
  904. kfree(obj);
  905. return 0;
  906. }
  907. static int wmi_get_notify_data(struct wmi_block *wblock, union acpi_object **obj)
  908. {
  909. struct acpi_buffer data = { ACPI_ALLOCATE_BUFFER, NULL };
  910. union acpi_object param = {
  911. .integer = {
  912. .type = ACPI_TYPE_INTEGER,
  913. .value = wblock->gblock.notify_id,
  914. }
  915. };
  916. struct acpi_object_list input = {
  917. .count = 1,
  918. .pointer = &param,
  919. };
  920. acpi_status status;
  921. status = acpi_evaluate_object(wblock->acpi_device->handle, "_WED", &input, &data);
  922. if (ACPI_FAILURE(status)) {
  923. dev_warn(&wblock->dev.dev, "Failed to get event data\n");
  924. return -EIO;
  925. }
  926. *obj = data.pointer;
  927. return 0;
  928. }
  929. static void wmi_notify_driver(struct wmi_block *wblock, union acpi_object *obj)
  930. {
  931. struct wmi_driver *driver = drv_to_wdrv(wblock->dev.dev.driver);
  932. if (!obj && !driver->no_notify_data) {
  933. dev_warn(&wblock->dev.dev, "Event contains no event data\n");
  934. return;
  935. }
  936. if (driver->notify)
  937. driver->notify(&wblock->dev, obj);
  938. }
  939. static int wmi_notify_device(struct device *dev, void *data)
  940. {
  941. struct wmi_block *wblock = dev_to_wblock(dev);
  942. union acpi_object *obj = NULL;
  943. u32 *event = data;
  944. int ret;
  945. if (!(wblock->gblock.flags & ACPI_WMI_EVENT && wblock->gblock.notify_id == *event))
  946. return 0;
  947. /* The ACPI WMI specification says that _WED should be
  948. * evaluated every time an notification is received, even
  949. * if no consumers are present.
  950. *
  951. * Some firmware implementations actually depend on this
  952. * by using a queue for events which will fill up if the
  953. * WMI driver core stops evaluating _WED due to missing
  954. * WMI event consumers.
  955. */
  956. if (!test_bit(WMI_NO_EVENT_DATA, &wblock->flags)) {
  957. ret = wmi_get_notify_data(wblock, &obj);
  958. if (ret < 0)
  959. return -EIO;
  960. }
  961. down_read(&wblock->notify_lock);
  962. if (wblock->dev.dev.driver && wblock->driver_ready)
  963. wmi_notify_driver(wblock, obj);
  964. if (wblock->handler)
  965. wblock->handler(obj, wblock->handler_data);
  966. up_read(&wblock->notify_lock);
  967. kfree(obj);
  968. acpi_bus_generate_netlink_event("wmi", acpi_dev_name(wblock->acpi_device), *event, 0);
  969. return -EBUSY;
  970. }
  971. static void acpi_wmi_notify_handler(acpi_handle handle, u32 event, void *context)
  972. {
  973. struct device *wmi_bus_dev = context;
  974. device_for_each_child(wmi_bus_dev, &event, wmi_notify_device);
  975. }
  976. static int wmi_remove_device(struct device *dev, void *data)
  977. {
  978. struct wmi_block *wblock = dev_to_wblock(dev);
  979. list_del(&wblock->list);
  980. device_unregister(dev);
  981. return 0;
  982. }
  983. static void acpi_wmi_remove(struct platform_device *device)
  984. {
  985. struct device *wmi_bus_device = dev_get_drvdata(&device->dev);
  986. device_for_each_child_reverse(wmi_bus_device, NULL, wmi_remove_device);
  987. }
  988. static void acpi_wmi_remove_notify_handler(void *data)
  989. {
  990. struct acpi_device *acpi_device = data;
  991. acpi_remove_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, acpi_wmi_notify_handler);
  992. }
  993. static void acpi_wmi_remove_bus_device(void *data)
  994. {
  995. struct device *wmi_bus_dev = data;
  996. device_unregister(wmi_bus_dev);
  997. }
  998. static int acpi_wmi_probe(struct platform_device *device)
  999. {
  1000. struct acpi_device *acpi_device;
  1001. struct device *wmi_bus_dev;
  1002. acpi_status status;
  1003. int error;
  1004. acpi_device = ACPI_COMPANION(&device->dev);
  1005. if (!acpi_device) {
  1006. dev_err(&device->dev, "ACPI companion is missing\n");
  1007. return -ENODEV;
  1008. }
  1009. wmi_bus_dev = device_create(&wmi_bus_class, &device->dev, MKDEV(0, 0), NULL, "wmi_bus-%s",
  1010. dev_name(&device->dev));
  1011. if (IS_ERR(wmi_bus_dev))
  1012. return PTR_ERR(wmi_bus_dev);
  1013. error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_bus_device, wmi_bus_dev);
  1014. if (error < 0)
  1015. return error;
  1016. dev_set_drvdata(&device->dev, wmi_bus_dev);
  1017. status = acpi_install_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY,
  1018. acpi_wmi_notify_handler, wmi_bus_dev);
  1019. if (ACPI_FAILURE(status)) {
  1020. dev_err(&device->dev, "Error installing notify handler\n");
  1021. return -ENODEV;
  1022. }
  1023. error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_notify_handler,
  1024. acpi_device);
  1025. if (error < 0)
  1026. return error;
  1027. error = parse_wdg(wmi_bus_dev, device);
  1028. if (error) {
  1029. dev_err(&device->dev, "Failed to parse _WDG method\n");
  1030. return error;
  1031. }
  1032. return 0;
  1033. }
  1034. int __must_check __wmi_driver_register(struct wmi_driver *driver,
  1035. struct module *owner)
  1036. {
  1037. driver->driver.owner = owner;
  1038. driver->driver.bus = &wmi_bus_type;
  1039. return driver_register(&driver->driver);
  1040. }
  1041. EXPORT_SYMBOL(__wmi_driver_register);
  1042. /**
  1043. * wmi_driver_unregister() - Unregister a WMI driver
  1044. * @driver: WMI driver to unregister
  1045. *
  1046. * Unregisters a WMI driver from the WMI bus.
  1047. */
  1048. void wmi_driver_unregister(struct wmi_driver *driver)
  1049. {
  1050. driver_unregister(&driver->driver);
  1051. }
  1052. EXPORT_SYMBOL(wmi_driver_unregister);
  1053. static struct platform_driver acpi_wmi_driver = {
  1054. .driver = {
  1055. .name = "acpi-wmi",
  1056. .acpi_match_table = wmi_device_ids,
  1057. },
  1058. .probe = acpi_wmi_probe,
  1059. .remove_new = acpi_wmi_remove,
  1060. };
  1061. static int __init acpi_wmi_init(void)
  1062. {
  1063. int error;
  1064. if (acpi_disabled)
  1065. return -ENODEV;
  1066. error = class_register(&wmi_bus_class);
  1067. if (error)
  1068. return error;
  1069. error = bus_register(&wmi_bus_type);
  1070. if (error)
  1071. goto err_unreg_class;
  1072. error = platform_driver_register(&acpi_wmi_driver);
  1073. if (error) {
  1074. pr_err("Error loading mapper\n");
  1075. goto err_unreg_bus;
  1076. }
  1077. return 0;
  1078. err_unreg_bus:
  1079. bus_unregister(&wmi_bus_type);
  1080. err_unreg_class:
  1081. class_unregister(&wmi_bus_class);
  1082. return error;
  1083. }
  1084. static void __exit acpi_wmi_exit(void)
  1085. {
  1086. platform_driver_unregister(&acpi_wmi_driver);
  1087. bus_unregister(&wmi_bus_type);
  1088. class_unregister(&wmi_bus_class);
  1089. }
  1090. subsys_initcall_sync(acpi_wmi_init);
  1091. module_exit(acpi_wmi_exit);