1 /* $NetBSD: ahsc.c,v 1.35 2005/12/11 12:16:28 christos Exp $ */
4 * Copyright (c) 1982, 1990 The Regents of the University of California.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
35 * Copyright (c) 1994 Christian E. Hopps
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
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.
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
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: ahsc.c,v 1.35 2005/12/11 12:16:28 christos Exp $");
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/kernel.h>
74 #include <sys/device.h>
75 #include <dev/scsipi/scsi_all.h>
76 #include <dev/scsipi/scsipi_all.h>
77 #include <dev/scsipi/scsiconf.h>
78 #include <amiga/amiga/custom.h>
79 #include <amiga/amiga/cc.h>
80 #include <amiga/amiga/cfdev.h>
81 #include <amiga/amiga/device.h>
82 #include <amiga/amiga/isr.h>
83 #include <amiga/dev/dmavar.h>
84 #include <amiga/dev/sbicreg.h>
85 #include <amiga/dev/sbicvar.h>
86 #include <amiga/dev/ahscreg.h>
87 #include <amiga/dev/zbusvar.h>
89 #include <machine/cpu.h>
91 void ahscattach(struct device
*, struct device
*, void *);
92 int ahscmatch(struct device
*, struct cfdata
*, void *);
94 void ahsc_enintr(struct sbic_softc
*);
95 void ahsc_dmastop(struct sbic_softc
*);
96 int ahsc_dmanext(struct sbic_softc
*);
97 int ahsc_dmaintr(void *);
98 int ahsc_dmago(struct sbic_softc
*, char *, int, int);
101 void ahsc_dump(void);
105 int ahsc_dmadebug
= 0;
108 CFATTACH_DECL(ahsc
, sizeof(struct sbic_softc
),
109 ahscmatch
, ahscattach
, NULL
, NULL
);
112 * if we are an A3000 we are here.
115 ahscmatch(struct device
*pdp
, struct cfdata
*cfp
, void *auxp
)
120 if (is_a3000() && matchname(auxp
, "ahsc"))
126 ahscattach(struct device
*pdp
, struct device
*dp
, void *auxp
)
128 volatile struct sdmac
*rp
;
129 struct sbic_softc
*sc
= (struct sbic_softc
*)dp
;
130 struct cfdev
*cdp
, *ecdp
;
131 struct scsipi_adapter
*adapt
= &sc
->sc_adapter
;
132 struct scsipi_channel
*chan
= &sc
->sc_channel
;
134 ecdp
= &cfdev
[ncfdev
];
136 for (cdp
= cfdev
; cdp
< ecdp
; cdp
++) {
137 if (cdp
->rom
.manid
== 8738 &&
138 cdp
->rom
.prodid
== 35)
142 sc
->sc_cregs
= rp
= ztwomap(0xdd0000);
144 * disable ints and reset bank register
146 rp
->CNTR
= CNTR_PDMD
;
147 rp
->DAWR
= DAWR_AHSC
;
148 sc
->sc_enintr
= ahsc_enintr
;
149 sc
->sc_dmago
= ahsc_dmago
;
150 sc
->sc_dmanext
= ahsc_dmanext
;
151 sc
->sc_dmastop
= ahsc_dmastop
;
155 * everything is a valid DMA address
160 sc
->sc_sbic
.sbic_asr_p
= ((vu_char
*)rp
+ 0x43);
161 sc
->sc_sbic
.sbic_value_p
= ((vu_char
*)rp
+ 0x47);
162 printf(": modified for Apollo CPU board\n");
164 sc
->sc_sbic
.sbic_asr_p
= ((vu_char
*)rp
+ 0x41);
165 sc
->sc_sbic
.sbic_value_p
= ((vu_char
*)rp
+ 0x43);
169 sc
->sc_clkfreq
= sbic_clock_override
? sbic_clock_override
: 143;
172 * Fill in the scsipi_adapter.
174 memset(adapt
, 0, sizeof(*adapt
));
175 adapt
->adapt_dev
= &sc
->sc_dev
;
176 adapt
->adapt_nchannels
= 1;
177 adapt
->adapt_openings
= 7;
178 adapt
->adapt_max_periph
= 1;
179 adapt
->adapt_request
= sbic_scsipi_request
;
180 adapt
->adapt_minphys
= sbic_minphys
;
183 * Fill in the scsipi_channel.
185 memset(chan
, 0, sizeof(*chan
));
186 chan
->chan_adapter
= adapt
;
187 chan
->chan_bustype
= &scsi_bustype
;
188 chan
->chan_channel
= 0;
189 chan
->chan_ntargets
= 8;
190 chan
->chan_nluns
= 8;
195 sc
->sc_isr
.isr_intr
= ahsc_dmaintr
;
196 sc
->sc_isr
.isr_arg
= sc
;
197 sc
->sc_isr
.isr_ipl
= 2;
198 add_isr (&sc
->sc_isr
);
201 * attach all scsi units on us
203 config_found(dp
, chan
, scsiprint
);
207 ahsc_enintr(struct sbic_softc
*dev
)
209 volatile struct sdmac
*sdp
;
213 dev
->sc_flags
|= SBICF_INTR
;
214 sdp
->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
218 ahsc_dmago(struct sbic_softc
*dev
, char *addr
, int count
, int flags
)
220 volatile struct sdmac
*sdp
;
224 * Set up the command word based on flags
226 dev
->sc_dmacmd
= CNTR_PDMD
| CNTR_INTEN
;
227 if ((flags
& DMAGO_READ
) == 0)
228 dev
->sc_dmacmd
|= CNTR_DDIR
;
230 if (ahsc_dmadebug
& DDB_IO
)
231 printf("ahsc_dmago: cmd %x\n", dev
->sc_dmacmd
);
234 dev
->sc_flags
|= SBICF_INTR
;
235 sdp
->CNTR
= dev
->sc_dmacmd
;
236 sdp
->ACR
= (u_int
) dev
->sc_cur
->dc_addr
;
239 return(dev
->sc_tcnt
);
243 ahsc_dmastop(struct sbic_softc
*dev
)
245 volatile struct sdmac
*sdp
;
251 if (ahsc_dmadebug
& DDB_FOLLOW
)
252 printf("ahsc_dmastop()\n");
254 if (dev
->sc_dmacmd
) {
256 if ((dev
->sc_dmacmd
& (CNTR_TCEN
| CNTR_DDIR
)) == 0) {
258 * only FLUSH if terminal count not enabled,
259 * and reading from peripheral
262 while ((sdp
->ISTR
& ISTR_FE_FLG
) == 0)
266 * clear possible interrupt and stop DMA
276 ahsc_dmaintr(void *arg
)
278 struct sbic_softc
*dev
= arg
;
279 volatile struct sdmac
*sdp
;
285 if ((stat
& (ISTR_INT_F
|ISTR_INT_P
)) == 0)
289 if (ahsc_dmadebug
& DDB_FOLLOW
)
290 printf("%s: dmaintr 0x%x\n", dev
->sc_dev
.dv_xname
, stat
);
294 * both, SCSI and DMA interrupts arrive here. I chose
295 * arbitrarily that DMA interrupts should have higher
296 * precedence than SCSI interrupts.
299 if (stat
& ISTR_E_INT
) {
302 sdp
->CINT
= 1; /* clear possible interrupt */
305 * check for SCSI ints in the same go and
306 * eventually save an interrupt
310 if (dev
->sc_flags
& SBICF_INTR
&& stat
& ISTR_INTS
)
311 found
+= sbicintr(dev
);
317 ahsc_dmanext(struct sbic_softc
*dev
)
319 volatile struct sdmac
*sdp
;
323 if (dev
->sc_cur
> dev
->sc_last
) {
324 /* shouldn't happen !! */
325 printf("ahsc_dmanext at end !!!\n");
329 if ((dev
->sc_dmacmd
& (CNTR_TCEN
| CNTR_DDIR
)) == 0) {
331 * only FLUSH if terminal count not enabled,
332 * and reading from peripheral
335 while ((sdp
->ISTR
& ISTR_FE_FLG
) == 0)
339 * clear possible interrupt and stop DMA
341 sdp
->CINT
= 1; /* clear possible interrupt */
342 sdp
->SP_DMA
= 1; /* stop DMA */
343 sdp
->CNTR
= dev
->sc_dmacmd
;
344 sdp
->ACR
= (u_int
)dev
->sc_cur
->dc_addr
;
347 dev
->sc_tcnt
= dev
->sc_cur
->dc_count
<< 1;
348 return(dev
->sc_tcnt
);
355 extern struct cfdriver ahsc_cd
;
356 struct sbic_softc
*sc
;
359 for (i
= 0; i
< ahsc_cd
.cd_ndevs
; ++i
) {
360 sc
= device_lookup_private(&ahsc_cd
, i
);