conf.h revision 85076
1258945Sroberto/*-
2280849Scy * Copyright (c) 1990, 1993
3258945Sroberto *	The Regents of the University of California.  All rights reserved.
4258945Sroberto * Copyright (c) 2000
5258945Sroberto *	Poul-Henning Kamp.  All rights reserved.
6258945Sroberto * (c) UNIX System Laboratories, Inc.
7258945Sroberto * All or some portions of this file are derived from material licensed
8258945Sroberto * to the University of California by American Telephone and Telegraph
9258945Sroberto * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10258945Sroberto * the permission of UNIX System Laboratories, Inc.
11258945Sroberto *
12258945Sroberto * Redistribution and use in source and binary forms, with or without
13258945Sroberto * modification, are permitted provided that the following conditions
14258945Sroberto * are met:
15258945Sroberto * 1. Redistributions of source code must retain the above copyright
16258945Sroberto *    notice, this list of conditions and the following disclaimer.
17258945Sroberto * 2. Redistributions in binary form must reproduce the above copyright
18280849Scy *    notice, this list of conditions and the following disclaimer in the
19258945Sroberto *    documentation and/or other materials provided with the distribution.
20258945Sroberto * 3. All advertising materials mentioning features or use of this software
21258945Sroberto *    must display the following acknowledgement:
22258945Sroberto *	This product includes software developed by the University of
23258945Sroberto *	California, Berkeley and its contributors.
24258945Sroberto * 4. Neither the name of the University nor the names of its contributors
25258945Sroberto *    may be used to endorse or promote products derived from this software
26258945Sroberto *    without specific prior written permission.
27258945Sroberto *
28258945Sroberto * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29258945Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30258945Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31258945Sroberto * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32258945Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33258945Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34258945Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35258945Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36258945Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37258945Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38258945Sroberto * SUCH DAMAGE.
39258945Sroberto *
40258945Sroberto *	@(#)conf.h	8.5 (Berkeley) 1/9/95
41258945Sroberto * $FreeBSD: head/sys/sys/conf.h 85076 2001-10-17 18:47:12Z jlemon $
42258945Sroberto */
43258945Sroberto
44258945Sroberto#ifndef _SYS_CONF_H_
45258945Sroberto#define	_SYS_CONF_H_
46258945Sroberto
47258945Sroberto#ifdef _KERNEL
48258945Sroberto#include <sys/eventhandler.h>
49258945Sroberto
50258945Srobertostruct tty;
51258945Srobertostruct disk;
52258945Srobertostruct vnode;
53258945Srobertostruct buf;
54258945SrobertoTAILQ_HEAD(snaphead, inode);
55258945Sroberto
56258945Srobertostruct specinfo {
57258945Sroberto	u_int		si_flags;
58258945Sroberto#define SI_STASHED	0x0001	/* created in stashed storage */
59258945Sroberto#define SI_ALIAS	0x0002	/* carrier of alias name */
60258945Sroberto#define SI_NAMED	0x0004	/* make_dev{_alias} has been called */
61258945Sroberto#define SI_CHEAPCLONE	0x0008	/* can be removed_dev'ed when vnode reclaims */
62258945Sroberto#define SI_CHILD	0x0010	/* child of another dev_t */
63258945Sroberto	struct timespec	si_atime;
64258945Sroberto	struct timespec	si_ctime;
65258945Sroberto	struct timespec	si_mtime;
66258945Sroberto	udev_t		si_udev;
67258945Sroberto	LIST_ENTRY(specinfo)	si_hash;
68258945Sroberto	SLIST_HEAD(, vnode)	si_hlist;
69258945Sroberto	LIST_HEAD(, specinfo)	si_children;
70258945Sroberto	LIST_ENTRY(specinfo)	si_siblings;
71258945Sroberto	dev_t		si_parent;
72258945Sroberto	struct snaphead	si_snapshots;
73258945Sroberto	int		(*si_copyonwrite)(struct vnode *, struct buf *);
74258945Sroberto	u_int		si_inode;
75258945Sroberto	char		si_name[SPECNAMELEN + 1];
76258945Sroberto	void		*si_drv1, *si_drv2;
77258945Sroberto	struct cdevsw	*si_devsw;
78258945Sroberto	int		si_iosize_max;	/* maximum I/O size (for physio &al) */
79258945Sroberto	uid_t		si_uid;
80258945Sroberto	gid_t		si_gid;
81258945Sroberto	mode_t		si_mode;
82258945Sroberto	union {
83258945Sroberto		struct {
84258945Sroberto			struct tty *__sit_tty;
85258945Sroberto		} __si_tty;
86258945Sroberto		struct {
87258945Sroberto			struct disk *__sid_disk;
88258945Sroberto			struct mount *__sid_mountpoint;
89258945Sroberto			int __sid_bsize_phys; /* min physical block size */
90258945Sroberto			int __sid_bsize_best; /* optimal block size */
91258945Sroberto		} __si_disk;
92258945Sroberto	} __si_u;
93258945Sroberto};
94258945Sroberto
95258945Sroberto#define si_tty		__si_u.__si_tty.__sit_tty
96258945Sroberto#define si_disk		__si_u.__si_disk.__sid_disk
97258945Sroberto#define si_mountpoint	__si_u.__si_disk.__sid_mountpoint
98258945Sroberto#define si_bsize_phys	__si_u.__si_disk.__sid_bsize_phys
99258945Sroberto#define si_bsize_best	__si_u.__si_disk.__sid_bsize_best
100258945Sroberto
101258945Sroberto/*
102258945Sroberto * Special device management
103258945Sroberto */
104258945Sroberto#define	SPECHSZ	64
105258945Sroberto#define	SPECHASH(rdev)	(((unsigned)(minor(rdev)))%SPECHSZ)
106258945Sroberto
107258945Sroberto/*
108258945Sroberto * Definitions of device driver entry switches
109258945Sroberto */
110258945Sroberto
111258945Srobertostruct bio;
112258945Srobertostruct buf;
113258945Srobertostruct thread;
114258945Srobertostruct uio;
115258945Srobertostruct knote;
116258945Sroberto
117258945Sroberto/*
118258945Sroberto * Note: d_thread_t is provided as a transition aid for those drivers
119258945Sroberto * that treat struct proc/struct thread as an opaque data type and
120258945Sroberto * exist in substantially the same form in both 4.x and 5.x.  Writers
121258945Sroberto * of drivers that dips into the d_thread_t structure should use
122258945Sroberto * struct thread or struct proc as appropriate for the version of the
123258945Sroberto * OS they are using.  It is provided in lieu of each device driver
124258945Sroberto * inventing its own way of doing this.  While it does violate style(9)
125258945Sroberto * in a number of ways, this violation is deemed to be less
126258945Sroberto * important than the benefits that a uniform API between releases
127258945Sroberto * gives.
128258945Sroberto *
129258945Sroberto * Users of struct thread/struct proc that aren't device drivers should
130258945Sroberto * not use d_thread_t.
131258945Sroberto */
132258945Sroberto
133258945Srobertotypedef struct thread d_thread_t;
134258945Sroberto
135258945Srobertotypedef int d_open_t __P((dev_t dev, int oflags, int devtype, d_thread_t *td));
136258945Srobertotypedef int d_close_t __P((dev_t dev, int fflag, int devtype, d_thread_t *td));
137258945Srobertotypedef void d_strategy_t __P((struct bio *bp));
138258945Srobertotypedef int d_ioctl_t __P((dev_t dev, u_long cmd, caddr_t data,
139258945Sroberto			   int fflag, d_thread_t *td));
140258945Srobertotypedef int d_dump_t __P((dev_t dev));
141258945Srobertotypedef int d_psize_t __P((dev_t dev));
142258945Sroberto
143258945Srobertotypedef int d_read_t __P((dev_t dev, struct uio *uio, int ioflag));
144258945Srobertotypedef int d_write_t __P((dev_t dev, struct uio *uio, int ioflag));
145258945Srobertotypedef int d_poll_t __P((dev_t dev, int events, d_thread_t *td));
146258945Srobertotypedef int d_kqfilter_t __P((dev_t dev, struct knote *kn));
147258945Srobertotypedef int d_mmap_t __P((dev_t dev, vm_offset_t offset, int nprot));
148258945Sroberto
149258945Srobertotypedef int l_open_t __P((dev_t dev, struct tty *tp));
150258945Srobertotypedef int l_close_t __P((struct tty *tp, int flag));
151258945Srobertotypedef int l_read_t __P((struct tty *tp, struct uio *uio, int flag));
152258945Srobertotypedef int l_write_t __P((struct tty *tp, struct uio *uio, int flag));
153258945Srobertotypedef int l_ioctl_t __P((struct tty *tp, u_long cmd, caddr_t data,
154258945Sroberto			   int flag, d_thread_t *td));
155258945Srobertotypedef int l_rint_t __P((int c, struct tty *tp));
156258945Srobertotypedef int l_start_t __P((struct tty *tp));
157258945Srobertotypedef int l_modem_t __P((struct tty *tp, int flag));
158258945Sroberto
159258945Sroberto/*
160258945Sroberto * XXX: The dummy argument can be used to do what strategy1() never
161258945Sroberto * did anywhere:  Create a per device flag to lock the device during
162258945Sroberto * label/slice surgery, all calls with a dummy == 0 gets stalled on
163258945Sroberto * a queue somewhere, whereas dummy == 1 are let through.  Once out
164258945Sroberto * of surgery, reset the flag and restart all the stuff on the stall
165258945Sroberto * queue.
166258945Sroberto */
167258945Sroberto#define BIO_STRATEGY(bp, dummy)						\
168258945Sroberto	do {								\
169258945Sroberto	if ((!(bp)->bio_cmd) || ((bp)->bio_cmd & ((bp)->bio_cmd - 1)))	\
170258945Sroberto		Debugger("bio_cmd botch");				\
171258945Sroberto	(*devsw((bp)->bio_dev)->d_strategy)(bp);			\
172258945Sroberto	} while (0)
173258945Sroberto
174258945Sroberto#define DEV_STRATEGY(bp, dummy)						\
175258945Sroberto	do {								\
176258945Sroberto	if ((bp)->b_flags & B_PHYS)					\
177258945Sroberto		(bp)->b_io.bio_offset = (bp)->b_offset;			\
178258945Sroberto	else								\
179258945Sroberto		(bp)->b_io.bio_offset = dbtob((bp)->b_blkno);		\
180258945Sroberto	(bp)->b_io.bio_done = bufdonebio;				\
181258945Sroberto	(bp)->b_io.bio_caller2 = (bp);					\
182258945Sroberto	BIO_STRATEGY(&(bp)->b_io, dummy);				\
183258945Sroberto	} while (0)
184258945Sroberto
185258945Sroberto#endif /* _KERNEL */
186258945Sroberto
187258945Sroberto/*
188258945Sroberto * Types for d_flags.
189258945Sroberto */
190258945Sroberto#define	D_TAPE	0x0001
191258945Sroberto#define	D_DISK	0x0002
192258945Sroberto#define	D_TTY	0x0004
193258945Sroberto#define	D_MEM	0x0008
194258945Sroberto
195258945Sroberto#ifdef _KERNEL
196258945Sroberto
197258945Sroberto#define	D_TYPEMASK	0xffff
198258945Sroberto
199258945Sroberto/*
200258945Sroberto * Flags for d_flags.
201258945Sroberto */
202258945Sroberto#define	D_MEMDISK	0x00010000	/* memory type disk */
203258945Sroberto#define	D_NAGGED	0x00020000	/* nagged about missing make_dev() */
204258945Sroberto#define	D_CANFREE	0x00040000	/* can free blocks */
205258945Sroberto#define	D_TRACKCLOSE	0x00080000	/* track all closes */
206258945Sroberto#define D_MMAP_ANON	0x00100000	/* special treatment in vm_mmap.c */
207258945Sroberto#define D_KQFILTER	0x00200000	/* has kqfilter entry */
208258945Sroberto
209258945Sroberto/*
210258945Sroberto * Character device switch table
211258945Sroberto */
212258945Srobertostruct cdevsw {
213258945Sroberto	d_open_t	*d_open;
214258945Sroberto	d_close_t	*d_close;
215258945Sroberto	d_read_t	*d_read;
216258945Sroberto	d_write_t	*d_write;
217258945Sroberto	d_ioctl_t	*d_ioctl;
218258945Sroberto	d_poll_t	*d_poll;
219258945Sroberto	d_mmap_t	*d_mmap;
220258945Sroberto	d_strategy_t	*d_strategy;
221258945Sroberto	const char	*d_name;	/* base device name, e.g. 'vn' */
222258945Sroberto	int		d_maj;
223258945Sroberto	d_dump_t	*d_dump;
224258945Sroberto	d_psize_t	*d_psize;
225258945Sroberto	u_int		d_flags;
226258945Sroberto	/* additions below are not binary compatible with 4.2 and below */
227258945Sroberto	d_kqfilter_t	*d_kqfilter;
228258945Sroberto};
229280849Scy
230280849Scy/*
231280849Scy * Line discipline switch table
232280849Scy */
233258945Srobertostruct linesw {
234280849Scy	l_open_t	*l_open;
235258945Sroberto	l_close_t	*l_close;
236280849Scy	l_read_t	*l_read;
237280849Scy	l_write_t	*l_write;
238280849Scy	l_ioctl_t	*l_ioctl;
239280849Scy	l_rint_t	*l_rint;
240280849Scy	l_start_t	*l_start;
241280849Scy	l_modem_t	*l_modem;
242280849Scy	u_char		l_hotchar;
243280849Scy};
244258945Sroberto
245258945Srobertoextern struct linesw linesw[];
246258945Srobertoextern int nlinesw;
247258945Sroberto
248280849Scyint ldisc_register __P((int , struct linesw *));
249258945Srobertovoid ldisc_deregister __P((int));
250280849Scy#define LDISC_LOAD 	-1		/* Loadable line discipline */
251280849Scy#endif /* _KERNEL */
252280849Scy
253258945Sroberto/*
254258945Sroberto * Swap device table
255258945Sroberto */
256258945Srobertostruct swdevt {
257258945Sroberto	udev_t	sw_dev;			/* For quasibogus swapdev reporting */
258258945Sroberto	int	sw_flags;
259258945Sroberto	int	sw_nblks;
260258945Sroberto	int     sw_used;
261258945Sroberto	struct	vnode *sw_vp;
262258945Sroberto	dev_t	sw_device;
263258945Sroberto};
264258945Sroberto#define	SW_FREED	0x01
265258945Sroberto#define	SW_SEQUENTIAL	0x02
266258945Sroberto#define	sw_freed	sw_flags	/* XXX compat */
267258945Sroberto
268258945Sroberto#ifdef _KERNEL
269258945Srobertod_open_t	noopen;
270258945Srobertod_close_t	noclose;
271258945Srobertod_read_t	noread;
272258945Srobertod_write_t	nowrite;
273258945Srobertod_ioctl_t	noioctl;
274258945Srobertod_mmap_t	nommap;
275258945Srobertod_kqfilter_t	nokqfilter;
276258945Sroberto#define	nostrategy	((d_strategy_t *)NULL)
277258945Sroberto#define	nopoll	seltrue
278258945Sroberto
279258945Srobertod_dump_t	nodump;
280258945Sroberto
281258945Sroberto#define NUMCDEVSW 256
282258945Sroberto
283258945Sroberto/*
284258945Sroberto * nopsize is little used, so not worth having dummy functions for.
285280849Scy */
286280849Scy#define	nopsize	((d_psize_t *)NULL)
287258945Sroberto
288258945Srobertod_open_t	nullopen;
289280849Scyd_close_t	nullclose;
290280849Scy
291258945Srobertol_ioctl_t	l_nullioctl;
292258945Srobertol_read_t	l_noread;
293258945Srobertol_write_t	l_nowrite;
294258945Sroberto
295258945Srobertostruct module;
296258945Sroberto
297258945Srobertostruct devsw_module_data {
298258945Sroberto	int	(*chainevh)(struct module *, int, void *); /* next handler */
299258945Sroberto	void	*chainarg;	/* arg for next event handler */
300280849Scy	/* Do not initialize fields hereafter */
301280849Scy};
302280849Scy
303280849Scy#define DEV_MODULE(name, evh, arg)					\
304280849Scystatic moduledata_t name##_mod = {					\
305280849Scy    #name,								\
306280849Scy    evh,								\
307280849Scy    arg									\
308280849Scy};									\
309280849ScyDECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
310280849Scy
311280849Scy
312280849Scyint	cdevsw_add __P((struct cdevsw *new));
313280849Scyint	cdevsw_remove __P((struct cdevsw *old));
314280849Scyint	count_dev __P((dev_t dev));
315280849Scyvoid	destroy_dev __P((dev_t dev));
316280849Scystruct cdevsw *devsw __P((dev_t dev));
317280849Scyconst char *devtoname __P((dev_t dev));
318280849Scyint	dev_named __P((dev_t pdev, const char *name));
319280849Scyvoid	dev_depends __P((dev_t pdev, dev_t cdev));
320280849Scyvoid	freedev __P((dev_t dev));
321int	iszerodev __P((dev_t dev));
322dev_t	makebdev __P((int maj, int min));
323dev_t	make_dev __P((struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, const char *fmt, ...)) __printflike(6, 7);
324dev_t	make_dev_alias __P((dev_t pdev, const char *fmt, ...)) __printflike(2, 3);
325int	dev2unit __P((dev_t dev));
326int	unit2minor __P((int unit));
327void	setconf __P((void));
328dev_t	getdiskbyname(char *name);
329
330/* This is type of the function DEVFS uses to hook into the kernel with */
331typedef void devfs_create_t __P((dev_t dev));
332typedef void devfs_destroy_t __P((dev_t dev));
333
334extern devfs_create_t *devfs_create_hook;
335extern devfs_destroy_t *devfs_destroy_hook;
336extern int devfs_present;
337
338/*
339 * XXX: This included for when DEVFS resurfaces
340 */
341
342#define		UID_ROOT	0
343#define		UID_BIN		3
344#define		UID_UUCP	66
345
346#define		GID_WHEEL	0
347#define		GID_KMEM	2
348#define		GID_OPERATOR	5
349#define		GID_BIN		7
350#define		GID_GAMES	13
351#define		GID_DIALER	68
352
353typedef void (*dev_clone_fn) __P((void *arg, char *name, int namelen, dev_t *result));
354
355int dev_stdclone __P((char *name, char **namep, char *stem, int *unit));
356EVENTHANDLER_DECLARE(dev_clone, dev_clone_fn);
357#endif /* _KERNEL */
358
359#endif /* !_SYS_CONF_H_ */
360