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