Lines Matching +full:per +full:- +full:hart
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ACPI-WMI mapping driver
5 * Copyright (C) 2007-2008 Carlos Corbacho <carlos@strangeworlds.co.uk>
9 * Copyright (c) 2001-2007 Anton Altaparmakov
12 * WMI bus infrastructure by Andrew Lutomirski and Darren Hart:
39 MODULE_DESCRIPTION("ACPI-WMI Mapping Driver");
107 "05901221-D566-11D1-B2F0-00A0C9062910", /* wmi-bmof */
127 if (guid_equal(&wblock->gblock.guid, &guid_input)) { in find_guid()
143 id = wdriver->id_table; in find_guid_context()
147 while (*id->guid_string) { in find_guid_context()
150 if (guid_parse(id->guid_string, &guid_input)) in find_guid_context()
152 if (guid_equal(&wblock->gblock.guid, &guid_input)) in find_guid_context()
153 return id->context; in find_guid_context()
168 return -ENOENT; in get_subobj_info()
170 return -EIO; in get_subobj_info()
175 return -EIO; in get_subobj_info()
190 block = &wblock->gblock; in wmi_method_enable()
191 handle = wblock->acpi_device->handle; in wmi_method_enable()
193 snprintf(method, 5, "WE%02X", block->notify_id); in wmi_method_enable()
207 static_assert(ARRAY_SIZE(wblock->gblock.object_id) == 2); in get_acpi_method_name()
212 buffer[2] = wblock->gblock.object_id[0]; in get_acpi_method_name()
213 buffer[3] = wblock->gblock.object_id[1]; in get_acpi_method_name()
219 if (wblock->gblock.flags & ACPI_WMI_STRING) in get_param_acpi_type()
230 .value = wblock->gblock.notify_id, in get_event_data()
238 return acpi_evaluate_object(wblock->acpi_device->handle, "_WED", &input, out); in get_event_data()
246 * set_required_buffer_size - Sets the buffer size needed for performing IOCTL
257 wblock->req_buf_size = length; in set_required_buffer_size()
264 * wmi_evaluate_method - Evaluate a WMI method
265 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
271 * Call an ACPI-WMI method
283 return wmidev_evaluate_method(&wblock->dev, instance, method_id, in wmi_evaluate_method()
289 * wmidev_evaluate_method - Evaluate a WMI method
296 * Call an ACPI-WMI method
309 block = &wblock->gblock; in wmidev_evaluate_method()
310 handle = wblock->acpi_device->handle; in wmidev_evaluate_method()
312 if (!(block->flags & ACPI_WMI_METHOD)) in wmidev_evaluate_method()
315 if (block->instance_count <= instance) in wmidev_evaluate_method()
329 params[2].buffer.length = in->length; in wmidev_evaluate_method()
330 params[2].buffer.pointer = in->pointer; in wmidev_evaluate_method()
353 block = &wblock->gblock; in __query_block()
354 handle = wblock->acpi_device->handle; in __query_block()
356 if (block->instance_count <= instance) in __query_block()
360 if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD)) in __query_block()
368 if (instance == 0 && test_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags)) in __query_block()
375 if (block->flags & ACPI_WMI_EXPENSIVE) { in __query_block()
391 * the WQxx method failed - we should disable collection anyway. in __query_block()
393 if ((block->flags & ACPI_WMI_EXPENSIVE) && ACPI_SUCCESS(wc_status)) { in __query_block()
408 * wmi_query_block - Return contents of a WMI block (deprecated)
409 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
413 * Return the contents of an ACPI-WMI data block to a buffer
442 * wmi_set_block - Write to a WMI block
443 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
447 * Write the contents of the input buffer to an ACPI-WMI data block
467 block = &wblock->gblock; in wmi_set_block()
468 handle = wblock->acpi_device->handle; in wmi_set_block()
470 if (block->instance_count <= instance) in wmi_set_block()
474 if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD)) in wmi_set_block()
482 params[1].buffer.length = in->length; in wmi_set_block()
483 params[1].buffer.pointer = in->pointer; in wmi_set_block()
493 pr_info("%pUL:\n", &g->guid); in wmi_dump_wdg()
494 if (g->flags & ACPI_WMI_EVENT) in wmi_dump_wdg()
495 pr_info("\tnotify_id: 0x%02X\n", g->notify_id); in wmi_dump_wdg()
497 pr_info("\tobject_id: %2pE\n", g->object_id); in wmi_dump_wdg()
498 pr_info("\tinstance_count: %d\n", g->instance_count); in wmi_dump_wdg()
499 pr_info("\tflags: %#x", g->flags); in wmi_dump_wdg()
500 if (g->flags) { in wmi_dump_wdg()
501 if (g->flags & ACPI_WMI_EXPENSIVE) in wmi_dump_wdg()
503 if (g->flags & ACPI_WMI_METHOD) in wmi_dump_wdg()
505 if (g->flags & ACPI_WMI_STRING) in wmi_dump_wdg()
507 if (g->flags & ACPI_WMI_EVENT) in wmi_dump_wdg()
531 switch (obj->type) { in wmi_notify_debug()
533 pr_cont("BUFFER_TYPE - length %u\n", obj->buffer.length); in wmi_notify_debug()
536 pr_cont("STRING_TYPE - %s\n", obj->string.pointer); in wmi_notify_debug()
539 pr_cont("INTEGER_TYPE - %llu\n", obj->integer.value); in wmi_notify_debug()
542 pr_cont("PACKAGE_TYPE - %u elements\n", obj->package.count); in wmi_notify_debug()
545 pr_cont("object type 0x%X\n", obj->type); in wmi_notify_debug()
551 * wmi_install_notify_handler - Register handler for WMI events
552 * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
556 * Register a handler for events sent to the ACPI-WMI mapper device.
575 if (guid_equal(&block->gblock.guid, &guid_input)) { in wmi_install_notify_handler()
576 if (block->handler && in wmi_install_notify_handler()
577 block->handler != wmi_notify_debug) in wmi_install_notify_handler()
580 block->handler = handler; in wmi_install_notify_handler()
581 block->handler_data = data; in wmi_install_notify_handler()
595 * wmi_remove_notify_handler - Unregister handler for WMI events
596 * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
598 * Unregister handler for events sent to the ACPI-WMI mapper device.
615 if (guid_equal(&block->gblock.guid, &guid_input)) { in wmi_remove_notify_handler()
616 if (!block->handler || in wmi_remove_notify_handler()
617 block->handler == wmi_notify_debug) in wmi_remove_notify_handler()
621 block->handler = wmi_notify_debug; in wmi_remove_notify_handler()
625 block->handler = NULL; in wmi_remove_notify_handler()
626 block->handler_data = NULL; in wmi_remove_notify_handler()
640 * wmi_get_event_data - Get WMI data associated with an event
643 * @out: Buffer to hold event data. out->pointer should be freed with kfree()
652 struct guid_block *gblock = &wblock->gblock; in wmi_get_event_data()
654 if ((gblock->flags & ACPI_WMI_EVENT) && gblock->notify_id == event) in wmi_get_event_data()
663 * wmi_has_guid - Check if a GUID is available
664 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
675 * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID
676 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
691 return acpi_device_uid(wblock->acpi_device); in wmi_get_acpi_device_uid()
718 return sysfs_emit(buf, "wmi:%pUL\n", &wblock->gblock.guid); in modalias_show()
727 return sysfs_emit(buf, "%pUL\n", &wblock->gblock.guid); in guid_show()
736 return sysfs_emit(buf, "%d\n", (int)wblock->gblock.instance_count); in instance_count_show()
746 (wblock->gblock.flags & ACPI_WMI_EXPENSIVE) != 0); in expensive_show()
764 return sysfs_emit(buf, "%02X\n", (unsigned int)wblock->gblock.notify_id); in notify_id_show()
779 return sysfs_emit(buf, "%c%c\n", wblock->gblock.object_id[0], in object_id_show()
780 wblock->gblock.object_id[1]); in object_id_show()
789 return sysfs_emit(buf, "%d\n", (int)wdev->setable); in setable_show()
810 if (add_uevent_var(env, "MODALIAS=wmi:%pUL", &wblock->gblock.guid)) in wmi_dev_uevent()
811 return -ENOMEM; in wmi_dev_uevent()
813 if (add_uevent_var(env, "WMI_GUID=%pUL", &wblock->gblock.guid)) in wmi_dev_uevent()
814 return -ENOMEM; in wmi_dev_uevent()
830 const struct wmi_device_id *id = wmi_driver->id_table; in wmi_dev_match()
835 while (*id->guid_string) { in wmi_dev_match()
838 if (WARN_ON(guid_parse(id->guid_string, &driver_guid))) in wmi_dev_match()
840 if (guid_equal(&driver_guid, &wblock->gblock.guid)) in wmi_dev_match()
850 const char *driver_name = filp->f_path.dentry->d_iname; in wmi_char_open()
855 if (!wblock->dev.dev.driver) in wmi_char_open()
857 if (strcmp(driver_name, wblock->dev.dev.driver->name) == 0) { in wmi_char_open()
858 filp->private_data = wblock; in wmi_char_open()
863 if (!filp->private_data) in wmi_char_open()
864 return -ENODEV; in wmi_char_open()
872 struct wmi_block *wblock = filp->private_data; in wmi_char_read()
875 &wblock->req_buf_size, in wmi_char_read()
876 sizeof(wblock->req_buf_size)); in wmi_char_read()
883 struct wmi_block *wblock = filp->private_data; in wmi_ioctl()
889 return -ENOTTY; in wmi_ioctl()
892 if (_IOC_NR(cmd) >= wblock->gblock.instance_count) in wmi_ioctl()
893 return -EINVAL; in wmi_ioctl()
895 mutex_lock(&wblock->char_mutex); in wmi_ioctl()
896 buf = wblock->handler_data; in wmi_ioctl()
897 if (get_user(buf->length, &input->length)) { in wmi_ioctl()
898 dev_dbg(&wblock->dev.dev, "Read length from user failed\n"); in wmi_ioctl()
899 ret = -EFAULT; in wmi_ioctl()
903 if (buf->length < wblock->req_buf_size) { in wmi_ioctl()
904 dev_err(&wblock->dev.dev, in wmi_ioctl()
906 buf->length, wblock->req_buf_size); in wmi_ioctl()
907 ret = -EINVAL; in wmi_ioctl()
911 if (buf->length > wblock->req_buf_size) in wmi_ioctl()
912 dev_warn(&wblock->dev.dev, in wmi_ioctl()
914 buf->length, wblock->req_buf_size); in wmi_ioctl()
917 if (copy_from_user(buf, input, wblock->req_buf_size)) { in wmi_ioctl()
918 dev_dbg(&wblock->dev.dev, "Copy %llu from user failed\n", in wmi_ioctl()
919 wblock->req_buf_size); in wmi_ioctl()
920 ret = -EFAULT; in wmi_ioctl()
925 wdriver = drv_to_wdrv(wblock->dev.dev.driver); in wmi_ioctl()
926 if (!try_module_get(wdriver->driver.owner)) { in wmi_ioctl()
927 ret = -EBUSY; in wmi_ioctl()
930 ret = wdriver->filter_callback(&wblock->dev, cmd, buf); in wmi_ioctl()
931 module_put(wdriver->driver.owner); in wmi_ioctl()
936 if (copy_to_user(input, buf, wblock->req_buf_size)) { in wmi_ioctl()
937 dev_dbg(&wblock->dev.dev, "Copy %llu to user failed\n", in wmi_ioctl()
938 wblock->req_buf_size); in wmi_ioctl()
939 ret = -EFAULT; in wmi_ioctl()
943 mutex_unlock(&wblock->char_mutex); in wmi_ioctl()
958 struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); in wmi_dev_probe()
963 dev_warn(dev, "failed to enable device -- probing anyway\n"); in wmi_dev_probe()
965 if (wdriver->probe) { in wmi_dev_probe()
966 ret = wdriver->probe(dev_to_wdev(dev), in wmi_dev_probe()
973 if (wdriver->filter_callback) { in wmi_dev_probe()
975 if (!wblock->req_buf_size) { in wmi_dev_probe()
976 dev_err(&wblock->dev.dev, in wmi_dev_probe()
978 ret = -EINVAL; in wmi_dev_probe()
982 wblock->handler_data = kmalloc(wblock->req_buf_size, in wmi_dev_probe()
984 if (!wblock->handler_data) { in wmi_dev_probe()
985 ret = -ENOMEM; in wmi_dev_probe()
989 buf = kasprintf(GFP_KERNEL, "wmi/%s", wdriver->driver.name); in wmi_dev_probe()
991 ret = -ENOMEM; in wmi_dev_probe()
994 wblock->char_dev.minor = MISC_DYNAMIC_MINOR; in wmi_dev_probe()
995 wblock->char_dev.name = buf; in wmi_dev_probe()
996 wblock->char_dev.fops = &wmi_fops; in wmi_dev_probe()
997 wblock->char_dev.mode = 0444; in wmi_dev_probe()
998 ret = misc_register(&wblock->char_dev); in wmi_dev_probe()
1001 ret = -ENOMEM; in wmi_dev_probe()
1006 set_bit(WMI_PROBED, &wblock->flags); in wmi_dev_probe()
1012 kfree(wblock->handler_data); in wmi_dev_probe()
1022 struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); in wmi_dev_remove()
1024 clear_bit(WMI_PROBED, &wblock->flags); in wmi_dev_remove()
1026 if (wdriver->filter_callback) { in wmi_dev_remove()
1027 misc_deregister(&wblock->char_dev); in wmi_dev_remove()
1028 kfree(wblock->char_dev.name); in wmi_dev_remove()
1029 kfree(wblock->handler_data); in wmi_dev_remove()
1032 if (wdriver->remove) in wmi_dev_remove()
1033 wdriver->remove(dev_to_wdev(dev)); in wmi_dev_remove()
1080 if (guid_equal(&wblock->gblock.guid, guid)) in guid_count()
1096 if (wblock->gblock.flags & ACPI_WMI_EVENT) { in wmi_create_device()
1097 wblock->dev.dev.type = &wmi_type_event; in wmi_create_device()
1101 if (wblock->gblock.flags & ACPI_WMI_METHOD) { in wmi_create_device()
1102 wblock->dev.dev.type = &wmi_type_method; in wmi_create_device()
1103 mutex_init(&wblock->char_mutex); in wmi_create_device()
1109 * required per the WMI documentation. If it is not present, in wmi_create_device()
1113 result = get_subobj_info(device->handle, method, &info); in wmi_create_device()
1122 wblock->dev.dev.type = &wmi_type_data; in wmi_create_device()
1134 if (info->type != ACPI_TYPE_METHOD || info->param_count == 0) in wmi_create_device()
1135 set_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags); in wmi_create_device()
1140 result = get_subobj_info(device->handle, method, NULL); in wmi_create_device()
1143 wblock->dev.setable = true; in wmi_create_device()
1146 wblock->dev.dev.bus = &wmi_bus_type; in wmi_create_device()
1147 wblock->dev.dev.parent = wmi_bus_dev; in wmi_create_device()
1149 count = guid_count(&wblock->gblock.guid); in wmi_create_device()
1151 dev_set_name(&wblock->dev.dev, "%pUL-%d", &wblock->gblock.guid, count); in wmi_create_device()
1153 dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid); in wmi_create_device()
1155 device_initialize(&wblock->dev.dev); in wmi_create_device()
1166 if (wblock->acpi_device == device) { in wmi_free_devices()
1167 list_del(&wblock->list); in wmi_free_devices()
1168 device_unregister(&wblock->dev.dev); in wmi_free_devices()
1187 if (guid_equal(&wblock->gblock.guid, guid)) { in guid_already_parsed_for_legacy()
1194 dev_warn(&device->dev, "duplicate WMI GUID %pUL (first instance was on %s)\n", in guid_already_parsed_for_legacy()
1195 guid, dev_name(&wblock->acpi_device->dev)); in guid_already_parsed_for_legacy()
1216 status = acpi_evaluate_object(device->handle, "_WDG", NULL, &out); in parse_wdg()
1218 return -ENXIO; in parse_wdg()
1222 return -ENXIO; in parse_wdg()
1224 if (obj->type != ACPI_TYPE_BUFFER) { in parse_wdg()
1225 retval = -ENXIO; in parse_wdg()
1229 gblock = (const struct guid_block *)obj->buffer.pointer; in parse_wdg()
1230 total = obj->buffer.length / sizeof(struct guid_block); in parse_wdg()
1241 retval = -ENOMEM; in parse_wdg()
1245 wblock->acpi_device = device; in parse_wdg()
1246 wblock->gblock = gblock[i]; in parse_wdg()
1254 list_add_tail(&wblock->list, &wmi_block_list); in parse_wdg()
1257 wblock->handler = wmi_notify_debug; in parse_wdg()
1267 if (wblock->acpi_device != device) in parse_wdg()
1270 retval = device_add(&wblock->dev.dev); in parse_wdg()
1273 &wblock->gblock.guid); in parse_wdg()
1276 list_del(&wblock->list); in parse_wdg()
1277 put_device(&wblock->dev.dev); in parse_wdg()
1316 case -EINVAL: in acpi_wmi_ec_space_handler()
1318 case -ENODEV: in acpi_wmi_ec_space_handler()
1320 case -ETIME: in acpi_wmi_ec_space_handler()
1333 struct guid_block *block = &iter->gblock; in acpi_wmi_notify_handler()
1335 if (iter->acpi_device->handle == handle && in acpi_wmi_notify_handler()
1336 (block->flags & ACPI_WMI_EVENT) && in acpi_wmi_notify_handler()
1337 (block->notify_id == event)) { in acpi_wmi_notify_handler()
1347 if (test_bit(WMI_PROBED, &wblock->flags) && wblock->dev.dev.driver) { in acpi_wmi_notify_handler()
1348 struct wmi_driver *driver = drv_to_wdrv(wblock->dev.dev.driver); in acpi_wmi_notify_handler()
1352 if (!driver->no_notify_data) { in acpi_wmi_notify_handler()
1355 dev_warn(&wblock->dev.dev, "failed to get event data\n"); in acpi_wmi_notify_handler()
1360 if (driver->notify) in acpi_wmi_notify_handler()
1361 driver->notify(&wblock->dev, evdata.pointer); in acpi_wmi_notify_handler()
1364 } else if (wblock->handler) { in acpi_wmi_notify_handler()
1366 wblock->handler(event, wblock->handler_data); in acpi_wmi_notify_handler()
1370 pr_info("DEBUG: GUID %pUL event 0x%02X\n", &wblock->gblock.guid, event); in acpi_wmi_notify_handler()
1373 wblock->acpi_device->pnp.device_class, in acpi_wmi_notify_handler()
1374 dev_name(&wblock->dev.dev), in acpi_wmi_notify_handler()
1380 struct acpi_device *acpi_device = ACPI_COMPANION(&device->dev); in acpi_wmi_remove()
1382 acpi_remove_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, in acpi_wmi_remove()
1384 acpi_remove_address_space_handler(acpi_device->handle, in acpi_wmi_remove()
1387 device_unregister(dev_get_drvdata(&device->dev)); in acpi_wmi_remove()
1399 acpi_device = ACPI_COMPANION(&device->dev); in acpi_wmi_probe()
1401 dev_err(&device->dev, "ACPI companion is missing\n"); in acpi_wmi_probe()
1402 return -ENODEV; in acpi_wmi_probe()
1405 status = acpi_install_address_space_handler(acpi_device->handle, in acpi_wmi_probe()
1410 dev_err(&device->dev, "Error installing EC region handler\n"); in acpi_wmi_probe()
1411 return -ENODEV; in acpi_wmi_probe()
1414 status = acpi_install_notify_handler(acpi_device->handle, in acpi_wmi_probe()
1419 dev_err(&device->dev, "Error installing notify handler\n"); in acpi_wmi_probe()
1420 error = -ENODEV; in acpi_wmi_probe()
1424 wmi_bus_dev = device_create(&wmi_bus_class, &device->dev, MKDEV(0, 0), in acpi_wmi_probe()
1425 NULL, "wmi_bus-%s", dev_name(&device->dev)); in acpi_wmi_probe()
1430 dev_set_drvdata(&device->dev, wmi_bus_dev); in acpi_wmi_probe()
1444 acpi_remove_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, in acpi_wmi_probe()
1448 acpi_remove_address_space_handler(acpi_device->handle, in acpi_wmi_probe()
1458 driver->driver.owner = owner; in __wmi_driver_register()
1459 driver->driver.bus = &wmi_bus_type; in __wmi_driver_register()
1461 return driver_register(&driver->driver); in __wmi_driver_register()
1467 driver_unregister(&driver->driver); in wmi_driver_unregister()
1473 .name = "acpi-wmi",
1485 return -ENODEV; in acpi_wmi_init()