xref: /netbsd-src/sys/arch/dreamcast/dev/maple/maplevar.h (revision 7fa608457b817eca6e0977b37f758ae064f3c99c)
1 /*	$NetBSD: maplevar.h,v 1.11 2007/10/17 19:54:10 garbled Exp $	*/
2 
3 /*-
4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by ITOH Yasufumi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*-
40  * Copyright (c) 2001 Marcus Comstedt
41  * All rights reserved.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  * 1. Redistributions of source code must retain the above copyright
47  *    notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in the
50  *    documentation and/or other materials provided with the distribution.
51  * 3. All advertising materials mentioning features or use of this software
52  *    must display the following acknowledgement:
53  *	This product includes software developed by Marcus Comstedt.
54  * 4. Neither the name of The NetBSD Foundation nor the names of its
55  *    contributors may be used to endorse or promote products derived
56  *    from this software without specific prior written permission.
57  *
58  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
59  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
60  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
61  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
62  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
64  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
66  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68  * POSSIBILITY OF SUCH DAMAGE.
69  */
70 
71 #include <sys/queue.h>
72 
73 #define MAPLE_PORTS 4
74 #define MAPLE_SUBUNITS 6
75 
76 #define MAPLE_NFUNC	32
77 
78 struct maple_func {
79 	int		f_funcno;
80 	struct maple_unit *f_unit;
81 	struct device	*f_dev;
82 
83 	/* callback */
84 	void		(*f_callback)(void *, struct maple_response *,
85 			    int /*len*/, int /*flags*/);
86 	void 		*f_arg;
87 
88 	uint32_t	f_work;		/* for periodic GETCOND and ping */
89 
90 	/* periodic command request */
91 	enum maple_periodic_stat {
92 		MAPLE_PERIODIC_NONE,
93 		MAPLE_PERIODIC_INQ,
94 		MAPLE_PERIODIC_DEFERED
95 	} f_periodic_stat;
96 	TAILQ_ENTRY(maple_func)	f_periodicq;
97 
98 	/* command request */
99 	int		f_command;
100 	int		f_datalen;
101 	const void	*f_dataaddr;
102 	enum maple_command_stat {
103 		MAPLE_CMDSTAT_NONE,		/* not in queue */
104 		MAPLE_CMDSTAT_ASYNC,		/* process immediately */
105 		MAPLE_CMDSTAT_PERIODIC_DEFERED,	/* periodic but process imdtly*/
106 		MAPLE_CMDSTAT_ASYNC_PERIODICQ,	/* async but on periodic queue*/
107 		MAPLE_CMDSTAT_PERIODIC		/* process on periodic timing */
108 	} f_cmdstat;
109 	TAILQ_ENTRY(maple_func)	f_cmdq;
110 };
111 
112 /* work-around problem with 3rd party memory cards */
113 #define MAPLE_MEMCARD_PING_HACK
114 
115 struct maple_unit {
116 	int		port, subunit;
117 	struct maple_func u_func[MAPLE_NFUNC];
118 	uint32_t	getcond_func_set;
119 	int		u_ping_func;	/* function used for ping */
120 	uint32_t	u_noping;	/* stop ping (bitmap of function) */
121 #ifdef MAPLE_MEMCARD_PING_HACK
122 	enum maple_ping_stat {
123 		MAPLE_PING_NORMAL,	/* ping with GETCOND */
124 		MAPLE_PING_MEMCARD,	/* memory card, possibly 3rd party */
125 		MAPLE_PING_MINFO	/* poorly implemented 3rd party card */
126 	} u_ping_stat;
127 #endif
128 	struct maple_devinfo devinfo;
129 
130 	/* DMA status / function */
131 	enum maple_dma_stat {
132 		MAPLE_DMA_IDLE,		/* not in queue */
133 		MAPLE_DMA_RETRY,	/* retrying last command (sc_retryq) */
134 		MAPLE_DMA_PERIODIC,	/* periodic GETCOND */
135 		MAPLE_DMA_ACMD,		/* asynchronous command */
136 		MAPLE_DMA_PCMD,		/* command on periodic timing */
137 		MAPLE_DMA_PROBE,	/* checking for insertion */
138 		MAPLE_DMA_PING		/* checking for removal */
139 	} u_dma_stat;
140 	int	u_dma_func;
141 
142 	SIMPLEQ_ENTRY(maple_unit)	u_dmaq;
143 
144 	/* start of each receive buffer */
145 	uint32_t	*u_rxbuf;
146   	uint32_t	u_rxbuf_phys;
147 
148 	/* for restarting command */
149 	int		u_command;
150 	int		u_datalen;
151 	const void	*u_dataaddr;
152 	enum maple_dma_stat u_saved_dma_stat;
153 	int		u_retrycnt;
154 #define MAPLE_RETRY_MAX	100	/* ~2s */
155 	/*
156 	 * The 2s retry is rather too long, but required to avoid
157 	 * unwanted detach/attach.
158 	 * If a Visual Memory (without cells) is inserted to a controller,
159 	 * the controller (including the base device and the other unit
160 	 * in the slot) stops responding for near 1 second.  If two VM are
161 	 * inserted in succession, the period becomes near 2s.
162 	 */
163 
164 	/* queue for probe/ping */
165 	enum maple_queue_stat {
166 		MAPLE_QUEUE_NONE,	/* not in queue */
167 		MAPLE_QUEUE_PROBE,	/* checking for insertion */
168 		MAPLE_QUEUE_PING	/* checking for removal */
169 	} u_queuestat;
170 	TAILQ_ENTRY(maple_unit)	u_q;
171 	int			u_proberetry;	/* retry count (subunit != 0) */
172 #define MAPLE_PROBERETRY_MAX	5
173 };
174 
175 struct maple_softc {
176 	struct device	sc_dev;
177 
178 	callout_t	maple_callout_ch;
179 	lwp_t		*event_thread;
180 
181 	int8_t		sc_port_unit_map[MAPLE_PORTS];
182 	int		sc_port_units[MAPLE_PORTS];
183 	int		sc_port_units_open[MAPLE_PORTS];
184 
185 	struct maple_unit sc_unit[MAPLE_PORTS][MAPLE_SUBUNITS];
186 
187 	uint32_t *sc_txbuf;	/* start of allocated transmit buffer */
188 	uint32_t *sc_txpos;	/* current write position in tx buffer */
189 	uint32_t *sc_txlink;	/* start of last written frame */
190 
191 	uint32_t sc_txbuf_phys;	/* 29-bit physical address */
192 
193 	void	*sc_intrhand;
194 	int	sc_dmadone;		/* wchan */
195 
196 	int	sc_event;		/* periodic event is active / wchan */
197 
198 	SIMPLEQ_HEAD(maple_dmaq_head, maple_unit) sc_dmaq, sc_retryq;
199 	TAILQ_HEAD(maple_unitq_head, maple_unit) sc_probeq, sc_pingq;
200 	TAILQ_HEAD(maple_fnq_head, maple_func) sc_periodicq, sc_periodicdeferq;
201 	TAILQ_HEAD(maple_cmdq_head, maple_func) sc_acmdq, sc_pcmdq;
202 };
203