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