conf.h revision 36735
1/*-
2 * Copyright (c) 1990, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the University of
21 *	California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 *    may be used to endorse or promote products derived from this software
24 *    without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 *	@(#)conf.h	8.5 (Berkeley) 1/9/95
39 * $Id: conf.h,v 1.39 1998/02/13 12:46:28 phk Exp $
40 */
41
42#ifndef _SYS_CONF_H_
43#define	_SYS_CONF_H_
44
45/*
46 * Definitions of device driver entry switches
47 */
48
49struct buf;
50struct proc;
51struct tty;
52struct uio;
53struct vnode;
54
55typedef int d_open_t __P((dev_t dev, int oflags, int devtype, struct proc *p));
56typedef int d_close_t __P((dev_t dev, int fflag, int devtype, struct proc *p));
57typedef void d_strategy_t __P((struct buf *bp));
58typedef int d_ioctl_t __P((dev_t dev, u_long cmd, caddr_t data,
59			   int fflag, struct proc *p));
60typedef int d_dump_t __P((dev_t dev));
61typedef int d_psize_t __P((dev_t dev));
62
63typedef int d_read_t __P((dev_t dev, struct uio *uio, int ioflag));
64typedef int d_write_t __P((dev_t dev, struct uio *uio, int ioflag));
65typedef void d_stop_t __P((struct tty *tp, int rw));
66typedef int d_reset_t __P((dev_t dev));
67typedef struct tty *d_devtotty_t __P((dev_t dev));
68typedef int d_poll_t __P((dev_t dev, int events, struct proc *p));
69typedef int d_mmap_t __P((dev_t dev, int offset, int nprot));
70
71typedef int l_open_t __P((dev_t dev, struct tty *tp));
72typedef int l_close_t __P((struct tty *tp, int flag));
73typedef int l_read_t __P((struct tty *tp, struct uio *uio, int flag));
74typedef int l_write_t __P((struct tty *tp, struct uio *uio, int flag));
75typedef int l_ioctl_t __P((struct tty *tp, u_long cmd, caddr_t data,
76			   int flag, struct proc *p));
77typedef int l_rint_t __P((int c, struct tty *tp));
78typedef int l_start_t __P((struct tty *tp));
79typedef int l_modem_t __P((struct tty *tp, int flag));
80
81/*
82 * Types for d_type.
83 */
84#define	D_TAPE	1
85#define	D_DISK	2
86#define	D_TTY	3
87
88#define	D_TYPEMASK	0xffff
89
90/*
91 * Flags for d_flags.
92 */
93#define	D_NOCLUSTERR	0x10000		/* disables cluter read */
94#define	D_NOCLUSTERW	0x20000		/* disables cluster write */
95#define	D_NOCLUSTERRW	(D_NOCLUSTERR | D_NOCLUSTERW)
96
97/*
98 * Block device switch table
99 */
100struct bdevsw {
101	d_open_t	*d_open;
102	d_close_t	*d_close;
103	d_strategy_t	*d_strategy;
104	d_ioctl_t	*d_ioctl;
105	d_dump_t	*d_dump;
106	d_psize_t	*d_psize;
107	u_int		d_flags;
108	char 		*d_name;	/* name of the driver e.g. audio */
109	struct cdevsw	*d_cdev; 	/* cross pointer to the cdev */
110	int		d_maj;		/* the major number we were assigned */
111	int		d_maxio;
112};
113
114#ifdef KERNEL
115extern struct bdevsw *bdevsw[];
116#endif
117
118/*
119 * Character device switch table
120 */
121struct cdevsw {
122	d_open_t	*d_open;
123	d_close_t	*d_close;
124	d_read_t	*d_read;
125	d_write_t	*d_write;
126	d_ioctl_t	*d_ioctl;
127	d_stop_t	*d_stop;
128	d_reset_t	*d_reset;	/* XXX not used */
129	d_devtotty_t	*d_devtotty;
130	d_poll_t	*d_poll;
131	d_mmap_t	*d_mmap;
132	d_strategy_t	*d_strategy;
133	char		*d_name;	/* see above */
134	struct bdevsw	*d_bdev;
135	int		d_maj;
136};
137
138#ifdef KERNEL
139extern struct cdevsw *cdevsw[];
140#endif
141
142/*
143 * Line discipline switch table
144 */
145struct linesw {
146	l_open_t	*l_open;
147	l_close_t	*l_close;
148	l_read_t	*l_read;
149	l_write_t	*l_write;
150	l_ioctl_t	*l_ioctl;
151	l_rint_t	*l_rint;
152	l_start_t	*l_start;
153	l_modem_t	*l_modem;
154	u_char		l_hotchar;
155};
156
157#ifdef KERNEL
158extern struct linesw linesw[];
159extern int nlinesw;
160
161int ldisc_register __P((int , struct linesw *));
162void ldisc_deregister __P((int));
163#define LDISC_LOAD 	-1		/* Loadable line discipline */
164#endif
165
166/*
167 * Swap device table
168 */
169struct swdevt {
170	dev_t	sw_dev;
171	int	sw_flags;
172	int	sw_nblks;
173	struct	vnode *sw_vp;
174};
175#define	SW_FREED	0x01
176#define	SW_SEQUENTIAL	0x02
177#define	sw_freed	sw_flags	/* XXX compat */
178
179#ifdef KERNEL
180d_open_t	noopen;
181d_close_t	noclose;
182d_read_t	noread;
183d_write_t	nowrite;
184d_ioctl_t	noioctl;
185d_stop_t	nostop;
186d_reset_t	noreset;
187d_devtotty_t	nodevtotty;
188d_mmap_t	nommap;
189
190/* Bogus defines for compatibility. */
191#define	noioc		noioctl
192#define	nostrat		nostrategy
193#define zerosize	nopsize
194/*
195 * XXX d_strategy seems to be unused for cdevs that aren't associated with
196 * bdevs and called without checking for it being non-NULL for bdevs.
197 */
198#define	nostrategy	((d_strategy_t *)NULL)
199
200d_dump_t	nodump;
201
202/*
203 * nopsize is little used, so not worth having dummy functions for.
204 */
205#define	nopsize	((d_psize_t *)NULL)
206
207d_open_t	nullopen;
208d_close_t	nullclose;
209#define	nullstop nostop		/* one void return is as good as another */
210#define	nullreset noreset	/* one unused function is as good as another */
211
212d_open_t	nxopen;
213d_close_t	nxclose;
214d_read_t	nxread;
215d_write_t	nxwrite;
216d_ioctl_t	nxioctl;
217#define	nxstop	nostop		/* one void return is as good as another */
218#define	nxreset	noreset		/* one unused function is as good as another */
219#define	nxdevtotty nodevtotty	/* one NULL return is as good as another */
220#define	nxmmap	nommap		/* one -1 return is as good as another */
221#define	nxstrategy nostrategy	/* one NULL value is as good as another */
222d_dump_t	nxdump;
223#define	nxpsize	nopsize		/* one NULL value is as good as another */
224
225d_read_t	rawread;
226d_write_t	rawwrite;
227
228l_read_t	l_noread;
229l_write_t	l_nowrite;
230
231/*
232 * XXX This is ugly.
233 */
234#ifdef _SYS_MODULE_H_
235
236struct cdevsw_module_data {
237    modeventhand_t	chainevh; /* next event handler in chain */
238    void*		chainarg; /* arg for next event handler */
239    dev_t		dev;	/* device major to use */
240    struct cdevsw*	cdevsw;	/* device functions */
241};
242
243struct bdevsw_module_data {
244    modeventhand_t	chainevh; /* next event handler in chain */
245    void*		chainarg; /* arg for next event handler */
246    int			bdev;	/* device major to use */
247    int			cdev;	/* device major to use */
248    struct bdevsw*	bdevsw;	/* device functions */
249};
250
251#define CDEV_MODULE(name, major, devsw, evh, arg)			\
252static struct cdevsw_module_data name##_cdevsw_mod = {			\
253    evh, arg, makedev(major, 0), &devsw					\
254};									\
255									\
256static moduledata_t name##_mod = {					\
257    #name,								\
258    cdevsw_module_handler,						\
259    &name##_cdevsw_mod							\
260};									\
261DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+major)
262
263#define BDEV_MODULE(name, bdev, cdev, devsw, evh, arg)			\
264static struct bdevsw_module_data name##_bdevsw_mod = {			\
265    evh, arg, makedev(bdev, 0), makedev(cdev, 0), &devsw		\
266};									\
267									\
268static moduledata_t name##_mod = {					\
269    #name,								\
270    bdevsw_module_handler,						\
271    &name##_bdevsw_mod							\
272};									\
273DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+cdev)
274
275int	cdevsw_module_handler __P((module_t mod, modeventtype_t what, void* arg));
276int	bdevsw_module_handler __P((module_t mod, modeventtype_t what, void* arg));
277
278#endif /* _SYS_MODULE_H_ */
279
280int	bdevsw_add __P((dev_t *descrip,struct bdevsw *new,struct bdevsw **old));
281int	cdevsw_add __P((dev_t *descrip,struct cdevsw *new,struct cdevsw **old));
282void	bdevsw_add_generic __P((int bdev, int cdev, struct bdevsw *bdevsw));
283dev_t	chrtoblk __P((dev_t dev));
284int	iskmemdev __P((dev_t dev));
285int	iszerodev __P((dev_t dev));
286void	setconf __P((void));
287#endif /* KERNEL */
288
289#include <machine/conf.h>
290
291#endif /* !_SYS_CONF_H_ */
292