xref: /netbsd-src/sys/arch/amiga/dev/drsc.c (revision d48f14661dda8638fee055ba15d35bdfb29b9fa8)
1 /*	$NetBSD: drsc.c,v 1.28 2005/12/11 12:16:28 christos Exp $ */
2 
3 /*
4  * Copyright (c) 1996 Ignatios Souvatzis
5  * Copyright (c) 1982, 1990 The Regents of the University of California.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)dma.c
33  */
34 
35 /*
36  * Copyright (c) 1994 Michael L. Hitch
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  *
47  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57  *
58  *	@(#)dma.c
59  */
60 
61 #include <sys/cdefs.h>
62 __KERNEL_RCSID(0, "$NetBSD: drsc.c,v 1.28 2005/12/11 12:16:28 christos Exp $");
63 
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/kernel.h>
67 #include <sys/device.h>
68 
69 #include <uvm/uvm_extern.h>
70 
71 #include <dev/scsipi/scsi_all.h>
72 #include <dev/scsipi/scsipi_all.h>
73 #include <dev/scsipi/scsiconf.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/amiga/drcustom.h>
81 
82 #include <machine/cpu.h>	/* is_xxx(), */
83 
84 void drscattach(struct device *, struct device *, void *);
85 int drscmatch(struct device *, struct cfdata *, void *);
86 int drsc_dmaintr(struct siop_softc *);
87 #ifdef DEBUG
88 void drsc_dump(void);
89 #endif
90 
91 #ifdef DEBUG
92 #endif
93 
94 CFATTACH_DECL(drsc, sizeof(struct siop_softc),
95     drscmatch, drscattach, NULL, NULL);
96 
97 static struct siop_softc *drsc_softc;
98 
99 /*
100  * One of us is on every DraCo motherboard,
101  */
102 int
103 drscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
104 {
105 	static int drsc_matched = 0;
106 
107 	/* Allow only one instance. */
108 	if (!is_draco() || !matchname(auxp, "drsc") || drsc_matched)
109 		return (0);
110 
111 	drsc_matched = 1;
112 	return(1);
113 }
114 
115 void
116 drscattach(struct device *pdp, struct device *dp, void *auxp)
117 {
118 	struct siop_softc *sc = (struct siop_softc *)dp;
119 	struct zbus_args *zap;
120 	siop_regmap_p rp;
121 	struct scsipi_adapter *adapt = &sc->sc_adapter;
122 	struct scsipi_channel *chan = &sc->sc_channel;
123 
124 	printf("\n");
125 
126 	zap = auxp;
127 
128 	sc->sc_siopp = rp = (siop_regmap_p)(DRCCADDR+PAGE_SIZE*DRSCSIPG);
129 
130 	/*
131 	 * CTEST7 = TT1
132 	 */
133 	sc->sc_clock_freq = 50;		/* Clock = 50MHz */
134 	sc->sc_ctest7 = 0x02;
135 
136 	alloc_sicallback();
137 
138 	/*
139 	 * Fill in the scsipi_adapter.
140 	 */
141 	memset(adapt, 0, sizeof(*adapt));
142 	adapt->adapt_dev = &sc->sc_dev;
143 	adapt->adapt_nchannels = 1;
144 	adapt->adapt_openings = 7;
145 	adapt->adapt_max_periph = 1;
146 	adapt->adapt_request = siop_scsipi_request;
147 	adapt->adapt_minphys = siop_minphys;
148 
149 	/*
150 	 * Fill in the scsipi_channel.
151 	 */
152 	memset(chan, 0, sizeof(*chan));
153 	chan->chan_adapter = adapt;
154 	chan->chan_bustype = &scsi_bustype;
155 	chan->chan_channel = 0;
156 	chan->chan_ntargets = 8;
157 	chan->chan_nluns = 8;
158 	chan->chan_id = 7;
159 
160 	siopinitialize(sc);
161 
162 #if 0
163 	sc->sc_isr.isr_intr = drsc_dmaintr;
164 	sc->sc_isr.isr_arg = sc;
165 	sc->sc_isr.isr_ipl = 4;
166 	add_isr(&sc->sc_isr);
167 #else
168 	drsc_softc = sc;
169 	single_inst_bclr_b(*draco_intpen, DRIRQ_SCSI);
170 	single_inst_bset_b(*draco_intena, DRIRQ_SCSI);
171 #endif
172 	/*
173 	 * attach all scsi units on us
174 	 */
175 	config_found(dp, chan, scsiprint);
176 }
177 
178 /*
179  * Level 4 interrupt processing for the MacroSystem DraCo mainboard
180  * SCSI.  Because the level 4 interrupt is above splbio, the
181  * interrupt status is saved and an sicallback to the level 2 interrupt
182  * handler scheduled.  This way, the actual processing of the interrupt
183  * can be deferred until splbio is unblocked.
184  */
185 
186 void
187 drsc_handler(void)
188 {
189 	struct siop_softc *sc = drsc_softc;
190 
191 	siop_regmap_p rp;
192 	int istat;
193 
194 	if (sc->sc_flags & SIOP_INTSOFF)
195 		return;		/* interrupts are not active */
196 
197 	rp = sc->sc_siopp;
198 	istat = rp->siop_istat;
199 
200 	if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
201 		return;
202 
203 	/*
204 	 * save interrupt status, DMA status, and SCSI status 0
205 	 * (may need to deal with stacked interrupts?)
206 	 */
207 	sc->sc_sstat0 = rp->siop_sstat0;
208 	sc->sc_istat = istat;
209 	sc->sc_dstat = rp->siop_dstat;
210 	/*
211 	 * disable interrupts until the callback can process this
212 	 * interrupt.
213 	 */
214 #ifdef DRSC_NOCALLBACK
215 	(void)spl1();
216 	siopintr(sc);
217 #else
218 	rp->siop_sien = 0;
219 	rp->siop_dien = 0;
220 	sc->sc_flags |= SIOP_INTDEFER | SIOP_INTSOFF;
221 	single_inst_bclr_b(*draco_intpen, DRIRQ_SCSI);
222 #ifdef DEBUG
223 	if (*draco_intpen & DRIRQ_SCSI)
224 		printf("%s: intpen still 0x%x\n", sc->sc_dev.dv_xname,
225 		    *draco_intpen);
226 #endif
227 	add_sicallback((sifunc_t)siopintr, sc, NULL);
228 #endif
229 	return;
230 }
231 
232 #ifdef DEBUG
233 void
234 drsc_dump(void)
235 {
236 	extern struct cfdriver drsc_cd;
237 	int i;
238 
239 	for (i = 0; i < drsc_cd.cd_ndevs; ++i)
240 		if (drsc_cd.cd_devs[i])
241 			siop_dump(drsc_cd.cd_devs[i]);
242 }
243 #endif
244