1996-02-10 23:23:18 +03:00
|
|
|
/* $NetBSD: com.c,v 1.65 1996/02/10 20:23:18 christos Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1995-06-05 00:39:22 +04:00
|
|
|
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
* Copyright (c) 1991 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-10-27 07:14:23 +03:00
|
|
|
* @(#)com.c 7.5 (Berkeley) 5/16/91
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* COM driver, based on HP dca driver
|
|
|
|
* uses National Semiconductor NS16450/NS16550AF UART
|
|
|
|
*/
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/types.h>
|
1994-03-08 11:12:56 +03:00
|
|
|
#include <sys/device.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
#include <machine/cpu.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <machine/pio.h>
|
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/isa/isavar.h>
|
1995-01-29 10:36:54 +03:00
|
|
|
#include <dev/isa/comreg.h>
|
1995-06-28 08:30:30 +04:00
|
|
|
#include <dev/ic/ns16550reg.h>
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
|
|
|
#include <dev/ic/hayespreg.h>
|
|
|
|
#endif
|
1995-10-15 22:43:04 +03:00
|
|
|
#define com_lcr com_cfcr
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1996-01-15 02:44:34 +03:00
|
|
|
#define COM_IBUFSIZE (2 * 512)
|
1995-06-05 00:39:22 +04:00
|
|
|
#define COM_IHIGHWATER ((3 * COM_IBUFSIZE) / 4)
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
struct com_softc {
|
|
|
|
struct device sc_dev;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1995-04-19 22:59:27 +04:00
|
|
|
struct tty *sc_tty;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-08-07 15:27:51 +04:00
|
|
|
int sc_overflows;
|
1995-06-05 00:39:22 +04:00
|
|
|
int sc_floods;
|
|
|
|
int sc_errors;
|
|
|
|
|
1994-11-19 00:57:40 +03:00
|
|
|
int sc_iobase;
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
|
|
|
int sc_hayespbase;
|
|
|
|
#endif
|
1994-03-12 10:25:16 +03:00
|
|
|
u_char sc_hwflags;
|
1994-03-29 08:35:37 +04:00
|
|
|
#define COM_HW_NOIEN 0x01
|
1994-03-12 10:25:16 +03:00
|
|
|
#define COM_HW_FIFO 0x02
|
1996-02-10 23:23:18 +03:00
|
|
|
#define COM_HW_HAYESP 0x04
|
1994-03-12 10:25:16 +03:00
|
|
|
#define COM_HW_CONSOLE 0x40
|
|
|
|
u_char sc_swflags;
|
|
|
|
#define COM_SW_SOFTCAR 0x01
|
|
|
|
#define COM_SW_CLOCAL 0x02
|
|
|
|
#define COM_SW_CRTSCTS 0x04
|
1994-03-18 08:13:26 +03:00
|
|
|
#define COM_SW_MDMBUF 0x08
|
1995-10-15 22:43:04 +03:00
|
|
|
u_char sc_msr, sc_mcr, sc_lcr;
|
1995-06-05 00:39:22 +04:00
|
|
|
u_char sc_dtr;
|
|
|
|
|
|
|
|
u_char *sc_ibuf, *sc_ibufp, *sc_ibufhigh, *sc_ibufend;
|
|
|
|
u_char sc_ibufs[2][COM_IBUFSIZE];
|
1994-03-29 08:35:37 +04:00
|
|
|
};
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1994-11-04 02:26:03 +03:00
|
|
|
int comprobe __P((struct device *, void *, void *));
|
|
|
|
void comattach __P((struct device *, struct device *, void *));
|
1994-03-08 11:12:56 +03:00
|
|
|
int comopen __P((dev_t, int, int, struct proc *));
|
|
|
|
int comclose __P((dev_t, int, int, struct proc *));
|
1994-08-07 15:27:51 +04:00
|
|
|
void comdiag __P((void *));
|
1995-04-17 16:06:30 +04:00
|
|
|
int comintr __P((void *));
|
1995-06-05 00:39:22 +04:00
|
|
|
void compoll __P((void *));
|
1994-03-08 11:12:56 +03:00
|
|
|
int comparam __P((struct tty *, struct termios *));
|
|
|
|
void comstart __P((struct tty *));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
struct cfdriver comcd = {
|
|
|
|
NULL, "com", comprobe, comattach, DV_TTY, sizeof(struct com_softc)
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int comdefaultrate = TTYDEF_SPEED;
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef COMCONSOLE
|
|
|
|
int comconsole = COMCONSOLE;
|
|
|
|
#else
|
|
|
|
int comconsole = -1;
|
|
|
|
#endif
|
|
|
|
int comconsinit;
|
|
|
|
int commajor;
|
1995-06-05 00:39:22 +04:00
|
|
|
int comsopen = 0;
|
|
|
|
int comevents = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#ifdef KGDB
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <machine/remote-sl.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
extern int kgdb_dev;
|
|
|
|
extern int kgdb_rate;
|
|
|
|
extern int kgdb_debug_init;
|
|
|
|
#endif
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
#define COMUNIT(x) (minor(x))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
/* Macros to clear/set/test flags. */
|
|
|
|
#define SET(t, f) (t) |= (f)
|
|
|
|
#define CLR(t, f) (t) &= ~(f)
|
|
|
|
#define ISSET(t, f) ((t) & (f))
|
1994-03-08 11:12:56 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
comspeed(speed)
|
|
|
|
long speed;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-08 11:12:56 +03:00
|
|
|
#define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
|
|
|
|
|
|
|
|
int x, err;
|
|
|
|
|
|
|
|
if (speed == 0)
|
|
|
|
return 0;
|
|
|
|
if (speed < 0)
|
|
|
|
return -1;
|
|
|
|
x = divrnd((COM_FREQ / 16), speed);
|
|
|
|
if (x <= 0)
|
|
|
|
return -1;
|
|
|
|
err = divrnd((COM_FREQ / 16) * 1000, speed * x) - 1000;
|
|
|
|
if (err < 0)
|
|
|
|
err = -err;
|
|
|
|
if (err > COM_TOLERANCE)
|
|
|
|
return -1;
|
|
|
|
return x;
|
|
|
|
|
|
|
|
#undef divrnd(n, q)
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
comprobe1(iobase)
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase;
|
1994-03-08 11:12:56 +03:00
|
|
|
{
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* force access to id reg */
|
1995-10-15 22:43:04 +03:00
|
|
|
outb(iobase + com_lcr, 0);
|
1994-03-08 11:12:56 +03:00
|
|
|
outb(iobase + com_iir, 0);
|
|
|
|
if (inb(iobase + com_iir) & 0x38)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
|
|
|
int
|
|
|
|
comprobeHAYESP(iobase, sc)
|
|
|
|
int iobase;
|
1996-01-15 02:44:34 +03:00
|
|
|
struct com_softc *sc;
|
|
|
|
{
|
1996-02-10 23:23:18 +03:00
|
|
|
char val, dips;
|
1996-01-15 02:44:34 +03:00
|
|
|
int combaselist[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hayes ESP cards have two iobases. One is for compatibility with
|
|
|
|
* 16550 serial chips, and at the same ISA PC base addresses. The
|
|
|
|
* other is for ESP-specific enhanced features, and lies at a
|
1996-02-10 23:23:18 +03:00
|
|
|
* different addressing range entirely (0x140, 0x180, 0x280, or 0x300).
|
1996-01-15 02:44:34 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Test for ESP signature */
|
1996-02-10 23:23:18 +03:00
|
|
|
if ((inb(iobase) & 0xf3) == 0)
|
|
|
|
return 0;
|
1996-01-15 02:44:34 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ESP is present at ESP enhanced base address; unknown com port
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Get the dip-switch configurations */
|
1996-02-10 23:23:18 +03:00
|
|
|
outb(iobase + HAYESP_CMD1, HAYESP_GETDIPS);
|
|
|
|
dips = inb(iobase + HAYESP_STATUS1);
|
1996-01-15 02:44:34 +03:00
|
|
|
|
|
|
|
/* Determine which com port this ESP card services: bits 0,1 of */
|
|
|
|
/* dips is the port # (0-3); combaselist[val] is the com_iobase */
|
1996-02-10 23:23:18 +03:00
|
|
|
if (sc->sc_iobase != combaselist[dips & 0x03])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
printf(": ESP");
|
1996-01-15 02:44:34 +03:00
|
|
|
|
1996-02-10 23:23:18 +03:00
|
|
|
/* Check ESP Self Test bits. */
|
1996-01-15 02:44:34 +03:00
|
|
|
/* Check for ESP version 2.0: bits 4,5,6 == 010 */
|
1996-02-10 23:23:18 +03:00
|
|
|
outb(iobase + HAYESP_CMD1, HAYESP_GETTEST);
|
|
|
|
val = inb(iobase + HAYESP_STATUS1); /* Clear reg 1 */
|
|
|
|
val = inb(iobase + HAYESP_STATUS2);
|
1996-01-15 02:44:34 +03:00
|
|
|
if ((val & 0x70) < 0x20) {
|
|
|
|
printf("-old (%o)", val & 0x70);
|
|
|
|
/* we do not support the necessary features */
|
1996-02-10 23:23:18 +03:00
|
|
|
return 0;
|
1996-01-15 02:44:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for ability to emulate 16550: bit 8 == 1 */
|
|
|
|
if ((dips & 0x80) == 0) {
|
|
|
|
printf(" slave");
|
|
|
|
/* XXX Does slave really mean no 16550 support?? */
|
1996-02-10 23:23:18 +03:00
|
|
|
return 0;
|
1996-01-15 02:44:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we made it this far, we are a full-featured ESP v2.0 (or
|
|
|
|
* better), at the correct com port address.
|
|
|
|
*/
|
|
|
|
|
1996-02-10 23:23:18 +03:00
|
|
|
SET(sc->sc_hwflags, COM_HW_HAYESP);
|
|
|
|
printf(", 1024k fifo\n");
|
|
|
|
return 1;
|
1996-01-15 02:44:34 +03:00
|
|
|
}
|
1996-02-10 23:23:18 +03:00
|
|
|
#endif
|
1996-01-15 02:44:34 +03:00
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1994-11-04 02:26:03 +03:00
|
|
|
comprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
1994-03-08 11:12:56 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = ia->ia_iobase;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
|
|
|
if (!comprobe1(iobase))
|
|
|
|
return 0;
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
ia->ia_iosize = COM_NPORTS;
|
|
|
|
ia->ia_msize = 0;
|
|
|
|
return 1;
|
1994-03-08 11:12:56 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
void
|
|
|
|
comattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct com_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
struct cfdata *cf = sc->sc_dev.dv_cfdata;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = ia->ia_iobase;
|
1994-03-08 11:12:56 +03:00
|
|
|
struct tty *tp;
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
|
|
|
int hayesp_ports[] = { 0x140, 0x180, 0x280, 0x300, 0 };
|
|
|
|
int *hayespp;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
sc->sc_iobase = iobase;
|
1995-10-15 22:43:04 +03:00
|
|
|
sc->sc_hwflags = ISSET(cf->cf_flags, COM_HW_NOIEN);
|
1994-03-12 10:25:16 +03:00
|
|
|
sc->sc_swflags = 0;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
if (sc->sc_dev.dv_unit == comconsole)
|
|
|
|
delay(1000);
|
1994-03-23 04:28:23 +03:00
|
|
|
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
|
|
|
/* Look for a Hayes ESP board. */
|
|
|
|
for (hayespp = hayesp_ports; *hayespp != 0; hayespp++)
|
|
|
|
if (comprobeHAYESP(*hayespp, sc)) {
|
|
|
|
sc->sc_hayespbase = *hayespp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* No ESP; look for other things. */
|
|
|
|
if (*hayespp == 0) {
|
|
|
|
#endif
|
1996-01-15 02:44:34 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* look for a NS 16550AF UART with FIFOs */
|
1994-03-08 11:12:56 +03:00
|
|
|
outb(iobase + com_fifo,
|
|
|
|
FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(100);
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(inb(iobase + com_iir), IIR_FIFO_MASK) == IIR_FIFO_MASK)
|
|
|
|
if (ISSET(inb(iobase + com_fifo), FIFO_TRIGGER_14) == FIFO_TRIGGER_14) {
|
|
|
|
SET(sc->sc_hwflags, COM_HW_FIFO);
|
1994-03-29 08:35:37 +04:00
|
|
|
printf(": ns16550a, working fifo\n");
|
1994-03-08 11:12:56 +03:00
|
|
|
} else
|
1995-06-02 01:26:51 +04:00
|
|
|
printf(": ns16550, broken fifo\n");
|
1994-03-08 11:12:56 +03:00
|
|
|
else
|
1995-06-02 01:26:51 +04:00
|
|
|
printf(": ns8250 or ns16450, no fifo\n");
|
1994-03-08 11:12:56 +03:00
|
|
|
outb(iobase + com_fifo, 0);
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
|
|
|
}
|
|
|
|
#endif
|
1994-03-08 11:12:56 +03:00
|
|
|
|
|
|
|
/* disable interrupts */
|
|
|
|
outb(iobase + com_ier, 0);
|
|
|
|
outb(iobase + com_mcr, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
if (ia->ia_irq != IRQUNK)
|
1995-12-24 05:29:35 +03:00
|
|
|
sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY,
|
|
|
|
comintr, sc);
|
1994-04-07 10:48:19 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef KGDB
|
1993-03-21 21:04:42 +03:00
|
|
|
if (kgdb_dev == makedev(commajor, unit)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (comconsole == unit)
|
|
|
|
kgdb_dev = -1; /* can't debug over console port */
|
|
|
|
else {
|
|
|
|
(void) cominit(unit, kgdb_rate);
|
|
|
|
if (kgdb_debug_init) {
|
|
|
|
/*
|
|
|
|
* Print prefix of device name,
|
|
|
|
* let kgdb_connect print the rest.
|
|
|
|
*/
|
1994-03-08 11:12:56 +03:00
|
|
|
printf("%s: ", sc->sc_dev.dv_xname);
|
1993-03-21 12:45:37 +03:00
|
|
|
kgdb_connect(1);
|
|
|
|
} else
|
1994-03-08 11:12:56 +03:00
|
|
|
printf("%s: kgdb enabled\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
if (sc->sc_dev.dv_unit == comconsole) {
|
|
|
|
/*
|
|
|
|
* Need to reset baud rate, etc. of next print so reset
|
|
|
|
* comconsinit. Also make sure console is always "hardwired".
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
comconsinit = 0;
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(sc->sc_hwflags, COM_HW_CONSOLE);
|
|
|
|
SET(sc->sc_swflags, COM_SW_SOFTCAR);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
|
|
|
comopen(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-08 11:12:56 +03:00
|
|
|
int unit = COMUNIT(dev);
|
|
|
|
struct com_softc *sc;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase;
|
1994-03-08 11:12:56 +03:00
|
|
|
struct tty *tp;
|
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
int error = 0;
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
if (unit >= comcd.cd_ndevs)
|
1994-03-08 11:12:56 +03:00
|
|
|
return ENXIO;
|
1994-03-29 08:35:37 +04:00
|
|
|
sc = comcd.cd_devs[unit];
|
|
|
|
if (!sc)
|
1994-03-08 11:12:56 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1995-04-19 22:59:27 +04:00
|
|
|
if (!sc->sc_tty)
|
|
|
|
tp = sc->sc_tty = ttymalloc();
|
1994-03-08 11:12:56 +03:00
|
|
|
else
|
1995-04-19 22:59:27 +04:00
|
|
|
tp = sc->sc_tty;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
tp->t_oproc = comstart;
|
|
|
|
tp->t_param = comparam;
|
|
|
|
tp->t_dev = dev;
|
1995-10-15 22:43:04 +03:00
|
|
|
if (!ISSET(tp->t_state, TS_ISOPEN)) {
|
|
|
|
SET(tp->t_state, TS_WOPEN);
|
1993-03-21 12:45:37 +03:00
|
|
|
ttychars(tp);
|
1994-01-30 19:41:27 +03:00
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
|
|
|
tp->t_cflag = TTYDEF_CFLAG;
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(sc->sc_swflags, COM_SW_CLOCAL))
|
|
|
|
SET(tp->t_cflag, CLOCAL);
|
|
|
|
if (ISSET(sc->sc_swflags, COM_SW_CRTSCTS))
|
|
|
|
SET(tp->t_cflag, CRTSCTS);
|
|
|
|
if (ISSET(sc->sc_swflags, COM_SW_MDMBUF))
|
|
|
|
SET(tp->t_cflag, MDMBUF);
|
1994-01-30 19:41:27 +03:00
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
|
|
|
tp->t_ispeed = tp->t_ospeed = comdefaultrate;
|
1995-06-05 00:39:22 +04:00
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
comparam(tp, &tp->t_termios);
|
|
|
|
ttsetwater(tp);
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1995-06-05 00:39:22 +04:00
|
|
|
if (comsopen++ == 0)
|
|
|
|
timeout(compoll, NULL, 1);
|
|
|
|
|
|
|
|
sc->sc_ibufp = sc->sc_ibuf = sc->sc_ibufs[0];
|
|
|
|
sc->sc_ibufhigh = sc->sc_ibuf + COM_IHIGHWATER;
|
|
|
|
sc->sc_ibufend = sc->sc_ibuf + COM_IBUFSIZE;
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
iobase = sc->sc_iobase;
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
1996-01-15 02:44:34 +03:00
|
|
|
/* Setup the ESP board */
|
1996-02-10 23:23:18 +03:00
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
|
|
|
|
int hayespbase = sc->sc_hayespbase;
|
|
|
|
|
1996-01-15 02:44:34 +03:00
|
|
|
outb(iobase + com_fifo,
|
|
|
|
FIFO_DMA_MODE|FIFO_ENABLE|
|
|
|
|
FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_8);
|
1996-02-10 23:23:18 +03:00
|
|
|
|
1996-01-15 02:44:34 +03:00
|
|
|
/* Set 16550 compatibility mode */
|
1996-02-10 23:23:18 +03:00
|
|
|
outb(hayespbase + HAYESP_CMD1, HAYESP_SETMODE);
|
|
|
|
outb(hayespbase + HAYESP_CMD2,
|
|
|
|
HAYESP_MODE_FIFO|HAYESP_MODE_RTS|
|
|
|
|
HAYESP_MODE_SCALE);
|
|
|
|
|
1996-01-15 02:44:34 +03:00
|
|
|
/* Set RTS/CTS flow control */
|
1996-02-10 23:23:18 +03:00
|
|
|
outb(hayespbase + HAYESP_CMD1, HAYESP_SETFLOWTYPE);
|
|
|
|
outb(hayespbase + HAYESP_CMD2, HAYESP_FLOW_RTS);
|
|
|
|
outb(hayespbase + HAYESP_CMD2, HAYESP_FLOW_CTS);
|
|
|
|
|
1996-01-15 02:44:34 +03:00
|
|
|
/* Set flow control levels */
|
1996-02-10 23:23:18 +03:00
|
|
|
outb(hayespbase + HAYESP_CMD1, HAYESP_SETRXFLOW);
|
|
|
|
outb(hayespbase + HAYESP_CMD2,
|
|
|
|
HAYESP_HIBYTE(HAYESP_RXHIWMARK));
|
|
|
|
outb(hayespbase + HAYESP_CMD2,
|
|
|
|
HAYESP_LOBYTE(HAYESP_RXHIWMARK));
|
|
|
|
outb(hayespbase + HAYESP_CMD2,
|
|
|
|
HAYESP_HIBYTE(HAYESP_RXLOWMARK));
|
|
|
|
outb(hayespbase + HAYESP_CMD2,
|
|
|
|
HAYESP_LOBYTE(HAYESP_RXLOWMARK));
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
|
1996-01-15 02:44:34 +03:00
|
|
|
/* Set the FIFO threshold based on the receive speed. */
|
1994-09-16 06:50:39 +04:00
|
|
|
outb(iobase + com_fifo,
|
|
|
|
FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST |
|
|
|
|
(tp->t_ispeed <= 1200 ? FIFO_TRIGGER_1 : FIFO_TRIGGER_8));
|
1994-03-08 11:12:56 +03:00
|
|
|
/* flush any pending I/O */
|
1995-10-15 22:43:04 +03:00
|
|
|
while (ISSET(inb(iobase + com_lsr), LSR_RXRDY))
|
1995-06-05 00:39:22 +04:00
|
|
|
(void) inb(iobase + com_data);
|
1994-03-08 11:12:56 +03:00
|
|
|
/* you turn me on, baby */
|
1994-03-23 04:28:23 +03:00
|
|
|
sc->sc_mcr = MCR_DTR | MCR_RTS;
|
1995-10-15 22:43:04 +03:00
|
|
|
if (!ISSET(sc->sc_hwflags, COM_HW_NOIEN))
|
|
|
|
SET(sc->sc_mcr, MCR_IENABLE);
|
1994-03-23 04:28:23 +03:00
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
1994-03-08 11:12:56 +03:00
|
|
|
outb(iobase + com_ier,
|
|
|
|
IER_ERXRDY | IER_ETXRDY | IER_ERLS | IER_EMSC);
|
|
|
|
|
|
|
|
sc->sc_msr = inb(iobase + com_msr);
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(sc->sc_swflags, COM_SW_SOFTCAR) ||
|
|
|
|
ISSET(sc->sc_msr, MSR_DCD) || ISSET(tp->t_cflag, MDMBUF))
|
|
|
|
SET(tp->t_state, TS_CARR_ON);
|
1994-03-08 11:12:56 +03:00
|
|
|
else
|
1995-10-15 22:43:04 +03:00
|
|
|
CLR(tp->t_state, TS_CARR_ON);
|
|
|
|
} else if (ISSET(tp->t_state, TS_XCLUDE) && p->p_ucred->cr_uid != 0)
|
1994-03-08 11:12:56 +03:00
|
|
|
return EBUSY;
|
1995-10-15 22:43:04 +03:00
|
|
|
else
|
1995-06-05 00:39:22 +04:00
|
|
|
s = spltty();
|
1994-03-08 11:12:56 +03:00
|
|
|
|
|
|
|
/* wait for carrier if necessary */
|
1995-10-15 22:43:04 +03:00
|
|
|
if (!ISSET(flag, O_NONBLOCK))
|
|
|
|
while (!ISSET(tp->t_cflag, CLOCAL) &&
|
|
|
|
!ISSET(tp->t_state, TS_CARR_ON)) {
|
|
|
|
SET(tp->t_state, TS_WOPEN);
|
|
|
|
error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
|
|
|
|
ttopen, 0);
|
1994-03-08 11:12:56 +03:00
|
|
|
if (error) {
|
|
|
|
/* XXX should turn off chip if we're the
|
|
|
|
only waiter */
|
|
|
|
splx(s);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (*linesw[tp->t_line].l_open)(dev, tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
comclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1994-03-08 11:12:56 +03:00
|
|
|
int unit = COMUNIT(dev);
|
1994-03-29 08:35:37 +04:00
|
|
|
struct com_softc *sc = comcd.cd_devs[unit];
|
1995-04-19 22:59:27 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = sc->sc_iobase;
|
1995-06-05 00:39:22 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
/* XXX This is for cons.c. */
|
1995-10-15 22:43:04 +03:00
|
|
|
if (!ISSET(tp->t_state, TS_ISOPEN))
|
1995-06-05 00:39:22 +04:00
|
|
|
return 0;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
(*linesw[tp->t_line].l_close)(tp, flag);
|
1995-06-05 00:39:22 +04:00
|
|
|
s = spltty();
|
1995-10-15 22:43:04 +03:00
|
|
|
CLR(sc->sc_lcr, LCR_SBREAK);
|
|
|
|
outb(iobase + com_lcr, sc->sc_lcr);
|
1995-06-05 00:39:22 +04:00
|
|
|
outb(iobase + com_ier, 0);
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(tp->t_cflag, HUPCL) &&
|
|
|
|
!ISSET(sc->sc_swflags, COM_SW_SOFTCAR)) {
|
1995-06-05 00:39:22 +04:00
|
|
|
/* XXX perhaps only clear DTR */
|
|
|
|
outb(iobase + com_mcr, 0);
|
1994-03-08 11:12:56 +03:00
|
|
|
}
|
1995-10-15 22:43:04 +03:00
|
|
|
CLR(tp->t_state, TS_BUSY | TS_FLUSH);
|
1995-06-05 00:39:22 +04:00
|
|
|
if (--comsopen == 0)
|
|
|
|
untimeout(compoll, NULL);
|
|
|
|
splx(s);
|
1993-03-21 12:45:37 +03:00
|
|
|
ttyclose(tp);
|
1994-03-08 11:12:56 +03:00
|
|
|
#ifdef notyet /* XXXX */
|
|
|
|
if (unit != comconsole) {
|
|
|
|
ttyfree(tp);
|
1995-04-19 22:59:27 +04:00
|
|
|
sc->sc_tty = 0;
|
1994-03-08 11:12:56 +03:00
|
|
|
}
|
1993-09-29 05:36:21 +03:00
|
|
|
#endif
|
1994-03-08 11:12:56 +03:00
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
comread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1994-03-08 11:12:56 +03:00
|
|
|
int flag;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-04-20 02:04:33 +04:00
|
|
|
struct com_softc *sc = comcd.cd_devs[COMUNIT(dev)];
|
|
|
|
struct tty *tp = sc->sc_tty;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
|
|
|
|
}
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
comwrite(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1994-03-08 11:12:56 +03:00
|
|
|
int flag;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-04-20 02:04:33 +04:00
|
|
|
struct com_softc *sc = comcd.cd_devs[COMUNIT(dev)];
|
|
|
|
struct tty *tp = sc->sc_tty;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
|
|
|
|
}
|
1995-04-19 22:59:27 +04:00
|
|
|
|
|
|
|
struct tty *
|
|
|
|
comtty(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
1995-04-20 02:04:33 +04:00
|
|
|
struct com_softc *sc = comcd.cd_devs[COMUNIT(dev)];
|
|
|
|
struct tty *tp = sc->sc_tty;
|
1995-04-19 22:59:27 +04:00
|
|
|
|
1995-04-20 02:04:33 +04:00
|
|
|
return (tp);
|
1995-04-19 22:59:27 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
static u_char
|
|
|
|
tiocm_xxx2mcr(data)
|
|
|
|
int data;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-08 11:12:56 +03:00
|
|
|
u_char m = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(data, TIOCM_DTR))
|
|
|
|
SET(m, MCR_DTR);
|
|
|
|
if (ISSET(data, TIOCM_RTS))
|
|
|
|
SET(m, MCR_RTS);
|
1994-03-08 11:12:56 +03:00
|
|
|
return m;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1994-02-10 00:06:46 +03:00
|
|
|
comioctl(dev, cmd, data, flag, p)
|
1993-03-21 12:45:37 +03:00
|
|
|
dev_t dev;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1993-03-21 12:45:37 +03:00
|
|
|
caddr_t data;
|
1994-02-10 00:06:46 +03:00
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-08 11:12:56 +03:00
|
|
|
int unit = COMUNIT(dev);
|
1994-03-29 08:35:37 +04:00
|
|
|
struct com_softc *sc = comcd.cd_devs[unit];
|
1995-04-19 22:59:27 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = sc->sc_iobase;
|
1994-03-08 11:12:56 +03:00
|
|
|
int error;
|
|
|
|
|
1994-02-10 00:06:46 +03:00
|
|
|
error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (error >= 0)
|
1994-03-08 11:12:56 +03:00
|
|
|
return error;
|
1994-02-10 00:06:46 +03:00
|
|
|
error = ttioctl(tp, cmd, data, flag, p);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (error >= 0)
|
1994-03-08 11:12:56 +03:00
|
|
|
return error;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TIOCSBRK:
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(sc->sc_lcr, LCR_SBREAK);
|
|
|
|
outb(iobase + com_lcr, sc->sc_lcr);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case TIOCCBRK:
|
1995-10-15 22:43:04 +03:00
|
|
|
CLR(sc->sc_lcr, LCR_SBREAK);
|
|
|
|
outb(iobase + com_lcr, sc->sc_lcr);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case TIOCSDTR:
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(sc->sc_mcr, sc->sc_dtr);
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case TIOCCDTR:
|
1995-10-15 22:43:04 +03:00
|
|
|
CLR(sc->sc_mcr, sc->sc_dtr);
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case TIOCMSET:
|
1995-10-15 22:43:04 +03:00
|
|
|
CLR(sc->sc_mcr, MCR_DTR | MCR_RTS);
|
1993-03-21 12:45:37 +03:00
|
|
|
case TIOCMBIS:
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data));
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case TIOCMBIC:
|
1995-10-15 22:43:04 +03:00
|
|
|
CLR(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data));
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-03-08 11:12:56 +03:00
|
|
|
case TIOCMGET: {
|
|
|
|
u_char m;
|
|
|
|
int bits = 0;
|
|
|
|
|
|
|
|
m = sc->sc_mcr;
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(m, MCR_DTR))
|
|
|
|
SET(bits, TIOCM_DTR);
|
|
|
|
if (ISSET(m, MCR_RTS))
|
|
|
|
SET(bits, TIOCM_RTS);
|
1994-03-08 11:12:56 +03:00
|
|
|
m = sc->sc_msr;
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(m, MSR_DCD))
|
|
|
|
SET(bits, TIOCM_CD);
|
|
|
|
if (ISSET(m, MSR_CTS))
|
|
|
|
SET(bits, TIOCM_CTS);
|
|
|
|
if (ISSET(m, MSR_DSR))
|
|
|
|
SET(bits, TIOCM_DSR);
|
|
|
|
if (ISSET(m, MSR_RI | MSR_TERI))
|
|
|
|
SET(bits, TIOCM_RI);
|
1994-03-08 11:12:56 +03:00
|
|
|
if (inb(iobase + com_ier))
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(bits, TIOCM_LE);
|
1994-03-08 11:12:56 +03:00
|
|
|
*(int *)data = bits;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-03-08 11:12:56 +03:00
|
|
|
}
|
1994-03-12 10:25:16 +03:00
|
|
|
case TIOCGFLAGS: {
|
1995-10-15 22:43:04 +03:00
|
|
|
int driverbits, userbits = 0;
|
|
|
|
|
|
|
|
driverbits = sc->sc_swflags;
|
|
|
|
if (ISSET(driverbits, COM_SW_SOFTCAR))
|
|
|
|
SET(userbits, TIOCFLAG_SOFTCAR);
|
|
|
|
if (ISSET(driverbits, COM_SW_CLOCAL))
|
|
|
|
SET(userbits, TIOCFLAG_CLOCAL);
|
|
|
|
if (ISSET(driverbits, COM_SW_CRTSCTS))
|
|
|
|
SET(userbits, TIOCFLAG_CRTSCTS);
|
|
|
|
if (ISSET(driverbits, COM_SW_MDMBUF))
|
|
|
|
SET(userbits, TIOCFLAG_MDMBUF);
|
|
|
|
|
|
|
|
*(int *)data = userbits;
|
1994-03-12 10:25:16 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TIOCSFLAGS: {
|
|
|
|
int userbits, driverbits = 0;
|
|
|
|
|
1994-03-12 10:43:03 +03:00
|
|
|
error = suser(p->p_ucred, &p->p_acflag);
|
|
|
|
if (error != 0)
|
|
|
|
return(EPERM);
|
1994-03-12 10:25:16 +03:00
|
|
|
|
|
|
|
userbits = *(int *)data;
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(userbits, TIOCFLAG_SOFTCAR) ||
|
|
|
|
ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
|
|
|
|
SET(driverbits, COM_SW_SOFTCAR);
|
|
|
|
if (ISSET(userbits, TIOCFLAG_CLOCAL))
|
|
|
|
SET(driverbits, COM_SW_CLOCAL);
|
|
|
|
if (ISSET(userbits, TIOCFLAG_CRTSCTS))
|
|
|
|
SET(driverbits, COM_SW_CRTSCTS);
|
|
|
|
if (ISSET(userbits, TIOCFLAG_MDMBUF))
|
|
|
|
SET(driverbits, COM_SW_MDMBUF);
|
1994-03-12 10:25:16 +03:00
|
|
|
|
1994-03-12 10:43:03 +03:00
|
|
|
sc->sc_swflags = driverbits;
|
1994-03-12 10:25:16 +03:00
|
|
|
break;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
1994-03-08 11:12:56 +03:00
|
|
|
return ENOTTY;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-08 11:12:56 +03:00
|
|
|
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
comparam(tp, t)
|
1994-03-08 11:12:56 +03:00
|
|
|
struct tty *tp;
|
|
|
|
struct termios *t;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct com_softc *sc = comcd.cd_devs[COMUNIT(tp->t_dev)];
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = sc->sc_iobase;
|
1994-03-08 11:12:56 +03:00
|
|
|
int ospeed = comspeed(t->c_ospeed);
|
1995-10-15 22:43:04 +03:00
|
|
|
u_char lcr;
|
1995-06-05 00:39:22 +04:00
|
|
|
tcflag_t oldcflag;
|
1994-03-08 11:12:56 +03:00
|
|
|
int s;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* check requested parameters */
|
1994-03-08 11:12:56 +03:00
|
|
|
if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
|
|
|
|
return EINVAL;
|
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
lcr = sc->sc_lcr & LCR_SBREAK;
|
|
|
|
|
|
|
|
switch (ISSET(t->c_cflag, CSIZE)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case CS5:
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(lcr, LCR_5BITS);
|
1994-03-08 11:12:56 +03:00
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case CS6:
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(lcr, LCR_6BITS);
|
1994-03-08 11:12:56 +03:00
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case CS7:
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(lcr, LCR_7BITS);
|
1994-03-08 11:12:56 +03:00
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case CS8:
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(lcr, LCR_8BITS);
|
1994-03-08 11:12:56 +03:00
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(t->c_cflag, PARENB)) {
|
|
|
|
SET(lcr, LCR_PENAB);
|
|
|
|
if (!ISSET(t->c_cflag, PARODD))
|
|
|
|
SET(lcr, LCR_PEVEN);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(t->c_cflag, CSTOPB))
|
|
|
|
SET(lcr, LCR_STOPB);
|
|
|
|
|
|
|
|
sc->sc_lcr = lcr;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
s = spltty();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ospeed == 0) {
|
|
|
|
CLR(sc->sc_mcr, MCR_DTR);
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
|
|
|
}
|
1994-09-16 06:50:39 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the FIFO threshold based on the receive speed, if we are
|
|
|
|
* changing it.
|
|
|
|
*/
|
1996-02-10 23:23:18 +03:00
|
|
|
if (tp->t_ispeed != t->c_ispeed) {
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
|
1994-09-16 06:50:39 +04:00
|
|
|
outb(iobase + com_fifo,
|
1995-06-05 00:39:22 +04:00
|
|
|
FIFO_ENABLE |
|
1994-09-16 06:50:39 +04:00
|
|
|
(t->c_ispeed <= 1200 ? FIFO_TRIGGER_1 : FIFO_TRIGGER_8));
|
|
|
|
}
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1995-06-05 00:39:22 +04:00
|
|
|
if (ospeed != 0) {
|
1995-10-15 22:43:04 +03:00
|
|
|
outb(iobase + com_lcr, lcr | LCR_DLAB);
|
1995-06-05 00:39:22 +04:00
|
|
|
outb(iobase + com_dlbl, ospeed);
|
|
|
|
outb(iobase + com_dlbh, ospeed >> 8);
|
1995-10-15 22:43:04 +03:00
|
|
|
outb(iobase + com_lcr, lcr);
|
|
|
|
SET(sc->sc_mcr, MCR_DTR);
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
1995-06-05 00:39:22 +04:00
|
|
|
} else
|
1995-10-15 22:43:04 +03:00
|
|
|
outb(iobase + com_lcr, lcr);
|
1994-09-16 06:50:39 +04:00
|
|
|
|
1994-03-12 10:25:16 +03:00
|
|
|
/* When not using CRTSCTS, RTS follows DTR. */
|
1995-10-15 22:43:04 +03:00
|
|
|
if (!ISSET(t->c_cflag, CRTSCTS)) {
|
|
|
|
if (ISSET(sc->sc_mcr, MCR_DTR)) {
|
|
|
|
if (!ISSET(sc->sc_mcr, MCR_RTS)) {
|
|
|
|
SET(sc->sc_mcr, MCR_RTS);
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
|
|
|
}
|
1994-03-08 11:12:56 +03:00
|
|
|
} else {
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(sc->sc_mcr, MCR_RTS)) {
|
|
|
|
CLR(sc->sc_mcr, MCR_RTS);
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
|
|
|
}
|
1994-03-08 11:12:56 +03:00
|
|
|
}
|
1995-06-05 00:39:22 +04:00
|
|
|
sc->sc_dtr = MCR_DTR | MCR_RTS;
|
|
|
|
} else
|
|
|
|
sc->sc_dtr = MCR_DTR;
|
1994-03-18 08:13:26 +03:00
|
|
|
|
1994-07-31 15:34:38 +04:00
|
|
|
/* and copy to tty */
|
|
|
|
tp->t_ispeed = t->c_ispeed;
|
|
|
|
tp->t_ospeed = t->c_ospeed;
|
1995-06-05 00:39:22 +04:00
|
|
|
oldcflag = tp->t_cflag;
|
1994-07-31 15:34:38 +04:00
|
|
|
tp->t_cflag = t->c_cflag;
|
|
|
|
|
1995-06-05 00:39:22 +04:00
|
|
|
/*
|
|
|
|
* If DCD is off and MDMBUF is changed, ask the tty layer if we should
|
|
|
|
* stop the device.
|
|
|
|
*/
|
1995-10-15 22:43:04 +03:00
|
|
|
if (!ISSET(sc->sc_msr, MSR_DCD) &&
|
|
|
|
!ISSET(sc->sc_swflags, COM_SW_SOFTCAR) &&
|
|
|
|
ISSET(oldcflag, MDMBUF) != ISSET(tp->t_cflag, MDMBUF) &&
|
1995-06-05 00:39:22 +04:00
|
|
|
(*linesw[tp->t_line].l_modem)(tp, 0) == 0) {
|
1995-10-15 22:43:04 +03:00
|
|
|
CLR(sc->sc_mcr, sc->sc_dtr);
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
1995-06-05 00:39:22 +04:00
|
|
|
}
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
splx(s);
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1993-08-29 17:46:31 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
comstart(tp)
|
1994-03-08 11:12:56 +03:00
|
|
|
struct tty *tp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct com_softc *sc = comcd.cd_devs[COMUNIT(tp->t_dev)];
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = sc->sc_iobase;
|
1994-03-08 11:12:56 +03:00
|
|
|
int s;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
s = spltty();
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(tp->t_state, TS_TTSTOP | TS_BUSY))
|
1994-03-08 11:12:56 +03:00
|
|
|
goto out;
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(tp->t_cflag, CRTSCTS) && !ISSET(sc->sc_msr, MSR_CTS))
|
1993-03-21 12:45:37 +03:00
|
|
|
goto out;
|
1995-07-04 10:47:18 +04:00
|
|
|
if (tp->t_outq.c_cc <= tp->t_lowat) {
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(tp->t_state, TS_ASLEEP)) {
|
|
|
|
CLR(tp->t_state, TS_ASLEEP);
|
|
|
|
wakeup(&tp->t_outq);
|
1995-07-04 10:47:18 +04:00
|
|
|
}
|
|
|
|
if (tp->t_outq.c_cc == 0)
|
|
|
|
goto out;
|
|
|
|
selwakeup(&tp->t_wsel);
|
|
|
|
}
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(tp->t_state, TS_BUSY);
|
1996-01-15 02:44:34 +03:00
|
|
|
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
|
1996-01-15 02:44:34 +03:00
|
|
|
u_char buffer[1024], *cp = buffer;
|
|
|
|
int n = q_to_b(&tp->t_outq, cp, sizeof buffer);
|
|
|
|
do
|
|
|
|
outb(iobase + com_data, *cp++);
|
|
|
|
while (--n);
|
|
|
|
}
|
1996-02-10 23:23:18 +03:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_FIFO)) {
|
1994-03-08 11:12:56 +03:00
|
|
|
u_char buffer[16], *cp = buffer;
|
|
|
|
int n = q_to_b(&tp->t_outq, cp, sizeof buffer);
|
|
|
|
do {
|
|
|
|
outb(iobase + com_data, *cp++);
|
|
|
|
} while (--n);
|
|
|
|
} else
|
|
|
|
outb(iobase + com_data, getc(&tp->t_outq));
|
1993-03-21 12:45:37 +03:00
|
|
|
out:
|
|
|
|
splx(s);
|
|
|
|
}
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Stop output on a line.
|
|
|
|
*/
|
1994-03-08 11:12:56 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
comstop(tp, flag)
|
1994-03-08 11:12:56 +03:00
|
|
|
struct tty *tp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-08 11:12:56 +03:00
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
s = spltty();
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(tp->t_state, TS_BUSY))
|
|
|
|
if (!ISSET(tp->t_state, TS_TTSTOP))
|
|
|
|
SET(tp->t_state, TS_FLUSH);
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1994-08-07 15:27:51 +04:00
|
|
|
void
|
|
|
|
comdiag(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct com_softc *sc = arg;
|
1995-06-05 00:39:22 +04:00
|
|
|
int overflows, floods;
|
1994-08-07 15:27:51 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = spltty();
|
1995-06-05 00:39:22 +04:00
|
|
|
sc->sc_errors = 0;
|
1994-08-07 15:27:51 +04:00
|
|
|
overflows = sc->sc_overflows;
|
|
|
|
sc->sc_overflows = 0;
|
1995-06-05 00:39:22 +04:00
|
|
|
floods = sc->sc_floods;
|
|
|
|
sc->sc_floods = 0;
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf overflow%s\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
overflows, overflows == 1 ? "" : "s",
|
|
|
|
floods, floods == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
compoll(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
int unit;
|
|
|
|
struct com_softc *sc;
|
|
|
|
struct tty *tp;
|
|
|
|
register u_char *ibufp;
|
|
|
|
u_char *ibufend;
|
|
|
|
register int c;
|
|
|
|
int s;
|
|
|
|
static int lsrmap[8] = {
|
|
|
|
0, TTY_PE,
|
|
|
|
TTY_FE, TTY_PE|TTY_FE,
|
|
|
|
TTY_FE, TTY_PE|TTY_FE,
|
|
|
|
TTY_FE, TTY_PE|TTY_FE
|
|
|
|
};
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
if (comevents == 0) {
|
|
|
|
splx(s);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
comevents = 0;
|
1994-08-07 15:27:51 +04:00
|
|
|
splx(s);
|
|
|
|
|
1995-06-05 00:39:22 +04:00
|
|
|
for (unit = 0; unit < comcd.cd_ndevs; unit++) {
|
|
|
|
sc = comcd.cd_devs[unit];
|
|
|
|
if (sc == 0 || sc->sc_ibufp == sc->sc_ibuf)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tp = sc->sc_tty;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
ibufp = sc->sc_ibuf;
|
|
|
|
ibufend = sc->sc_ibufp;
|
|
|
|
|
1995-07-04 10:47:18 +04:00
|
|
|
if (ibufp == ibufend) {
|
|
|
|
splx(s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1995-06-05 00:39:22 +04:00
|
|
|
sc->sc_ibufp = sc->sc_ibuf = (ibufp == sc->sc_ibufs[0]) ?
|
|
|
|
sc->sc_ibufs[1] : sc->sc_ibufs[0];
|
|
|
|
sc->sc_ibufhigh = sc->sc_ibuf + COM_IHIGHWATER;
|
|
|
|
sc->sc_ibufend = sc->sc_ibuf + COM_IBUFSIZE;
|
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
if (tp == 0 || !ISSET(tp->t_state, TS_ISOPEN)) {
|
1995-06-05 00:39:22 +04:00
|
|
|
splx(s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(tp->t_cflag, CRTSCTS) &&
|
|
|
|
!ISSET(sc->sc_mcr, MCR_RTS)) {
|
|
|
|
/* XXX */
|
|
|
|
SET(sc->sc_mcr, MCR_RTS);
|
|
|
|
outb(sc->sc_iobase + com_mcr, sc->sc_mcr);
|
|
|
|
}
|
1995-06-05 00:39:22 +04:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
while (ibufp < ibufend) {
|
|
|
|
c = *ibufp++;
|
|
|
|
if (*ibufp & LSR_OE) {
|
|
|
|
sc->sc_overflows++;
|
|
|
|
if (sc->sc_errors++ == 0)
|
|
|
|
timeout(comdiag, sc, 60 * hz);
|
|
|
|
}
|
|
|
|
/* This is ugly, but fast. */
|
|
|
|
c |= lsrmap[(*ibufp++ & (LSR_BI|LSR_FE|LSR_PE)) >> 2];
|
|
|
|
(*linesw[tp->t_line].l_rint)(c, tp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
timeout(compoll, NULL, 1);
|
1994-08-07 15:27:51 +04:00
|
|
|
}
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
comintr(arg)
|
|
|
|
void *arg;
|
1994-03-08 11:12:56 +03:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
struct com_softc *sc = arg;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = sc->sc_iobase;
|
1994-03-08 11:12:56 +03:00
|
|
|
struct tty *tp;
|
1995-05-28 07:26:37 +04:00
|
|
|
u_char lsr, data, msr, delta;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(inb(iobase + com_iir), IIR_NOPEND))
|
1995-05-28 07:26:37 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
tp = sc->sc_tty;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
|
|
|
for (;;) {
|
1995-05-28 07:26:37 +04:00
|
|
|
lsr = inb(iobase + com_lsr);
|
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(lsr, LSR_RCV_MASK)) {
|
1995-06-05 00:39:22 +04:00
|
|
|
register u_char *p = sc->sc_ibufp;
|
|
|
|
|
|
|
|
comevents = 1;
|
1995-05-28 07:26:37 +04:00
|
|
|
do {
|
1995-10-15 22:43:04 +03:00
|
|
|
data = ISSET(lsr, LSR_RXRDY) ?
|
|
|
|
inb(iobase + com_data) : 0;
|
|
|
|
if (ISSET(lsr, LSR_BI)) {
|
1995-06-05 00:39:22 +04:00
|
|
|
#ifdef DDB
|
1995-06-05 00:50:14 +04:00
|
|
|
if (sc->sc_dev.dv_unit == comconsole) {
|
|
|
|
Debugger();
|
|
|
|
goto next;
|
1995-06-05 23:08:09 +04:00
|
|
|
}
|
1994-03-08 11:12:56 +03:00
|
|
|
#endif
|
1995-06-05 23:08:09 +04:00
|
|
|
data = '\0';
|
1995-10-15 22:43:04 +03:00
|
|
|
}
|
1995-06-05 00:39:22 +04:00
|
|
|
if (p >= sc->sc_ibufend) {
|
|
|
|
sc->sc_floods++;
|
|
|
|
if (sc->sc_errors++ == 0)
|
|
|
|
timeout(comdiag, sc, 60 * hz);
|
|
|
|
} else {
|
|
|
|
*p++ = data;
|
|
|
|
*p++ = lsr;
|
|
|
|
if (p == sc->sc_ibufhigh &&
|
1995-10-15 22:43:04 +03:00
|
|
|
ISSET(tp->t_cflag, CRTSCTS)) {
|
|
|
|
/* XXX */
|
|
|
|
CLR(sc->sc_mcr, MCR_RTS);
|
1995-06-05 00:39:22 +04:00
|
|
|
outb(iobase + com_mcr,
|
1995-10-15 22:43:04 +03:00
|
|
|
sc->sc_mcr);
|
|
|
|
}
|
1995-05-28 07:26:37 +04:00
|
|
|
}
|
1995-06-05 00:39:22 +04:00
|
|
|
next:
|
1995-05-28 07:26:37 +04:00
|
|
|
lsr = inb(iobase + com_lsr);
|
1995-10-15 22:43:04 +03:00
|
|
|
} while (ISSET(lsr, LSR_RCV_MASK));
|
1995-06-05 00:39:22 +04:00
|
|
|
|
|
|
|
sc->sc_ibufp = p;
|
1995-05-28 07:26:37 +04:00
|
|
|
}
|
1995-10-15 22:43:04 +03:00
|
|
|
#if 0
|
|
|
|
else if (ISSET(lsr, LSR_BI|LSR_FE|LSR_PE|LSR_OE))
|
|
|
|
printf("weird lsr %02x\n", lsr);
|
|
|
|
#endif
|
1995-05-28 07:26:37 +04:00
|
|
|
|
|
|
|
msr = inb(iobase + com_msr);
|
|
|
|
|
|
|
|
if (msr != sc->sc_msr) {
|
|
|
|
delta = msr ^ sc->sc_msr;
|
|
|
|
sc->sc_msr = msr;
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(delta, MSR_DCD) &&
|
|
|
|
!ISSET(sc->sc_swflags, COM_SW_SOFTCAR) &&
|
|
|
|
(*linesw[tp->t_line].l_modem)(tp, ISSET(msr, MSR_DCD)) == 0) {
|
|
|
|
CLR(sc->sc_mcr, sc->sc_dtr);
|
|
|
|
outb(iobase + com_mcr, sc->sc_mcr);
|
1995-05-28 07:26:37 +04:00
|
|
|
}
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(delta & msr, MSR_CTS) &&
|
|
|
|
ISSET(tp->t_cflag, CRTSCTS)) {
|
1995-05-28 07:26:37 +04:00
|
|
|
/* the line is up and we want to do rts/cts flow control */
|
1995-06-05 00:39:22 +04:00
|
|
|
(*linesw[tp->t_line].l_start)(tp);
|
1995-05-28 07:26:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
if (ISSET(lsr, LSR_TXRDY) && ISSET(tp->t_state, TS_BUSY)) {
|
|
|
|
CLR(tp->t_state, TS_BUSY);
|
|
|
|
if (ISSET(tp->t_state, TS_FLUSH))
|
|
|
|
CLR(tp->t_state, TS_FLUSH);
|
|
|
|
else
|
|
|
|
(*linesw[tp->t_line].l_start)(tp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ISSET(inb(iobase + com_iir), IIR_NOPEND))
|
1995-05-28 07:26:37 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Following are all routines needed for COM to act as console
|
|
|
|
*/
|
1994-02-01 06:42:08 +03:00
|
|
|
#include <dev/cons.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-04-10 05:05:55 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
comcnprobe(cp)
|
|
|
|
struct consdev *cp;
|
|
|
|
{
|
1994-03-08 11:12:56 +03:00
|
|
|
|
|
|
|
if (!comprobe1(CONADDR)) {
|
|
|
|
cp->cn_pri = CN_DEAD;
|
|
|
|
return;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* locate the major number */
|
|
|
|
for (commajor = 0; commajor < nchrdev; commajor++)
|
|
|
|
if (cdevsw[commajor].d_open == comopen)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* initialize required fields */
|
1994-03-29 08:35:37 +04:00
|
|
|
cp->cn_dev = makedev(commajor, CONUNIT);
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef COMCONSOLE
|
|
|
|
cp->cn_pri = CN_REMOTE; /* Force a serial port console */
|
|
|
|
#else
|
|
|
|
cp->cn_pri = CN_NORMAL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1995-04-10 05:05:55 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
comcninit(cp)
|
|
|
|
struct consdev *cp;
|
|
|
|
{
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
cominit(CONUNIT, comdefaultrate);
|
|
|
|
comconsole = CONUNIT;
|
1994-03-08 11:12:56 +03:00
|
|
|
comconsinit = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cominit(unit, rate)
|
|
|
|
int unit, rate;
|
|
|
|
{
|
1994-03-08 11:12:56 +03:00
|
|
|
int s = splhigh();
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = CONADDR;
|
1994-03-08 11:12:56 +03:00
|
|
|
u_char stat;
|
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
outb(iobase + com_lcr, LCR_DLAB);
|
1994-03-08 11:12:56 +03:00
|
|
|
rate = comspeed(comdefaultrate);
|
|
|
|
outb(iobase + com_dlbl, rate);
|
|
|
|
outb(iobase + com_dlbh, rate >> 8);
|
1995-10-15 22:43:04 +03:00
|
|
|
outb(iobase + com_lcr, LCR_8BITS);
|
1994-03-08 11:12:56 +03:00
|
|
|
outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY);
|
|
|
|
outb(iobase + com_fifo, FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_4);
|
|
|
|
stat = inb(iobase + com_iir);
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
comcngetc(dev)
|
1994-03-08 11:12:56 +03:00
|
|
|
dev_t dev;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-08 11:12:56 +03:00
|
|
|
int s = splhigh();
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = CONADDR;
|
1994-03-08 11:12:56 +03:00
|
|
|
u_char stat, c;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
while (!ISSET(stat = inb(iobase + com_lsr), LSR_RXRDY))
|
1993-03-21 12:45:37 +03:00
|
|
|
;
|
1994-03-08 11:12:56 +03:00
|
|
|
c = inb(iobase + com_data);
|
|
|
|
stat = inb(iobase + com_iir);
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
1994-03-08 11:12:56 +03:00
|
|
|
return c;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Console kernel output character routine.
|
|
|
|
*/
|
1995-04-10 05:05:55 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
comcnputc(dev, c)
|
|
|
|
dev_t dev;
|
1994-03-08 11:12:56 +03:00
|
|
|
int c;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
int s = splhigh();
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = CONADDR;
|
1994-03-08 11:12:56 +03:00
|
|
|
u_char stat;
|
|
|
|
register int timo;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#ifdef KGDB
|
|
|
|
if (dev != kgdb_dev)
|
|
|
|
#endif
|
|
|
|
if (comconsinit == 0) {
|
1994-03-08 11:12:56 +03:00
|
|
|
(void) cominit(COMUNIT(dev), comdefaultrate);
|
1993-03-21 12:45:37 +03:00
|
|
|
comconsinit = 1;
|
|
|
|
}
|
|
|
|
/* wait for any pending transmission to finish */
|
|
|
|
timo = 50000;
|
1995-10-15 22:43:04 +03:00
|
|
|
while (!ISSET(stat = inb(iobase + com_lsr), LSR_TXRDY) && --timo)
|
1993-03-21 12:45:37 +03:00
|
|
|
;
|
1994-03-08 11:12:56 +03:00
|
|
|
outb(iobase + com_data, c);
|
1993-03-21 12:45:37 +03:00
|
|
|
/* wait for this transmission to complete */
|
|
|
|
timo = 1500000;
|
1995-10-15 22:43:04 +03:00
|
|
|
while (!ISSET(stat = inb(iobase + com_lsr), LSR_TXRDY) && --timo)
|
1993-03-21 12:45:37 +03:00
|
|
|
;
|
|
|
|
/* clear any interrupts generated by this transmission */
|
1994-03-08 11:12:56 +03:00
|
|
|
stat = inb(iobase + com_iir);
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
1994-10-26 21:06:30 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
comcnpollc(dev, on)
|
|
|
|
dev_t dev;
|
|
|
|
int on;
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|