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