Lines Matching +full:hart +full:- +full:3
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:
36 MODULE_DESCRIPTION("ACPI-WMI Mapping Driver");
84 #define ACPI_WMI_EVENT BIT(3) /* GUID is an event */
114 id = wdriver->id_table; in find_guid_context()
118 while (*id->guid_string) { in find_guid_context()
119 if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid)) in find_guid_context()
120 return id->context; in find_guid_context()
132 static_assert(ARRAY_SIZE(wblock->gblock.object_id) == 2); in get_acpi_method_name()
137 buffer[2] = wblock->gblock.object_id[0]; in get_acpi_method_name()
138 buffer[3] = wblock->gblock.object_id[1]; in get_acpi_method_name()
144 if (wblock->gblock.flags & ACPI_WMI_STRING) in get_param_acpi_type()
155 /* Legacy GUID-based functions are restricted to only see in wmidev_match_guid()
158 if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags)) in wmidev_match_guid()
161 if (guid_equal(guid, &wblock->gblock.guid)) in wmidev_match_guid()
180 if (!(wblock->gblock.flags & ACPI_WMI_EXPENSIVE)) in wmi_device_enable()
183 if (wblock->dev.dev.type == &wmi_type_method) in wmi_device_enable()
186 if (wblock->dev.dev.type == &wmi_type_event) in wmi_device_enable()
187 snprintf(method, sizeof(method), "WE%02X", wblock->gblock.notify_id); in wmi_device_enable()
196 status = acpi_get_handle(wblock->acpi_device->handle, method, &handle); in wmi_device_enable()
202 return -EIO; in wmi_device_enable()
219 return ERR_PTR(-ENODEV); in wmi_find_device_by_guid()
226 put_device(&wdev->dev); in wmi_device_put()
234 * wmi_instance_count - Get number of WMI object instances
235 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
258 * wmidev_instance_count - Get number of WMI object instances
269 return wblock->gblock.instance_count; in wmidev_instance_count()
274 * wmi_evaluate_method - Evaluate a WMI method (deprecated)
275 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
281 * Call an ACPI-WMI method, the caller must free @out.
304 * wmidev_evaluate_method - Evaluate a WMI method
311 * Call an ACPI-WMI method, the caller must free @out.
322 union acpi_object params[3]; in wmidev_evaluate_method()
326 block = &wblock->gblock; in wmidev_evaluate_method()
327 handle = wblock->acpi_device->handle; in wmidev_evaluate_method()
332 if (!(block->flags & ACPI_WMI_METHOD)) in wmidev_evaluate_method()
335 if (block->instance_count <= instance) in wmidev_evaluate_method()
338 input.count = 3; in wmidev_evaluate_method()
346 params[2].buffer.length = in->length; in wmidev_evaluate_method()
347 params[2].buffer.pointer = in->pointer; in wmidev_evaluate_method()
367 block = &wblock->gblock; in __query_block()
368 handle = wblock->acpi_device->handle; in __query_block()
370 if (block->instance_count <= instance) in __query_block()
374 if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD)) in __query_block()
382 if (instance == 0 && test_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags)) in __query_block()
391 * wmi_query_block - Return contents of a WMI block (deprecated)
392 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
396 * Query a ACPI-WMI block, the caller must free @out.
412 dev_warn(&wdev->dev, "Failed to enable device\n"); in wmi_query_block()
418 dev_warn(&wdev->dev, "Failed to disable device\n"); in wmi_query_block()
427 * wmidev_block_query - Return contents of a WMI block
431 * Query an ACPI-WMI block, the caller must free the result.
448 * wmi_set_block - Write to a WMI block (deprecated)
449 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
453 * Write the contents of the input buffer to an ACPI-WMI data block.
467 dev_warn(&wdev->dev, "Failed to enable device\n"); in wmi_set_block()
472 dev_warn(&wdev->dev, "Failed to disable device\n"); in wmi_set_block()
481 * wmidev_block_set - Write to a WMI block
486 * Write contents of the input buffer to an ACPI-WMI data block.
493 acpi_handle handle = wblock->acpi_device->handle; in wmidev_block_set()
494 struct guid_block *block = &wblock->gblock; in wmidev_block_set()
502 if (block->instance_count <= instance) in wmidev_block_set()
506 if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD)) in wmidev_block_set()
514 params[1].buffer.length = in->length; in wmidev_block_set()
515 params[1].buffer.pointer = in->pointer; in wmidev_block_set()
524 * wmi_install_notify_handler - Register handler for WMI events (deprecated)
525 * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
529 * Register a handler for events sent to the ACPI-WMI mapper device.
547 down_write(&wblock->notify_lock); in wmi_install_notify_handler()
548 if (wblock->handler) { in wmi_install_notify_handler()
551 wblock->handler = handler; in wmi_install_notify_handler()
552 wblock->handler_data = data; in wmi_install_notify_handler()
555 dev_warn(&wblock->dev.dev, "Failed to enable device\n"); in wmi_install_notify_handler()
559 up_write(&wblock->notify_lock); in wmi_install_notify_handler()
568 * wmi_remove_notify_handler - Unregister handler for WMI events (deprecated)
569 * @guid: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
571 * Unregister handler for events sent to the ACPI-WMI mapper device.
587 down_write(&wblock->notify_lock); in wmi_remove_notify_handler()
588 if (!wblock->handler) { in wmi_remove_notify_handler()
592 dev_warn(&wblock->dev.dev, "Failed to disable device\n"); in wmi_remove_notify_handler()
594 wblock->handler = NULL; in wmi_remove_notify_handler()
595 wblock->handler_data = NULL; in wmi_remove_notify_handler()
599 up_write(&wblock->notify_lock); in wmi_remove_notify_handler()
608 * wmi_has_guid - Check if a GUID is available
609 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
630 * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines GUID (deprecated)
631 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
648 uid = acpi_device_uid(wblock->acpi_device); in wmi_get_acpi_device_uid()
664 return sysfs_emit(buf, "wmi:%pUL\n", &wblock->gblock.guid); in modalias_show()
673 return sysfs_emit(buf, "%pUL\n", &wblock->gblock.guid); in guid_show()
682 return sysfs_emit(buf, "%d\n", (int)wblock->gblock.instance_count); in instance_count_show()
692 (wblock->gblock.flags & ACPI_WMI_EXPENSIVE) != 0); in expensive_show()
703 ret = sysfs_emit(buf, "%s\n", wdev->driver_override); in driver_override_show()
715 ret = driver_set_override(dev, &wdev->driver_override, buf, count); in driver_override_store()
738 return sysfs_emit(buf, "%02X\n", (unsigned int)wblock->gblock.notify_id); in notify_id_show()
753 return sysfs_emit(buf, "%c%c\n", wblock->gblock.object_id[0], in object_id_show()
754 wblock->gblock.object_id[1]); in object_id_show()
763 return sysfs_emit(buf, "%d\n", (int)wdev->setable); in setable_show()
784 if (add_uevent_var(env, "MODALIAS=wmi:%pUL", &wblock->gblock.guid)) in wmi_dev_uevent()
785 return -ENOMEM; in wmi_dev_uevent()
787 if (add_uevent_var(env, "WMI_GUID=%pUL", &wblock->gblock.guid)) in wmi_dev_uevent()
788 return -ENOMEM; in wmi_dev_uevent()
797 kfree(wblock->dev.driver_override); in wmi_dev_release()
805 const struct wmi_device_id *id = wmi_driver->id_table; in wmi_dev_match()
808 if (wblock->dev.driver_override) in wmi_dev_match()
809 return !strcmp(wblock->dev.driver_override, driver->name); in wmi_dev_match()
814 while (*id->guid_string) { in wmi_dev_match()
815 if (guid_parse_and_compare(id->guid_string, &wblock->gblock.guid)) in wmi_dev_match()
835 struct wmi_driver *wdriver = to_wmi_driver(dev->driver); in wmi_dev_probe()
843 if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) { in wmi_dev_probe()
845 dev->driver->name); in wmi_dev_probe()
847 return -ENODEV; in wmi_dev_probe()
850 if (wdriver->notify) { in wmi_dev_probe()
851 if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data) in wmi_dev_probe()
852 return -ENODEV; in wmi_dev_probe()
856 dev_warn(dev, "failed to enable device -- probing anyway\n"); in wmi_dev_probe()
859 * We have to make sure that all devres-managed resources are released first because in wmi_dev_probe()
866 if (wdriver->probe) { in wmi_dev_probe()
867 ret = wdriver->probe(to_wmi_device(dev), in wmi_dev_probe()
873 down_write(&wblock->notify_lock); in wmi_dev_probe()
874 wblock->driver_ready = true; in wmi_dev_probe()
875 up_write(&wblock->notify_lock); in wmi_dev_probe()
883 struct wmi_driver *wdriver = to_wmi_driver(dev->driver); in wmi_dev_remove()
885 down_write(&wblock->notify_lock); in wmi_dev_remove()
886 wblock->driver_ready = false; in wmi_dev_remove()
887 up_write(&wblock->notify_lock); in wmi_dev_remove()
889 if (wdriver->remove) in wmi_dev_remove()
890 wdriver->remove(to_wmi_device(dev)); in wmi_dev_remove()
898 if (dev->driver) { in wmi_dev_shutdown()
899 wdriver = to_wmi_driver(dev->driver); in wmi_dev_shutdown()
907 down_write(&wblock->notify_lock); in wmi_dev_shutdown()
908 wblock->driver_ready = false; in wmi_dev_shutdown()
909 up_write(&wblock->notify_lock); in wmi_dev_shutdown()
911 if (wdriver->shutdown) in wmi_dev_shutdown()
912 wdriver->shutdown(to_wmi_device(dev)); in wmi_dev_shutdown()
915 * We still need to disable the WMI device here since devres-managed resources in wmi_dev_shutdown()
960 if (guid_equal(&wblock->gblock.guid, context->guid)) in wmi_count_guids()
961 context->count++; in wmi_count_guids()
991 if (wblock->gblock.flags & ACPI_WMI_EVENT) { in wmi_create_device()
992 wblock->dev.dev.type = &wmi_type_event; in wmi_create_device()
996 if (wblock->gblock.flags & ACPI_WMI_METHOD) { in wmi_create_device()
998 if (!acpi_has_method(device->handle, method)) { in wmi_create_device()
1003 return -ENXIO; in wmi_create_device()
1006 wblock->dev.dev.type = &wmi_type_method; in wmi_create_device()
1016 status = acpi_get_handle(device->handle, method, &method_handle); in wmi_create_device()
1022 return -ENXIO; in wmi_create_device()
1027 return -EIO; in wmi_create_device()
1029 wblock->dev.dev.type = &wmi_type_data; in wmi_create_device()
1041 if (info->type != ACPI_TYPE_METHOD || info->param_count == 0) in wmi_create_device()
1042 set_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags); in wmi_create_device()
1047 if (acpi_has_method(device->handle, method)) in wmi_create_device()
1048 wblock->dev.setable = true; in wmi_create_device()
1051 init_rwsem(&wblock->notify_lock); in wmi_create_device()
1052 wblock->driver_ready = false; in wmi_create_device()
1053 wblock->dev.dev.bus = &wmi_bus_type; in wmi_create_device()
1054 wblock->dev.dev.parent = wmi_bus_dev; in wmi_create_device()
1056 count = guid_count(&wblock->gblock.guid); in wmi_create_device()
1061 dev_set_name(&wblock->dev.dev, "%pUL-%d", &wblock->gblock.guid, count); in wmi_create_device()
1062 set_bit(WMI_GUID_DUPLICATED, &wblock->flags); in wmi_create_device()
1064 dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid); in wmi_create_device()
1067 device_initialize(&wblock->dev.dev); in wmi_create_device()
1077 * Many aggregate WMI drivers do not use -EPROBE_DEFER when they in wmi_add_device()
1085 link = device_link_add(&wdev->dev, &pdev->dev, DL_FLAG_AUTOREMOVE_SUPPLIER); in wmi_add_device()
1087 return -EINVAL; in wmi_add_device()
1089 return device_add(&wdev->dev); in wmi_add_device()
1097 struct acpi_device *device = ACPI_COMPANION(&pdev->dev); in parse_wdg()
1107 status = acpi_evaluate_object(device->handle, "_WDG", NULL, &out); in parse_wdg()
1109 return -ENXIO; in parse_wdg()
1113 return -ENXIO; in parse_wdg()
1115 if (obj->type != ACPI_TYPE_BUFFER) { in parse_wdg()
1117 return -ENXIO; in parse_wdg()
1120 event_data_available = acpi_has_method(device->handle, "_WED"); in parse_wdg()
1121 gblock = (const struct guid_block *)obj->buffer.pointer; in parse_wdg()
1122 total = obj->buffer.length / sizeof(struct guid_block); in parse_wdg()
1134 wblock->acpi_device = device; in parse_wdg()
1135 wblock->gblock = gblock[i]; in parse_wdg()
1137 set_bit(WMI_NO_EVENT_DATA, &wblock->flags); in parse_wdg()
1145 retval = wmi_add_device(pdev, &wblock->dev); in parse_wdg()
1148 &wblock->gblock.guid); in parse_wdg()
1150 put_device(&wblock->dev.dev); in parse_wdg()
1165 .value = wblock->gblock.notify_id, in wmi_get_notify_data()
1174 status = acpi_evaluate_object(wblock->acpi_device->handle, "_WED", &input, &data); in wmi_get_notify_data()
1176 dev_warn(&wblock->dev.dev, "Failed to get event data\n"); in wmi_get_notify_data()
1177 return -EIO; in wmi_get_notify_data()
1187 struct wmi_driver *driver = to_wmi_driver(wblock->dev.dev.driver); in wmi_notify_driver()
1189 if (!obj && !driver->no_notify_data) { in wmi_notify_driver()
1190 dev_warn(&wblock->dev.dev, "Event contains no event data\n"); in wmi_notify_driver()
1194 if (driver->notify) in wmi_notify_driver()
1195 driver->notify(&wblock->dev, obj); in wmi_notify_driver()
1205 if (!(wblock->gblock.flags & ACPI_WMI_EVENT && wblock->gblock.notify_id == *event)) in wmi_notify_device()
1217 if (!test_bit(WMI_NO_EVENT_DATA, &wblock->flags)) { in wmi_notify_device()
1220 return -EIO; in wmi_notify_device()
1223 down_read(&wblock->notify_lock); in wmi_notify_device()
1225 if (wblock->dev.dev.driver && wblock->driver_ready) in wmi_notify_device()
1228 if (wblock->handler) in wmi_notify_device()
1229 wblock->handler(obj, wblock->handler_data); in wmi_notify_device()
1231 up_read(&wblock->notify_lock); in wmi_notify_device()
1235 acpi_bus_generate_netlink_event("wmi", acpi_dev_name(wblock->acpi_device), *event, 0); in wmi_notify_device()
1237 return -EBUSY; in wmi_notify_device()
1256 struct device *wmi_bus_device = dev_get_drvdata(&device->dev); in acpi_wmi_remove()
1265 acpi_remove_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, acpi_wmi_notify_handler); in acpi_wmi_remove_notify_handler()
1282 acpi_device = ACPI_COMPANION(&device->dev); in acpi_wmi_probe()
1284 dev_err(&device->dev, "ACPI companion is missing\n"); in acpi_wmi_probe()
1285 return -ENODEV; in acpi_wmi_probe()
1288 wmi_bus_dev = device_create(&wmi_bus_class, &device->dev, MKDEV(0, 0), NULL, "wmi_bus-%s", in acpi_wmi_probe()
1289 dev_name(&device->dev)); in acpi_wmi_probe()
1293 error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_bus_device, wmi_bus_dev); in acpi_wmi_probe()
1297 dev_set_drvdata(&device->dev, wmi_bus_dev); in acpi_wmi_probe()
1299 status = acpi_install_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, in acpi_wmi_probe()
1302 dev_err(&device->dev, "Error installing notify handler\n"); in acpi_wmi_probe()
1303 return -ENODEV; in acpi_wmi_probe()
1305 error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_notify_handler, in acpi_wmi_probe()
1312 dev_err(&device->dev, "Failed to parse _WDG method\n"); in acpi_wmi_probe()
1322 driver->driver.owner = owner; in __wmi_driver_register()
1323 driver->driver.bus = &wmi_bus_type; in __wmi_driver_register()
1325 return driver_register(&driver->driver); in __wmi_driver_register()
1330 * wmi_driver_unregister() - Unregister a WMI driver
1337 driver_unregister(&driver->driver); in wmi_driver_unregister()
1343 .name = "acpi-wmi",
1355 return -ENODEV; in acpi_wmi_init()