xref: /freebsd/sys/dev/tdfx/tdfx_io.h (revision aa0a1e58)
1 /*-
2  * Copyright (c) 2000-2001 by Coleman Kane <cokane@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Gardner Buchanan.
16  * 4. The name of Gardner Buchanan may not be used to endorse or promote
17  *    products derived from this software without specific prior written
18  *    permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  *   $FreeBSD$
32  */
33 
34 /* This code originally came from <shocking@prth.pgs.com>
35  * it is basically a derivative of some sys/dhio.h file to work with the 3dfx
36  * cards
37  */
38 #ifndef TDFX_IO_H
39 #define TDFX_IO_H
40 
41 #ifndef KERNEL
42 #include <sys/types.h>
43 #endif
44 
45 /*
46  * define an ioctl here
47  */
48 #define DHIOCRESET _IO('D', 0)   /* reset the voodoo device */
49 #define GETVOODOO 0x3302
50 #define SETVOODOO 0x3303
51 #define MOREVOODOO 0x3300
52 #define _IOC_NRBITS	8
53 #define _IOC_TYPEBITS	8
54 #define _IOC_SIZEBITS	14
55 #define _IOC_DIRBITS	2
56 
57 #define _IOC_NRMASK	((1 << _IOC_NRBITS)-1)
58 #define _IOC_TYPEMASK	((1 << _IOC_TYPEBITS)-1)
59 #define _IOC_SIZEMASK	((1 << _IOC_SIZEBITS)-1)
60 #define _IOC_DIRMASK	((1 << _IOC_DIRBITS)-1)
61 
62 #define _IOC_NRSHIFT	0
63 #define _IOC_TYPESHIFT	(_IOC_NRSHIFT+_IOC_NRBITS)
64 #define _IOC_SIZESHIFT	(_IOC_TYPESHIFT+_IOC_TYPEBITS)
65 #define _IOC_DIRSHIFT	(_IOC_SIZESHIFT+_IOC_SIZEBITS)
66 
67 /*
68  * Direction bits.
69  */
70 #define _IOC_NONE	0U
71 #define _IOC_WRITE	1U
72 #define _IOC_READ	2U
73 
74 #define _IOCV(dir,type,nr,size) \
75 	(((dir)  << _IOC_DIRSHIFT) | \
76 	 ((type) << _IOC_TYPESHIFT) | \
77 	 ((nr)   << _IOC_NRSHIFT) | \
78 	 ((size) << _IOC_SIZESHIFT))
79 
80 /* used to create numbers */
81 #define _IOV(type,nr)		_IOCV(_IOC_NONE,(type),(nr),0)
82 #define _IORV(type,nr,size)	_IOCV(_IOC_READ,(type),(nr),sizeof(size))
83 #define _IOWV(type,nr,size)	_IOCV(_IOC_WRITE,(type),(nr),sizeof(size))
84 #define _IOWRV(type,nr,size)	_IOCV(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
85 
86 /* used to decode ioctl numbers.. */
87 #define _IOC_DIR(nr)		(((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
88 #define _IOC_TYPE(nr)		(((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
89 #define _IOC_NR(nr)		(((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
90 #define _IOC_SIZE(nr)		(((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
91 
92 /* ...and for the drivers/sound files... */
93 
94 #define IOCV_IN		(_IOC_WRITE << _IOC_DIRSHIFT)
95 #define IOCV_OUT	(_IOC_READ << _IOC_DIRSHIFT)
96 #define IOCV_INOUT	((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
97 #define IOCSIZE_MASK	(_IOC_SIZEMASK << _IOC_SIZESHIFT)
98 #define IOCSIZE_SHIFT	(_IOC_SIZESHIFT)
99 
100 #endif
101