Home | History | Annotate | Line # | Download | only in dev
      1  1.5  thorpej /*	$NetBSD: bppcsc.c,v 1.5 2021/08/07 16:18:41 thorpej 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.5  thorpej __KERNEL_RCSID(0, "$NetBSD: bppcsc.c,v 1.5 2021/08/07 16:18:41 thorpej 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.2  rkujawa #include <amiga/dev/p5busvar.h>
     83  1.1      phx 
     84  1.1      phx #define BPPC_SCSI_OFF	0xf40000
     85  1.1      phx #define BPPC_PUPROM_OFF	0xf00010
     86  1.1      phx 
     87  1.3      chs void bppcscattach(device_t, device_t, void *);
     88  1.3      chs int bppcscmatch(device_t, cfdata_t, void *);
     89  1.1      phx int bppcsc_dmaintr(void *);
     90  1.1      phx #ifdef DEBUG
     91  1.1      phx void bppcsc_dump(void);
     92  1.1      phx #endif
     93  1.1      phx 
     94  1.3      chs CFATTACH_DECL_NEW(bppcsc, sizeof(struct siop_softc),
     95  1.1      phx     bppcscmatch, bppcscattach, NULL, NULL);
     96  1.1      phx 
     97  1.1      phx /*
     98  1.1      phx  * if we are a Phase5 BlizzardPPC 603e+
     99  1.1      phx  */
    100  1.1      phx int
    101  1.3      chs bppcscmatch(device_t parent, cfdata_t cf, void *aux)
    102  1.1      phx {
    103  1.2  rkujawa 	struct p5bus_attach_args *p5baa;
    104  1.2  rkujawa 
    105  1.3      chs 	p5baa = aux;
    106  1.2  rkujawa 
    107  1.2  rkujawa 	if (strcmp(p5baa->p5baa_name, "bppcsc") == 0)
    108  1.2  rkujawa 		return 1;
    109  1.1      phx 
    110  1.1      phx 	return 0 ;
    111  1.1      phx }
    112  1.1      phx 
    113  1.1      phx void
    114  1.3      chs bppcscattach(device_t parent, device_t self, void *aux)
    115  1.1      phx {
    116  1.1      phx 	struct siop_softc *sc;
    117  1.1      phx 	struct scsipi_adapter *adapt;
    118  1.1      phx 	struct scsipi_channel *chan;
    119  1.1      phx 	siop_regmap_p rp;
    120  1.1      phx 
    121  1.3      chs 	sc = device_private(self);
    122  1.3      chs 	sc->sc_dev = self;
    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.3      chs 	adapt->adapt_dev = self;
    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.5  thorpej 	config_found(self, chan, scsiprint, CFARGS_NONE);
    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