]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/uinput.h
Merge branch 'lguest' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux...
[net-next-2.6.git] / include / linux / uinput.h
CommitLineData
1da177e4
LT
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>
221979aa 23 *
1da177e4 24 * Changes/Revisions:
ff462551
AH
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
1da177e4
LT
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 */
ff462551 34
a830df36
MF
35#include <linux/input.h>
36
ff462551
AH
37#define UINPUT_VERSION 3
38
1da177e4 39#ifdef __KERNEL__
1da177e4
LT
40#define UINPUT_NAME "uinput"
41#define UINPUT_BUFFER_SIZE 16
42#define UINPUT_NUM_REQUESTS 16
43
29506415 44enum uinput_state { UIST_NEW_DEVICE, UIST_SETUP_COMPLETE, UIST_CREATED };
1da177e4
LT
45
46struct uinput_request {
47 int id;
48 int code; /* UI_FF_UPLOAD, UI_FF_ERASE */
49
50 int retval;
0048e603 51 struct completion done;
1da177e4
LT
52
53 union {
54 int effect_id;
ff462551
AH
55 struct {
56 struct ff_effect *effect;
57 struct ff_effect *old;
58 } upload;
1da177e4
LT
59 } u;
60};
61
62struct uinput_device {
63 struct input_dev *dev;
221979aa 64 struct mutex mutex;
29506415 65 enum uinput_state state;
1da177e4 66 wait_queue_head_t waitq;
29506415
DT
67 unsigned char ready;
68 unsigned char head;
69 unsigned char tail;
1da177e4 70 struct input_event buff[UINPUT_BUFFER_SIZE];
ff462551 71 int ff_effects_max;
1da177e4
LT
72
73 struct uinput_request *requests[UINPUT_NUM_REQUESTS];
74 wait_queue_head_t requests_waitq;
0048e603 75 spinlock_t requests_lock;
1da177e4
LT
76};
77#endif /* __KERNEL__ */
78
79struct uinput_ff_upload {
80 int request_id;
81 int retval;
82 struct ff_effect effect;
ff462551 83 struct ff_effect old;
1da177e4
LT
84};
85
86struct uinput_ff_erase {
87 int request_id;
88 int retval;
89 int effect_id;
90};
91
92/* ioctl */
93#define UINPUT_IOCTL_BASE 'U'
94#define UI_DEV_CREATE _IO(UINPUT_IOCTL_BASE, 1)
95#define UI_DEV_DESTROY _IO(UINPUT_IOCTL_BASE, 2)
96
97#define UI_SET_EVBIT _IOW(UINPUT_IOCTL_BASE, 100, int)
98#define UI_SET_KEYBIT _IOW(UINPUT_IOCTL_BASE, 101, int)
99#define UI_SET_RELBIT _IOW(UINPUT_IOCTL_BASE, 102, int)
100#define UI_SET_ABSBIT _IOW(UINPUT_IOCTL_BASE, 103, int)
101#define UI_SET_MSCBIT _IOW(UINPUT_IOCTL_BASE, 104, int)
102#define UI_SET_LEDBIT _IOW(UINPUT_IOCTL_BASE, 105, int)
103#define UI_SET_SNDBIT _IOW(UINPUT_IOCTL_BASE, 106, int)
104#define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int)
105#define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*)
59c7c037 106#define UI_SET_SWBIT _IOW(UINPUT_IOCTL_BASE, 109, int)
1da177e4
LT
107
108#define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
109#define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
110#define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase)
111#define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase)
112
ff462551
AH
113/*
114 * To write a force-feedback-capable driver, the upload_effect
1da177e4
LT
115 * and erase_effect callbacks in input_dev must be implemented.
116 * The uinput driver will generate a fake input event when one of
117 * these callbacks are invoked. The userspace code then uses
118 * ioctls to retrieve additional parameters and send the return code.
119 * The callback blocks until this return code is sent.
120 *
ff462551
AH
121 * The described callback mechanism is only used if ff_effects_max
122 * is set.
1da177e4
LT
123 *
124 * To implement upload_effect():
ff462551 125 * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_UPLOAD.
1da177e4
LT
126 * A request ID will be given in 'value'.
127 * 2. Allocate a uinput_ff_upload struct, fill in request_id with
128 * the 'value' from the EV_UINPUT event.
129 * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the
130 * uinput_ff_upload struct. It will be filled in with the
ff462551
AH
131 * ff_effects passed to upload_effect().
132 * 4. Perform the effect upload, and place a return code back into
133 the uinput_ff_upload struct.
1da177e4
LT
134 * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the
135 * uinput_ff_upload_effect struct. This will complete execution
136 * of our upload_effect() handler.
137 *
138 * To implement erase_effect():
ff462551 139 * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_ERASE.
1da177e4
LT
140 * A request ID will be given in 'value'.
141 * 2. Allocate a uinput_ff_erase struct, fill in request_id with
142 * the 'value' from the EV_UINPUT event.
143 * 3. Issue a UI_BEGIN_FF_ERASE ioctl, giving it the
144 * uinput_ff_erase struct. It will be filled in with the
145 * effect ID passed to erase_effect().
146 * 4. Perform the effect erasure, and place a return code back
147 * into the uinput_ff_erase struct.
1da177e4
LT
148 * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the
149 * uinput_ff_erase_effect struct. This will complete execution
150 * of our erase_effect() handler.
151 */
152
ff462551
AH
153/*
154 * This is the new event type, used only by uinput.
1da177e4
LT
155 * 'code' is UI_FF_UPLOAD or UI_FF_ERASE, and 'value'
156 * is the unique request ID. This number was picked
157 * arbitrarily, above EV_MAX (since the input system
158 * never sees it) but in the range of a 16-bit int.
159 */
160#define EV_UINPUT 0x0101
161#define UI_FF_UPLOAD 1
162#define UI_FF_ERASE 2
163
1da177e4
LT
164#define UINPUT_MAX_NAME_SIZE 80
165struct uinput_user_dev {
166 char name[UINPUT_MAX_NAME_SIZE];
167 struct input_id id;
81c2a3ba
DM
168 int ff_effects_max;
169 int absmax[ABS_CNT];
170 int absmin[ABS_CNT];
171 int absfuzz[ABS_CNT];
172 int absflat[ABS_CNT];
1da177e4
LT
173};
174#endif /* __UINPUT_H_ */
175