Annotation of XNU/bsd/dev/ppc/conf.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /*
        !            23:  * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
        !            24:  * Copyright (c) 1993 NeXT Computer, Inc.
        !            25:  *
        !            26:  * UNIX Device switch tables.
        !            27:  *
        !            28:  * HISTORY
        !            29:  *
        !            30:  * 30 July 1997 Umesh Vaishampayan ([email protected])
        !            31:  *     enabled file descriptor pseudo-device.
        !            32:  * 18 June 1993 ? at NeXT
        !            33:  *     Cleaned up a lot of stuff in this file.
        !            34:  */
        !            35: 
        !            36: #include <sys/param.h>
        !            37: #include <sys/systm.h>
        !            38: #include <sys/buf.h>
        !            39: #include <sys/ioctl.h>
        !            40: #include <sys/tty.h>
        !            41: #include <sys/conf.h>
        !            42: 
        !            43: 
        !            44: extern int     nulldev();
        !            45: 
        !            46: struct bdevsw  bdevsw[] =
        !            47: {
        !            48:        /*
        !            49:         *      For block devices, every other block of 8 slots is 
        !            50:         *      reserved to NeXT.  The other slots are available for
        !            51:         *      the user.  This way we can both add new entries without
        !            52:         *      running into each other.  Be sure to fill in NeXT's
        !            53:         *      8 reserved slots when you jump over us -- we'll do the
        !            54:         *      same for you.
        !            55:         */
        !            56: 
        !            57:        /* 0 - 7 are reserved to NeXT */
        !            58: 
        !            59:        NO_BDEVICE,                                                     /* 0*/
        !            60:        NO_BDEVICE,                                                     /* 1*/
        !            61:        NO_BDEVICE,                                                     /* 2*/
        !            62:        NO_BDEVICE,                                                     /* 3*/
        !            63:        NO_BDEVICE,                                                     /* 4*/
        !            64:        NO_BDEVICE,                                                     /* 5*/
        !            65:        NO_BDEVICE,                                                     /* 6*/
        !            66:        NO_BDEVICE,                                                     /* 7*/
        !            67: 
        !            68:        /* 8 - 15 are reserved to the user */
        !            69:        NO_BDEVICE,                                                     /* 8*/
        !            70:        NO_BDEVICE,                                                     /* 9*/
        !            71:        NO_BDEVICE,                                                     /*10*/
        !            72:        NO_BDEVICE,                                                     /*11*/
        !            73:        NO_BDEVICE,                                                     /*12*/
        !            74:        NO_BDEVICE,                                                     /*13*/
        !            75:        NO_BDEVICE,                                                     /*14*/
        !            76:        NO_BDEVICE,                                                     /*15*/
        !            77: 
        !            78:        /* 16 - 23 are reserved to NeXT */
        !            79:        NO_BDEVICE,                                                     /*16*/
        !            80:        NO_BDEVICE,                                                     /*17*/
        !            81:        NO_BDEVICE,                                                     /*18*/
        !            82:        NO_BDEVICE,                                                     /*18*/
        !            83:        NO_BDEVICE,                                                     /*20*/
        !            84:        NO_BDEVICE,                                                     /*21*/
        !            85:        NO_BDEVICE,                                                     /*22*/
        !            86:        NO_BDEVICE,                                                     /*23*/
        !            87: };
        !            88: 
        !            89: int    nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]);
        !            90: 
        !            91: extern struct tty *km_tty[];
        !            92: extern int     consopen(), consclose(), consread(), conswrite(), consioctl(),
        !            93:                consselect(), cons_getc(), cons_putc();
        !            94: extern int     kmopen(),kmclose(),kmread(),kmwrite(),kmioctl(),
        !            95:                kmgetc(), kmputc(dev_t dev, char c);
        !            96: 
        !            97: extern int     cttyopen(), cttyread(), cttywrite(), cttyioctl(), cttyselect();
        !            98: 
        !            99: extern int     mmread(),mmwrite();
        !           100: #define        mmselect        seltrue
        !           101: 
        !           102: #if 1
        !           103: #define NPTY 32
        !           104: #else /* 1 */
        !           105: #include <pty.h>
        !           106: #endif /* 1 */
        !           107: #if NPTY > 0
        !           108: extern struct tty *pt_tty[];
        !           109: extern int     ptsopen(),ptsclose(),ptsread(),ptswrite(),ptsstop(),ptsputc();
        !           110: extern int     ptcopen(),ptcclose(),ptcread(),ptcwrite(),ptcselect(),
        !           111:                ptyioctl();
        !           112: #else
        !           113: #define ptsopen                eno_opcl
        !           114: #define ptsclose       eno_opcl
        !           115: #define ptsread                eno_rdwrt
        !           116: #define ptswrite       eno_rdwrt
        !           117: #define        ptsstop         nulldev
        !           118: #define ptsputc                nulldev
        !           119: 
        !           120: #define ptcopen                eno_opcl
        !           121: #define ptcclose       eno_opcl
        !           122: #define ptcread                eno_rdwrt
        !           123: #define ptcwrite       eno_rdwrt
        !           124: #define        ptcselect       eno_select
        !           125: #define ptyioctl       eno_ioctl
        !           126: #endif
        !           127: 
        !           128: extern int     logopen(),logclose(),logread(),logioctl(),logselect();
        !           129: extern int     nvopen(),       nvclose(),nvread(),     nvwrite();
        !           130: extern int     seltrue();
        !           131: 
        !           132: struct cdevsw  cdevsw[] =
        !           133: {
        !           134:        /*
        !           135:         *      For character devices, every other block of 16 slots is
        !           136:         *      reserved to NeXT.  The other slots are available for
        !           137:         *      the user.  This way we can both add new entries without
        !           138:         *      running into each other.  Be sure to fill in NeXT's
        !           139:         *      16 reserved slots when you jump over us -- we'll do the
        !           140:         *      same for you.
        !           141:         */
        !           142: 
        !           143:        /* 0 - 15 are reserved to NeXT */
        !           144: 
        !           145:     {
        !           146:        consopen,       consclose,      consread,       conswrite,      /* 0*/
        !           147:        consioctl,      nulldev,        nulldev,        0,      consselect,
        !           148:        eno_mmap,       eno_strat,      cons_getc,      cons_putc, D_TTY
        !           149:    },
        !           150:     NO_CDEVICE,                                                                /* 1*/
        !           151:     {
        !           152:        cttyopen,       nulldev,        cttyread,       cttywrite,      /* 2*/
        !           153:        cttyioctl,      nulldev,        nulldev,        0,              cttyselect,
        !           154:        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY
        !           155:     },
        !           156:     {
        !           157:        nulldev,        nulldev,        mmread,         mmwrite,        /* 3*/
        !           158:        eno_ioctl,      nulldev,        nulldev,        0,              mmselect,
        !           159:        eno_mmap,               eno_strat,      eno_getc,       eno_putc,       0
        !           160:     },
        !           161:     {
        !           162:        ptsopen,        ptsclose,       ptsread,        ptswrite,       /* 4*/
        !           163:        ptyioctl,       ptsstop,        nulldev,        pt_tty,         ttselect,
        !           164:        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY
        !           165:     },
        !           166:     {
        !           167:        ptcopen,        ptcclose,       ptcread,        ptcwrite,       /* 5*/
        !           168:        ptyioctl,       nulldev,        nulldev,        0,              ptcselect,
        !           169:        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       D_TTY
        !           170:     },
        !           171:     {
        !           172:        logopen,        logclose,       logread,        eno_rdwrt,      /* 6*/
        !           173:        logioctl,       eno_stop,       nulldev,        0,              logselect,
        !           174:        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       0
        !           175:     },
        !           176:     NO_CDEVICE,                                                                /* 7*/
        !           177:     NO_CDEVICE,                                                                /* 8*/
        !           178:     NO_CDEVICE,                                                                /* 9*/
        !           179:     NO_CDEVICE,                                                                /*10*/
        !           180:     NO_CDEVICE,                                                                /*11*/
        !           181:     {
        !           182:        kmopen,         kmclose,        kmread,         kmwrite,        /*12*/
        !           183:        kmioctl,        nulldev,        nulldev,        km_tty,         ttselect,
        !           184:        eno_mmap,       eno_strat,      kmgetc,         kmputc,         0
        !           185:     },
        !           186:     NO_CDEVICE,                                                                /*13*/
        !           187:     NO_CDEVICE,                                                                /*14*/
        !           188:     NO_CDEVICE,                                                                /*15*/
        !           189: 
        !           190:        /* 16 - 31 are reserved to the user */
        !           191:     NO_CDEVICE,                                                                /*16*/
        !           192:     NO_CDEVICE,                                                                /*17*/
        !           193:     NO_CDEVICE,                                                                /*18*/
        !           194:     NO_CDEVICE,                                                                /*19*/
        !           195:     NO_CDEVICE,                                                                /*20*/
        !           196:     NO_CDEVICE,                                                                /*21*/
        !           197:     NO_CDEVICE,                                                                /*22*/
        !           198:     NO_CDEVICE,                                                                /*23*/
        !           199:     NO_CDEVICE,                                                                /*24*/
        !           200:     NO_CDEVICE,                                                                /*25*/
        !           201:     NO_CDEVICE,                                                                /*26*/
        !           202:     NO_CDEVICE,                                                                /*27*/
        !           203:     NO_CDEVICE,                                                                /*28*/
        !           204:     NO_CDEVICE,                                                                /*29*/
        !           205:     NO_CDEVICE,                                                                /*30*/
        !           206:     NO_CDEVICE,                                                                /*31*/
        !           207: 
        !           208:        /* 32 - 47 are reserved to NeXT */
        !           209:     NO_CDEVICE,                                                                /*32*/
        !           210:     NO_CDEVICE,                                                                /*33*/
        !           211:     NO_CDEVICE,                                                                /*34*/
        !           212:     NO_CDEVICE,                                                                /*35*/
        !           213:     NO_CDEVICE,                                                                /*36*/
        !           214:     {
        !           215:        nvopen,         nvclose,        nvread,         nvwrite,        /*37*/
        !           216:        eno_ioctl,      nulldev,        nulldev,        0,              seltrue,
        !           217:        eno_mmap,       eno_strat,      eno_getc,       eno_putc,       0
        !           218:     },
        !           219:     NO_CDEVICE,                                                                /*38*/
        !           220:     NO_CDEVICE,                                                                /*39*/
        !           221:     NO_CDEVICE,                                                                /*40*/
        !           222:        /* 41 used to be for fd */
        !           223:     NO_CDEVICE,                                                                /*41*/
        !           224:     NO_CDEVICE,                                                                /*42*/
        !           225: };
        !           226: int    nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]);
        !           227: 
        !           228: 
        !           229: #include       <sys/vnode.h> /* for VCHR and VBLK */
        !           230: /*
        !           231:  * return true if a disk
        !           232:  */
        !           233: int
        !           234: isdisk(dev, type)
        !           235:        dev_t dev;
        !           236:        int type;
        !           237: {
        !           238:        switch (major(dev)) {
        !           239:        case 1: /* fd: floppy */
        !           240:        case 6: /* sd: scsi disk */
        !           241:        case 3: /* ide:  */
        !           242:                if (type == VBLK)
        !           243:                        return(1);
        !           244:                break;
        !           245:        case 14:         /* sd: scsi disk */
        !           246:        case 41: /* fd: floppy */
        !           247:                if (type == VCHR)
        !           248:                        return(1);
        !           249:                break;
        !           250:        }
        !           251:        return(0);
        !           252: }
        !           253: 
        !           254: static int chrtoblktab[] = {
        !           255:        /* CHR*/        /* BLK*/        /* CHR*/        /* BLK*/
        !           256:        /*  0 */        NODEV,          /*  1 */        NODEV,
        !           257:        /*  2 */        NODEV,          /*  3 */        NODEV,
        !           258:        /*  4 */        NODEV,          /*  5 */        NODEV,
        !           259:        /*  6 */        NODEV,          /*  7 */        NODEV,
        !           260:        /*  8 */        NODEV,          /*  9 */        NODEV,
        !           261:        /* 10 */        NODEV,          /* 11 */        NODEV,
        !           262:        /* 12 */        NODEV,          /* 13 */        NODEV,
        !           263:        /* 14 */        6,              /* 15 */        NODEV,
        !           264:        /* 16 */        NODEV,          /* 17 */        NODEV,
        !           265:        /* 18 */        NODEV,          /* 19 */        NODEV,
        !           266:        /* 20 */        NODEV,          /* 21 */        NODEV,
        !           267:        /* 22 */        NODEV,          /* 23 */        NODEV,
        !           268:        /* 24 */        NODEV,          /* 25 */        NODEV,
        !           269:        /* 26 */        NODEV,          /* 27 */        NODEV,
        !           270:        /* 28 */        NODEV,          /* 29 */        NODEV,
        !           271:        /* 30 */        NODEV,          /* 31 */        NODEV,
        !           272:        /* 32 */        NODEV,          /* 33 */        NODEV,
        !           273:        /* 34 */        NODEV,          /* 35 */        NODEV,
        !           274:        /* 36 */        NODEV,          /* 37 */        NODEV,
        !           275:        /* 38 */        NODEV,          /* 39 */        NODEV,
        !           276:        /* 40 */        NODEV,          /* 41 */        1,
        !           277:        /* 42 */        NODEV,          /* 43 */        NODEV,
        !           278:        /* 44 */        NODEV,
        !           279: };
        !           280: 
        !           281: /*
        !           282:  * convert chr dev to blk dev
        !           283:  */
        !           284: dev_t
        !           285: chrtoblk(dev)
        !           286:        dev_t dev;
        !           287: {
        !           288:        int blkmaj;
        !           289: 
        !           290:        if (major(dev) >= nchrdev)
        !           291:                return(NODEV);
        !           292:        blkmaj = chrtoblktab[major(dev)];
        !           293:        if (blkmaj == NODEV)
        !           294:                return(NODEV);
        !           295:        return(makedev(blkmaj, minor(dev)));
        !           296: }
        !           297: 
        !           298: /*
        !           299:  * Returns true if dev is /dev/mem or /dev/kmem.
        !           300:  */
        !           301: int iskmemdev(dev)
        !           302:        dev_t dev;
        !           303: {
        !           304: 
        !           305:        return (major(dev) == 3 && minor(dev) < 2);
        !           306: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.