diff options
author | Juergen Kreileder <jk@blackdown.de> | 2005-05-29 03:26:43 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor_core@ameritech.net> | 2005-05-29 03:26:43 -0400 |
commit | 52658bb685df77f71e97f1b503dee97d27a88b0f (patch) | |
tree | bd3d820981655590b4beb7f11322a7bbe53adcec /drivers/input/evdev.c | |
parent | 024ac44c701d43f5e2d34bd6a35b2813a36e6010 (diff) |
Input: Add support for 32-bit emulation on 64-bit platforms for evdev.
Signed-off-by: Juergen Kreileder <jk@blackdown.de>
Signed-off-by: Vojtech Pavlik <vojtech@suse.cz>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/evdev.c')
-rw-r--r-- | drivers/input/evdev.c | 268 |
1 files changed, 266 insertions, 2 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 17552a29978b..a04a8314dc87 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/smp_lock.h> | 21 | #include <linux/smp_lock.h> |
22 | #include <linux/device.h> | 22 | #include <linux/device.h> |
23 | #include <linux/devfs_fs_kernel.h> | 23 | #include <linux/devfs_fs_kernel.h> |
24 | #include <linux/compat.h> | ||
24 | 25 | ||
25 | struct evdev { | 26 | struct evdev { |
26 | int exist; | 27 | int exist; |
@@ -145,6 +146,41 @@ static int evdev_open(struct inode * inode, struct file * file) | |||
145 | return 0; | 146 | return 0; |
146 | } | 147 | } |
147 | 148 | ||
149 | #ifdef CONFIG_COMPAT | ||
150 | struct input_event_compat { | ||
151 | struct compat_timeval time; | ||
152 | __u16 type; | ||
153 | __u16 code; | ||
154 | __s32 value; | ||
155 | }; | ||
156 | |||
157 | #ifdef CONFIG_X86_64 | ||
158 | # define COMPAT_TEST test_thread_flag(TIF_IA32) | ||
159 | #elif defined(CONFIG_IA64) | ||
160 | # define COMPAT_TEST IS_IA32_PROCESS(ia64_task_regs(current)) | ||
161 | #elif defined(CONFIG_ARCH_S390) | ||
162 | # define COMPAT_TEST test_thread_flag(TIF_31BIT) | ||
163 | #else | ||
164 | # define COMPAT_TEST test_thread_flag(TIF_32BIT) | ||
165 | #endif | ||
166 | |||
167 | static ssize_t evdev_write_compat(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) | ||
168 | { | ||
169 | struct evdev_list *list = file->private_data; | ||
170 | struct input_event_compat event; | ||
171 | int retval = 0; | ||
172 | |||
173 | while (retval < count) { | ||
174 | if (copy_from_user(&event, buffer + retval, sizeof(struct input_event_compat))) | ||
175 | return -EFAULT; | ||
176 | input_event(list->evdev->handle.dev, event.type, event.code, event.value); | ||
177 | retval += sizeof(struct input_event_compat); | ||
178 | } | ||
179 | |||
180 | return retval; | ||
181 | } | ||
182 | #endif | ||
183 | |||
148 | static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) | 184 | static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) |
149 | { | 185 | { |
150 | struct evdev_list *list = file->private_data; | 186 | struct evdev_list *list = file->private_data; |
@@ -153,6 +189,11 @@ static ssize_t evdev_write(struct file * file, const char __user * buffer, size_ | |||
153 | 189 | ||
154 | if (!list->evdev->exist) return -ENODEV; | 190 | if (!list->evdev->exist) return -ENODEV; |
155 | 191 | ||
192 | #ifdef CONFIG_COMPAT | ||
193 | if (COMPAT_TEST) | ||
194 | return evdev_write_compat(file, buffer, count, ppos); | ||
195 | #endif | ||
196 | |||
156 | while (retval < count) { | 197 | while (retval < count) { |
157 | 198 | ||
158 | if (copy_from_user(&event, buffer + retval, sizeof(struct input_event))) | 199 | if (copy_from_user(&event, buffer + retval, sizeof(struct input_event))) |
@@ -164,11 +205,56 @@ static ssize_t evdev_write(struct file * file, const char __user * buffer, size_ | |||
164 | return retval; | 205 | return retval; |
165 | } | 206 | } |
166 | 207 | ||
208 | #ifdef CONFIG_COMPAT | ||
209 | static ssize_t evdev_read_compat(struct file * file, char __user * buffer, size_t count, loff_t *ppos) | ||
210 | { | ||
211 | struct evdev_list *list = file->private_data; | ||
212 | int retval; | ||
213 | |||
214 | if (count < sizeof(struct input_event_compat)) | ||
215 | return -EINVAL; | ||
216 | |||
217 | if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK)) | ||
218 | return -EAGAIN; | ||
219 | |||
220 | retval = wait_event_interruptible(list->evdev->wait, | ||
221 | list->head != list->tail || (!list->evdev->exist)); | ||
222 | |||
223 | if (retval) | ||
224 | return retval; | ||
225 | |||
226 | if (!list->evdev->exist) | ||
227 | return -ENODEV; | ||
228 | |||
229 | while (list->head != list->tail && retval + sizeof(struct input_event_compat) <= count) { | ||
230 | struct input_event *event = (struct input_event *) list->buffer + list->tail; | ||
231 | struct input_event_compat event_compat; | ||
232 | event_compat.time.tv_sec = event->time.tv_sec; | ||
233 | event_compat.time.tv_usec = event->time.tv_usec; | ||
234 | event_compat.type = event->type; | ||
235 | event_compat.code = event->code; | ||
236 | event_compat.value = event->value; | ||
237 | |||
238 | if (copy_to_user(buffer + retval, &event_compat, | ||
239 | sizeof(struct input_event_compat))) return -EFAULT; | ||
240 | list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1); | ||
241 | retval += sizeof(struct input_event_compat); | ||
242 | } | ||
243 | |||
244 | return retval; | ||
245 | } | ||
246 | #endif | ||
247 | |||
167 | static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) | 248 | static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) |
168 | { | 249 | { |
169 | struct evdev_list *list = file->private_data; | 250 | struct evdev_list *list = file->private_data; |
170 | int retval; | 251 | int retval; |
171 | 252 | ||
253 | #ifdef CONFIG_COMPAT | ||
254 | if (COMPAT_TEST) | ||
255 | return evdev_read_compat(file, buffer, count, ppos); | ||
256 | #endif | ||
257 | |||
172 | if (count < sizeof(struct input_event)) | 258 | if (count < sizeof(struct input_event)) |
173 | return -EINVAL; | 259 | return -EINVAL; |
174 | 260 | ||
@@ -203,7 +289,7 @@ static unsigned int evdev_poll(struct file *file, poll_table *wait) | |||
203 | (list->evdev->exist ? 0 : (POLLHUP | POLLERR)); | 289 | (list->evdev->exist ? 0 : (POLLHUP | POLLERR)); |
204 | } | 290 | } |
205 | 291 | ||
206 | static int evdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) | 292 | static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
207 | { | 293 | { |
208 | struct evdev_list *list = file->private_data; | 294 | struct evdev_list *list = file->private_data; |
209 | struct evdev *evdev = list->evdev; | 295 | struct evdev *evdev = list->evdev; |
@@ -389,6 +475,181 @@ static int evdev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
389 | return -EINVAL; | 475 | return -EINVAL; |
390 | } | 476 | } |
391 | 477 | ||
478 | #ifdef CONFIG_COMPAT | ||
479 | |||
480 | #define BITS_PER_LONG_COMPAT (sizeof(compat_long_t) * 8) | ||
481 | #define NBITS_COMPAT(x) ((((x)-1)/BITS_PER_LONG_COMPAT)+1) | ||
482 | #define OFF_COMPAT(x) ((x)%BITS_PER_LONG_COMPAT) | ||
483 | #define BIT_COMPAT(x) (1UL<<OFF_COMPAT(x)) | ||
484 | #define LONG_COMPAT(x) ((x)/BITS_PER_LONG_COMPAT) | ||
485 | #define test_bit_compat(bit, array) ((array[LONG_COMPAT(bit)] >> OFF_COMPAT(bit)) & 1) | ||
486 | |||
487 | static long evdev_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) | ||
488 | { | ||
489 | struct evdev_list *list = file->private_data; | ||
490 | struct evdev *evdev = list->evdev; | ||
491 | struct input_dev *dev = evdev->handle.dev; | ||
492 | struct input_absinfo abs; | ||
493 | void __user *p = compat_ptr(arg); | ||
494 | int i; | ||
495 | |||
496 | if (!evdev->exist) return -ENODEV; | ||
497 | |||
498 | switch (cmd) { | ||
499 | |||
500 | case EVIOCGVERSION: | ||
501 | case EVIOCGID: | ||
502 | case EVIOCGKEYCODE: | ||
503 | case EVIOCSKEYCODE: | ||
504 | case EVIOCSFF: | ||
505 | case EVIOCRMFF: | ||
506 | case EVIOCGEFFECTS: | ||
507 | case EVIOCGRAB: | ||
508 | return evdev_ioctl(file, cmd, (unsigned long) p); | ||
509 | |||
510 | default: | ||
511 | |||
512 | if (_IOC_TYPE(cmd) != 'E' || _IOC_DIR(cmd) != _IOC_READ) | ||
513 | return -EINVAL; | ||
514 | |||
515 | if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) { | ||
516 | |||
517 | long *bits; | ||
518 | int len; | ||
519 | |||
520 | switch (_IOC_NR(cmd) & EV_MAX) { | ||
521 | case 0: bits = dev->evbit; len = EV_MAX; break; | ||
522 | case EV_KEY: bits = dev->keybit; len = KEY_MAX; break; | ||
523 | case EV_REL: bits = dev->relbit; len = REL_MAX; break; | ||
524 | case EV_ABS: bits = dev->absbit; len = ABS_MAX; break; | ||
525 | case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break; | ||
526 | case EV_LED: bits = dev->ledbit; len = LED_MAX; break; | ||
527 | case EV_SND: bits = dev->sndbit; len = SND_MAX; break; | ||
528 | case EV_FF: bits = dev->ffbit; len = FF_MAX; break; | ||
529 | default: return -EINVAL; | ||
530 | } | ||
531 | len = NBITS_COMPAT(len) * sizeof(compat_long_t); | ||
532 | if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); | ||
533 | #ifdef __BIG_ENDIAN | ||
534 | for (i = 0; i < len / sizeof(compat_long_t); i++) | ||
535 | if (copy_to_user((compat_long_t*) p + i, | ||
536 | (compat_long_t*) bits + i + 1 - ((i % 2) << 1), | ||
537 | sizeof(compat_long_t))) | ||
538 | return -EFAULT; | ||
539 | return len; | ||
540 | #else | ||
541 | return copy_to_user(p, bits, len) ? -EFAULT : len; | ||
542 | #endif | ||
543 | } | ||
544 | |||
545 | if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) { | ||
546 | int len; | ||
547 | len = NBITS_COMPAT(KEY_MAX) * sizeof(compat_long_t); | ||
548 | if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); | ||
549 | #ifdef __BIG_ENDIAN | ||
550 | for (i = 0; i < len / sizeof(compat_long_t); i++) | ||
551 | if (copy_to_user((compat_long_t*) p + i, | ||
552 | (compat_long_t*) dev->key + i + 1 - ((i % 2) << 1), | ||
553 | sizeof(compat_long_t))) | ||
554 | return -EFAULT; | ||
555 | return len; | ||
556 | #else | ||
557 | return copy_to_user(p, dev->key, len) ? -EFAULT : len; | ||
558 | #endif | ||
559 | } | ||
560 | |||
561 | if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) { | ||
562 | int len; | ||
563 | len = NBITS_COMPAT(LED_MAX) * sizeof(compat_long_t); | ||
564 | if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); | ||
565 | #ifdef __BIG_ENDIAN | ||
566 | for (i = 0; i < len / sizeof(compat_long_t); i++) | ||
567 | if (copy_to_user((compat_long_t*) p + i, | ||
568 | (compat_long_t*) dev->led + i + 1 - ((i % 2) << 1), | ||
569 | sizeof(compat_long_t))) | ||
570 | return -EFAULT; | ||
571 | return len; | ||
572 | #else | ||
573 | return copy_to_user(p, dev->led, len) ? -EFAULT : len; | ||
574 | #endif | ||
575 | } | ||
576 | |||
577 | if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) { | ||
578 | int len; | ||
579 | len = NBITS_COMPAT(SND_MAX) * sizeof(compat_long_t); | ||
580 | if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); | ||
581 | #ifdef __BIG_ENDIAN | ||
582 | for (i = 0; i < len / sizeof(compat_long_t); i++) | ||
583 | if (copy_to_user((compat_long_t*) p + i, | ||
584 | (compat_long_t*) dev->snd + i + 1 - ((i % 2) << 1), | ||
585 | sizeof(compat_long_t))) | ||
586 | return -EFAULT; | ||
587 | return len; | ||
588 | #else | ||
589 | return copy_to_user(p, dev->snd, len) ? -EFAULT : len; | ||
590 | #endif | ||
591 | } | ||
592 | |||
593 | if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) { | ||
594 | int len; | ||
595 | if (!dev->name) return -ENOENT; | ||
596 | len = strlen(dev->name) + 1; | ||
597 | if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); | ||
598 | return copy_to_user(p, dev->name, len) ? -EFAULT : len; | ||
599 | } | ||
600 | |||
601 | if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) { | ||
602 | int len; | ||
603 | if (!dev->phys) return -ENOENT; | ||
604 | len = strlen(dev->phys) + 1; | ||
605 | if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); | ||
606 | return copy_to_user(p, dev->phys, len) ? -EFAULT : len; | ||
607 | } | ||
608 | |||
609 | if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) { | ||
610 | int len; | ||
611 | if (!dev->uniq) return -ENOENT; | ||
612 | len = strlen(dev->uniq) + 1; | ||
613 | if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); | ||
614 | return copy_to_user(p, dev->uniq, len) ? -EFAULT : len; | ||
615 | } | ||
616 | |||
617 | if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { | ||
618 | |||
619 | int t = _IOC_NR(cmd) & ABS_MAX; | ||
620 | |||
621 | abs.value = dev->abs[t]; | ||
622 | abs.minimum = dev->absmin[t]; | ||
623 | abs.maximum = dev->absmax[t]; | ||
624 | abs.fuzz = dev->absfuzz[t]; | ||
625 | abs.flat = dev->absflat[t]; | ||
626 | |||
627 | if (copy_to_user(p, &abs, sizeof(struct input_absinfo))) | ||
628 | return -EFAULT; | ||
629 | |||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { | ||
634 | |||
635 | int t = _IOC_NR(cmd) & ABS_MAX; | ||
636 | |||
637 | if (copy_from_user(&abs, p, sizeof(struct input_absinfo))) | ||
638 | return -EFAULT; | ||
639 | |||
640 | dev->abs[t] = abs.value; | ||
641 | dev->absmin[t] = abs.minimum; | ||
642 | dev->absmax[t] = abs.maximum; | ||
643 | dev->absfuzz[t] = abs.fuzz; | ||
644 | dev->absflat[t] = abs.flat; | ||
645 | |||
646 | return 0; | ||
647 | } | ||
648 | } | ||
649 | return -EINVAL; | ||
650 | } | ||
651 | #endif | ||
652 | |||
392 | static struct file_operations evdev_fops = { | 653 | static struct file_operations evdev_fops = { |
393 | .owner = THIS_MODULE, | 654 | .owner = THIS_MODULE, |
394 | .read = evdev_read, | 655 | .read = evdev_read, |
@@ -396,7 +657,10 @@ static struct file_operations evdev_fops = { | |||
396 | .poll = evdev_poll, | 657 | .poll = evdev_poll, |
397 | .open = evdev_open, | 658 | .open = evdev_open, |
398 | .release = evdev_release, | 659 | .release = evdev_release, |
399 | .ioctl = evdev_ioctl, | 660 | .unlocked_ioctl = evdev_ioctl, |
661 | #ifdef CONFIG_COMPAT | ||
662 | .compat_ioctl = evdev_ioctl_compat, | ||
663 | #endif | ||
400 | .fasync = evdev_fasync, | 664 | .fasync = evdev_fasync, |
401 | .flush = evdev_flush | 665 | .flush = evdev_flush |
402 | }; | 666 | }; |