1 /* $NetBSD: conf.h,v 1.107 2002/10/26 13:50:18 jdolecek Exp $ */ 2 3 /*- 4 * Copyright (c) 1990, 1993 5 * The Regents of the University of California. All rights reserved. 6 * (c) UNIX System Laboratories, Inc. 7 * All or some portions of this file are derived from material licensed 8 * to the University of California by American Telephone and Telegraph 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * the permission of UNIX System Laboratories, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the University of 23 * California, Berkeley and its contributors. 24 * 4. Neither the name of the University nor the names of its contributors 25 * may be used to endorse or promote products derived from this software 26 * without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 38 * SUCH DAMAGE. 39 * 40 * @(#)conf.h 8.5 (Berkeley) 1/9/95 41 */ 42 43 #ifndef _SYS_CONF_H_ 44 #define _SYS_CONF_H_ 45 46 /* 47 * Definitions of device driver entry switches 48 */ 49 50 struct buf; 51 struct knote; 52 struct proc; 53 struct tty; 54 struct uio; 55 struct vnode; 56 57 /* 58 * Types for d_type 59 */ 60 #define D_TAPE 1 61 #define D_DISK 2 62 #define D_TTY 3 63 64 /* 65 * Block device switch table 66 */ 67 struct bdevsw { 68 int (*d_open)(dev_t, int, int, struct proc *); 69 int (*d_close)(dev_t, int, int, struct proc *); 70 void (*d_strategy)(struct buf *); 71 int (*d_ioctl)(dev_t, u_long, caddr_t, int, struct proc *); 72 int (*d_dump)(dev_t, daddr_t, caddr_t, size_t); 73 int (*d_psize)(dev_t); 74 int d_type; 75 }; 76 77 /* 78 * Character device switch table 79 */ 80 struct cdevsw { 81 int (*d_open)(dev_t, int, int, struct proc *); 82 int (*d_close)(dev_t, int, int, struct proc *); 83 int (*d_read)(dev_t, struct uio *, int); 84 int (*d_write)(dev_t, struct uio *, int); 85 int (*d_ioctl)(dev_t, u_long, caddr_t, int, struct proc *); 86 void (*d_stop)(struct tty *, int); 87 struct tty * (*d_tty)(dev_t); 88 int (*d_poll)(dev_t, int, struct proc *); 89 paddr_t (*d_mmap)(dev_t, off_t, int); 90 int (*d_kqfilter)(dev_t dev, struct knote *kn); 91 int d_type; 92 }; 93 94 #ifdef _KERNEL 95 96 int devsw_attach(const char *, const struct bdevsw *, int *, 97 const struct cdevsw *, int *); 98 void devsw_detach(const struct bdevsw *, const struct cdevsw *); 99 const struct bdevsw *bdevsw_lookup(dev_t); 100 const struct cdevsw *cdevsw_lookup(dev_t); 101 int bdevsw_lookup_major(const struct bdevsw *); 102 int cdevsw_lookup_major(const struct cdevsw *); 103 104 #define dev_type_open(n) int n (dev_t, int, int, struct proc *) 105 #define dev_type_close(n) int n (dev_t, int, int, struct proc *) 106 #define dev_type_read(n) int n (dev_t, struct uio *, int) 107 #define dev_type_write(n) int n (dev_t, struct uio *, int) 108 #define dev_type_ioctl(n) \ 109 int n (dev_t, u_long, caddr_t, int, struct proc *) 110 #define dev_type_stop(n) void n (struct tty *, int) 111 #define dev_type_tty(n) struct tty * n (dev_t) 112 #define dev_type_poll(n) int n (dev_t, int, struct proc *) 113 #define dev_type_mmap(n) paddr_t n (dev_t, off_t, int) 114 #define dev_type_strategy(n) void n (struct buf *) 115 #define dev_type_dump(n) int n (dev_t, daddr_t, caddr_t, size_t) 116 #define dev_type_size(n) int n (dev_t) 117 #define dev_type_kqfilter(n) int n (dev_t, struct knote *) 118 119 #define noopen ((dev_type_open((*)))enodev) 120 #define noclose ((dev_type_close((*)))enodev) 121 #define noread ((dev_type_read((*)))enodev) 122 #define nowrite ((dev_type_write((*)))enodev) 123 #define noioctl ((dev_type_ioctl((*)))enodev) 124 #define nostop ((dev_type_stop((*)))enodev) 125 #define notty NULL 126 #define nopoll seltrue 127 #define nommap ((dev_type_mmap((*)))enodev) 128 #define nodump ((dev_type_dump((*)))enodev) 129 #define nosize NULL 130 #define nokqfilter seltrue_kqfilter 131 132 #define nullopen ((dev_type_open((*)))nullop) 133 #define nullclose ((dev_type_close((*)))nullop) 134 #define nullread ((dev_type_read((*)))nullop) 135 #define nullwrite ((dev_type_write((*)))nullop) 136 #define nullioctl ((dev_type_ioctl((*)))nullop) 137 #define nullstop ((dev_type_stop((*)))nullop) 138 #define nullpoll ((dev_type_poll((*)))nullop) 139 #define nullmmap ((dev_type_mmap((*)))nullop) 140 #define nulldump ((dev_type_dump((*)))nullop) 141 #define nullkqfilter ((dev_type_kqfilter((*)))eopnotsupp) 142 143 /* symbolic sleep message strings */ 144 extern const char devopn[], devio[], devwait[], devin[], devout[]; 145 extern const char devioc[], devcls[]; 146 147 #endif /* _KERNEL */ 148 149 /* 150 * Line discipline switch table 151 */ 152 struct linesw { 153 char *l_name; /* Linesw name */ 154 int l_no; /* Linesw number (compatibility) */ 155 156 int (*l_open) __P((dev_t dev, struct tty *tp)); 157 int (*l_close) __P((struct tty *tp, int flags)); 158 int (*l_read) __P((struct tty *tp, struct uio *uio, 159 int flag)); 160 int (*l_write) __P((struct tty *tp, struct uio *uio, 161 int flag)); 162 int (*l_ioctl) __P((struct tty *tp, u_long cmd, caddr_t data, 163 int flag, struct proc *p)); 164 int (*l_rint) __P((int c, struct tty *tp)); 165 int (*l_start) __P((struct tty *tp)); 166 int (*l_modem) __P((struct tty *tp, int flag)); 167 int (*l_poll) __P((struct tty *tp, int events, 168 struct proc *p)); 169 }; 170 171 #ifdef _KERNEL 172 extern struct linesw **linesw; 173 extern int nlinesw; 174 extern void ttyldisc_init __P((void)); 175 int ttyldisc_add __P((struct linesw *disc, int no)); 176 struct linesw *ttyldisc_remove __P((char *name)); 177 struct linesw *ttyldisc_lookup __P((char *name)); 178 179 /* For those defining their own line disciplines: */ 180 #define ttynodisc ((int (*) __P((dev_t, struct tty *)))enodev) 181 #define ttyerrclose ((int (*) __P((struct tty *, int flags)))enodev) 182 #define ttyerrio ((int (*) __P((struct tty *, struct uio *, int)))enodev) 183 #define ttyerrinput ((int (*) __P((int c, struct tty *)))enodev) 184 #define ttyerrstart ((int (*) __P((struct tty *)))enodev) 185 #define ttyerrpoll ((int (*) __P((struct tty *, int, struct proc *)))enodev) 186 187 int ttynullioctl __P((struct tty *, u_long, caddr_t, int, struct proc *)); 188 #endif 189 190 /* 191 * Swap device table 192 */ 193 struct swdevt { 194 dev_t sw_dev; 195 int sw_flags; 196 int sw_nblks; 197 struct vnode *sw_vp; 198 }; 199 #define SW_FREED 0x01 200 #define SW_SEQUENTIAL 0x02 201 #define sw_freed sw_flags /* XXX compat */ 202 203 #ifdef _KERNEL 204 extern struct swdevt swdevt[]; 205 206 #define DEV_MEM 0 /* minor device 0 is physical memory */ 207 #define DEV_KMEM 1 /* minor device 1 is kernel memory */ 208 #define DEV_NULL 2 /* minor device 2 is EOF/rathole */ 209 #ifdef __arm__ /* XXX: FIX ME ARM! */ 210 #define DEV_ZERO 3 /* minor device 3 is '\0'/rathole */ 211 #else 212 #define DEV_ZERO 12 /* minor device 12 is '\0'/rathole */ 213 #endif 214 215 #endif /* _KERNEL */ 216 217 struct devsw_conv { 218 const char *d_name; 219 int d_bmajor; 220 int d_cmajor; 221 }; 222 223 #ifdef _KERNEL 224 const char *devsw_blk2name(int); 225 int devsw_name2blk(const char *, char *, size_t); 226 dev_t devsw_chr2blk(dev_t); 227 dev_t devsw_blk2chr(dev_t); 228 #endif /* _KERNEL */ 229 230 #ifdef _KERNEL 231 struct device; 232 void setroot __P((struct device *, int)); 233 void swapconf __P((void)); 234 #endif /* _KERNEL */ 235 236 #endif /* !_SYS_CONF_H_ */ 237