digi.h revision 78496
176195Sbrian/*- 276195Sbrian * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org> 378412Sbrian * based on work by Slawa Olhovchenkov 478412Sbrian * John Prince <johnp@knight-trosoft.com> 578412Sbrian * Eric Hernes 676195Sbrian * All rights reserved. 776195Sbrian * 876195Sbrian * Redistribution and use in source and binary forms, with or without 976195Sbrian * modification, are permitted provided that the following conditions 1076195Sbrian * are met: 1176195Sbrian * 1. Redistributions of source code must retain the above copyright 1276195Sbrian * notice, this list of conditions and the following disclaimer. 1376195Sbrian * 2. Redistributions in binary form must reproduce the above copyright 1476195Sbrian * notice, this list of conditions and the following disclaimer in the 1576195Sbrian * documentation and/or other materials provided with the distribution. 1676195Sbrian * 1776195Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1876195Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1976195Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2076195Sbrian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2176195Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2276195Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2376195Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2476195Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2576195Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2676195Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2776195Sbrian * SUCH DAMAGE. 2876195Sbrian * 2976195Sbrian * $FreeBSD: head/sys/dev/digi/digi.h 78496 2001-06-20 14:52:08Z brian $ 3076195Sbrian */ 3176195Sbrian 3276195Sbrian#define W(p) (*(u_int16_t *)(p)) 3376195Sbrian#define vW(p) (*(u_int16_t volatile *)(p)) 3476195Sbrian#define D(p) (*(u_int32_t *)(p)) 3576195Sbrian#define vD(p) (*(u_int32_t volatile *)(p)) 3676195Sbrian 3776195Sbrian#define CE_OVERRUN 0 3876195Sbrian#define CE_INTERRUPT_BUF_OVERFLOW 1 3976195Sbrian#define CE_TTY_BUF_OVERFLOW 2 4076195Sbrian#define CE_NTYPES 3 4176195Sbrian#define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum]) 4276195Sbrian 4376327Sbrian/*#define DIGI_INTERRUPT*/ 4476327Sbrian 4576196Sbrian#ifndef DEBUG 4676195Sbrian#define DEBUG 4776196Sbrian#endif 4876195Sbrian 4976195Sbrian#ifdef DEBUG 5076195Sbrianextern unsigned digi_debug; 5176195Sbrian#define DLOG(level, args) if (digi_debug & (level)) device_printf args 5276195Sbrian#else 5376195Sbrian#define DLOG(level, args) 5476195Sbrian#endif 5576195Sbrian 5676195Sbrian 5776195Sbrianstruct digi_softc; 5876195Sbrian 5976195Sbrian/* digiboard port structure */ 6076195Sbrianstruct digi_p { 6176195Sbrian struct digi_softc *sc; 6276195Sbrian 6376195Sbrian int status; 6476195Sbrian#define ENABLED 1 6576195Sbrian#define DIGI_DTR_OFF 2 6676195Sbrian#define PAUSE_TX 8 6776195Sbrian#define PAUSE_RX 16 6876195Sbrian 6976195Sbrian int opencnt; 7076195Sbrian ushort txbufsize; 7176195Sbrian ushort rxbufsize; 7276195Sbrian volatile struct board_chan *bc; 7376195Sbrian struct tty *tp; 7476195Sbrian 7576195Sbrian dev_t dev[6]; 7676195Sbrian 7776195Sbrian u_char *txbuf; 7876195Sbrian u_char *rxbuf; 7976195Sbrian u_char txwin; 8076195Sbrian u_char rxwin; 8176195Sbrian 8276195Sbrian u_char pnum; /* port number */ 8376195Sbrian 8476195Sbrian u_char modemfake; /* Modem values to be forced */ 8576195Sbrian u_char mstat; 8676195Sbrian u_char modem; /* Force values */ 8776195Sbrian 8876195Sbrian int active_out; /* nonzero if the callout device is open */ 8976195Sbrian int dtr_wait; /* time to hold DTR down on close (* 1/hz) */ 9076195Sbrian u_int wopeners; /* # processes waiting for DCD in open() */ 9176195Sbrian 9276195Sbrian /* 9376195Sbrian * The high level of the driver never reads status registers directly 9476195Sbrian * because there would be too many side effects to handle conveniently. 9576195Sbrian * Instead, it reads copies of the registers stored here by the 9676195Sbrian * interrupt handler. 9776195Sbrian */ 9876195Sbrian u_char last_modem_status; /* last MSR read by intr handler */ 9976195Sbrian u_char prev_modem_status; /* last MSR handled by high level */ 10076195Sbrian 10176195Sbrian 10276195Sbrian /* Initial state. */ 10376195Sbrian struct termios it_in; /* should be in struct tty */ 10476195Sbrian struct termios it_out; 10576195Sbrian 10676195Sbrian /* Lock state. */ 10776195Sbrian struct termios lt_in; /* should be in struct tty */ 10876195Sbrian struct termios lt_out; 10976195Sbrian 11076195Sbrian u_int do_timestamp; 11176195Sbrian u_int do_dcd_timestamp; 11276195Sbrian struct timeval dcd_timestamp; 11376195Sbrian 11476195Sbrian u_long bytes_in, bytes_out; 11576195Sbrian u_int delta_error_counts[CE_NTYPES]; 11676195Sbrian u_long error_counts; 11776195Sbrian 11876195Sbrian tcflag_t c_iflag; /* hold true IXON/IXOFF/IXANY */ 11976195Sbrian int lcc, lostcc, lbuf; 12076195Sbrian u_char send_ring; 12178496Sbrian 12278496Sbrian unsigned laltpin : 1; /* Alternate pin settings locked */ 12378496Sbrian unsigned ialtpin : 1; /* Initial alternate pin settings */ 12478496Sbrian 12578496Sbrian int cd; /* Depends on the altpin setting */ 12678496Sbrian int dsr; 12776195Sbrian}; 12876195Sbrian 12976195Sbrian/* 13076195Sbrian * Map TIOCM_* values to digiboard values 13176195Sbrian */ 13276195Sbrianstruct digi_control_signals { 13376195Sbrian int rts; 13476195Sbrian int cd; 13576195Sbrian int dsr; 13676195Sbrian int cts; 13776195Sbrian int ri; 13876195Sbrian int dtr; 13976195Sbrian}; 14076195Sbrian 14176195Sbrianenum digi_board_status { 14276195Sbrian DIGI_STATUS_NOTINIT, 14376195Sbrian DIGI_STATUS_ENABLED, 14476195Sbrian DIGI_STATUS_DISABLED 14576195Sbrian}; 14676195Sbrian 14776195Sbrian/* Digiboard per-board structure */ 14876195Sbrianstruct digi_softc { 14976195Sbrian /* struct board_info */ 15076195Sbrian device_t dev; 15176195Sbrian 15276195Sbrian const char *name; 15376195Sbrian enum digi_board_status status; 15476195Sbrian ushort numports; /* number of ports on card */ 15576195Sbrian ushort port; /* I/O port */ 15676195Sbrian ushort wport; /* window select I/O port */ 15776195Sbrian 15876195Sbrian struct { 15976195Sbrian struct resource *mem; 16076195Sbrian int mrid; 16176195Sbrian struct resource *irq; 16276195Sbrian int irqrid; 16376195Sbrian struct resource *io; 16476195Sbrian int iorid; 16576195Sbrian void *irqHandler; 16676195Sbrian int unit; 16776195Sbrian dev_t ctldev; 16876195Sbrian } res; 16976195Sbrian 17076195Sbrian u_char *vmem; /* virtual memory address */ 17176195Sbrian u_char *memcmd; 17276195Sbrian volatile u_char *memevent; 17376195Sbrian long pmem; /* physical memory address */ 17476195Sbrian 17576195Sbrian struct { 17676195Sbrian u_char *data; 17776195Sbrian size_t size; 17876195Sbrian } bios, fep, link; 17976195Sbrian 18076195Sbrian#ifdef DIGI_INTERRUPT 18176195Sbrian struct timeval intr_timestamp; 18276195Sbrian#endif 18376195Sbrian 18476195Sbrian struct digi_p *ports; /* pointer to array of port descriptors */ 18576195Sbrian struct tty *ttys; /* pointer to array of TTY structures */ 18676195Sbrian volatile struct global_data *gdata; 18776195Sbrian u_char window; /* saved window */ 18876195Sbrian int win_size; 18976195Sbrian int win_bits; 19076195Sbrian int mem_size; 19176195Sbrian int mem_seg; 19276705Sbrian enum digi_model model; 19376195Sbrian const struct digi_control_signals *csigs; 19476195Sbrian int opencnt; 19576195Sbrian unsigned pcibus : 1; /* On a PCI bus ? */ 19676195Sbrian 19776195Sbrian struct callout_handle callout; /* poll timeout handle */ 19876195Sbrian struct callout_handle inttest; /* int test timeout handle */ 19976195Sbrian const char *module; 20076195Sbrian 20176195Sbrian u_char *(*setwin)(struct digi_softc *_sc, unsigned _addr); 20276195Sbrian void (*hidewin)(struct digi_softc *_sc); 20376195Sbrian void (*towin)(struct digi_softc *_sc, int _win); 20476195Sbrian#ifdef DEBUG 20576195Sbrian int intr_count; 20676195Sbrian#endif 20776195Sbrian}; 20876195Sbrian 20976195Sbrianextern devclass_t digi_devclass; 21076195Sbrianextern const struct digi_control_signals digi_xixe_signals; 21176195Sbrianextern const struct digi_control_signals digi_normal_signals; 21276195Sbrian 21376195Sbrianconst char *digi_errortxt(int _id); 21476195Sbrianint digi_modhandler(module_t _mod, int _event, void *_arg); 21576195Sbrianint digi_attach(struct digi_softc *); 21676195Sbrianint digi_detach(device_t _dev); 21776195Sbrianint digi_shutdown(device_t _dev); 218