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.10 2003/08/27 06:48:14 rob 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 <bus/isa/isareg.h>
82 #include <bus/isa/isavar.h>
84 #include <bus/pci/pcireg.h>
85 #include <bus/pci/pcivar.h>
88 #include <dev/misc/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>
102 #include "../ic_layer/esp.h"
104 #include "../ic_layer/ns16550.h"
106 #define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
108 #define CALLOUT_MASK 0x80
109 #define CONTROL_MASK 0x60
110 #define CONTROL_INIT_STATE 0x20
111 #define CONTROL_LOCK_STATE 0x40
112 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
113 #define MINOR_TO_UNIT(mynor) ((((mynor) & ~0xffffU) >> (8 + 3)) \
115 #define UNIT_TO_MINOR(unit) ((((unit) & ~0x1fU) << (8 + 3)) \
119 /* checks in flags for multiport and which is multiport "master chip"
122 #define COM_ISMULTIPORT(flags) ((flags) & 0x01)
123 #define COM_MPMASTER(flags) (((flags) >> 8) & 0x0ff)
124 #define COM_NOTAST4(flags) ((flags) & 0x04)
125 #endif /* COM_MULTIPORT */
127 #define COM_CONSOLE(flags) ((flags) & 0x10)
128 #define COM_FORCECONSOLE(flags) ((flags) & 0x20)
129 #define COM_LLCONSOLE(flags) ((flags) & 0x40)
130 #define COM_DEBUGGER(flags) ((flags) & 0x80)
131 #define COM_LOSESOUTINTS(flags) ((flags) & 0x08)
132 #define COM_NOFIFO(flags) ((flags) & 0x02)
133 #define COM_ST16650A(flags) ((flags) & 0x20000)
134 #define COM_C_NOPROBE (0x40000)
135 #define COM_NOPROBE(flags) ((flags) & COM_C_NOPROBE)
136 #define COM_C_IIR_TXRDYBUG (0x80000)
137 #define COM_IIR_TXRDYBUG(flags) ((flags) & COM_C_IIR_TXRDYBUG)
138 #define COM_TI16754(flags) ((flags) & 0x200000)
139 #define COM_FIFOSIZE(flags) (((flags) & 0xff000000) >> 24)
141 #define com_scr 7 /* scratch register for 16450-16550 (R/W) */
143 #define sio_getreg(com, off) \
144 (bus_space_read_1((com)->bst, (com)->bsh, (off)))
145 #define sio_setreg(com, off, value) \
146 (bus_space_write_1((com)->bst, (com)->bsh, (off), (value)))
150 * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher
151 * than the other bits so that they can be tested as a group without masking
154 * The following com and tty flags correspond closely:
155 * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and
157 * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart())
158 * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam())
159 * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam())
160 * TS_FLUSH is not used.
161 * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON.
162 * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state).
164 #define CS_BUSY 0x80 /* output in progress */
165 #define CS_TTGO 0x40 /* output not stopped by XOFF */
166 #define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */
167 #define CS_CHECKMSR 1 /* check of MSR scheduled */
168 #define CS_CTS_OFLOW 2 /* use CTS output flow control */
169 #define CS_DTR_OFF 0x10 /* DTR held off */
170 #define CS_ODONE 4 /* output completed */
171 #define CS_RTS_IFLOW 8 /* use RTS input flow control */
172 #define CSE_BUSYCHECK 1 /* siobusycheck() scheduled */
174 static char const * const error_desc[] = {
177 #define CE_INTERRUPT_BUF_OVERFLOW 1
178 "interrupt-level buffer overflow",
179 #define CE_TTY_BUF_OVERFLOW 2
180 "tty-level buffer overflow",
184 #define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum])
186 /* types. XXX - should be elsewhere */
187 typedef u_int Port_t; /* hardware port */
188 typedef u_char bool_t; /* boolean */
190 /* queue of linear buffers */
192 u_char *l_head; /* next char to process */
193 u_char *l_tail; /* one past the last char to process */
194 struct lbq *l_next; /* next in queue */
195 bool_t l_queued; /* nonzero if queued */
198 /* com device structure */
200 u_int flags; /* Copy isa device flags */
201 u_char state; /* miscellaneous flag bits */
202 bool_t active_out; /* nonzero if the callout device is open */
203 u_char cfcr_image; /* copy of value written to CFCR */
205 bool_t esp; /* is this unit a hayes esp board? */
207 u_char extra_state; /* more flag bits, separate for order trick */
208 u_char fifo_image; /* copy of value written to FIFO */
209 bool_t hasfifo; /* nonzero for 16550 UARTs */
210 bool_t st16650a; /* Is a Startech 16650A or RTS/CTS compat */
211 bool_t loses_outints; /* nonzero if device loses output interrupts */
212 u_char mcr_image; /* copy of value written to MCR */
214 bool_t multiport; /* is this unit part of a multiport device? */
215 #endif /* COM_MULTIPORT */
216 bool_t no_irq; /* nonzero if irq is not attached */
217 bool_t gone; /* hardware disappeared */
218 bool_t poll; /* nonzero if polling is required */
219 bool_t poll_output; /* nonzero if polling for output is required */
220 int unit; /* unit number */
221 int dtr_wait; /* time to hold DTR down on close (* 1/hz) */
223 u_int wopeners; /* # processes waiting for DCD in open() */
226 * The high level of the driver never reads status registers directly
227 * because there would be too many side effects to handle conveniently.
228 * Instead, it reads copies of the registers stored here by the
231 u_char last_modem_status; /* last MSR read by intr handler */
232 u_char prev_modem_status; /* last MSR handled by high level */
234 u_char hotchar; /* ldisc-specific char to be handled ASAP */
235 u_char *ibuf; /* start of input buffer */
236 u_char *ibufend; /* end of input buffer */
237 u_char *ibufold; /* old input buffer, to be freed */
238 u_char *ihighwater; /* threshold in input buffer */
239 u_char *iptr; /* next free spot in input buffer */
240 int ibufsize; /* size of ibuf (not include error bytes) */
241 int ierroff; /* offset of error bytes in ibuf */
243 struct lbq obufq; /* head of queue of output buffers */
244 struct lbq obufs[2]; /* output buffers */
247 bus_space_handle_t bsh;
249 Port_t data_port; /* i/o ports */
254 Port_t modem_ctl_port;
255 Port_t line_status_port;
256 Port_t modem_status_port;
257 Port_t intr_ctl_port; /* Ports of IIR register */
259 struct tty *tp; /* cross reference */
262 struct termios it_in; /* should be in struct tty */
263 struct termios it_out;
266 struct termios lt_in; /* should be in struct tty */
267 struct termios lt_out;
270 bool_t do_dcd_timestamp;
271 struct timeval timestamp;
272 struct timeval dcd_timestamp;
273 struct pps_state pps;
275 u_long bytes_in; /* statistics */
277 u_int delta_error_counts[CE_NTYPES];
278 u_long error_counts[CE_NTYPES];
282 struct resource *irqres;
283 struct resource *ioportres;
287 * Data area for output buffers. Someday we should build the output
288 * buffer queue without copying data.
295 static int espattach (struct com_s *com, Port_t esp_port);
297 static int sioattach (device_t dev, int rid, u_long rclk);
298 static int sio_isa_attach (device_t dev);
300 static timeout_t siobusycheck;
301 static u_int siodivisor (u_long rclk, speed_t speed);
302 static timeout_t siodtrwakeup;
303 static void comhardclose (struct com_s *com);
304 static void sioinput (struct com_s *com);
305 static void siointr1 (struct com_s *com);
306 static void siointr (void *arg);
307 static int commctl (struct com_s *com, int bits, int how);
308 static int comparam (struct tty *tp, struct termios *t);
309 static inthand2_t siopoll;
310 static int sioprobe (device_t dev, int xrid, u_long rclk);
311 static int sio_isa_probe (device_t dev);
312 static void siosettimeout (void);
313 static int siosetwater (struct com_s *com, speed_t speed);
314 static void comstart (struct tty *tp);
315 static void comstop (struct tty *tp, int rw);
316 static timeout_t comwakeup;
317 static void disc_optim (struct tty *tp, struct termios *t,
321 static int sio_pccard_attach (device_t dev);
322 static int sio_pccard_detach (device_t dev);
323 static int sio_pccard_probe (device_t dev);
324 #endif /* NCARD > 0 */
327 static int sio_pci_attach (device_t dev);
328 static void sio_pci_kludge_unit (device_t dev);
329 static int sio_pci_probe (device_t dev);
330 #endif /* NPCI > 0 */
333 static int sio_puc_attach (device_t dev);
334 static int sio_puc_probe (device_t dev);
335 #endif /* NPUC > 0 */
337 static char driver_name[] = "sio";
339 /* table and macro for fast conversion from a unit number to its com struct */
340 static devclass_t sio_devclass;
341 #define com_addr(unit) ((struct com_s *) \
342 devclass_get_softc(sio_devclass, unit))
344 static device_method_t sio_isa_methods[] = {
345 /* Device interface */
346 DEVMETHOD(device_probe, sio_isa_probe),
347 DEVMETHOD(device_attach, sio_isa_attach),
352 static driver_t sio_isa_driver = {
355 sizeof(struct com_s),
359 static device_method_t sio_pccard_methods[] = {
360 /* Device interface */
361 DEVMETHOD(device_probe, sio_pccard_probe),
362 DEVMETHOD(device_attach, sio_pccard_attach),
363 DEVMETHOD(device_detach, sio_pccard_detach),
368 static driver_t sio_pccard_driver = {
371 sizeof(struct com_s),
373 #endif /* NCARD > 0 */
376 static device_method_t sio_pci_methods[] = {
377 /* Device interface */
378 DEVMETHOD(device_probe, sio_pci_probe),
379 DEVMETHOD(device_attach, sio_pci_attach),
384 static driver_t sio_pci_driver = {
387 sizeof(struct com_s),
389 #endif /* NPCI > 0 */
392 static device_method_t sio_puc_methods[] = {
393 /* Device interface */
394 DEVMETHOD(device_probe, sio_puc_probe),
395 DEVMETHOD(device_attach, sio_puc_attach),
400 static driver_t sio_puc_driver = {
403 sizeof(struct com_s),
405 #endif /* NPUC > 0 */
407 static d_open_t sioopen;
408 static d_close_t sioclose;
409 static d_read_t sioread;
410 static d_write_t siowrite;
411 static d_ioctl_t sioioctl;
413 #define CDEV_MAJOR 28
414 static struct cdevsw sio_cdevsw = {
415 /* name */ driver_name,
416 /* maj */ CDEV_MAJOR,
417 /* flags */ D_TTY | D_KQFILTER,
422 /* close */ sioclose,
424 /* write */ siowrite,
425 /* ioctl */ sioioctl,
428 /* strategy */ nostrategy,
431 /* kqfilter */ ttykqfilter
435 static volatile speed_t comdefaultrate = CONSPEED;
436 static u_long comdefaultrclk = DEFAULT_RCLK;
437 SYSCTL_ULONG(_machdep, OID_AUTO, conrclk, CTLFLAG_RW, &comdefaultrclk, 0, "");
439 static volatile speed_t gdbdefaultrate = CONSPEED;
441 static u_int com_events; /* input chars + weighted output completions */
442 static Port_t siocniobase;
443 static int siocnunit;
444 static Port_t siogdbiobase;
445 static int siogdbunit = -1;
446 static bool_t sio_registered;
447 static int sio_timeout;
448 static int sio_timeouts_until_log;
449 static struct callout_handle sio_timeout_handle
450 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
451 static int sio_numunits;
454 /* XXX configure this properly. */
455 static Port_t likely_com_ports[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, };
456 static Port_t likely_esp_ports[] = { 0x140, 0x180, 0x280, 0 };
460 * handle sysctl read/write requests for console speed
462 * In addition to setting comdefaultrate for I/O through /dev/console,
463 * also set the initial and lock values for the /dev/ttyXX device
464 * if there is one associated with the console. Finally, if the /dev/tty
465 * device has already been open, change the speed on the open running port
470 sysctl_machdep_comdefaultrate(SYSCTL_HANDLER_ARGS)
477 newspeed = comdefaultrate;
479 error = sysctl_handle_opaque(oidp, &newspeed, sizeof newspeed, req);
480 if (error || !req->newptr)
483 comdefaultrate = newspeed;
485 if (comconsole < 0) /* serial console not selected? */
488 com = com_addr(comconsole);
493 * set the initial and lock rates for /dev/ttydXX and /dev/cuaXX
494 * (note, the lock rates really are boolean -- if non-zero, disallow
497 com->it_in.c_ispeed = com->it_in.c_ospeed =
498 com->lt_in.c_ispeed = com->lt_in.c_ospeed =
499 com->it_out.c_ispeed = com->it_out.c_ospeed =
500 com->lt_out.c_ispeed = com->lt_out.c_ospeed = comdefaultrate;
503 * if we're open, change the running rate too
506 if (tp && (tp->t_state & TS_ISOPEN)) {
507 tp->t_termios.c_ispeed =
508 tp->t_termios.c_ospeed = comdefaultrate;
510 error = comparam(tp, &tp->t_termios);
516 SYSCTL_PROC(_machdep, OID_AUTO, conspeed, CTLTYPE_INT | CTLFLAG_RW,
517 0, 0, sysctl_machdep_comdefaultrate, "I", "");
519 #define SET_FLAG(dev, bit) device_set_flags(dev, device_get_flags(dev) | (bit))
520 #define CLR_FLAG(dev, bit) device_set_flags(dev, device_get_flags(dev) & ~(bit))
524 sio_pccard_probe(dev)
527 /* Do not probe IRQ - pccard doesn't turn on the interrupt line */
528 /* until bus_setup_intr */
529 SET_FLAG(dev, COM_C_NOPROBE);
531 return (sioprobe(dev, 0, 0UL));
535 sio_pccard_attach(dev)
538 return (sioattach(dev, 0, 0UL));
542 * sio_detach - unload the driver and clear the table.
544 * This is usually called when the card is ejected, but
545 * can be caused by a modunload of a controller driver.
546 * The idea is to reset the driver's view of the device
547 * and ensure that any driver entry points such as
548 * read and write do not hang.
551 sio_pccard_detach(dev)
556 com = (struct com_s *) device_get_softc(dev);
558 device_printf(dev, "NULL com in siounload\n");
563 bus_teardown_intr(dev, com->irqres, com->cookie);
564 bus_release_resource(dev, SYS_RES_IRQ, 0, com->irqres);
567 bus_release_resource(dev, SYS_RES_IOPORT, 0, com->ioportres);
568 if (com->tp && (com->tp->t_state & TS_ISOPEN)) {
569 device_printf(dev, "still open, forcing close\n");
575 if (com->ibuf != NULL)
576 free(com->ibuf, M_DEVBUF);
578 device_printf(dev, "unloaded\n");
581 #endif /* NCARD > 0 */
590 static struct pci_ids pci_ids[] = {
591 { 0x100812b9, "3COM PCI FaxModem", 0x10 },
592 { 0x2000131f, "CyberSerial (1-port) 16550", 0x10 },
593 { 0x01101407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 },
594 { 0x01111407, "Koutech IOFLEX-2S PCI Dual Port Serial", 0x10 },
595 { 0x048011c1, "Lucent kermit based PCI Modem", 0x14 },
596 { 0x95211415, "Oxford Semiconductor PCI Dual Port Serial", 0x10 },
597 { 0x7101135e, "SeaLevel Ultra 530.PCI Single Port Serial", 0x18 },
598 { 0x0000151f, "SmartLink 5634PCV SurfRider", 0x10 },
599 { 0x98459710, "Netmos Nm9845 PCI Bridge with Dual UART", 0x10 },
600 { 0x00000000, NULL, 0 }
610 type = pci_get_devid(dev);
612 while (id->type && id->type != type)
614 if (id->desc == NULL)
616 sio_pci_kludge_unit(dev);
617 return (sioattach(dev, id->rid, 0UL));
621 * Don't cut and paste this to other drivers. It is a horrible kludge
622 * which will fail to work and also be unnecessary in future versions.
625 sio_pci_kludge_unit(dev)
635 while (resource_int_value("sio", unit, "port", &start) == 0 &&
638 if (device_get_unit(dev) < unit) {
639 dc = device_get_devclass(dev);
640 while (devclass_get_device(dc, unit))
642 device_printf(dev, "moving to sio%d\n", unit);
643 err = device_set_unit(dev, unit); /* EVIL DO NOT COPY */
645 device_printf(dev, "error moving device %d\n", err);
656 type = pci_get_devid(dev);
658 while (id->type && id->type != type)
660 if (id->desc == NULL)
662 device_set_desc(dev, id->desc);
663 return (sioprobe(dev, id->rid, 0UL));
665 #endif /* NPCI > 0 */
674 if (BUS_READ_IVAR(device_get_parent(dev), dev, PUC_IVAR_FREQ,
677 return (sioattach(dev, 0, rclk));
686 if (BUS_READ_IVAR(device_get_parent(dev), dev, PUC_IVAR_FREQ,
689 return (sioprobe(dev, 0, rclk));
693 static struct isa_pnp_id sio_ids[] = {
694 {0x0005d041, "Standard PC COM port"}, /* PNP0500 */
695 {0x0105d041, "16550A-compatible COM port"}, /* PNP0501 */
696 {0x0205d041, "Multiport serial device (non-intelligent 16550)"}, /* PNP0502 */
697 {0x1005d041, "Generic IRDA-compatible device"}, /* PNP0510 */
698 {0x1105d041, "Generic IRDA-compatible device"}, /* PNP0511 */
699 /* Devices that do not have a compatid */
700 {0x12206804, NULL}, /* ACH2012 - 5634BTS 56K Video Ready Modem */
701 {0x7602a904, NULL}, /* AEI0276 - 56K v.90 Fax Modem (LKT) */
702 {0x00007905, NULL}, /* AKY0000 - 56K Plug&Play Modem */
703 {0x21107905, NULL}, /* AKY1021 - 56K Plug&Play Modem */
704 {0x01405407, NULL}, /* AZT4001 - AZT3000 PnP SOUND DEVICE, MODEM */
705 {0x56039008, NULL}, /* BDP0356 - Best Data 56x2 */
706 {0x56159008, NULL}, /* BDP1556 - B.D. Smart One 56SPS,Voice Modem*/
707 {0x36339008, NULL}, /* BDP3336 - Best Data Prods. 336F */
708 {0x0014490a, NULL}, /* BRI1400 - Boca 33.6 PnP */
709 {0x0015490a, NULL}, /* BRI1500 - Internal Fax Data */
710 {0x0034490a, NULL}, /* BRI3400 - Internal ACF Modem */
711 {0x0094490a, NULL}, /* BRI9400 - Boca K56Flex PnP */
712 {0x00b4490a, NULL}, /* BRIB400 - Boca 56k PnP */
713 {0x0030320d, NULL}, /* CIR3000 - Cirrus Logic V43 */
714 {0x0100440e, NULL}, /* CRD0001 - Cardinal MVP288IV ? */
715 {0x01308c0e, NULL}, /* CTL3001 - Creative Labs Phoneblaster */
716 {0x36033610, NULL}, /* DAV0336 - DAVICOM 336PNP MODEM */
717 {0x01009416, NULL}, /* ETT0001 - E-Tech Bullet 33k6 PnP */
718 {0x0000aa1a, NULL}, /* FUJ0000 - FUJITSU Modem 33600 PNP/I2 */
719 {0x1200c31e, NULL}, /* GVC0012 - VF1128HV-R9 (win modem?) */
720 {0x0303c31e, NULL}, /* GVC0303 - MaxTech 33.6 PnP D/F/V */
721 {0x0505c31e, NULL}, /* GVC0505 - GVC 56k Faxmodem */
722 {0x0116c31e, NULL}, /* GVC1601 - Rockwell V.34 Plug & Play Modem */
723 {0x0050c31e, NULL}, /* GVC5000 - some GVC modem */
724 {0x3800f91e, NULL}, /* GWY0038 - Telepath with v.90 */
725 {0x9062f91e, NULL}, /* GWY6290 - Telepath with x2 Technology */
726 {0x8100e425, NULL}, /* IOD0081 - I-O DATA DEVICE,INC. IFML-560 */
727 {0x21002534, NULL}, /* MAE0021 - Jetstream Int V.90 56k Voice Series 2*/
728 {0x0000f435, NULL}, /* MOT0000 - Motorola ModemSURFR 33.6 Intern */
729 {0x5015f435, NULL}, /* MOT1550 - Motorola ModemSURFR 56K Modem */
730 {0xf015f435, NULL}, /* MOT15F0 - Motorola VoiceSURFR 56K Modem */
731 {0x6045f435, NULL}, /* MOT4560 - Motorola ? */
732 {0x61e7a338, NULL}, /* NECE761 - 33.6Modem */
733 {0x08804f3f, NULL}, /* OZO8008 - Zoom (33.6k Modem) */
734 {0x0f804f3f, NULL}, /* OZO800f - Zoom 2812 (56k Modem) */
735 {0x39804f3f, NULL}, /* OZO8039 - Zoom 56k flex */
736 {0x00914f3f, NULL}, /* OZO9100 - Zoom 2919 (K56 Faxmodem) */
737 {0x3024a341, NULL}, /* PMC2430 - Pace 56 Voice Internal Modem */
738 {0x1000eb49, NULL}, /* ROK0010 - Rockwell ? */
739 {0x1200b23d, NULL}, /* RSS0012 - OMRON ME5614ISA */
740 {0x5002734a, NULL}, /* RSS0250 - 5614Jx3(G) Internal Modem */
741 {0x6202734a, NULL}, /* RSS0262 - 5614Jx3[G] V90+K56Flex Modem */
742 {0x1010104d, NULL}, /* SHP1010 - Rockwell 33600bps Modem */
743 {0xc100ad4d, NULL}, /* SMM00C1 - Leopard 56k PnP */
744 {0x9012b04e, NULL}, /* SUP1290 - Supra ? */
745 {0x1013b04e, NULL}, /* SUP1310 - SupraExpress 336i PnP */
746 {0x8013b04e, NULL}, /* SUP1380 - SupraExpress 288i PnP Voice */
747 {0x8113b04e, NULL}, /* SUP1381 - SupraExpress 336i PnP Voice */
748 {0x5016b04e, NULL}, /* SUP1650 - Supra 336i Sp Intl */
749 {0x7016b04e, NULL}, /* SUP1670 - Supra 336i V+ Intl */
750 {0x7420b04e, NULL}, /* SUP2070 - Supra ? */
751 {0x8020b04e, NULL}, /* SUP2080 - Supra ? */
752 {0x8420b04e, NULL}, /* SUP2084 - SupraExpress 56i PnP */
753 {0x7121b04e, NULL}, /* SUP2171 - SupraExpress 56i Sp? */
754 {0x8024b04e, NULL}, /* SUP2480 - Supra ? */
755 {0x01007256, NULL}, /* USR0001 - U.S. Robotics Inc., Sportster W */
756 {0x02007256, NULL}, /* USR0002 - U.S. Robotics Inc. Sportster 33. */
757 {0x04007256, NULL}, /* USR0004 - USR Sportster 14.4k */
758 {0x06007256, NULL}, /* USR0006 - USR Sportster 33.6k */
759 {0x11007256, NULL}, /* USR0011 - USR ? */
760 {0x01017256, NULL}, /* USR0101 - USR ? */
761 {0x30207256, NULL}, /* USR2030 - U.S.Robotics Inc. Sportster 560 */
762 {0x50207256, NULL}, /* USR2050 - U.S.Robotics Inc. Sportster 33. */
763 {0x70207256, NULL}, /* USR2070 - U.S.Robotics Inc. Sportster 560 */
764 {0x30307256, NULL}, /* USR3030 - U.S. Robotics 56K FAX INT */
765 {0x31307256, NULL}, /* USR3031 - U.S. Robotics 56K FAX INT */
766 {0x50307256, NULL}, /* USR3050 - U.S. Robotics 56K FAX INT */
767 {0x70307256, NULL}, /* USR3070 - U.S. Robotics 56K Voice INT */
768 {0x90307256, NULL}, /* USR3090 - USR ? */
769 {0x70917256, NULL}, /* USR9170 - U.S. Robotics 56K FAX INT */
770 {0x90917256, NULL}, /* USR9190 - USR 56k Voice INT */
771 {0x0300695c, NULL}, /* WCI0003 - Fax/Voice/Modem/Speakphone/Asvd */
772 {0x01a0896a, NULL}, /* ZTIA001 - Zoom Internal V90 Faxmodem */
773 {0x61f7896a, NULL}, /* ZTIF761 - Zoom ComStar 33.6 */
783 /* Check isapnp ids */
784 if (ISA_PNP_PROBE(device_get_parent(dev), dev, sio_ids) == ENXIO)
786 return (sioprobe(dev, 0, 0UL));
790 sioprobe(dev, xrid, rclk)
796 static bool_t already_init;
805 intrmask_t irqmap[4];
810 u_int flags = device_get_flags(dev);
812 struct resource *port;
815 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
816 0, ~0, IO_COMSIZE, RF_ACTIVE);
820 com = device_get_softc(dev);
821 com->bst = rman_get_bustag(port);
822 com->bsh = rman_get_bushandle(port);
829 * XXX this is broken - when we are first called, there are no
830 * previously configured IO ports. We could hard code
831 * 0x3f8, 0x2f8, 0x3e8, 0x2e8 etc but that's probably worse.
832 * This code has been doing nothing since the conversion since
833 * "count" is zero the first time around.
837 * Turn off MCR_IENABLE for all likely serial ports. An unused
838 * port with its MCR_IENABLE gate open will inhibit interrupts
839 * from any used port that shares the interrupt vector.
840 * XXX the gate enable is elsewhere for some multiports.
843 int count, i, xioport;
845 devclass_get_devices(sio_devclass, &devs, &count);
846 for (i = 0; i < count; i++) {
848 if (device_is_enabled(xdev) &&
849 bus_get_resource(xdev, SYS_RES_IOPORT, 0, &xioport,
851 outb(xioport + com_mcr, 0);
858 if (COM_LLCONSOLE(flags)) {
859 printf("sio%d: reserved for low-level i/o\n",
860 device_get_unit(dev));
861 bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
866 * If the device is on a multiport card and has an AST/4
867 * compatible interrupt control register, initialize this
868 * register and prepare to leave MCR_IENABLE clear in the mcr.
869 * Otherwise, prepare to set MCR_IENABLE in the mcr.
870 * Point idev to the device struct giving the correct id_irq.
871 * This is the struct for the master device if there is one.
874 mcr_image = MCR_IENABLE;
876 if (COM_ISMULTIPORT(flags)) {
880 idev = devclass_get_device(sio_devclass, COM_MPMASTER(flags));
882 printf("sio%d: master device %d not configured\n",
883 device_get_unit(dev), COM_MPMASTER(flags));
886 if (!COM_NOTAST4(flags)) {
887 if (bus_get_resource(idev, SYS_RES_IOPORT, 0, &io,
890 if (bus_get_resource(idev, SYS_RES_IRQ, 0,
892 outb(xiobase + com_scr, 0x80);
894 outb(xiobase + com_scr, 0);
899 #endif /* COM_MULTIPORT */
900 if (bus_get_resource(idev, SYS_RES_IRQ, 0, NULL, NULL) != 0)
903 bzero(failures, sizeof failures);
904 iobase = rman_get_start(port);
907 * We don't want to get actual interrupts, just masked ones.
908 * Interrupts from this line should already be masked in the ICU,
909 * but mask them in the processor as well in case there are some
910 * (misconfigured) shared interrupts.
916 * For the TI16754 chips, set prescaler to 1 (4 is often the
917 * default after-reset value) as otherwise it's impossible to
918 * get highest baudrates.
920 if (COM_TI16754(flags)) {
923 cfcr = sio_getreg(com, com_cfcr);
924 sio_setreg(com, com_cfcr, CFCR_EFR_ENABLE);
925 efr = sio_getreg(com, com_efr);
926 /* Unlock extended features to turn off prescaler. */
927 sio_setreg(com, com_efr, efr | EFR_EFE);
929 sio_setreg(com, com_cfcr, (cfcr != CFCR_EFR_ENABLE) ? cfcr : 0);
930 /* Turn off prescaler. */
931 sio_setreg(com, com_mcr,
932 sio_getreg(com, com_mcr) & ~MCR_PRESCALE);
933 sio_setreg(com, com_cfcr, CFCR_EFR_ENABLE);
934 sio_setreg(com, com_efr, efr);
935 sio_setreg(com, com_cfcr, cfcr);
939 * Initialize the speed and the word size and wait long enough to
940 * drain the maximum of 16 bytes of junk in device output queues.
941 * The speed is undefined after a master reset and must be set
942 * before relying on anything related to output. There may be
943 * junk after a (very fast) soft reboot and (apparently) after
945 * XXX what about the UART bug avoided by waiting in comparam()?
946 * We don't want to to wait long enough to drain at 2 bps.
948 if (iobase == siocniobase)
949 DELAY((16 + 1) * 1000000 / (comdefaultrate / 10));
951 sio_setreg(com, com_cfcr, CFCR_DLAB | CFCR_8BITS);
952 divisor = siodivisor(rclk, SIO_TEST_SPEED);
953 sio_setreg(com, com_dlbl, divisor & 0xff);
954 sio_setreg(com, com_dlbh, divisor >> 8);
955 sio_setreg(com, com_cfcr, CFCR_8BITS);
956 DELAY((16 + 1) * 1000000 / (SIO_TEST_SPEED / 10));
960 * Enable the interrupt gate and disable device interupts. This
961 * should leave the device driving the interrupt line low and
962 * guarantee an edge trigger if an interrupt can be generated.
965 sio_setreg(com, com_mcr, mcr_image);
966 sio_setreg(com, com_ier, 0);
967 DELAY(1000); /* XXX */
968 irqmap[0] = isa_irq_pending();
971 * Attempt to set loopback mode so that we can send a null byte
972 * without annoying any external device.
975 sio_setreg(com, com_mcr, mcr_image | MCR_LOOPBACK);
978 * Attempt to generate an output interrupt. On 8250's, setting
979 * IER_ETXRDY generates an interrupt independent of the current
980 * setting and independent of whether the THR is empty. On 16450's,
981 * setting IER_ETXRDY generates an interrupt independent of the
982 * current setting. On 16550A's, setting IER_ETXRDY only
983 * generates an interrupt when IER_ETXRDY is not already set.
985 sio_setreg(com, com_ier, IER_ETXRDY);
988 * On some 16x50 incompatibles, setting IER_ETXRDY doesn't generate
989 * an interrupt. They'd better generate one for actually doing
990 * output. Loopback may be broken on the same incompatibles but
991 * it's unlikely to do more than allow the null byte out.
993 sio_setreg(com, com_data, 0);
994 DELAY((1 + 2) * 1000000 / (SIO_TEST_SPEED / 10));
997 * Turn off loopback mode so that the interrupt gate works again
998 * (MCR_IENABLE was hidden). This should leave the device driving
999 * an interrupt line high. It doesn't matter if the interrupt
1000 * line oscillates while we are not looking at it, since interrupts
1004 sio_setreg(com, com_mcr, mcr_image);
1007 * Some pcmcia cards have the "TXRDY bug", so we check everyone
1008 * for IIR_TXRDY implementation ( Palido 321s, DC-1S... )
1010 if (COM_NOPROBE(flags)) {
1011 /* Reading IIR register twice */
1012 for (fn = 0; fn < 2; fn ++) {
1014 failures[6] = sio_getreg(com, com_iir);
1016 /* Check IIR_TXRDY clear ? */
1018 if (failures[6] & IIR_TXRDY) {
1019 /* Nop, Double check with clearing IER */
1020 sio_setreg(com, com_ier, 0);
1021 if (sio_getreg(com, com_iir) & IIR_NOPEND) {
1022 /* Ok. we're familia this gang */
1023 SET_FLAG(dev, COM_C_IIR_TXRDYBUG);
1025 /* Unknown, Just omit this chip.. XXX */
1027 sio_setreg(com, com_mcr, 0);
1030 /* OK. this is well-known guys */
1031 CLR_FLAG(dev, COM_C_IIR_TXRDYBUG);
1033 sio_setreg(com, com_ier, 0);
1034 sio_setreg(com, com_cfcr, CFCR_8BITS);
1036 bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
1037 return (iobase == siocniobase ? 0 : result);
1042 * o the CFCR, IER and MCR in UART hold the values written to them
1043 * (the values happen to be all distinct - this is good for
1044 * avoiding false positive tests from bus echoes).
1045 * o an output interrupt is generated and its vector is correct.
1046 * o the interrupt goes away when the IIR in the UART is read.
1049 failures[0] = sio_getreg(com, com_cfcr) - CFCR_8BITS;
1050 failures[1] = sio_getreg(com, com_ier) - IER_ETXRDY;
1051 failures[2] = sio_getreg(com, com_mcr) - mcr_image;
1052 DELAY(10000); /* Some internal modems need this time */
1053 irqmap[1] = isa_irq_pending();
1054 failures[4] = (sio_getreg(com, com_iir) & IIR_IMASK) - IIR_TXRDY;
1055 DELAY(1000); /* XXX */
1056 irqmap[2] = isa_irq_pending();
1057 failures[6] = (sio_getreg(com, com_iir) & IIR_IMASK) - IIR_NOPEND;
1060 * Turn off all device interrupts and check that they go off properly.
1061 * Leave MCR_IENABLE alone. For ports without a master port, it gates
1062 * the OUT2 output of the UART to
1063 * the ICU input. Closing the gate would give a floating ICU input
1064 * (unless there is another device driving it) and spurious interrupts.
1065 * (On the system that this was first tested on, the input floats high
1066 * and gives a (masked) interrupt as soon as the gate is closed.)
1068 sio_setreg(com, com_ier, 0);
1069 sio_setreg(com, com_cfcr, CFCR_8BITS); /* dummy to avoid bus echo */
1070 failures[7] = sio_getreg(com, com_ier);
1071 DELAY(1000); /* XXX */
1072 irqmap[3] = isa_irq_pending();
1073 failures[9] = (sio_getreg(com, com_iir) & IIR_IMASK) - IIR_NOPEND;
1077 irqs = irqmap[1] & ~irqmap[0];
1078 if (bus_get_resource(idev, SYS_RES_IRQ, 0, &xirq, NULL) == 0 &&
1079 ((1 << xirq) & irqs) == 0)
1081 "sio%d: configured irq %ld not in bitmap of probed irqs %#x\n",
1082 device_get_unit(dev), xirq, irqs);
1084 printf("sio%d: irq maps: %#x %#x %#x %#x\n",
1085 device_get_unit(dev),
1086 irqmap[0], irqmap[1], irqmap[2], irqmap[3]);
1089 for (fn = 0; fn < sizeof failures; ++fn)
1091 sio_setreg(com, com_mcr, 0);
1094 printf("sio%d: probe failed test(s):",
1095 device_get_unit(dev));
1096 for (fn = 0; fn < sizeof failures; ++fn)
1103 bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
1104 return (iobase == siocniobase ? 0 : result);
1109 espattach(com, esp_port)
1117 * Check the ESP-specific I/O port to see if we're an ESP
1118 * card. If not, return failure immediately.
1120 if ((inb(esp_port) & 0xf3) == 0) {
1121 printf(" port 0x%x is not an ESP board?\n", esp_port);
1126 * We've got something that claims to be a Hayes ESP card.
1130 /* Get the dip-switch configuration */
1131 outb(esp_port + ESP_CMD1, ESP_GETDIPS);
1132 dips = inb(esp_port + ESP_STATUS1);
1135 * Bits 0,1 of dips say which COM port we are.
1137 if (rman_get_start(com->ioportres) == likely_com_ports[dips & 0x03])
1140 printf(" esp_port has com %d\n", dips & 0x03);
1145 * Check for ESP version 2.0 or later: bits 4,5,6 = 010.
1147 outb(esp_port + ESP_CMD1, ESP_GETTEST);
1148 val = inb(esp_port + ESP_STATUS1); /* clear reg 1 */
1149 val = inb(esp_port + ESP_STATUS2);
1150 if ((val & 0x70) < 0x20) {
1151 printf("-old (%o)", val & 0x70);
1156 * Check for ability to emulate 16550: bit 7 == 1
1158 if ((dips & 0x80) == 0) {
1164 * Okay, we seem to be a Hayes ESP card. Whee.
1167 com->esp_port = esp_port;
1170 #endif /* COM_ESP */
1176 return (sioattach(dev, 0, 0UL));
1180 sioattach(dev, xrid, rclk)
1194 struct resource *port;
1198 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
1199 0, ~0, IO_COMSIZE, RF_ACTIVE);
1203 iobase = rman_get_start(port);
1204 unit = device_get_unit(dev);
1205 com = device_get_softc(dev);
1206 flags = device_get_flags(dev);
1208 if (unit >= sio_numunits)
1209 sio_numunits = unit + 1;
1211 * sioprobe() has initialized the device registers as follows:
1212 * o cfcr = CFCR_8BITS.
1213 * It is most important that CFCR_DLAB is off, so that the
1214 * data port is not hidden when we enable interrupts.
1216 * Interrupts are only enabled when the line is open.
1217 * o mcr = MCR_IENABLE, or 0 if the port has AST/4 compatible
1218 * interrupt control register or the config specifies no irq.
1219 * Keeping MCR_DTR and MCR_RTS off might stop the external
1220 * device from sending before we are ready.
1222 bzero(com, sizeof *com);
1224 com->ioportres = port;
1225 com->bst = rman_get_bustag(port);
1226 com->bsh = rman_get_bushandle(port);
1227 com->cfcr_image = CFCR_8BITS;
1228 com->dtr_wait = 3 * hz;
1229 com->loses_outints = COM_LOSESOUTINTS(flags) != 0;
1230 com->no_irq = bus_get_resource(dev, SYS_RES_IRQ, 0, NULL, NULL) != 0;
1231 com->tx_fifo_size = 1;
1232 com->obufs[0].l_head = com->obuf1;
1233 com->obufs[1].l_head = com->obuf2;
1235 com->data_port = iobase + com_data;
1236 com->int_id_port = iobase + com_iir;
1237 com->modem_ctl_port = iobase + com_mcr;
1238 com->mcr_image = inb(com->modem_ctl_port);
1239 com->line_status_port = iobase + com_lsr;
1240 com->modem_status_port = iobase + com_msr;
1241 com->intr_ctl_port = iobase + com_ier;
1244 rclk = DEFAULT_RCLK;
1248 * We don't use all the flags from <sys/ttydefaults.h> since they
1249 * are only relevant for logins. It's important to have echo off
1250 * initially so that the line doesn't start blathering before the
1251 * echo flag can be turned off.
1253 com->it_in.c_iflag = 0;
1254 com->it_in.c_oflag = 0;
1255 com->it_in.c_cflag = TTYDEF_CFLAG;
1256 com->it_in.c_lflag = 0;
1257 if (unit == comconsole) {
1258 com->it_in.c_iflag = TTYDEF_IFLAG;
1259 com->it_in.c_oflag = TTYDEF_OFLAG;
1260 com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
1261 com->it_in.c_lflag = TTYDEF_LFLAG;
1262 com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL;
1263 com->lt_out.c_ispeed = com->lt_out.c_ospeed =
1264 com->lt_in.c_ispeed = com->lt_in.c_ospeed =
1265 com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate;
1267 com->it_in.c_ispeed = com->it_in.c_ospeed = TTYDEF_SPEED;
1268 if (siosetwater(com, com->it_in.c_ispeed) != 0) {
1271 * Leave i/o resources allocated if this is a `cn'-level
1272 * console, so that other devices can't snarf them.
1274 if (iobase != siocniobase)
1275 bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
1279 termioschars(&com->it_in);
1280 com->it_out = com->it_in;
1282 /* attempt to determine UART type */
1283 printf("sio%d: type", unit);
1286 #ifdef COM_MULTIPORT
1287 if (!COM_ISMULTIPORT(flags) && !COM_IIR_TXRDYBUG(flags))
1289 if (!COM_IIR_TXRDYBUG(flags))
1296 scr = sio_getreg(com, com_scr);
1297 sio_setreg(com, com_scr, 0xa5);
1298 scr1 = sio_getreg(com, com_scr);
1299 sio_setreg(com, com_scr, 0x5a);
1300 scr2 = sio_getreg(com, com_scr);
1301 sio_setreg(com, com_scr, scr);
1302 if (scr1 != 0xa5 || scr2 != 0x5a) {
1304 goto determined_type;
1307 sio_setreg(com, com_fifo, FIFO_ENABLE | FIFO_RX_HIGH);
1310 switch (inb(com->int_id_port) & IIR_FIFO_MASK) {
1321 if (COM_NOFIFO(flags)) {
1322 printf(" 16550A fifo disabled");
1324 com->hasfifo = TRUE;
1325 if (COM_ST16650A(flags)) {
1327 com->tx_fifo_size = 32;
1328 printf(" ST16650A");
1329 } else if (COM_TI16754(flags)) {
1330 com->tx_fifo_size = 64;
1333 com->tx_fifo_size = COM_FIFOSIZE(flags);
1338 for (espp = likely_esp_ports; *espp != 0; espp++)
1339 if (espattach(com, *espp)) {
1340 com->tx_fifo_size = 1024;
1344 if (!com->st16650a && !COM_TI16754(flags)) {
1345 if (!com->tx_fifo_size)
1346 com->tx_fifo_size = 16;
1348 printf(" lookalike with %d bytes FIFO",
1358 * Set 16550 compatibility mode.
1359 * We don't use the ESP_MODE_SCALE bit to increase the
1360 * fifo trigger levels because we can't handle large
1362 * XXX flow control should be set in comparam(), not here.
1364 outb(com->esp_port + ESP_CMD1, ESP_SETMODE);
1365 outb(com->esp_port + ESP_CMD2, ESP_MODE_RTS | ESP_MODE_FIFO);
1367 /* Set RTS/CTS flow control. */
1368 outb(com->esp_port + ESP_CMD1, ESP_SETFLOWTYPE);
1369 outb(com->esp_port + ESP_CMD2, ESP_FLOW_RTS);
1370 outb(com->esp_port + ESP_CMD2, ESP_FLOW_CTS);
1372 /* Set flow-control levels. */
1373 outb(com->esp_port + ESP_CMD1, ESP_SETRXFLOW);
1374 outb(com->esp_port + ESP_CMD2, HIBYTE(768));
1375 outb(com->esp_port + ESP_CMD2, LOBYTE(768));
1376 outb(com->esp_port + ESP_CMD2, HIBYTE(512));
1377 outb(com->esp_port + ESP_CMD2, LOBYTE(512));
1379 #endif /* COM_ESP */
1380 sio_setreg(com, com_fifo, 0);
1383 #ifdef COM_MULTIPORT
1384 if (COM_ISMULTIPORT(flags)) {
1387 com->multiport = TRUE;
1388 printf(" (multiport");
1389 if (unit == COM_MPMASTER(flags))
1392 masterdev = devclass_get_device(sio_devclass,
1393 COM_MPMASTER(flags));
1394 com->no_irq = (masterdev == NULL || bus_get_resource(masterdev,
1395 SYS_RES_IRQ, 0, NULL, NULL) != 0);
1397 #endif /* COM_MULTIPORT */
1398 if (unit == comconsole)
1399 printf(", console");
1400 if (COM_IIR_TXRDYBUG(flags))
1401 printf(" with a bogus IIR_TXRDY register");
1404 if (!sio_registered) {
1405 register_swi(SWI_TTY, siopoll, NULL ,"swi_siopoll");
1406 sio_registered = TRUE;
1408 minorbase = UNIT_TO_MINOR(unit);
1409 make_dev(&sio_cdevsw, minorbase,
1410 UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit);
1411 make_dev(&sio_cdevsw, minorbase | CONTROL_INIT_STATE,
1412 UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit);
1413 make_dev(&sio_cdevsw, minorbase | CONTROL_LOCK_STATE,
1414 UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit);
1415 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
1416 UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit);
1417 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
1418 UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit);
1419 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
1420 UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
1422 com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
1423 pps_init(&com->pps);
1426 com->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0ul, ~0ul, 1,
1429 ret = BUS_SETUP_INTR(device_get_parent(dev), dev, com->irqres,
1430 INTR_TYPE_TTY | INTR_TYPE_FAST,
1431 siointr, com, &com->cookie);
1433 ret = BUS_SETUP_INTR(device_get_parent(dev), dev,
1434 com->irqres, INTR_TYPE_TTY,
1435 siointr, com, &com->cookie);
1437 device_printf(dev, "unable to activate interrupt in fast mode - using normal mode\n");
1440 device_printf(dev, "could not activate interrupt\n");
1441 #if defined(DDB) && (defined(BREAK_TO_DEBUGGER) || \
1442 defined(ALT_BREAK_TO_DEBUGGER))
1444 * Enable interrupts for early break-to-debugger support
1447 if (ret == 0 && unit == comconsole)
1448 outb(siocniobase + com_ier, IER_ERXRDY | IER_ERLS |
1457 sioopen(dev_t dev, int flag, int mode, struct thread *td)
1467 unit = MINOR_TO_UNIT(mynor);
1468 com = com_addr(unit);
1473 if (mynor & CONTROL_MASK)
1475 tp = dev->si_tty = com->tp = ttymalloc(com->tp);
1478 * We jump to this label after all non-interrupted sleeps to pick
1479 * up any changes of the device state.
1482 while (com->state & CS_DTR_OFF) {
1483 error = tsleep(&com->dtr_wait, PCATCH, "siodtr", 0);
1484 if (com_addr(unit) == NULL)
1486 if (error != 0 || com->gone)
1489 if (tp->t_state & TS_ISOPEN) {
1491 * The device is open, so everything has been initialized.
1494 if (mynor & CALLOUT_MASK) {
1495 if (!com->active_out) {
1500 if (com->active_out) {
1501 if (flag & O_NONBLOCK) {
1505 error = tsleep(&com->active_out,
1506 PCATCH, "siobi", 0);
1507 if (com_addr(unit) == NULL)
1509 if (error != 0 || com->gone)
1514 if (tp->t_state & TS_XCLUDE && suser(td)) {
1520 * The device isn't open, so there are no conflicts.
1521 * Initialize it. Initialization is done twice in many
1522 * cases: to preempt sleeping callin opens if we are
1523 * callout, and to complete a callin open after DCD rises.
1525 tp->t_oproc = comstart;
1526 tp->t_param = comparam;
1527 tp->t_stop = comstop;
1529 tp->t_termios = mynor & CALLOUT_MASK
1530 ? com->it_out : com->it_in;
1531 (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET);
1532 com->poll = com->no_irq;
1533 com->poll_output = com->loses_outints;
1535 error = comparam(tp, &tp->t_termios);
1540 * XXX we should goto open_top if comparam() slept.
1544 * (Re)enable and drain fifos.
1546 * Certain SMC chips cause problems if the fifos
1547 * are enabled while input is ready. Turn off the
1548 * fifo if necessary to clear the input. We test
1549 * the input ready bit after enabling the fifos
1550 * since we've already enabled them in comparam()
1551 * and to handle races between enabling and fresh
1555 sio_setreg(com, com_fifo,
1556 FIFO_RCV_RST | FIFO_XMT_RST
1559 * XXX the delays are for superstitious
1560 * historical reasons. It must be less than
1561 * the character time at the maximum
1562 * supported speed (87 usec at 115200 bps
1563 * 8N1). Otherwise we might loop endlessly
1564 * if data is streaming in. We used to use
1565 * delays of 100. That usually worked
1566 * because DELAY(100) used to usually delay
1567 * for about 85 usec instead of 100.
1570 if (!(inb(com->line_status_port) & LSR_RXRDY))
1572 sio_setreg(com, com_fifo, 0);
1574 (void) inb(com->data_port);
1579 (void) inb(com->line_status_port);
1580 (void) inb(com->data_port);
1581 com->prev_modem_status = com->last_modem_status
1582 = inb(com->modem_status_port);
1583 if (COM_IIR_TXRDYBUG(com->flags)) {
1584 outb(com->intr_ctl_port, IER_ERXRDY | IER_ERLS
1587 outb(com->intr_ctl_port, IER_ERXRDY | IER_ETXRDY
1588 | IER_ERLS | IER_EMSC);
1592 * Handle initial DCD. Callout devices get a fake initial
1593 * DCD (trapdoor DCD). If we are callout, then any sleeping
1594 * callin opens get woken up and resume sleeping on "siobi"
1595 * instead of "siodcd".
1598 * XXX `mynor & CALLOUT_MASK' should be
1599 * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
1600 * TRAPDOOR_CARRIER is the default initial state for callout
1601 * devices and SOFT_CARRIER is like CLOCAL except it hides
1604 if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
1605 (*linesw[tp->t_line].l_modem)(tp, 1);
1608 * Wait for DCD if necessary.
1610 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
1611 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
1613 error = tsleep(TSA_CARR_ON(tp), PCATCH, "siodcd", 0);
1614 if (com_addr(unit) == NULL)
1617 if (error != 0 || com->gone)
1621 error = (*linesw[tp->t_line].l_open)(dev, tp);
1622 disc_optim(tp, &tp->t_termios, com);
1623 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
1624 com->active_out = TRUE;
1628 if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
1634 sioclose(dev_t dev, int flag, int mode, struct thread *td)
1642 if (mynor & CONTROL_MASK)
1644 com = com_addr(MINOR_TO_UNIT(mynor));
1649 (*linesw[tp->t_line].l_close)(tp, flag);
1650 disc_optim(tp, &tp->t_termios, com);
1651 comstop(tp, FREAD | FWRITE);
1657 printf("sio%d: gone\n", com->unit);
1659 if (com->ibuf != NULL)
1660 free(com->ibuf, M_DEVBUF);
1661 bzero(tp, sizeof *tp);
1678 com->poll_output = FALSE;
1679 com->do_timestamp = FALSE;
1680 com->do_dcd_timestamp = FALSE;
1681 com->pps.ppsparam.mode = 0;
1682 sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
1685 #if defined(DDB) && (defined(BREAK_TO_DEBUGGER) || \
1686 defined(ALT_BREAK_TO_DEBUGGER))
1688 * Leave interrupts enabled and don't clear DTR if this is the
1689 * console. This allows us to detect break-to-debugger events
1690 * while the console device is closed.
1692 if (com->unit != comconsole)
1695 sio_setreg(com, com_ier, 0);
1696 if (tp->t_cflag & HUPCL
1698 * XXX we will miss any carrier drop between here and the
1699 * next open. Perhaps we should watch DCD even when the
1700 * port is closed; it is not sufficient to check it at
1701 * the next open because it might go up and down while
1702 * we're not watching.
1704 || (!com->active_out
1705 && !(com->prev_modem_status & MSR_DCD)
1706 && !(com->it_in.c_cflag & CLOCAL))
1707 || !(tp->t_state & TS_ISOPEN)) {
1708 (void)commctl(com, TIOCM_DTR, DMBIC);
1709 if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {
1710 timeout(siodtrwakeup, com, com->dtr_wait);
1711 com->state |= CS_DTR_OFF;
1717 * Disable fifos so that they are off after controlled
1718 * reboots. Some BIOSes fail to detect 16550s when the
1719 * fifos are enabled.
1721 sio_setreg(com, com_fifo, 0);
1723 com->active_out = FALSE;
1724 wakeup(&com->active_out);
1725 wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
1730 sioread(dev, uio, flag)
1739 if (mynor & CONTROL_MASK)
1741 com = com_addr(MINOR_TO_UNIT(mynor));
1742 if (com == NULL || com->gone)
1744 return ((*linesw[com->tp->t_line].l_read)(com->tp, uio, flag));
1748 siowrite(dev, uio, flag)
1758 if (mynor & CONTROL_MASK)
1761 unit = MINOR_TO_UNIT(mynor);
1762 com = com_addr(unit);
1763 if (com == NULL || com->gone)
1766 * (XXX) We disallow virtual consoles if the physical console is
1767 * a serial port. This is in case there is a display attached that
1768 * is not the console. In that situation we don't need/want the X
1769 * server taking over the console.
1771 if (constty != NULL && unit == comconsole)
1773 return ((*linesw[com->tp->t_line].l_write)(com->tp, uio, flag));
1783 com = (struct com_s *)chan;
1786 * Clear TS_BUSY if low-level output is complete.
1787 * spl locking is sufficient because siointr1() does not set CS_BUSY.
1788 * If siointr1() clears CS_BUSY after we look at it, then we'll get
1789 * called again. Reading the line status port outside of siointr1()
1790 * is safe because CS_BUSY is clear so there are no output interrupts
1794 if (com->state & CS_BUSY)
1795 com->extra_state &= ~CSE_BUSYCHECK; /* False alarm. */
1796 else if ((inb(com->line_status_port) & (LSR_TSRE | LSR_TXRDY))
1797 == (LSR_TSRE | LSR_TXRDY)) {
1798 com->tp->t_state &= ~TS_BUSY;
1800 com->extra_state &= ~CSE_BUSYCHECK;
1802 timeout(siobusycheck, com, hz / 100);
1807 siodivisor(rclk, speed)
1815 if (speed == 0 || speed > (ULONG_MAX - 1) / 8)
1817 divisor = (rclk / (8UL * speed) + 1) / 2;
1818 if (divisor == 0 || divisor >= 65536)
1820 actual_speed = rclk / (16UL * divisor);
1822 /* 10 times error in percent: */
1823 error = ((actual_speed - (long)speed) * 2000 / (long)speed + 1) / 2;
1825 /* 3.0% maximum error tolerance: */
1826 if (error < -30 || error > 30)
1838 com = (struct com_s *)chan;
1839 com->state &= ~CS_DTR_OFF;
1840 wakeup(&com->dtr_wait);
1855 if (!(tp->t_state & TS_ISOPEN) || !(tp->t_cflag & CREAD)) {
1856 com_events -= (com->iptr - com->ibuf);
1857 com->iptr = com->ibuf;
1860 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1862 * Avoid the grotesquely inefficient lineswitch routine
1863 * (ttyinput) in "raw" mode. It usually takes about 450
1864 * instructions (that's without canonical processing or echo!).
1865 * slinput is reasonably fast (usually 40 instructions plus
1870 incc = com->iptr - buf;
1871 if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
1872 && (com->state & CS_RTS_IFLOW
1873 || tp->t_iflag & IXOFF)
1874 && !(tp->t_state & TS_TBLOCK))
1876 com->delta_error_counts[CE_TTY_BUF_OVERFLOW]
1877 += b_to_q((char *)buf, incc, &tp->t_rawq);
1881 tp->t_rawcc += incc;
1883 if (tp->t_state & TS_TTSTOP
1884 && (tp->t_iflag & IXANY
1885 || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1886 tp->t_state &= ~TS_TTSTOP;
1887 tp->t_lflag &= ~FLUSHO;
1891 } while (buf < com->iptr);
1895 line_status = buf[com->ierroff];
1898 & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) {
1899 if (line_status & LSR_BI)
1900 recv_data |= TTY_BI;
1901 if (line_status & LSR_FE)
1902 recv_data |= TTY_FE;
1903 if (line_status & LSR_OE)
1904 recv_data |= TTY_OE;
1905 if (line_status & LSR_PE)
1906 recv_data |= TTY_PE;
1908 (*linesw[tp->t_line].l_rint)(recv_data, tp);
1910 } while (buf < com->iptr);
1912 com_events -= (com->iptr - com->ibuf);
1913 com->iptr = com->ibuf;
1916 * There is now room for another low-level buffer full of input,
1917 * so enable RTS if it is now disabled and there is room in the
1918 * high-level buffer.
1920 if ((com->state & CS_RTS_IFLOW) && !(com->mcr_image & MCR_RTS) &&
1921 !(tp->t_state & TS_TBLOCK))
1922 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
1929 #ifndef COM_MULTIPORT
1931 siointr1((struct com_s *) arg);
1933 #else /* COM_MULTIPORT */
1934 bool_t possibly_more_intrs;
1939 * Loop until there is no activity on any port. This is necessary
1940 * to get an interrupt edge more than to avoid another interrupt.
1941 * If the IRQ signal is just an OR of the IRQ signals from several
1942 * devices, then the edge from one may be lost because another is
1947 possibly_more_intrs = FALSE;
1948 for (unit = 0; unit < sio_numunits; ++unit) {
1949 com = com_addr(unit);
1952 * would it work here, or be counter-productive?
1956 && (inb(com->int_id_port) & IIR_IMASK)
1959 possibly_more_intrs = TRUE;
1961 /* XXX com_unlock(); */
1963 } while (possibly_more_intrs);
1965 #endif /* COM_MULTIPORT */
1973 u_char modem_status;
1978 struct timecounter *tc;
1981 int_ctl = inb(com->intr_ctl_port);
1982 int_ctl_new = int_ctl;
1984 while (!com->gone) {
1985 if (com->pps.ppsparam.mode & PPS_CAPTUREBOTH) {
1986 modem_status = inb(com->modem_status_port);
1987 if ((modem_status ^ com->last_modem_status) & MSR_DCD) {
1989 count = tc->tc_get_timecount(tc);
1990 pps_event(&com->pps, tc, count,
1991 (modem_status & MSR_DCD) ?
1992 PPS_CAPTUREASSERT : PPS_CAPTURECLEAR);
1995 line_status = inb(com->line_status_port);
1997 /* input event? (check first to help avoid overruns) */
1998 while (line_status & LSR_RCV_MASK) {
1999 /* break/unnattached error bits or real input? */
2000 if (!(line_status & LSR_RXRDY))
2003 recv_data = inb(com->data_port);
2004 #if defined(DDB) && defined(ALT_BREAK_TO_DEBUGGER)
2006 * Solaris implements a new BREAK which is initiated
2007 * by a character sequence CR ~ ^b which is similar
2008 * to a familiar pattern used on Sun servers by the
2011 #define KEY_CRTLB 2 /* ^B */
2012 #define KEY_CR 13 /* CR '\r' */
2013 #define KEY_TILDE 126 /* ~ */
2015 if (com->unit == comconsole) {
2016 static int brk_state1 = 0, brk_state2 = 0;
2017 if (recv_data == KEY_CR) {
2018 brk_state1 = recv_data;
2020 } else if (brk_state1 == KEY_CR && (recv_data == KEY_TILDE || recv_data == KEY_CRTLB)) {
2021 if (recv_data == KEY_TILDE)
2022 brk_state2 = recv_data;
2023 else if (brk_state2 == KEY_TILDE && recv_data == KEY_CRTLB) {
2025 brk_state1 = brk_state2 = 0;
2033 if (line_status & (LSR_BI | LSR_FE | LSR_PE)) {
2035 * Don't store BI if IGNBRK or FE/PE if IGNPAR.
2036 * Otherwise, push the work to a higher level
2037 * (to handle PARMRK) if we're bypassing.
2038 * Otherwise, convert BI/FE and PE+INPCK to 0.
2040 * This makes bypassing work right in the
2041 * usual "raw" case (IGNBRK set, and IGNPAR
2044 * Note: BI together with FE/PE means just BI.
2046 if (line_status & LSR_BI) {
2047 #if defined(DDB) && defined(BREAK_TO_DEBUGGER)
2048 if (com->unit == comconsole) {
2054 || com->tp->t_iflag & IGNBRK)
2058 || com->tp->t_iflag & IGNPAR)
2061 if (com->tp->t_state & TS_CAN_BYPASS_L_RINT
2062 && (line_status & (LSR_BI | LSR_FE)
2063 || com->tp->t_iflag & INPCK))
2067 if (com->hotchar != 0 && recv_data == com->hotchar)
2070 if (ioptr >= com->ibufend)
2071 CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
2073 if (com->do_timestamp)
2074 microtime(&com->timestamp);
2077 #if 0 /* for testing input latency vs efficiency */
2078 if (com->iptr - com->ibuf == 8)
2081 ioptr[0] = recv_data;
2082 ioptr[com->ierroff] = line_status;
2083 com->iptr = ++ioptr;
2084 if (ioptr == com->ihighwater
2085 && com->state & CS_RTS_IFLOW)
2086 outb(com->modem_ctl_port,
2087 com->mcr_image &= ~MCR_RTS);
2088 if (line_status & LSR_OE)
2089 CE_RECORD(com, CE_OVERRUN);
2093 * "& 0x7F" is to avoid the gcc-1.40 generating a slow
2094 * jump from the top of the loop to here
2096 line_status = inb(com->line_status_port) & 0x7F;
2099 /* modem status change? (always check before doing output) */
2100 modem_status = inb(com->modem_status_port);
2101 if (modem_status != com->last_modem_status) {
2102 if (com->do_dcd_timestamp
2103 && !(com->last_modem_status & MSR_DCD)
2104 && modem_status & MSR_DCD)
2105 microtime(&com->dcd_timestamp);
2108 * Schedule high level to handle DCD changes. Note
2109 * that we don't use the delta bits anywhere. Some
2110 * UARTs mess them up, and it's easy to remember the
2111 * previous bits and calculate the delta.
2113 com->last_modem_status = modem_status;
2114 if (!(com->state & CS_CHECKMSR)) {
2115 com_events += LOTS_OF_EVENTS;
2116 com->state |= CS_CHECKMSR;
2120 /* handle CTS change immediately for crisp flow ctl */
2121 if (com->state & CS_CTS_OFLOW) {
2122 if (modem_status & MSR_CTS)
2123 com->state |= CS_ODEVREADY;
2125 com->state &= ~CS_ODEVREADY;
2129 /* output queued and everything ready? */
2130 if (line_status & LSR_TXRDY
2131 && com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
2132 ioptr = com->obufq.l_head;
2133 if (com->tx_fifo_size > 1) {
2136 ocount = com->obufq.l_tail - ioptr;
2137 if (ocount > com->tx_fifo_size)
2138 ocount = com->tx_fifo_size;
2139 com->bytes_out += ocount;
2141 outb(com->data_port, *ioptr++);
2142 while (--ocount != 0);
2144 outb(com->data_port, *ioptr++);
2147 com->obufq.l_head = ioptr;
2148 if (COM_IIR_TXRDYBUG(com->flags)) {
2149 int_ctl_new = int_ctl | IER_ETXRDY;
2151 if (ioptr >= com->obufq.l_tail) {
2154 qp = com->obufq.l_next;
2155 qp->l_queued = FALSE;
2158 com->obufq.l_head = qp->l_head;
2159 com->obufq.l_tail = qp->l_tail;
2160 com->obufq.l_next = qp;
2162 /* output just completed */
2163 if (COM_IIR_TXRDYBUG(com->flags)) {
2164 int_ctl_new = int_ctl & ~IER_ETXRDY;
2166 com->state &= ~CS_BUSY;
2168 if (!(com->state & CS_ODONE)) {
2169 com_events += LOTS_OF_EVENTS;
2170 com->state |= CS_ODONE;
2171 setsofttty(); /* handle at high level ASAP */
2174 if (COM_IIR_TXRDYBUG(com->flags) && (int_ctl != int_ctl_new)) {
2175 outb(com->intr_ctl_port, int_ctl_new);
2180 #ifndef COM_MULTIPORT
2181 if ((inb(com->int_id_port) & IIR_IMASK) == IIR_NOPEND)
2182 #endif /* COM_MULTIPORT */
2188 sioioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
2195 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
2197 struct termios term;
2201 com = com_addr(MINOR_TO_UNIT(mynor));
2202 if (com == NULL || com->gone)
2204 if (mynor & CONTROL_MASK) {
2207 switch (mynor & CONTROL_MASK) {
2208 case CONTROL_INIT_STATE:
2209 ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
2211 case CONTROL_LOCK_STATE:
2212 ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
2215 return (ENODEV); /* /dev/nodev */
2222 *ct = *(struct termios *)data;
2225 *(struct termios *)data = *ct;
2228 *(int *)data = TTYDISC;
2231 bzero(data, sizeof(struct winsize));
2238 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
2239 term = tp->t_termios;
2241 error = ttsetcompat(tp, &cmd, data, &term);
2245 data = (caddr_t)&term;
2247 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
2249 struct termios *dt = (struct termios *)data;
2250 struct termios *lt = mynor & CALLOUT_MASK
2251 ? &com->lt_out : &com->lt_in;
2253 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
2254 | (dt->c_iflag & ~lt->c_iflag);
2255 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
2256 | (dt->c_oflag & ~lt->c_oflag);
2257 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
2258 | (dt->c_cflag & ~lt->c_cflag);
2259 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
2260 | (dt->c_lflag & ~lt->c_lflag);
2261 for (cc = 0; cc < NCCS; ++cc)
2262 if (lt->c_cc[cc] != 0)
2263 dt->c_cc[cc] = tp->t_cc[cc];
2264 if (lt->c_ispeed != 0)
2265 dt->c_ispeed = tp->t_ispeed;
2266 if (lt->c_ospeed != 0)
2267 dt->c_ospeed = tp->t_ospeed;
2269 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
2270 if (error != ENOIOCTL)
2273 error = ttioctl(tp, cmd, data, flag);
2274 disc_optim(tp, &tp->t_termios, com);
2275 if (error != ENOIOCTL) {
2281 sio_setreg(com, com_cfcr, com->cfcr_image |= CFCR_SBREAK);
2284 sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
2287 (void)commctl(com, TIOCM_DTR, DMBIS);
2290 (void)commctl(com, TIOCM_DTR, DMBIC);
2293 * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
2294 * changes get undone on the next call to comparam().
2297 (void)commctl(com, *(int *)data, DMSET);
2300 (void)commctl(com, *(int *)data, DMBIS);
2303 (void)commctl(com, *(int *)data, DMBIC);
2306 *(int *)data = commctl(com, 0, DMGET);
2309 /* must be root since the wait applies to following logins */
2315 com->dtr_wait = *(int *)data * hz / 100;
2318 *(int *)data = com->dtr_wait * 100 / hz;
2321 com->do_timestamp = TRUE;
2322 *(struct timeval *)data = com->timestamp;
2324 case TIOCDCDTIMESTAMP:
2325 com->do_dcd_timestamp = TRUE;
2326 *(struct timeval *)data = com->dcd_timestamp;
2330 error = pps_ioctl(cmd, data, &com->pps);
2331 if (error == ENODEV)
2340 siopoll(void *dummy)
2344 if (com_events == 0)
2347 for (unit = 0; unit < sio_numunits; ++unit) {
2352 com = com_addr(unit);
2356 if (tp == NULL || com->gone) {
2358 * Discard any events related to never-opened or
2359 * going-away devices.
2362 incc = com->iptr - com->ibuf;
2363 com->iptr = com->ibuf;
2364 if (com->state & CS_CHECKMSR) {
2365 incc += LOTS_OF_EVENTS;
2366 com->state &= ~CS_CHECKMSR;
2372 if (com->iptr != com->ibuf) {
2377 if (com->state & CS_CHECKMSR) {
2378 u_char delta_modem_status;
2381 delta_modem_status = com->last_modem_status
2382 ^ com->prev_modem_status;
2383 com->prev_modem_status = com->last_modem_status;
2384 com_events -= LOTS_OF_EVENTS;
2385 com->state &= ~CS_CHECKMSR;
2387 if (delta_modem_status & MSR_DCD)
2388 (*linesw[tp->t_line].l_modem)
2389 (tp, com->prev_modem_status & MSR_DCD);
2391 if (com->state & CS_ODONE) {
2393 com_events -= LOTS_OF_EVENTS;
2394 com->state &= ~CS_ODONE;
2396 if (!(com->state & CS_BUSY)
2397 && !(com->extra_state & CSE_BUSYCHECK)) {
2398 timeout(siobusycheck, com, hz / 100);
2399 com->extra_state |= CSE_BUSYCHECK;
2401 (*linesw[tp->t_line].l_start)(tp);
2403 if (com_events == 0)
2406 if (com_events >= LOTS_OF_EVENTS)
2424 unit = DEV_TO_UNIT(tp->t_dev);
2425 com = com_addr(unit);
2429 /* do historical conversions */
2430 if (t->c_ispeed == 0)
2431 t->c_ispeed = t->c_ospeed;
2433 /* check requested parameters */
2434 if (t->c_ospeed == 0)
2437 if (t->c_ispeed != t->c_ospeed)
2439 divisor = siodivisor(com->rclk, t->c_ispeed);
2444 /* parameters are OK, convert them to the com struct and the device */
2447 (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
2449 (void)commctl(com, TIOCM_DTR, DMBIS);
2451 switch (cflag & CSIZE) {
2465 if (cflag & PARENB) {
2467 if (!(cflag & PARODD))
2473 if (com->hasfifo && divisor != 0) {
2475 * Use a fifo trigger level low enough so that the input
2476 * latency from the fifo is less than about 16 msec and
2477 * the total latency is less than about 30 msec. These
2478 * latencies are reasonable for humans. Serial comms
2479 * protocols shouldn't expect anything better since modem
2480 * latencies are larger.
2482 * Interrupts can be held up for long periods of time
2483 * due to inefficiencies in other parts of the kernel,
2484 * certain video cards, etc. Setting the FIFO trigger
2485 * point to MEDH instead of HIGH gives us 694uS of slop
2486 * (8 character times) instead of 173uS (2 character times)
2489 com->fifo_image = t->c_ospeed <= 4800
2490 ? FIFO_ENABLE : FIFO_ENABLE | FIFO_RX_MEDH;
2493 * The Hayes ESP card needs the fifo DMA mode bit set
2494 * in compatibility mode. If not, it will interrupt
2495 * for each character received.
2498 com->fifo_image |= FIFO_DMA_MODE;
2500 sio_setreg(com, com_fifo, com->fifo_image);
2504 * This returns with interrupts disabled so that we can complete
2505 * the speed change atomically. Keeping interrupts disabled is
2506 * especially important while com_data is hidden.
2508 (void) siosetwater(com, t->c_ispeed);
2511 sio_setreg(com, com_cfcr, cfcr | CFCR_DLAB);
2513 * Only set the divisor registers if they would change,
2514 * since on some 16550 incompatibles (UMC8669F), setting
2515 * them while input is arriving them loses sync until
2516 * data stops arriving.
2518 dlbl = divisor & 0xFF;
2519 if (sio_getreg(com, com_dlbl) != dlbl)
2520 sio_setreg(com, com_dlbl, dlbl);
2521 dlbh = divisor >> 8;
2522 if (sio_getreg(com, com_dlbh) != dlbh)
2523 sio_setreg(com, com_dlbh, dlbh);
2526 sio_setreg(com, com_cfcr, com->cfcr_image = cfcr);
2528 if (!(tp->t_state & TS_TTSTOP))
2529 com->state |= CS_TTGO;
2531 if (cflag & CRTS_IFLOW) {
2532 if (com->st16650a) {
2533 sio_setreg(com, com_cfcr, 0xbf);
2534 sio_setreg(com, com_fifo,
2535 sio_getreg(com, com_fifo) | 0x40);
2537 com->state |= CS_RTS_IFLOW;
2539 * If CS_RTS_IFLOW just changed from off to on, the change
2540 * needs to be propagated to MCR_RTS. This isn't urgent,
2541 * so do it later by calling comstart() instead of repeating
2542 * a lot of code from comstart() here.
2544 } else if (com->state & CS_RTS_IFLOW) {
2545 com->state &= ~CS_RTS_IFLOW;
2547 * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS
2548 * on here, since comstart() won't do it later.
2550 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2551 if (com->st16650a) {
2552 sio_setreg(com, com_cfcr, 0xbf);
2553 sio_setreg(com, com_fifo,
2554 sio_getreg(com, com_fifo) & ~0x40);
2560 * Set up state to handle output flow control.
2561 * XXX - worth handling MDMBUF (DCD) flow control at the lowest level?
2562 * Now has 10+ msec latency, while CTS flow has 50- usec latency.
2564 com->state |= CS_ODEVREADY;
2565 com->state &= ~CS_CTS_OFLOW;
2566 if (cflag & CCTS_OFLOW) {
2567 com->state |= CS_CTS_OFLOW;
2568 if (!(com->last_modem_status & MSR_CTS))
2569 com->state &= ~CS_ODEVREADY;
2570 if (com->st16650a) {
2571 sio_setreg(com, com_cfcr, 0xbf);
2572 sio_setreg(com, com_fifo,
2573 sio_getreg(com, com_fifo) | 0x80);
2576 if (com->st16650a) {
2577 sio_setreg(com, com_cfcr, 0xbf);
2578 sio_setreg(com, com_fifo,
2579 sio_getreg(com, com_fifo) & ~0x80);
2583 sio_setreg(com, com_cfcr, com->cfcr_image);
2585 /* XXX shouldn't call functions while intrs are disabled. */
2586 disc_optim(tp, t, com);
2588 * Recover from fiddling with CS_TTGO. We used to call siointr1()
2589 * unconditionally, but that defeated the careful discarding of
2590 * stale input in sioopen().
2592 if (com->state >= (CS_BUSY | CS_TTGO))
2598 if (com->ibufold != NULL) {
2599 free(com->ibufold, M_DEVBUF);
2600 com->ibufold = NULL;
2606 siosetwater(com, speed)
2616 * Make the buffer size large enough to handle a softtty interrupt
2617 * latency of about 2 ticks without loss of throughput or data
2618 * (about 3 ticks if input flow control is not used or not honoured,
2619 * but a bit less for CS5-CS7 modes).
2621 cp4ticks = speed / 10 / hz * 4;
2622 for (ibufsize = 128; ibufsize < cp4ticks;)
2624 if (ibufsize == com->ibufsize) {
2630 * Allocate input buffer. The extra factor of 2 in the size is
2631 * to allow for an error byte for each input byte.
2633 ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
2639 /* Initialize non-critical variables. */
2640 com->ibufold = com->ibuf;
2641 com->ibufsize = ibufsize;
2644 tp->t_ififosize = 2 * ibufsize;
2645 tp->t_ispeedwat = (speed_t)-1;
2646 tp->t_ospeedwat = (speed_t)-1;
2650 * Read current input buffer, if any. Continue with interrupts
2654 if (com->iptr != com->ibuf)
2658 * Initialize critical variables, including input buffer watermarks.
2659 * The external device is asked to stop sending when the buffer
2660 * exactly reaches high water, or when the high level requests it.
2661 * The high level is notified immediately (rather than at a later
2662 * clock tick) when this watermark is reached.
2663 * The buffer size is chosen so the watermark should almost never
2665 * The low watermark is invisibly 0 since the buffer is always
2666 * emptied all at once.
2668 com->iptr = com->ibuf = ibuf;
2669 com->ibufend = ibuf + ibufsize;
2670 com->ierroff = ibufsize;
2671 com->ihighwater = ibuf + 3 * ibufsize / 4;
2683 unit = DEV_TO_UNIT(tp->t_dev);
2684 com = com_addr(unit);
2689 if (tp->t_state & TS_TTSTOP)
2690 com->state &= ~CS_TTGO;
2692 com->state |= CS_TTGO;
2693 if (tp->t_state & TS_TBLOCK) {
2694 if (com->mcr_image & MCR_RTS && com->state & CS_RTS_IFLOW)
2695 outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
2697 if (!(com->mcr_image & MCR_RTS) && com->iptr < com->ihighwater
2698 && com->state & CS_RTS_IFLOW)
2699 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2702 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
2707 if (tp->t_outq.c_cc != 0) {
2711 if (!com->obufs[0].l_queued) {
2712 com->obufs[0].l_tail
2713 = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1,
2715 com->obufs[0].l_next = NULL;
2716 com->obufs[0].l_queued = TRUE;
2718 if (com->state & CS_BUSY) {
2719 qp = com->obufq.l_next;
2720 while ((next = qp->l_next) != NULL)
2722 qp->l_next = &com->obufs[0];
2724 com->obufq.l_head = com->obufs[0].l_head;
2725 com->obufq.l_tail = com->obufs[0].l_tail;
2726 com->obufq.l_next = &com->obufs[0];
2727 com->state |= CS_BUSY;
2731 if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
2732 com->obufs[1].l_tail
2733 = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2,
2735 com->obufs[1].l_next = NULL;
2736 com->obufs[1].l_queued = TRUE;
2738 if (com->state & CS_BUSY) {
2739 qp = com->obufq.l_next;
2740 while ((next = qp->l_next) != NULL)
2742 qp->l_next = &com->obufs[1];
2744 com->obufq.l_head = com->obufs[1].l_head;
2745 com->obufq.l_tail = com->obufs[1].l_tail;
2746 com->obufq.l_next = &com->obufs[1];
2747 com->state |= CS_BUSY;
2751 tp->t_state |= TS_BUSY;
2754 if (com->state >= (CS_BUSY | CS_TTGO))
2755 siointr1(com); /* fake interrupt to start output */
2768 com = com_addr(DEV_TO_UNIT(tp->t_dev));
2769 if (com == NULL || com->gone)
2775 /* XXX avoid h/w bug. */
2778 sio_setreg(com, com_fifo,
2779 FIFO_XMT_RST | com->fifo_image);
2780 com->obufs[0].l_queued = FALSE;
2781 com->obufs[1].l_queued = FALSE;
2782 if (com->state & CS_ODONE)
2783 com_events -= LOTS_OF_EVENTS;
2784 com->state &= ~(CS_ODONE | CS_BUSY);
2785 com->tp->t_state &= ~TS_BUSY;
2790 /* XXX avoid h/w bug. */
2793 sio_setreg(com, com_fifo,
2794 FIFO_RCV_RST | com->fifo_image);
2795 com_events -= (com->iptr - com->ibuf);
2796 com->iptr = com->ibuf;
2803 commctl(com, bits, how)
2812 bits = TIOCM_LE; /* XXX - always enabled while open */
2813 mcr = com->mcr_image;
2818 msr = com->prev_modem_status;
2826 * XXX - MSR_RI is naturally volatile, and we make MSR_TERI
2827 * more volatile by reading the modem status a lot. Perhaps
2828 * we should latch both bits until the status is read here.
2830 if (msr & (MSR_RI | MSR_TERI))
2835 if (bits & TIOCM_DTR)
2837 if (bits & TIOCM_RTS)
2844 outb(com->modem_ctl_port,
2845 com->mcr_image = mcr | (com->mcr_image & MCR_IENABLE));
2848 outb(com->modem_ctl_port, com->mcr_image |= mcr);
2851 outb(com->modem_ctl_port, com->mcr_image &= ~mcr);
2866 * Set our timeout period to 1 second if no polled devices are open.
2867 * Otherwise set it to max(1/200, 1/hz).
2868 * Enable timeouts iff some device is open.
2870 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2873 for (unit = 0; unit < sio_numunits; ++unit) {
2874 com = com_addr(unit);
2875 if (com != NULL && com->tp != NULL
2876 && com->tp->t_state & TS_ISOPEN && !com->gone) {
2878 if (com->poll || com->poll_output) {
2879 sio_timeout = hz > 200 ? hz / 200 : 1;
2885 sio_timeouts_until_log = hz / sio_timeout;
2886 sio_timeout_handle = timeout(comwakeup, (void *)NULL,
2889 /* Flush error messages, if any. */
2890 sio_timeouts_until_log = 1;
2891 comwakeup((void *)NULL);
2892 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2903 sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout);
2906 * Recover from lost output interrupts.
2907 * Poll any lines that don't use interrupts.
2909 for (unit = 0; unit < sio_numunits; ++unit) {
2910 com = com_addr(unit);
2911 if (com != NULL && !com->gone
2912 && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
2920 * Check for and log errors, but not too often.
2922 if (--sio_timeouts_until_log > 0)
2924 sio_timeouts_until_log = hz / sio_timeout;
2925 for (unit = 0; unit < sio_numunits; ++unit) {
2928 com = com_addr(unit);
2933 for (errnum = 0; errnum < CE_NTYPES; ++errnum) {
2938 delta = com->delta_error_counts[errnum];
2939 com->delta_error_counts[errnum] = 0;
2943 total = com->error_counts[errnum] += delta;
2944 log(LOG_ERR, "sio%d: %u more %s%s (total %lu)\n",
2945 unit, delta, error_desc[errnum],
2946 delta == 1 ? "" : "s", total);
2952 disc_optim(tp, t, com)
2957 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2958 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2959 && (!(t->c_iflag & PARMRK)
2960 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2961 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2962 && linesw[tp->t_line].l_rint == ttyinput)
2963 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2965 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2966 com->hotchar = linesw[tp->t_line].l_hotchar;
2970 * Following are all routines needed for SIO to act as console
2972 #include <sys/cons.h>
2982 static speed_t siocngetspeed (Port_t, u_long rclk);
2983 static void siocnclose (struct siocnstate *sp, Port_t iobase);
2984 static void siocnopen (struct siocnstate *sp, Port_t iobase, int speed);
2985 static void siocntxwait (Port_t iobase);
2987 static cn_probe_t siocnprobe;
2988 static cn_init_t siocninit;
2989 static cn_checkc_t siocncheckc;
2990 static cn_getc_t siocngetc;
2991 static cn_putc_t siocnputc;
2994 CONS_DRIVER(sio, siocnprobe, siocninit, NULL, siocngetc, siocncheckc,
2998 /* To get the GDB related variables */
3000 #include <ddb/ddb.h>
3010 * Wait for any pending transmission to finish. Required to avoid
3011 * the UART lockup bug when the speed is changed, and for normal
3015 while ((inb(iobase + com_lsr) & (LSR_TSRE | LSR_TXRDY))
3016 != (LSR_TSRE | LSR_TXRDY) && --timo != 0)
3021 * Read the serial port specified and try to figure out what speed
3022 * it's currently running at. We're assuming the serial port has
3023 * been initialized and is basicly idle. This routine is only intended
3024 * to be run at system startup.
3026 * If the value read from the serial port doesn't make sense, return 0.
3030 siocngetspeed(iobase, rclk)
3039 cfcr = inb(iobase + com_cfcr);
3040 outb(iobase + com_cfcr, CFCR_DLAB | cfcr);
3042 dlbl = inb(iobase + com_dlbl);
3043 dlbh = inb(iobase + com_dlbh);
3045 outb(iobase + com_cfcr, cfcr);
3047 divisor = dlbh << 8 | dlbl;
3049 /* XXX there should be more sanity checking. */
3052 return (rclk / (16UL * divisor));
3056 siocnopen(sp, iobase, speed)
3057 struct siocnstate *sp;
3066 * Save all the device control registers except the fifo register
3067 * and set our default ones (cs8 -parenb speed=comdefaultrate).
3068 * We can't save the fifo register since it is read-only.
3070 sp->ier = inb(iobase + com_ier);
3071 outb(iobase + com_ier, 0); /* spltty() doesn't stop siointr() */
3072 siocntxwait(iobase);
3073 sp->cfcr = inb(iobase + com_cfcr);
3074 outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS);
3075 sp->dlbl = inb(iobase + com_dlbl);
3076 sp->dlbh = inb(iobase + com_dlbh);
3078 * Only set the divisor registers if they would change, since on
3079 * some 16550 incompatibles (Startech), setting them clears the
3080 * data input register. This also reduces the effects of the
3083 divisor = siodivisor(comdefaultrclk, speed);
3084 dlbl = divisor & 0xFF;
3085 if (sp->dlbl != dlbl)
3086 outb(iobase + com_dlbl, dlbl);
3087 dlbh = divisor >> 8;
3088 if (sp->dlbh != dlbh)
3089 outb(iobase + com_dlbh, dlbh);
3090 outb(iobase + com_cfcr, CFCR_8BITS);
3091 sp->mcr = inb(iobase + com_mcr);
3093 * We don't want interrupts, but must be careful not to "disable"
3094 * them by clearing the MCR_IENABLE bit, since that might cause
3095 * an interrupt by floating the IRQ line.
3097 outb(iobase + com_mcr, (sp->mcr & MCR_IENABLE) | MCR_DTR | MCR_RTS);
3101 siocnclose(sp, iobase)
3102 struct siocnstate *sp;
3106 * Restore the device control registers.
3108 siocntxwait(iobase);
3109 outb(iobase + com_cfcr, CFCR_DLAB | CFCR_8BITS);
3110 if (sp->dlbl != inb(iobase + com_dlbl))
3111 outb(iobase + com_dlbl, sp->dlbl);
3112 if (sp->dlbh != inb(iobase + com_dlbh))
3113 outb(iobase + com_dlbh, sp->dlbh);
3114 outb(iobase + com_cfcr, sp->cfcr);
3116 * XXX damp oscillations of MCR_DTR and MCR_RTS by not restoring them.
3118 outb(iobase + com_mcr, sp->mcr | MCR_DTR | MCR_RTS);
3119 outb(iobase + com_ier, sp->ier);
3130 struct siocnstate sp;
3133 * Find our first enabled console, if any. If it is a high-level
3134 * console device, then initialize it and return successfully.
3135 * If it is a low-level console device, then initialize it and
3136 * return unsuccessfully. It must be initialized in both cases
3137 * for early use by console drivers and debuggers. Initializing
3138 * the hardware is not necessary in all cases, since the i/o
3139 * routines initialize it on the fly, but it is necessary if
3140 * input might arrive while the hardware is switched back to an
3141 * uninitialized state. We can't handle multiple console devices
3142 * yet because our low-level routines don't take a device arg.
3143 * We trust the user to set the console flags properly so that we
3144 * don't need to probe.
3146 cp->cn_pri = CN_DEAD;
3148 for (unit = 0; unit < 16; unit++) { /* XXX need to know how many */
3151 if (resource_int_value("sio", unit, "disabled", &disabled) == 0) {
3155 if (resource_int_value("sio", unit, "flags", &flags))
3157 if (COM_CONSOLE(flags) || COM_DEBUGGER(flags)) {
3161 if (resource_int_value("sio", unit, "port", &port))
3165 if (boothowto & RB_SERIAL) {
3167 siocngetspeed(iobase, comdefaultrclk);
3169 comdefaultrate = boot_speed;
3173 * Initialize the divisor latch. We can't rely on
3174 * siocnopen() to do this the first time, since it
3175 * avoids writing to the latch if the latch appears
3176 * to have the correct value. Also, if we didn't
3177 * just read the speed from the hardware, then we
3178 * need to set the speed in hardware so that
3179 * switching it later is null.
3181 cfcr = inb(iobase + com_cfcr);
3182 outb(iobase + com_cfcr, CFCR_DLAB | cfcr);
3183 divisor = siodivisor(comdefaultrclk, comdefaultrate);
3184 outb(iobase + com_dlbl, divisor & 0xff);
3185 outb(iobase + com_dlbh, divisor >> 8);
3186 outb(iobase + com_cfcr, cfcr);
3188 siocnopen(&sp, iobase, comdefaultrate);
3191 if (COM_CONSOLE(flags) && !COM_LLCONSOLE(flags)) {
3192 cp->cn_dev = makedev(CDEV_MAJOR, unit);
3193 cp->cn_pri = COM_FORCECONSOLE(flags)
3194 || boothowto & RB_SERIAL
3195 ? CN_REMOTE : CN_NORMAL;
3196 siocniobase = iobase;
3199 if (COM_DEBUGGER(flags)) {
3200 printf("sio%d: gdb debugging port\n", unit);
3201 siogdbiobase = iobase;
3204 gdbdev = makedev(CDEV_MAJOR, unit);
3205 gdb_getc = siocngetc;
3206 gdb_putc = siocnputc;
3214 * XXX Ugly Compatability.
3215 * If no gdb port has been specified, set it to be the console
3216 * as some configuration files don't specify the gdb port.
3218 if (gdbdev == NODEV && (boothowto & RB_GDB)) {
3219 printf("Warning: no GDB port specified. Defaulting to sio%d.\n",
3221 printf("Set flag 0x80 on desired GDB port in your\n");
3222 printf("configuration file (currently sio only).\n");
3223 siogdbiobase = siocniobase;
3224 siogdbunit = siocnunit;
3225 gdbdev = makedev(CDEV_MAJOR, siocnunit);
3226 gdb_getc = siocngetc;
3227 gdb_putc = siocnputc;
3235 CONS_DRIVER(sio, NULL, NULL, NULL, siocngetc, siocncheckc, siocnputc, NULL);
3238 siocnattach(port, speed)
3245 struct siocnstate sp;
3248 comdefaultrate = speed;
3249 sio_consdev.cn_pri = CN_NORMAL;
3250 sio_consdev.cn_dev = makedev(CDEV_MAJOR, 0);
3255 * Initialize the divisor latch. We can't rely on
3256 * siocnopen() to do this the first time, since it
3257 * avoids writing to the latch if the latch appears
3258 * to have the correct value. Also, if we didn't
3259 * just read the speed from the hardware, then we
3260 * need to set the speed in hardware so that
3261 * switching it later is null.
3263 cfcr = inb(siocniobase + com_cfcr);
3264 outb(siocniobase + com_cfcr, CFCR_DLAB | cfcr);
3265 divisor = siodivisor(comdefaultrclk, comdefaultrate);
3266 outb(siocniobase + com_dlbl, divisor & 0xff);
3267 outb(siocniobase + com_dlbh, divisor >> 8);
3268 outb(siocniobase + com_cfcr, cfcr);
3270 siocnopen(&sp, siocniobase, comdefaultrate);
3273 cn_tab = &sio_consdev;
3278 siogdbattach(port, speed)
3285 struct siocnstate sp;
3287 siogdbiobase = port;
3288 gdbdefaultrate = speed;
3293 * Initialize the divisor latch. We can't rely on
3294 * siocnopen() to do this the first time, since it
3295 * avoids writing to the latch if the latch appears
3296 * to have the correct value. Also, if we didn't
3297 * just read the speed from the hardware, then we
3298 * need to set the speed in hardware so that
3299 * switching it later is null.
3301 cfcr = inb(siogdbiobase + com_cfcr);
3302 outb(siogdbiobase + com_cfcr, CFCR_DLAB | cfcr);
3303 divisor = siodivisor(comdefaultrclk, gdbdefaultrate);
3304 outb(siogdbiobase + com_dlbl, divisor & 0xff);
3305 outb(siogdbiobase + com_dlbh, divisor >> 8);
3306 outb(siogdbiobase + com_cfcr, cfcr);
3308 siocnopen(&sp, siogdbiobase, gdbdefaultrate);
3320 comconsole = DEV_TO_UNIT(cp->cn_dev);
3330 struct siocnstate sp;
3332 if (minor(dev) == siogdbunit)
3333 iobase = siogdbiobase;
3335 iobase = siocniobase;
3337 siocnopen(&sp, iobase, comdefaultrate);
3338 if (inb(iobase + com_lsr) & LSR_RXRDY)
3339 c = inb(iobase + com_data);
3342 siocnclose(&sp, iobase);
3355 struct siocnstate sp;
3357 if (minor(dev) == siogdbunit)
3358 iobase = siogdbiobase;
3360 iobase = siocniobase;
3362 siocnopen(&sp, iobase, comdefaultrate);
3363 while (!(inb(iobase + com_lsr) & LSR_RXRDY))
3365 c = inb(iobase + com_data);
3366 siocnclose(&sp, iobase);
3377 struct siocnstate sp;
3380 if (minor(dev) == siogdbunit)
3381 iobase = siogdbiobase;
3383 iobase = siocniobase;
3385 siocnopen(&sp, iobase, comdefaultrate);
3386 siocntxwait(iobase);
3387 outb(iobase + com_data, c);
3388 siocnclose(&sp, iobase);
3399 struct siocnstate sp;
3401 iobase = siogdbiobase;
3403 siocnopen(&sp, iobase, gdbdefaultrate);
3404 while (!(inb(iobase + com_lsr) & LSR_RXRDY))
3406 c = inb(iobase + com_data);
3407 siocnclose(&sp, iobase);
3417 struct siocnstate sp;
3420 siocnopen(&sp, siogdbiobase, gdbdefaultrate);
3421 siocntxwait(siogdbiobase);
3422 outb(siogdbiobase + com_data, c);
3423 siocnclose(&sp, siogdbiobase);
3428 DRIVER_MODULE(sio, isa, sio_isa_driver, sio_devclass, 0, 0);
3430 DRIVER_MODULE(sio, pccard, sio_pccard_driver, sio_devclass, 0, 0);
3433 DRIVER_MODULE(sio, pci, sio_pci_driver, sio_devclass, 0, 0);
3436 DRIVER_MODULE(sio, puc, sio_puc_driver, sio_devclass, 0, 0);