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