Deleted Added
full compact
sio.c (46635) sio.c (46766)
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

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
31 * SUCH DAMAGE.
32 *
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

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
31 * SUCH DAMAGE.
32 *
33 * $Id: sio.c,v 1.90 1999/05/05 01:53:43 kato Exp $
33 * $Id: sio.c,v 1.91 1999/05/07 10:11:17 phk Exp $
34 * from: @(#)com.c 7.5 (Berkeley) 5/16/91
35 * from: i386/isa sio.c,v 1.234
36 */
37
38#include "opt_comconsole.h"
39#include "opt_compat.h"
40#include "opt_ddb.h"
41#include "opt_devfs.h"

--- 196 unchanged lines hidden (view full) ---

238#define COM_ISMULTIPORT(flags) ((flags) & 0x01)
239#define COM_MPMASTER(flags) (((flags) >> 8) & 0x0ff)
240#define COM_NOTAST4(flags) ((flags) & 0x04)
241#endif /* COM_MULTIPORT */
242
243#define COM_CONSOLE(flags) ((flags) & 0x10)
244#define COM_FORCECONSOLE(flags) ((flags) & 0x20)
245#define COM_LLCONSOLE(flags) ((flags) & 0x40)
34 * from: @(#)com.c 7.5 (Berkeley) 5/16/91
35 * from: i386/isa sio.c,v 1.234
36 */
37
38#include "opt_comconsole.h"
39#include "opt_compat.h"
40#include "opt_ddb.h"
41#include "opt_devfs.h"

--- 196 unchanged lines hidden (view full) ---

238#define COM_ISMULTIPORT(flags) ((flags) & 0x01)
239#define COM_MPMASTER(flags) (((flags) >> 8) & 0x0ff)
240#define COM_NOTAST4(flags) ((flags) & 0x04)
241#endif /* COM_MULTIPORT */
242
243#define COM_CONSOLE(flags) ((flags) & 0x10)
244#define COM_FORCECONSOLE(flags) ((flags) & 0x20)
245#define COM_LLCONSOLE(flags) ((flags) & 0x40)
246#define COM_DEBUGGER(flags) ((flags) & 0x80)
246#define COM_LOSESOUTINTS(flags) ((flags) & 0x08)
247#define COM_NOFIFO(flags) ((flags) & 0x02)
248#define COM_ST16650A(flags) ((flags) & 0x20000)
249#define COM_C_NOPROBE (0x40000)
250#define COM_NOPROBE(flags) ((flags) & COM_C_NOPROBE)
251#define COM_C_IIR_TXRDYBUG (0x80000)
252#define COM_IIR_TXRDYBUG(flags) ((flags) & COM_C_IIR_TXRDYBUG)
253#define COM_FIFOSIZE(flags) (((flags) & 0xff000000) >> 24)

--- 210 unchanged lines hidden (view full) ---

464 DEVMETHOD(device_attach, sioattach),
465
466 { 0, 0 }
467};
468
469static driver_t sio_driver = {
470 driver_name,
471 sio_methods,
247#define COM_LOSESOUTINTS(flags) ((flags) & 0x08)
248#define COM_NOFIFO(flags) ((flags) & 0x02)
249#define COM_ST16650A(flags) ((flags) & 0x20000)
250#define COM_C_NOPROBE (0x40000)
251#define COM_NOPROBE(flags) ((flags) & COM_C_NOPROBE)
252#define COM_C_IIR_TXRDYBUG (0x80000)
253#define COM_IIR_TXRDYBUG(flags) ((flags) & COM_C_IIR_TXRDYBUG)
254#define COM_FIFOSIZE(flags) (((flags) & 0xff000000) >> 24)

--- 210 unchanged lines hidden (view full) ---

465 DEVMETHOD(device_attach, sioattach),
466
467 { 0, 0 }
468};
469
470static driver_t sio_driver = {
471 driver_name,
472 sio_methods,
472 DRIVER_TYPE_TTY|DRIVER_TYPE_FAST,
473 sizeof(struct com_s),
474};
475
476static d_open_t sioopen;
477static d_close_t sioclose;
478static d_read_t sioread;
479static d_write_t siowrite;
480static d_ioctl_t sioioctl;

--- 11 unchanged lines hidden (view full) ---

492
493int comconsole = -1;
494static volatile speed_t comdefaultrate = CONSPEED;
495#ifdef __alpha__
496static volatile speed_t gdbdefaultrate = CONSPEED;
497#endif
498static u_int com_events; /* input chars + weighted output completions */
499static Port_t siocniobase;
473 sizeof(struct com_s),
474};
475
476static d_open_t sioopen;
477static d_close_t sioclose;
478static d_read_t sioread;
479static d_write_t siowrite;
480static d_ioctl_t sioioctl;

