1 /* $NetBSD: dz_vsbus.c,v 1.39 2008/03/11 05:34:03 matt Exp $ */
3 * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: dz_vsbus.c,v 1.39 2008/03/11 05:34:03 matt Exp $");
36 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/ioctl.h>
43 #include <sys/device.h>
44 #include <sys/reboot.h>
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>
55 #include <arch/vax/vax/gencons.h>
57 #include <dev/dec/dzreg.h>
58 #include <dev/dec/dzvar.h>
64 #include "opt_cputype.h"
66 #if NDZKBD > 0 || NDZMS > 0
67 #include <dev/dec/dzkbdvar.h>
70 static struct dz_linestate dz_conslinestate
= { NULL
, -1, NULL
, NULL
, NULL
};
74 static int dz_vsbus_match(device_t
, cfdata_t
, void *);
75 static void dz_vsbus_attach(device_t
, device_t
, void *);
77 static vaddr_t dz_regs
; /* Used for console */
79 CFATTACH_DECL_NEW(dz_vsbus
, sizeof(struct dz_softc
),
80 dz_vsbus_match
, dz_vsbus_attach
, NULL
, NULL
);
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: */
97 #if NDZKBD > 0 || NDZMS > 0
99 dz_print(void *aux
, const char *name
)
102 #if NDZKBD > 0 || NDZMS > 0
103 struct dz_attach_args
*dz_args
= aux
;
105 aprint_normal (" line %d", dz_args
->line
);
106 if (dz_args
->hwflags
& DZ_HWFLAG_CONSOLE
)
107 aprint_normal (" (console)");
112 aprint_normal ("lkc at %s", name
);
121 dz_vsbus_match(device_t parent
, cfdata_t cf
, void *aux
)
123 struct vsbus_attach_args
* const va
= aux
;
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)
133 dzP
= (struct ss_dz
*)va
->va_addr
;
135 dzP
->csr
= DZ_CSR_MSE
|DZ_CSR_TXIE
;
142 /* If the device doesn't exist, no interrupt has been generated */
147 dz_vsbus_attach(device_t parent
, device_t self
, void *aux
)
149 struct dz_softc
* const sc
= device_private(self
);
150 struct vsbus_attach_args
* const va
= aux
;
152 extern const struct cdevsw dz_cdevsw
;
154 #if NDZKBD > 0 || NDZMS > 0
155 struct dzkm_attach_args daa
;
161 * XXX - This is evil and ugly, but...
162 * due to the nature of how bus_space_* works on VAX, this will
163 * be perfectly good until everything is converted.
165 if (dz_regs
== 0) /* This isn't console */ {
166 dz_regs
= vax_map_physmem(va
->va_paddr
, 1);
169 consline
= minor(cn_tab
->cn_dev
);
170 sc
->sc_ioh
= dz_regs
;
171 sc
->sc_dr
.dr_csr
= 0;
172 sc
->sc_dr
.dr_rbuf
= 4;
173 sc
->sc_dr
.dr_dtr
= 9;
174 sc
->sc_dr
.dr_break
= 13;
175 sc
->sc_dr
.dr_tbuf
= 12;
176 sc
->sc_dr
.dr_tcr
= 8;
177 sc
->sc_dr
.dr_dcd
= 13;
178 sc
->sc_dr
.dr_ring
= 13;
180 sc
->sc_dr
.dr_firstreg
= 0;
181 sc
->sc_dr
.dr_winsize
= 14;
183 sc
->sc_type
= DZ_DZV
;
185 sc
->sc_dsr
= 0x0f; /* XXX check if VS has modem ctrl bits */
187 scb_vecalloc(va
->va_cvec
, dzxint
, sc
, SCB_ISTACK
, &sc
->sc_tintrcnt
);
188 scb_vecalloc(va
->va_cvec
- 4, dzrint
, sc
, SCB_ISTACK
, &sc
->sc_rintrcnt
);
191 aprint_normal_dev(self
, "4 lines");
193 dzattach(sc
, NULL
, consline
);
197 cn_set_magic("\033D"); /* set VAX DDB escape sequence */
200 /* Don't touch this port if this is the console */
201 if (cn_tab
->cn_dev
!= makedev(cdevsw_lookup_major(&dz_cdevsw
), 0)) {
202 dz
->rbuf
= DZ_LPR_RX_ENABLE
| (DZ_LPR_B4800
<< 8)
206 (cn_tab
->cn_pri
== CN_INTERNAL
? DZKBD_CONSOLE
: 0);
207 config_found(self
, &daa
, dz_print
);
211 dz
->rbuf
= DZ_LPR_RX_ENABLE
| (DZ_LPR_B4800
<< 8) | DZ_LPR_8_BIT_CHAR \
212 | DZ_LPR_PARENB
| DZ_LPR_OPAR
| 1 /* line */;
215 config_found(self
, &daa
, dz_print
);
227 int mino
= minor(dev
);
232 while ((dz
->csr
& 0x80) == 0)
233 ; /* Wait for char */
235 if (((rbuf
>> 8) & 3) != mino
)
238 } while (c
== 17 || c
== 19); /* ignore XON/XOFF */
248 dzcnprobe(struct consdev
*cndev
)
250 extern vaddr_t iospace
;
252 paddr_t ioaddr
= 0x200A0000;
253 extern const struct cdevsw dz_cdevsw
;
255 switch (vax_boardtype
) {
259 diagcons
= (vax_confdata
& 0x20 ? 3 : 0);
264 diagcons
= (vax_confdata
& 0x100 ? 3 : 0);
269 diagcons
= (vax_confdata
& 8 ? 3 : 0);
278 cndev
->cn_pri
= CN_DEAD
;
282 cndev
->cn_pri
= CN_REMOTE
;
284 cndev
->cn_pri
= CN_NORMAL
;
285 cndev
->cn_dev
= makedev(cdevsw_lookup_major(&dz_cdevsw
), diagcons
);
287 dz
= (void *)dz_regs
;
288 ioaccess(iospace
, ioaddr
, 1);
292 dzcninit(struct consdev
*cndev
)
296 dz
->csr
= 0; /* Disable scanning until initting is done */
297 dz
->tcr
= (1 << minor(cndev
->cn_dev
)); /* Turn on xmitter */
298 dz
->csr
= 0x20; /* Turn scanning back on */
303 dzcnputc(dev_t dev
, int ch
)
305 int timeout
= 1<<15; /* don't hang the machine! */
306 int mino
= minor(dev
);
310 if (mfpr(PR_MAPEN
) == 0)
314 tcr
= dz
->tcr
; /* remember which lines to scan */
315 dz
->tcr
= (1 << mino
);
317 while ((dz
->csr
& 0x8000) == 0) /* Wait until ready */
320 dz
->tdr
= ch
; /* Put the character */
322 while ((dz
->csr
& 0x8000) == 0) /* Wait until ready */
331 dzcnpollc(dev_t dev
, int pollflag
)
336 mask
= vsbus_setmask(0);
341 #if NDZKBD > 0 || NDZMS > 0
343 dzgetc(struct dz_linestate
*ls
)
345 int line
= ls
->dz_line
;
351 for(; (dz
->csr
& DZ_CSR_RX_DONE
) == 0;);
353 if (((rbuf
>> 8) & 3) == line
) {
355 return (rbuf
& 0xff);
361 dzputc(struct dz_linestate
*ls
, int ch
)
366 extern const struct cdevsw dz_cdevsw
;
368 /* if the dz has already been attached, the MI
369 driver will do the transmitting: */
370 if (ls
&& ls
->dz_sc
) {
373 putc(ch
, &ls
->dz_tty
->t_outq
);
375 if (!(tcr
& (1 << line
)))
376 dz
->tcr
= tcr
| (1 << line
);
382 /* use dzcnputc to do the transmitting: */
383 dzcnputc(makedev(cdevsw_lookup_major(&dz_cdevsw
), 0), ch
);
385 #endif /* NDZKBD > 0 || NDZMS > 0 */