xref: /netbsd-src/sys/arch/amiga/dev/afsc.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: afsc.c,v 1.42 2008/06/13 08:13:37 cegger Exp $ */
2 
3 /*
4  * Copyright (c) 1982, 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)dma.c
32  */
33 
34 /*
35  * Copyright (c) 1994 Michael L. Hitch
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  *
46  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56  *
57  *	@(#)dma.c
58  */
59 
60 #include <sys/cdefs.h>
61 __KERNEL_RCSID(0, "$NetBSD: afsc.c,v 1.42 2008/06/13 08:13:37 cegger Exp $");
62 
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
66 #include <sys/device.h>
67 
68 #include <uvm/uvm_extern.h>
69 
70 #include <dev/scsipi/scsi_all.h>
71 #include <dev/scsipi/scsipi_all.h>
72 #include <dev/scsipi/scsiconf.h>
73 #include <machine/cpu.h>
74 #include <amiga/amiga/custom.h>
75 #include <amiga/amiga/cc.h>
76 #include <amiga/amiga/device.h>
77 #include <amiga/amiga/isr.h>
78 #include <amiga/dev/siopreg.h>
79 #include <amiga/dev/siopvar.h>
80 #include <amiga/dev/zbusvar.h>
81 
82 #ifdef __powerpc__
83 #define badaddr(a)      badaddr_read(a, 2, NULL)
84 #endif
85 
86 void afscattach(struct device *, struct device *, void *);
87 int afscmatch(struct device *, struct cfdata *, void *);
88 int afsc_dmaintr(void *);
89 #ifdef DEBUG
90 void afsc_dump(void);
91 #endif
92 
93 
94 #ifdef DEBUG
95 #endif
96 
97 CFATTACH_DECL(afsc, sizeof(struct siop_softc),
98     afscmatch, afscattach, NULL, NULL);
99 
100 CFATTACH_DECL(aftsc, sizeof(struct siop_softc),
101     afscmatch, afscattach, NULL, NULL);
102 
103 /*
104  * if we are a Commodore Amiga A4091 or possibly an A4000T
105  */
106 int
107 afscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
108 {
109 	struct zbus_args *zap;
110 	siop_regmap_p rp;
111 	u_long temp, scratch;
112 
113 	zap = auxp;
114 	if (zap->manid == 514 && zap->prodid == 84)
115 		return(1);		/* It's an A4091 SCSI card */
116 	if (!is_a4000() || !matchname("afsc", auxp))
117 		return(0);		/* Not on an A4000 or not A4000T SCSI */
118 	rp = ztwomap(0xdd0040);
119 	if (badaddr((void *)__UNVOLATILE(&rp->siop_scratch)) ||
120 	    badaddr((void *)__UNVOLATILE(&rp->siop_temp))) {
121 		return(0);
122 	}
123 	scratch = rp->siop_scratch;
124 	temp = rp->siop_temp;
125 	rp->siop_scratch = 0xdeadbeef;
126 	rp->siop_temp = 0xaaaa5555;
127 	if (rp->siop_scratch != 0xdeadbeef || rp->siop_temp != 0xaaaa5555)
128 		return(0);
129 	rp->siop_scratch = scratch;
130 	rp->siop_temp = temp;
131 	if (rp->siop_scratch != scratch || rp->siop_temp != temp)
132 		return(0);
133 	return(1);
134 }
135 
136 void
137 afscattach(struct device *pdp, struct device *dp, void *auxp)
138 {
139 	struct siop_softc *sc = (struct siop_softc *)dp;
140 	struct zbus_args *zap;
141 	siop_regmap_p rp;
142 	struct scsipi_adapter *adapt = &sc->sc_adapter;
143 	struct scsipi_channel *chan = &sc->sc_channel;
144 
145 	printf("\n");
146 
147 	zap = auxp;
148 
149 	if (zap->manid == 514 && zap->prodid == 84)
150 		sc->sc_siopp = rp = (siop_regmap_p)((char *)zap->va +
151 						    0x00800000);
152 	else
153 		sc->sc_siopp = rp = ztwomap(0xdd0040);
154 
155 	/*
156 	 * CTEST7 = 80 [disable burst]
157 	 */
158 	sc->sc_clock_freq = 50;		/* Clock = 50 MHz */
159 	sc->sc_ctest7 = SIOP_CTEST7_CDIS;
160 	sc->sc_dcntl = SIOP_DCNTL_EA;
161 
162 	/*
163 	 * Fill in the scsipi_adapter.
164 	 */
165 	memset(adapt, 0, sizeof(*adapt));
166 	adapt->adapt_dev = &sc->sc_dev;
167 	adapt->adapt_nchannels = 1;
168 	adapt->adapt_openings = 7;
169 	adapt->adapt_max_periph = 1;
170 	adapt->adapt_request = siop_scsipi_request;
171 	adapt->adapt_minphys = siop_minphys;
172 
173 	/*
174 	 * Fill in the scsipi_channel.
175 	 */
176 	memset(chan, 0, sizeof(*chan));
177 	chan->chan_adapter = adapt;
178 	chan->chan_bustype = &scsi_bustype;
179 	chan->chan_channel = 0;
180 	chan->chan_ntargets = 8;
181 	chan->chan_nluns = 8;
182 	chan->chan_id = 7;
183 
184 	siopinitialize(sc);
185 
186 	sc->sc_isr.isr_intr = afsc_dmaintr;
187 	sc->sc_isr.isr_arg = sc;
188 	sc->sc_isr.isr_ipl = 2;
189 	add_isr (&sc->sc_isr);
190 
191 	/*
192 	 * attach all scsi units on us
193 	 */
194 	config_found(dp, chan, scsiprint);
195 }
196 
197 int
198 afsc_dmaintr(void *arg)
199 {
200 	struct siop_softc *sc = arg;
201 	siop_regmap_p rp;
202 	u_char istat;
203 
204 	if (sc->sc_flags & SIOP_INTSOFF)
205 		return (0);	/* interrupts are not active */
206 	rp = sc->sc_siopp;
207 	istat = rp->siop_istat;
208 	if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
209 		return(0);
210 	/*
211 	 * save interrupt status, DMA status, and SCSI status 0
212 	 * (may need to deal with stacked interrupts?)
213 	 */
214 	sc->sc_sstat0 = rp->siop_sstat0;
215 	sc->sc_istat = istat;
216 	sc->sc_dstat = rp->siop_dstat;
217 	siopintr(sc);
218 	return(1);
219 }
220 
221 #ifdef DEBUG
222 void
223 afsc_dump(void)
224 {
225 	extern struct cfdriver afsc_cd;
226 	struct siop_softc *sc;
227 	int i;
228 
229 	for (i = 0; i < afsc_cd.cd_ndevs; ++i) {
230 		sc = device_lookup_private(&afsc_cd, i);
231 		if (sc != NULL)
232 			siop_dump(sc);
233 	}
234 }
235 #endif
236