conf.h revision 163529
1139825Simp/*-
21541Srgrimes * Copyright (c) 1990, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes * Copyright (c) 2000
51541Srgrimes *	Poul-Henning Kamp.  All rights reserved.
61541Srgrimes * (c) UNIX System Laboratories, Inc.
71541Srgrimes * All or some portions of this file are derived from material licensed
81541Srgrimes * to the University of California by American Telephone and Telegraph
91541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
101541Srgrimes * the permission of UNIX System Laboratories, Inc.
111541Srgrimes *
121541Srgrimes * Redistribution and use in source and binary forms, with or without
131541Srgrimes * modification, are permitted provided that the following conditions
141541Srgrimes * are met:
151541Srgrimes * 1. Redistributions of source code must retain the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer.
171541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
181541Srgrimes *    notice, this list of conditions and the following disclaimer in the
191541Srgrimes *    documentation and/or other materials provided with the distribution.
201541Srgrimes * 4. Neither the name of the University nor the names of its contributors
211541Srgrimes *    may be used to endorse or promote products derived from this software
221541Srgrimes *    without specific prior written permission.
231541Srgrimes *
241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3214495Shsu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3350477Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341541Srgrimes * SUCH DAMAGE.
351541Srgrimes *
362165Spaul *	@(#)conf.h	8.5 (Berkeley) 1/9/95
372165Spaul * $FreeBSD: head/sys/sys/conf.h 163529 2006-10-20 07:59:50Z kib $
381541Srgrimes */
391541Srgrimes
401541Srgrimes#ifndef _SYS_CONF_H_
4136449Sdt#define	_SYS_CONF_H_
421541Srgrimes
431541Srgrimes#ifdef _KERNEL
441541Srgrimes#include <sys/eventhandler.h>
451541Srgrimes#else
461541Srgrimes#include <sys/queue.h>
471541Srgrimes#endif
48143063Sjoerg
49143063Sjoergstruct tty;
50143063Sjoergstruct snapdata;
51143063Sjoergstruct devfs_dirent;
52143063Sjoergstruct cdevsw;
53143063Sjoerg
54143063Sjoergstruct cdev {
55143063Sjoerg	struct cdev_priv	*si_priv;
56143063Sjoerg	u_int		si_flags;
57143063Sjoerg#define SI_ALIAS	0x0002	/* carrier of alias name */
58143063Sjoerg#define SI_NAMED	0x0004	/* make_dev{_alias} has been called */
59143063Sjoerg#define SI_CHEAPCLONE	0x0008	/* can be removed_dev'ed when vnode reclaims */
60143063Sjoerg#define SI_CHILD	0x0010	/* child of another struct cdev **/
61143063Sjoerg#define SI_DEVOPEN	0x0020	/* opened by device */
62143063Sjoerg#define SI_CONSOPEN	0x0040	/* opened by console */
63143063Sjoerg#define SI_DUMPDEV	0x0080	/* is kernel dumpdev */
64143063Sjoerg#define SI_CANDELETE	0x0100	/* can do BIO_DELETE */
65143063Sjoerg#define SI_CLONELIST	0x0200	/* on a clone list */
66143063Sjoerg	struct timespec	si_atime;
67143063Sjoerg	struct timespec	si_ctime;
68143063Sjoerg	struct timespec	si_mtime;
69143063Sjoerg	uid_t		si_uid;
70143063Sjoerg	gid_t		si_gid;
71143063Sjoerg	mode_t		si_mode;
72143063Sjoerg	struct ucred	*si_cred;	/* cached clone-time credential */
73143063Sjoerg	u_int		si_drv0;
74143063Sjoerg	int		si_refcount;
75143063Sjoerg	LIST_ENTRY(cdev)	si_list;
76143063Sjoerg	LIST_ENTRY(cdev)	si_clone;
77150976Snetchild	LIST_HEAD(, cdev)	si_children;
78143063Sjoerg	LIST_ENTRY(cdev)	si_siblings;
79150976Snetchild	struct cdev *si_parent;
80150976Snetchild	char		*si_name;
81143063Sjoerg	void		*si_drv1, *si_drv2;
82143063Sjoerg	struct cdevsw	*si_devsw;
83143063Sjoerg	int		si_iosize_max;	/* maximum I/O size (for physio &al) */
84143063Sjoerg	u_long		si_usecount;
85143063Sjoerg	u_long		si_threadcount;
86143063Sjoerg	union {
87143063Sjoerg		struct tty *__sit_tty;
88143063Sjoerg		struct snapdata *__sid_snapdata;
89143063Sjoerg	} __si_u;
90143063Sjoerg	char		__si_namebuf[SPECNAMELEN + 1];
91143063Sjoerg};
92143063Sjoerg
93143063Sjoerg#define si_tty		__si_u.__sit_tty
94143063Sjoerg#define si_snapdata	__si_u.__sid_snapdata
95143063Sjoerg
96143063Sjoerg#ifdef _KERNEL
97143063Sjoerg
98143063Sjoerg/*
99143063Sjoerg * Definitions of device driver entry switches
100143063Sjoerg */
101143063Sjoerg
102143063Sjoergstruct bio;
103143063Sjoergstruct buf;
104143063Sjoergstruct thread;
105143063Sjoergstruct uio;
106143063Sjoergstruct knote;
107143063Sjoergstruct clonedevs;
108143063Sjoergstruct vnode;
109120608Smux
110120608Smux/*
111126891Strhodes * Note: d_thread_t is provided as a transition aid for those drivers
112120608Smux * that treat struct proc/struct thread as an opaque data type and
113120629Smux * exist in substantially the same form in both 4.x and 5.x.  Writers
114120608Smux * of drivers that dips into the d_thread_t structure should use
115120608Smux * struct thread or struct proc as appropriate for the version of the
116120608Smux * OS they are using.  It is provided in lieu of each device driver
117120608Smux * inventing its own way of doing this.  While it does violate style(9)
118120608Smux * in a number of ways, this violation is deemed to be less
1191541Srgrimes * important than the benefits that a uniform API between releases
1201541Srgrimes * gives.
12136971Sbde *
12236971Sbde * Users of struct thread/struct proc that aren't device drivers should
12336971Sbde * not use d_thread_t.
12436971Sbde */
12536971Sbde
12625083Sjdptypedef struct thread d_thread_t;
12725083Sjdp
12825083Sjdptypedef int d_open_t(struct cdev *dev, int oflags, int devtype, struct thread *td);
1291541Srgrimestypedef int d_fdopen_t(struct cdev *dev, int oflags, struct thread *td, int fdidx);
1301541Srgrimestypedef int d_close_t(struct cdev *dev, int fflag, int devtype, struct thread *td);
1311541Srgrimestypedef void d_strategy_t(struct bio *bp);
1325012Sbdetypedef int d_ioctl_t(struct cdev *dev, u_long cmd, caddr_t data,
1335012Sbde		      int fflag, struct thread *td);
13425083Sjdp
13525083Sjdptypedef int d_read_t(struct cdev *dev, struct uio *uio, int ioflag);
1361541Srgrimestypedef int d_write_t(struct cdev *dev, struct uio *uio, int ioflag);
1371541Srgrimestypedef int d_poll_t(struct cdev *dev, int events, struct thread *td);
1381541Srgrimestypedef int d_kqfilter_t(struct cdev *dev, struct knote *kn);
1391541Srgrimestypedef int d_mmap_t(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr,
1401541Srgrimes   		     int nprot);
1411541Srgrimestypedef void d_purge_t(struct cdev *dev);
1421541Srgrimes
143143063Sjoergtypedef int d_spare2_t(struct cdev *dev);
1441541Srgrimes
145143063Sjoergtypedef int dumper_t(
1461541Srgrimes	void *priv,		/* Private to the driver. */
1471541Srgrimes	void *virtual,		/* Virtual (mapped) address. */
1481541Srgrimes	vm_offset_t physical,	/* Physical address of virtual. */
1491541Srgrimes	off_t offset,		/* Byte-offset to write at. */
1501541Srgrimes	size_t length);		/* Number of bytes to dump. */
1511541Srgrimes
1521541Srgrimes#endif /* _KERNEL */
153143063Sjoerg
1541541Srgrimes/*
1551541Srgrimes * Types for d_flags.
1561541Srgrimes */
1571541Srgrimes#define	D_TAPE	0x0001
1581541Srgrimes#define	D_DISK	0x0002
1591541Srgrimes#define	D_TTY	0x0004
1601541Srgrimes#define	D_MEM	0x0008
1611541Srgrimes
1621541Srgrimes#ifdef _KERNEL
1631541Srgrimes
1641541Srgrimes#define	D_TYPEMASK	0xffff
1651541Srgrimes
1661541Srgrimes/*
1671541Srgrimes * Flags for d_flags which the drivers can set.
1681541Srgrimes */
1691541Srgrimes#define	D_TRACKCLOSE	0x00080000	/* track all closes */
1701541Srgrimes#define D_MMAP_ANON	0x00100000	/* special treatment in vm_mmap.c */
1715209Snate#define D_PSEUDO	0x00200000	/* make_dev() can return NULL */
172143063Sjoerg#define D_NEEDGIANT	0x00400000	/* driver want Giant */
1731541Srgrimes
1741541Srgrimes/*
1751541Srgrimes * Version numbers.
17638509Sbde */
17738509Sbde#define D_VERSION_00	0x20011966
17838509Sbde#define D_VERSION_01	0x17032005	/* Add d_uid,gid,mode & kind */
17938509Sbde#define D_VERSION	D_VERSION_01
180103845Speter
181103845Speter/*
182103845Speter * Flags used for internal housekeeping
1831541Srgrimes */
184103845Speter#define D_INIT		0x80000000	/* cdevsw initialized */
18583443Sasmodai
18683443Sasmodai/*
18783443Sasmodai * Character device switch table
188103834Speter */
189103836Speterstruct cdevsw {
190103841Speter	int			d_version;
191103845Speter	u_int			d_flags;
192126891Strhodes	const char		*d_name;
193103845Speter	d_open_t		*d_open;
194103845Speter	d_fdopen_t		*d_fdopen;
195103845Speter	d_close_t		*d_close;
1962059Sdg	d_read_t		*d_read;
197126891Strhodes	d_write_t		*d_write;
19883443Sasmodai	d_ioctl_t		*d_ioctl;
19983443Sasmodai	d_poll_t		*d_poll;
20083443Sasmodai	d_mmap_t		*d_mmap;
201103845Speter	d_strategy_t		*d_strategy;
2021541Srgrimes	dumper_t		*d_dump;
203120608Smux	d_kqfilter_t		*d_kqfilter;
20483443Sasmodai	d_purge_t		*d_purge;
20583443Sasmodai	d_spare2_t		*d_spare2;
20683443Sasmodai	uid_t			d_uid;
207132782Skan	gid_t			d_gid;
208103834Speter	mode_t			d_mode;
209103834Speter	const char		*d_kind;
210103836Speter
21117648Speter	/* These fields should not be messed with by drivers */
212126891Strhodes	LIST_ENTRY(cdevsw)	d_list;
213126891Strhodes	LIST_HEAD(, cdev)	d_devs;
214126891Strhodes	int			d_spare3;
215126891Strhodes	struct cdevsw		*d_gianttrick;
216132782Skan};
217126891Strhodes
218126891Strhodes#define NUMCDEVSW 256
219126891Strhodes
220103845Speter#define MAXMINOR	0xffff00ffU
221126891Strhodes
2221541Srgrimesstruct module;
223132538Stjr
224187961Sdasstruct devsw_module_data {
225132538Stjr	int	(*chainevh)(struct module *, int, void *); /* next handler */
226132538Stjr	void	*chainarg;	/* arg for next event handler */
227187961Sdas	/* Do not initialize fields hereafter */
228132538Stjr};
229132538Stjr
230132538Stjr#define DEV_MODULE(name, evh, arg)					\
231126891Strhodesstatic moduledata_t name##_mod = {					\
232117906Speter    #name,								\
233117906Speter    evh,								\
234117906Speter    arg									\
235117906Speter};									\
236117906SpeterDECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
237174496Salc
238174496Salc
239174496Salcvoid clone_setup(struct clonedevs **cdp);
240174496Salcvoid clone_cleanup(struct clonedevs **);
241174496Salc#define CLONE_UNITMASK 0xfffff
242174496Salc#define CLONE_FLAG0 (CLONE_UNITMASK + 1)
243177618Ssamint clone_create(struct clonedevs **, struct cdevsw *, int *unit, struct cdev **dev, u_int extra);
244177618Ssam
245177618Ssamint	count_dev(struct cdev *_dev);
246177618Ssamvoid	destroy_dev(struct cdev *_dev);
247177618Ssamstruct cdevsw *dev_refthread(struct cdev *_dev);
248177618Ssamstruct cdevsw *devvn_refthread(struct vnode *vp, struct cdev **devp);
249120608Smuxvoid	dev_relthread(struct cdev *_dev);
250117837Sphkvoid	dev_depends(struct cdev *_pdev, struct cdev *_cdev);
251117837Sphkvoid	dev_ref(struct cdev *dev);
252117837Sphkvoid	dev_refl(struct cdev *dev);
253117837Sphkvoid	dev_rel(struct cdev *dev);
254117837Sphkvoid	dev_strategy(struct cdev *dev, struct buf *bp);
25585672Smikestruct cdev *make_dev(struct cdevsw *_devsw, int _minor, uid_t _uid, gid_t _gid,
256126891Strhodes		int _perms, const char *_fmt, ...) __printflike(6, 7);
25785672Smikestruct cdev *make_dev_cred(struct cdevsw *_devsw, int _minor,
25885672Smike		struct ucred *_cr, uid_t _uid, gid_t _gid, int _perms,
25985672Smike		const char *_fmt, ...) __printflike(7, 8);
260126891Strhodesstruct cdev *make_dev_alias(struct cdev *_pdev, const char *_fmt, ...) __printflike(2, 3);
26186302Smikeint	dev2unit(struct cdev *_dev);
26286302Smikevoid	dev_lock(void);
26386302Smikevoid	dev_unlock(void);
26438509Sbdeint	unit2minor(int _unit);
265104591Smikeu_int	minor2unit(u_int _minor);
266103370Swollmanvoid	setconf(void);
267103370Swollman
268103370Swollman#define		UID_ROOT	0
26986803Smike#define		UID_BIN		3
27086803Smike#define		UID_UUCP	66
271121783Speter
27286803Smike#define		GID_WHEEL	0
27386803Smike#define		GID_KMEM	2
27486803Smike#define		GID_OPERATOR	5
27586803Smike#define		GID_BIN		7
27686803Smike#define		GID_GAMES	13
27786803Smike#define		GID_DIALER	68
27886803Smike
279120609Smuxtypedef void (*dev_clone_fn)(void *arg, struct ucred *cred, char *name,
280120609Smux	    int namelen, struct cdev **result);
281120609Smux
282120609Smuxint dev_stdclone(char *_name, char **_namep, const char *_stem, int *_unit);
283120609SmuxEVENTHANDLER_DECLARE(dev_clone, dev_clone_fn);
284120609Smux
285120609Smux/* Stuff relating to kernel-dump */
286120609Smux
287120609Smuxstruct dumperinfo {
288120609Smux	dumper_t *dumper;	/* Dumping function. */
289120609Smux	void    *priv;		/* Private parts. */
290120609Smux	u_int   blocksize;	/* Size of block in bytes. */
291120609Smux	off_t   mediaoffset;	/* Initial offset in bytes. */
292120609Smux	off_t   mediasize;	/* Space available in bytes. */
293120609Smux};
294120609Smux
295120609Smuxint set_dumper(struct dumperinfo *);
296120609Smuxvoid dumpsys(struct dumperinfo *);
297120609Smuxextern int dumping;		/* system is dumping */
298120609Smux
299120609Smux/* D_TTY related functions */
300120609Smuxd_close_t	 ttyclose;
301120609Smuxd_ioctl_t	 ttyioctl;
302120609Smuxd_kqfilter_t	 ttykqfilter;
303120609Smuxd_open_t	 ttyopen;
304120609Smuxd_poll_t	 ttypoll;
305120609Smuxd_read_t	 ttyread;
306120609Smuxd_write_t	 ttywrite;
307120609Smux
308120609Smux#endif /* _KERNEL */
309120609Smux
310120609Smux#endif /* !_SYS_CONF_H_ */
311120609Smux