xref: /netbsd-src/sys/arch/amiga/dev/wesc.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1 /*	$NetBSD: wesc.c,v 1.42 2021/08/07 16:18:41 thorpej 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: wesc.c,v 1.42 2021/08/07 16:18:41 thorpej 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 wescattach(device_t, device_t, void *);
80 int wescmatch(device_t, cfdata_t, void *);
81 int wesc_dmaintr(void *);
82 #ifdef DEBUG
83 void wesc_dump(void);
84 #endif
85 
86 
87 #ifdef DEBUG
88 #endif
89 
90 CFATTACH_DECL_NEW(wesc, sizeof(struct siop_softc),
91     wescmatch, wescattach, NULL, NULL);
92 
93 /*
94  * if we are an MacroSystemsUS Warp Engine
95  */
96 int
wescmatch(device_t parent,cfdata_t cf,void * aux)97 wescmatch(device_t parent, cfdata_t cf, void *aux)
98 {
99 	struct zbus_args *zap;
100 
101 	zap = aux;
102 	if (zap->manid == 2203 && zap->prodid == 19)
103 		return(1);
104 	return(0);
105 }
106 
107 void
wescattach(device_t parent,device_t self,void * aux)108 wescattach(device_t parent, device_t self, void *aux)
109 {
110 	struct siop_softc *sc = device_private(self);
111 	struct zbus_args *zap;
112 	siop_regmap_p rp;
113 	struct scsipi_adapter *adapt = &sc->sc_adapter;
114 	struct scsipi_channel *chan = &sc->sc_channel;
115 
116 	sc->sc_dev = self;
117 
118 	printf("\n");
119 
120 	zap = aux;
121 
122 	sc->sc_siopp = rp = (siop_regmap_p)((char *)zap->va + 0x40000);
123 
124 	/*
125 	 * CTEST7 = SC0, TT1
126 	 */
127 	sc->sc_clock_freq = 50;		/* Clock = 50 MHz */
128 	sc->sc_ctest7 = SIOP_CTEST7_SC0 | SIOP_CTEST7_TT1;
129 	sc->sc_dcntl = 0x00;
130 
131 	/*
132 	 * Fill in the scsipi_adapter.
133 	 */
134 	memset(adapt, 0, sizeof(*adapt));
135 	adapt->adapt_dev = self;
136 	adapt->adapt_nchannels = 1;
137 	adapt->adapt_openings = 7;
138 	adapt->adapt_max_periph = 1;
139 	adapt->adapt_request = siop_scsipi_request;
140 	adapt->adapt_minphys = siop_minphys;
141 
142 	/*
143 	 * Fill in the scsipi_channel.
144 	 */
145 	memset(chan, 0, sizeof(*chan));
146 	chan->chan_adapter = adapt;
147 	chan->chan_bustype = &scsi_bustype;
148 	chan->chan_channel = 0;
149 	chan->chan_ntargets = 8;
150 	chan->chan_nluns = 8;
151 	chan->chan_id = 7;
152 
153 	siopinitialize(sc);
154 
155 	sc->sc_isr.isr_intr = wesc_dmaintr;
156 	sc->sc_isr.isr_arg = sc;
157 	sc->sc_isr.isr_ipl = 2;
158 	add_isr (&sc->sc_isr);
159 
160 	/*
161 	 * attach all scsi units on us
162 	 */
163 	config_found(self, chan, scsiprint, CFARGS_NONE);
164 }
165 
166 int
wesc_dmaintr(void * arg)167 wesc_dmaintr(void *arg)
168 {
169 	struct siop_softc *sc = arg;
170 	siop_regmap_p rp;
171 	u_char istat;
172 
173 	if (sc->sc_flags & SIOP_INTSOFF)
174 		return (0);	/* interrupts are not active */
175 	rp = sc->sc_siopp;
176 	istat = rp->siop_istat;
177 	if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
178 		return (0);
179 	/*
180 	 * save interrupt status, DMA status, and SCSI status 0
181 	 * (may need to deal with stacked interrupts?)
182 	 */
183 	sc->sc_sstat0 = rp->siop_sstat0;
184 	sc->sc_istat = istat;
185 	sc->sc_dstat = rp->siop_dstat;
186 	siopintr(sc);
187 	return(1);
188 }
189 
190 #ifdef DEBUG
191 void
wesc_dump(void)192 wesc_dump(void)
193 {
194 	extern struct cfdriver wesc_cd;
195 	struct siop_softc *sc;
196 	int i;
197 
198 	for (i = 0; i < wesc_cd.cd_ndevs; ++i) {
199 		sc = device_lookup_private(&wesc_cd, i);
200 		if (sc != NULL)
201 			siop_dump(sc);
202 	}
203 }
204 #endif
205