Home | History | Annotate | Line # | Download | only in vsa
dz_vsbus.c revision 1.39
      1 /*	$NetBSD: dz_vsbus.c,v 1.39 2008/03/11 05:34:03 matt Exp $ */
      2 /*
      3  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed at Ludd, University of
     17  *      Lule}, Sweden and its contributors.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: dz_vsbus.c,v 1.39 2008/03/11 05:34:03 matt Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/proc.h>
     38 #include <sys/systm.h>
     39 #include <sys/ioctl.h>
     40 #include <sys/tty.h>
     41 #include <sys/file.h>
     42 #include <sys/conf.h>
     43 #include <sys/device.h>
     44 #include <sys/reboot.h>
     45 
     46 #include <dev/cons.h>
     47 
     48 #include <machine/mtpr.h>
     49 #include <machine/sid.h>
     50 #include <machine/uvax.h>
     51 #include <machine/vsbus.h>
     52 #include <machine/cpu.h>
     53 #include <machine/scb.h>
     54 
     55 #include <arch/vax/vax/gencons.h>
     56 
     57 #include <dev/dec/dzreg.h>
     58 #include <dev/dec/dzvar.h>
     59 
     60 #include "ioconf.h"
     61 #include "locators.h"
     62 #include "dzkbd.h"
     63 #include "dzms.h"
     64 #include "opt_cputype.h"
     65 
     66 #if NDZKBD > 0 || NDZMS > 0
     67 #include <dev/dec/dzkbdvar.h>
     68 
     69 #if 0
     70 static	struct dz_linestate dz_conslinestate = { NULL, -1, NULL, NULL, NULL };
     71 #endif
     72 #endif
     73 
     74 static  int     dz_vsbus_match(device_t, cfdata_t, void *);
     75 static  void    dz_vsbus_attach(device_t, device_t, void *);
     76 
     77 static	vaddr_t dz_regs; /* Used for console */
     78 
     79 CFATTACH_DECL(dz_vsbus, sizeof(struct dz_softc),
     80     dz_vsbus_match, dz_vsbus_attach, NULL, NULL);
     81 
     82 #define REG(name)     short name; short X##name##X;
     83 static volatile struct ss_dz {/* base address of DZ-controller: 0x200A0000 */
     84 	REG(csr);	/* 00 Csr: control/status register */
     85 	REG(rbuf);	/* 04 Rbuf/Lpr: receive buffer/line param reg. */
     86 	REG(tcr);	/* 08 Tcr: transmit console register */
     87 	REG(tdr);	/* 0C Msr/Tdr: modem status reg/transmit data reg */
     88 	REG(lpr0);	/* 10 Lpr0: */
     89 	REG(lpr1);	/* 14 Lpr0: */
     90 	REG(lpr2);	/* 18 Lpr0: */
     91 	REG(lpr3);	/* 1C Lpr0: */
     92 } *dz;
     93 #undef REG
     94 
     95 cons_decl(dz);
     96 
     97 #if NDZKBD > 0 || NDZMS > 0
     98 static int
     99 dz_print(void *aux, const char *name)
    100 {
    101 #if 0
    102 #if NDZKBD > 0 || NDZMS > 0
    103 	struct dz_attach_args *dz_args = aux;
    104 	if (name == NULL) {
    105 		aprint_normal (" line %d", dz_args->line);
    106 		if (dz_args->hwflags & DZ_HWFLAG_CONSOLE)
    107 			aprint_normal (" (console)");
    108 	}
    109 	return (QUIET);
    110 #else
    111 	if (name)
    112 		aprint_normal ("lkc at %s", name);
    113 	return (UNCONF);
    114 #endif
    115 #endif
    116 	return (UNCONF);
    117 }
    118 #endif
    119 
    120 static int
    121 dz_vsbus_match(device_t parent, cfdata_t cf, void *aux)
    122 {
    123 	struct vsbus_attach_args * const va = aux;
    124 	struct ss_dz *dzP;
    125 	short i;
    126 
    127 #if VAX53 || VAX49 || VAXANY
    128 	if (vax_boardtype == VAX_BTYP_53 || vax_boardtype == VAX_BTYP_49)
    129 		if (cf->cf_loc[VSBUSCF_CSR] != 0x25000000)
    130 			return 0; /* Ugly */
    131 #endif
    132 
    133 	dzP = (struct ss_dz *)va->va_addr;
    134 	i = dzP->tcr;
    135 	dzP->csr = DZ_CSR_MSE|DZ_CSR_TXIE;
    136 	dzP->tcr = 0;
    137 	DELAY(1000);
    138 	dzP->tcr = 1;
    139 	DELAY(100000);
    140 	dzP->tcr = i;
    141 
    142 	/* If the device doesn't exist, no interrupt has been generated */
    143 	return 1;
    144 }
    145 
    146 static void
    147 dz_vsbus_attach(device_t parent, device_t self, void *aux)
    148 {
    149 	struct dz_softc * const sc = device_private(self);
    150 	struct vsbus_attach_args * const va = aux;
    151 #if NDZKBD > 0
    152 	extern const struct cdevsw dz_cdevsw;
    153 #endif
    154 #if NDZKBD > 0 || NDZMS > 0
    155 	struct dzkm_attach_args daa;
    156 #endif
    157 	int s, consline;
    158 
    159 	/*
    160 	 * XXX - This is evil and ugly, but...
    161 	 * due to the nature of how bus_space_* works on VAX, this will
    162 	 * be perfectly good until everything is converted.
    163 	 */
    164 	if (dz_regs == 0) /* This isn't console */ {
    165 		dz_regs = vax_map_physmem(va->va_paddr, 1);
    166 		consline = -1;
    167 	} else
    168 		consline = minor(cn_tab->cn_dev);
    169 	sc->sc_ioh = dz_regs;
    170 	sc->sc_dr.dr_csr = 0;
    171 	sc->sc_dr.dr_rbuf = 4;
    172 	sc->sc_dr.dr_dtr = 9;
    173 	sc->sc_dr.dr_break = 13;
    174 	sc->sc_dr.dr_tbuf = 12;
    175 	sc->sc_dr.dr_tcr = 8;
    176 	sc->sc_dr.dr_dcd = 13;
    177 	sc->sc_dr.dr_ring = 13;
    178 
    179 	sc->sc_dr.dr_firstreg = 0;
    180 	sc->sc_dr.dr_winsize = 14;
    181 
    182 	sc->sc_type = DZ_DZV;
    183 
    184 	sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
    185 
    186 	scb_vecalloc(va->va_cvec, dzxint, sc, SCB_ISTACK, &sc->sc_tintrcnt);
    187 	scb_vecalloc(va->va_cvec - 4, dzrint, sc, SCB_ISTACK, &sc->sc_rintrcnt);
    188 
    189 	aprint_normal("\n");
    190 	aprint_normal_dev(self, "4 lines");
    191 
    192 	dzattach(sc, NULL, consline);
    193 	DELAY(10000);
    194 
    195 	if (consline != -1)
    196 		cn_set_magic("\033D"); /* set VAX DDB escape sequence */
    197 
    198 #if NDZKBD > 0
    199 	/* Don't touch this port if this is the console */
    200 	if (cn_tab->cn_dev != makedev(cdevsw_lookup_major(&dz_cdevsw), 0)) {
    201 		dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8)
    202 		    | DZ_LPR_8_BIT_CHAR;
    203 		daa.daa_line = 0;
    204 		daa.daa_flags =
    205 		    (cn_tab->cn_pri == CN_INTERNAL ? DZKBD_CONSOLE : 0);
    206 		config_found(self, &daa, dz_print);
    207 	}
    208 #endif
    209 #if NDZMS > 0
    210 	dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8) | DZ_LPR_8_BIT_CHAR \
    211 	    | DZ_LPR_PARENB | DZ_LPR_OPAR | 1 /* line */;
    212 	daa.daa_line = 1;
    213 	daa.daa_flags = 0;
    214 	config_found(self, &daa, dz_print);
    215 #endif
    216 	s = spltty();
    217 	dzrint(sc);
    218 	dzxint(sc);
    219 	splx(s);
    220 }
    221 
    222 int
    223 dzcngetc(dev_t dev)
    224 {
    225 	int c = 0, s;
    226 	int mino = minor(dev);
    227 	u_short rbuf;
    228 
    229 	s = spltty();
    230 	do {
    231 		while ((dz->csr & 0x80) == 0)
    232 			; /* Wait for char */
    233 		rbuf = dz->rbuf;
    234 		if (((rbuf >> 8) & 3) != mino)
    235 			continue;
    236 		c = rbuf & 0x7f;
    237 	} while (c == 17 || c == 19);		/* ignore XON/XOFF */
    238 	splx(s);
    239 
    240 	if (c == 13)
    241 		c = 10;
    242 
    243 	return (c);
    244 }
    245 
    246 void
    247 dzcnprobe(struct consdev *cndev)
    248 {
    249 	extern	vaddr_t iospace;
    250 	int diagcons;
    251 	paddr_t ioaddr = 0x200A0000;
    252 	extern const struct cdevsw dz_cdevsw;
    253 
    254 	switch (vax_boardtype) {
    255 	case VAX_BTYP_410:
    256 	case VAX_BTYP_420:
    257 	case VAX_BTYP_43:
    258 		diagcons = (vax_confdata & 0x20 ? 3 : 0);
    259 		break;
    260 
    261 	case VAX_BTYP_46:
    262 	case VAX_BTYP_48:
    263 		diagcons = (vax_confdata & 0x100 ? 3 : 0);
    264 		break;
    265 
    266 	case VAX_BTYP_49:
    267 		ioaddr = 0x25000000;
    268 		diagcons = (vax_confdata & 8 ? 3 : 0);
    269 		break;
    270 
    271 	case VAX_BTYP_53:
    272 		ioaddr = 0x25000000;
    273 		diagcons = 3;
    274 		break;
    275 
    276 	default:
    277 		cndev->cn_pri = CN_DEAD;
    278 		return;
    279 	}
    280 	if (diagcons)
    281 		cndev->cn_pri = CN_REMOTE;
    282 	else
    283 		cndev->cn_pri = CN_NORMAL;
    284 	cndev->cn_dev = makedev(cdevsw_lookup_major(&dz_cdevsw), diagcons);
    285 	dz_regs = iospace;
    286 	dz = (void *)dz_regs;
    287 	ioaccess(iospace, ioaddr, 1);
    288 }
    289 
    290 void
    291 dzcninit(struct consdev *cndev)
    292 {
    293 	dz = (void*)dz_regs;
    294 
    295 	dz->csr = 0;    /* Disable scanning until initting is done */
    296 	dz->tcr = (1 << minor(cndev->cn_dev));    /* Turn on xmitter */
    297 	dz->csr = 0x20; /* Turn scanning back on */
    298 }
    299 
    300 
    301 void
    302 dzcnputc(dev_t dev, int	ch)
    303 {
    304 	int timeout = 1<<15;            /* don't hang the machine! */
    305 	int mino = minor(dev);
    306 	int s;
    307 	u_short tcr;
    308 
    309 	if (mfpr(PR_MAPEN) == 0)
    310 		return;
    311 
    312 	s = spltty();
    313 	tcr = dz->tcr;	/* remember which lines to scan */
    314 	dz->tcr = (1 << mino);
    315 
    316 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    317 		if (--timeout < 0)
    318 			break;
    319 	dz->tdr = ch;                    /* Put the  character */
    320 	timeout = 1<<15;
    321 	while ((dz->csr & 0x8000) == 0) /* Wait until ready */
    322 		if (--timeout < 0)
    323 			break;
    324 
    325 	dz->tcr = tcr;
    326 	splx(s);
    327 }
    328 
    329 void
    330 dzcnpollc(dev_t dev, int pollflag)
    331 {
    332 	static	u_char mask;
    333 
    334 	if (pollflag)
    335 		mask = vsbus_setmask(0);
    336 	else
    337 		vsbus_setmask(mask);
    338 }
    339 
    340 #if NDZKBD > 0 || NDZMS > 0
    341 int
    342 dzgetc(struct dz_linestate *ls)
    343 {
    344 	int line = ls->dz_line;
    345 	int s;
    346 	u_short rbuf;
    347 
    348 	s = spltty();
    349 	for (;;) {
    350 		for(; (dz->csr & DZ_CSR_RX_DONE) == 0;);
    351 		rbuf = dz->rbuf;
    352 		if (((rbuf >> 8) & 3) == line) {
    353 			splx(s);
    354 			return (rbuf & 0xff);
    355 		}
    356 	}
    357 }
    358 
    359 void
    360 dzputc(struct dz_linestate *ls, int ch)
    361 {
    362 	int line;
    363 	u_short tcr;
    364 	int s;
    365 	extern const struct cdevsw dz_cdevsw;
    366 
    367 	/* if the dz has already been attached, the MI
    368 	   driver will do the transmitting: */
    369 	if (ls && ls->dz_sc) {
    370 		s = spltty();
    371 		line = ls->dz_line;
    372 		putc(ch, &ls->dz_tty->t_outq);
    373 		tcr = dz->tcr;
    374 		if (!(tcr & (1 << line)))
    375 			dz->tcr = tcr | (1 << line);
    376 		dzxint(ls->dz_sc);
    377 		splx(s);
    378 		return;
    379 	}
    380 
    381 	/* use dzcnputc to do the transmitting: */
    382 	dzcnputc(makedev(cdevsw_lookup_major(&dz_cdevsw), 0), ch);
    383 }
    384 #endif /* NDZKBD > 0 || NDZMS > 0 */
    385