Annotation of kernel/machdep/ppc/serial_console.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /* 
        !            26:  * Mach Operating System
        !            27:  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
        !            28:  * All Rights Reserved.
        !            29:  * 
        !            30:  * Permission to use, copy, modify and distribute this software and its
        !            31:  * documentation is hereby granted, provided that both the copyright
        !            32:  * notice and this permission notice appear in all copies of the
        !            33:  * software, derivative works or modified versions, and any portions
        !            34:  * thereof, and that both notices appear in supporting documentation.
        !            35:  * 
        !            36:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
        !            37:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
        !            38:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
        !            39:  * 
        !            40:  * Carnegie Mellon requests users of this software to return to
        !            41:  * 
        !            42:  *  Software Distribution Coordinator  or  [email protected]
        !            43:  *  School of Computer Science
        !            44:  *  Carnegie Mellon University
        !            45:  *  Pittsburgh PA 15213-3890
        !            46:  * 
        !            47:  * any improvements or extensions that they make and grant Carnegie Mellon
        !            48:  * the rights to redistribute these changes.
        !            49:  */
        !            50: /*
        !            51:  */
        !            52: /*
        !            53:  *     File: serial_console.c
        !            54:  *     Author: Alessandro Forin, Carnegie Mellon University
        !            55:  *     Date:   7/91
        !            56:  *
        !            57:  *     Console driver for serial-line based consoles.
        !            58:  */
        !            59: 
        !            60: #include <platforms.h>
        !            61: #include <serial_console_default.h>
        !            62: 
        !            63: #include <mach_kdb.h>
        !            64: #include <kern/spl.h>
        !            65: #include <machine/machparam.h>         /* spl definitions */
        !            66: #include <types.h>
        !            67: #include <device/io_req.h>
        !            68: #include <device/tty.h>
        !            69: #include <device/conf.h>
        !            70: #include <sys/syslog.h>
        !            71: #include <chips/busses.h>
        !            72: #include <chips/serial_console_entries.h>
        !            73: #include <ppc/screen_defs.h>
        !            74: #include <ppc/misc_protos.h>
        !            75: #include <ppc/POWERMAC/video_console_entries.h>
        !            76: #include <ppc/screen_switch.h>
        !            77: 
        !            78: /*
        !            79:  * A machine MUST have a console.  In our case
        !            80:  * things are a little complicated by the graphic
        !            81:  * display: people expect it to be their "console",
        !            82:  * but we'd like to be able to live without it.
        !            83:  * This is not to be confused with the "rconsole" thing:
        !            84:  * that just duplicates the console I/O to
        !            85:  * another place (for debugging/logging purposes).
        !            86:  */
        !            87: 
        !            88: const int console_unit = 0;
        !            89: const int console_chan = CONSOLE_PORT;
        !            90: 
        !            91: #if MACH_KGDB
        !            92: void no_spl_vcputc(char), no_spl_scputc(char);
        !            93: int no_spl_vcgetc(void), no_spl_scgetc(void);
        !            94: 
        !            95: #define OPS(putc, getc, nosplputc, nosplgetc) putc, getc, nosplputc, nosplgetc
        !            96: 
        !            97: #else
        !            98: 
        !            99: #define OPS(putc, getc, nosplputc, nosplgetc) putc, getc
        !           100: 
        !           101: #endif /* MACH_KGDB */
        !           102: 
        !           103: const struct console_ops {
        !           104:        int     (*putc)(int, int, int);
        !           105:        int     (*getc)(int, int, boolean_t, boolean_t);
        !           106: #if MACH_KGDB
        !           107:        void    (*no_spl_putc)(char);   /* Must not do splwhatever(). */
        !           108:        int     (*no_spl_getc)(void);   /* Must not do splwhatever(). */
        !           109: #endif
        !           110: } cons_ops[] = {
        !           111: #define SCC_CONS_OPS 0
        !           112:        {OPS(scc_putc, scc_getc, no_spl_scputc, no_spl_scgetc)},
        !           113: #define VC_CONS_OPS 1
        !           114:        {OPS(vcputc, vcgetc, no_spl_vcputc, no_spl_vcgetc)},
        !           115: };
        !           116: #define NCONSOPS (sizeof cons_ops / sizeof cons_ops[0])
        !           117: 
        !           118: #if SERIAL_CONSOLE_DEFAULT
        !           119: #define CONS_OPS SCC_CONS_OPS
        !           120: #define CONS_NAME "com"
        !           121: #else
        !           122: #define CONS_OPS VC_CONS_OPS
        !           123: #define CONS_NAME "vc"
        !           124: #endif
        !           125: unsigned int cons_ops_index = CONS_OPS;
        !           126: 
        !           127: void
        !           128: m3_cnputc(char c)
        !           129: {
        !           130:        cons_ops[cons_ops_index].putc(console_unit, console_chan, c);
        !           131:        if (c == '\n')
        !           132:                cnputc('\r');
        !           133: }
        !           134: 
        !           135: int
        !           136: m3_cngetc()
        !           137: {
        !           138:        return cons_ops[cons_ops_index].getc(console_unit, console_chan,
        !           139:                                             TRUE, FALSE);
        !           140: }
        !           141: 
        !           142: #if MACH_KGDB
        !           143: void
        !           144: kgdb_putc(char c)
        !           145: {
        !           146:        no_spl_scc_putc(KGDB_PORT, c);
        !           147: }
        !           148: 
        !           149: int
        !           150: kgdb_getc(boolean_t timeout)
        !           151: {
        !           152:        return no_spl_scc_getc(KGDB_PORT, timeout);
        !           153: }
        !           154: 
        !           155: void
        !           156: no_spl_putc(char c)
        !           157: {
        !           158:        cons_ops[cons_ops_index].no_spl_putc(c);
        !           159:        if (c == '\n')
        !           160:                cons_ops[cons_ops_index].no_spl_putc('\r');
        !           161: }
        !           162: 
        !           163: int
        !           164: no_spl_getc()
        !           165: {
        !           166:        return cons_ops[cons_ops_index].no_spl_getc();
        !           167: }
        !           168: 
        !           169: void
        !           170: no_spl_scputc(char c)
        !           171: {
        !           172:        no_spl_scc_putc(CONSOLE_PORT, c);
        !           173: }
        !           174: 
        !           175: int
        !           176: no_spl_scgetc()
        !           177: {
        !           178:        return no_spl_scc_getc(CONSOLE_PORT, FALSE);
        !           179: }
        !           180: 
        !           181: void
        !           182: no_spl_vcputc(char c)
        !           183: {
        !           184:        vc_putchar(c);
        !           185: }
        !           186: 
        !           187: int
        !           188: no_spl_vcgetc()
        !           189: {
        !           190:        return( kmtrygetc());
        !           191: //     return vcgetc(0, 0, TRUE, FALSE);
        !           192: }
        !           193: #endif /* MACH_KGDB */
        !           194: 
        !           195: int    
        !           196: vcputc(int a, int b, int c)
        !           197: {
        !           198:        return( kmputc( c));
        !           199: }
        !           200: 
        !           201: int    
        !           202: vcgetc(int a, int b, boolean_t c, boolean_t d)
        !           203: {
        !           204:        return( kmgetc());
        !           205: }
        !           206: 
        !           207: int
        !           208: switch_to_video_console()
        !           209: {
        !           210:        int old_cons_ops = cons_ops_index;
        !           211:        cons_ops_index = VC_CONS_OPS;
        !           212:        return old_cons_ops;
        !           213: }
        !           214: 
        !           215: int
        !           216: switch_to_serial_console()
        !           217: {
        !           218:        int old_cons_ops = cons_ops_index;
        !           219:        cons_ops_index = SCC_CONS_OPS;
        !           220:        return old_cons_ops;
        !           221: }
        !           222: 
        !           223: /* The switch_to_{video,serial,kgdb}_console functions return a cookie that
        !           224:    can be used to restore the console to whatever it was before, in the
        !           225:    same way that splwhatever() and splx() work.  */
        !           226: void
        !           227: switch_to_old_console(int old_console)
        !           228: {
        !           229:        static boolean_t squawked;
        !           230:        unsigned int ops = old_console;
        !           231: 
        !           232:        if (ops >= NCONSOPS && !squawked) {
        !           233:                squawked = TRUE;
        !           234:                printf("switch_to_old_console: unknown ops %d\n", ops);
        !           235:        } else
        !           236:                cons_ops_index = ops;
        !           237: }
        !           238: 
        !           239: /*
        !           240:  * This is basically a special form of autoconf,
        !           241:  * to get printf() going before true autoconf.
        !           242:  */
        !           243: int
        !           244: cons_find(boolean_t tube)
        !           245: {
        !           246:        register int             i;
        !           247:        struct tty              *tp;
        !           248: 
        !           249:        extern struct dev_ops dev_name_list[];
        !           250:        extern int dev_name_count;
        !           251:        extern struct dev_indirect dev_indirect_list[];
        !           252: 
        !           253:        /* Set up indirect console device */
        !           254: 
        !           255:        for (i = 0; i < dev_name_count; i++) {
        !           256:                if (strcmp(dev_name_list[i].d_name, CONS_NAME) == 0) {
        !           257:                        dev_indirect_list[0].d_ops = &dev_name_list[i];
        !           258:                        break;
        !           259:                }
        !           260:        }
        !           261: 
        !           262:        return  1;
        !           263: }

unix.superglobalmegacorp.com

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