sc_mbmem.c revision 1.1 1 /* $NetBSD: sc_mbmem.c,v 1.1 2001/04/18 03:38:39 fredette Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Glass, David Jones, Gordon W. Ross, and Matthew Fredette.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * This file contains only the machine-dependent parts of the
41 * Sun-2 SCSI driver. (Autoconfig stuff and DMA functions.)
42 * The machine-independent parts are in sunscpal.c
43 *
44 * Supported hardware includes:
45 * Sun SCSI-2 on Multibus (Sun2/120,Sun2/170)
46 * Sun SCSI-2 on VME (Sun2/50,Sun3/160,Sun3/260,others?)
47 *
48 * Credits, history:
49 *
50 * Matthew Fredette took revision 1.15 of si_vme.c, and then heavily
51 * modified it to support the Sun sc. The remaining credits
52 * are from si_vme.c:
53 *
54 * David Jones wrote the initial version of this module, which
55 * included support for the VME adapter only. (no reselection).
56 *
57 * Gordon Ross added support for the OBIO adapter, and re-worked
58 * both the VME and OBIO code to support disconnect/reselect.
59 * (Required figuring out the hardware "features" noted above.)
60 *
61 * The autoconfiguration boilerplate came from Adam Glass.
62 */
63
64 /*****************************************************************
65 * Multibus functions for sc
66 ****************************************************************/
67
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/errno.h>
71 #include <sys/kernel.h>
72 #include <sys/malloc.h>
73 #include <sys/device.h>
74 #include <sys/buf.h>
75 #include <sys/proc.h>
76 #include <sys/user.h>
77
78 #include <dev/scsipi/scsi_all.h>
79 #include <dev/scsipi/scsipi_all.h>
80 #include <dev/scsipi/scsipi_debug.h>
81 #include <dev/scsipi/scsiconf.h>
82
83 #include <machine/autoconf.h>
84 #include <machine/bus.h>
85
86 /* #define DEBUG XXX */
87
88 #include <dev/ic/sunscpalreg.h>
89 #include <dev/ic/sunscpalvar.h>
90
91 #include "screg.h"
92
93 /*
94 * Transfers smaller than this are done using PIO
95 * (on assumption they're not worth DMA overhead)
96 */
97 #define MIN_DMA_LEN 128
98
99 /*
100 * New-style autoconfig attachment
101 */
102
103 static int sunsc_mbmem_match __P((struct device *, struct cfdata *, void *));
104 static void sunsc_mbmem_attach __P((struct device *, struct device *, void *));
105 static int sunsc_mbmem_intr __P((void *));
106
107 struct cfattach sc_mbmem_ca = {
108 sizeof(struct sunscpal_softc), sunsc_mbmem_match, sunsc_mbmem_attach
109 };
110
111 /*
112 * Options for parity, DMA, and interrupts.
113 */
114 int sunsc_mbmem_options = 0x00;
115
116 static int
117 sunsc_mbmem_match(parent, cf, aux)
118 struct device *parent;
119 struct cfdata *cf;
120 void *aux;
121 {
122 struct confargs *ca = aux;
123
124 /* No default Multibus address. */
125 if (ca->ca_paddr == -1)
126 return (0);
127
128 /* Make sure something is there... */
129 if (!bus_space_probe(ca->ca_bustag, 0, ca->ca_paddr,
130 1, /* probe size */
131 1, /* offset */
132 0, /* flags */
133 NULL, NULL))
134 return (0);
135
136 /* Default interrupt priority. */
137 if (ca->ca_intpri == -1)
138 ca->ca_intpri = 2;
139
140 return (1);
141 }
142
143 static void
144 sunsc_mbmem_attach(parent, self, args)
145 struct device *parent, *self;
146 void *args;
147 {
148 struct sunscpal_softc *sc = (void *) self;
149 struct cfdata *cf = self->dv_cfdata;
150 struct confargs *ca = args;
151
152 /* Map in the device. */
153 sc->sunscpal_regt = ca->ca_bustag;
154 sc->sunscpal_dmat = ca->ca_dmatag;
155 if (bus_space_map(ca->ca_bustag, ca->ca_paddr, sizeof(struct sunsc_regs),
156 0, &sc->sunscpal_regh))
157 panic("sunsc_mbmem_attach: can't map");
158
159 /* Device register offsets. */
160 sc->sunscpal_data = offsetof(struct sunsc_regs, sunsc_data);
161 sc->sunscpal_cmd_stat = offsetof(struct sunsc_regs, sunsc_cmd_stat);
162 sc->sunscpal_icr = offsetof(struct sunsc_regs, sunsc_icr);
163 sc->sunscpal_dma_addr_h = offsetof(struct sunsc_regs, sunsc_dma_addr_h);
164 sc->sunscpal_dma_addr_l = offsetof(struct sunsc_regs, sunsc_dma_addr_l);
165 sc->sunscpal_dma_count = offsetof(struct sunsc_regs, sunsc_dma_count);
166 sc->sunscpal_intvec = offsetof(struct sunsc_regs, sunsc_intvec);
167
168 /* Miscellaneous. */
169 sc->sc_min_dma_len = MIN_DMA_LEN;
170 sc->sc_rev = SUNSCPAL_VARIANT_501_1006;
171
172 /* Attach interrupt handler. */
173 bus_intr_establish(ca->ca_bustag, ca->ca_intpri, IPL_BIO, 0,
174 sunsc_mbmem_intr, sc);
175
176 /* Do the common attach stuff. */
177 sunscpal_attach(sc, (cf->cf_flags ? cf->cf_flags : sunsc_mbmem_options));
178 }
179
180 static int
181 sunsc_mbmem_intr(void *arg)
182 {
183 struct sunscpal_softc *sc = arg;
184 int claimed;
185
186 claimed = sunscpal_intr(sc);
187 #ifdef DEBUG
188 if (!claimed) {
189 printf("sunsc_intr: spurious from SBC\n");
190 }
191 #endif
192 /* Yes, we DID cause this interrupt. */
193 claimed = 1;
194
195 return (claimed);
196 }
197