Lines Matching +full:abs +full:- +full:flat
1 // SPDX-License-Identifier: GPL-2.0-or-later
11 * - add UI_GET_SYSNAME ioctl
13 * - updated ff support for the changes in kernel interface
14 * - added MODULE_VERSION
16 * - added force feedback support
17 * - added UI_SET_PHYS
19 * - first public version
31 #include "../input-compat.h"
80 udev->buff[udev->head] = (struct input_event) { in uinput_dev_event()
88 udev->head = (udev->head + 1) % UINPUT_BUFFER_SIZE; in uinput_dev_event()
90 wake_up_interruptible(&udev->waitq); in uinput_dev_event()
102 spin_lock(&udev->requests_lock); in uinput_request_alloc_id()
105 if (!udev->requests[id]) { in uinput_request_alloc_id()
106 request->id = id; in uinput_request_alloc_id()
107 udev->requests[id] = request; in uinput_request_alloc_id()
113 spin_unlock(&udev->requests_lock); in uinput_request_alloc_id()
124 return udev->requests[id]; in uinput_request_find()
131 return wait_event_interruptible(udev->requests_waitq, in uinput_request_reserve_slot()
139 spin_lock(&udev->requests_lock); in uinput_request_release_slot()
140 udev->requests[id] = NULL; in uinput_request_release_slot()
141 spin_unlock(&udev->requests_lock); in uinput_request_release_slot()
143 wake_up(&udev->requests_waitq); in uinput_request_release_slot()
151 retval = mutex_lock_interruptible(&udev->mutex); in uinput_request_send()
155 if (udev->state != UIST_CREATED) { in uinput_request_send()
156 retval = -ENODEV; in uinput_request_send()
160 init_completion(&request->done); in uinput_request_send()
166 uinput_dev_event(udev->dev, EV_UINPUT, request->code, request->id); in uinput_request_send()
169 mutex_unlock(&udev->mutex); in uinput_request_send()
186 if (!wait_for_completion_timeout(&request->done, 30 * HZ)) { in uinput_request_submit()
187 retval = -ETIMEDOUT; in uinput_request_submit()
191 retval = request->retval; in uinput_request_submit()
194 uinput_request_release_slot(udev, request->id); in uinput_request_submit()
207 spin_lock(&udev->requests_lock); in uinput_flush_requests()
210 request = udev->requests[i]; in uinput_flush_requests()
212 request->retval = -ENODEV; in uinput_flush_requests()
213 complete(&request->done); in uinput_flush_requests()
217 spin_unlock(&udev->requests_lock); in uinput_flush_requests()
249 if (effect->type == FF_PERIODIC && in uinput_dev_upload_effect()
250 effect->u.periodic.waveform == FF_CUSTOM) in uinput_dev_upload_effect()
251 return -EINVAL; in uinput_dev_upload_effect()
265 if (!test_bit(EV_FF, dev->evbit)) in uinput_dev_erase_effect()
266 return -ENOSYS; in uinput_dev_erase_effect()
280 * the udev->mutex), or the file descriptor is closed and there is in uinput_dev_flush()
289 struct input_dev *dev = udev->dev; in uinput_destroy_device()
290 enum uinput_state old_state = udev->state; in uinput_destroy_device()
292 udev->state = UIST_NEW_DEVICE; in uinput_destroy_device()
295 name = dev->name; in uinput_destroy_device()
296 phys = dev->phys; in uinput_destroy_device()
305 udev->dev = NULL; in uinput_destroy_device()
311 struct input_dev *dev = udev->dev; in uinput_create_device()
314 if (udev->state != UIST_SETUP_COMPLETE) { in uinput_create_device()
316 return -EINVAL; in uinput_create_device()
319 if (test_bit(EV_ABS, dev->evbit)) { in uinput_create_device()
321 if (!dev->absinfo) { in uinput_create_device()
322 error = -EINVAL; in uinput_create_device()
326 if (test_bit(ABS_MT_SLOT, dev->absbit)) { in uinput_create_device()
331 } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { in uinput_create_device()
336 if (test_bit(EV_FF, dev->evbit) && !udev->ff_effects_max) { in uinput_create_device()
337 printk(KERN_DEBUG "%s: ff_effects_max should be non-zero when FF_BIT is set\n", in uinput_create_device()
339 error = -EINVAL; in uinput_create_device()
343 if (udev->ff_effects_max) { in uinput_create_device()
344 error = input_ff_create(dev, udev->ff_effects_max); in uinput_create_device()
348 dev->ff->upload = uinput_dev_upload_effect; in uinput_create_device()
349 dev->ff->erase = uinput_dev_erase_effect; in uinput_create_device()
350 dev->ff->playback = uinput_dev_playback; in uinput_create_device()
351 dev->ff->set_gain = uinput_dev_set_gain; in uinput_create_device()
352 dev->ff->set_autocenter = uinput_dev_set_autocenter; in uinput_create_device()
358 dev->flush = uinput_dev_flush; in uinput_create_device()
361 dev->event = uinput_dev_event; in uinput_create_device()
363 input_set_drvdata(udev->dev, udev); in uinput_create_device()
365 error = input_register_device(udev->dev); in uinput_create_device()
369 udev->state = UIST_CREATED; in uinput_create_device()
384 return -ENOMEM; in uinput_open()
386 mutex_init(&newdev->mutex); in uinput_open()
387 spin_lock_init(&newdev->requests_lock); in uinput_open()
388 init_waitqueue_head(&newdev->requests_waitq); in uinput_open()
389 init_waitqueue_head(&newdev->waitq); in uinput_open()
390 newdev->state = UIST_NEW_DEVICE; in uinput_open()
392 file->private_data = newdev; in uinput_open()
399 const struct input_absinfo *abs) in uinput_validate_absinfo() argument
403 min = abs->minimum; in uinput_validate_absinfo()
404 max = abs->maximum; in uinput_validate_absinfo()
408 "%s: invalid abs[%02x] min:%d max:%d\n", in uinput_validate_absinfo()
410 return -EINVAL; in uinput_validate_absinfo()
413 if (!check_sub_overflow(max, min, &range) && abs->flat > range) { in uinput_validate_absinfo()
416 UINPUT_NAME, code, abs->flat, min, max); in uinput_validate_absinfo()
417 return -EINVAL; in uinput_validate_absinfo()
423 * (we are not using in-kernel slot assignment so not going to in uinput_validate_absinfo()
431 return -EINVAL; in uinput_validate_absinfo()
442 if (!test_bit(EV_ABS, dev->evbit)) in uinput_validate_absbits()
449 for_each_set_bit(cnt, dev->absbit, ABS_CNT) { in uinput_validate_absbits()
450 if (!dev->absinfo) in uinput_validate_absbits()
451 return -EINVAL; in uinput_validate_absbits()
453 error = uinput_validate_absinfo(dev, cnt, &dev->absinfo[cnt]); in uinput_validate_absbits()
467 if (udev->state == UIST_CREATED) in uinput_dev_setup()
468 return -EINVAL; in uinput_dev_setup()
471 return -EFAULT; in uinput_dev_setup()
474 return -EINVAL; in uinput_dev_setup()
476 dev = udev->dev; in uinput_dev_setup()
477 dev->id = setup.id; in uinput_dev_setup()
478 udev->ff_effects_max = setup.ff_effects_max; in uinput_dev_setup()
480 kfree(dev->name); in uinput_dev_setup()
481 dev->name = kstrndup(setup.name, UINPUT_MAX_NAME_SIZE, GFP_KERNEL); in uinput_dev_setup()
482 if (!dev->name) in uinput_dev_setup()
483 return -ENOMEM; in uinput_dev_setup()
485 udev->state = UIST_SETUP_COMPLETE; in uinput_dev_setup()
497 return -E2BIG; in uinput_abs_setup()
499 if (udev->state == UIST_CREATED) in uinput_abs_setup()
500 return -EINVAL; in uinput_abs_setup()
503 return -EFAULT; in uinput_abs_setup()
506 return -ERANGE; in uinput_abs_setup()
508 dev = udev->dev; in uinput_abs_setup()
515 if (!dev->absinfo) in uinput_abs_setup()
516 return -ENOMEM; in uinput_abs_setup()
518 set_bit(setup.code, dev->absbit); in uinput_abs_setup()
519 dev->absinfo[setup.code] = setup.absinfo; in uinput_abs_setup()
533 return -EINVAL; in uinput_setup_device_legacy()
535 if (!udev->dev) { in uinput_setup_device_legacy()
536 udev->dev = input_allocate_device(); in uinput_setup_device_legacy()
537 if (!udev->dev) in uinput_setup_device_legacy()
538 return -ENOMEM; in uinput_setup_device_legacy()
541 dev = udev->dev; in uinput_setup_device_legacy()
547 udev->ff_effects_max = user_dev->ff_effects_max; in uinput_setup_device_legacy()
550 if (!user_dev->name[0]) { in uinput_setup_device_legacy()
551 retval = -EINVAL; in uinput_setup_device_legacy()
555 kfree(dev->name); in uinput_setup_device_legacy()
556 dev->name = kstrndup(user_dev->name, UINPUT_MAX_NAME_SIZE, in uinput_setup_device_legacy()
558 if (!dev->name) { in uinput_setup_device_legacy()
559 retval = -ENOMEM; in uinput_setup_device_legacy()
563 dev->id.bustype = user_dev->id.bustype; in uinput_setup_device_legacy()
564 dev->id.vendor = user_dev->id.vendor; in uinput_setup_device_legacy()
565 dev->id.product = user_dev->id.product; in uinput_setup_device_legacy()
566 dev->id.version = user_dev->id.version; in uinput_setup_device_legacy()
569 input_abs_set_max(dev, i, user_dev->absmax[i]); in uinput_setup_device_legacy()
570 input_abs_set_min(dev, i, user_dev->absmin[i]); in uinput_setup_device_legacy()
571 input_abs_set_fuzz(dev, i, user_dev->absfuzz[i]); in uinput_setup_device_legacy()
572 input_abs_set_flat(dev, i, user_dev->absflat[i]); in uinput_setup_device_legacy()
579 udev->state = UIST_SETUP_COMPLETE; in uinput_setup_device_legacy()
623 return -EINVAL; in uinput_inject_events()
633 return -EFAULT; in uinput_inject_events()
637 input_set_timestamp(udev->dev, timestamp); in uinput_inject_events()
639 input_event(udev->dev, ev.type, ev.code, ev.value); in uinput_inject_events()
650 struct uinput_device *udev = file->private_data; in uinput_write()
656 retval = mutex_lock_interruptible(&udev->mutex); in uinput_write()
660 retval = udev->state == UIST_CREATED ? in uinput_write()
664 mutex_unlock(&udev->mutex); in uinput_write()
674 spin_lock_irq(&udev->dev->event_lock); in uinput_fetch_next_event()
676 have_event = udev->head != udev->tail; in uinput_fetch_next_event()
678 *event = udev->buff[udev->tail]; in uinput_fetch_next_event()
679 udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE; in uinput_fetch_next_event()
682 spin_unlock_irq(&udev->dev->event_lock); in uinput_fetch_next_event()
697 return -EFAULT; in uinput_events_to_user()
708 struct uinput_device *udev = file->private_data; in uinput_read()
712 return -EINVAL; in uinput_read()
715 retval = mutex_lock_interruptible(&udev->mutex); in uinput_read()
719 if (udev->state != UIST_CREATED) in uinput_read()
720 retval = -ENODEV; in uinput_read()
721 else if (udev->head == udev->tail && in uinput_read()
722 (file->f_flags & O_NONBLOCK)) in uinput_read()
723 retval = -EAGAIN; in uinput_read()
727 mutex_unlock(&udev->mutex); in uinput_read()
732 if (!(file->f_flags & O_NONBLOCK)) in uinput_read()
733 retval = wait_event_interruptible(udev->waitq, in uinput_read()
734 udev->head != udev->tail || in uinput_read()
735 udev->state != UIST_CREATED); in uinput_read()
743 struct uinput_device *udev = file->private_data; in uinput_poll()
746 poll_wait(file, &udev->waitq, wait); in uinput_poll()
748 if (udev->head != udev->tail) in uinput_poll()
756 struct uinput_device *udev = file->private_data; in uinput_release()
778 ff_up_compat.request_id = ff_up->request_id; in uinput_ff_upload_to_user()
779 ff_up_compat.retval = ff_up->retval; in uinput_ff_upload_to_user()
786 memcpy(&ff_up_compat.effect, &ff_up->effect, in uinput_ff_upload_to_user()
788 memcpy(&ff_up_compat.old, &ff_up->old, in uinput_ff_upload_to_user()
793 return -EFAULT; in uinput_ff_upload_to_user()
797 return -EFAULT; in uinput_ff_upload_to_user()
811 return -EFAULT; in uinput_ff_upload_from_user()
813 ff_up->request_id = ff_up_compat.request_id; in uinput_ff_upload_from_user()
814 ff_up->retval = ff_up_compat.retval; in uinput_ff_upload_from_user()
815 memcpy(&ff_up->effect, &ff_up_compat.effect, in uinput_ff_upload_from_user()
817 memcpy(&ff_up->old, &ff_up_compat.old, in uinput_ff_upload_from_user()
823 return -EFAULT; in uinput_ff_upload_from_user()
835 return -EFAULT; in uinput_ff_upload_to_user()
844 return -EFAULT; in uinput_ff_upload_from_user()
854 if (udev->state == UIST_CREATED) \
855 __ret = -EINVAL; \
857 __ret = -EINVAL; \
858 else set_bit((_arg), udev->dev->_bit); \
869 return -ENOENT; in uinput_str_to_user()
872 return -EINVAL; in uinput_str_to_user()
880 return -EFAULT; in uinput_str_to_user()
883 ret = put_user(0, p + len - 1); in uinput_str_to_user()
884 return ret ? -EFAULT : len; in uinput_str_to_user()
891 struct uinput_device *udev = file->private_data; in uinput_ioctl_handler()
899 retval = mutex_lock_interruptible(&udev->mutex); in uinput_ioctl_handler()
903 if (!udev->dev) { in uinput_ioctl_handler()
904 udev->dev = input_allocate_device(); in uinput_ioctl_handler()
905 if (!udev->dev) { in uinput_ioctl_handler()
906 retval = -ENOMEM; in uinput_ioctl_handler()
914 retval = -EFAULT; in uinput_ioctl_handler()
972 if (udev->state == UIST_CREATED) { in uinput_ioctl_handler()
973 retval = -EINVAL; in uinput_ioctl_handler()
983 kfree(udev->dev->phys); in uinput_ioctl_handler()
984 udev->dev->phys = phys; in uinput_ioctl_handler()
993 if (!req || req->code != UI_FF_UPLOAD || in uinput_ioctl_handler()
994 !req->u.upload.effect) { in uinput_ioctl_handler()
995 retval = -EINVAL; in uinput_ioctl_handler()
1000 ff_up.effect = *req->u.upload.effect; in uinput_ioctl_handler()
1001 if (req->u.upload.old) in uinput_ioctl_handler()
1002 ff_up.old = *req->u.upload.old; in uinput_ioctl_handler()
1011 retval = -EFAULT; in uinput_ioctl_handler()
1016 if (!req || req->code != UI_FF_ERASE) { in uinput_ioctl_handler()
1017 retval = -EINVAL; in uinput_ioctl_handler()
1022 ff_erase.effect_id = req->u.effect_id; in uinput_ioctl_handler()
1024 retval = -EFAULT; in uinput_ioctl_handler()
1036 if (!req || req->code != UI_FF_UPLOAD || in uinput_ioctl_handler()
1037 !req->u.upload.effect) { in uinput_ioctl_handler()
1038 retval = -EINVAL; in uinput_ioctl_handler()
1042 req->retval = ff_up.retval; in uinput_ioctl_handler()
1043 complete(&req->done); in uinput_ioctl_handler()
1048 retval = -EFAULT; in uinput_ioctl_handler()
1053 if (!req || req->code != UI_FF_ERASE) { in uinput_ioctl_handler()
1054 retval = -EINVAL; in uinput_ioctl_handler()
1058 req->retval = ff_erase.retval; in uinput_ioctl_handler()
1059 complete(&req->done); in uinput_ioctl_handler()
1065 /* Now check variable-length commands */ in uinput_ioctl_handler()
1068 if (udev->state != UIST_CREATED) { in uinput_ioctl_handler()
1069 retval = -ENOENT; in uinput_ioctl_handler()
1072 name = dev_name(&udev->dev->dev); in uinput_ioctl_handler()
1081 retval = -EINVAL; in uinput_ioctl_handler()
1083 mutex_unlock(&udev->mutex); in uinput_ioctl_handler()