1 /* 2 * Copyright (c) 1992 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This software was developed by the Computer Systems Engineering group 6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7 * contributed to Berkeley. 8 * 9 * All advertising materials mentioning features or use of this software 10 * must display the following acknowledgement: 11 * This product includes software developed by the University of 12 * California, Lawrence Berkeley Laboratory. 13 * 14 * %sccs.include.redist.c% 15 * 16 * @(#)conf.c 7.4 (Berkeley) 04/20/93 17 * 18 * from: $Header: conf.c,v 1.14 92/11/26 03:04:49 torek Exp $ (LBL) 19 */ 20 21 #include <sys/param.h> 22 #include <sys/systm.h> 23 #include <sys/buf.h> 24 #include <sys/ioctl.h> 25 #include <sys/tty.h> 26 #include <sys/conf.h> 27 28 int rawread __P((dev_t, struct uio *, int)); 29 int rawwrite __P((dev_t, struct uio *, int)); 30 int swstrategy __P((struct buf *)); 31 int ttselect __P((dev_t, int, struct proc *)); 32 33 #define dev_type_open(n) int n __P((dev_t, int, int, struct proc *)) 34 #define dev_type_close(n) int n __P((dev_t, int, int, struct proc *)) 35 #define dev_type_strategy(n) int n __P((struct buf *)) 36 #define dev_type_ioctl(n) \ 37 int n __P((dev_t, int, caddr_t, int, struct proc *)) 38 39 /* bdevsw-specific types */ 40 /* dev_type_dump(n) int n __P((dev_t, daddr_t, caddr_t, int))*/ 41 #define dev_type_dump(n) int n () 42 #define dev_type_size(n) int n __P((dev_t)) 43 44 /* error/nullop functions */ 45 #define error_open ((dev_type_open((*))) enodev) 46 #define error_close ((dev_type_close((*))) enodev) 47 #define error_ioctl ((dev_type_ioctl((*))) enodev) 48 #define error_dump ((dev_type_dump((*))) enodev) 49 50 #define null_open ((dev_type_open((*))) nullop) 51 #define null_close ((dev_type_close((*))) nullop) 52 53 #define dev_decl(n,t) __CONCAT(dev_type_,t)(__CONCAT(n,t)) 54 #define dev_init(c,n,t) \ 55 (c > 0 ? __CONCAT(n,t) : (__CONCAT(dev_type_,t)((*))) enxio) 56 57 /* bdevsw-specific initializations */ 58 #define dev_size_init(c,n) (c > 0 ? __CONCAT(n,size) : 0) 59 60 #define bdev_decl(n) \ 61 dev_decl(n,open); dev_decl(n,close); dev_decl(n,strategy); \ 62 dev_decl(n,ioctl); dev_decl(n,dump); dev_decl(n,size) 63 64 #define bdev_disk_init(c,n) { \ 65 dev_init(c,n,open), dev_init(c,n,close), \ 66 dev_init(c,n,strategy), dev_init(c,n,ioctl), \ 67 dev_init(c,n,dump), dev_size_init(c,n), 0 } 68 69 #define bdev_tape_init(c,n) { \ 70 dev_init(c,n,open), dev_init(c,n,close), \ 71 dev_init(c,n,strategy), dev_init(c,n,ioctl), \ 72 dev_init(c,n,dump), 0, B_TAPE } 73 74 #define bdev_swap_init() { \ 75 error_open, error_close, swstrategy, error_ioctl, error_dump, 0, 0 } 76 77 #define bdev_notdef() bdev_tape_init(0,no) 78 bdev_decl(no); /* dummy declarations */ 79 80 #include "sd.h" 81 82 bdev_decl(sd); 83 84 struct bdevsw bdevsw[] = 85 { 86 bdev_notdef(), /* 0 */ 87 bdev_notdef(), /* 1 */ 88 bdev_notdef(), /* 2 */ 89 bdev_swap_init(), /* 3 */ 90 bdev_notdef(), /* 4 */ 91 bdev_notdef(), /* 5 */ 92 bdev_notdef(), /* 6 */ 93 bdev_disk_init(NSD,sd), /* 7: scsi disk */ 94 }; 95 96 int nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]); 97 98 /* cdevsw-specific types */ 99 #define dev_type_read(n) int n __P((dev_t, struct uio *, int)) 100 #define dev_type_write(n) int n __P((dev_t, struct uio *, int)) 101 #define dev_type_select(n) int n __P((dev_t, int, struct proc *)) 102 #define dev_type_map(n) int n __P(()) 103 104 #define error_read ((dev_type_read((*))) enodev) 105 #define error_write ((dev_type_write((*))) enodev) 106 #define error_select ((dev_type_select((*))) enodev) 107 108 #define cdev_decl(n) \ 109 dev_decl(n,open); dev_decl(n,close); dev_decl(n,read); \ 110 dev_decl(n,write); dev_decl(n,ioctl); dev_decl(n,select); \ 111 dev_decl(n,map); dev_decl(n,strategy); \ 112 extern struct tty __CONCAT(n,_tty)[] 113 114 #define dev_tty_init(c,n) (c > 0 ? __CONCAT(n,_tty) : 0) 115 116 /* open, close, read, write, ioctl, strategy */ 117 #define cdev_disk_init(c,n) { \ 118 dev_init(c,n,open), dev_init(c,n,close), rawread, rawwrite, \ 119 dev_init(c,n,ioctl), 0, 0, 0, seltrue, 0, dev_init(c,n,strategy) } 120 121 /* open, close, read, write, ioctl, strategy */ 122 #define cdev_tape_init(c,n) { \ 123 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 124 dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, 0, seltrue, 0, \ 125 dev_init(c,n,strategy) } 126 127 /* open, close, read, write, ioctl, tty */ 128 #define cdev_tty_init(c,n) { \ 129 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 130 dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, dev_tty_init(c,n), \ 131 ttselect, 0, 0 } 132 133 /* open, close, read, write, ioctl, select */ 134 #define cdev_gen_init(c,n) { \ 135 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 136 dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, 0, \ 137 dev_init(c,n,select), 0, 0 } 138 139 /* open, close, ioctl, mmap */ 140 #define cdev_fb_init(c,n) { \ 141 dev_init(c,n,open), dev_init(c,n,close), error_read, error_write, \ 142 dev_init(c,n,ioctl), 0, 0, 0, seltrue, dev_init(c,n,map), 0 } 143 144 #define cdev_notdef() { \ 145 error_open, error_close, error_read, error_write, \ 146 error_ioctl, 0, 0, 0, seltrue, 0, 0 } 147 148 cdev_decl(no); /* dummy declarations */ 149 150 cdev_decl(cn); 151 /* open, close, read, write, ioctl, select -- XXX should be a tty */ 152 extern struct tty cons; 153 #define cdev_cn_init(c,n) { \ 154 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 155 dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, &cons, \ 156 dev_init(c,n,select), 0, 0 } 157 158 cdev_decl(ctty); 159 /* open, read, write, ioctl, select -- XXX should be a tty */ 160 #define cdev_ctty_init(c,n) { \ 161 dev_init(c,n,open), null_close, dev_init(c,n,read), \ 162 dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, 0, \ 163 dev_init(c,n,select), 0, 0 } 164 165 dev_type_read(mmrw); 166 /* read/write */ 167 #define cdev_mm_init(c,n) { \ 168 null_open, null_close, mmrw, mmrw, error_ioctl, 0, 0, 0, \ 169 seltrue, 0, 0 } 170 171 /* read, write, strategy */ 172 #define cdev_swap_init(c,n) { \ 173 null_open, null_close, rawread, rawwrite, error_ioctl, 0, 0, 0, \ 174 seltrue, 0, dev_init(c,n,strategy) } 175 176 #include "pty.h" 177 #define pts_tty pt_tty 178 #define ptsioctl ptyioctl 179 cdev_decl(pts); 180 #define ptc_tty pt_tty 181 #define ptcioctl ptyioctl 182 cdev_decl(ptc); 183 184 /* open, close, read, write, ioctl, tty, select */ 185 #define cdev_ptc_init(c,n) { \ 186 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 187 dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, dev_tty_init(c,n), \ 188 dev_init(c,n,select), 0, 0 } 189 190 cdev_decl(log); 191 /* open, close, read, ioctl, select -- XXX should be a generic device */ 192 #define cdev_log_init(c,n) { \ 193 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 194 error_write, dev_init(c,n,ioctl), 0, 0, 0, dev_init(c,n,select), 0, 0 } 195 196 dev_type_open(fdopen); 197 /* open */ 198 #define cdev_fd_init(c,n) { \ 199 dev_init(c,n,open), error_close, error_read, error_write, \ 200 error_ioctl, 0, 0, 0, error_select, 0, 0 } 201 202 #include "zs.h" 203 cdev_decl(zs); 204 205 cdev_decl(kbd); 206 cdev_decl(ms); 207 cdev_decl(fb); 208 209 #include "bwtwo.h" 210 cdev_decl(bwtwo); 211 212 #include "cgthree.h" 213 cdev_decl(cgthree); 214 215 #include "bsdaudio.h" 216 cdev_decl(audio); 217 218 cdev_decl(openprom); 219 /* open, close, ioctl */ 220 #define cdev_openprom_init(c,n) { \ 221 dev_init(c,n,open), dev_init(c,n,close), error_read, error_write, \ 222 dev_init(c,n,ioctl), 0, 0, 0, error_select, 0, 0 } 223 224 #include "bpfilter.h" 225 cdev_decl(bpf); 226 /* open, close, read, write, ioctl, select -- XXX should be generic device */ 227 #define cdev_bpf_init(c,n) { \ 228 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 229 dev_init(c,n,write), dev_init(c,n,ioctl), 0, 0, 0, \ 230 dev_init(c,n,select), 0, 0 } 231 232 /* prototype sun-equivalent cdevsw[] */ 233 struct cdevsw cdevsw[] = 234 { 235 cdev_cn_init(1,cn), /* 0: virtual console */ 236 cdev_notdef(), /* 1 */ 237 cdev_ctty_init(1,ctty), /* 2: controlling terminal */ 238 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */ 239 cdev_notdef(), /* 4 */ 240 cdev_notdef(), /* 5 */ 241 cdev_notdef(), /* 6 */ 242 cdev_swap_init(1,sw), /* 7: /dev/drum (swap pseudo-device) */ 243 cdev_notdef(), /* 8 */ 244 cdev_notdef(), /* 9 */ 245 cdev_notdef(), /* 10 */ 246 cdev_notdef(), /* 11 */ 247 cdev_tty_init(NZS,zs), /* 12: zs serial */ 248 cdev_gen_init(1,ms), /* 13: /dev/mouse */ 249 cdev_notdef(), /* 14 */ 250 cdev_notdef(), /* 15: sun /dev/winNNN */ 251 cdev_log_init(1,log), /* 16: /dev/klog */ 252 cdev_disk_init(NSD,sd), /* 17: scsi disk */ 253 cdev_notdef(), /* 18: should be scsi tape */ 254 cdev_notdef(), /* 19 */ 255 cdev_ptc_init(NPTY,ptc), /* 20: pseudo-tty master */ 256 cdev_tty_init(NPTY,pts), /* 21: pseudo-tty slave */ 257 cdev_fb_init(1,fb), /* 22: /dev/fb indirect driver */ 258 cdev_notdef(), /* 23 */ 259 cdev_fd_init(1,fd), /* 24: /dev/std{in,out,err} */ 260 cdev_notdef(), /* 25 */ 261 cdev_notdef(), /* 26 */ 262 cdev_fb_init(NBWTWO,bwtwo), /* 27: /dev/bwtwo */ 263 cdev_notdef(), /* 28 */ 264 cdev_gen_init(1,kbd), /* 29: /dev/kbd */ 265 cdev_notdef(), /* 30 */ 266 cdev_notdef(), /* 31: should be /dev/cgtwo */ 267 cdev_notdef(), /* 32: should be /dev/gpone */ 268 cdev_notdef(), /* 33 */ 269 cdev_notdef(), /* 34 */ 270 cdev_notdef(), /* 35 */ 271 cdev_notdef(), /* 36 */ 272 cdev_notdef(), /* 37 */ 273 cdev_notdef(), /* 38 */ 274 cdev_notdef(), /* 39 */ 275 cdev_notdef(), /* 40 */ 276 cdev_notdef(), /* 41 */ 277 cdev_notdef(), /* 42 */ 278 cdev_notdef(), /* 43 */ 279 cdev_notdef(), /* 44 */ 280 cdev_notdef(), /* 45 */ 281 cdev_notdef(), /* 46 */ 282 cdev_notdef(), /* 47 */ 283 cdev_notdef(), /* 48 */ 284 cdev_notdef(), /* 49 */ 285 cdev_notdef(), /* 50 */ 286 cdev_notdef(), /* 51 */ 287 cdev_notdef(), /* 52 */ 288 cdev_notdef(), /* 53 */ 289 cdev_notdef(), /* 54 */ 290 cdev_fb_init(NCGTHREE,cgthree), /* 55: /dev/cgthree */ 291 cdev_notdef(), /* 56 */ 292 cdev_notdef(), /* 57 */ 293 cdev_notdef(), /* 58 */ 294 cdev_notdef(), /* 59 */ 295 cdev_notdef(), /* 60 */ 296 cdev_notdef(), /* 61 */ 297 cdev_notdef(), /* 62 */ 298 cdev_notdef(), /* 63 */ 299 cdev_notdef(), /* 64 */ 300 cdev_notdef(), /* 65 */ 301 cdev_notdef(), /* 66 */ 302 cdev_notdef(), /* 67 */ 303 cdev_notdef(), /* 68 */ 304 cdev_gen_init(NBSDAUDIO,audio), /* 69: /dev/audio */ 305 cdev_openprom_init(1,openprom), /* 70: /dev/openprom */ 306 cdev_notdef(), /* 71 */ 307 cdev_notdef(), /* 72 */ 308 cdev_notdef(), /* 73 */ 309 cdev_notdef(), /* 74 */ 310 cdev_notdef(), /* 75 */ 311 cdev_notdef(), /* 76 */ 312 cdev_notdef(), /* 77 */ 313 cdev_notdef(), /* 78 */ 314 cdev_notdef(), /* 79 */ 315 cdev_notdef(), /* 80 */ 316 cdev_notdef(), /* 81 */ 317 cdev_notdef(), /* 82 */ 318 cdev_notdef(), /* 83 */ 319 cdev_notdef(), /* 84 */ 320 cdev_notdef(), /* 85 */ 321 cdev_notdef(), /* 86 */ 322 cdev_notdef(), /* 87 */ 323 cdev_notdef(), /* 88 */ 324 cdev_notdef(), /* 89 */ 325 cdev_notdef(), /* 90 */ 326 cdev_notdef(), /* 91 */ 327 cdev_notdef(), /* 92 */ 328 cdev_notdef(), /* 93 */ 329 cdev_notdef(), /* 94 */ 330 cdev_notdef(), /* 95 */ 331 cdev_notdef(), /* 96 */ 332 cdev_notdef(), /* 97 */ 333 cdev_notdef(), /* 98 */ 334 cdev_notdef(), /* 99 */ 335 cdev_notdef(), /* 100 */ 336 cdev_notdef(), /* 101 */ 337 cdev_notdef(), /* 102 */ 338 cdev_notdef(), /* 103 */ 339 cdev_notdef(), /* 104 */ 340 cdev_bpf_init(NBPFILTER,bpf), /* 105: packet filter */ 341 cdev_notdef(), /* 106 */ 342 cdev_notdef(), /* 107 */ 343 cdev_notdef(), /* 108 */ 344 cdev_notdef(), /* 109 */ 345 }; 346 347 int nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]); 348 349 /* 350 * Swapdev is a fake device implemented 351 * in sw.c used only internally to get to swstrategy. 352 * It cannot be provided to the users, because the 353 * swstrategy routine munches the b_dev and b_blkno entries 354 * before calling the appropriate driver. This would horribly 355 * confuse, e.g. the hashing routines. Instead, /dev/drum is 356 * provided as a character (raw) device. 357 */ 358 dev_t swapdev = makedev(3, 0); 359