Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 #ifndef _UAPI_ASM_GENERIC_IOCTL_H
0003 #define _UAPI_ASM_GENERIC_IOCTL_H
0004 
0005 /* ioctl command encoding: 32 bits total, command in lower 16 bits,
0006  * size of the parameter structure in the lower 14 bits of the
0007  * upper 16 bits.
0008  * Encoding the size of the parameter structure in the ioctl request
0009  * is useful for catching programs compiled with old versions
0010  * and to avoid overwriting user space outside the user buffer area.
0011  * The highest 2 bits are reserved for indicating the ``access mode''.
0012  * NOTE: This limits the max parameter size to 16kB -1 !
0013  */
0014 
0015 /*
0016  * The following is for compatibility across the various Linux
0017  * platforms.  The generic ioctl numbering scheme doesn't really enforce
0018  * a type field.  De facto, however, the top 8 bits of the lower 16
0019  * bits are indeed used as a type field, so we might just as well make
0020  * this explicit here.  Please be sure to use the decoding macros
0021  * below from now on.
0022  */
0023 #define _IOC_NRBITS 8
0024 #define _IOC_TYPEBITS   8
0025 
0026 /*
0027  * Let any architecture override either of the following before
0028  * including this file.
0029  */
0030 
0031 #ifndef _IOC_SIZEBITS
0032 # define _IOC_SIZEBITS  14
0033 #endif
0034 
0035 #ifndef _IOC_DIRBITS
0036 # define _IOC_DIRBITS   2
0037 #endif
0038 
0039 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
0040 #define _IOC_TYPEMASK   ((1 << _IOC_TYPEBITS)-1)
0041 #define _IOC_SIZEMASK   ((1 << _IOC_SIZEBITS)-1)
0042 #define _IOC_DIRMASK    ((1 << _IOC_DIRBITS)-1)
0043 
0044 #define _IOC_NRSHIFT    0
0045 #define _IOC_TYPESHIFT  (_IOC_NRSHIFT+_IOC_NRBITS)
0046 #define _IOC_SIZESHIFT  (_IOC_TYPESHIFT+_IOC_TYPEBITS)
0047 #define _IOC_DIRSHIFT   (_IOC_SIZESHIFT+_IOC_SIZEBITS)
0048 
0049 /*
0050  * Direction bits, which any architecture can choose to override
0051  * before including this file.
0052  *
0053  * NOTE: _IOC_WRITE means userland is writing and kernel is
0054  * reading. _IOC_READ means userland is reading and kernel is writing.
0055  */
0056 
0057 #ifndef _IOC_NONE
0058 # define _IOC_NONE  0U
0059 #endif
0060 
0061 #ifndef _IOC_WRITE
0062 # define _IOC_WRITE 1U
0063 #endif
0064 
0065 #ifndef _IOC_READ
0066 # define _IOC_READ  2U
0067 #endif
0068 
0069 #define _IOC(dir,type,nr,size) \
0070     (((dir)  << _IOC_DIRSHIFT) | \
0071      ((type) << _IOC_TYPESHIFT) | \
0072      ((nr)   << _IOC_NRSHIFT) | \
0073      ((size) << _IOC_SIZESHIFT))
0074 
0075 #ifndef __KERNEL__
0076 #define _IOC_TYPECHECK(t) (sizeof(t))
0077 #endif
0078 
0079 /*
0080  * Used to create numbers.
0081  *
0082  * NOTE: _IOW means userland is writing and kernel is reading. _IOR
0083  * means userland is reading and kernel is writing.
0084  */
0085 #define _IO(type,nr)        _IOC(_IOC_NONE,(type),(nr),0)
0086 #define _IOR(type,nr,size)  _IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
0087 #define _IOW(type,nr,size)  _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
0088 #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
0089 #define _IOR_BAD(type,nr,size)  _IOC(_IOC_READ,(type),(nr),sizeof(size))
0090 #define _IOW_BAD(type,nr,size)  _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
0091 #define _IOWR_BAD(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
0092 
0093 /* used to decode ioctl numbers.. */
0094 #define _IOC_DIR(nr)        (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
0095 #define _IOC_TYPE(nr)       (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
0096 #define _IOC_NR(nr)     (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
0097 #define _IOC_SIZE(nr)       (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
0098 
0099 /* ...and for the drivers/sound files... */
0100 
0101 #define IOC_IN      (_IOC_WRITE << _IOC_DIRSHIFT)
0102 #define IOC_OUT     (_IOC_READ << _IOC_DIRSHIFT)
0103 #define IOC_INOUT   ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
0104 #define IOCSIZE_MASK    (_IOC_SIZEMASK << _IOC_SIZESHIFT)
0105 #define IOCSIZE_SHIFT   (_IOC_SIZESHIFT)
0106 
0107 #endif /* _UAPI_ASM_GENERIC_IOCTL_H */