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