xref: /netbsd/sys/arch/amiga/dev/zssc.c (revision 6550d01e)
1 /*	$NetBSD: zssc.c,v 1.44 2010/12/20 00:25:26 matt 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: zssc.c,v 1.44 2010/12/20 00:25:26 matt 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 <dev/scsipi/scsi_all.h>
69 #include <dev/scsipi/scsipi_all.h>
70 #include <dev/scsipi/scsiconf.h>
71 #include <amiga/amiga/custom.h>
72 #include <amiga/amiga/cc.h>
73 #include <amiga/amiga/device.h>
74 #include <amiga/amiga/isr.h>
75 #include <amiga/dev/siopreg.h>
76 #include <amiga/dev/siopvar.h>
77 #include <amiga/dev/zbusvar.h>
78 
79 void zsscattach(struct device *, struct device *, void *);
80 int  zsscmatch(struct device *, struct cfdata *, void *);
81 int  zssc_dmaintr(void *);
82 #ifdef DEBUG
83 void zssc_dump(void);
84 #endif
85 
86 CFATTACH_DECL(zssc, sizeof(struct siop_softc),
87     zsscmatch, zsscattach, NULL, NULL);
88 
89 /*
90  * if we are an PPI Zeus
91  */
92 int
93 zsscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
94 {
95 	struct zbus_args *zap;
96 
97 	zap = auxp;
98 	if (zap->manid == 2026 && zap->prodid == 150)
99 		return(1);
100 	return(0);
101 }
102 
103 void
104 zsscattach(struct device *pdp, struct device *dp, void *auxp)
105 {
106 	struct siop_softc *sc;
107 	struct zbus_args *zap;
108 	siop_regmap_p rp;
109 
110 	printf("\n");
111 
112 	zap = auxp;
113 
114 	sc = (struct siop_softc *)dp;
115 	sc->sc_siopp = rp = (siop_regmap_p)((char *)zap->va + 0x4000);
116 
117 	/*
118 	 * CTEST7 = 00
119 	 */
120 	sc->sc_clock_freq = 66;		/* Clock = 66 MHz */
121 	sc->sc_ctest7 = 0x00;
122 	sc->sc_dcntl = 0x00;
123 
124 	sc->sc_siop_si = softint_establish(SOFTINT_BIO,
125 	    (void (*)(void *))siopintr, sc);
126 
127 	sc->sc_adapter.adapt_dev = &sc->sc_dev;
128 	sc->sc_adapter.adapt_nchannels = 1;
129 	sc->sc_adapter.adapt_openings = 7;
130 	sc->sc_adapter.adapt_max_periph = 1;
131 	sc->sc_adapter.adapt_ioctl = NULL;
132 	sc->sc_adapter.adapt_minphys = siop_minphys;
133 	sc->sc_adapter.adapt_request = siop_scsipi_request;
134 
135 	sc->sc_channel.chan_adapter = &sc->sc_adapter;
136 	sc->sc_channel.chan_bustype = &scsi_bustype;
137 	sc->sc_channel.chan_channel = 0;
138 	sc->sc_channel.chan_ntargets = 8;
139 	sc->sc_channel.chan_nluns = 8;
140 	sc->sc_channel.chan_id = 7;
141 
142 	siopinitialize(sc);
143 
144 	sc->sc_isr.isr_intr = zssc_dmaintr;
145 	sc->sc_isr.isr_arg = sc;
146 	sc->sc_isr.isr_ipl = 6;
147 	add_isr(&sc->sc_isr);
148 
149 	/*
150 	 * attach all scsi units on us
151 	 */
152 	config_found(dp, &sc->sc_channel, scsiprint);
153 }
154 
155 /*
156  * Level 6 interrupt processing for the Progressive Peripherals Inc
157  * Zeus SCSI.  Because the level 6 interrupt is above splbio, the
158  * interrupt status is saved and a softint scheduled.  This way,
159  * the actual processing of the interrupt can be deferred until
160  * splbio is unblocked.
161  */
162 
163 int
164 zssc_dmaintr(void *arg)
165 {
166 	struct siop_softc *sc = arg;
167 	siop_regmap_p rp;
168 	int istat;
169 
170 	if (sc->sc_flags & SIOP_INTSOFF)
171 		return (0);	/* interrupts are not active */
172 	rp = sc->sc_siopp;
173 	istat = rp->siop_istat;
174 	if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
175 		return(0);
176 	/*
177 	 * save interrupt status, DMA status, and SCSI status 0
178 	 * (may need to deal with stacked interrupts?)
179 	 */
180 	sc->sc_sstat0 = rp->siop_sstat0;
181 	sc->sc_istat = istat;
182 	sc->sc_dstat = rp->siop_dstat;
183 	/*
184 	 * disable interrupts until the callback can process this
185 	 * interrupt.
186 	 */
187 	rp->siop_sien = 0;
188 	rp->siop_dien = 0;
189 	sc->sc_flags |= SIOP_INTDEFER | SIOP_INTSOFF;
190 	softint_schedule(sc->sc_siop_si);
191 	return(1);
192 }
193 
194 #ifdef DEBUG
195 void
196 zssc_dump(void)
197 {
198 	extern struct cfdriver zssc_cd;
199 	struct siop_softc *sc;
200 	int i;
201 
202 	for (i = 0; i < zssc_cd.cd_ndevs; ++i) {
203 		sc = device_lookup_private(&zssc_cd, i);
204 		if (sc != NULL)
205 			siop_dump(sc);
206 	}
207 }
208 #endif
209