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