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