evdev.c 17 KB

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