]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/i386/conf.c
xnu-2050.24.15.tar.gz
[apple/xnu.git] / bsd / dev / i386 / conf.c
index f06b30fc6a0d02584c8f93b4e105af763d058008..bff6f72322b7a8dc0bfe655fecaf217a08467346 100644 (file)
@@ -1,26 +1,31 @@
 /*
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1997-2012 Apple Computer, Inc. All rights reserved.
  *
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  */
 /*
- * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
  * Copyright (c) 1993 NeXT Computer, Inc.
  *
  * UNIX Device switch tables.
  * Copyright (c) 1993 NeXT Computer, Inc.
  *
  * UNIX Device switch tables.
 
 #include <sys/param.h>
 #include <sys/systm.h>
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/buf.h>
 #include <sys/ioctl.h>
 #include <sys/tty.h>
 #include <sys/conf.h>
 
 #include <sys/ioctl.h>
 #include <sys/tty.h>
 #include <sys/conf.h>
 
-
-extern int     nulldev();
+/* Prototypes that should be elsewhere: */
+extern dev_t   chrtoblk(dev_t dev);
+extern int     chrtoblk_set(int cdev, int bdev);
+extern int     iskmemdev(dev_t dev);
 
 struct bdevsw  bdevsw[] =
 {
        /*
         *      For block devices, every other block of 8 slots is 
 
 struct bdevsw  bdevsw[] =
 {
        /*
         *      For block devices, every other block of 8 slots is 
-        *      reserved to NeXT.  The other slots are available for
+        *      reserved for Apple.  The other slots are available for
         *      the user.  This way we can both add new entries without
         *      the user.  This way we can both add new entries without
-        *      running into each other.  Be sure to fill in NeXT's
+        *      running into each other.  Be sure to fill in Apple's
         *      8 reserved slots when you jump over us -- we'll do the
         *      same for you.
         */
 
         *      8 reserved slots when you jump over us -- we'll do the
         *      same for you.
         */
 
-       /* 0 - 7 are reserved to NeXT */
+       /* 0 - 7 are reserved for Apple */
 
        NO_BDEVICE,                                                     /* 0*/
        NO_BDEVICE,                                                     /* 1*/
 
        NO_BDEVICE,                                                     /* 0*/
        NO_BDEVICE,                                                     /* 1*/
@@ -75,7 +81,7 @@ struct bdevsw bdevsw[] =
        NO_BDEVICE,                                                     /*14*/
        NO_BDEVICE,                                                     /*15*/
 
        NO_BDEVICE,                                                     /*14*/
        NO_BDEVICE,                                                     /*15*/
 
-       /* 16 - 23 are reserved to NeXT */
+       /* 16 - 23 are reserved for Apple */
        NO_BDEVICE,                                                     /*16*/
        NO_BDEVICE,                                                     /*17*/
        NO_BDEVICE,                                                     /*18*/
        NO_BDEVICE,                                                     /*16*/
        NO_BDEVICE,                                                     /*17*/
        NO_BDEVICE,                                                     /*18*/
@@ -89,39 +95,64 @@ struct bdevsw       bdevsw[] =
 int    nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
 
 extern struct tty *km_tty[];
 int    nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
 
 extern struct tty *km_tty[];
-extern int     cnopen(),cnclose(),cnread(),cnwrite(),cnioctl(),
-               cnselect(),cngetc(), cnputc(dev_t dev, char c);
-extern int     kmopen(),kmclose(),kmread(),kmwrite(),kmioctl(),
-               kmgetc(), kmputc(dev_t dev, char c);
-extern int     sgopen(),sgclose(), sgioctl();
+extern d_open_t                cnopen;
+extern d_close_t       cnclose;
+extern d_read_t                cnread;
+extern d_write_t       cnwrite;
+extern d_ioctl_t       cnioctl;
+extern d_select_t      cnselect;
+extern d_open_t                kmopen;
+extern d_close_t       kmclose;
+extern d_read_t                kmread;
+extern d_write_t       kmwrite;
+extern d_ioctl_t       kmioctl;
+extern d_open_t                sgopen;
+extern d_close_t       sgclose;
+extern d_ioctl_t       sgioctl;
 
 #if NVOL > 0
 
 #if NVOL > 0
-extern int     volopen(),volclose(),volioctl();
+extern d_open_t                volopen;
+extern d_close_t       volclose;
+extern d_ioctl_t       volioctl;
 #else
 #define        volopen         eno_opcl
 #define        volclose        eno_opcl
 #define        volioctl        eno_ioctl
 #endif
 
 #else
 #define        volopen         eno_opcl
 #define        volclose        eno_opcl
 #define        volioctl        eno_ioctl
 #endif
 
-extern int     cttyopen(), cttyread(), cttywrite(), cttyioctl(), cttyselect();
+extern d_open_t                cttyopen;
+extern d_close_t       cttyclose;
+extern d_read_t                cttyread;
+extern d_write_t       cttywrite;
+extern d_ioctl_t       cttyioctl;
+extern d_select_t      cttyselect;
 
 
-extern int     mmread(),mmwrite();
-#define        mmselect        seltrue
+extern d_read_t                mmread;
+extern d_write_t       mmwrite;
+extern d_ioctl_t       mmioctl;
+#define        mmselect        (select_fcn_t *)seltrue
 #define mmmmap         eno_mmap
 
 #include <pty.h>
 #if NPTY > 0
 extern struct tty *pt_tty[];
 #define mmmmap         eno_mmap
 
 #include <pty.h>
 #if NPTY > 0
 extern struct tty *pt_tty[];
-extern int     ptsopen(),ptsclose(),ptsread(),ptswrite(),ptsstop(),ptsputc();
-extern int     ptcopen(),ptcclose(),ptcread(),ptcwrite(),ptcselect(),
-               ptyioctl();
+extern d_open_t                ptsopen;
+extern d_close_t       ptsclose;
+extern d_read_t                ptsread;
+extern d_write_t       ptswrite;
+extern d_stop_t                ptsstop;
+extern d_open_t                ptcopen;
+extern d_close_t       ptcclose;
+extern d_read_t                ptcread;
+extern d_write_t       ptcwrite;
+extern d_select_t      ptcselect;
+extern d_ioctl_t       ptyioctl;
 #else
 #define ptsopen                eno_opcl
 #define ptsclose       eno_opcl
 #define ptsread                eno_rdwrt
 #define ptswrite       eno_rdwrt
 #define        ptsstop         nulldev
 #else
 #define ptsopen                eno_opcl
 #define ptsclose       eno_opcl
 #define ptsread                eno_rdwrt
 #define ptswrite       eno_rdwrt
 #define        ptsstop         nulldev
-#define ptsputc                nulldev
 
 #define ptcopen                eno_opcl
 #define ptcclose       eno_opcl
 
 #define ptcopen                eno_opcl
 #define ptcclose       eno_opcl
@@ -131,54 +162,68 @@ extern int        ptcopen(),ptcclose(),ptcread(),ptcwrite(),ptcselect(),
 #define ptyioctl       eno_ioctl
 #endif
 
 #define ptyioctl       eno_ioctl
 #endif
 
-extern int     logopen(),logclose(),logread(),logioctl(),logselect();
-extern int     fdesc_open(), fdesc_read(), fdesc_write(),
-               fdesc_ioctl(), fdesc_select();
+extern d_open_t                logopen;
+extern d_close_t       logclose;
+extern d_read_t                logread;
+extern d_ioctl_t       logioctl;
+extern d_select_t      logselect;
+extern d_open_t                fdesc_open;
+extern d_read_t                fdesc_read;
+extern d_write_t       fdesc_write;
+extern d_ioctl_t       fdesc_ioctl;
+extern d_select_t      fdesc_select;
 
 
-extern int     seltrue();
+#define nullopen       (d_open_t *)&nulldev
+#define nullclose      (d_close_t *)&nulldev
+#define nullread       (d_read_t *)&nulldev
+#define nullwrite      (d_write_t *)&nulldev
+#define nullioctl      (d_ioctl_t *)&nulldev
+#define nullselect     (d_select_t *)&nulldev
+#define nullstop       (d_stop_t *)&nulldev
+#define nullreset      (d_reset_t *)&nulldev
 
 struct cdevsw  cdevsw[] =
 {
        /*
         *      For character devices, every other block of 16 slots is
 
 struct cdevsw  cdevsw[] =
 {
        /*
         *      For character devices, every other block of 16 slots is
-        *      reserved to NeXT.  The other slots are available for
+        *      reserved for Apple.  The other slots are available for
         *      the user.  This way we can both add new entries without
         *      the user.  This way we can both add new entries without
-        *      running into each other.  Be sure to fill in NeXT's
+        *      running into each other.  Be sure to fill in Apple's
         *      16 reserved slots when you jump over us -- we'll do the
         *      same for you.
         */
 
         *      16 reserved slots when you jump over us -- we'll do the
         *      same for you.
         */
 
-       /* 0 - 15 are reserved to NeXT */
+       /* 0 - 15 are reserved for Apple */
 
     {
        cnopen,         cnclose,        cnread,         cnwrite,        /* 0*/
 
     {
        cnopen,         cnclose,        cnread,         cnwrite,        /* 0*/
-       cnioctl,        nulldev,        nulldev,        0,              cnselect,
-       eno_mmap,       eno_strat,      cngetc,         cnputc,         D_TTY
+       cnioctl,        nullstop,       nullreset,      0,              cnselect,
+       eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY
     },
     NO_CDEVICE,                                                                /* 1*/
     {
     },
     NO_CDEVICE,                                                                /* 1*/
     {
-       cttyopen,       nulldev,        cttyread,       cttywrite,      /* 2*/
-       cttyioctl,      nulldev,        nulldev,        0,              cttyselect,
-       eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY
+       cttyopen,       cttyclose,      cttyread,       cttywrite,      /* 2*/
+       cttyioctl,      nullstop,       nullreset,      0,              cttyselect,
+       eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY | D_TRACKCLOSE
     },
     {
     },
     {
-       nulldev,        nulldev,        mmread,         mmwrite,        /* 3*/
-       eno_ioctl,      nulldev,        nulldev,        0,              mmselect,
-       mmmmap,         eno_strat,      eno_getc,       eno_putc,       0
+       nullopen,       nullclose,      mmread,         mmwrite,        /* 3*/
+       mmioctl,        nullstop,       nullreset,      0,              mmselect,
+       mmmmap,         eno_strat,      eno_getc,       eno_putc,       D_DISK
     },
     {
        ptsopen,        ptsclose,       ptsread,        ptswrite,       /* 4*/
     },
     {
        ptsopen,        ptsclose,       ptsread,        ptswrite,       /* 4*/
-       ptyioctl,       ptsstop,        nulldev,        pt_tty,         ttselect,
+       ptyioctl,       ptsstop,        nullreset,      pt_tty,         ttselect,
        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY
     },
     {
        ptcopen,        ptcclose,       ptcread,        ptcwrite,       /* 5*/
        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY
     },
     {
        ptcopen,        ptcclose,       ptcread,        ptcwrite,       /* 5*/
-       ptyioctl,       nulldev,        nulldev,        0,              ptcselect,
+       ptyioctl,       nullstop,       nullreset,      0,              ptcselect,
        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY
     },
     {
        logopen,        logclose,       logread,        eno_rdwrt,      /* 6*/
        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY
     },
     {
        logopen,        logclose,       logread,        eno_rdwrt,      /* 6*/
-       logioctl,       eno_stop,       nulldev,        0,              logselect,
+       logioctl,       eno_stop,       nullreset,      0,              logselect,
        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       0
     },
     NO_CDEVICE,                                                                /* 7*/
        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       0
     },
     NO_CDEVICE,                                                                /* 7*/
@@ -188,8 +233,8 @@ struct cdevsw       cdevsw[] =
     NO_CDEVICE,                                                                /*11*/
     {
        kmopen,         kmclose,        kmread,         kmwrite,        /*12*/
     NO_CDEVICE,                                                                /*11*/
     {
        kmopen,         kmclose,        kmread,         kmwrite,        /*12*/
-       kmioctl,        nulldev,        nulldev,        km_tty,         ttselect,
-       eno_mmap,       eno_strat,      kmgetc,         kmputc,         0
+       kmioctl,        nullstop,       nullreset,      km_tty,         ttselect,
+       eno_mmap,       eno_strat,      eno_getc,       eno_putc,       0
     },
     NO_CDEVICE,                                                                /*13*/
     NO_CDEVICE,                                                                /*14*/
     },
     NO_CDEVICE,                                                                /*13*/
     NO_CDEVICE,                                                                /*14*/
@@ -238,21 +283,20 @@ struct cdevsw     cdevsw[] =
     NO_CDEVICE,                                                                /*41*/
     {
        volopen,        volclose,       eno_rdwrt,      eno_rdwrt,      /*42*/
     NO_CDEVICE,                                                                /*41*/
     {
        volopen,        volclose,       eno_rdwrt,      eno_rdwrt,      /*42*/
-       volioctl,       eno_stop,       eno_reset,      0,              seltrue,
+       volioctl,       eno_stop,       eno_reset,      0,              (select_fcn_t *)seltrue,
        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       0
     },
 };
 int    nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
 
        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       0
     },
 };
 int    nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
 
