Home | History | Annotate | Line # | Download | only in tc
asc_tc.c revision 1.10.2.1
      1  1.10.2.1    bouyer /*	$NetBSD: asc_tc.c,v 1.10.2.1 2000/11/20 11:43:13 bouyer Exp $	*/
      2       1.1  jonathan 
      3       1.1  jonathan /*
      4       1.1  jonathan  * Copyright 1996 The Board of Trustees of The Leland Stanford
      5       1.1  jonathan  * Junior University. All Rights Reserved.
      6       1.1  jonathan  *
      7       1.1  jonathan  * Permission to use, copy, modify, and distribute this
      8       1.1  jonathan  * software and its documentation for any purpose and without
      9       1.1  jonathan  * fee is hereby granted, provided that the above copyright
     10       1.1  jonathan  * notice appear in all copies.  Stanford University
     11       1.1  jonathan  * makes no representations about the suitability of this
     12       1.1  jonathan  * software for any purpose.  It is provided "as is" without
     13       1.1  jonathan  * express or implied warranty.
     14       1.1  jonathan  *
     15       1.1  jonathan  */
     16       1.1  jonathan 
     17       1.1  jonathan #include <sys/param.h>
     18       1.1  jonathan #include <sys/systm.h>
     19       1.1  jonathan #include <sys/types.h>
     20       1.1  jonathan #include <sys/device.h>
     21      1.10       mrg 
     22       1.1  jonathan #include <dev/tc/tcvar.h>
     23       1.1  jonathan #include <dev/tc/ioasicvar.h>
     24       1.1  jonathan 
     25       1.1  jonathan #include <pmax/dev/device.h>	/* XXX */
     26       1.1  jonathan #include <pmax/dev/scsi.h>	/* XXX */
     27       1.1  jonathan 
     28       1.1  jonathan #include <pmax/dev/ascreg.h>	/* XXX */
     29       1.1  jonathan #include <dev/tc/ascvar.h>
     30       1.1  jonathan 
     31       1.1  jonathan /*XXX*/
     32       1.1  jonathan 
     33       1.1  jonathan 
     34       1.1  jonathan /*
     35       1.1  jonathan  * Autoconfiguration data for config.
     36       1.1  jonathan  */
     37       1.6  jonathan int asc_tc_match __P((struct device *, struct cfdata *, void *));
     38       1.1  jonathan void asc_tc_attach __P((struct device *, struct device *, void *));
     39       1.1  jonathan 
     40       1.1  jonathan struct cfattach asc_tc_ca = {
     41       1.1  jonathan 	sizeof(struct asc_softc), asc_tc_match, asc_tc_attach
     42       1.1  jonathan };
     43       1.1  jonathan 
     44       1.1  jonathan /*
     45       1.1  jonathan  * DMA callbacks
     46       1.1  jonathan  */
     47       1.1  jonathan 
     48       1.7    mhitch static int
     49       1.1  jonathan tc_dma_start __P((struct asc_softc *asc, struct scsi_state *state,
     50       1.7    mhitch 		  caddr_t cp, int flag, int len, int off));
     51       1.1  jonathan 
     52       1.1  jonathan static void
     53       1.1  jonathan tc_dma_end __P((struct asc_softc *asc, struct scsi_state *state,
     54       1.1  jonathan 		int flag));
     55       1.1  jonathan 
     56       1.1  jonathan 
     57       1.1  jonathan int
     58       1.1  jonathan asc_tc_match(parent, match, aux)
     59       1.1  jonathan 	struct device *parent;
     60       1.6  jonathan 	struct cfdata *match;
     61       1.1  jonathan 	void *aux;
     62       1.1  jonathan {
     63       1.1  jonathan 	struct tc_attach_args *t = aux;
     64       1.1  jonathan 
     65       1.1  jonathan 	if (strncmp(t->ta_modname, "PMAZ-AA ", TC_ROM_LLEN))
     66       1.1  jonathan 		return (0);
     67       1.1  jonathan 
     68       1.1  jonathan 	return (1);
     69       1.1  jonathan }
     70       1.1  jonathan 
     71       1.1  jonathan 
     72       1.1  jonathan 
     73       1.1  jonathan void
     74       1.1  jonathan asc_tc_attach(parent, self, aux)
     75       1.1  jonathan 	struct device *parent;
     76       1.1  jonathan 	struct device *self;
     77       1.1  jonathan 	void *aux;
     78       1.1  jonathan {
     79       1.1  jonathan 	register struct tc_attach_args *t = aux;
     80       1.1  jonathan 	register asc_softc_t asc = (asc_softc_t) self;
     81       1.7    mhitch 	u_char *buff;
     82       1.7    mhitch 	int i, speed;
     83       1.1  jonathan 	int unit;
     84       1.1  jonathan 
     85       1.1  jonathan 	unit = asc->sc_dev.dv_unit;
     86       1.1  jonathan 
     87       1.1  jonathan 	/*
     88       1.1  jonathan 	 * Initialize hw descriptor, cache some pointers
     89       1.1  jonathan 	 */
     90  1.10.2.1    bouyer 	asc->regs = (asc_regmap_t *)(t->ta_addr + ASC_OFFSET_53C94);
     91       1.1  jonathan 
     92       1.1  jonathan 	/*
     93       1.1  jonathan 	 * Set up machine dependencies.
     94       1.1  jonathan 	 * (1) how to do dma
     95       1.1  jonathan 	 * (2) timing based on turbochannel frequency
     96       1.1  jonathan 	 */
     97       1.1  jonathan 
     98       1.1  jonathan 	/*
     99       1.1  jonathan 	 * Fall through for turbochannel option.
    100       1.1  jonathan 	 */
    101  1.10.2.1    bouyer 	asc->dmar = (volatile int *)(t->ta_addr + ASC_OFFSET_DMAR);
    102  1.10.2.1    bouyer 	buff = (u_char *)(t->ta_addr + ASC_OFFSET_RAM);
    103       1.7    mhitch 
    104       1.7    mhitch 	/*
    105       1.7    mhitch 	 * Statically partition the DMA buffer between targets.
    106       1.7    mhitch 	 * This way we will eventually be able to attach/detach
    107       1.7    mhitch 	 * drives on-fly.  And 18k/target is plenty for normal use.
    108       1.7    mhitch 	 */
    109       1.7    mhitch 
    110       1.7    mhitch 	/*
    111       1.7    mhitch 	 * Give each target its own DMA buffer region.
    112       1.7    mhitch 	 * We may want to try ping ponging buffers later.
    113       1.7    mhitch 	 */
    114       1.7    mhitch 	for (i = 0; i < ASC_NCMD; i++)
    115       1.7    mhitch 		asc->st[i].dmaBufAddr = buff + PER_TGT_DMA_SIZE * i;
    116       1.7    mhitch 
    117       1.1  jonathan 	asc->dma_start = tc_dma_start;
    118       1.1  jonathan 	asc->dma_end = tc_dma_end;
    119       1.1  jonathan 
    120       1.1  jonathan 	/*
    121       1.1  jonathan 	 * Now for timing. The 3max has a 25Mhz tb whereas the 3min and
    122       1.1  jonathan 	 * maxine are 12.5Mhz.
    123       1.1  jonathan 	 */
    124       1.8  jonathan 	printf(" (bus speed: %s MHz) ", t->ta_busspeed? "25"  : "12.5");
    125       1.1  jonathan 
    126       1.1  jonathan 	switch (t->ta_busspeed) {
    127       1.1  jonathan 	case TC_SPEED_25_MHZ:
    128       1.1  jonathan 		speed = ASC_SPEED_25_MHZ;
    129       1.1  jonathan 		break;
    130       1.1  jonathan 
    131       1.1  jonathan 	default:
    132       1.4  christos 		printf(" (unknown TC speed, assuming 12.5MHz) ");
    133       1.1  jonathan 		/* FALLTHROUGH*/
    134       1.1  jonathan 	case TC_SPEED_12_5_MHZ:
    135       1.1  jonathan 		speed = ASC_SPEED_12_5_MHZ;
    136       1.1  jonathan 		break;
    137       1.1  jonathan 	};
    138       1.1  jonathan 
    139       1.7    mhitch 	ascattach(asc, speed);
    140       1.1  jonathan 
    141       1.1  jonathan 	/* tie pseudo-slot to device */
    142       1.1  jonathan 	tc_intr_establish(parent, t->ta_cookie, TC_IPL_BIO,
    143       1.1  jonathan 			  asc_intr, asc);
    144       1.1  jonathan }
    145       1.1  jonathan 
    146       1.1  jonathan 
    147       1.1  jonathan /*
    148       1.1  jonathan  * DMA handling routines. For a turbochannel device, just set the dmar.
    149       1.1  jonathan  * For the I/O ASIC, handle the actual DMA interface.
    150       1.1  jonathan  */
    151       1.7    mhitch static int
    152       1.7    mhitch tc_dma_start(asc, state, cp, flag, len, off)
    153       1.1  jonathan 	asc_softc_t asc;
    154       1.1  jonathan 	State *state;
    155       1.1  jonathan 	caddr_t cp;
    156       1.1  jonathan 	int flag;
    157       1.7    mhitch 	int len;
    158       1.7    mhitch 	int off;
    159       1.1  jonathan {
    160       1.1  jonathan 
    161       1.7    mhitch 	if (len > PER_TGT_DMA_SIZE)
    162       1.7    mhitch 		len = PER_TGT_DMA_SIZE;
    163       1.1  jonathan 	if (flag == ASCDMA_WRITE)
    164       1.7    mhitch 		bcopy(cp, state->dmaBufAddr + off, len);
    165       1.7    mhitch 	if (flag == ASCDMA_WRITE)
    166       1.7    mhitch 		*asc->dmar = ASC_DMAR_WRITE | ASC_DMA_ADDR(state->dmaBufAddr + off);
    167       1.1  jonathan 	else
    168       1.7    mhitch 		*asc->dmar = ASC_DMA_ADDR(state->dmaBufAddr + off);
    169       1.7    mhitch 	return (len);
    170       1.1  jonathan }
    171       1.1  jonathan 
    172       1.1  jonathan static void
    173       1.1  jonathan tc_dma_end(asc, state, flag)
    174       1.1  jonathan 	asc_softc_t asc;
    175       1.1  jonathan 	State *state;
    176       1.1  jonathan 	int flag;
    177       1.1  jonathan {
    178       1.7    mhitch 	if (flag == ASCDMA_READ)
    179       1.7    mhitch 		bcopy(state->dmaBufAddr, state->buf, state->dmalen);
    180       1.1  jonathan }
    181