dz_vsbus.c revision 1.49 1 /* $NetBSD: dz_vsbus.c,v 1.49 2025/03/02 13:43:39 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.49 2025/03/02 13:43:39 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 struct dzkm_attach_args *daa = aux;
93
94 aprint_normal (" line %d", daa->daa_line);
95
96 return (QUIET);
97 }
98 #endif
99
100 static int
101 dz_vsbus_match(device_t parent, cfdata_t cf, void *aux)
102 {
103 struct vsbus_attach_args * const va = aux;
104 volatile struct ss_dz *dzP;
105 short i;
106
107 #if VAX53 || VAX49 || VAXANY
108 if (vax_boardtype == VAX_BTYP_53 || vax_boardtype == VAX_BTYP_49)
109 if (cf->cf_loc[VSBUSCF_CSR] != DZ_CSR_KA49)
110 return 0; /* Ugly */
111 #endif
112
113 dzP = (struct ss_dz *)va->va_addr;
114 i = dzP->tcr;
115 dzP->csr = DZ_CSR_MSE|DZ_CSR_TXIE;
116 dzP->tcr = 0;
117 DELAY(1000);
118 dzP->tcr = 1;
119 DELAY(100000);
120 dzP->tcr = i;
121
122 /* If the device doesn't exist, no interrupt has been generated */
123 return 1;
124 }
125
126 static void
127 dz_vsbus_attach(device_t parent, device_t self, void *aux)
128 {
129 struct dz_softc * const sc = device_private(self);
130 struct vsbus_attach_args * const va = aux;
131 #if NDZKBD > 0
132 extern const struct cdevsw dz_cdevsw;
133 #endif
134 #if NDZKBD > 0 || NDZMS > 0
135 struct dzkm_attach_args daa;
136 #endif
137 int s, consline;
138
139 sc->sc_dev = self;
140 /*
141 * XXX - This is evil and ugly, but...
142 * due to the nature of how bus_space_* works on VAX, this will
143 * be perfectly good until everything is converted.
144 */
145 if (major(cn_tab->cn_dev) != cdevsw_lookup_major(&dz_cdevsw)) {
146 dz_regs = vax_map_physmem(va->va_paddr, 1);
147 consline = -1;
148 } else
149 consline = minor(cn_tab->cn_dev);
150 sc->sc_ioh = dz_regs;
151 sc->sc_dr.dr_csr = 0;
152 sc->sc_dr.dr_rbuf = 4;
153 sc->sc_dr.dr_dtr = 9;
154 sc->sc_dr.dr_break = 13;
155 sc->sc_dr.dr_tbuf = 12;
156 sc->sc_dr.dr_tcr = 8;
157 sc->sc_dr.dr_dcd = 13;
158 sc->sc_dr.dr_ring = 13;
159
160 sc->sc_dr.dr_firstreg = 0;
161 sc->sc_dr.dr_winsize = 14;
162
163 sc->sc_type = DZ_DZV;
164
165 sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */
166
167 scb_vecalloc(va->va_cvec, dzxint, sc, SCB_ISTACK, &sc->sc_tintrcnt);
168 scb_vecalloc(va->va_cvec - 4, dzrint, sc, SCB_ISTACK, &sc->sc_rintrcnt);
169
170 aprint_normal("\n");
171 aprint_normal_dev(self, "4 lines");
172 if (consline != -1)
173 aprint_normal(", console on line %d", consline);
174
175 dzattach(sc, NULL, consline);
176 DELAY(10000);
177
178 if (consline != -1)
179 cn_set_magic("\033D"); /* set VAX DDB escape sequence */
180
181 #if NDZKBD > 0
182 /* Don't touch this port if this is the console */
183 if (cn_tab->cn_dev != makedev(cdevsw_lookup_major(&dz_cdevsw), 0)) {
184 dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8)
185 | DZ_LPR_8_BIT_CHAR;
186 daa.daa_line = 0;
187 daa.daa_flags =
188 (cn_tab->cn_pri == CN_INTERNAL ? DZKBD_CONSOLE : 0);
189 config_found(self, &daa, dz_print, CFARGS_NONE);
190 }
191 #endif
192 #if NDZMS > 0
193 dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8) | DZ_LPR_8_BIT_CHAR \
194 | DZ_LPR_PARENB | DZ_LPR_OPAR | 1 /* line */;
195 daa.daa_line = 1;
196 daa.daa_flags = 0;
197 config_found(self, &daa, dz_print, CFARGS_NONE);
198 #endif
199 s = spltty();
200 dzrint(sc);
201 dzxint(sc);
202 splx(s);
203 }
204
205 int
206 dzcngetc(dev_t dev)
207 {
208 int c = 0, s;
209 int mino = minor(dev);
210 u_short rbuf;
211
212 s = spltty();
213 do {
214 while ((dz->csr & 0x80) == 0)
215 ; /* Wait for char */
216 rbuf = dz->rbuf;
217 if (((rbuf >> 8) & 3) != mino)
218 continue;
219 c = rbuf & 0x7f;
220 } while (c == 17 || c == 19); /* ignore XON/XOFF */
221 splx(s);
222
223 if (c == 13)
224 c = 10;
225
226 return (c);
227 }
228
229 void
230 dzcnprobe(struct consdev *cndev)
231 {
232 extern vaddr_t iospace;
233 int diagcons;
234 paddr_t ioaddr = 0x200A0000;
235 extern const struct cdevsw dz_cdevsw;
236
237 switch (vax_boardtype) {
238 case VAX_BTYP_410:
239 case VAX_BTYP_420:
240 case VAX_BTYP_43:
241 diagcons = (vax_confdata & 0x20 ? 3 : 0);
242 break;
243
244 case VAX_BTYP_46:
245 case VAX_BTYP_48:
246 diagcons = (vax_confdata & 0x100 ? 3 : 0);
247 break;
248
249 case VAX_BTYP_49:
250 ioaddr = DZ_CSR_KA49;
251 diagcons = (vax_confdata & 8 ? 3 : 0);
252 break;
253
254 case VAX_BTYP_53:
255 ioaddr = DZ_CSR_KA49;
256 diagcons = 3;
257 break;
258
259 default:
260 cndev->cn_pri = CN_DEAD;
261 return;
262 }
263 if (diagcons)
264 cndev->cn_pri = CN_REMOTE;
265 else
266 cndev->cn_pri = CN_NORMAL;
267 cndev->cn_dev = makedev(cdevsw_lookup_major(&dz_cdevsw), diagcons);
268 dz_regs = iospace;
269 dz = (void *)dz_regs;
270 ioaccess(iospace, ioaddr, 1);
271 dz->csr = 0; /* Disable scanning until initting is done */
272 dz->tcr = (1 << minor(cndev->cn_dev)); /* Turn on xmitter */
273 dz->csr = 0x20; /* Turn scanning back on */
274 }
275
276 void
277 dzcninit(struct consdev *cndev)
278 {
279 dz = (void*)dz_regs;
280
281 dz->csr = 0; /* Disable scanning until initting is done */
282 dz->tcr = (1 << minor(cndev->cn_dev)); /* Turn on xmitter */
283 dz->csr = 0x20; /* Turn scanning back on */
284 }
285
286
287 void
288 dzcnputc(dev_t dev, int ch)
289 {
290 int timeout = 1<<15; /* don't hang the machine! */
291 int mino = minor(dev);
292 int s;
293 u_short tcr;
294
295 if (mfpr(PR_MAPEN) == 0)
296 return;
297
298 s = spltty();
299 tcr = dz->tcr; /* remember which lines to scan */
300 dz->tcr = (1 << mino);
301
302 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
303 if (--timeout < 0)
304 break;
305 dz->tdr = ch; /* Put the character */
306 timeout = 1<<15;
307 while ((dz->csr & 0x8000) == 0) /* Wait until ready */
308 if (--timeout < 0)
309 break;
310
311 dz->tcr = tcr;
312 splx(s);
313 }
314
315 void
316 dzcnpollc(dev_t dev, int pollflag)
317 {
318 static u_char mask;
319
320 if (pollflag)
321 mask = vsbus_setmask(0);
322 else
323 vsbus_setmask(mask);
324 }
325
326 #if NDZKBD > 0 || NDZMS > 0
327 int
328 dzgetc(struct dz_linestate *ls)
329 {
330 int line = ls->dz_line;
331 int s;
332 u_short rbuf;
333
334 s = spltty();
335 for (;;) {
336 for(; (dz->csr & DZ_CSR_RX_DONE) == 0;);
337 rbuf = dz->rbuf;
338 if (((rbuf >> 8) & 3) == line) {
339 splx(s);
340 return (rbuf & 0xff);
341 }
342 }
343 }
344
345 void
346 dzputc(struct dz_linestate *ls, int ch)
347 {
348 int line;
349 u_short tcr;
350 int s;
351 extern const struct cdevsw dz_cdevsw;
352
353 /* if the dz has already been attached, the MI
354 driver will do the transmitting: */
355 if (ls && ls->dz_sc) {
356 s = spltty();
357 line = ls->dz_line;
358 putc(ch, &ls->dz_tty->t_outq);
359 tcr = dz->tcr;
360 if (!(tcr & (1 << line)))
361 dz->tcr = tcr | (1 << line);
362 dzxint(ls->dz_sc);
363 splx(s);
364 return;
365 }
366
367 /* use dzcnputc to do the transmitting: */
368 dzcnputc(makedev(cdevsw_lookup_major(&dz_cdevsw), 0), ch);
369 }
370 #endif /* NDZKBD > 0 || NDZMS > 0 */
371