Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / amiga / dev / mgnsc.c
blob1ace6538e495109056394e61c8f723c98f47934a
1 /* $NetBSD: mgnsc.c,v 1.43 2008/06/13 08:13:37 cegger Exp $ */
3 /*
4 * Copyright (c) 1982, 1990 The Regents of the University of California.
5 * All rights reserved.
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.
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.
31 * @(#)dma.c
35 * Copyright (c) 1994 Michael L. Hitch
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.
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.
57 * @(#)dma.c
60 #include <sys/cdefs.h>
61 __KERNEL_RCSID(0, "$NetBSD: mgnsc.c,v 1.43 2008/06/13 08:13:37 cegger Exp $");
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
66 #include <sys/device.h>
68 #include <uvm/uvm_extern.h>
70 #include <dev/scsipi/scsi_all.h>
71 #include <dev/scsipi/scsipi_all.h>
72 #include <dev/scsipi/scsiconf.h>
73 #include <amiga/amiga/custom.h>
74 #include <amiga/amiga/cc.h>
75 #include <amiga/amiga/device.h>
76 #include <amiga/amiga/isr.h>
77 #include <amiga/dev/siopreg.h>
78 #include <amiga/dev/siopvar.h>
79 #include <amiga/dev/zbusvar.h>
81 void mgnscattach(struct device *, struct device *, void *);
82 int mgnscmatch(struct device *, struct cfdata *, void *);
83 int mgnsc_dmaintr(void *);
84 #ifdef DEBUG
85 void mgnsc_dump(void);
86 #endif
89 #ifdef DEBUG
90 #endif
92 CFATTACH_DECL(mgnsc, sizeof(struct siop_softc),
93 mgnscmatch, mgnscattach, NULL, NULL);
96 * if we are a CSA Magnum 40 SCSI
98 int
99 mgnscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
101 struct zbus_args *zap;
103 zap = auxp;
104 if (zap->manid == 1058 && zap->prodid == 17)
105 return(1);
106 return(0);
109 void
110 mgnscattach(struct device *pdp, struct device *dp, void *auxp)
112 struct siop_softc *sc = (struct siop_softc *)dp;
113 struct zbus_args *zap;
114 siop_regmap_p rp;
115 struct scsipi_adapter *adapt = &sc->sc_adapter;
116 struct scsipi_channel *chan = &sc->sc_channel;
118 printf("\n");
119 zap = auxp;
121 sc->sc_siopp = rp = (siop_regmap_p)((char *)zap->va + 0x8000);
124 * CTEST7 = TT1
126 sc->sc_clock_freq = 33; /* Clock = 33 MHz */
127 sc->sc_ctest7 = SIOP_CTEST7_TT1;
128 sc->sc_dcntl = 0x00;
130 sc->sc_siop_si = softint_establish(SOFTINT_BIO,
131 (void (*)(void *))siopintr, sc);
134 * Fill in the scsipi_adapter.
136 memset(adapt, 0, sizeof(*adapt));
137 adapt->adapt_dev = &sc->sc_dev;
138 adapt->adapt_nchannels = 1;
139 adapt->adapt_openings = 7;
140 adapt->adapt_max_periph = 1;
141 adapt->adapt_request = siop_scsipi_request;
142 adapt->adapt_minphys = siop_minphys;
145 * Fill in the scsipi_channel.
147 memset(chan, 0, sizeof(*chan));
148 chan->chan_adapter = adapt;
149 chan->chan_bustype = &scsi_bustype;
150 chan->chan_channel = 0;
151 chan->chan_ntargets = 8;
152 chan->chan_nluns = 8;
153 chan->chan_id = 7;
155 siopinitialize(sc);
157 sc->sc_isr.isr_intr = mgnsc_dmaintr;
158 sc->sc_isr.isr_arg = sc;
159 sc->sc_isr.isr_ipl = 6;
160 add_isr (&sc->sc_isr);
163 * attach all scsi units on us
165 config_found(dp, chan, scsiprint);
169 * Level 6 interrupt processing for the Magnum/40 SCSI. Because the
170 * level 6 interrupt is above splbio, the interrupt status is saved
171 * and a softint scheduled. This way, the actual processing of the
172 * interrupt can be deferred until splbio is unblocked.
176 mgnsc_dmaintr(void *arg)
178 struct siop_softc *sc = arg;
179 siop_regmap_p rp;
180 u_char istat;
182 if (sc->sc_flags & SIOP_INTSOFF)
183 return (0); /* interrupts are not active */
184 rp = sc->sc_siopp;
185 istat = rp->siop_istat;
186 if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
187 return (0);
189 * save interrupt status, DMA status, and SCSI status 0
190 * (may need to deal with stacked interrupts?)
192 sc->sc_sstat0 = rp->siop_sstat0;
193 sc->sc_istat = istat;
194 sc->sc_dstat = rp->siop_dstat;
196 * disable interrupts until the callback can process this
197 * interrupt.
199 rp->siop_sien = 0;
200 rp->siop_dien = 0;
201 sc->sc_flags |= SIOP_INTDEFER | SIOP_INTSOFF;
202 softint_schedule(sc->sc_siop_si);
203 return (1);
206 #ifdef DEBUG
207 void
208 mgnsc_dump(void)
210 extern struct cfdriver mgnsc_cd;
211 struct siop_softc *sc;
212 int i;
214 for (i = 0; i < mgnsc_cd.cd_ndevs; ++i) {
215 sc = device_lookup_private(&mgnsc_cd, i);
216 if (sc != NULL)
217 siop_dump(sc);
220 #endif