Home | History | Annotate | Line # | Download | only in dev
bppcsc.c revision 1.1
      1  1.1  phx /*	$NetBSD: bppcsc.c,v 1.1 2011/01/14 10:01:12 phx Exp $ */
      2  1.1  phx 
      3  1.1  phx /*
      4  1.1  phx  * Copyright (c) 1982, 1990 The Regents of the University of California.
      5  1.1  phx  * All rights reserved.
      6  1.1  phx  *
      7  1.1  phx  * Redistribution and use in source and binary forms, with or without
      8  1.1  phx  * modification, are permitted provided that the following conditions
      9  1.1  phx  * are met:
     10  1.1  phx  * 1. Redistributions of source code must retain the above copyright
     11  1.1  phx  *    notice, this list of conditions and the following disclaimer.
     12  1.1  phx  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  phx  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  phx  *    documentation and/or other materials provided with the distribution.
     15  1.1  phx  * 3. Neither the name of the University nor the names of its contributors
     16  1.1  phx  *    may be used to endorse or promote products derived from this software
     17  1.1  phx  *    without specific prior written permission.
     18  1.1  phx  *
     19  1.1  phx  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  1.1  phx  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.1  phx  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.1  phx  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  1.1  phx  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.1  phx  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.1  phx  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.1  phx  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.1  phx  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.1  phx  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.1  phx  * SUCH DAMAGE.
     30  1.1  phx  *
     31  1.1  phx  *	@(#)dma.c
     32  1.1  phx  */
     33  1.1  phx 
     34  1.1  phx /*
     35  1.1  phx  * Copyright (c) 2011 Radoslaw Kujawa
     36  1.1  phx  * Copyright (c) 1994 Michael L. Hitch
     37  1.1  phx  *
     38  1.1  phx  * Redistribution and use in source and binary forms, with or without
     39  1.1  phx  * modification, are permitted provided that the following conditions
     40  1.1  phx  * are met:
     41  1.1  phx  * 1. Redistributions of source code must retain the above copyright
     42  1.1  phx  *    notice, this list of conditions and the following disclaimer.
     43  1.1  phx  * 2. Redistributions in binary form must reproduce the above copyright
     44  1.1  phx  *    notice, this list of conditions and the following disclaimer in the
     45  1.1  phx  *    documentation and/or other materials provided with the distribution.
     46  1.1  phx  *
     47  1.1  phx  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     48  1.1  phx  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     49  1.1  phx  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     50  1.1  phx  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     51  1.1  phx  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     52  1.1  phx  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     53  1.1  phx  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     54  1.1  phx  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     55  1.1  phx  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     56  1.1  phx  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     57  1.1  phx  *
     58  1.1  phx  *	@(#)dma.c
     59  1.1  phx  */
     60  1.1  phx 
     61  1.1  phx #include <sys/cdefs.h>
     62  1.1  phx __KERNEL_RCSID(0, "$NetBSD: bppcsc.c,v 1.1 2011/01/14 10:01:12 phx Exp $");
     63  1.1  phx 
     64  1.1  phx #include <sys/param.h>
     65  1.1  phx #include <sys/systm.h>
     66  1.1  phx #include <sys/kernel.h>
     67  1.1  phx #include <sys/device.h>
     68  1.1  phx 
     69  1.1  phx #include <uvm/uvm_extern.h>
     70  1.1  phx 
     71  1.1  phx #include <dev/scsipi/scsi_all.h>
     72  1.1  phx #include <dev/scsipi/scsipi_all.h>
     73  1.1  phx #include <dev/scsipi/scsiconf.h>
     74  1.1  phx 
     75  1.1  phx #include <amiga/amiga/custom.h>
     76  1.1  phx #include <amiga/amiga/cc.h>
     77  1.1  phx #include <amiga/amiga/device.h>
     78  1.1  phx #include <amiga/amiga/isr.h>
     79  1.1  phx #include <amiga/dev/siopreg.h>
     80  1.1  phx #include <amiga/dev/siopvar.h>
     81  1.1  phx #include <amiga/dev/zbusvar.h>
     82  1.1  phx 
     83  1.1  phx #define BPPC_SCSI_OFF	0xf40000
     84  1.1  phx #define BPPC_PUPROM_OFF	0xf00010
     85  1.1  phx 
     86  1.1  phx void bppcscattach(struct device *, struct device *, void *);
     87  1.1  phx int bppcscmatch(struct device *, struct cfdata *, void *);
     88  1.1  phx int bppcsc_dmaintr(void *);
     89  1.1  phx #ifdef DEBUG
     90  1.1  phx void bppcsc_dump(void);
     91  1.1  phx #endif
     92  1.1  phx 
     93  1.1  phx CFATTACH_DECL(bppcsc, sizeof(struct siop_softc),
     94  1.1  phx     bppcscmatch, bppcscattach, NULL, NULL);
     95  1.1  phx 
     96  1.1  phx /*
     97  1.1  phx  * if we are a Phase5 BlizzardPPC 603e+
     98  1.1  phx  */
     99  1.1  phx int
    100  1.1  phx bppcscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
    101  1.1  phx {
    102  1.1  phx 	struct zbus_args *zap;
    103  1.1  phx 	char *p5type;
    104  1.1  phx 
    105  1.1  phx 	zap = auxp;
    106  1.1  phx 	if (zap->manid == 8512 && zap->prodid == 110) {
    107  1.1  phx 		p5type = (char *)__UNVOLATILE(ztwomap(BPPC_PUPROM_OFF));
    108  1.1  phx 		if (p5type[0] == 'I')		/* only "+" model has SCSI */
    109  1.1  phx 			return 1;
    110  1.1  phx 	}
    111  1.1  phx 	return 0 ;
    112  1.1  phx }
    113  1.1  phx 
    114  1.1  phx void
    115  1.1  phx bppcscattach(struct device *pdp, struct device *dp, void *auxp)
    116  1.1  phx {
    117  1.1  phx 	struct siop_softc *sc;
    118  1.1  phx 	struct scsipi_adapter *adapt;
    119  1.1  phx 	struct scsipi_channel *chan;
    120  1.1  phx 	siop_regmap_p rp;
    121  1.1  phx 
    122  1.1  phx 	sc = (struct siop_softc *)dp;
    123  1.1  phx 	adapt = &sc->sc_adapter;
    124  1.1  phx 	chan = &sc->sc_channel;
    125  1.1  phx 
    126  1.1  phx 	aprint_naive(": SCSI controller\n");
    127  1.1  phx 	aprint_normal(": BlizzardPPC 603e+ SCSI adapter\n");
    128  1.1  phx 
    129  1.1  phx 	sc->sc_siopp = rp = ztwomap(BPPC_SCSI_OFF);
    130  1.1  phx #ifdef DEBUG
    131  1.1  phx 	siop_dump(sc);
    132  1.1  phx #endif
    133  1.1  phx 	/*
    134  1.1  phx 	 * CTEST7 = 00
    135  1.1  phx 	 */
    136  1.1  phx 	sc->sc_clock_freq = 50;		/* Clock = 50 MHz */
    137  1.1  phx 	sc->sc_ctest7 = 0x00;
    138  1.1  phx 	sc->sc_dcntl = 0x20;		/* XXX - taken from cbiiisc */
    139  1.1  phx 
    140  1.1  phx 	/*
    141  1.1  phx 	 * Fill in the scsipi_adapter.
    142  1.1  phx 	 */
    143  1.1  phx 	memset(adapt, 0, sizeof(*adapt));
    144  1.1  phx 	adapt->adapt_dev = &sc->sc_dev;
    145  1.1  phx 	adapt->adapt_nchannels = 1;
    146  1.1  phx 	adapt->adapt_openings = 7;
    147  1.1  phx 	adapt->adapt_max_periph = 1;
    148  1.1  phx 	adapt->adapt_request = siop_scsipi_request;
    149  1.1  phx 	adapt->adapt_minphys = siop_minphys;
    150  1.1  phx 
    151  1.1  phx 	/*
    152  1.1  phx 	 * Fill in the scsipi_channel.
    153  1.1  phx 	 */
    154  1.1  phx 	memset(chan, 0, sizeof(*chan));
    155  1.1  phx 	chan->chan_adapter = adapt;
    156  1.1  phx 	chan->chan_bustype = &scsi_bustype;
    157  1.1  phx 	chan->chan_channel = 0;
    158  1.1  phx 	chan->chan_ntargets = 8;
    159  1.1  phx 	chan->chan_nluns = 8;
    160  1.1  phx 	chan->chan_id = 7;
    161  1.1  phx 
    162  1.1  phx 	siopinitialize(sc);
    163  1.1  phx 
    164  1.1  phx 	sc->sc_isr.isr_intr = bppcsc_dmaintr;
    165  1.1  phx 	sc->sc_isr.isr_arg = sc;
    166  1.1  phx 	sc->sc_isr.isr_ipl = 2;
    167  1.1  phx 	add_isr (&sc->sc_isr);
    168  1.1  phx 
    169  1.1  phx 	/*
    170  1.1  phx 	 * attach all scsi units on us
    171  1.1  phx 	 */
    172  1.1  phx 	config_found(dp, chan, scsiprint);
    173  1.1  phx }
    174  1.1  phx 
    175  1.1  phx int
    176  1.1  phx bppcsc_dmaintr(void *arg)
    177  1.1  phx {
    178  1.1  phx 	struct siop_softc *sc;
    179  1.1  phx 	siop_regmap_p rp;
    180  1.1  phx 	u_char istat;
    181  1.1  phx 
    182  1.1  phx 	sc = arg;
    183  1.1  phx 	if (sc->sc_flags & SIOP_INTSOFF)
    184  1.1  phx 		return 0;	/* interrupts are not active */
    185  1.1  phx 	rp = sc->sc_siopp;
    186  1.1  phx 	amiga_membarrier();
    187  1.1  phx 	istat = rp->siop_istat;
    188  1.1  phx 	if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
    189  1.1  phx 		return 0;
    190  1.1  phx 	/*
    191  1.1  phx 	 * save interrupt status, DMA status, and SCSI status 0
    192  1.1  phx 	 * (may need to deal with stacked interrupts?)
    193  1.1  phx 	 */
    194  1.1  phx 	sc->sc_sstat0 = rp->siop_sstat0;
    195  1.1  phx 	sc->sc_istat = istat;
    196  1.1  phx 	sc->sc_dstat = rp->siop_dstat;
    197  1.1  phx 	amiga_membarrier();
    198  1.1  phx 	siopintr(sc);
    199  1.1  phx 	return 1;
    200  1.1  phx }
    201  1.1  phx 
    202  1.1  phx #ifdef DEBUG
    203  1.1  phx void
    204  1.1  phx bppcsc_dump(void)
    205  1.1  phx {
    206  1.1  phx 	extern struct cfdriver bppcsc_cd;
    207  1.1  phx 	struct siop_softc *sc;
    208  1.1  phx 	int i;
    209  1.1  phx 
    210  1.1  phx 	for (i = 0; i < bppcsc_cd.cd_ndevs; ++i) {
    211  1.1  phx 		sc = device_lookup_private(&bppcsc_cd, i);
    212  1.1  phx 		if (sc != NULL)
    213  1.1  phx 			siop_dump(sc);
    214  1.1  phx 	}
    215  1.1  phx }
    216  1.1  phx #endif
    217