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