xref: /dragonfly/sys/dev/serial/sio/sio_private.h (revision 0de090e1)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
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  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $DragonFly: src/sys/dev/serial/sio/sio_private.h,v 1.2 2004/09/19 02:05:54 dillon Exp $
30  */
31 
32 #ifdef COM_MULTIPORT
33 /* checks in flags for multiport and which is multiport "master chip"
34  * for a given card
35  */
36 #define	COM_ISMULTIPORT(flags)	((flags) & 0x01)
37 #define	COM_MPMASTER(flags)	(((flags) >> 8) & 0x0ff)
38 #define	COM_NOTAST4(flags)	((flags) & 0x04)
39 #endif /* COM_MULTIPORT */
40 
41 #define	COM_CONSOLE(flags)	((flags) & 0x10)
42 #define	COM_FORCECONSOLE(flags)	((flags) & 0x20)
43 #define	COM_LLCONSOLE(flags)	((flags) & 0x40)
44 #define	COM_DEBUGGER(flags)	((flags) & 0x80)
45 #define	COM_LOSESOUTINTS(flags)	((flags) & 0x08)
46 #define	COM_NOFIFO(flags)		((flags) & 0x02)
47 #define COM_ST16650A(flags)	((flags) & 0x20000)
48 #define COM_C_NOPROBE		(0x40000)
49 #define COM_NOPROBE(flags)	((flags) & COM_C_NOPROBE)
50 #define COM_C_IIR_TXRDYBUG	(0x80000)
51 #define COM_IIR_TXRDYBUG(flags)	((flags) & COM_C_IIR_TXRDYBUG)
52 #define	COM_TI16754(flags)	((flags) & 0x200000)
53 #define	COM_FIFOSIZE(flags)	(((flags) & 0xff000000) >> 24)
54 
55 #define	CE_NTYPES			3
56 #define	CE_RECORD(com, errnum)		(++(com)->delta_error_counts[errnum])
57 
58 /* types.  XXX - should be elsewhere */
59 typedef u_int	Port_t;		/* hardware port */
60 typedef u_char	bool_t;		/* boolean */
61 
62 /* queue of linear buffers */
63 struct lbq {
64 	u_char	*l_head;	/* next char to process */
65 	u_char	*l_tail;	/* one past the last char to process */
66 	struct lbq *l_next;	/* next in queue */
67 	bool_t	l_queued;	/* nonzero if queued */
68 };
69 
70 /* com device structure */
71 struct com_s {
72 	u_int	flags;		/* Copy isa device flags */
73 	u_char	state;		/* miscellaneous flag bits */
74 	bool_t  active_out;	/* nonzero if the callout device is open */
75 	u_char	cfcr_image;	/* copy of value written to CFCR */
76 #ifdef COM_ESP
77 	bool_t	esp;		/* is this unit a hayes esp board? */
78 #endif
79 	u_char	extra_state;	/* more flag bits, separate for order trick */
80 	u_char	fifo_image;	/* copy of value written to FIFO */
81 	bool_t	hasfifo;	/* nonzero for 16550 UARTs */
82 	bool_t	st16650a;	/* Is a Startech 16650A or RTS/CTS compat */
83 	bool_t	loses_outints;	/* nonzero if device loses output interrupts */
84 	u_char	mcr_image;	/* copy of value written to MCR */
85 #ifdef COM_MULTIPORT
86 	bool_t	multiport;	/* is this unit part of a multiport device? */
87 #endif /* COM_MULTIPORT */
88 	bool_t	no_irq;		/* nonzero if irq is not attached */
89 	bool_t  gone;		/* hardware disappeared */
90 	bool_t	poll;		/* nonzero if polling is required */
91 	bool_t	poll_output;	/* nonzero if polling for output is required */
92 	int	unit;		/* unit	number */
93 	int	dtr_wait;	/* time to hold DTR down on close (* 1/hz) */
94 	struct callout dtr_ch;
95 	struct callout busy_ch;
96 	u_int	tx_fifo_size;
97 	u_int	wopeners;	/* # processes waiting for DCD in open() */
98 
99 	/*
100 	 * The high level of the driver never reads status registers directly
101 	 * because there would be too many side effects to handle conveniently.
102 	 * Instead, it reads copies of the registers stored here by the
103 	 * interrupt handler.
104 	 */
105 	u_char	last_modem_status;	/* last MSR read by intr handler */
106 	u_char	prev_modem_status;	/* last MSR handled by high level */
107 
108 	u_char	hotchar;	/* ldisc-specific char to be handled ASAP */
109 	u_char	*ibuf;		/* start of input buffer */
110 	u_char	*ibufend;	/* end of input buffer */
111 	u_char	*ibufold;	/* old input buffer, to be freed */
112 	u_char	*ihighwater;	/* threshold in input buffer */
113 	u_char	*iptr;		/* next free spot in input buffer */
114 	int	ibufsize;	/* size of ibuf (not include error bytes) */
115 	int	ierroff;	/* offset of error bytes in ibuf */
116 
117 	struct lbq	obufq;	/* head of queue of output buffers */
118 	struct lbq	obufs[2];	/* output buffers */
119 
120 	bus_space_tag_t		bst;
121 	bus_space_handle_t	bsh;
122 
123 	Port_t	data_port;	/* i/o ports */
124 #ifdef COM_ESP
125 	Port_t	esp_port;
126 #endif
127 	Port_t	int_id_port;
128 	Port_t	modem_ctl_port;
129 	Port_t	line_status_port;
130 	Port_t	modem_status_port;
131 	Port_t	intr_ctl_port;	/* Ports of IIR register */
132 
133 	struct tty	*tp;	/* cross reference */
134 
135 	/* Initial state. */
136 	struct termios	it_in;	/* should be in struct tty */
137 	struct termios	it_out;
138 
139 	/* Lock state. */
140 	struct termios	lt_in;	/* should be in struct tty */
141 	struct termios	lt_out;
142 
143 	bool_t	do_timestamp;
144 	bool_t	do_dcd_timestamp;
145 	struct timeval	timestamp;
146 	struct timeval	dcd_timestamp;
147 	struct	pps_state pps;
148 
149 	u_long	bytes_in;	/* statistics */
150 	u_long	bytes_out;
151 	u_int	delta_error_counts[CE_NTYPES];
152 	u_long	error_counts[CE_NTYPES];
153 
154 	u_long	rclk;
155 
156 	struct resource *irqres;
157 	struct resource *ioportres;
158 	void *cookie;
159 
160 	/*
161 	 * Data area for output buffers.  Someday we should build the output
162 	 * buffer queue without copying data.
163 	 */
164 	u_char	obuf1[256];
165 	u_char	obuf2[256];
166 };
167 
168 #define SET_FLAG(dev, bit) device_set_flags(dev, device_get_flags(dev) | (bit))
169 #define CLR_FLAG(dev, bit) device_set_flags(dev, device_get_flags(dev) & ~(bit))
170 
171 extern devclass_t	sio_devclass;
172 
173 int	sioattach	(device_t dev, int rid, u_long rclk);
174 int	sioprobe	(device_t dev, int xrid, u_long rclk);
175