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); |
Bjorn Helgaas | f61bb93 | 2009-04-07 15:37:37 +0000 | [diff] [blame] | 96 | static void acpi_wmi_notify(struct acpi_device *device, u32 event); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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 = { |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 106 | .name = "acpi-wmi", |
| 107 | .owner = THIS_MODULE, |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 108 | .ids = wmi_device_ids, |
| 109 | .ops = { |
| 110 | .add = acpi_wmi_add, |
| 111 | .remove = acpi_wmi_remove, |
Bjorn Helgaas | f61bb93 | 2009-04-07 15:37:37 +0000 | [diff] [blame] | 112 | .notify = acpi_wmi_notify, |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 113 | }, |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | /* |
| 117 | * GUID parsing functions |
| 118 | */ |
| 119 | |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 120 | static bool find_guid(const char *guid_string, struct wmi_block **out) |
| 121 | { |
Andy Shevchenko | 538d7eb | 2016-05-20 17:01:30 -0700 | [diff] [blame] | 122 | uuid_le guid_input; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 123 | struct wmi_block *wblock; |
| 124 | struct guid_block *block; |
| 125 | struct list_head *p; |
| 126 | |
Andy Shevchenko | 538d7eb | 2016-05-20 17:01:30 -0700 | [diff] [blame] | 127 | if (uuid_le_to_bin(guid_string, &guid_input)) |
| 128 | return false; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 129 | |
Dmitry Torokhov | 762e1a2 | 2010-08-26 00:15:14 -0700 | [diff] [blame] | 130 | list_for_each(p, &wmi_block_list) { |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 131 | wblock = list_entry(p, struct wmi_block, list); |
| 132 | block = &wblock->gblock; |
| 133 | |
Andy Shevchenko | 538d7eb | 2016-05-20 17:01:30 -0700 | [diff] [blame] | 134 | if (memcmp(block->guid, &guid_input, 16) == 0) { |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 135 | if (out) |
| 136 | *out = wblock; |
Joe Perches | 097c27f | 2015-03-30 10:43:20 -0700 | [diff] [blame] | 137 | return true; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
Joe Perches | 097c27f | 2015-03-30 10:43:20 -0700 | [diff] [blame] | 140 | return false; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Andy Lutomirski | d4fc91a | 2015-11-25 14:03:43 -0800 | [diff] [blame] | 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 | |
Matthew Garrett | a66bfa7 | 2008-10-08 21:40:32 +0100 | [diff] [blame] | 167 | static acpi_status wmi_method_enable(struct wmi_block *wblock, int enable) |
| 168 | { |
| 169 | struct guid_block *block = NULL; |
| 170 | char method[5]; |
Matthew Garrett | a66bfa7 | 2008-10-08 21:40:32 +0100 | [diff] [blame] | 171 | acpi_status status; |
| 172 | acpi_handle handle; |
| 173 | |
| 174 | block = &wblock->gblock; |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 175 | handle = wblock->acpi_device->handle; |
Matthew Garrett | a66bfa7 | 2008-10-08 21:40:32 +0100 | [diff] [blame] | 176 | |
Matthew Garrett | a66bfa7 | 2008-10-08 21:40:32 +0100 | [diff] [blame] | 177 | snprintf(method, 5, "WE%02X", block->notify_id); |
Zhang Rui | 8122ab66 | 2013-09-03 08:31:57 +0800 | [diff] [blame] | 178 | status = acpi_execute_simple_method(handle, method, enable); |
Matthew Garrett | a66bfa7 | 2008-10-08 21:40:32 +0100 | [diff] [blame] | 179 | |
| 180 | if (status != AE_OK && status != AE_NOT_FOUND) |
| 181 | return status; |
| 182 | else |
| 183 | return AE_OK; |
| 184 | } |
| 185 | |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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]; |
Costantino Leandro | f3d83e2 | 2009-08-26 14:29:28 -0700 | [diff] [blame] | 208 | char method[5] = "WM"; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 209 | |
| 210 | if (!find_guid(guid_string, &wblock)) |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 211 | return AE_ERROR; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 212 | |
| 213 | block = &wblock->gblock; |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 214 | handle = wblock->acpi_device->handle; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 215 | |
Al Viro | e6bafba | 2008-02-13 04:03:25 +0000 | [diff] [blame] | 216 | if (!(block->flags & ACPI_WMI_METHOD)) |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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; |
Zhang Rui | 54f14c2 | 2013-09-03 08:32:07 +0800 | [diff] [blame] | 262 | acpi_handle handle; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 263 | acpi_status status, wc_status = AE_ERROR; |
Zhang Rui | 8122ab66 | 2013-09-03 08:31:57 +0800 | [diff] [blame] | 264 | struct acpi_object_list input; |
| 265 | union acpi_object wq_params[1]; |
Costantino Leandro | f3d83e2 | 2009-08-26 14:29:28 -0700 | [diff] [blame] | 266 | char method[5]; |
| 267 | char wc_method[5] = "WC"; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 268 | |
| 269 | if (!guid_string || !out) |
| 270 | return AE_BAD_PARAMETER; |
| 271 | |
| 272 | if (!find_guid(guid_string, &wblock)) |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 273 | return AE_ERROR; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 274 | |
| 275 | block = &wblock->gblock; |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 276 | handle = wblock->acpi_device->handle; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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)) |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 283 | return AE_ERROR; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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 | |
Andy Lutomirski | d4fc91a | 2015-11-25 14:03:43 -0800 | [diff] [blame] | 290 | if (instance == 0 && wblock->read_takes_no_args) |
| 291 | input.count = 0; |
| 292 | |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 293 | /* |
| 294 | * If ACPI_WMI_EXPENSIVE, call the relevant WCxx method first to |
| 295 | * enable collection. |
| 296 | */ |
| 297 | if (block->flags & ACPI_WMI_EXPENSIVE) { |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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 | */ |
Zhang Rui | 54f14c2 | 2013-09-03 08:32:07 +0800 | [diff] [blame] | 305 | if (acpi_has_method(handle, wc_method)) |
Zhang Rui | 8122ab66 | 2013-09-03 08:31:57 +0800 | [diff] [blame] | 306 | wc_status = acpi_execute_simple_method(handle, |
| 307 | wc_method, 1); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | strcpy(method, "WQ"); |
| 311 | strncat(method, block->object_id, 2); |
| 312 | |
Carlos Corbacho | dab36ad | 2008-08-02 17:28:45 +0100 | [diff] [blame] | 313 | status = acpi_evaluate_object(handle, method, &input, out); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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 | */ |
Carlos Corbacho | a527f2d | 2008-02-24 13:34:34 +0000 | [diff] [blame] | 319 | if ((block->flags & ACPI_WMI_EXPENSIVE) && ACPI_SUCCESS(wc_status)) { |
Zhang Rui | 8122ab66 | 2013-09-03 08:31:57 +0800 | [diff] [blame] | 320 | status = acpi_execute_simple_method(handle, wc_method, 0); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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]; |
Costantino Leandro | f3d83e2 | 2009-08-26 14:29:28 -0700 | [diff] [blame] | 343 | char method[5] = "WS"; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 344 | |
| 345 | if (!guid_string || !in) |
| 346 | return AE_BAD_DATA; |
| 347 | |
| 348 | if (!find_guid(guid_string, &wblock)) |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 349 | return AE_ERROR; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 350 | |
| 351 | block = &wblock->gblock; |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 352 | handle = wblock->acpi_device->handle; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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)) |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 359 | return AE_ERROR; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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 | |
Dmitry Torokhov | 3783066 | 2010-08-26 00:15:09 -0700 | [diff] [blame] | 380 | static void wmi_dump_wdg(const struct guid_block *g) |
Thomas Renninger | a929aae | 2010-05-03 15:30:17 +0200 | [diff] [blame] | 381 | { |
Rasmus Villemoes | 85b4e4e | 2015-09-10 00:08:45 +0200 | [diff] [blame] | 382 | pr_info("%pUL:\n", g->guid); |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 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); |
Joe Perches | dd8e908 | 2011-03-29 15:21:53 -0700 | [diff] [blame] | 387 | pr_info("\tflags: %#x", g->flags); |
Thomas Renninger | a929aae | 2010-05-03 15:30:17 +0200 | [diff] [blame] | 388 | if (g->flags) { |
Thomas Renninger | a929aae | 2010-05-03 15:30:17 +0200 | [diff] [blame] | 389 | if (g->flags & ACPI_WMI_EXPENSIVE) |
Joe Perches | dd8e908 | 2011-03-29 15:21:53 -0700 | [diff] [blame] | 390 | pr_cont(" ACPI_WMI_EXPENSIVE"); |
Thomas Renninger | a929aae | 2010-05-03 15:30:17 +0200 | [diff] [blame] | 391 | if (g->flags & ACPI_WMI_METHOD) |
Joe Perches | dd8e908 | 2011-03-29 15:21:53 -0700 | [diff] [blame] | 392 | pr_cont(" ACPI_WMI_METHOD"); |
Thomas Renninger | a929aae | 2010-05-03 15:30:17 +0200 | [diff] [blame] | 393 | if (g->flags & ACPI_WMI_STRING) |
Joe Perches | dd8e908 | 2011-03-29 15:21:53 -0700 | [diff] [blame] | 394 | pr_cont(" ACPI_WMI_STRING"); |
Thomas Renninger | a929aae | 2010-05-03 15:30:17 +0200 | [diff] [blame] | 395 | if (g->flags & ACPI_WMI_EVENT) |
Joe Perches | dd8e908 | 2011-03-29 15:21:53 -0700 | [diff] [blame] | 396 | pr_cont(" ACPI_WMI_EVENT"); |
Thomas Renninger | a929aae | 2010-05-03 15:30:17 +0200 | [diff] [blame] | 397 | } |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 398 | pr_cont("\n"); |
Thomas Renninger | a929aae | 2010-05-03 15:30:17 +0200 | [diff] [blame] | 399 | |
| 400 | } |
| 401 | |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 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; |
Axel Lin | 1492616 | 2010-06-28 09:30:45 +0800 | [diff] [blame] | 406 | acpi_status status; |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 407 | |
Axel Lin | 1492616 | 2010-06-28 09:30:45 +0800 | [diff] [blame] | 408 | status = wmi_get_event_data(value, &response); |
| 409 | if (status != AE_OK) { |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 410 | pr_info("bad event status 0x%x\n", status); |
Axel Lin | 1492616 | 2010-06-28 09:30:45 +0800 | [diff] [blame] | 411 | return; |
| 412 | } |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 413 | |
| 414 | obj = (union acpi_object *)response.pointer; |
| 415 | |
| 416 | if (!obj) |
| 417 | return; |
| 418 | |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 419 | pr_info("DEBUG Event "); |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 420 | switch(obj->type) { |
| 421 | case ACPI_TYPE_BUFFER: |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 422 | pr_cont("BUFFER_TYPE - length %d\n", obj->buffer.length); |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 423 | break; |
| 424 | case ACPI_TYPE_STRING: |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 425 | pr_cont("STRING_TYPE - %s\n", obj->string.pointer); |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 426 | break; |
| 427 | case ACPI_TYPE_INTEGER: |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 428 | pr_cont("INTEGER_TYPE - %llu\n", obj->integer.value); |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 429 | break; |
| 430 | case ACPI_TYPE_PACKAGE: |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 431 | pr_cont("PACKAGE_TYPE - %d elements\n", obj->package.count); |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 432 | break; |
| 433 | default: |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 434 | pr_cont("object type 0x%X\n", obj->type); |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 435 | } |
Axel Lin | 1492616 | 2010-06-28 09:30:45 +0800 | [diff] [blame] | 436 | kfree(obj); |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 437 | } |
| 438 | |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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; |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 450 | acpi_status status = AE_NOT_EXIST; |
Andy Shevchenko | 538d7eb | 2016-05-20 17:01:30 -0700 | [diff] [blame] | 451 | uuid_le guid_input; |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 452 | struct list_head *p; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 453 | |
| 454 | if (!guid || !handler) |
| 455 | return AE_BAD_PARAMETER; |
| 456 | |
Andy Shevchenko | 538d7eb | 2016-05-20 17:01:30 -0700 | [diff] [blame] | 457 | if (uuid_le_to_bin(guid, &guid_input)) |
| 458 | return AE_BAD_PARAMETER; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 459 | |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 460 | list_for_each(p, &wmi_block_list) { |
| 461 | acpi_status wmi_status; |
| 462 | block = list_entry(p, struct wmi_block, list); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 463 | |
Andy Shevchenko | 538d7eb | 2016-05-20 17:01:30 -0700 | [diff] [blame] | 464 | if (memcmp(block->gblock.guid, &guid_input, 16) == 0) { |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 465 | if (block->handler && |
| 466 | block->handler != wmi_notify_debug) |
| 467 | return AE_ALREADY_ACQUIRED; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 468 | |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 469 | block->handler = handler; |
| 470 | block->handler_data = data; |
| 471 | |
| 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 | } |
Matthew Garrett | a66bfa7 | 2008-10-08 21:40:32 +0100 | [diff] [blame] | 478 | |
| 479 | return status; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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; |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 491 | acpi_status status = AE_NOT_EXIST; |
Andy Shevchenko | 538d7eb | 2016-05-20 17:01:30 -0700 | [diff] [blame] | 492 | uuid_le guid_input; |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 493 | struct list_head *p; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 494 | |
| 495 | if (!guid) |
| 496 | return AE_BAD_PARAMETER; |
| 497 | |
Andy Shevchenko | 538d7eb | 2016-05-20 17:01:30 -0700 | [diff] [blame] | 498 | if (uuid_le_to_bin(guid, &guid_input)) |
| 499 | return AE_BAD_PARAMETER; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 500 | |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 501 | list_for_each(p, &wmi_block_list) { |
| 502 | acpi_status wmi_status; |
| 503 | block = list_entry(p, struct wmi_block, list); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 504 | |
Andy Shevchenko | 538d7eb | 2016-05-20 17:01:30 -0700 | [diff] [blame] | 505 | if (memcmp(block->gblock.guid, &guid_input, 16) == 0) { |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 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 | } |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 523 | } |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 524 | |
Matthew Garrett | a66bfa7 | 2008-10-08 21:40:32 +0100 | [diff] [blame] | 525 | return status; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 526 | } |
| 527 | EXPORT_SYMBOL_GPL(wmi_remove_notify_handler); |
| 528 | |
| 529 | /** |
| 530 | * wmi_get_event_data - Get WMI data associated with an event |
| 531 | * |
Anisse Astier | 3e9b988 | 2009-12-04 10:10:09 +0100 | [diff] [blame] | 532 | * @event: Event to find |
| 533 | * @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] | 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 | |
Dmitry Torokhov | 762e1a2 | 2010-08-26 00:15:14 -0700 | [diff] [blame] | 550 | list_for_each(p, &wmi_block_list) { |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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)) |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 556 | return acpi_evaluate_object(wblock->acpi_device->handle, |
| 557 | "_WED", &input, out); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 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 | |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 586 | /* |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 587 | * sysfs interface |
| 588 | */ |
Dmitry Torokhov | 614ef43 | 2010-08-26 00:15:25 -0700 | [diff] [blame] | 589 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 590 | char *buf) |
| 591 | { |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 592 | struct wmi_block *wblock = dev_to_wblock(dev); |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 593 | |
Rasmus Villemoes | 85b4e4e | 2015-09-10 00:08:45 +0200 | [diff] [blame] | 594 | return sprintf(buf, "wmi:%pUL\n", wblock->gblock.guid); |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 595 | } |
Greg Kroah-Hartman | e80b89a | 2013-07-24 15:05:18 -0700 | [diff] [blame] | 596 | static DEVICE_ATTR_RO(modalias); |
Dmitry Torokhov | 614ef43 | 2010-08-26 00:15:25 -0700 | [diff] [blame] | 597 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 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 | |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | e80b89a | 2013-07-24 15:05:18 -0700 | [diff] [blame] | 626 | static struct attribute *wmi_attrs[] = { |
| 627 | &dev_attr_modalias.attr, |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 628 | &dev_attr_guid.attr, |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 629 | &dev_attr_instance_count.attr, |
| 630 | &dev_attr_expensive.attr, |
Greg Kroah-Hartman | e80b89a | 2013-07-24 15:05:18 -0700 | [diff] [blame] | 631 | NULL, |
Dmitry Torokhov | 614ef43 | 2010-08-26 00:15:25 -0700 | [diff] [blame] | 632 | }; |
Greg Kroah-Hartman | e80b89a | 2013-07-24 15:05:18 -0700 | [diff] [blame] | 633 | ATTRIBUTE_GROUPS(wmi); |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 634 | |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 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 | |
Andy Lutomirski | d4fc91a | 2015-11-25 14:03:43 -0800 | [diff] [blame] | 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[] = { |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 687 | &dev_attr_object_id.attr, |
| 688 | NULL, |
| 689 | }; |
Andy Lutomirski | d4fc91a | 2015-11-25 14:03:43 -0800 | [diff] [blame] | 690 | ATTRIBUTE_GROUPS(wmi_method); |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 691 | |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 692 | static int wmi_dev_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 693 | { |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 694 | struct wmi_block *wblock = dev_to_wblock(dev); |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 695 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 696 | if (add_uevent_var(env, "MODALIAS=wmi:%pUL", wblock->gblock.guid)) |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 697 | return -ENOMEM; |
| 698 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 699 | if (add_uevent_var(env, "WMI_GUID=%pUL", wblock->gblock.guid)) |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 700 | return -ENOMEM; |
| 701 | |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 702 | return 0; |
| 703 | } |
| 704 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 705 | static void wmi_dev_release(struct device *dev) |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 706 | { |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 707 | struct wmi_block *wblock = dev_to_wblock(dev); |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 708 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 709 | kfree(wblock); |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 710 | } |
| 711 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 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; |
| 718 | |
| 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 | } |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static int wmi_dev_probe(struct device *dev) |
| 734 | { |
| 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"); |
| 764 | |
| 765 | return ret; |
| 766 | } |
| 767 | |
| 768 | static struct class wmi_bus_class = { |
| 769 | .name = "wmi_bus", |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 770 | }; |
| 771 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 772 | static struct bus_type wmi_bus_type = { |
| 773 | .name = "wmi", |
| 774 | .dev_groups = wmi_groups, |
| 775 | .match = wmi_dev_match, |
| 776 | .uevent = wmi_dev_uevent, |
| 777 | .probe = wmi_dev_probe, |
| 778 | .remove = wmi_dev_remove, |
| 779 | }; |
| 780 | |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 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", |
Andy Lutomirski | d4fc91a | 2015-11-25 14:03:43 -0800 | [diff] [blame] | 789 | .groups = wmi_method_groups, |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 790 | .release = wmi_dev_release, |
| 791 | }; |
| 792 | |
| 793 | static struct device_type wmi_type_data = { |
| 794 | .name = "data", |
Andy Lutomirski | d4fc91a | 2015-11-25 14:03:43 -0800 | [diff] [blame] | 795 | .groups = wmi_data_groups, |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 796 | .release = wmi_dev_release, |
| 797 | }; |
| 798 | |
Darren Hart (VMware) | 6ee50aa | 2017-06-06 10:13:49 -0700 | [diff] [blame^] | 799 | static void wmi_create_device(struct device *wmi_bus_dev, |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 800 | const struct guid_block *gblock, |
Andy Lutomirski | 7f5809b | 2015-11-19 14:44:46 -0800 | [diff] [blame] | 801 | struct wmi_block *wblock, |
| 802 | struct acpi_device *device) |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 803 | { |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 804 | wblock->dev.dev.bus = &wmi_bus_type; |
| 805 | wblock->dev.dev.parent = wmi_bus_dev; |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 806 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 807 | dev_set_name(&wblock->dev.dev, "%pUL", gblock->guid); |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 808 | |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 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 { |
Andy Lutomirski | d4fc91a | 2015-11-25 14:03:43 -0800 | [diff] [blame] | 814 | struct acpi_device_info *info; |
| 815 | char method[5]; |
| 816 | int result; |
| 817 | |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 818 | wblock->dev.dev.type = &wmi_type_data; |
Andy Lutomirski | d4fc91a | 2015-11-25 14:03:43 -0800 | [diff] [blame] | 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 | |
Andy Lutomirski | d79b107 | 2015-11-25 10:01:37 -0800 | [diff] [blame] | 853 | } |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 854 | |
Darren Hart (VMware) | 6ee50aa | 2017-06-06 10:13:49 -0700 | [diff] [blame^] | 855 | device_initialize(&wblock->dev.dev); |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 856 | } |
| 857 | |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 858 | static void wmi_free_devices(struct acpi_device *device) |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 859 | { |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 860 | struct wmi_block *wblock, *next; |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 861 | |
| 862 | /* Delete devices for all the GUIDs */ |
Dmitry Torokhov | 023b956 | 2011-09-07 15:00:02 -0700 | [diff] [blame] | 863 | list_for_each_entry_safe(wblock, next, &wmi_block_list, list) { |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 864 | if (wblock->acpi_device == device) { |
| 865 | list_del(&wblock->list); |
Darren Hart (VMware) | 6ee50aa | 2017-06-06 10:13:49 -0700 | [diff] [blame^] | 866 | device_unregister(&wblock->dev.dev); |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 867 | } |
Dmitry Torokhov | 023b956 | 2011-09-07 15:00:02 -0700 | [diff] [blame] | 868 | } |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 869 | } |
| 870 | |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 871 | static bool guid_already_parsed(struct acpi_device *device, |
| 872 | const u8 *guid) |
Carlos Corbacho | d1f9e49 | 2009-12-26 19:14:59 +0000 | [diff] [blame] | 873 | { |
Carlos Corbacho | d1f9e49 | 2009-12-26 19:14:59 +0000 | [diff] [blame] | 874 | struct wmi_block *wblock; |
Carlos Corbacho | d1f9e49 | 2009-12-26 19:14:59 +0000 | [diff] [blame] | 875 | |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 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)); |
Carlos Corbacho | d1f9e49 | 2009-12-26 19:14:59 +0000 | [diff] [blame] | 886 | return true; |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 887 | } |
| 888 | } |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 889 | |
Carlos Corbacho | d1f9e49 | 2009-12-26 19:14:59 +0000 | [diff] [blame] | 890 | return false; |
| 891 | } |
| 892 | |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 893 | /* |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 894 | * Parse the _WDG method for the GUID data blocks |
| 895 | */ |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 896 | 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] | 897 | { |
| 898 | struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; |
Dmitry Torokhov | 3783066 | 2010-08-26 00:15:09 -0700 | [diff] [blame] | 899 | const struct guid_block *gblock; |
Darren Hart (VMware) | 6ee50aa | 2017-06-06 10:13:49 -0700 | [diff] [blame^] | 900 | struct wmi_block *wblock, *next; |
| 901 | union acpi_object *obj; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 902 | acpi_status status; |
Darren Hart (VMware) | 6ee50aa | 2017-06-06 10:13:49 -0700 | [diff] [blame^] | 903 | int retval = 0; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 904 | u32 i, total; |
| 905 | |
Andy Lutomirski | 7f5809b | 2015-11-19 14:44:46 -0800 | [diff] [blame] | 906 | status = acpi_evaluate_object(device->handle, "_WDG", NULL, &out); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 907 | if (ACPI_FAILURE(status)) |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 908 | return -ENXIO; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 909 | |
| 910 | obj = (union acpi_object *) out.pointer; |
Dmitry Torokhov | 3d2c63e | 2010-08-26 00:15:03 -0700 | [diff] [blame] | 911 | if (!obj) |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 912 | return -ENXIO; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 913 | |
Dmitry Torokhov | 64ed0ab | 2010-08-26 00:14:58 -0700 | [diff] [blame] | 914 | if (obj->type != ACPI_TYPE_BUFFER) { |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 915 | retval = -ENXIO; |
Dmitry Torokhov | 64ed0ab | 2010-08-26 00:14:58 -0700 | [diff] [blame] | 916 | goto out_free_pointer; |
| 917 | } |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 918 | |
Dmitry Torokhov | 3783066 | 2010-08-26 00:15:09 -0700 | [diff] [blame] | 919 | gblock = (const struct guid_block *)obj->buffer.pointer; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 920 | total = obj->buffer.length / sizeof(struct guid_block); |
| 921 | |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 922 | for (i = 0; i < total; i++) { |
Thomas Renninger | a929aae | 2010-05-03 15:30:17 +0200 | [diff] [blame] | 923 | if (debug_dump_wdg) |
| 924 | wmi_dump_wdg(&gblock[i]); |
| 925 | |
Andy Lutomirski | a1c31bcd | 2015-11-25 08:24:42 -0800 | [diff] [blame] | 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 | |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 935 | wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL); |
Darren Hart (VMware) | 6ee50aa | 2017-06-06 10:13:49 -0700 | [diff] [blame^] | 936 | if (!wblock) { |
| 937 | retval = -ENOMEM; |
| 938 | break; |
| 939 | } |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 940 | |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 941 | wblock->acpi_device = device; |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 942 | wblock->gblock = gblock[i]; |
| 943 | |
Darren Hart (VMware) | 6ee50aa | 2017-06-06 10:13:49 -0700 | [diff] [blame^] | 944 | wmi_create_device(wmi_bus_dev, &gblock[i], wblock, device); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 945 | |
Colin King | 58f6425 | 2010-11-19 15:40:02 +0000 | [diff] [blame] | 946 | list_add_tail(&wblock->list, &wmi_block_list); |
| 947 | |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 948 | if (debug_event) { |
| 949 | wblock->handler = wmi_notify_debug; |
Dmitry Torokhov | 2d5ab55 | 2010-08-26 00:14:48 -0700 | [diff] [blame] | 950 | wmi_method_enable(wblock, 1); |
Thomas Renninger | fc3155b | 2010-05-03 15:30:15 +0200 | [diff] [blame] | 951 | } |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Darren Hart (VMware) | 6ee50aa | 2017-06-06 10:13:49 -0700 | [diff] [blame^] | 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 | } |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 972 | |
Axel Lin | a5167c5 | 2010-06-03 11:45:45 +0800 | [diff] [blame] | 973 | out_free_pointer: |
| 974 | kfree(out.pointer); |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 975 | return retval; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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, |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 984 | u32 bits, u64 *value, |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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); |
Lin Ming | 439913f | 2010-01-28 10:53:19 +0800 | [diff] [blame] | 1001 | (*value) |= ((u64)temp) << i; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 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 | |
Bjorn Helgaas | f61bb93 | 2009-04-07 15:37:37 +0000 | [diff] [blame] | 1022 | static void acpi_wmi_notify(struct acpi_device *device, u32 event) |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1023 | { |
| 1024 | struct guid_block *block; |
| 1025 | struct wmi_block *wblock; |
| 1026 | struct list_head *p; |
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 | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 1032 | if (wblock->acpi_device == device && |
| 1033 | (block->flags & ACPI_WMI_EVENT) && |
| 1034 | (block->notify_id == event)) { |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1035 | if (wblock->handler) |
| 1036 | wblock->handler(event, wblock->handler_data); |
Thomas Renninger | 7715348c | 2010-05-03 15:30:16 +0200 | [diff] [blame] | 1037 | if (debug_event) { |
Rasmus Villemoes | 85b4e4e | 2015-09-10 00:08:45 +0200 | [diff] [blame] | 1038 | pr_info("DEBUG Event GUID: %pUL\n", |
| 1039 | wblock->gblock.guid); |
Thomas Renninger | 7715348c | 2010-05-03 15:30:16 +0200 | [diff] [blame] | 1040 | } |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1041 | |
| 1042 | acpi_bus_generate_netlink_event( |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 1043 | device->pnp.device_class, dev_name(&device->dev), |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1044 | event, 0); |
| 1045 | break; |
| 1046 | } |
| 1047 | } |
| 1048 | } |
| 1049 | |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 1050 | static int acpi_wmi_remove(struct acpi_device *device) |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1051 | { |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1052 | acpi_remove_address_space_handler(device->handle, |
| 1053 | ACPI_ADR_SPACE_EC, &acpi_wmi_ec_space_handler); |
Andy Lutomirski | b0e8630 | 2015-11-24 19:50:01 -0800 | [diff] [blame] | 1054 | wmi_free_devices(device); |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 1055 | device_unregister((struct device *)acpi_driver_data(device)); |
| 1056 | device->driver_data = NULL; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1057 | |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
Thomas Renninger | 925b108 | 2010-07-16 13:11:36 +0200 | [diff] [blame] | 1061 | static int acpi_wmi_add(struct acpi_device *device) |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1062 | { |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 1063 | struct device *wmi_bus_dev; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1064 | acpi_status status; |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 1065 | int error; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1066 | |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1067 | status = acpi_install_address_space_handler(device->handle, |
| 1068 | ACPI_ADR_SPACE_EC, |
| 1069 | &acpi_wmi_ec_space_handler, |
| 1070 | NULL, NULL); |
Dmitry Torokhov | 5212cd6 | 2010-08-26 00:14:42 -0700 | [diff] [blame] | 1071 | if (ACPI_FAILURE(status)) { |
Andy Lutomirski | 46492ee | 2015-11-24 19:54:46 -0800 | [diff] [blame] | 1072 | dev_err(&device->dev, "Error installing EC region handler\n"); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1073 | return -ENODEV; |
Dmitry Torokhov | 5212cd6 | 2010-08-26 00:14:42 -0700 | [diff] [blame] | 1074 | } |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1075 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 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); |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 1085 | if (error) { |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 1086 | pr_err("Failed to parse WDG method\n"); |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 1087 | goto err_remove_busdev; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 1090 | return 0; |
Andy Lutomirski | 46492ee | 2015-11-24 19:54:46 -0800 | [diff] [blame] | 1091 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 1092 | err_remove_busdev: |
| 1093 | device_unregister(wmi_bus_dev); |
| 1094 | |
Andy Lutomirski | 46492ee | 2015-11-24 19:54:46 -0800 | [diff] [blame] | 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; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 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 | |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1119 | static int __init acpi_wmi_init(void) |
| 1120 | { |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 1121 | int error; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1122 | |
| 1123 | if (acpi_disabled) |
| 1124 | return -ENODEV; |
| 1125 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 1126 | error = class_register(&wmi_bus_class); |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 1127 | if (error) |
| 1128 | return error; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1129 | |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 1130 | error = bus_register(&wmi_bus_type); |
| 1131 | if (error) |
| 1132 | goto err_unreg_class; |
| 1133 | |
Dmitry Torokhov | c64eefd | 2010-08-26 00:15:30 -0700 | [diff] [blame] | 1134 | error = acpi_bus_register_driver(&acpi_wmi_driver); |
| 1135 | if (error) { |
| 1136 | pr_err("Error loading mapper\n"); |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 1137 | goto err_unreg_bus; |
Matthew Garrett | 1caab3c | 2009-11-04 14:17:53 -0500 | [diff] [blame] | 1138 | } |
| 1139 | |
Dmitry Torokhov | 8e07514 | 2010-08-26 00:15:19 -0700 | [diff] [blame] | 1140 | return 0; |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 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; |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | static void __exit acpi_wmi_exit(void) |
| 1152 | { |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1153 | acpi_bus_unregister_driver(&acpi_wmi_driver); |
Andy Lutomirski | 844af95 | 2015-11-24 19:49:23 -0800 | [diff] [blame] | 1154 | class_unregister(&wmi_bus_class); |
| 1155 | bus_unregister(&wmi_bus_type); |
Carlos Corbacho | bff431e | 2008-02-05 02:17:04 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | subsys_initcall(acpi_wmi_init); |
| 1159 | module_exit(acpi_wmi_exit); |