1 /* 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 /*- 34 * Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo, 35 * Michael L. Finch, Bradley A. Grantham, and 36 * Lawrence A. Kesteloot 37 * All rights reserved. 38 * 39 * Redistribution and use in source and binary forms, with or without 40 * modification, are permitted provided that the following conditions 41 * are met: 42 * 1. Redistributions of source code must retain the above copyright 43 * notice, this list of conditions and the following disclaimer. 44 * 2. Redistributions in binary form must reproduce the above copyright 45 * notice, this list of conditions and the following disclaimer in the 46 * documentation and/or other materials provided with the distribution. 47 * 3. All advertising materials mentioning features or use of this software 48 * must display the following acknowledgement: 49 * This product includes software developed by the Alice Group. 50 * 4. The names of the Alice Group or any of its members may not be used 51 * to endorse or promote products derived from this software without 52 * specific prior written permission. 53 * 54 * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR 55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 57 * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT, 58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 63 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64 * 65 */ 66 /*- 67 * from: @(#)conf.c 7.9 (Berkeley) 5/28/91 68 * $Id: conf.c,v 1.4 1994/02/03 21:46:51 briggs Exp $ 69 */ 70 /* 71 ALICE 72 BG 06/02/92,23:25:54 73 I have modified this file to correspond loosely to our requirements. 74 We need to go back through and check on a few things: 75 1) can we get rid of the _notdef()'s? 76 2) should we keep all the devices I left here? (e.g. cd...) 77 3) did I put the new devices in the right places? 78 */ 79 80 #include "sys/param.h" 81 #include "sys/systm.h" 82 #include "sys/buf.h" 83 #include "sys/ioctl.h" 84 #include "sys/tty.h" 85 #include "sys/conf.h" 86 87 int rawread __P((dev_t, struct uio *, int)); 88 int rawwrite __P((dev_t, struct uio *, int)); 89 int swstrategy __P((struct buf *)); 90 int ttselect __P((dev_t, int, struct proc *)); 91 92 #define dev_type_open(n) int n __P((dev_t, int, int, struct proc *)) 93 #define dev_type_close(n) int n __P((dev_t, int, int, struct proc *)) 94 #define dev_type_strategy(n) int n __P((struct buf *)) 95 #define dev_type_ioctl(n) \ 96 int n __P((dev_t, int, caddr_t, int, struct proc *)) 97 98 /* bdevsw-specific types */ 99 #define dev_type_dump(n) int n __P((dev_t)) 100 #define dev_type_size(n) int n __P((dev_t)) 101 102 #define dev_decl(n,t) __CONCAT(dev_type_,t)(__CONCAT(n,t)) 103 104 #define dev_init(c,n,t) \ 105 ((c > 0) ? __CONCAT(n,t) : (__CONCAT(dev_type_,t)((*))) enxio) 106 107 /* bdevsw-specific initializations */ 108 #define dev_size_init(c,n) (c > 0 ? __CONCAT(n,size) : 0) 109 110 #define bdev_decl(n) \ 111 dev_decl(n,open); dev_decl(n,close); dev_decl(n,strategy); \ 112 dev_decl(n,ioctl); dev_decl(n,dump); dev_decl(n,size) 113 114 #define bdev_disk_init(c,n) { \ 115 dev_init(c,n,open), (dev_type_close((*))) nullop, \ 116 dev_init(c,n,strategy), dev_init(c,n,ioctl), \ 117 dev_init(c,n,dump), dev_size_init(c,n), 0 } 118 119 #define bdev_cd_init(c,n) { \ 120 dev_init(c,n,open), (dev_type_close((*))) nullop, \ 121 dev_init(c,n,strategy), dev_init(c,n,ioctl), \ 122 (dev_type_dump((*))) enodev, dev_size_init(c,n), 0 } 123 124 #define bdev_tape_init(c,n) { \ 125 dev_init(c,n,open), dev_init(c,n,close), \ 126 dev_init(c,n,strategy), dev_init(c,n,ioctl), \ 127 (dev_type_dump((*))) enodev, 0, B_TAPE } 128 129 #define bdev_swap_init() { \ 130 (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \ 131 swstrategy, (dev_type_ioctl((*))) enodev, \ 132 (dev_type_dump((*))) enodev, 0, 0 } 133 134 #define bdev_notdef() bdev_tape_init(0,no) 135 bdev_decl(no); /* dummy declarations */ 136 137 /* 06/02/92,23:14:37 BG -- I deleted ct.h and rd.h, we won't even adapt 'em */ 138 #include "st.h" 139 #include "sd.h" 140 #include "cd.h" 141 #include "ch.h" 142 #define NVN 0 /*#include "vn.h"*/ 143 144 bdev_decl(st); 145 bdev_decl(sd); 146 bdev_decl(cd); 147 bdev_decl(vn); 148 149 /* 06/02/92,23:15:39 BG -- deleted ct and rd, defined as notdef, I don't know */ 150 /* what entirely removing them would do... */ 151 struct bdevsw bdevsw[] = 152 { 153 bdev_notdef(), /* 0: cs80 cartridge tape */ 154 bdev_notdef(), /* 1 */ 155 bdev_notdef(), /* 2: hpib disk */ 156 bdev_swap_init(), /* 3: swap pseudo-device */ 157 bdev_disk_init(NSD,sd), /* 4: scsi disk */ 158 bdev_tape_init(NST,st), /* 5: scsi tape */ 159 bdev_cd_init(NCD,cd), /* 6: scsi CD driver */ 160 bdev_notdef(), /* i386-14: vnode disk driver (swap to files) */ 161 }; 162 163 int nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]); 164 165 /* cdevsw-specific types */ 166 #define dev_type_read(n) int n __P((dev_t, struct uio *, int)) 167 #define dev_type_write(n) int n __P((dev_t, struct uio *, int)) 168 #define dev_type_stop(n) int n __P((struct tty *, int)) 169 #define dev_type_reset(n) int n __P((int)) 170 #define dev_type_select(n) int n __P((dev_t, int, struct proc *)) 171 #define dev_type_map(n) int n __P(()) 172 173 #define cdev_decl(n) \ 174 dev_decl(n,open); dev_decl(n,close); dev_decl(n,read); \ 175 dev_decl(n,write); dev_decl(n,ioctl); dev_decl(n,stop); \ 176 dev_decl(n,reset); dev_decl(n,select); dev_decl(n,map); \ 177 dev_decl(n,strategy); extern struct tty __CONCAT(n,_tty)[] 178 179 #define dev_tty_init(c,n) (c > 0 ? __CONCAT(n,_tty) : 0) 180 181 /* open, read, write, ioctl, strategy */ 182 #define cdev_disk_init(c,n) { \ 183 dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,raw,read), \ 184 dev_init(c,raw,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ 185 (dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, \ 186 dev_init(c,n,strategy) } 187 188 /* open, close, read, write, ioctl, strategy */ 189 #define cdev_tape_init(c,n) { \ 190 dev_init(c,n,open), dev_init(c,n,close), \ 191 (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \ 192 dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ 193 (dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, \ 194 dev_init(c,n,strategy) } 195 196 /* open, close, read, write, ioctl, stop, tty */ 197 #define cdev_tty_init(c,n) { \ 198 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 199 dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \ 200 (dev_type_reset((*))) nullop, dev_tty_init(c,n), ttselect, \ 201 (dev_type_map((*))) enodev, 0 } 202 203 #define cdev_notdef() { \ 204 (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \ 205 (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \ 206 (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \ 207 (dev_type_reset((*))) nullop, 0, seltrue, \ 208 (dev_type_map((*))) enodev, 0 } 209 210 cdev_decl(no); /* dummy declarations */ 211 212 cdev_decl(con); 213 /* 06/02/92,23:17:34 BG -- this will be LAK's console driver, if I understand */ 214 /* the difference between cn and ctty correctly. */ 215 /* open, close, read, write, ioctl, select -- XXX should be a tty */ 216 #define cdev_con_init(c,n) { \ 217 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 218 dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ 219 (dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \ 220 (dev_type_map((*))) enodev, 0 } 221 222 cdev_decl(ctty); 223 /* open, read, write, ioctl, select -- XXX should be a tty */ 224 #define cdev_ctty_init(c,n) { \ 225 dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \ 226 dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ 227 (dev_type_reset((*))) nullop, 0, dev_init(c,n,select), \ 228 (dev_type_map((*))) enodev, 0 } 229 230 dev_type_read(mmrw); 231 /* read/write */ 232 #define cdev_mm_init(c,n) { \ 233 (dev_type_open((*))) nullop, (dev_type_close((*))) nullop, mmrw, \ 234 mmrw, (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) nullop, \ 235 (dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, 0 } 236 237 /* read, write, strategy */ 238 #define cdev_swap_init(c,n) { \ 239 (dev_type_open((*))) nullop, (dev_type_close((*))) nullop, rawread, \ 240 rawwrite, (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \ 241 (dev_type_reset((*))) nullop, 0, (dev_type_select((*))) enodev, \ 242 (dev_type_map((*))) enodev, dev_init(c,n,strategy) } 243 244 #include "pty.h" 245 #define pts_tty pt_tty 246 #define ptsioctl ptyioctl 247 cdev_decl(pts); 248 #define ptc_tty pt_tty 249 #define ptcioctl ptyioctl 250 cdev_decl(ptc); 251 252 /* open, close, read, write, ioctl, tty, select */ 253 #define cdev_ptc_init(c,n) { \ 254 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 255 dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ 256 (dev_type_reset((*))) nullop, dev_tty_init(c,n), dev_init(c,n,select), \ 257 (dev_type_map((*))) enodev, 0 } 258 259 cdev_decl(log); 260 /* open, close, read, ioctl, select -- XXX should be a generic device */ 261 #define cdev_log_init(c,n) { \ 262 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 263 (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ 264 (dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \ 265 dev_init(c,n,select), (dev_type_map((*))) enodev, 0 } 266 267 cdev_decl(st); 268 cdev_decl(sd); 269 /* cdev_decl(ch); */ 270 271 /* 06/02/92,23:18:17 BG -- I removed rd, ct, grf, ppi, dca, ite, dcm, and I */ 272 /* made hil into kbd (keyboard) */ 273 /* MF i want grf back !!*/ 274 275 /* frame buffer guy */ 276 cdev_decl(grf); 277 /* open, close, ioctl, select, map -- XXX should be a map device */ 278 #define cdev_grf_init(c,n) { \ 279 dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) nullop, \ 280 (dev_type_write((*))) nullop, dev_init(c,n,ioctl), \ 281 (dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \ 282 dev_init(c,n,select), dev_init(c,n,map), 0 } 283 284 cdev_decl(kbd); 285 /* open, close, read, ioctl, select, map -- XXX should be a map device */ 286 #define cdev_kbd_init(c,n) { \ 287 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 288 (dev_type_write((*))) nullop, dev_init(c,n,ioctl), \ 289 (dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \ 290 dev_init(c,n,select), dev_init(c,n,map), 0 } 291 292 /* 06/02/92,23:21:56 BG -- this was dcm, we will make it ser (serial ports) */ 293 #define NSER 2 294 /* #include "ser.h" */ 295 cdev_decl(ser); 296 297 cdev_decl(cd); 298 299 #define NCLOCK 0 /* #include "clock.h" */ 300 cdev_decl(clock); 301 /* open, close, ioctl, map -- XXX should be a map device */ 302 #define cdev_clock_init(c,n) { \ 303 dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) nullop, \ 304 (dev_type_write((*))) nullop, dev_init(c,n,ioctl), \ 305 (dev_type_stop((*))) enodev, (dev_type_reset((*))) nullop, 0, \ 306 (dev_type_select((*))) nullop, dev_init(c,n,map), 0 } 307 308 cdev_decl(vn); 309 /* open, read, write, ioctl -- XXX should be a disk */ 310 #define cdev_vn_init(c,n) { \ 311 dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \ 312 dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ 313 (dev_type_reset((*))) nullop, 0, seltrue, (dev_type_map((*))) enodev, \ 314 0 } 315 316 dev_type_open(fdopen); 317 /* open */ 318 #define cdev_fd_init(c,n) { \ 319 dev_init(c,n,open), (dev_type_close((*))) enodev, \ 320 (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \ 321 (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \ 322 (dev_type_reset((*))) enodev, 0, (dev_type_select((*))) enodev, \ 323 (dev_type_map((*))) enodev, 0 } 324 325 #include "bpfilter.h" 326 cdev_decl(bpf); 327 /* open, close, read, write, ioctl, select -- XXX should be generic device */ 328 #define cdev_bpf_init(c,n) { \ 329 dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ 330 dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ 331 (dev_type_reset((*))) enodev, 0, dev_init(c,n,select), \ 332 (dev_type_map((*))) enodev, 0 } 333 334 335 struct cdevsw cdevsw[] = 336 { 337 cdev_con_init(9,con), /* 0: virtual console */ 338 cdev_ctty_init(1,ctty), /* 1: controlling terminal */ 339 cdev_mm_init(1,mm), /* 2: /dev/{null,mem,kmem,...} */ 340 cdev_swap_init(1,sw), /* 3: /dev/drum (swap pseudo-device) */ 341 cdev_tty_init(NPTY,pts), /* 4: pseudo-tty slave */ 342 cdev_ptc_init(NPTY,ptc), /* 5: pseudo-tty master */ 343 cdev_log_init(1,log), /* 6: /dev/klog */ 344 cdev_notdef(), /* 7: was cs80 cartridge tape */ 345 cdev_disk_init(NSD,sd), /* 8: scsi disk */ 346 cdev_notdef(), /* 9: was hpib disk */ 347 cdev_grf_init(1,grf), /* 10: was frame buffer */ 348 cdev_notdef(), /* 11: was printer/plotter interface */ 349 cdev_tty_init(NSER,ser), /* 12: 2 mac serial ports -- BG*/ 350 cdev_disk_init(NSD,sd), /* 13: scsi disk */ 351 cdev_tape_init(NST,st), /* 14: scsi tape */ 352 cdev_tape_init(NCD,cd), /* 15: scsi compact disc */ 353 cdev_kbd_init(0,kbd), /* 16: ADB keyboard -- BG -- BARF*/ 354 /* cdev_disk_init(NCH,ch), 17: scsi changer device */ 355 cdev_notdef(), /* 17: until we find chstrategy... */ 356 cdev_clock_init(NCLOCK,clock), /* 18: mapped clock */ 357 cdev_vn_init(NVN,vn), /* 19: vnode disk */ 358 cdev_tape_init(NST,st), /* 20: exabyte tape */ 359 cdev_fd_init(1,fd), /* 21: file descriptor pseudo-dev */ 360 cdev_bpf_init(NBPFILTER,bpf), /* 22: berkeley packet filter */ 361 }; 362 363 int nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]); 364 365 int mem_no = 2; /* major device number of memory special file */ 366 367 /* 368 * Swapdev is a fake device implemented 369 * in sw.c used only internally to get to swstrategy. 370 * It cannot be provided to the users, because the 371 * swstrategy routine munches the b_dev and b_blkno entries 372 * before calling the appropriate driver. This would horribly 373 * confuse, e.g. the hashing routines. Instead, /dev/drum is 374 * provided as a character (raw) device. 375 */ 376 dev_t swapdev = makedev(3, 0); 377