1*e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 2607ca46eSDavid Howells /* 3607ca46eSDavid Howells * User level driver support for input subsystem 4607ca46eSDavid Howells * 5607ca46eSDavid Howells * Heavily based on evdev.c by Vojtech Pavlik 6607ca46eSDavid Howells * 7607ca46eSDavid Howells * This program is free software; you can redistribute it and/or modify 8607ca46eSDavid Howells * it under the terms of the GNU General Public License as published by 9607ca46eSDavid Howells * the Free Software Foundation; either version 2 of the License, or 10607ca46eSDavid Howells * (at your option) any later version. 11607ca46eSDavid Howells * 12607ca46eSDavid Howells * This program is distributed in the hope that it will be useful, 13607ca46eSDavid Howells * but WITHOUT ANY WARRANTY; without even the implied warranty of 14607ca46eSDavid Howells * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15607ca46eSDavid Howells * GNU General Public License for more details. 16607ca46eSDavid Howells * 17607ca46eSDavid Howells * You should have received a copy of the GNU General Public License 18607ca46eSDavid Howells * along with this program; if not, write to the Free Software 19607ca46eSDavid Howells * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20607ca46eSDavid Howells * 21607ca46eSDavid Howells * Author: Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org> 22607ca46eSDavid Howells * 23607ca46eSDavid Howells * Changes/Revisions: 24052876f8SBenjamin Tissoires * 0.5 08/13/2015 (David Herrmann <dh.herrmann@gmail.com> & 25052876f8SBenjamin Tissoires * Benjamin Tissoires <benjamin.tissoires@redhat.com>) 26052876f8SBenjamin Tissoires * - add UI_DEV_SETUP ioctl 27052876f8SBenjamin Tissoires * - add UI_ABS_SETUP ioctl 28052876f8SBenjamin Tissoires * - add UI_GET_VERSION ioctl 29e3480a61SBenjamin Tissoires * 0.4 01/09/2014 (Benjamin Tissoires <benjamin.tissoires@redhat.com>) 30e3480a61SBenjamin Tissoires * - add UI_GET_SYSNAME ioctl 31607ca46eSDavid Howells * 0.3 24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>) 32607ca46eSDavid Howells * - update ff support for the changes in kernel interface 33607ca46eSDavid Howells * - add UINPUT_VERSION 34607ca46eSDavid Howells * 0.2 16/10/2004 (Micah Dowty <micah@navi.cx>) 35607ca46eSDavid Howells * - added force feedback support 36607ca46eSDavid Howells * - added UI_SET_PHYS 37607ca46eSDavid Howells * 0.1 20/06/2002 38607ca46eSDavid Howells * - first public version 39607ca46eSDavid Howells */ 40607ca46eSDavid Howells #ifndef _UAPI__UINPUT_H_ 41607ca46eSDavid Howells #define _UAPI__UINPUT_H_ 42607ca46eSDavid Howells 43607ca46eSDavid Howells #include <linux/types.h> 44607ca46eSDavid Howells #include <linux/input.h> 45607ca46eSDavid Howells 46052876f8SBenjamin Tissoires #define UINPUT_VERSION 5 47052876f8SBenjamin Tissoires #define UINPUT_MAX_NAME_SIZE 80 48607ca46eSDavid Howells 49607ca46eSDavid Howells struct uinput_ff_upload { 50607ca46eSDavid Howells __u32 request_id; 51607ca46eSDavid Howells __s32 retval; 52607ca46eSDavid Howells struct ff_effect effect; 53607ca46eSDavid Howells struct ff_effect old; 54607ca46eSDavid Howells }; 55607ca46eSDavid Howells 56607ca46eSDavid Howells struct uinput_ff_erase { 57607ca46eSDavid Howells __u32 request_id; 58607ca46eSDavid Howells __s32 retval; 59607ca46eSDavid Howells __u32 effect_id; 60607ca46eSDavid Howells }; 61607ca46eSDavid Howells 62607ca46eSDavid Howells /* ioctl */ 63607ca46eSDavid Howells #define UINPUT_IOCTL_BASE 'U' 64607ca46eSDavid Howells #define UI_DEV_CREATE _IO(UINPUT_IOCTL_BASE, 1) 65607ca46eSDavid Howells #define UI_DEV_DESTROY _IO(UINPUT_IOCTL_BASE, 2) 66607ca46eSDavid Howells 67052876f8SBenjamin Tissoires struct uinput_setup { 68052876f8SBenjamin Tissoires struct input_id id; 69052876f8SBenjamin Tissoires char name[UINPUT_MAX_NAME_SIZE]; 70052876f8SBenjamin Tissoires __u32 ff_effects_max; 71052876f8SBenjamin Tissoires }; 72052876f8SBenjamin Tissoires 73052876f8SBenjamin Tissoires /** 74052876f8SBenjamin Tissoires * UI_DEV_SETUP - Set device parameters for setup 75052876f8SBenjamin Tissoires * 76fbae10dbSDavid Herrmann * This ioctl sets parameters for the input device to be created. It 77fbae10dbSDavid Herrmann * supersedes the old "struct uinput_user_dev" method, which wrote this data 78fbae10dbSDavid Herrmann * via write(). To actually set the absolute axes UI_ABS_SETUP should be 79fbae10dbSDavid Herrmann * used. 80052876f8SBenjamin Tissoires * 81fbae10dbSDavid Herrmann * The ioctl takes a "struct uinput_setup" object as argument. The fields of 82052876f8SBenjamin Tissoires * this object are as follows: 83052876f8SBenjamin Tissoires * id: See the description of "struct input_id". This field is 84052876f8SBenjamin Tissoires * copied unchanged into the new device. 85052876f8SBenjamin Tissoires * name: This is used unchanged as name for the new device. 86052876f8SBenjamin Tissoires * ff_effects_max: This limits the maximum numbers of force-feedback effects. 87052876f8SBenjamin Tissoires * See below for a description of FF with uinput. 88052876f8SBenjamin Tissoires * 89052876f8SBenjamin Tissoires * This ioctl can be called multiple times and will overwrite previous values. 90fbae10dbSDavid Herrmann * If this ioctl fails with -EINVAL, it is recommended to use the old 91fbae10dbSDavid Herrmann * "uinput_user_dev" method via write() as a fallback, in case you run on an 92fbae10dbSDavid Herrmann * old kernel that does not support this ioctl. 93052876f8SBenjamin Tissoires * 94052876f8SBenjamin Tissoires * This ioctl may fail with -EINVAL if it is not supported or if you passed 95052876f8SBenjamin Tissoires * incorrect values, -ENOMEM if the kernel runs out of memory or -EFAULT if the 96052876f8SBenjamin Tissoires * passed uinput_setup object cannot be read/written. 97052876f8SBenjamin Tissoires * If this call fails, partial data may have already been applied to the 98052876f8SBenjamin Tissoires * internal device. 99052876f8SBenjamin Tissoires */ 100052876f8SBenjamin Tissoires #define UI_DEV_SETUP _IOW(UINPUT_IOCTL_BASE, 3, struct uinput_setup) 101052876f8SBenjamin Tissoires 102052876f8SBenjamin Tissoires struct uinput_abs_setup { 103052876f8SBenjamin Tissoires __u16 code; /* axis code */ 104052876f8SBenjamin Tissoires /* __u16 filler; */ 105052876f8SBenjamin Tissoires struct input_absinfo absinfo; 106052876f8SBenjamin Tissoires }; 107052876f8SBenjamin Tissoires 108052876f8SBenjamin Tissoires /** 109052876f8SBenjamin Tissoires * UI_ABS_SETUP - Set absolute axis information for the device to setup 110052876f8SBenjamin Tissoires * 111052876f8SBenjamin Tissoires * This ioctl sets one absolute axis information for the input device to be 112fbae10dbSDavid Herrmann * created. It supersedes the old "struct uinput_user_dev" method, which wrote 113052876f8SBenjamin Tissoires * part of this data and the content of UI_DEV_SETUP via write(). 114052876f8SBenjamin Tissoires * 115fbae10dbSDavid Herrmann * The ioctl takes a "struct uinput_abs_setup" object as argument. The fields 116052876f8SBenjamin Tissoires * of this object are as follows: 117052876f8SBenjamin Tissoires * code: The corresponding input code associated with this axis 118052876f8SBenjamin Tissoires * (ABS_X, ABS_Y, etc...) 119052876f8SBenjamin Tissoires * absinfo: See "struct input_absinfo" for a description of this field. 120052876f8SBenjamin Tissoires * This field is copied unchanged into the kernel for the 121052876f8SBenjamin Tissoires * specified axis. If the axis is not enabled via 122052876f8SBenjamin Tissoires * UI_SET_ABSBIT, this ioctl will enable it. 123052876f8SBenjamin Tissoires * 124052876f8SBenjamin Tissoires * This ioctl can be called multiple times and will overwrite previous values. 125fbae10dbSDavid Herrmann * If this ioctl fails with -EINVAL, it is recommended to use the old 126fbae10dbSDavid Herrmann * "uinput_user_dev" method via write() as a fallback, in case you run on an 127fbae10dbSDavid Herrmann * old kernel that does not support this ioctl. 128052876f8SBenjamin Tissoires * 129052876f8SBenjamin Tissoires * This ioctl may fail with -EINVAL if it is not supported or if you passed 130052876f8SBenjamin Tissoires * incorrect values, -ENOMEM if the kernel runs out of memory or -EFAULT if the 131052876f8SBenjamin Tissoires * passed uinput_setup object cannot be read/written. 132052876f8SBenjamin Tissoires * If this call fails, partial data may have already been applied to the 133052876f8SBenjamin Tissoires * internal device. 134052876f8SBenjamin Tissoires */ 135052876f8SBenjamin Tissoires #define UI_ABS_SETUP _IOW(UINPUT_IOCTL_BASE, 4, struct uinput_abs_setup) 136052876f8SBenjamin Tissoires 137607ca46eSDavid Howells #define UI_SET_EVBIT _IOW(UINPUT_IOCTL_BASE, 100, int) 138607ca46eSDavid Howells #define UI_SET_KEYBIT _IOW(UINPUT_IOCTL_BASE, 101, int) 139607ca46eSDavid Howells #define UI_SET_RELBIT _IOW(UINPUT_IOCTL_BASE, 102, int) 140607ca46eSDavid Howells #define UI_SET_ABSBIT _IOW(UINPUT_IOCTL_BASE, 103, int) 141607ca46eSDavid Howells #define UI_SET_MSCBIT _IOW(UINPUT_IOCTL_BASE, 104, int) 142607ca46eSDavid Howells #define UI_SET_LEDBIT _IOW(UINPUT_IOCTL_BASE, 105, int) 143607ca46eSDavid Howells #define UI_SET_SNDBIT _IOW(UINPUT_IOCTL_BASE, 106, int) 144607ca46eSDavid Howells #define UI_SET_FFBIT _IOW(UINPUT_IOCTL_BASE, 107, int) 145607ca46eSDavid Howells #define UI_SET_PHYS _IOW(UINPUT_IOCTL_BASE, 108, char*) 146607ca46eSDavid Howells #define UI_SET_SWBIT _IOW(UINPUT_IOCTL_BASE, 109, int) 147607ca46eSDavid Howells #define UI_SET_PROPBIT _IOW(UINPUT_IOCTL_BASE, 110, int) 148607ca46eSDavid Howells 149607ca46eSDavid Howells #define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload) 150607ca46eSDavid Howells #define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload) 151607ca46eSDavid Howells #define UI_BEGIN_FF_ERASE _IOWR(UINPUT_IOCTL_BASE, 202, struct uinput_ff_erase) 152607ca46eSDavid Howells #define UI_END_FF_ERASE _IOW(UINPUT_IOCTL_BASE, 203, struct uinput_ff_erase) 153607ca46eSDavid Howells 154e3480a61SBenjamin Tissoires /** 155e3480a61SBenjamin Tissoires * UI_GET_SYSNAME - get the sysfs name of the created uinput device 156e3480a61SBenjamin Tissoires * 157e3480a61SBenjamin Tissoires * @return the sysfs name of the created virtual input device. 158e3480a61SBenjamin Tissoires * The complete sysfs path is then /sys/devices/virtual/input/--NAME-- 159e3480a61SBenjamin Tissoires * Usually, it is in the form "inputN" 160e3480a61SBenjamin Tissoires */ 161029b1836SGabriel Laskar #define UI_GET_SYSNAME(len) _IOC(_IOC_READ, UINPUT_IOCTL_BASE, 44, len) 162e3480a61SBenjamin Tissoires 163ba4e9a61SDavid Herrmann /** 164ba4e9a61SDavid Herrmann * UI_GET_VERSION - Return version of uinput protocol 165ba4e9a61SDavid Herrmann * 166ba4e9a61SDavid Herrmann * This writes uinput protocol version implemented by the kernel into 167ba4e9a61SDavid Herrmann * the integer pointed to by the ioctl argument. The protocol version 168ba4e9a61SDavid Herrmann * is hard-coded in the kernel and is independent of the uinput device. 169ba4e9a61SDavid Herrmann */ 170029b1836SGabriel Laskar #define UI_GET_VERSION _IOR(UINPUT_IOCTL_BASE, 45, unsigned int) 171ba4e9a61SDavid Herrmann 172607ca46eSDavid Howells /* 173607ca46eSDavid Howells * To write a force-feedback-capable driver, the upload_effect 174607ca46eSDavid Howells * and erase_effect callbacks in input_dev must be implemented. 175607ca46eSDavid Howells * The uinput driver will generate a fake input event when one of 176607ca46eSDavid Howells * these callbacks are invoked. The userspace code then uses 177607ca46eSDavid Howells * ioctls to retrieve additional parameters and send the return code. 178607ca46eSDavid Howells * The callback blocks until this return code is sent. 179607ca46eSDavid Howells * 180607ca46eSDavid Howells * The described callback mechanism is only used if ff_effects_max 181607ca46eSDavid Howells * is set. 182607ca46eSDavid Howells * 183607ca46eSDavid Howells * To implement upload_effect(): 184607ca46eSDavid Howells * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_UPLOAD. 185607ca46eSDavid Howells * A request ID will be given in 'value'. 186607ca46eSDavid Howells * 2. Allocate a uinput_ff_upload struct, fill in request_id with 187607ca46eSDavid Howells * the 'value' from the EV_UINPUT event. 188607ca46eSDavid Howells * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the 189607ca46eSDavid Howells * uinput_ff_upload struct. It will be filled in with the 190607ca46eSDavid Howells * ff_effects passed to upload_effect(). 191607ca46eSDavid Howells * 4. Perform the effect upload, and place a return code back into 192607ca46eSDavid Howells the uinput_ff_upload struct. 193607ca46eSDavid Howells * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the 194607ca46eSDavid Howells * uinput_ff_upload_effect struct. This will complete execution 195607ca46eSDavid Howells * of our upload_effect() handler. 196607ca46eSDavid Howells * 197607ca46eSDavid Howells * To implement erase_effect(): 198607ca46eSDavid Howells * 1. Wait for an event with type == EV_UINPUT and code == UI_FF_ERASE. 199607ca46eSDavid Howells * A request ID will be given in 'value'. 200607ca46eSDavid Howells * 2. Allocate a uinput_ff_erase struct, fill in request_id with 201607ca46eSDavid Howells * the 'value' from the EV_UINPUT event. 202607ca46eSDavid Howells * 3. Issue a UI_BEGIN_FF_ERASE ioctl, giving it the 203607ca46eSDavid Howells * uinput_ff_erase struct. It will be filled in with the 204607ca46eSDavid Howells * effect ID passed to erase_effect(). 205607ca46eSDavid Howells * 4. Perform the effect erasure, and place a return code back 206607ca46eSDavid Howells * into the uinput_ff_erase struct. 207607ca46eSDavid Howells * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the 208607ca46eSDavid Howells * uinput_ff_erase_effect struct. This will complete execution 209607ca46eSDavid Howells * of our erase_effect() handler. 210607ca46eSDavid Howells */ 211607ca46eSDavid Howells 212607ca46eSDavid Howells /* 213607ca46eSDavid Howells * This is the new event type, used only by uinput. 214607ca46eSDavid Howells * 'code' is UI_FF_UPLOAD or UI_FF_ERASE, and 'value' 215607ca46eSDavid Howells * is the unique request ID. This number was picked 216607ca46eSDavid Howells * arbitrarily, above EV_MAX (since the input system 217607ca46eSDavid Howells * never sees it) but in the range of a 16-bit int. 218607ca46eSDavid Howells */ 219607ca46eSDavid Howells #define EV_UINPUT 0x0101 220607ca46eSDavid Howells #define UI_FF_UPLOAD 1 221607ca46eSDavid Howells #define UI_FF_ERASE 2 222607ca46eSDavid Howells 223607ca46eSDavid Howells struct uinput_user_dev { 224607ca46eSDavid Howells char name[UINPUT_MAX_NAME_SIZE]; 225607ca46eSDavid Howells struct input_id id; 226607ca46eSDavid Howells __u32 ff_effects_max; 227607ca46eSDavid Howells __s32 absmax[ABS_CNT]; 228607ca46eSDavid Howells __s32 absmin[ABS_CNT]; 229607ca46eSDavid Howells __s32 absfuzz[ABS_CNT]; 230607ca46eSDavid Howells __s32 absflat[ABS_CNT]; 231607ca46eSDavid Howells }; 232607ca46eSDavid Howells #endif /* _UAPI__UINPUT_H_ */ 233