uinput.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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.3 24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>)
  26. * - update ff support for the changes in kernel interface
  27. * - add UINPUT_VERSION
  28. * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>)
  29. * - added force feedback support
  30. * - added UI_SET_PHYS
  31. * 0.1 20/06/2002
  32. * - first public version
  33. */
  34. #include <linux/input.h>
  35. #define UINPUT_VERSION 3
  36. #ifdef __KERNEL__
  37. #define UINPUT_NAME "uinput"
  38. #define UINPUT_BUFFER_SIZE 16
  39. #define UINPUT_NUM_REQUESTS 16
  40. enum uinput_state { UIST_NEW_DEVICE, UIST_SETUP_COMPLETE, UIST_CREATED };
  41. struct uinput_request {
  42. int id;
  43. int code; /* UI_FF_UPLOAD, UI_FF_ERASE */
  44. int retval;
  45. struct completion done;
  46. union {
  47. int effect_id;
  48. struct {
  49. struct ff_effect *effect;
  50. struct ff_effect *old;
  51. } upload;
  52. } u;
  53. };
  54. struct uinput_device {
  55. struct input_dev *dev;
  56. struct mutex mutex;
  57. enum uinput_state state;
  58. wait_queue_head_t waitq;
  59. unsigned char ready;
  60. unsigned char head;
  61. unsigned char tail;
  62. struct input_event buff[UINPUT_BUFFER_SIZE];
  63. unsigned int ff_effects_max;
  64. struct uinput_request *requests[UINPUT_NUM_REQUESTS];
  65. wait_queue_head_t requests_waitq;
  66. spinlock_t requests_lock;
  67. };
  68. #endif /* __KERNEL__ */
  69. struct uinput_ff_upload {
  70. int request_id;
  71. int retval;
  72. struct ff_effect effect;
  73. struct ff_effect old;
  74. };
  75. struct uinput_ff_erase {
  76. int request_id;
  77. int retval;
  78. int effect_id;
  79. };
  80. /* ioctl */
  81. #define UINPUT_IOCTL_BASE 'U'
  82. #define UI_DEV_CREATE _IO(UINPUT_IOCTL_BASE, 1)
  83. #define UI_DEV_DESTROY _IO(UINPUT_IOCTL_BASE, 2)
  84. #define UI_SET_EVBIT _IOW(UINPUT_IOCTL_BASE, 100, int)
  85. #define UI_SET_KEYBIT _IOW(UINPUT_IOCTL_BASE, 101, int)
  86. #define UI_SET_RELBIT _IOW(UINPUT_IOCTL_BASE, 102, int)
  87. #define UI_SET_ABSBIT _IOW(UINPUT_IOCTL_BASE, 103, int)
  88. #define UI_SET_MSCBIT _IOW(UINPUT_IOCTL_BASE, 104, int)
  89. #define UI_SET_LEDBIT _IOW(UINPUT_IOCTL_BASE, 105, int)
  90. #define UI_SET_SNDBIT _IOW(UINPUT_IOCTL_BASE, 106, int)
  91. #define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int)
  92. #define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*)
  93. #define UI_SET_SWBIT _IOW(UINPUT_IOCTL_BASE, 109, int)
  94. #define UI_SET_PROPBIT _IOW(UINPUT_IOCTL_BASE, 110, int)
  95. #define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
  96. #define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
  97. #define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase)
  98. #define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase)
  99. /*
  100. * To write a force-feedback-capable driver, the upload_effect
  101. * and erase_effect callbacks in input_dev must be implemented.
  102. * The uinput driver will generate a fake input event when one of
  103. * these callbacks are invoked. The userspace code then uses
  104. * ioctls to retrieve additional parameters and send the return code.
  105. * The callback blocks until this return code is sent.
  106. *
  107. * The described callback mechanism is only used if ff_effects_max
  108. * is set.
  109. *
  110. * To implement upload_effect():
  111. * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_UPLOAD.
  112. * A request ID will be given in 'value'.
  113. * 2. Allocate a uinput_ff_upload struct, fill in request_id with
  114. * the 'value' from the EV_UINPUT event.
  115. * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the
  116. * uinput_ff_upload struct. It will be filled in with the
  117. * ff_effects passed to upload_effect().
  118. * 4. Perform the effect upload, and place a return code back into
  119. the uinput_ff_upload struct.
  120. * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the
  121. * uinput_ff_upload_effect struct. This will complete execution
  122. * of our upload_effect() handler.
  123. *
  124. * To implement erase_effect():
  125. * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_ERASE.
  126. * A request ID will be given in 'value'.
  127. * 2. Allocate a uinput_ff_erase struct, fill in request_id with
  128. * the 'value' from the EV_UINPUT event.
  129. * 3. Issue a UI_BEGIN_FF_ERASE ioctl, giving it the
  130. * uinput_ff_erase struct. It will be filled in with the
  131. * effect ID passed to erase_effect().
  132. * 4. Perform the effect erasure, and place a return code back
  133. * into the uinput_ff_erase struct.
  134. * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the
  135. * uinput_ff_erase_effect struct. This will complete execution
  136. * of our erase_effect() handler.
  137. */
  138. /*
  139. * This is the new event type, used only by uinput.
  140. * 'code' is UI_FF_UPLOAD or UI_FF_ERASE, and 'value'
  141. * is the unique request ID. This number was picked
  142. * arbitrarily, above EV_MAX (since the input system
  143. * never sees it) but in the range of a 16-bit int.
  144. */
  145. #define EV_UINPUT 0x0101
  146. #define UI_FF_UPLOAD 1
  147. #define UI_FF_ERASE 2
  148. #define UINPUT_MAX_NAME_SIZE 80
  149. struct uinput_user_dev {
  150. char name[UINPUT_MAX_NAME_SIZE];
  151. struct input_id id;
  152. int ff_effects_max;
  153. int absmax[ABS_CNT];
  154. int absmin[ABS_CNT];
  155. int absfuzz[ABS_CNT];
  156. int absflat[ABS_CNT];
  157. };
  158. #endif /* __UINPUT_H_ */