digi.h revision 76358
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 76358 2001-05-08 07:55:33Z 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/*#define DIGI_INTERRUPT*/
41
42#ifndef DEBUG
43#define	DEBUG
44#endif
45
46#ifdef DEBUG
47extern unsigned digi_debug;
48#define	DLOG(level, args)	if (digi_debug & (level)) device_printf args
49#else
50#define	DLOG(level, args)
51#endif
52
53
54struct digi_softc;
55
56/* digiboard port structure */
57struct digi_p {
58	struct digi_softc *sc;
59
60	int status;
61#define ENABLED 1
62#define DIGI_DTR_OFF 2
63#define PAUSE_TX 8
64#define PAUSE_RX 16
65
66	int opencnt;
67	ushort txbufsize;
68	ushort rxbufsize;
69	volatile struct board_chan *bc;
70	struct tty *tp;
71
72	dev_t dev[6];
73
74	u_char *txbuf;
75	u_char *rxbuf;
76	u_char txwin;
77	u_char rxwin;
78
79	u_char pnum;		/* port number */
80
81	u_char modemfake;	/* Modem values to be forced */
82	u_char mstat;
83	u_char modem;		/* Force values */
84
85	int active_out;		/* nonzero if the callout device is open */
86	int dtr_wait;		/* time to hold DTR down on close (* 1/hz) */
87	u_int wopeners;		/* # processes waiting for DCD in open() */
88
89	/*
90	 * The high level of the driver never reads status registers directly
91	 * because there would be too many side effects to handle conveniently.
92	 * Instead, it reads copies of the registers stored here by the
93	 * interrupt handler.
94	 */
95	u_char last_modem_status;	/* last MSR read by intr handler */
96	u_char prev_modem_status;	/* last MSR handled by high level */
97
98
99	/* Initial state. */
100	struct termios it_in;		/* should be in struct tty */
101	struct termios it_out;
102
103	/* Lock state. */
104	struct termios lt_in;		/* should be in struct tty */
105	struct termios lt_out;
106
107	u_int do_timestamp;
108	u_int do_dcd_timestamp;
109	struct timeval dcd_timestamp;
110
111	u_long bytes_in, bytes_out;
112	u_int delta_error_counts[CE_NTYPES];
113	u_long error_counts;
114
115	tcflag_t c_iflag;		/* hold true IXON/IXOFF/IXANY */
116	int lcc, lostcc, lbuf;
117	u_char send_ring;
118};
119
120/*
121 * Map TIOCM_* values to digiboard values
122 */
123struct digi_control_signals {
124	int rts;
125	int cd;
126	int dsr;
127	int cts;
128	int ri;
129	int dtr;
130};
131
132enum digi_board_status {
133	DIGI_STATUS_NOTINIT,
134	DIGI_STATUS_ENABLED,
135	DIGI_STATUS_DISABLED
136};
137
138/* Digiboard per-board structure */
139struct digi_softc {
140	/* struct board_info */
141	device_t dev;
142
143	const char *name;
144	enum digi_board_status status;
145	ushort numports;		/* number of ports on card */
146	ushort port;			/* I/O port */
147	ushort wport;			/* window select I/O port */
148
149	struct {
150		struct resource *mem;
151		int mrid;
152		struct resource *irq;
153		int irqrid;
154		struct resource *io;
155		int iorid;
156		void *irqHandler;
157		int unit;
158		dev_t ctldev;
159	} res;
160
161	u_char *vmem;			/* virtual memory address */
162	u_char *memcmd;
163	volatile u_char *memevent;
164	long pmem;			/* physical memory address */
165
166	struct {
167		u_char *data;
168		size_t size;
169	} bios, fep, link;
170
171#ifdef DIGI_INTERRUPT
172	struct timeval intr_timestamp;
173#endif
174
175	struct digi_p *ports;	/* pointer to array of port descriptors */
176	struct tty *ttys;	/* pointer to array of TTY structures */
177	volatile struct global_data *gdata;
178	u_char window;		/* saved window */
179	int win_size;
180	int win_bits;
181	int mem_size;
182	int mem_seg;
183	digiModel_t model;
184	const struct digi_control_signals *csigs;
185	int opencnt;
186	unsigned pcibus : 1;		/* On a PCI bus ? */
187
188	struct callout_handle callout;	/* poll timeout handle */
189	struct callout_handle inttest;	/* int test timeout handle */
190	const char *module;
191
192	u_char *(*setwin)(struct digi_softc *_sc, unsigned _addr);
193	void	(*hidewin)(struct digi_softc *_sc);
194	void	(*towin)(struct digi_softc *_sc, int _win);
195#ifdef DEBUG
196	int	intr_count;
197#endif
198};
199
200extern devclass_t digi_devclass;
201extern const struct digi_control_signals digi_xixe_signals;
202extern const struct digi_control_signals digi_normal_signals;
203
204const char	*digi_errortxt(int _id);
205int		 digi_modhandler(module_t _mod, int _event, void *_arg);
206int		 digi_attach(struct digi_softc *);
207int		 digi_detach(device_t _dev);
208int		 digi_shutdown(device_t _dev);
209