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