Annotation of XNU/bsd/dev/ppc/km.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: /*     Copyright (c) 1992 NeXT Computer, Inc.  All rights reserved. 
        !            23:  *
        !            24:  * km.m - kernel keyboard/monitor module, procedural interface.
        !            25:  *
        !            26:  * HISTORY
        !            27:  */
        !            28: 
        !            29: #include <sys/param.h>
        !            30: #include <sys/tty.h>
        !            31: 
        !            32: #include <dev/ppc/cons.h>
        !            33: #include <sys/conf.h>
        !            34: #include <sys/systm.h>
        !            35: #include <sys/uio.h>
        !            36: #include <sys/fcntl.h>         /* for kmopen */
        !            37: #include <sys/errno.h>         
        !            38: #include <sys/proc.h>          /* for kmopen */
        !            39: #include <sys/msgbuf.h>
        !            40: #include <sys/time.h>
        !            41: #include <dev/kmreg_com.h>
        !            42: #include <pexpert/pexpert.h>
        !            43: 
        !            44: struct ConsoleSize {
        !            45:     unsigned short     rows;
        !            46:     unsigned short     cols;
        !            47:     unsigned short     pixel_width;
        !            48:     unsigned short     pixel_height;
        !            49: };
        !            50: 
        !            51: /*
        !            52:  * 'Global' variables, shared only by this file and conf.c.
        !            53:  */
        !            54: extern struct tty      cons;
        !            55: struct tty *km_tty[1] = { &cons };
        !            56: 
        !            57: int disableConsoleOutput;
        !            58: 
        !            59: /*
        !            60:  * 'Global' variables, shared only by this file and kmDevice.m.
        !            61:  */
        !            62: int initialized = 0;
        !            63: 
        !            64: static int kmoutput(struct tty *tp);
        !            65: static void kmstart(struct tty *tp);
        !            66: 
        !            67: extern void KeyboardOpen(void);
        !            68: 
        !            69: int kminit()
        !            70: {
        !            71:         cons.t_dev = makedev(12, 0);
        !            72:        initialized = 1;
        !            73: }
        !            74: /*
        !            75:  * cdevsw interface to km driver.
        !            76:  */
        !            77: int 
        !            78: kmopen(
        !            79:        dev_t dev, 
        !            80:        int flag,
        !            81:        int devtype, 
        !            82:        struct proc *pp)
        !            83: {
        !            84:        int rtn;
        !            85:        int unit;
        !            86:        struct tty *tp;
        !            87:        struct winsize *wp;
        !            88:        struct ConsoleSize size;
        !            89:        int ret;
        !            90:        
        !            91:        unit = minor(dev);
        !            92:        if(unit >= 1)
        !            93:                return (ENXIO);
        !            94: 
        !            95:        tp = (struct tty *)&cons;
        !            96:        tp->t_oproc = kmstart;
        !            97:        tp->t_param = NULL;
        !            98:        tp->t_dev = dev;
        !            99:        
        !           100:        if ( !(tp->t_state & TS_ISOPEN) ) {
        !           101:                tp->t_iflag = TTYDEF_IFLAG;
        !           102:                tp->t_oflag = TTYDEF_OFLAG;
        !           103:                tp->t_cflag = (CREAD | CS8 | CLOCAL);
        !           104:                tp->t_lflag = TTYDEF_LFLAG;
        !           105:                tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
        !           106:                termioschars(&tp->t_termios);
        !           107:                ttsetwater(tp);
        !           108:        } else if ((tp->t_state & TS_XCLUDE) && pp->p_ucred->cr_uid != 0)
        !           109:                return EBUSY;
        !           110: 
        !           111:        tp->t_state |= TS_CARR_ON; /* lie and say carrier exists and is on. */
        !           112:        ret = ((*linesw[tp->t_line].l_open)(dev, tp));
        !           113: #if FIXME
        !           114:        if (ret == 0) {
        !           115:                (*basicConsole->GetSize)(basicConsole, &size);
        !           116:                wp = &tp->t_winsize;
        !           117:                wp->ws_row = size.rows;
        !           118:                wp->ws_col = size.cols;
        !           119:                wp->ws_xpixel = size.pixel_width;
        !           120:                wp->ws_ypixel = size.pixel_height;
        !           121:        }
        !           122:        KeyboardOpen();
        !           123: #else /* FIXME */
        !           124:                wp = &tp->t_winsize;
        !           125:                wp->ws_row = 24;
        !           126:                wp->ws_col = 80;
        !           127:                wp->ws_xpixel = 10;
        !           128:                wp->ws_ypixel = 12;
        !           129:                if (flag & O_POPUP)
        !           130:                     PE_initialize_console( 0, kPETextScreen);
        !           131: #endif /* FIXME */
        !           132: 
        !           133:        return ret;
        !           134: }
        !           135: 
        !           136: int 
        !           137: kmclose(
        !           138:        dev_t dev, 
        !           139:        int flag,
        !           140:        int mode,
        !           141:        struct proc *p)
        !           142: {
        !           143:         
        !           144:        struct tty *tp;
        !           145: 
        !           146:        tp = &cons;
        !           147:        (*linesw[tp->t_line].l_close)(tp,flag);
        !           148:        ttyclose(tp);
        !           149:        return (0);
        !           150: }
        !           151: 
        !           152: int 
        !           153: kmread(
        !           154:        dev_t dev, 
        !           155:        struct uio *uio,
        !           156:        int ioflag)
        !           157: {
        !           158:        register struct tty *tp;
        !           159:  
        !           160:        tp = &cons;
        !           161:        return ((*linesw[tp->t_line].l_read)(tp, uio, ioflag));
        !           162: }
        !           163: 
        !           164: int 
        !           165: kmwrite(
        !           166:        dev_t dev, 
        !           167:        struct uio *uio,
        !           168:        int ioflag)
        !           169: {
        !           170:        register struct tty *tp;
        !           171:  
        !           172:        tp = &cons;
        !           173:        return ((*linesw[tp->t_line].l_write)(tp, uio, ioflag));
        !           174: }
        !           175: 
        !           176: int 
        !           177: kmioctl(
        !           178:        dev_t dev, 
        !           179:        int cmd, 
        !           180:        caddr_t data, 
        !           181:        int flag,
        !           182:        struct proc *p)
        !           183: {
        !           184:        int error;
        !           185:        struct tty *tp = &cons;
        !           186:        struct ConsoleSize size;
        !           187:        struct winsize *wp;
        !           188:        
        !           189:        switch (cmd) {
        !           190:                
        !           191: 
        !           192: 
        !           193:            case KMIOCSIZE:
        !           194:                wp = (struct winsize *)data;
        !           195:                wp->ws_row = 24;
        !           196:                wp->ws_col = 80;
        !           197:                wp->ws_xpixel = 10;
        !           198:                wp->ws_ypixel = 12;
        !           199:                return 0;
        !           200:                
        !           201:            case TIOCSWINSZ:
        !           202:                /* Prevent changing of console size --
        !           203:                 * this ensures that login doesn't revert to the
        !           204:                 * termcap-defined size
        !           205:                 */
        !           206:                return EINVAL;
        !           207: 
        !           208:            /* Bodge in the CLOCAL flag as the km device is always local */
        !           209:            case TIOCSETA:
        !           210:            case TIOCSETAW:
        !           211:            case TIOCSETAF: {
        !           212:                register struct termios *t = (struct termios *)data;
        !           213:                t->c_cflag |= CLOCAL;
        !           214:                /* No Break */
        !           215:            }
        !           216:            default:            
        !           217:                error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
        !           218:                if (error >= 0) {
        !           219:                        return error;
        !           220:                }
        !           221:                error = ttioctl (tp, cmd, data, flag, p);
        !           222:                if (error >= 0) {
        !           223:                        return error;
        !           224:                }
        !           225:                else {
        !           226:                        return ENOTTY;
        !           227:                }
        !           228:        }
        !           229: }
        !           230: 
        !           231: int 
        !           232: kmputc(
        !           233:        int c)
        !           234: {
        !           235: 
        !           236:        if( disableConsoleOutput)
        !           237:            return( 0);
        !           238:        
        !           239:         if(!initialized)
        !           240:             return( 0);
        !           241: 
        !           242:         if(c == '\n')
        !           243:             cnputcusr('\r');
        !           244: 
        !           245:         cnputcusr(c);
        !           246: 
        !           247:        return 0;
        !           248: }
        !           249: 
        !           250: int 
        !           251: kmgetc(
        !           252:        dev_t dev)
        !           253: {
        !           254:        extern int cnecho(char c);
        !           255:        int c;
        !           256:        
        !           257:        c= cngetc();
        !           258: 
        !           259:        if (c == '\r') {
        !           260:                c = '\n';
        !           261:        }
        !           262:        cnputcusr(c);
        !           263:        return c;
        !           264: }
        !           265: 
        !           266: int 
        !           267: kmgetc_silent(
        !           268:        dev_t dev)
        !           269: {
        !           270:        int c;
        !           271:        
        !           272:        c= cngetc();
        !           273:        if (c == '\r') {
        !           274:                c = '\n';
        !           275:        }
        !           276:        return c;
        !           277: }
        !           278: 
        !           279: /*
        !           280:  * Callouts from linesw.
        !           281:  */
        !           282:  
        !           283: #define KM_LOWAT_DELAY ((ns_time_t)1000)
        !           284: 
        !           285: static void 
        !           286: kmstart(
        !           287:        struct tty *tp)
        !           288: {
        !           289:        extern int hz;
        !           290:        if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
        !           291:                goto out;
        !           292:        if (tp->t_outq.c_cc == 0)
        !           293:                goto out;
        !           294:        tp->t_state |= TS_BUSY;
        !           295:        if (tp->t_outq.c_cc > tp->t_lowat) {
        !           296:                /*
        !           297:                 * Start immediately.
        !           298:                 */
        !           299:                kmoutput(tp);
        !           300:        }
        !           301:        else {
        !           302:                /*
        !           303:                 * Wait a bit...
        !           304:                 */
        !           305: #if 0
        !           306:                /* FIXME */
        !           307:                timeout(kmoutput, tp, hz);
        !           308: #else
        !           309:                kmoutput(tp);
        !           310: #endif
        !           311:        }
        !           312: out:
        !           313:        ttwwakeup(tp);
        !           314: }
        !           315: 
        !           316: static int 
        !           317: kmoutput(
        !           318:        struct tty *tp)
        !           319: {
        !           320:        /*
        !           321:         * FIXME - to be grokked...copied from m68k km.c.
        !           322:         */
        !           323:        char            buf[80];
        !           324:        char            *cp;
        !           325:        int             cc = -1;
        !           326: 
        !           327:        extern int hz;
        !           328:        while (tp->t_outq.c_cc > 0) {
        !           329:                cc = ndqb(&tp->t_outq, 0);
        !           330:                if (cc == 0)
        !           331:                        break;
        !           332:                cc = min(cc, sizeof buf);
        !           333:                (void) q_to_b(&tp->t_outq, buf, cc);
        !           334:                for (cp = buf; cp < &buf[cc]; cp++) {
        !           335:                    kmputc(*cp & 0x7f);
        !           336:                }
        !           337:        }
        !           338:         if (tp->t_outq.c_cc > 0) {
        !           339:                timeout(kmoutput, tp, hz);
        !           340:        }
        !           341:        tp->t_state &= ~TS_BUSY;
        !           342:        ttwwakeup(tp);
        !           343:        return 0;
        !           344: }
        !           345: cons_cinput(char ch)
        !           346: {
        !           347:        struct tty *tp = &cons;
        !           348:        
        !           349:        (*linesw[tp->t_line].l_rint) (ch, tp);
        !           350: }
        !           351: 

unix.superglobalmegacorp.com

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