mgnsc.c revision 1.37 1 /* $NetBSD: mgnsc.c,v 1.37 2003/08/07 16:26:42 agc 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 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * @(#)dma.c
66 */
67
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: mgnsc.c,v 1.37 2003/08/07 16:26:42 agc Exp $");
70
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/kernel.h>
74 #include <sys/device.h>
75
76 #include <uvm/uvm_extern.h>
77
78 #include <dev/scsipi/scsi_all.h>
79 #include <dev/scsipi/scsipi_all.h>
80 #include <dev/scsipi/scsiconf.h>
81 #include <amiga/amiga/custom.h>
82 #include <amiga/amiga/cc.h>
83 #include <amiga/amiga/device.h>
84 #include <amiga/amiga/isr.h>
85 #include <amiga/dev/siopreg.h>
86 #include <amiga/dev/siopvar.h>
87 #include <amiga/dev/zbusvar.h>
88
89 void mgnscattach(struct device *, struct device *, void *);
90 int mgnscmatch(struct device *, struct cfdata *, void *);
91 int mgnsc_dmaintr(void *);
92 #ifdef DEBUG
93 void mgnsc_dump(void);
94 #endif
95
96
97 #ifdef DEBUG
98 #endif
99
100 CFATTACH_DECL(mgnsc, sizeof(struct siop_softc),
101 mgnscmatch, mgnscattach, NULL, NULL);
102
103 /*
104 * if we are a CSA Magnum 40 SCSI
105 */
106 int
107 mgnscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
108 {
109 struct zbus_args *zap;
110
111 zap = auxp;
112 if (zap->manid == 1058 && zap->prodid == 17)
113 return(1);
114 return(0);
115 }
116
117 void
118 mgnscattach(struct device *pdp, struct device *dp, void *auxp)
119 {
120 struct siop_softc *sc = (struct siop_softc *)dp;
121 struct zbus_args *zap;
122 siop_regmap_p rp;
123 struct scsipi_adapter *adapt = &sc->sc_adapter;
124 struct scsipi_channel *chan = &sc->sc_channel;
125
126 printf("\n");
127 zap = auxp;
128
129 sc->sc_siopp = rp = (siop_regmap_p)((caddr_t)zap->va + 0x8000);
130
131 /*
132 * CTEST7 = TT1
133 */
134 sc->sc_clock_freq = 33; /* Clock = 33Mhz */
135 sc->sc_ctest7 = SIOP_CTEST7_TT1;
136 sc->sc_dcntl = 0x00;
137
138 alloc_sicallback();
139
140 /*
141 * Fill in the scsipi_adapter.
142 */
143 memset(adapt, 0, sizeof(*adapt));
144 adapt->adapt_dev = &sc->sc_dev;
145 adapt->adapt_nchannels = 1;
146 adapt->adapt_openings = 7;
147 adapt->adapt_max_periph = 1;
148 adapt->adapt_request = siop_scsipi_request;
149 adapt->adapt_minphys = siop_minphys;
150
151 /*
152 * Fill in the scsipi_channel.
153 */
154 memset(chan, 0, sizeof(*chan));
155 chan->chan_adapter = adapt;
156 chan->chan_bustype = &scsi_bustype;
157 chan->chan_channel = 0;
158 chan->chan_ntargets = 8;
159 chan->chan_nluns = 8;
160 chan->chan_id = 7;
161
162 siopinitialize(sc);
163
164 sc->sc_isr.isr_intr = mgnsc_dmaintr;
165 sc->sc_isr.isr_arg = sc;
166 sc->sc_isr.isr_ipl = 6;
167 add_isr (&sc->sc_isr);
168
169 /*
170 * attach all scsi units on us
171 */
172 config_found(dp, chan, scsiprint);
173 }
174
175 /*
176 * Level 6 interrupt processing for the Magnum/40 SCSI. Because the
177 * level 6 interrupt is above splbio, the interrupt status is saved
178 * and an sicallback to the level 2 interrupt handler scheduled.
179 * This way, the actual processing of the interrupt can be deferred
180 * until splbio is unblocked.
181 */
182
183 int
184 mgnsc_dmaintr(void *arg)
185 {
186 struct siop_softc *sc = arg;
187 siop_regmap_p rp;
188 u_char istat;
189
190 if (sc->sc_flags & SIOP_INTSOFF)
191 return (0); /* interrupts are not active */
192 rp = sc->sc_siopp;
193 istat = rp->siop_istat;
194 if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
195 return (0);
196 /*
197 * save interrupt status, DMA status, and SCSI status 0
198 * (may need to deal with stacked interrupts?)
199 */
200 sc->sc_sstat0 = rp->siop_sstat0;
201 sc->sc_istat = istat;
202 sc->sc_dstat = rp->siop_dstat;
203 /*
204 * disable interrupts until the callback can process this
205 * interrupt.
206 */
207 rp->siop_sien = 0;
208 rp->siop_dien = 0;
209 sc->sc_flags |= SIOP_INTDEFER | SIOP_INTSOFF;
210 add_sicallback((sifunc_t)siopintr, sc, NULL);
211 return (1);
212 }
213
214 #ifdef DEBUG
215 void
216 mgnsc_dump(void)
217 {
218 extern struct cfdriver mgnsc_cd;
219 int i;
220
221 for (i = 0; i < mgnsc_cd.cd_ndevs; ++i)
222 if (mgnsc_cd.cd_devs[i])
223 siop_dump(mgnsc_cd.cd_devs[i]);
224 }
225 #endif
226