2000-11-02 02:54:57 +03:00
|
|
|
/* $NetBSD: com.c,v 1.181 2000/11/01 23:54:57 eeh Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1999-02-04 02:57:27 +03:00
|
|
|
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
|
1998-08-15 21:47:15 +04:00
|
|
|
* All rights reserved.
|
1997-04-05 00:56:34 +04:00
|
|
|
*
|
1998-08-15 21:47:15 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum.
|
1997-04-05 00:56:34 +04:00
|
|
|
*
|
|
|
|
* 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:
|
1998-08-15 21:47:15 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1997-04-05 00:56:34 +04:00
|
|
|
*
|
1998-08-15 21:47:15 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
1997-04-05 00:56:34 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
*/
|
|
|
|
|
2000-09-22 03:27:32 +04:00
|
|
|
#if defined(__sparc__) || defined(__sparc_v9__)
|
|
|
|
#define DDB_BREAK_CHAR 1 /* L1 or Stop key */
|
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1997-04-05 00:56:34 +04:00
|
|
|
* COM driver, uses National Semiconductor NS16450/NS16550AF UART
|
1997-10-19 18:26:16 +04:00
|
|
|
* Supports automatic hardware flow control on StarTech ST16C650A UART
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1997-10-19 15:45:33 +04:00
|
|
|
|
1998-07-05 02:18:13 +04:00
|
|
|
#include "opt_ddb.h"
|
2000-08-03 04:30:47 +04:00
|
|
|
#include "opt_ddbparam.h"
|
1999-11-22 06:53:38 +03:00
|
|
|
#include "opt_com.h"
|
1998-07-05 02:18:13 +04:00
|
|
|
|
1997-10-19 15:45:33 +04:00
|
|
|
#include "rnd.h"
|
|
|
|
#if NRND > 0 && defined(RND_COM)
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
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>
|
1997-11-03 09:12:02 +03:00
|
|
|
#include <sys/malloc.h>
|
1998-06-10 16:06:23 +04:00
|
|
|
#include <sys/timepps.h>
|
1998-11-19 02:58:52 +03:00
|
|
|
#include <sys/vnode.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1996-05-13 03:51:23 +04:00
|
|
|
#include <machine/intr.h>
|
1997-04-05 00:56:34 +04:00
|
|
|
#include <machine/bus.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1997-10-16 04:01:00 +04:00
|
|
|
#include <dev/ic/comreg.h>
|
|
|
|
#include <dev/ic/comvar.h>
|
1995-06-28 08:30:30 +04:00
|
|
|
#include <dev/ic/ns16550reg.h>
|
1997-10-19 18:26:16 +04:00
|
|
|
#include <dev/ic/st16650reg.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
|
1997-08-23 18:01:32 +04:00
|
|
|
#include <dev/cons.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1996-03-17 16:38:14 +03:00
|
|
|
#include "com.h"
|
|
|
|
|
1996-03-10 12:01:20 +03:00
|
|
|
#ifdef COM_HAYESP
|
1996-10-22 02:34:38 +04:00
|
|
|
int comprobeHAYESP __P((bus_space_handle_t hayespioh, struct com_softc *sc));
|
1996-03-10 12:01:20 +03:00
|
|
|
#endif
|
1997-07-06 00:52:40 +04:00
|
|
|
|
1997-08-14 20:15:15 +04:00
|
|
|
#if defined(DDB) || defined(KGDB)
|
|
|
|
static void com_enable_debugport __P((struct com_softc *));
|
|
|
|
#endif
|
1998-02-02 02:33:01 +03:00
|
|
|
void com_config __P((struct com_softc *));
|
1998-03-21 07:02:47 +03:00
|
|
|
void com_shutdown __P((struct com_softc *));
|
1997-09-17 00:34:23 +04:00
|
|
|
int comspeed __P((long, long));
|
1997-08-23 18:01:32 +04:00
|
|
|
static u_char cflag2lcr __P((tcflag_t));
|
1996-04-30 00:02:32 +04:00
|
|
|
int comparam __P((struct tty *, struct termios *));
|
|
|
|
void comstart __P((struct tty *));
|
1997-04-05 00:56:34 +04:00
|
|
|
void comstop __P((struct tty *, int));
|
|
|
|
int comhwiflow __P((struct tty *, int));
|
|
|
|
|
|
|
|
void com_loadchannelregs __P((struct com_softc *));
|
1997-06-15 15:18:59 +04:00
|
|
|
void com_hwiflow __P((struct com_softc *));
|
1997-04-05 00:56:34 +04:00
|
|
|
void com_break __P((struct com_softc *, int));
|
|
|
|
void com_modem __P((struct com_softc *, int));
|
2000-09-18 02:07:39 +04:00
|
|
|
void tiocm_to_com __P((struct com_softc *, u_long, int));
|
1999-02-04 02:57:27 +03:00
|
|
|
int com_to_tiocm __P((struct com_softc *));
|
1997-04-05 00:56:34 +04:00
|
|
|
void com_iflush __P((struct com_softc *));
|
1996-04-30 00:02:32 +04:00
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
int com_common_getc __P((bus_space_tag_t, bus_space_handle_t));
|
|
|
|
void com_common_putc __P((bus_space_tag_t, bus_space_handle_t, int));
|
|
|
|
|
1996-04-30 00:02:32 +04:00
|
|
|
/* XXX: These belong elsewhere */
|
|
|
|
cdev_decl(com);
|
|
|
|
bdev_decl(com);
|
|
|
|
|
|
|
|
int comcngetc __P((dev_t));
|
|
|
|
void comcnputc __P((dev_t, int));
|
|
|
|
void comcnpollc __P((dev_t, int));
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
#define integrate static inline
|
1997-11-03 09:12:02 +03:00
|
|
|
#ifdef __GENERIC_SOFT_INTERRUPTS
|
|
|
|
void comsoft __P((void *));
|
|
|
|
#else
|
1998-02-03 02:01:02 +03:00
|
|
|
#ifndef __NO_SOFT_SERIAL_INTERRUPT
|
1997-11-03 09:12:02 +03:00
|
|
|
void comsoft __P((void));
|
|
|
|
#else
|
|
|
|
void comsoft __P((void *));
|
2000-03-23 10:01:25 +03:00
|
|
|
struct callout comsoft_callout = CALLOUT_INITIALIZER;
|
1997-11-03 09:12:02 +03:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
integrate void com_rxsoft __P((struct com_softc *, struct tty *));
|
|
|
|
integrate void com_txsoft __P((struct com_softc *, struct tty *));
|
|
|
|
integrate void com_stsoft __P((struct com_softc *, struct tty *));
|
1997-06-15 15:18:59 +04:00
|
|
|
integrate void com_schedrx __P((struct com_softc *));
|
1997-11-03 09:12:02 +03:00
|
|
|
void comdiag __P((void *));
|
|
|
|
|
1998-01-12 12:23:08 +03:00
|
|
|
extern struct cfdriver com_cd;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
/*
|
|
|
|
* Make this an option variable one can patch.
|
|
|
|
* But be warned: this must be a power of 2!
|
|
|
|
*/
|
|
|
|
u_int com_rbuf_size = COM_RING_SIZE;
|
|
|
|
|
|
|
|
/* Stop input when 3/4 of the ring is full; restart when only 1/4 is full. */
|
|
|
|
u_int com_rbuf_hiwat = (COM_RING_SIZE * 1) / 4;
|
|
|
|
u_int com_rbuf_lowat = (COM_RING_SIZE * 3) / 4;
|
|
|
|
|
2000-09-22 18:46:38 +04:00
|
|
|
static bus_addr_t comconsaddr;
|
1997-08-23 18:01:32 +04:00
|
|
|
static bus_space_tag_t comconstag;
|
|
|
|
static bus_space_handle_t comconsioh;
|
|
|
|
static int comconsattached;
|
|
|
|
static int comconsrate;
|
|
|
|
static tcflag_t comconscflag;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
1998-06-10 16:06:23 +04:00
|
|
|
static int ppscap =
|
|
|
|
PPS_TSFMT_TSPEC |
|
|
|
|
PPS_CAPTUREASSERT |
|
|
|
|
PPS_CAPTURECLEAR |
|
|
|
|
#ifdef PPS_SYNC
|
|
|
|
PPS_HARDPPSONASSERT | PPS_HARDPPSONCLEAR |
|
|
|
|
#endif /* PPS_SYNC */
|
|
|
|
PPS_OFFSETASSERT | PPS_OFFSETCLEAR;
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
#ifndef __GENERIC_SOFT_INTERRUPTS
|
1998-02-03 02:01:02 +03:00
|
|
|
#ifdef __NO_SOFT_SERIAL_INTERRUPT
|
1997-04-05 00:56:34 +04:00
|
|
|
volatile int com_softintr_scheduled;
|
|
|
|
#endif
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#ifdef KGDB
|
1997-07-06 00:52:40 +04:00
|
|
|
#include <sys/kgdb.h>
|
|
|
|
|
2000-09-22 18:46:38 +04:00
|
|
|
static bus_addr_t com_kgdb_addr;
|
1997-08-23 18:01:32 +04:00
|
|
|
static bus_space_tag_t com_kgdb_iot;
|
|
|
|
static bus_space_handle_t com_kgdb_ioh;
|
|
|
|
static int com_kgdb_attached;
|
1997-07-06 00:52:40 +04:00
|
|
|
|
|
|
|
int com_kgdb_getc __P((void *));
|
|
|
|
void com_kgdb_putc __P((void *, int));
|
|
|
|
#endif /* KGDB */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
#define COMUNIT_MASK 0x7ffff
|
|
|
|
#define COMDIALOUT_MASK 0x80000
|
|
|
|
|
|
|
|
#define COMUNIT(x) (minor(x) & COMUNIT_MASK)
|
|
|
|
#define COMDIALOUT(x) (minor(x) & COMDIALOUT_MASK)
|
|
|
|
|
|
|
|
#define COM_ISALIVE(sc) ((sc)->enabled != 0 && \
|
|
|
|
ISSET((sc)->sc_dev.dv_flags, DVF_ACTIVE))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-04-19 02:02:47 +04:00
|
|
|
#define BR BUS_SPACE_BARRIER_READ
|
|
|
|
#define BW BUS_SPACE_BARRIER_WRITE
|
|
|
|
#define COM_BARRIER(t, h, f) bus_space_barrier((t), (h), 0, COM_NPORTS, (f))
|
|
|
|
|
2000-09-23 21:17:11 +04:00
|
|
|
#if (defined(MULTIPROCESSOR) || defined(LOCKDEBUG)) && defined(COM_MPLOCK)
|
|
|
|
|
|
|
|
#define COM_LOCK(sc) simple_lock(&(sc)->sc_lock)
|
|
|
|
#define COM_UNLOCK(sc) simple_unlock(&(sc)->sc_lock)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define COM_LOCK(sc)
|
|
|
|
#define COM_UNLOCK(sc)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1997-09-17 00:34:23 +04:00
|
|
|
comspeed(speed, frequency)
|
|
|
|
long speed, frequency;
|
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;
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
#if 0
|
1994-03-08 11:12:56 +03:00
|
|
|
if (speed == 0)
|
1997-04-05 00:56:34 +04:00
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
if (speed <= 0)
|
|
|
|
return (-1);
|
1997-09-17 00:34:23 +04:00
|
|
|
x = divrnd(frequency / 16, speed);
|
1994-03-08 11:12:56 +03:00
|
|
|
if (x <= 0)
|
1997-04-05 00:56:34 +04:00
|
|
|
return (-1);
|
1997-10-19 03:11:45 +04:00
|
|
|
err = divrnd(((quad_t)frequency) * 1000 / 16, speed * x) - 1000;
|
1994-03-08 11:12:56 +03:00
|
|
|
if (err < 0)
|
|
|
|
err = -err;
|
|
|
|
if (err > COM_TOLERANCE)
|
1997-04-05 00:56:34 +04:00
|
|
|
return (-1);
|
|
|
|
return (x);
|
1994-03-08 11:12:56 +03:00
|
|
|
|
2000-05-03 23:19:04 +04:00
|
|
|
#undef divrnd
|
1994-03-08 11:12:56 +03:00
|
|
|
}
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
#ifdef COM_DEBUG
|
1997-06-15 15:18:59 +04:00
|
|
|
int com_debug = 0;
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
void comstatus __P((struct com_softc *, char *));
|
|
|
|
void
|
|
|
|
comstatus(sc, str)
|
|
|
|
struct com_softc *sc;
|
|
|
|
char *str;
|
|
|
|
{
|
|
|
|
struct tty *tp = sc->sc_tty;
|
|
|
|
|
|
|
|
printf("%s: %s %sclocal %sdcd %sts_carr_on %sdtr %stx_stopped\n",
|
|
|
|
sc->sc_dev.dv_xname, str,
|
|
|
|
ISSET(tp->t_cflag, CLOCAL) ? "+" : "-",
|
|
|
|
ISSET(sc->sc_msr, MSR_DCD) ? "+" : "-",
|
|
|
|
ISSET(tp->t_state, TS_CARR_ON) ? "+" : "-",
|
|
|
|
ISSET(sc->sc_mcr, MCR_DTR) ? "+" : "-",
|
|
|
|
sc->sc_tx_stopped ? "+" : "-");
|
|
|
|
|
1997-06-15 15:18:59 +04:00
|
|
|
printf("%s: %s %scrtscts %scts %sts_ttstop %srts %xrx_flags\n",
|
1997-04-05 00:56:34 +04:00
|
|
|
sc->sc_dev.dv_xname, str,
|
|
|
|
ISSET(tp->t_cflag, CRTSCTS) ? "+" : "-",
|
|
|
|
ISSET(sc->sc_msr, MSR_CTS) ? "+" : "-",
|
|
|
|
ISSET(tp->t_state, TS_TTSTOP) ? "+" : "-",
|
|
|
|
ISSET(sc->sc_mcr, MCR_RTS) ? "+" : "-",
|
1997-06-15 15:18:59 +04:00
|
|
|
sc->sc_rx_flags);
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1998-09-17 01:30:58 +04:00
|
|
|
comprobe1(iot, ioh)
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
1994-03-08 11:12:56 +03:00
|
|
|
{
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* force access to id reg */
|
1999-02-12 15:45:48 +03:00
|
|
|
bus_space_write_1(iot, ioh, com_lcr, LCR_8BITS);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_iir, 0);
|
1999-02-12 15:45:48 +03:00
|
|
|
if ((bus_space_read_1(iot, ioh, com_lcr) != LCR_8BITS) ||
|
|
|
|
(bus_space_read_1(iot, ioh, com_iir) & 0x38))
|
1997-04-05 00:56:34 +04:00
|
|
|
return (0);
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
|
|
|
int
|
1996-03-10 12:01:20 +03:00
|
|
|
comprobeHAYESP(hayespioh, sc)
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_handle_t hayespioh;
|
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 };
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
1996-01-15 02:44:34 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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-10-22 02:34:38 +04:00
|
|
|
if ((bus_space_read_1(iot, hayespioh, 0) & 0xf3) == 0)
|
1997-04-05 00:56:34 +04:00
|
|
|
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-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETDIPS);
|
|
|
|
dips = bus_space_read_1(iot, hayespioh, 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])
|
1997-04-05 00:56:34 +04:00
|
|
|
return (0);
|
1996-02-10 23:23:18 +03:00
|
|
|
|
1996-10-13 05:37:04 +04:00
|
|
|
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-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, hayespioh, HAYESP_CMD1, HAYESP_GETTEST);
|
1997-04-05 00:56:34 +04:00
|
|
|
val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS1); /* Clear reg1 */
|
1996-10-22 02:34:38 +04:00
|
|
|
val = bus_space_read_1(iot, hayespioh, HAYESP_STATUS2);
|
1996-01-15 02:44:34 +03:00
|
|
|
if ((val & 0x70) < 0x20) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("-old (%o)", val & 0x70);
|
1996-01-15 02:44:34 +03:00
|
|
|
/* we do not support the necessary features */
|
1997-04-05 00:56:34 +04:00
|
|
|
return (0);
|
1996-01-15 02:44:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for ability to emulate 16550: bit 8 == 1 */
|
|
|
|
if ((dips & 0x80) == 0) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" slave");
|
1996-01-15 02:44:34 +03:00
|
|
|
/* XXX Does slave really mean no 16550 support?? */
|
1997-04-05 00:56:34 +04: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);
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(", 1024 byte fifo\n");
|
1997-04-05 00:56:34 +04:00
|
|
|
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
|
|
|
|
1997-08-14 20:15:15 +04:00
|
|
|
#if defined(DDB) || defined(KGDB)
|
|
|
|
static void
|
|
|
|
com_enable_debugport(sc)
|
|
|
|
struct com_softc *sc;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
/* Turn on line break interrupt, set carrier. */
|
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1997-08-14 20:15:15 +04:00
|
|
|
sc->sc_ier = IER_ERXRDY;
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
|
|
|
|
SET(sc->sc_mcr, MCR_DTR | MCR_RTS);
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_mcr, sc->sc_mcr);
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1997-08-14 20:15:15 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
void
|
1997-04-05 00:56:34 +04:00
|
|
|
com_attach_subr(sc)
|
|
|
|
struct com_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-09-22 18:46:38 +04:00
|
|
|
bus_addr_t iobase = sc->sc_iobase;
|
1997-04-05 00:56:34 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1997-11-03 09:12:02 +03:00
|
|
|
struct tty *tp;
|
1997-10-21 05:25:41 +04:00
|
|
|
#ifdef COM16650
|
1997-10-19 18:26:16 +04:00
|
|
|
u_int8_t lcr;
|
1997-10-21 05:25:41 +04:00
|
|
|
#endif
|
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
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_init(&sc->sc_diag_callout);
|
2000-09-26 18:12:42 +04:00
|
|
|
#if (defined(MULTIPROCESSOR) || defined(LOCKDEBUG)) && defined(COM_MPLOCK)
|
2000-09-23 21:17:11 +04:00
|
|
|
simple_lock_init(&sc->sc_lock);
|
|
|
|
#endif
|
2000-03-23 10:01:25 +03:00
|
|
|
|
1997-10-20 00:01:08 +04:00
|
|
|
/* Disable interrupts before configuring the device. */
|
|
|
|
sc->sc_ier = 0;
|
1998-02-02 02:33:01 +03:00
|
|
|
bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
|
1997-10-20 00:01:08 +04:00
|
|
|
|
1997-08-23 18:01:32 +04:00
|
|
|
if (iot == comconstag && iobase == comconsaddr) {
|
1997-08-16 12:33:08 +04:00
|
|
|
comconsattached = 1;
|
|
|
|
|
1996-12-14 13:46:38 +03:00
|
|
|
/* Make sure the console is always "hardwired". */
|
1996-03-10 12:01:20 +03:00
|
|
|
delay(1000); /* wait for output to finish */
|
|
|
|
SET(sc->sc_hwflags, COM_HW_CONSOLE);
|
1997-04-05 00:56:34 +04:00
|
|
|
SET(sc->sc_swflags, TIOCFLAG_SOFTCAR);
|
1996-03-10 12:01:20 +03:00
|
|
|
}
|
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. */
|
1996-03-10 12:01:20 +03:00
|
|
|
for (hayespp = hayesp_ports; *hayespp != 0; hayespp++) {
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_handle_t hayespioh;
|
1996-03-10 12:01:20 +03:00
|
|
|
|
|
|
|
#define HAYESP_NPORTS 8 /* XXX XXX XXX ??? ??? ??? */
|
1996-10-22 04:45:25 +04:00
|
|
|
if (bus_space_map(iot, *hayespp, HAYESP_NPORTS, 0, &hayespioh))
|
1996-03-10 12:01:20 +03:00
|
|
|
continue;
|
|
|
|
if (comprobeHAYESP(hayespioh, sc)) {
|
|
|
|
sc->sc_hayespioh = hayespioh;
|
1997-04-05 00:56:34 +04:00
|
|
|
sc->sc_fifolen = 1024;
|
|
|
|
|
1996-02-10 23:23:18 +03:00
|
|
|
break;
|
|
|
|
}
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_unmap(iot, hayespioh, HAYESP_NPORTS);
|
1996-03-10 12:01:20 +03:00
|
|
|
}
|
1996-02-10 23:23:18 +03:00
|
|
|
/* No ESP; look for other things. */
|
1998-02-02 02:33:01 +03:00
|
|
|
if (!ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
|
1996-02-10 23:23:18 +03:00
|
|
|
#endif
|
1997-04-05 00:56:34 +04:00
|
|
|
sc->sc_fifolen = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
/* look for a NS 16550AF UART with FIFOs */
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_fifo,
|
1994-03-08 11:12:56 +03:00
|
|
|
FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(100);
|
1997-04-05 00:56:34 +04:00
|
|
|
if (ISSET(bus_space_read_1(iot, ioh, com_iir), IIR_FIFO_MASK)
|
|
|
|
== IIR_FIFO_MASK)
|
|
|
|
if (ISSET(bus_space_read_1(iot, ioh, com_fifo), FIFO_TRIGGER_14)
|
|
|
|
== FIFO_TRIGGER_14) {
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(sc->sc_hwflags, COM_HW_FIFO);
|
1997-10-19 18:26:16 +04:00
|
|
|
|
1997-10-21 05:25:41 +04:00
|
|
|
#ifdef COM16650
|
1997-10-19 18:26:16 +04:00
|
|
|
/*
|
|
|
|
* IIR changes into the EFR if LCR is set to LCR_EERS
|
|
|
|
* on 16650s. We also know IIR != 0 at this point.
|
|
|
|
* Write 0 into the EFR, and read it. If the result
|
|
|
|
* is 0, we have a 16650.
|
|
|
|
*
|
|
|
|
* Older 16650s were broken; the test to detect them
|
|
|
|
* is taken from the Linux driver. Apparently
|
|
|
|
* setting DLAB enable gives access to the EFR on
|
|
|
|
* these chips.
|
|
|
|
*/
|
|
|
|
lcr = bus_space_read_1(iot, ioh, com_lcr);
|
|
|
|
bus_space_write_1(iot, ioh, com_lcr, LCR_EERS);
|
|
|
|
bus_space_write_1(iot, ioh, com_efr, 0);
|
|
|
|
if (bus_space_read_1(iot, ioh, com_efr) == 0) {
|
|
|
|
bus_space_write_1(iot, ioh, com_lcr,
|
|
|
|
lcr | LCR_DLAB);
|
|
|
|
if (bus_space_read_1(iot, ioh, com_efr) == 0) {
|
|
|
|
CLR(sc->sc_hwflags, COM_HW_FIFO);
|
|
|
|
sc->sc_fifolen = 0;
|
|
|
|
} else {
|
|
|
|
SET(sc->sc_hwflags, COM_HW_FLOW);
|
|
|
|
sc->sc_fifolen = 32;
|
|
|
|
}
|
1997-10-21 05:25:41 +04:00
|
|
|
} else
|
|
|
|
#endif
|
1997-10-19 18:26:16 +04:00
|
|
|
sc->sc_fifolen = 16;
|
|
|
|
|
1997-10-21 05:25:41 +04:00
|
|
|
#ifdef COM16650
|
1997-10-29 21:28:07 +03:00
|
|
|
bus_space_write_1(iot, ioh, com_lcr, lcr);
|
|
|
|
if (sc->sc_fifolen == 0)
|
|
|
|
printf(": st16650, broken fifo\n");
|
|
|
|
else if (sc->sc_fifolen == 32)
|
|
|
|
printf(": st16650a, working fifo\n");
|
|
|
|
else
|
1997-10-21 05:25:41 +04:00
|
|
|
#endif
|
1997-10-29 21:28:07 +03:00
|
|
|
printf(": ns16550a, working fifo\n");
|
1994-03-08 11:12:56 +03:00
|
|
|
} else
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(": ns16550, broken fifo\n");
|
1994-03-08 11:12:56 +03:00
|
|
|
else
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(": ns8250 or ns16450, no fifo\n");
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_fifo, 0);
|
2000-01-24 00:06:01 +03:00
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_TXFIFO_DISABLE)) {
|
|
|
|
sc->sc_fifolen = 1;
|
|
|
|
printf("%s: txfifo disabled\n", sc->sc_dev.dv_xname);
|
|
|
|
}
|
1996-02-10 23:23:18 +03:00
|
|
|
#ifdef COM_HAYESP
|
|
|
|
}
|
|
|
|
#endif
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
tp = ttymalloc();
|
|
|
|
tp->t_oproc = comstart;
|
|
|
|
tp->t_param = comparam;
|
|
|
|
tp->t_hwiflow = comhwiflow;
|
|
|
|
|
|
|
|
sc->sc_tty = tp;
|
1998-09-09 09:17:53 +04:00
|
|
|
sc->sc_rbuf = malloc(com_rbuf_size << 1, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (sc->sc_rbuf == NULL) {
|
|
|
|
printf("%s: unable to allocate ring buffer\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
1997-11-03 09:12:02 +03:00
|
|
|
sc->sc_ebuf = sc->sc_rbuf + (com_rbuf_size << 1);
|
1998-09-09 09:17:53 +04:00
|
|
|
|
|
|
|
tty_attach(tp);
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
if (!ISSET(sc->sc_hwflags, COM_HW_NOIEN))
|
|
|
|
SET(sc->sc_mcr, MCR_IENABLE);
|
1994-04-07 10:48:19 +04:00
|
|
|
|
1996-12-14 13:46:38 +03:00
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
|
1997-08-23 18:01:32 +04:00
|
|
|
int maj;
|
|
|
|
|
|
|
|
/* locate the major number */
|
|
|
|
for (maj = 0; maj < nchrdev; maj++)
|
|
|
|
if (cdevsw[maj].d_open == comopen)
|
|
|
|
break;
|
|
|
|
|
|
|
|
cn_tab->cn_dev = makedev(maj, sc->sc_dev.dv_unit);
|
1998-02-02 02:33:01 +03:00
|
|
|
|
1996-12-14 13:46:38 +03:00
|
|
|
printf("%s: console\n", sc->sc_dev.dv_xname);
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef KGDB
|
1997-07-06 00:52:40 +04:00
|
|
|
/*
|
|
|
|
* Allow kgdb to "take over" this port. If this is
|
|
|
|
* the kgdb device, it has exclusive use.
|
|
|
|
*/
|
1997-08-23 18:01:32 +04:00
|
|
|
if (iot == com_kgdb_iot && iobase == com_kgdb_addr) {
|
|
|
|
com_kgdb_attached = 1;
|
|
|
|
|
1997-08-14 20:15:15 +04:00
|
|
|
SET(sc->sc_hwflags, COM_HW_KGDB);
|
1997-08-12 21:25:43 +04:00
|
|
|
printf("%s: kgdb\n", sc->sc_dev.dv_xname);
|
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __GENERIC_SOFT_INTERRUPTS
|
|
|
|
sc->sc_si = softintr_establish(IPL_SOFTSERIAL, comsoft, sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
1997-10-19 15:45:33 +04:00
|
|
|
|
|
|
|
#if NRND > 0 && defined(RND_COM)
|
|
|
|
rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
|
1999-02-28 20:08:05 +03:00
|
|
|
RND_TYPE_TTY, 0);
|
1997-10-19 15:45:33 +04:00
|
|
|
#endif
|
1998-02-02 02:33:01 +03:00
|
|
|
|
|
|
|
/* if there are no enable/disable functions, assume the device
|
|
|
|
is always enabled */
|
|
|
|
if (!sc->enable)
|
|
|
|
sc->enabled = 1;
|
|
|
|
|
|
|
|
com_config(sc);
|
1998-02-03 01:54:55 +03:00
|
|
|
|
|
|
|
SET(sc->sc_hwflags, COM_HW_DEV_OK);
|
1998-02-02 02:33:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
com_config(sc)
|
|
|
|
struct com_softc *sc;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
/* Disable interrupts before configuring the device. */
|
|
|
|
sc->sc_ier = 0;
|
|
|
|
bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
|
|
|
|
|
|
|
|
#ifdef COM_HAYESP
|
|
|
|
/* Look for a Hayes ESP board. */
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) {
|
|
|
|
sc->sc_fifolen = 1024;
|
|
|
|
|
|
|
|
/* Set 16550 compatibility mode */
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD1,
|
|
|
|
HAYESP_SETMODE);
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
|
|
|
|
HAYESP_MODE_FIFO|HAYESP_MODE_RTS|
|
|
|
|
HAYESP_MODE_SCALE);
|
|
|
|
|
|
|
|
/* Set RTS/CTS flow control */
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD1,
|
|
|
|
HAYESP_SETFLOWTYPE);
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
|
|
|
|
HAYESP_FLOW_RTS);
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
|
|
|
|
HAYESP_FLOW_CTS);
|
|
|
|
|
|
|
|
/* Set flow control levels */
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD1,
|
|
|
|
HAYESP_SETRXFLOW);
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
|
|
|
|
HAYESP_HIBYTE(HAYESP_RXHIWMARK));
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
|
|
|
|
HAYESP_LOBYTE(HAYESP_RXHIWMARK));
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
|
|
|
|
HAYESP_HIBYTE(HAYESP_RXLOWMARK));
|
|
|
|
bus_space_write_1(iot, sc->sc_hayespioh, HAYESP_CMD2,
|
|
|
|
HAYESP_LOBYTE(HAYESP_RXLOWMARK));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DDB
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
|
|
|
|
com_enable_debugport(sc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef KGDB
|
|
|
|
/*
|
|
|
|
* Allow kgdb to "take over" this port. If this is
|
|
|
|
* the kgdb device, it has exclusive use.
|
|
|
|
*/
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_KGDB))
|
|
|
|
com_enable_debugport(sc);
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
int
|
|
|
|
com_detach(self, flags)
|
|
|
|
struct device *self;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct com_softc *sc = (struct com_softc *)self;
|
|
|
|
int maj, mn;
|
|
|
|
|
|
|
|
/* locate the major number */
|
|
|
|
for (maj = 0; maj < nchrdev; maj++)
|
|
|
|
if (cdevsw[maj].d_open == comopen)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Nuke the vnodes for any open instances. */
|
|
|
|
mn = self->dv_unit;
|
|
|
|
vdevgone(maj, mn, mn, VCHR);
|
|
|
|
|
|
|
|
mn |= COMDIALOUT_MASK;
|
|
|
|
vdevgone(maj, mn, mn, VCHR);
|
|
|
|
|
|
|
|
/* Free the receive buffer. */
|
|
|
|
free(sc->sc_rbuf, M_DEVBUF);
|
|
|
|
|
|
|
|
/* Detach and free the tty. */
|
|
|
|
tty_detach(sc->sc_tty);
|
|
|
|
ttyfree(sc->sc_tty);
|
|
|
|
|
|
|
|
#ifdef __GENERIC_SOFT_INTERRUPTS
|
|
|
|
/* Unhook the soft interrupt handler. */
|
|
|
|
softintr_disestablish(sc->sc_si);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NRND > 0 && defined(RND_COM)
|
|
|
|
/* Unhook the entropy source. */
|
|
|
|
rnd_detach_source(&sc->rnd_source);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
com_activate(self, act)
|
|
|
|
struct device *self;
|
|
|
|
enum devact act;
|
|
|
|
{
|
|
|
|
struct com_softc *sc = (struct com_softc *)self;
|
|
|
|
int s, rv = 0;
|
|
|
|
|
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1998-11-19 02:58:52 +03:00
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
rv = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
if (sc->sc_hwflags & (COM_HW_CONSOLE|COM_HW_KGDB)) {
|
|
|
|
rv = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->disable != NULL && sc->enabled != 0) {
|
|
|
|
(*sc->disable)(sc);
|
|
|
|
sc->enabled = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2000-09-23 21:17:11 +04:00
|
|
|
|
|
|
|
COM_UNLOCK(sc);
|
1998-11-19 02:58:52 +03:00
|
|
|
splx(s);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
1998-03-21 07:02:47 +03:00
|
|
|
void
|
|
|
|
com_shutdown(sc)
|
|
|
|
struct com_softc *sc;
|
|
|
|
{
|
|
|
|
struct tty *tp = sc->sc_tty;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1998-03-21 07:02:47 +03:00
|
|
|
|
|
|
|
/* If we were asserting flow control, then deassert it. */
|
|
|
|
SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
|
|
|
|
com_hwiflow(sc);
|
|
|
|
|
|
|
|
/* Clear any break condition set with TIOCSBRK. */
|
|
|
|
com_break(sc, 0);
|
|
|
|
|
1998-06-10 16:06:23 +04:00
|
|
|
/* Turn off PPS capture on last close. */
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsmask = 0;
|
1998-06-10 16:06:23 +04:00
|
|
|
sc->ppsparam.mode = 0;
|
|
|
|
|
1998-03-21 07:02:47 +03:00
|
|
|
/*
|
|
|
|
* Hang up if necessary. Wait a bit, so the other side has time to
|
|
|
|
* notice even if we immediately open the port again.
|
2000-08-18 17:22:39 +04:00
|
|
|
* Avoid tsleeping above splhigh().
|
1998-03-21 07:02:47 +03:00
|
|
|
*/
|
|
|
|
if (ISSET(tp->t_cflag, HUPCL)) {
|
|
|
|
com_modem(sc, 0);
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
2000-08-18 17:22:39 +04:00
|
|
|
splx(s);
|
|
|
|
/* XXX tsleep will only timeout */
|
1998-03-21 07:02:47 +03:00
|
|
|
(void) tsleep(sc, TTIPRI, ttclos, hz);
|
2000-08-18 17:22:39 +04:00
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1998-03-21 07:02:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn off interrupts. */
|
|
|
|
#ifdef DDB
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE))
|
|
|
|
sc->sc_ier = IER_ERXRDY; /* interrupt on break */
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
sc->sc_ier = 0;
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
|
|
|
|
|
|
|
|
if (sc->disable) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (!sc->enabled)
|
|
|
|
panic("com_shutdown: not enabled?");
|
|
|
|
#endif
|
|
|
|
(*sc->disable)(sc);
|
|
|
|
sc->enabled = 0;
|
|
|
|
}
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1998-03-21 07:02:47 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
struct com_softc *sc;
|
|
|
|
struct tty *tp;
|
1997-04-05 00:56:34 +04:00
|
|
|
int s, s2;
|
1998-03-21 07:27:58 +03:00
|
|
|
int error;
|
2000-07-06 05:47:34 +04:00
|
|
|
|
|
|
|
sc = device_lookup(&com_cd, COMUNIT(dev));
|
|
|
|
if (sc == NULL || !ISSET(sc->sc_hwflags, COM_HW_DEV_OK) ||
|
2000-09-22 03:27:32 +04:00
|
|
|
sc->sc_rbuf == NULL)
|
1997-04-05 00:56:34 +04:00
|
|
|
return (ENXIO);
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
if (ISSET(sc->sc_dev.dv_flags, DVF_ACTIVE) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
#ifdef KGDB
|
|
|
|
/*
|
|
|
|
* If this is the kgdb port, no other use is permitted.
|
|
|
|
*/
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_KGDB))
|
|
|
|
return (EBUSY);
|
|
|
|
#endif
|
|
|
|
|
1997-11-01 23:31:57 +03:00
|
|
|
tp = sc->sc_tty;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
if (ISSET(tp->t_state, TS_ISOPEN) &&
|
|
|
|
ISSET(tp->t_state, TS_XCLUDE) &&
|
2000-09-22 03:27:32 +04:00
|
|
|
p->p_ucred->cr_uid != 0)
|
1997-04-05 00:56:34 +04:00
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the following iff this is a first open.
|
|
|
|
*/
|
1998-03-21 07:02:47 +03:00
|
|
|
if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
|
1997-04-05 00:56:34 +04:00
|
|
|
struct termios t;
|
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
tp->t_dev = dev;
|
|
|
|
|
1997-11-01 23:31:57 +03:00
|
|
|
s2 = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1997-11-01 23:31:57 +03:00
|
|
|
|
1998-02-02 02:33:01 +03:00
|
|
|
if (sc->enable) {
|
|
|
|
if ((*sc->enable)(sc)) {
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1998-03-21 07:02:47 +03:00
|
|
|
splx(s2);
|
1998-02-06 06:25:34 +03:00
|
|
|
splx(s);
|
1998-02-02 02:33:01 +03:00
|
|
|
printf("%s: device enable failed\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
sc->enabled = 1;
|
|
|
|
com_config(sc);
|
|
|
|
}
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/* Turn on interrupts. */
|
|
|
|
sc->sc_ier = IER_ERXRDY | IER_ERLS | IER_EMSC;
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
|
|
|
|
|
|
|
|
/* Fetch the current modem control status, needed later. */
|
|
|
|
sc->sc_msr = bus_space_read_1(sc->sc_iot, sc->sc_ioh, com_msr);
|
|
|
|
|
1998-06-10 16:06:23 +04:00
|
|
|
/* Clear PPS capture state on first open. */
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsmask = 0;
|
1999-02-04 02:22:11 +03:00
|
|
|
sc->ppsparam.mode = 0;
|
1998-06-10 16:06:23 +04:00
|
|
|
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1997-11-01 23:31:57 +03:00
|
|
|
splx(s2);
|
1997-04-05 00:56:34 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the termios status to the defaults. Add in the
|
|
|
|
* sticky bits from TIOCSFLAGS.
|
|
|
|
*/
|
|
|
|
t.c_ispeed = 0;
|
1997-04-05 00:49:49 +04:00
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
|
1997-04-05 00:56:34 +04:00
|
|
|
t.c_ospeed = comconsrate;
|
|
|
|
t.c_cflag = comconscflag;
|
1997-04-05 00:49:49 +04:00
|
|
|
} else {
|
1997-04-05 00:56:34 +04:00
|
|
|
t.c_ospeed = TTYDEF_SPEED;
|
|
|
|
t.c_cflag = TTYDEF_CFLAG;
|
1997-04-05 00:49:49 +04:00
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
if (ISSET(sc->sc_swflags, TIOCFLAG_CLOCAL))
|
|
|
|
SET(t.c_cflag, CLOCAL);
|
|
|
|
if (ISSET(sc->sc_swflags, TIOCFLAG_CRTSCTS))
|
|
|
|
SET(t.c_cflag, CRTSCTS);
|
|
|
|
if (ISSET(sc->sc_swflags, TIOCFLAG_MDMBUF))
|
|
|
|
SET(t.c_cflag, MDMBUF);
|
1997-12-17 01:52:37 +03:00
|
|
|
/* Make sure comparam() will do something. */
|
|
|
|
tp->t_ospeed = 0;
|
1997-11-01 23:31:57 +03:00
|
|
|
(void) comparam(tp, &t);
|
1997-04-05 00:56:34 +04:00
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
1994-01-30 19:41:27 +03:00
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
1997-04-05 00:56:34 +04:00
|
|
|
ttychars(tp);
|
1993-03-21 12:45:37 +03:00
|
|
|
ttsetwater(tp);
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1998-02-19 12:23:38 +03:00
|
|
|
s2 = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1998-02-19 12:23:38 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/*
|
|
|
|
* Turn on DTR. We must always do this, even if carrier is not
|
|
|
|
* present, because otherwise we'd have to use TIOCSDTR
|
1997-11-01 23:40:36 +03:00
|
|
|
* immediately after setting CLOCAL, which applications do not
|
|
|
|
* expect. We always assert DTR while the device is open
|
|
|
|
* unless explicitly requested to deassert it.
|
1997-04-05 00:56:34 +04:00
|
|
|
*/
|
|
|
|
com_modem(sc, 1);
|
1996-02-10 23:23:18 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/* Clear the input ring, and unblock. */
|
1997-11-03 09:12:02 +03:00
|
|
|
sc->sc_rbput = sc->sc_rbget = sc->sc_rbuf;
|
|
|
|
sc->sc_rbavail = com_rbuf_size;
|
1997-04-05 00:56:34 +04:00
|
|
|
com_iflush(sc);
|
1997-06-15 15:18:59 +04:00
|
|
|
CLR(sc->sc_rx_flags, RX_ANY_BLOCK);
|
|
|
|
com_hwiflow(sc);
|
1996-02-10 23:23:18 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
#ifdef COM_DEBUG
|
1997-06-15 15:18:59 +04:00
|
|
|
if (com_debug)
|
|
|
|
comstatus(sc, "comopen ");
|
1996-02-10 23:23:18 +03:00
|
|
|
#endif
|
1994-03-08 11:12:56 +03:00
|
|
|
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1997-04-05 00:56:34 +04:00
|
|
|
splx(s2);
|
|
|
|
}
|
1998-03-22 03:55:37 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
splx(s);
|
1998-03-21 07:02:47 +03:00
|
|
|
|
1998-03-22 03:55:37 +03:00
|
|
|
error = ttyopen(tp, COMDIALOUT(dev), ISSET(flag, O_NONBLOCK));
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
2000-11-02 02:54:57 +03:00
|
|
|
error = (*tp->t_linesw->l_open)(dev, tp);
|
1998-02-22 08:09:58 +03:00
|
|
|
if (error)
|
1998-03-21 07:02:47 +03:00
|
|
|
goto bad;
|
1998-02-22 08:09:58 +03:00
|
|
|
|
1998-03-21 07:02:47 +03:00
|
|
|
return (0);
|
1998-02-22 08:09:58 +03:00
|
|
|
|
1998-03-21 07:02:47 +03:00
|
|
|
bad:
|
|
|
|
if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
|
|
|
|
/*
|
|
|
|
* We failed to open the device, and nobody else had it opened.
|
|
|
|
* Clean up the state as appropriate.
|
|
|
|
*/
|
|
|
|
com_shutdown(sc);
|
|
|
|
}
|
1998-02-22 08:09:58 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
return (error);
|
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;
|
|
|
|
{
|
2000-07-06 05:47:34 +04:00
|
|
|
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(dev));
|
1995-04-19 22:59:27 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
1995-06-05 00:39:22 +04:00
|
|
|
|
|
|
|
/* XXX This is for cons.c. */
|
1995-10-15 22:43:04 +03:00
|
|
|
if (!ISSET(tp->t_state, TS_ISOPEN))
|
1997-04-05 00:56:34 +04:00
|
|
|
return (0);
|
1994-03-08 11:12:56 +03:00
|
|
|
|
2000-11-02 02:54:57 +03:00
|
|
|
(*tp->t_linesw->l_close)(tp, flag);
|
1997-04-05 00:56:34 +04:00
|
|
|
ttyclose(tp);
|
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
if (COM_ISALIVE(sc) == 0)
|
|
|
|
return (0);
|
|
|
|
|
1998-03-22 03:55:37 +03:00
|
|
|
if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
|
|
|
|
/*
|
|
|
|
* Although we got a last close, the device may still be in
|
|
|
|
* use; e.g. if this was the dialout node, and there are still
|
|
|
|
* processes waiting for carrier on the non-dialout node.
|
|
|
|
*/
|
|
|
|
com_shutdown(sc);
|
|
|
|
}
|
1997-11-01 23:31:57 +03:00
|
|
|
|
1997-04-05 00:56:34 +04: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
|
|
|
{
|
2000-07-06 05:47:34 +04:00
|
|
|
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(dev));
|
1995-04-20 02:04:33 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
1998-11-19 02:58:52 +03:00
|
|
|
|
|
|
|
if (COM_ISALIVE(sc) == 0)
|
|
|
|
return (EIO);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-11-02 02:54:57 +03:00
|
|
|
return ((*tp->t_linesw->l_read)(tp, uio, flag));
|
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
|
|
|
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
|
|
|
{
|
2000-07-06 05:47:34 +04:00
|
|
|
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(dev));
|
1995-04-20 02:04:33 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
1998-11-19 02:58:52 +03:00
|
|
|
|
|
|
|
if (COM_ISALIVE(sc) == 0)
|
|
|
|
return (EIO);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-11-02 02:54:57 +03:00
|
|
|
return ((*tp->t_linesw->l_write)(tp, uio, flag));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-04-19 22:59:27 +04:00
|
|
|
|
|
|
|
struct tty *
|
|
|
|
comtty(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
2000-07-06 05:47:34 +04:00
|
|
|
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(dev));
|
1995-04-20 02:04:33 +04:00
|
|
|
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
|
|
|
}
|
1997-10-01 01:51:43 +04: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
|
|
|
{
|
2000-07-06 05:47:34 +04:00
|
|
|
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(dev));
|
1995-04-19 22:59:27 +04:00
|
|
|
struct tty *tp = sc->sc_tty;
|
1994-03-08 11:12:56 +03:00
|
|
|
int error;
|
1998-02-19 12:23:38 +03:00
|
|
|
int s;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
if (COM_ISALIVE(sc) == 0)
|
|
|
|
return (EIO);
|
|
|
|
|
2000-11-02 02:54:57 +03:00
|
|
|
error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (error >= 0)
|
1997-04-05 00:56:34 +04: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)
|
1997-04-05 00:56:34 +04:00
|
|
|
return (error);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-02-22 06:24:58 +03:00
|
|
|
error = 0;
|
|
|
|
|
1998-02-19 12:23:38 +03:00
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1998-02-19 12:23:38 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
switch (cmd) {
|
|
|
|
case TIOCSBRK:
|
1997-04-05 00:56:34 +04:00
|
|
|
com_break(sc, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case TIOCCBRK:
|
1997-04-05 00:56:34 +04:00
|
|
|
com_break(sc, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case TIOCSDTR:
|
1997-04-05 00:56:34 +04:00
|
|
|
com_modem(sc, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
case TIOCCDTR:
|
1997-04-05 00:56:34 +04:00
|
|
|
com_modem(sc, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
|
|
|
case TIOCGFLAGS:
|
|
|
|
*(int *)data = sc->sc_swflags;
|
1994-03-12 10:25:16 +03:00
|
|
|
break;
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
case TIOCSFLAGS:
|
1994-03-12 10:43:03 +03:00
|
|
|
error = suser(p->p_ucred, &p->p_acflag);
|
1997-04-05 00:56:34 +04:00
|
|
|
if (error)
|
1998-02-19 12:23:38 +03:00
|
|
|
break;
|
1997-04-05 00:56:34 +04:00
|
|
|
sc->sc_swflags = *(int *)data;
|
1994-03-12 10:25:16 +03:00
|
|
|
break;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
|
|
|
case TIOCMSET:
|
|
|
|
case TIOCMBIS:
|
|
|
|
case TIOCMBIC:
|
1999-02-04 02:57:27 +03:00
|
|
|
tiocm_to_com(sc, cmd, *(int *)data);
|
1997-10-01 01:51:43 +04:00
|
|
|
break;
|
|
|
|
|
1999-02-04 02:57:27 +03:00
|
|
|
case TIOCMGET:
|
|
|
|
*(int *)data = com_to_tiocm(sc);
|
1997-10-01 01:51:43 +04:00
|
|
|
break;
|
1998-06-10 16:06:23 +04:00
|
|
|
|
1999-11-04 08:33:58 +03:00
|
|
|
case PPS_IOC_CREATE:
|
1998-06-10 16:06:23 +04:00
|
|
|
break;
|
|
|
|
|
1999-11-04 08:33:58 +03:00
|
|
|
case PPS_IOC_DESTROY:
|
1998-06-10 16:06:23 +04:00
|
|
|
break;
|
|
|
|
|
1999-11-04 08:33:58 +03:00
|
|
|
case PPS_IOC_GETPARAMS: {
|
1998-06-10 16:06:23 +04:00
|
|
|
pps_params_t *pp;
|
|
|
|
pp = (pps_params_t *)data;
|
|
|
|
*pp = sc->ppsparam;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-11-04 08:33:58 +03:00
|
|
|
case PPS_IOC_SETPARAMS: {
|
1998-06-10 16:06:23 +04:00
|
|
|
pps_params_t *pp;
|
|
|
|
int mode;
|
|
|
|
pp = (pps_params_t *)data;
|
|
|
|
if (pp->mode & ~ppscap) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->ppsparam = *pp;
|
|
|
|
/*
|
|
|
|
* Compute msr masks from user-specified timestamp state.
|
|
|
|
*/
|
|
|
|
mode = sc->ppsparam.mode;
|
1999-02-04 02:20:33 +03:00
|
|
|
#ifdef PPS_SYNC
|
1998-06-10 16:06:23 +04:00
|
|
|
if (mode & PPS_HARDPPSONASSERT) {
|
|
|
|
mode |= PPS_CAPTUREASSERT;
|
|
|
|
/* XXX revoke any previous HARDPPS source */
|
|
|
|
}
|
|
|
|
if (mode & PPS_HARDPPSONCLEAR) {
|
|
|
|
mode |= PPS_CAPTURECLEAR;
|
|
|
|
/* XXX revoke any previous HARDPPS source */
|
|
|
|
}
|
1999-02-04 02:20:33 +03:00
|
|
|
#endif /* PPS_SYNC */
|
1998-06-10 16:06:23 +04:00
|
|
|
switch (mode & PPS_CAPTUREBOTH) {
|
|
|
|
case 0:
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsmask = 0;
|
1998-06-10 16:06:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPS_CAPTUREASSERT:
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsmask = MSR_DCD;
|
1998-06-10 16:06:23 +04:00
|
|
|
sc->sc_ppsassert = MSR_DCD;
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsclear = -1;
|
1998-06-10 16:06:23 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PPS_CAPTURECLEAR:
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsmask = MSR_DCD;
|
|
|
|
sc->sc_ppsassert = -1;
|
1998-06-10 16:06:23 +04:00
|
|
|
sc->sc_ppsclear = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPS_CAPTUREBOTH:
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsmask = MSR_DCD;
|
1998-06-10 16:06:23 +04:00
|
|
|
sc->sc_ppsassert = MSR_DCD;
|
|
|
|
sc->sc_ppsclear = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-11-04 08:33:58 +03:00
|
|
|
case PPS_IOC_GETCAP:
|
1998-06-10 16:06:23 +04:00
|
|
|
*(int*)data = ppscap;
|
|
|
|
break;
|
|
|
|
|
1999-11-04 08:33:58 +03:00
|
|
|
case PPS_IOC_FETCH: {
|
1998-06-10 16:06:23 +04:00
|
|
|
pps_info_t *pi;
|
|
|
|
pi = (pps_info_t *)data;
|
|
|
|
*pi = sc->ppsinfo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TIOCDCDTIMESTAMP: /* XXX old, overloaded API used by xntpd v3 */
|
|
|
|
/*
|
|
|
|
* Some GPS clocks models use the falling rather than
|
|
|
|
* rising edge as the on-the-second signal.
|
|
|
|
* The old API has no way to specify PPS polarity.
|
|
|
|
*/
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsmask = MSR_DCD;
|
1998-06-10 16:06:23 +04:00
|
|
|
#ifndef PPS_TRAILING_EDGE
|
|
|
|
sc->sc_ppsassert = MSR_DCD;
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsclear = -1;
|
|
|
|
TIMESPEC_TO_TIMEVAL((struct timeval *)data,
|
1998-06-10 16:06:23 +04:00
|
|
|
&sc->ppsinfo.assert_timestamp);
|
|
|
|
#else
|
1999-02-04 02:20:33 +03:00
|
|
|
sc->sc_ppsassert = -1
|
1998-06-10 16:06:23 +04:00
|
|
|
sc->sc_ppsclear = 0;
|
1999-02-04 02:20:33 +03:00
|
|
|
TIMESPEC_TO_TIMEVAL((struct timeval *)data,
|
1998-06-10 16:06:23 +04:00
|
|
|
&sc->ppsinfo.clear_timestamp);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
1998-02-19 12:23:38 +03:00
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
|
|
|
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1998-02-19 12:23:38 +03:00
|
|
|
splx(s);
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
#ifdef COM_DEBUG
|
1997-06-15 15:18:59 +04:00
|
|
|
if (com_debug)
|
1997-04-05 00:56:34 +04:00
|
|
|
comstatus(sc, "comioctl ");
|
|
|
|
#endif
|
|
|
|
|
1998-02-19 12:23:38 +03:00
|
|
|
return (error);
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
|
|
|
|
1997-06-15 15:18:59 +04:00
|
|
|
integrate void
|
|
|
|
com_schedrx(sc)
|
|
|
|
struct com_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
sc->sc_rx_ready = 1;
|
|
|
|
|
|
|
|
/* Wake up the poller. */
|
|
|
|
#ifdef __GENERIC_SOFT_INTERRUPTS
|
|
|
|
softintr_schedule(sc->sc_si);
|
|
|
|
#else
|
1998-02-03 02:01:02 +03:00
|
|
|
#ifndef __NO_SOFT_SERIAL_INTERRUPT
|
1997-06-15 15:18:59 +04:00
|
|
|
setsoftserial();
|
|
|
|
#else
|
|
|
|
if (!com_softintr_scheduled) {
|
|
|
|
com_softintr_scheduled = 1;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&comsoft_callout, 1, comsoft, NULL);
|
1997-06-15 15:18:59 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
void
|
|
|
|
com_break(sc, onoff)
|
|
|
|
struct com_softc *sc;
|
|
|
|
int onoff;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (onoff)
|
|
|
|
SET(sc->sc_lcr, LCR_SBREAK);
|
|
|
|
else
|
|
|
|
CLR(sc->sc_lcr, LCR_SBREAK);
|
|
|
|
|
|
|
|
if (!sc->sc_heldchange) {
|
|
|
|
if (sc->sc_tx_busy) {
|
|
|
|
sc->sc_heldtbc = sc->sc_tbc;
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldchange = 1;
|
|
|
|
} else
|
|
|
|
com_loadchannelregs(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
void
|
|
|
|
com_modem(sc, onoff)
|
|
|
|
struct com_softc *sc;
|
|
|
|
int onoff;
|
|
|
|
{
|
|
|
|
|
1999-02-04 02:57:27 +03:00
|
|
|
if (sc->sc_mcr_dtr == 0)
|
|
|
|
return;
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
if (onoff)
|
|
|
|
SET(sc->sc_mcr, sc->sc_mcr_dtr);
|
|
|
|
else
|
|
|
|
CLR(sc->sc_mcr, sc->sc_mcr_dtr);
|
|
|
|
|
|
|
|
if (!sc->sc_heldchange) {
|
|
|
|
if (sc->sc_tx_busy) {
|
|
|
|
sc->sc_heldtbc = sc->sc_tbc;
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldchange = 1;
|
|
|
|
} else
|
|
|
|
com_loadchannelregs(sc);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1999-02-04 02:57:27 +03:00
|
|
|
void
|
|
|
|
tiocm_to_com(sc, how, ttybits)
|
|
|
|
struct com_softc *sc;
|
2000-09-18 02:07:39 +04:00
|
|
|
u_long how;
|
|
|
|
int ttybits;
|
1999-02-04 02:57:27 +03:00
|
|
|
{
|
|
|
|
u_char combits;
|
|
|
|
|
|
|
|
combits = 0;
|
|
|
|
if (ISSET(ttybits, TIOCM_DTR))
|
|
|
|
SET(combits, MCR_DTR);
|
|
|
|
if (ISSET(ttybits, TIOCM_RTS))
|
|
|
|
SET(combits, MCR_RTS);
|
|
|
|
|
|
|
|
switch (how) {
|
|
|
|
case TIOCMBIC:
|
|
|
|
CLR(sc->sc_mcr, combits);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMBIS:
|
|
|
|
SET(sc->sc_mcr, combits);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TIOCMSET:
|
|
|
|
CLR(sc->sc_mcr, MCR_DTR | MCR_RTS);
|
|
|
|
SET(sc->sc_mcr, combits);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sc->sc_heldchange) {
|
|
|
|
if (sc->sc_tx_busy) {
|
|
|
|
sc->sc_heldtbc = sc->sc_tbc;
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldchange = 1;
|
|
|
|
} else
|
|
|
|
com_loadchannelregs(sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
com_to_tiocm(sc)
|
|
|
|
struct com_softc *sc;
|
|
|
|
{
|
|
|
|
u_char combits;
|
|
|
|
int ttybits = 0;
|
|
|
|
|
|
|
|
combits = sc->sc_mcr;
|
|
|
|
if (ISSET(combits, MCR_DTR))
|
|
|
|
SET(ttybits, TIOCM_DTR);
|
|
|
|
if (ISSET(combits, MCR_RTS))
|
|
|
|
SET(ttybits, TIOCM_RTS);
|
|
|
|
|
|
|
|
combits = sc->sc_msr;
|
|
|
|
if (ISSET(combits, MSR_DCD))
|
|
|
|
SET(ttybits, TIOCM_CD);
|
|
|
|
if (ISSET(combits, MSR_CTS))
|
|
|
|
SET(ttybits, TIOCM_CTS);
|
|
|
|
if (ISSET(combits, MSR_DSR))
|
|
|
|
SET(ttybits, TIOCM_DSR);
|
|
|
|
if (ISSET(combits, MSR_RI | MSR_TERI))
|
|
|
|
SET(ttybits, TIOCM_RI);
|
|
|
|
|
|
|
|
if (sc->sc_ier != 0)
|
|
|
|
SET(ttybits, TIOCM_LE);
|
|
|
|
|
|
|
|
return (ttybits);
|
|
|
|
}
|
|
|
|
|
1997-08-23 18:01:32 +04:00
|
|
|
static u_char
|
|
|
|
cflag2lcr(cflag)
|
1997-09-19 05:17:37 +04:00
|
|
|
tcflag_t cflag;
|
1997-08-23 18:01:32 +04:00
|
|
|
{
|
|
|
|
u_char lcr = 0;
|
|
|
|
|
|
|
|
switch (ISSET(cflag, CSIZE)) {
|
1997-11-03 09:12:02 +03:00
|
|
|
case CS5:
|
1997-08-23 18:01:32 +04:00
|
|
|
SET(lcr, LCR_5BITS);
|
|
|
|
break;
|
1997-11-03 09:12:02 +03:00
|
|
|
case CS6:
|
1997-08-23 18:01:32 +04:00
|
|
|
SET(lcr, LCR_6BITS);
|
|
|
|
break;
|
1997-11-03 09:12:02 +03:00
|
|
|
case CS7:
|
1997-08-23 18:01:32 +04:00
|
|
|
SET(lcr, LCR_7BITS);
|
|
|
|
break;
|
1997-11-03 09:12:02 +03:00
|
|
|
case CS8:
|
1997-08-23 18:01:32 +04:00
|
|
|
SET(lcr, LCR_8BITS);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ISSET(cflag, PARENB)) {
|
|
|
|
SET(lcr, LCR_PENAB);
|
|
|
|
if (!ISSET(cflag, PARODD))
|
|
|
|
SET(lcr, LCR_PEVEN);
|
|
|
|
}
|
|
|
|
if (ISSET(cflag, CSTOPB))
|
|
|
|
SET(lcr, LCR_STOPB);
|
|
|
|
|
1997-09-19 05:17:37 +04:00
|
|
|
return (lcr);
|
1997-08-23 18:01:32 +04: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
|
|
|
{
|
2000-07-06 05:47:34 +04:00
|
|
|
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(tp->t_dev));
|
1997-09-17 00:34:23 +04:00
|
|
|
int ospeed = comspeed(t->c_ospeed, sc->sc_frequency);
|
1995-10-15 22:43:04 +03:00
|
|
|
u_char lcr;
|
1994-03-08 11:12:56 +03:00
|
|
|
int s;
|
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
if (COM_ISALIVE(sc) == 0)
|
|
|
|
return (EIO);
|
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
/* Check requested parameters. */
|
1997-04-05 00:56:34 +04:00
|
|
|
if (ospeed < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
if (t->c_ispeed && t->c_ispeed != t->c_ospeed)
|
|
|
|
return (EINVAL);
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/*
|
|
|
|
* For the console, always force CLOCAL and !HUPCL, so that the port
|
|
|
|
* is always active.
|
|
|
|
*/
|
|
|
|
if (ISSET(sc->sc_swflags, TIOCFLAG_SOFTCAR) ||
|
|
|
|
ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
|
|
|
|
SET(t->c_cflag, CLOCAL);
|
|
|
|
CLR(t->c_cflag, HUPCL);
|
1995-10-15 22:43:04 +03:00
|
|
|
}
|
1994-09-16 06:50:39 +04:00
|
|
|
|
1997-12-17 01:52:37 +03:00
|
|
|
/*
|
|
|
|
* If there were no changes, don't do anything. This avoids dropping
|
|
|
|
* input and improves performance when all we did was frob things like
|
|
|
|
* VMIN and VTIME.
|
|
|
|
*/
|
|
|
|
if (tp->t_ospeed == t->c_ospeed &&
|
|
|
|
tp->t_cflag == t->c_cflag)
|
|
|
|
return (0);
|
|
|
|
|
1997-11-02 12:31:49 +03:00
|
|
|
lcr = ISSET(sc->sc_lcr, LCR_SBREAK) | cflag2lcr(t->c_cflag);
|
|
|
|
|
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1997-11-02 12:31:49 +03:00
|
|
|
|
|
|
|
sc->sc_lcr = lcr;
|
|
|
|
|
1994-09-16 06:50:39 +04:00
|
|
|
/*
|
1997-04-05 00:56:34 +04:00
|
|
|
* If we're not in a mode that assumes a connection is present, then
|
|
|
|
* ignore carrier changes.
|
|
|
|
*/
|
|
|
|
if (ISSET(t->c_cflag, CLOCAL | MDMBUF))
|
|
|
|
sc->sc_msr_dcd = 0;
|
|
|
|
else
|
|
|
|
sc->sc_msr_dcd = MSR_DCD;
|
|
|
|
/*
|
|
|
|
* Set the flow control pins depending on the current flow control
|
|
|
|
* mode.
|
1994-09-16 06:50:39 +04:00
|
|
|
*/
|
1997-04-05 00:56:34 +04:00
|
|
|
if (ISSET(t->c_cflag, CRTSCTS)) {
|
|
|
|
sc->sc_mcr_dtr = MCR_DTR;
|
|
|
|
sc->sc_mcr_rts = MCR_RTS;
|
|
|
|
sc->sc_msr_cts = MSR_CTS;
|
1997-10-19 18:26:16 +04:00
|
|
|
sc->sc_efr = EFR_AUTORTS | EFR_AUTOCTS;
|
1997-04-05 00:56:34 +04:00
|
|
|
} else if (ISSET(t->c_cflag, MDMBUF)) {
|
|
|
|
/*
|
|
|
|
* For DTR/DCD flow control, make sure we don't toggle DTR for
|
|
|
|
* carrier detection.
|
|
|
|
*/
|
|
|
|
sc->sc_mcr_dtr = 0;
|
|
|
|
sc->sc_mcr_rts = MCR_DTR;
|
|
|
|
sc->sc_msr_cts = MSR_DCD;
|
1997-10-19 18:26:16 +04:00
|
|
|
sc->sc_efr = 0;
|
1997-04-05 00:56:34 +04:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If no flow control, then always set RTS. This will make
|
|
|
|
* the other side happy if it mistakenly thinks we're doing
|
|
|
|
* RTS/CTS flow control.
|
|
|
|
*/
|
|
|
|
sc->sc_mcr_dtr = MCR_DTR | MCR_RTS;
|
|
|
|
sc->sc_mcr_rts = 0;
|
|
|
|
sc->sc_msr_cts = 0;
|
1997-10-19 18:26:16 +04:00
|
|
|
sc->sc_efr = 0;
|
1997-04-05 00:56:34 +04:00
|
|
|
if (ISSET(sc->sc_mcr, MCR_DTR))
|
|
|
|
SET(sc->sc_mcr, MCR_RTS);
|
|
|
|
else
|
|
|
|
CLR(sc->sc_mcr, MCR_RTS);
|
|
|
|
}
|
|
|
|
sc->sc_msr_mask = sc->sc_msr_cts | sc->sc_msr_dcd;
|
|
|
|
|
1996-12-14 11:56:23 +03:00
|
|
|
#if 0
|
1997-04-05 00:56:34 +04:00
|
|
|
if (ospeed == 0)
|
|
|
|
CLR(sc->sc_mcr, sc->sc_mcr_dtr);
|
|
|
|
else
|
|
|
|
SET(sc->sc_mcr, sc->sc_mcr_dtr);
|
1996-02-17 07:04:28 +03:00
|
|
|
#endif
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
sc->sc_dlbl = ospeed;
|
|
|
|
sc->sc_dlbh = ospeed >> 8;
|
1996-02-17 07:04:28 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/*
|
|
|
|
* Set the FIFO threshold based on the receive speed.
|
|
|
|
*
|
|
|
|
* * If it's a low speed, it's probably a mouse or some other
|
|
|
|
* interactive device, so set the threshold low.
|
|
|
|
* * If it's a high speed, trim the trigger level down to prevent
|
|
|
|
* overflows.
|
|
|
|
* * Otherwise set it a bit higher.
|
|
|
|
*/
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_HAYESP))
|
|
|
|
sc->sc_fifo = FIFO_DMA_MODE | FIFO_ENABLE | FIFO_TRIGGER_8;
|
|
|
|
else if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
|
|
|
|
sc->sc_fifo = FIFO_ENABLE |
|
|
|
|
(t->c_ospeed <= 1200 ? FIFO_TRIGGER_1 :
|
|
|
|
t->c_ospeed <= 38400 ? FIFO_TRIGGER_8 : FIFO_TRIGGER_4);
|
|
|
|
else
|
|
|
|
sc->sc_fifo = 0;
|
1994-03-18 08:13:26 +03:00
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
/* And copy to tty. */
|
1997-04-05 00:56:34 +04:00
|
|
|
tp->t_ispeed = 0;
|
1994-07-31 15:34:38 +04:00
|
|
|
tp->t_ospeed = t->c_ospeed;
|
|
|
|
tp->t_cflag = t->c_cflag;
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
if (!sc->sc_heldchange) {
|
|
|
|
if (sc->sc_tx_busy) {
|
|
|
|
sc->sc_heldtbc = sc->sc_tbc;
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldchange = 1;
|
|
|
|
} else
|
|
|
|
com_loadchannelregs(sc);
|
|
|
|
}
|
|
|
|
|
1997-11-02 12:15:41 +03:00
|
|
|
if (!ISSET(t->c_cflag, CHWFLOW)) {
|
1997-11-02 12:24:51 +03:00
|
|
|
/* Disable the high water mark. */
|
|
|
|
sc->sc_r_hiwat = 0;
|
|
|
|
sc->sc_r_lowat = 0;
|
1997-11-02 12:15:41 +03:00
|
|
|
if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
|
|
|
|
CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
|
|
|
|
com_schedrx(sc);
|
|
|
|
}
|
|
|
|
if (ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED)) {
|
|
|
|
CLR(sc->sc_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED);
|
|
|
|
com_hwiflow(sc);
|
|
|
|
}
|
1997-11-02 12:24:51 +03:00
|
|
|
} else {
|
1997-11-03 09:12:02 +03:00
|
|
|
sc->sc_r_hiwat = com_rbuf_hiwat;
|
|
|
|
sc->sc_r_lowat = com_rbuf_lowat;
|
1997-11-02 12:15:41 +03:00
|
|
|
}
|
|
|
|
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1997-04-05 00:56:34 +04:00
|
|
|
splx(s);
|
|
|
|
|
1995-06-05 00:39:22 +04:00
|
|
|
/*
|
1997-04-05 00:56:34 +04:00
|
|
|
* Update the tty layer's idea of the carrier bit, in case we changed
|
1997-11-02 12:15:41 +03:00
|
|
|
* CLOCAL or MDMBUF. We don't hang up here; we only do that by
|
|
|
|
* explicit request.
|
1995-06-05 00:39:22 +04:00
|
|
|
*/
|
2000-11-02 02:54:57 +03:00
|
|
|
(void) (*tp->t_linesw->l_modem)(tp, ISSET(sc->sc_msr, MSR_DCD));
|
1997-04-05 00:56:34 +04:00
|
|
|
|
|
|
|
#ifdef COM_DEBUG
|
1997-06-15 15:18:59 +04:00
|
|
|
if (com_debug)
|
|
|
|
comstatus(sc, "comparam ");
|
1997-04-05 00:56:34 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!ISSET(t->c_cflag, CHWFLOW)) {
|
|
|
|
if (sc->sc_tx_stopped) {
|
|
|
|
sc->sc_tx_stopped = 0;
|
|
|
|
comstart(tp);
|
|
|
|
}
|
1995-06-05 00:39:22 +04:00
|
|
|
}
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
com_iflush(sc)
|
|
|
|
struct com_softc *sc;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1998-02-02 02:33:01 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
int reg;
|
|
|
|
#endif
|
|
|
|
int timo;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
1998-02-02 02:33:01 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
reg = 0xffff;
|
|
|
|
#endif
|
|
|
|
timo = 50000;
|
1997-04-05 00:56:34 +04:00
|
|
|
/* flush any pending I/O */
|
1998-02-02 02:33:01 +03:00
|
|
|
while (ISSET(bus_space_read_1(iot, ioh, com_lsr), LSR_RXRDY)
|
|
|
|
&& --timo)
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
reg =
|
|
|
|
#else
|
|
|
|
(void)
|
|
|
|
#endif
|
|
|
|
bus_space_read_1(iot, ioh, com_data);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (!timo)
|
|
|
|
printf("%s: com_iflush timeout %02x\n", sc->sc_dev.dv_xname,
|
|
|
|
reg);
|
|
|
|
#endif
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
com_loadchannelregs(sc)
|
|
|
|
struct com_softc *sc;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
/* XXXXX necessary? */
|
|
|
|
com_iflush(sc);
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, com_ier, 0);
|
|
|
|
|
1997-10-19 18:26:16 +04:00
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_FLOW)) {
|
|
|
|
bus_space_write_1(iot, ioh, com_lcr, LCR_EERS);
|
|
|
|
bus_space_write_1(iot, ioh, com_efr, sc->sc_efr);
|
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_lcr, sc->sc_lcr | LCR_DLAB);
|
|
|
|
bus_space_write_1(iot, ioh, com_dlbl, sc->sc_dlbl);
|
|
|
|
bus_space_write_1(iot, ioh, com_dlbh, sc->sc_dlbh);
|
|
|
|
bus_space_write_1(iot, ioh, com_lcr, sc->sc_lcr);
|
|
|
|
bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr_active = sc->sc_mcr);
|
|
|
|
bus_space_write_1(iot, ioh, com_fifo, sc->sc_fifo);
|
|
|
|
|
|
|
|
bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
comhwiflow(tp, block)
|
|
|
|
struct tty *tp;
|
|
|
|
int block;
|
|
|
|
{
|
2000-07-06 05:47:34 +04:00
|
|
|
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(tp->t_dev));
|
1997-04-05 00:56:34 +04:00
|
|
|
int s;
|
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
if (COM_ISALIVE(sc) == 0)
|
|
|
|
return (0);
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
if (sc->sc_mcr_rts == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
if (block) {
|
1997-06-15 15:18:59 +04:00
|
|
|
if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
|
|
|
|
SET(sc->sc_rx_flags, RX_TTY_BLOCKED);
|
|
|
|
com_hwiflow(sc);
|
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
} else {
|
1997-06-15 15:18:59 +04:00
|
|
|
if (ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED)) {
|
|
|
|
CLR(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
|
|
|
|
com_schedrx(sc);
|
|
|
|
}
|
|
|
|
if (ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
|
|
|
|
CLR(sc->sc_rx_flags, RX_TTY_BLOCKED);
|
|
|
|
com_hwiflow(sc);
|
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
2000-09-23 21:17:11 +04:00
|
|
|
|
|
|
|
COM_UNLOCK(sc);
|
1994-03-08 11:12:56 +03:00
|
|
|
splx(s);
|
1997-04-05 00:56:34 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* (un)block input via hw flowcontrol
|
|
|
|
*/
|
|
|
|
void
|
1997-06-15 15:18:59 +04:00
|
|
|
com_hwiflow(sc)
|
1997-04-05 00:56:34 +04:00
|
|
|
struct com_softc *sc;
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
|
|
|
if (sc->sc_mcr_rts == 0)
|
|
|
|
return;
|
|
|
|
|
1997-06-15 15:18:59 +04:00
|
|
|
if (ISSET(sc->sc_rx_flags, RX_ANY_BLOCK)) {
|
1997-04-05 00:56:34 +04:00
|
|
|
CLR(sc->sc_mcr, sc->sc_mcr_rts);
|
|
|
|
CLR(sc->sc_mcr_active, sc->sc_mcr_rts);
|
|
|
|
} else {
|
|
|
|
SET(sc->sc_mcr, sc->sc_mcr_rts);
|
|
|
|
SET(sc->sc_mcr_active, sc->sc_mcr_rts);
|
|
|
|
}
|
|
|
|
bus_space_write_1(iot, ioh, com_mcr, sc->sc_mcr_active);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2000-07-06 05:47:34 +04:00
|
|
|
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(tp->t_dev));
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-03-08 11:12:56 +03:00
|
|
|
int s;
|
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
if (COM_ISALIVE(sc) == 0)
|
|
|
|
return;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
s = spltty();
|
2000-09-22 18:46:38 +04:00
|
|
|
if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP))
|
1996-02-19 18:09:25 +03:00
|
|
|
goto out;
|
2000-09-22 18:46:38 +04:00
|
|
|
if (sc->sc_tx_stopped)
|
1997-11-03 09:12:02 +03:00
|
|
|
goto out;
|
2000-09-22 18:46:38 +04:00
|
|
|
|
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
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
selwakeup(&tp->t_wsel);
|
2000-09-22 18:46:38 +04:00
|
|
|
if (tp->t_outq.c_cc == 0)
|
1997-11-03 09:12:02 +03:00
|
|
|
goto out;
|
1995-07-04 10:47:18 +04:00
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
|
|
|
|
/* Grab the first contiguous region of buffer space. */
|
|
|
|
{
|
|
|
|
u_char *tba;
|
|
|
|
int tbc;
|
|
|
|
|
|
|
|
tba = tp->t_outq.c_cf;
|
|
|
|
tbc = ndqb(&tp->t_outq, 0);
|
|
|
|
|
|
|
|
(void)splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1997-04-05 00:56:34 +04:00
|
|
|
|
|
|
|
sc->sc_tba = tba;
|
|
|
|
sc->sc_tbc = tbc;
|
|
|
|
}
|
|
|
|
|
1995-10-15 22:43:04 +03:00
|
|
|
SET(tp->t_state, TS_BUSY);
|
1997-04-05 00:56:34 +04:00
|
|
|
sc->sc_tx_busy = 1;
|
1996-01-15 02:44:34 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/* Enable transmit completion interrupts if necessary. */
|
1996-02-19 18:09:25 +03:00
|
|
|
if (!ISSET(sc->sc_ier, IER_ETXRDY)) {
|
|
|
|
SET(sc->sc_ier, IER_ETXRDY);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
|
1996-02-19 18:09:25 +03:00
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
|
|
|
|
/* Output the first chunk of the contiguous buffer. */
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
n = sc->sc_tbc;
|
|
|
|
if (n > sc->sc_fifolen)
|
|
|
|
n = sc->sc_fifolen;
|
1997-04-05 00:56:34 +04:00
|
|
|
bus_space_write_multi_1(iot, ioh, com_data, sc->sc_tba, n);
|
|
|
|
sc->sc_tbc -= n;
|
|
|
|
sc->sc_tba += n;
|
1996-01-15 02:44:34 +03:00
|
|
|
}
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1997-04-05 00:56:34 +04:00
|
|
|
out:
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
1997-04-05 00:56:34 +04:00
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Stop output on a line.
|
|
|
|
*/
|
1996-09-02 10:43:16 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
comstop(tp, flag)
|
1994-03-08 11:12:56 +03:00
|
|
|
struct tty *tp;
|
1996-04-30 00:02:32 +04:00
|
|
|
int flag;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-07-06 05:47:34 +04:00
|
|
|
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(tp->t_dev));
|
1994-03-08 11:12:56 +03:00
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1997-04-05 00:56:34 +04:00
|
|
|
if (ISSET(tp->t_state, TS_BUSY)) {
|
|
|
|
/* Stop transmitting at the next chunk. */
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldtbc = 0;
|
1995-10-15 22:43:04 +03:00
|
|
|
if (!ISSET(tp->t_state, TS_TTSTOP))
|
|
|
|
SET(tp->t_state, TS_FLUSH);
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
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;
|
1997-04-05 00:56:34 +04:00
|
|
|
int overflows, floods;
|
1994-08-07 15:27:51 +04:00
|
|
|
int s;
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
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;
|
1997-04-05 00:56:34 +04:00
|
|
|
sc->sc_errors = 0;
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1995-06-05 00:39:22 +04:00
|
|
|
splx(s);
|
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf flood%s\n",
|
1995-06-05 00:39:22 +04:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
overflows, overflows == 1 ? "" : "s",
|
1997-04-05 00:56:34 +04:00
|
|
|
floods, floods == 1 ? "" : "s");
|
1995-06-05 00:39:22 +04:00
|
|
|
}
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
integrate void
|
1997-11-03 09:12:02 +03:00
|
|
|
com_rxsoft(sc, tp)
|
|
|
|
struct com_softc *sc;
|
|
|
|
struct tty *tp;
|
1995-06-05 00:39:22 +04:00
|
|
|
{
|
2000-11-02 02:54:57 +03:00
|
|
|
int (*rint) __P((int c, struct tty *tp)) = tp->t_linesw->l_rint;
|
1997-11-03 09:12:02 +03:00
|
|
|
u_char *get, *end;
|
|
|
|
u_int cc, scc;
|
|
|
|
u_char lsr;
|
|
|
|
int code;
|
|
|
|
int s;
|
1995-06-05 00:39:22 +04:00
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
end = sc->sc_ebuf;
|
1997-04-05 00:56:34 +04:00
|
|
|
get = sc->sc_rbget;
|
1997-11-03 09:12:02 +03:00
|
|
|
scc = cc = com_rbuf_size - sc->sc_rbavail;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
if (cc == com_rbuf_size) {
|
1997-04-05 00:56:34 +04:00
|
|
|
sc->sc_floods++;
|
|
|
|
if (sc->sc_errors++ == 0)
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_diag_callout, 60 * hz,
|
|
|
|
comdiag, sc);
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
|
|
|
|
1997-06-15 15:18:59 +04:00
|
|
|
while (cc) {
|
1997-11-03 09:12:02 +03:00
|
|
|
code = get[0];
|
1997-11-03 11:20:35 +03:00
|
|
|
lsr = get[1];
|
|
|
|
if (ISSET(lsr, LSR_OE | LSR_BI | LSR_FE | LSR_PE)) {
|
|
|
|
if (ISSET(lsr, LSR_OE)) {
|
|
|
|
sc->sc_overflows++;
|
|
|
|
if (sc->sc_errors++ == 0)
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_diag_callout,
|
|
|
|
60 * hz, comdiag, sc);
|
1997-11-03 11:20:35 +03:00
|
|
|
}
|
1997-11-03 09:12:02 +03:00
|
|
|
if (ISSET(lsr, LSR_BI | LSR_FE))
|
|
|
|
SET(code, TTY_FE);
|
|
|
|
if (ISSET(lsr, LSR_PE))
|
|
|
|
SET(code, TTY_PE);
|
|
|
|
}
|
|
|
|
if ((*rint)(code, tp) == -1) {
|
1997-06-15 15:18:59 +04:00
|
|
|
/*
|
|
|
|
* The line discipline's buffer is out of space.
|
|
|
|
*/
|
|
|
|
if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
|
|
|
|
/*
|
|
|
|
* We're either not using flow control, or the
|
|
|
|
* line discipline didn't tell us to block for
|
|
|
|
* some reason. Either way, we have no way to
|
|
|
|
* know when there's more space available, so
|
|
|
|
* just drop the rest of the data.
|
|
|
|
*/
|
1997-11-03 09:12:02 +03:00
|
|
|
get += cc << 1;
|
|
|
|
if (get >= end)
|
|
|
|
get -= com_rbuf_size << 1;
|
1997-06-15 15:18:59 +04:00
|
|
|
cc = 0;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Don't schedule any more receive processing
|
|
|
|
* until the line discipline tells us there's
|
|
|
|
* space available (through comhwiflow()).
|
|
|
|
* Leave the rest of the data in the input
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
SET(sc->sc_rx_flags, RX_TTY_OVERFLOWED);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1997-11-03 09:12:02 +03:00
|
|
|
get += 2;
|
|
|
|
if (get >= end)
|
|
|
|
get = sc->sc_rbuf;
|
1997-06-15 15:18:59 +04:00
|
|
|
cc--;
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
|
|
|
|
1997-06-15 15:18:59 +04:00
|
|
|
if (cc != scc) {
|
|
|
|
sc->sc_rbget = get;
|
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
|
|
|
|
1997-06-15 15:18:59 +04:00
|
|
|
cc = sc->sc_rbavail += scc - cc;
|
|
|
|
/* Buffers should be ok again, release possible block. */
|
|
|
|
if (cc >= sc->sc_r_lowat) {
|
|
|
|
if (ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
|
|
|
|
CLR(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
|
|
|
|
SET(sc->sc_ier, IER_ERXRDY);
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_ier, sc->sc_ier);
|
|
|
|
}
|
|
|
|
if (ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED)) {
|
|
|
|
CLR(sc->sc_rx_flags, RX_IBUF_BLOCKED);
|
|
|
|
com_hwiflow(sc);
|
|
|
|
}
|
|
|
|
}
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1997-06-15 15:18:59 +04:00
|
|
|
splx(s);
|
1995-06-05 00:39:22 +04:00
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
1994-08-07 15:27:51 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
integrate void
|
1997-11-03 09:12:02 +03:00
|
|
|
com_txsoft(sc, tp)
|
|
|
|
struct com_softc *sc;
|
|
|
|
struct tty *tp;
|
1997-04-05 00:56:34 +04:00
|
|
|
{
|
1995-06-05 00:39:22 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
CLR(tp->t_state, TS_BUSY);
|
|
|
|
if (ISSET(tp->t_state, TS_FLUSH))
|
|
|
|
CLR(tp->t_state, TS_FLUSH);
|
|
|
|
else
|
|
|
|
ndflush(&tp->t_outq, (int)(sc->sc_tba - tp->t_outq.c_cf));
|
2000-11-02 02:54:57 +03:00
|
|
|
(*tp->t_linesw->l_start)(tp);
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
1995-06-05 00:39:22 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
integrate void
|
1997-11-03 09:12:02 +03:00
|
|
|
com_stsoft(sc, tp)
|
|
|
|
struct com_softc *sc;
|
|
|
|
struct tty *tp;
|
1997-04-05 00:56:34 +04:00
|
|
|
{
|
|
|
|
u_char msr, delta;
|
|
|
|
int s;
|
1995-06-05 00:39:22 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
s = splserial();
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1997-04-05 00:56:34 +04:00
|
|
|
msr = sc->sc_msr;
|
|
|
|
delta = sc->sc_msr_delta;
|
|
|
|
sc->sc_msr_delta = 0;
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1997-04-05 00:56:34 +04:00
|
|
|
splx(s);
|
1995-06-05 00:39:22 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
if (ISSET(delta, sc->sc_msr_dcd)) {
|
|
|
|
/*
|
|
|
|
* Inform the tty layer that carrier detect changed.
|
|
|
|
*/
|
2000-11-02 02:54:57 +03:00
|
|
|
(void) (*tp->t_linesw->l_modem)(tp, ISSET(msr, MSR_DCD));
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ISSET(delta, sc->sc_msr_cts)) {
|
|
|
|
/* Block or unblock output according to flow control. */
|
|
|
|
if (ISSET(msr, sc->sc_msr_cts)) {
|
|
|
|
sc->sc_tx_stopped = 0;
|
2000-11-02 02:54:57 +03:00
|
|
|
(*tp->t_linesw->l_start)(tp);
|
1997-04-05 00:56:34 +04:00
|
|
|
} else {
|
|
|
|
sc->sc_tx_stopped = 1;
|
1995-07-04 10:47:18 +04:00
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
1995-07-04 10:47:18 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
#ifdef COM_DEBUG
|
1997-06-15 15:18:59 +04:00
|
|
|
if (com_debug)
|
1997-11-03 09:12:02 +03:00
|
|
|
comstatus(sc, "com_stsoft");
|
1997-04-05 00:56:34 +04:00
|
|
|
#endif
|
|
|
|
}
|
1995-06-05 00:39:22 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
#ifdef __GENERIC_SOFT_INTERRUPTS
|
|
|
|
void
|
|
|
|
comsoft(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct com_softc *sc = arg;
|
|
|
|
struct tty *tp;
|
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
if (COM_ISALIVE(sc) == 0)
|
1998-02-02 02:33:01 +03:00
|
|
|
return;
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
{
|
|
|
|
#else
|
|
|
|
void
|
1998-02-03 02:01:02 +03:00
|
|
|
#ifndef __NO_SOFT_SERIAL_INTERRUPT
|
1997-04-05 00:56:34 +04:00
|
|
|
comsoft()
|
|
|
|
#else
|
|
|
|
comsoft(arg)
|
|
|
|
void *arg;
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct com_softc *sc;
|
|
|
|
struct tty *tp;
|
|
|
|
int unit;
|
1998-02-03 02:01:02 +03:00
|
|
|
#ifdef __NO_SOFT_SERIAL_INTERRUPT
|
1997-04-05 00:56:34 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splsoftserial();
|
|
|
|
com_softintr_scheduled = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (unit = 0; unit < com_cd.cd_ndevs; unit++) {
|
2000-07-06 05:47:34 +04:00
|
|
|
sc = device_lookup(&com_cd, unit);
|
1998-02-03 01:54:55 +03:00
|
|
|
if (sc == NULL || !ISSET(sc->sc_hwflags, COM_HW_DEV_OK))
|
1995-06-05 00:39:22 +04:00
|
|
|
continue;
|
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
if (COM_ISALIVE(sc) == 0)
|
1998-02-02 02:33:01 +03:00
|
|
|
continue;
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
tp = sc->sc_tty;
|
1998-03-21 07:02:47 +03:00
|
|
|
if (tp == NULL)
|
|
|
|
continue;
|
|
|
|
if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0)
|
1997-04-05 00:56:34 +04:00
|
|
|
continue;
|
1997-08-27 22:00:13 +04:00
|
|
|
#endif
|
|
|
|
tp = sc->sc_tty;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
|
|
|
if (sc->sc_rx_ready) {
|
|
|
|
sc->sc_rx_ready = 0;
|
1997-11-03 09:12:02 +03:00
|
|
|
com_rxsoft(sc, tp);
|
1995-10-15 22:43:04 +03:00
|
|
|
}
|
1995-06-05 00:39:22 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
if (sc->sc_st_check) {
|
|
|
|
sc->sc_st_check = 0;
|
1997-11-03 09:12:02 +03:00
|
|
|
com_stsoft(sc, tp);
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
1995-06-05 00:39:22 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
if (sc->sc_tx_done) {
|
|
|
|
sc->sc_tx_done = 0;
|
1997-11-03 09:12:02 +03:00
|
|
|
com_txsoft(sc, tp);
|
1995-06-05 00:39:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
#ifndef __GENERIC_SOFT_INTERRUPTS
|
1998-02-03 02:01:02 +03:00
|
|
|
#ifdef __NO_SOFT_SERIAL_INTERRUPT
|
1997-04-05 00:56:34 +04:00
|
|
|
splx(s);
|
|
|
|
#endif
|
|
|
|
#endif
|
1994-08-07 15:27:51 +04:00
|
|
|
}
|
|
|
|
|
1998-02-25 11:32:35 +03:00
|
|
|
#ifdef __ALIGN_BRACKET_LEVEL_FOR_CTAGS
|
|
|
|
/* there has got to be a better way to do comsoft() */
|
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
|
1994-03-08 11:12:56 +03:00
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
comintr(arg)
|
1997-11-03 09:12:02 +03:00
|
|
|
void *arg;
|
1994-03-08 11:12:56 +03:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
struct com_softc *sc = arg;
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1997-11-03 09:12:02 +03:00
|
|
|
u_char *put, *end;
|
|
|
|
u_int cc;
|
|
|
|
u_char lsr, iir;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1998-11-19 02:58:52 +03:00
|
|
|
if (COM_ISALIVE(sc) == 0)
|
1998-02-02 02:33:01 +03:00
|
|
|
return (0);
|
|
|
|
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_LOCK(sc);
|
1996-10-22 02:34:38 +04:00
|
|
|
iir = bus_space_read_1(iot, ioh, com_iir);
|
2000-09-23 21:17:11 +04:00
|
|
|
if (ISSET(iir, IIR_NOPEND)) {
|
|
|
|
COM_UNLOCK(sc);
|
1996-10-06 05:52:26 +04:00
|
|
|
return (0);
|
2000-09-23 21:17:11 +04:00
|
|
|
}
|
1995-05-28 07:26:37 +04:00
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
end = sc->sc_ebuf;
|
1997-04-05 00:56:34 +04:00
|
|
|
put = sc->sc_rbput;
|
|
|
|
cc = sc->sc_rbavail;
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
do {
|
2000-02-07 05:17:18 +03:00
|
|
|
u_char msr, delta;
|
1995-05-28 07:26:37 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
lsr = bus_space_read_1(iot, ioh, com_lsr);
|
1997-08-12 21:25:43 +04:00
|
|
|
#if defined(DDB) || defined(KGDB)
|
|
|
|
if (ISSET(lsr, LSR_BI)) {
|
2000-08-03 04:30:47 +04:00
|
|
|
#ifndef DDB_BREAK_CHAR
|
1997-08-12 21:25:43 +04:00
|
|
|
#ifdef DDB
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
|
1999-01-26 20:08:37 +03:00
|
|
|
console_debugger();
|
1997-08-12 21:25:43 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef KGDB
|
|
|
|
if (ISSET(sc->sc_hwflags, COM_HW_KGDB)) {
|
|
|
|
kgdb_connect(1);
|
|
|
|
continue;
|
|
|
|
}
|
2000-08-03 04:30:47 +04:00
|
|
|
#endif
|
1997-07-06 00:52:40 +04:00
|
|
|
#endif
|
1997-08-12 21:25:43 +04:00
|
|
|
}
|
|
|
|
#endif /* DDB || KGDB */
|
1997-07-06 00:52:40 +04:00
|
|
|
|
1997-06-15 15:18:59 +04:00
|
|
|
if (ISSET(lsr, LSR_RCV_MASK) &&
|
|
|
|
!ISSET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED)) {
|
1997-11-03 09:12:02 +03:00
|
|
|
while (cc > 0) {
|
|
|
|
put[0] = bus_space_read_1(iot, ioh, com_data);
|
|
|
|
put[1] = lsr;
|
2000-09-22 03:27:32 +04:00
|
|
|
#if defined(DDB) && defined(DDB_BREAK_CHAR)
|
2000-08-03 04:30:47 +04:00
|
|
|
if (put[0] == DDB_BREAK_CHAR &&
|
|
|
|
ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) {
|
|
|
|
console_debugger();
|
|
|
|
|
|
|
|
lsr = bus_space_read_1(iot, ioh, com_lsr);
|
|
|
|
if (!ISSET(lsr, LSR_RCV_MASK))
|
|
|
|
break;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
1997-11-03 09:12:02 +03:00
|
|
|
put += 2;
|
|
|
|
if (put >= end)
|
|
|
|
put = sc->sc_rbuf;
|
|
|
|
cc--;
|
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
lsr = bus_space_read_1(iot, ioh, com_lsr);
|
1997-11-03 09:12:02 +03:00
|
|
|
if (!ISSET(lsr, LSR_RCV_MASK))
|
|
|
|
break;
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
1997-11-03 09:12:02 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/*
|
|
|
|
* Current string of incoming characters ended because
|
1997-11-03 09:12:02 +03:00
|
|
|
* no more data was available or we ran out of space.
|
|
|
|
* Schedule a receive event if any data was received.
|
|
|
|
* If we're out of space, turn off receive interrupts.
|
1997-04-05 00:56:34 +04:00
|
|
|
*/
|
|
|
|
sc->sc_rbput = put;
|
|
|
|
sc->sc_rbavail = cc;
|
1997-06-15 15:18:59 +04:00
|
|
|
if (!ISSET(sc->sc_rx_flags, RX_TTY_OVERFLOWED))
|
|
|
|
sc->sc_rx_ready = 1;
|
1997-11-03 09:12:02 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/*
|
|
|
|
* See if we are in danger of overflowing a buffer. If
|
|
|
|
* so, use hardware flow control to ease the pressure.
|
|
|
|
*/
|
1997-06-15 15:18:59 +04:00
|
|
|
if (!ISSET(sc->sc_rx_flags, RX_IBUF_BLOCKED) &&
|
1997-04-05 00:56:34 +04:00
|
|
|
cc < sc->sc_r_hiwat) {
|
1997-06-15 15:18:59 +04:00
|
|
|
SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
|
|
|
|
com_hwiflow(sc);
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
1997-11-03 09:12:02 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/*
|
1997-06-15 15:18:59 +04:00
|
|
|
* If we're out of space, disable receive interrupts
|
|
|
|
* until the queue has drained a bit.
|
1997-04-05 00:56:34 +04:00
|
|
|
*/
|
|
|
|
if (!cc) {
|
1997-06-15 15:18:59 +04:00
|
|
|
SET(sc->sc_rx_flags, RX_IBUF_OVERFLOWED);
|
|
|
|
CLR(sc->sc_ier, IER_ERXRDY);
|
|
|
|
bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
1996-10-06 05:52:26 +04:00
|
|
|
} else {
|
|
|
|
if ((iir & IIR_IMASK) == IIR_RXRDY) {
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_ier, 0);
|
1996-10-06 05:52:26 +04:00
|
|
|
delay(10);
|
1997-04-05 00:56:34 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_ier,sc->sc_ier);
|
1996-10-06 05:52:26 +04:00
|
|
|
iir = IIR_NOPEND;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1995-05-28 07:26:37 +04:00
|
|
|
|
1996-10-22 02:34:38 +04:00
|
|
|
msr = bus_space_read_1(iot, ioh, com_msr);
|
1997-04-05 00:56:34 +04:00
|
|
|
delta = msr ^ sc->sc_msr;
|
|
|
|
sc->sc_msr = msr;
|
2000-02-07 02:23:37 +03:00
|
|
|
/*
|
|
|
|
* Pulse-per-second (PSS) signals on edge of DCD?
|
|
|
|
* Process these even if line discipline is ignoring DCD.
|
|
|
|
*/
|
2000-02-07 05:17:18 +03:00
|
|
|
if (delta & sc->sc_ppsmask) {
|
2000-02-07 02:23:37 +03:00
|
|
|
struct timeval tv;
|
2000-02-07 05:17:18 +03:00
|
|
|
if ((msr & sc->sc_ppsmask) == sc->sc_ppsassert) {
|
2000-02-07 02:23:37 +03:00
|
|
|
/* XXX nanotime() */
|
|
|
|
microtime(&tv);
|
|
|
|
TIMEVAL_TO_TIMESPEC(&tv,
|
|
|
|
&sc->ppsinfo.assert_timestamp);
|
|
|
|
if (sc->ppsparam.mode & PPS_OFFSETASSERT) {
|
|
|
|
timespecadd(&sc->ppsinfo.assert_timestamp,
|
|
|
|
&sc->ppsparam.assert_offset,
|
1998-06-10 16:06:23 +04:00
|
|
|
&sc->ppsinfo.assert_timestamp);
|
2000-02-07 02:23:37 +03:00
|
|
|
}
|
1998-06-10 16:06:23 +04:00
|
|
|
|
|
|
|
#ifdef PPS_SYNC
|
2000-02-07 02:23:37 +03:00
|
|
|
if (sc->ppsparam.mode & PPS_HARDPPSONASSERT)
|
|
|
|
hardpps(&tv, tv.tv_usec);
|
1998-06-10 16:06:23 +04:00
|
|
|
#endif
|
2000-02-07 02:23:37 +03:00
|
|
|
sc->ppsinfo.assert_sequence++;
|
|
|
|
sc->ppsinfo.current_mode = sc->ppsparam.mode;
|
|
|
|
|
2000-02-07 05:17:18 +03:00
|
|
|
} else if ((msr & sc->sc_ppsmask) == sc->sc_ppsclear) {
|
2000-02-07 02:23:37 +03:00
|
|
|
/* XXX nanotime() */
|
|
|
|
microtime(&tv);
|
|
|
|
TIMEVAL_TO_TIMESPEC(&tv,
|
|
|
|
&sc->ppsinfo.clear_timestamp);
|
|
|
|
if (sc->ppsparam.mode & PPS_OFFSETCLEAR) {
|
|
|
|
timespecadd(&sc->ppsinfo.clear_timestamp,
|
|
|
|
&sc->ppsparam.clear_offset,
|
1998-06-10 16:06:23 +04:00
|
|
|
&sc->ppsinfo.clear_timestamp);
|
2000-02-07 02:23:37 +03:00
|
|
|
}
|
1998-06-10 16:06:23 +04:00
|
|
|
|
|
|
|
#ifdef PPS_SYNC
|
2000-02-07 02:23:37 +03:00
|
|
|
if (sc->ppsparam.mode & PPS_HARDPPSONCLEAR)
|
|
|
|
hardpps(&tv, tv.tv_usec);
|
1998-06-10 16:06:23 +04:00
|
|
|
#endif
|
2000-02-07 02:23:37 +03:00
|
|
|
sc->ppsinfo.clear_sequence++;
|
|
|
|
sc->ppsinfo.current_mode = sc->ppsparam.mode;
|
1998-06-10 16:06:23 +04:00
|
|
|
}
|
2000-02-07 02:23:37 +03:00
|
|
|
}
|
2000-02-07 05:17:18 +03:00
|
|
|
|
2000-02-07 02:23:37 +03:00
|
|
|
/*
|
|
|
|
* Process normal status changes
|
|
|
|
*/
|
|
|
|
if (ISSET(delta, sc->sc_msr_mask)) {
|
|
|
|
SET(sc->sc_msr_delta, delta);
|
1998-06-10 16:06:23 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/*
|
|
|
|
* Stop output immediately if we lose the output
|
|
|
|
* flow control signal or carrier detect.
|
|
|
|
*/
|
|
|
|
if (ISSET(~msr, sc->sc_msr_mask)) {
|
|
|
|
sc->sc_tbc = 0;
|
|
|
|
sc->sc_heldtbc = 0;
|
|
|
|
#ifdef COM_DEBUG
|
1997-06-15 15:18:59 +04:00
|
|
|
if (com_debug)
|
|
|
|
comstatus(sc, "comintr ");
|
1997-04-05 00:56:34 +04:00
|
|
|
#endif
|
1995-05-28 07:26:37 +04:00
|
|
|
}
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
sc->sc_st_check = 1;
|
1995-10-15 22:43:04 +03:00
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
} while (!ISSET((iir = bus_space_read_1(iot, ioh, com_iir)), IIR_NOPEND));
|
1995-10-15 22:43:04 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/*
|
|
|
|
* Done handling any receive interrupts. See if data can be
|
|
|
|
* transmitted as well. Schedule tx done event if no data left
|
|
|
|
* and tty was marked busy.
|
|
|
|
*/
|
|
|
|
if (ISSET(lsr, LSR_TXRDY)) {
|
|
|
|
/*
|
|
|
|
* If we've delayed a parameter change, do it now, and restart
|
|
|
|
* output.
|
|
|
|
*/
|
|
|
|
if (sc->sc_heldchange) {
|
|
|
|
com_loadchannelregs(sc);
|
|
|
|
sc->sc_heldchange = 0;
|
|
|
|
sc->sc_tbc = sc->sc_heldtbc;
|
|
|
|
sc->sc_heldtbc = 0;
|
|
|
|
}
|
1997-11-03 09:12:02 +03:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/* Output the next chunk of the contiguous buffer, if any. */
|
|
|
|
if (sc->sc_tbc > 0) {
|
|
|
|
int n;
|
|
|
|
|
1997-11-03 09:12:02 +03:00
|
|
|
n = sc->sc_tbc;
|
|
|
|
if (n > sc->sc_fifolen)
|
|
|
|
n = sc->sc_fifolen;
|
1997-04-05 00:56:34 +04:00
|
|
|
bus_space_write_multi_1(iot, ioh, com_data, sc->sc_tba, n);
|
|
|
|
sc->sc_tbc -= n;
|
|
|
|
sc->sc_tba += n;
|
1997-11-03 09:12:02 +03:00
|
|
|
} else {
|
|
|
|
/* Disable transmit completion interrupts if necessary. */
|
|
|
|
if (ISSET(sc->sc_ier, IER_ETXRDY)) {
|
|
|
|
CLR(sc->sc_ier, IER_ETXRDY);
|
|
|
|
bus_space_write_1(iot, ioh, com_ier, sc->sc_ier);
|
|
|
|
}
|
|
|
|
if (sc->sc_tx_busy) {
|
|
|
|
sc->sc_tx_busy = 0;
|
|
|
|
sc->sc_tx_done = 1;
|
|
|
|
}
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2000-09-23 21:17:11 +04:00
|
|
|
COM_UNLOCK(sc);
|
1996-10-06 05:52:26 +04:00
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/* Wake up the poller. */
|
|
|
|
#ifdef __GENERIC_SOFT_INTERRUPTS
|
|
|
|
softintr_schedule(sc->sc_si);
|
|
|
|
#else
|
1998-02-03 02:01:02 +03:00
|
|
|
#ifndef __NO_SOFT_SERIAL_INTERRUPT
|
1997-04-05 00:56:34 +04:00
|
|
|
setsoftserial();
|
|
|
|
#else
|
|
|
|
if (!com_softintr_scheduled) {
|
|
|
|
com_softintr_scheduled = 1;
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&comsoft_callout, 1, comsoft, NULL);
|
1996-02-19 17:53:03 +03:00
|
|
|
}
|
|
|
|
#endif
|
1997-04-05 00:56:34 +04:00
|
|
|
#endif
|
1997-10-19 15:45:33 +04:00
|
|
|
|
|
|
|
#if NRND > 0 && defined(RND_COM)
|
|
|
|
rnd_add_uint32(&sc->rnd_source, iir | lsr);
|
|
|
|
#endif
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
/*
|
|
|
|
* The following functions are polled getc and putc routines, shared
|
|
|
|
* by the console and kgdb glue.
|
|
|
|
*/
|
|
|
|
|
2000-08-03 04:30:47 +04:00
|
|
|
#if defined(DDB) && defined(DDB_BREAK_CHAR)
|
|
|
|
#define MAX_UNGETC 20
|
|
|
|
static int com_ungetc[MAX_UNGETC];
|
|
|
|
static int com_ungetccount = 0;
|
|
|
|
#endif
|
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
int
|
|
|
|
com_common_getc(iot, ioh)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
{
|
|
|
|
int s = splserial();
|
|
|
|
u_char stat, c;
|
|
|
|
|
2000-08-03 04:30:47 +04:00
|
|
|
#if defined(DDB) && defined(DDB_BREAK_CHAR)
|
|
|
|
/* got a character from reading things earlier */
|
|
|
|
if (com_ungetccount > 0) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
c = com_ungetc[0];
|
|
|
|
for (i = 1; i < com_ungetccount; i++) {
|
|
|
|
com_ungetc[i -1] = com_ungetc[i];
|
|
|
|
}
|
|
|
|
com_ungetccount--;
|
|
|
|
splx(s);
|
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-02-09 13:22:45 +03:00
|
|
|
/* block until a character becomes available */
|
|
|
|
while (!ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_RXRDY))
|
1997-07-06 00:52:40 +04:00
|
|
|
;
|
1998-02-09 13:22:45 +03:00
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
c = bus_space_read_1(iot, ioh, com_data);
|
|
|
|
stat = bus_space_read_1(iot, ioh, com_iir);
|
2000-08-03 04:30:47 +04:00
|
|
|
#if defined(DDB) && defined(DDB_BREAK_CHAR)
|
|
|
|
if (c == DDB_BREAK_CHAR) {
|
|
|
|
extern int db_active;
|
|
|
|
|
|
|
|
if (db_active == 0) {
|
|
|
|
console_debugger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1997-07-06 00:52:40 +04:00
|
|
|
splx(s);
|
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
com_common_putc(iot, ioh, c)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
int c;
|
|
|
|
{
|
|
|
|
int s = splserial();
|
1997-11-03 09:12:02 +03:00
|
|
|
int timo;
|
1997-07-06 00:52:40 +04:00
|
|
|
|
2000-08-03 04:30:47 +04:00
|
|
|
#if defined(DDB) && defined(DDB_BREAK_CHAR)
|
|
|
|
int cin, stat;
|
|
|
|
if (com_ungetccount < MAX_UNGETC
|
|
|
|
&& ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_RXRDY)) {
|
|
|
|
cin = bus_space_read_1(iot, ioh, com_data);
|
|
|
|
stat = bus_space_read_1(iot, ioh, com_iir);
|
|
|
|
if (cin == DDB_BREAK_CHAR) {
|
|
|
|
console_debugger();
|
|
|
|
}
|
|
|
|
com_ungetc[com_ungetccount++] = cin;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
/* wait for any pending transmission to finish */
|
1999-04-19 23:27:31 +04:00
|
|
|
timo = 150000;
|
1999-04-19 02:02:47 +04:00
|
|
|
while (!ISSET(bus_space_read_1(iot, ioh, com_lsr), LSR_TXRDY) && --timo)
|
1999-04-19 23:27:31 +04:00
|
|
|
continue;
|
1998-02-09 13:22:45 +03:00
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_data, c);
|
1999-04-19 02:02:47 +04:00
|
|
|
COM_BARRIER(iot, ioh, BR | BW);
|
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
/* wait for this transmission to complete */
|
1999-04-19 23:27:31 +04:00
|
|
|
timo = 1500000;
|
1999-04-19 02:02:47 +04:00
|
|
|
while (!ISSET(bus_space_read_1(iot, ioh, com_lsr), LSR_TXRDY) && --timo)
|
1999-04-19 23:27:31 +04:00
|
|
|
continue;
|
1998-02-09 13:22:45 +03:00
|
|
|
|
1999-03-29 17:21:15 +04:00
|
|
|
splx(s);
|
1997-07-06 00:52:40 +04:00
|
|
|
}
|
|
|
|
|
1997-04-05 00:56:34 +04:00
|
|
|
/*
|
1999-12-21 14:04:36 +03:00
|
|
|
* Initialize UART for use as console or KGDB line.
|
1997-04-05 00:56:34 +04:00
|
|
|
*/
|
1997-08-23 18:01:32 +04:00
|
|
|
int
|
1997-09-17 00:34:23 +04:00
|
|
|
cominit(iot, iobase, rate, frequency, cflag, iohp)
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_tag_t iot;
|
2000-09-22 18:46:38 +04:00
|
|
|
bus_addr_t iobase;
|
1997-09-17 00:34:23 +04:00
|
|
|
int rate, frequency;
|
1997-08-23 18:01:32 +04:00
|
|
|
tcflag_t cflag;
|
|
|
|
bus_space_handle_t *iohp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-08-23 18:01:32 +04:00
|
|
|
bus_space_handle_t ioh;
|
|
|
|
|
|
|
|
if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh))
|
1997-09-19 05:17:37 +04:00
|
|
|
return (ENOMEM); /* ??? */
|
1994-03-08 11:12:56 +03:00
|
|
|
|
1997-10-19 18:26:16 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_lcr, LCR_EERS);
|
|
|
|
bus_space_write_1(iot, ioh, com_efr, 0);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_lcr, LCR_DLAB);
|
1997-09-17 00:34:23 +04:00
|
|
|
rate = comspeed(rate, frequency);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_dlbl, rate);
|
|
|
|
bus_space_write_1(iot, ioh, com_dlbh, rate >> 8);
|
1997-08-23 18:01:32 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_lcr, cflag2lcr(cflag));
|
1999-12-21 14:04:36 +03:00
|
|
|
bus_space_write_1(iot, ioh, com_mcr, MCR_DTR | MCR_RTS);
|
1996-10-22 02:34:38 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_fifo,
|
1996-10-06 05:46:04 +04:00
|
|
|
FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
|
1997-04-05 00:56:34 +04:00
|
|
|
bus_space_write_1(iot, ioh, com_ier, 0);
|
1997-08-23 18:01:32 +04:00
|
|
|
|
|
|
|
*iohp = ioh;
|
1997-09-19 05:17:37 +04:00
|
|
|
return (0);
|
1997-04-05 00:56:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-08-23 18:01:32 +04:00
|
|
|
* Following are all routines needed for COM to act as console
|
1997-04-05 00:56:34 +04:00
|
|
|
*/
|
2000-09-22 03:27:32 +04:00
|
|
|
struct consdev comcons = {
|
|
|
|
NULL, NULL, comcngetc, comcnputc, comcnpollc, NULL,
|
|
|
|
NODEV, CN_NORMAL
|
|
|
|
};
|
|
|
|
|
1997-08-23 18:01:32 +04:00
|
|
|
|
|
|
|
int
|
1997-09-17 00:34:23 +04:00
|
|
|
comcnattach(iot, iobase, rate, frequency, cflag)
|
1997-04-05 00:56:34 +04:00
|
|
|
bus_space_tag_t iot;
|
2000-09-22 18:46:38 +04:00
|
|
|
bus_addr_t iobase;
|
1997-09-17 00:34:23 +04:00
|
|
|
int rate, frequency;
|
1997-08-23 18:01:32 +04:00
|
|
|
tcflag_t cflag;
|
1997-04-05 00:56:34 +04:00
|
|
|
{
|
1997-08-23 18:01:32 +04:00
|
|
|
int res;
|
1997-04-05 00:56:34 +04:00
|
|
|
|
1997-09-17 00:34:23 +04:00
|
|
|
res = cominit(iot, iobase, rate, frequency, cflag, &comconsioh);
|
1997-09-19 05:17:37 +04:00
|
|
|
if (res)
|
|
|
|
return (res);
|
1997-08-23 18:01:32 +04:00
|
|
|
|
|
|
|
cn_tab = &comcons;
|
|
|
|
|
|
|
|
comconstag = iot;
|
|
|
|
comconsaddr = iobase;
|
|
|
|
comconsrate = rate;
|
|
|
|
comconscflag = cflag;
|
|
|
|
|
1997-09-19 05:17:37 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-04-30 00:02:32 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
comcngetc(dev)
|
1994-03-08 11:12:56 +03:00
|
|
|
dev_t dev;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
return (com_common_getc(comconstag, comconsioh));
|
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
|
|
|
{
|
|
|
|
|
1997-07-06 00:52:40 +04:00
|
|
|
com_common_putc(comconstag, comconsioh, c);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-10-26 21:06:30 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
comcnpollc(dev, on)
|
|
|
|
dev_t dev;
|
|
|
|
int on;
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
1997-08-23 18:01:32 +04:00
|
|
|
|
|
|
|
#ifdef KGDB
|
|
|
|
int
|
1997-09-17 00:34:23 +04:00
|
|
|
com_kgdb_attach(iot, iobase, rate, frequency, cflag)
|
1997-08-23 18:01:32 +04:00
|
|
|
bus_space_tag_t iot;
|
2000-09-22 18:46:38 +04:00
|
|
|
bus_addr_t iobase;
|
1997-10-03 10:11:35 +04:00
|
|
|
int rate, frequency;
|
1997-08-23 18:01:32 +04:00
|
|
|
tcflag_t cflag;
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
1997-08-24 13:40:16 +04:00
|
|
|
if (iot == comconstag && iobase == comconsaddr)
|
1997-09-19 05:17:37 +04:00
|
|
|
return (EBUSY); /* cannot share with console */
|
1997-08-24 13:40:16 +04:00
|
|
|
|
1997-09-17 00:34:23 +04:00
|
|
|
res = cominit(iot, iobase, rate, frequency, cflag, &com_kgdb_ioh);
|
1997-09-19 05:17:37 +04:00
|
|
|
if (res)
|
|
|
|
return (res);
|
1997-08-23 18:01:32 +04:00
|
|
|
|
|
|
|
kgdb_attach(com_kgdb_getc, com_kgdb_putc, NULL);
|
|
|
|
kgdb_dev = 123; /* unneeded, only to satisfy some tests */
|
|
|
|
|
|
|
|
com_kgdb_iot = iot;
|
|
|
|
com_kgdb_addr = iobase;
|
|
|
|
|
1997-09-19 05:17:37 +04:00
|
|
|
return (0);
|
1997-08-23 18:01:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
com_kgdb_getc(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (com_common_getc(com_kgdb_iot, com_kgdb_ioh));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
|
|
|
com_kgdb_putc(arg, c)
|
|
|
|
void *arg;
|
|
|
|
int c;
|
|
|
|
{
|
|
|
|
|
|
|
|
return (com_common_putc(com_kgdb_iot, com_kgdb_ioh, c));
|
|
|
|
}
|
|
|
|
#endif /* KGDB */
|
|
|
|
|
|
|
|
/* helper function to identify the com ports used by
|
|
|
|
console or KGDB (and not yet autoconf attached) */
|
|
|
|
int
|
|
|
|
com_is_console(iot, iobase, ioh)
|
1997-09-19 05:17:37 +04:00
|
|
|
bus_space_tag_t iot;
|
2000-09-22 18:46:38 +04:00
|
|
|
bus_addr_t iobase;
|
1997-09-19 05:17:37 +04:00
|
|
|
bus_space_handle_t *ioh;
|
1997-08-23 18:01:32 +04:00
|
|
|
{
|
|
|
|
bus_space_handle_t help;
|
|
|
|
|
1997-09-19 05:17:37 +04:00
|
|
|
if (!comconsattached &&
|
|
|
|
iot == comconstag && iobase == comconsaddr)
|
1997-08-23 18:01:32 +04:00
|
|
|
help = comconsioh;
|
|
|
|
#ifdef KGDB
|
1997-09-19 05:17:37 +04:00
|
|
|
else if (!com_kgdb_attached &&
|
|
|
|
iot == com_kgdb_iot && iobase == com_kgdb_addr)
|
1997-08-23 18:01:32 +04:00
|
|
|
help = com_kgdb_ioh;
|
|
|
|
#endif
|
|
|
|
else
|
1997-09-19 05:17:37 +04:00
|
|
|
return (0);
|
1997-08-23 18:01:32 +04:00
|
|
|
|
1997-09-19 05:17:37 +04:00
|
|
|
if (ioh)
|
|
|
|
*ioh = help;
|
|
|
|
return (1);
|
1997-08-23 18:01:32 +04:00
|
|
|
}
|