sbc_obio.c revision 1.18 1 /* $NetBSD: sbc_obio.c,v 1.18 2005/01/15 16:01:00 chs Exp $ */
2
3 /*
4 * Copyright (C) 1996,1997 Scott Reynolds. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: sbc_obio.c,v 1.18 2005/01/15 16:01:00 chs Exp $");
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/errno.h>
37 #include <sys/device.h>
38 #include <sys/buf.h>
39 #include <sys/proc.h>
40 #include <sys/user.h>
41
42 #include <dev/scsipi/scsi_all.h>
43 #include <dev/scsipi/scsipi_all.h>
44 #include <dev/scsipi/scsipi_debug.h>
45 #include <dev/scsipi/scsiconf.h>
46
47 #include <dev/ic/ncr5380reg.h>
48 #include <dev/ic/ncr5380var.h>
49
50 #include <machine/cpu.h>
51 #include <machine/viareg.h>
52
53 #include <mac68k/dev/sbcreg.h>
54 #include <mac68k/dev/sbcvar.h>
55
56 /*
57 * From Guide to the Macintosh Family Hardware, pp. 137-143
58 * These are offsets from SCSIBase (see pmap_bootstrap.c)
59 */
60 #define SBC_REG_OFS 0x10000
61 #define SBC_DMA_OFS 0x12000
62 #define SBC_HSK_OFS 0x06000
63
64 #define SBC_DMA_OFS_PB500 0x06000
65
66 #define SBC_REG_OFS_IIFX 0x08000 /* Just guessing... */
67 #define SBC_DMA_OFS_IIFX 0x0c000
68 #define SBC_HSK_OFS_IIFX 0x0e000
69
70 #define SBC_REG_OFS_DUO2 0x00000
71 #define SBC_DMA_OFS_DUO2 0x02000
72 #define SBC_HSK_OFS_DUO2 0x04000
73
74 static int sbc_obio_match(struct device *, struct cfdata *, void *);
75 static void sbc_obio_attach(struct device *, struct device *, void *);
76
77 void sbc_intr_enable(struct ncr5380_softc *);
78 void sbc_intr_disable(struct ncr5380_softc *);
79 void sbc_obio_clrintr(struct ncr5380_softc *);
80
81 CFATTACH_DECL(sbc_obio, sizeof(struct sbc_softc),
82 sbc_obio_match, sbc_obio_attach, NULL, NULL);
83
84 static int
85 sbc_obio_match(struct device *parent, struct cfdata *cf, void *args)
86 {
87 switch (current_mac_model->machineid) {
88 case MACH_MACIIFX: /* Note: the IIfx isn't (yet) supported. */
89 /*
90 if (cf->cf_unit == 0)
91 return 1;
92 */
93 break;
94 case MACH_MACPB210:
95 case MACH_MACPB230:
96 case MACH_MACPB250:
97 case MACH_MACPB270:
98 case MACH_MACPB280:
99 case MACH_MACPB280C:
100 if (cf->cf_unit == 1)
101 return 1;
102 /*FALLTHROUGH*/
103 default:
104 if (cf->cf_unit == 0 && mac68k_machine.scsi80)
105 return 1;
106 }
107 return 0;
108 }
109
110 static void
111 sbc_obio_attach(struct device *parent, struct device *self, void *args)
112 {
113 struct sbc_softc *sc = (struct sbc_softc *) self;
114 struct ncr5380_softc *ncr_sc = (struct ncr5380_softc *) sc;
115 char bits[64];
116 extern vaddr_t SCSIBase;
117
118 /* Pull in the options flags. */
119 sc->sc_options = ((ncr_sc->sc_dev.dv_cfdata->cf_flags | sbc_options)
120 & SBC_OPTIONS_MASK);
121
122 /*
123 * Set up offsets to 5380 registers and GLUE I/O space, and turn
124 * off options we know we can't support on certain models.
125 */
126 switch (current_mac_model->machineid) {
127 case MACH_MACIIFX: /* Note: the IIfx isn't (yet) supported. */
128 sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS_IIFX);
129 sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS_IIFX);
130 sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS_IIFX);
131 sc->sc_options &= ~(SBC_INTR | SBC_RESELECT);
132 break;
133 case MACH_MACPB500:
134 sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS);
135 sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS); /*??*/
136 sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS_PB500);
137 sc->sc_options &= ~(SBC_INTR | SBC_RESELECT);
138 break;
139 case MACH_MACPB210:
140 case MACH_MACPB230:
141 case MACH_MACPB250:
142 case MACH_MACPB270:
143 case MACH_MACPB280:
144 case MACH_MACPB280C:
145 if (ncr_sc->sc_dev.dv_unit == 1) {
146 sc->sc_regs = (struct sbc_regs *)(0xfee00000 + SBC_REG_OFS_DUO2);
147 sc->sc_drq_addr = (vaddr_t)(0xfee00000 + SBC_HSK_OFS_DUO2);
148 sc->sc_nodrq_addr = (vaddr_t)(0xfee00000 + SBC_DMA_OFS_DUO2);
149 break;
150 }
151 /*FALLTHROUGH*/
152 default:
153 sc->sc_regs = (struct sbc_regs *)(SCSIBase + SBC_REG_OFS);
154 sc->sc_drq_addr = (vaddr_t)(SCSIBase + SBC_HSK_OFS);
155 sc->sc_nodrq_addr = (vaddr_t)(SCSIBase + SBC_DMA_OFS);
156 break;
157 }
158
159 /*
160 * Initialize fields used by the MI code
161 */
162 ncr_sc->sci_r0 = &sc->sc_regs->sci_pr0.sci_reg;
163 ncr_sc->sci_r1 = &sc->sc_regs->sci_pr1.sci_reg;
164 ncr_sc->sci_r2 = &sc->sc_regs->sci_pr2.sci_reg;
165 ncr_sc->sci_r3 = &sc->sc_regs->sci_pr3.sci_reg;
166 ncr_sc->sci_r4 = &sc->sc_regs->sci_pr4.sci_reg;
167 ncr_sc->sci_r5 = &sc->sc_regs->sci_pr5.sci_reg;
168 ncr_sc->sci_r6 = &sc->sc_regs->sci_pr6.sci_reg;
169 ncr_sc->sci_r7 = &sc->sc_regs->sci_pr7.sci_reg;
170
171 ncr_sc->sc_rev = NCR_VARIANT_NCR5380;
172
173 /*
174 * MD function pointers used by the MI code.
175 */
176 if (sc->sc_options & SBC_PDMA) {
177 ncr_sc->sc_pio_out = sbc_pdma_out;
178 ncr_sc->sc_pio_in = sbc_pdma_in;
179 } else {
180 ncr_sc->sc_pio_out = ncr5380_pio_out;
181 ncr_sc->sc_pio_in = ncr5380_pio_in;
182 }
183 ncr_sc->sc_dma_alloc = NULL;
184 ncr_sc->sc_dma_free = NULL;
185 ncr_sc->sc_dma_poll = NULL;
186 ncr_sc->sc_intr_on = NULL;
187 ncr_sc->sc_intr_off = NULL;
188 ncr_sc->sc_dma_setup = NULL;
189 ncr_sc->sc_dma_start = NULL;
190 ncr_sc->sc_dma_eop = NULL;
191 ncr_sc->sc_dma_stop = NULL;
192 ncr_sc->sc_flags = 0;
193 ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
194
195 if (sc->sc_options & SBC_INTR) {
196 ncr_sc->sc_dma_alloc = sbc_dma_alloc;
197 ncr_sc->sc_dma_free = sbc_dma_free;
198 ncr_sc->sc_dma_poll = sbc_dma_poll;
199 ncr_sc->sc_dma_setup = sbc_dma_setup;
200 ncr_sc->sc_dma_start = sbc_dma_start;
201 ncr_sc->sc_dma_eop = sbc_dma_eop;
202 ncr_sc->sc_dma_stop = sbc_dma_stop;
203 via2_register_irq(VIA2_SCSIDRQ, sbc_drq_intr, ncr_sc);
204 }
205
206 via2_register_irq(VIA2_SCSIIRQ, sbc_irq_intr, ncr_sc);
207 sc->sc_clrintr = sbc_obio_clrintr;
208
209 if ((sc->sc_options & SBC_RESELECT) == 0)
210 ncr_sc->sc_no_disconnect = 0xff;
211
212 if (sc->sc_options)
213 printf(": options=%s", bitmask_snprintf(sc->sc_options,
214 SBC_OPTIONS_BITS, bits, sizeof(bits)));
215 printf("\n");
216
217 if (sc->sc_options & (SBC_INTR|SBC_RESELECT)) {
218 /* Enable SCSI interrupts through VIA2 */
219 sbc_intr_enable(ncr_sc);
220 }
221
222 #ifdef SBC_DEBUG
223 if (sbc_debug)
224 printf("%s: softc=%p regs=%p\n", ncr_sc->sc_dev.dv_xname,
225 sc, sc->sc_regs);
226 #endif
227
228 ncr_sc->sc_channel.chan_id = 7;
229 ncr_sc->sc_adapter.adapt_minphys = minphys;
230
231 /*
232 * Initialize the SCSI controller itself.
233 */
234 ncr5380_attach(ncr_sc);
235 }
236
237 /*
238 * Interrupt support routines.
239 */
240 void
241 sbc_intr_enable(struct ncr5380_softc *ncr_sc)
242 {
243 struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
244 int s, flags;
245
246 flags = V2IF_SCSIIRQ;
247 if (sc->sc_options & SBC_INTR)
248 flags |= V2IF_SCSIDRQ;
249
250 s = splhigh();
251 if (VIA2 == VIA2OFF)
252 via2_reg(vIER) = 0x80 | flags;
253 else
254 via2_reg(rIER) = 0x80 | flags;
255 splx(s);
256 }
257
258 void
259 sbc_intr_disable(struct ncr5380_softc *ncr_sc)
260 {
261 struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
262 int s, flags;
263
264 flags = V2IF_SCSIIRQ;
265 if (sc->sc_options & SBC_INTR)
266 flags |= V2IF_SCSIDRQ;
267
268 s = splhigh();
269 if (VIA2 == VIA2OFF)
270 via2_reg(vIER) = flags;
271 else
272 via2_reg(rIER) = flags;
273 splx(s);
274 }
275
276 void
277 sbc_obio_clrintr(struct ncr5380_softc *ncr_sc)
278 {
279 struct sbc_softc *sc = (struct sbc_softc *)ncr_sc;
280 int flags;
281
282 flags = V2IF_SCSIIRQ;
283 if (sc->sc_options & SBC_INTR)
284 flags |= V2IF_SCSIDRQ;
285
286 if (VIA2 == VIA2OFF)
287 via2_reg(vIFR) = 0x80 | flags;
288 else
289 via2_reg(rIFR) = 0x80 | flags;
290 }
291