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