--- 11 unchanged lines hidden (view full) ---

492
493int comconsole = -1;
494static volatile speed_t comdefaultrate = CONSPEED;
495#ifdef __alpha__
496static volatile speed_t gdbdefaultrate = CONSPEED;
497#endif
498static u_int com_events; /* input chars + weighted output completions */
499static Port_t siocniobase;
500#ifdef __alpha__
500static int siocnunit;
501static Port_t siogdbiobase;
501static Port_t siogdbiobase;
502#endif
502static int siogdbunit = -1;
503static bool_t sio_registered;
504static int sio_timeout;
505static int sio_timeouts_until_log;
506static struct callout_handle sio_timeout_handle
507 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
508#if 0 /* XXX */
509static struct tty *sio_tty[NSIOTOT];
510#else

--- 1344 unchanged lines hidden (view full) ---

1855 UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
1856#endif
1857 com->flags = isa_get_flags(dev); /* Heritate id_flags for later */
1858 com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
1859 pps_init(&com->pps);
1860
1861 res = bus_alloc_resource(dev, SYS_RES_IRQ, &zero, 0ul, ~0ul, 1,
1862 RF_SHAREABLE | RF_ACTIVE);
503static bool_t sio_registered;
504static int sio_timeout;
505static int sio_timeouts_until_log;
506static struct callout_handle sio_timeout_handle
507 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
508#if 0 /* XXX */
509static struct tty *sio_tty[NSIOTOT];
510#else

--- 1344 unchanged lines hidden (view full) ---

1855 UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
1856#endif
1857 com->flags = isa_get_flags(dev); /* Heritate id_flags for later */
1858 com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
1859 pps_init(&com->pps);
1860
1861 res = bus_alloc_resource(dev, SYS_RES_IRQ, &zero, 0ul, ~0ul, 1,
1862 RF_SHAREABLE | RF_ACTIVE);
1863 BUS_SETUP_INTR(device_get_parent(dev), dev, res, siointr, com,
1864 &ih);
1863 BUS_SETUP_INTR(device_get_parent(dev), dev, res,
1864 INTR_TYPE_TTY | INTR_TYPE_FAST,
1865 siointr, com, &ih);
1865
1866 return (0);
1867}
1868
1869static int
1870sioopen(dev, flag, mode, p)
1871 dev_t dev;
1872 int flag;

--- 335 unchanged lines hidden (view full) ---

2208 if (tp->t_cflag & HUPCL
2209 /*
2210 * XXX we will miss any carrier drop between here and the
2211 * next open. Perhaps we should watch DCD even when the
2212 * port is closed; it is not sufficient to check it at
2213 * the next open because it might go up and down while
2214 * we're not watching.
2215 */
1866
1867 return (0);
1868}
1869
1870static int
1871sioopen(dev, flag, mode, p)
1872 dev_t dev;
1873 int flag;

--- 335 unchanged lines hidden (view full) ---

