xref: /netbsd-src/sys/arch/amiga/dev/cbiiisc.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: cbiiisc.c,v 1.23 2021/08/07 16:18:41 thorpej Exp $ */
2aad01611Sagc 
3aad01611Sagc /*
4aad01611Sagc  * Copyright (c) 1982, 1990 The Regents of the University of California.
5aad01611Sagc  * All rights reserved.
6aad01611Sagc  *
7aad01611Sagc  * Redistribution and use in source and binary forms, with or without
8aad01611Sagc  * modification, are permitted provided that the following conditions
9aad01611Sagc  * are met:
10aad01611Sagc  * 1. Redistributions of source code must retain the above copyright
11aad01611Sagc  *    notice, this list of conditions and the following disclaimer.
12aad01611Sagc  * 2. Redistributions in binary form must reproduce the above copyright
13aad01611Sagc  *    notice, this list of conditions and the following disclaimer in the
14aad01611Sagc  *    documentation and/or other materials provided with the distribution.
15aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
16aad01611Sagc  *    may be used to endorse or promote products derived from this software
17aad01611Sagc  *    without specific prior written permission.
18aad01611Sagc  *
19aad01611Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20aad01611Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21aad01611Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22aad01611Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23aad01611Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24aad01611Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25aad01611Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26aad01611Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27aad01611Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28aad01611Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29aad01611Sagc  * SUCH DAMAGE.
30aad01611Sagc  *
31aad01611Sagc  *	@(#)dma.c
32aad01611Sagc  */
336505010dSis 
346505010dSis /*
356505010dSis  * Copyright (c) 1994,1998 Michael L. Hitch
366505010dSis  *
376505010dSis  * Redistribution and use in source and binary forms, with or without
386505010dSis  * modification, are permitted provided that the following conditions
396505010dSis  * are met:
406505010dSis  * 1. Redistributions of source code must retain the above copyright
416505010dSis  *    notice, this list of conditions and the following disclaimer.
426505010dSis  * 2. Redistributions in binary form must reproduce the above copyright
436505010dSis  *    notice, this list of conditions and the following disclaimer in the
446505010dSis  *    documentation and/or other materials provided with the distribution.
456505010dSis  *
4621f2c02fSmhitch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
4721f2c02fSmhitch  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4821f2c02fSmhitch  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
4921f2c02fSmhitch  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
5021f2c02fSmhitch  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
5121f2c02fSmhitch  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5221f2c02fSmhitch  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5321f2c02fSmhitch  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5421f2c02fSmhitch  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
5521f2c02fSmhitch  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
566505010dSis  *
576505010dSis  *	@(#)dma.c
586505010dSis  */
596505010dSis 
601ea4df81Saymeric #include <sys/cdefs.h>
61*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: cbiiisc.c,v 1.23 2021/08/07 16:18:41 thorpej Exp $");
621ea4df81Saymeric 
636505010dSis #include <sys/param.h>
646505010dSis #include <sys/systm.h>
656505010dSis #include <sys/kernel.h>
666505010dSis #include <sys/device.h>
676a66466fSmatt #include <sys/cpu.h>
680871fe34Sthorpej 
696505010dSis #include <dev/scsipi/scsi_all.h>
706505010dSis #include <dev/scsipi/scsipi_all.h>
716505010dSis #include <dev/scsipi/scsiconf.h>
726505010dSis #include <amiga/amiga/custom.h>
736505010dSis #include <amiga/amiga/cc.h>
746505010dSis #include <amiga/amiga/device.h>
756505010dSis #include <amiga/amiga/isr.h>
766505010dSis 
776505010dSis #define ARCH_720			/* This is for a 53c770 */
786505010dSis 
796505010dSis #include <amiga/dev/siopreg.h>
806505010dSis #include <amiga/dev/siopvar.h>
816505010dSis #include <amiga/dev/zbusvar.h>
82363ad7afSrkujawa #include <amiga/dev/p5busvar.h>
836505010dSis 
84cbab9cadSchs void cbiiiscattach(device_t, device_t, void *);
85cbab9cadSchs int  cbiiiscmatch(device_t, cfdata_t, void *);
869382c873Saymeric int  cbiiisc_dmaintr(void *);
876505010dSis #ifdef DEBUG
889382c873Saymeric void cbiiisc_dump(void);
896505010dSis #endif
906505010dSis 
916505010dSis #ifdef DEBUG
926505010dSis #endif
936505010dSis 
94cbab9cadSchs CFATTACH_DECL_NEW(cbiiisc, sizeof(struct siop_softc),
95c5e91d44Sthorpej     cbiiiscmatch, cbiiiscattach, NULL, NULL);
966505010dSis 
976505010dSis /*
986505010dSis  * if we are a CyberStorm MK III SCSI
996505010dSis  */
1006505010dSis int
cbiiiscmatch(device_t parent,cfdata_t cf,void * aux)101cbab9cadSchs cbiiiscmatch(device_t parent, cfdata_t cf, void *aux)
1026505010dSis {
103363ad7afSrkujawa 	struct p5bus_attach_args *p5baa;
1046505010dSis 
105cbab9cadSchs 	p5baa = aux;
106363ad7afSrkujawa 
107363ad7afSrkujawa 	if (strcmp(p5baa->p5baa_name, "cbiiisc") == 0)
108363ad7afSrkujawa 		return 1;
109363ad7afSrkujawa 
110363ad7afSrkujawa 	return 0;
1116505010dSis }
1126505010dSis 
1136505010dSis void
cbiiiscattach(device_t parent,device_t self,void * aux)114cbab9cadSchs cbiiiscattach(device_t parent, device_t self, void *aux)
1156505010dSis {
116cbab9cadSchs 	struct siop_softc *sc = device_private(self);
1176505010dSis 	siop_regmap_p rp;
118937a7a3eSbouyer         struct scsipi_adapter *adapt = &sc->sc_adapter;
119937a7a3eSbouyer         struct scsipi_channel *chan = &sc->sc_channel;
1206505010dSis 
121363ad7afSrkujawa 	aprint_normal(": CyberStorm PPC/Mk-III SCSI host adapter\n");
1226505010dSis 
123cbab9cadSchs 	sc->sc_dev = self;
1246505010dSis 	sc->sc_siopp = rp = ztwomap(0xf40000);
12592568502Sis 	/* siopng_dump_registers(sc); */
1266505010dSis 
1276505010dSis 	/*
1286505010dSis 	 * CTEST7 = 00
1296505010dSis 	 */
130a1f606d3Slukem 	sc->sc_clock_freq = 50;		/* Clock = 50 MHz >> */
1316505010dSis 	sc->sc_ctest7 = 0x00;
1326505010dSis 	sc->sc_dcntl = 0x20;		/* XXX ?? */
1336505010dSis 
134937a7a3eSbouyer         /*
135937a7a3eSbouyer          * Fill in the scsipi_adapter.
136937a7a3eSbouyer          */
137937a7a3eSbouyer         memset(adapt, 0, sizeof(*adapt));
138cbab9cadSchs         adapt->adapt_dev = self;
139937a7a3eSbouyer         adapt->adapt_nchannels = 1;
140937a7a3eSbouyer         adapt->adapt_openings = 7;
141937a7a3eSbouyer         adapt->adapt_max_periph = 1;
142937a7a3eSbouyer         adapt->adapt_request = siopng_scsipi_request;
143937a7a3eSbouyer         adapt->adapt_minphys = siopng_minphys;
1446505010dSis 
145937a7a3eSbouyer         /*
146937a7a3eSbouyer          * Fill in the scsipi_channel.
147937a7a3eSbouyer          */
148937a7a3eSbouyer         memset(chan, 0, sizeof(*chan));
149937a7a3eSbouyer         chan->chan_adapter = adapt;
150937a7a3eSbouyer         chan->chan_bustype = &scsi_bustype;
151937a7a3eSbouyer         chan->chan_channel = 0;
152937a7a3eSbouyer         chan->chan_ntargets = 16;
153937a7a3eSbouyer         chan->chan_nluns = 8;
154937a7a3eSbouyer         chan->chan_id = 7;
1556505010dSis 
1566505010dSis 	siopnginitialize(sc);
1576505010dSis 
158937a7a3eSbouyer 	if (sc->sc_channel.chan_ntargets < 0)
159b7ee76f1Sis 		return;
160b7ee76f1Sis 
1616505010dSis 	sc->sc_isr.isr_intr = cbiiisc_dmaintr;
1626505010dSis 	sc->sc_isr.isr_arg = sc;
1636505010dSis 	sc->sc_isr.isr_ipl = 2;		/* ?? */
1646505010dSis 	add_isr(&sc->sc_isr);
1656505010dSis 
1666505010dSis 	/*
1676505010dSis 	 * attach all scsi units on us
1686505010dSis 	 */
169*c7fb772bSthorpej 	config_found(self, chan, scsiprint, CFARGS_NONE);
1706505010dSis }
1716505010dSis 
1726505010dSis int
cbiiisc_dmaintr(void * arg)1739382c873Saymeric cbiiisc_dmaintr(void *arg)
1746505010dSis {
1756505010dSis 	struct siop_softc *sc = arg;
1766505010dSis 	siop_regmap_p rp;
1776505010dSis 	int istat;
1786505010dSis 
1796505010dSis 	if (sc->sc_flags & SIOP_INTSOFF)
1806505010dSis 		return (0);	/* interrupts are not active */
1816505010dSis 	rp = sc->sc_siopp;
182ae95aa4aSphx 	amiga_membarrier();
1836505010dSis 	istat = rp->siop_istat;
1846505010dSis 	if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
1856505010dSis 		return(0);
1866505010dSis 	/*
1876505010dSis 	 * save interrupt status, DMA status, and SCSI status 0
1886505010dSis 	 * (may need to deal with stacked interrupts?)
1896505010dSis 	 */
1906505010dSis 	sc->sc_sist = rp->siop_sist;
1916505010dSis 	sc->sc_istat = istat;
1926505010dSis 	sc->sc_dstat = rp->siop_dstat;
193ae95aa4aSphx 	amiga_membarrier();
1946505010dSis 	siopngintr(sc);
1956505010dSis 	return(1);
1966505010dSis }
1976505010dSis 
1986505010dSis #ifdef DEBUG
1996505010dSis void
cbiiisc_dump(void)2009382c873Saymeric cbiiisc_dump(void)
2016505010dSis {
2026505010dSis 	extern struct cfdriver cbiiisc_cd;
203da026a97Scegger 	struct siop_softc *sc;
2046505010dSis 	int i;
2056505010dSis 
206da026a97Scegger 	for (i = 0; i < cbiiisc_cd.cd_ndevs; ++i) {
207da026a97Scegger 		sc = device_lookup_private(&cbiiisc_cd, i);
208da026a97Scegger 		if (sc != NULL)
209da026a97Scegger 			siopng_dump(sc);
210da026a97Scegger 	}
2116505010dSis }
2126505010dSis #endif
213