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