bppcsc.c revision 1.2 1 1.2 rkujawa /* $NetBSD: bppcsc.c,v 1.2 2012/01/10 20:29:50 rkujawa 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.2 rkujawa __KERNEL_RCSID(0, "$NetBSD: bppcsc.c,v 1.2 2012/01/10 20:29:50 rkujawa 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.1 phx void bppcscattach(struct device *, struct device *, void *);
88 1.1 phx int bppcscmatch(struct device *, struct cfdata *, 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.1 phx CFATTACH_DECL(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.1 phx bppcscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
102 1.1 phx {
103 1.2 rkujawa struct p5bus_attach_args *p5baa;
104 1.2 rkujawa
105 1.2 rkujawa p5baa = (struct p5bus_attach_args *) auxp;
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.1 phx bppcscattach(struct device *pdp, struct device *dp, void *auxp)
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.1 phx sc = (struct siop_softc *)dp;
122 1.1 phx adapt = &sc->sc_adapter;
123 1.1 phx chan = &sc->sc_channel;
124 1.1 phx
125 1.1 phx aprint_naive(": SCSI controller\n");
126 1.1 phx aprint_normal(": BlizzardPPC 603e+ SCSI adapter\n");
127 1.1 phx
128 1.1 phx sc->sc_siopp = rp = ztwomap(BPPC_SCSI_OFF);
129 1.1 phx #ifdef DEBUG
130 1.1 phx siop_dump(sc);
131 1.1 phx #endif
132 1.1 phx /*
133 1.1 phx * CTEST7 = 00
134 1.1 phx */
135 1.1 phx sc->sc_clock_freq = 50; /* Clock = 50 MHz */
136 1.1 phx sc->sc_ctest7 = 0x00;
137 1.1 phx sc->sc_dcntl = 0x20; /* XXX - taken from cbiiisc */
138 1.1 phx
139 1.1 phx /*
140 1.1 phx * Fill in the scsipi_adapter.
141 1.1 phx */
142 1.1 phx memset(adapt, 0, sizeof(*adapt));
143 1.1 phx adapt->adapt_dev = &sc->sc_dev;
144 1.1 phx adapt->adapt_nchannels = 1;
145 1.1 phx adapt->adapt_openings = 7;
146 1.1 phx adapt->adapt_max_periph = 1;
147 1.1 phx adapt->adapt_request = siop_scsipi_request;
148 1.1 phx adapt->adapt_minphys = siop_minphys;
149 1.1 phx
150 1.1 phx /*
151 1.1 phx * Fill in the scsipi_channel.
152 1.1 phx */
153 1.1 phx memset(chan, 0, sizeof(*chan));
154 1.1 phx chan->chan_adapter = adapt;
155 1.1 phx chan->chan_bustype = &scsi_bustype;
156 1.1 phx chan->chan_channel = 0;
157 1.1 phx chan->chan_ntargets = 8;
158 1.1 phx chan->chan_nluns = 8;
159 1.1 phx chan->chan_id = 7;
160 1.1 phx
161 1.1 phx siopinitialize(sc);
162 1.1 phx
163 1.1 phx sc->sc_isr.isr_intr = bppcsc_dmaintr;
164 1.1 phx sc->sc_isr.isr_arg = sc;
165 1.1 phx sc->sc_isr.isr_ipl = 2;
166 1.1 phx add_isr (&sc->sc_isr);
167 1.1 phx
168 1.1 phx /*
169 1.1 phx * attach all scsi units on us
170 1.1 phx */
171 1.1 phx config_found(dp, chan, scsiprint);
172 1.1 phx }
173 1.1 phx
174 1.1 phx int
175 1.1 phx bppcsc_dmaintr(void *arg)
176 1.1 phx {
177 1.1 phx struct siop_softc *sc;
178 1.1 phx siop_regmap_p rp;
179 1.1 phx u_char istat;
180 1.1 phx
181 1.1 phx sc = arg;
182 1.1 phx if (sc->sc_flags & SIOP_INTSOFF)
183 1.1 phx return 0; /* interrupts are not active */
184 1.1 phx rp = sc->sc_siopp;
185 1.1 phx amiga_membarrier();
186 1.1 phx istat = rp->siop_istat;
187 1.1 phx if ((istat & (SIOP_ISTAT_SIP | SIOP_ISTAT_DIP)) == 0)
188 1.1 phx return 0;
189 1.1 phx /*
190 1.1 phx * save interrupt status, DMA status, and SCSI status 0
191 1.1 phx * (may need to deal with stacked interrupts?)
192 1.1 phx */
193 1.1 phx sc->sc_sstat0 = rp->siop_sstat0;
194 1.1 phx sc->sc_istat = istat;
195 1.1 phx sc->sc_dstat = rp->siop_dstat;
196 1.1 phx amiga_membarrier();
197 1.1 phx siopintr(sc);
198 1.1 phx return 1;
199 1.1 phx }
200 1.1 phx
201 1.1 phx #ifdef DEBUG
202 1.1 phx void
203 1.1 phx bppcsc_dump(void)
204 1.1 phx {
205 1.1 phx extern struct cfdriver bppcsc_cd;
206 1.1 phx struct siop_softc *sc;
207 1.1 phx int i;
208 1.1 phx
209 1.1 phx for (i = 0; i < bppcsc_cd.cd_ndevs; ++i) {
210 1.1 phx sc = device_lookup_private(&bppcsc_cd, i);
211 1.1 phx if (sc != NULL)
212 1.1 phx siop_dump(sc);
213 1.1 phx }
214 1.1 phx }
215 1.1 phx #endif
216