root/arch/i386/i386/conf.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. iskmemdev
  2. iszerodev
  3. getnulldev
  4. dev_rawpart

    1 /*      $OpenBSD: conf.c,v 1.118 2007/07/23 13:30:21 mk Exp $   */
    2 /*      $NetBSD: conf.c,v 1.75 1996/05/03 19:40:20 christos Exp $       */
    3 
    4 /*
    5  * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. All advertising materials mentioning features or use of this software
   16  *    must display the following acknowledgement:
   17  *      This product includes software developed by Charles Hannum.
   18  * 4. The name of the author may not be used to endorse or promote products
   19  *    derived from this software without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   31  */
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/buf.h>
   36 #include <sys/device.h>
   37 #include <sys/disklabel.h>
   38 #include <sys/ioctl.h>
   39 #include <sys/tty.h>
   40 #include <sys/vnode.h>
   41 
   42 #include <machine/conf.h>
   43 
   44 #include "inet.h"
   45 
   46 #include "wd.h"
   47 bdev_decl(wd);
   48 #include "fdc.h"
   49 #include "fd.h"
   50 bdev_decl(fd);
   51 #include "sd.h"
   52 #include "st.h"
   53 #include "cd.h"
   54 #include "uk.h"
   55 #include "mcd.h"
   56 bdev_decl(mcd);
   57 #include "vnd.h"
   58 #include "ccd.h"
   59 #include "raid.h"
   60 #include "rd.h"
   61 
   62 struct bdevsw   bdevsw[] =
   63 {
   64         bdev_disk_init(NWD,wd),         /* 0: ST506/ESDI/IDE disk */
   65         bdev_swap_init(1,sw),           /* 1: swap pseudo-device */
   66         bdev_disk_init(NFD,fd),         /* 2: floppy diskette */
   67         bdev_notdef(),                  /* 3 */
   68         bdev_disk_init(NSD,sd),         /* 4: SCSI disk */
   69         bdev_tape_init(NST,st),         /* 5: SCSI tape */
   70         bdev_disk_init(NCD,cd),         /* 6: SCSI CD-ROM */
   71         bdev_disk_init(NMCD,mcd),       /* 7: Mitsumi CD-ROM */
   72         bdev_lkm_dummy(),               /* 8 */
   73         bdev_lkm_dummy(),               /* 9 */
   74         bdev_lkm_dummy(),               /* 10 */
   75         bdev_lkm_dummy(),               /* 11 */
   76         bdev_lkm_dummy(),               /* 12 */
   77         bdev_lkm_dummy(),               /* 13 */
   78         bdev_disk_init(NVND,vnd),       /* 14: vnode disk driver */
   79         bdev_notdef(),                  /* 15 */
   80         bdev_disk_init(NCCD,ccd),       /* 16: concatenated disk driver */
   81         bdev_disk_init(NRD,rd),         /* 17: ram disk driver */
   82         bdev_notdef(),                  /* 18 */
   83         bdev_disk_init(NRAID,raid),     /* 19: RAIDframe disk driver */
   84 };
   85 int     nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]);
   86 
   87 /* open, close, read, write, ioctl, tty, mmap */
   88 #define cdev_pc_init(c,n) { \
   89         dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
   90         dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
   91         dev_init(c,n,tty), ttpoll, dev_init(c,n,mmap), D_TTY }
   92 
   93 /* open, close, read, ioctl */
   94 #define cdev_joy_init(c,n) { \
   95         dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
   96         (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
   97         (dev_type_stop((*))) enodev, 0, seltrue, \
   98         (dev_type_mmap((*))) enodev }
   99 
  100 /* open, close, ioctl, poll -- XXX should be a generic device */
  101 #define cdev_ocis_init(c,n) { \
  102         dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
  103         (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
  104         (dev_type_stop((*))) enodev, 0,  dev_init(c,n,poll), \
  105         (dev_type_mmap((*))) enodev, 0 }
  106 
  107 /* open, close, read */
  108 #define cdev_nvram_init(c,n) { \
  109         dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
  110         (dev_type_write((*))) enodev, (dev_type_ioctl((*))) enodev, \
  111         (dev_type_stop((*))) enodev, 0, seltrue, \
  112         (dev_type_mmap((*))) enodev, 0 }
  113 
  114 
  115 #define mmread  mmrw
  116 #define mmwrite mmrw
  117 cdev_decl(mm);
  118 cdev_decl(wd);
  119 #include "systrace.h"
  120 #include "bio.h"
  121 #include "pty.h"
  122 #include "com.h"
  123 #include "pccom.h"
  124 cdev_decl(com);
  125 cdev_decl(fd);
  126 #include "ss.h"
  127 #include "lpt.h"
  128 cdev_decl(lpt);
  129 #include "ch.h"
  130 #include "bpfilter.h"
  131 #if 0
  132 #include "pcmcia.h"
  133 cdev_decl(pcmcia);
  134 #endif
  135 #include "spkr.h"
  136 cdev_decl(spkr);
  137 #if 0 /* old (non-wsmouse) drivers */
  138 #include "mms.h"
  139 cdev_decl(mms);
  140 #include "lms.h"
  141 cdev_decl(lms);
  142 #include "opms.h"
  143 cdev_decl(pms);
  144 #endif
  145 #include "cy.h"
  146 cdev_decl(cy);
  147 cdev_decl(mcd);
  148 #include "tun.h"
  149 #include "audio.h"
  150 #include "midi.h"
  151 #include "sequencer.h"
  152 cdev_decl(music);
  153 #include "joy.h"
  154 #include "acpi.h"
  155 #include "apm.h"
  156 #include "bthub.h"
  157 #include "pctr.h"
  158 #include "bios.h"
  159 #include "iop.h"
  160 #ifdef XFS
  161 #include <xfs/nxfs.h>
  162 cdev_decl(xfs_dev);
  163 #endif
  164 #include "bktr.h"
  165 #include "ksyms.h"
  166 #include "usb.h"
  167 #include "uhid.h"
  168 #include "ugen.h"
  169 #include "ulpt.h"
  170 #include "urio.h"
  171 #include "ucom.h"
  172 #include "uscanner.h"
  173 #include "cz.h"
  174 cdev_decl(cztty);
  175 #include "radio.h"
  176 #include "gpr.h"
  177 #include "nvram.h"
  178 cdev_decl(nvram);
  179 
  180 /* XXX -- this needs to be supported by config(8)! */
  181 #if (NCOM > 0) && (NPCCOM > 0)
  182 #error com and pccom are mutually exclusive.  Sorry.
  183 #endif
  184 
  185 #include "wsdisplay.h"
  186 #include "wskbd.h"
  187 #include "wsmouse.h"
  188 #include "wsmux.h"
  189 
  190 #ifdef USER_PCICONF
  191 #include "pci.h"
  192 cdev_decl(pci);
  193 #endif
  194 
  195 #include "pf.h"
  196 #include "hotplug.h"
  197 #include "gpio.h"
  198 
  199 struct cdevsw   cdevsw[] =
  200 {
  201         cdev_cn_init(1,cn),             /* 0: virtual console */
  202         cdev_ctty_init(1,ctty),         /* 1: controlling terminal */
  203         cdev_mm_init(1,mm),             /* 2: /dev/{null,mem,kmem,...} */
  204         cdev_disk_init(NWD,wd),         /* 3: ST506/ESDI/IDE disk */
  205         cdev_swap_init(1,sw),           /* 4: /dev/drum (swap pseudo-device) */
  206         cdev_tty_init(NPTY,pts),        /* 5: pseudo-tty slave */
  207         cdev_ptc_init(NPTY,ptc),        /* 6: pseudo-tty master */
  208         cdev_log_init(1,log),           /* 7: /dev/klog */
  209 #if NPCCOM > 0
  210         cdev_tty_init(NPCCOM,com),      /* 8: serial port */
  211 #else
  212         cdev_tty_init(NCOM,com),        /* 8: serial port */
  213 #endif
  214         cdev_disk_init(NFD,fd),         /* 9: floppy disk */
  215         cdev_notdef(),                  /* 10 */
  216         cdev_notdef(),                  /* 11 */
  217         cdev_wsdisplay_init(NWSDISPLAY, /* 12: frame buffers, etc. */
  218             wsdisplay),
  219         cdev_disk_init(NSD,sd),         /* 13: SCSI disk */
  220         cdev_tape_init(NST,st),         /* 14: SCSI tape */
  221         cdev_disk_init(NCD,cd),         /* 15: SCSI CD-ROM */
  222         cdev_lpt_init(NLPT,lpt),        /* 16: parallel printer */
  223         cdev_ch_init(NCH,ch),           /* 17: SCSI autochanger */
  224         cdev_disk_init(NCCD,ccd),       /* 18: concatenated disk driver */
  225         cdev_ss_init(NSS,ss),           /* 19: SCSI scanner */
  226         cdev_uk_init(NUK,uk),           /* 20: unknown SCSI */
  227         cdev_apm_init(NAPM,apm),        /* 21: Advancded Power Management */
  228         cdev_fd_init(1,filedesc),       /* 22: file descriptor pseudo-device */
  229         cdev_bpftun_init(NBPFILTER,bpf),/* 23: Berkeley packet filter */
  230         cdev_notdef(),                  /* 24 */
  231 #if 0
  232         cdev_ocis_init(NPCMCIA,pcmcia), /* 25: PCMCIA Bus */
  233 #else
  234         cdev_notdef(),                  /* 25 */
  235 #endif
  236         cdev_joy_init(NJOY,joy),        /* 26: joystick */
  237         cdev_spkr_init(NSPKR,spkr),     /* 27: PC speaker */
  238         cdev_lkm_init(NLKM,lkm),        /* 28: loadable module driver */
  239         cdev_lkm_dummy(),               /* 29 */
  240         cdev_lkm_dummy(),               /* 30 */
  241         cdev_lkm_dummy(),               /* 31 */
  242         cdev_lkm_dummy(),               /* 32 */
  243         cdev_lkm_dummy(),               /* 33 */
  244         cdev_lkm_dummy(),               /* 34 */
  245         cdev_notdef(),                  /* 35: Microsoft mouse */
  246         cdev_notdef(),                  /* 36: Logitech mouse */
  247         cdev_notdef(),                  /* 37: Extended PS/2 mouse */
  248         cdev_tty_init(NCY,cy),          /* 38: Cyclom serial port */
  249         cdev_disk_init(NMCD,mcd),       /* 39: Mitsumi CD-ROM */
  250         cdev_bpftun_init(NTUN,tun),     /* 40: network tunnel */
  251         cdev_disk_init(NVND,vnd),       /* 41: vnode disk driver */
  252         cdev_audio_init(NAUDIO,audio),  /* 42: generic audio I/O */
  253 #ifdef COMPAT_SVR4
  254         cdev_svr4_net_init(1,svr4_net), /* 43: svr4 net pseudo-device */
  255 #else
  256         cdev_notdef(),                  /* 43 */
  257 #endif
  258         cdev_notdef(),                  /* 44 */
  259         cdev_random_init(1,random),     /* 45: random data source */
  260         cdev_ocis_init(NPCTR,pctr),     /* 46: pentium performance counters */
  261         cdev_disk_init(NRD,rd),         /* 47: ram disk driver */
  262         cdev_ocis_init(NBIOS,bios),     /* 48: onboard BIOS PROM */
  263         cdev_bktr_init(NBKTR,bktr),     /* 49: Bt848 video capture device */
  264         cdev_ksyms_init(NKSYMS,ksyms),  /* 50: Kernel symbols device */
  265 #ifdef XFS
  266         cdev_xfs_init(NXFS,xfs_dev),    /* 51: xfs communication device */
  267 #else
  268         cdev_notdef(),                  /* 51 */
  269 #endif
  270         cdev_midi_init(NMIDI,midi),     /* 52: MIDI I/O */
  271         cdev_midi_init(NSEQUENCER,sequencer),   /* 53: sequencer I/O */
  272         cdev_disk_init(NRAID,raid),     /* 54: RAIDframe disk driver */
  273         cdev_notdef(),                  /* 55: */
  274         /* The following slots are reserved for isdn4bsd. */
  275         cdev_notdef(),                  /* 56: i4b main device */
  276         cdev_notdef(),                  /* 57: i4b control device */
  277         cdev_notdef(),                  /* 58: i4b raw b-channel access */
  278         cdev_notdef(),                  /* 59: i4b trace device */
  279         cdev_notdef(),                  /* 60: i4b phone device */
  280         /* End of reserved slots for isdn4bsd. */
  281         cdev_usb_init(NUSB,usb),        /* 61: USB controller */
  282         cdev_usbdev_init(NUHID,uhid),   /* 62: USB generic HID */
  283         cdev_usbdev_init(NUGEN,ugen),   /* 63: USB generic driver */
  284         cdev_ulpt_init(NULPT,ulpt),     /* 64: USB printers */
  285         cdev_urio_init(NURIO,urio),     /* 65: USB Diamond Rio 500 */
  286         cdev_tty_init(NUCOM,ucom),      /* 66: USB tty */
  287         cdev_mouse_init(NWSKBD, wskbd), /* 67: keyboards */
  288         cdev_mouse_init(NWSMOUSE,       /* 68: mice */
  289             wsmouse),
  290         cdev_mouse_init(NWSMUX, wsmux), /* 69: ws multiplexor */
  291         cdev_crypto_init(NCRYPTO,crypto), /* 70: /dev/crypto */
  292         cdev_tty_init(NCZ,cztty),       /* 71: Cyclades-Z serial port */
  293 #ifdef USER_PCICONF
  294         cdev_pci_init(NPCI,pci),        /* 72: PCI user */
  295 #else
  296         cdev_notdef(),
  297 #endif
  298         cdev_pf_init(NPF,pf),           /* 73: packet filter */
  299         cdev_notdef(),                  /* 74: ALTQ (deprecated) */
  300         cdev_iop_init(NIOP,iop),        /* 75: I2O IOP control interface */
  301         cdev_radio_init(NRADIO, radio), /* 76: generic radio I/O */
  302         cdev_usbdev_init(NUSCANNER,uscanner),   /* 77: USB scanners */
  303         cdev_systrace_init(NSYSTRACE,systrace), /* 78: system call tracing */
  304         cdev_bio_init(NBIO,bio),        /* 79: ioctl tunnel */
  305         cdev_ch_init(NGPR,gpr),         /* 80: GPR400 SmartCard reader */
  306         cdev_ptm_init(NPTY,ptm),        /* 81: pseudo-tty ptm device */
  307         cdev_hotplug_init(NHOTPLUG,hotplug), /* 82: devices hot plugging */
  308         cdev_gpio_init(NGPIO,gpio),     /* 83: GPIO interface */
  309         cdev_nvram_init(NNVRAM,nvram),  /* 84: NVRAM interface */
  310         cdev_acpi_init(NACPI,acpi),     /* 85: ACPI */
  311         cdev_bthub_init(NBTHUB,bthub),  /* 86: bthub */
  312 };
  313 int     nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]);
  314 
  315 int     mem_no = 2;     /* major device number of memory special file */
  316 
  317 /*
  318  * Swapdev is a fake device implemented
  319  * in sw.c used only internally to get to swstrategy.
  320  * It cannot be provided to the users, because the
  321  * swstrategy routine munches the b_dev and b_blkno entries
  322  * before calling the appropriate driver.  This would horribly
  323  * confuse, e.g. the hashing routines. Instead, /dev/drum is
  324  * provided as a character (raw) device.
  325  */
  326 dev_t   swapdev = makedev(1, 0);
  327 
  328 /*
  329  * Returns true if dev is /dev/mem or /dev/kmem.
  330  */
  331 int
  332 iskmemdev(dev_t dev)
  333 {
  334         return (major(dev) == mem_no && (minor(dev) < 2 || minor(dev) == 14));
  335 }
  336 
  337 /*
  338  * Returns true if dev is /dev/zero.
  339  */
  340 int
  341 iszerodev(dev_t dev)
  342 {
  343         return (major(dev) == mem_no && minor(dev) == 12);
  344 }
  345 
  346 dev_t
  347 getnulldev(void)
  348 {
  349         return makedev(mem_no, 2);
  350 }
  351 
  352 int chrtoblktbl[] = {
  353         /* XXXX This needs to be dynamic for LKMs. */
  354         /*VCHR*/        /*VBLK*/
  355         /*  0 */        NODEV,
  356         /*  1 */        NODEV,
  357         /*  2 */        NODEV,
  358         /*  3 */        0,
  359         /*  4 */        NODEV,
  360         /*  5 */        NODEV,
  361         /*  6 */        NODEV,
  362         /*  7 */        NODEV,
  363         /*  8 */        NODEV,
  364         /*  9 */        2,
  365         /* 10 */        3,
  366         /* 11 */        15,
  367         /* 12 */        NODEV,
  368         /* 13 */        4,
  369         /* 14 */        5,
  370         /* 15 */        6,
  371         /* 16 */        NODEV,
  372         /* 17 */        NODEV,
  373         /* 18 */        16,
  374         /* 19 */        NODEV,
  375         /* 20 */        NODEV,
  376         /* 21 */        NODEV,
  377         /* 22 */        NODEV,
  378         /* 23 */        NODEV,
  379         /* 24 */        18,
  380         /* 25 */        NODEV,
  381         /* 26 */        NODEV,
  382         /* 27 */        NODEV,
  383         /* 28 */        NODEV,
  384         /* 29 */        NODEV,
  385         /* 30 */        NODEV,
  386         /* 31 */        NODEV,
  387         /* 32 */        NODEV,
  388         /* 33 */        NODEV,
  389         /* 34 */        NODEV,
  390         /* 35 */        NODEV,
  391         /* 36 */        NODEV,
  392         /* 37 */        NODEV,
  393         /* 38 */        NODEV,
  394         /* 39 */        7,
  395         /* 40 */        NODEV,
  396         /* 41 */        14,
  397         /* 42 */        NODEV,
  398         /* 43 */        NODEV,
  399         /* 44 */        NODEV,
  400         /* 45 */        NODEV,
  401         /* 46 */        NODEV,
  402         /* 47 */        17,
  403         /* 48 */        NODEV,
  404         /* 49 */        NODEV,
  405         /* 50 */        NODEV,
  406         /* 51 */        NODEV,
  407         /* 52 */        NODEV,
  408         /* 53 */        NODEV,
  409         /* 54 */        19,
  410 };
  411 int nchrtoblktbl = sizeof(chrtoblktbl) / sizeof(chrtoblktbl[0]);
  412 
  413 /*
  414  * In order to map BSD bdev numbers of disks to their BIOS equivalents
  415  * we use several heuristics, one being using checksums of the first
  416  * few blocks of a disk to get a signature we can match with /boot's
  417  * computed signatures.  To know where from to read, we must provide a
  418  * disk driver name -> bdev major number table, which follows.
  419  * Note: floppies are not included as those are differentiated by the BIOS.
  420  */
  421 int findblkmajor(struct device *dv);
  422 dev_t dev_rawpart(struct device *);     /* XXX */
  423 
  424 dev_t
  425 dev_rawpart(struct device *dv)
  426 {
  427         int majdev;
  428 
  429         majdev = findblkmajor(dv);
  430 
  431         switch (majdev) {
  432         /* add here any device you want to be checksummed on boot */
  433         case 0:         /* wd */
  434         case 4:         /* sd */
  435                 return (MAKEDISKDEV(majdev, dv->dv_unit, RAW_PART));
  436                 break;
  437         default:
  438                 ;
  439         }
  440 
  441         return (NODEV);
  442 }
  443 
  444 /*
  445  * This entire table could be autoconfig()ed but that would mean that
  446  * the kernel's idea of the console would be out of sync with that of
  447  * the standalone boot.  I think it best that they both use the same
  448  * known algorithm unless we see a pressing need otherwise.
  449  */
  450 #include <dev/cons.h>
  451 
  452 cons_decl(com);
  453 cons_decl(ws);
  454 
  455 struct  consdev constab[] = {
  456 #if NWSDISPLAY > 0
  457         cons_init(ws),
  458 #endif
  459 #if NCOM + NPCCOM > 0
  460         cons_init(com),
  461 #endif
  462         { 0 },
  463 };

/* [<][>][^][v][top][bottom][index][help] */