zs.c revision 1.59 1 1.59 mycroft /* $NetBSD: zs.c,v 1.59 1998/03/30 02:41:21 mycroft Exp $ */
2 1.18 deraadt
3 1.50 gwr /*-
4 1.50 gwr * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.50 gwr * All rights reserved.
6 1.1 deraadt *
7 1.50 gwr * This code is derived from software contributed to The NetBSD Foundation
8 1.50 gwr * by Gordon W. Ross.
9 1.1 deraadt *
10 1.1 deraadt * Redistribution and use in source and binary forms, with or without
11 1.1 deraadt * modification, are permitted provided that the following conditions
12 1.1 deraadt * are met:
13 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
14 1.1 deraadt * notice, this list of conditions and the following disclaimer.
15 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
17 1.1 deraadt * documentation and/or other materials provided with the distribution.
18 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
19 1.1 deraadt * must display the following acknowledgement:
20 1.50 gwr * This product includes software developed by the NetBSD
21 1.50 gwr * Foundation, Inc. and its contributors.
22 1.50 gwr * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.50 gwr * contributors may be used to endorse or promote products derived
24 1.50 gwr * from this software without specific prior written permission.
25 1.50 gwr *
26 1.50 gwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.50 gwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.50 gwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.50 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.50 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.50 gwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.50 gwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.50 gwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.50 gwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.50 gwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.50 gwr * POSSIBILITY OF SUCH DAMAGE.
37 1.1 deraadt */
38 1.1 deraadt
39 1.1 deraadt /*
40 1.50 gwr * Zilog Z8530 Dual UART driver (machine-dependent part)
41 1.50 gwr *
42 1.50 gwr * Runs two serial lines per chip using slave drivers.
43 1.50 gwr * Plain tty/async lines use the zs_async slave.
44 1.50 gwr * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
45 1.1 deraadt */
46 1.38 mrg
47 1.1 deraadt #include <sys/param.h>
48 1.34 christos #include <sys/systm.h>
49 1.50 gwr #include <sys/conf.h>
50 1.1 deraadt #include <sys/device.h>
51 1.1 deraadt #include <sys/file.h>
52 1.1 deraadt #include <sys/ioctl.h>
53 1.50 gwr #include <sys/kernel.h>
54 1.50 gwr #include <sys/proc.h>
55 1.1 deraadt #include <sys/tty.h>
56 1.1 deraadt #include <sys/time.h>
57 1.1 deraadt #include <sys/syslog.h>
58 1.1 deraadt
59 1.1 deraadt #include <machine/autoconf.h>
60 1.50 gwr #include <machine/bsd_openprom.h>
61 1.37 christos #include <machine/conf.h>
62 1.1 deraadt #include <machine/cpu.h>
63 1.50 gwr #include <machine/eeprom.h>
64 1.50 gwr #include <machine/psl.h>
65 1.50 gwr #include <machine/z8530var.h>
66 1.50 gwr
67 1.50 gwr #include <dev/cons.h>
68 1.50 gwr #include <dev/ic/z8530reg.h>
69 1.1 deraadt
70 1.1 deraadt #include <sparc/sparc/vaddrs.h>
71 1.1 deraadt #include <sparc/sparc/auxreg.h>
72 1.50 gwr #include <sparc/dev/cons.h>
73 1.50 gwr
74 1.50 gwr #include "kbd.h" /* NKBD */
75 1.50 gwr #include "zs.h" /* NZS */
76 1.1 deraadt
77 1.50 gwr /* Make life easier for the initialized arrays here. */
78 1.50 gwr #if NZS < 3
79 1.50 gwr #undef NZS
80 1.50 gwr #define NZS 3
81 1.1 deraadt #endif
82 1.1 deraadt
83 1.50 gwr /*
84 1.50 gwr * Some warts needed by z8530tty.c -
85 1.50 gwr * The default parity REALLY needs to be the same as the PROM uses,
86 1.50 gwr * or you can not see messages done with printf during boot-up...
87 1.50 gwr */
88 1.50 gwr int zs_def_cflag = (CREAD | CS8 | HUPCL);
89 1.50 gwr int zs_major = 12;
90 1.1 deraadt
91 1.50 gwr /*
92 1.50 gwr * The Sun provides a 4.9152 MHz clock to the ZS chips.
93 1.50 gwr */
94 1.50 gwr #define PCLK (9600 * 512) /* PCLK pin input clock rate */
95 1.1 deraadt
96 1.1 deraadt /*
97 1.1 deraadt * Select software interrupt bit based on TTY ipl.
98 1.1 deraadt */
99 1.1 deraadt #if PIL_TTY == 1
100 1.1 deraadt # define IE_ZSSOFT IE_L1
101 1.1 deraadt #elif PIL_TTY == 4
102 1.1 deraadt # define IE_ZSSOFT IE_L4
103 1.1 deraadt #elif PIL_TTY == 6
104 1.1 deraadt # define IE_ZSSOFT IE_L6
105 1.1 deraadt #else
106 1.1 deraadt # error "no suitable software interrupt bit"
107 1.1 deraadt #endif
108 1.1 deraadt
109 1.50 gwr #define ZS_DELAY() (CPU_ISSUN4C ? (0) : delay(2))
110 1.1 deraadt
111 1.50 gwr /* The layout of this is hardware-dependent (padding, order). */
112 1.50 gwr struct zschan {
113 1.50 gwr volatile u_char zc_csr; /* ctrl,status, and indirect access */
114 1.50 gwr u_char zc_xxx0;
115 1.50 gwr volatile u_char zc_data; /* data */
116 1.50 gwr u_char zc_xxx1;
117 1.35 thorpej };
118 1.50 gwr struct zsdevice {
119 1.50 gwr /* Yes, they are backwards. */
120 1.50 gwr struct zschan zs_chan_b;
121 1.50 gwr struct zschan zs_chan_a;
122 1.35 thorpej };
123 1.1 deraadt
124 1.50 gwr /* Saved PROM mappings */
125 1.50 gwr static struct zsdevice *zsaddr[NZS];
126 1.1 deraadt
127 1.50 gwr /* Flags from cninit() */
128 1.50 gwr static int zs_hwflags[NZS][2];
129 1.1 deraadt
130 1.50 gwr /* Default speed for each channel */
131 1.50 gwr static int zs_defspeed[NZS][2] = {
132 1.50 gwr { 9600, /* ttya */
133 1.50 gwr 9600 }, /* ttyb */
134 1.50 gwr { 1200, /* keyboard */
135 1.50 gwr 1200 }, /* mouse */
136 1.50 gwr { 9600, /* ttyc */
137 1.50 gwr 9600 }, /* ttyd */
138 1.50 gwr };
139 1.1 deraadt
140 1.50 gwr static u_char zs_init_reg[16] = {
141 1.50 gwr 0, /* 0: CMD (reset, etc.) */
142 1.50 gwr 0, /* 1: No interrupts yet. */
143 1.50 gwr 0, /* 2: IVECT */
144 1.50 gwr ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
145 1.50 gwr ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
146 1.50 gwr ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
147 1.50 gwr 0, /* 6: TXSYNC/SYNCLO */
148 1.50 gwr 0, /* 7: RXSYNC/SYNCHI */
149 1.50 gwr 0, /* 8: alias for data port */
150 1.50 gwr ZSWR9_MASTER_IE | ZSWR9_NO_VECTOR,
151 1.50 gwr 0, /*10: Misc. TX/RX control bits */
152 1.50 gwr ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
153 1.50 gwr 14, /*12: BAUDLO (default=9600) */
154 1.50 gwr 0, /*13: BAUDHI (default=9600) */
155 1.50 gwr ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
156 1.50 gwr ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
157 1.50 gwr };
158 1.1 deraadt
159 1.50 gwr struct zschan *
160 1.50 gwr zs_get_chan_addr(zs_unit, channel)
161 1.50 gwr int zs_unit, channel;
162 1.50 gwr {
163 1.57 pk struct zsdevice *addr;
164 1.57 pk struct zschan *zc;
165 1.50 gwr
166 1.50 gwr if (zs_unit >= NZS)
167 1.57 pk return (NULL);
168 1.50 gwr addr = zsaddr[zs_unit];
169 1.50 gwr if (addr == NULL)
170 1.50 gwr addr = zsaddr[zs_unit] = findzs(zs_unit);
171 1.50 gwr if (addr == NULL)
172 1.57 pk return (NULL);
173 1.50 gwr if (channel == 0) {
174 1.50 gwr zc = &addr->zs_chan_a;
175 1.50 gwr } else {
176 1.50 gwr zc = &addr->zs_chan_b;
177 1.50 gwr }
178 1.50 gwr return (zc);
179 1.50 gwr }
180 1.34 christos
181 1.34 christos
182 1.50 gwr /****************************************************************
183 1.50 gwr * Autoconfig
184 1.50 gwr ****************************************************************/
185 1.1 deraadt
186 1.50 gwr /* Definition of the driver for autoconfig. */
187 1.57 pk static int zs_match_mainbus __P((struct device *, struct cfdata *, void *));
188 1.57 pk static int zs_match_obio __P((struct device *, struct cfdata *, void *));
189 1.57 pk static void zs_attach_mainbus __P((struct device *, struct device *, void *));
190 1.57 pk static void zs_attach_obio __P((struct device *, struct device *, void *));
191 1.57 pk
192 1.57 pk static void zs_attach __P((struct zsc_softc *, int));
193 1.50 gwr static int zs_print __P((void *, const char *name));
194 1.1 deraadt
195 1.57 pk struct cfattach zs_mainbus_ca = {
196 1.57 pk sizeof(struct zsc_softc), zs_match_mainbus, zs_attach_mainbus
197 1.57 pk };
198 1.57 pk
199 1.57 pk struct cfattach zs_obio_ca = {
200 1.57 pk sizeof(struct zsc_softc), zs_match_obio, zs_attach_obio
201 1.50 gwr };
202 1.1 deraadt
203 1.55 thorpej extern struct cfdriver zs_cd;
204 1.34 christos
205 1.50 gwr /* Interrupt handlers. */
206 1.50 gwr static int zshard __P((void *));
207 1.50 gwr static int zssoft __P((void *));
208 1.50 gwr static struct intrhand levelsoft = { zssoft };
209 1.12 deraadt
210 1.50 gwr static int zs_get_speed __P((struct zs_chanstate *));
211 1.12 deraadt
212 1.12 deraadt
213 1.1 deraadt /*
214 1.50 gwr * Is the zs chip present?
215 1.1 deraadt */
216 1.1 deraadt static int
217 1.57 pk zs_match_mainbus(parent, cf, aux)
218 1.16 deraadt struct device *parent;
219 1.45 pk struct cfdata *cf;
220 1.45 pk void *aux;
221 1.1 deraadt {
222 1.57 pk struct mainbus_attach_args *ma = aux;
223 1.1 deraadt
224 1.57 pk if (strcmp(cf->cf_driver->cd_name, ma->ma_name) != 0)
225 1.14 deraadt return (0);
226 1.57 pk
227 1.57 pk return (getpropint(ma->ma_node, "slave", -2) == cf->cf_unit);
228 1.1 deraadt }
229 1.1 deraadt
230 1.57 pk static int
231 1.57 pk zs_match_obio(parent, cf, aux)
232 1.57 pk struct device *parent;
233 1.57 pk struct cfdata *cf;
234 1.57 pk void *aux;
235 1.57 pk {
236 1.57 pk union obio_attach_args *uoba = aux;
237 1.57 pk struct obio4_attach_args *oba;
238 1.57 pk
239 1.57 pk if (uoba->uoba_isobio4 == 0) {
240 1.57 pk struct sbus_attach_args *sa = &uoba->uoba_sbus;
241 1.57 pk
242 1.57 pk if (strcmp(cf->cf_driver->cd_name, sa->sa_name) != 0)
243 1.57 pk return (0);
244 1.57 pk
245 1.57 pk return (getpropint(sa->sa_node, "slave", -2) == cf->cf_unit);
246 1.57 pk }
247 1.57 pk
248 1.57 pk oba = &uoba->uoba_oba4;
249 1.58 pk return (bus_space_probe(oba->oba_bustag, 0, oba->oba_paddr,
250 1.58 pk 1, 0, 0, NULL, NULL));
251 1.57 pk }
252 1.57 pk
253 1.57 pk static void
254 1.57 pk zs_attach_mainbus(parent, self, aux)
255 1.57 pk struct device *parent;
256 1.57 pk struct device *self;
257 1.57 pk void *aux;
258 1.57 pk {
259 1.57 pk struct zsc_softc *zsc = (void *) self;
260 1.57 pk struct mainbus_attach_args *ma = aux;
261 1.57 pk int zs_unit = zsc->zsc_dev.dv_unit;
262 1.57 pk
263 1.57 pk zsc->zsc_bustag = ma->ma_bustag;
264 1.57 pk zsc->zsc_dmatag = ma->ma_dmatag;
265 1.57 pk
266 1.57 pk /* Use the mapping setup by the Sun PROM. */
267 1.57 pk if (zsaddr[zs_unit] == NULL)
268 1.57 pk zsaddr[zs_unit] = findzs(zs_unit);
269 1.57 pk if ((void*)zsaddr[zs_unit] != ma->ma_promvaddr)
270 1.57 pk panic("zsattach_mainbus");
271 1.57 pk
272 1.57 pk zs_attach(zsc, ma->ma_pri);
273 1.57 pk }
274 1.57 pk
275 1.57 pk static void
276 1.57 pk zs_attach_obio(parent, self, aux)
277 1.57 pk struct device *parent;
278 1.57 pk struct device *self;
279 1.57 pk void *aux;
280 1.57 pk {
281 1.57 pk struct zsc_softc *zsc = (void *) self;
282 1.57 pk union obio_attach_args *uoba = aux;
283 1.57 pk int zs_unit = zsc->zsc_dev.dv_unit;
284 1.57 pk
285 1.57 pk /* Use the mapping setup by the Sun PROM. */
286 1.57 pk if (zsaddr[zs_unit] == NULL)
287 1.57 pk zsaddr[zs_unit] = findzs(zs_unit);
288 1.57 pk
289 1.57 pk if (uoba->uoba_isobio4 == 0) {
290 1.57 pk struct sbus_attach_args *sa = &uoba->uoba_sbus;
291 1.57 pk zsc->zsc_bustag = sa->sa_bustag;
292 1.57 pk zsc->zsc_dmatag = sa->sa_dmatag;
293 1.57 pk zs_attach(zsc, sa->sa_pri);
294 1.57 pk } else {
295 1.57 pk struct obio4_attach_args *oba = &uoba->uoba_oba4;
296 1.57 pk zsc->zsc_bustag = oba->oba_bustag;
297 1.57 pk zsc->zsc_dmatag = oba->oba_dmatag;
298 1.57 pk zs_attach(zsc, oba->oba_pri);
299 1.57 pk }
300 1.57 pk }
301 1.1 deraadt /*
302 1.1 deraadt * Attach a found zs.
303 1.1 deraadt *
304 1.1 deraadt * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
305 1.1 deraadt * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
306 1.1 deraadt */
307 1.1 deraadt static void
308 1.57 pk zs_attach(zsc, pri)
309 1.57 pk struct zsc_softc *zsc;
310 1.57 pk int pri;
311 1.1 deraadt {
312 1.50 gwr struct zsc_attach_args zsc_args;
313 1.50 gwr volatile struct zschan *zc;
314 1.50 gwr struct zs_chanstate *cs;
315 1.57 pk int s, zs_unit, channel;
316 1.1 deraadt static int didintr, prevpri;
317 1.1 deraadt
318 1.57 pk printf(" softpri %d\n", PIL_TTY);
319 1.50 gwr
320 1.50 gwr /*
321 1.50 gwr * Initialize software state for each channel.
322 1.50 gwr */
323 1.57 pk zs_unit = zsc->zsc_dev.dv_unit;
324 1.50 gwr for (channel = 0; channel < 2; channel++) {
325 1.50 gwr zsc_args.channel = channel;
326 1.50 gwr zsc_args.hwflags = zs_hwflags[zs_unit][channel];
327 1.50 gwr cs = &zsc->zsc_cs_store[channel];
328 1.50 gwr zsc->zsc_cs[channel] = cs;
329 1.50 gwr
330 1.50 gwr cs->cs_channel = channel;
331 1.50 gwr cs->cs_private = NULL;
332 1.50 gwr cs->cs_ops = &zsops_null;
333 1.50 gwr cs->cs_brg_clk = PCLK / 16;
334 1.50 gwr
335 1.50 gwr zc = zs_get_chan_addr(zs_unit, channel);
336 1.50 gwr cs->cs_reg_csr = &zc->zc_csr;
337 1.50 gwr cs->cs_reg_data = &zc->zc_data;
338 1.50 gwr
339 1.50 gwr bcopy(zs_init_reg, cs->cs_creg, 16);
340 1.50 gwr bcopy(zs_init_reg, cs->cs_preg, 16);
341 1.50 gwr
342 1.50 gwr /* XXX: Get these from the PROM properties! */
343 1.50 gwr /* XXX: See the mvme167 code. Better. */
344 1.50 gwr if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE)
345 1.50 gwr cs->cs_defspeed = zs_get_speed(cs);
346 1.50 gwr else
347 1.50 gwr cs->cs_defspeed = zs_defspeed[zs_unit][channel];
348 1.50 gwr cs->cs_defcflag = zs_def_cflag;
349 1.50 gwr
350 1.50 gwr /* Make these correspond to cs_defcflag (-crtscts) */
351 1.50 gwr cs->cs_rr0_dcd = ZSRR0_DCD;
352 1.50 gwr cs->cs_rr0_cts = 0;
353 1.50 gwr cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
354 1.50 gwr cs->cs_wr5_rts = 0;
355 1.50 gwr
356 1.50 gwr /*
357 1.50 gwr * Clear the master interrupt enable.
358 1.50 gwr * The INTENA is common to both channels,
359 1.50 gwr * so just do it on the A channel.
360 1.50 gwr */
361 1.50 gwr if (channel == 0) {
362 1.50 gwr zs_write_reg(cs, 9, 0);
363 1.50 gwr }
364 1.50 gwr
365 1.50 gwr /*
366 1.50 gwr * Look for a child driver for this channel.
367 1.50 gwr * The child attach will setup the hardware.
368 1.50 gwr */
369 1.57 pk if (!config_found(&zsc->zsc_dev, (void *)&zsc_args, zs_print)) {
370 1.50 gwr /* No sub-driver. Just reset it. */
371 1.50 gwr u_char reset = (channel == 0) ?
372 1.50 gwr ZSWR9_A_RESET : ZSWR9_B_RESET;
373 1.56 mrg s = splzs();
374 1.50 gwr zs_write_reg(cs, 9, reset);
375 1.50 gwr splx(s);
376 1.50 gwr }
377 1.50 gwr }
378 1.50 gwr
379 1.50 gwr /*
380 1.50 gwr * Now safe to install interrupt handlers. Note the arguments
381 1.50 gwr * to the interrupt handlers aren't used. Note, we only do this
382 1.50 gwr * once since both SCCs interrupt at the same level and vector.
383 1.50 gwr */
384 1.1 deraadt if (!didintr) {
385 1.1 deraadt didintr = 1;
386 1.1 deraadt prevpri = pri;
387 1.57 pk bus_intr_establish(zsc->zsc_bustag, pri, 0, zshard, NULL);
388 1.1 deraadt intr_establish(PIL_TTY, &levelsoft);
389 1.1 deraadt } else if (pri != prevpri)
390 1.1 deraadt panic("broken zs interrupt scheme");
391 1.57 pk
392 1.50 gwr evcnt_attach(&zsc->zsc_dev, "intr", &zsc->zsc_intrcnt);
393 1.1 deraadt
394 1.1 deraadt /*
395 1.50 gwr * Set the master interrupt enable and interrupt vector.
396 1.50 gwr * (common to both channels, do it on A)
397 1.1 deraadt */
398 1.50 gwr cs = zsc->zsc_cs[0];
399 1.1 deraadt s = splhigh();
400 1.50 gwr /* interrupt vector */
401 1.50 gwr zs_write_reg(cs, 2, zs_init_reg[2]);
402 1.50 gwr /* master interrupt control (enable) */
403 1.50 gwr zs_write_reg(cs, 9, zs_init_reg[9]);
404 1.50 gwr splx(s);
405 1.50 gwr
406 1.50 gwr #if 0
407 1.47 pk /*
408 1.50 gwr * XXX: L1A hack - We would like to be able to break into
409 1.50 gwr * the debugger during the rest of autoconfiguration, so
410 1.50 gwr * lower interrupts just enough to let zs interrupts in.
411 1.50 gwr * This is done after both zs devices are attached.
412 1.50 gwr */
413 1.50 gwr if (zs_unit == 1) {
414 1.50 gwr printf("zs1: enabling zs interrupts\n");
415 1.50 gwr (void)splfd(); /* XXX: splzs - 1 */
416 1.47 pk }
417 1.50 gwr #endif
418 1.1 deraadt }
419 1.1 deraadt
420 1.50 gwr static int
421 1.50 gwr zs_print(aux, name)
422 1.50 gwr void *aux;
423 1.50 gwr const char *name;
424 1.1 deraadt {
425 1.50 gwr struct zsc_attach_args *args = aux;
426 1.1 deraadt
427 1.50 gwr if (name != NULL)
428 1.50 gwr printf("%s: ", name);
429 1.1 deraadt
430 1.50 gwr if (args->channel != -1)
431 1.50 gwr printf(" channel %d", args->channel);
432 1.1 deraadt
433 1.57 pk return (UNCONF);
434 1.1 deraadt }
435 1.1 deraadt
436 1.50 gwr static volatile int zssoftpending;
437 1.1 deraadt
438 1.1 deraadt /*
439 1.50 gwr * Our ZS chips all share a common, autovectored interrupt,
440 1.50 gwr * so we have to look at all of them on each interrupt.
441 1.1 deraadt */
442 1.1 deraadt static int
443 1.50 gwr zshard(arg)
444 1.50 gwr void *arg;
445 1.1 deraadt {
446 1.50 gwr register struct zsc_softc *zsc;
447 1.50 gwr register int unit, rr3, rval, softreq;
448 1.1 deraadt
449 1.50 gwr rval = softreq = 0;
450 1.50 gwr for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
451 1.50 gwr zsc = zs_cd.cd_devs[unit];
452 1.50 gwr if (zsc == NULL)
453 1.50 gwr continue;
454 1.50 gwr rr3 = zsc_intr_hard(zsc);
455 1.50 gwr /* Count up the interrupts. */
456 1.50 gwr if (rr3) {
457 1.50 gwr rval |= rr3;
458 1.50 gwr zsc->zsc_intrcnt.ev_count++;
459 1.50 gwr }
460 1.50 gwr softreq |= zsc->zsc_cs[0]->cs_softreq;
461 1.50 gwr softreq |= zsc->zsc_cs[1]->cs_softreq;
462 1.50 gwr }
463 1.1 deraadt
464 1.50 gwr /* We are at splzs here, so no need to lock. */
465 1.50 gwr if (softreq && (zssoftpending == 0)) {
466 1.50 gwr zssoftpending = IE_ZSSOFT;
467 1.50 gwr #if defined(SUN4M)
468 1.50 gwr if (CPU_ISSUN4M)
469 1.50 gwr raise(0, PIL_TTY);
470 1.50 gwr else
471 1.50 gwr #endif
472 1.56 mrg ienab_bis(IE_ZSSOFT);
473 1.50 gwr }
474 1.50 gwr return (rval);
475 1.1 deraadt }
476 1.1 deraadt
477 1.1 deraadt /*
478 1.50 gwr * Similar scheme as for zshard (look at all of them)
479 1.1 deraadt */
480 1.50 gwr static int
481 1.50 gwr zssoft(arg)
482 1.50 gwr void *arg;
483 1.1 deraadt {
484 1.50 gwr register struct zsc_softc *zsc;
485 1.50 gwr register int s, unit;
486 1.1 deraadt
487 1.50 gwr /* This is not the only ISR on this IPL. */
488 1.50 gwr if (zssoftpending == 0)
489 1.50 gwr return (0);
490 1.1 deraadt
491 1.50 gwr /*
492 1.50 gwr * The soft intr. bit will be set by zshard only if
493 1.50 gwr * the variable zssoftpending is zero. The order of
494 1.50 gwr * these next two statements prevents our clearing
495 1.50 gwr * the soft intr bit just after zshard has set it.
496 1.50 gwr */
497 1.50 gwr /* ienab_bic(IE_ZSSOFT); */
498 1.50 gwr zssoftpending = 0;
499 1.1 deraadt
500 1.50 gwr /* Make sure we call the tty layer at spltty. */
501 1.1 deraadt s = spltty();
502 1.50 gwr for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
503 1.50 gwr zsc = zs_cd.cd_devs[unit];
504 1.50 gwr if (zsc == NULL)
505 1.50 gwr continue;
506 1.56 mrg (void)zsc_intr_soft(zsc);
507 1.1 deraadt }
508 1.1 deraadt splx(s);
509 1.50 gwr return (1);
510 1.1 deraadt }
511 1.1 deraadt
512 1.50 gwr
513 1.1 deraadt /*
514 1.50 gwr * Compute the current baud rate given a ZS channel.
515 1.1 deraadt */
516 1.50 gwr static int
517 1.50 gwr zs_get_speed(cs)
518 1.50 gwr struct zs_chanstate *cs;
519 1.50 gwr {
520 1.50 gwr int tconst;
521 1.50 gwr
522 1.50 gwr tconst = zs_read_reg(cs, 12);
523 1.50 gwr tconst |= zs_read_reg(cs, 13) << 8;
524 1.50 gwr return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
525 1.1 deraadt }
526 1.1 deraadt
527 1.1 deraadt /*
528 1.50 gwr * MD functions for setting the baud rate and control modes.
529 1.1 deraadt */
530 1.1 deraadt int
531 1.50 gwr zs_set_speed(cs, bps)
532 1.50 gwr struct zs_chanstate *cs;
533 1.50 gwr int bps; /* bits per second */
534 1.1 deraadt {
535 1.50 gwr int tconst, real_bps;
536 1.50 gwr
537 1.50 gwr if (bps == 0)
538 1.50 gwr return (0);
539 1.1 deraadt
540 1.50 gwr #ifdef DIAGNOSTIC
541 1.50 gwr if (cs->cs_brg_clk == 0)
542 1.50 gwr panic("zs_set_speed");
543 1.50 gwr #endif
544 1.50 gwr
545 1.50 gwr tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
546 1.50 gwr if (tconst < 0)
547 1.50 gwr return (EINVAL);
548 1.28 pk
549 1.50 gwr /* Convert back to make sure we can do it. */
550 1.50 gwr real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
551 1.1 deraadt
552 1.50 gwr /* XXX - Allow some tolerance here? */
553 1.50 gwr if (real_bps != bps)
554 1.50 gwr return (EINVAL);
555 1.28 pk
556 1.50 gwr cs->cs_preg[12] = tconst;
557 1.50 gwr cs->cs_preg[13] = tconst >> 8;
558 1.1 deraadt
559 1.50 gwr /* Caller will stuff the pending registers. */
560 1.50 gwr return (0);
561 1.28 pk }
562 1.28 pk
563 1.50 gwr int
564 1.50 gwr zs_set_modes(cs, cflag)
565 1.50 gwr struct zs_chanstate *cs;
566 1.50 gwr int cflag; /* bits per second */
567 1.28 pk {
568 1.50 gwr int s;
569 1.28 pk
570 1.50 gwr /*
571 1.50 gwr * Output hardware flow control on the chip is horrendous:
572 1.50 gwr * if carrier detect drops, the receiver is disabled, and if
573 1.50 gwr * CTS drops, the transmitter is stoped IN MID CHARACTER!
574 1.50 gwr * Therefore, NEVER set the HFC bit, and instead use the
575 1.50 gwr * status interrupt to detect CTS changes.
576 1.50 gwr */
577 1.50 gwr s = splzs();
578 1.52 mycroft if ((cflag & (CLOCAL | MDMBUF)) != 0)
579 1.50 gwr cs->cs_rr0_dcd = 0;
580 1.52 mycroft else
581 1.50 gwr cs->cs_rr0_dcd = ZSRR0_DCD;
582 1.52 mycroft if ((cflag & CRTSCTS) != 0) {
583 1.50 gwr cs->cs_wr5_dtr = ZSWR5_DTR;
584 1.50 gwr cs->cs_wr5_rts = ZSWR5_RTS;
585 1.53 mycroft cs->cs_rr0_cts = ZSRR0_CTS;
586 1.53 mycroft } else if ((cflag & CDTRCTS) != 0) {
587 1.53 mycroft cs->cs_wr5_dtr = 0;
588 1.53 mycroft cs->cs_wr5_rts = ZSWR5_DTR;
589 1.50 gwr cs->cs_rr0_cts = ZSRR0_CTS;
590 1.52 mycroft } else if ((cflag & MDMBUF) != 0) {
591 1.52 mycroft cs->cs_wr5_dtr = 0;
592 1.52 mycroft cs->cs_wr5_rts = ZSWR5_DTR;
593 1.52 mycroft cs->cs_rr0_cts = ZSRR0_DCD;
594 1.50 gwr } else {
595 1.50 gwr cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
596 1.50 gwr cs->cs_wr5_rts = 0;
597 1.50 gwr cs->cs_rr0_cts = 0;
598 1.50 gwr }
599 1.50 gwr splx(s);
600 1.28 pk
601 1.50 gwr /* Caller will stuff the pending registers. */
602 1.50 gwr return (0);
603 1.38 mrg }
604 1.28 pk
605 1.1 deraadt
606 1.1 deraadt /*
607 1.50 gwr * Read or write the chip with suitable delays.
608 1.1 deraadt */
609 1.50 gwr
610 1.50 gwr u_char
611 1.50 gwr zs_read_reg(cs, reg)
612 1.50 gwr struct zs_chanstate *cs;
613 1.50 gwr u_char reg;
614 1.1 deraadt {
615 1.50 gwr u_char val;
616 1.14 deraadt
617 1.50 gwr *cs->cs_reg_csr = reg;
618 1.50 gwr ZS_DELAY();
619 1.50 gwr val = *cs->cs_reg_csr;
620 1.50 gwr ZS_DELAY();
621 1.57 pk return (val);
622 1.1 deraadt }
623 1.1 deraadt
624 1.50 gwr void
625 1.50 gwr zs_write_reg(cs, reg, val)
626 1.50 gwr struct zs_chanstate *cs;
627 1.50 gwr u_char reg, val;
628 1.1 deraadt {
629 1.50 gwr *cs->cs_reg_csr = reg;
630 1.14 deraadt ZS_DELAY();
631 1.50 gwr *cs->cs_reg_csr = val;
632 1.14 deraadt ZS_DELAY();
633 1.50 gwr }
634 1.1 deraadt
635 1.56 mrg u_char
636 1.56 mrg zs_read_csr(cs)
637 1.50 gwr struct zs_chanstate *cs;
638 1.50 gwr {
639 1.50 gwr register u_char val;
640 1.1 deraadt
641 1.50 gwr val = *cs->cs_reg_csr;
642 1.14 deraadt ZS_DELAY();
643 1.57 pk return (val);
644 1.1 deraadt }
645 1.1 deraadt
646 1.50 gwr void zs_write_csr(cs, val)
647 1.50 gwr struct zs_chanstate *cs;
648 1.50 gwr u_char val;
649 1.50 gwr {
650 1.50 gwr *cs->cs_reg_csr = val;
651 1.14 deraadt ZS_DELAY();
652 1.1 deraadt }
653 1.1 deraadt
654 1.50 gwr u_char zs_read_data(cs)
655 1.50 gwr struct zs_chanstate *cs;
656 1.1 deraadt {
657 1.50 gwr register u_char val;
658 1.1 deraadt
659 1.50 gwr val = *cs->cs_reg_data;
660 1.29 pk ZS_DELAY();
661 1.57 pk return (val);
662 1.50 gwr }
663 1.50 gwr
664 1.50 gwr void zs_write_data(cs, val)
665 1.50 gwr struct zs_chanstate *cs;
666 1.50 gwr u_char val;
667 1.50 gwr {
668 1.50 gwr *cs->cs_reg_data = val;
669 1.14 deraadt ZS_DELAY();
670 1.1 deraadt }
671 1.1 deraadt
672 1.50 gwr /****************************************************************
673 1.50 gwr * Console support functions (Sun specific!)
674 1.50 gwr * Note: this code is allowed to know about the layout of
675 1.50 gwr * the chip registers, and uses that to keep things simple.
676 1.50 gwr * XXX - I think I like the mvme167 code better. -gwr
677 1.50 gwr ****************************************************************/
678 1.50 gwr
679 1.50 gwr extern void Debugger __P((void));
680 1.50 gwr void *zs_conschan;
681 1.50 gwr
682 1.50 gwr /*
683 1.50 gwr * Handle user request to enter kernel debugger.
684 1.50 gwr */
685 1.34 christos void
686 1.50 gwr zs_abort(cs)
687 1.50 gwr struct zs_chanstate *cs;
688 1.1 deraadt {
689 1.50 gwr register volatile struct zschan *zc = zs_conschan;
690 1.50 gwr int rr0;
691 1.50 gwr
692 1.50 gwr /* Wait for end of break to avoid PROM abort. */
693 1.50 gwr /* XXX - Limit the wait? */
694 1.50 gwr do {
695 1.50 gwr rr0 = zc->zc_csr;
696 1.50 gwr ZS_DELAY();
697 1.50 gwr } while (rr0 & ZSRR0_BREAK);
698 1.1 deraadt
699 1.49 pk #if defined(KGDB)
700 1.50 gwr zskgdb(cs);
701 1.49 pk #elif defined(DDB)
702 1.5 pk Debugger();
703 1.5 pk #else
704 1.44 christos printf("stopping on keyboard abort\n");
705 1.1 deraadt callrom();
706 1.5 pk #endif
707 1.1 deraadt }
708 1.1 deraadt
709 1.1 deraadt /*
710 1.50 gwr * Polled input char.
711 1.1 deraadt */
712 1.50 gwr int
713 1.50 gwr zs_getc(arg)
714 1.50 gwr void *arg;
715 1.1 deraadt {
716 1.50 gwr register volatile struct zschan *zc = arg;
717 1.50 gwr register int s, c, rr0;
718 1.1 deraadt
719 1.50 gwr s = splhigh();
720 1.50 gwr /* Wait for a character to arrive. */
721 1.50 gwr do {
722 1.50 gwr rr0 = zc->zc_csr;
723 1.50 gwr ZS_DELAY();
724 1.50 gwr } while ((rr0 & ZSRR0_RX_READY) == 0);
725 1.1 deraadt
726 1.50 gwr c = zc->zc_data;
727 1.50 gwr ZS_DELAY();
728 1.50 gwr splx(s);
729 1.1 deraadt
730 1.50 gwr /*
731 1.50 gwr * This is used by the kd driver to read scan codes,
732 1.50 gwr * so don't translate '\r' ==> '\n' here...
733 1.50 gwr */
734 1.50 gwr return (c);
735 1.1 deraadt }
736 1.1 deraadt
737 1.1 deraadt /*
738 1.50 gwr * Polled output char.
739 1.1 deraadt */
740 1.50 gwr void
741 1.50 gwr zs_putc(arg, c)
742 1.16 deraadt void *arg;
743 1.50 gwr int c;
744 1.1 deraadt {
745 1.50 gwr register volatile struct zschan *zc = arg;
746 1.50 gwr register int s, rr0;
747 1.1 deraadt
748 1.50 gwr s = splhigh();
749 1.59 mycroft
750 1.50 gwr /* Wait for transmitter to become ready. */
751 1.50 gwr do {
752 1.50 gwr rr0 = zc->zc_csr;
753 1.50 gwr ZS_DELAY();
754 1.50 gwr } while ((rr0 & ZSRR0_TX_READY) == 0);
755 1.21 deraadt
756 1.50 gwr zc->zc_data = c;
757 1.50 gwr ZS_DELAY();
758 1.59 mycroft
759 1.50 gwr splx(s);
760 1.50 gwr }
761 1.21 deraadt
762 1.50 gwr /*****************************************************************/
763 1.21 deraadt
764 1.50 gwr static void zscninit __P((struct consdev *));
765 1.50 gwr static int zscngetc __P((dev_t));
766 1.50 gwr static void zscnputc __P((dev_t, int));
767 1.1 deraadt
768 1.1 deraadt /*
769 1.50 gwr * Console table shared by ttya, ttyb
770 1.1 deraadt */
771 1.50 gwr struct consdev consdev_tty = {
772 1.50 gwr nullcnprobe,
773 1.50 gwr zscninit,
774 1.50 gwr zscngetc,
775 1.50 gwr zscnputc,
776 1.50 gwr nullcnpollc,
777 1.50 gwr };
778 1.50 gwr
779 1.1 deraadt static void
780 1.50 gwr zscninit(cn)
781 1.50 gwr struct consdev *cn;
782 1.1 deraadt {
783 1.1 deraadt }
784 1.1 deraadt
785 1.1 deraadt /*
786 1.50 gwr * Polled console input putchar.
787 1.1 deraadt */
788 1.50 gwr static int
789 1.50 gwr zscngetc(dev)
790 1.50 gwr dev_t dev;
791 1.50 gwr {
792 1.50 gwr return (zs_getc(zs_conschan));
793 1.1 deraadt }
794 1.1 deraadt
795 1.1 deraadt /*
796 1.50 gwr * Polled console output putchar.
797 1.1 deraadt */
798 1.50 gwr static void
799 1.50 gwr zscnputc(dev, c)
800 1.50 gwr dev_t dev;
801 1.50 gwr int c;
802 1.50 gwr {
803 1.50 gwr zs_putc(zs_conschan, c);
804 1.50 gwr }
805 1.1 deraadt
806 1.50 gwr /*****************************************************************/
807 1.1 deraadt
808 1.50 gwr static void prom_cninit __P((struct consdev *));
809 1.50 gwr static int prom_cngetc __P((dev_t));
810 1.50 gwr static void prom_cnputc __P((dev_t, int));
811 1.1 deraadt
812 1.50 gwr /*
813 1.50 gwr * The console is set to this one initially,
814 1.50 gwr * which lets us use the PROM until consinit()
815 1.50 gwr * is called to select a real console.
816 1.50 gwr */
817 1.50 gwr struct consdev consdev_prom = {
818 1.50 gwr nullcnprobe,
819 1.50 gwr prom_cninit,
820 1.50 gwr prom_cngetc,
821 1.50 gwr prom_cnputc,
822 1.50 gwr nullcnpollc,
823 1.50 gwr };
824 1.1 deraadt
825 1.1 deraadt /*
826 1.50 gwr * The console table pointer is statically initialized
827 1.50 gwr * to point to the PROM (output only) table, so that
828 1.50 gwr * early calls to printf will work.
829 1.1 deraadt */
830 1.50 gwr struct consdev *cn_tab = &consdev_prom;
831 1.50 gwr
832 1.50 gwr void
833 1.50 gwr nullcnprobe(cn)
834 1.50 gwr struct consdev *cn;
835 1.1 deraadt {
836 1.1 deraadt }
837 1.1 deraadt
838 1.1 deraadt static void
839 1.50 gwr prom_cninit(cn)
840 1.50 gwr struct consdev *cn;
841 1.1 deraadt {
842 1.1 deraadt }
843 1.1 deraadt
844 1.1 deraadt /*
845 1.50 gwr * PROM console input putchar.
846 1.50 gwr * (dummy - this is output only)
847 1.1 deraadt */
848 1.1 deraadt static int
849 1.50 gwr prom_cngetc(dev)
850 1.50 gwr dev_t dev;
851 1.1 deraadt {
852 1.50 gwr return (0);
853 1.1 deraadt }
854 1.1 deraadt
855 1.1 deraadt /*
856 1.50 gwr * PROM console output putchar.
857 1.1 deraadt */
858 1.1 deraadt static void
859 1.50 gwr prom_cnputc(dev, c)
860 1.50 gwr dev_t dev;
861 1.16 deraadt int c;
862 1.1 deraadt {
863 1.50 gwr char c0 = (c & 0x7f);
864 1.1 deraadt
865 1.50 gwr if (promvec->pv_romvec_vers > 2)
866 1.50 gwr (*promvec->pv_v2devops.v2_write)
867 1.50 gwr (*promvec->pv_v2bootargs.v2_fd1, &c0, 1);
868 1.50 gwr else
869 1.50 gwr (*promvec->pv_putchar)(c);
870 1.1 deraadt }
871 1.1 deraadt
872 1.50 gwr /*****************************************************************/
873 1.50 gwr
874 1.50 gwr extern struct consdev consdev_kd;
875 1.50 gwr
876 1.50 gwr static char *prom_inSrc_name[] = {
877 1.50 gwr "keyboard/display",
878 1.50 gwr "ttya", "ttyb",
879 1.50 gwr "ttyc", "ttyd" };
880 1.50 gwr
881 1.1 deraadt /*
882 1.50 gwr * This function replaces sys/dev/cninit.c
883 1.50 gwr * Determine which device is the console using
884 1.50 gwr * the PROM "input source" and "output sink".
885 1.1 deraadt */
886 1.1 deraadt void
887 1.50 gwr consinit()
888 1.1 deraadt {
889 1.50 gwr struct zschan *zc;
890 1.50 gwr struct consdev *cn;
891 1.50 gwr int channel, zs_unit, zstty_unit;
892 1.50 gwr int inSource, outSink;
893 1.50 gwr
894 1.50 gwr if (promvec->pv_romvec_vers > 2) {
895 1.50 gwr /* We need to probe the PROM device tree */
896 1.50 gwr register int node,fd;
897 1.50 gwr char buffer[128];
898 1.50 gwr register struct nodeops *no;
899 1.50 gwr register struct v2devops *op;
900 1.50 gwr register char *cp;
901 1.50 gwr extern int fbnode;
902 1.50 gwr
903 1.50 gwr inSource = outSink = -1;
904 1.50 gwr no = promvec->pv_nodeops;
905 1.50 gwr op = &promvec->pv_v2devops;
906 1.50 gwr
907 1.50 gwr node = findroot();
908 1.50 gwr if (no->no_proplen(node, "stdin-path") >= sizeof(buffer)) {
909 1.50 gwr printf("consinit: increase buffer size and recompile\n");
910 1.50 gwr goto setup_output;
911 1.50 gwr }
912 1.50 gwr /* XXX: fix above */
913 1.50 gwr
914 1.50 gwr no->no_getprop(node, "stdin-path",buffer);
915 1.50 gwr
916 1.50 gwr /*
917 1.50 gwr * Open an "instance" of this device.
918 1.50 gwr * You'd think it would be appropriate to call v2_close()
919 1.50 gwr * on the handle when we're done with it. But that seems
920 1.50 gwr * to cause the device to shut down somehow; for the moment,
921 1.50 gwr * we simply leave it open...
922 1.50 gwr */
923 1.50 gwr if ((fd = op->v2_open(buffer)) == 0 ||
924 1.50 gwr (node = op->v2_fd_phandle(fd)) == 0) {
925 1.50 gwr printf("consinit: bogus stdin path %s.\n",buffer);
926 1.50 gwr goto setup_output;
927 1.50 gwr }
928 1.50 gwr if (no->no_proplen(node,"keyboard") >= 0) {
929 1.50 gwr inSource = PROMDEV_KBD;
930 1.50 gwr goto setup_output;
931 1.50 gwr }
932 1.50 gwr if (strcmp(getpropstring(node,"device_type"),"serial") != 0) {
933 1.50 gwr /* not a serial, not keyboard. what is it?!? */
934 1.50 gwr inSource = -1;
935 1.50 gwr goto setup_output;
936 1.50 gwr }
937 1.50 gwr /*
938 1.50 gwr * At this point we assume the device path is in the form
939 1.50 gwr * ....device@x,y:a for ttya and ...device@x,y:b for ttyb.
940 1.50 gwr * If it isn't, we defer to the ROM
941 1.50 gwr */
942 1.50 gwr cp = buffer;
943 1.50 gwr while (*cp)
944 1.50 gwr cp++;
945 1.50 gwr cp -= 2;
946 1.50 gwr #ifdef DEBUG
947 1.50 gwr if (cp < buffer)
948 1.50 gwr panic("consinit: bad stdin path %s",buffer);
949 1.50 gwr #endif
950 1.50 gwr /* XXX: only allows tty's a->z, assumes PROMDEV_TTYx contig */
951 1.50 gwr if (cp[0]==':' && cp[1] >= 'a' && cp[1] <= 'z')
952 1.50 gwr inSource = PROMDEV_TTYA + (cp[1] - 'a');
953 1.50 gwr /* else use rom */
954 1.50 gwr setup_output:
955 1.50 gwr node = findroot();
956 1.50 gwr if (no->no_proplen(node, "stdout-path") >= sizeof(buffer)) {
957 1.50 gwr printf("consinit: increase buffer size and recompile\n");
958 1.50 gwr goto setup_console;
959 1.50 gwr }
960 1.50 gwr /* XXX: fix above */
961 1.50 gwr
962 1.50 gwr no->no_getprop(node, "stdout-path", buffer);
963 1.50 gwr
964 1.50 gwr if ((fd = op->v2_open(buffer)) == 0 ||
965 1.50 gwr (node = op->v2_fd_phandle(fd)) == 0) {
966 1.50 gwr printf("consinit: bogus stdout path %s.\n",buffer);
967 1.50 gwr goto setup_output;
968 1.50 gwr }
969 1.50 gwr if (strcmp(getpropstring(node,"device_type"),"display") == 0) {
970 1.50 gwr /* frame buffer output */
971 1.50 gwr outSink = PROMDEV_SCREEN;
972 1.50 gwr fbnode = node;
973 1.50 gwr } else if (strcmp(getpropstring(node,"device_type"), "serial")
974 1.50 gwr != 0) {
975 1.50 gwr /* not screen, not serial. Whatzit? */
976 1.50 gwr outSink = -1;
977 1.50 gwr } else { /* serial console. which? */
978 1.50 gwr /*
979 1.50 gwr * At this point we assume the device path is in the
980 1.50 gwr * form:
981 1.50 gwr * ....device@x,y:a for ttya, etc.
982 1.50 gwr * If it isn't, we defer to the ROM
983 1.50 gwr */
984 1.50 gwr cp = buffer;
985 1.50 gwr while (*cp)
986 1.50 gwr cp++;
987 1.50 gwr cp -= 2;
988 1.50 gwr #ifdef DEBUG
989 1.50 gwr if (cp < buffer)
990 1.50 gwr panic("consinit: bad stdout path %s",buffer);
991 1.50 gwr #endif
992 1.50 gwr /* XXX: only allows tty's a->z, assumes PROMDEV_TTYx contig */
993 1.50 gwr if (cp[0]==':' && cp[1] >= 'a' && cp[1] <= 'z')
994 1.50 gwr outSink = PROMDEV_TTYA + (cp[1] - 'a');
995 1.50 gwr else outSink = -1;
996 1.50 gwr }
997 1.50 gwr } else {
998 1.50 gwr inSource = *promvec->pv_stdin;
999 1.50 gwr outSink = *promvec->pv_stdout;
1000 1.50 gwr }
1001 1.50 gwr
1002 1.50 gwr setup_console:
1003 1.50 gwr
1004 1.50 gwr if (inSource != outSink) {
1005 1.50 gwr printf("cninit: mismatched PROM output selector\n");
1006 1.50 gwr }
1007 1.50 gwr
1008 1.50 gwr switch (inSource) {
1009 1.50 gwr default:
1010 1.50 gwr printf("cninit: invalid inSource=%d\n", inSource);
1011 1.50 gwr callrom();
1012 1.50 gwr inSource = PROMDEV_KBD;
1013 1.50 gwr /* fall through */
1014 1.50 gwr
1015 1.50 gwr case 0: /* keyboard/display */
1016 1.50 gwr #if NKBD > 0
1017 1.51 gwr zs_unit = 1; /* XXX - config info! */
1018 1.50 gwr channel = 0;
1019 1.50 gwr cn = &consdev_kd;
1020 1.50 gwr /* Set cn_dev, cn_pri in kd.c */
1021 1.50 gwr break;
1022 1.50 gwr #else /* NKBD */
1023 1.50 gwr printf("cninit: kdb/display not configured\n");
1024 1.50 gwr callrom();
1025 1.50 gwr inSource = PROMDEV_TTYA;
1026 1.50 gwr /* fall through */
1027 1.50 gwr #endif /* NKBD */
1028 1.50 gwr
1029 1.50 gwr case PROMDEV_TTYA:
1030 1.50 gwr case PROMDEV_TTYB:
1031 1.50 gwr zstty_unit = inSource - PROMDEV_TTYA;
1032 1.51 gwr zs_unit = 0; /* XXX - config info! */
1033 1.50 gwr channel = zstty_unit & 1;
1034 1.50 gwr cn = &consdev_tty;
1035 1.50 gwr cn->cn_dev = makedev(zs_major, zstty_unit);
1036 1.50 gwr cn->cn_pri = CN_REMOTE;
1037 1.50 gwr break;
1038 1.50 gwr
1039 1.50 gwr }
1040 1.50 gwr /* Now that inSource has been validated, print it. */
1041 1.50 gwr printf("console is %s\n", prom_inSrc_name[inSource]);
1042 1.1 deraadt
1043 1.50 gwr zc = zs_get_chan_addr(zs_unit, channel);
1044 1.50 gwr if (zc == NULL) {
1045 1.50 gwr printf("cninit: zs not mapped.\n");
1046 1.1 deraadt return;
1047 1.1 deraadt }
1048 1.50 gwr zs_conschan = zc;
1049 1.50 gwr zs_hwflags[zs_unit][channel] = ZS_HWFLAG_CONSOLE;
1050 1.50 gwr cn_tab = cn;
1051 1.50 gwr (*cn->cn_init)(cn);
1052 1.50 gwr #ifdef KGDB
1053 1.50 gwr zs_kgdb_init();
1054 1.50 gwr #endif
1055 1.1 deraadt }
1056