Lines Matching +full:hart +full:- +full:index +full:- +full:bits
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:
20 #include <linux/bits.h>
37 MODULE_DESCRIPTION("ACPI-WMI Mapping Driver");
115 id = wdriver->id_table; in find_guid_context()
119 while (*id->guid_string) { in find_guid_context()
120 if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid)) in find_guid_context()
121 return id->context; in find_guid_context()
134 block = &wblock->gblock; in wmi_method_enable()
135 handle = wblock->acpi_device->handle; in wmi_method_enable()
137 snprintf(method, 5, "WE%02X", block->notify_id); in wmi_method_enable()
151 static_assert(ARRAY_SIZE(wblock->gblock.object_id) == 2); in get_acpi_method_name()
156 buffer[2] = wblock->gblock.object_id[0]; in get_acpi_method_name()
157 buffer[3] = wblock->gblock.object_id[1]; in get_acpi_method_name()
163 if (wblock->gblock.flags & ACPI_WMI_STRING) in get_param_acpi_type()
174 /* Legacy GUID-based functions are restricted to only see in wmidev_match_guid()
177 if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags)) in wmidev_match_guid()
180 if (guid_equal(guid, &wblock->gblock.guid)) in wmidev_match_guid()
200 return ERR_PTR(-ENODEV); in wmi_find_device_by_guid()
207 put_device(&wdev->dev); in wmi_device_put()
215 * wmi_instance_count - Get number of WMI object instances
216 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
239 * wmidev_instance_count - Get number of WMI object instances
250 return wblock->gblock.instance_count; in wmidev_instance_count()
255 * wmi_evaluate_method - Evaluate a WMI method (deprecated)
256 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
257 * @instance: Instance index
262 * Call an ACPI-WMI method, the caller must free @out.
285 * wmidev_evaluate_method - Evaluate a WMI method
287 * @instance: Instance index
292 * Call an ACPI-WMI method, the caller must free @out.
307 block = &wblock->gblock; in wmidev_evaluate_method()
308 handle = wblock->acpi_device->handle; in wmidev_evaluate_method()
313 if (!(block->flags & ACPI_WMI_METHOD)) in wmidev_evaluate_method()
316 if (block->instance_count <= instance) in wmidev_evaluate_method()
327 params[2].buffer.length = in->length; in wmidev_evaluate_method()
328 params[2].buffer.pointer = in->pointer; in wmidev_evaluate_method()
350 block = &wblock->gblock; in __query_block()
351 handle = wblock->acpi_device->handle; in __query_block()
353 if (block->instance_count <= instance) in __query_block()
357 if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD)) in __query_block()
365 if (instance == 0 && test_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags)) in __query_block()
372 if (block->flags & ACPI_WMI_EXPENSIVE) { in __query_block()
388 * the WQxx method failed - we should disable collection anyway. in __query_block()
390 if ((block->flags & ACPI_WMI_EXPENSIVE) && ACPI_SUCCESS(wc_status)) { in __query_block()
405 * wmi_query_block - Return contents of a WMI block (deprecated)
406 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
407 * @instance: Instance index
410 * Query a ACPI-WMI block, the caller must free @out.
435 * wmidev_block_query - Return contents of a WMI block
437 * @instance: Instance index
439 * Query an ACPI-WMI block, the caller must free the result.
456 * wmi_set_block - Write to a WMI block (deprecated)
457 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
458 * @instance: Instance index
461 * Write the contents of the input buffer to an ACPI-WMI data block.
482 * wmidev_block_set - Write to a WMI block
484 * @instance: Instance index
487 * Write contents of the input buffer to an ACPI-WMI data block.
494 acpi_handle handle = wblock->acpi_device->handle; in wmidev_block_set()
495 struct guid_block *block = &wblock->gblock; in wmidev_block_set()
503 if (block->instance_count <= instance) in wmidev_block_set()
507 if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD)) in wmidev_block_set()
515 params[1].buffer.length = in->length; in wmidev_block_set()
516 params[1].buffer.pointer = in->pointer; in wmidev_block_set()
525 * wmi_install_notify_handler - Register handler for WMI events (deprecated)
526 * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
530 * Register a handler for events sent to the ACPI-WMI mapper device.
548 down_write(&wblock->notify_lock); in wmi_install_notify_handler()
549 if (wblock->handler) { in wmi_install_notify_handler()
552 wblock->handler = handler; in wmi_install_notify_handler()
553 wblock->handler_data = data; in wmi_install_notify_handler()
556 dev_warn(&wblock->dev.dev, "Failed to enable device\n"); in wmi_install_notify_handler()
560 up_write(&wblock->notify_lock); in wmi_install_notify_handler()
569 * wmi_remove_notify_handler - Unregister handler for WMI events (deprecated)
570 * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
572 * Unregister handler for events sent to the ACPI-WMI mapper device.
588 down_write(&wblock->notify_lock); in wmi_remove_notify_handler()
589 if (!wblock->handler) { in wmi_remove_notify_handler()
593 dev_warn(&wblock->dev.dev, "Failed to disable device\n"); in wmi_remove_notify_handler()
595 wblock->handler = NULL; in wmi_remove_notify_handler()
596 wblock->handler_data = NULL; in wmi_remove_notify_handler()
600 up_write(&wblock->notify_lock); in wmi_remove_notify_handler()
609 * wmi_has_guid - Check if a GUID is available
610 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
631 * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID (deprecated)
632 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
649 uid = acpi_device_uid(wblock->acpi_device); in wmi_get_acpi_device_uid()
667 return sysfs_emit(buf, "wmi:%pUL\n", &wblock->gblock.guid); in modalias_show()
676 return sysfs_emit(buf, "%pUL\n", &wblock->gblock.guid); in guid_show()
685 return sysfs_emit(buf, "%d\n", (int)wblock->gblock.instance_count); in instance_count_show()
695 (wblock->gblock.flags & ACPI_WMI_EXPENSIVE) != 0); in expensive_show()
706 ret = sysfs_emit(buf, "%s\n", wdev->driver_override); in driver_override_show()
718 ret = driver_set_override(dev, &wdev->driver_override, buf, count); in driver_override_store()
741 return sysfs_emit(buf, "%02X\n", (unsigned int)wblock->gblock.notify_id); in notify_id_show()
756 return sysfs_emit(buf, "%c%c\n", wblock->gblock.object_id[0], in object_id_show()
757 wblock->gblock.object_id[1]); in object_id_show()
766 return sysfs_emit(buf, "%d\n", (int)wdev->setable); in setable_show()
787 if (add_uevent_var(env, "MODALIAS=wmi:%pUL", &wblock->gblock.guid)) in wmi_dev_uevent()
788 return -ENOMEM; in wmi_dev_uevent()
790 if (add_uevent_var(env, "WMI_GUID=%pUL", &wblock->gblock.guid)) in wmi_dev_uevent()
791 return -ENOMEM; in wmi_dev_uevent()
800 kfree(wblock->dev.driver_override); in wmi_dev_release()
808 const struct wmi_device_id *id = wmi_driver->id_table; in wmi_dev_match()
811 if (wblock->dev.driver_override) in wmi_dev_match()
812 return !strcmp(wblock->dev.driver_override, driver->name); in wmi_dev_match()
817 while (*id->guid_string) { in wmi_dev_match()
818 if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid)) in wmi_dev_match()
830 struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); in wmi_dev_probe()
838 if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) { in wmi_dev_probe()
840 dev->driver->name); in wmi_dev_probe()
842 return -ENODEV; in wmi_dev_probe()
845 if (wdriver->notify) { in wmi_dev_probe()
846 if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data) in wmi_dev_probe()
847 return -ENODEV; in wmi_dev_probe()
851 dev_warn(dev, "failed to enable device -- probing anyway\n"); in wmi_dev_probe()
853 if (wdriver->probe) { in wmi_dev_probe()
854 ret = wdriver->probe(dev_to_wdev(dev), in wmi_dev_probe()
864 down_write(&wblock->notify_lock); in wmi_dev_probe()
865 wblock->driver_ready = true; in wmi_dev_probe()
866 up_write(&wblock->notify_lock); in wmi_dev_probe()
874 struct wmi_driver *wdriver = drv_to_wdrv(dev->driver); in wmi_dev_remove()
876 down_write(&wblock->notify_lock); in wmi_dev_remove()
877 wblock->driver_ready = false; in wmi_dev_remove()
878 up_write(&wblock->notify_lock); in wmi_dev_remove()
880 if (wdriver->remove) in wmi_dev_remove()
881 wdriver->remove(dev_to_wdev(dev)); in wmi_dev_remove()
928 if (guid_equal(&wblock->gblock.guid, guid)) in guid_count()
945 if (wblock->gblock.flags & ACPI_WMI_EVENT) { in wmi_create_device()
946 wblock->dev.dev.type = &wmi_type_event; in wmi_create_device()
950 if (wblock->gblock.flags & ACPI_WMI_METHOD) { in wmi_create_device()
952 if (!acpi_has_method(device->handle, method)) { in wmi_create_device()
957 return -ENXIO; in wmi_create_device()
960 wblock->dev.dev.type = &wmi_type_method; in wmi_create_device()
970 status = acpi_get_handle(device->handle, method, &method_handle); in wmi_create_device()
976 return -ENXIO; in wmi_create_device()
981 return -EIO; in wmi_create_device()
983 wblock->dev.dev.type = &wmi_type_data; in wmi_create_device()
995 if (info->type != ACPI_TYPE_METHOD || info->param_count == 0) in wmi_create_device()
996 set_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags); in wmi_create_device()
1001 if (acpi_has_method(device->handle, method)) in wmi_create_device()
1002 wblock->dev.setable = true; in wmi_create_device()
1005 init_rwsem(&wblock->notify_lock); in wmi_create_device()
1006 wblock->driver_ready = false; in wmi_create_device()
1007 wblock->dev.dev.bus = &wmi_bus_type; in wmi_create_device()
1008 wblock->dev.dev.parent = wmi_bus_dev; in wmi_create_device()
1010 count = guid_count(&wblock->gblock.guid); in wmi_create_device()
1012 dev_set_name(&wblock->dev.dev, "%pUL-%d", &wblock->gblock.guid, count); in wmi_create_device()
1013 set_bit(WMI_GUID_DUPLICATED, &wblock->flags); in wmi_create_device()
1015 dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid); in wmi_create_device()
1018 device_initialize(&wblock->dev.dev); in wmi_create_device()
1028 * Many aggregate WMI drivers do not use -EPROBE_DEFER when they in wmi_add_device()
1036 link = device_link_add(&wdev->dev, &pdev->dev, DL_FLAG_AUTOREMOVE_SUPPLIER); in wmi_add_device()
1038 return -EINVAL; in wmi_add_device()
1040 return device_add(&wdev->dev); in wmi_add_device()
1048 struct acpi_device *device = ACPI_COMPANION(&pdev->dev); in parse_wdg()
1058 status = acpi_evaluate_object(device->handle, "_WDG", NULL, &out); in parse_wdg()
1060 return -ENXIO; in parse_wdg()
1064 return -ENXIO; in parse_wdg()
1066 if (obj->type != ACPI_TYPE_BUFFER) { in parse_wdg()
1068 return -ENXIO; in parse_wdg()
1071 event_data_available = acpi_has_method(device->handle, "_WED"); in parse_wdg()
1072 gblock = (const struct guid_block *)obj->buffer.pointer; in parse_wdg()
1073 total = obj->buffer.length / sizeof(struct guid_block); in parse_wdg()
1085 wblock->acpi_device = device; in parse_wdg()
1086 wblock->gblock = gblock[i]; in parse_wdg()
1088 set_bit(WMI_NO_EVENT_DATA, &wblock->flags); in parse_wdg()
1096 list_add_tail(&wblock->list, &wmi_block_list); in parse_wdg()
1098 retval = wmi_add_device(pdev, &wblock->dev); in parse_wdg()
1101 &wblock->gblock.guid); in parse_wdg()
1103 list_del(&wblock->list); in parse_wdg()
1104 put_device(&wblock->dev.dev); in parse_wdg()
1119 .value = wblock->gblock.notify_id, in wmi_get_notify_data()
1128 status = acpi_evaluate_object(wblock->acpi_device->handle, "_WED", &input, &data); in wmi_get_notify_data()
1130 dev_warn(&wblock->dev.dev, "Failed to get event data\n"); in wmi_get_notify_data()
1131 return -EIO; in wmi_get_notify_data()
1141 struct wmi_driver *driver = drv_to_wdrv(wblock->dev.dev.driver); in wmi_notify_driver()
1143 if (!obj && !driver->no_notify_data) { in wmi_notify_driver()
1144 dev_warn(&wblock->dev.dev, "Event contains no event data\n"); in wmi_notify_driver()
1148 if (driver->notify) in wmi_notify_driver()
1149 driver->notify(&wblock->dev, obj); in wmi_notify_driver()
1159 if (!(wblock->gblock.flags & ACPI_WMI_EVENT && wblock->gblock.notify_id == *event)) in wmi_notify_device()
1171 if (!test_bit(WMI_NO_EVENT_DATA, &wblock->flags)) { in wmi_notify_device()
1174 return -EIO; in wmi_notify_device()
1177 down_read(&wblock->notify_lock); in wmi_notify_device()
1179 if (wblock->dev.dev.driver && wblock->driver_ready) in wmi_notify_device()
1182 if (wblock->handler) in wmi_notify_device()
1183 wblock->handler(obj, wblock->handler_data); in wmi_notify_device()
1185 up_read(&wblock->notify_lock); in wmi_notify_device()
1189 acpi_bus_generate_netlink_event("wmi", acpi_dev_name(wblock->acpi_device), *event, 0); in wmi_notify_device()
1191 return -EBUSY; in wmi_notify_device()
1205 list_del(&wblock->list); in wmi_remove_device()
1213 struct device *wmi_bus_device = dev_get_drvdata(&device->dev); in acpi_wmi_remove()
1222 acpi_remove_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, acpi_wmi_notify_handler); in acpi_wmi_remove_notify_handler()
1239 acpi_device = ACPI_COMPANION(&device->dev); in acpi_wmi_probe()
1241 dev_err(&device->dev, "ACPI companion is missing\n"); in acpi_wmi_probe()
1242 return -ENODEV; in acpi_wmi_probe()
1245 wmi_bus_dev = device_create(&wmi_bus_class, &device->dev, MKDEV(0, 0), NULL, "wmi_bus-%s", in acpi_wmi_probe()
1246 dev_name(&device->dev)); in acpi_wmi_probe()
1250 error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_bus_device, wmi_bus_dev); in acpi_wmi_probe()
1254 dev_set_drvdata(&device->dev, wmi_bus_dev); in acpi_wmi_probe()
1256 status = acpi_install_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, in acpi_wmi_probe()
1259 dev_err(&device->dev, "Error installing notify handler\n"); in acpi_wmi_probe()
1260 return -ENODEV; in acpi_wmi_probe()
1262 error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_notify_handler, in acpi_wmi_probe()
1269 dev_err(&device->dev, "Failed to parse _WDG method\n"); in acpi_wmi_probe()
1279 driver->driver.owner = owner; in __wmi_driver_register()
1280 driver->driver.bus = &wmi_bus_type; in __wmi_driver_register()
1282 return driver_register(&driver->driver); in __wmi_driver_register()
1287 * wmi_driver_unregister() - Unregister a WMI driver
1294 driver_unregister(&driver->driver); in wmi_driver_unregister()
1300 .name = "acpi-wmi",
1312 return -ENODEV; in acpi_wmi_init()