conf.h revision 143628
1193326Sed/*-
2193326Sed * Copyright (c) 1990, 1993
3193326Sed *	The Regents of the University of California.  All rights reserved.
4193326Sed * Copyright (c) 2000
5193326Sed *	Poul-Henning Kamp.  All rights reserved.
6193326Sed * (c) UNIX System Laboratories, Inc.
7193326Sed * All or some portions of this file are derived from material licensed
8193326Sed * to the University of California by American Telephone and Telegraph
9193326Sed * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10193326Sed * the permission of UNIX System Laboratories, Inc.
11193326Sed *
12193326Sed * Redistribution and use in source and binary forms, with or without
13193326Sed * modification, are permitted provided that the following conditions
14193326Sed * are met:
15193326Sed * 1. Redistributions of source code must retain the above copyright
16193326Sed *    notice, this list of conditions and the following disclaimer.
17193326Sed * 2. Redistributions in binary form must reproduce the above copyright
18200583Srdivacky *    notice, this list of conditions and the following disclaimer in the
19193326Sed *    documentation and/or other materials provided with the distribution.
20193326Sed * 4. Neither the name of the University nor the names of its contributors
21198092Srdivacky *    may be used to endorse or promote products derived from this software
22193326Sed *    without specific prior written permission.
23193326Sed *
24193326Sed * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25193326Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26193326Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27193326Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28203955Srdivacky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29203955Srdivacky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30193326Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31198092Srdivacky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32198092Srdivacky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33198092Srdivacky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34198092Srdivacky * SUCH DAMAGE.
35198092Srdivacky *
36205219Srdivacky *	@(#)conf.h	8.5 (Berkeley) 1/9/95
37203955Srdivacky * $FreeBSD: head/sys/sys/conf.h 143628 2005-03-15 10:52:17Z phk $
38203955Srdivacky */
39203955Srdivacky
40203955Srdivacky#ifndef _SYS_CONF_H_
41203955Srdivacky#define	_SYS_CONF_H_
42203955Srdivacky
43203955Srdivacky#ifdef _KERNEL
44203955Srdivacky#include <sys/eventhandler.h>
45193326Sed#else
46193326Sed#include <sys/queue.h>
47193326Sed#endif
48193326Sed
49198092Srdivackystruct tty;
50193326Sedstruct snapdata;
51193326Sedstruct devfs_dirent;
52198092Srdivackystruct cdevsw;
53198092Srdivacky
54198092Srdivackystruct cdev {
55198092Srdivacky	u_int		si_flags;
56193326Sed#define SI_ALIAS	0x0002	/* carrier of alias name */
57198092Srdivacky#define SI_NAMED	0x0004	/* make_dev{_alias} has been called */
58193326Sed#define SI_CHEAPCLONE	0x0008	/* can be removed_dev'ed when vnode reclaims */
59193326Sed#define SI_CHILD	0x0010	/* child of another struct cdev **/
60193326Sed#define SI_DEVOPEN	0x0020	/* opened by device */
61193326Sed#define SI_CONSOPEN	0x0040	/* opened by console */
62193326Sed#define SI_DUMPDEV	0x0080	/* is kernel dumpdev */
63193326Sed#define SI_CANDELETE	0x0100	/* can do BIO_DELETE */
64195341Sed#define SI_CLONELIST	0x0200	/* on a clone list */
65203955Srdivacky	struct timespec	si_atime;
66203955Srdivacky	struct timespec	si_ctime;
67203955Srdivacky	struct timespec	si_mtime;
68203955Srdivacky	dev_t		si_udev;
69203955Srdivacky	int		si_refcount;
70195341Sed	LIST_ENTRY(cdev)	si_list;
71195341Sed	LIST_ENTRY(cdev)	si_clone;
72195341Sed	LIST_ENTRY(cdev)	si_hash;
73198092Srdivacky	LIST_HEAD(,devfs_dirent)si_alist;
74203955Srdivacky	LIST_HEAD(, cdev)	si_children;
75193326Sed	LIST_ENTRY(cdev)	si_siblings;
76203955Srdivacky	struct cdev *si_parent;
77203955Srdivacky	u_int		si_inode;
78198092Srdivacky	char		*si_name;
79193326Sed	void		*si_drv1, *si_drv2;
80193326Sed	struct cdevsw	*si_devsw;
81203955Srdivacky	int		si_iosize_max;	/* maximum I/O size (for physio &al) */
82193326Sed	uid_t		si_uid;
83203955Srdivacky	gid_t		si_gid;
84203955Srdivacky	mode_t		si_mode;
85193326Sed	u_long		si_usecount;
86198092Srdivacky	u_long		si_threadcount;
87198092Srdivacky	union {
88198092Srdivacky		struct tty *__sit_tty;
89198092Srdivacky		struct snapdata *__sid_snapdata;
90203955Srdivacky	} __si_u;
91203955Srdivacky	char		__si_namebuf[SPECNAMELEN + 1];
92198092Srdivacky};
93203955Srdivacky
94198092Srdivacky#define si_tty		__si_u.__sit_tty
95198092Srdivacky#define si_snapdata	__si_u.__sid_snapdata
96198092Srdivacky
97204643Srdivacky#ifdef _KERNEL
98198092Srdivacky
99198092Srdivacky/*
100198092Srdivacky * Definitions of device driver entry switches
101198092Srdivacky */
102198092Srdivacky
103198092Srdivackystruct bio;
104198092Srdivackystruct buf;
105198092Srdivackystruct thread;
106198092Srdivackystruct uio;
107198092Srdivackystruct knote;
108198092Srdivackystruct clonedevs;
109198092Srdivacky
110198092Srdivacky/*
111198092Srdivacky * Note: d_thread_t is provided as a transition aid for those drivers
112198092Srdivacky * that treat struct proc/struct thread as an opaque data type and
113198092Srdivacky * exist in substantially the same form in both 4.x and 5.x.  Writers
114198092Srdivacky * of drivers that dips into the d_thread_t structure should use
115198092Srdivacky * struct thread or struct proc as appropriate for the version of the
116198092Srdivacky * OS they are using.  It is provided in lieu of each device driver
117198092Srdivacky * inventing its own way of doing this.  While it does violate style(9)
118198092Srdivacky * in a number of ways, this violation is deemed to be less
119198092Srdivacky * important than the benefits that a uniform API between releases
120198092Srdivacky * gives.
121198092Srdivacky *
122198092Srdivacky * Users of struct thread/struct proc that aren't device drivers should
123198092Srdivacky * not use d_thread_t.
124198092Srdivacky */
125198092Srdivacky
126198092Srdivackytypedef struct thread d_thread_t;
127198092Srdivacky
128198092Srdivackytypedef int d_open_t(struct cdev *dev, int oflags, int devtype, struct thread *td);
129198092Srdivackytypedef int d_fdopen_t(struct cdev *dev, int oflags, struct thread *td, int fdidx);
130198092Srdivackytypedef int d_close_t(struct cdev *dev, int fflag, int devtype, struct thread *td);
131198092Srdivackytypedef void d_strategy_t(struct bio *bp);
132198092Srdivackytypedef int d_ioctl_t(struct cdev *dev, u_long cmd, caddr_t data,
133198092Srdivacky		      int fflag, struct thread *td);
134198092Srdivacky
135198092Srdivackytypedef int d_read_t(struct cdev *dev, struct uio *uio, int ioflag);
136198092Srdivackytypedef int d_write_t(struct cdev *dev, struct uio *uio, int ioflag);
137198092Srdivackytypedef int d_poll_t(struct cdev *dev, int events, struct thread *td);
138198092Srdivackytypedef int d_kqfilter_t(struct cdev *dev, struct knote *kn);
139198092Srdivackytypedef int d_mmap_t(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr,
140203955Srdivacky   		     int nprot);
141203955Srdivackytypedef void d_purge_t(struct cdev *dev);
142198092Srdivacky
143198092Srdivackytypedef int d_spare2_t(struct cdev *dev);
144204643Srdivacky
145204643Srdivackytypedef int dumper_t(
146204643Srdivacky	void *priv,		/* Private to the driver. */
147198092Srdivacky	void *virtual,		/* Virtual (mapped) address. */
148198092Srdivacky	vm_offset_t physical,	/* Physical address of virtual. */
149203955Srdivacky	off_t offset,		/* Byte-offset to write at. */
150198092Srdivacky	size_t length);		/* Number of bytes to dump. */
151198092Srdivacky
152198092Srdivacky#endif /* _KERNEL */
153198092Srdivacky
154198092Srdivacky/*
155193326Sed * Types for d_flags.
156193326Sed */
157202379Srdivacky#define	D_TAPE	0x0001
158202379Srdivacky#define	D_DISK	0x0002
159202379Srdivacky#define	D_TTY	0x0004
160202379Srdivacky#define	D_MEM	0x0008
161202379Srdivacky
162202379Srdivacky#ifdef _KERNEL
163202379Srdivacky
164202379Srdivacky#define	D_TYPEMASK	0xffff
165202379Srdivacky
166202379Srdivacky/*
167202379Srdivacky * Flags for d_flags which the drivers can set.
168202379Srdivacky */
169202379Srdivacky#define	D_MEMDISK	0x00010000	/* memory type disk */
170193326Sed#define	D_TRACKCLOSE	0x00080000	/* track all closes */
171198092Srdivacky#define D_MMAP_ANON	0x00100000	/* special treatment in vm_mmap.c */
172194711Sed#define D_PSEUDO	0x00200000	/* make_dev() can return NULL */
173194711Sed#define D_NEEDGIANT	0x00400000	/* driver want Giant */
174198092Srdivacky
175194711Sed/*
176193326Sed * Version numbers.
177193326Sed */
178198092Srdivacky#define D_VERSION_00	0x20011966
179193326Sed#define D_VERSION	D_VERSION_00
180194711Sed
181194711Sed/*
182193326Sed * Flags used for internal housekeeping
183195341Sed */
184193326Sed#define D_INIT		0x80000000	/* cdevsw initialized */
185198092Srdivacky#define D_ALLOCMAJ	0x40000000	/* major# is allocated */
186198092Srdivacky
187198092Srdivacky/*
188198092Srdivacky * Character device switch table
189198092Srdivacky */
190201361Srdivackystruct cdevsw {
191198092Srdivacky	int			d_version;
192198092Srdivacky	int			d_maj;
193194711Sed	u_int			d_flags;
194198092Srdivacky	const char		*d_name;
195194711Sed	d_open_t		*d_open;
196193326Sed	d_fdopen_t		*d_fdopen;
197194711Sed	d_close_t		*d_close;
198193326Sed	d_read_t		*d_read;
199193326Sed	d_write_t		*d_write;
200198092Srdivacky	d_ioctl_t		*d_ioctl;
201198092Srdivacky	d_poll_t		*d_poll;
202193326Sed	d_mmap_t		*d_mmap;
203193326Sed	d_strategy_t		*d_strategy;
204193326Sed	dumper_t		*d_dump;
205193326Sed	d_kqfilter_t		*d_kqfilter;
206193326Sed	d_purge_t		*d_purge;
207195341Sed	d_spare2_t		*d_spare2;
208193326Sed
209193326Sed	/* These fields should not be messed with by drivers */
210193326Sed	LIST_ENTRY(cdevsw)	d_list;
211193326Sed	LIST_HEAD(, cdev)	d_devs;
212193326Sed	int			d_spare3;
213198893Srdivacky};
214198893Srdivacky
215198893Srdivacky#endif /* _KERNEL */
216198893Srdivacky
217193326Sed#ifdef _KERNEL
218193326Sed
219198092Srdivacky#define NUMCDEVSW 256
220198092Srdivacky
221193326Sed#define MAXMINOR	0xffff00ffU
222198092Srdivacky
223193326Sed/*
224193326Sed * XXX: do not use MAJOR_AUTO unless you have no choice.  In general drivers
225193326Sed * should just not initialize .d_maj and that will DTRT.
226193326Sed */
227193326Sed#define	MAJOR_AUTO	0	/* XXX: Not GM */
228193326Sed
229198092Srdivackystruct module;
230193326Sed
231193326Sedstruct devsw_module_data {
232193326Sed	int	(*chainevh)(struct module *, int, void *); /* next handler */
233193326Sed	void	*chainarg;	/* arg for next event handler */
234193326Sed	/* Do not initialize fields hereafter */
235199482Srdivacky};
236193326Sed
237198092Srdivacky#define DEV_MODULE(name, evh, arg)					\
238193326Sedstatic moduledata_t name##_mod = {					\
239193326Sed    #name,								\
240193326Sed    evh,								\
241193326Sed    arg									\
242193326Sed};									\
243193326SedDECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
244193326Sed
245193326Sed
246193326Sedvoid clone_setup(struct clonedevs **cdp);
247193326Sedvoid clone_cleanup(struct clonedevs **);
248198092Srdivacky#define CLONE_UNITMASK 0xfffff
249193326Sed#define CLONE_FLAG0 (CLONE_UNITMASK + 1)
250194613Sedint clone_create(struct clonedevs **, struct cdevsw *, int *unit, struct cdev **dev, u_int extra);
251194613Sed
252203955Srdivackyint	count_dev(struct cdev *_dev);
253193326Sedvoid	destroy_dev(struct cdev *_dev);
254198092Srdivackystruct cdevsw *dev_refthread(struct cdev *_dev);
255194613Sedvoid	dev_relthread(struct cdev *_dev);
256194613Sedint	dev_named(struct cdev *_pdev, const char *_name);
257203955Srdivackyvoid	dev_depends(struct cdev *_pdev, struct cdev *_cdev);
258193326Sedvoid	dev_ref(struct cdev *dev);
259194613Sedvoid	dev_rel(struct cdev *dev);
260194613Sedvoid	dev_strategy(struct cdev *dev, struct buf *bp);
261203955Srdivackystruct cdev *makebdev(int _maj, int _min);
262193326Sedstruct cdev *make_dev(struct cdevsw *_devsw, int _minor, uid_t _uid, gid_t _gid,
263194613Sed		int _perms, const char *_fmt, ...) __printflike(6, 7);
264194613Sedstruct cdev *make_dev_alias(struct cdev *_pdev, const char *_fmt, ...) __printflike(2, 3);
265194613Sedint	dev2unit(struct cdev *_dev);
266198092Srdivackyvoid	dev_lock(void);
267203955Srdivackyvoid	dev_unlock(void);
268198092Srdivackyint	unit2minor(int _unit);
269194613Sedu_int	minor2unit(u_int _minor);
270194613Sedvoid	setconf(void);
271201361Srdivacky
272203955Srdivackyvoid devfs_create(struct cdev *dev);
273198092Srdivackyvoid devfs_destroy(struct cdev *dev);
274198092Srdivacky
275198092Srdivacky#define		UID_ROOT	0
276198092Srdivacky#define		UID_BIN		3
277203955Srdivacky#define		UID_UUCP	66
278198092Srdivacky
279193326Sed#define		GID_WHEEL	0
280193326Sed#define		GID_KMEM	2
281193326Sed#define		GID_OPERATOR	5
282193326Sed#define		GID_BIN		7
283193326Sed#define		GID_GAMES	13
284198092Srdivacky#define		GID_DIALER	68
285193326Sed
286193326Sedtypedef void (*dev_clone_fn)(void *arg, char *name, int namelen, struct cdev **result);
287198092Srdivacky
288198092Srdivackyint dev_stdclone(char *_name, char **_namep, const char *_stem, int *_unit);
289198092SrdivackyEVENTHANDLER_DECLARE(dev_clone, dev_clone_fn);
290198092Srdivacky
291198092Srdivacky/* Stuff relating to kernel-dump */
292193326Sed
293198092Srdivackystruct dumperinfo {
294193326Sed	dumper_t *dumper;	/* Dumping function. */
295193326Sed	void    *priv;		/* Private parts. */
296193326Sed	u_int   blocksize;	/* Size of block in bytes. */
297193326Sed	off_t   mediaoffset;	/* Initial offset in bytes. */
298193326Sed	off_t   mediasize;	/* Space available in bytes. */
299193326Sed};
300199482Srdivacky
301193326Sedint set_dumper(struct dumperinfo *);
302193326Sedvoid dumpsys(struct dumperinfo *);
303193326Sedextern int dumping;		/* system is dumping */
304199482Srdivacky
305199482Srdivacky/* D_TTY related functions */
306199482Srdivackyd_close_t	 ttyclose;
307193326Sedd_ioctl_t	 ttyioctl;
308203955Srdivackyd_kqfilter_t	 ttykqfilter;
309193326Sedd_open_t	 ttyopen;
310198092Srdivackyd_poll_t	 ttypoll;
311198092Srdivackyd_read_t	 ttyread;
312198092Srdivackyd_write_t	 ttywrite;
313203955Srdivacky
314198092Srdivacky#endif /* _KERNEL */
315193326Sed
316193326Sed#endif /* !_SYS_CONF_H_ */
317193326Sed