]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - drivers/platform/x86/wmi.c
UBUNTU: Ubuntu-5.4.0-117.132
[mirror_ubuntu-focal-kernel.git] / drivers / platform / x86 / wmi.c
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
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
19 #include <linux/acpi.h>
20 #include <linux/device.h>
21 #include <linux/init.h>
22 #include <linux/kernel.h>
23 #include <linux/list.h>
24 #include <linux/miscdevice.h>
25 #include <linux/module.h>
26 #include <linux/platform_device.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
29 #include <linux/uaccess.h>
30 #include <linux/uuid.h>
31 #include <linux/wmi.h>
32 #include <uapi/linux/wmi.h>
33
34 ACPI_MODULE_NAME("wmi");
35 MODULE_AUTHOR("Carlos Corbacho");
36 MODULE_DESCRIPTION("ACPI-WMI Mapping Driver");
37 MODULE_LICENSE("GPL");
38
39 static LIST_HEAD(wmi_block_list);
40
41 struct guid_block {
42 char guid[16];
43 union {
44 char object_id[2];
45 struct {
46 unsigned char notify_id;
47 unsigned char reserved;
48 };
49 };
50 u8 instance_count;
51 u8 flags;
52 };
53
54 struct wmi_block {
55 struct wmi_device dev;
56 struct list_head list;
57 struct guid_block gblock;
58 struct miscdevice char_dev;
59 struct mutex char_mutex;
60 struct acpi_device *acpi_device;
61 wmi_notify_handler handler;
62 void *handler_data;
63 u64 req_buf_size;
64
65 bool read_takes_no_args;
66 };
67
68
69 /*
70 * If the GUID data block is marked as expensive, we must enable and
71 * explicitily disable data collection.
72 */
73 #define ACPI_WMI_EXPENSIVE 0x1
74 #define ACPI_WMI_METHOD 0x2 /* GUID is a method */
75 #define ACPI_WMI_STRING 0x4 /* GUID takes & returns a string */
76 #define ACPI_WMI_EVENT 0x8 /* GUID is an event */
77
78 static bool debug_event;
79 module_param(debug_event, bool, 0444);
80 MODULE_PARM_DESC(debug_event,
81 "Log WMI Events [0/1]");
82
83 static bool debug_dump_wdg;
84 module_param(debug_dump_wdg, bool, 0444);
85 MODULE_PARM_DESC(debug_dump_wdg,
86 "Dump available WMI interfaces [0/1]");
87
88 static int acpi_wmi_remove(struct platform_device *device);
89 static int acpi_wmi_probe(struct platform_device *device);
90
91 static const struct acpi_device_id wmi_device_ids[] = {
92 {"PNP0C14", 0},
93 {"pnp0c14", 0},
94 {"", 0},
95 };
96 MODULE_DEVICE_TABLE(acpi, wmi_device_ids);
97
98 static struct platform_driver acpi_wmi_driver = {
99 .driver = {
100 .name = "acpi-wmi",
101 .acpi_match_table = wmi_device_ids,
102 },
103 .probe = acpi_wmi_probe,
104 .remove = acpi_wmi_remove,
105 };
106
107 /*
108 * GUID parsing functions
109 */
110
111 static bool find_guid(const char *guid_string, struct wmi_block **out)
112 {
113 uuid_le guid_input;
114 struct wmi_block *wblock;
115 struct guid_block *block;
116
117 if (uuid_le_to_bin(guid_string, &guid_input))
118 return false;
119
120 list_for_each_entry(wblock, &wmi_block_list, list) {
121 block = &wblock->gblock;
122
123 if (memcmp(block->guid, &guid_input, 16) == 0) {
124 if (out)
125 *out = wblock;
126 return true;
127 }
128 }
129 return false;
130 }
131
132 static const void *find_guid_context(struct wmi_block *wblock,
133 struct wmi_driver *wdriver)
134 {
135 const struct wmi_device_id *id;
136 uuid_le guid_input;
137
138 if (wblock == NULL || wdriver == NULL)
139 return NULL;
140 if (wdriver->id_table == NULL)
141 return NULL;
142
143 id = wdriver->id_table;
144 while (*id->guid_string) {
145 if (uuid_le_to_bin(id->guid_string, &guid_input))
146 continue;
147 if (!memcmp(wblock->gblock.guid, &guid_input, 16))
148 return id->context;
149 id++;
150 }
151 return NULL;
152 }
153
154 static int get_subobj_info(acpi_handle handle, const char *pathname,
155 struct acpi_device_info **info)
156 {
157 struct acpi_device_info *dummy_info, **info_ptr;
158 acpi_handle subobj_handle;
159 acpi_status status;
160
161 status = acpi_get_handle(handle, (char *)pathname, &subobj_handle);
162 if (status == AE_NOT_FOUND)
163 return -ENOENT;
164 else if (ACPI_FAILURE(status))
165 return -EIO;
166
167 info_ptr = info ? info : &dummy_info;
168 status = acpi_get_object_info(subobj_handle, info_ptr);
169 if (ACPI_FAILURE(status))
170 return -EIO;
171
172 if (!info)
173 kfree(dummy_info);
174
175 return 0;
176 }
177
178 static acpi_status wmi_method_enable(struct wmi_block *wblock, int enable)
179 {
180 struct guid_block *block = NULL;
181 char method[5];
182 acpi_status status;
183 acpi_handle handle;
184
185 block = &wblock->gblock;
186 handle = wblock->acpi_device->handle;
187
188 snprintf(method, 5, "WE%02X", block->notify_id);
189 status = acpi_execute_simple_method(handle, method, enable);
190
191 if (status != AE_OK && status != AE_NOT_FOUND)
192 return status;
193 else
194 return AE_OK;
195 }
196
197 /*
198 * Exported WMI functions
199 */
200
201 /**
202 * set_required_buffer_size - Sets the buffer size needed for performing IOCTL
203 * @wdev: A wmi bus device from a driver
204 * @instance: Instance index
205 *
206 * Allocates memory needed for buffer, stores the buffer size in that memory
207 */
208 int set_required_buffer_size(struct wmi_device *wdev, u64 length)
209 {
210 struct wmi_block *wblock;
211
212 wblock = container_of(wdev, struct wmi_block, dev);
213 wblock->req_buf_size = length;
214
215 return 0;
216 }
217 EXPORT_SYMBOL_GPL(set_required_buffer_size);
218
219 /**
220 * wmi_evaluate_method - Evaluate a WMI method
221 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
222 * @instance: Instance index
223 * @method_id: Method ID to call
224 * &in: Buffer containing input for the method call
225 * &out: Empty buffer to return the method results
226 *
227 * Call an ACPI-WMI method
228 */
229 acpi_status wmi_evaluate_method(const char *guid_string, u8 instance,
230 u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)
231 {
232 struct wmi_block *wblock = NULL;
233
234 if (!find_guid(guid_string, &wblock))
235 return AE_ERROR;
236 return wmidev_evaluate_method(&wblock->dev, instance, method_id,
237 in, out);
238 }
239 EXPORT_SYMBOL_GPL(wmi_evaluate_method);
240
241 /**
242 * wmidev_evaluate_method - Evaluate a WMI method
243 * @wdev: A wmi bus device from a driver
244 * @instance: Instance index
245 * @method_id: Method ID to call
246 * &in: Buffer containing input for the method call
247 * &out: Empty buffer to return the method results
248 *
249 * Call an ACPI-WMI method
250 */
251 acpi_status wmidev_evaluate_method(struct wmi_device *wdev, u8 instance,
252 u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)
253 {
254 struct guid_block *block = NULL;
255 struct wmi_block *wblock = NULL;
256 acpi_handle handle;
257 acpi_status status;
258 struct acpi_object_list input;
259 union acpi_object params[3];
260 char method[5] = "WM";
261
262 wblock = container_of(wdev, struct wmi_block, dev);
263 block = &wblock->gblock;
264 handle = wblock->acpi_device->handle;
265
266 if (!(block->flags & ACPI_WMI_METHOD))
267 return AE_BAD_DATA;
268
269 if (block->instance_count <= instance)
270 return AE_BAD_PARAMETER;
271
272 input.count = 2;
273 input.pointer = params;
274 params[0].type = ACPI_TYPE_INTEGER;
275 params[0].integer.value = instance;
276 params[1].type = ACPI_TYPE_INTEGER;
277 params[1].integer.value = method_id;
278
279 if (in) {
280 input.count = 3;
281
282 if (block->flags & ACPI_WMI_STRING) {
283 params[2].type = ACPI_TYPE_STRING;
284 } else {
285 params[2].type = ACPI_TYPE_BUFFER;
286 }
287 params[2].buffer.length = in->length;
288 params[2].buffer.pointer = in->pointer;
289 }
290
291 strncat(method, block->object_id, 2);
292
293 status = acpi_evaluate_object(handle, method, &input, out);
294
295 return status;
296 }
297 EXPORT_SYMBOL_GPL(wmidev_evaluate_method);
298
299 static acpi_status __query_block(struct wmi_block *wblock, u8 instance,
300 struct acpi_buffer *out)
301 {
302 struct guid_block *block = NULL;
303 acpi_handle handle;
304 acpi_status status, wc_status = AE_ERROR;
305 struct acpi_object_list input;
306 union acpi_object wq_params[1];
307 char method[5];
308 char wc_method[5] = "WC";
309
310 if (!out)
311 return AE_BAD_PARAMETER;
312
313 block = &wblock->gblock;
314 handle = wblock->acpi_device->handle;
315
316 if (block->instance_count <= instance)
317 return AE_BAD_PARAMETER;
318
319 /* Check GUID is a data block */
320 if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD))
321 return AE_ERROR;
322
323 input.count = 1;
324 input.pointer = wq_params;
325 wq_params[0].type = ACPI_TYPE_INTEGER;
326 wq_params[0].integer.value = instance;
327
328 if (instance == 0 && wblock->read_takes_no_args)
329 input.count = 0;
330
331 /*
332 * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method first to
333 * enable collection.
334 */
335 if (block->flags & ACPI_WMI_EXPENSIVE) {
336 strncat(wc_method, block->object_id, 2);
337
338 /*
339 * Some GUIDs break the specification by declaring themselves
340 * expensive, but have no corresponding WCxx method. So we
341 * should not fail if this happens.
342 */
343 wc_status = acpi_execute_simple_method(handle, wc_method, 1);
344 }
345
346 strcpy(method, "WQ");
347 strncat(method, block->object_id, 2);
348
349 status = acpi_evaluate_object(handle, method, &input, out);
350
351 /*
352 * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method, even if
353 * the WQxx method failed - we should disable collection anyway.
354 */
355 if ((block->flags & ACPI_WMI_EXPENSIVE) && ACPI_SUCCESS(wc_status)) {
356 /*
357 * Ignore whether this WCxx call succeeds or not since
358 * the previously executed WQxx method call might have
359 * succeeded, and returning the failing status code
360 * of this call would throw away the result of the WQxx
361 * call, potentially leaking memory.
362 */
363 acpi_execute_simple_method(handle, wc_method, 0);
364 }
365
366 return status;
367 }
368
369 /**
370 * wmi_query_block - Return contents of a WMI block (deprecated)
371 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
372 * @instance: Instance index
373 * &out: Empty buffer to return the contents of the data block to
374 *
375 * Return the contents of an ACPI-WMI data block to a buffer
376 */
377 acpi_status wmi_query_block(const char *guid_string, u8 instance,
378 struct acpi_buffer *out)
379 {
380 struct wmi_block *wblock;
381
382 if (!guid_string)
383 return AE_BAD_PARAMETER;
384
385 if (!find_guid(guid_string, &wblock))
386 return AE_ERROR;
387
388 return __query_block(wblock, instance, out);
389 }
390 EXPORT_SYMBOL_GPL(wmi_query_block);
391
392 union acpi_object *wmidev_block_query(struct wmi_device *wdev, u8 instance)
393 {
394 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
395 struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev);
396
397 if (ACPI_FAILURE(__query_block(wblock, instance, &out)))
398 return NULL;
399
400 return (union acpi_object *)out.pointer;
401 }
402 EXPORT_SYMBOL_GPL(wmidev_block_query);
403
404 /**
405 * wmi_set_block - Write to a WMI block
406 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
407 * @instance: Instance index
408 * &in: Buffer containing new values for the data block
409 *
410 * Write the contents of the input buffer to an ACPI-WMI data block
411 */
412 acpi_status wmi_set_block(const char *guid_string, u8 instance,
413 const struct acpi_buffer *in)
414 {
415 struct guid_block *block = NULL;
416 struct wmi_block *wblock = NULL;
417 acpi_handle handle;
418 struct acpi_object_list input;
419 union acpi_object params[2];
420 char method[5] = "WS";
421
422 if (!guid_string || !in)
423 return AE_BAD_DATA;
424
425 if (!find_guid(guid_string, &wblock))
426 return AE_ERROR;
427
428 block = &wblock->gblock;
429 handle = wblock->acpi_device->handle;
430
431 if (block->instance_count <= instance)
432 return AE_BAD_PARAMETER;
433
434 /* Check GUID is a data block */
435 if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD))
436 return AE_ERROR;
437
438 input.count = 2;
439 input.pointer = params;
440 params[0].type = ACPI_TYPE_INTEGER;
441 params[0].integer.value = instance;
442
443 if (block->flags & ACPI_WMI_STRING) {
444 params[1].type = ACPI_TYPE_STRING;
445 } else {
446 params[1].type = ACPI_TYPE_BUFFER;
447 }
448 params[1].buffer.length = in->length;
449 params[1].buffer.pointer = in->pointer;
450
451 strncat(method, block->object_id, 2);
452
453 return acpi_evaluate_object(handle, method, &input, NULL);
454 }
455 EXPORT_SYMBOL_GPL(wmi_set_block);
456
457 static void wmi_dump_wdg(const struct guid_block *g)
458 {
459 pr_info("%pUL:\n", g->guid);
460 if (g->flags & ACPI_WMI_EVENT)
461 pr_info("\tnotify_id: 0x%02X\n", g->notify_id);
462 else
463 pr_info("\tobject_id: %2pE\n", g->object_id);
464 pr_info("\tinstance_count: %d\n", g->instance_count);
465 pr_info("\tflags: %#x", g->flags);
466 if (g->flags) {
467 if (g->flags & ACPI_WMI_EXPENSIVE)
468 pr_cont(" ACPI_WMI_EXPENSIVE");
469 if (g->flags & ACPI_WMI_METHOD)
470 pr_cont(" ACPI_WMI_METHOD");
471 if (g->flags & ACPI_WMI_STRING)
472 pr_cont(" ACPI_WMI_STRING");
473 if (g->flags & ACPI_WMI_EVENT)
474 pr_cont(" ACPI_WMI_EVENT");
475 }
476 pr_cont("\n");
477
478 }
479
480 static void wmi_notify_debug(u32 value, void *context)
481 {
482 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
483 union acpi_object *obj;
484 acpi_status status;
485
486 status = wmi_get_event_data(value, &response);
487 if (status != AE_OK) {
488 pr_info("bad event status 0x%x\n", status);
489 return;
490 }
491
492 obj = (union acpi_object *)response.pointer;
493
494 if (!obj)
495 return;
496
497 pr_info("DEBUG Event ");
498 switch(obj->type) {
499 case ACPI_TYPE_BUFFER:
500 pr_cont("BUFFER_TYPE - length %d\n", obj->buffer.length);
501 break;
502 case ACPI_TYPE_STRING:
503 pr_cont("STRING_TYPE - %s\n", obj->string.pointer);
504 break;
505 case ACPI_TYPE_INTEGER:
506 pr_cont("INTEGER_TYPE - %llu\n", obj->integer.value);
507 break;
508 case ACPI_TYPE_PACKAGE:
509 pr_cont("PACKAGE_TYPE - %d elements\n", obj->package.count);
510 break;
511 default:
512 pr_cont("object type 0x%X\n", obj->type);
513 }
514 kfree(obj);
515 }
516
517 /**
518 * wmi_install_notify_handler - Register handler for WMI events
519 * @handler: Function to handle notifications
520 * @data: Data to be returned to handler when event is fired
521 *
522 * Register a handler for events sent to the ACPI-WMI mapper device.
523 */
524 acpi_status wmi_install_notify_handler(const char *guid,
525 wmi_notify_handler handler, void *data)
526 {
527 struct wmi_block *block;
528 acpi_status status = AE_NOT_EXIST;
529 uuid_le guid_input;
530
531 if (!guid || !handler)
532 return AE_BAD_PARAMETER;
533
534 if (uuid_le_to_bin(guid, &guid_input))
535 return AE_BAD_PARAMETER;
536
537 list_for_each_entry(block, &wmi_block_list, list) {
538 acpi_status wmi_status;
539
540 if (memcmp(block->gblock.guid, &guid_input, 16) == 0) {
541 if (block->handler &&
542 block->handler != wmi_notify_debug)
543 return AE_ALREADY_ACQUIRED;
544
545 block->handler = handler;
546 block->handler_data = data;
547
548 wmi_status = wmi_method_enable(block, 1);
549 if ((wmi_status != AE_OK) ||
550 ((wmi_status == AE_OK) && (status == AE_NOT_EXIST)))
551 status = wmi_status;
552 }
553 }
554
555 return status;
556 }
557 EXPORT_SYMBOL_GPL(wmi_install_notify_handler);
558
559 /**
560 * wmi_uninstall_notify_handler - Unregister handler for WMI events
561 *
562 * Unregister handler for events sent to the ACPI-WMI mapper device.
563 */
564 acpi_status wmi_remove_notify_handler(const char *guid)
565 {
566 struct wmi_block *block;
567 acpi_status status = AE_NOT_EXIST;
568 uuid_le guid_input;
569
570 if (!guid)
571 return AE_BAD_PARAMETER;
572
573 if (uuid_le_to_bin(guid, &guid_input))
574 return AE_BAD_PARAMETER;
575
576 list_for_each_entry(block, &wmi_block_list, list) {
577 acpi_status wmi_status;
578
579 if (memcmp(block->gblock.guid, &guid_input, 16) == 0) {
580 if (!block->handler ||
581 block->handler == wmi_notify_debug)
582 return AE_NULL_ENTRY;
583
584 if (debug_event) {
585 block->handler = wmi_notify_debug;
586 status = AE_OK;
587 } else {
588 wmi_status = wmi_method_enable(block, 0);
589 block->handler = NULL;
590 block->handler_data = NULL;
591 if ((wmi_status != AE_OK) ||
592 ((wmi_status == AE_OK) &&
593 (status == AE_NOT_EXIST)))
594 status = wmi_status;
595 }
596 }
597 }
598
599 return status;
600 }
601 EXPORT_SYMBOL_GPL(wmi_remove_notify_handler);
602
603 /**
604 * wmi_get_event_data - Get WMI data associated with an event
605 *
606 * @event: Event to find
607 * @out: Buffer to hold event data. out->pointer should be freed with kfree()
608 *
609 * Returns extra data associated with an event in WMI.
610 */
611 acpi_status wmi_get_event_data(u32 event, struct acpi_buffer *out)
612 {
613 struct acpi_object_list input;
614 union acpi_object params[1];
615 struct guid_block *gblock;
616 struct wmi_block *wblock;
617
618 input.count = 1;
619 input.pointer = params;
620 params[0].type = ACPI_TYPE_INTEGER;
621 params[0].integer.value = event;
622
623 list_for_each_entry(wblock, &wmi_block_list, list) {
624 gblock = &wblock->gblock;
625
626 if ((gblock->flags & ACPI_WMI_EVENT) &&
627 (gblock->notify_id == event))
628 return acpi_evaluate_object(wblock->acpi_device->handle,
629 "_WED", &input, out);
630 }
631
632 return AE_NOT_FOUND;
633 }
634 EXPORT_SYMBOL_GPL(wmi_get_event_data);
635
636 /**
637 * wmi_has_guid - Check if a GUID is available
638 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
639 *
640 * Check if a given GUID is defined by _WDG
641 */
642 bool wmi_has_guid(const char *guid_string)
643 {
644 return find_guid(guid_string, NULL);
645 }
646 EXPORT_SYMBOL_GPL(wmi_has_guid);
647
648 /**
649 * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID
650 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
651 *
652 * Find the _UID of ACPI device associated with this WMI GUID.
653 *
654 * Return: The ACPI _UID field value or NULL if the WMI GUID was not found
655 */
656 char *wmi_get_acpi_device_uid(const char *guid_string)
657 {
658 struct wmi_block *wblock = NULL;
659
660 if (!find_guid(guid_string, &wblock))
661 return NULL;
662
663 return acpi_device_uid(wblock->acpi_device);
664 }
665 EXPORT_SYMBOL_GPL(wmi_get_acpi_device_uid);
666
667 static struct wmi_block *dev_to_wblock(struct device *dev)
668 {
669 return container_of(dev, struct wmi_block, dev.dev);
670 }
671
672 static struct wmi_device *dev_to_wdev(struct device *dev)
673 {
674 return container_of(dev, struct wmi_device, dev);
675 }
676
677 /*
678 * sysfs interface
679 */
680 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
681 char *buf)
682 {
683 struct wmi_block *wblock = dev_to_wblock(dev);
684
685 return sprintf(buf, "wmi:%pUL\n", wblock->gblock.guid);
686 }
687 static DEVICE_ATTR_RO(modalias);
688
689 static ssize_t guid_show(struct device *dev, struct device_attribute *attr,
690 char *buf)
691 {
692 struct wmi_block *wblock = dev_to_wblock(dev);
693
694 return sprintf(buf, "%pUL\n", wblock->gblock.guid);
695 }
696 static DEVICE_ATTR_RO(guid);
697
698 static ssize_t instance_count_show(struct device *dev,
699 struct device_attribute *attr, char *buf)
700 {
701 struct wmi_block *wblock = dev_to_wblock(dev);
702
703 return sprintf(buf, "%d\n", (int)wblock->gblock.instance_count);
704 }
705 static DEVICE_ATTR_RO(instance_count);
706
707 static ssize_t expensive_show(struct device *dev,
708 struct device_attribute *attr, char *buf)
709 {
710 struct wmi_block *wblock = dev_to_wblock(dev);
711
712 return sprintf(buf, "%d\n",
713 (wblock->gblock.flags & ACPI_WMI_EXPENSIVE) != 0);
714 }
715 static DEVICE_ATTR_RO(expensive);
716
717 static struct attribute *wmi_attrs[] = {
718 &dev_attr_modalias.attr,
719 &dev_attr_guid.attr,
720 &dev_attr_instance_count.attr,
721 &dev_attr_expensive.attr,
722 NULL,
723 };
724 ATTRIBUTE_GROUPS(wmi);
725
726 static ssize_t notify_id_show(struct device *dev, struct device_attribute *attr,
727 char *buf)
728 {
729 struct wmi_block *wblock = dev_to_wblock(dev);
730
731 return sprintf(buf, "%02X\n", (unsigned int)wblock->gblock.notify_id);
732 }
733 static DEVICE_ATTR_RO(notify_id);
734
735 static struct attribute *wmi_event_attrs[] = {
736 &dev_attr_notify_id.attr,
737 NULL,
738 };
739 ATTRIBUTE_GROUPS(wmi_event);
740
741 static ssize_t object_id_show(struct device *dev, struct device_attribute *attr,
742 char *buf)
743 {
744 struct wmi_block *wblock = dev_to_wblock(dev);
745
746 return sprintf(buf, "%c%c\n", wblock->gblock.object_id[0],
747 wblock->gblock.object_id[1]);
748 }
749 static DEVICE_ATTR_RO(object_id);
750
751 static ssize_t setable_show(struct device *dev, struct device_attribute *attr,
752 char *buf)
753 {
754 struct wmi_device *wdev = dev_to_wdev(dev);
755
756 return sprintf(buf, "%d\n", (int)wdev->setable);
757 }
758 static DEVICE_ATTR_RO(setable);
759
760 static struct attribute *wmi_data_attrs[] = {
761 &dev_attr_object_id.attr,
762 &dev_attr_setable.attr,
763 NULL,
764 };
765 ATTRIBUTE_GROUPS(wmi_data);
766
767 static struct attribute *wmi_method_attrs[] = {
768 &dev_attr_object_id.attr,
769 NULL,
770 };
771 ATTRIBUTE_GROUPS(wmi_method);
772
773 static int wmi_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
774 {
775 struct wmi_block *wblock = dev_to_wblock(dev);
776
777 if (add_uevent_var(env, "MODALIAS=wmi:%pUL", wblock->gblock.guid))
778 return -ENOMEM;
779
780 if (add_uevent_var(env, "WMI_GUID=%pUL", wblock->gblock.guid))
781 return -ENOMEM;
782
783 return 0;
784 }
785
786 static void wmi_dev_release(struct device *dev)
787 {
788 struct wmi_block *wblock = dev_to_wblock(dev);
789
790 kfree(wblock);
791 }
792
793 static int wmi_dev_match(struct device *dev, struct device_driver *driver)
794 {
795 struct wmi_driver *wmi_driver =
796 container_of(driver, struct wmi_driver, driver);
797 struct wmi_block *wblock = dev_to_wblock(dev);
798 const struct wmi_device_id *id = wmi_driver->id_table;
799
800 if (id == NULL)
801 return 0;
802
803 while (*id->guid_string) {
804 uuid_le driver_guid;
805
806 if (WARN_ON(uuid_le_to_bin(id->guid_string, &driver_guid)))
807 continue;
808 if (!memcmp(&driver_guid, wblock->gblock.guid, 16))
809 return 1;
810
811 id++;
812 }
813
814 return 0;
815 }
816 static int wmi_char_open(struct inode *inode, struct file *filp)
817 {
818 const char *driver_name = filp->f_path.dentry->d_iname;
819 struct wmi_block *wblock = NULL;
820 struct wmi_block *next = NULL;
821
822 list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
823 if (!wblock->dev.dev.driver)
824 continue;
825 if (strcmp(driver_name, wblock->dev.dev.driver->name) == 0) {
826 filp->private_data = wblock;
827 break;
828 }
829 }
830
831 if (!filp->private_data)
832 return -ENODEV;
833
834 return nonseekable_open(inode, filp);
835 }
836
837 static ssize_t wmi_char_read(struct file *filp, char __user *buffer,
838 size_t length, loff_t *offset)
839 {
840 struct wmi_block *wblock = filp->private_data;
841
842 return simple_read_from_buffer(buffer, length, offset,
843 &wblock->req_buf_size,
844 sizeof(wblock->req_buf_size));
845 }
846
847 static long wmi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
848 {
849 struct wmi_ioctl_buffer __user *input =
850 (struct wmi_ioctl_buffer __user *) arg;
851 struct wmi_block *wblock = filp->private_data;
852 struct wmi_ioctl_buffer *buf = NULL;
853 struct wmi_driver *wdriver = NULL;
854 int ret;
855
856 if (_IOC_TYPE(cmd) != WMI_IOC)
857 return -ENOTTY;
858
859 /* make sure we're not calling a higher instance than exists*/
860 if (_IOC_NR(cmd) >= wblock->gblock.instance_count)
861 return -EINVAL;
862
863 mutex_lock(&wblock->char_mutex);
864 buf = wblock->handler_data;
865 if (get_user(buf->length, &input->length)) {
866 dev_dbg(&wblock->dev.dev, "Read length from user failed\n");
867 ret = -EFAULT;
868 goto out_ioctl;
869 }
870 /* if it's too small, abort */
871 if (buf->length < wblock->req_buf_size) {
872 dev_err(&wblock->dev.dev,
873 "Buffer %lld too small, need at least %lld\n",
874 buf->length, wblock->req_buf_size);
875 ret = -EINVAL;
876 goto out_ioctl;
877 }
878 /* if it's too big, warn, driver will only use what is needed */
879 if (buf->length > wblock->req_buf_size)
880 dev_warn(&wblock->dev.dev,
881 "Buffer %lld is bigger than required %lld\n",
882 buf->length, wblock->req_buf_size);
883
884 /* copy the structure from userspace */
885 if (copy_from_user(buf, input, wblock->req_buf_size)) {
886 dev_dbg(&wblock->dev.dev, "Copy %llu from user failed\n",
887 wblock->req_buf_size);
888 ret = -EFAULT;
889 goto out_ioctl;
890 }
891
892 /* let the driver do any filtering and do the call */
893 wdriver = container_of(wblock->dev.dev.driver,
894 struct wmi_driver, driver);
895 if (!try_module_get(wdriver->driver.owner)) {
896 ret = -EBUSY;
897 goto out_ioctl;
898 }
899 ret = wdriver->filter_callback(&wblock->dev, cmd, buf);
900 module_put(wdriver->driver.owner);
901 if (ret)
902 goto out_ioctl;
903
904 /* return the result (only up to our internal buffer size) */
905 if (copy_to_user(input, buf, wblock->req_buf_size)) {
906 dev_dbg(&wblock->dev.dev, "Copy %llu to user failed\n",
907 wblock->req_buf_size);
908 ret = -EFAULT;
909 }
910
911 out_ioctl:
912 mutex_unlock(&wblock->char_mutex);
913 return ret;
914 }
915
916 static const struct file_operations wmi_fops = {
917 .owner = THIS_MODULE,
918 .read = wmi_char_read,
919 .open = wmi_char_open,
920 .unlocked_ioctl = wmi_ioctl,
921 .compat_ioctl = wmi_ioctl,
922 };
923
924 static int wmi_dev_probe(struct device *dev)
925 {
926 struct wmi_block *wblock = dev_to_wblock(dev);
927 struct wmi_driver *wdriver =
928 container_of(dev->driver, struct wmi_driver, driver);
929 int ret = 0;
930 char *buf;
931
932 if (ACPI_FAILURE(wmi_method_enable(wblock, 1)))
933 dev_warn(dev, "failed to enable device -- probing anyway\n");
934
935 if (wdriver->probe) {
936 ret = wdriver->probe(dev_to_wdev(dev),
937 find_guid_context(wblock, wdriver));
938 if (ret != 0)
939 goto probe_failure;
940 }
941
942 /* driver wants a character device made */
943 if (wdriver->filter_callback) {
944 /* check that required buffer size declared by driver or MOF */
945 if (!wblock->req_buf_size) {
946 dev_err(&wblock->dev.dev,
947 "Required buffer size not set\n");
948 ret = -EINVAL;
949 goto probe_failure;
950 }
951
952 wblock->handler_data = kmalloc(wblock->req_buf_size,
953 GFP_KERNEL);
954 if (!wblock->handler_data) {
955 ret = -ENOMEM;
956 goto probe_failure;
957 }
958
959 buf = kasprintf(GFP_KERNEL, "wmi/%s", wdriver->driver.name);
960 if (!buf) {
961 ret = -ENOMEM;
962 goto probe_string_failure;
963 }
964 wblock->char_dev.minor = MISC_DYNAMIC_MINOR;
965 wblock->char_dev.name = buf;
966 wblock->char_dev.fops = &wmi_fops;
967 wblock->char_dev.mode = 0444;
968 ret = misc_register(&wblock->char_dev);
969 if (ret) {
970 dev_warn(dev, "failed to register char dev: %d\n", ret);
971 ret = -ENOMEM;
972 goto probe_misc_failure;
973 }
974 }
975
976 return 0;
977
978 probe_misc_failure:
979 kfree(buf);
980 probe_string_failure:
981 kfree(wblock->handler_data);
982 probe_failure:
983 if (ACPI_FAILURE(wmi_method_enable(wblock, 0)))
984 dev_warn(dev, "failed to disable device\n");
985 return ret;
986 }
987
988 static int wmi_dev_remove(struct device *dev)
989 {
990 struct wmi_block *wblock = dev_to_wblock(dev);
991 struct wmi_driver *wdriver =
992 container_of(dev->driver, struct wmi_driver, driver);
993 int ret = 0;
994
995 if (wdriver->filter_callback) {
996 misc_deregister(&wblock->char_dev);
997 kfree(wblock->char_dev.name);
998 kfree(wblock->handler_data);
999 }
1000
1001 if (wdriver->remove)
1002 ret = wdriver->remove(dev_to_wdev(dev));
1003
1004 if (ACPI_FAILURE(wmi_method_enable(wblock, 0)))
1005 dev_warn(dev, "failed to disable device\n");
1006
1007 return ret;
1008 }
1009
1010 static struct class wmi_bus_class = {
1011 .name = "wmi_bus",
1012 };
1013
1014 static struct bus_type wmi_bus_type = {
1015 .name = "wmi",
1016 .dev_groups = wmi_groups,
1017 .match = wmi_dev_match,
1018 .uevent = wmi_dev_uevent,
1019 .probe = wmi_dev_probe,
1020 .remove = wmi_dev_remove,
1021 };
1022
1023 static const struct device_type wmi_type_event = {
1024 .name = "event",
1025 .groups = wmi_event_groups,
1026 .release = wmi_dev_release,
1027 };
1028
1029 static const struct device_type wmi_type_method = {
1030 .name = "method",
1031 .groups = wmi_method_groups,
1032 .release = wmi_dev_release,
1033 };
1034
1035 static const struct device_type wmi_type_data = {
1036 .name = "data",
1037 .groups = wmi_data_groups,
1038 .release = wmi_dev_release,
1039 };
1040
1041 static int wmi_create_device(struct device *wmi_bus_dev,
1042 const struct guid_block *gblock,
1043 struct wmi_block *wblock,
1044 struct acpi_device *device)
1045 {
1046 struct acpi_device_info *info;
1047 char method[5];
1048 int result;
1049
1050 if (gblock->flags & ACPI_WMI_EVENT) {
1051 wblock->dev.dev.type = &wmi_type_event;
1052 goto out_init;
1053 }
1054
1055 if (gblock->flags & ACPI_WMI_METHOD) {
1056 wblock->dev.dev.type = &wmi_type_method;
1057 mutex_init(&wblock->char_mutex);
1058 goto out_init;
1059 }
1060
1061 /*
1062 * Data Block Query Control Method (WQxx by convention) is
1063 * required per the WMI documentation. If it is not present,
1064 * we ignore this data block.
1065 */
1066 strcpy(method, "WQ");
1067 strncat(method, wblock->gblock.object_id, 2);
1068 result = get_subobj_info(device->handle, method, &info);
1069
1070 if (result) {
1071 dev_warn(wmi_bus_dev,
1072 "%s data block query control method not found\n",
1073 method);
1074 return result;
1075 }
1076
1077 wblock->dev.dev.type = &wmi_type_data;
1078
1079 /*
1080 * The Microsoft documentation specifically states:
1081 *
1082 * Data blocks registered with only a single instance
1083 * can ignore the parameter.
1084 *
1085 * ACPICA will get mad at us if we call the method with the wrong number
1086 * of arguments, so check what our method expects. (On some Dell
1087 * laptops, WQxx may not be a method at all.)
1088 */
1089 if (info->type != ACPI_TYPE_METHOD || info->param_count == 0)
1090 wblock->read_takes_no_args = true;
1091
1092 kfree(info);
1093
1094 strcpy(method, "WS");
1095 strncat(method, wblock->gblock.object_id, 2);
1096 result = get_subobj_info(device->handle, method, NULL);
1097
1098 if (result == 0)
1099 wblock->dev.setable = true;
1100
1101 out_init:
1102 wblock->dev.dev.bus = &wmi_bus_type;
1103 wblock->dev.dev.parent = wmi_bus_dev;
1104
1105 dev_set_name(&wblock->dev.dev, "%pUL", gblock->guid);
1106
1107 device_initialize(&wblock->dev.dev);
1108
1109 return 0;
1110 }
1111
1112 static void wmi_free_devices(struct acpi_device *device)
1113 {
1114 struct wmi_block *wblock, *next;
1115
1116 /* Delete devices for all the GUIDs */
1117 list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
1118 if (wblock->acpi_device == device) {
1119 list_del(&wblock->list);
1120 device_unregister(&wblock->dev.dev);
1121 }
1122 }
1123 }
1124
1125 static bool guid_already_parsed(struct acpi_device *device,
1126 const u8 *guid)
1127 {
1128 struct wmi_block *wblock;
1129
1130 list_for_each_entry(wblock, &wmi_block_list, list) {
1131 if (memcmp(wblock->gblock.guid, guid, 16) == 0) {
1132 /*
1133 * Because we historically didn't track the relationship
1134 * between GUIDs and ACPI nodes, we don't know whether
1135 * we need to suppress GUIDs that are unique on a
1136 * given node but duplicated across nodes.
1137 */
1138 dev_warn(&device->dev, "duplicate WMI GUID %pUL (first instance was on %s)\n",
1139 guid, dev_name(&wblock->acpi_device->dev));
1140 return true;
1141 }
1142 }
1143
1144 return false;
1145 }
1146
1147 /*
1148 * Parse the _WDG method for the GUID data blocks
1149 */
1150 static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
1151 {
1152 struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
1153 const struct guid_block *gblock;
1154 struct wmi_block *wblock, *next;
1155 union acpi_object *obj;
1156 acpi_status status;
1157 int retval = 0;
1158 u32 i, total;
1159
1160 status = acpi_evaluate_object(device->handle, "_WDG", NULL, &out);
1161 if (ACPI_FAILURE(status))
1162 return -ENXIO;
1163
1164 obj = (union acpi_object *) out.pointer;
1165 if (!obj)
1166 return -ENXIO;
1167
1168 if (obj->type != ACPI_TYPE_BUFFER) {
1169 retval = -ENXIO;
1170 goto out_free_pointer;
1171 }
1172
1173 gblock = (const struct guid_block *)obj->buffer.pointer;
1174 total = obj->buffer.length / sizeof(struct guid_block);
1175
1176 for (i = 0; i < total; i++) {
1177 if (debug_dump_wdg)
1178 wmi_dump_wdg(&gblock[i]);
1179
1180 /*
1181 * Some WMI devices, like those for nVidia hooks, have a
1182 * duplicate GUID. It's not clear what we should do in this
1183 * case yet, so for now, we'll just ignore the duplicate
1184 * for device creation.
1185 */
1186 if (guid_already_parsed(device, gblock[i].guid))
1187 continue;
1188
1189 wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
1190 if (!wblock) {
1191 retval = -ENOMEM;
1192 break;
1193 }
1194
1195 wblock->acpi_device = device;
1196 wblock->gblock = gblock[i];
1197
1198 retval = wmi_create_device(wmi_bus_dev, &gblock[i], wblock, device);
1199 if (retval) {
1200 kfree(wblock);
1201 continue;
1202 }
1203
1204 list_add_tail(&wblock->list, &wmi_block_list);
1205
1206 if (debug_event) {
1207 wblock->handler = wmi_notify_debug;
1208 wmi_method_enable(wblock, 1);
1209 }
1210 }
1211
1212 /*
1213 * Now that all of the devices are created, add them to the
1214 * device tree and probe subdrivers.
1215 */
1216 list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
1217 if (wblock->acpi_device != device)
1218 continue;
1219
1220 retval = device_add(&wblock->dev.dev);
1221 if (retval) {
1222 dev_err(wmi_bus_dev, "failed to register %pUL\n",
1223 wblock->gblock.guid);
1224 if (debug_event)
1225 wmi_method_enable(wblock, 0);
1226 list_del(&wblock->list);
1227 put_device(&wblock->dev.dev);
1228 }
1229 }
1230
1231 out_free_pointer:
1232 kfree(out.pointer);
1233 return retval;
1234 }
1235
1236 /*
1237 * WMI can have EmbeddedControl access regions. In which case, we just want to
1238 * hand these off to the EC driver.
1239 */
1240 static acpi_status
1241 acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address,
1242 u32 bits, u64 *value,
1243 void *handler_context, void *region_context)
1244 {
1245 int result = 0, i = 0;
1246 u8 temp = 0;
1247
1248 if ((address > 0xFF) || !value)
1249 return AE_BAD_PARAMETER;
1250
1251 if (function != ACPI_READ && function != ACPI_WRITE)
1252 return AE_BAD_PARAMETER;
1253
1254 if (bits != 8)
1255 return AE_BAD_PARAMETER;
1256
1257 if (function == ACPI_READ) {
1258 result = ec_read(address, &temp);
1259 (*value) |= ((u64)temp) << i;
1260 } else {
1261 temp = 0xff & ((*value) >> i);
1262 result = ec_write(address, temp);
1263 }
1264
1265 switch (result) {
1266 case -EINVAL:
1267 return AE_BAD_PARAMETER;
1268 break;
1269 case -ENODEV:
1270 return AE_NOT_FOUND;
1271 break;
1272 case -ETIME:
1273 return AE_TIME;
1274 break;
1275 default:
1276 return AE_OK;
1277 }
1278 }
1279
1280 static void acpi_wmi_notify_handler(acpi_handle handle, u32 event,
1281 void *context)
1282 {
1283 struct guid_block *block;
1284 struct wmi_block *wblock;
1285 bool found_it = false;
1286
1287 list_for_each_entry(wblock, &wmi_block_list, list) {
1288 block = &wblock->gblock;
1289
1290 if (wblock->acpi_device->handle == handle &&
1291 (block->flags & ACPI_WMI_EVENT) &&
1292 (block->notify_id == event))
1293 {
1294 found_it = true;
1295 break;
1296 }
1297 }
1298
1299 if (!found_it)
1300 return;
1301
1302 /* If a driver is bound, then notify the driver. */
1303 if (wblock->dev.dev.driver) {
1304 struct wmi_driver *driver;
1305 struct acpi_object_list input;
1306 union acpi_object params[1];
1307 struct acpi_buffer evdata = { ACPI_ALLOCATE_BUFFER, NULL };
1308 acpi_status status;
1309
1310 driver = container_of(wblock->dev.dev.driver,
1311 struct wmi_driver, driver);
1312
1313 input.count = 1;
1314 input.pointer = params;
1315 params[0].type = ACPI_TYPE_INTEGER;
1316 params[0].integer.value = event;
1317
1318 status = acpi_evaluate_object(wblock->acpi_device->handle,
1319 "_WED", &input, &evdata);
1320 if (ACPI_FAILURE(status)) {
1321 dev_warn(&wblock->dev.dev,
1322 "failed to get event data\n");
1323 return;
1324 }
1325
1326 if (driver->notify)
1327 driver->notify(&wblock->dev,
1328 (union acpi_object *)evdata.pointer);
1329
1330 kfree(evdata.pointer);
1331 } else if (wblock->handler) {
1332 /* Legacy handler */
1333 wblock->handler(event, wblock->handler_data);
1334 }
1335
1336 if (debug_event) {
1337 pr_info("DEBUG Event GUID: %pUL\n",
1338 wblock->gblock.guid);
1339 }
1340
1341 acpi_bus_generate_netlink_event(
1342 wblock->acpi_device->pnp.device_class,
1343 dev_name(&wblock->dev.dev),
1344 event, 0);
1345
1346 }
1347
1348 static int acpi_wmi_remove(struct platform_device *device)
1349 {
1350 struct acpi_device *acpi_device = ACPI_COMPANION(&device->dev);
1351
1352 acpi_remove_notify_handler(acpi_device->handle, ACPI_DEVICE_NOTIFY,
1353 acpi_wmi_notify_handler);
1354 acpi_remove_address_space_handler(acpi_device->handle,
1355 ACPI_ADR_SPACE_EC, &acpi_wmi_ec_space_handler);
1356 wmi_free_devices(acpi_device);
1357 device_destroy(&wmi_bus_class, MKDEV(0, 0));
1358
1359 return 0;
1360 }
1361
1362 static int acpi_wmi_probe(struct platform_device *device)
1363 {
1364 struct acpi_device *acpi_device;
1365 struct device *wmi_bus_dev;
1366 acpi_status status;
1367 int error;
1368
1369 acpi_device = ACPI_COMPANION(&device->dev);
1370 if (!acpi_device) {
1371 dev_err(&device->dev, "ACPI companion is missing\n");
1372 return -ENODEV;
1373 }
1374
1375 status = acpi_install_address_space_handler(acpi_device->handle,
1376 ACPI_ADR_SPACE_EC,
1377 &acpi_wmi_ec_space_handler,
1378 NULL, NULL);
1379 if (ACPI_FAILURE(status)) {
1380 dev_err(&device->dev, "Error installing EC region handler\n");
1381 return -ENODEV;
1382 }
1383
1384 status = acpi_install_notify_handler(acpi_device->handle,
1385 ACPI_DEVICE_NOTIFY,
1386 acpi_wmi_notify_handler,
1387 NULL);
1388 if (ACPI_FAILURE(status)) {
1389 dev_err(&device->dev, "Error installing notify handler\n");
1390 error = -ENODEV;
1391 goto err_remove_ec_handler;
1392 }
1393
1394 wmi_bus_dev = device_create(&wmi_bus_class, &device->dev, MKDEV(0, 0),
1395 NULL, "wmi_bus-%s", dev_name(&device->dev));
1396 if (IS_ERR(wmi_bus_dev)) {
1397 error = PTR_ERR(wmi_bus_dev);
1398 goto err_remove_notify_handler;
1399 }
1400 dev_set_drvdata(&device->dev, wmi_bus_dev);
1401
1402 error = parse_wdg(wmi_bus_dev, acpi_device);
1403 if (error) {
1404 pr_err("Failed to parse WDG method\n");
1405 goto err_remove_busdev;
1406 }
1407
1408 return 0;
1409
1410 err_remove_busdev:
1411 device_destroy(&wmi_bus_class, MKDEV(0, 0));
1412
1413 err_remove_notify_handler:
1414 acpi_remove_notify_handler(acpi_device->handle, ACPI_DEVICE_NOTIFY,
1415 acpi_wmi_notify_handler);
1416
1417 err_remove_ec_handler:
1418 acpi_remove_address_space_handler(acpi_device->handle,
1419 ACPI_ADR_SPACE_EC,
1420 &acpi_wmi_ec_space_handler);
1421
1422 return error;
1423 }
1424
1425 int __must_check __wmi_driver_register(struct wmi_driver *driver,
1426 struct module *owner)
1427 {
1428 driver->driver.owner = owner;
1429 driver->driver.bus = &wmi_bus_type;
1430
1431 return driver_register(&driver->driver);
1432 }
1433 EXPORT_SYMBOL(__wmi_driver_register);
1434
1435 void wmi_driver_unregister(struct wmi_driver *driver)
1436 {
1437 driver_unregister(&driver->driver);
1438 }
1439 EXPORT_SYMBOL(wmi_driver_unregister);
1440
1441 static int __init acpi_wmi_init(void)
1442 {
1443 int error;
1444
1445 if (acpi_disabled)
1446 return -ENODEV;
1447
1448 error = class_register(&wmi_bus_class);
1449 if (error)
1450 return error;
1451
1452 error = bus_register(&wmi_bus_type);
1453 if (error)
1454 goto err_unreg_class;
1455
1456 error = platform_driver_register(&acpi_wmi_driver);
1457 if (error) {
1458 pr_err("Error loading mapper\n");
1459 goto err_unreg_bus;
1460 }
1461
1462 return 0;
1463
1464 err_unreg_bus:
1465 bus_unregister(&wmi_bus_type);
1466
1467 err_unreg_class:
1468 class_unregister(&wmi_bus_class);
1469
1470 return error;
1471 }
1472
1473 static void __exit acpi_wmi_exit(void)
1474 {
1475 platform_driver_unregister(&acpi_wmi_driver);
1476 bus_unregister(&wmi_bus_type);
1477 class_unregister(&wmi_bus_class);
1478 }
1479
1480 subsys_initcall_sync(acpi_wmi_init);
1481 module_exit(acpi_wmi_exit);