uinput.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #ifndef __UINPUT_H_
  2. #define __UINPUT_H_
  3. /*
  4. * User level driver support for input subsystem
  5. *
  6. * Heavily based on evdev.c by Vojtech Pavlik
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
  23. *
  24. * Changes/Revisions:
  25. * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>)
  26. * - added force feedback support
  27. * - added UI_SET_PHYS
  28. * 0.1 20/06/2002
  29. * - first public version
  30. */
  31. #ifdef __KERNEL__
  32. #define UINPUT_MINOR 223
  33. #define UINPUT_NAME "uinput"
  34. #define UINPUT_BUFFER_SIZE 16
  35. #define UINPUT_NUM_REQUESTS 16
  36. /* state flags => bit index for {set|clear|test}_bit ops */
  37. #define UIST_CREATED 0
  38. struct uinput_request {
  39. int id;
  40. int code; /* UI_FF_UPLOAD, UI_FF_ERASE */
  41. int retval;
  42. struct completion done;
  43. union {
  44. int effect_id;
  45. struct ff_effect* effect;
  46. } u;
  47. };
  48. struct uinput_device {
  49. struct input_dev *dev;
  50. unsigned long state;
  51. wait_queue_head_t waitq;
  52. unsigned char ready,
  53. head,
  54. tail;
  55. struct input_event buff[UINPUT_BUFFER_SIZE];
  56. struct uinput_request *requests[UINPUT_NUM_REQUESTS];
  57. wait_queue_head_t requests_waitq;
  58. spinlock_t requests_lock;
  59. };
  60. #endif /* __KERNEL__ */
  61. struct uinput_ff_upload {
  62. int request_id;
  63. int retval;
  64. struct ff_effect effect;
  65. };
  66. struct uinput_ff_erase {
  67. int request_id;
  68. int retval;
  69. int effect_id;
  70. };
  71. /* ioctl */
  72. #define UINPUT_IOCTL_BASE 'U'
  73. #define UI_DEV_CREATE _IO(UINPUT_IOCTL_BASE, 1)
  74. #define UI_DEV_DESTROY _IO(UINPUT_IOCTL_BASE, 2)
  75. #define UI_SET_EVBIT _IOW(UINPUT_IOCTL_BASE, 100, int)
  76. #define UI_SET_KEYBIT _IOW(UINPUT_IOCTL_BASE, 101, int)
  77. #define UI_SET_RELBIT _IOW(UINPUT_IOCTL_BASE, 102, int)
  78. #define UI_SET_ABSBIT _IOW(UINPUT_IOCTL_BASE, 103, int)
  79. #define UI_SET_MSCBIT _IOW(UINPUT_IOCTL_BASE, 104, int)
  80. #define UI_SET_LEDBIT _IOW(UINPUT_IOCTL_BASE, 105, int)
  81. #define UI_SET_SNDBIT _IOW(UINPUT_IOCTL_BASE, 106, int)
  82. #define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int)
  83. #define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*)
  84. #define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
  85. #define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
  86. #define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase)
  87. #define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase)
  88. /* To write a force-feedback-capable driver, the upload_effect
  89. * and erase_effect callbacks in input_dev must be implemented.
  90. * The uinput driver will generate a fake input event when one of
  91. * these callbacks are invoked. The userspace code then uses
  92. * ioctls to retrieve additional parameters and send the return code.
  93. * The callback blocks until this return code is sent.
  94. *
  95. * The described callback mechanism is only used if EV_FF is set.
  96. * Otherwise, default implementations of upload_effect and erase_effect
  97. * are used.
  98. *
  99. * To implement upload_effect():
  100. * 1. Wait for an event with type==EV_UINPUT and code==UI_FF_UPLOAD.
  101. * A request ID will be given in 'value'.
  102. * 2. Allocate a uinput_ff_upload struct, fill in request_id with
  103. * the 'value' from the EV_UINPUT event.
  104. * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the
  105. * uinput_ff_upload struct. It will be filled in with the
  106. * ff_effect passed to upload_effect().
  107. * 4. Perform the effect upload, and place the modified ff_effect
  108. * and a return code back into the uinput_ff_upload struct.
  109. * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the
  110. * uinput_ff_upload_effect struct. This will complete execution
  111. * of our upload_effect() handler.
  112. *
  113. * To implement erase_effect():
  114. * 1. Wait for an event with type==EV_UINPUT and code==UI_FF_ERASE.
  115. * A request ID will be given in 'value'.
  116. * 2. Allocate a uinput_ff_erase struct, fill in request_id with
  117. * the 'value' from the EV_UINPUT event.
  118. * 3. Issue a UI_BEGIN_FF_ERASE ioctl, giving it the
  119. * uinput_ff_erase struct. It will be filled in with the
  120. * effect ID passed to erase_effect().
  121. * 4. Perform the effect erasure, and place a return code back
  122. * into the uinput_ff_erase struct.
  123. * and a return code back into the uinput_ff_erase struct.
  124. * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the
  125. * uinput_ff_erase_effect struct. This will complete execution
  126. * of our erase_effect() handler.
  127. */
  128. /* This is the new event type, used only by uinput.
  129. * 'code' is UI_FF_UPLOAD or UI_FF_ERASE, and 'value'
  130. * is the unique request ID. This number was picked
  131. * arbitrarily, above EV_MAX (since the input system
  132. * never sees it) but in the range of a 16-bit int.
  133. */
  134. #define EV_UINPUT 0x0101
  135. #define UI_FF_UPLOAD 1
  136. #define UI_FF_ERASE 2
  137. #ifndef NBITS
  138. #define NBITS(x) ((((x)-1)/(sizeof(long)*8))+1)
  139. #endif /* NBITS */
  140. #define UINPUT_MAX_NAME_SIZE 80
  141. struct uinput_user_dev {
  142. char name[UINPUT_MAX_NAME_SIZE];
  143. struct input_id id;
  144. int ff_effects_max;
  145. int absmax[ABS_MAX + 1];
  146. int absmin[ABS_MAX + 1];
  147. int absfuzz[ABS_MAX + 1];
  148. int absflat[ABS_MAX + 1];
  149. };
  150. #endif /* __UINPUT_H_ */