xref: /netbsd/sys/arch/mips/sibyte/dev/sbjcnvar.h (revision 261b927a)
1 /* $NetBSD: sbjcnvar.h,v 1.9 2023/05/13 11:19:19 andvar Exp $ */
2 
3 /*
4  * Copyright 2000, 2001
5  * Broadcom Corporation. All rights reserved.
6  *
7  * This software is furnished under license and may be used and copied only
8  * in accordance with the following terms and conditions.  Subject to these
9  * conditions, you may download, copy, install, use, modify and distribute
10  * modified or unmodified copies of this software in source and/or binary
11  * form. No title or ownership is transferred hereby.
12  *
13  * 1) Any source code used, modified or distributed must reproduce and
14  *    retain this copyright notice and list of conditions as they appear in
15  *    the source file.
16  *
17  * 2) No right is granted to use any trade name, trademark, or logo of
18  *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
19  *    used to endorse or promote products derived from this software
20  *    without the prior written permission of Broadcom Corporation.
21  *
22  * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
23  *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
24  *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
25  *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
26  *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
27  *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32  *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /* from: $NetBSD: comvar.h,v 1.32 2000/03/23 07:01:30 thorpej Exp */
36 
37 /*
38  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  *    notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  *    notice, this list of conditions and the following disclaimer in the
47  *    documentation and/or other materials provided with the distribution.
48  * 3. All advertising materials mentioning features or use of this software
49  *    must display the following acknowledgement:
50  *      This product includes software developed by Christopher G. Demetriou
51  *	for the NetBSD Project.
52  * 4. The name of the author may not be used to endorse or promote products
53  *    derived from this software without specific prior written permission
54  *
55  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
56  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
57  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
58  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
59  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
60  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
64  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65  */
66 
67 #ifdef RND_SBJCN
68 #include <sys/rndsource.h>
69 #endif
70 
71 #include <sys/callout.h>
72 
73 #define	SBJCN_CHAN(x)		(TTUNIT(x) & 1)
74 #define	SBJCN_UNIT(x)		(TTUNIT(x) >> 1)
75 #define	SBJCN_DIALOUT(x)	TTDIALOUT(x)
76 
77 #define	SBJCN_TOLERANCE	30	/* baud rate tolerance, in 0.1% units */
78 
79 int	sbjcn_cnattach(u_long addr, int chan, int rate,
80 	    tcflag_t cflag);
81 #ifdef KGDB
82 int	sbjcn_kgdb_attach(u_long addr, int chan, int rate,
83 	    tcflag_t cflag);
84 #endif
85 int	sbjcn_is_console(u_long addr, int chan);
86 
87 /* Hardware flag masks */
88 #define	SBJCN_HW_CONSOLE		0x01
89 #define	SBJCN_HW_KGDB			0x02
90 #define	SBJCN_HW_DEV_OK			0x04
91 
92 /* Buffer size for character buffer */
93 #define	SBJCN_RING_SIZE		2048
94 
95 struct sbjcn_channel {
96 	int		ch_num;
97 	struct sbjcn_softc *ch_sc;
98 	struct tty	*ch_tty;	/* tty struct */
99 	struct callout	ch_diag_callout; /* callout for diagnostic msgs */
100 	struct callout	ch_callout;	/* callout for channel processing */
101 
102 	volatile char	*ch_input_reg;	/* kseg1 addr of input reg */
103 	volatile char	*ch_output_reg;	/* kseg1 addr of output reg */
104 	volatile char	*ch_control_reg;/* kseg1 addr of control reg */
105 
106 	volatile int	ch_waiting_input; /*  */
107 	volatile uint64_t ch_input_buf; /* up to 7 buffered bytes */
108 
109 	volatile char	*ch_base;	/* kseg1 addr of channel regs */
110 	volatile char	*ch_isr_base;	/* kseg1 addr of channel ISR */
111 	volatile char	*ch_imr_base;	/* kseg1 addr of channel IMR */
112 #ifdef XXXCGDnotyet
113 	volatile char	*ch_inchg_base;	/* kseg1 addr of channel inport-chg */
114 #endif
115 
116 	u_int		ch_overflows;
117 	u_int		ch_floods;
118 	u_int		ch_errors;
119 
120 	u_int		ch_hwflags;
121 	u_int		ch_swflags;
122 
123 	u_int		ch_r_hiwat;
124 	u_int		ch_r_lowat;
125 
126 	/* receive ring buffer management */
127 	u_char *volatile ch_rbget;
128 	u_char *volatile ch_rbput;
129  	volatile u_int	ch_rbavail;
130 	u_char		*ch_rbuf;
131 	u_char		*ch_ebuf;
132 
133 	/* transmit buffer management */
134 	u_char		*ch_tba;
135 	u_int		ch_tbc;
136 	u_int		ch_heldtbc;
137 
138 	volatile u_int ch_rx_flags;
139 #define	RX_TTY_BLOCKED		0x01
140 #define	RX_TTY_OVERFLOWED	0x02
141 #define	RX_IBUF_BLOCKED		0x04
142 #define	RX_IBUF_OVERFLOWED	0x08
143 #define	RX_ANY_BLOCK		0x0f
144 	volatile u_int	ch_tx_busy;
145 	volatile u_int	ch_tx_done;
146 	volatile u_int	ch_tx_stopped;
147 	volatile u_int	ch_rx_ready;
148 
149 	volatile u_char ch_heldchange;
150 
151 	volatile u_int	ch_brc;
152 	volatile u_char	ch_imr;
153 	volatile u_char	ch_iports, ch_iports_delta;
154 	volatile u_char	ch_oports, ch_oports_active;
155 	volatile u_char	ch_mode1, ch_mode2;
156 
157 	u_char		ch_i_dcd, ch_i_cts, ch_i_dsr, ch_i_ri, ch_i_mask;
158 	u_char		ch_o_dtr, ch_o_rts, ch_o_mask;
159 
160 	u_char		ch_i_dcd_pin, ch_i_cts_pin, ch_i_dsr_pin, ch_i_ri_pin;
161 	u_char		ch_o_dtr_pin, ch_o_rts_pin;
162 };
163 
164 struct sbjcn_softc {
165 	device_t	sc_dev;		/* base device */
166 
167 	/* shared data structures */
168 	u_long		sc_addr;	/* phys addr of JTAG console bus_space */
169 
170 	struct sbjcn_channel sc_channels[1];
171 };
172