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