conf.h revision 198706
1114472Sru/*-
2146515Sru * Copyright (c) 1990, 1993
321495Sjmacd *	The Regents of the University of California.  All rights reserved.
4146515Sru * Copyright (c) 2000
521495Sjmacd *	Poul-Henning Kamp.  All rights reserved.
621495Sjmacd * (c) UNIX System Laboratories, Inc.
721495Sjmacd * All or some portions of this file are derived from material licensed
821495Sjmacd * to the University of California by American Telephone and Telegraph
921495Sjmacd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
1021495Sjmacd * the permission of UNIX System Laboratories, Inc.
1121495Sjmacd *
1221495Sjmacd * Redistribution and use in source and binary forms, with or without
1321495Sjmacd * modification, are permitted provided that the following conditions
1421495Sjmacd * are met:
1521495Sjmacd * 1. Redistributions of source code must retain the above copyright
1621495Sjmacd *    notice, this list of conditions and the following disclaimer.
1721495Sjmacd * 2. Redistributions in binary form must reproduce the above copyright
1821495Sjmacd *    notice, this list of conditions and the following disclaimer in the
1921495Sjmacd *    documentation and/or other materials provided with the distribution.
2021495Sjmacd * 4. Neither the name of the University nor the names of its contributors
2121495Sjmacd *    may be used to endorse or promote products derived from this software
2221495Sjmacd *    without specific prior written permission.
2321495Sjmacd *
2421495Sjmacd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2521495Sjmacd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2642660Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2742660Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2842660Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2921495Sjmacd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3021495Sjmacd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3121495Sjmacd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3221495Sjmacd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3321495Sjmacd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3421495Sjmacd * SUCH DAMAGE.
3521495Sjmacd *
3621495Sjmacd *	@(#)conf.h	8.5 (Berkeley) 1/9/95
3742660Smarkm * $FreeBSD: head/sys/sys/conf.h 198706 2009-10-31 10:35:41Z ed $
3821495Sjmacd */
3921495Sjmacd
4021495Sjmacd#ifndef _SYS_CONF_H_
4142660Smarkm#define	_SYS_CONF_H_
4221495Sjmacd
4321495Sjmacd#ifdef _KERNEL
4421495Sjmacd#include <sys/eventhandler.h>
4542660Smarkm#else
4621495Sjmacd#include <sys/queue.h>
4721495Sjmacd#endif
4821495Sjmacd
4942660Smarkmstruct snapdata;
5021495Sjmacdstruct devfs_dirent;
5121495Sjmacdstruct cdevsw;
5221495Sjmacdstruct file;
5342660Smarkm
5421495Sjmacdstruct cdev {
5521495Sjmacd	void		*__si_reserved;
5642660Smarkm	u_int		si_flags;
5721495Sjmacd#define SI_ALIAS	0x0002	/* carrier of alias name */
5821495Sjmacd#define SI_NAMED	0x0004	/* make_dev{_alias} has been called */
5921495Sjmacd#define SI_CHEAPCLONE	0x0008	/* can be removed_dev'ed when vnode reclaims */
6042660Smarkm#define SI_CHILD	0x0010	/* child of another struct cdev **/
6121495Sjmacd#define SI_DEVOPEN	0x0020	/* opened by device */
6221495Sjmacd#define SI_CONSOPEN	0x0040	/* opened by console */
6321495Sjmacd#define SI_DUMPDEV	0x0080	/* is kernel dumpdev */
6442660Smarkm#define SI_CANDELETE	0x0100	/* can do BIO_DELETE */
6521495Sjmacd#define SI_CLONELIST	0x0200	/* on a clone list */
6621495Sjmacd	struct timespec	si_atime;
6721495Sjmacd	struct timespec	si_ctime;
6842660Smarkm	struct timespec	si_mtime;
6921495Sjmacd	uid_t		si_uid;
7021495Sjmacd	gid_t		si_gid;
7121495Sjmacd	mode_t		si_mode;
7221495Sjmacd	struct ucred	*si_cred;	/* cached clone-time credential */
7321495Sjmacd	int		si_drv0;
7442660Smarkm	int		si_refcount;
7521495Sjmacd	LIST_ENTRY(cdev)	si_list;
7621495Sjmacd	LIST_ENTRY(cdev)	si_clone;
7721495Sjmacd	LIST_HEAD(, cdev)	si_children;
7821495Sjmacd	LIST_ENTRY(cdev)	si_siblings;
7921495Sjmacd	struct cdev *si_parent;
80146515Sru	char		*si_name;
8121495Sjmacd	void		*si_drv1, *si_drv2;
8221495Sjmacd	struct cdevsw	*si_devsw;
8321495Sjmacd	int		si_iosize_max;	/* maximum I/O size (for physio &al) */
8421495Sjmacd	u_long		si_usecount;
8542660Smarkm	u_long		si_threadcount;
8642660Smarkm	union {
8721495Sjmacd		struct snapdata *__sid_snapdata;
8821495Sjmacd	} __si_u;
8921495Sjmacd	char		__si_namebuf[SPECNAMELEN + 1];
9042660Smarkm};
9121495Sjmacd
9242660Smarkm#define si_snapdata	__si_u.__sid_snapdata
9342660Smarkm
9421495Sjmacd#ifdef _KERNEL
95146515Sru
9621495Sjmacd/*
9721495Sjmacd * Definitions of device driver entry switches
9821495Sjmacd */
9942660Smarkm
10021495Sjmacdstruct bio;
10121495Sjmacdstruct buf;
10221495Sjmacdstruct thread;
10321495Sjmacdstruct uio;
10421495Sjmacdstruct knote;
105146515Srustruct clonedevs;
10621495Sjmacdstruct vm_object;
10721495Sjmacdstruct vnode;
10821495Sjmacd
10921495Sjmacd/*
11021495Sjmacd * Note: d_thread_t is provided as a transition aid for those drivers
11121495Sjmacd * that treat struct proc/struct thread as an opaque data type and
11221495Sjmacd * exist in substantially the same form in both 4.x and 5.x.  Writers
11321495Sjmacd * of drivers that dips into the d_thread_t structure should use
11421495Sjmacd * struct thread or struct proc as appropriate for the version of the
11521495Sjmacd * OS they are using.  It is provided in lieu of each device driver
11642660Smarkm * inventing its own way of doing this.  While it does violate style(9)
11721495Sjmacd * in a number of ways, this violation is deemed to be less
11842660Smarkm * important than the benefits that a uniform API between releases
11942660Smarkm * gives.
12042660Smarkm *
12142660Smarkm * Users of struct thread/struct proc that aren't device drivers should
12221495Sjmacd * not use d_thread_t.
12342660Smarkm */
12442660Smarkm
12542660Smarkmtypedef struct thread d_thread_t;
12621495Sjmacd
12742660Smarkmtypedef int d_open_t(struct cdev *dev, int oflags, int devtype, struct thread *td);
12842660Smarkmtypedef int d_fdopen_t(struct cdev *dev, int oflags, struct thread *td, struct file *fp);
12942660Smarkmtypedef int d_close_t(struct cdev *dev, int fflag, int devtype, struct thread *td);
13021495Sjmacdtypedef void d_strategy_t(struct bio *bp);
13142660Smarkmtypedef int d_ioctl_t(struct cdev *dev, u_long cmd, caddr_t data,
13242660Smarkm		      int fflag, struct thread *td);
13342660Smarkm
13421495Sjmacdtypedef int d_read_t(struct cdev *dev, struct uio *uio, int ioflag);
13542660Smarkmtypedef int d_write_t(struct cdev *dev, struct uio *uio, int ioflag);
13642660Smarkmtypedef int d_poll_t(struct cdev *dev, int events, struct thread *td);
13742660Smarkmtypedef int d_kqfilter_t(struct cdev *dev, struct knote *kn);
13842660Smarkmtypedef int d_mmap_t(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr,
13942660Smarkm   		     int nprot);
14042660Smarkmtypedef int d_mmap2_t(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr,
14121495Sjmacd		     int nprot, vm_memattr_t *memattr);
14242660Smarkmtypedef int d_mmap_single_t(struct cdev *cdev, vm_ooffset_t *offset,
14321495Sjmacd    vm_size_t size, struct vm_object **object, int nprot);
14421495Sjmacdtypedef void d_purge_t(struct cdev *dev);
14521495Sjmacd
14642660Smarkmtypedef int dumper_t(
14742660Smarkm	void *_priv,		/* Private to the driver. */
14842660Smarkm	void *_virtual,		/* Virtual (mapped) address. */
14942660Smarkm	vm_offset_t _physical,	/* Physical address of virtual. */
15021495Sjmacd	off_t _offset,		/* Byte-offset to write at. */
15142660Smarkm	size_t _length);	/* Number of bytes to dump. */
15242660Smarkm
15342660Smarkm#endif /* _KERNEL */
15421495Sjmacd
15542660Smarkm/*
15642660Smarkm * Types for d_flags.
15742660Smarkm */
15842660Smarkm#define	D_TAPE	0x0001
15921495Sjmacd#define	D_DISK	0x0002
16042660Smarkm#define	D_TTY	0x0004
16142660Smarkm#define	D_MEM	0x0008
16242660Smarkm
16321495Sjmacd#ifdef _KERNEL
16442660Smarkm
16542660Smarkm#define	D_TYPEMASK	0xffff
16621495Sjmacd
16742660Smarkm/*
16842660Smarkm * Flags for d_flags which the drivers can set.
16921495Sjmacd */
17042660Smarkm#define	D_TRACKCLOSE	0x00080000	/* track all closes */
17121495Sjmacd#define D_MMAP_ANON	0x00100000	/* special treatment in vm_mmap.c */
17242660Smarkm#define D_PSEUDO	0x00200000	/* make_dev() can return NULL */
17342660Smarkm#define D_NEEDGIANT	0x00400000	/* driver want Giant */
17421495Sjmacd#define	D_NEEDMINOR	0x00800000	/* driver uses clone_create() */
17542660Smarkm#define	D_MMAP2		0x01000000	/* driver uses d_mmap2() */
17642660Smarkm
17742660Smarkm/*
17842660Smarkm * Version numbers.
17942660Smarkm */
18042660Smarkm#define D_VERSION_00	0x20011966
18121495Sjmacd#define D_VERSION_01	0x17032005	/* Add d_uid,gid,mode & kind */
18242660Smarkm#define D_VERSION_02	0x28042009	/* Add d_mmap_single */
18342660Smarkm#define D_VERSION	D_VERSION_02
18442660Smarkm
18542660Smarkm/*
18642660Smarkm * Flags used for internal housekeeping
18742660Smarkm */
18821495Sjmacd#define D_INIT		0x80000000	/* cdevsw initialized */
18942660Smarkm
19042660Smarkm/*
19142660Smarkm * Character device switch table
19242660Smarkm */
19321495Sjmacdstruct cdevsw {
19442660Smarkm	int			d_version;
19542660Smarkm	u_int			d_flags;
19621495Sjmacd	const char		*d_name;
19721495Sjmacd	d_open_t		*d_open;
19821495Sjmacd	d_fdopen_t		*d_fdopen;
19921495Sjmacd	d_close_t		*d_close;
20021495Sjmacd	d_read_t		*d_read;
20121495Sjmacd	d_write_t		*d_write;
20221495Sjmacd	d_ioctl_t		*d_ioctl;
20321495Sjmacd	d_poll_t		*d_poll;
204146515Sru	union {
20521495Sjmacd		d_mmap_t		*old;
20621495Sjmacd		d_mmap2_t		*new;
20721495Sjmacd	} __d_mmap;
20821495Sjmacd	d_strategy_t		*d_strategy;
20921495Sjmacd	dumper_t		*d_dump;
21021495Sjmacd	d_kqfilter_t		*d_kqfilter;
21121495Sjmacd	d_purge_t		*d_purge;
21221495Sjmacd	d_mmap_single_t		*d_mmap_single;
21321495Sjmacd
21421495Sjmacd	int32_t			d_spare0[3];
21521495Sjmacd	void			*d_spare1[3];
21621495Sjmacd
21721495Sjmacd	/* These fields should not be messed with by drivers */
21821495Sjmacd	LIST_HEAD(, cdev)	d_devs;
21921495Sjmacd	int			d_spare2;
22021495Sjmacd	union {
22121495Sjmacd		struct cdevsw		*gianttrick;
22221495Sjmacd		SLIST_ENTRY(cdevsw)	postfree_list;
22321495Sjmacd	} __d_giant;
22421495Sjmacd};
22521495Sjmacd#define	d_mmap			__d_mmap.old
22621495Sjmacd#define	d_mmap2			__d_mmap.new
22721495Sjmacd#define	d_gianttrick		__d_giant.gianttrick
22821495Sjmacd#define	d_postfree_list		__d_giant.postfree_list
22921495Sjmacd
23021495Sjmacdstruct module;
23121495Sjmacd
23221495Sjmacdstruct devsw_module_data {
23321495Sjmacd	int	(*chainevh)(struct module *, int, void *); /* next handler */
23421495Sjmacd	void	*chainarg;	/* arg for next event handler */
23521495Sjmacd	/* Do not initialize fields hereafter */
23621495Sjmacd};
23721495Sjmacd
23821495Sjmacd#define DEV_MODULE(name, evh, arg)					\
23921495Sjmacdstatic moduledata_t name##_mod = {					\
24021495Sjmacd    #name,								\
24121495Sjmacd    evh,								\
24221495Sjmacd    arg									\
24321495Sjmacd};									\
24421495SjmacdDECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
24521495Sjmacd
24621495Sjmacd
24721495Sjmacdvoid clone_setup(struct clonedevs **cdp);
24821495Sjmacdvoid clone_cleanup(struct clonedevs **);
24921495Sjmacd#define CLONE_UNITMASK 0xfffff
250146515Sru#define CLONE_FLAG0 (CLONE_UNITMASK + 1)
25121495Sjmacdint clone_create(struct clonedevs **, struct cdevsw *, int *unit, struct cdev **dev, int extra);
25221495Sjmacd
25321495Sjmacdint	count_dev(struct cdev *_dev);
25421495Sjmacdvoid	destroy_dev(struct cdev *_dev);
25521495Sjmacdint	destroy_dev_sched(struct cdev *dev);
25621495Sjmacdint	destroy_dev_sched_cb(struct cdev *dev, void (*cb)(void *), void *arg);
25721495Sjmacdvoid	destroy_dev_drain(struct cdevsw *csw);
25821495Sjmacdvoid	drain_dev_clone_events(void);
25921495Sjmacdstruct cdevsw *dev_refthread(struct cdev *_dev);
26042660Smarkmstruct cdevsw *devvn_refthread(struct vnode *vp, struct cdev **devp);
26142660Smarkmvoid	dev_relthread(struct cdev *_dev);
26221495Sjmacdvoid	dev_depends(struct cdev *_pdev, struct cdev *_cdev);
26321495Sjmacdvoid	dev_ref(struct cdev *dev);
26421495Sjmacdvoid	dev_refl(struct cdev *dev);
26521495Sjmacdvoid	dev_rel(struct cdev *dev);
26642660Smarkmvoid	dev_strategy(struct cdev *dev, struct buf *bp);
26721495Sjmacdstruct cdev *make_dev(struct cdevsw *_devsw, int _unit, uid_t _uid, gid_t _gid,
26821495Sjmacd		int _perms, const char *_fmt, ...) __printflike(6, 7);
26921495Sjmacdstruct cdev *make_dev_cred(struct cdevsw *_devsw, int _unit,
27021495Sjmacd		struct ucred *_cr, uid_t _uid, gid_t _gid, int _perms,
27193139Sru		const char *_fmt, ...) __printflike(7, 8);
27293139Sru#define MAKEDEV_REF     0x1
27393139Sru#define MAKEDEV_WHTOUT	0x2
27493139Srustruct cdev *make_dev_credf(int _flags,
275146515Sru		struct cdevsw *_devsw, int _unit,
27693139Sru		struct ucred *_cr, uid_t _uid, gid_t _gid, int _mode,
27793139Sru		const char *_fmt, ...) __printflike(8, 9);
27893139Srustruct cdev *make_dev_alias(struct cdev *_pdev, const char *_fmt, ...) __printflike(2, 3);
27993139Sruvoid	dev_lock(void);
28093139Sruvoid	dev_unlock(void);
28193139Sruvoid	setconf(void);
28293139Sru
28393139Sru#define	dev2unit(d)	((d)->si_drv0)
28493139Sru
28593139Srutypedef	void (*cdevpriv_dtr_t)(void *data);
28693139Sruint	devfs_get_cdevpriv(void **datap);
28793139Sruint	devfs_set_cdevpriv(void *priv, cdevpriv_dtr_t dtr);
28893139Sruvoid	devfs_clear_cdevpriv(void);
28993139Sruvoid	devfs_fpdrop(struct file *fp);	/* XXX This is not public KPI */
29093139Sru
29193139Sru#define		UID_ROOT	0
29293139Sru#define		UID_BIN		3
29393139Sru#define		UID_UUCP	66
29493139Sru#define		UID_NOBODY	65534
29593139Sru
29693139Sru#define		GID_WHEEL	0
29793139Sru#define		GID_KMEM	2
29893139Sru#define		GID_TTY		4
29993139Sru#define		GID_OPERATOR	5
30093139Sru#define		GID_BIN		7
30193139Sru#define		GID_GAMES	13
30293139Sru#define		GID_DIALER	68
30393139Sru#define		GID_NOBODY	65534
30493139Sru
30593139Srutypedef void (*dev_clone_fn)(void *arg, struct ucred *cred, char *name,
306	    int namelen, struct cdev **result);
307
308int dev_stdclone(char *_name, char **_namep, const char *_stem, int *_unit);
309EVENTHANDLER_DECLARE(dev_clone, dev_clone_fn);
310
311/* Stuff relating to kernel-dump */
312
313struct dumperinfo {
314	dumper_t *dumper;	/* Dumping function. */
315	void    *priv;		/* Private parts. */
316	u_int   blocksize;	/* Size of block in bytes. */
317	u_int	maxiosize;	/* Max size allowed for an individual I/O */
318	off_t   mediaoffset;	/* Initial offset in bytes. */
319	off_t   mediasize;	/* Space available in bytes. */
320};
321
322int set_dumper(struct dumperinfo *);
323int dump_write(struct dumperinfo *, void *, vm_offset_t, off_t, size_t);
324void dumpsys(struct dumperinfo *);
325extern int dumping;		/* system is dumping */
326
327#endif /* _KERNEL */
328
329#endif /* !_SYS_CONF_H_ */
330