xref: /netbsd-src/sys/dev/ic/comvar.h (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: comvar.h,v 1.50 2005/12/27 00:46:38 chs Exp $	*/
2 
3 /*
4  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Christopher G. Demetriou
17  *	for the NetBSD Project.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "rnd.h"
34 #include "opt_multiprocessor.h"
35 #include "opt_lockdebug.h"
36 #include "opt_com.h"
37 #include "opt_kgdb.h"
38 
39 #if NRND > 0 && defined(RND_COM)
40 #include <sys/rnd.h>
41 #endif
42 
43 #include <sys/callout.h>
44 #include <sys/timepps.h>
45 #include <sys/lock.h>
46 
47 int comcnattach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
48 
49 #ifdef KGDB
50 int com_kgdb_attach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t);
51 #endif
52 
53 int com_is_console(bus_space_tag_t, bus_addr_t, bus_space_handle_t *);
54 
55 /* Hardware flag masks */
56 #define	COM_HW_NOIEN	0x01
57 #define	COM_HW_FIFO	0x02
58 		/*	0x04	free for use */
59 #define	COM_HW_FLOW	0x08
60 #define	COM_HW_DEV_OK	0x20
61 #define	COM_HW_CONSOLE	0x40
62 #define	COM_HW_KGDB	0x80
63 #define	COM_HW_TXFIFO_DISABLE	0x100
64 #define	COM_HW_NO_TXPRELOAD	0x200
65 
66 /* Buffer size for character buffer */
67 #define	COM_RING_SIZE	2048
68 
69 struct com_softc {
70 	struct device sc_dev;
71 	void *sc_si;
72 	struct tty *sc_tty;
73 
74 	struct callout sc_diag_callout;
75 
76 	bus_addr_t sc_iobase;			/* XXX ISA-centric name */
77 	int sc_frequency;
78 
79 	bus_space_tag_t sc_iot;
80 	bus_space_handle_t sc_ioh;
81 	bus_space_handle_t sc_hayespioh;
82 
83 	u_int sc_overflows,
84 	      sc_floods,
85 	      sc_errors;
86 
87 	int sc_hwflags,
88 	    sc_swflags;
89 	u_int sc_fifolen;
90 
91 	u_int sc_r_hiwat,
92 	      sc_r_lowat;
93 	u_char *volatile sc_rbget,
94 	       *volatile sc_rbput;
95  	volatile u_int sc_rbavail;
96 	u_char *sc_rbuf,
97 	       *sc_ebuf;
98 
99  	u_char *sc_tba;
100  	u_int sc_tbc,
101 	      sc_heldtbc;
102 
103 	volatile u_char sc_rx_flags,
104 #define	RX_TTY_BLOCKED		0x01
105 #define	RX_TTY_OVERFLOWED	0x02
106 #define	RX_IBUF_BLOCKED		0x04
107 #define	RX_IBUF_OVERFLOWED	0x08
108 #define	RX_ANY_BLOCK		0x0f
109 			sc_tx_busy,
110 			sc_tx_done,
111 			sc_tx_stopped,
112 			sc_st_check,
113 			sc_rx_ready;
114 
115 	volatile u_char sc_heldchange;
116 	volatile u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr,
117 	    sc_mcr_active, sc_lcr, sc_ier, sc_fifo, sc_dlbl, sc_dlbh, sc_efr;
118 	u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd;
119 
120 #ifdef COM_HAYESP
121 	u_char sc_prescaler;
122 #endif
123 
124 	/*
125 	 * There are a great many almost-ns16550-compatible UARTs out
126 	 * there, which have minor differences.  The type field here
127 	 * lets us distinguish between them.
128 	 */
129 	int sc_type;
130 #define	COM_TYPE_NORMAL		0	/* normal 16x50 */
131 #define	COM_TYPE_HAYESP		1	/* Hayes ESP modem */
132 #define	COM_TYPE_PXA2x0		2	/* Intel PXA2x0 processor built-in */
133 #define	COM_TYPE_AU1x00		3	/* AMD/Alchemy Au1x000 proc. built-in */
134 
135 	/* power management hooks */
136 	int (*enable)(struct com_softc *);
137 	void (*disable)(struct com_softc *);
138 	int enabled;
139 
140 	/* PPS signal on DCD, with or without inkernel clock disciplining */
141 	u_char	sc_ppsmask;			/* pps signal mask */
142 	u_char	sc_ppsassert;			/* pps leading edge */
143 	u_char	sc_ppsclear;			/* pps trailing edge */
144 	pps_info_t ppsinfo;
145 	pps_params_t ppsparam;
146 
147 #if NRND > 0 && defined(RND_COM)
148 	rndsource_element_t  rnd_source;
149 #endif
150 	struct simplelock	sc_lock;
151 };
152 
153 /* Macros to clear/set/test flags. */
154 #define SET(t, f)	(t) |= (f)
155 #define CLR(t, f)	(t) &= ~(f)
156 #define ISSET(t, f)	((t) & (f))
157 
158 int comprobe1(bus_space_tag_t, bus_space_handle_t);
159 int comintr(void *);
160 void com_attach_subr(struct com_softc *);
161 int com_detach(struct device *, int);
162 int com_activate(struct device *, enum devact);
163 
164 #ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
165 #ifdef __NO_SOFT_SERIAL_INTERRUPT
166 #define	IPL_SERIAL	IPL_TTY
167 #define	splserial()	spltty()
168 #define	IPL_SOFTSERIAL	IPL_TTY
169 #define	splsoftserial()	spltty()
170 #endif
171 #endif
172