Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _SPARC_IOCTL_H |
| 2 | #define _SPARC_IOCTL_H |
| 3 | |
| 4 | /* |
| 5 | * Our DIR and SIZE overlap in order to simulteneously provide |
| 6 | * a non-zero _IOC_NONE (for binary compatibility) and |
| 7 | * 14 bits of size as on i386. Here's the layout: |
| 8 | * |
| 9 | * 0xE0000000 DIR |
| 10 | * 0x80000000 DIR = WRITE |
| 11 | * 0x40000000 DIR = READ |
| 12 | * 0x20000000 DIR = NONE |
| 13 | * 0x3FFF0000 SIZE (overlaps NONE bit) |
| 14 | * 0x0000FF00 TYPE |
| 15 | * 0x000000FF NR (CMD) |
| 16 | */ |
| 17 | |
| 18 | #define _IOC_NRBITS 8 |
| 19 | #define _IOC_TYPEBITS 8 |
| 20 | #define _IOC_SIZEBITS 13 /* Actually 14, see below. */ |
| 21 | #define _IOC_DIRBITS 3 |
| 22 | |
| 23 | #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) |
| 24 | #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) |
| 25 | #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) |
| 26 | #define _IOC_XSIZEMASK ((1 << (_IOC_SIZEBITS+1))-1) |
| 27 | #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) |
| 28 | |
| 29 | #define _IOC_NRSHIFT 0 |
| 30 | #define _IOC_TYPESHIFT (_IOC_NRSHIFT + _IOC_NRBITS) |
| 31 | #define _IOC_SIZESHIFT (_IOC_TYPESHIFT + _IOC_TYPEBITS) |
| 32 | #define _IOC_DIRSHIFT (_IOC_SIZESHIFT + _IOC_SIZEBITS) |
| 33 | |
| 34 | #define _IOC_NONE 1U |
| 35 | #define _IOC_READ 2U |
| 36 | #define _IOC_WRITE 4U |
| 37 | |
| 38 | #define _IOC(dir,type,nr,size) \ |
| 39 | (((dir) << _IOC_DIRSHIFT) | \ |
| 40 | ((type) << _IOC_TYPESHIFT) | \ |
| 41 | ((nr) << _IOC_NRSHIFT) | \ |
| 42 | ((size) << _IOC_SIZESHIFT)) |
| 43 | |
| 44 | #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) |
| 45 | #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) |
| 46 | #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) |
| 47 | #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) |
| 48 | |
| 49 | /* Used to decode ioctl numbers in drivers despite the leading underscore... */ |
| 50 | #define _IOC_DIR(nr) \ |
| 51 | ( (((((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) & (_IOC_WRITE|_IOC_READ)) != 0)? \ |
| 52 | (((nr) >> _IOC_DIRSHIFT) & (_IOC_WRITE|_IOC_READ)): \ |
| 53 | (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) ) |
| 54 | #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK) |
| 55 | #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) |
| 56 | #define _IOC_SIZE(nr) \ |
| 57 | ((((((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) & (_IOC_WRITE|_IOC_READ)) == 0)? \ |
| 58 | 0: (((nr) >> _IOC_SIZESHIFT) & _IOC_XSIZEMASK)) |
| 59 | |
| 60 | /* ...and for the PCMCIA and sound. */ |
| 61 | #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT) |
| 62 | #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT) |
| 63 | #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT) |
| 64 | #define IOCSIZE_MASK (_IOC_XSIZEMASK << _IOC_SIZESHIFT) |
| 65 | #define IOCSIZE_SHIFT (_IOC_SIZESHIFT) |
| 66 | |
| 67 | #endif /* !(_SPARC_IOCTL_H) */ |