1633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
2633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * This file is subject to the terms and conditions of the GNU General Public
3633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * License.  See the file "COPYING" in the main directory of this archive
4633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * for more details.
5633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham *
6633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Copyright (C) 1995, 96, 99, 2001 Ralf Baechle
7633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
8633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#ifndef _ASM_IOCTL_H
9633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _ASM_IOCTL_H
10633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
11633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
12633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * The original linux ioctl numbering scheme was just a general
13633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * "anything goes" setup, where more or less random numbers were
14633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * assigned.  Sorry, I was clueless when I started out on this.
15633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham *
16633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * On the alpha, we'll try to clean it up a bit, using a more sane
17633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * ioctl numbering, and also trying to be compatible with OSF/1 in
18633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * the process. I'd like to clean it up for the i386 as well, but
19633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * it's so painful recognizing both the new and the old numbers..
20633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham *
21633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * The same applies for for the MIPS ABI; in fact even the macros
22633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * from Linux/Alpha fit almost perfectly.
23633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
24633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
25633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_NRBITS	8
26633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_TYPEBITS	8
27633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_SIZEBITS	13
28633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_DIRBITS	3
29633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
30633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
31633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
32633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
33633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
34633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
35633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_NRSHIFT	0
36633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
37633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
38633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
39633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
40633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
41633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
42633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * And this turns out useful to catch old ioctl numbers in header
43633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * files for us.
44633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
45633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_NONE	1U
46633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_READ	2U
47633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_WRITE	4U
48633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
49633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/*
50633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham * The following are included for compatibility
51633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham */
52633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_VOID	0x20000000
53633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_OUT	0x40000000
54633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_IN		0x80000000
55633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_INOUT	(IOC_IN|IOC_OUT)
56633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
57633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC(dir, type, nr, size) \
58633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	(((dir)  << _IOC_DIRSHIFT) | \
59633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 ((type) << _IOC_TYPESHIFT) | \
60633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 ((nr)   << _IOC_NRSHIFT) | \
61633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	 ((size) << _IOC_SIZESHIFT))
62633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
63633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/* provoke compile error for invalid uses of size argument */
64633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandhamextern unsigned int __invalid_size_argument_for_IOC;
65633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_TYPECHECK(t) \
66633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	((sizeof(t) == sizeof(t[1]) && \
67633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	  sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
68633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham	  sizeof(t) : __invalid_size_argument_for_IOC)
69633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
70633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/* used to create numbers */
71633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IO(type, nr)		_IOC(_IOC_NONE, (type), (nr), 0)
72633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOR(type, nr, size)	_IOC(_IOC_READ, (type), (nr), (_IOC_TYPECHECK(size)))
73633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOW(type, nr, size)	_IOC(_IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
74633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOWR(type, nr, size)	_IOC(_IOC_READ|_IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
75633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOR_BAD(type, nr, size)	_IOC(_IOC_READ, (type), (nr), sizeof(size))
76633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOW_BAD(type, nr, size)	_IOC(_IOC_WRITE, (type), (nr), sizeof(size))
77633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOWR_BAD(type, nr, size)	_IOC(_IOC_READ|_IOC_WRITE, (type), (nr), sizeof(size))
78633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
79633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
80633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/* used to decode them.. */
81633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
82633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
83633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
84633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
85633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
86633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham/* ...and for the drivers/sound files... */
87633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
88633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
89633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
90633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
91633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
92633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
93633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham
94633c3473533ad9f2cca069b22cc5d95cd4e3510bRaghu Gandham#endif /* _ASM_IOCTL_H */
95