conf.h revision 112569
1203945Sweongyo/*-
2203945Sweongyo * Copyright (c) 1990, 1993
3203945Sweongyo *	The Regents of the University of California.  All rights reserved.
4203945Sweongyo * Copyright (c) 2000
5203945Sweongyo *	Poul-Henning Kamp.  All rights reserved.
6203945Sweongyo * (c) UNIX System Laboratories, Inc.
7203945Sweongyo * All or some portions of this file are derived from material licensed
8203945Sweongyo * to the University of California by American Telephone and Telegraph
9203945Sweongyo * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10203945Sweongyo * the permission of UNIX System Laboratories, Inc.
11203945Sweongyo *
12203945Sweongyo * Redistribution and use in source and binary forms, with or without
13203945Sweongyo * modification, are permitted provided that the following conditions
14203945Sweongyo * are met:
15203945Sweongyo * 1. Redistributions of source code must retain the above copyright
16203945Sweongyo *    notice, this list of conditions and the following disclaimer.
17203945Sweongyo * 2. Redistributions in binary form must reproduce the above copyright
18203945Sweongyo *    notice, this list of conditions and the following disclaimer in the
19203945Sweongyo *    documentation and/or other materials provided with the distribution.
20203945Sweongyo * 3. All advertising materials mentioning features or use of this software
21203945Sweongyo *    must display the following acknowledgement:
22203945Sweongyo *	This product includes software developed by the University of
23203945Sweongyo *	California, Berkeley and its contributors.
24203945Sweongyo * 4. Neither the name of the University nor the names of its contributors
25203945Sweongyo *    may be used to endorse or promote products derived from this software
26203945Sweongyo *    without specific prior written permission.
27203945Sweongyo *
28203945Sweongyo * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29203945Sweongyo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30203945Sweongyo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31203945Sweongyo * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32203945Sweongyo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33203945Sweongyo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34203945Sweongyo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35203945Sweongyo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36203945Sweongyo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37203945Sweongyo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38203945Sweongyo * SUCH DAMAGE.
39203945Sweongyo *
40203945Sweongyo *	@(#)conf.h	8.5 (Berkeley) 1/9/95
41203945Sweongyo * $FreeBSD: head/sys/sys/conf.h 112569 2003-03-25 00:07:06Z jake $
42203945Sweongyo */
43203945Sweongyo
44203945Sweongyo#ifndef _SYS_CONF_H_
45203945Sweongyo#define	_SYS_CONF_H_
46203945Sweongyo
47203945Sweongyo#ifdef _KERNEL
48203945Sweongyo#include <sys/eventhandler.h>
49203945Sweongyo
50203945Sweongyostruct tty;
51203945Sweongyostruct disk;
52203945Sweongyostruct vnode;
53203945Sweongyostruct buf;
54203945SweongyoTAILQ_HEAD(snaphead, inode);
55203945Sweongyo
56203945Sweongyostruct cdev {
57203945Sweongyo	u_int		si_flags;
58203945Sweongyo#define SI_STASHED	0x0001	/* created in stashed storage */
59203945Sweongyo#define SI_ALIAS	0x0002	/* carrier of alias name */
60203945Sweongyo#define SI_NAMED	0x0004	/* make_dev{_alias} has been called */
61203945Sweongyo#define SI_CHEAPCLONE	0x0008	/* can be removed_dev'ed when vnode reclaims */
62203945Sweongyo#define SI_CHILD	0x0010	/* child of another dev_t */
63203945Sweongyo#define SI_DEVOPEN	0x0020	/* opened by device */
64203945Sweongyo#define SI_CONSOPEN	0x0040	/* opened by console */
65203945Sweongyo#define SI_DUMPDEV	0x0080	/* is kernel dumpdev */
66203945Sweongyo#define SI_CANDELETE	0x0100	/* can do BIO_DELETE */
67203945Sweongyo	struct timespec	si_atime;
68203945Sweongyo	struct timespec	si_ctime;
69203945Sweongyo	struct timespec	si_mtime;
70203945Sweongyo	udev_t		si_udev;
71206358Srpaulo	LIST_ENTRY(cdev)	si_hash;
72203945Sweongyo	SLIST_HEAD(, vnode)	si_hlist;
73203945Sweongyo	LIST_HEAD(, cdev)	si_children;
74203945Sweongyo	LIST_ENTRY(cdev)	si_siblings;
75203945Sweongyo	dev_t		si_parent;
76227309Sed	u_int		si_inode;
77227309Sed	char		*si_name;
78203945Sweongyo	void		*si_drv1, *si_drv2;
79203945Sweongyo	struct cdevsw	*si_devsw;
80203945Sweongyo	int		si_iosize_max;	/* maximum I/O size (for physio &al) */
81203945Sweongyo	u_int		si_stripesize;
82203945Sweongyo	u_int		si_stripeoffset;
83203945Sweongyo	uid_t		si_uid;
84203945Sweongyo	gid_t		si_gid;
85203945Sweongyo	mode_t		si_mode;
86203945Sweongyo	u_long		si_usecount;
87203945Sweongyo	union {
88203945Sweongyo		struct {
89203945Sweongyo			struct tty *__sit_tty;
90203945Sweongyo		} __si_tty;
91203945Sweongyo		struct {
92203945Sweongyo			struct mount *__sid_mountpoint;
93203945Sweongyo			int __sid_bsize_phys; /* min physical block size */
94203945Sweongyo			int __sid_bsize_best; /* optimal block size */
95203945Sweongyo			struct snaphead	__sid_snapshots;
96203945Sweongyo			daddr_t __sid_snaplistsize; /* size of snapblklist. */
97203945Sweongyo			daddr_t	*__sid_snapblklist; /* known snapshot blocks. */
98203945Sweongyo			int (*__sid_copyonwrite)(struct vnode *, struct buf *);
99203945Sweongyo		} __si_disk;
100203945Sweongyo	} __si_u;
101203945Sweongyo	char		__si_namebuf[SPECNAMELEN + 1];
102203945Sweongyo};
103203945Sweongyo
104203945Sweongyo#define si_tty		__si_u.__si_tty.__sit_tty
105203945Sweongyo#define si_mountpoint	__si_u.__si_disk.__sid_mountpoint
106203945Sweongyo#define si_bsize_phys	__si_u.__si_disk.__sid_bsize_phys
107203945Sweongyo#define si_bsize_best	__si_u.__si_disk.__sid_bsize_best
108203945Sweongyo#define si_snapshots	__si_u.__si_disk.__sid_snapshots
109203945Sweongyo#define si_snaplistsize	__si_u.__si_disk.__sid_snaplistsize
110203945Sweongyo#define si_snapblklist	__si_u.__si_disk.__sid_snapblklist
111203945Sweongyo#define si_copyonwrite	__si_u.__si_disk.__sid_copyonwrite
112203945Sweongyo
113203945Sweongyo/*
114203945Sweongyo * Special device management
115203945Sweongyo */
116203945Sweongyo#define	SPECHSZ	64
117203945Sweongyo#define	SPECHASH(rdev)	(((unsigned)(minor(rdev)))%SPECHSZ)
118203945Sweongyo
119203945Sweongyo/*
120203945Sweongyo * Definitions of device driver entry switches
121203945Sweongyo */
122203945Sweongyo
123203945Sweongyostruct bio;
124203945Sweongyostruct buf;
125203945Sweongyostruct thread;
126203945Sweongyostruct uio;
127203945Sweongyostruct knote;
128203945Sweongyo
129203945Sweongyo/*
130203945Sweongyo * Note: d_thread_t is provided as a transition aid for those drivers
131203945Sweongyo * that treat struct proc/struct thread as an opaque data type and
132203945Sweongyo * exist in substantially the same form in both 4.x and 5.x.  Writers
133203945Sweongyo * of drivers that dips into the d_thread_t structure should use
134203945Sweongyo * struct thread or struct proc as appropriate for the version of the
135203945Sweongyo * OS they are using.  It is provided in lieu of each device driver
136203945Sweongyo * inventing its own way of doing this.  While it does violate style(9)
137203945Sweongyo * in a number of ways, this violation is deemed to be less
138204922Sweongyo * important than the benefits that a uniform API between releases
139203945Sweongyo * gives.
140203945Sweongyo *
141203945Sweongyo * Users of struct thread/struct proc that aren't device drivers should
142203945Sweongyo * not use d_thread_t.
143203945Sweongyo */
144203945Sweongyo
145203945Sweongyotypedef struct thread d_thread_t;
146203945Sweongyo
147203945Sweongyotypedef int d_open_t(dev_t dev, int oflags, int devtype, struct thread *td);
148203945Sweongyotypedef int d_close_t(dev_t dev, int fflag, int devtype, struct thread *td);
149203945Sweongyotypedef void d_strategy_t(struct bio *bp);
150203945Sweongyotypedef int d_ioctl_t(dev_t dev, u_long cmd, caddr_t data,
151203945Sweongyo		      int fflag, struct thread *td);
152203945Sweongyo
153203945Sweongyotypedef int d_read_t(dev_t dev, struct uio *uio, int ioflag);
154203945Sweongyotypedef int d_write_t(dev_t dev, struct uio *uio, int ioflag);
155203945Sweongyotypedef int d_poll_t(dev_t dev, int events, struct thread *td);
156203945Sweongyotypedef int d_kqfilter_t(dev_t dev, struct knote *kn);
157203945Sweongyotypedef int d_mmap_t(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr,
158203945Sweongyo   		     int nprot);
159203945Sweongyo
160203945Sweongyotypedef int l_open_t(dev_t dev, struct tty *tp);
161203945Sweongyotypedef int l_close_t(struct tty *tp, int flag);
162203945Sweongyotypedef int l_read_t(struct tty *tp, struct uio *uio, int flag);
163203945Sweongyotypedef int l_write_t(struct tty *tp, struct uio *uio, int flag);
164203945Sweongyotypedef int l_ioctl_t(struct tty *tp, u_long cmd, caddr_t data,
165203945Sweongyo		      int flag, struct thread *td);
166203945Sweongyotypedef int l_rint_t(int c, struct tty *tp);
167203945Sweongyotypedef int l_start_t(struct tty *tp);
168203945Sweongyotypedef int l_modem_t(struct tty *tp, int flag);
169203945Sweongyo
170203945Sweongyotypedef int dumper_t(
171203945Sweongyo	void *priv,		/* Private to the driver. */
172203945Sweongyo	void *virtual,		/* Virtual (mapped) address. */
173203945Sweongyo	vm_offset_t physical,	/* Physical address of virtual. */
174203945Sweongyo	off_t offset,		/* Byte-offset to write at. */
175203945Sweongyo	size_t length);		/* Number of bytes to dump. */
176203945Sweongyo
177203945Sweongyo#define BIO_STRATEGY(bp)						\
178203945Sweongyo	do {								\
179203945Sweongyo	if ((!(bp)->bio_cmd) || ((bp)->bio_cmd & ((bp)->bio_cmd - 1)))	\
180203945Sweongyo		Debugger("bio_cmd botch");				\
181203945Sweongyo	(*devsw((bp)->bio_dev)->d_strategy)(bp);			\
182203945Sweongyo	} while (0)
183203945Sweongyo
184203945Sweongyo#define DEV_STRATEGY(bp)						\
185203945Sweongyo	do {								\
186203945Sweongyo	if ((bp)->b_flags & B_PHYS)					\
187203945Sweongyo		(bp)->b_io.bio_offset = (bp)->b_offset;			\
188203945Sweongyo	else								\
189203945Sweongyo		(bp)->b_io.bio_offset = dbtob((bp)->b_blkno);		\
190203945Sweongyo	(bp)->b_io.bio_done = bufdonebio;				\
191203945Sweongyo	(bp)->b_io.bio_caller2 = (bp);					\
192203945Sweongyo	BIO_STRATEGY(&(bp)->b_io);					\
193203945Sweongyo	} while (0)
194203945Sweongyo
195203945Sweongyo#endif /* _KERNEL */
196228621Sbschmidt
197228621Sbschmidt/*
198203945Sweongyo * Types for d_flags.
199203945Sweongyo */
200203945Sweongyo#define	D_TAPE	0x0001
201203945Sweongyo#define	D_DISK	0x0002
202203945Sweongyo#define	D_TTY	0x0004
203203945Sweongyo#define	D_MEM	0x0008
204203945Sweongyo
205203945Sweongyo#ifdef _KERNEL
206203945Sweongyo
207203945Sweongyo#define	D_TYPEMASK	0xffff
208203945Sweongyo
209203945Sweongyo/*
210203945Sweongyo * Flags for d_flags.
211203945Sweongyo */
212203945Sweongyo#define	D_MEMDISK	0x00010000	/* memory type disk */
213203945Sweongyo#define	D_NAGGED	0x00020000	/* nagged about missing make_dev() */
214203945Sweongyo#define	D_TRACKCLOSE	0x00080000	/* track all closes */
215203945Sweongyo#define D_MMAP_ANON	0x00100000	/* special treatment in vm_mmap.c */
216203945Sweongyo#define D_NOGIANT	0x00400000	/* Doesn't want Giant */
217203945Sweongyo
218203945Sweongyo/*
219203945Sweongyo * Character device switch table
220203945Sweongyo */
221203945Sweongyostruct cdevsw {
222203945Sweongyo	int		d_maj;
223203945Sweongyo	u_int		d_flags;
224203945Sweongyo	const char	*d_name;
225203945Sweongyo	d_open_t	*d_open;
226203945Sweongyo	d_close_t	*d_close;
227203945Sweongyo	d_read_t	*d_read;
228203945Sweongyo	d_write_t	*d_write;
229203945Sweongyo	d_ioctl_t	*d_ioctl;
230203945Sweongyo	d_poll_t	*d_poll;
231203945Sweongyo	d_mmap_t	*d_mmap;
232203945Sweongyo	d_strategy_t	*d_strategy;
233203945Sweongyo	dumper_t	*d_dump;
234203945Sweongyo	d_kqfilter_t	*d_kqfilter;
235203945Sweongyo};
236203945Sweongyo
237203945Sweongyo/*
238203945Sweongyo * Line discipline switch table
239203945Sweongyo */
240203945Sweongyostruct linesw {
241203945Sweongyo	l_open_t	*l_open;
242203945Sweongyo	l_close_t	*l_close;
243203945Sweongyo	l_read_t	*l_read;
244203945Sweongyo	l_write_t	*l_write;
245203945Sweongyo	l_ioctl_t	*l_ioctl;
246203945Sweongyo	l_rint_t	*l_rint;
247203945Sweongyo	l_start_t	*l_start;
248203945Sweongyo	l_modem_t	*l_modem;
249203945Sweongyo	u_char		l_hotchar;
250203945Sweongyo};
251203945Sweongyo
252203945Sweongyoextern struct linesw linesw[];
253203945Sweongyoextern int nlinesw;
254203945Sweongyo
255203945Sweongyoint ldisc_register(int , struct linesw *);
256203945Sweongyovoid ldisc_deregister(int);
257203945Sweongyo#define LDISC_LOAD 	-1		/* Loadable line discipline */
258203945Sweongyo#endif /* _KERNEL */
259203945Sweongyo
260203945Sweongyo#ifdef _KERNEL
261203945Sweongyod_open_t	noopen;
262203945Sweongyod_close_t	noclose;
263203945Sweongyod_read_t	noread;
264203945Sweongyod_write_t	nowrite;
265203945Sweongyod_ioctl_t	noioctl;
266203945Sweongyod_mmap_t	nommap;
267203945Sweongyod_kqfilter_t	nokqfilter;
268203945Sweongyo#define	nostrategy	((d_strategy_t *)NULL)
269203945Sweongyo#define	nopoll	seltrue
270203945Sweongyo
271203945Sweongyodumper_t	nodump;
272203945Sweongyo
273203945Sweongyo#define NUMCDEVSW 256
274203945Sweongyo
275203945Sweongyo#define	MAJOR_AUTO	0	/* XXX: Not GM */
276203945Sweongyo
277203945Sweongyo/*
278203945Sweongyo * nopsize is little used, so not worth having dummy functions for.
279203945Sweongyo */
280203945Sweongyo#define	nopsize	(NULL)
281203945Sweongyo
282203945Sweongyod_open_t	nullopen;
283203945Sweongyod_close_t	nullclose;
284203945Sweongyo
285203945Sweongyol_ioctl_t	l_nullioctl;
286203945Sweongyol_read_t	l_noread;
287203945Sweongyol_write_t	l_nowrite;
288203945Sweongyo
289203945Sweongyostruct module;
290203945Sweongyo
291203945Sweongyostruct devsw_module_data {
292203945Sweongyo	int	(*chainevh)(struct module *, int, void *); /* next handler */
293203945Sweongyo	void	*chainarg;	/* arg for next event handler */
294203945Sweongyo	/* Do not initialize fields hereafter */
295203945Sweongyo};
296203945Sweongyo
297203945Sweongyo#define DEV_MODULE(name, evh, arg)					\
298203945Sweongyostatic moduledata_t name##_mod = {					\
299203945Sweongyo    #name,								\
300203945Sweongyo    evh,								\
301203945Sweongyo    arg									\
302203945Sweongyo};									\
303203945SweongyoDECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
304203945Sweongyo
305203945Sweongyo
306203945Sweongyoint	count_dev(dev_t _dev);
307203945Sweongyovoid	destroy_dev(dev_t _dev);
308203945Sweongyovoid	revoke_and_destroy_dev(dev_t _dev);
309203945Sweongyostruct cdevsw *devsw(dev_t _dev);
310203945Sweongyoconst char *devtoname(dev_t _dev);
311203945Sweongyoint	dev_named(dev_t _pdev, const char *_name);
312203945Sweongyovoid	dev_depends(dev_t _pdev, dev_t _cdev);
313203945Sweongyovoid	freedev(dev_t _dev);
314203945Sweongyodev_t	makebdev(int _maj, int _min);
315203945Sweongyodev_t	make_dev(struct cdevsw *_devsw, int _minor, uid_t _uid, gid_t _gid,
316203945Sweongyo		int _perms, const char *_fmt, ...) __printflike(6, 7);
317203945Sweongyodev_t	make_dev_alias(dev_t _pdev, const char *_fmt, ...) __printflike(2, 3);
318203945Sweongyoint	dev2unit(dev_t _dev);
319203945Sweongyoint	unit2minor(int _unit);
320203945Sweongyovoid	setconf(void);
321203945Sweongyodev_t	getdiskbyname(char *_name);
322203945Sweongyo
323203945Sweongyovoid devfs_create(dev_t dev);
324203945Sweongyovoid devfs_destroy(dev_t dev);
325203945Sweongyo
326203945Sweongyo#define		UID_ROOT	0
327203945Sweongyo#define		UID_BIN		3
328203945Sweongyo#define		UID_UUCP	66
329203945Sweongyo
330203945Sweongyo#define		GID_WHEEL	0
331203945Sweongyo#define		GID_KMEM	2
332203945Sweongyo#define		GID_OPERATOR	5
333203945Sweongyo#define		GID_BIN		7
334203945Sweongyo#define		GID_GAMES	13
335203945Sweongyo#define		GID_DIALER	68
336203945Sweongyo
337203945Sweongyotypedef void (*dev_clone_fn)(void *arg, char *name, int namelen, dev_t *result);
338203945Sweongyo
339203945Sweongyoint dev_stdclone(char *_name, char **_namep, const char *_stem, int *_unit);
340203945SweongyoEVENTHANDLER_DECLARE(dev_clone, dev_clone_fn);
341203945Sweongyo
342203945Sweongyo/* Stuff relating to kernel-dump */
343203945Sweongyo
344203945Sweongyostruct dumperinfo {
345203945Sweongyo	dumper_t *dumper;	/* Dumping function. */
346203945Sweongyo	void    *priv;		/* Private parts. */
347203945Sweongyo	u_int   blocksize;	/* Size of block in bytes. */
348203945Sweongyo	off_t   mediaoffset;	/* Initial offset in bytes. */
349203945Sweongyo	off_t   mediasize;	/* Space available in bytes. */
350203945Sweongyo};
351203945Sweongyo
352203945Sweongyoint set_dumper(struct dumperinfo *);
353203945Sweongyovoid dumpsys(struct dumperinfo *);
354203945Sweongyoextern int dumping;		/* system is dumping */
355203945Sweongyo
356203945Sweongyo#endif /* _KERNEL */
357203945Sweongyo
358203945Sweongyo#endif /* !_SYS_CONF_H_ */
359203945Sweongyo