xref: /dragonfly/sys/sys/conf.h (revision 1bf4b486)
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  * $FreeBSD: src/sys/sys/conf.h,v 1.103.2.6 2002/03/11 01:14:55 dd Exp $
40  * $DragonFly: src/sys/sys/conf.h,v 1.9 2005/02/21 18:56:02 dillon Exp $
41  */
42 
43 #ifndef _SYS_CONF_H_
44 #define	_SYS_CONF_H_
45 
46 #include <sys/queue.h>
47 #include <sys/time.h>
48 
49 #define SPECNAMELEN	15
50 
51 struct tty;
52 struct disk;
53 struct vnode;
54 struct lwkt_port;
55 
56 struct specinfo {
57 	u_int		si_flags;
58 	udev_t		si_udev;
59 	LIST_ENTRY(specinfo)	si_hash;
60 	SLIST_HEAD(, vnode) si_hlist;
61 	char		si_name[SPECNAMELEN + 1];
62 	void		*si_drv1;
63 	void		*si_drv2;
64 	struct cdevsw	*si_devsw;	/* direct device switch */
65 	struct lwkt_port *si_port;	/* direct port dispatch */
66 	int		si_iosize_max;	/* maximum I/O size (for physio &al) */
67 	int		si_refs;
68 	union {
69 		struct {
70 			struct tty *__sit_tty;
71 		} __si_tty;
72 		struct {
73 			struct disk *__sid_disk;
74 			struct mount *__sid_mountpoint;
75 			int __sid_bsize_phys; /* min physical block size */
76 			int __sid_bsize_best; /* optimal block size */
77 		} __si_disk;
78 	} __si_u;
79 	time_t		si_lastread;		/* time_second */
80 	time_t		si_lastwrite;		/* time_second */
81 };
82 
83 #define SI_STASHED	0x0001	/* created in stashed storage */
84 #define SI_HASHED	0x0002	/* in (maj,min) hash table */
85 #define SI_ADHOC	0x0004	/* created via make_adhoc_dev() or udev2dev() */
86 
87 #define si_tty		__si_u.__si_tty.__sit_tty
88 #define si_disk		__si_u.__si_disk.__sid_disk
89 #define si_mountpoint	__si_u.__si_disk.__sid_mountpoint
90 #define si_bsize_phys	__si_u.__si_disk.__sid_bsize_phys
91 #define si_bsize_best	__si_u.__si_disk.__sid_bsize_best
92 
93 #define CDEVSW_ALL_MINORS	0	/* mask of 0 always matches 0 */
94 
95 /*
96  * Special device management
97  */
98 #define	SPECHSZ	64
99 #define	SPECHASH(rdev)	(((unsigned)(minor(rdev)))%SPECHSZ)
100 
101 /*
102  * Definitions of device driver entry switches
103  */
104 
105 struct buf;
106 struct proc;
107 struct uio;
108 struct knote;
109 
110 /*
111  * Note: d_thread_t is provided as a transition aid for those drivers
112  * that treat struct proc/struct thread as an opaque data type and
113  * exist in substantially the same form in both 4.x and 5.x.  Writers
114  * of drivers that dips into the d_thread_t structure should use
115  * struct thread or struct proc as appropriate for the version of the
116  * OS they are using.  It is provided in lieu of each device driver
117  * inventing its own way of doing this.  While it does violate style(9)
118  * in a number of ways, this violation is deemed to be less
119  * important than the benefits that a uniform API between releases
120  * gives.
121  *
122  * Users of struct thread/struct proc that aren't device drivers should
123  * not use d_thread_t.
124  */
125 
126 struct thread;
127 struct lwkt_port;
128 
129 typedef struct thread d_thread_t;
130 typedef int d_clone_t (dev_t dev);
131 typedef int d_open_t (dev_t dev, int oflags, int devtype, d_thread_t *td);
132 typedef int d_close_t (dev_t dev, int fflag, int devtype, d_thread_t *td);
133 typedef void d_strategy_t (struct buf *bp);
134 typedef int d_ioctl_t (dev_t dev, u_long cmd, caddr_t data,
135 			   int fflag, d_thread_t *td);
136 typedef int d_dump_t (dev_t dev, u_int count, u_int blkno, u_int secsize);
137 typedef int d_psize_t (dev_t dev);
138 
139 typedef int d_read_t (dev_t dev, struct uio *uio, int ioflag);
140 typedef int d_write_t (dev_t dev, struct uio *uio, int ioflag);
141 typedef int d_poll_t (dev_t dev, int events, d_thread_t *td);
142 typedef int d_kqfilter_t (dev_t dev, struct knote *kn);
143 typedef int d_mmap_t (dev_t dev, vm_offset_t offset, int nprot);
144 
145 typedef int l_open_t (dev_t dev, struct tty *tp);
146 typedef int l_close_t (struct tty *tp, int flag);
147 typedef int l_read_t (struct tty *tp, struct uio *uio, int flag);
148 typedef int l_write_t (struct tty *tp, struct uio *uio, int flag);
149 typedef int l_ioctl_t (struct tty *tp, u_long cmd, caddr_t data,
150 			   int flag, d_thread_t *td);
151 typedef int l_rint_t (int c, struct tty *tp);
152 typedef int l_start_t (struct tty *tp);
153 typedef int l_modem_t (struct tty *tp, int flag);
154 
155 /*
156  * XXX: The dummy argument can be used to do what strategy1() never
157  * did anywhere:  Create a per device flag to lock the device during
158  * label/slice surgery, all calls with a dummy == 0 gets stalled on
159  * a queue somewhere, whereas dummy == 1 are let through.  Once out
160  * of surgery, reset the flag and restart all the stuff on the stall
161  * queue.
162  */
163 #define BUF_STRATEGY(bp, dummy) dev_dstrategy((bp)->b_dev, bp)
164 /*
165  * Types for d_flags.
166  */
167 #define	D_TAPE	0x0001
168 #define	D_DISK	0x0002
169 #define	D_TTY	0x0004
170 #define	D_MEM	0x0008
171 
172 #define	D_TYPEMASK	0xffff
173 
174 /*
175  * Flags for d_flags.
176  */
177 #define	D_MEMDISK	0x00010000	/* memory type disk */
178 #define	D_NAGGED	0x00020000	/* nagged about missing make_dev() */
179 #define	D_CANFREE	0x00040000	/* can free blocks */
180 #define	D_TRACKCLOSE	0x00080000	/* track all closes */
181 #define D_MASTER	0x00100000	/* used by pty/tty code */
182 #define	D_KQFILTER	0x00200000	/* has kqfilter entry */
183 
184 /*
185  * Character device switch table.
186  *
187  * NOTE: positions are hard coded for static structure initialization.
188  */
189 struct cdevsw {
190 	const char	*d_name;	/* base device name, e.g. 'vn' */
191 	int		d_maj;		/* major (char) device number */
192 	u_int		d_flags;	/* D_ flags */
193 	struct lwkt_port *d_port;	/* port (template only) */
194 	d_clone_t	*d_clone;	/* clone from base cdevsw */
195 
196 	/*
197 	 * Old style vectors are used only if d_port is NULL when the cdevsw
198 	 * is added to the system.   They have been renamed to prevent misuse.
199 	 */
200 	d_open_t	*old_open;
201 	d_close_t	*old_close;
202 	d_read_t	*old_read;
203 	d_write_t	*old_write;
204 	d_ioctl_t	*old_ioctl;
205 	d_poll_t	*old_poll;
206 	d_mmap_t	*old_mmap;
207 	d_strategy_t	*old_strategy;
208 	d_dump_t	*old_dump;
209 	d_psize_t	*old_psize;
210 	d_kqfilter_t	*old_kqfilter;
211 	void		(*old_dummy1)(void);	/* expansion space */
212 	void		(*old_dummy2)(void);
213 	void		(*old_dummy3)(void);
214 	void		(*old_dummy4)(void);
215 	int		d_refs;			/* ref count */
216 	void		*d_data;		/* custom driver data */
217 };
218 
219 struct cdevlink {
220 	struct cdevlink	*next;
221 	u_int		mask;
222 	u_int		match;
223 	struct cdevsw	*devsw;
224 };
225 
226 /*
227  * Line discipline switch table
228  */
229 struct linesw {
230 	l_open_t	*l_open;
231 	l_close_t	*l_close;
232 	l_read_t	*l_read;
233 	l_write_t	*l_write;
234 	l_ioctl_t	*l_ioctl;
235 	l_rint_t	*l_rint;
236 	l_start_t	*l_start;
237 	l_modem_t	*l_modem;
238 	u_char		l_hotchar;
239 };
240 
241 #ifdef _KERNEL
242 extern struct linesw linesw[];
243 extern int nlinesw;
244 
245 int ldisc_register (int , struct linesw *);
246 void ldisc_deregister (int);
247 #define LDISC_LOAD 	-1		/* Loadable line discipline */
248 #endif
249 
250 /*
251  * Swap device table
252  */
253 struct swdevt {
254 	udev_t	sw_dev;			/* For quasibogus swapdev reporting */
255 	int	sw_flags;
256 	int	sw_nblks;
257 	struct	vnode *sw_vp;
258 	dev_t	sw_device;
259 };
260 #define	SW_FREED	0x01
261 #define	SW_SEQUENTIAL	0x02
262 #define	sw_freed	sw_flags	/* XXX compat */
263 
264 #ifdef _KERNEL
265 d_open_t	noopen;
266 d_close_t	noclose;
267 d_read_t	noread;
268 d_write_t	nowrite;
269 d_ioctl_t	noioctl;
270 d_clone_t	noclone;
271 d_mmap_t	nommap;
272 d_kqfilter_t	nokqfilter;
273 d_strategy_t	nostrategy;
274 d_poll_t	nopoll;
275 d_psize_t	nopsize;
276 d_dump_t	nodump;
277 
278 #define NUMCDEVSW 256
279 
280 d_open_t	nullopen;
281 d_close_t	nullclose;
282 
283 l_ioctl_t	l_nullioctl;
284 l_read_t	l_noread;
285 l_write_t	l_nowrite;
286 
287 struct module;
288 
289 struct devsw_module_data {
290 	int	(*chainevh)(struct module *, int, void *); /* next handler */
291 	void	*chainarg;	/* arg for next event handler */
292 	/* Do not initialize fields hereafter */
293 };
294 
295 #define DEV_MODULE(name, evh, arg)					\
296 static moduledata_t name##_mod = {					\
297     #name,								\
298     evh,								\
299     arg									\
300 };									\
301 DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
302 
303 extern struct cdevsw dead_cdevsw;
304 
305 void	compile_devsw(struct cdevsw *);
306 int	cdevsw_add (struct cdevsw *, u_int mask, u_int match);
307 struct cdevsw *cdevsw_add_override (dev_t, u_int mask, u_int match);
308 struct lwkt_port *cdevsw_dev_override(dev_t dev, struct lwkt_port *port);
309 
310 int	cdevsw_remove (struct cdevsw *, u_int mask, u_int match);
311 struct cdevsw *cdevsw_get (int x, int y);
312 void	cdevsw_release (struct cdevsw *);
313 int	count_dev (dev_t dev);
314 int	count_udev (udev_t dev);
315 void	destroy_dev (dev_t dev);
316 void	destroy_all_dev (struct cdevsw *, u_int mask, u_int match);
317 void	release_dev (dev_t dev);
318 dev_t	reference_dev (dev_t dev);
319 struct cdevsw *devsw (dev_t dev);
320 const char *devtoname (dev_t dev);
321 void	freedev (dev_t dev);
322 int	iszerodev (dev_t dev);
323 dev_t	make_dev (struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, const char *fmt, ...) __printflike(6, 7);
324 dev_t	make_adhoc_dev (struct cdevsw *devsw, int minor);
325 dev_t	make_sub_dev (dev_t dev, int minor);
326 int	lminor (dev_t dev);
327 void	setconf (void);
328 dev_t	getdiskbyname(const char *name);
329 int	dev_is_good(dev_t dev);
330 
331 /*
332  * XXX: This included for when DEVFS resurfaces
333  */
334 
335 #define		UID_ROOT	0
336 #define		UID_BIN		3
337 #define		UID_UUCP	66
338 
339 #define		GID_WHEEL	0
340 #define		GID_KMEM	2
341 #define		GID_OPERATOR	5
342 #define		GID_BIN		7
343 #define		GID_GAMES	13
344 #define		GID_DIALER	68
345 
346 #endif /* _KERNEL */
347 
348 #endif /* !_SYS_CONF_H_ */
349