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