1999-12-03 07:26:17 +03:00
|
|
|
/* $NetBSD: asc_ioasic.c,v 1.18 1999/12/03 04:26:17 mhitch Exp $ */
|
1996-09-26 01:07:46 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1996 The Board of Trustees of The Leland Stanford
|
|
|
|
* Junior University. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose and without
|
|
|
|
* fee is hereby granted, provided that the above copyright
|
|
|
|
* notice appear in all copies. Stanford University
|
|
|
|
* makes no representations about the suitability of this
|
|
|
|
* software for any purpose. It is provided "as is" without
|
|
|
|
* express or implied warranty.
|
|
|
|
*
|
|
|
|
*/
|
1997-07-28 23:39:22 +04:00
|
|
|
#define USE_CACHED_BUFFER 0
|
|
|
|
|
1996-09-26 01:07:46 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
1999-04-20 10:48:58 +04:00
|
|
|
|
1996-09-26 01:07:46 +04:00
|
|
|
#include <dev/tc/tcvar.h>
|
|
|
|
#include <dev/tc/ioasicvar.h>
|
1999-04-20 10:48:58 +04:00
|
|
|
|
1997-06-22 11:42:25 +04:00
|
|
|
#include <pmax/dev/device.h> /* XXX */
|
|
|
|
#include <pmax/dev/scsi.h> /* XXX */
|
1996-09-26 01:07:46 +04:00
|
|
|
|
1997-06-22 11:42:25 +04:00
|
|
|
#include <pmax/dev/ascreg.h> /* XXX */
|
1996-09-26 01:07:46 +04:00
|
|
|
#include <dev/tc/ascvar.h>
|
|
|
|
|
1997-06-22 11:42:25 +04:00
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/bus.h> /* bus, cache consistency, etc */
|
1996-09-26 01:07:46 +04:00
|
|
|
|
|
|
|
/*XXX*/
|
|
|
|
#include <pmax/pmax/asic.h> /* XXX ioasic register defs? */
|
1999-01-16 09:36:42 +03:00
|
|
|
#include <pmax/pmax/kmin.h> /* XXX ioasic register defs? */
|
1996-09-26 01:07:46 +04:00
|
|
|
#include <pmax/pmax/pmaxtype.h>
|
|
|
|
extern int pmax_boardtype;
|
|
|
|
|
1998-08-13 06:10:37 +04:00
|
|
|
extern paddr_t kvtophys __P((vaddr_t));
|
1996-09-26 01:07:46 +04:00
|
|
|
|
1998-05-27 08:30:07 +04:00
|
|
|
extern tc_addr_t ioasic_base; /* XXX */
|
|
|
|
|
1996-09-26 01:07:46 +04:00
|
|
|
/*
|
|
|
|
* Autoconfiguration data for config.
|
|
|
|
*/
|
1997-07-21 09:39:02 +04:00
|
|
|
int asc_ioasic_match __P((struct device *, struct cfdata *, void *));
|
1996-09-26 01:07:46 +04:00
|
|
|
void asc_ioasic_attach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct cfattach asc_ioasic_ca = {
|
|
|
|
sizeof(struct asc_softc), asc_ioasic_match, asc_ioasic_attach
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DMA callback declarations
|
|
|
|
*/
|
|
|
|
|
1997-07-28 23:39:22 +04:00
|
|
|
static int
|
|
|
|
asic_dma_start __P((asc_softc_t asc, State *state, caddr_t cp, int flag,
|
|
|
|
int len, int off));
|
1996-09-26 01:07:46 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
asic_dma_end __P((asc_softc_t asc, State *state, int flag));
|
|
|
|
|
|
|
|
int
|
|
|
|
asc_ioasic_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
1997-07-21 09:39:02 +04:00
|
|
|
struct cfdata *match;
|
1996-09-26 01:07:46 +04:00
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct ioasicdev_attach_args *d = aux;
|
|
|
|
|
1999-11-15 08:25:57 +03:00
|
|
|
if (strncmp(d->iada_modname, "asc", TC_ROM_LLEN) != 0)
|
1996-09-26 01:07:46 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
asc_ioasic_attach(parent, self, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
register struct ioasicdev_attach_args *d = aux;
|
|
|
|
register asc_softc_t asc = (asc_softc_t) self;
|
|
|
|
|
1999-01-16 09:36:42 +03:00
|
|
|
tc_addr_t ascaddr;
|
1996-09-26 01:07:46 +04:00
|
|
|
int unit;
|
|
|
|
|
1999-01-16 09:36:42 +03:00
|
|
|
ascaddr = (tc_addr_t)MIPS_PHYS_TO_KSEG1(d->iada_addr);
|
1996-09-26 01:07:46 +04:00
|
|
|
unit = asc->sc_dev.dv_unit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize hw descriptor, cache some pointers
|
|
|
|
*/
|
|
|
|
asc->regs = (asc_regmap_t *)(ascaddr + ASC_OFFSET_53C94);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up machine dependencies.
|
|
|
|
* (1) how to do dma
|
|
|
|
* (2) timing based on turbochannel frequency
|
|
|
|
*/
|
|
|
|
|
|
|
|
*((volatile int *)IOASIC_REG_SCSI_DMAPTR(ioasic_base)) = -1;
|
|
|
|
*((volatile int *)IOASIC_REG_SCSI_DMANPTR(ioasic_base)) = -1;
|
|
|
|
*((volatile int *)IOASIC_REG_SCSI_SCR(ioasic_base)) = 0;
|
|
|
|
asc->dma_start = asic_dma_start;
|
|
|
|
asc->dma_end = asic_dma_end;
|
|
|
|
|
1997-04-06 13:58:30 +04:00
|
|
|
/* digital meters show IOASIC 53c94s are clocked at approx 25MHz */
|
1997-07-28 23:39:22 +04:00
|
|
|
ascattach(asc, ASC_SPEED_25_MHZ);
|
1996-09-26 01:07:46 +04:00
|
|
|
|
|
|
|
/* tie pseudo-slot to device */
|
|
|
|
|
|
|
|
ioasic_intr_establish(parent, d->iada_cookie, TC_IPL_BIO,
|
|
|
|
asc_intr, asc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DMA handling routines. For a turbochannel device, just set the dmar.
|
|
|
|
* For the I/O ASIC, handle the actual DMA interface.
|
|
|
|
*/
|
1997-07-28 23:39:22 +04:00
|
|
|
static int
|
|
|
|
asic_dma_start(asc, state, cp, flag, len, off)
|
1996-09-26 01:07:46 +04:00
|
|
|
asc_softc_t asc;
|
|
|
|
State *state;
|
|
|
|
caddr_t cp;
|
|
|
|
int flag;
|
1997-07-28 23:39:22 +04:00
|
|
|
int len;
|
|
|
|
int off;
|
1996-09-26 01:07:46 +04:00
|
|
|
{
|
|
|
|
register volatile u_int *ssr = (volatile u_int *)
|
|
|
|
IOASIC_REG_CSR(ioasic_base);
|
|
|
|
u_int phys, nphys;
|
|
|
|
|
|
|
|
/* stop DMA engine first */
|
|
|
|
*ssr &= ~IOASIC_CSR_DMAEN_SCSI;
|
|
|
|
*((volatile int *)IOASIC_REG_SCSI_SCR(ioasic_base)) = 0;
|
|
|
|
|
1997-07-28 23:39:22 +04:00
|
|
|
/* restrict len to the maximum the IOASIC can transfer */
|
|
|
|
if (len > ((caddr_t)mips_trunc_page(cp + NBPG * 2) - cp))
|
|
|
|
len = (caddr_t)mips_trunc_page(cp + NBPG * 2) - cp;
|
|
|
|
|
1999-12-03 07:26:17 +03:00
|
|
|
if ((vaddr_t)cp & 7) {
|
|
|
|
u_int32_t *p;
|
|
|
|
u_int32_t scrval;
|
|
|
|
|
|
|
|
p = (u_int32_t *)((vaddr_t)cp & ~7);
|
|
|
|
*((volatile u_int32_t *)IOASIC_REG_SCSI_SDR0(ioasic_base)) = p[0];
|
|
|
|
*((volatile u_int32_t *)IOASIC_REG_SCSI_SDR1(ioasic_base)) = p[1];
|
|
|
|
scrval = ((vaddr_t)cp >> 1) & 3;
|
|
|
|
cp = (caddr_t)((vaddr_t)cp & ~7);
|
|
|
|
if (flag != ASCDMA_READ) {
|
|
|
|
scrval |= 4;
|
|
|
|
cp += 8;
|
|
|
|
}
|
|
|
|
*((volatile int *)IOASIC_REG_SCSI_SCR(ioasic_base)) = scrval;
|
|
|
|
}
|
|
|
|
|
1997-07-28 23:39:22 +04:00
|
|
|
/* If R4K, writeback and invalidate the buffer */
|
|
|
|
if (CPUISMIPS3)
|
1998-08-13 06:10:37 +04:00
|
|
|
mips3_HitFlushDCache((vaddr_t)cp, len);
|
1997-07-28 23:39:22 +04:00
|
|
|
|
|
|
|
/* Get physical address of buffer start, no next phys addr */
|
1998-08-13 06:10:37 +04:00
|
|
|
phys = (u_int)kvtophys((vaddr_t)cp);
|
1997-07-28 23:39:22 +04:00
|
|
|
nphys = -1;
|
|
|
|
|
|
|
|
/* Compute 2nd DMA pointer only if next page is part of this I/O */
|
|
|
|
if ((NBPG - (phys & (NBPG - 1))) < len) {
|
|
|
|
cp = (caddr_t)mips_trunc_page(cp + NBPG);
|
1998-08-13 06:10:37 +04:00
|
|
|
nphys = (u_int)kvtophys((vaddr_t)cp);
|
1997-07-28 23:39:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If not R4K, need to invalidate cache lines for both physical segments */
|
|
|
|
if (!CPUISMIPS3 && flag == ASCDMA_READ) {
|
|
|
|
MachFlushDCache(MIPS_PHYS_TO_KSEG0(phys),
|
|
|
|
nphys == 0xffffffff ? len : NBPG - (phys & (NBPG - 1)));
|
|
|
|
if (nphys != 0xffffffff)
|
|
|
|
MachFlushDCache(MIPS_PHYS_TO_KSEG0(nphys),
|
|
|
|
NBPG); /* XXX */
|
|
|
|
}
|
1996-09-26 01:07:46 +04:00
|
|
|
|
1997-07-28 23:39:22 +04:00
|
|
|
#ifdef notyet
|
1996-09-26 01:07:46 +04:00
|
|
|
asc->dma_next = cp;
|
|
|
|
asc->dma_xfer = state->dmalen - (nphys - phys);
|
1997-07-28 23:39:22 +04:00
|
|
|
#endif
|
1996-09-26 01:07:46 +04:00
|
|
|
|
|
|
|
*(volatile int *)IOASIC_REG_SCSI_DMAPTR(ioasic_base) =
|
|
|
|
IOASIC_DMA_ADDR(phys);
|
|
|
|
*(volatile int *)IOASIC_REG_SCSI_DMANPTR(ioasic_base) =
|
|
|
|
IOASIC_DMA_ADDR(nphys);
|
|
|
|
if (flag == ASCDMA_READ)
|
|
|
|
*ssr |= IOASIC_CSR_SCSI_DIR | IOASIC_CSR_DMAEN_SCSI;
|
|
|
|
else
|
|
|
|
*ssr = (*ssr & ~IOASIC_CSR_SCSI_DIR) | IOASIC_CSR_DMAEN_SCSI;
|
|
|
|
wbflush();
|
1997-07-28 23:39:22 +04:00
|
|
|
return (len);
|
1996-09-26 01:07:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
asic_dma_end(asc, state, flag)
|
|
|
|
asc_softc_t asc;
|
|
|
|
State *state;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
register volatile u_int *ssr = (volatile u_int *)
|
|
|
|
IOASIC_REG_CSR(ioasic_base);
|
|
|
|
register volatile u_int *dmap = (volatile u_int *)
|
|
|
|
IOASIC_REG_SCSI_DMAPTR(ioasic_base);
|
|
|
|
register u_short *to;
|
|
|
|
int nb;
|
|
|
|
|
|
|
|
*ssr &= ~IOASIC_CSR_DMAEN_SCSI;
|
1997-07-28 23:39:22 +04:00
|
|
|
#if USE_CACHED_BUFFER /* XXX - Should uncached address always be used? */
|
1997-06-22 11:42:25 +04:00
|
|
|
to = (u_short *)MIPS_PHYS_TO_KSEG0(*dmap >> 3);
|
1997-07-28 23:39:22 +04:00
|
|
|
#else
|
|
|
|
to = (u_short *)MIPS_PHYS_TO_KSEG1(*dmap >> 3);
|
|
|
|
#endif
|
1996-09-26 01:07:46 +04:00
|
|
|
*dmap = -1;
|
|
|
|
*((volatile int *)IOASIC_REG_SCSI_DMANPTR(ioasic_base)) = -1;
|
|
|
|
wbflush();
|
|
|
|
|
|
|
|
if (flag == ASCDMA_READ) {
|
1997-07-28 23:39:22 +04:00
|
|
|
#if !defined(ASC_IOASIC_BOUNCE) && USE_CACHED_BUFFER
|
|
|
|
/* Invalidate cache for the buffer */
|
1997-06-15 22:24:05 +04:00
|
|
|
#ifdef MIPS3
|
1997-06-21 08:06:11 +04:00
|
|
|
if (CPUISMIPS3)
|
1997-06-22 11:42:25 +04:00
|
|
|
MachFlushDCache(MIPS_KSEG1_TO_PHYS(state->dmaBufAddr),
|
1997-06-15 22:24:05 +04:00
|
|
|
state->dmalen);
|
|
|
|
else
|
1997-06-21 08:06:11 +04:00
|
|
|
#endif /* MIPS3 */
|
1997-06-22 11:42:25 +04:00
|
|
|
MachFlushDCache(MIPS_PHYS_TO_KSEG0(
|
|
|
|
MIPS_KSEG1_TO_PHYS(state->dmaBufAddr)),
|
1997-06-15 22:24:05 +04:00
|
|
|
state->dmalen);
|
1997-07-28 23:39:22 +04:00
|
|
|
#endif /* USE_CACHED_BUFFER */
|
1996-09-26 01:07:46 +04:00
|
|
|
if ( (nb = *((int *)IOASIC_REG_SCSI_SCR(ioasic_base))) != 0) {
|
1999-12-03 07:26:17 +03:00
|
|
|
int sdr[2];
|
|
|
|
/* pick up last upto 6 bytes, sigh. */
|
|
|
|
|
|
|
|
/* Copy untransferred data from IOASIC */
|
|
|
|
sdr[0] = *(int *)IOASIC_REG_SCSI_SDR0(ioasic_base);
|
|
|
|
sdr[1] = *(int *)IOASIC_REG_SCSI_SDR1(ioasic_base);
|
|
|
|
memcpy(to, (char *)sdr, nb * 2);
|
1996-09-26 01:07:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef notdef
|
1999-01-16 09:36:42 +03:00
|
|
|
/*
|
|
|
|
* XXX Below is just informational for how IOASIC DMA is handled. XXX
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern struct cfdriver asc_cd;
|
|
|
|
|
1996-09-26 01:07:46 +04:00
|
|
|
/*
|
|
|
|
* Called by asic_intr() for scsi dma pointer update interrupts.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
asc_dma_intr()
|
|
|
|
{
|
|
|
|
asc_softc_t asc = &asc_cd.cd_devs[0]; /*XXX*/
|
|
|
|
u_int next_phys;
|
|
|
|
|
|
|
|
asc->dma_xfer -= NBPG;
|
|
|
|
if (asc->dma_xfer <= -NBPG) {
|
|
|
|
volatile u_int *ssr = (volatile u_int *)
|
|
|
|
IOASIC_REG_CSR(ioasic_base);
|
|
|
|
*ssr &= ~IOASIC_CSR_DMAEN_SCSI;
|
|
|
|
} else {
|
|
|
|
asc->dma_next += NBPG;
|
1997-06-22 11:42:25 +04:00
|
|
|
next_phys = MIPS_KSEG0_TO_PHYS(asc->dma_next);
|
1996-09-26 01:07:46 +04:00
|
|
|
}
|
|
|
|
*(volatile int *)IOASIC_REG_SCSI_DMANPTR(ioasic_base) =
|
|
|
|
IOASIC_DMA_ADDR(next_phys);
|
|
|
|
wbflush();
|
|
|
|
}
|
|
|
|
#endif /*notdef*/
|