conf.h revision 46676
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.51 1999/05/07 10:11:23 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 specinfo;
52struct tty;
53struct uio;
54struct vnode;
55
56typedef int d_open_t __P((dev_t dev, int oflags, int devtype, struct proc *p));
57typedef int d_close_t __P((dev_t dev, int fflag, int devtype, struct proc *p));
58typedef void d_strategy_t __P((struct buf *bp));
59typedef int d_parms_t __P((dev_t dev, struct specinfo *sinfo, int ctl));
60typedef int d_ioctl_t __P((dev_t dev, u_long cmd, caddr_t data,
61			   int fflag, struct proc *p));
62typedef int d_dump_t __P((dev_t dev));
63typedef int d_psize_t __P((dev_t dev));
64
65typedef int d_read_t __P((dev_t dev, struct uio *uio, int ioflag));
66typedef int d_write_t __P((dev_t dev, struct uio *uio, int ioflag));
67typedef void d_stop_t __P((struct tty *tp, int rw));
68typedef int d_reset_t __P((dev_t dev));
69typedef struct tty *d_devtotty_t __P((dev_t dev));
70typedef int d_poll_t __P((dev_t dev, int events, struct proc *p));
71typedef int d_mmap_t __P((dev_t dev, vm_offset_t offset, int nprot));
72
73typedef int l_open_t __P((dev_t dev, struct tty *tp));
74typedef int l_close_t __P((struct tty *tp, int flag));
75typedef int l_read_t __P((struct tty *tp, struct uio *uio, int flag));
76typedef int l_write_t __P((struct tty *tp, struct uio *uio, int flag));
77typedef int l_ioctl_t __P((struct tty *tp, u_long cmd, caddr_t data,
78			   int flag, struct proc *p));
79typedef int l_rint_t __P((int c, struct tty *tp));
80typedef int l_start_t __P((struct tty *tp));
81typedef int l_modem_t __P((struct tty *tp, int flag));
82
83/*
84 * Types for d_type.
85 */
86#define	D_TAPE	1
87#define	D_DISK	2
88#define	D_TTY	3
89
90#define	D_TYPEMASK	0xffff
91
92/*
93 * Flags for d_flags.
94 */
95#define	D_NOCLUSTERR	0x10000		/* disables cluter read */
96#define	D_NOCLUSTERW	0x20000		/* disables cluster write */
97#define	D_NOCLUSTERRW	(D_NOCLUSTERR | D_NOCLUSTERW)
98#define	D_CANFREE	0x40000		/* can free blocks */
99
100/*
101 * Control type for d_parms() call.
102 */
103#define DPARM_GET	0		/* ask device to load parms in  */
104
105/*
106 * Character device switch table
107 */
108struct cdevsw {
109	d_open_t	*d_open;
110	d_close_t	*d_close;
111	d_read_t	*d_read;
112	d_write_t	*d_write;
113	d_ioctl_t	*d_ioctl;
114	d_stop_t	*d_stop;
115	d_reset_t	*d_reset;	/* XXX not used */
116	d_devtotty_t	*d_devtotty;
117	d_poll_t	*d_poll;
118	d_mmap_t	*d_mmap;
119	d_strategy_t	*d_strategy;
120	char		*d_name;	/* base device name, e.g. 'vn' */
121	d_parms_t	*d_parms;	/* populate/override specinfo */
122	int		d_maj;
123	d_dump_t	*d_dump;
124	d_psize_t	*d_psize;
125	u_int		d_flags;
126	int		d_maxio;
127	int		d_bmaj;
128};
129
130#ifdef KERNEL
131extern struct cdevsw *cdevsw[];
132extern int bmaj2cmaj[];
133
134static __inline
135struct cdevsw *
136devsw(dev_t dev)
137{
138	return(cdevsw[major(dev)]);
139}
140
141static __inline
142struct cdevsw *
143bdevsw(dev_t dev)
144{
145	struct cdevsw *c = cdevsw[bmaj2cmaj[major(dev)]];
146	/* CMAJ zero is the console, which has no strategy so this works */
147	if (c->d_strategy)
148		return (c);
149	return (0);
150}
151#endif
152
153/*
154 * Line discipline switch table
155 */
156struct linesw {
157	l_open_t	*l_open;
158	l_close_t	*l_close;
159	l_read_t	*l_read;
160	l_write_t	*l_write;
161	l_ioctl_t	*l_ioctl;
162	l_rint_t	*l_rint;
163	l_start_t	*l_start;
164	l_modem_t	*l_modem;
165	u_char		l_hotchar;
166};
167
168#ifdef KERNEL
169extern struct linesw linesw[];
170extern int nlinesw;
171
172int ldisc_register __P((int , struct linesw *));
173void ldisc_deregister __P((int));
174#define LDISC_LOAD 	-1		/* Loadable line discipline */
175#endif
176
177/*
178 * Swap device table
179 */
180struct swdevt {
181	dev_t	sw_dev;
182	int	sw_flags;
183	int	sw_nblks;
184	struct	vnode *sw_vp;
185};
186#define	SW_FREED	0x01
187#define	SW_SEQUENTIAL	0x02
188#define	sw_freed	sw_flags	/* XXX compat */
189
190#ifdef KERNEL
191d_open_t	noopen;
192d_close_t	noclose;
193d_read_t	noread;
194d_write_t	nowrite;
195d_ioctl_t	noioctl;
196d_stop_t	nostop;
197d_reset_t	noreset;
198d_devtotty_t	nodevtotty;
199d_mmap_t	nommap;
200
201/* Bogus defines for compatibility. */
202#define	noioc		noioctl
203#define	nostrat		nostrategy
204#define zerosize	nopsize
205/*
206 * XXX d_strategy seems to be unused for cdevs that aren't associated with
207 * bdevs and called without checking for it being non-NULL for bdevs.
208 */
209#define	nostrategy	((d_strategy_t *)NULL)
210
211d_dump_t	nodump;
212
213/*
214 * nopsize is little used, so not worth having dummy functions for.
215 */
216#define	nopsize	((d_psize_t *)NULL)
217
218d_open_t	nullopen;
219d_close_t	nullclose;
220#define	nullstop nostop		/* one void return is as good as another */
221#define	nullreset noreset	/* one unused function is as good as another */
222
223l_read_t	l_noread;
224l_write_t	l_nowrite;
225
226struct module;
227
228struct devsw_module_data {
229	int	(*chainevh)(struct module *, int, void *); /* next handler */
230	void	*chainarg;	/* arg for next event handler */
231	int	bdev;		/* device major to use */
232	int	cdev;		/* device major to use */
233	struct	cdevsw *cdevsw;	/* device functions */
234};
235
236#define DEV_MODULE(name, cmaj, bmaj, devsw, evh, arg)			\
237static struct devsw_module_data name##_devsw_mod = {			\
238    evh, arg, bmaj == NODEV ? NODEV : makedev(bmaj, 0),			\
239    cmaj == NODEV ? NODEV :  makedev(cmaj, 0), &devsw			\
240};									\
241									\
242static moduledata_t name##_mod = {					\
243    #name,								\
244    devsw_module_handler,						\
245    &name##_devsw_mod							\
246};									\
247DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+cmaj*256+bmaj)
248
249int	devsw_module_handler __P((struct module *mod, int what, void *arg));
250
251int	cdevsw_add __P((dev_t *descrip,struct cdevsw *new,struct cdevsw **old));
252void	cdevsw_add_generic __P((int bdev, int cdev, struct cdevsw *cdevsw));
253dev_t	chrtoblk __P((dev_t dev));
254int	iskmemdev __P((dev_t dev));
255int	iszerodev __P((dev_t dev));
256void	setconf __P((void));
257#endif /* KERNEL */
258
259#endif /* !_SYS_CONF_H_ */
260