2 * Copyright (c) 1991 The Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * $FreeBSD: src/sys/isa/sio.c,v 1.291.2.35 2003/05/18 08:51:15 murray Exp $
34 * $DragonFly: src/sys/dev/serial/sio/sio.c,v 1.3 2003/06/23 17:55:40 dillon Exp $
35 * from: @(#)com.c 7.5 (Berkeley) 5/16/91
36 * from: i386/isa sio.c,v 1.234
39 #include "opt_comconsole.h"
40 #include "opt_compat.h"
51 * Serial driver, based on 386BSD-0.1 com driver.
52 * Mostly rewritten to use pseudo-DMA.
53 * Works for National Semiconductor NS8250-NS16550AF UARTs.
54 * COM driver, based on HP dca driver.
56 * Changes for PC-Card integration:
57 * - Added PC-Card driver table and handlers
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/reboot.h>
62 #include <sys/malloc.h>
65 #include <sys/module.h>
67 #include <sys/dkstat.h>
68 #include <sys/fcntl.h>
69 #include <sys/interrupt.h>
70 #include <sys/kernel.h>
71 #include <sys/syslog.h>
72 #include <sys/sysctl.h>
74 #include <machine/bus_pio.h>
75 #include <machine/bus.h>
77 #include <sys/timepps.h>
79 #include <machine/limits.h>
81 #include <isa/isareg.h>
82 #include <isa/isavar.h>
84 #include <pci/pcireg.h>
85 #include <pci/pcivar.h>
88 #include <dev/puc/pucvar.h>
90 #include <machine/lock.h>
92 #include <machine/clock.h>
93 #include <machine/ipl.h>
95 #include <machine/lock.h>
97 #include <machine/resource.h>
99 #include <isa/sioreg.h>
102 #include <dev/ic/esp.h>
104 #include <dev/ic/ns16550.h>
107 #define disable_intr()
108 #define enable_intr()
112 #define disable_intr() COM_DISABLE_INTR()
113 #define enable_intr() COM_ENABLE_INTR()
116 #define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
118 #define CALLOUT_MASK 0x80
119 #define CONTROL_MASK 0x60
120 #define CONTROL_INIT_STATE 0x20
121 #define CONTROL_LOCK_STATE 0x40
122 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
123 #define MINOR_TO_UNIT(mynor) ((((mynor) & ~0xffffU) >> (8 + 3)) \
125 #define UNIT_TO_MINOR(unit) ((((unit) & ~0x1fU) << (8 + 3)) \
129 /* checks in flags for multiport and which is multiport "master chip"
132 #define COM_ISMULTIPORT(flags) ((flags) & 0x01)
133 #define COM_MPMASTER(flags) (((flags) >> 8) & 0x0ff)
134 #define COM_NOTAST4(flags) ((flags) & 0x04)
135 #endif /* COM_MULTIPORT */
137 #define COM_CONSOLE(flags) ((flags) & 0x10)
138 #define COM_FORCECONSOLE(flags) ((flags) & 0x20)
139 #define COM_LLCONSOLE(flags) ((flags) & 0x40)
140 #define COM_DEBUGGER(flags) ((flags) & 0x80)
141 #define COM_LOSESOUTINTS(flags) ((flags) & 0x08)
142 #define COM_NOFIFO(flags) ((flags) & 0x02)
143 #define COM_ST16650A(flags) ((flags) & 0x20000)
144 #define COM_C_NOPROBE (0x40000)
145 #define COM_NOPROBE(flags) ((flags) & COM_C_NOPROBE)
146 #define COM_C_IIR_TXRDYBUG (0x80000)
147 #define COM_IIR_TXRDYBUG(flags) ((flags) & COM_C_IIR_TXRDYBUG)
148 #define COM_TI16754(flags) ((flags) & 0x200000)
149 #define COM_FIFOSIZE(flags) (((flags) & 0xff000000) >> 24)
151 #define com_scr 7 /* scratch register for 16450-16550 (R/W) */
153 #define sio_getreg(com, off) \
154 (bus_space_read_1((com)->bst, (com)->bsh, (off)))
155 #define sio_setreg(com, off, value) \
156 (bus_space_write_1((com)->bst, (com)->bsh, (off), (value)))
160 * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher
161 * than the other bits so that they can be tested as a group without masking
164 * The following com and tty flags correspond closely:
165 * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and
167 * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart())
168 * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam())
169 * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam())
170 * TS_FLUSH is not used.
171 * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON.
172 * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state).
174 #define CS_BUSY 0x80 /* output in progress */
175 #define CS_TTGO 0x40 /* output not stopped by XOFF */
176 #define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */
177 #define CS_CHECKMSR 1 /* check of MSR scheduled */
178 #define CS_CTS_OFLOW 2 /* use CTS output flow control */
179 #define CS_DTR_OFF 0x10 /* DTR held off */
180 #define CS_ODONE 4 /* output completed */
181 #define CS_RTS_IFLOW 8 /* use RTS input flow control */
182 #define CSE_BUSYCHECK 1 /* siobusycheck() scheduled */
184 static char const * const error_desc[] = {
187 #define CE_INTERRUPT_BUF_OVERFLOW 1
188 "interrupt-level buffer overflow",
189 #define CE_TTY_BUF_OVERFLOW 2
190 "tty-level buffer overflow",
194 #define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum])
196 /* types. XXX - should be elsewhere */
197 typedef u_int Port_t; /* hardware port */
198 typedef u_char bool_t; /* boolean */
200 /* queue of linear buffers */
202 u_char *l_head; /* next char to process */
203 u_char *l_tail; /* one past the last char to process */
204 struct lbq *l_next; /* next in queue */
205 bool_t l_queued; /* nonzero if queued */
208 /* com device structure */
210 u_int flags; /* Copy isa device flags */
211 u_char state; /* miscellaneous flag bits */
212 bool_t active_out; /* nonzero if the callout device is open */
213 u_char cfcr_image; /* copy of value written to CFCR */
215 bool_t esp; /* is this unit a hayes esp board? */
217 u_char extra_state; /* more flag bits, separate for order trick */
218 u_char fifo_image; /* copy of value written to FIFO */
219 bool_t hasfifo; /* nonzero for 16550 UARTs */
220 bool_t st16650a; /* Is a Startech 16650A or RTS/CTS compat */
221 bool_t loses_outints; /* nonzero if device loses output interrupts */
222 u_char mcr_image; /* copy of value written to MCR */
224 bool_t multiport; /* is this unit part of a multiport device? */
225 #endif /* COM_MULTIPORT */
226 bool_t no_irq; /* nonzero if irq is not attached */
227 bool_t gone; /* hardware disappeared */
228 bool_t poll; /* nonzero if polling is required */
229 bool_t poll_output; /* nonzero if polling for output is required */
230 int unit; /* unit number */
231 int dtr_wait; /* time to hold DTR down on close (* 1/hz) */
233 u_int wopeners; /* # processes waiting for DCD in open() */
236 * The high level of the driver never reads status registers directly
237 * because there would be too many side effects to handle conveniently.
238 * Instead, it reads copies of the registers stored here by the
241 u_char last_modem_status; /* last MSR read by intr handler */
242 u_char prev_modem_status; /* last MSR handled by high level */
244 u_char hotchar; /* ldisc-specific char to be handled ASAP */
245 u_char *ibuf; /* start of input buffer */
246 u_char *ibufend; /* end of input buffer */
247 u_char *ibufold; /* old input buffer, to be freed */
248 u_char *ihighwater; /* threshold in input buffer */
249 u_char *iptr; /* next free spot in input buffer */
250 int ibufsize; /* size of ibuf (not include error bytes) */
251 int ierroff; /* offset of error bytes in ibuf */
253 struct lbq obufq; /* head of queue of output buffers */
254 struct lbq obufs[2]; /* output buffers */
257 bus_space_handle_t bsh;
259 Port_t data_port; /* i/o ports */
264 Port_t modem_ctl_port;
265 Port_t line_status_port;
266 Port_t modem_status_port;
267 Port_t intr_ctl_port; /* Ports of IIR register */
269 struct tty *tp; /* cross reference */
272 struct termios it_in; /* should be in struct tty */
273 struct termios it_out;
276 struct termios lt_in; /* should be in struct tty */
277 struct termios lt_out;
280 bool_t do_dcd_timestamp;
281 struct timeval timestamp;
282 struct timeval dcd_timestamp;
283 struct pps_state pps;
285 u_long bytes_in; /* statistics */
287 u_int delta_error_counts[CE_NTYPES];
288 u_long error_counts[CE_NTYPES];
292 struct resource *irqres;
293 struct resource *ioportres;
297 * Data area for output buffers. Someday we should build the output
298 * buffer queue without copying data.
305 static int espattach __P((struct com_s *com, Port_t esp_port));
307 static int sioattach __P((device_t dev, int rid, u_long rclk));
308 static int sio_isa_attach __P((device_t dev));
310 static timeout_t siobusycheck;
311 static u_int siodivisor __P((u_long rclk, speed_t speed));
312 static timeout_t siodtrwakeup;
313 static void comhardclose __P((struct com_s *com));
314 static void sioinput __P((struct com_s *com));
315 static void siointr1 __P((struct com_s *com));
316 static void siointr __P((void *arg));
317 static int commctl __P((struct com_s *com, int bits, int how));
318 static int comparam __P((struct tty *tp, struct termios *t));
319 static swihand_t siopoll;
320 static int sioprobe __P((device_t dev, int xrid, u_long rclk));
321 static int sio_isa_probe __P((device_t dev));
322 static void siosettimeout __P((void));
323 static int siosetwater __P((struct com_s *com, speed_t speed));
324 static void comstart __P((struct tty *tp));
325 static void comstop __P((struct tty *tp, int rw));
326 static timeout_t comwakeup;
327 static void disc_optim __P((struct tty *tp, struct termios *t,
331 static int sio_pccard_attach __P((device_t dev));
332 static int sio_pccard_detach __P((device_t dev));
333 static int sio_pccard_probe __P((device_t dev));
334 #endif /* NCARD > 0 */
337 static int sio_pci_attach __P((device_t dev));
338 static void sio_pci_kludge_unit __P((device_t dev));
339 static int sio_pci_probe __P((device_t dev));
340 #endif /* NPCI > 0 */
343 static int sio_puc_attach __P((device_t dev));
344 static int sio_puc_probe __P((device_t dev));
345 #endif /* NPUC > 0 */
347 static char driver_name[] = "sio";
349 /* table and macro for fast conversion from a unit number to its com struct */
350 static devclass_t sio_devclass;
351 #define com_addr(unit) ((struct com_s *) \
352 devclass_get_softc(sio_devclass, unit))
354 static device_method_t sio_isa_methods[] = {
355 /* Device interface */
356 DEVMETHOD(device_probe, sio_isa_probe),
357 DEVMETHOD(device_attach, sio_isa_attach),
362 static driver_t sio_isa_driver = {
365 sizeof(struct com_s),
369 static device_method_t sio_pccard_methods[] = {
370 /* Device interface */
371 DEVMETHOD(device_probe, sio_pccard_probe),
372 DEVMETHOD(device_attach, sio_pccard_attach),
373 DEVMETHOD(device_detach, sio_pccard_detach),
378 static driver_t sio_pccard_driver = {
381 sizeof(struct com_s),
383 #endif /* NCARD > 0 */
386 static device_method_t sio_pci_methods[] = {
387 /* Device interface */
388 DEVMETHOD(device_probe, sio_pci_probe),
389 DEVMETHOD(device_attach, sio_pci_attach),
394 static driver_t sio_pci_driver = {
397 sizeof(struct com_s),
399 #endif /* NPCI > 0 */
402 static device_method_t sio_puc_methods[] = {
403 /* Device interface */
404 DEVMETHOD(device_probe, sio_puc_probe),
405 DEVMETHOD(device_attach, sio_puc_attach),
410 static driver_t sio_puc_driver = {
413 sizeof(struct com_s),
415 #endif /* NPUC > 0 */
417 static d_open_t sioopen;
418 static d_close_t sioclose;
419 static d_read_t sioread;
420 static d_write_t siowrite;
421 static d_ioctl_t sioioctl;
423 #define CDEV_MAJOR 28
424 static struct cdevsw sio_cdevsw = {
426 /* close */ sioclose,
428 /* write */ siowrite,
429 /* ioctl */ sioioctl,
432 /* strategy */ nostrategy,
433 /* name */ driver_name,
434 /* maj */ CDEV_MAJOR,
437 /* flags */ D_TTY | D_KQFILTER,
439 /* kqfilter */ ttykqfilter,
443 static volatile speed_t comdefaultrate = CONSPEED;
444 static u_long comdefaultrclk = DEFAULT_RCLK;
445 SYSCTL_ULONG(_machdep, OID_AUTO, conrclk, CTLFLAG_RW, &comdefaultrclk, 0, "");
447 static volatile speed_t gdbdefaultrate = CONSPEED;
449 static u_int com_events; /* input chars + weighted output completions */
450 static Port_t siocniobase;
451 static int siocnunit;
452 static Port_t siogdbiobase;
453 static int siogdbunit = -1;
454 static bool_t sio_registered;
455 static int sio_timeout;
456 static int sio_timeouts_until_log;
457 static struct callout_handle sio_timeout_handle
458 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
459 static int sio_numunits;
462 /* XXX configure this properly. */
463 static Port_t likely_com_ports[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, };
464 static Port_t likely_esp_ports[] = { 0x140, 0x180, 0x280, 0 };
468 * handle sysctl read/write requests for console speed
470 * In addition to setting comdefaultrate for I/O through /dev/console,
471 * also set the initial and lock values for the /dev/ttyXX device
472 * if there is one associated with the console. Finally, if the /dev/tty
473 * device has already been open, change the speed on the open running port
478 sysctl_machdep_comdefaultrate(SYSCTL_HANDLER_ARGS)
485 newspeed = comdefaultrate;
487 error = sysctl_handle_opaque(oidp, &newspeed, sizeof newspeed, req);
488 if (error || !req->newptr)
491 comdefaultrate = newspeed;
493 if (comconsole < 0) /* serial console not selected? */
496 com = com_addr(comconsole);
501 * set the initial and lock rates for /dev/ttydXX and /dev/cuaXX
502 * (note, the lock rates really are boolean -- if non-zero, disallow
505 com->it_in.c_ispeed = com->it_in.c_ospeed =
506 com->lt_in.c_ispeed = com->lt_in.c_ospeed =
507 com->it_out.c_ispeed = com->it_out.c_ospeed =
508 com->lt_out.c_ispeed = com->lt_out.c_ospeed = comdefaultrate;
511 * if we're open, change the running rate too
514 if (tp && (tp->t_state & TS_ISOPEN)) {
515 tp->t_termios.c_ispeed =
516 tp->t_termios.c_ospeed = comdefaultrate;
518 error = comparam(tp, &tp->t_termios);
524 SYSCTL_PROC(_machdep, OID_AUTO, conspeed, CTLTYPE_INT | CTLFLAG_RW,
525 0, 0, sysctl_machdep_comdefaultrate, "I", "");
527 #define SET_FLAG(dev, bit) device_set_flags(dev, device_get_flags(dev) | (bit))
528 #define CLR_FLAG(dev, bit) device_set_flags(dev, device_get_flags(dev) & ~(bit))
532 sio_pccard_probe(dev)
535 /* Do not probe IRQ - pccard doesn't turn on the interrupt line */
536 /* until bus_setup_intr */
537 SET_FLAG(dev, COM_C_NOPROBE);
539 return (sioprobe(dev, 0, 0UL));
543 sio_pccard_attach(dev)
546 return (sioattach(dev, 0, 0UL));
550 * sio_detach - unload the driver and clear the table.
552 * This is usually called when the card is ejected, but
553 * can be caused by a modunload of a controller driver.
554 * The idea is to reset the driver's view of the device
555 * and ensure that any driver entry points such as
556 * read and write do not hang.
559 sio_pccard_detach(dev)
564 com = (struct com_s *) device_get_softc(dev);
566 device_printf(dev, "NULL com in siounload\n");
571 bus_teardown_intr(dev, com->irqres, com->cookie);
572 bus_release_resource(dev, SYS_RES_IRQ, 0, com->irqres);
575 bus_release_resource(dev, SYS_RES_IOPORT, 0, com->ioportres);
576 if (com->tp && (com->tp->t_state & TS_ISOPEN)) {
577 device_printf(dev, "still open, forcing close\n");
583 if (com->ibuf != NULL)
584 free(com->ibuf, M_DEVBUF);
586 device_printf(dev, "unloaded\n");
589 #endif /* NCARD > 0 */
598 static struct pci_ids pci_ids[] = {
599 { 0x100812b9, "3COM PCI FaxModem", 0x10 },
600 { 0x2000131f, "CyberSerial (1-port) 16550", 0x10 },
601 { 0x01101407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 },
602 { 0x01111407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 },
603 { 0x048011c1, "Lucent kermit based PCI Modem", 0x14 },
604 { 0x95211415, "Oxford Semiconductor PCI Dual Port Serial", 0x10 },
605 { 0x7101135e, "SeaLevel Ultra 530.PCI Single Port Serial", 0x18 },
606 { 0x0000151f, "SmartLink 5634PCV SurfRider", 0x10 },
607 { 0x98459710, "Netmos Nm9845 PCI Bridge with Dual UART", 0x10 },
608 { 0x00000000, NULL, 0 }
618 type = pci_get_devid(dev);
620 while (id->type && id->type != type)
622 if (id->desc == NULL)
624 sio_pci_kludge_unit(dev);
625 return (sioattach(dev, id->rid, 0UL));
629 * Don't cut and paste this to other drivers. It is a horrible kludge
630 * which will fail to work and also be unnecessary in future versions.
633 sio_pci_kludge_unit(dev)
643 while (resource_int_value("sio", unit, "port", &start) == 0 &&
646 if (device_get_unit(dev) < unit) {
647 dc = device_get_devclass(dev);
648 while (devclass_get_device(dc, unit))
650 device_printf(dev, "moving to sio%d\n", unit);
651 err = device_set_unit(dev, unit); /* EVIL DO NOT COPY */
653 device_printf(dev, "error moving device %d\n", err);
664 type = pci_get_devid(dev);
666 while (id->type && id->type != type)
668 if (id->desc == NULL)
670 device_set_desc(dev, id->desc);
671 return (sioprobe(dev, id->rid, 0UL));
673 #endif /* NPCI > 0 */
682 if (BUS_READ_IVAR(device_get_parent(dev), dev, PUC_IVAR_FREQ,
685 return (sioattach(dev, 0, rclk));
694 if (BUS_READ_IVAR(device_get_parent(dev), dev, PUC_IVAR_FREQ,
697 return (sioprobe(dev, 0, rclk));
701 static struct isa_pnp_id sio_ids[] = {
702 {0x0005d041, "Standard PC COM port"}, /* PNP0500 */
703 {0x0105d041, "16550A-compatible COM port"}, /* PNP0501 */
704 {0x0205d041, "Multiport serial device (non-intelligent 16550)"}, /* PNP0502 */
705 {0x1005d041, "Generic IRDA-compatible device"}, /* PNP0510 */
706 {0x1105d041, "Generic IRDA-compatible device"}, /* PNP0511 */
707 /* Devices that do not have a compatid */
708 {0x12206804, NULL}, /* ACH2012 - 5634BTS 56K Video Ready Modem */
709 {0x7602a904, NULL}, /* AEI0276 - 56K v.90 Fax Modem (LKT) */
710 {0x00007905, NULL}, /* AKY0000 - 56K Plug&Play Modem */
711 {0x21107905, NULL}, /* AKY1021 - 56K Plug&Play Modem */
712 {0x01405407, NULL}, /* AZT4001 - AZT3000 PnP SOUND DEVICE, MODEM */
713 {0x56039008, NULL}, /* BDP0356 - Best Data 56x2 */
714 {0x56159008, NULL}, /* BDP1556 - B.D. Smart One 56SPS,Voice Modem*/
715 {0x36339008, NULL}, /* BDP3336 - Best Data Prods. 336F */
716 {0x0014490a, NULL}, /* BRI1400 - Boca 33.6 PnP */
717 {0x0015490a, NULL}, /* BRI1500 - Internal Fax Data */
718 {0x0034490a, NULL}, /* BRI3400 - Internal ACF Modem */
719 {0x0094490a, NULL}, /* BRI9400 - Boca K56Flex PnP */
720 {0x00b4490a, NULL}, /* BRIB400 - Boca 56k PnP */
721 {0x0030320d, NULL}, /* CIR3000 - Cirrus Logic V43 */
722 {0x0100440e, NULL}, /* CRD0001 - Cardinal MVP288IV ? */
723 {0x01308c0e, NULL}, /* CTL3001 - Creative Labs Phoneblaster */
724 {0x36033610, NULL}, /* DAV0336 - DAVICOM 336PNP MODEM */
725 {0x01009416, NULL}, /* ETT0001 - E-Tech Bullet 33k6 PnP */
726 {0x0000aa1a, NULL}, /* FUJ0000 - FUJITSU Modem 33600 PNP/I2 */
727 {0x1200c31e, NULL}, /* GVC0012 - VF1128HV-R9 (win modem?) */
728 {0x0303c31e, NULL}, /* GVC0303 - MaxTech 33.6 PnP D/F/V */
729 {0x0505c31e, NULL}, /* GVC0505 - GVC 56k Faxmodem */
730 {0x0116c31e, NULL}, /* GVC1601 - Rockwell V.34 Plug & Play Modem */
731 {0x0050c31e, NULL}, /* GVC5000 - some GVC modem */
732 {0x3800f91e, NULL}, /* GWY0038 - Telepath with v.90 */
733 {0x9062f91e, NULL}, /* GWY6290 - Telepath with x2 Technology */
734 {0x8100e425, NULL}, /* IOD0081 - I-O DATA DEVICE,INC. IFML-560 */
735 {0x21002534, NULL}, /* MAE0021 - Jetstream Int V.90 56k Voice Series 2*/
736 {0x0000f435, NULL}, /* MOT0000 - Motorola ModemSURFR 33.6 Intern */
737 {0x5015f435, NULL}, /* MOT1550 - Motorola ModemSURFR 56K Modem */
738 {0xf015f435, NULL}, /* MOT15F0 - Motorola VoiceSURFR 56K Modem */
739 {0x6045f435, NULL}, /* MOT4560 - Motorola ? */
740 {0x61e7a338, NULL}, /* NECE761 - 33.6Modem */
741 {0x08804f3f, NULL}, /* OZO8008 - Zoom (33.6k Modem) */
742 {0x0f804f3f, NULL}, /* OZO800f - Zoom 2812 (56k Modem) */
743 {0x39804f3f, NULL}, /* OZO8039 - Zoom 56k flex */
744 {0x00914f3f, NULL}, /* OZO9100 - Zoom 2919 (K56 Faxmodem) */
745 {0x3024a341, NULL}, /* PMC2430 - Pace 56 Voice Internal Modem */
746 {0x1000eb49, NULL}, /* ROK0010 - Rockwell ? */
747 {0x1200b23d, NULL}, /* RSS0012 - OMRON ME5614ISA */
748 {0x5002734a, NULL}, /* RSS0250 - 5614Jx3(G) Internal Modem */
749 {0x6202734a, NULL}, /* RSS0262 - 5614Jx3[G] V90+K56Flex Modem */
750 {0x1010104d, NULL}, /* SHP1010 - Rockwell 33600bps Modem */
751 {0xc100ad4d, NULL}, /* SMM00C1 - Leopard 56k PnP */
752 {0x9012b04e, NULL}, /* SUP1290 - Supra ? */
753 {0x1013b04e, NULL}, /* SUP1310 - SupraExpress 336i PnP */
754 {0x8013b04e, NULL}, /* SUP1380 - SupraExpress 288i PnP Voice */
755 {0x8113b04e, NULL}, /* SUP1381 - SupraExpress 336i PnP Voice */
756 {0x5016b04e, NULL}, /* SUP1650 - Supra 336i Sp Intl */
757 {0x7016b04e, NULL}, /* SUP1670 - Supra 336i V+ Intl */
758 {0x7420b04e, NULL}, /* SUP2070 - Supra ? */
759 {0x8020b04e, NULL}, /* SUP2080 - Supra ? */
760 {0x8420b04e, NULL}, /* SUP2084 - SupraExpress 56i PnP */
761 {0x7121b04e, NULL}, /* SUP2171 - SupraExpress 56i Sp? */
762 {0x8024b04e, NULL}, /* SUP2480 - Supra ? */
763 {0x01007256, NULL}, /* USR0001 - U.S. Robotics Inc., Sportster W */
764 {0x02007256, NULL}, /* USR0002 - U.S. Robotics Inc. Sportster 33. */
765 {0x04007256, NULL}, /* USR0004 - USR Sportster 14.4k */
766 {0x06007256, NULL}, /* USR0006 - USR Sportster 33.6k */
767 {0x11007256, NULL}, /* USR0011 - USR ? */
768 {0x01017256, NULL}, /* USR0101 - USR ? */
769 {0x30207256, NULL}, /* USR2030 - U.S.Robotics Inc. Sportster 560 */
770 {0x50207256, NULL}, /* USR2050 - U.S.Robotics Inc. Sportster 33. */
771 {0x70207256, NULL}, /* USR2070 - U.S.Robotics Inc. Sportster 560 */
772 {0x30307256, NULL}, /* USR3030 - U.S. Robotics 56K FAX INT */
773 {0x31307256, NULL}, /* USR3031 - U.S. Robotics 56K FAX INT */
774 {0x50307256, NULL}, /* USR3050 - U.S. Robotics 56K FAX INT */
775 {0x70307256, NULL}, /* USR3070 - U.S. Robotics 56K Voice INT */
776 {0x90307256, NULL}, /* USR3090 - USR ? */
777 {0x70917256, NULL}, /* USR9170 - U.S. Robotics 56K FAX INT */
778 {0x90917256, NULL}, /* USR9190 - USR 56k Voice INT */
779 {0x0300695c, NULL}, /* WCI0003 - Fax/Voice/Modem/Speakphone/Asvd */
780 {0x01a0896a, NULL}, /* ZTIA001 - Zoom Internal V90 Faxmodem */
781 {0x61f7896a, NULL}, /* ZTIF761 - Zoom ComStar 33.6 */
791 /* Check isapnp ids */
792 if (ISA_PNP_PROBE(device_get_parent(dev), dev, sio_ids) == ENXIO)
794 return (sioprobe(dev, 0, 0UL));
798 sioprobe(dev, xrid, rclk)
804 static bool_t already_init;
813 intrmask_t irqmap[4];
818 u_int flags = device_get_flags(dev);
820 struct resource *port;
823 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
824 0, ~0, IO_COMSIZE, RF_ACTIVE);
828 com = device_get_softc(dev);
829 com->bst = rman_get_bustag(port);
830 com->bsh = rman_get_bushandle(port);
837 * XXX this is broken - when we are first called, there are no
838 * previously configured IO ports. We could hard code
839 * 0x3f8, 0x2f8, 0x3e8, 0x2e8 etc but that's probably worse.
840 * This code has been doing nothing since the conversion since
841 * "count" is zero the first time around.
845 * Turn off MCR_IENABLE for all likely serial ports. An unused
846 * port with its MCR_IENABLE gate open will inhibit interrupts
847 * from any used port that shares the interrupt vector.
848 * XXX the gate enable is elsewhere for some multiports.
851 int count, i, xioport;
853 devclass_get_devices(sio_devclass, &devs, &count);
854 for (i = 0; i < count; i++) {
856 if (device_is_enabled(xdev) &&
857 bus_get_resource(xdev, SYS_RES_IOPORT, 0, &xioport,
859 outb(xioport + com_mcr, 0);
866 if (COM_LLCONSOLE(flags)) {
867 printf("sio%d: reserved for low-level i/o\n",
868 device_get_unit(dev));
869 bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
874 * If the device is on a multiport card and has an AST/4
875 * compatible interrupt control register, initialize this
876 * register and prepare to leave MCR_IENABLE clear in the mcr.
877 * Otherwise, prepare to set MCR_IENABLE in the mcr.
878 * Point idev to the device struct giving the correct id_irq.
879 * This is the struct for the master device if there is one.
882 mcr_image = MCR_IENABLE;
884 if (COM_ISMULTIPORT(flags)) {
888 idev = devclass_get_device(sio_devclass, COM_MPMASTER(flags));
890 printf("sio%d: master device %d not configured\n",
891 device_get_unit(dev), COM_MPMASTER(flags));
894 if (!COM_NOTAST4(flags)) {
895 if (bus_get_resource(idev, SYS_RES_IOPORT, 0, &io,
898 if (bus_get_resource(idev, SYS_RES_IRQ, 0,
900 outb(xiobase + com_scr, 0x80);
902 outb(xiobase + com_scr, 0);
907 #endif /* COM_MULTIPORT */
908 if (bus_get_resource(idev, SYS_RES_IRQ, 0, NULL, NULL) != 0)
911 bzero(failures, sizeof failures);
912 iobase = rman_get_start(port);
915 * We don't want to get actual interrupts, just masked ones.
916 * Interrupts from this line should already be masked in the ICU,
917 * but mask them in the processor as well in case there are some
918 * (misconfigured) shared interrupts.
924 * For the TI16754 chips, set prescaler to 1 (4 is often the
925 * default after-reset value) as otherwise it's impossible to
926 * get highest baudrates.
928 if (COM_TI16754(flags)) {
931 cfcr = sio_getreg(com, com_cfcr);
932 sio_setreg(com, com_cfcr, CFCR_EFR_ENABLE);
933 efr = sio_getreg(com, com_efr);
934 /* Unlock extended features to turn off prescaler. */
935 sio_setreg(com, com_efr, efr | EFR_EFE);
937 sio_setreg(com, com_cfcr, (cfcr != CFCR_EFR_ENABLE) ? cfcr : 0);
938 /* Turn off prescaler. */
939 sio_setreg(com, com_mcr,
940 sio_getreg(com, com_mcr) & ~MCR_PRESCALE);
941 sio_setreg(com, com_cfcr, CFCR_EFR_ENABLE);
942 sio_setreg(com, com_efr, efr);
943 sio_setreg(com, com_cfcr, cfcr);
947 * Initialize the speed and the word size and wait long enough to
948 * drain the maximum of 16 bytes of junk in device output queues.
949 * The speed is undefined after a master reset and must be set
950 * before relying on anything related to output. There may be
951 * junk after a (very fast) soft reboot and (apparently) after
953 * XXX what about the UART bug avoided by waiting in comparam()?
954 * We don't want to to wait long enough to drain at 2 bps.
956 if (iobase == siocniobase)
957 DELAY((16 + 1) * 1000000 / (comdefaultrate / 10));
959 sio_setreg(com, com_cfcr, CFCR_DLAB | CFCR_8BITS);
960 divisor = siodivisor(rclk, SIO_TEST_SPEED);
961 sio_setreg(com, com_dlbl, divisor & 0xff);
962 sio_setreg(com, com_dlbh, divisor >> 8);
963 sio_setreg(com, com_cfcr, CFCR_8BITS);
964 DELAY((16 + 1) * 1000000 / (SIO_TEST_SPEED / 10));
968 * Enable the interrupt gate and disable device interupts. This
969 * should leave the device driving the interrupt line low and
970 * guarantee an edge trigger if an interrupt can be generated.
973 sio_setreg(com, com_mcr, mcr_image);
974 sio_setreg(com, com_ier, 0);
975 DELAY(1000); /* XXX */
976 irqmap[0] = isa_irq_pending();
979 * Attempt to set loopback mode so that we can send a null byte
980 * without annoying any external device.
983 sio_setreg(com, com_mcr, mcr_image | MCR_LOOPBACK);
986 * Attempt to generate an output interrupt. On 8250's, setting
987 * IER_ETXRDY generates an interrupt independent of the current
988 * setting and independent of whether the THR is empty. On 16450's,
989 * setting IER_ETXRDY generates an interrupt independent of the
990 * current setting. On 16550A's, setting IER_ETXRDY only
991 * generates an interrupt when IER_ETXRDY is not already set.
993 sio_setreg(com, com_ier, IER_ETXRDY);
996 * On some 16x50 incompatibles, setting IER_ETXRDY doesn't generate
997 * an interrupt. They'd better generate one for actually doing
998 * output. Loopback may be broken on the same incompatibles but
999 * it's unlikely to do more than allow the null byte out.
1001 sio_setreg(com, com_data, 0);
1002 DELAY((1 + 2) * 1000000 / (SIO_TEST_SPEED / 10));
1005 * Turn off loopback mode so that the interrupt gate works again
1006 * (MCR_IENABLE was hidden). This should leave the device driving
1007 * an interrupt line high. It doesn't matter if the interrupt
1008 * line oscillates while we are not looking at it, since interrupts
1012 sio_setreg(com, com_mcr, mcr_image);
1015 * Some pcmcia cards have the "TXRDY bug", so we check everyone
1016 * for IIR_TXRDY implementation ( Palido 321s, DC-1S... )
1018 if (COM_NOPROBE(flags)) {
1019 /* Reading IIR register twice */
1020 for (fn = 0; fn < 2; fn ++) {
1022 failures[6] = sio_getreg(com, com_iir);
1024 /* Check IIR_TXRDY clear ? */
1026 if (failures[6] & IIR_TXRDY) {
1027 /* Nop, Double check with clearing IER */
1028 sio_setreg(com, com_ier, 0);
1029 if (sio_getreg(com, com_iir) & IIR_NOPEND) {
1030 /* Ok. we're familia this gang */
1031 SET_FLAG(dev, COM_C_IIR_TXRDYBUG);
1033 /* Unknown, Just omit this chip.. XXX */
1035 sio_setreg(com, com_mcr, 0);
1038 /* OK. this is well-known guys */
1039 CLR_FLAG(dev, COM_C_IIR_TXRDYBUG);
1041 sio_setreg(com, com_ier, 0);
1042 sio_setreg(com, com_cfcr, CFCR_8BITS);
1044 bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
1045 return (iobase == siocniobase ? 0 : result);
1050 * o the CFCR, IER and MCR in UART hold the values written to them
1051 * (the values happen to be all distinct - this is good for
1052 * avoiding false positive tests from bus echoes).
1053 * o an output interrupt is generated and its vector is correct.
1054 * o the interrupt goes away when the IIR in the UART is read.
1057 failures[0] = sio_getreg(com, com_cfcr) - CFCR_8BITS;
1058 failures[1] = sio_getreg(com, com_ier) - IER_ETXRDY;
1059 failures[2] = sio_getreg(com, com_mcr) - mcr_image;
1060 DELAY(10000); /* Some internal modems need this time */
1061 irqmap[1] = isa_irq_pending();
1062 failures[4] = (sio_getreg(com, com_iir) & IIR_IMASK) - IIR_TXRDY;
1063 DELAY(1000); /* XXX */
1064 irqmap[2] = isa_irq_pending();
1065 failures[6] = (sio_getreg(com, com_iir) & IIR_IMASK) - IIR_NOPEND;
1068 * Turn off all device interrupts and check that they go off properly.
1069 * Leave MCR_IENABLE alone. For ports without a master port, it gates
1070 * the OUT2 output of the UART to
1071 * the ICU input. Closing the gate would give a floating ICU input
1072 * (unless there is another device driving it) and spurious interrupts.
1073 * (On the system that this was first tested on, the input floats high
1074 * and gives a (masked) interrupt as soon as the gate is closed.)
1076 sio_setreg(com, com_ier, 0);
1077 sio_setreg(com, com_cfcr, CFCR_8BITS); /* dummy to avoid bus echo */
1078 failures[7] = sio_getreg(com, com_ier);
1079 DELAY(1000); /* XXX */
1080 irqmap[3] = isa_irq_pending();
1081 failures[9] = (sio_getreg(com, com_iir) & IIR_IMASK) - IIR_NOPEND;
1085 irqs = irqmap[1] & ~irqmap[0];
1086 if (bus_get_resource(idev, SYS_RES_IRQ, 0, &xirq, NULL) == 0 &&
1087 ((1 << xirq) & irqs) == 0)
1089 "sio%d: configured irq %ld not in bitmap of probed irqs %#x\n",
1090 device_get_unit(dev), xirq, irqs);
1092 printf("sio%d: irq maps: %#x %#x %#x %#x\n",
1093 device_get_unit(dev),
1094 irqmap[0], irqmap[1], irqmap[2], irqmap[3]);
1097 for (fn = 0; fn < sizeof failures; ++fn)
1099 sio_setreg(com, com_mcr, 0);
1102 printf("sio%d: probe failed test(s):",
1103 device_get_unit(dev));
1104 for (fn = 0; fn < sizeof failures; ++fn)
1111 bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
1112 return (iobase == siocniobase ? 0 : result);
1117 espattach(com, esp_port)
1125 * Check the ESP-specific I/O port to see if we're an ESP
1126 * card. If not, return failure immediately.
1128 if ((inb(esp_port) & 0xf3) == 0) {
1129 printf(" port 0x%x is not an ESP board?\n", esp_port);
1134 * We've got something that claims to be a Hayes ESP card.
1138 /* Get the dip-switch configuration */
1139 outb(esp_port + ESP_CMD1, ESP_GETDIPS);
1140 dips = inb(esp_port + ESP_STATUS1);
1143 * Bits 0,1 of dips say which COM port we are.
1145 if (rman_get_start(com->ioportres) == likely_com_ports[dips & 0x03])
1148 printf(" esp_port has com %d\n", dips & 0x03);
1153 * Check for ESP version 2.0 or later: bits 4,5,6 = 010.
1155 outb(esp_port + ESP_CMD1, ESP_GETTEST);
1156 val = inb(esp_port + ESP_STATUS1); /* clear reg 1 */
1157 val = inb(esp_port + ESP_STATUS2);
1158 if ((val & 0x70) < 0x20) {
1159 printf("-old (%o)", val & 0x70);
1164 * Check for ability to emulate 16550: bit 7 == 1
1166 if ((dips & 0x80) == 0) {
1172 * Okay, we seem to be a Hayes ESP card. Whee.
1175 com->esp_port = esp_port;
1178 #endif /* COM_ESP */
1184 return (sioattach(dev, 0, 0UL));
1188 sioattach(dev, xrid, rclk)
1202 struct resource *port;
1206 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
1207 0, ~0, IO_COMSIZE, RF_ACTIVE);
1211 iobase = rman_get_start(port);
1212 unit = device_get_unit(dev);
1213 com = device_get_softc(dev);
1214 flags = device_get_flags(dev);
1216 if (unit >= sio_numunits)
1217 sio_numunits = unit + 1;
1219 * sioprobe() has initialized the device registers as follows:
1220 * o cfcr = CFCR_8BITS.
1221 * It is most important that CFCR_DLAB is off, so that the
1222 * data port is not hidden when we enable interrupts.
1224 * Interrupts are only enabled when the line is open.
1225 * o mcr = MCR_IENABLE, or 0 if the port has AST/4 compatible
1226 * interrupt control register or the config specifies no irq.
1227 * Keeping MCR_DTR and MCR_RTS off might stop the external
1228 * device from sending before we are ready.
1230 bzero(com, sizeof *com);
1232 com->ioportres = port;
1233 com->bst = rman_get_bustag(port);
1234 com->bsh = rman_get_bushandle(port);
1235 com->cfcr_image = CFCR_8BITS;
1236 com->dtr_wait = 3 * hz;
1237 com->loses_outints = COM_LOSESOUTINTS(flags) != 0;
1238 com->no_irq = bus_get_resource(dev, SYS_RES_IRQ, 0, NULL, NULL) != 0;
1239 com->tx_fifo_size = 1;
1240 com->obufs[0].l_head = com->obuf1;
1241 com->obufs[1].l_head = com->obuf2;
1243 com->data_port = iobase + com_data;
1244 com->int_id_port = iobase + com_iir;
1245 com->modem_ctl_port = iobase + com_mcr;
1246 com->mcr_image = inb(com->modem_ctl_port);
1247 com->line_status_port = iobase + com_lsr;
1248 com->modem_status_port = iobase + com_msr;
1249 com->intr_ctl_port = iobase + com_ier;
1252 rclk = DEFAULT_RCLK;
1256 * We don't use all the flags from <sys/ttydefaults.h> since they
1257 * are only relevant for logins. It's important to have echo off
1258 * initially so that the line doesn't start blathering before the
1259 * echo flag can be turned off.
1261 com->it_in.c_iflag = 0;
1262 com->it_in.c_oflag = 0;
1263 com->it_in.c_cflag = TTYDEF_CFLAG;
1264 com->it_in.c_lflag = 0;
1265 if (unit == comconsole) {
1266 com->it_in.c_iflag = TTYDEF_IFLAG;
1267 com->it_in.c_oflag = TTYDEF_OFLAG;
1268 com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
1269 com->it_in.c_lflag = TTYDEF_LFLAG;
1270 com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL;
1271 com->lt_out.c_ispeed = com->lt_out.c_ospeed =
1272 com->lt_in.c_ispeed = com->lt_in.c_ospeed =
1273 com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate;
1275 com->it_in.c_ispeed = com->it_in.c_ospeed = TTYDEF_SPEED;
1276 if (siosetwater(com, com->it_in.c_ispeed) != 0) {
1279 * Leave i/o resources allocated if this is a `cn'-level
1280 * console, so that other devices can't snarf them.
1282 if (iobase != siocniobase)
1283 bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
1287 termioschars(&com->it_in);
1288 com->it_out = com->it_in;
1290 /* attempt to determine UART type */
1291 printf("sio%d: type", unit);
1294 #ifdef COM_MULTIPORT
1295 if (!COM_ISMULTIPORT(flags) && !COM_IIR_TXRDYBUG(flags))
1297 if (!COM_IIR_TXRDYBUG(flags))
1304 scr = sio_getreg(com, com_scr);
1305 sio_setreg(com, com_scr, 0xa5);
1306 scr1 = sio_getreg(com, com_scr);
1307 sio_setreg(com, com_scr, 0x5a);
1308 scr2 = sio_getreg(com, com_scr);
1309 sio_setreg(com, com_scr, scr);
1310 if (scr1 != 0xa5 || scr2 != 0x5a) {
1312 goto determined_type;
1315 sio_setreg(com, com_fifo, FIFO_ENABLE | FIFO_RX_HIGH);
1318 switch (inb(com->int_id_port) & IIR_FIFO_MASK) {
1329 if (COM_NOFIFO(flags)) {
1330 printf(" 16550A fifo disabled");
1332 com->hasfifo = TRUE;
1333 if (COM_ST16650A(flags)) {
1335 com->tx_fifo_size = 32;
1336 printf(" ST16650A");
1337 } else if (COM_TI16754(flags)) {
1338 com->tx_fifo_size = 64;
1341 com->tx_fifo_size = COM_FIFOSIZE(flags);
1346 for (espp = likely_esp_ports; *espp != 0; espp++)
1347 if (espattach(com, *espp)) {
1348 com->tx_fifo_size = 1024;
1352 if (!com->st16650a && !COM_TI16754(flags)) {
1353 if (!com->tx_fifo_size)
1354 com->tx_fifo_size = 16;
1356 printf(" lookalike with %d bytes FIFO",
1366 * Set 16550 compatibility mode.
1367 * We don't use the ESP_MODE_SCALE bit to increase the
1368 * fifo trigger levels because we can't handle large
1370 * XXX flow control should be set in comparam(), not here.
1372 outb(com->esp_port + ESP_CMD1, ESP_SETMODE);
1373 outb(com->esp_port + ESP_CMD2, ESP_MODE_RTS | ESP_MODE_FIFO);
1375 /* Set RTS/CTS flow control. */
1376 outb(com->esp_port + ESP_CMD1, ESP_SETFLOWTYPE);
1377 outb(com->esp_port + ESP_CMD2, ESP_FLOW_RTS);
1378 outb(com->esp_port + ESP_CMD2, ESP_FLOW_CTS);
1380 /* Set flow-control levels. */
1381 outb(com->esp_port + ESP_CMD1, ESP_SETRXFLOW);
1382 outb(com->esp_port + ESP_CMD2, HIBYTE(768));
1383 outb(com->esp_port + ESP_CMD2, LOBYTE(768));
1384 outb(com->esp_port + ESP_CMD2, HIBYTE(512));
1385 outb(com->esp_port + ESP_CMD2, LOBYTE(512));
1387 #endif /* COM_ESP */
1388 sio_setreg(com, com_fifo, 0);
1391 #ifdef COM_MULTIPORT
1392 if (COM_ISMULTIPORT(flags)) {
1395 com->multiport = TRUE;
1396 printf(" (multiport");
1397 if (unit == COM_MPMASTER(flags))
1400 masterdev = devclass_get_device(sio_devclass,
1401 COM_MPMASTER(flags));
1402 com->no_irq = (masterdev == NULL || bus_get_resource(masterdev,
1403 SYS_RES_IRQ, 0, NULL, NULL) != 0);
1405 #endif /* COM_MULTIPORT */
1406 if (unit == comconsole)
1407 printf(", console");
1408 if (COM_IIR_TXRDYBUG(flags))
1409 printf(" with a bogus IIR_TXRDY register");
1412 if (!sio_registered) {
1413 register_swi(SWI_TTY, siopoll);
1414 sio_registered = TRUE;
1416 minorbase = UNIT_TO_MINOR(unit);
1417 make_dev(&sio_cdevsw, minorbase,
1418 UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit);
1419 make_dev(&sio_cdevsw, minorbase | CONTROL_INIT_STATE,
1420 UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit);
1421 make_dev(&sio_cdevsw, minorbase | CONTROL_LOCK_STATE,
1422 UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit);
1423 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
1424 UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit);
1425 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
1426 UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit);
1427 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
1428 UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
1430 com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
1431 pps_init(&com->pps);
1434 com->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0ul, ~0ul, 1,
1437 ret = BUS_SETUP_INTR(device_get_parent(dev), dev, com->irqres,
1438 INTR_TYPE_TTY | INTR_TYPE_FAST,
1439 siointr, com, &com->cookie);
1441 ret = BUS_SETUP_INTR(device_get_parent(dev), dev,
1442 com->irqres, INTR_TYPE_TTY,
1443 siointr, com, &com->cookie);
1445 device_printf(dev, "unable to activate interrupt in fast mode - using normal mode\n");
1448 device_printf(dev, "could not activate interrupt\n");
1449 #if defined(DDB) && (defined(BREAK_TO_DEBUGGER) || \
1450 defined(ALT_BREAK_TO_DEBUGGER))
1452 * Enable interrupts for early break-to-debugger support
1455 if (ret == 0 && unit == comconsole)
1456 outb(siocniobase + com_ier, IER_ERXRDY | IER_ERLS |
1465 sioopen(dev_t dev, int flag, int mode, struct thread *td)
1475 unit = MINOR_TO_UNIT(mynor);
1476 com = com_addr(unit);
1481 if (mynor & CONTROL_MASK)
1483 tp = dev->si_tty = com->tp = ttymalloc(com->tp);
1486 * We jump to this label after all non-interrupted sleeps to pick
1487 * up any changes of the device state.
1490 while (com->state & CS_DTR_OFF) {
1491 error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "siodtr", 0);
1492 if (com_addr(unit) == NULL)
1494 if (error != 0 || com->gone)
1497 if (tp->t_state & TS_ISOPEN) {
1499 * The device is open, so everything has been initialized.
1502 if (mynor & CALLOUT_MASK) {
1503 if (!com->active_out) {
1508 if (com->active_out) {
1509 if (flag & O_NONBLOCK) {
1513 error = tsleep(&com->active_out,
1514 TTIPRI | PCATCH, "siobi", 0);
1515 if (com_addr(unit) == NULL)
1517 if (error != 0 || com->gone)
1522 if (tp->t_state & TS_XCLUDE &&
1523 suser_xxx(td->td_proc->p_ucred, 0)) {
1529 * The device isn't open, so there are no conflicts.
1530 * Initialize it. Initialization is done twice in many
1531 * cases: to preempt sleeping callin opens if we are
1532 * callout, and to complete a callin open after DCD rises.
1534 tp->t_oproc = comstart;
1535 tp->t_param = comparam;
1536 tp->t_stop = comstop;
1538 tp->t_termios = mynor & CALLOUT_MASK
1539 ? com->it_out : com->it_in;
1540 (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET);
1541 com->poll = com->no_irq;
1542 com->poll_output = com->loses_outints;
1544 error = comparam(tp, &tp->t_termios);
1549 * XXX we should goto open_top if comparam() slept.
1553 * (Re)enable and drain fifos.
1555 * Certain SMC chips cause problems if the fifos
1556 * are enabled while input is ready. Turn off the
1557 * fifo if necessary to clear the input. We test
1558 * the input ready bit after enabling the fifos
1559 * since we've already enabled them in comparam()
1560 * and to handle races between enabling and fresh
1564 sio_setreg(com, com_fifo,
1565 FIFO_RCV_RST | FIFO_XMT_RST
1568 * XXX the delays are for superstitious
1569 * historical reasons. It must be less than
1570 * the character time at the maximum
1571 * supported speed (87 usec at 115200 bps
1572 * 8N1). Otherwise we might loop endlessly
1573 * if data is streaming in. We used to use
1574 * delays of 100. That usually worked
1575 * because DELAY(100) used to usually delay
1576 * for about 85 usec instead of 100.
1579 if (!(inb(com->line_status_port) & LSR_RXRDY))
1581 sio_setreg(com, com_fifo, 0);
1583 (void) inb(com->data_port);
1588 (void) inb(com->line_status_port);
1589 (void) inb(com->data_port);
1590 com->prev_modem_status = com->last_modem_status
1591 = inb(com->modem_status_port);
1592 if (COM_IIR_TXRDYBUG(com->flags)) {
1593 outb(com->intr_ctl_port, IER_ERXRDY | IER_ERLS
1596 outb(com->intr_ctl_port, IER_ERXRDY | IER_ETXRDY
1597 | IER_ERLS | IER_EMSC);
1601 * Handle initial DCD. Callout devices get a fake initial
1602 * DCD (trapdoor DCD). If we are callout, then any sleeping
1603 * callin opens get woken up and resume sleeping on "siobi"
1604 * instead of "siodcd".
1607 * XXX `mynor & CALLOUT_MASK' should be
1608 * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
1609 * TRAPDOOR_CARRIER is the default initial state for callout
1610 * devices and SOFT_CARRIER is like CLOCAL except it hides
1613 if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
1614 (*linesw[tp->t_line].l_modem)(tp, 1);
1617 * Wait for DCD if necessary.
1619 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
1620 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
1622 error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "siodcd", 0);
1623 if (com_addr(unit) == NULL)
1626 if (error != 0 || com->gone)
1630 error = (*linesw[tp->t_line].l_open)(dev, tp);
1631 disc_optim(tp, &tp->t_termios, com);
1632 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
1633 com->active_out = TRUE;
1637 if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
1643 sioclose(dev_t dev, int flag, int mode, struct thread *td)
1651 if (mynor & CONTROL_MASK)
1653 com = com_addr(MINOR_TO_UNIT(mynor));
1658 (*linesw[tp->t_line].l_close)(tp, flag);
1659 disc_optim(tp, &tp->t_termios, com);
1660 comstop(tp, FREAD | FWRITE);
1666 printf("sio%d: gone\n", com->unit);
1668 if (com->ibuf != NULL)
1669 free(com->ibuf, M_DEVBUF);
1670 bzero(tp, sizeof *tp);
1687 com->poll_output = FALSE;
1688 com->do_timestamp = FALSE;
1689 com->do_dcd_timestamp = FALSE;
1690 com->pps.ppsparam.mode = 0;
1691 sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
1694 #if defined(DDB) && (defined(BREAK_TO_DEBUGGER) || \
1695 defined(ALT_BREAK_TO_DEBUGGER))
1697 * Leave interrupts enabled and don't clear DTR if this is the
1698 * console. This allows us to detect break-to-debugger events
1699 * while the console device is closed.
1701 if (com->unit != comconsole)
1704 sio_setreg(com, com_ier, 0);
1705 if (tp->t_cflag & HUPCL
1707 * XXX we will miss any carrier drop between here and the
1708 * next open. Perhaps we should watch DCD even when the
1709 * port is closed; it is not sufficient to check it at
1710 * the next open because it might go up and down while
1711 * we're not watching.
1713 || (!com->active_out
1714 && !(com->prev_modem_status & MSR_DCD)
1715 && !(com->it_in.c_cflag & CLOCAL))
1716 || !(tp->t_state & TS_ISOPEN)) {
1717 (void)commctl(com, TIOCM_DTR, DMBIC);
1718 if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {
1719 timeout(siodtrwakeup, com, com->dtr_wait);
1720 com->state |= CS_DTR_OFF;
1726 * Disable fifos so that they are off after controlled
1727 * reboots. Some BIOSes fail to detect 16550s when the
1728 * fifos are enabled.
1730 sio_setreg(com, com_fifo, 0);
1732 com->active_out = FALSE;
1733 wakeup(&com->active_out);
1734 wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
1739 sioread(dev, uio, flag)
1748 if (mynor & CONTROL_MASK)
1750 com = com_addr(MINOR_TO_UNIT(mynor));
1751 if (com == NULL || com->gone)
1753 return ((*linesw[com->tp->t_line].l_read)(com->tp, uio, flag));
1757 siowrite(dev, uio, flag)
1767 if (mynor & CONTROL_MASK)
1770 unit = MINOR_TO_UNIT(mynor);
1771 com = com_addr(unit);
1772 if (com == NULL || com->gone)
1775 * (XXX) We disallow virtual consoles if the physical console is
1776 * a serial port. This is in case there is a display attached that
1777 * is not the console. In that situation we don't need/want the X
1778 * server taking over the console.
1780 if (constty != NULL && unit == comconsole)
1782 return ((*linesw[com->tp->t_line].l_write)(com->tp, uio, flag));
1792 com = (struct com_s *)chan;
1795 * Clear TS_BUSY if low-level output is complete.
1796 * spl locking is sufficient because siointr1() does not set CS_BUSY.
1797 * If siointr1() clears CS_BUSY after we look at it, then we'll get
1798 * called again. Reading the line status port outside of siointr1()
1799 * is safe because CS_BUSY is clear so there are no output interrupts
1803 if (com->state & CS_BUSY)
1804 com->extra_state &= ~CSE_BUSYCHECK; /* False alarm. */
1805 else if ((inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY))
1806 == (LSR_TSRE | LSR_TXRDY)) {
1807 com->tp->t_state &= ~TS_BUSY;
1809 com->extra_state &= ~CSE_BUSYCHECK;
1811 timeout(siobusycheck, com, hz / 100);
1816 siodivisor(rclk, speed)
1824 if (speed == 0 || speed > (ULONG_MAX - 1) / 8)
1826 divisor = (rclk / (8UL * speed) + 1) / 2;
1827 if (divisor == 0 || divisor >= 65536)
1829 actual_speed = rclk / (16UL * divisor);
1831 /* 10 times error in percent: */
1832 error = ((actual_speed - (long)speed) * 2000 / (long)speed + 1) / 2;
1834 /* 3.0% maximum error tolerance: */
1835 if (error < -30 || error > 30)
1847 com = (struct com_s *)chan;
1848 com->state &= ~CS_DTR_OFF;
1849 wakeup(&com->dtr_wait);
1864 if (!(tp->t_state & TS_ISOPEN) || !(tp->t_cflag & CREAD)) {
1865 com_events -= (com->iptr - com->ibuf);
1866 com->iptr = com->ibuf;
1869 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1871 * Avoid the grotesquely inefficient lineswitch routine
1872 * (ttyinput) in "raw" mode. It usually takes about 450
1873 * instructions (that's without canonical processing or echo!).
1874 * slinput is reasonably fast (usually 40 instructions plus
1879 incc = com->iptr - buf;
1880 if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
1881 && (com->state & CS_RTS_IFLOW
1882 || tp->t_iflag & IXOFF)
1883 && !(tp->t_state & TS_TBLOCK))
1885 com->delta_error_counts[CE_TTY_BUF_OVERFLOW]
1886 += b_to_q((char *)buf, incc, &tp->t_rawq);
1890 tp->t_rawcc += incc;
1892 if (tp->t_state & TS_TTSTOP
1893 && (tp->t_iflag & IXANY
1894 || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1895 tp->t_state &= ~TS_TTSTOP;
1896 tp->t_lflag &= ~FLUSHO;
1900 } while (buf < com->iptr);
1904 line_status = buf[com->ierroff];
1907 & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) {
1908 if (line_status & LSR_BI)
1909 recv_data |= TTY_BI;
1910 if (line_status & LSR_FE)
1911 recv_data |= TTY_FE;
1912 if (line_status & LSR_OE)
1913 recv_data |= TTY_OE;
1914 if (line_status & LSR_PE)
1915 recv_data |= TTY_PE;
1917 (*linesw[tp->t_line].l_rint)(recv_data, tp);
1919 } while (buf < com->iptr);
1921 com_events -= (com->iptr - com->ibuf);
1922 com->iptr = com->ibuf;
1925 * There is now room for another low-level buffer full of input,
1926 * so enable RTS if it is now disabled and there is room in the
1927 * high-level buffer.
1929 if ((com->state & CS_RTS_IFLOW) && !(com->mcr_image & MCR_RTS) &&
1930 !(tp->t_state & TS_TBLOCK))
1931 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
1938 #ifndef COM_MULTIPORT
1940 siointr1((struct com_s *) arg);
1942 #else /* COM_MULTIPORT */
1943 bool_t possibly_more_intrs;
1948 * Loop until there is no activity on any port. This is necessary
1949 * to get an interrupt edge more than to avoid another interrupt.
1950 * If the IRQ signal is just an OR of the IRQ signals from several
1951 * devices, then the edge from one may be lost because another is
1956 possibly_more_intrs = FALSE;
1957 for (unit = 0; unit < sio_numunits; ++unit) {
1958 com = com_addr(unit);
1961 * would it work here, or be counter-productive?
1965 && (inb(com->int_id_port) & IIR_IMASK)
1968 possibly_more_intrs = TRUE;
1970 /* XXX COM_UNLOCK(); */
1972 } while (possibly_more_intrs);
1974 #endif /* COM_MULTIPORT */
1982 u_char modem_status;
1987 struct timecounter *tc;
1990 int_ctl = inb(com->intr_ctl_port);
1991 int_ctl_new = int_ctl;
1993 while (!com->gone) {
1994 if (com->pps.ppsparam.mode & PPS_CAPTUREBOTH) {
1995 modem_status = inb(com->modem_status_port);
1996 if ((modem_status ^ com->last_modem_status) & MSR_DCD) {
1998 count = tc->tc_get_timecount(tc);
1999 pps_event(&com->pps, tc, count,
2000 (modem_status & MSR_DCD) ?
2001 PPS_CAPTUREASSERT : PPS_CAPTURECLEAR);
2004 line_status = inb(com->line_status_port);
2006 /* input event? (check first to help avoid overruns) */
2007 while (line_status & LSR_RCV_MASK) {
2008 /* break/unnattached error bits or real input? */
2009 if (!(line_status & LSR_RXRDY))
2012 recv_data = inb(com->data_port);
2013 #if defined(DDB) && defined(ALT_BREAK_TO_DEBUGGER)
2015 * Solaris implements a new BREAK which is initiated
2016 * by a character sequence CR ~ ^b which is similar
2017 * to a familiar pattern used on Sun servers by the
2020 #define KEY_CRTLB 2 /* ^B */
2021 #define KEY_CR 13 /* CR '\r' */
2022 #define KEY_TILDE 126 /* ~ */
2024 if (com->unit == comconsole) {
2025 static int brk_state1 = 0, brk_state2 = 0;
2026 if (recv_data == KEY_CR) {
2027 brk_state1 = recv_data;
2029 } else if (brk_state1 == KEY_CR && (recv_data == KEY_TILDE || recv_data == KEY_CRTLB)) {
2030 if (recv_data == KEY_TILDE)
2031 brk_state2 = recv_data;
2032 else if (brk_state2 == KEY_TILDE && recv_data == KEY_CRTLB) {
2034 brk_state1 = brk_state2 = 0;
2042 if (line_status & (LSR_BI | LSR_FE | LSR_PE)) {
2044 * Don't store BI if IGNBRK or FE/PE if IGNPAR.
2045 * Otherwise, push the work to a higher level
2046 * (to handle PARMRK) if we're bypassing.
2047 * Otherwise, convert BI/FE and PE+INPCK to 0.
2049 * This makes bypassing work right in the
2050 * usual "raw" case (IGNBRK set, and IGNPAR
2053 * Note: BI together with FE/PE means just BI.
2055 if (line_status & LSR_BI) {
2056 #if defined(DDB) && defined(BREAK_TO_DEBUGGER)
2057 if (com->unit == comconsole) {
2063 || com->tp->t_iflag & IGNBRK)
2067 || com->tp->t_iflag & IGNPAR)
2070 if (com->tp->t_state & TS_CAN_BYPASS_L_RINT
2071 && (line_status & (LSR_BI | LSR_FE)
2072 || com->tp->t_iflag & INPCK))
2076 if (com->hotchar != 0 && recv_data == com->hotchar)
2079 if (ioptr >= com->ibufend)
2080 CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
2082 if (com->do_timestamp)
2083 microtime(&com->timestamp);
2086 #if 0 /* for testing input latency vs efficiency */
2087 if (com->iptr - com->ibuf == 8)
2090 ioptr[0] = recv_data;
2091 ioptr[com->ierroff] = line_status;
2092 com->iptr = ++ioptr;
2093 if (ioptr == com->ihighwater
2094 && com->state & CS_RTS_IFLOW)
2095 outb(com->modem_ctl_port,
2096 com->mcr_image &= ~MCR_RTS);
2097 if (line_status & LSR_OE)
2098 CE_RECORD(com, CE_OVERRUN);
2102 * "& 0x7F" is to avoid the gcc-1.40 generating a slow
2103 * jump from the top of the loop to here
2105 line_status = inb(com->line_status_port) & 0x7F;
2108 /* modem status change? (always check before doing output) */
2109 modem_status = inb(com->modem_status_port);
2110 if (modem_status != com->last_modem_status) {
2111 if (com->do_dcd_timestamp
2112 && !(com->last_modem_status & MSR_DCD)
2113 && modem_status & MSR_DCD)
2114 microtime(&com->dcd_timestamp);
2117 * Schedule high level to handle DCD changes. Note
2118 * that we don't use the delta bits anywhere. Some
2119 * UARTs mess them up, and it's easy to remember the
2120 * previous bits and calculate the delta.
2122 com->last_modem_status = modem_status;
2123 if (!(com->state & CS_CHECKMSR)) {
2124 com_events += LOTS_OF_EVENTS;
2125 com->state |= CS_CHECKMSR;
2129 /* handle CTS change immediately for crisp flow ctl */
2130 if (com->state & CS_CTS_OFLOW) {
2131 if (modem_status & MSR_CTS)
2132 com->state |= CS_ODEVREADY;
2134 com->state &= ~CS_ODEVREADY;
2138 /* output queued and everything ready? */
2139 if (line_status & LSR_TXRDY
2140 && com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
2141 ioptr = com->obufq.l_head;
2142 if (com->tx_fifo_size > 1) {
2145 ocount = com->obufq.l_tail - ioptr;
2146 if (ocount > com->tx_fifo_size)
2147 ocount = com->tx_fifo_size;
2148 com->bytes_out += ocount;
2150 outb(com->data_port, *ioptr++);
2151 while (--ocount != 0);
2153 outb(com->data_port, *ioptr++);
2156 com->obufq.l_head = ioptr;
2157 if (COM_IIR_TXRDYBUG(com->flags)) {
2158 int_ctl_new = int_ctl | IER_ETXRDY;
2160 if (ioptr >= com->obufq.l_tail) {
2163 qp = com->obufq.l_next;
2164 qp->l_queued = FALSE;
2167 com->obufq.l_head = qp->l_head;
2168 com->obufq.l_tail = qp->l_tail;
2169 com->obufq.l_next = qp;
2171 /* output just completed */
2172 if (COM_IIR_TXRDYBUG(com->flags)) {
2173 int_ctl_new = int_ctl & ~IER_ETXRDY;
2175 com->state &= ~CS_BUSY;
2177 if (!(com->state & CS_ODONE)) {
2178 com_events += LOTS_OF_EVENTS;
2179 com->state |= CS_ODONE;
2180 setsofttty(); /* handle at high level ASAP */
2183 if (COM_IIR_TXRDYBUG(com->flags) && (int_ctl != int_ctl_new)) {
2184 outb(com->intr_ctl_port, int_ctl_new);
2189 #ifndef COM_MULTIPORT
2190 if ((inb(com->int_id_port) & IIR_IMASK) == IIR_NOPEND)
2191 #endif /* COM_MULTIPORT */
2197 sioioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
2204 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
2206 struct termios term;
2210 com = com_addr(MINOR_TO_UNIT(mynor));
2211 if (com == NULL || com->gone)
2213 if (mynor & CONTROL_MASK) {
2216 switch (mynor & CONTROL_MASK) {
2217 case CONTROL_INIT_STATE:
2218 ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
2220 case CONTROL_LOCK_STATE:
2221 ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
2224 return (ENODEV); /* /dev/nodev */
2228 error = suser_xxx(td->td_proc->p_ucred, 0);
2231 *ct = *(struct termios *)data;
2234 *(struct termios *)data = *ct;
2237 *(int *)data = TTYDISC;
2240 bzero(data, sizeof(struct winsize));
2247 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
2248 term = tp->t_termios;
2250 error = ttsetcompat(tp, &cmd, data, &term);
2254 data = (caddr_t)&term;
2256 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
2258 struct termios *dt = (struct termios *)data;
2259 struct termios *lt = mynor & CALLOUT_MASK
2260 ? &com->lt_out : &com->lt_in;
2262 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
2263 | (dt->c_iflag & ~lt->c_iflag);
2264 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
2265 | (dt->c_oflag & ~lt->c_oflag);
2266 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
2267 | (dt->c_cflag & ~lt->c_cflag);
2268 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
2269 | (dt->c_lflag & ~lt->c_lflag);
2270 for (cc = 0; cc < NCCS; ++cc)
2271 if (lt->c_cc[cc] != 0)
2272 dt->c_cc[cc] = tp->t_cc[cc];
2273 if (lt->c_ispeed != 0)
2274 dt->c_ispeed = tp->t_ispeed;
2275 if (lt->c_ospeed != 0)
2276 dt->c_ospeed = tp->t_ospeed;
2278 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
2279 if (error != ENOIOCTL)
2282 error = ttioctl(tp, cmd, data, flag);
2283 disc_optim(tp, &tp->t_termios, com);
2284 if (error != ENOIOCTL) {
2290 sio_setreg(com, com_cfcr, com->cfcr_image |= CFCR_SBREAK);
2293 sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
2296 (void)commctl(com, TIOCM_DTR, DMBIS);
2299 (void)commctl(com, TIOCM_DTR, DMBIC);
2302 * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
2303 * changes get undone on the next call to comparam().
2306 (void)commctl(com, *(int *)data, DMSET);
2309 (void)commctl(com, *(int *)data, DMBIS);
2312 (void)commctl(com, *(int *)data, DMBIC);
2315 *(int *)data = commctl(com, 0, DMGET);
2318 /* must be root since the wait applies to following logins */
2319 error = suser_xxx(td->td_proc->p_ucred, 0);
2324 com->dtr_wait = *(int *)data * hz / 100;
2327 *(int *)data = com->dtr_wait * 100 / hz;
2330 com->do_timestamp = TRUE;
2331 *(struct timeval *)data = com->timestamp;
2333 case TIOCDCDTIMESTAMP:
2334 com->do_dcd_timestamp = TRUE;
2335 *(struct timeval *)data = com->dcd_timestamp;
2339 error = pps_ioctl(cmd, data, &com->pps);
2340 if (error == ENODEV)
2353 if (com_events == 0)
2356 for (unit = 0; unit < sio_numunits; ++unit) {
2361 com = com_addr(unit);
2365 if (tp == NULL || com->gone) {
2367 * Discard any events related to never-opened or
2368 * going-away devices.
2371 incc = com->iptr - com->ibuf;
2372 com->iptr = com->ibuf;
2373 if (com->state & CS_CHECKMSR) {
2374 incc += LOTS_OF_EVENTS;
2375 com->state &= ~CS_CHECKMSR;
2381 if (com->iptr != com->ibuf) {
2386 if (com->state & CS_CHECKMSR) {
2387 u_char delta_modem_status;
2390 delta_modem_status = com->last_modem_status
2391 ^ com->prev_modem_status;
2392 com->prev_modem_status = com->last_modem_status;
2393 com_events -= LOTS_OF_EVENTS;
2394 com->state &= ~CS_CHECKMSR;
2396 if (delta_modem_status & MSR_DCD)
2397 (*linesw[tp->t_line].l_modem)
2398 (tp, com->prev_modem_status & MSR_DCD);
2400 if (com->state & CS_ODONE) {
2402 com_events -= LOTS_OF_EVENTS;
2403 com->state &= ~CS_ODONE;
2405 if (!(com->state & CS_BUSY)
2406 && !(com->extra_state & CSE_BUSYCHECK)) {
2407 timeout(siobusycheck, com, hz / 100);
2408 com->extra_state |= CSE_BUSYCHECK;
2410 (*linesw[tp->t_line].l_start)(tp);
2412 if (com_events == 0)
2415 if (com_events >= LOTS_OF_EVENTS)
2433 unit = DEV_TO_UNIT(tp->t_dev);
2434 com = com_addr(unit);
2438 /* do historical conversions */
2439 if (t->c_ispeed == 0)
2440 t->c_ispeed = t->c_ospeed;
2442 /* check requested parameters */
2443 if (t->c_ospeed == 0)
2446 if (t->c_ispeed != t->c_ospeed)
2448 divisor = siodivisor(com->rclk, t->c_ispeed);
2453 /* parameters are OK, convert them to the com struct and the device */
2456 (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
2458 (void)commctl(com, TIOCM_DTR, DMBIS);
2460 switch (cflag & CSIZE) {
2474 if (cflag & PARENB) {
2476 if (!(cflag & PARODD))
2482 if (com->hasfifo && divisor != 0) {
2484 * Use a fifo trigger level low enough so that the input
2485 * latency from the fifo is less than about 16 msec and
2486 * the total latency is less than about 30 msec. These
2487 * latencies are reasonable for humans. Serial comms
2488 * protocols shouldn't expect anything better since modem
2489 * latencies are larger.
2491 * Interrupts can be held up for long periods of time
2492 * due to inefficiencies in other parts of the kernel,
2493 * certain video cards, etc. Setting the FIFO trigger
2494 * point to MEDH instead of HIGH gives us 694uS of slop
2495 * (8 character times) instead of 173uS (2 character times)
2498 com->fifo_image = t->c_ospeed <= 4800
2499 ? FIFO_ENABLE : FIFO_ENABLE | FIFO_RX_MEDH;
2502 * The Hayes ESP card needs the fifo DMA mode bit set
2503 * in compatibility mode. If not, it will interrupt
2504 * for each character received.
2507 com->fifo_image |= FIFO_DMA_MODE;
2509 sio_setreg(com, com_fifo, com->fifo_image);
2513 * This returns with interrupts disabled so that we can complete
2514 * the speed change atomically. Keeping interrupts disabled is
2515 * especially important while com_data is hidden.
2517 (void) siosetwater(com, t->c_ispeed);
2520 sio_setreg(com, com_cfcr, cfcr | CFCR_DLAB);
2522 * Only set the divisor registers if they would change,
2523 * since on some 16550 incompatibles (UMC8669F), setting
2524 * them while input is arriving them loses sync until
2525 * data stops arriving.
2527 dlbl = divisor & 0xFF;
2528 if (sio_getreg(com, com_dlbl) != dlbl)
2529 sio_setreg(com, com_dlbl, dlbl);
2530 dlbh = divisor >> 8;
2531 if (sio_getreg(com, com_dlbh) != dlbh)
2532 sio_setreg(com, com_dlbh, dlbh);
2535 sio_setreg(com, com_cfcr, com->cfcr_image = cfcr);
2537 if (!(tp->t_state & TS_TTSTOP))
2538 com->state |= CS_TTGO;
2540 if (cflag & CRTS_IFLOW) {
2541 if (com->st16650a) {
2542 sio_setreg(com, com_cfcr, 0xbf);
2543 sio_setreg(com, com_fifo,
2544 sio_getreg(com, com_fifo) | 0x40);
2546 com->state |= CS_RTS_IFLOW;
2548 * If CS_RTS_IFLOW just changed from off to on, the change
2549 * needs to be propagated to MCR_RTS. This isn't urgent,
2550 * so do it later by calling comstart() instead of repeating
2551 * a lot of code from comstart() here.
2553 } else if (com->state & CS_RTS_IFLOW) {
2554 com->state &= ~CS_RTS_IFLOW;
2556 * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS
2557 * on here, since comstart() won't do it later.
2559 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2560 if (com->st16650a) {
2561 sio_setreg(com, com_cfcr, 0xbf);
2562 sio_setreg(com, com_fifo,
2563 sio_getreg(com, com_fifo) & ~0x40);
2569 * Set up state to handle output flow control.
2570 * XXX - worth handling MDMBUF (DCD) flow control at the lowest level?
2571 * Now has 10+ msec latency, while CTS flow has 50- usec latency.
2573 com->state |= CS_ODEVREADY;
2574 com->state &= ~CS_CTS_OFLOW;
2575 if (cflag & CCTS_OFLOW) {
2576 com->state |= CS_CTS_OFLOW;
2577 if (!(com->last_modem_status & MSR_CTS))
2578 com->state &= ~CS_ODEVREADY;
2579 if (com->st16650a) {
2580 sio_setreg(com, com_cfcr, 0xbf);
2581 sio_setreg(com, com_fifo,
2582 sio_getreg(com, com_fifo) | 0x80);
2585 if (com->st16650a) {
2586 sio_setreg(com, com_cfcr, 0xbf);
2587 sio_setreg(com, com_fifo,
2588 sio_getreg(com, com_fifo) & ~0x80);
2592 sio_setreg(com, com_cfcr, com->cfcr_image);
2594 /* XXX shouldn't call functions while intrs are disabled. */
2595 disc_optim(tp, t, com);
2597 * Recover from fiddling with CS_TTGO. We used to call siointr1()
2598 * unconditionally, but that defeated the careful discarding of
2599 * stale input in sioopen().
2601 if (com->state >= (CS_BUSY | CS_TTGO))
2607 if (com->ibufold != NULL) {
2608 free(com->ibufold, M_DEVBUF);
2609 com->ibufold = NULL;
2615 siosetwater(com, speed)
2625 * Make the buffer size large enough to handle a softtty interrupt
2626 * latency of about 2 ticks without loss of throughput or data
2627 * (about 3 ticks if input flow control is not used or not honoured,
2628 * but a bit less for CS5-CS7 modes).
2630 cp4ticks = speed / 10 / hz * 4;
2631 for (ibufsize = 128; ibufsize < cp4ticks;)
2633 if (ibufsize == com->ibufsize) {
2639 * Allocate input buffer. The extra factor of 2 in the size is
2640 * to allow for an error byte for each input byte.
2642 ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
2648 /* Initialize non-critical variables. */
2649 com->ibufold = com->ibuf;
2650 com->ibufsize = ibufsize;
2653 tp->t_ififosize = 2 * ibufsize;
2654 tp->t_ispeedwat = (speed_t)-1;
2655 tp->t_ospeedwat = (speed_t)-1;
2659 * Read current input buffer, if any. Continue with interrupts
2663 if (com->iptr != com->ibuf)
2667 * Initialize critical variables, including input buffer watermarks.
2668 * The external device is asked to stop sending when the buffer
2669 * exactly reaches high water, or when the high level requests it.
2670 * The high level is notified immediately (rather than at a later
2671 * clock tick) when this watermark is reached.
2672 * The buffer size is chosen so the watermark should almost never
2674 * The low watermark is invisibly 0 since the buffer is always
2675 * emptied all at once.
2677 com->iptr = com->ibuf = ibuf;
2678 com->ibufend = ibuf + ibufsize;
2679 com->ierroff = ibufsize;
2680 com->ihighwater = ibuf + 3 * ibufsize / 4;
2692 unit = DEV_TO_UNIT(tp->t_dev);
2693 com = com_addr(unit);
2698 if (tp->t_state & TS_TTSTOP)
2699 com->state &= ~CS_TTGO;
2701 com->state |= CS_TTGO;
2702 if (tp->t_state & TS_TBLOCK) {
2703 if (com->mcr_image & MCR_RTS && com->state & CS_RTS_IFLOW)
2704 outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
2706 if (!(com->mcr_image & MCR_RTS) && com->iptr < com->ihighwater
2707 && com->state & CS_RTS_IFLOW)
2708 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2711 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
2716 if (tp->t_outq.c_cc != 0) {
2720 if (!com->obufs[0].l_queued) {
2721 com->obufs[0].l_tail
2722 = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1,
2724 com->obufs[0].l_next = NULL;
2725 com->obufs[0].l_queued = TRUE;
2727 if (com->state & CS_BUSY) {
2728 qp = com->obufq.l_next;
2729 while ((next = qp->l_next) != NULL)
2731 qp->l_next = &com->obufs[0];
2733 com->obufq.l_head = com->obufs[0].l_head;
2734 com->obufq.l_tail = com->obufs[0].l_tail;
2735 com->obufq.l_next = &com->obufs[0];
2736 com->state |= CS_BUSY;
2740 if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
2741 com->obufs[1].l_tail
2742 = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2,
2744 com->obufs[1].l_next = NULL;
2745 com->obufs[1].l_queued = TRUE;
2747 if (com->state & CS_BUSY) {
2748 qp = com->obufq.l_next;
2749 while ((next = qp->l_next) != NULL)
2751 qp->l_next = &com->obufs[1];
2753 com->obufq.l_head = com->obufs[1].l_head;
2754 com->obufq.l_tail = com->obufs[1].l_tail;
2755 com->obufq.l_next = &com->obufs[1];
2756 com->state |= CS_BUSY;
2760 tp->t_state |= TS_BUSY;
2763 if (com->state >= (CS_BUSY | CS_TTGO))
2764 siointr1(com); /* fake interrupt to start output */
2777 com = com_addr(DEV_TO_UNIT(tp->t_dev));
2778 if (com == NULL || com->gone)
2784 /* XXX avoid h/w bug. */
2787 sio_setreg(com, com_fifo,
2788 FIFO_XMT_RST | com->fifo_image);
2789 com->obufs[0].l_queued = FALSE;
2790 com->obufs[1].l_queued = FALSE;
2791 if (com->state & CS_ODONE)
2792 com_events -= LOTS_OF_EVENTS;
2793 com->state &= ~(CS_ODONE | CS_BUSY);
2794 com->tp->t_state &= ~TS_BUSY;
2799 /* XXX avoid h/w bug. */
2802 sio_setreg(com, com_fifo,
2803 FIFO_RCV_RST | com->fifo_image);
2804 com_events -= (com->iptr - com->ibuf);
2805 com->iptr = com->ibuf;
2812 commctl(com, bits, how)
2821 bits = TIOCM_LE; /* XXX - always enabled while open */
2822 mcr = com->mcr_image;
2827 msr = com->prev_modem_status;
2835 * XXX - MSR_RI is naturally volatile, and we make MSR_TERI
2836 * more volatile by reading the modem status a lot. Perhaps
2837 * we should latch both bits until the status is read here.
2839 if (msr & (MSR_RI | MSR_TERI))
2844 if (bits & TIOCM_DTR)
2846 if (bits & TIOCM_RTS)
2853 outb(com->modem_ctl_port,
2854 com->mcr_image = mcr | (com->mcr_image & MCR_IENABLE));
2857 outb(com->modem_ctl_port, com->mcr_image |= mcr);
2860 outb(com->modem_ctl_port, com->mcr_image &= ~mcr);
2875 * Set our timeout period to 1 second if no polled devices are open.
2876 * Otherwise set it to max(1/200, 1/hz).
2877 * Enable timeouts iff some device is open.
2879 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2882 for (unit = 0; unit < sio_numunits; ++unit) {
2883 com = com_addr(unit);
2884 if (com != NULL && com->tp != NULL
2885 && com->tp->t_state & TS_ISOPEN && !com->gone) {
2887 if (com->poll || com->poll_output) {
2888 sio_timeout = hz > 200 ? hz / 200 : 1;
2894 sio_timeouts_until_log = hz / sio_timeout;
2895 sio_timeout_handle = timeout(comwakeup, (void *)NULL,
2898 /* Flush error messages, if any. */
2899 sio_timeouts_until_log = 1;
2900 comwakeup((void *)NULL);
2901 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2912 sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout);
2915 * Recover from lost output interrupts.
2916 * Poll any lines that don't use interrupts.
2918 for (unit = 0; unit < sio_numunits; ++unit) {
2919 com = com_addr(unit);
2920 if (com != NULL && !com->gone
2921 && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
2929 * Check for and log errors, but not too often.
2931 if (--sio_timeouts_until_log > 0)
2933 sio_timeouts_until_log = hz / sio_timeout;
2934 for (unit = 0; unit < sio_numunits; ++unit) {
2937 com = com_addr(unit);
2942 for (errnum = 0; errnum < CE_NTYPES; ++errnum) {
2947 delta = com->delta_error_counts[errnum];
2948 com->delta_error_counts[errnum] = 0;
2952 total = com->error_counts[errnum] += delta;
2953 log(LOG_ERR, "sio%d: %u more %s%s (total %lu)\n",
2954 unit, delta, error_desc[errnum],
2955 delta == 1 ? "" : "s", total);
2961 disc_optim(tp, t, com)
2966 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2967 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2968 && (!(t->c_iflag & PARMRK)
2969 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2970 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2971 && linesw[tp->t_line].l_rint == ttyinput)
2972 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2974 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2975 com->hotchar = linesw[tp->t_line].l_hotchar;
2979 * Following are all routines needed for SIO to act as console
2981 #include <sys/cons.h>
2991 static speed_t siocngetspeed __P((Port_t, u_long rclk));
2992 static void siocnclose __P((struct siocnstate *sp, Port_t iobase));
2993 static void siocnopen __P((struct siocnstate *sp, Port_t iobase, int speed));
2994 static void siocntxwait __P((Port_t iobase));
2996 static cn_probe_t siocnprobe;
2997 static cn_init_t siocninit;
2998 static cn_checkc_t siocncheckc;
2999 static cn_getc_t siocngetc;
3000 static cn_putc_t siocnputc;
3003 CONS_DRIVER(sio, siocnprobe, siocninit, NULL, siocngetc, siocncheckc,
3007 /* To get the GDB related variables */
3009 #include <ddb/ddb.h>
3019 * Wait for any pending transmission to finish. Required to avoid
3020 * the UART lockup bug when the speed is changed, and for normal
3024 while ((inb(iobase + com_lsr) & (LSR_TSRE | LSR_TXRDY))
3025 != (LSR_TSRE | LSR_TXRDY) && --timo != 0)
3030 * Read the serial port specified and try to figure out what speed
3031 * it's currently running at. We're assuming the serial port has
3032 * been initialized and is basicly idle. This routine is only intended
3033 * to be run at system startup.
3035 * If the value read from the serial port doesn't make sense, return 0.
3039 siocngetspeed(iobase, rclk)
3048 cfcr = inb(iobase + com_cfcr);
3049 outb(iobase + com_cfcr, CFCR_DLAB | cfcr);
3051 dlbl = inb(iobase + com_dlbl);
3052 dlbh = inb(iobase + com_dlbh);
3054 outb(iobase + com_cfcr, cfcr);
3056 divisor = dlbh << 8 | dlbl;
3058 /* XXX there should be more sanity checking. */
3061 return (rclk / (16UL * divisor));
3065 siocnopen(sp, iobase, speed)
3066 struct siocnstate *sp;
3075 * Save all the device control registers except the fifo register
3076 * and set our default ones (cs8 -parenb speed=comdefaultrate).
3077 * We can't save the fifo register since it is read-only.
3079 sp->ier = inb(iobase + com_ier);
3080 outb(iobase + com_ier, 0); /* spltty() doesn't stop siointr() */
3081 siocntxwait(iobase);
3082 sp->cfcr = inb(iobase + com_cfcr);
3083 outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS);
3084 sp->dlbl = inb(iobase + com_dlbl);
3085 sp->dlbh = inb(iobase + com_dlbh);
3087 * Only set the divisor registers if they would change, since on
3088 * some 16550 incompatibles (Startech), setting them clears the
3089 * data input register. This also reduces the effects of the
3092 divisor = siodivisor(comdefaultrclk, speed);
3093 dlbl = divisor & 0xFF;
3094 if (sp->dlbl != dlbl)
3095 outb(iobase + com_dlbl, dlbl);
3096 dlbh = divisor >> 8;
3097 if (sp->dlbh != dlbh)
3098 outb(iobase + com_dlbh, dlbh);
3099 outb(iobase + com_cfcr, CFCR_8BITS);
3100 sp->mcr = inb(iobase + com_mcr);
3102 * We don't want interrupts, but must be careful not to "disable"
3103 * them by clearing the MCR_IENABLE bit, since that might cause
3104 * an interrupt by floating the IRQ line.
3106 outb(iobase + com_mcr, (sp->mcr & MCR_IENABLE) | MCR_DTR | MCR_RTS);
3110 siocnclose(sp, iobase)
3111 struct siocnstate *sp;
3115 * Restore the device control registers.
3117 siocntxwait(iobase);
3118 outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS);
3119 if (sp->dlbl != inb(iobase + com_dlbl))
3120 outb(iobase + com_dlbl, sp->dlbl);
3121 if (sp->dlbh != inb(iobase + com_dlbh))
3122 outb(iobase + com_dlbh, sp->dlbh);
3123 outb(iobase + com_cfcr, sp->cfcr);
3125 * XXX damp oscillations of MCR_DTR and MCR_RTS by not restoring them.
3127 outb(iobase + com_mcr, sp->mcr | MCR_DTR | MCR_RTS);
3128 outb(iobase + com_ier, sp->ier);
3139 struct siocnstate sp;
3142 * Find our first enabled console, if any. If it is a high-level
3143 * console device, then initialize it and return successfully.
3144 * If it is a low-level console device, then initialize it and
3145 * return unsuccessfully. It must be initialized in both cases
3146 * for early use by console drivers and debuggers. Initializing
3147 * the hardware is not necessary in all cases, since the i/o
3148 * routines initialize it on the fly, but it is necessary if
3149 * input might arrive while the hardware is switched back to an
3150 * uninitialized state. We can't handle multiple console devices
3151 * yet because our low-level routines don't take a device arg.
3152 * We trust the user to set the console flags properly so that we
3153 * don't need to probe.
3155 cp->cn_pri = CN_DEAD;
3157 for (unit = 0; unit < 16; unit++) { /* XXX need to know how many */
3160 if (resource_int_value("sio", unit, "disabled", &disabled) == 0) {
3164 if (resource_int_value("sio", unit, "flags", &flags))
3166 if (COM_CONSOLE(flags) || COM_DEBUGGER(flags)) {
3170 if (resource_int_value("sio", unit, "port", &port))
3174 if (boothowto & RB_SERIAL) {
3176 siocngetspeed(iobase, comdefaultrclk);
3178 comdefaultrate = boot_speed;
3182 * Initialize the divisor latch. We can't rely on
3183 * siocnopen() to do this the first time, since it
3184 * avoids writing to the latch if the latch appears
3185 * to have the correct value. Also, if we didn't
3186 * just read the speed from the hardware, then we
3187 * need to set the speed in hardware so that
3188 * switching it later is null.
3190 cfcr = inb(iobase + com_cfcr);
3191 outb(iobase + com_cfcr, CFCR_DLAB | cfcr);
3192 divisor = siodivisor(comdefaultrclk, comdefaultrate);
3193 outb(iobase + com_dlbl, divisor & 0xff);
3194 outb(iobase + com_dlbh, divisor >> 8);
3195 outb(iobase + com_cfcr, cfcr);
3197 siocnopen(&sp, iobase, comdefaultrate);
3200 if (COM_CONSOLE(flags) && !COM_LLCONSOLE(flags)) {
3201 cp->cn_dev = makedev(CDEV_MAJOR, unit);
3202 cp->cn_pri = COM_FORCECONSOLE(flags)
3203 || boothowto & RB_SERIAL
3204 ? CN_REMOTE : CN_NORMAL;
3205 siocniobase = iobase;
3208 if (COM_DEBUGGER(flags)) {
3209 printf("sio%d: gdb debugging port\n", unit);
3210 siogdbiobase = iobase;
3213 gdbdev = makedev(CDEV_MAJOR, unit);
3214 gdb_getc = siocngetc;
3215 gdb_putc = siocnputc;
3223 * XXX Ugly Compatability.
3224 * If no gdb port has been specified, set it to be the console
3225 * as some configuration files don't specify the gdb port.
3227 if (gdbdev == NODEV && (boothowto & RB_GDB)) {
3228 printf("Warning: no GDB port specified. Defaulting to sio%d.\n",
3230 printf("Set flag 0x80 on desired GDB port in your\n");
3231 printf("configuration file (currently sio only).\n");
3232 siogdbiobase = siocniobase;
3233 siogdbunit = siocnunit;
3234 gdbdev = makedev(CDEV_MAJOR, siocnunit);
3235 gdb_getc = siocngetc;
3236 gdb_putc = siocnputc;
3244 CONS_DRIVER(sio, NULL, NULL, NULL, siocngetc, siocncheckc, siocnputc, NULL);
3247 siocnattach(port, speed)
3254 struct siocnstate sp;
3257 comdefaultrate = speed;
3258 sio_consdev.cn_pri = CN_NORMAL;
3259 sio_consdev.cn_dev = makedev(CDEV_MAJOR, 0);
3264 * Initialize the divisor latch. We can't rely on
3265 * siocnopen() to do this the first time, since it
3266 * avoids writing to the latch if the latch appears
3267 * to have the correct value. Also, if we didn't
3268 * just read the speed from the hardware, then we
3269 * need to set the speed in hardware so that
3270 * switching it later is null.
3272 cfcr = inb(siocniobase + com_cfcr);
3273 outb(siocniobase + com_cfcr, CFCR_DLAB | cfcr);
3274 divisor = siodivisor(comdefaultrclk, comdefaultrate);
3275 outb(siocniobase + com_dlbl, divisor & 0xff);
3276 outb(siocniobase + com_dlbh, divisor >> 8);
3277 outb(siocniobase + com_cfcr, cfcr);
3279 siocnopen(&sp, siocniobase, comdefaultrate);
3282 cn_tab = &sio_consdev;
3287 siogdbattach(port, speed)
3294 struct siocnstate sp;
3296 siogdbiobase = port;
3297 gdbdefaultrate = speed;
3302 * Initialize the divisor latch. We can't rely on
3303 * siocnopen() to do this the first time, since it
3304 * avoids writing to the latch if the latch appears
3305 * to have the correct value. Also, if we didn't
3306 * just read the speed from the hardware, then we
3307 * need to set the speed in hardware so that
3308 * switching it later is null.
3310 cfcr = inb(siogdbiobase + com_cfcr);
3311 outb(siogdbiobase + com_cfcr, CFCR_DLAB | cfcr);
3312 divisor = siodivisor(comdefaultrclk, gdbdefaultrate);
3313 outb(siogdbiobase + com_dlbl, divisor & 0xff);
3314 outb(siogdbiobase + com_dlbh, divisor >> 8);
3315 outb(siogdbiobase + com_cfcr, cfcr);
3317 siocnopen(&sp, siogdbiobase, gdbdefaultrate);
3329 comconsole = DEV_TO_UNIT(cp->cn_dev);
3339 struct siocnstate sp;
3341 if (minor(dev) == siogdbunit)
3342 iobase = siogdbiobase;
3344 iobase = siocniobase;
3346 siocnopen(&sp, iobase, comdefaultrate);
3347 if (inb(iobase + com_lsr) & LSR_RXRDY)
3348 c = inb(iobase + com_data);
3351 siocnclose(&sp, iobase);
3364 struct siocnstate sp;
3366 if (minor(dev) == siogdbunit)
3367 iobase = siogdbiobase;
3369 iobase = siocniobase;
3371 siocnopen(&sp, iobase, comdefaultrate);
3372 while (!(inb(iobase + com_lsr) & LSR_RXRDY))
3374 c = inb(iobase + com_data);
3375 siocnclose(&sp, iobase);
3386 struct siocnstate sp;
3389 if (minor(dev) == siogdbunit)
3390 iobase = siogdbiobase;
3392 iobase = siocniobase;
3394 siocnopen(&sp, iobase, comdefaultrate);
3395 siocntxwait(iobase);
3396 outb(iobase + com_data, c);
3397 siocnclose(&sp, iobase);
3408 struct siocnstate sp;
3410 iobase = siogdbiobase;
3412 siocnopen(&sp, iobase, gdbdefaultrate);
3413 while (!(inb(iobase + com_lsr) & LSR_RXRDY))
3415 c = inb(iobase + com_data);
3416 siocnclose(&sp, iobase);
3426 struct siocnstate sp;
3429 siocnopen(&sp, siogdbiobase, gdbdefaultrate);
3430 siocntxwait(siogdbiobase);
3431 outb(siogdbiobase + com_data, c);
3432 siocnclose(&sp, siogdbiobase);
3437 DRIVER_MODULE(sio, isa, sio_isa_driver, sio_devclass, 0, 0);
3439 DRIVER_MODULE(sio, pccard, sio_pccard_driver, sio_devclass, 0, 0);
3442 DRIVER_MODULE(sio, pci, sio_pci_driver, sio_devclass, 0, 0);
3445 DRIVER_MODULE(sio, puc, sio_puc_driver, sio_devclass, 0, 0);