]>
Commit | Line | Data |
---|---|---|
bff431e4 CC |
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 | ||
8e07514d DT |
30 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
31 | ||
bff431e4 CC |
32 | #include <linux/kernel.h> |
33 | #include <linux/init.h> | |
34 | #include <linux/types.h> | |
1caab3c1 | 35 | #include <linux/device.h> |
bff431e4 CC |
36 | #include <linux/list.h> |
37 | #include <linux/acpi.h> | |
5a0e3ad6 | 38 | #include <linux/slab.h> |
7c52d551 | 39 | #include <linux/module.h> |
844af950 | 40 | #include <linux/wmi.h> |
538d7eb8 | 41 | #include <linux/uuid.h> |
bff431e4 CC |
42 | |
43 | ACPI_MODULE_NAME("wmi"); | |
44 | MODULE_AUTHOR("Carlos Corbacho"); | |
45 | MODULE_DESCRIPTION("ACPI-WMI Mapping Driver"); | |
46 | MODULE_LICENSE("GPL"); | |
47 | ||
762e1a2f | 48 | static LIST_HEAD(wmi_block_list); |
bff431e4 CC |
49 | |
50 | struct guid_block { | |
51 | char guid[16]; | |
52 | union { | |
53 | char object_id[2]; | |
54 | struct { | |
55 | unsigned char notify_id; | |
56 | unsigned char reserved; | |
57 | }; | |
58 | }; | |
59 | u8 instance_count; | |
60 | u8 flags; | |
61 | }; | |
62 | ||
63 | struct wmi_block { | |
844af950 | 64 | struct wmi_device dev; |
bff431e4 CC |
65 | struct list_head list; |
66 | struct guid_block gblock; | |
b0e86302 | 67 | struct acpi_device *acpi_device; |
bff431e4 CC |
68 | wmi_notify_handler handler; |
69 | void *handler_data; | |
d4fc91ad AL |
70 | |
71 | bool read_takes_no_args; /* only defined if readable */ | |
bff431e4 CC |
72 | }; |
73 | ||
bff431e4 CC |
74 | |
75 | /* | |
76 | * If the GUID data block is marked as expensive, we must enable and | |
77 | * explicitily disable data collection. | |
78 | */ | |
79 | #define ACPI_WMI_EXPENSIVE 0x1 | |
80 | #define ACPI_WMI_METHOD 0x2 /* GUID is a method */ | |
81 | #define ACPI_WMI_STRING 0x4 /* GUID takes & returns a string */ | |
82 | #define ACPI_WMI_EVENT 0x8 /* GUID is an event */ | |
83 | ||
90ab5ee9 | 84 | static bool debug_event; |
fc3155b2 TR |
85 | module_param(debug_event, bool, 0444); |
86 | MODULE_PARM_DESC(debug_event, | |
87 | "Log WMI Events [0/1]"); | |
88 | ||
90ab5ee9 | 89 | static bool debug_dump_wdg; |
a929aae0 TR |
90 | module_param(debug_dump_wdg, bool, 0444); |
91 | MODULE_PARM_DESC(debug_dump_wdg, | |
92 | "Dump available WMI interfaces [0/1]"); | |
93 | ||
51fac838 | 94 | static int acpi_wmi_remove(struct acpi_device *device); |
bff431e4 | 95 | static int acpi_wmi_add(struct acpi_device *device); |
f61bb939 | 96 | static void acpi_wmi_notify(struct acpi_device *device, u32 event); |
bff431e4 CC |
97 | |
98 | static const struct acpi_device_id wmi_device_ids[] = { | |
99 | {"PNP0C14", 0}, | |
100 | {"pnp0c14", 0}, | |
101 | {"", 0}, | |
102 | }; | |
103 | MODULE_DEVICE_TABLE(acpi, wmi_device_ids); | |
104 | ||
105 | static struct acpi_driver acpi_wmi_driver = { | |
844af950 AL |
106 | .name = "acpi-wmi", |
107 | .owner = THIS_MODULE, | |
bff431e4 CC |
108 | .ids = wmi_device_ids, |
109 | .ops = { | |
110 | .add = acpi_wmi_add, | |
111 | .remove = acpi_wmi_remove, | |
f61bb939 | 112 | .notify = acpi_wmi_notify, |
c64eefd4 | 113 | }, |
bff431e4 CC |
114 | }; |
115 | ||
116 | /* | |
117 | * GUID parsing functions | |
118 | */ | |
119 | ||
bff431e4 CC |
120 | static bool find_guid(const char *guid_string, struct wmi_block **out) |
121 | { | |
538d7eb8 | 122 | uuid_le guid_input; |
bff431e4 CC |
123 | struct wmi_block *wblock; |
124 | struct guid_block *block; | |
125 | struct list_head *p; | |
126 | ||
538d7eb8 AS |
127 | if (uuid_le_to_bin(guid_string, &guid_input)) |
128 | return false; | |
bff431e4 | 129 | |
762e1a2f | 130 | list_for_each(p, &wmi_block_list) { |
bff431e4 CC |
131 | wblock = list_entry(p, struct wmi_block, list); |
132 | block = &wblock->gblock; | |
133 | ||
538d7eb8 | 134 | if (memcmp(block->guid, &guid_input, 16) == 0) { |
bff431e4 CC |
135 | if (out) |
136 | *out = wblock; | |
097c27fc | 137 | return true; |
bff431e4 CC |
138 | } |
139 | } | |
097c27fc | 140 | return false; |
bff431e4 CC |
141 | } |
142 | ||
d4fc91ad AL |
143 | static int get_subobj_info(acpi_handle handle, const char *pathname, |
144 | struct acpi_device_info **info) | |
145 | { | |
146 | struct acpi_device_info *dummy_info, **info_ptr; | |
147 | acpi_handle subobj_handle; | |
148 | acpi_status status; | |
149 | ||
150 | status = acpi_get_handle(handle, (char *)pathname, &subobj_handle); | |
151 | if (status == AE_NOT_FOUND) | |
152 | return -ENOENT; | |
153 | else if (ACPI_FAILURE(status)) | |
154 | return -EIO; | |
155 | ||
156 | info_ptr = info ? info : &dummy_info; | |
157 | status = acpi_get_object_info(subobj_handle, info_ptr); | |
158 | if (ACPI_FAILURE(status)) | |
159 | return -EIO; | |
160 | ||
161 | if (!info) | |
162 | kfree(dummy_info); | |
163 | ||
164 | return 0; | |
165 | } | |
166 | ||
a66bfa7a MG |
167 | static acpi_status wmi_method_enable(struct wmi_block *wblock, int enable) |
168 | { | |
169 | struct guid_block *block = NULL; | |
170 | char method[5]; | |
a66bfa7a MG |
171 | acpi_status status; |
172 | acpi_handle handle; | |
173 | ||
174 | block = &wblock->gblock; | |
b0e86302 | 175 | handle = wblock->acpi_device->handle; |
a66bfa7a | 176 | |
a66bfa7a | 177 | snprintf(method, 5, "WE%02X", block->notify_id); |
8122ab66 | 178 | status = acpi_execute_simple_method(handle, method, enable); |
a66bfa7a MG |
179 | |
180 | if (status != AE_OK && status != AE_NOT_FOUND) | |
181 | return status; | |
182 | else | |
183 | return AE_OK; | |
184 | } | |
185 | ||
bff431e4 CC |
186 | /* |
187 | * Exported WMI functions | |
188 | */ | |
189 | /** | |
190 | * wmi_evaluate_method - Evaluate a WMI method | |
191 | * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba | |
192 | * @instance: Instance index | |
193 | * @method_id: Method ID to call | |
194 | * &in: Buffer containing input for the method call | |
195 | * &out: Empty buffer to return the method results | |
196 | * | |
197 | * Call an ACPI-WMI method | |
198 | */ | |
199 | acpi_status wmi_evaluate_method(const char *guid_string, u8 instance, | |
200 | u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out) | |
201 | { | |
202 | struct guid_block *block = NULL; | |
203 | struct wmi_block *wblock = NULL; | |
204 | acpi_handle handle; | |
205 | acpi_status status; | |
206 | struct acpi_object_list input; | |
207 | union acpi_object params[3]; | |
f3d83e24 | 208 | char method[5] = "WM"; |
bff431e4 CC |
209 | |
210 | if (!find_guid(guid_string, &wblock)) | |
08237974 | 211 | return AE_ERROR; |
bff431e4 CC |
212 | |
213 | block = &wblock->gblock; | |
b0e86302 | 214 | handle = wblock->acpi_device->handle; |
bff431e4 | 215 | |
e6bafba5 | 216 | if (!(block->flags & ACPI_WMI_METHOD)) |
bff431e4 CC |
217 | return AE_BAD_DATA; |
218 | ||
219 | if (block->instance_count < instance) | |
220 | return AE_BAD_PARAMETER; | |
221 | ||
222 | input.count = 2; | |
223 | input.pointer = params; | |
224 | params[0].type = ACPI_TYPE_INTEGER; | |
225 | params[0].integer.value = instance; | |
226 | params[1].type = ACPI_TYPE_INTEGER; | |
227 | params[1].integer.value = method_id; | |
228 | ||
229 | if (in) { | |
230 | input.count = 3; | |
231 | ||
232 | if (block->flags & ACPI_WMI_STRING) { | |
233 | params[2].type = ACPI_TYPE_STRING; | |
234 | } else { | |
235 | params[2].type = ACPI_TYPE_BUFFER; | |
236 | } | |
237 | params[2].buffer.length = in->length; | |
238 | params[2].buffer.pointer = in->pointer; | |
239 | } | |
240 | ||
241 | strncat(method, block->object_id, 2); | |
242 | ||
243 | status = acpi_evaluate_object(handle, method, &input, out); | |
244 | ||
245 | return status; | |
246 | } | |
247 | EXPORT_SYMBOL_GPL(wmi_evaluate_method); | |
248 | ||
249 | /** | |
250 | * wmi_query_block - Return contents of a WMI block | |
251 | * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba | |
252 | * @instance: Instance index | |
253 | * &out: Empty buffer to return the contents of the data block to | |
254 | * | |
255 | * Return the contents of an ACPI-WMI data block to a buffer | |
256 | */ | |
257 | acpi_status wmi_query_block(const char *guid_string, u8 instance, | |
258 | struct acpi_buffer *out) | |
259 | { | |
260 | struct guid_block *block = NULL; | |
261 | struct wmi_block *wblock = NULL; | |
54f14c27 | 262 | acpi_handle handle; |
bff431e4 | 263 | acpi_status status, wc_status = AE_ERROR; |
8122ab66 ZR |
264 | struct acpi_object_list input; |
265 | union acpi_object wq_params[1]; | |
f3d83e24 CL |
266 | char method[5]; |
267 | char wc_method[5] = "WC"; | |
bff431e4 CC |
268 | |
269 | if (!guid_string || !out) | |
270 | return AE_BAD_PARAMETER; | |
271 | ||
272 | if (!find_guid(guid_string, &wblock)) | |
08237974 | 273 | return AE_ERROR; |
bff431e4 CC |
274 | |
275 | block = &wblock->gblock; | |
b0e86302 | 276 | handle = wblock->acpi_device->handle; |
bff431e4 CC |
277 | |
278 | if (block->instance_count < instance) | |
279 | return AE_BAD_PARAMETER; | |
280 | ||
281 | /* Check GUID is a data block */ | |
282 | if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD)) | |
08237974 | 283 | return AE_ERROR; |
bff431e4 CC |
284 | |
285 | input.count = 1; | |
286 | input.pointer = wq_params; | |
287 | wq_params[0].type = ACPI_TYPE_INTEGER; | |
288 | wq_params[0].integer.value = instance; | |
289 | ||
d4fc91ad AL |
290 | if (instance == 0 && wblock->read_takes_no_args) |
291 | input.count = 0; | |
292 | ||
bff431e4 CC |
293 | /* |
294 | * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method first to | |
295 | * enable collection. | |
296 | */ | |
297 | if (block->flags & ACPI_WMI_EXPENSIVE) { | |
bff431e4 CC |
298 | strncat(wc_method, block->object_id, 2); |
299 | ||
300 | /* | |
301 | * Some GUIDs break the specification by declaring themselves | |
302 | * expensive, but have no corresponding WCxx method. So we | |
303 | * should not fail if this happens. | |
304 | */ | |
54f14c27 | 305 | if (acpi_has_method(handle, wc_method)) |
8122ab66 ZR |
306 | wc_status = acpi_execute_simple_method(handle, |
307 | wc_method, 1); | |
bff431e4 CC |
308 | } |
309 | ||
310 | strcpy(method, "WQ"); | |
311 | strncat(method, block->object_id, 2); | |
312 | ||
dab36ad8 | 313 | status = acpi_evaluate_object(handle, method, &input, out); |
bff431e4 CC |
314 | |
315 | /* | |
316 | * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method, even if | |
317 | * the WQxx method failed - we should disable collection anyway. | |
318 | */ | |
a527f2d7 | 319 | if ((block->flags & ACPI_WMI_EXPENSIVE) && ACPI_SUCCESS(wc_status)) { |
8122ab66 | 320 | status = acpi_execute_simple_method(handle, wc_method, 0); |
bff431e4 CC |
321 | } |
322 | ||
323 | return status; | |
324 | } | |
325 | EXPORT_SYMBOL_GPL(wmi_query_block); | |
326 | ||
327 | /** | |
328 | * wmi_set_block - Write to a WMI block | |
329 | * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba | |
330 | * @instance: Instance index | |
331 | * &in: Buffer containing new values for the data block | |
332 | * | |
333 | * Write the contents of the input buffer to an ACPI-WMI data block | |
334 | */ | |
335 | acpi_status wmi_set_block(const char *guid_string, u8 instance, | |
336 | const struct acpi_buffer *in) | |
337 | { | |
338 | struct guid_block *block = NULL; | |
339 | struct wmi_block *wblock = NULL; | |
340 | acpi_handle handle; | |
341 | struct acpi_object_list input; | |
342 | union acpi_object params[2]; | |
f3d83e24 | 343 | char method[5] = "WS"; |
bff431e4 CC |
344 | |
345 | if (!guid_string || !in) | |
346 | return AE_BAD_DATA; | |
347 | ||
348 | if (!find_guid(guid_string, &wblock)) | |
08237974 | 349 | return AE_ERROR; |
bff431e4 CC |
350 | |
351 | block = &wblock->gblock; | |
b0e86302 | 352 | handle = wblock->acpi_device->handle; |
bff431e4 CC |
353 | |
354 | if (block->instance_count < instance) | |
355 | return AE_BAD_PARAMETER; | |
356 | ||
357 | /* Check GUID is a data block */ | |
358 | if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD)) | |
08237974 | 359 | return AE_ERROR; |
bff431e4 CC |
360 | |
361 | input.count = 2; | |
362 | input.pointer = params; | |
363 | params[0].type = ACPI_TYPE_INTEGER; | |
364 | params[0].integer.value = instance; | |
365 | ||
366 | if (block->flags & ACPI_WMI_STRING) { | |
367 | params[1].type = ACPI_TYPE_STRING; | |
368 | } else { | |
369 | params[1].type = ACPI_TYPE_BUFFER; | |
370 | } | |
371 | params[1].buffer.length = in->length; | |
372 | params[1].buffer.pointer = in->pointer; | |
373 | ||
374 | strncat(method, block->object_id, 2); | |
375 | ||
376 | return acpi_evaluate_object(handle, method, &input, NULL); | |
377 | } | |
378 | EXPORT_SYMBOL_GPL(wmi_set_block); | |
379 | ||
37830662 | 380 | static void wmi_dump_wdg(const struct guid_block *g) |
a929aae0 | 381 | { |
85b4e4eb | 382 | pr_info("%pUL:\n", g->guid); |
8e07514d DT |
383 | pr_info("\tobject_id: %c%c\n", g->object_id[0], g->object_id[1]); |
384 | pr_info("\tnotify_id: %02X\n", g->notify_id); | |
385 | pr_info("\treserved: %02X\n", g->reserved); | |
386 | pr_info("\tinstance_count: %d\n", g->instance_count); | |
dd8e908e | 387 | pr_info("\tflags: %#x", g->flags); |
a929aae0 | 388 | if (g->flags) { |
a929aae0 | 389 | if (g->flags & ACPI_WMI_EXPENSIVE) |
dd8e908e | 390 | pr_cont(" ACPI_WMI_EXPENSIVE"); |
a929aae0 | 391 | if (g->flags & ACPI_WMI_METHOD) |
dd8e908e | 392 | pr_cont(" ACPI_WMI_METHOD"); |
a929aae0 | 393 | if (g->flags & ACPI_WMI_STRING) |
dd8e908e | 394 | pr_cont(" ACPI_WMI_STRING"); |
a929aae0 | 395 | if (g->flags & ACPI_WMI_EVENT) |
dd8e908e | 396 | pr_cont(" ACPI_WMI_EVENT"); |
a929aae0 | 397 | } |
8e07514d | 398 | pr_cont("\n"); |
a929aae0 TR |
399 | |
400 | } | |
401 | ||
fc3155b2 TR |
402 | static void wmi_notify_debug(u32 value, void *context) |
403 | { | |
404 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; | |
405 | union acpi_object *obj; | |
1492616a | 406 | acpi_status status; |
fc3155b2 | 407 | |
1492616a AL |
408 | status = wmi_get_event_data(value, &response); |
409 | if (status != AE_OK) { | |
8e07514d | 410 | pr_info("bad event status 0x%x\n", status); |
1492616a AL |
411 | return; |
412 | } | |
fc3155b2 TR |
413 | |
414 | obj = (union acpi_object *)response.pointer; | |
415 | ||
416 | if (!obj) | |
417 | return; | |
418 | ||
8e07514d | 419 | pr_info("DEBUG Event "); |
fc3155b2 TR |
420 | switch(obj->type) { |
421 | case ACPI_TYPE_BUFFER: | |
8e07514d | 422 | pr_cont("BUFFER_TYPE - length %d\n", obj->buffer.length); |
fc3155b2 TR |
423 | break; |
424 | case ACPI_TYPE_STRING: | |
8e07514d | 425 | pr_cont("STRING_TYPE - %s\n", obj->string.pointer); |
fc3155b2 TR |
426 | break; |
427 | case ACPI_TYPE_INTEGER: | |
8e07514d | 428 | pr_cont("INTEGER_TYPE - %llu\n", obj->integer.value); |
fc3155b2 TR |
429 | break; |
430 | case ACPI_TYPE_PACKAGE: | |
8e07514d | 431 | pr_cont("PACKAGE_TYPE - %d elements\n", obj->package.count); |
fc3155b2 TR |
432 | break; |
433 | default: | |
8e07514d | 434 | pr_cont("object type 0x%X\n", obj->type); |
fc3155b2 | 435 | } |
1492616a | 436 | kfree(obj); |
fc3155b2 TR |
437 | } |
438 | ||
bff431e4 CC |
439 | /** |
440 | * wmi_install_notify_handler - Register handler for WMI events | |
441 | * @handler: Function to handle notifications | |
442 | * @data: Data to be returned to handler when event is fired | |
443 | * | |
444 | * Register a handler for events sent to the ACPI-WMI mapper device. | |
445 | */ | |
446 | acpi_status wmi_install_notify_handler(const char *guid, | |
447 | wmi_notify_handler handler, void *data) | |
448 | { | |
449 | struct wmi_block *block; | |
58f6425e | 450 | acpi_status status = AE_NOT_EXIST; |
538d7eb8 | 451 | uuid_le guid_input; |
58f6425e | 452 | struct list_head *p; |
bff431e4 CC |
453 | |
454 | if (!guid || !handler) | |
455 | return AE_BAD_PARAMETER; | |
456 | ||
538d7eb8 AS |
457 | if (uuid_le_to_bin(guid, &guid_input)) |
458 | return AE_BAD_PARAMETER; | |
bff431e4 | 459 | |
58f6425e CK |
460 | list_for_each(p, &wmi_block_list) { |
461 | acpi_status wmi_status; | |
462 | block = list_entry(p, struct wmi_block, list); | |
463 | ||
538d7eb8 | 464 | if (memcmp(block->gblock.guid, &guid_input, 16) == 0) { |
58f6425e CK |
465 | if (block->handler && |
466 | block->handler != wmi_notify_debug) | |
467 | return AE_ALREADY_ACQUIRED; | |
bff431e4 | 468 | |
58f6425e CK |
469 | block->handler = handler; |
470 | block->handler_data = data; | |
bff431e4 | 471 | |
58f6425e CK |
472 | wmi_status = wmi_method_enable(block, 1); |
473 | if ((wmi_status != AE_OK) || | |
474 | ((wmi_status == AE_OK) && (status == AE_NOT_EXIST))) | |
475 | status = wmi_status; | |
476 | } | |
477 | } | |
a66bfa7a MG |
478 | |
479 | return status; | |
bff431e4 CC |
480 | } |
481 | EXPORT_SYMBOL_GPL(wmi_install_notify_handler); | |
482 | ||
483 | /** | |
484 | * wmi_uninstall_notify_handler - Unregister handler for WMI events | |
485 | * | |
486 | * Unregister handler for events sent to the ACPI-WMI mapper device. | |
487 | */ | |
488 | acpi_status wmi_remove_notify_handler(const char *guid) | |
489 | { | |
490 | struct wmi_block *block; | |
58f6425e | 491 | acpi_status status = AE_NOT_EXIST; |
538d7eb8 | 492 | uuid_le guid_input; |
58f6425e | 493 | struct list_head *p; |
bff431e4 CC |
494 | |
495 | if (!guid) | |
496 | return AE_BAD_PARAMETER; | |
497 | ||
538d7eb8 AS |
498 | if (uuid_le_to_bin(guid, &guid_input)) |
499 | return AE_BAD_PARAMETER; | |
bff431e4 | 500 | |
58f6425e CK |
501 | list_for_each(p, &wmi_block_list) { |
502 | acpi_status wmi_status; | |
503 | block = list_entry(p, struct wmi_block, list); | |
504 | ||
538d7eb8 | 505 | if (memcmp(block->gblock.guid, &guid_input, 16) == 0) { |
58f6425e CK |
506 | if (!block->handler || |
507 | block->handler == wmi_notify_debug) | |
508 | return AE_NULL_ENTRY; | |
509 | ||
510 | if (debug_event) { | |
511 | block->handler = wmi_notify_debug; | |
512 | status = AE_OK; | |
513 | } else { | |
514 | wmi_status = wmi_method_enable(block, 0); | |
515 | block->handler = NULL; | |
516 | block->handler_data = NULL; | |
517 | if ((wmi_status != AE_OK) || | |
518 | ((wmi_status == AE_OK) && | |
519 | (status == AE_NOT_EXIST))) | |
520 | status = wmi_status; | |
521 | } | |
522 | } | |
fc3155b2 | 523 | } |
58f6425e | 524 | |
a66bfa7a | 525 | return status; |
bff431e4 CC |
526 | } |
527 | EXPORT_SYMBOL_GPL(wmi_remove_notify_handler); | |
528 | ||
529 | /** | |
530 | * wmi_get_event_data - Get WMI data associated with an event | |
531 | * | |
3e9b988e AA |
532 | * @event: Event to find |
533 | * @out: Buffer to hold event data. out->pointer should be freed with kfree() | |
bff431e4 CC |
534 | * |
535 | * Returns extra data associated with an event in WMI. | |
536 | */ | |
537 | acpi_status wmi_get_event_data(u32 event, struct acpi_buffer *out) | |
538 | { | |
539 | struct acpi_object_list input; | |
540 | union acpi_object params[1]; | |
541 | struct guid_block *gblock; | |
542 | struct wmi_block *wblock; | |
543 | struct list_head *p; | |
544 | ||
545 | input.count = 1; | |
546 | input.pointer = params; | |
547 | params[0].type = ACPI_TYPE_INTEGER; | |
548 | params[0].integer.value = event; | |
549 | ||
762e1a2f | 550 | list_for_each(p, &wmi_block_list) { |
bff431e4 CC |
551 | wblock = list_entry(p, struct wmi_block, list); |
552 | gblock = &wblock->gblock; | |
553 | ||
554 | if ((gblock->flags & ACPI_WMI_EVENT) && | |
555 | (gblock->notify_id == event)) | |
b0e86302 AL |
556 | return acpi_evaluate_object(wblock->acpi_device->handle, |
557 | "_WED", &input, out); | |
bff431e4 CC |
558 | } |
559 | ||
560 | return AE_NOT_FOUND; | |
561 | } | |
562 | EXPORT_SYMBOL_GPL(wmi_get_event_data); | |
563 | ||
564 | /** | |
565 | * wmi_has_guid - Check if a GUID is available | |
566 | * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba | |
567 | * | |
568 | * Check if a given GUID is defined by _WDG | |
569 | */ | |
570 | bool wmi_has_guid(const char *guid_string) | |
571 | { | |
572 | return find_guid(guid_string, NULL); | |
573 | } | |
574 | EXPORT_SYMBOL_GPL(wmi_has_guid); | |
575 | ||
844af950 AL |
576 | static struct wmi_block *dev_to_wblock(struct device *dev) |
577 | { | |
578 | return container_of(dev, struct wmi_block, dev.dev); | |
579 | } | |
580 | ||
581 | static struct wmi_device *dev_to_wdev(struct device *dev) | |
582 | { | |
583 | return container_of(dev, struct wmi_device, dev); | |
584 | } | |
585 | ||
1caab3c1 MG |
586 | /* |
587 | * sysfs interface | |
588 | */ | |
614ef432 | 589 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
1caab3c1 MG |
590 | char *buf) |
591 | { | |
844af950 | 592 | struct wmi_block *wblock = dev_to_wblock(dev); |
1caab3c1 | 593 | |
85b4e4eb | 594 | return sprintf(buf, "wmi:%pUL\n", wblock->gblock.guid); |
1caab3c1 | 595 | } |
e80b89a5 | 596 | static DEVICE_ATTR_RO(modalias); |
614ef432 | 597 | |
844af950 AL |
598 | static ssize_t guid_show(struct device *dev, struct device_attribute *attr, |
599 | char *buf) | |
600 | { | |
601 | struct wmi_block *wblock = dev_to_wblock(dev); | |
602 | ||
603 | return sprintf(buf, "%pUL\n", wblock->gblock.guid); | |
604 | } | |
605 | static DEVICE_ATTR_RO(guid); | |
606 | ||
d79b1074 AL |
607 | static ssize_t instance_count_show(struct device *dev, |
608 | struct device_attribute *attr, char *buf) | |
609 | { | |
610 | struct wmi_block *wblock = dev_to_wblock(dev); | |
611 | ||
612 | return sprintf(buf, "%d\n", (int)wblock->gblock.instance_count); | |
613 | } | |
614 | static DEVICE_ATTR_RO(instance_count); | |
615 | ||
616 | static ssize_t expensive_show(struct device *dev, | |
617 | struct device_attribute *attr, char *buf) | |
618 | { | |
619 | struct wmi_block *wblock = dev_to_wblock(dev); | |
620 | ||
621 | return sprintf(buf, "%d\n", | |
622 | (wblock->gblock.flags & ACPI_WMI_EXPENSIVE) != 0); | |
623 | } | |
624 | static DEVICE_ATTR_RO(expensive); | |
625 | ||
e80b89a5 GKH |
626 | static struct attribute *wmi_attrs[] = { |
627 | &dev_attr_modalias.attr, | |
844af950 | 628 | &dev_attr_guid.attr, |
d79b1074 AL |
629 | &dev_attr_instance_count.attr, |
630 | &dev_attr_expensive.attr, | |
e80b89a5 | 631 | NULL, |
614ef432 | 632 | }; |
e80b89a5 | 633 | ATTRIBUTE_GROUPS(wmi); |
1caab3c1 | 634 | |
d79b1074 AL |
635 | static ssize_t notify_id_show(struct device *dev, struct device_attribute *attr, |
636 | char *buf) | |
637 | { | |
638 | struct wmi_block *wblock = dev_to_wblock(dev); | |
639 | ||
640 | return sprintf(buf, "%02X\n", (unsigned int)wblock->gblock.notify_id); | |
641 | } | |
642 | static DEVICE_ATTR_RO(notify_id); | |
643 | ||
644 | static struct attribute *wmi_event_attrs[] = { | |
645 | &dev_attr_notify_id.attr, | |
646 | NULL, | |
647 | }; | |
648 | ATTRIBUTE_GROUPS(wmi_event); | |
649 | ||
650 | static ssize_t object_id_show(struct device *dev, struct device_attribute *attr, | |
651 | char *buf) | |
652 | { | |
653 | struct wmi_block *wblock = dev_to_wblock(dev); | |
654 | ||
655 | return sprintf(buf, "%c%c\n", wblock->gblock.object_id[0], | |
656 | wblock->gblock.object_id[1]); | |
657 | } | |
658 | static DEVICE_ATTR_RO(object_id); | |
659 | ||
d4fc91ad AL |
660 | static ssize_t readable_show(struct device *dev, struct device_attribute *attr, |
661 | char *buf) | |
662 | { | |
663 | struct wmi_device *wdev = dev_to_wdev(dev); | |
664 | ||
665 | return sprintf(buf, "%d\n", (int)wdev->readable); | |
666 | } | |
667 | static DEVICE_ATTR_RO(readable); | |
668 | ||
669 | static ssize_t writeable_show(struct device *dev, struct device_attribute *attr, | |
670 | char *buf) | |
671 | { | |
672 | struct wmi_device *wdev = dev_to_wdev(dev); | |
673 | ||
674 | return sprintf(buf, "%d\n", (int)wdev->writeable); | |
675 | } | |
676 | static DEVICE_ATTR_RO(writeable); | |
677 | ||
678 | static struct attribute *wmi_data_attrs[] = { | |
679 | &dev_attr_object_id.attr, | |
680 | &dev_attr_readable.attr, | |
681 | &dev_attr_writeable.attr, | |
682 | NULL, | |
683 | }; | |
684 | ATTRIBUTE_GROUPS(wmi_data); | |
685 | ||
686 | static struct attribute *wmi_method_attrs[] = { | |
d79b1074 AL |
687 | &dev_attr_object_id.attr, |
688 | NULL, | |
689 | }; | |
d4fc91ad | 690 | ATTRIBUTE_GROUPS(wmi_method); |
d79b1074 | 691 | |
1caab3c1 MG |
692 | static int wmi_dev_uevent(struct device *dev, struct kobj_uevent_env *env) |
693 | { | |
844af950 | 694 | struct wmi_block *wblock = dev_to_wblock(dev); |
1caab3c1 | 695 | |
844af950 | 696 | if (add_uevent_var(env, "MODALIAS=wmi:%pUL", wblock->gblock.guid)) |
1caab3c1 MG |
697 | return -ENOMEM; |
698 | ||
844af950 | 699 | if (add_uevent_var(env, "WMI_GUID=%pUL", wblock->gblock.guid)) |
1caab3c1 MG |
700 | return -ENOMEM; |
701 | ||
844af950 AL |
702 | return 0; |
703 | } | |
704 | ||
705 | static void wmi_dev_release(struct device *dev) | |
706 | { | |
707 | struct wmi_block *wblock = dev_to_wblock(dev); | |
708 | ||
709 | kfree(wblock); | |
710 | } | |
711 | ||
712 | static int wmi_dev_match(struct device *dev, struct device_driver *driver) | |
713 | { | |
714 | struct wmi_driver *wmi_driver = | |
715 | container_of(driver, struct wmi_driver, driver); | |
716 | struct wmi_block *wblock = dev_to_wblock(dev); | |
717 | const struct wmi_device_id *id = wmi_driver->id_table; | |
1caab3c1 | 718 | |
844af950 AL |
719 | while (id->guid_string) { |
720 | uuid_le driver_guid; | |
721 | ||
722 | if (WARN_ON(uuid_le_to_bin(id->guid_string, &driver_guid))) | |
723 | continue; | |
724 | if (!memcmp(&driver_guid, wblock->gblock.guid, 16)) | |
725 | return 1; | |
726 | ||
727 | id++; | |
728 | } | |
1caab3c1 MG |
729 | |
730 | return 0; | |
731 | } | |
732 | ||
844af950 | 733 | static int wmi_dev_probe(struct device *dev) |
1caab3c1 | 734 | { |
844af950 AL |
735 | struct wmi_block *wblock = dev_to_wblock(dev); |
736 | struct wmi_driver *wdriver = | |
737 | container_of(dev->driver, struct wmi_driver, driver); | |
738 | int ret = 0; | |
739 | ||
740 | if (ACPI_FAILURE(wmi_method_enable(wblock, 1))) | |
741 | dev_warn(dev, "failed to enable device -- probing anyway\n"); | |
742 | ||
743 | if (wdriver->probe) { | |
744 | ret = wdriver->probe(dev_to_wdev(dev)); | |
745 | if (ret != 0 && ACPI_FAILURE(wmi_method_enable(wblock, 0))) | |
746 | dev_warn(dev, "failed to disable device\n"); | |
747 | } | |
748 | ||
749 | return ret; | |
750 | } | |
751 | ||
752 | static int wmi_dev_remove(struct device *dev) | |
753 | { | |
754 | struct wmi_block *wblock = dev_to_wblock(dev); | |
755 | struct wmi_driver *wdriver = | |
756 | container_of(dev->driver, struct wmi_driver, driver); | |
757 | int ret = 0; | |
758 | ||
759 | if (wdriver->remove) | |
760 | ret = wdriver->remove(dev_to_wdev(dev)); | |
761 | ||
762 | if (ACPI_FAILURE(wmi_method_enable(wblock, 0))) | |
763 | dev_warn(dev, "failed to disable device\n"); | |
c64eefd4 | 764 | |
844af950 | 765 | return ret; |
1caab3c1 MG |
766 | } |
767 | ||
844af950 AL |
768 | static struct class wmi_bus_class = { |
769 | .name = "wmi_bus", | |
770 | }; | |
771 | ||
772 | static struct bus_type wmi_bus_type = { | |
1caab3c1 | 773 | .name = "wmi", |
e80b89a5 | 774 | .dev_groups = wmi_groups, |
844af950 AL |
775 | .match = wmi_dev_match, |
776 | .uevent = wmi_dev_uevent, | |
777 | .probe = wmi_dev_probe, | |
778 | .remove = wmi_dev_remove, | |
1caab3c1 MG |
779 | }; |
780 | ||
d79b1074 AL |
781 | static struct device_type wmi_type_event = { |
782 | .name = "event", | |
783 | .groups = wmi_event_groups, | |
784 | .release = wmi_dev_release, | |
785 | }; | |
786 | ||
787 | static struct device_type wmi_type_method = { | |
788 | .name = "method", | |
d4fc91ad | 789 | .groups = wmi_method_groups, |
d79b1074 AL |
790 | .release = wmi_dev_release, |
791 | }; | |
792 | ||
793 | static struct device_type wmi_type_data = { | |
794 | .name = "data", | |
d4fc91ad | 795 | .groups = wmi_data_groups, |
d79b1074 AL |
796 | .release = wmi_dev_release, |
797 | }; | |
798 | ||
6ee50aaa | 799 | static void wmi_create_device(struct device *wmi_bus_dev, |
844af950 | 800 | const struct guid_block *gblock, |
7f5809bf AL |
801 | struct wmi_block *wblock, |
802 | struct acpi_device *device) | |
1caab3c1 | 803 | { |
844af950 AL |
804 | wblock->dev.dev.bus = &wmi_bus_type; |
805 | wblock->dev.dev.parent = wmi_bus_dev; | |
1caab3c1 | 806 | |
844af950 | 807 | dev_set_name(&wblock->dev.dev, "%pUL", gblock->guid); |
1caab3c1 | 808 | |
d79b1074 AL |
809 | if (gblock->flags & ACPI_WMI_EVENT) { |
810 | wblock->dev.dev.type = &wmi_type_event; | |
811 | } else if (gblock->flags & ACPI_WMI_METHOD) { | |
812 | wblock->dev.dev.type = &wmi_type_method; | |
813 | } else { | |
d4fc91ad AL |
814 | struct acpi_device_info *info; |
815 | char method[5]; | |
816 | int result; | |
817 | ||
d79b1074 | 818 | wblock->dev.dev.type = &wmi_type_data; |
d4fc91ad AL |
819 | |
820 | strcpy(method, "WQ"); | |
821 | strncat(method, wblock->gblock.object_id, 2); | |
822 | result = get_subobj_info(device->handle, method, &info); | |
823 | ||
824 | if (result == 0) { | |
825 | wblock->dev.readable = true; | |
826 | ||
827 | /* | |
828 | * The Microsoft documentation specifically states: | |
829 | * | |
830 | * Data blocks registered with only a single instance | |
831 | * can ignore the parameter. | |
832 | * | |
833 | * ACPICA will get mad at us if we call the method | |
834 | * with the wrong number of arguments, so check what | |
835 | * our method expects. (On some Dell laptops, WQxx | |
836 | * may not be a method at all.) | |
837 | */ | |
838 | if (info->type != ACPI_TYPE_METHOD || | |
839 | info->param_count == 0) | |
840 | wblock->read_takes_no_args = true; | |
841 | ||
842 | kfree(info); | |
843 | } | |
844 | ||
845 | strcpy(method, "WS"); | |
846 | strncat(method, wblock->gblock.object_id, 2); | |
847 | result = get_subobj_info(device->handle, method, NULL); | |
848 | ||
849 | if (result == 0) { | |
850 | wblock->dev.writeable = true; | |
851 | } | |
852 | ||
d79b1074 | 853 | } |
1caab3c1 | 854 | |
6ee50aaa | 855 | device_initialize(&wblock->dev.dev); |
1caab3c1 MG |
856 | } |
857 | ||
b0e86302 | 858 | static void wmi_free_devices(struct acpi_device *device) |
1caab3c1 | 859 | { |
c64eefd4 | 860 | struct wmi_block *wblock, *next; |
1caab3c1 MG |
861 | |
862 | /* Delete devices for all the GUIDs */ | |
023b9565 | 863 | list_for_each_entry_safe(wblock, next, &wmi_block_list, list) { |
b0e86302 AL |
864 | if (wblock->acpi_device == device) { |
865 | list_del(&wblock->list); | |
6ee50aaa | 866 | device_unregister(&wblock->dev.dev); |
b0e86302 | 867 | } |
023b9565 | 868 | } |
1caab3c1 MG |
869 | } |
870 | ||
b0e86302 AL |
871 | static bool guid_already_parsed(struct acpi_device *device, |
872 | const u8 *guid) | |
d1f9e497 | 873 | { |
d1f9e497 | 874 | struct wmi_block *wblock; |
d1f9e497 | 875 | |
b0e86302 AL |
876 | list_for_each_entry(wblock, &wmi_block_list, list) { |
877 | if (memcmp(wblock->gblock.guid, guid, 16) == 0) { | |
878 | /* | |
879 | * Because we historically didn't track the relationship | |
880 | * between GUIDs and ACPI nodes, we don't know whether | |
881 | * we need to suppress GUIDs that are unique on a | |
882 | * given node but duplicated across nodes. | |
883 | */ | |
884 | dev_warn(&device->dev, "duplicate WMI GUID %pUL (first instance was on %s)\n", | |
885 | guid, dev_name(&wblock->acpi_device->dev)); | |
d1f9e497 | 886 | return true; |
b0e86302 AL |
887 | } |
888 | } | |
d1f9e497 | 889 | |
c64eefd4 | 890 | return false; |
2d5ab555 DT |
891 | } |
892 | ||
bff431e4 CC |
893 | /* |
894 | * Parse the _WDG method for the GUID data blocks | |
895 | */ | |
844af950 | 896 | static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device) |
bff431e4 CC |
897 | { |
898 | struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; | |
37830662 | 899 | const struct guid_block *gblock; |
6ee50aaa DHV |
900 | struct wmi_block *wblock, *next; |
901 | union acpi_object *obj; | |
bff431e4 | 902 | acpi_status status; |
6ee50aaa | 903 | int retval = 0; |
bff431e4 CC |
904 | u32 i, total; |
905 | ||
7f5809bf | 906 | status = acpi_evaluate_object(device->handle, "_WDG", NULL, &out); |
bff431e4 | 907 | if (ACPI_FAILURE(status)) |
c64eefd4 | 908 | return -ENXIO; |
bff431e4 CC |
909 | |
910 | obj = (union acpi_object *) out.pointer; | |
3d2c63eb | 911 | if (!obj) |
c64eefd4 | 912 | return -ENXIO; |
bff431e4 | 913 | |
64ed0ab8 | 914 | if (obj->type != ACPI_TYPE_BUFFER) { |
c64eefd4 | 915 | retval = -ENXIO; |
64ed0ab8 DT |
916 | goto out_free_pointer; |
917 | } | |
bff431e4 | 918 | |
37830662 | 919 | gblock = (const struct guid_block *)obj->buffer.pointer; |
bff431e4 CC |
920 | total = obj->buffer.length / sizeof(struct guid_block); |
921 | ||
bff431e4 | 922 | for (i = 0; i < total; i++) { |
58f6425e CK |
923 | if (debug_dump_wdg) |
924 | wmi_dump_wdg(&gblock[i]); | |
925 | ||
a1c31bcd AL |
926 | /* |
927 | * Some WMI devices, like those for nVidia hooks, have a | |
928 | * duplicate GUID. It's not clear what we should do in this | |
929 | * case yet, so for now, we'll just ignore the duplicate | |
930 | * for device creation. | |
931 | */ | |
932 | if (guid_already_parsed(device, gblock[i].guid)) | |
933 | continue; | |
934 | ||
58f6425e | 935 | wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL); |
6ee50aaa DHV |
936 | if (!wblock) { |
937 | retval = -ENOMEM; | |
938 | break; | |
939 | } | |
58f6425e | 940 | |
b0e86302 | 941 | wblock->acpi_device = device; |
58f6425e CK |
942 | wblock->gblock = gblock[i]; |
943 | ||
6ee50aaa | 944 | wmi_create_device(wmi_bus_dev, &gblock[i], wblock, device); |
c64eefd4 | 945 | |
58f6425e | 946 | list_add_tail(&wblock->list, &wmi_block_list); |
bff431e4 | 947 | |
fc3155b2 TR |
948 | if (debug_event) { |
949 | wblock->handler = wmi_notify_debug; | |
2d5ab555 | 950 | wmi_method_enable(wblock, 1); |
fc3155b2 | 951 | } |
bff431e4 CC |
952 | } |
953 | ||
6ee50aaa DHV |
954 | /* |
955 | * Now that all of the devices are created, add them to the | |
956 | * device tree and probe subdrivers. | |
957 | */ | |
958 | list_for_each_entry_safe(wblock, next, &wmi_block_list, list) { | |
959 | if (wblock->acpi_device != device) | |
960 | continue; | |
961 | ||
962 | retval = device_add(&wblock->dev.dev); | |
963 | if (retval) { | |
964 | dev_err(wmi_bus_dev, "failed to register %pULL\n", | |
965 | wblock->gblock.guid); | |
966 | if (debug_event) | |
967 | wmi_method_enable(wblock, 0); | |
968 | list_del(&wblock->list); | |
969 | put_device(&wblock->dev.dev); | |
970 | } | |
971 | } | |
c64eefd4 | 972 | |
a5167c5b AL |
973 | out_free_pointer: |
974 | kfree(out.pointer); | |
c64eefd4 | 975 | return retval; |
bff431e4 CC |
976 | } |
977 | ||
978 | /* | |
979 | * WMI can have EmbeddedControl access regions. In which case, we just want to | |
980 | * hand these off to the EC driver. | |
981 | */ | |
982 | static acpi_status | |
983 | acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address, | |
439913ff | 984 | u32 bits, u64 *value, |
bff431e4 CC |
985 | void *handler_context, void *region_context) |
986 | { | |
987 | int result = 0, i = 0; | |
988 | u8 temp = 0; | |
989 | ||
990 | if ((address > 0xFF) || !value) | |
991 | return AE_BAD_PARAMETER; | |
992 | ||
993 | if (function != ACPI_READ && function != ACPI_WRITE) | |
994 | return AE_BAD_PARAMETER; | |
995 | ||
996 | if (bits != 8) | |
997 | return AE_BAD_PARAMETER; | |
998 | ||
999 | if (function == ACPI_READ) { | |
1000 | result = ec_read(address, &temp); | |
439913ff | 1001 | (*value) |= ((u64)temp) << i; |
bff431e4 CC |
1002 | } else { |
1003 | temp = 0xff & ((*value) >> i); | |
1004 | result = ec_write(address, temp); | |
1005 | } | |
1006 | ||
1007 | switch (result) { | |
1008 | case -EINVAL: | |
1009 | return AE_BAD_PARAMETER; | |
1010 | break; | |
1011 | case -ENODEV: | |
1012 | return AE_NOT_FOUND; | |
1013 | break; | |
1014 | case -ETIME: | |
1015 | return AE_TIME; | |
1016 | break; | |
1017 | default: | |
1018 | return AE_OK; | |
1019 | } | |
1020 | } | |
1021 | ||
f61bb939 | 1022 | static void acpi_wmi_notify(struct acpi_device *device, u32 event) |
bff431e4 CC |
1023 | { |
1024 | struct guid_block *block; | |
1025 | struct wmi_block *wblock; | |
1026 | struct list_head *p; | |
bff431e4 | 1027 | |
762e1a2f | 1028 | list_for_each(p, &wmi_block_list) { |
bff431e4 CC |
1029 | wblock = list_entry(p, struct wmi_block, list); |
1030 | block = &wblock->gblock; | |
1031 | ||
b0e86302 AL |
1032 | if (wblock->acpi_device == device && |
1033 | (block->flags & ACPI_WMI_EVENT) && | |
1034 | (block->notify_id == event)) { | |
bff431e4 CC |
1035 | if (wblock->handler) |
1036 | wblock->handler(event, wblock->handler_data); | |
7715348c | 1037 | if (debug_event) { |
85b4e4eb RV |
1038 | pr_info("DEBUG Event GUID: %pUL\n", |
1039 | wblock->gblock.guid); | |
7715348c | 1040 | } |
bff431e4 CC |
1041 | |
1042 | acpi_bus_generate_netlink_event( | |
0794469d | 1043 | device->pnp.device_class, dev_name(&device->dev), |
bff431e4 CC |
1044 | event, 0); |
1045 | break; | |
1046 | } | |
1047 | } | |
1048 | } | |
1049 | ||
51fac838 | 1050 | static int acpi_wmi_remove(struct acpi_device *device) |
bff431e4 | 1051 | { |
bff431e4 CC |
1052 | acpi_remove_address_space_handler(device->handle, |
1053 | ACPI_ADR_SPACE_EC, &acpi_wmi_ec_space_handler); | |
b0e86302 | 1054 | wmi_free_devices(device); |
844af950 AL |
1055 | device_unregister((struct device *)acpi_driver_data(device)); |
1056 | device->driver_data = NULL; | |
bff431e4 CC |
1057 | |
1058 | return 0; | |
1059 | } | |
1060 | ||
925b1089 | 1061 | static int acpi_wmi_add(struct acpi_device *device) |
bff431e4 | 1062 | { |
844af950 | 1063 | struct device *wmi_bus_dev; |
bff431e4 | 1064 | acpi_status status; |
c64eefd4 | 1065 | int error; |
bff431e4 | 1066 | |
bff431e4 CC |
1067 | status = acpi_install_address_space_handler(device->handle, |
1068 | ACPI_ADR_SPACE_EC, | |
1069 | &acpi_wmi_ec_space_handler, | |
1070 | NULL, NULL); | |
5212cd67 | 1071 | if (ACPI_FAILURE(status)) { |
46492ee4 | 1072 | dev_err(&device->dev, "Error installing EC region handler\n"); |
bff431e4 | 1073 | return -ENODEV; |
5212cd67 | 1074 | } |
bff431e4 | 1075 | |
844af950 AL |
1076 | wmi_bus_dev = device_create(&wmi_bus_class, &device->dev, MKDEV(0, 0), |
1077 | NULL, "wmi_bus-%s", dev_name(&device->dev)); | |
1078 | if (IS_ERR(wmi_bus_dev)) { | |
1079 | error = PTR_ERR(wmi_bus_dev); | |
1080 | goto err_remove_handler; | |
1081 | } | |
1082 | device->driver_data = wmi_bus_dev; | |
1083 | ||
1084 | error = parse_wdg(wmi_bus_dev, device); | |
c64eefd4 | 1085 | if (error) { |
8e07514d | 1086 | pr_err("Failed to parse WDG method\n"); |
844af950 | 1087 | goto err_remove_busdev; |
bff431e4 CC |
1088 | } |
1089 | ||
c64eefd4 | 1090 | return 0; |
46492ee4 | 1091 | |
844af950 AL |
1092 | err_remove_busdev: |
1093 | device_unregister(wmi_bus_dev); | |
1094 | ||
46492ee4 AL |
1095 | err_remove_handler: |
1096 | acpi_remove_address_space_handler(device->handle, | |
1097 | ACPI_ADR_SPACE_EC, | |
1098 | &acpi_wmi_ec_space_handler); | |
1099 | ||
1100 | return error; | |
bff431e4 CC |
1101 | } |
1102 | ||
844af950 AL |
1103 | int __must_check __wmi_driver_register(struct wmi_driver *driver, |
1104 | struct module *owner) | |
1105 | { | |
1106 | driver->driver.owner = owner; | |
1107 | driver->driver.bus = &wmi_bus_type; | |
1108 | ||
1109 | return driver_register(&driver->driver); | |
1110 | } | |
1111 | EXPORT_SYMBOL(__wmi_driver_register); | |
1112 | ||
1113 | void wmi_driver_unregister(struct wmi_driver *driver) | |
1114 | { | |
1115 | driver_unregister(&driver->driver); | |
1116 | } | |
1117 | EXPORT_SYMBOL(wmi_driver_unregister); | |
1118 | ||
bff431e4 CC |
1119 | static int __init acpi_wmi_init(void) |
1120 | { | |
c64eefd4 | 1121 | int error; |
bff431e4 CC |
1122 | |
1123 | if (acpi_disabled) | |
1124 | return -ENODEV; | |
1125 | ||
844af950 | 1126 | error = class_register(&wmi_bus_class); |
c64eefd4 DT |
1127 | if (error) |
1128 | return error; | |
1caab3c1 | 1129 | |
844af950 AL |
1130 | error = bus_register(&wmi_bus_type); |
1131 | if (error) | |
1132 | goto err_unreg_class; | |
1133 | ||
c64eefd4 DT |
1134 | error = acpi_bus_register_driver(&acpi_wmi_driver); |
1135 | if (error) { | |
1136 | pr_err("Error loading mapper\n"); | |
844af950 | 1137 | goto err_unreg_bus; |
bff431e4 CC |
1138 | } |
1139 | ||
8e07514d | 1140 | return 0; |
844af950 AL |
1141 | |
1142 | err_unreg_class: | |
1143 | class_unregister(&wmi_bus_class); | |
1144 | ||
1145 | err_unreg_bus: | |
1146 | bus_unregister(&wmi_bus_type); | |
1147 | ||
1148 | return error; | |
bff431e4 CC |
1149 | } |
1150 | ||
1151 | static void __exit acpi_wmi_exit(void) | |
1152 | { | |
bff431e4 | 1153 | acpi_bus_unregister_driver(&acpi_wmi_driver); |
844af950 AL |
1154 | class_unregister(&wmi_bus_class); |
1155 | bus_unregister(&wmi_bus_type); | |
bff431e4 CC |
1156 | } |
1157 | ||
1158 | subsys_initcall(acpi_wmi_init); | |
1159 | module_exit(acpi_wmi_exit); |