+uint64_t cdevsw_flags[sizeof (cdevsw) / sizeof (cdevsw[0])];
 
 #include       <sys/vnode.h> /* for VCHR and VBLK */
 /*
  * return true if a disk
  */
 int
 
 #include       <sys/vnode.h> /* for VCHR and VBLK */
 /*
  * return true if a disk
  */
 int
-isdisk(dev, type)
-       dev_t dev;
-       int type;
+isdisk(dev_t dev, int type)
 {
        dev_t   maj = major(dev);
 
 {
        dev_t   maj = major(dev);
 
@@ -264,7 +308,7 @@ isdisk(dev, type)
                }
                /* FALL THROUGH */
        case VBLK:
                }
                /* FALL THROUGH */
        case VBLK:
-               if (bdevsw[maj].d_type == D_DISK) {
+               if ((D_TYPEMASK & bdevsw[maj].d_type) == D_DISK) {
                        return (1);
                }
                break;
                        return (1);
                }
                break;
@@ -281,7 +325,7 @@ static int chrtoblktab[] = {
        /*  8 */        NODEV,          /*  9 */        NODEV,
        /* 10 */        NODEV,          /* 11 */        NODEV,
        /* 12 */        NODEV,          /* 13 */        NODEV,
        /*  8 */        NODEV,          /*  9 */        NODEV,
        /* 10 */        NODEV,          /* 11 */        NODEV,
        /* 12 */        NODEV,          /* 13 */        NODEV,
-       /* 14 */        6,              /* 15 */        NODEV,
+       /* 14 */        NODEV,          /* 15 */        NODEV,
        /* 16 */        NODEV,          /* 17 */        NODEV,
        /* 18 */        NODEV,          /* 19 */        NODEV,
        /* 20 */        NODEV,          /* 21 */        NODEV,
        /* 16 */        NODEV,          /* 17 */        NODEV,
        /* 18 */        NODEV,          /* 19 */        NODEV,
        /* 20 */        NODEV,          /* 21 */        NODEV,
@@ -294,7 +338,7 @@ static int chrtoblktab[] = {
        /* 34 */        NODEV,          /* 35 */        NODEV,
        /* 36 */        NODEV,          /* 37 */        NODEV,
        /* 38 */        NODEV,          /* 39 */        NODEV,
        /* 34 */        NODEV,          /* 35 */        NODEV,
        /* 36 */        NODEV,          /* 37 */        NODEV,
        /* 38 */        NODEV,          /* 39 */        NODEV,
-       /* 40 */        NODEV,          /* 41 */        1,
+       /* 40 */        NODEV,          /* 41 */        NODEV,
        /* 42 */        NODEV,          /* 43 */        NODEV,
        /* 44 */        NODEV,
 };
        /* 42 */        NODEV,          /* 43 */        NODEV,
        /* 44 */        NODEV,
 };
@@ -303,8 +347,7 @@ static int chrtoblktab[] = {
  * convert chr dev to blk dev
  */
 dev_t
  * convert chr dev to blk dev
  */
 dev_t
-chrtoblk(dev)
-       dev_t dev;
+chrtoblk(dev_t dev)
 {
        int blkmaj;
 
 {
        int blkmaj;
 
@@ -330,9 +373,7 @@ chrtoblk_set(int cdev, int bdev)
 /*
  * Returns true if dev is /dev/mem or /dev/kmem.
  */
 /*
  * Returns true if dev is /dev/mem or /dev/kmem.
  */
-int iskmemdev(dev)
-       dev_t dev;
+int iskmemdev(dev_t dev)
 {
 {
-
        return (major(dev) == 3 && minor(dev) < 2);
 }
        return (major(dev) == 3 && minor(dev) < 2);
 }