evdev.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * Event char devices, giving access to raw input device events.
  3. *
  4. * Copyright (c) 1999-2002 Vojtech Pavlik
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. */
  10. #define EVDEV_MINOR_BASE 64
  11. #define EVDEV_MINORS 32
  12. #define EVDEV_BUFFER_SIZE 64
  13. #include <linux/poll.h>
  14. #include <linux/slab.h>
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/input.h>
  18. #include <linux/major.h>
  19. #include <linux/smp_lock.h>
  20. #include <linux/device.h>
  21. #include <linux/compat.h>
  22. struct evdev {
  23. int exist;
  24. int open;
  25. int minor;
  26. char name[16];
  27. struct input_handle handle;
  28. wait_queue_head_t wait;
  29. struct evdev_list *grab;
  30. struct list_head list;
  31. };
  32. struct evdev_list {
  33. struct input_event buffer[EVDEV_BUFFER_SIZE];
  34. int head;
  35. int tail;
  36. struct fasync_struct *fasync;
  37. struct evdev *evdev;
  38. struct list_head node;
  39. };
  40. static struct evdev *evdev_table[EVDEV_MINORS];
  41. static void evdev_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)
  42. {
  43. struct evdev *evdev = handle->private;
  44. struct evdev_list *list;
  45. if (evdev->grab) {
  46. list = evdev->grab;
  47. do_gettimeofday(&list->buffer[list->head].time);
  48. list->buffer[list->head].type = type;
  49. list->buffer[list->head].code = code;
  50. list->buffer[list->head].value = value;
  51. list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1);
  52. kill_fasync(&list->fasync, SIGIO, POLL_IN);
  53. } else
  54. list_for_each_entry(list, &evdev->list, node) {
  55. do_gettimeofday(&list->buffer[list->head].time);
  56. list->buffer[list->head].type = type;
  57. list->buffer[list->head].code = code;
  58. list->buffer[list->head].value = value;
  59. list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1);
  60. kill_fasync(&list->fasync, SIGIO, POLL_IN);
  61. }
  62. wake_up_interruptible(&evdev->wait);
  63. }
  64. static int evdev_fasync(int fd, struct file *file, int on)
  65. {
  66. int retval;
  67. struct evdev_list *list = file->private_data;
  68. retval = fasync_helper(fd, file, on, &list->fasync);
  69. return retval < 0 ? retval : 0;
  70. }
  71. static int evdev_flush(struct file *file, fl_owner_t id)
  72. {
  73. struct evdev_list *list = file->private_data;
  74. if (!list->evdev->exist)
  75. return -ENODEV;
  76. return input_flush_device(&list->evdev->handle, file);
  77. }
  78. static void evdev_free(struct evdev *evdev)
  79. {
  80. evdev_table[evdev->minor] = NULL;
  81. kfree(evdev);
  82. }
  83. static int evdev_release(struct inode * inode, struct file * file)
  84. {
  85. struct evdev_list *list = file->private_data;
  86. if (list->evdev->grab == list) {
  87. input_release_device(&list->evdev->handle);
  88. list->evdev->grab = NULL;
  89. }
  90. evdev_fasync(-1, file, 0);
  91. list_del(&list->node);
  92. if (!--list->evdev->open) {
  93. if (list->evdev->exist)
  94. input_close_device(&list->evdev->handle);
  95. else
  96. evdev_free(list->evdev);
  97. }
  98. kfree(list);
  99. return 0;
  100. }
  101. static int evdev_open(struct inode * inode, struct file * file)
  102. {
  103. struct evdev_list *list;
  104. int i = iminor(inode) - EVDEV_MINOR_BASE;
  105. int accept_err;
  106. if (i >= EVDEV_MINORS || !evdev_table[i] || !evdev_table[i]->exist)
  107. return -ENODEV;
  108. if ((accept_err = input_accept_process(&(evdev_table[i]->handle), file)))
  109. return accept_err;
  110. if (!(list = kzalloc(sizeof(struct evdev_list), GFP_KERNEL)))
  111. return -ENOMEM;
  112. list->evdev = evdev_table[i];
  113. list_add_tail(&list->node, &evdev_table[i]->list);
  114. file->private_data = list;
  115. if (!list->evdev->open++)
  116. if (list->evdev->exist)
  117. input_open_device(&list->evdev->handle);
  118. return 0;
  119. }
  120. #ifdef CONFIG_COMPAT
  121. struct input_event_compat {
  122. struct compat_timeval time;
  123. __u16 type;
  124. __u16 code;
  125. __s32 value;
  126. };
  127. /* Note to the author of this code: did it ever occur to
  128. you why the ifdefs are needed? Think about it again. -AK */
  129. #ifdef CONFIG_X86_64
  130. # define COMPAT_TEST is_compat_task()
  131. #elif defined(CONFIG_IA64)
  132. # define COMPAT_TEST IS_IA32_PROCESS(task_pt_regs(current))
  133. #elif defined(CONFIG_S390)
  134. # define COMPAT_TEST test_thread_flag(TIF_31BIT)
  135. #elif defined(CONFIG_MIPS)
  136. # define COMPAT_TEST (current->thread.mflags & MF_32BIT_ADDR)
  137. #else
  138. # define COMPAT_TEST test_thread_flag(TIF_32BIT)
  139. #endif
  140. static inline size_t evdev_event_size(void)
  141. {
  142. return COMPAT_TEST ?
  143. sizeof(struct input_event_compat) : sizeof(struct input_event);
  144. }
  145. static int evdev_event_from_user(const char __user *buffer, struct input_event *event)
  146. {
  147. if (COMPAT_TEST) {
  148. struct input_event_compat compat_event;
  149. if (copy_from_user(&compat_event, buffer, sizeof(struct input_event_compat)))
  150. return -EFAULT;
  151. event->time.tv_sec = compat_event.time.tv_sec;
  152. event->time.tv_usec = compat_event.time.tv_usec;
  153. event->type = compat_event.type;
  154. event->code = compat_event.code;
  155. event->value = compat_event.value;
  156. } else {
  157. if (copy_from_user(event, buffer, sizeof(struct input_event)))
  158. return -EFAULT;
  159. }
  160. return 0;
  161. }
  162. static int evdev_event_to_user(char __user *buffer, const struct input_event *event)
  163. {
  164. if (COMPAT_TEST) {
  165. struct input_event_compat compat_event;
  166. compat_event.time.tv_sec = event->time.tv_sec;
  167. compat_event.time.tv_usec = event->time.tv_usec;
  168. compat_event.type = event->type;
  169. compat_event.code = event->code;
  170. compat_event.value = event->value;
  171. if (copy_to_user(buffer, &compat_event, sizeof(struct input_event_compat)))
  172. return -EFAULT;
  173. } else {
  174. if (copy_to_user(buffer, event, sizeof(struct input_event)))
  175. return -EFAULT;
  176. }
  177. return 0;
  178. }
  179. #else
  180. static inline size_t evdev_event_size(void)
  181. {
  182. return sizeof(struct input_event);
  183. }
  184. static int evdev_event_from_user(const char __user *buffer, struct input_event *event)
  185. {
  186. if (copy_from_user(event, buffer, sizeof(struct input_event)))
  187. return -EFAULT;
  188. return 0;
  189. }
  190. static int evdev_event_to_user(char __user *buffer, const struct input_event *event)
  191. {
  192. if (copy_to_user(buffer, event, sizeof(struct input_event)))
  193. return -EFAULT;
  194. return 0;
  195. }
  196. #endif /* CONFIG_COMPAT */
  197. static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos)
  198. {
  199. struct evdev_list *list = file->private_data;
  200. struct input_event event;
  201. int retval = 0;
  202. if (!list->evdev->exist)
  203. return -ENODEV;
  204. while (retval < count) {
  205. if (evdev_event_from_user(buffer + retval, &event))
  206. return -EFAULT;
  207. input_event(list->evdev->handle.dev, event.type, event.code, event.value);
  208. retval += evdev_event_size();
  209. }
  210. return retval;
  211. }
  212. static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos)
  213. {
  214. struct evdev_list *list = file->private_data;
  215. int retval;
  216. if (count < evdev_event_size())
  217. return -EINVAL;
  218. if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK))
  219. return -EAGAIN;
  220. retval = wait_event_interruptible(list->evdev->wait,
  221. list->head != list->tail || (!list->evdev->exist));
  222. if (retval)
  223. return retval;
  224. if (!list->evdev->exist)
  225. return -ENODEV;
  226. while (list->head != list->tail && retval + evdev_event_size() <= count) {
  227. struct input_event *event = (struct input_event *) list->buffer + list->tail;
  228. if (evdev_event_to_user(buffer + retval, event))
  229. return -EFAULT;
  230. list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1);
  231. retval += evdev_event_size();
  232. }
  233. return retval;
  234. }
  235. /* No kernel lock - fine */
  236. static unsigned int evdev_poll(struct file *file, poll_table *wait)
  237. {
  238. struct evdev_list *list = file->private_data;
  239. poll_wait(file, &list->evdev->wait, wait);
  240. return ((list->head == list->tail) ? 0 : (POLLIN | POLLRDNORM)) |
  241. (list->evdev->exist ? 0 : (POLLHUP | POLLERR));
  242. }
  243. #ifdef CONFIG_COMPAT
  244. #define BITS_PER_LONG_COMPAT (sizeof(compat_long_t) * 8)
  245. #define NBITS_COMPAT(x) ((((x) - 1) / BITS_PER_LONG_COMPAT) + 1)
  246. #ifdef __BIG_ENDIAN
  247. static int bits_to_user(unsigned long *bits, unsigned int maxbit,
  248. unsigned int maxlen, void __user *p, int compat)
  249. {
  250. int len, i;
  251. if (compat) {
  252. len = NBITS_COMPAT(maxbit) * sizeof(compat_long_t);
  253. if (len < maxlen)
  254. len = maxlen;
  255. for (i = 0; i < len / sizeof(compat_long_t); i++)
  256. if (copy_to_user((compat_long_t __user *) p + i,
  257. (compat_long_t *) bits +
  258. i + 1 - ((i % 2) << 1),
  259. sizeof(compat_long_t)))
  260. return -EFAULT;
  261. } else {
  262. len = NBITS(maxbit) * sizeof(long);
  263. if (len > maxlen)
  264. len = maxlen;
  265. if (copy_to_user(p, bits, len))
  266. return -EFAULT;
  267. }
  268. return len;
  269. }
  270. #else
  271. static int bits_to_user(unsigned long *bits, unsigned int maxbit,
  272. unsigned int maxlen, void __user *p, int compat)
  273. {
  274. int len = compat ?
  275. NBITS_COMPAT(maxbit) * sizeof(compat_long_t) :
  276. NBITS(maxbit) * sizeof(long);
  277. if (len > maxlen)
  278. len = maxlen;
  279. return copy_to_user(p, bits, len) ? -EFAULT : len;
  280. }
  281. #endif /* __BIG_ENDIAN */
  282. #else
  283. static int bits_to_user(unsigned long *bits, unsigned int maxbit,
  284. unsigned int maxlen, void __user *p, int compat)
  285. {
  286. int len = NBITS(maxbit) * sizeof(long);
  287. if (len > maxlen)
  288. len = maxlen;
  289. return copy_to_user(p, bits, len) ? -EFAULT : len;
  290. }
  291. #endif /* CONFIG_COMPAT */
  292. static int str_to_user(const char *str, unsigned int maxlen, void __user *p)
  293. {
  294. int len;
  295. if (!str)
  296. return -ENOENT;
  297. len = strlen(str) + 1;
  298. if (len > maxlen)
  299. len = maxlen;
  300. return copy_to_user(p, str, len) ? -EFAULT : len;
  301. }
  302. static long evdev_ioctl_handler(struct file *file, unsigned int cmd,
  303. void __user *p, int compat_mode)
  304. {
  305. struct evdev_list *list = file->private_data;
  306. struct evdev *evdev = list->evdev;
  307. struct input_dev *dev = evdev->handle.dev;
  308. struct input_absinfo abs;
  309. int __user *ip = (int __user *)p;
  310. int i, t, u, v;
  311. if (!evdev->exist)
  312. return -ENODEV;
  313. switch (cmd) {
  314. case EVIOCGVERSION:
  315. return put_user(EV_VERSION, ip);
  316. case EVIOCGID:
  317. if (copy_to_user(p, &dev->id, sizeof(struct input_id)))
  318. return -EFAULT;
  319. return 0;
  320. case EVIOCGREP:
  321. if (!test_bit(EV_REP, dev->evbit))
  322. return -ENOSYS;
  323. if (put_user(dev->rep[REP_DELAY], ip))
  324. return -EFAULT;
  325. if (put_user(dev->rep[REP_PERIOD], ip + 1))
  326. return -EFAULT;
  327. return 0;
  328. case EVIOCSREP:
  329. if (!test_bit(EV_REP, dev->evbit))
  330. return -ENOSYS;
  331. if (get_user(u, ip))
  332. return -EFAULT;
  333. if (get_user(v, ip + 1))
  334. return -EFAULT;
  335. input_event(dev, EV_REP, REP_DELAY, u);
  336. input_event(dev, EV_REP, REP_PERIOD, v);
  337. return 0;
  338. case EVIOCGKEYCODE:
  339. if (get_user(t, ip))
  340. return -EFAULT;
  341. if (t < 0 || t >= dev->keycodemax || !dev->keycodesize)
  342. return -EINVAL;
  343. if (put_user(INPUT_KEYCODE(dev, t), ip + 1))
  344. return -EFAULT;
  345. return 0;
  346. case EVIOCSKEYCODE:
  347. if (get_user(t, ip))
  348. return -EFAULT;
  349. if (t < 0 || t >= dev->keycodemax || !dev->keycodesize)
  350. return -EINVAL;
  351. if (get_user(v, ip + 1))
  352. return -EFAULT;
  353. if (v < 0 || v > KEY_MAX)
  354. return -EINVAL;
  355. if (dev->keycodesize < sizeof(v) && (v >> (dev->keycodesize * 8)))
  356. return -EINVAL;
  357. u = SET_INPUT_KEYCODE(dev, t, v);
  358. clear_bit(u, dev->keybit);
  359. set_bit(v, dev->keybit);
  360. for (i = 0; i < dev->keycodemax; i++)
  361. if (INPUT_KEYCODE(dev, i) == u)
  362. set_bit(u, dev->keybit);
  363. return 0;
  364. case EVIOCSFF:
  365. if (dev->upload_effect) {
  366. struct ff_effect effect;
  367. int err;
  368. if (copy_from_user(&effect, p, sizeof(effect)))
  369. return -EFAULT;
  370. err = dev->upload_effect(dev, &effect);
  371. if (put_user(effect.id, &(((struct ff_effect __user *)p)->id)))
  372. return -EFAULT;
  373. return err;
  374. } else
  375. return -ENOSYS;
  376. case EVIOCRMFF:
  377. if (!dev->erase_effect)
  378. return -ENOSYS;
  379. return dev->erase_effect(dev, (int)(unsigned long) p);
  380. case EVIOCGEFFECTS:
  381. if (put_user(dev->ff_effects_max, ip))
  382. return -EFAULT;
  383. return 0;
  384. case EVIOCGRAB:
  385. if (p) {
  386. if (evdev->grab)
  387. return -EBUSY;
  388. if (input_grab_device(&evdev->handle))
  389. return -EBUSY;
  390. evdev->grab = list;
  391. return 0;
  392. } else {
  393. if (evdev->grab != list)
  394. return -EINVAL;
  395. input_release_device(&evdev->handle);
  396. evdev->grab = NULL;
  397. return 0;
  398. }
  399. default:
  400. if (_IOC_TYPE(cmd) != 'E')
  401. return -EINVAL;
  402. if (_IOC_DIR(cmd) == _IOC_READ) {
  403. if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) {
  404. long *bits;
  405. int len;
  406. switch (_IOC_NR(cmd) & EV_MAX) {
  407. case 0: bits = dev->evbit; len = EV_MAX; break;
  408. case EV_KEY: bits = dev->keybit; len = KEY_MAX; break;
  409. case EV_REL: bits = dev->relbit; len = REL_MAX; break;
  410. case EV_ABS: bits = dev->absbit; len = ABS_MAX; break;
  411. case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break;
  412. case EV_LED: bits = dev->ledbit; len = LED_MAX; break;
  413. case EV_SND: bits = dev->sndbit; len = SND_MAX; break;
  414. case EV_FF: bits = dev->ffbit; len = FF_MAX; break;
  415. case EV_SW: bits = dev->swbit; len = SW_MAX; break;
  416. default: return -EINVAL;
  417. }
  418. return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode);
  419. }
  420. if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0)))
  421. return bits_to_user(dev->key, KEY_MAX, _IOC_SIZE(cmd),
  422. p, compat_mode);
  423. if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0)))
  424. return bits_to_user(dev->led, LED_MAX, _IOC_SIZE(cmd),
  425. p, compat_mode);
  426. if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0)))
  427. return bits_to_user(dev->snd, SND_MAX, _IOC_SIZE(cmd),
  428. p, compat_mode);
  429. if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0)))
  430. return bits_to_user(dev->sw, SW_MAX, _IOC_SIZE(cmd),
  431. p, compat_mode);
  432. if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0)))
  433. return str_to_user(dev->name, _IOC_SIZE(cmd), p);
  434. if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0)))
  435. return str_to_user(dev->phys, _IOC_SIZE(cmd), p);
  436. if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0)))
  437. return str_to_user(dev->uniq, _IOC_SIZE(cmd), p);
  438. if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
  439. int t = _IOC_NR(cmd) & ABS_MAX;
  440. abs.value = dev->abs[t];
  441. abs.minimum = dev->absmin[t];
  442. abs.maximum = dev->absmax[t];
  443. abs.fuzz = dev->absfuzz[t];
  444. abs.flat = dev->absflat[t];
  445. if (copy_to_user(p, &abs, sizeof(struct input_absinfo)))
  446. return -EFAULT;
  447. return 0;
  448. }
  449. }
  450. if (_IOC_DIR(cmd) == _IOC_WRITE) {
  451. if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
  452. int t = _IOC_NR(cmd) & ABS_MAX;
  453. if (copy_from_user(&abs, p, sizeof(struct input_absinfo)))
  454. return -EFAULT;
  455. dev->abs[t] = abs.value;
  456. dev->absmin[t] = abs.minimum;
  457. dev->absmax[t] = abs.maximum;
  458. dev->absfuzz[t] = abs.fuzz;
  459. dev->absflat[t] = abs.flat;
  460. return 0;
  461. }
  462. }
  463. }
  464. return -EINVAL;
  465. }
  466. static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  467. {
  468. return evdev_ioctl_handler(file, cmd, (void __user *)arg, 0);
  469. }
  470. #ifdef CONFIG_COMPAT
  471. static long evdev_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg)
  472. {
  473. return evdev_ioctl_handler(file, cmd, compat_ptr(arg), 1);
  474. }
  475. #endif
  476. static struct file_operations evdev_fops = {
  477. .owner = THIS_MODULE,
  478. .read = evdev_read,
  479. .write = evdev_write,
  480. .poll = evdev_poll,
  481. .open = evdev_open,
  482. .release = evdev_release,
  483. .unlocked_ioctl = evdev_ioctl,
  484. #ifdef CONFIG_COMPAT
  485. .compat_ioctl = evdev_ioctl_compat,
  486. #endif
  487. .fasync = evdev_fasync,
  488. .flush = evdev_flush
  489. };
  490. static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id)
  491. {
  492. struct evdev *evdev;
  493. struct class_device *cdev;
  494. int minor;
  495. for (minor = 0; minor < EVDEV_MINORS && evdev_table[minor]; minor++);
  496. if (minor == EVDEV_MINORS) {
  497. printk(KERN_ERR "evdev: no more free evdev devices\n");
  498. return NULL;
  499. }
  500. if (!(evdev = kzalloc(sizeof(struct evdev), GFP_KERNEL)))
  501. return NULL;
  502. INIT_LIST_HEAD(&evdev->list);
  503. init_waitqueue_head(&evdev->wait);
  504. evdev->exist = 1;
  505. evdev->minor = minor;
  506. evdev->handle.dev = dev;
  507. evdev->handle.name = evdev->name;
  508. evdev->handle.handler = handler;
  509. evdev->handle.private = evdev;
  510. sprintf(evdev->name, "event%d", minor);
  511. evdev_table[minor] = evdev;
  512. cdev = class_device_create(&input_class, &dev->cdev,
  513. MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor),
  514. dev->cdev.dev, evdev->name);
  515. /* temporary symlink to keep userspace happy */
  516. sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
  517. evdev->name);
  518. return &evdev->handle;
  519. }
  520. static void evdev_disconnect(struct input_handle *handle)
  521. {
  522. struct evdev *evdev = handle->private;
  523. struct evdev_list *list;
  524. sysfs_remove_link(&input_class.subsys.kset.kobj, evdev->name);
  525. class_device_destroy(&input_class,
  526. MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + evdev->minor));
  527. evdev->exist = 0;
  528. if (evdev->open) {
  529. input_close_device(handle);
  530. wake_up_interruptible(&evdev->wait);
  531. list_for_each_entry(list, &evdev->list, node)
  532. kill_fasync(&list->fasync, SIGIO, POLL_HUP);
  533. } else
  534. evdev_free(evdev);
  535. }
  536. static struct input_device_id evdev_ids[] = {
  537. { .driver_info = 1 }, /* Matches all devices */
  538. { }, /* Terminating zero entry */
  539. };
  540. MODULE_DEVICE_TABLE(input, evdev_ids);
  541. static struct input_handler evdev_handler = {
  542. .event = evdev_event,
  543. .connect = evdev_connect,
  544. .disconnect = evdev_disconnect,
  545. .fops = &evdev_fops,
  546. .minor = EVDEV_MINOR_BASE,
  547. .name = "evdev",
  548. .id_table = evdev_ids,
  549. };
  550. static int __init evdev_init(void)
  551. {
  552. input_register_handler(&evdev_handler);
  553. return 0;
  554. }
  555. static void __exit evdev_exit(void)
  556. {
  557. input_unregister_handler(&evdev_handler);
  558. }
  559. module_init(evdev_init);
  560. module_exit(evdev_exit);
  561. MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
  562. MODULE_DESCRIPTION("Input driver event char devices");
  563. MODULE_LICENSE("GPL");