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:
36 MODULE_DESCRIPTION("ACPI-WMI Mapping Driver");
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()
133 block = &wblock->gblock; in wmi_method_enable()
134 handle = wblock->acpi_device->handle; in wmi_method_enable()
136 snprintf(method, 5, "WE%02X", block->notify_id); in wmi_method_enable()
150 static_assert(ARRAY_SIZE(wblock->gblock.object_id) == 2); in get_acpi_method_name()
155 buffer[2] = wblock->gblock.object_id[0]; in get_acpi_method_name()
156 buffer[3] = wblock->gblock.object_id[1]; in get_acpi_method_name()
162 if (wblock->gblock.flags & ACPI_WMI_STRING) in get_param_acpi_type()
173 /* Legacy GUID-based functions are restricted to only see in wmidev_match_guid()
176 if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags)) in wmidev_match_guid()
179 if (guid_equal(guid, &wblock->gblock.guid)) in wmidev_match_guid()
199 return ERR_PTR(-ENODEV); in wmi_find_device_by_guid()
206 put_device(&wdev->dev); in wmi_device_put()
214 * wmi_instance_count - Get number of WMI object instances
215 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
238 * wmidev_instance_count - Get number of WMI object instances
249 return wblock->gblock.instance_count; in wmidev_instance_count()
254 * wmi_evaluate_method - Evaluate a WMI method (deprecated)
255 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
261 * Call an ACPI-WMI method, the caller must free @out.
284 * wmidev_evaluate_method - Evaluate a WMI method
291 * Call an ACPI-WMI method, the caller must free @out.
306 block = &wblock->gblock; in wmidev_evaluate_method()
307 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()
326 params[2].buffer.length = in->length; in wmidev_evaluate_method()
327 params[2].buffer.pointer = in->pointer; in wmidev_evaluate_method()
349 block = &wblock->gblock; in __query_block()
350 handle = wblock->acpi_device->handle; in __query_block()
352 if (block->instance_count <= instance) in __query_block()
356 if (block->flags & (ACPI_WMI_EVENT | ACPI_WMI_METHOD)) in __query_block()
364 if (instance == 0 && test_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags)) in __query_block()
371 if (block->flags & ACPI_WMI_EXPENSIVE) { in __query_block()
387 * the WQxx method failed - we should disable collection anyway. in __query_block()
389 if ((block->flags & ACPI_WMI_EXPENSIVE) && ACPI_SUCCESS(wc_status)) { in __query_block()
404 * wmi_query_block - Return contents of a WMI block (deprecated)
405 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
409 * Query a ACPI-WMI block, the caller must free @out.
434 * wmidev_block_query - Return contents of a WMI block
438 * Query an ACPI-WMI block, the caller must free the result.
455 * wmi_set_block - Write to a WMI block (deprecated)
456 * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
460 * Write the contents of the input buffer to an ACPI-WMI data 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()
827 struct wmi_driver *wdriver = to_wmi_driver(dev->driver); in wmi_dev_probe()
835 if (test_bit(WMI_GUID_DUPLICATED, &wblock->flags) && !wdriver->no_singleton) { in wmi_dev_probe()
837 dev->driver->name); in wmi_dev_probe()
839 return -ENODEV; in wmi_dev_probe()
842 if (wdriver->notify) { in wmi_dev_probe()
843 if (test_bit(WMI_NO_EVENT_DATA, &wblock->flags) && !wdriver->no_notify_data) in wmi_dev_probe()
844 return -ENODEV; in wmi_dev_probe()
848 dev_warn(dev, "failed to enable device -- probing anyway\n"); in wmi_dev_probe()
850 if (wdriver->probe) { in wmi_dev_probe()
851 ret = wdriver->probe(to_wmi_device(dev), in wmi_dev_probe()
861 down_write(&wblock->notify_lock); in wmi_dev_probe()
862 wblock->driver_ready = true; in wmi_dev_probe()
863 up_write(&wblock->notify_lock); in wmi_dev_probe()
871 struct wmi_driver *wdriver = to_wmi_driver(dev->driver); in wmi_dev_remove()
873 down_write(&wblock->notify_lock); in wmi_dev_remove()
874 wblock->driver_ready = false; in wmi_dev_remove()
875 up_write(&wblock->notify_lock); in wmi_dev_remove()
877 if (wdriver->remove) in wmi_dev_remove()
878 wdriver->remove(to_wmi_device(dev)); in wmi_dev_remove()
889 if (dev->driver) { in wmi_dev_shutdown()
890 wdriver = to_wmi_driver(dev->driver); in wmi_dev_shutdown()
898 down_write(&wblock->notify_lock); in wmi_dev_shutdown()
899 wblock->driver_ready = false; in wmi_dev_shutdown()
900 up_write(&wblock->notify_lock); in wmi_dev_shutdown()
902 if (wdriver->shutdown) in wmi_dev_shutdown()
903 wdriver->shutdown(to_wmi_device(dev)); in wmi_dev_shutdown()
947 if (guid_equal(&wblock->gblock.guid, context->guid)) in wmi_count_guids()
948 context->count++; in wmi_count_guids()
978 if (wblock->gblock.flags & ACPI_WMI_EVENT) { in wmi_create_device()
979 wblock->dev.dev.type = &wmi_type_event; in wmi_create_device()
983 if (wblock->gblock.flags & ACPI_WMI_METHOD) { in wmi_create_device()
985 if (!acpi_has_method(device->handle, method)) { in wmi_create_device()
990 return -ENXIO; in wmi_create_device()
993 wblock->dev.dev.type = &wmi_type_method; in wmi_create_device()
999 * required per the WMI documentation. If it is not present, in wmi_create_device()
1003 status = acpi_get_handle(device->handle, method, &method_handle); in wmi_create_device()
1009 return -ENXIO; in wmi_create_device()
1014 return -EIO; in wmi_create_device()
1016 wblock->dev.dev.type = &wmi_type_data; in wmi_create_device()
1028 if (info->type != ACPI_TYPE_METHOD || info->param_count == 0) in wmi_create_device()
1029 set_bit(WMI_READ_TAKES_NO_ARGS, &wblock->flags); in wmi_create_device()
1034 if (acpi_has_method(device->handle, method)) in wmi_create_device()
1035 wblock->dev.setable = true; in wmi_create_device()
1038 init_rwsem(&wblock->notify_lock); in wmi_create_device()
1039 wblock->driver_ready = false; in wmi_create_device()
1040 wblock->dev.dev.bus = &wmi_bus_type; in wmi_create_device()
1041 wblock->dev.dev.parent = wmi_bus_dev; in wmi_create_device()
1043 count = guid_count(&wblock->gblock.guid); in wmi_create_device()
1048 dev_set_name(&wblock->dev.dev, "%pUL-%d", &wblock->gblock.guid, count); in wmi_create_device()
1049 set_bit(WMI_GUID_DUPLICATED, &wblock->flags); in wmi_create_device()
1051 dev_set_name(&wblock->dev.dev, "%pUL", &wblock->gblock.guid); in wmi_create_device()
1054 device_initialize(&wblock->dev.dev); in wmi_create_device()
1064 * Many aggregate WMI drivers do not use -EPROBE_DEFER when they in wmi_add_device()
1072 link = device_link_add(&wdev->dev, &pdev->dev, DL_FLAG_AUTOREMOVE_SUPPLIER); in wmi_add_device()
1074 return -EINVAL; in wmi_add_device()
1076 return device_add(&wdev->dev); in wmi_add_device()
1084 struct acpi_device *device = ACPI_COMPANION(&pdev->dev); in parse_wdg()
1094 status = acpi_evaluate_object(device->handle, "_WDG", NULL, &out); in parse_wdg()
1096 return -ENXIO; in parse_wdg()
1100 return -ENXIO; in parse_wdg()
1102 if (obj->type != ACPI_TYPE_BUFFER) { in parse_wdg()
1104 return -ENXIO; in parse_wdg()
1107 event_data_available = acpi_has_method(device->handle, "_WED"); in parse_wdg()
1108 gblock = (const struct guid_block *)obj->buffer.pointer; in parse_wdg()
1109 total = obj->buffer.length / sizeof(struct guid_block); in parse_wdg()
1121 wblock->acpi_device = device; in parse_wdg()
1122 wblock->gblock = gblock[i]; in parse_wdg()
1124 set_bit(WMI_NO_EVENT_DATA, &wblock->flags); in parse_wdg()
1132 retval = wmi_add_device(pdev, &wblock->dev); in parse_wdg()
1135 &wblock->gblock.guid); in parse_wdg()
1137 put_device(&wblock->dev.dev); in parse_wdg()
1152 .value = wblock->gblock.notify_id, in wmi_get_notify_data()
1161 status = acpi_evaluate_object(wblock->acpi_device->handle, "_WED", &input, &data); in wmi_get_notify_data()
1163 dev_warn(&wblock->dev.dev, "Failed to get event data\n"); in wmi_get_notify_data()
1164 return -EIO; in wmi_get_notify_data()
1174 struct wmi_driver *driver = to_wmi_driver(wblock->dev.dev.driver); in wmi_notify_driver()
1176 if (!obj && !driver->no_notify_data) { in wmi_notify_driver()
1177 dev_warn(&wblock->dev.dev, "Event contains no event data\n"); in wmi_notify_driver()
1181 if (driver->notify) in wmi_notify_driver()
1182 driver->notify(&wblock->dev, obj); in wmi_notify_driver()
1192 if (!(wblock->gblock.flags & ACPI_WMI_EVENT && wblock->gblock.notify_id == *event)) in wmi_notify_device()
1204 if (!test_bit(WMI_NO_EVENT_DATA, &wblock->flags)) { in wmi_notify_device()
1207 return -EIO; in wmi_notify_device()
1210 down_read(&wblock->notify_lock); in wmi_notify_device()
1212 if (wblock->dev.dev.driver && wblock->driver_ready) in wmi_notify_device()
1215 if (wblock->handler) in wmi_notify_device()
1216 wblock->handler(obj, wblock->handler_data); in wmi_notify_device()
1218 up_read(&wblock->notify_lock); in wmi_notify_device()
1222 acpi_bus_generate_netlink_event("wmi", acpi_dev_name(wblock->acpi_device), *event, 0); in wmi_notify_device()
1224 return -EBUSY; in wmi_notify_device()
1243 struct device *wmi_bus_device = dev_get_drvdata(&device->dev); in acpi_wmi_remove()
1252 acpi_remove_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, acpi_wmi_notify_handler); in acpi_wmi_remove_notify_handler()
1269 acpi_device = ACPI_COMPANION(&device->dev); in acpi_wmi_probe()
1271 dev_err(&device->dev, "ACPI companion is missing\n"); in acpi_wmi_probe()
1272 return -ENODEV; in acpi_wmi_probe()
1275 wmi_bus_dev = device_create(&wmi_bus_class, &device->dev, MKDEV(0, 0), NULL, "wmi_bus-%s", in acpi_wmi_probe()
1276 dev_name(&device->dev)); in acpi_wmi_probe()
1280 error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_bus_device, wmi_bus_dev); in acpi_wmi_probe()
1284 dev_set_drvdata(&device->dev, wmi_bus_dev); in acpi_wmi_probe()
1286 status = acpi_install_notify_handler(acpi_device->handle, ACPI_ALL_NOTIFY, in acpi_wmi_probe()
1289 dev_err(&device->dev, "Error installing notify handler\n"); in acpi_wmi_probe()
1290 return -ENODEV; in acpi_wmi_probe()
1292 error = devm_add_action_or_reset(&device->dev, acpi_wmi_remove_notify_handler, in acpi_wmi_probe()
1299 dev_err(&device->dev, "Failed to parse _WDG method\n"); in acpi_wmi_probe()
1309 driver->driver.owner = owner; in __wmi_driver_register()
1310 driver->driver.bus = &wmi_bus_type; in __wmi_driver_register()
1312 return driver_register(&driver->driver); in __wmi_driver_register()
1317 * wmi_driver_unregister() - Unregister a WMI driver
1324 driver_unregister(&driver->driver); in wmi_driver_unregister()
1330 .name = "acpi-wmi",
1342 return -ENODEV; in acpi_wmi_init()