digi.h revision 76196
1/*-
2 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/digi/digi.h 76196 2001-05-02 01:47:34Z brian $
27 */
28
29#define	W(p)				(*(u_int16_t *)(p))
30#define	vW(p)				(*(u_int16_t volatile *)(p))
31#define	D(p)				(*(u_int32_t *)(p))
32#define	vD(p)				(*(u_int32_t volatile *)(p))
33
34#define	CE_OVERRUN			0
35#define	CE_INTERRUPT_BUF_OVERFLOW	1
36#define	CE_TTY_BUF_OVERFLOW		2
37#define	CE_NTYPES			3
38#define	CE_RECORD(com, errnum)		(++(com)->delta_error_counts[errnum])
39
40#ifndef DEBUG
41#define	DEBUG
42#endif
43
44#ifdef DEBUG
45extern unsigned digi_debug;
46#define	DLOG(level, args)	if (digi_debug & (level)) device_printf args
47#else
48#define	DLOG(level, args)
49#endif
50
51
52struct digi_softc;
53
54/* digiboard port structure */
55struct digi_p {
56	struct digi_softc *sc;
57
58	int status;
59#define ENABLED 1
60#define DIGI_DTR_OFF 2
61#define PAUSE_TX 8
62#define PAUSE_RX 16
63
64	int opencnt;
65	ushort txbufsize;
66	ushort rxbufsize;
67	volatile struct board_chan *bc;
68	struct tty *tp;
69
70	dev_t dev[6];
71
72	u_char *txbuf;
73	u_char *rxbuf;
74	u_char txwin;
75	u_char rxwin;
76
77	u_char pnum;		/* port number */
78
79	u_char modemfake;	/* Modem values to be forced */
80	u_char mstat;
81	u_char modem;		/* Force values */
82
83	int active_out;		/* nonzero if the callout device is open */
84	int dtr_wait;		/* time to hold DTR down on close (* 1/hz) */
85	u_int wopeners;		/* # processes waiting for DCD in open() */
86
87	/*
88	 * The high level of the driver never reads status registers directly
89	 * because there would be too many side effects to handle conveniently.
90	 * Instead, it reads copies of the registers stored here by the
91	 * interrupt handler.
92	 */
93	u_char last_modem_status;	/* last MSR read by intr handler */
94	u_char prev_modem_status;	/* last MSR handled by high level */
95
96
97	/* Initial state. */
98	struct termios it_in;		/* should be in struct tty */
99	struct termios it_out;
100
101	/* Lock state. */
102	struct termios lt_in;		/* should be in struct tty */
103	struct termios lt_out;
104
105	u_int do_timestamp;
106	u_int do_dcd_timestamp;
107	struct timeval dcd_timestamp;
108
109	u_long bytes_in, bytes_out;
110	u_int delta_error_counts[CE_NTYPES];
111	u_long error_counts;
112
113	tcflag_t c_iflag;		/* hold true IXON/IXOFF/IXANY */
114	int lcc, lostcc, lbuf;
115	u_char send_ring;
116};
117
118/*
119 * Map TIOCM_* values to digiboard values
120 */
121struct digi_control_signals {
122	int rts;
123	int cd;
124	int dsr;
125	int cts;
126	int ri;
127	int dtr;
128};
129
130enum digi_board_status {
131	DIGI_STATUS_NOTINIT,
132	DIGI_STATUS_ENABLED,
133	DIGI_STATUS_DISABLED
134};
135
136/* Digiboard per-board structure */
137struct digi_softc {
138	/* struct board_info */
139	device_t dev;
140
141	const char *name;
142	enum digi_board_status status;
143	ushort numports;		/* number of ports on card */
144	ushort port;			/* I/O port */
145	ushort wport;			/* window select I/O port */
146
147	struct {
148		struct resource *mem;
149		int mrid;
150		struct resource *irq;
151		int irqrid;
152		struct resource *io;
153		int iorid;
154		void *irqHandler;
155		int unit;
156		dev_t ctldev;
157	} res;
158
159	u_char *vmem;			/* virtual memory address */
160	u_char *memcmd;
161	volatile u_char *memevent;
162	long pmem;			/* physical memory address */
163
164	struct {
165		u_char *data;
166		size_t size;
167	} bios, fep, link;
168
169#ifdef DIGI_INTERRUPT
170	struct timeval intr_timestamp;
171#endif
172
173	struct digi_p *ports;	/* pointer to array of port descriptors */
174	struct tty *ttys;	/* pointer to array of TTY structures */
175	volatile struct global_data *gdata;
176	u_char window;		/* saved window */
177	int win_size;
178	int win_bits;
179	int mem_size;
180	int mem_seg;
181	digiModel_t model;
182	const struct digi_control_signals *csigs;
183	int opencnt;
184	unsigned pcibus : 1;		/* On a PCI bus ? */
185
186	struct callout_handle callout;	/* poll timeout handle */
187	struct callout_handle inttest;	/* int test timeout handle */
188	const char *module;
189
190	u_char *(*setwin)(struct digi_softc *_sc, unsigned _addr);
191	void	(*hidewin)(struct digi_softc *_sc);
192	void	(*towin)(struct digi_softc *_sc, int _win);
193#ifdef DEBUG
194	int	intr_count;
195#endif
196};
197
198extern devclass_t digi_devclass;
199extern const struct digi_control_signals digi_xixe_signals;
200extern const struct digi_control_signals digi_normal_signals;
201
202const char	*digi_errortxt(int _id);
203int		 digi_modhandler(module_t _mod, int _event, void *_arg);
204int		 digi_attach(struct digi_softc *);
205int		 digi_detach(device_t _dev);
206int		 digi_shutdown(device_t _dev);
207