uinput.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  2. /*
  3. * User level driver support for input subsystem
  4. *
  5. * Heavily based on evdev.c by Vojtech Pavlik
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
  22. *
  23. * Changes/Revisions:
  24. * 0.5 08/13/2015 (David Herrmann <dh.herrmann@gmail.com> &
  25. * Benjamin Tissoires <benjamin.tissoires@redhat.com>)
  26. * - add UI_DEV_SETUP ioctl
  27. * - add UI_ABS_SETUP ioctl
  28. * - add UI_GET_VERSION ioctl
  29. * 0.4 01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>)
  30. * - add UI_GET_SYSNAME ioctl
  31. * 0.3 24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>)
  32. * - update ff support for the changes in kernel interface
  33. * - add UINPUT_VERSION
  34. * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>)
  35. * - added force feedback support
  36. * - added UI_SET_PHYS
  37. * 0.1 20/06/2002
  38. * - first public version
  39. */
  40. #ifndef _UAPI__UINPUT_H_
  41. #define _UAPI__UINPUT_H_
  42. #include <linux/types.h>
  43. #include <linux/input.h>
  44. #define UINPUT_VERSION 5
  45. #define UINPUT_MAX_NAME_SIZE 80
  46. struct uinput_ff_upload {
  47. __u32 request_id;
  48. __s32 retval;
  49. struct ff_effect effect;
  50. struct ff_effect old;
  51. };
  52. struct uinput_ff_erase {
  53. __u32 request_id;
  54. __s32 retval;
  55. __u32 effect_id;
  56. };
  57. /* ioctl */
  58. #define UINPUT_IOCTL_BASE 'U'
  59. #define UI_DEV_CREATE _IO(UINPUT_IOCTL_BASE, 1)
  60. #define UI_DEV_DESTROY _IO(UINPUT_IOCTL_BASE, 2)
  61. struct uinput_setup {
  62. struct input_id id;
  63. char name[UINPUT_MAX_NAME_SIZE];
  64. __u32 ff_effects_max;
  65. };
  66. /**
  67. * UI_DEV_SETUP - Set device parameters for setup
  68. *
  69. * This ioctl sets parameters for the input device to be created. It
  70. * supersedes the old "struct uinput_user_dev" method, which wrote this data
  71. * via write(). To actually set the absolute axes UI_ABS_SETUP should be
  72. * used.
  73. *
  74. * The ioctl takes a "struct uinput_setup" object as argument. The fields of
  75. * this object are as follows:
  76. * id: See the description of "struct input_id". This field is
  77. * copied unchanged into the new device.
  78. * name: This is used unchanged as name for the new device.
  79. * ff_effects_max: This limits the maximum numbers of force-feedback effects.
  80. * See below for a description of FF with uinput.
  81. *
  82. * This ioctl can be called multiple times and will overwrite previous values.
  83. * If this ioctl fails with -EINVAL, it is recommended to use the old
  84. * "uinput_user_dev" method via write() as a fallback, in case you run on an
  85. * old kernel that does not support this ioctl.
  86. *
  87. * This ioctl may fail with -EINVAL if it is not supported or if you passed
  88. * incorrect values, -ENOMEM if the kernel runs out of memory or -EFAULT if the
  89. * passed uinput_setup object cannot be read/written.
  90. * If this call fails, partial data may have already been applied to the
  91. * internal device.
  92. */
  93. #define UI_DEV_SETUP _IOW(UINPUT_IOCTL_BASE, 3, struct uinput_setup)
  94. struct uinput_abs_setup {
  95. __u16 code; /* axis code */
  96. /* __u16 filler; */
  97. struct input_absinfo absinfo;
  98. };
  99. /**
  100. * UI_ABS_SETUP - Set absolute axis information for the device to setup
  101. *
  102. * This ioctl sets one absolute axis information for the input device to be
  103. * created. It supersedes the old "struct uinput_user_dev" method, which wrote
  104. * part of this data and the content of UI_DEV_SETUP via write().
  105. *
  106. * The ioctl takes a "struct uinput_abs_setup" object as argument. The fields
  107. * of this object are as follows:
  108. * code: The corresponding input code associated with this axis
  109. * (ABS_X, ABS_Y, etc...)
  110. * absinfo: See "struct input_absinfo" for a description of this field.
  111. * This field is copied unchanged into the kernel for the
  112. * specified axis. If the axis is not enabled via
  113. * UI_SET_ABSBIT, this ioctl will enable it.
  114. *
  115. * This ioctl can be called multiple times and will overwrite previous values.
  116. * If this ioctl fails with -EINVAL, it is recommended to use the old
  117. * "uinput_user_dev" method via write() as a fallback, in case you run on an
  118. * old kernel that does not support this ioctl.
  119. *
  120. * This ioctl may fail with -EINVAL if it is not supported or if you passed
  121. * incorrect values, -ENOMEM if the kernel runs out of memory or -EFAULT if the
  122. * passed uinput_setup object cannot be read/written.
  123. * If this call fails, partial data may have already been applied to the
  124. * internal device.
  125. */
  126. #define UI_ABS_SETUP _IOW(UINPUT_IOCTL_BASE, 4, struct uinput_abs_setup)
  127. #define UI_SET_EVBIT _IOW(UINPUT_IOCTL_BASE, 100, int)
  128. #define UI_SET_KEYBIT _IOW(UINPUT_IOCTL_BASE, 101, int)
  129. #define UI_SET_RELBIT _IOW(UINPUT_IOCTL_BASE, 102, int)
  130. #define UI_SET_ABSBIT _IOW(UINPUT_IOCTL_BASE, 103, int)
  131. #define UI_SET_MSCBIT _IOW(UINPUT_IOCTL_BASE, 104, int)
  132. #define UI_SET_LEDBIT _IOW(UINPUT_IOCTL_BASE, 105, int)
  133. #define UI_SET_SNDBIT _IOW(UINPUT_IOCTL_BASE, 106, int)
  134. #define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int)
  135. #define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*)
  136. #define UI_SET_SWBIT _IOW(UINPUT_IOCTL_BASE, 109, int)
  137. #define UI_SET_PROPBIT _IOW(UINPUT_IOCTL_BASE, 110, int)
  138. #define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
  139. #define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
  140. #define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase)
  141. #define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase)
  142. /**
  143. * UI_GET_SYSNAME - get the sysfs name of the created uinput device
  144. *
  145. * @return the sysfs name of the created virtual input device.
  146. * The complete sysfs path is then /sys/devices/virtual/input/--NAME--
  147. * Usually, it is in the form "inputN"
  148. */
  149. #define UI_GET_SYSNAME(len) _IOC(_IOC_READ, UINPUT_IOCTL_BASE, 44, len)
  150. /**
  151. * UI_GET_VERSION - Return version of uinput protocol
  152. *
  153. * This writes uinput protocol version implemented by the kernel into
  154. * the integer pointed to by the ioctl argument. The protocol version
  155. * is hard-coded in the kernel and is independent of the uinput device.
  156. */
  157. #define UI_GET_VERSION _IOR(UINPUT_IOCTL_BASE, 45, unsigned int)
  158. /*
  159. * To write a force-feedback-capable driver, the upload_effect
  160. * and erase_effect callbacks in input_dev must be implemented.
  161. * The uinput driver will generate a fake input event when one of
  162. * these callbacks are invoked. The userspace code then uses
  163. * ioctls to retrieve additional parameters and send the return code.
  164. * The callback blocks until this return code is sent.
  165. *
  166. * The described callback mechanism is only used if ff_effects_max
  167. * is set.
  168. *
  169. * To implement upload_effect():
  170. * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_UPLOAD.
  171. * A request ID will be given in 'value'.
  172. * 2. Allocate a uinput_ff_upload struct, fill in request_id with
  173. * the 'value' from the EV_UINPUT event.
  174. * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the
  175. * uinput_ff_upload struct. It will be filled in with the
  176. * ff_effects passed to upload_effect().
  177. * 4. Perform the effect upload, and place a return code back into
  178. the uinput_ff_upload struct.
  179. * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the
  180. * uinput_ff_upload_effect struct. This will complete execution
  181. * of our upload_effect() handler.
  182. *
  183. * To implement erase_effect():
  184. * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_ERASE.
  185. * A request ID will be given in 'value'.
  186. * 2. Allocate a uinput_ff_erase struct, fill in request_id with
  187. * the 'value' from the EV_UINPUT event.
  188. * 3. Issue a UI_BEGIN_FF_ERASE ioctl, giving it the
  189. * uinput_ff_erase struct. It will be filled in with the
  190. * effect ID passed to erase_effect().
  191. * 4. Perform the effect erasure, and place a return code back
  192. * into the uinput_ff_erase struct.
  193. * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the
  194. * uinput_ff_erase_effect struct. This will complete execution
  195. * of our erase_effect() handler.
  196. */
  197. /*
  198. * This is the new event type, used only by uinput.
  199. * 'code' is UI_FF_UPLOAD or UI_FF_ERASE, and 'value'
  200. * is the unique request ID. This number was picked
  201. * arbitrarily, above EV_MAX (since the input system
  202. * never sees it) but in the range of a 16-bit int.
  203. */
  204. #define EV_UINPUT 0x0101
  205. #define UI_FF_UPLOAD 1
  206. #define UI_FF_ERASE 2
  207. struct uinput_user_dev {
  208. char name[UINPUT_MAX_NAME_SIZE];
  209. struct input_id id;
  210. __u32 ff_effects_max;
  211. __s32 absmax[ABS_CNT];
  212. __s32 absmin[ABS_CNT];
  213. __s32 absfuzz[ABS_CNT];
  214. __s32 absflat[ABS_CNT];
  215. };
  216. #endif /* _UAPI__UINPUT_H_ */