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