com.c revision 1.78 1 1.78 cgd /* $NetBSD: com.c,v 1.78 1996/04/11 22:28:31 cgd Exp $ */
2 1.38 cgd
3 1.1 cgd /*-
4 1.71 mycroft * Copyright (c) 1993, 1994, 1995, 1996
5 1.71 mycroft * Charles M. Hannum. All rights reserved.
6 1.1 cgd * Copyright (c) 1991 The Regents of the University of California.
7 1.1 cgd * All rights reserved.
8 1.1 cgd *
9 1.1 cgd * Redistribution and use in source and binary forms, with or without
10 1.1 cgd * modification, are permitted provided that the following conditions
11 1.1 cgd * are met:
12 1.1 cgd * 1. Redistributions of source code must retain the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer.
14 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 cgd * notice, this list of conditions and the following disclaimer in the
16 1.1 cgd * documentation and/or other materials provided with the distribution.
17 1.1 cgd * 3. All advertising materials mentioning features or use of this software
18 1.1 cgd * must display the following acknowledgement:
19 1.1 cgd * This product includes software developed by the University of
20 1.1 cgd * California, Berkeley and its contributors.
21 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
22 1.1 cgd * may be used to endorse or promote products derived from this software
23 1.1 cgd * without specific prior written permission.
24 1.1 cgd *
25 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 cgd * SUCH DAMAGE.
36 1.1 cgd *
37 1.38 cgd * @(#)com.c 7.5 (Berkeley) 5/16/91
38 1.1 cgd */
39 1.1 cgd
40 1.1 cgd /*
41 1.1 cgd * COM driver, based on HP dca driver
42 1.1 cgd * uses National Semiconductor NS16450/NS16550AF UART
43 1.1 cgd */
44 1.14 mycroft #include <sys/param.h>
45 1.14 mycroft #include <sys/systm.h>
46 1.14 mycroft #include <sys/ioctl.h>
47 1.14 mycroft #include <sys/select.h>
48 1.14 mycroft #include <sys/tty.h>
49 1.14 mycroft #include <sys/proc.h>
50 1.14 mycroft #include <sys/user.h>
51 1.14 mycroft #include <sys/conf.h>
52 1.14 mycroft #include <sys/file.h>
53 1.14 mycroft #include <sys/uio.h>
54 1.14 mycroft #include <sys/kernel.h>
55 1.14 mycroft #include <sys/syslog.h>
56 1.14 mycroft #include <sys/types.h>
57 1.21 mycroft #include <sys/device.h>
58 1.14 mycroft
59 1.78 cgd #ifdef i386 /* XXX */
60 1.78 cgd #include <machine/cpu.h> /* XXX */
61 1.78 cgd #else /* XXX */
62 1.78 cgd #include <machine/intr.h>
63 1.78 cgd #endif /* XXX */
64 1.75 cgd #include <machine/bus.h>
65 1.14 mycroft
66 1.49 cgd #include <dev/isa/isavar.h>
67 1.47 cgd #include <dev/isa/comreg.h>
68 1.74 cgd #include <dev/isa/comvar.h>
69 1.60 cgd #include <dev/ic/ns16550reg.h>
70 1.65 christos #ifdef COM_HAYESP
71 1.65 christos #include <dev/ic/hayespreg.h>
72 1.65 christos #endif
73 1.62 mycroft #define com_lcr com_cfcr
74 1.14 mycroft
75 1.77 cgd #include "com.h"
76 1.77 cgd
77 1.64 christos #define COM_IBUFSIZE (2 * 512)
78 1.57 mycroft #define COM_IHIGHWATER ((3 * COM_IBUFSIZE) / 4)
79 1.57 mycroft
80 1.21 mycroft struct com_softc {
81 1.21 mycroft struct device sc_dev;
82 1.49 cgd void *sc_ih;
83 1.50 mycroft struct tty *sc_tty;
84 1.1 cgd
85 1.33 mycroft int sc_overflows;
86 1.57 mycroft int sc_floods;
87 1.57 mycroft int sc_errors;
88 1.57 mycroft
89 1.66 mycroft int sc_halt;
90 1.66 mycroft
91 1.41 mycroft int sc_iobase;
92 1.65 christos #ifdef COM_HAYESP
93 1.65 christos int sc_hayespbase;
94 1.65 christos #endif
95 1.75 cgd
96 1.75 cgd bus_chipset_tag_t sc_bc;
97 1.75 cgd bus_io_handle_t sc_ioh;
98 1.75 cgd bus_io_handle_t sc_hayespioh;
99 1.75 cgd
100 1.22 cgd u_char sc_hwflags;
101 1.29 mycroft #define COM_HW_NOIEN 0x01
102 1.22 cgd #define COM_HW_FIFO 0x02
103 1.65 christos #define COM_HW_HAYESP 0x04
104 1.22 cgd #define COM_HW_CONSOLE 0x40
105 1.22 cgd u_char sc_swflags;
106 1.22 cgd #define COM_SW_SOFTCAR 0x01
107 1.22 cgd #define COM_SW_CLOCAL 0x02
108 1.22 cgd #define COM_SW_CRTSCTS 0x04
109 1.25 cgd #define COM_SW_MDMBUF 0x08
110 1.69 mycroft u_char sc_msr, sc_mcr, sc_lcr, sc_ier;
111 1.57 mycroft u_char sc_dtr;
112 1.57 mycroft
113 1.57 mycroft u_char *sc_ibuf, *sc_ibufp, *sc_ibufhigh, *sc_ibufend;
114 1.57 mycroft u_char sc_ibufs[2][COM_IBUFSIZE];
115 1.29 mycroft };
116 1.21 mycroft
117 1.75 cgd #ifdef COM_HAYESP
118 1.75 cgd int comprobeHAYESP __P((bus_io_handle_t hayespioh, struct com_softc *sc));
119 1.75 cgd #endif
120 1.21 mycroft int comopen __P((dev_t, int, int, struct proc *));
121 1.21 mycroft int comclose __P((dev_t, int, int, struct proc *));
122 1.33 mycroft void comdiag __P((void *));
123 1.49 cgd int comintr __P((void *));
124 1.57 mycroft void compoll __P((void *));
125 1.21 mycroft int comparam __P((struct tty *, struct termios *));
126 1.21 mycroft void comstart __P((struct tty *));
127 1.1 cgd
128 1.76 thorpej /*
129 1.76 thorpej * XXX the following two cfattach structs should be different, and possibly
130 1.76 thorpej * XXX elsewhere.
131 1.76 thorpej */
132 1.77 cgd int comprobe __P((struct device *, void *, void *));
133 1.77 cgd void comattach __P((struct device *, struct device *, void *));
134 1.77 cgd
135 1.77 cgd #if NCOM_ISA
136 1.76 thorpej struct cfattach com_isa_ca = {
137 1.76 thorpej sizeof(struct com_softc), comprobe, comattach
138 1.76 thorpej };
139 1.77 cgd #endif
140 1.76 thorpej
141 1.77 cgd #if NCOM_COMMULTI
142 1.77 cgd struct cfattach com_commulti_ca = {
143 1.76 thorpej sizeof(struct com_softc), comprobe, comattach
144 1.76 thorpej };
145 1.77 cgd #endif
146 1.75 cgd
147 1.76 thorpej struct cfdriver com_cd = {
148 1.76 thorpej NULL, "com", DV_TTY
149 1.1 cgd };
150 1.1 cgd
151 1.76 thorpej int cominit __P((bus_chipset_tag_t, bus_io_handle_t, int));
152 1.76 thorpej
153 1.1 cgd #ifdef COMCONSOLE
154 1.75 cgd int comdefaultrate = CONSPEED; /* XXX why set default? */
155 1.1 cgd #else
156 1.66 mycroft int comdefaultrate = TTYDEF_SPEED;
157 1.1 cgd #endif
158 1.75 cgd int comconsaddr;
159 1.1 cgd int comconsinit;
160 1.75 cgd int comconsattached;
161 1.75 cgd bus_chipset_tag_t comconsbc;
162 1.75 cgd bus_io_handle_t comconsioh;
163 1.75 cgd
164 1.1 cgd int commajor;
165 1.57 mycroft int comsopen = 0;
166 1.57 mycroft int comevents = 0;
167 1.1 cgd
168 1.1 cgd #ifdef KGDB
169 1.14 mycroft #include <machine/remote-sl.h>
170 1.1 cgd extern int kgdb_dev;
171 1.1 cgd extern int kgdb_rate;
172 1.1 cgd extern int kgdb_debug_init;
173 1.1 cgd #endif
174 1.1 cgd
175 1.21 mycroft #define COMUNIT(x) (minor(x))
176 1.1 cgd
177 1.62 mycroft /* Macros to clear/set/test flags. */
178 1.62 mycroft #define SET(t, f) (t) |= (f)
179 1.62 mycroft #define CLR(t, f) (t) &= ~(f)
180 1.62 mycroft #define ISSET(t, f) ((t) & (f))
181 1.21 mycroft
182 1.21 mycroft int
183 1.21 mycroft comspeed(speed)
184 1.21 mycroft long speed;
185 1.1 cgd {
186 1.21 mycroft #define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
187 1.21 mycroft
188 1.21 mycroft int x, err;
189 1.21 mycroft
190 1.21 mycroft if (speed == 0)
191 1.21 mycroft return 0;
192 1.21 mycroft if (speed < 0)
193 1.21 mycroft return -1;
194 1.21 mycroft x = divrnd((COM_FREQ / 16), speed);
195 1.21 mycroft if (x <= 0)
196 1.21 mycroft return -1;
197 1.21 mycroft err = divrnd((COM_FREQ / 16) * 1000, speed * x) - 1000;
198 1.21 mycroft if (err < 0)
199 1.21 mycroft err = -err;
200 1.21 mycroft if (err > COM_TOLERANCE)
201 1.21 mycroft return -1;
202 1.21 mycroft return x;
203 1.21 mycroft
204 1.21 mycroft #undef divrnd(n, q)
205 1.21 mycroft }
206 1.21 mycroft
207 1.21 mycroft int
208 1.75 cgd comprobe1(bc, ioh, iobase)
209 1.75 cgd bus_chipset_tag_t bc;
210 1.75 cgd bus_io_handle_t ioh;
211 1.41 mycroft int iobase;
212 1.21 mycroft {
213 1.21 mycroft
214 1.1 cgd /* force access to id reg */
215 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, 0);
216 1.75 cgd bus_io_write_1(bc, ioh, com_iir, 0);
217 1.75 cgd if (bus_io_read_1(bc, ioh, com_iir) & 0x38)
218 1.21 mycroft return 0;
219 1.21 mycroft
220 1.21 mycroft return 1;
221 1.1 cgd }
222 1.1 cgd
223 1.65 christos #ifdef COM_HAYESP
224 1.65 christos int
225 1.75 cgd comprobeHAYESP(hayespioh, sc)
226 1.75 cgd bus_io_handle_t hayespioh;
227 1.64 christos struct com_softc *sc;
228 1.64 christos {
229 1.65 christos char val, dips;
230 1.64 christos int combaselist[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
231 1.75 cgd bus_chipset_tag_t bc = sc->sc_bc;
232 1.64 christos
233 1.64 christos /*
234 1.64 christos * Hayes ESP cards have two iobases. One is for compatibility with
235 1.64 christos * 16550 serial chips, and at the same ISA PC base addresses. The
236 1.64 christos * other is for ESP-specific enhanced features, and lies at a
237 1.65 christos * different addressing range entirely (0x140, 0x180, 0x280, or 0x300).
238 1.64 christos */
239 1.64 christos
240 1.64 christos /* Test for ESP signature */
241 1.75 cgd if ((bus_io_read_1(bc, hayespioh, 0) & 0xf3) == 0)
242 1.65 christos return 0;
243 1.64 christos
244 1.64 christos /*
245 1.64 christos * ESP is present at ESP enhanced base address; unknown com port
246 1.64 christos */
247 1.64 christos
248 1.64 christos /* Get the dip-switch configurations */
249 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_GETDIPS);
250 1.75 cgd dips = bus_io_read_1(bc, hayespioh, HAYESP_STATUS1);
251 1.64 christos
252 1.64 christos /* Determine which com port this ESP card services: bits 0,1 of */
253 1.64 christos /* dips is the port # (0-3); combaselist[val] is the com_iobase */
254 1.65 christos if (sc->sc_iobase != combaselist[dips & 0x03])
255 1.65 christos return 0;
256 1.65 christos
257 1.65 christos printf(": ESP");
258 1.64 christos
259 1.65 christos /* Check ESP Self Test bits. */
260 1.64 christos /* Check for ESP version 2.0: bits 4,5,6 == 010 */
261 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_GETTEST);
262 1.75 cgd val = bus_io_read_1(bc, hayespioh, HAYESP_STATUS1); /* Clear reg 1 */
263 1.75 cgd val = bus_io_read_1(bc, hayespioh, HAYESP_STATUS2);
264 1.64 christos if ((val & 0x70) < 0x20) {
265 1.64 christos printf("-old (%o)", val & 0x70);
266 1.64 christos /* we do not support the necessary features */
267 1.65 christos return 0;
268 1.64 christos }
269 1.64 christos
270 1.64 christos /* Check for ability to emulate 16550: bit 8 == 1 */
271 1.64 christos if ((dips & 0x80) == 0) {
272 1.64 christos printf(" slave");
273 1.64 christos /* XXX Does slave really mean no 16550 support?? */
274 1.65 christos return 0;
275 1.64 christos }
276 1.64 christos
277 1.64 christos /*
278 1.64 christos * If we made it this far, we are a full-featured ESP v2.0 (or
279 1.64 christos * better), at the correct com port address.
280 1.64 christos */
281 1.64 christos
282 1.65 christos SET(sc->sc_hwflags, COM_HW_HAYESP);
283 1.73 scottr printf(", 1024 byte fifo\n");
284 1.65 christos return 1;
285 1.64 christos }
286 1.65 christos #endif
287 1.64 christos
288 1.21 mycroft int
289 1.40 mycroft comprobe(parent, match, aux)
290 1.40 mycroft struct device *parent;
291 1.40 mycroft void *match, *aux;
292 1.29 mycroft {
293 1.75 cgd struct cfdata *cf = match;
294 1.75 cgd bus_chipset_tag_t bc;
295 1.75 cgd bus_io_handle_t ioh;
296 1.75 cgd int iobase, needioh;
297 1.75 cgd int rv = 1;
298 1.75 cgd
299 1.76 thorpej /*
300 1.76 thorpej * XXX should be broken out into functions for isa probe and
301 1.76 thorpej * XXX for commulti probe, with a helper function that contains
302 1.76 thorpej * XXX most of the interesting stuff.
303 1.76 thorpej */
304 1.77 cgd #if NCOM_ISA
305 1.75 cgd if (!strcmp(parent->dv_cfdata->cf_driver->cd_name, "isa")) {
306 1.75 cgd struct isa_attach_args *ia = aux;
307 1.75 cgd
308 1.75 cgd bc = ia->ia_bc;
309 1.75 cgd iobase = ia->ia_iobase;
310 1.75 cgd needioh = 1;
311 1.77 cgd } else
312 1.77 cgd #endif
313 1.77 cgd #if NCOM_COMMULTI
314 1.77 cgd if (1) {
315 1.75 cgd struct commulti_attach_args *ca = aux;
316 1.75 cgd
317 1.75 cgd if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != ca->ca_slave)
318 1.75 cgd return (0);
319 1.75 cgd
320 1.75 cgd bc = ca->ca_bc;
321 1.75 cgd iobase = ca->ca_iobase;
322 1.75 cgd ioh = ca->ca_ioh;
323 1.75 cgd needioh = 0;
324 1.77 cgd } else
325 1.77 cgd #endif
326 1.77 cgd return(0); /* This cannot happen */
327 1.75 cgd
328 1.75 cgd /* if it's in use as console, it's there. */
329 1.75 cgd if (iobase == comconsaddr && !comconsattached)
330 1.75 cgd goto out;
331 1.75 cgd
332 1.75 cgd if (needioh && bus_io_map(bc, iobase, COM_NPORTS, &ioh)) {
333 1.75 cgd rv = 0;
334 1.75 cgd goto out;
335 1.75 cgd }
336 1.75 cgd rv = comprobe1(bc, ioh, iobase);
337 1.75 cgd if (needioh)
338 1.75 cgd bus_io_unmap(bc, ioh, COM_NPORTS);
339 1.21 mycroft
340 1.75 cgd out:
341 1.77 cgd #if NCOM_ISA
342 1.75 cgd if (rv && !strcmp(parent->dv_cfdata->cf_driver->cd_name, "isa")) {
343 1.75 cgd struct isa_attach_args *ia = aux;
344 1.21 mycroft
345 1.75 cgd ia->ia_iosize = COM_NPORTS;
346 1.75 cgd ia->ia_msize = 0;
347 1.75 cgd }
348 1.77 cgd #endif
349 1.75 cgd return (rv);
350 1.21 mycroft }
351 1.1 cgd
352 1.29 mycroft void
353 1.29 mycroft comattach(parent, self, aux)
354 1.29 mycroft struct device *parent, *self;
355 1.29 mycroft void *aux;
356 1.29 mycroft {
357 1.29 mycroft struct com_softc *sc = (void *)self;
358 1.29 mycroft struct cfdata *cf = sc->sc_dev.dv_cfdata;
359 1.75 cgd int iobase, irq;
360 1.75 cgd bus_chipset_tag_t bc;
361 1.75 cgd bus_io_handle_t ioh;
362 1.21 mycroft struct tty *tp;
363 1.65 christos #ifdef COM_HAYESP
364 1.65 christos int hayesp_ports[] = { 0x140, 0x180, 0x280, 0x300, 0 };
365 1.65 christos int *hayespp;
366 1.65 christos #endif
367 1.1 cgd
368 1.76 thorpej /*
369 1.76 thorpej * XXX should be broken out into functions for isa attach and
370 1.76 thorpej * XXX for commulti attach, with a helper function that contains
371 1.76 thorpej * XXX most of the interesting stuff.
372 1.76 thorpej */
373 1.75 cgd sc->sc_hwflags = 0;
374 1.75 cgd sc->sc_swflags = 0;
375 1.77 cgd #if NCOM_ISA
376 1.75 cgd if (!strcmp(parent->dv_cfdata->cf_driver->cd_name, "isa")) {
377 1.75 cgd struct isa_attach_args *ia = aux;
378 1.75 cgd
379 1.75 cgd /*
380 1.75 cgd * We're living on an isa.
381 1.75 cgd */
382 1.75 cgd iobase = ia->ia_iobase;
383 1.75 cgd bc = ia->ia_bc;
384 1.75 cgd if (iobase != comconsaddr) {
385 1.75 cgd if (bus_io_map(bc, iobase, COM_NPORTS, &ioh))
386 1.75 cgd panic("comattach: io mapping failed");
387 1.75 cgd } else
388 1.75 cgd ioh = comconsioh;
389 1.75 cgd irq = ia->ia_irq;
390 1.77 cgd } else
391 1.77 cgd #endif
392 1.77 cgd #if NCOM_COMMULTI
393 1.77 cgd if (1) {
394 1.75 cgd struct commulti_attach_args *ca = aux;
395 1.75 cgd
396 1.75 cgd /*
397 1.75 cgd * We're living on a commulti.
398 1.75 cgd */
399 1.75 cgd iobase = ca->ca_iobase;
400 1.75 cgd bc = ca->ca_bc;
401 1.75 cgd ioh = ca->ca_ioh;
402 1.75 cgd irq = IRQUNK;
403 1.75 cgd
404 1.75 cgd if (ca->ca_noien)
405 1.75 cgd sc->sc_hwflags |= COM_HW_NOIEN;
406 1.77 cgd } else
407 1.77 cgd #endif
408 1.77 cgd panic("comattach: impossible");
409 1.75 cgd
410 1.75 cgd sc->sc_bc = bc;
411 1.75 cgd sc->sc_ioh = ioh;
412 1.21 mycroft sc->sc_iobase = iobase;
413 1.21 mycroft
414 1.75 cgd if (iobase == comconsaddr) {
415 1.75 cgd comconsattached = 1;
416 1.75 cgd
417 1.75 cgd /*
418 1.75 cgd * Need to reset baud rate, etc. of next print so reset
419 1.75 cgd * comconsinit. Also make sure console is always "hardwired".
420 1.75 cgd */
421 1.75 cgd delay(1000); /* wait for output to finish */
422 1.75 cgd comconsinit = 0;
423 1.75 cgd SET(sc->sc_hwflags, COM_HW_CONSOLE);
424 1.75 cgd SET(sc->sc_swflags, COM_SW_SOFTCAR);
425 1.75 cgd }
426 1.26 cgd
427 1.65 christos #ifdef COM_HAYESP
428 1.65 christos /* Look for a Hayes ESP board. */
429 1.75 cgd for (hayespp = hayesp_ports; *hayespp != 0; hayespp++) {
430 1.75 cgd bus_io_handle_t hayespioh;
431 1.75 cgd
432 1.75 cgd #define HAYESP_NPORTS 8 /* XXX XXX XXX ??? ??? ??? */
433 1.75 cgd if (bus_io_map(bc, *hayespp, HAYESP_NPORTS, &hayespioh))
434 1.75 cgd continue;
435 1.75 cgd if (comprobeHAYESP(hayespioh, sc)) {
436 1.65 christos sc->sc_hayespbase = *hayespp;
437 1.75 cgd sc->sc_hayespioh = hayespioh;
438 1.65 christos break;
439 1.65 christos }
440 1.75 cgd bus_io_unmap(bc, hayespioh, HAYESP_NPORTS);
441 1.75 cgd }
442 1.65 christos /* No ESP; look for other things. */
443 1.65 christos if (*hayespp == 0) {
444 1.65 christos #endif
445 1.64 christos
446 1.1 cgd /* look for a NS 16550AF UART with FIFOs */
447 1.75 cgd bus_io_write_1(bc, ioh, com_fifo,
448 1.21 mycroft FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14);
449 1.20 mycroft delay(100);
450 1.75 cgd if (ISSET(bus_io_read_1(bc, ioh, com_iir), IIR_FIFO_MASK) == IIR_FIFO_MASK)
451 1.75 cgd if (ISSET(bus_io_read_1(bc, ioh, com_fifo), FIFO_TRIGGER_14) == FIFO_TRIGGER_14) {
452 1.62 mycroft SET(sc->sc_hwflags, COM_HW_FIFO);
453 1.29 mycroft printf(": ns16550a, working fifo\n");
454 1.21 mycroft } else
455 1.56 jtc printf(": ns16550, broken fifo\n");
456 1.21 mycroft else
457 1.56 jtc printf(": ns8250 or ns16450, no fifo\n");
458 1.75 cgd bus_io_write_1(bc, ioh, com_fifo, 0);
459 1.65 christos #ifdef COM_HAYESP
460 1.65 christos }
461 1.65 christos #endif
462 1.21 mycroft
463 1.21 mycroft /* disable interrupts */
464 1.75 cgd bus_io_write_1(bc, ioh, com_ier, 0);
465 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, 0);
466 1.1 cgd
467 1.78 cgd if (irq != IRQUNK) {
468 1.78 cgd #if NCOM_ISA
469 1.78 cgd if (!strcmp(parent->dv_cfdata->cf_driver->cd_name, "isa")) {
470 1.78 cgd struct isa_attach_args *ia = aux;
471 1.78 cgd
472 1.78 cgd sc->sc_ih = isa_intr_establish(ia->ia_ic, irq,
473 1.78 cgd IST_EDGE, IPL_TTY, comintr, sc);
474 1.78 cgd } else
475 1.78 cgd #endif
476 1.78 cgd panic("comattach: IRQ but can't have one");
477 1.78 cgd }
478 1.30 mycroft
479 1.1 cgd #ifdef KGDB
480 1.2 cgd if (kgdb_dev == makedev(commajor, unit)) {
481 1.75 cgd if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
482 1.1 cgd kgdb_dev = -1; /* can't debug over console port */
483 1.1 cgd else {
484 1.75 cgd (void) cominit(bc, ioh, kgdb_rate);
485 1.1 cgd if (kgdb_debug_init) {
486 1.1 cgd /*
487 1.1 cgd * Print prefix of device name,
488 1.1 cgd * let kgdb_connect print the rest.
489 1.1 cgd */
490 1.21 mycroft printf("%s: ", sc->sc_dev.dv_xname);
491 1.1 cgd kgdb_connect(1);
492 1.1 cgd } else
493 1.21 mycroft printf("%s: kgdb enabled\n",
494 1.21 mycroft sc->sc_dev.dv_xname);
495 1.1 cgd }
496 1.1 cgd }
497 1.1 cgd #endif
498 1.21 mycroft
499 1.75 cgd /* XXX maybe move up some? */
500 1.75 cgd if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
501 1.75 cgd printf("%s: console\n", sc->sc_dev.dv_xname);
502 1.1 cgd }
503 1.1 cgd
504 1.21 mycroft int
505 1.21 mycroft comopen(dev, flag, mode, p)
506 1.21 mycroft dev_t dev;
507 1.21 mycroft int flag, mode;
508 1.21 mycroft struct proc *p;
509 1.1 cgd {
510 1.21 mycroft int unit = COMUNIT(dev);
511 1.21 mycroft struct com_softc *sc;
512 1.75 cgd bus_chipset_tag_t bc;
513 1.75 cgd bus_io_handle_t ioh;
514 1.21 mycroft struct tty *tp;
515 1.21 mycroft int s;
516 1.1 cgd int error = 0;
517 1.1 cgd
518 1.76 thorpej if (unit >= com_cd.cd_ndevs)
519 1.21 mycroft return ENXIO;
520 1.76 thorpej sc = com_cd.cd_devs[unit];
521 1.29 mycroft if (!sc)
522 1.21 mycroft return ENXIO;
523 1.21 mycroft
524 1.50 mycroft if (!sc->sc_tty)
525 1.50 mycroft tp = sc->sc_tty = ttymalloc();
526 1.21 mycroft else
527 1.50 mycroft tp = sc->sc_tty;
528 1.21 mycroft
529 1.1 cgd tp->t_oproc = comstart;
530 1.1 cgd tp->t_param = comparam;
531 1.1 cgd tp->t_dev = dev;
532 1.62 mycroft if (!ISSET(tp->t_state, TS_ISOPEN)) {
533 1.62 mycroft SET(tp->t_state, TS_WOPEN);
534 1.1 cgd ttychars(tp);
535 1.16 ws tp->t_iflag = TTYDEF_IFLAG;
536 1.16 ws tp->t_oflag = TTYDEF_OFLAG;
537 1.16 ws tp->t_cflag = TTYDEF_CFLAG;
538 1.62 mycroft if (ISSET(sc->sc_swflags, COM_SW_CLOCAL))
539 1.62 mycroft SET(tp->t_cflag, CLOCAL);
540 1.62 mycroft if (ISSET(sc->sc_swflags, COM_SW_CRTSCTS))
541 1.62 mycroft SET(tp->t_cflag, CRTSCTS);
542 1.62 mycroft if (ISSET(sc->sc_swflags, COM_SW_MDMBUF))
543 1.62 mycroft SET(tp->t_cflag, MDMBUF);
544 1.16 ws tp->t_lflag = TTYDEF_LFLAG;
545 1.16 ws tp->t_ispeed = tp->t_ospeed = comdefaultrate;
546 1.57 mycroft
547 1.57 mycroft s = spltty();
548 1.57 mycroft
549 1.1 cgd comparam(tp, &tp->t_termios);
550 1.1 cgd ttsetwater(tp);
551 1.21 mycroft
552 1.57 mycroft if (comsopen++ == 0)
553 1.57 mycroft timeout(compoll, NULL, 1);
554 1.57 mycroft
555 1.57 mycroft sc->sc_ibufp = sc->sc_ibuf = sc->sc_ibufs[0];
556 1.57 mycroft sc->sc_ibufhigh = sc->sc_ibuf + COM_IHIGHWATER;
557 1.57 mycroft sc->sc_ibufend = sc->sc_ibuf + COM_IBUFSIZE;
558 1.57 mycroft
559 1.75 cgd bc = sc->sc_bc;
560 1.75 cgd ioh = sc->sc_ioh;
561 1.65 christos #ifdef COM_HAYESP
562 1.64 christos /* Setup the ESP board */
563 1.65 christos if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
564 1.75 cgd bus_io_handle_t hayespioh = sc->sc_hayespioh;
565 1.65 christos
566 1.75 cgd bus_io_write_1(bc, ioh, com_fifo,
567 1.64 christos FIFO_DMA_MODE|FIFO_ENABLE|
568 1.64 christos FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_8);
569 1.65 christos
570 1.64 christos /* Set 16550 compatibility mode */
571 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_SETMODE);
572 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD2,
573 1.65 christos HAYESP_MODE_FIFO|HAYESP_MODE_RTS|
574 1.65 christos HAYESP_MODE_SCALE);
575 1.65 christos
576 1.64 christos /* Set RTS/CTS flow control */
577 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_SETFLOWTYPE);
578 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD2, HAYESP_FLOW_RTS);
579 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD2, HAYESP_FLOW_CTS);
580 1.65 christos
581 1.64 christos /* Set flow control levels */
582 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_SETRXFLOW);
583 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD2,
584 1.65 christos HAYESP_HIBYTE(HAYESP_RXHIWMARK));
585 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD2,
586 1.65 christos HAYESP_LOBYTE(HAYESP_RXHIWMARK));
587 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD2,
588 1.65 christos HAYESP_HIBYTE(HAYESP_RXLOWMARK));
589 1.75 cgd bus_io_write_1(bc, hayespioh, HAYESP_CMD2,
590 1.65 christos HAYESP_LOBYTE(HAYESP_RXLOWMARK));
591 1.65 christos } else
592 1.65 christos #endif
593 1.65 christos if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
594 1.64 christos /* Set the FIFO threshold based on the receive speed. */
595 1.75 cgd bus_io_write_1(bc, ioh, com_fifo,
596 1.36 mycroft FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST |
597 1.36 mycroft (tp->t_ispeed <= 1200 ? FIFO_TRIGGER_1 : FIFO_TRIGGER_8));
598 1.21 mycroft /* flush any pending I/O */
599 1.75 cgd while (ISSET(bus_io_read_1(bc, ioh, com_lsr), LSR_RXRDY))
600 1.75 cgd (void) bus_io_read_1(bc, ioh, com_data);
601 1.21 mycroft /* you turn me on, baby */
602 1.26 cgd sc->sc_mcr = MCR_DTR | MCR_RTS;
603 1.62 mycroft if (!ISSET(sc->sc_hwflags, COM_HW_NOIEN))
604 1.62 mycroft SET(sc->sc_mcr, MCR_IENABLE);
605 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
606 1.69 mycroft sc->sc_ier = IER_ERXRDY | IER_ERLS | IER_EMSC;
607 1.75 cgd bus_io_write_1(bc, ioh, com_ier, sc->sc_ier);
608 1.21 mycroft
609 1.75 cgd sc->sc_msr = bus_io_read_1(bc, ioh, com_msr);
610 1.62 mycroft if (ISSET(sc->sc_swflags, COM_SW_SOFTCAR) ||
611 1.62 mycroft ISSET(sc->sc_msr, MSR_DCD) || ISSET(tp->t_cflag, MDMBUF))
612 1.62 mycroft SET(tp->t_state, TS_CARR_ON);
613 1.21 mycroft else
614 1.62 mycroft CLR(tp->t_state, TS_CARR_ON);
615 1.62 mycroft } else if (ISSET(tp->t_state, TS_XCLUDE) && p->p_ucred->cr_uid != 0)
616 1.21 mycroft return EBUSY;
617 1.62 mycroft else
618 1.57 mycroft s = spltty();
619 1.21 mycroft
620 1.21 mycroft /* wait for carrier if necessary */
621 1.62 mycroft if (!ISSET(flag, O_NONBLOCK))
622 1.62 mycroft while (!ISSET(tp->t_cflag, CLOCAL) &&
623 1.62 mycroft !ISSET(tp->t_state, TS_CARR_ON)) {
624 1.62 mycroft SET(tp->t_state, TS_WOPEN);
625 1.62 mycroft error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
626 1.62 mycroft ttopen, 0);
627 1.21 mycroft if (error) {
628 1.21 mycroft /* XXX should turn off chip if we're the
629 1.21 mycroft only waiter */
630 1.21 mycroft splx(s);
631 1.21 mycroft return error;
632 1.21 mycroft }
633 1.21 mycroft }
634 1.21 mycroft splx(s);
635 1.21 mycroft
636 1.21 mycroft return (*linesw[tp->t_line].l_open)(dev, tp);
637 1.1 cgd }
638 1.1 cgd
639 1.21 mycroft int
640 1.1 cgd comclose(dev, flag, mode, p)
641 1.1 cgd dev_t dev;
642 1.1 cgd int flag, mode;
643 1.1 cgd struct proc *p;
644 1.1 cgd {
645 1.21 mycroft int unit = COMUNIT(dev);
646 1.76 thorpej struct com_softc *sc = com_cd.cd_devs[unit];
647 1.50 mycroft struct tty *tp = sc->sc_tty;
648 1.75 cgd bus_chipset_tag_t bc = sc->sc_bc;
649 1.75 cgd bus_io_handle_t ioh = sc->sc_ioh;
650 1.57 mycroft int s;
651 1.57 mycroft
652 1.57 mycroft /* XXX This is for cons.c. */
653 1.62 mycroft if (!ISSET(tp->t_state, TS_ISOPEN))
654 1.57 mycroft return 0;
655 1.21 mycroft
656 1.1 cgd (*linesw[tp->t_line].l_close)(tp, flag);
657 1.57 mycroft s = spltty();
658 1.62 mycroft CLR(sc->sc_lcr, LCR_SBREAK);
659 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, sc->sc_lcr);
660 1.75 cgd bus_io_write_1(bc, ioh, com_ier, 0);
661 1.62 mycroft if (ISSET(tp->t_cflag, HUPCL) &&
662 1.62 mycroft !ISSET(sc->sc_swflags, COM_SW_SOFTCAR)) {
663 1.57 mycroft /* XXX perhaps only clear DTR */
664 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, 0);
665 1.57 mycroft }
666 1.62 mycroft CLR(tp->t_state, TS_BUSY | TS_FLUSH);
667 1.57 mycroft if (--comsopen == 0)
668 1.57 mycroft untimeout(compoll, NULL);
669 1.57 mycroft splx(s);
670 1.1 cgd ttyclose(tp);
671 1.21 mycroft #ifdef notyet /* XXXX */
672 1.75 cgd if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
673 1.21 mycroft ttyfree(tp);
674 1.50 mycroft sc->sc_tty = 0;
675 1.21 mycroft }
676 1.13 cgd #endif
677 1.21 mycroft return 0;
678 1.1 cgd }
679 1.1 cgd
680 1.21 mycroft int
681 1.1 cgd comread(dev, uio, flag)
682 1.1 cgd dev_t dev;
683 1.1 cgd struct uio *uio;
684 1.21 mycroft int flag;
685 1.1 cgd {
686 1.76 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
687 1.52 mycroft struct tty *tp = sc->sc_tty;
688 1.1 cgd
689 1.1 cgd return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
690 1.1 cgd }
691 1.1 cgd
692 1.21 mycroft int
693 1.1 cgd comwrite(dev, uio, flag)
694 1.1 cgd dev_t dev;
695 1.1 cgd struct uio *uio;
696 1.21 mycroft int flag;
697 1.1 cgd {
698 1.76 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
699 1.52 mycroft struct tty *tp = sc->sc_tty;
700 1.1 cgd
701 1.1 cgd return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
702 1.1 cgd }
703 1.50 mycroft
704 1.50 mycroft struct tty *
705 1.50 mycroft comtty(dev)
706 1.50 mycroft dev_t dev;
707 1.50 mycroft {
708 1.76 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
709 1.52 mycroft struct tty *tp = sc->sc_tty;
710 1.50 mycroft
711 1.52 mycroft return (tp);
712 1.50 mycroft }
713 1.1 cgd
714 1.21 mycroft static u_char
715 1.21 mycroft tiocm_xxx2mcr(data)
716 1.21 mycroft int data;
717 1.21 mycroft {
718 1.21 mycroft u_char m = 0;
719 1.21 mycroft
720 1.62 mycroft if (ISSET(data, TIOCM_DTR))
721 1.62 mycroft SET(m, MCR_DTR);
722 1.62 mycroft if (ISSET(data, TIOCM_RTS))
723 1.62 mycroft SET(m, MCR_RTS);
724 1.21 mycroft return m;
725 1.1 cgd }
726 1.1 cgd
727 1.21 mycroft int
728 1.19 mycroft comioctl(dev, cmd, data, flag, p)
729 1.1 cgd dev_t dev;
730 1.39 cgd u_long cmd;
731 1.1 cgd caddr_t data;
732 1.19 mycroft int flag;
733 1.19 mycroft struct proc *p;
734 1.1 cgd {
735 1.21 mycroft int unit = COMUNIT(dev);
736 1.76 thorpej struct com_softc *sc = com_cd.cd_devs[unit];
737 1.50 mycroft struct tty *tp = sc->sc_tty;
738 1.75 cgd bus_chipset_tag_t bc = sc->sc_bc;
739 1.75 cgd bus_io_handle_t ioh = sc->sc_ioh;
740 1.21 mycroft int error;
741 1.21 mycroft
742 1.19 mycroft error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
743 1.1 cgd if (error >= 0)
744 1.21 mycroft return error;
745 1.19 mycroft error = ttioctl(tp, cmd, data, flag, p);
746 1.1 cgd if (error >= 0)
747 1.21 mycroft return error;
748 1.1 cgd
749 1.1 cgd switch (cmd) {
750 1.1 cgd case TIOCSBRK:
751 1.62 mycroft SET(sc->sc_lcr, LCR_SBREAK);
752 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, sc->sc_lcr);
753 1.1 cgd break;
754 1.1 cgd case TIOCCBRK:
755 1.62 mycroft CLR(sc->sc_lcr, LCR_SBREAK);
756 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, sc->sc_lcr);
757 1.1 cgd break;
758 1.1 cgd case TIOCSDTR:
759 1.62 mycroft SET(sc->sc_mcr, sc->sc_dtr);
760 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
761 1.1 cgd break;
762 1.1 cgd case TIOCCDTR:
763 1.62 mycroft CLR(sc->sc_mcr, sc->sc_dtr);
764 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
765 1.1 cgd break;
766 1.1 cgd case TIOCMSET:
767 1.62 mycroft CLR(sc->sc_mcr, MCR_DTR | MCR_RTS);
768 1.1 cgd case TIOCMBIS:
769 1.62 mycroft SET(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data));
770 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
771 1.1 cgd break;
772 1.1 cgd case TIOCMBIC:
773 1.62 mycroft CLR(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data));
774 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
775 1.1 cgd break;
776 1.21 mycroft case TIOCMGET: {
777 1.21 mycroft u_char m;
778 1.21 mycroft int bits = 0;
779 1.21 mycroft
780 1.21 mycroft m = sc->sc_mcr;
781 1.62 mycroft if (ISSET(m, MCR_DTR))
782 1.62 mycroft SET(bits, TIOCM_DTR);
783 1.62 mycroft if (ISSET(m, MCR_RTS))
784 1.62 mycroft SET(bits, TIOCM_RTS);
785 1.21 mycroft m = sc->sc_msr;
786 1.62 mycroft if (ISSET(m, MSR_DCD))
787 1.62 mycroft SET(bits, TIOCM_CD);
788 1.62 mycroft if (ISSET(m, MSR_CTS))
789 1.62 mycroft SET(bits, TIOCM_CTS);
790 1.62 mycroft if (ISSET(m, MSR_DSR))
791 1.62 mycroft SET(bits, TIOCM_DSR);
792 1.62 mycroft if (ISSET(m, MSR_RI | MSR_TERI))
793 1.62 mycroft SET(bits, TIOCM_RI);
794 1.75 cgd if (bus_io_read_1(bc, ioh, com_ier))
795 1.62 mycroft SET(bits, TIOCM_LE);
796 1.21 mycroft *(int *)data = bits;
797 1.1 cgd break;
798 1.21 mycroft }
799 1.22 cgd case TIOCGFLAGS: {
800 1.62 mycroft int driverbits, userbits = 0;
801 1.22 cgd
802 1.62 mycroft driverbits = sc->sc_swflags;
803 1.62 mycroft if (ISSET(driverbits, COM_SW_SOFTCAR))
804 1.62 mycroft SET(userbits, TIOCFLAG_SOFTCAR);
805 1.62 mycroft if (ISSET(driverbits, COM_SW_CLOCAL))
806 1.62 mycroft SET(userbits, TIOCFLAG_CLOCAL);
807 1.62 mycroft if (ISSET(driverbits, COM_SW_CRTSCTS))
808 1.62 mycroft SET(userbits, TIOCFLAG_CRTSCTS);
809 1.62 mycroft if (ISSET(driverbits, COM_SW_MDMBUF))
810 1.62 mycroft SET(userbits, TIOCFLAG_MDMBUF);
811 1.22 cgd
812 1.62 mycroft *(int *)data = userbits;
813 1.22 cgd break;
814 1.22 cgd }
815 1.22 cgd case TIOCSFLAGS: {
816 1.22 cgd int userbits, driverbits = 0;
817 1.22 cgd
818 1.23 cgd error = suser(p->p_ucred, &p->p_acflag);
819 1.23 cgd if (error != 0)
820 1.23 cgd return(EPERM);
821 1.22 cgd
822 1.22 cgd userbits = *(int *)data;
823 1.62 mycroft if (ISSET(userbits, TIOCFLAG_SOFTCAR) ||
824 1.62 mycroft ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
825 1.62 mycroft SET(driverbits, COM_SW_SOFTCAR);
826 1.62 mycroft if (ISSET(userbits, TIOCFLAG_CLOCAL))
827 1.62 mycroft SET(driverbits, COM_SW_CLOCAL);
828 1.62 mycroft if (ISSET(userbits, TIOCFLAG_CRTSCTS))
829 1.62 mycroft SET(driverbits, COM_SW_CRTSCTS);
830 1.62 mycroft if (ISSET(userbits, TIOCFLAG_MDMBUF))
831 1.62 mycroft SET(driverbits, COM_SW_MDMBUF);
832 1.22 cgd
833 1.23 cgd sc->sc_swflags = driverbits;
834 1.22 cgd break;
835 1.22 cgd }
836 1.1 cgd default:
837 1.21 mycroft return ENOTTY;
838 1.1 cgd }
839 1.21 mycroft
840 1.21 mycroft return 0;
841 1.1 cgd }
842 1.1 cgd
843 1.21 mycroft int
844 1.1 cgd comparam(tp, t)
845 1.21 mycroft struct tty *tp;
846 1.21 mycroft struct termios *t;
847 1.1 cgd {
848 1.76 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
849 1.75 cgd bus_chipset_tag_t bc = sc->sc_bc;
850 1.75 cgd bus_io_handle_t ioh = sc->sc_ioh;
851 1.21 mycroft int ospeed = comspeed(t->c_ospeed);
852 1.62 mycroft u_char lcr;
853 1.57 mycroft tcflag_t oldcflag;
854 1.21 mycroft int s;
855 1.21 mycroft
856 1.1 cgd /* check requested parameters */
857 1.21 mycroft if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
858 1.21 mycroft return EINVAL;
859 1.21 mycroft
860 1.66 mycroft lcr = ISSET(sc->sc_lcr, LCR_SBREAK);
861 1.62 mycroft
862 1.62 mycroft switch (ISSET(t->c_cflag, CSIZE)) {
863 1.1 cgd case CS5:
864 1.62 mycroft SET(lcr, LCR_5BITS);
865 1.21 mycroft break;
866 1.1 cgd case CS6:
867 1.62 mycroft SET(lcr, LCR_6BITS);
868 1.21 mycroft break;
869 1.1 cgd case CS7:
870 1.62 mycroft SET(lcr, LCR_7BITS);
871 1.21 mycroft break;
872 1.1 cgd case CS8:
873 1.62 mycroft SET(lcr, LCR_8BITS);
874 1.21 mycroft break;
875 1.1 cgd }
876 1.62 mycroft if (ISSET(t->c_cflag, PARENB)) {
877 1.62 mycroft SET(lcr, LCR_PENAB);
878 1.62 mycroft if (!ISSET(t->c_cflag, PARODD))
879 1.62 mycroft SET(lcr, LCR_PEVEN);
880 1.1 cgd }
881 1.62 mycroft if (ISSET(t->c_cflag, CSTOPB))
882 1.62 mycroft SET(lcr, LCR_STOPB);
883 1.62 mycroft
884 1.62 mycroft sc->sc_lcr = lcr;
885 1.1 cgd
886 1.21 mycroft s = spltty();
887 1.35 mycroft
888 1.62 mycroft if (ospeed == 0) {
889 1.62 mycroft CLR(sc->sc_mcr, MCR_DTR);
890 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
891 1.62 mycroft }
892 1.36 mycroft
893 1.36 mycroft /*
894 1.36 mycroft * Set the FIFO threshold based on the receive speed, if we are
895 1.36 mycroft * changing it.
896 1.36 mycroft */
897 1.66 mycroft #if 1
898 1.65 christos if (tp->t_ispeed != t->c_ispeed) {
899 1.66 mycroft #else
900 1.66 mycroft if (1) {
901 1.66 mycroft #endif
902 1.66 mycroft if (ospeed != 0) {
903 1.66 mycroft /*
904 1.66 mycroft * Make sure the transmit FIFO is empty before
905 1.67 mycroft * proceeding. If we don't do this, some revisions
906 1.67 mycroft * of the UART will hang. Interestingly enough,
907 1.67 mycroft * even if we do this will the last character is
908 1.67 mycroft * still being pushed out, they don't hang. This
909 1.67 mycroft * seems good enough.
910 1.66 mycroft */
911 1.66 mycroft while (ISSET(tp->t_state, TS_BUSY)) {
912 1.66 mycroft int error;
913 1.66 mycroft
914 1.66 mycroft ++sc->sc_halt;
915 1.66 mycroft error = ttysleep(tp, &tp->t_outq,
916 1.66 mycroft TTOPRI | PCATCH, "comprm", 0);
917 1.66 mycroft --sc->sc_halt;
918 1.66 mycroft if (error) {
919 1.66 mycroft splx(s);
920 1.66 mycroft comstart(tp);
921 1.66 mycroft return (error);
922 1.66 mycroft }
923 1.66 mycroft }
924 1.66 mycroft
925 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, lcr | LCR_DLAB);
926 1.75 cgd bus_io_write_1(bc, ioh, com_dlbl, ospeed);
927 1.75 cgd bus_io_write_1(bc, ioh, com_dlbh, ospeed >> 8);
928 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, lcr);
929 1.66 mycroft SET(sc->sc_mcr, MCR_DTR);
930 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
931 1.66 mycroft } else
932 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, lcr);
933 1.66 mycroft
934 1.66 mycroft if (!ISSET(sc->sc_hwflags, COM_HW_HAYESP) &&
935 1.66 mycroft ISSET(sc->sc_hwflags, COM_HW_FIFO))
936 1.75 cgd bus_io_write_1(bc, ioh, com_fifo,
937 1.57 mycroft FIFO_ENABLE |
938 1.36 mycroft (t->c_ispeed <= 1200 ? FIFO_TRIGGER_1 : FIFO_TRIGGER_8));
939 1.57 mycroft } else
940 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, lcr);
941 1.21 mycroft
942 1.22 cgd /* When not using CRTSCTS, RTS follows DTR. */
943 1.62 mycroft if (!ISSET(t->c_cflag, CRTSCTS)) {
944 1.62 mycroft if (ISSET(sc->sc_mcr, MCR_DTR)) {
945 1.62 mycroft if (!ISSET(sc->sc_mcr, MCR_RTS)) {
946 1.62 mycroft SET(sc->sc_mcr, MCR_RTS);
947 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
948 1.62 mycroft }
949 1.21 mycroft } else {
950 1.62 mycroft if (ISSET(sc->sc_mcr, MCR_RTS)) {
951 1.62 mycroft CLR(sc->sc_mcr, MCR_RTS);
952 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
953 1.62 mycroft }
954 1.21 mycroft }
955 1.57 mycroft sc->sc_dtr = MCR_DTR | MCR_RTS;
956 1.57 mycroft } else
957 1.57 mycroft sc->sc_dtr = MCR_DTR;
958 1.21 mycroft
959 1.57 mycroft /* and copy to tty */
960 1.57 mycroft tp->t_ispeed = t->c_ispeed;
961 1.57 mycroft tp->t_ospeed = t->c_ospeed;
962 1.57 mycroft oldcflag = tp->t_cflag;
963 1.57 mycroft tp->t_cflag = t->c_cflag;
964 1.25 cgd
965 1.25 cgd /*
966 1.57 mycroft * If DCD is off and MDMBUF is changed, ask the tty layer if we should
967 1.57 mycroft * stop the device.
968 1.25 cgd */
969 1.62 mycroft if (!ISSET(sc->sc_msr, MSR_DCD) &&
970 1.62 mycroft !ISSET(sc->sc_swflags, COM_SW_SOFTCAR) &&
971 1.62 mycroft ISSET(oldcflag, MDMBUF) != ISSET(tp->t_cflag, MDMBUF) &&
972 1.57 mycroft (*linesw[tp->t_line].l_modem)(tp, 0) == 0) {
973 1.62 mycroft CLR(sc->sc_mcr, sc->sc_dtr);
974 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
975 1.21 mycroft }
976 1.1 cgd
977 1.66 mycroft /* Just to be sure... */
978 1.21 mycroft splx(s);
979 1.66 mycroft comstart(tp);
980 1.21 mycroft return 0;
981 1.1 cgd }
982 1.21 mycroft
983 1.12 deraadt void
984 1.1 cgd comstart(tp)
985 1.21 mycroft struct tty *tp;
986 1.1 cgd {
987 1.76 thorpej struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
988 1.75 cgd bus_chipset_tag_t bc = sc->sc_bc;
989 1.75 cgd bus_io_handle_t ioh = sc->sc_ioh;
990 1.21 mycroft int s;
991 1.21 mycroft
992 1.1 cgd s = spltty();
993 1.69 mycroft if (ISSET(tp->t_state, TS_BUSY))
994 1.70 mycroft goto out;
995 1.69 mycroft if (ISSET(tp->t_state, TS_TIMEOUT | TS_TTSTOP) ||
996 1.69 mycroft sc->sc_halt > 0)
997 1.69 mycroft goto stopped;
998 1.62 mycroft if (ISSET(tp->t_cflag, CRTSCTS) && !ISSET(sc->sc_msr, MSR_CTS))
999 1.69 mycroft goto stopped;
1000 1.61 mycroft if (tp->t_outq.c_cc <= tp->t_lowat) {
1001 1.62 mycroft if (ISSET(tp->t_state, TS_ASLEEP)) {
1002 1.62 mycroft CLR(tp->t_state, TS_ASLEEP);
1003 1.62 mycroft wakeup(&tp->t_outq);
1004 1.61 mycroft }
1005 1.61 mycroft if (tp->t_outq.c_cc == 0)
1006 1.69 mycroft goto stopped;
1007 1.61 mycroft selwakeup(&tp->t_wsel);
1008 1.61 mycroft }
1009 1.62 mycroft SET(tp->t_state, TS_BUSY);
1010 1.64 christos
1011 1.70 mycroft if (!ISSET(sc->sc_ier, IER_ETXRDY)) {
1012 1.70 mycroft SET(sc->sc_ier, IER_ETXRDY);
1013 1.75 cgd bus_io_write_1(bc, ioh, com_ier, sc->sc_ier);
1014 1.70 mycroft }
1015 1.65 christos #ifdef COM_HAYESP
1016 1.65 christos if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
1017 1.64 christos u_char buffer[1024], *cp = buffer;
1018 1.64 christos int n = q_to_b(&tp->t_outq, cp, sizeof buffer);
1019 1.64 christos do
1020 1.75 cgd bus_io_write_1(bc, ioh, com_data, *cp++);
1021 1.64 christos while (--n);
1022 1.64 christos }
1023 1.65 christos else
1024 1.65 christos #endif
1025 1.65 christos if (ISSET(sc->sc_hwflags, COM_HW_FIFO)) {
1026 1.21 mycroft u_char buffer[16], *cp = buffer;
1027 1.21 mycroft int n = q_to_b(&tp->t_outq, cp, sizeof buffer);
1028 1.21 mycroft do {
1029 1.75 cgd bus_io_write_1(bc, ioh, com_data, *cp++);
1030 1.21 mycroft } while (--n);
1031 1.21 mycroft } else
1032 1.75 cgd bus_io_write_1(bc, ioh, com_data, getc(&tp->t_outq));
1033 1.70 mycroft out:
1034 1.69 mycroft splx(s);
1035 1.69 mycroft return;
1036 1.69 mycroft stopped:
1037 1.69 mycroft if (ISSET(sc->sc_ier, IER_ETXRDY)) {
1038 1.69 mycroft CLR(sc->sc_ier, IER_ETXRDY);
1039 1.75 cgd bus_io_write_1(bc, ioh, com_ier, sc->sc_ier);
1040 1.69 mycroft }
1041 1.1 cgd splx(s);
1042 1.1 cgd }
1043 1.21 mycroft
1044 1.1 cgd /*
1045 1.1 cgd * Stop output on a line.
1046 1.1 cgd */
1047 1.21 mycroft void
1048 1.1 cgd comstop(tp, flag)
1049 1.21 mycroft struct tty *tp;
1050 1.1 cgd {
1051 1.21 mycroft int s;
1052 1.1 cgd
1053 1.1 cgd s = spltty();
1054 1.62 mycroft if (ISSET(tp->t_state, TS_BUSY))
1055 1.62 mycroft if (!ISSET(tp->t_state, TS_TTSTOP))
1056 1.62 mycroft SET(tp->t_state, TS_FLUSH);
1057 1.1 cgd splx(s);
1058 1.1 cgd }
1059 1.1 cgd
1060 1.33 mycroft void
1061 1.33 mycroft comdiag(arg)
1062 1.33 mycroft void *arg;
1063 1.33 mycroft {
1064 1.33 mycroft struct com_softc *sc = arg;
1065 1.57 mycroft int overflows, floods;
1066 1.33 mycroft int s;
1067 1.33 mycroft
1068 1.33 mycroft s = spltty();
1069 1.57 mycroft sc->sc_errors = 0;
1070 1.33 mycroft overflows = sc->sc_overflows;
1071 1.33 mycroft sc->sc_overflows = 0;
1072 1.57 mycroft floods = sc->sc_floods;
1073 1.57 mycroft sc->sc_floods = 0;
1074 1.57 mycroft splx(s);
1075 1.57 mycroft
1076 1.57 mycroft log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf overflow%s\n",
1077 1.57 mycroft sc->sc_dev.dv_xname,
1078 1.57 mycroft overflows, overflows == 1 ? "" : "s",
1079 1.57 mycroft floods, floods == 1 ? "" : "s");
1080 1.57 mycroft }
1081 1.57 mycroft
1082 1.57 mycroft void
1083 1.57 mycroft compoll(arg)
1084 1.57 mycroft void *arg;
1085 1.57 mycroft {
1086 1.57 mycroft int unit;
1087 1.57 mycroft struct com_softc *sc;
1088 1.57 mycroft struct tty *tp;
1089 1.57 mycroft register u_char *ibufp;
1090 1.57 mycroft u_char *ibufend;
1091 1.57 mycroft register int c;
1092 1.57 mycroft int s;
1093 1.57 mycroft static int lsrmap[8] = {
1094 1.57 mycroft 0, TTY_PE,
1095 1.57 mycroft TTY_FE, TTY_PE|TTY_FE,
1096 1.57 mycroft TTY_FE, TTY_PE|TTY_FE,
1097 1.57 mycroft TTY_FE, TTY_PE|TTY_FE
1098 1.57 mycroft };
1099 1.57 mycroft
1100 1.57 mycroft s = spltty();
1101 1.57 mycroft if (comevents == 0) {
1102 1.57 mycroft splx(s);
1103 1.57 mycroft goto out;
1104 1.57 mycroft }
1105 1.57 mycroft comevents = 0;
1106 1.33 mycroft splx(s);
1107 1.33 mycroft
1108 1.76 thorpej for (unit = 0; unit < com_cd.cd_ndevs; unit++) {
1109 1.76 thorpej sc = com_cd.cd_devs[unit];
1110 1.57 mycroft if (sc == 0 || sc->sc_ibufp == sc->sc_ibuf)
1111 1.57 mycroft continue;
1112 1.57 mycroft
1113 1.57 mycroft tp = sc->sc_tty;
1114 1.57 mycroft
1115 1.57 mycroft s = spltty();
1116 1.57 mycroft
1117 1.57 mycroft ibufp = sc->sc_ibuf;
1118 1.57 mycroft ibufend = sc->sc_ibufp;
1119 1.61 mycroft
1120 1.61 mycroft if (ibufp == ibufend) {
1121 1.61 mycroft splx(s);
1122 1.61 mycroft continue;
1123 1.61 mycroft }
1124 1.57 mycroft
1125 1.57 mycroft sc->sc_ibufp = sc->sc_ibuf = (ibufp == sc->sc_ibufs[0]) ?
1126 1.57 mycroft sc->sc_ibufs[1] : sc->sc_ibufs[0];
1127 1.57 mycroft sc->sc_ibufhigh = sc->sc_ibuf + COM_IHIGHWATER;
1128 1.57 mycroft sc->sc_ibufend = sc->sc_ibuf + COM_IBUFSIZE;
1129 1.57 mycroft
1130 1.62 mycroft if (tp == 0 || !ISSET(tp->t_state, TS_ISOPEN)) {
1131 1.57 mycroft splx(s);
1132 1.57 mycroft continue;
1133 1.57 mycroft }
1134 1.57 mycroft
1135 1.62 mycroft if (ISSET(tp->t_cflag, CRTSCTS) &&
1136 1.62 mycroft !ISSET(sc->sc_mcr, MCR_RTS)) {
1137 1.62 mycroft /* XXX */
1138 1.62 mycroft SET(sc->sc_mcr, MCR_RTS);
1139 1.75 cgd bus_io_write_1(sc->sc_bc, sc->sc_ioh, com_mcr,
1140 1.75 cgd sc->sc_mcr);
1141 1.62 mycroft }
1142 1.57 mycroft
1143 1.57 mycroft splx(s);
1144 1.57 mycroft
1145 1.57 mycroft while (ibufp < ibufend) {
1146 1.57 mycroft c = *ibufp++;
1147 1.57 mycroft if (*ibufp & LSR_OE) {
1148 1.57 mycroft sc->sc_overflows++;
1149 1.57 mycroft if (sc->sc_errors++ == 0)
1150 1.57 mycroft timeout(comdiag, sc, 60 * hz);
1151 1.57 mycroft }
1152 1.57 mycroft /* This is ugly, but fast. */
1153 1.57 mycroft c |= lsrmap[(*ibufp++ & (LSR_BI|LSR_FE|LSR_PE)) >> 2];
1154 1.57 mycroft (*linesw[tp->t_line].l_rint)(c, tp);
1155 1.57 mycroft }
1156 1.57 mycroft }
1157 1.57 mycroft
1158 1.57 mycroft out:
1159 1.57 mycroft timeout(compoll, NULL, 1);
1160 1.21 mycroft }
1161 1.1 cgd
1162 1.21 mycroft int
1163 1.49 cgd comintr(arg)
1164 1.49 cgd void *arg;
1165 1.21 mycroft {
1166 1.49 cgd struct com_softc *sc = arg;
1167 1.75 cgd bus_chipset_tag_t bc = sc->sc_bc;
1168 1.75 cgd bus_io_handle_t ioh = sc->sc_ioh;
1169 1.21 mycroft struct tty *tp;
1170 1.55 mycroft u_char lsr, data, msr, delta;
1171 1.69 mycroft #ifdef COM_DEBUG
1172 1.72 mycroft int n;
1173 1.69 mycroft struct {
1174 1.72 mycroft u_char iir, lsr, msr;
1175 1.69 mycroft } iter[32];
1176 1.69 mycroft #endif
1177 1.55 mycroft
1178 1.72 mycroft #ifdef COM_DEBUG
1179 1.72 mycroft n = 0;
1180 1.75 cgd if (ISSET(iter[n].iir = bus_io_read_1(bc, ioh, com_iir), IIR_NOPEND))
1181 1.72 mycroft return (0);
1182 1.72 mycroft #else
1183 1.75 cgd if (ISSET(bus_io_read_1(bc, ioh, com_iir), IIR_NOPEND))
1184 1.55 mycroft return (0);
1185 1.72 mycroft #endif
1186 1.21 mycroft
1187 1.55 mycroft tp = sc->sc_tty;
1188 1.21 mycroft
1189 1.21 mycroft for (;;) {
1190 1.69 mycroft #ifdef COM_DEBUG
1191 1.69 mycroft iter[n].lsr =
1192 1.69 mycroft #endif
1193 1.75 cgd lsr = bus_io_read_1(bc, ioh, com_lsr);
1194 1.55 mycroft
1195 1.69 mycroft if (ISSET(lsr, LSR_RXRDY)) {
1196 1.57 mycroft register u_char *p = sc->sc_ibufp;
1197 1.57 mycroft
1198 1.57 mycroft comevents = 1;
1199 1.55 mycroft do {
1200 1.75 cgd data = bus_io_read_1(bc, ioh, com_data);
1201 1.62 mycroft if (ISSET(lsr, LSR_BI)) {
1202 1.72 mycroft #ifdef notdef
1203 1.69 mycroft printf("break %02x %02x %02x %02x\n",
1204 1.69 mycroft sc->sc_msr, sc->sc_mcr, sc->sc_lcr,
1205 1.69 mycroft sc->sc_dtr);
1206 1.69 mycroft #endif
1207 1.57 mycroft #ifdef DDB
1208 1.75 cgd if (ISSET(sc->sc_hwflags,
1209 1.75 cgd COM_HW_CONSOLE)) {
1210 1.58 mycroft Debugger();
1211 1.58 mycroft goto next;
1212 1.59 mycroft }
1213 1.21 mycroft #endif
1214 1.62 mycroft }
1215 1.57 mycroft if (p >= sc->sc_ibufend) {
1216 1.57 mycroft sc->sc_floods++;
1217 1.57 mycroft if (sc->sc_errors++ == 0)
1218 1.57 mycroft timeout(comdiag, sc, 60 * hz);
1219 1.57 mycroft } else {
1220 1.57 mycroft *p++ = data;
1221 1.57 mycroft *p++ = lsr;
1222 1.57 mycroft if (p == sc->sc_ibufhigh &&
1223 1.62 mycroft ISSET(tp->t_cflag, CRTSCTS)) {
1224 1.62 mycroft /* XXX */
1225 1.62 mycroft CLR(sc->sc_mcr, MCR_RTS);
1226 1.75 cgd bus_io_write_1(bc, ioh, com_mcr,
1227 1.75 cgd sc->sc_mcr);
1228 1.62 mycroft }
1229 1.55 mycroft }
1230 1.57 mycroft next:
1231 1.69 mycroft #ifdef COM_DEBUG
1232 1.69 mycroft if (++n >= 32)
1233 1.69 mycroft goto ohfudge;
1234 1.69 mycroft iter[n].lsr =
1235 1.69 mycroft #endif
1236 1.75 cgd lsr = bus_io_read_1(bc, ioh, com_lsr);
1237 1.69 mycroft } while (ISSET(lsr, LSR_RXRDY));
1238 1.57 mycroft
1239 1.57 mycroft sc->sc_ibufp = p;
1240 1.55 mycroft }
1241 1.69 mycroft #ifdef COM_DEBUG
1242 1.62 mycroft else if (ISSET(lsr, LSR_BI|LSR_FE|LSR_PE|LSR_OE))
1243 1.62 mycroft printf("weird lsr %02x\n", lsr);
1244 1.62 mycroft #endif
1245 1.55 mycroft
1246 1.69 mycroft #ifdef COM_DEBUG
1247 1.69 mycroft iter[n].msr =
1248 1.69 mycroft #endif
1249 1.75 cgd msr = bus_io_read_1(bc, ioh, com_msr);
1250 1.55 mycroft
1251 1.55 mycroft if (msr != sc->sc_msr) {
1252 1.55 mycroft delta = msr ^ sc->sc_msr;
1253 1.55 mycroft sc->sc_msr = msr;
1254 1.62 mycroft if (ISSET(delta, MSR_DCD) &&
1255 1.62 mycroft !ISSET(sc->sc_swflags, COM_SW_SOFTCAR) &&
1256 1.62 mycroft (*linesw[tp->t_line].l_modem)(tp, ISSET(msr, MSR_DCD)) == 0) {
1257 1.62 mycroft CLR(sc->sc_mcr, sc->sc_dtr);
1258 1.75 cgd bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr);
1259 1.55 mycroft }
1260 1.62 mycroft if (ISSET(delta & msr, MSR_CTS) &&
1261 1.62 mycroft ISSET(tp->t_cflag, CRTSCTS)) {
1262 1.55 mycroft /* the line is up and we want to do rts/cts flow control */
1263 1.57 mycroft (*linesw[tp->t_line].l_start)(tp);
1264 1.55 mycroft }
1265 1.55 mycroft }
1266 1.55 mycroft
1267 1.62 mycroft if (ISSET(lsr, LSR_TXRDY) && ISSET(tp->t_state, TS_BUSY)) {
1268 1.68 mycroft CLR(tp->t_state, TS_BUSY | TS_FLUSH);
1269 1.66 mycroft if (sc->sc_halt > 0)
1270 1.66 mycroft wakeup(&tp->t_outq);
1271 1.69 mycroft (*linesw[tp->t_line].l_start)(tp);
1272 1.62 mycroft }
1273 1.62 mycroft
1274 1.69 mycroft #ifdef COM_DEBUG
1275 1.69 mycroft if (++n >= 32)
1276 1.69 mycroft goto ohfudge;
1277 1.75 cgd if (ISSET(iter[n].iir = bus_io_read_1(bc, ioh, com_iir), IIR_NOPEND))
1278 1.72 mycroft return (1);
1279 1.72 mycroft #else
1280 1.75 cgd if (ISSET(bus_io_read_1(bc, ioh, com_iir), IIR_NOPEND))
1281 1.72 mycroft return (1);
1282 1.69 mycroft #endif
1283 1.1 cgd }
1284 1.69 mycroft #ifdef COM_DEBUG
1285 1.69 mycroft ohfudge:
1286 1.69 mycroft printf("comintr: too many iterations");
1287 1.69 mycroft for (n = 0; n < 32; n++) {
1288 1.69 mycroft if ((n % 4) == 0)
1289 1.72 mycroft printf("\ncomintr: iter[%02d]", n);
1290 1.72 mycroft printf(" %02x %02x %02x", iter[n].iir, iter[n].lsr, iter[n].msr);
1291 1.69 mycroft }
1292 1.69 mycroft printf("\n");
1293 1.72 mycroft printf("comintr: msr %02x mcr %02x lcr %02x ier %02x\n",
1294 1.72 mycroft sc->sc_msr, sc->sc_mcr, sc->sc_lcr, sc->sc_ier);
1295 1.72 mycroft printf("comintr: state %08x cc %d\n", sc->sc_tty->t_state,
1296 1.72 mycroft sc->sc_tty->t_outq.c_cc);
1297 1.69 mycroft #endif
1298 1.1 cgd }
1299 1.1 cgd
1300 1.1 cgd /*
1301 1.1 cgd * Following are all routines needed for COM to act as console
1302 1.1 cgd */
1303 1.17 cgd #include <dev/cons.h>
1304 1.1 cgd
1305 1.48 mycroft void
1306 1.1 cgd comcnprobe(cp)
1307 1.1 cgd struct consdev *cp;
1308 1.1 cgd {
1309 1.75 cgd bus_chipset_tag_t bc;
1310 1.75 cgd bus_io_handle_t ioh;
1311 1.75 cgd int found;
1312 1.75 cgd
1313 1.75 cgd #if 0
1314 1.75 cgd XXX NEEDS TO BE FIXED XXX
1315 1.75 cgd bc = ???;
1316 1.75 cgd #endif
1317 1.75 cgd if (bus_io_map(bc, CONADDR, COM_NPORTS, &ioh)) {
1318 1.75 cgd cp->cn_pri = CN_DEAD;
1319 1.75 cgd return;
1320 1.75 cgd }
1321 1.75 cgd found = comprobe1(bc, ioh, CONADDR);
1322 1.75 cgd bus_io_unmap(bc, ioh, COM_NPORTS);
1323 1.75 cgd if (!found) {
1324 1.21 mycroft cp->cn_pri = CN_DEAD;
1325 1.21 mycroft return;
1326 1.21 mycroft }
1327 1.1 cgd
1328 1.1 cgd /* locate the major number */
1329 1.1 cgd for (commajor = 0; commajor < nchrdev; commajor++)
1330 1.1 cgd if (cdevsw[commajor].d_open == comopen)
1331 1.1 cgd break;
1332 1.1 cgd
1333 1.1 cgd /* initialize required fields */
1334 1.29 mycroft cp->cn_dev = makedev(commajor, CONUNIT);
1335 1.1 cgd #ifdef COMCONSOLE
1336 1.1 cgd cp->cn_pri = CN_REMOTE; /* Force a serial port console */
1337 1.1 cgd #else
1338 1.1 cgd cp->cn_pri = CN_NORMAL;
1339 1.1 cgd #endif
1340 1.1 cgd }
1341 1.1 cgd
1342 1.48 mycroft void
1343 1.1 cgd comcninit(cp)
1344 1.1 cgd struct consdev *cp;
1345 1.1 cgd {
1346 1.1 cgd
1347 1.75 cgd #if 0
1348 1.75 cgd XXX NEEDS TO BE FIXED XXX
1349 1.75 cgd comconsbc = ???;
1350 1.75 cgd #endif
1351 1.75 cgd if (bus_io_map(comconsbc, CONADDR, COM_NPORTS, &comconsioh))
1352 1.75 cgd panic("comcninit: mapping failed");
1353 1.75 cgd
1354 1.75 cgd cominit(comconsbc, comconsioh, comdefaultrate);
1355 1.75 cgd comconsaddr = CONADDR;
1356 1.21 mycroft comconsinit = 0;
1357 1.1 cgd }
1358 1.1 cgd
1359 1.75 cgd cominit(bc, ioh, rate)
1360 1.75 cgd bus_chipset_tag_t bc;
1361 1.75 cgd bus_io_handle_t ioh;
1362 1.75 cgd int rate;
1363 1.1 cgd {
1364 1.21 mycroft int s = splhigh();
1365 1.21 mycroft u_char stat;
1366 1.1 cgd
1367 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, LCR_DLAB);
1368 1.21 mycroft rate = comspeed(comdefaultrate);
1369 1.75 cgd bus_io_write_1(bc, ioh, com_dlbl, rate);
1370 1.75 cgd bus_io_write_1(bc, ioh, com_dlbh, rate >> 8);
1371 1.75 cgd bus_io_write_1(bc, ioh, com_lcr, LCR_8BITS);
1372 1.75 cgd bus_io_write_1(bc, ioh, com_ier, IER_ERXRDY | IER_ETXRDY);
1373 1.75 cgd bus_io_write_1(bc, ioh, com_fifo, FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_4);
1374 1.75 cgd stat = bus_io_read_1(bc, ioh, com_iir);
1375 1.1 cgd splx(s);
1376 1.1 cgd }
1377 1.1 cgd
1378 1.1 cgd comcngetc(dev)
1379 1.21 mycroft dev_t dev;
1380 1.1 cgd {
1381 1.21 mycroft int s = splhigh();
1382 1.75 cgd bus_chipset_tag_t bc = comconsbc;
1383 1.75 cgd bus_io_handle_t ioh = comconsioh;
1384 1.21 mycroft u_char stat, c;
1385 1.1 cgd
1386 1.75 cgd while (!ISSET(stat = bus_io_read_1(bc, ioh, com_lsr), LSR_RXRDY))
1387 1.1 cgd ;
1388 1.75 cgd c = bus_io_read_1(bc, ioh, com_data);
1389 1.75 cgd stat = bus_io_read_1(bc, ioh, com_iir);
1390 1.1 cgd splx(s);
1391 1.21 mycroft return c;
1392 1.1 cgd }
1393 1.1 cgd
1394 1.1 cgd /*
1395 1.1 cgd * Console kernel output character routine.
1396 1.1 cgd */
1397 1.48 mycroft void
1398 1.1 cgd comcnputc(dev, c)
1399 1.1 cgd dev_t dev;
1400 1.21 mycroft int c;
1401 1.1 cgd {
1402 1.21 mycroft int s = splhigh();
1403 1.75 cgd bus_chipset_tag_t bc = comconsbc;
1404 1.75 cgd bus_io_handle_t ioh = comconsioh;
1405 1.21 mycroft u_char stat;
1406 1.1 cgd register int timo;
1407 1.1 cgd
1408 1.1 cgd #ifdef KGDB
1409 1.1 cgd if (dev != kgdb_dev)
1410 1.1 cgd #endif
1411 1.1 cgd if (comconsinit == 0) {
1412 1.75 cgd (void) cominit(bc, ioh, comdefaultrate);
1413 1.1 cgd comconsinit = 1;
1414 1.1 cgd }
1415 1.1 cgd /* wait for any pending transmission to finish */
1416 1.1 cgd timo = 50000;
1417 1.75 cgd while (!ISSET(stat = bus_io_read_1(bc, ioh, com_lsr), LSR_TXRDY) && --timo)
1418 1.1 cgd ;
1419 1.75 cgd bus_io_write_1(bc, ioh, com_data, c);
1420 1.1 cgd /* wait for this transmission to complete */
1421 1.1 cgd timo = 1500000;
1422 1.75 cgd while (!ISSET(stat = bus_io_read_1(bc, ioh, com_lsr), LSR_TXRDY) && --timo)
1423 1.1 cgd ;
1424 1.1 cgd /* clear any interrupts generated by this transmission */
1425 1.75 cgd stat = bus_io_read_1(bc, ioh, com_iir);
1426 1.1 cgd splx(s);
1427 1.37 mycroft }
1428 1.37 mycroft
1429 1.37 mycroft void
1430 1.37 mycroft comcnpollc(dev, on)
1431 1.37 mycroft dev_t dev;
1432 1.37 mycroft int on;
1433 1.37 mycroft {
1434 1.37 mycroft
1435 1.2 cgd }
1436