- Additional rearrangement for the sake of running on the DECstation some

day.
- Convert to use bus_dma.
- Fix cleaning up unaligned start address.
- Correctly determine if the device supports Fast SCSI, and adjust the
  minimum sync period accordingly.
- Compute minimum sync period correctly on the 25MHz devices.
- Use GPI2 to determine if we're a 25MHz or 40MHz device.
- Currectly determine SCSI ID and "fast mode enabled" for the built-in
  TCDS on DEC 3000 models, using cached information from the PROM environment.
This commit is contained in:
thorpej 1998-05-26 23:43:05 +00:00
parent ab087002d1
commit 1ef3ca572e
3 changed files with 161 additions and 39 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcds.c,v 1.24 1998/05/25 01:14:38 thorpej Exp $ */
/* $NetBSD: tcds.c,v 1.25 1998/05/26 23:43:05 thorpej Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -66,17 +66,19 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: tcds.c,v 1.24 1998/05/25 01:14:38 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: tcds.c,v 1.25 1998/05/26 23:43:05 thorpej Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>
#ifdef __alpha__
#include <machine/rpb.h>
#ifndef EVCNT_COUNTERS
#include <machine/intrcnt.h>
#endif
#endif /* __alpha__ */
#include <machine/bus.h>
@ -99,6 +101,8 @@ struct tcds_softc {
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
bus_dma_tag_t sc_dmat;
void *sc_cookie;
int sc_flags;
@ -108,7 +112,7 @@ struct tcds_softc {
/* sc_flags */
#define TCDSF_BASEBOARD 0x01 /* baseboard on DEC 3000 */
#define TCDSF_FASTSCSI 0x02 /* fast SCSI device */
#define TCDSF_FASTSCSI 0x02 /* supports Fast SCSI */
/* Definition of the driver for autoconfig. */
int tcdsmatch __P((struct device *, struct cfdata *, void *));
@ -127,8 +131,10 @@ struct tcds_device {
const char *td_name;
int td_flags;
} tcds_devices[] = {
#ifdef __alpha__
{ "PMAZ-DS ", TCDSF_BASEBOARD },
{ "PMAZ-FS ", TCDSF_BASEBOARD|TCDSF_FASTSCSI },
#endif /* __alpha__ */
{ "PMAZB-AA", 0 },
{ "PMAZC-AA", TCDSF_FASTSCSI },
{ NULL, 0 },
@ -172,7 +178,7 @@ tcdsattach(parent, self, aux)
struct tcds_slotconfig *slotc;
struct tcds_device *td;
bus_space_handle_t sbsh[2];
int i, id, fast;
int i, error, gpi2;
extern int cputype;
td = tcds_lookup(ta->ta_modname);
@ -181,22 +187,17 @@ tcdsattach(parent, self, aux)
printf(": TurboChannel Dual SCSI");
if (td->td_flags & TCDSF_BASEBOARD)
printf(", baseboard");
if (td->td_flags & TCDSF_FASTSCSI)
printf(", fast");
printf(" (baseboard)");
printf("\n");
sc->sc_flags = td->td_flags;
#ifndef __alpha__
if (sc->sc_flags & TCDSF_BASEBOARD)
panic("tcdsattach: baseboard TCDS on non-Alpha?!");
#endif
sc->sc_bst = ta->ta_memt;
sc->sc_dmat = ta->ta_dmat;
/*
* Map the device.
*/
sc->sc_bst = ta->ta_memt;
if (bus_space_map(sc->sc_bst, ta->ta_addr,
(TCDS_SCSI1_OFFSET + 0x100), 0, &sc->sc_bsh)) {
printf("%s: unable to map device\n", sc->sc_dv.dv_xname);
@ -228,6 +229,12 @@ tcdsattach(parent, self, aux)
/* XXX Initial contents of CIR? */
/*
* Remember if GPI2 is set in the CIR; we'll need it later.
*/
gpi2 = (bus_space_read_4(sc->sc_bst, sc->sc_bsh, TCDS_CIR) &
TCDS_CIR_GPI_2) != 0;
/*
* Set up the per-slot defintions for later use.
*/
@ -244,6 +251,12 @@ tcdsattach(parent, self, aux)
slotc->sc_asc = NULL;
slotc->sc_intrhand = tcds_intrnull;
slotc->sc_intrarg = (void *)(long)i;
slotc->sc_dmat = sc->sc_dmat;
if ((error = tcds_dma_init(slotc)) != 0) {
printf("%s: tcds_dma_init failed, error = %d\n",
sc->sc_dv.dv_xname, error);
return;
}
}
/* information for slot 0 */
@ -274,18 +287,28 @@ tcdsattach(parent, self, aux)
/* find the hardware attached to the TCDS ASIC */
for (i = 0; i < 2; i++) {
tcds_params(sc, i, &id, &fast);
tcds_params(sc, i, &tcdsdev.tcdsda_id,
&tcdsdev.tcdsda_fast);
tcdsdev.tcdsda_bst = sc->sc_bst;
tcdsdev.tcdsda_bsh = sbsh[i];
tcdsdev.tcdsda_chip = i;
tcdsdev.tcdsda_sc = &sc->sc_slots[i];
tcdsdev.tcdsda_id = id; /* XXX */
tcdsdev.tcdsda_freq = 25000000; /* XXX */
if (sc->sc_flags & TCDSF_FASTSCSI)
tcdsdev.tcdsda_variant = NCR_VARIANT_NCR53C96;
else
/*
* Determine the chip frequency. If GPI2 is set, we have a
* 25MHz clock, else a 40MHz clock.
*/
if (gpi2) {
tcdsdev.tcdsda_freq = 25000000;
tcdsdev.tcdsda_period = 5;
} else {
tcdsdev.tcdsda_freq = 40000000;
tcdsdev.tcdsda_period = tcdsdev.tcdsda_fast ? 4 : 8;
}
if (sc->sc_flags & TCDSF_BASEBOARD)
tcdsdev.tcdsda_variant = NCR_VARIANT_NCR53C94;
else
tcdsdev.tcdsda_variant = NCR_VARIANT_NCR53C96;
tcds_scsi_reset(tcdsdev.tcdsda_sc);
@ -546,13 +569,15 @@ tcds_params(sc, chip, idp, fastp)
struct tcds_softc *sc;
int chip, *idp, *fastp;
{
int id, fast;
u_int32_t ids;
#ifdef __alpha__
if (sc->sc_flags && TCDSF_BASEBOARD) {
/* XXX Implement me. */
*idp = 7;
*fastp = 0;
extern u_int8_t dec_3000_scsiid[], dec_3000_scsifast[];
id = dec_3000_scsiid[chip];
fast = dec_3000_scsifast[chip];
} else
#endif /* __alpha__ */
{
@ -565,11 +590,23 @@ tcds_params(sc, chip, idp, fastp)
if (chip == 0)
ids >>= 4;
*idp = ids & 0x7;
*fastp = ids & 0x8;
id = ids & 0x7;
fast = ids & 0x8;
}
if ((sc->sc_flags & TCDSF_FASTSCSI) != 0 && *fastp == 0)
printf("%s: WARNING: chip %d not in fast mode\n",
if (id < 0 || id > 7) {
printf("%s: WARNING: bad SCSI ID %d for chip %d, using 7\n",
sc->sc_dv.dv_xname, id, chip);
id = 7;
}
if ((sc->sc_flags & TCDSF_FASTSCSI) == 0)
fast = 0;
if (fast)
printf("%s: fast mode set for chip %d\n",
sc->sc_dv.dv_xname, chip);
*idp = id;
*fastp = fast;
}

View File

@ -1,4 +1,41 @@
/* $NetBSD: tcds_dma.c,v 1.24 1998/05/24 23:41:43 thorpej Exp $ */
/* $NetBSD: tcds_dma.c,v 1.25 1998/05/26 23:43:05 thorpej Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
* NASA Ames Research Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1994 Peter Galbavy. All rights reserved.
@ -31,7 +68,7 @@
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: tcds_dma.c,v 1.24 1998/05/24 23:41:43 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: tcds_dma.c,v 1.25 1998/05/26 23:43:05 thorpej Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -95,10 +132,12 @@ tcds_dma_intr(sc)
struct tcds_slotconfig *sc;
{
struct ncr53c9x_softc *nsc = &sc->sc_asc->sc_ncr53c9x;
bus_dmamap_t map = sc->sc_dmamap;
u_int32_t dud;
int trans = 0, resid = 0;
u_int32_t *addr, dudmask;
u_int8_t tcl, tcm, tch;
bus_addr_t pa;
NCR_DMA(("tcds_dma %d: intr", sc->sc_slot));
@ -149,6 +188,9 @@ tcds_dma_intr(sc)
NCR_DMA(("tcds_dma_intr: tcl=%d, tcm=%d, tch=%d; trans=%d, resid=%d\n",
tcl, tcm, tch, trans, resid));
bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize,
(sc->sc_iswrite ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE));
/*
* Clean up unaligned DMAs into main memory.
*/
@ -157,7 +199,7 @@ tcds_dma_intr(sc)
dud = bus_space_read_4(sc->sc_bst, sc->sc_bsh, sc->sc_dud0);
if ((dud & TCDS_DUD0_VALIDBITS) != 0) {
addr = (u_int32_t *)
((vm_offset_t)sc->sc_dmaaddr & ~0x3);
((vm_offset_t)*sc->sc_dmaaddr & ~0x3);
dudmask = 0;
if (dud & TCDS_DUD0_VALID00)
panic("tcds_dma: dud0 byte 0 valid");
@ -171,15 +213,12 @@ tcds_dma_intr(sc)
#endif
NCR_DMA(("dud0 at 0x%p dudmask 0x%x\n",
addr, dudmask));
addr = (u_int32_t *)ALPHA_PHYS_TO_K0SEG((vm_offset_t)addr);
*addr = (*addr & ~dudmask) | (dud & dudmask);
}
dud = bus_space_read_4(sc->sc_bst, sc->sc_bsh, sc->sc_dud1);
if ((dud & TCDS_DUD1_VALIDBITS) != 0) {
addr = (u_int32_t *)
((vm_offset_t)bus_space_read_4(sc->sc_bst,
sc->sc_bsh, sc->sc_sda) << 2);
pa = bus_space_read_4(sc->sc_bst, sc->sc_bsh,
sc->sc_sda) << 2;
dudmask = 0;
if (dud & TCDS_DUD1_VALID00)
dudmask |= TCDS_DUD_BYTE00;
@ -192,13 +231,22 @@ tcds_dma_intr(sc)
panic("tcds_dma: dud1 byte 3 valid");
#endif
NCR_DMA(("dud1 at 0x%p dudmask 0x%x\n",
addr, dudmask));
addr = (u_int32_t *)ALPHA_PHYS_TO_K0SEG((vm_offset_t)addr);
pa, dudmask));
/* XXX Fix TC_PHYS_TO_UNCACHED() */
#if defined(__alpha__)
addr = (u_int32_t *)ALPHA_PHYS_TO_K0SEG(pa);
#elif defined(__mips__)
addr = (u_int32_t *)MIPS_PHYS_TO_KSEG1(pa);
#else
#error TurboChannel only exists on DECs, folks...
#endif
*addr = (*addr & ~dudmask) | (dud & dudmask);
}
/* XXX deal with saved residual byte? */
}
bus_dmamap_unload(sc->sc_dmat, map);
*sc->sc_dmalen -= trans;
*sc->sc_dmaaddr += trans;
@ -226,6 +274,7 @@ tcds_dma_setup(sc, addr, len, datain, dmasize)
size_t *len, *dmasize;
int datain; /* DMA into main memory */
{
bus_dmamap_t map = sc->sc_dmamap;
u_int32_t dic;
size_t size;
@ -245,12 +294,24 @@ tcds_dma_setup(sc, addr, len, datain, dmasize)
NCR_DMA(("dma_start: dmasize = %ld\n", sc->sc_dmasize));
if (bus_dmamap_load(sc->sc_dmat, map, *addr, size,
NULL, BUS_DMA_NOWAIT)) {
/*
* XXX Should return an error, here, but the upper-layer
* XXX doesn't check the return value!
*/
panic("tcds_dma_setup: dmamap load failed");
}
bus_dmamap_sync(sc->sc_dmat, map, 0, map->dm_mapsize,
(sc->sc_iswrite ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE));
/* Load address, set/clear unaligned transfer and read/write bits. */
bus_space_write_4(sc->sc_bst, sc->sc_bsh, sc->sc_sda,
vtophys((vm_offset_t)*addr) >> 2);
map->dm_segs[0].ds_addr >> 2);
dic = bus_space_read_4(sc->sc_bst, sc->sc_bsh, sc->sc_dic);
dic &= ~TCDS_DIC_ADDRMASK;
dic |= (vm_offset_t)*addr & TCDS_DIC_ADDRMASK;
dic |= map->dm_segs[0].ds_addr & TCDS_DIC_ADDRMASK;
if (datain)
dic |= TCDS_DIC_WRITE;
else
@ -279,3 +340,18 @@ tcds_dma_isactive(sc)
return (sc->sc_active);
}
int
tcds_dma_init(sc)
struct tcds_slotconfig *sc;
{
/*
* The TCDS ASIC cannot DMA across 8k boundaries, and this
* driver is written such that each DMA segment gets a new
* call to tcds_dma_setup(). Thus, the DMA map only needs
* to support 8k transfers.
*/
return (bus_dmamap_create(sc->sc_dmat, 0x2000, 1, 0x2000,
0x2000, BUS_DMA_NOWAIT, &sc->sc_dmamap));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcdsvar.h,v 1.9 1998/05/24 23:41:43 thorpej Exp $ */
/* $NetBSD: tcdsvar.h,v 1.10 1998/05/26 23:43:05 thorpej Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@ -36,7 +36,7 @@ struct tcds_slotconfig {
bus_space_tag_t sc_bst; /* to frob TCDS regs */
bus_space_handle_t sc_bsh;
struct asc_softc *sc_asc; /* to frob child's regs */
struct asc_tcds_softc *sc_asc; /* to frob child's regs */
int (*sc_intrhand) __P((void *)); /* intr. handler */
void *sc_intrarg; /* intr. handler arg. */
@ -62,6 +62,8 @@ struct tcds_slotconfig {
/*
* DMA bookkeeping information.
*/
bus_dma_tag_t sc_dmat;
bus_dmamap_t sc_dmamap;
int sc_active; /* DMA active ? */
int sc_iswrite; /* DMA into main memory? */
size_t sc_dmasize;
@ -76,7 +78,9 @@ struct tcdsdev_attach_args {
int tcdsda_chip; /* chip number */
int tcdsda_id; /* SCSI ID */
u_int tcdsda_freq; /* chip frequency */
int tcdsda_period; /* min. sync period */
int tcdsda_variant; /* NCR chip variant */
int tcdsda_fast; /* chip does Fast mode */
};
/*
@ -101,3 +105,8 @@ int tcds_dma_setup __P((struct tcds_slotconfig *, caddr_t *, size_t *,
int, size_t *));
void tcds_dma_go __P((struct tcds_slotconfig *));
int tcds_dma_isactive __P((struct tcds_slotconfig *));
/*
* TCDS DMA functions (private to TCDS)
*/
int tcds_dma_init __P((struct tcds_slotconfig *));