xref: /minix/sys/sys/conf.h (revision 0a6a1f1d)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: conf.h,v 1.145 2014/07/25 07:56:14 dholland Exp $	*/
26c8f7fc3SBen Gras 
36c8f7fc3SBen Gras /*-
46c8f7fc3SBen Gras  * Copyright (c) 1990, 1993
56c8f7fc3SBen Gras  *	The Regents of the University of California.  All rights reserved.
66c8f7fc3SBen Gras  * (c) UNIX System Laboratories, Inc.
76c8f7fc3SBen Gras  * All or some portions of this file are derived from material licensed
86c8f7fc3SBen Gras  * to the University of California by American Telephone and Telegraph
96c8f7fc3SBen Gras  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
106c8f7fc3SBen Gras  * the permission of UNIX System Laboratories, Inc.
116c8f7fc3SBen Gras  *
126c8f7fc3SBen Gras  * Redistribution and use in source and binary forms, with or without
136c8f7fc3SBen Gras  * modification, are permitted provided that the following conditions
146c8f7fc3SBen Gras  * are met:
156c8f7fc3SBen Gras  * 1. Redistributions of source code must retain the above copyright
166c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer.
176c8f7fc3SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
186c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer in the
196c8f7fc3SBen Gras  *    documentation and/or other materials provided with the distribution.
206c8f7fc3SBen Gras  * 3. Neither the name of the University nor the names of its contributors
216c8f7fc3SBen Gras  *    may be used to endorse or promote products derived from this software
226c8f7fc3SBen Gras  *    without specific prior written permission.
236c8f7fc3SBen Gras  *
246c8f7fc3SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
256c8f7fc3SBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
266c8f7fc3SBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
276c8f7fc3SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
286c8f7fc3SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
296c8f7fc3SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
306c8f7fc3SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
316c8f7fc3SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
326c8f7fc3SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
336c8f7fc3SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
346c8f7fc3SBen Gras  * SUCH DAMAGE.
356c8f7fc3SBen Gras  *
366c8f7fc3SBen Gras  *	@(#)conf.h	8.5 (Berkeley) 1/9/95
376c8f7fc3SBen Gras  */
386c8f7fc3SBen Gras 
396c8f7fc3SBen Gras #ifndef _SYS_CONF_H_
406c8f7fc3SBen Gras #define _SYS_CONF_H_
416c8f7fc3SBen Gras 
426c8f7fc3SBen Gras /*
436c8f7fc3SBen Gras  * Definitions of device driver entry switches
446c8f7fc3SBen Gras  */
456c8f7fc3SBen Gras 
466c8f7fc3SBen Gras #include <sys/queue.h>
4784d9c625SLionel Sambuc #include <sys/device_if.h>
486c8f7fc3SBen Gras 
496c8f7fc3SBen Gras struct buf;
506c8f7fc3SBen Gras struct knote;
516c8f7fc3SBen Gras struct lwp;
526c8f7fc3SBen Gras struct tty;
536c8f7fc3SBen Gras struct uio;
546c8f7fc3SBen Gras struct vnode;
556c8f7fc3SBen Gras 
566c8f7fc3SBen Gras /*
576c8f7fc3SBen Gras  * Types for d_flag
586c8f7fc3SBen Gras  */
596c8f7fc3SBen Gras #define D_OTHER		0x0000
606c8f7fc3SBen Gras #define	D_TAPE		0x0001
616c8f7fc3SBen Gras #define	D_DISK		0x0002
626c8f7fc3SBen Gras #define	D_TTY		0x0003
636c8f7fc3SBen Gras #define	D_TYPEMASK	0x00ff
646c8f7fc3SBen Gras #define	D_MPSAFE	0x0100
656c8f7fc3SBen Gras #define	D_NEGOFFSAFE	0x0200
666c8f7fc3SBen Gras 
676c8f7fc3SBen Gras /*
686c8f7fc3SBen Gras  * Block device switch table
696c8f7fc3SBen Gras  */
706c8f7fc3SBen Gras struct bdevsw {
716c8f7fc3SBen Gras 	int		(*d_open)(dev_t, int, int, struct lwp *);
726c8f7fc3SBen Gras 	int		(*d_close)(dev_t, int, int, struct lwp *);
736c8f7fc3SBen Gras 	void		(*d_strategy)(struct buf *);
746c8f7fc3SBen Gras 	int		(*d_ioctl)(dev_t, u_long, void *, int, struct lwp *);
756c8f7fc3SBen Gras 	int		(*d_dump)(dev_t, daddr_t, void *, size_t);
766c8f7fc3SBen Gras 	int		(*d_psize)(dev_t);
77*0a6a1f1dSLionel Sambuc 	int		(*d_discard)(dev_t, off_t, off_t);
786c8f7fc3SBen Gras 	int		d_flag;
796c8f7fc3SBen Gras };
806c8f7fc3SBen Gras 
816c8f7fc3SBen Gras /*
826c8f7fc3SBen Gras  * Character device switch table
836c8f7fc3SBen Gras  */
846c8f7fc3SBen Gras struct cdevsw {
856c8f7fc3SBen Gras 	int		(*d_open)(dev_t, int, int, struct lwp *);
866c8f7fc3SBen Gras 	int		(*d_close)(dev_t, int, int, struct lwp *);
876c8f7fc3SBen Gras 	int		(*d_read)(dev_t, struct uio *, int);
886c8f7fc3SBen Gras 	int		(*d_write)(dev_t, struct uio *, int);
896c8f7fc3SBen Gras 	int		(*d_ioctl)(dev_t, u_long, void *, int, struct lwp *);
906c8f7fc3SBen Gras 	void		(*d_stop)(struct tty *, int);
916c8f7fc3SBen Gras 	struct tty *	(*d_tty)(dev_t);
926c8f7fc3SBen Gras 	int		(*d_poll)(dev_t, int, struct lwp *);
936c8f7fc3SBen Gras 	paddr_t		(*d_mmap)(dev_t, off_t, int);
946c8f7fc3SBen Gras 	int		(*d_kqfilter)(dev_t, struct knote *);
95*0a6a1f1dSLionel Sambuc 	int		(*d_discard)(dev_t, off_t, off_t);
966c8f7fc3SBen Gras 	int		d_flag;
976c8f7fc3SBen Gras };
986c8f7fc3SBen Gras 
996c8f7fc3SBen Gras #ifdef _KERNEL
1006c8f7fc3SBen Gras 
1016c8f7fc3SBen Gras #include <sys/mutex.h>
1026c8f7fc3SBen Gras extern kmutex_t device_lock;
1036c8f7fc3SBen Gras 
1046c8f7fc3SBen Gras int devsw_attach(const char *, const struct bdevsw *, devmajor_t *,
1056c8f7fc3SBen Gras 		 const struct cdevsw *, devmajor_t *);
1066c8f7fc3SBen Gras int devsw_detach(const struct bdevsw *, const struct cdevsw *);
1076c8f7fc3SBen Gras const struct bdevsw *bdevsw_lookup(dev_t);
1086c8f7fc3SBen Gras const struct cdevsw *cdevsw_lookup(dev_t);
1096c8f7fc3SBen Gras devmajor_t bdevsw_lookup_major(const struct bdevsw *);
1106c8f7fc3SBen Gras devmajor_t cdevsw_lookup_major(const struct cdevsw *);
1116c8f7fc3SBen Gras 
1126c8f7fc3SBen Gras #define	dev_type_open(n)	int n (dev_t, int, int, struct lwp *)
1136c8f7fc3SBen Gras #define	dev_type_close(n)	int n (dev_t, int, int, struct lwp *)
1146c8f7fc3SBen Gras #define	dev_type_read(n)	int n (dev_t, struct uio *, int)
1156c8f7fc3SBen Gras #define	dev_type_write(n)	int n (dev_t, struct uio *, int)
1166c8f7fc3SBen Gras #define	dev_type_ioctl(n) \
1176c8f7fc3SBen Gras 		int n (dev_t, u_long, void *, int, struct lwp *)
1186c8f7fc3SBen Gras #define	dev_type_stop(n)	void n (struct tty *, int)
1196c8f7fc3SBen Gras #define	dev_type_tty(n)		struct tty * n (dev_t)
1206c8f7fc3SBen Gras #define	dev_type_poll(n)	int n (dev_t, int, struct lwp *)
1216c8f7fc3SBen Gras #define	dev_type_mmap(n)	paddr_t n (dev_t, off_t, int)
1226c8f7fc3SBen Gras #define	dev_type_strategy(n)	void n (struct buf *)
1236c8f7fc3SBen Gras #define	dev_type_dump(n)	int n (dev_t, daddr_t, void *, size_t)
1246c8f7fc3SBen Gras #define	dev_type_size(n)	int n (dev_t)
1256c8f7fc3SBen Gras #define	dev_type_kqfilter(n)	int n (dev_t, struct knote *)
126*0a6a1f1dSLionel Sambuc #define dev_type_discard(n)	int n (dev_t, off_t, off_t)
1276c8f7fc3SBen Gras 
1286c8f7fc3SBen Gras #define	noopen		((dev_type_open((*)))enodev)
1296c8f7fc3SBen Gras #define	noclose		((dev_type_close((*)))enodev)
1306c8f7fc3SBen Gras #define	noread		((dev_type_read((*)))enodev)
1316c8f7fc3SBen Gras #define	nowrite		((dev_type_write((*)))enodev)
1326c8f7fc3SBen Gras #define	noioctl		((dev_type_ioctl((*)))enodev)
1336c8f7fc3SBen Gras #define	nostop		((dev_type_stop((*)))enodev)
1346c8f7fc3SBen Gras #define	notty		NULL
1356c8f7fc3SBen Gras #define	nopoll		seltrue
1366c8f7fc3SBen Gras #define	nommap		((dev_type_mmap((*)))enodev)
1376c8f7fc3SBen Gras #define	nodump		((dev_type_dump((*)))enodev)
1386c8f7fc3SBen Gras #define	nosize		NULL
1396c8f7fc3SBen Gras #define	nokqfilter	seltrue_kqfilter
140*0a6a1f1dSLionel Sambuc #define nodiscard	((dev_type_discard((*)))enodev)
1416c8f7fc3SBen Gras 
1426c8f7fc3SBen Gras #define	nullopen	((dev_type_open((*)))nullop)
1436c8f7fc3SBen Gras #define	nullclose	((dev_type_close((*)))nullop)
1446c8f7fc3SBen Gras #define	nullread	((dev_type_read((*)))nullop)
1456c8f7fc3SBen Gras #define	nullwrite	((dev_type_write((*)))nullop)
1466c8f7fc3SBen Gras #define	nullioctl	((dev_type_ioctl((*)))nullop)
1476c8f7fc3SBen Gras #define	nullstop	((dev_type_stop((*)))nullop)
1486c8f7fc3SBen Gras #define	nullpoll	((dev_type_poll((*)))nullop)
1496c8f7fc3SBen Gras #define	nullmmap	((dev_type_mmap((*)))nullop)
1506c8f7fc3SBen Gras #define	nulldump	((dev_type_dump((*)))nullop)
1516c8f7fc3SBen Gras #define	nullkqfilter	((dev_type_kqfilter((*)))eopnotsupp)
152*0a6a1f1dSLionel Sambuc #define nulldiscard	((dev_type_discard((*)))nullop)
1536c8f7fc3SBen Gras 
1546c8f7fc3SBen Gras /* device access wrappers. */
1556c8f7fc3SBen Gras 
1566c8f7fc3SBen Gras dev_type_open(bdev_open);
1576c8f7fc3SBen Gras dev_type_close(bdev_close);
1586c8f7fc3SBen Gras dev_type_strategy(bdev_strategy);
1596c8f7fc3SBen Gras dev_type_ioctl(bdev_ioctl);
1606c8f7fc3SBen Gras dev_type_dump(bdev_dump);
1616c8f7fc3SBen Gras dev_type_size(bdev_size);
162*0a6a1f1dSLionel Sambuc dev_type_discard(bdev_discard);
1636c8f7fc3SBen Gras 
1646c8f7fc3SBen Gras dev_type_open(cdev_open);
1656c8f7fc3SBen Gras dev_type_close(cdev_close);
1666c8f7fc3SBen Gras dev_type_read(cdev_read);
1676c8f7fc3SBen Gras dev_type_write(cdev_write);
1686c8f7fc3SBen Gras dev_type_ioctl(cdev_ioctl);
1696c8f7fc3SBen Gras dev_type_stop(cdev_stop);
1706c8f7fc3SBen Gras dev_type_tty(cdev_tty);
1716c8f7fc3SBen Gras dev_type_poll(cdev_poll);
1726c8f7fc3SBen Gras dev_type_mmap(cdev_mmap);
1736c8f7fc3SBen Gras dev_type_kqfilter(cdev_kqfilter);
174*0a6a1f1dSLionel Sambuc dev_type_discard(cdev_discard);
1756c8f7fc3SBen Gras 
1766c8f7fc3SBen Gras int	cdev_type(dev_t);
1776c8f7fc3SBen Gras int	bdev_type(dev_t);
1786c8f7fc3SBen Gras 
1796c8f7fc3SBen Gras /* symbolic sleep message strings */
1806c8f7fc3SBen Gras extern	const char devopn[], devio[], devwait[], devin[], devout[];
1816c8f7fc3SBen Gras extern	const char devioc[], devcls[];
1826c8f7fc3SBen Gras 
1836c8f7fc3SBen Gras #endif /* _KERNEL */
1846c8f7fc3SBen Gras 
1856c8f7fc3SBen Gras /*
1866c8f7fc3SBen Gras  * Line discipline switch table
1876c8f7fc3SBen Gras  */
1886c8f7fc3SBen Gras struct linesw {
1896c8f7fc3SBen Gras 	const char *l_name;	/* Linesw name */
1906c8f7fc3SBen Gras 
1916c8f7fc3SBen Gras 	LIST_ENTRY(linesw) l_list;
1926c8f7fc3SBen Gras 	u_int	l_refcnt;	/* locked by ttyldisc_list_slock */
1936c8f7fc3SBen Gras 	int	l_no;		/* legacy discipline number (for TIOCGETD) */
1946c8f7fc3SBen Gras 
1956c8f7fc3SBen Gras 	int	(*l_open)	(dev_t, struct tty *);
1966c8f7fc3SBen Gras 	int	(*l_close)	(struct tty *, int);
1976c8f7fc3SBen Gras 	int	(*l_read)	(struct tty *, struct uio *, int);
1986c8f7fc3SBen Gras 	int	(*l_write)	(struct tty *, struct uio *, int);
1996c8f7fc3SBen Gras 	int	(*l_ioctl)	(struct tty *, u_long, void *, int,
2006c8f7fc3SBen Gras 				    struct lwp *);
2016c8f7fc3SBen Gras 	int	(*l_rint)	(int, struct tty *);
2026c8f7fc3SBen Gras 	int	(*l_start)	(struct tty *);
2036c8f7fc3SBen Gras 	int	(*l_modem)	(struct tty *, int);
2046c8f7fc3SBen Gras 	int	(*l_poll)	(struct tty *, int, struct lwp *);
2056c8f7fc3SBen Gras };
2066c8f7fc3SBen Gras 
2076c8f7fc3SBen Gras #ifdef _KERNEL
2086c8f7fc3SBen Gras void	       ttyldisc_init(void);
2096c8f7fc3SBen Gras int	       ttyldisc_attach(struct linesw *);
2106c8f7fc3SBen Gras int	       ttyldisc_detach(struct linesw *);
2116c8f7fc3SBen Gras struct linesw *ttyldisc_lookup(const char *);
2126c8f7fc3SBen Gras struct linesw *ttyldisc_lookup_bynum(int);
2136c8f7fc3SBen Gras struct linesw *ttyldisc_default(void);
2146c8f7fc3SBen Gras void	       ttyldisc_release(struct linesw *);
2156c8f7fc3SBen Gras 
2166c8f7fc3SBen Gras /* For those defining their own line disciplines: */
2176c8f7fc3SBen Gras #define	ttynodisc ((int (*)(dev_t, struct tty *))enodev)
2186c8f7fc3SBen Gras #define	ttyerrclose ((int (*)(struct tty *, int))enodev)
2196c8f7fc3SBen Gras #define	ttyerrio ((int (*)(struct tty *, struct uio *, int))enodev)
2206c8f7fc3SBen Gras #define	ttyerrinput ((int (*)(int, struct tty *))enodev)
2216c8f7fc3SBen Gras #define	ttyerrstart ((int (*)(struct tty *))enodev)
2226c8f7fc3SBen Gras 
2236c8f7fc3SBen Gras int	ttyerrpoll (struct tty *, int, struct lwp *);
2246c8f7fc3SBen Gras int	ttynullioctl(struct tty *, u_long, void *, int, struct lwp *);
2256c8f7fc3SBen Gras 
2266c8f7fc3SBen Gras int	iskmemdev(dev_t);
2276c8f7fc3SBen Gras int	seltrue_kqfilter(dev_t, struct knote *);
2286c8f7fc3SBen Gras #endif
2296c8f7fc3SBen Gras 
2306c8f7fc3SBen Gras #ifdef _KERNEL
2316c8f7fc3SBen Gras 
2326c8f7fc3SBen Gras #define	DEV_MEM		0	/* minor device 0 is physical memory */
2336c8f7fc3SBen Gras #define	DEV_KMEM	1	/* minor device 1 is kernel memory */
2346c8f7fc3SBen Gras #define	DEV_NULL	2	/* minor device 2 is EOF/rathole */
2356c8f7fc3SBen Gras #ifdef COMPAT_16
2366c8f7fc3SBen Gras #define	_DEV_ZERO_oARM	3	/* reserved: old ARM /dev/zero minor */
2376c8f7fc3SBen Gras #endif
2386c8f7fc3SBen Gras #define	DEV_ZERO	12	/* minor device 12 is '\0'/rathole */
2396c8f7fc3SBen Gras 
2406c8f7fc3SBen Gras enum devnode_class {
2416c8f7fc3SBen Gras 	DEVNODE_DONTBOTHER,
2426c8f7fc3SBen Gras 	DEVNODE_SINGLE,
2436c8f7fc3SBen Gras 	DEVNODE_VECTOR,
2446c8f7fc3SBen Gras };
2456c8f7fc3SBen Gras #define DEVNODE_FLAG_LINKZERO	0x01	/* create name -> name0 link */
2466c8f7fc3SBen Gras #define DEVNODE_FLAG_ISMINOR0	0x02	/* vector[0] specifies minor */
2476c8f7fc3SBen Gras #ifdef notyet
2486c8f7fc3SBen Gras #define DEVNODE_FLAG_ISMINOR1	0x04	/* vector[1] specifies starting minor */
2496c8f7fc3SBen Gras #endif
2506c8f7fc3SBen Gras 
2516c8f7fc3SBen Gras struct devsw_conv {
2526c8f7fc3SBen Gras 	const char *d_name;
2536c8f7fc3SBen Gras 	devmajor_t d_bmajor;
2546c8f7fc3SBen Gras 	devmajor_t d_cmajor;
2556c8f7fc3SBen Gras 
2566c8f7fc3SBen Gras 	/* information about /dev nodes related to the device */
2576c8f7fc3SBen Gras 	enum devnode_class d_class;
2586c8f7fc3SBen Gras 	int d_flags;
2596c8f7fc3SBen Gras 	int d_vectdim[2];
2606c8f7fc3SBen Gras };
2616c8f7fc3SBen Gras 
2626c8f7fc3SBen Gras void devsw_init(void);
2636c8f7fc3SBen Gras const char *devsw_blk2name(devmajor_t);
2646c8f7fc3SBen Gras const char *cdevsw_getname(devmajor_t);
2656c8f7fc3SBen Gras const char *bdevsw_getname(devmajor_t);
2666c8f7fc3SBen Gras devmajor_t devsw_name2blk(const char *, char *, size_t);
2676c8f7fc3SBen Gras devmajor_t devsw_name2chr(const char *, char *, size_t);
2686c8f7fc3SBen Gras dev_t devsw_chr2blk(dev_t);
2696c8f7fc3SBen Gras dev_t devsw_blk2chr(dev_t);
2706c8f7fc3SBen Gras 
2716c8f7fc3SBen Gras void mm_init(void);
2726c8f7fc3SBen Gras #endif /* _KERNEL */
2736c8f7fc3SBen Gras 
2746c8f7fc3SBen Gras #ifdef _KERNEL
27584d9c625SLionel Sambuc void	setroot(device_t, int);
2766c8f7fc3SBen Gras void	rootconf(void);
2776c8f7fc3SBen Gras void	swapconf(void);
2786c8f7fc3SBen Gras #endif /* _KERNEL */
2796c8f7fc3SBen Gras 
2806c8f7fc3SBen Gras #endif /* !_SYS_CONF_H_ */
281