2209 if (tp->t_cflag & HUPCL
2210 /*
2211 * XXX we will miss any carrier drop between here and the
2212 * next open. Perhaps we should watch DCD even when the
2213 * port is closed; it is not sufficient to check it at
2214 * the next open because it might go up and down while
2215 * we're not watching.
2216 */
2216 || !com->active_out
2217 || (!com->active_out
2217#ifdef PC98
2218 && !(tmp)
2219#else
2218#ifdef PC98
2219 && !(tmp)
2220#else
2220 && !(com->prev_modem_status & MSR_DCD)
2221 && !(com->prev_modem_status & MSR_DCD)
2221#endif
2222#endif
2222 && !(com->it_in.c_cflag & CLOCAL)
2223 && !(com->it_in.c_cflag & CLOCAL))
2223 || !(tp->t_state & TS_ISOPEN)) {
2224#ifdef PC98
2225 if (IS_8251(com->pc98_if_type))
2226 com_tiocm_bic(com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE);
2227 else
2228#endif
2229 (void)commctl(com, TIOCM_DTR, DMBIC);
2230 if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {

--- 1704 unchanged lines hidden (view full) ---

3935static cn_probe_t siocnprobe;
3936static cn_init_t siocninit;
3937static cn_checkc_t siocncheckc;
3938 cn_getc_t siocngetc;
3939 cn_putc_t siocnputc;
3940
3941CONS_DRIVER(sio, siocnprobe, siocninit, siocngetc, siocncheckc, siocnputc);
3942
2224 || !(tp->t_state & TS_ISOPEN)) {
2225#ifdef PC98
2226 if (IS_8251(com->pc98_if_type))
2227 com_tiocm_bic(com, TIOCM_DTR|TIOCM_RTS|TIOCM_LE);
2228 else
2229#endif
2230 (void)commctl(com, TIOCM_DTR, DMBIC);
2231 if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {

--- 1704 unchanged lines hidden (view full) ---

3936static cn_probe_t siocnprobe;
3937static cn_init_t siocninit;
3938static cn_checkc_t siocncheckc;
3939 cn_getc_t siocngetc;
3940 cn_putc_t siocnputc;
3941
3942CONS_DRIVER(sio, siocnprobe, siocninit, siocngetc, siocncheckc, siocnputc);
3943
3944/*
3945 * Routines to support GDB on an sio port.
3946 */
3947dev_t gdbdev;
3948cn_getc_t *gdb_getc;
3949cn_putc_t *gdb_putc;
3950
3943#endif
3944
3945static void
3946siocntxwait(iobase)
3947 Port_t iobase;
3948{
3949 int timo;
3950

--- 138 unchanged lines hidden (view full) ---

4089 * don't need to probe.
4090 */
4091 cp->cn_pri = CN_DEAD;
4092
4093 for (unit = 0; unit < 16; unit++) { /* XXX need to know how many */
4094 int flags;
4095 if (resource_int_value("sio", unit, "flags", &flags))
4096 continue;
3951#endif
3952
3953static void
3954siocntxwait(iobase)
3955 Port_t iobase;
3956{
3957 int timo;
3958

--- 138 unchanged lines hidden (view full) ---

4097 * don't need to probe.
4098 */
4099 cp->cn_pri = CN_DEAD;
4100
4101 for (unit = 0; unit < 16; unit++) { /* XXX need to know how many */
4102 int flags;
4103 if (resource_int_value("sio", unit, "flags", &flags))
4104 continue;
4097 if (COM_CONSOLE(flags)) {
4105 if (COM_CONSOLE(flags) || COM_DEBUGGER(flags)) {
4098 int port;
4106 int port;
4107 Port_t iobase;
4108
4099 if (resource_int_value("sio", unit, "port", &port))
4100 continue;
4109 if (resource_int_value("sio", unit, "port", &port))
4110 continue;
4101 siocniobase = port;
4111 iobase = port;
4102 s = spltty();
4103 if (boothowto & RB_SERIAL) {
4112 s = spltty();
4113 if (boothowto & RB_SERIAL) {
4104 boot_speed = siocngetspeed(siocniobase,
4105 comspeedtab);
4114 boot_speed = siocngetspeed(iobase, comspeedtab);
4106 if (boot_speed)
4107 comdefaultrate = boot_speed;
4108 }
4109
4110 /*
4111 * Initialize the divisor latch. We can't rely on
4112 * siocnopen() to do this the first time, since it
4113 * avoids writing to the latch if the latch appears
4114 * to have the correct value. Also, if we didn't
4115 * just read the speed from the hardware, then we
4116 * need to set the speed in hardware so that
4117 * switching it later is null.
4118 */
4115 if (boot_speed)
4116 comdefaultrate = boot_speed;
4117 }
4118
4119 /*
4120 * Initialize the divisor latch. We can't rely on
4121 * siocnopen() to do this the first time, since it
4122 * avoids writing to the latch if the latch appears
4123 * to have the correct value. Also, if we didn't
4124 * just read the speed from the hardware, then we
4125 * need to set the speed in hardware so that
4126 * switching it later is null.
4127 */
4119 cfcr = inb(siocniobase + com_cfcr);
4120 outb(siocniobase + com_cfcr, CFCR_DLAB | cfcr);
4121 outb(siocniobase + com_dlbl,
4128 cfcr = inb(iobase + com_cfcr);
4129 outb(iobase + com_cfcr, CFCR_DLAB | cfcr);
4130 outb(iobase + com_dlbl,
4122 COMBRD(comdefaultrate) & 0xff);
4131 COMBRD(comdefaultrate) & 0xff);
4123 outb(siocniobase + com_dlbh,
4132 outb(iobase + com_dlbh,
4124 (u_int) COMBRD(comdefaultrate) >> 8);
4133 (u_int) COMBRD(comdefaultrate) >> 8);
4125 outb(siocniobase + com_cfcr, cfcr);
4134 outb(iobase + com_cfcr, cfcr);
4126
4135
4127 siocnopen(&sp, siocniobase, comdefaultrate);
4136 siocnopen(&sp, iobase, comdefaultrate);
4137
4128 splx(s);
4138 splx(s);
4129 if (!COM_LLCONSOLE(flags)) {
4139 if (COM_CONSOLE(flags) && !COM_LLCONSOLE(flags)) {
4130 cp->cn_dev = makedev(CDEV_MAJOR, unit);
4131 cp->cn_pri = COM_FORCECONSOLE(flags)
4132 || boothowto & RB_SERIAL
4133 ? CN_REMOTE : CN_NORMAL;
4140 cp->cn_dev = makedev(CDEV_MAJOR, unit);
4141 cp->cn_pri = COM_FORCECONSOLE(flags)
4142 || boothowto & RB_SERIAL
4143 ? CN_REMOTE : CN_NORMAL;
4144 printf("sio%d: system console\n", unit);
4145 siocniobase = iobase;
4146 siocnunit = unit;
4134 }
4147 }
4135 break;
4148 if (COM_DEBUGGER(flags) && !COM_LLCONSOLE(flags)) {
4149 printf("sio%d: gdb debugging port\n", unit);
4150 siogdbiobase = iobase;
4151 siogdbunit = unit;
4152#ifdef __i386__
4153 gdbdev = makedev(CDEV_MAJOR, unit);
4154 gdb_getc = siocngetc;
4155 gdb_putc = siocnputc;
4156#endif
4157 }
4136 }
4137 }
4158 }
4159 }
4160#ifdef __i386__
4161 /*
4162 * XXX Ugly Compatability.
4163 * If no gdb port has been specified, set it to be the console
4164 * as some configuration files don't specify the gdb port.
4165 */
4166 if (gdbdev == -1 && (boothowto & RB_GDB)) {
4167 printf("Warning: no GDB port specified. Defaulting to sio%d.\n",
4168 siocnunit);
4169 printf("Set flag 0x80 on desired GDB port in your\n");
4170 printf("configuration file (currently sio only).\n");
4171 siogdbiobase = siocniobase;
4172 siogdbunit = siocnunit;
4173 gdbdev = makedev(CDEV_MAJOR, siocnunit);
4174 gdb_getc = siocngetc;
4175 gdb_putc = siocnputc;
4176 }
4177#endif
4138}
4139
4140#ifdef __alpha__
4141
4142struct consdev siocons = {
4143 NULL, NULL, siocngetc, siocncheckc, siocnputc,
4144 NULL, makedev(CDEV_MAJOR, 0), CN_NORMAL,
4145};

--- 94 unchanged lines hidden (view full) ---

4240siocncheckc(dev)
4241 dev_t dev;
4242{
4243 int c;
4244 Port_t iobase;
4245 int s;
4246 struct siocnstate sp;
4247
4178}
4179
4180#ifdef __alpha__
4181
4182struct consdev siocons = {
4183 NULL, NULL, siocngetc, siocncheckc, siocnputc,
4184 NULL, makedev(CDEV_MAJOR, 0), CN_NORMAL,
4185};

--- 94 unchanged lines hidden (view full) ---

4280siocncheckc(dev)
4281 dev_t dev;
4282{
4283 int c;
4284 Port_t iobase;
4285 int s;
4286 struct siocnstate sp;
4287
4248 iobase = siocniobase;
4288 if (minor(dev) == siogdbunit)
4289 iobase = siogdbiobase;
4290 else
4291 iobase = siocniobase;
4249 s = spltty();
4250 siocnopen(&sp, iobase, comdefaultrate);
4251 if (inb(iobase + com_lsr) & LSR_RXRDY)
4252 c = inb(iobase + com_data);
4253 else
4254 c = -1;
4255 siocnclose(&sp, iobase);
4256 splx(s);

--- 5 unchanged lines hidden (view full) ---

4262siocngetc(dev)
4263 dev_t dev;
4264{
4265 int c;
4266 Port_t iobase;
4267 int s;
4268 struct siocnstate sp;
4269
4292 s = spltty();
4293 siocnopen(&sp, iobase, comdefaultrate);
4294 if (inb(iobase + com_lsr) & LSR_RXRDY)
4295 c = inb(iobase + com_data);
4296 else
4297 c = -1;
4298 siocnclose(&sp, iobase);
4299 splx(s);

--- 5 unchanged lines hidden (view full) ---

4305siocngetc(dev)
4306 dev_t dev;
4307{
4308 int c;
4309 Port_t iobase;
4310 int s;
4311 struct siocnstate sp;
4312
4270 iobase = siocniobase;
4313 if (minor(dev) == siogdbunit)
4314 iobase = siogdbiobase;
4315 else
4316 iobase = siocniobase;
4271 s = spltty();
4272 siocnopen(&sp, iobase, comdefaultrate);
4273 while (!(inb(iobase + com_lsr) & LSR_RXRDY))
4274 ;
4275 c = inb(iobase + com_data);
4276 siocnclose(&sp, iobase);
4277 splx(s);
4278 return (c);
4279}
4280
4281void
4282siocnputc(dev, c)
4283 dev_t dev;
4284 int c;
4285{
4286 int s;
4287 struct siocnstate sp;
4317 s = spltty();
4318 siocnopen(&sp, iobase, comdefaultrate);
4319 while (!(inb(iobase + com_lsr) & LSR_RXRDY))
4320 ;
4321 c = inb(iobase + com_data);
4322 siocnclose(&sp, iobase);
4323 splx(s);
4324 return (c);
4325}
4326
4327void
4328siocnputc(dev, c)
4329 dev_t dev;
4330 int c;
4331{
4332 int s;
4333 struct siocnstate sp;
4334 Port_t iobase;
4288
4335
4336 if (minor(dev) == siogdbunit)
4337 iobase = siogdbiobase;
4338 else
4339 iobase = siocniobase;
4289 s = spltty();
4340 s = spltty();
4290 siocnopen(&sp, siocniobase, comdefaultrate);
4291 siocntxwait(siocniobase);
4292 outb(siocniobase + com_data, c);
4293 siocnclose(&sp, siocniobase);
4341 siocnopen(&sp, iobase, comdefaultrate);
4342 siocntxwait(iobase);
4343 outb(iobase + com_data, c);
4344 siocnclose(&sp, iobase);
4294 splx(s);
4295}
4296
4297#ifdef __alpha__
4298int
4299siogdbgetc()
4300{
4301 int c;

--- 679 unchanged lines hidden ---
4345 splx(s);
4346}
4347
4348#ifdef __alpha__
4349int
4350siogdbgetc()
4351{
4352 int c;

--- 679 unchanged lines hidden ---