1 /* 2 * Copyright (c) 1994 Christian E. Hopps 3 * Copyright (c) 1982, 1990 The Regents of the University of California. 4 * 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. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by the University of 17 * California, Berkeley and its contributors. 18 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)dma.c 35 * $Id: ahsc.c,v 1.3 1994/05/16 04:55:05 chopps Exp $ 36 */ 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/kernel.h> 40 #include <sys/device.h> 41 #include <scsi/scsi_all.h> 42 #include <scsi/scsiconf.h> 43 #include <amiga/amiga/custom.h> 44 #include <amiga/amiga/cc.h> 45 #include <amiga/amiga/device.h> 46 #include <amiga/dev/dmavar.h> 47 #include <amiga/dev/sbicreg.h> 48 #include <amiga/dev/sbicvar.h> 49 #include <amiga/dev/ahscreg.h> 50 #include <amiga/dev/ztwobusvar.h> 51 52 int ahscprint __P((void *auxp, char *)); 53 void ahscattach __P((struct device *, struct device *, void *)); 54 int ahscmatch __P((struct device *, struct cfdata *, void *)); 55 56 void ahsc_dmafree __P((struct sbic_softc *)); 57 void ahsc_dmastop __P((struct sbic_softc *)); 58 int ahsc_dmanext __P((struct sbic_softc *)); 59 int ahsc_dmaintr __P((void)); 60 int ahsc_dmago __P((struct sbic_softc *, char *, int, int)); 61 62 struct scsi_adapter ahsc_scsiswitch = { 63 sbic_scsicmd, 64 sbic_minphys, 65 0, /* no lun support */ 66 0, /* no lun support */ 67 sbic_adinfo, 68 "ahsc", 69 }; 70 71 struct scsi_device ahsc_scsidev = { 72 NULL, /* use default error handler */ 73 NULL, /* do not have a start functio */ 74 NULL, /* have no async handler */ 75 NULL, /* Use default done routine */ 76 "ahsc", 77 0, 78 }; 79 80 81 #ifdef DEBUG 82 void ahsc_dmatimeout __P((void *)); 83 int ahsc_dmadebug = 0; 84 #endif 85 86 struct cfdriver ahsccd = { 87 NULL, "ahsc", ahscmatch, ahscattach, 88 DV_DULL, sizeof(struct sbic_softc), NULL, 0 }; 89 90 /* 91 * if we are an A3000 we are here. 92 */ 93 int 94 ahscmatch(pdp, cdp, auxp) 95 struct device *pdp; 96 struct cfdata *cdp; 97 void *auxp; 98 { 99 char *mbusstr; 100 101 mbusstr = auxp; 102 if (is_a3000() && matchname(auxp, "ahsc")) 103 return(1); 104 return(0); 105 } 106 107 void 108 ahscattach(pdp, dp, auxp) 109 struct device *pdp, *dp; 110 void *auxp; 111 { 112 volatile struct sdmac *rp; 113 struct sbic_softc *sc; 114 115 printf("\n"); 116 117 sc = (struct sbic_softc *)dp; 118 sc->sc_cregs = rp = ztwomap(0xdd0000); 119 /* 120 * disable ints and reset bank register 121 */ 122 rp->CNTR = CNTR_PDMD; 123 rp->DAWR = DAWR_AHSC; 124 sc->sc_dmafree = ahsc_dmafree; 125 sc->sc_dmago = ahsc_dmago; 126 sc->sc_dmanext = ahsc_dmanext; 127 sc->sc_dmastop = ahsc_dmastop; 128 sc->sc_dmacmd = 0; 129 130 #ifdef DEBUG 131 /* make sure timeout is really not needed */ 132 timeout(ahsc_dmatimeout, 0, 30 * hz); 133 #endif 134 /* 135 * eveything is a valid dma address 136 */ 137 sc->sc_dmamask = 0; 138 sc->sc_sbicp = (sbic_regmap_p) ((int)rp + 0x41); 139 sc->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 143; 140 141 sbicreset(sc); 142 143 sc->sc_link.adapter_softc = sc; 144 sc->sc_link.adapter_targ = 7; 145 sc->sc_link.adapter = &ahsc_scsiswitch; 146 sc->sc_link.device = &ahsc_scsidev; 147 TAILQ_INIT(&sc->sc_xslist); 148 149 custom.intreq = INTF_PORTS; 150 custom.intena = INTF_SETCLR | INTF_PORTS; 151 152 /* 153 * attach all scsi units on us 154 */ 155 config_found(dp, &sc->sc_link, ahscprint); 156 } 157 158 /* 159 * print diag if pnp is NULL else just extra 160 */ 161 int 162 ahscprint(auxp, pnp) 163 void *auxp; 164 char *pnp; 165 { 166 if (pnp == NULL) 167 return(UNCONF); 168 return(QUIET); 169 } 170 171 172 void 173 ahsc_dmafree(dev) 174 struct sbic_softc *dev; 175 { 176 volatile struct sdmac *sdp; 177 int s; 178 179 sdp = dev->sc_cregs; 180 181 s = splbio(); 182 #ifdef DEBUG 183 dev->sc_dmatimo = 0; 184 #endif 185 if (dev->sc_dmacmd) { 186 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) { 187 /* 188 * only FLUSH if terminal count not enabled, 189 * and reading from peripheral 190 */ 191 sdp->FLUSH = 1; 192 while ((sdp->ISTR & ISTR_FE_FLG) == 0) 193 ; 194 } 195 /* 196 * clear possible interrupt and stop dma 197 */ 198 sdp->CINT = 1; 199 sdp->SP_DMA = 1; 200 dev->sc_dmacmd = 0; 201 } 202 /* 203 * disable interrupts 204 */ 205 sdp->CNTR = CNTR_PDMD; /* disable interrupts from dma/scsi */ 206 dev->sc_flags &= ~SBICF_INTR; 207 splx(s); 208 } 209 210 int 211 ahsc_dmago(dev, addr, count, flags) 212 struct sbic_softc *dev; 213 char *addr; 214 int count, flags; 215 { 216 volatile struct sdmac *sdp; 217 218 sdp = dev->sc_cregs; 219 /* 220 * Set up the command word based on flags 221 */ 222 dev->sc_dmacmd = CNTR_PDMD | CNTR_INTEN; 223 if ((flags & DMAGO_READ) == 0) 224 dev->sc_dmacmd |= CNTR_DDIR; 225 #ifdef DEBUG 226 if (ahsc_dmadebug & DDB_IO) 227 printf("ahsc_dmago: cmd %x\n", dev->sc_dmacmd); 228 dev->sc_dmatimo = 1; 229 #endif 230 231 dev->sc_flags |= SBICF_INTR; 232 sdp->CNTR = dev->sc_dmacmd; 233 sdp->ACR = (u_int) dev->sc_cur->dc_addr; 234 sdp->ST_DMA = 1; 235 236 return(dev->sc_tcnt); 237 } 238 239 void 240 ahsc_dmastop(dev) 241 struct sbic_softc *dev; 242 { 243 volatile struct sdmac *sdp; 244 int s; 245 246 sdp = dev->sc_cregs; 247 248 #ifdef DEBUG 249 if (ahsc_dmadebug & DDB_FOLLOW) 250 printf("ahsc_dmastop()\n"); 251 dev->sc_dmatimo = 0; 252 #endif 253 if (dev->sc_dmacmd) { 254 s = splbio(); 255 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) { 256 /* 257 * only FLUSH if terminal count not enabled, 258 * and reading from peripheral 259 */ 260 sdp->FLUSH = 1; 261 while ((sdp->ISTR & ISTR_FE_FLG) == 0) 262 ; 263 } 264 /* 265 * clear possible interrupt and stop dma 266 */ 267 sdp->CINT = 1; 268 sdp->SP_DMA = 1; 269 dev->sc_dmacmd = 0; 270 splx(s); 271 } 272 } 273 274 int 275 ahsc_dmaintr() 276 { 277 volatile struct sdmac *sdp; 278 struct sbic_softc *dev; 279 int i, stat, found; 280 281 found = 0; 282 for (i = 0; i < ahsccd.cd_ndevs; i++) { 283 dev = ahsccd.cd_devs[i]; 284 if (dev == NULL) 285 continue; 286 sdp = dev->sc_cregs; 287 stat = sdp->ISTR; 288 289 if ((stat & (ISTR_INT_F|ISTR_INT_P)) == 0) 290 continue; 291 292 #ifdef DEBUG 293 if (ahsc_dmadebug & DDB_FOLLOW) 294 printf("ahsc_dmaintr (%d, 0x%x)\n", i, stat); 295 #endif 296 297 /* 298 * both, SCSI and DMA interrupts arrive here. I chose 299 * arbitrarily that DMA interrupts should have higher 300 * precedence than SCSI interrupts. 301 */ 302 if (stat & ISTR_E_INT) { 303 found++; 304 305 sdp->CINT = 1; /* clear possible interrupt */ 306 307 /* 308 * check for SCSI ints in the same go and 309 * eventually save an interrupt 310 */ 311 } 312 313 if (dev->sc_flags & SBICF_INTR && stat & ISTR_INTS) 314 found += sbicintr(dev); 315 } 316 return(found); 317 } 318 319 320 int 321 ahsc_dmanext(dev) 322 struct sbic_softc *dev; 323 { 324 volatile struct sdmac *sdp; 325 int i, stat; 326 327 sdp = dev->sc_cregs; 328 329 if (dev->sc_cur > dev->sc_last) { 330 /* shouldn't happen !! */ 331 printf("ahsc_dmanext at end !!!\n"); 332 ahsc_dmastop(dev); 333 return(0); 334 } 335 #ifdef DEBUG 336 dev->sc_dmatimo = 1; 337 #endif 338 if ((dev->sc_dmacmd & (CNTR_TCEN | CNTR_DDIR)) == 0) { 339 /* 340 * only FLUSH if terminal count not enabled, 341 * and reading from peripheral 342 */ 343 sdp->FLUSH = 1; 344 while ((sdp->ISTR & ISTR_FE_FLG) == 0) 345 ; 346 } 347 /* 348 * clear possible interrupt and stop dma 349 */ 350 sdp->CINT = 1; /* clear possible interrupt */ 351 sdp->SP_DMA = 1; /* stop dma */ 352 sdp->CNTR = dev->sc_dmacmd; 353 sdp->ACR = (u_int)dev->sc_cur->dc_addr; 354 sdp->ST_DMA = 1; 355 356 dev->sc_tcnt = dev->sc_cur->dc_count << 1; 357 return(dev->sc_tcnt); 358 } 359 360 #ifdef DEBUG 361 /*ARGSUSED*/ 362 void 363 ahsc_dmatimeout(arg) 364 void *arg; 365 { 366 struct sbic_softc *dev; 367 int i, s; 368 369 for (i = 0; i < ahsccd.cd_ndevs; i++) { 370 dev = ahsccd.cd_devs[i]; 371 if (dev == NULL) 372 continue; 373 374 s = splbio(); 375 if (dev->sc_dmatimo) { 376 if (dev->sc_dmatimo > 1) 377 printf("ahsc_dma%d: timeout #%d\n", 378 dev->sc_dev.dv_unit, dev->sc_dmatimo - 1); 379 dev->sc_dmatimo++; 380 } 381 splx(s); 382 } 383 timeout(ahsc_dmatimeout, 0, 30 * hz); 384 } 385 #endif 386