18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
28c2ecf20Sopenharmony_ci#ifndef _ALPHA_IOCTL_H
38c2ecf20Sopenharmony_ci#define _ALPHA_IOCTL_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * The original linux ioctl numbering scheme was just a general
78c2ecf20Sopenharmony_ci * "anything goes" setup, where more or less random numbers were
88c2ecf20Sopenharmony_ci * assigned.  Sorry, I was clueless when I started out on this.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * On the alpha, we'll try to clean it up a bit, using a more sane
118c2ecf20Sopenharmony_ci * ioctl numbering, and also trying to be compatible with OSF/1 in
128c2ecf20Sopenharmony_ci * the process. I'd like to clean it up for the i386 as well, but
138c2ecf20Sopenharmony_ci * it's so painful recognizing both the new and the old numbers..
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define _IOC_NRBITS	8
178c2ecf20Sopenharmony_ci#define _IOC_TYPEBITS	8
188c2ecf20Sopenharmony_ci#define _IOC_SIZEBITS	13
198c2ecf20Sopenharmony_ci#define _IOC_DIRBITS	3
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
228c2ecf20Sopenharmony_ci#define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
238c2ecf20Sopenharmony_ci#define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
248c2ecf20Sopenharmony_ci#define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define _IOC_NRSHIFT	0
278c2ecf20Sopenharmony_ci#define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
288c2ecf20Sopenharmony_ci#define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
298c2ecf20Sopenharmony_ci#define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/*
328c2ecf20Sopenharmony_ci * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit.
338c2ecf20Sopenharmony_ci * And this turns out useful to catch old ioctl numbers in header
348c2ecf20Sopenharmony_ci * files for us.
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_ci#define _IOC_NONE	1U
378c2ecf20Sopenharmony_ci#define _IOC_READ	2U
388c2ecf20Sopenharmony_ci#define _IOC_WRITE	4U
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define _IOC(dir,type,nr,size)			\
418c2ecf20Sopenharmony_ci	((unsigned int)				\
428c2ecf20Sopenharmony_ci	 (((dir)  << _IOC_DIRSHIFT) |		\
438c2ecf20Sopenharmony_ci	  ((type) << _IOC_TYPESHIFT) |		\
448c2ecf20Sopenharmony_ci	  ((nr)   << _IOC_NRSHIFT) |		\
458c2ecf20Sopenharmony_ci	  ((size) << _IOC_SIZESHIFT)))
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/* used to create numbers */
488c2ecf20Sopenharmony_ci#define _IO(type,nr)		_IOC(_IOC_NONE,(type),(nr),0)
498c2ecf20Sopenharmony_ci#define _IOR(type,nr,size)	_IOC(_IOC_READ,(type),(nr),sizeof(size))
508c2ecf20Sopenharmony_ci#define _IOW(type,nr,size)	_IOC(_IOC_WRITE,(type),(nr),sizeof(size))
518c2ecf20Sopenharmony_ci#define _IOWR(type,nr,size)	_IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/* used to decode them.. */
548c2ecf20Sopenharmony_ci#define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
558c2ecf20Sopenharmony_ci#define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
568c2ecf20Sopenharmony_ci#define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
578c2ecf20Sopenharmony_ci#define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* ...and for the drivers/sound files... */
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define IOC_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
628c2ecf20Sopenharmony_ci#define IOC_OUT		(_IOC_READ << _IOC_DIRSHIFT)
638c2ecf20Sopenharmony_ci#define IOC_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
648c2ecf20Sopenharmony_ci#define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
658c2ecf20Sopenharmony_ci#define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#endif /* _ALPHA_IOCTL_H */
68