Home | History | Annotate | Line # | Download | only in boot
cons.c revision 1.1
      1  1.1  kiyohara /*	$NetBSD: cons.c,v 1.1 2011/03/03 05:59:37 kiyohara Exp $	*/
      2  1.1  kiyohara 
      3  1.1  kiyohara /*
      4  1.1  kiyohara  * Copyright (c) 1990, 1993
      5  1.1  kiyohara  *	The Regents of the University of California.  All rights reserved.
      6  1.1  kiyohara  *
      7  1.1  kiyohara  * This code is derived from software contributed to Berkeley by
      8  1.1  kiyohara  * the Systems Programming Group of the University of Utah Computer
      9  1.1  kiyohara  * Science Department.
     10  1.1  kiyohara  *
     11  1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     12  1.1  kiyohara  * modification, are permitted provided that the following conditions
     13  1.1  kiyohara  * are met:
     14  1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     15  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     16  1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     19  1.1  kiyohara  * 3. Neither the name of the University nor the names of its contributors
     20  1.1  kiyohara  *    may be used to endorse or promote products derived from this software
     21  1.1  kiyohara  *    without specific prior written permission.
     22  1.1  kiyohara  *
     23  1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  kiyohara  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  kiyohara  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  kiyohara  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  kiyohara  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  kiyohara  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  kiyohara  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  kiyohara  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  kiyohara  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  kiyohara  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  kiyohara  * SUCH DAMAGE.
     34  1.1  kiyohara  *
     35  1.1  kiyohara  * from: Utah Hdr: cons.c 1.7 92/02/28
     36  1.1  kiyohara  *
     37  1.1  kiyohara  *	@(#)cons.c	8.1 (Berkeley) 6/10/93
     38  1.1  kiyohara  */
     39  1.1  kiyohara /*
     40  1.1  kiyohara  * Copyright (c) 1988 University of Utah.
     41  1.1  kiyohara  *
     42  1.1  kiyohara  * This code is derived from software contributed to Berkeley by
     43  1.1  kiyohara  * the Systems Programming Group of the University of Utah Computer
     44  1.1  kiyohara  * Science Department.
     45  1.1  kiyohara  *
     46  1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     47  1.1  kiyohara  * modification, are permitted provided that the following conditions
     48  1.1  kiyohara  * are met:
     49  1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     50  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     51  1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     53  1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     54  1.1  kiyohara  * 3. All advertising materials mentioning features or use of this software
     55  1.1  kiyohara  *    must display the following acknowledgement:
     56  1.1  kiyohara  *	This product includes software developed by the University of
     57  1.1  kiyohara  *	California, Berkeley and its contributors.
     58  1.1  kiyohara  * 4. Neither the name of the University nor the names of its contributors
     59  1.1  kiyohara  *    may be used to endorse or promote products derived from this software
     60  1.1  kiyohara  *    without specific prior written permission.
     61  1.1  kiyohara  *
     62  1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     63  1.1  kiyohara  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     64  1.1  kiyohara  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     65  1.1  kiyohara  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     66  1.1  kiyohara  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     67  1.1  kiyohara  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     68  1.1  kiyohara  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     69  1.1  kiyohara  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     70  1.1  kiyohara  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     71  1.1  kiyohara  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     72  1.1  kiyohara  * SUCH DAMAGE.
     73  1.1  kiyohara  *
     74  1.1  kiyohara  * from: Utah Hdr: cons.c 1.7 92/02/28
     75  1.1  kiyohara  *
     76  1.1  kiyohara  *	@(#)cons.c	8.1 (Berkeley) 6/10/93
     77  1.1  kiyohara  */
     78  1.1  kiyohara 
     79  1.1  kiyohara #include <lib/libsa/stand.h>
     80  1.1  kiyohara 
     81  1.1  kiyohara #include <machine/cpu.h>
     82  1.1  kiyohara 
     83  1.1  kiyohara #include "boot.h"
     84  1.1  kiyohara #include "cons.h"
     85  1.1  kiyohara 
     86  1.1  kiyohara #ifdef CONS_SCIF
     87  1.1  kiyohara static void scifcnprobe(struct consdev *);
     88  1.1  kiyohara static void scifcninit(struct consdev *);
     89  1.1  kiyohara static void scifcnputchar(void *, int);
     90  1.1  kiyohara static int scifcngetchar(void *);
     91  1.1  kiyohara static int scifcnscan(void *);
     92  1.1  kiyohara # include "scif.h"
     93  1.1  kiyohara # ifndef SCIFSPEED
     94  1.1  kiyohara #  define SCIFSPEED 19200
     95  1.1  kiyohara # endif
     96  1.1  kiyohara #endif
     97  1.1  kiyohara 
     98  1.1  kiyohara #ifdef CONS_COM
     99  1.1  kiyohara static void comcnprobe(struct consdev *);
    100  1.1  kiyohara static void comcninit(struct consdev *);
    101  1.1  kiyohara static void comcnputchar(void *, int);
    102  1.1  kiyohara static int comcngetchar(void *);
    103  1.1  kiyohara static int comcnscan(void *);
    104  1.1  kiyohara # include "ns16550.h"
    105  1.1  kiyohara # ifndef COMPORT
    106  1.1  kiyohara #  define COMPORT 0xa4000000
    107  1.1  kiyohara # endif
    108  1.1  kiyohara # ifndef COMSPEED
    109  1.1  kiyohara #  define COMSPEED 19200
    110  1.1  kiyohara # endif
    111  1.1  kiyohara #endif
    112  1.1  kiyohara 
    113  1.1  kiyohara static struct consdev constab[] = {
    114  1.1  kiyohara #ifdef CONS_SCIF
    115  1.1  kiyohara 	{ "scif", 0, SCIFSPEED,
    116  1.1  kiyohara 	    scifcnprobe, scifcninit, scifcngetchar, scifcnputchar, scifcnscan },
    117  1.1  kiyohara #endif
    118  1.1  kiyohara #ifdef CONS_COM
    119  1.1  kiyohara 	{ "com", 0, COMSPEED,
    120  1.1  kiyohara 	    comcnprobe, comcninit, comcngetchar, comcnputchar, comcnscan },
    121  1.1  kiyohara #endif
    122  1.1  kiyohara 	{ 0 }
    123  1.1  kiyohara };
    124  1.1  kiyohara 
    125  1.1  kiyohara static struct consdev *cn_tab;
    126  1.1  kiyohara 
    127  1.1  kiyohara char *
    128  1.1  kiyohara cninit()
    129  1.1  kiyohara {
    130  1.1  kiyohara 	register struct consdev *cp;
    131  1.1  kiyohara 
    132  1.1  kiyohara 	cn_tab = NULL;
    133  1.1  kiyohara 	for (cp = constab; cp->cn_probe; cp++) {
    134  1.1  kiyohara 		(*cp->cn_probe)(cp);
    135  1.1  kiyohara 		if (cp->cn_pri > CN_DEAD &&
    136  1.1  kiyohara 		    (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
    137  1.1  kiyohara 			cn_tab = cp;
    138  1.1  kiyohara 	}
    139  1.1  kiyohara 	if (cn_tab) {
    140  1.1  kiyohara 		(*cn_tab->cn_init)(cn_tab);
    141  1.1  kiyohara 		return cn_tab->cn_name;
    142  1.1  kiyohara 	}
    143  1.1  kiyohara 
    144  1.1  kiyohara 	return NULL;
    145  1.1  kiyohara }
    146  1.1  kiyohara 
    147  1.1  kiyohara int
    148  1.1  kiyohara cngetc(void)
    149  1.1  kiyohara {
    150  1.1  kiyohara 
    151  1.1  kiyohara 	if (cn_tab)
    152  1.1  kiyohara 		return (*cn_tab->cn_getc)(cn_tab->cn_dev);
    153  1.1  kiyohara 	return 0;
    154  1.1  kiyohara }
    155  1.1  kiyohara 
    156  1.1  kiyohara void
    157  1.1  kiyohara cnputc(int c)
    158  1.1  kiyohara {
    159  1.1  kiyohara 
    160  1.1  kiyohara 	if (cn_tab)
    161  1.1  kiyohara 		(*cn_tab->cn_putc)(cn_tab->cn_dev, c);
    162  1.1  kiyohara }
    163  1.1  kiyohara 
    164  1.1  kiyohara int
    165  1.1  kiyohara cnscan(void)
    166  1.1  kiyohara {
    167  1.1  kiyohara 
    168  1.1  kiyohara 	if (cn_tab)
    169  1.1  kiyohara 		return (*cn_tab->cn_scan)(cn_tab->cn_dev);
    170  1.1  kiyohara 	return -1;
    171  1.1  kiyohara }
    172  1.1  kiyohara 
    173  1.1  kiyohara #ifdef CONS_SCIF
    174  1.1  kiyohara /*
    175  1.1  kiyohara  * sh3 scif console
    176  1.1  kiyohara  */
    177  1.1  kiyohara static void
    178  1.1  kiyohara scifcnprobe(struct consdev *cp)
    179  1.1  kiyohara {
    180  1.1  kiyohara 
    181  1.1  kiyohara 	cp->cn_pri = CN_REMOTE;
    182  1.1  kiyohara }
    183  1.1  kiyohara 
    184  1.1  kiyohara static void
    185  1.1  kiyohara scifcninit(struct consdev *cp)
    186  1.1  kiyohara {
    187  1.1  kiyohara 
    188  1.1  kiyohara 	cp->cn_dev = scif_init(cp->speed);
    189  1.1  kiyohara }
    190  1.1  kiyohara 
    191  1.1  kiyohara static int
    192  1.1  kiyohara scifcngetchar(void *dev)
    193  1.1  kiyohara {
    194  1.1  kiyohara 
    195  1.1  kiyohara 	return scif_getc();
    196  1.1  kiyohara }
    197  1.1  kiyohara 
    198  1.1  kiyohara static void
    199  1.1  kiyohara scifcnputchar(void *dev, int c)
    200  1.1  kiyohara {
    201  1.1  kiyohara 
    202  1.1  kiyohara 	if (c == '\n')
    203  1.1  kiyohara 		scif_putc('\r');
    204  1.1  kiyohara 	scif_putc(c);
    205  1.1  kiyohara }
    206  1.1  kiyohara 
    207  1.1  kiyohara static int
    208  1.1  kiyohara scifcnscan(void *dev)
    209  1.1  kiyohara {
    210  1.1  kiyohara 
    211  1.1  kiyohara 	return scif_scankbd();
    212  1.1  kiyohara }
    213  1.1  kiyohara #endif /* CONS_SCIF */
    214  1.1  kiyohara 
    215  1.1  kiyohara #ifdef CONS_COM
    216  1.1  kiyohara /*
    217  1.1  kiyohara  * com console
    218  1.1  kiyohara  */
    219  1.1  kiyohara static void
    220  1.1  kiyohara comcnprobe(struct consdev *cp)
    221  1.1  kiyohara {
    222  1.1  kiyohara 
    223  1.1  kiyohara 	cp->cn_pri = CN_REMOTE;
    224  1.1  kiyohara }
    225  1.1  kiyohara 
    226  1.1  kiyohara static void
    227  1.1  kiyohara comcninit(struct consdev *cp)
    228  1.1  kiyohara {
    229  1.1  kiyohara 
    230  1.1  kiyohara 	cp->cn_dev = com_init(cp->address, cp->speed);
    231  1.1  kiyohara }
    232  1.1  kiyohara 
    233  1.1  kiyohara static int
    234  1.1  kiyohara comcngetchar(void *dev)
    235  1.1  kiyohara {
    236  1.1  kiyohara 
    237  1.1  kiyohara 	return com_getc(dev);
    238  1.1  kiyohara }
    239  1.1  kiyohara 
    240  1.1  kiyohara static void
    241  1.1  kiyohara comcnputchar(void *dev, int c)
    242  1.1  kiyohara {
    243  1.1  kiyohara 
    244  1.1  kiyohara 	if (c == '\n')
    245  1.1  kiyohara 		com_putc(dev, '\r');
    246  1.1  kiyohara 	com_putc(dev, c);
    247  1.1  kiyohara }
    248  1.1  kiyohara 
    249  1.1  kiyohara static int
    250  1.1  kiyohara comcnscan(void *dev)
    251  1.1  kiyohara {
    252  1.1  kiyohara 
    253  1.1  kiyohara 	return com_scankbd(dev);
    254  1.1  kiyohara }
    255  1.1  kiyohara #endif /* CONS_COM */
    256