ivsc.c revision 1.5 1 /* $NetBSD: ivsc.c,v 1.5 1994/10/26 02:04:07 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1994 Michael L. Hitch
5 * Copyright (c) 1982, 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)ivsdma.c
37 */
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/device.h>
42 #include <vm/vm.h> /* XXXX Kludge for IVS Vector - mlh */
43 #include <scsi/scsi_all.h>
44 #include <scsi/scsiconf.h>
45 #include <amiga/amiga/custom.h>
46 #include <amiga/amiga/device.h>
47 #include <amiga/dev/scireg.h>
48 #include <amiga/dev/scivar.h>
49 #include <amiga/dev/ztwobusvar.h>
50
51 int ivscprint __P((void *auxp, char *));
52 void ivscattach __P((struct device *, struct device *, void *));
53 int ivscmatch __P((struct device *, struct cfdata *, void *));
54
55 int ivsc_intr __P((void));
56 #ifdef notyet
57 int ivsc_dma_xfer_in __P((struct sci_softc *dev, int len,
58 register u_char *buf, int phase));
59 int ivsc_dma_xfer_out __P((struct sci_softc *dev, int len,
60 register u_char *buf, int phase));
61 #endif
62
63 struct scsi_adapter ivsc_scsiswitch = {
64 sci_scsicmd,
65 sci_minphys,
66 0, /* no lun support */
67 0, /* no lun support */
68 sci_adinfo,
69 "ivsc",
70 };
71
72 struct scsi_device ivsc_scsidev = {
73 NULL, /* use default error handler */
74 NULL, /* do not have a start functio */
75 NULL, /* have no async handler */
76 NULL, /* Use default done routine */
77 "ivsc",
78 0,
79 };
80
81 #define QPRINTF
82
83 #ifdef DEBUG
84 extern int sci_debug;
85 #endif
86
87 extern int sci_data_wait;
88
89 struct cfdriver ivsccd = {
90 NULL, "ivsc", ivscmatch, ivscattach,
91 DV_DULL, sizeof(struct sci_softc), NULL, 0 };
92
93 /*
94 * if this is an IVS board
95 */
96 int
97 ivscmatch(pdp, cdp, auxp)
98 struct device *pdp;
99 struct cfdata *cdp;
100 void *auxp;
101 {
102 struct ztwobus_args *zap;
103
104 zap = auxp;
105
106 /*
107 * Check manufacturer and product id.
108 */
109 if (zap->manid != 2112 || /* If manufacturer is IVS */
110 (zap->prodid != 52 && /* product = Trumpcard */
111 zap->prodid != 243)) /* product = Vector SCSI */
112 return(0); /* didn't match */
113 if (zap->prodid == 243) {
114 /*
115 * XXXX Ouch! board addresss isn't Zorro II or Zorro III!
116 * XXXX Kludge it up until I can do it better (MLH).
117 *
118 * XXXX pa 0x00f00000 shouldn't be used for anything
119 */
120 if (pmap_extract(kernel_pmap, (vm_offset_t) ztwomap(0x00f00000))
121 == 0x00f00000) {
122 physaccess(ztwomap(0x00f00000),zap->pa,
123 NBPG, PG_W|PG_CI);
124 zap->va = (void *) ztwomap(0x00f00000) +
125 ((int)zap->pa & PGOFSET);
126 #ifdef DEBUG
127 printf("IVS Vector: mapped to %x kva %x\n",
128 ztwomap(0x00f00000), zap->va);
129 #endif
130 }
131 else {
132 printf("Unable to map IVS Vector SCSI\n");
133 return (0);
134 }
135 }
136 return(1);
137 }
138
139 void
140 ivscattach(pdp, dp, auxp)
141 struct device *pdp, *dp;
142 void *auxp;
143 {
144 volatile u_char *rp;
145 struct sci_softc *sc;
146 struct ztwobus_args *zap;
147
148 printf("\n");
149
150 zap = auxp;
151
152 sc = (struct sci_softc *)dp;
153 rp = zap->va + 0x40;
154 sc->sci_data = rp;
155 sc->sci_odata = rp;
156 sc->sci_icmd = rp + 2;
157 sc->sci_mode = rp + 4;
158 sc->sci_tcmd = rp + 6;
159 sc->sci_bus_csr = rp + 8;
160 sc->sci_sel_enb = rp + 8;
161 sc->sci_csr = rp + 10;
162 sc->sci_dma_send = rp + 10;
163 sc->sci_idata = rp + 12;
164 sc->sci_trecv = rp + 12;
165 sc->sci_iack = rp + 14;
166 sc->sci_irecv = rp + 14;
167
168 #ifdef notyet
169 sc->dma_xfer_in = ivsc_dma_xfer_in;
170 sc->dma_xfer_out = ivsc_dma_xfer_out;
171 #endif
172
173 scireset(sc);
174
175 sc->sc_link.adapter_softc = sc;
176 sc->sc_link.adapter_targ = 7;
177 sc->sc_link.adapter = &ivsc_scsiswitch;
178 sc->sc_link.device = &ivsc_scsidev;
179 TAILQ_INIT(&sc->sc_xslist);
180
181 custom.intreq = INTF_PORTS;
182 custom.intena = INTF_SETCLR | INTF_PORTS;
183
184 /*
185 * attach all scsi units on us
186 */
187 config_found(dp, &sc->sc_link, ivscprint);
188 }
189
190 /*
191 * print diag if pnp is NULL else just extra
192 */
193 int
194 ivscprint(auxp, pnp)
195 void *auxp;
196 char *pnp;
197 {
198 if (pnp == NULL)
199 return(UNCONF);
200 return(QUIET);
201 }
202
203 #ifdef notyet
204 int
205 ivsc_dma_xfer_in (dev, len, buf, phase)
206 struct sci_softc *dev;
207 int len;
208 register u_char *buf;
209 int phase;
210 {
211 }
212
213 int
214 ivsc_dma_xfer_out (dev, len, buf, phase)
215 struct sci_softc *dev;
216 int len;
217 register u_char *buf;
218 int phase;
219 {
220 }
221 #endif
222
223 int
224 ivsc_intr()
225 {
226 struct sci_softc *dev;
227 int i, found;
228 u_char stat;
229
230 found = 0;
231 for (i = 0; i < ivsccd.cd_ndevs; i++) {
232 dev = ivsccd.cd_devs[i];
233 if (dev == NULL)
234 continue;
235 if ((*dev->sci_csr & SCI_CSR_INT) == 0)
236 continue;
237 ++found;
238 stat = *dev->sci_iack;
239 }
240 return (found);
241 }
242