intio_dmac.c revision 1.1.2.3 1 1.1.2.3 minoura /* $NetBSD: intio_dmac.c,v 1.1.2.3 1999/02/10 16:02:26 minoura Exp $ */
2 1.1.2.1 minoura
3 1.1.2.1 minoura /*-
4 1.1.2.1 minoura * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 1.1.2.1 minoura * All rights reserved.
6 1.1.2.1 minoura *
7 1.1.2.1 minoura * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.1 minoura * by Minoura Makoto.
9 1.1.2.1 minoura *
10 1.1.2.1 minoura * Redistribution and use in source and binary forms, with or without
11 1.1.2.1 minoura * modification, are permitted provided that the following conditions
12 1.1.2.1 minoura * are met:
13 1.1.2.1 minoura * 1. Redistributions of source code must retain the above copyright
14 1.1.2.1 minoura * notice, this list of conditions and the following disclaimer.
15 1.1.2.1 minoura * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.1 minoura * notice, this list of conditions and the following disclaimer in the
17 1.1.2.1 minoura * documentation and/or other materials provided with the distribution.
18 1.1.2.1 minoura * 3. All advertising materials mentioning features or use of this software
19 1.1.2.1 minoura * must display the following acknowledgement:
20 1.1.2.1 minoura * This product includes software developed by the NetBSD
21 1.1.2.1 minoura * Foundation, Inc. and its contributors.
22 1.1.2.1 minoura * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.1 minoura * contributors may be used to endorse or promote products derived
24 1.1.2.1 minoura * from this software without specific prior written permission.
25 1.1.2.1 minoura *
26 1.1.2.1 minoura * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.1 minoura * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.1 minoura * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.1 minoura * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.1 minoura * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.1 minoura * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.1 minoura * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.1 minoura * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.1 minoura * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.1 minoura * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.1 minoura * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.1 minoura */
38 1.1.2.1 minoura
39 1.1.2.1 minoura /*
40 1.1.2.1 minoura * Hitachi HD63450 (= Motorola MC68450) DMAC driver for x68k.
41 1.1.2.1 minoura */
42 1.1.2.1 minoura
43 1.1.2.1 minoura #include <sys/param.h>
44 1.1.2.1 minoura #include <sys/systm.h>
45 1.1.2.1 minoura #include <sys/device.h>
46 1.1.2.1 minoura #include <sys/malloc.h>
47 1.1.2.1 minoura #include <sys/extent.h>
48 1.1.2.1 minoura #include <vm/vm.h>
49 1.1.2.1 minoura
50 1.1.2.1 minoura #include <machine/bus.h>
51 1.1.2.1 minoura #include <machine/cpu.h>
52 1.1.2.1 minoura #include <machine/frame.h>
53 1.1.2.1 minoura
54 1.1.2.1 minoura #include <arch/x68k/dev/intiovar.h>
55 1.1.2.1 minoura #include <arch/x68k/dev/dmacvar.h>
56 1.1.2.1 minoura
57 1.1.2.1 minoura #ifdef DMAC_DEBUG
58 1.1.2.1 minoura #define DPRINTF(n,x) if (dmacdebug>(n)&0x0f) printf x
59 1.1.2.1 minoura #define DDUMPREGS(n,x) if (dmacdebug>(n)&0x0f) {printf x; dmac_dump_regs();}
60 1.1.2.1 minoura int dmacdebug = 0;
61 1.1.2.1 minoura #else
62 1.1.2.1 minoura #define DPRINTF(n,x)
63 1.1.2.1 minoura #define DDUMPREGS(n,x)
64 1.1.2.1 minoura #endif
65 1.1.2.1 minoura
66 1.1.2.1 minoura static void dmac_init_channels __P((struct dmac_softc*));
67 1.1.2.1 minoura static int dmac_program_arraychain __P((struct device*, struct dmac_dma_xfer*));
68 1.1.2.1 minoura static int dmac_done __P((void*));
69 1.1.2.1 minoura static int dmac_error __P((void*));
70 1.1.2.1 minoura
71 1.1.2.1 minoura static int dmac_dump_regs __P((void));
72 1.1.2.1 minoura
73 1.1.2.1 minoura /*
74 1.1.2.1 minoura * autoconf stuff
75 1.1.2.1 minoura */
76 1.1.2.1 minoura static int dmac_match __P((struct device *, struct cfdata *, void *));
77 1.1.2.1 minoura static void dmac_attach __P((struct device *, struct device *, void *));
78 1.1.2.1 minoura
79 1.1.2.1 minoura struct cfattach dmac_ca = {
80 1.1.2.1 minoura sizeof(struct dmac_softc), dmac_match, dmac_attach
81 1.1.2.1 minoura };
82 1.1.2.1 minoura
83 1.1.2.1 minoura static int
84 1.1.2.1 minoura dmac_match(parent, cf, aux)
85 1.1.2.1 minoura struct device *parent;
86 1.1.2.1 minoura struct cfdata *cf;
87 1.1.2.1 minoura void *aux;
88 1.1.2.1 minoura {
89 1.1.2.1 minoura struct intio_attach_args *ia = aux;
90 1.1.2.1 minoura
91 1.1.2.1 minoura if (strcmp (ia->ia_name, "dmac") != 0)
92 1.1.2.1 minoura return (0);
93 1.1.2.1 minoura if (cf->cf_unit != 0)
94 1.1.2.1 minoura return (0);
95 1.1.2.1 minoura
96 1.1.2.1 minoura /* fixed address */
97 1.1.2.1 minoura if (ia->ia_addr != DMAC_ADDR)
98 1.1.2.1 minoura return (0);
99 1.1.2.1 minoura if (ia->ia_intr != -1)
100 1.1.2.1 minoura return (0);
101 1.1.2.1 minoura
102 1.1.2.1 minoura return 1;
103 1.1.2.1 minoura }
104 1.1.2.1 minoura
105 1.1.2.1 minoura static void
106 1.1.2.1 minoura dmac_attach(parent, self, aux)
107 1.1.2.1 minoura struct device *parent, *self;
108 1.1.2.1 minoura void *aux;
109 1.1.2.1 minoura {
110 1.1.2.1 minoura struct dmac_softc *sc = (struct dmac_softc *)self;
111 1.1.2.1 minoura struct intio_attach_args *ia = aux;
112 1.1.2.1 minoura int r;
113 1.1.2.1 minoura
114 1.1.2.1 minoura ia->ia_size = DMAC_CHAN_SIZE * DMAC_NCHAN;
115 1.1.2.1 minoura r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
116 1.1.2.1 minoura #ifdef DIAGNOSTIC
117 1.1.2.1 minoura if (r)
118 1.1.2.1 minoura panic ("IO map for DMAC corruption??");
119 1.1.2.1 minoura #endif
120 1.1.2.1 minoura
121 1.1.2.1 minoura ((struct intio_softc*) parent)->sc_dmac = self;
122 1.1.2.1 minoura sc->sc_bst = ia->ia_bst;
123 1.1.2.1 minoura bus_space_map (sc->sc_bst, ia->ia_addr, ia->ia_size, 0, &sc->sc_bht);
124 1.1.2.1 minoura dmac_init_channels(sc);
125 1.1.2.1 minoura
126 1.1.2.1 minoura printf (": HD63450 DMAC\n%s: 4 channels available.\n", self->dv_xname);
127 1.1.2.1 minoura }
128 1.1.2.1 minoura
129 1.1.2.1 minoura #define DMAC_MAPSIZE 64
130 1.1.2.1 minoura /* Allocate statically in order to make sure the DMAC can reach the maps. */
131 1.1.2.1 minoura static struct dmac_sg_array dmac_map[DMAC_NCHAN][DMAC_MAPSIZE];
132 1.1.2.1 minoura
133 1.1.2.1 minoura static void
134 1.1.2.1 minoura dmac_init_channels(sc)
135 1.1.2.1 minoura struct dmac_softc *sc;
136 1.1.2.1 minoura {
137 1.1.2.1 minoura int i;
138 1.1.2.1 minoura pmap_t pmap = pmap_kernel();
139 1.1.2.1 minoura
140 1.1.2.1 minoura for (i=0; i<DMAC_NCHAN; i++) {
141 1.1.2.1 minoura sc->sc_channels[i].ch_channel = i;
142 1.1.2.1 minoura sc->sc_channels[i].ch_name[0] = 0;
143 1.1.2.1 minoura sc->sc_channels[i].ch_softc = &sc->sc_dev;
144 1.1.2.1 minoura sc->sc_channels[i].ch_map =
145 1.1.2.1 minoura (void*) pmap_extract (pmap, (vaddr_t) &dmac_map[i]);
146 1.1.2.1 minoura bus_space_subregion(sc->sc_bst, sc->sc_bht,
147 1.1.2.1 minoura DMAC_CHAN_SIZE*i, DMAC_CHAN_SIZE,
148 1.1.2.1 minoura &sc->sc_channels[i].ch_bht);
149 1.1.2.1 minoura }
150 1.1.2.1 minoura
151 1.1.2.1 minoura return;
152 1.1.2.1 minoura }
153 1.1.2.1 minoura
154 1.1.2.1 minoura
155 1.1.2.1 minoura /*
156 1.1.2.1 minoura * Channel initialization/deinitialization per user device.
157 1.1.2.1 minoura */
158 1.1.2.1 minoura struct dmac_channel_stat *
159 1.1.2.2 minoura dmac_alloc_channel(self, ch, name,
160 1.1.2.2 minoura normalv, normal, normalarg,
161 1.1.2.2 minoura errorv, error, errorarg)
162 1.1.2.1 minoura struct device *self;
163 1.1.2.1 minoura int ch;
164 1.1.2.1 minoura char *name;
165 1.1.2.1 minoura int normalv, errorv;
166 1.1.2.1 minoura dmac_intr_handler_t normal, error;
167 1.1.2.2 minoura void *normalarg, *errorarg;
168 1.1.2.1 minoura {
169 1.1.2.1 minoura struct intio_softc *intio = (void*) self;
170 1.1.2.1 minoura struct dmac_softc *sc = (void*) intio->sc_dmac;
171 1.1.2.1 minoura struct dmac_channel_stat *chan = &sc->sc_channels[ch];
172 1.1.2.1 minoura char intrname[16];
173 1.1.2.1 minoura
174 1.1.2.1 minoura #ifdef DIAGNOSTIC
175 1.1.2.1 minoura if (ch < 0 || ch >= DMAC_NCHAN)
176 1.1.2.1 minoura panic ("Invalid DMAC channel.");
177 1.1.2.1 minoura if (chan->ch_name[0])
178 1.1.2.1 minoura panic ("DMAC: channel in use.");
179 1.1.2.1 minoura if (strlen(name) > 8)
180 1.1.2.1 minoura panic ("DMAC: wrong user name.");
181 1.1.2.1 minoura #endif
182 1.1.2.1 minoura
183 1.1.2.1 minoura /* fill the channel status structure. */
184 1.1.2.1 minoura strcpy(chan->ch_name, name);
185 1.1.2.1 minoura chan->ch_dcr = (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC |
186 1.1.2.1 minoura DMAC_DCR_OPS_8BIT);
187 1.1.2.3 minoura chan->ch_ocr = (DMAC_OCR_SIZE_BYTE_NOPACK | DMAC_OCR_CHAIN_ARRAY |
188 1.1.2.1 minoura DMAC_OCR_REQG_EXTERNAL);
189 1.1.2.1 minoura chan->ch_normalv = normalv;
190 1.1.2.1 minoura chan->ch_errorv = errorv;
191 1.1.2.1 minoura chan->ch_normal = normal;
192 1.1.2.1 minoura chan->ch_error = error;
193 1.1.2.2 minoura chan->ch_normalarg = normalarg;
194 1.1.2.2 minoura chan->ch_errorarg = errorarg;
195 1.1.2.1 minoura chan->ch_xfer_in_progress = 0;
196 1.1.2.1 minoura
197 1.1.2.1 minoura /* setup the device-specific registers */
198 1.1.2.1 minoura bus_space_write_1 (sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
199 1.1.2.1 minoura bus_space_write_1 (sc->sc_bst, chan->ch_bht,
200 1.1.2.1 minoura DMAC_REG_DCR, chan->ch_dcr);
201 1.1.2.1 minoura bus_space_write_1 (sc->sc_bst, chan->ch_bht, DMAC_REG_CPR, 0);
202 1.1.2.1 minoura
203 1.1.2.1 minoura /*
204 1.1.2.1 minoura * X68k physical user space is a subset of the kernel space;
205 1.1.2.1 minoura * the memory is always included in the physical user space,
206 1.1.2.1 minoura * while the device is not.
207 1.1.2.1 minoura */
208 1.1.2.1 minoura bus_space_write_1 (sc->sc_bst, chan->ch_bht,
209 1.1.2.1 minoura DMAC_REG_BFCR, DMAC_FC_USER_DATA);
210 1.1.2.1 minoura bus_space_write_1 (sc->sc_bst, chan->ch_bht,
211 1.1.2.1 minoura DMAC_REG_MFCR, DMAC_FC_USER_DATA);
212 1.1.2.1 minoura bus_space_write_1 (sc->sc_bst, chan->ch_bht,
213 1.1.2.1 minoura DMAC_REG_DFCR, DMAC_FC_KERNEL_DATA);
214 1.1.2.1 minoura
215 1.1.2.1 minoura /* setup the interrupt handlers */
216 1.1.2.1 minoura bus_space_write_1 (sc->sc_bst, chan->ch_bht, DMAC_REG_NIVR, normalv);
217 1.1.2.1 minoura bus_space_write_1 (sc->sc_bst, chan->ch_bht, DMAC_REG_EIVR, errorv);
218 1.1.2.1 minoura
219 1.1.2.1 minoura strcpy(intrname, name);
220 1.1.2.1 minoura strcat(intrname, "dma");
221 1.1.2.1 minoura intio_intr_establish (normalv, intrname, dmac_done, chan);
222 1.1.2.1 minoura
223 1.1.2.1 minoura strcpy(intrname, name);
224 1.1.2.1 minoura strcat(intrname, "dmaerr");
225 1.1.2.1 minoura intio_intr_establish (errorv, intrname, dmac_error, chan);
226 1.1.2.1 minoura
227 1.1.2.1 minoura return chan;
228 1.1.2.1 minoura }
229 1.1.2.1 minoura
230 1.1.2.1 minoura int
231 1.1.2.1 minoura dmac_free_channel(self, ch, channel)
232 1.1.2.1 minoura struct device *self;
233 1.1.2.1 minoura int ch;
234 1.1.2.1 minoura void *channel;
235 1.1.2.1 minoura {
236 1.1.2.1 minoura struct dmac_softc *sc = (void*) self;
237 1.1.2.1 minoura struct dmac_channel_stat *chan = &sc->sc_channels[ch];
238 1.1.2.1 minoura
239 1.1.2.1 minoura if (chan != channel)
240 1.1.2.1 minoura return -1;
241 1.1.2.1 minoura if (ch != chan->ch_channel)
242 1.1.2.1 minoura return -1;
243 1.1.2.1 minoura #if DIAGNOSTIC
244 1.1.2.1 minoura if (chan->ch_xfer_in_progress)
245 1.1.2.1 minoura panic ("dmac_free_channel: DMA transfer in progress");
246 1.1.2.1 minoura #endif
247 1.1.2.1 minoura
248 1.1.2.1 minoura chan->ch_name[0] = 0;
249 1.1.2.1 minoura intio_intr_disestablish(chan->ch_normalv, channel);
250 1.1.2.1 minoura intio_intr_disestablish(chan->ch_errorv, channel);
251 1.1.2.1 minoura
252 1.1.2.1 minoura return 0;
253 1.1.2.1 minoura }
254 1.1.2.1 minoura
255 1.1.2.1 minoura /*
256 1.1.2.1 minoura * Initialization / deinitialization per transfer.
257 1.1.2.1 minoura */
258 1.1.2.1 minoura struct dmac_dma_xfer *
259 1.1.2.1 minoura dmac_prepare_xfer (chan, dmat, dmamap, dir, scr, dar)
260 1.1.2.1 minoura struct dmac_channel_stat *chan;
261 1.1.2.1 minoura bus_dma_tag_t dmat;
262 1.1.2.1 minoura bus_dmamap_t dmamap;
263 1.1.2.1 minoura int dir, scr;
264 1.1.2.1 minoura void *dar;
265 1.1.2.1 minoura {
266 1.1.2.1 minoura struct dmac_dma_xfer *r = malloc (sizeof (struct dmac_dma_xfer),
267 1.1.2.1 minoura M_DEVBUF, M_WAITOK);
268 1.1.2.1 minoura
269 1.1.2.1 minoura r->dx_channel = chan;
270 1.1.2.1 minoura r->dx_dmamap = dmamap;
271 1.1.2.1 minoura r->dx_tag = dmat;
272 1.1.2.1 minoura r->dx_ocr = dir & DMAC_OCR_DIR_MASK;
273 1.1.2.1 minoura r->dx_scr = scr & (DMAC_SCR_MAC_MASK|DMAC_SCR_DAC_MASK);
274 1.1.2.2 minoura r->dx_device = dar;
275 1.1.2.1 minoura r->dx_done = 0;
276 1.1.2.1 minoura
277 1.1.2.1 minoura return r;
278 1.1.2.1 minoura }
279 1.1.2.1 minoura
280 1.1.2.1 minoura #ifdef DMAC_DEBUG
281 1.1.2.1 minoura static struct dmac_channel_stat *debugchan = 0;
282 1.1.2.1 minoura #endif
283 1.1.2.1 minoura
284 1.1.2.3 minoura #ifdef DMAC_DEBUG
285 1.1.2.3 minoura static u_int8_t dcsr, dcer, ddcr, docr, dscr, dccr, dcpr, dgcr,
286 1.1.2.3 minoura dnivr, deivr, ddfcr, dmfcr, dbfcr;
287 1.1.2.3 minoura static u_int16_t dmtcr, dbtcr;
288 1.1.2.3 minoura static u_int32_t ddar, dmar, dbar;
289 1.1.2.3 minoura #endif
290 1.1.2.1 minoura /*
291 1.1.2.1 minoura * Do the actual transfer.
292 1.1.2.1 minoura */
293 1.1.2.1 minoura int
294 1.1.2.1 minoura dmac_start_xfer(self, xf)
295 1.1.2.1 minoura struct device *self;
296 1.1.2.1 minoura struct dmac_dma_xfer *xf;
297 1.1.2.1 minoura {
298 1.1.2.1 minoura struct dmac_softc *sc = (void*) self;
299 1.1.2.1 minoura struct dmac_channel_stat *chan = xf->dx_channel;
300 1.1.2.1 minoura int c;
301 1.1.2.1 minoura
302 1.1.2.1 minoura
303 1.1.2.1 minoura #ifdef DMAC_DEBUG
304 1.1.2.1 minoura debugchan=chan;
305 1.1.2.1 minoura #endif
306 1.1.2.1 minoura bus_space_write_1(sc->sc_bst, chan->ch_bht,
307 1.1.2.1 minoura DMAC_REG_OCR, (xf->dx_ocr | chan->ch_ocr));
308 1.1.2.1 minoura bus_space_write_1(sc->sc_bst, chan->ch_bht,
309 1.1.2.1 minoura DMAC_REG_SCR, xf->dx_scr);
310 1.1.2.1 minoura
311 1.1.2.1 minoura /* program DMAC in array chainning mode */
312 1.1.2.1 minoura xf->dx_done = 0;
313 1.1.2.1 minoura DPRINTF (3, ("First program:\n"));
314 1.1.2.1 minoura c = dmac_program_arraychain(self, xf);
315 1.1.2.1 minoura
316 1.1.2.1 minoura /* setup the address/count registers */
317 1.1.2.1 minoura bus_space_write_4(sc->sc_bst, chan->ch_bht,
318 1.1.2.1 minoura DMAC_REG_BAR, (int) chan->ch_map);
319 1.1.2.1 minoura bus_space_write_4(sc->sc_bst, chan->ch_bht,
320 1.1.2.1 minoura DMAC_REG_DAR, (int) xf->dx_device);
321 1.1.2.1 minoura bus_space_write_1(sc->sc_bst, chan->ch_bht,
322 1.1.2.1 minoura DMAC_REG_CSR, 0xff);
323 1.1.2.1 minoura bus_space_write_2(sc->sc_bst, chan->ch_bht,
324 1.1.2.1 minoura DMAC_REG_BTCR, c);
325 1.1.2.1 minoura
326 1.1.2.1 minoura /* START!! */
327 1.1.2.3 minoura DDUMPREGS (3, ("first start\n"));
328 1.1.2.3 minoura #ifdef DMAC_DEBUG
329 1.1.2.3 minoura dcsr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR);
330 1.1.2.3 minoura dcer = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CER);
331 1.1.2.3 minoura ddcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_DCR);
332 1.1.2.3 minoura docr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_OCR);
333 1.1.2.3 minoura dscr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_SCR);
334 1.1.2.3 minoura dccr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CCR);
335 1.1.2.3 minoura dcpr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CPR);
336 1.1.2.3 minoura dgcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_GCR);
337 1.1.2.3 minoura dnivr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_NIVR);
338 1.1.2.3 minoura deivr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_EIVR);
339 1.1.2.3 minoura ddfcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_DFCR);
340 1.1.2.3 minoura dmfcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_MFCR);
341 1.1.2.3 minoura dbfcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_BFCR);
342 1.1.2.3 minoura dmtcr = bus_space_read_2(sc->sc_bst, chan->ch_bht, DMAC_REG_MTCR);
343 1.1.2.3 minoura dbtcr = bus_space_read_2(sc->sc_bst, chan->ch_bht, DMAC_REG_BTCR);
344 1.1.2.3 minoura ddar = bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_DAR);
345 1.1.2.3 minoura dmar = bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_MAR);
346 1.1.2.3 minoura dbar = bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_BAR);
347 1.1.2.3 minoura #endif
348 1.1.2.1 minoura #if defined(M68040) || defined(M68060)
349 1.1.2.1 minoura if (mmutype == MMU_68040)
350 1.1.2.3 minoura dma_cachectl((caddr_t) &dmac_map[chan->ch_channel],
351 1.1.2.3 minoura sizeof(struct dmac_sg_array)*DMAC_MAPSIZE);
352 1.1.2.1 minoura #endif
353 1.1.2.1 minoura bus_space_write_1(sc->sc_bst, chan->ch_bht,
354 1.1.2.1 minoura DMAC_REG_CCR, DMAC_CCR_STR|DMAC_CCR_INT);
355 1.1.2.1 minoura chan->ch_xfer_in_progress = xf;
356 1.1.2.1 minoura
357 1.1.2.1 minoura return 0;
358 1.1.2.1 minoura }
359 1.1.2.1 minoura
360 1.1.2.1 minoura static int
361 1.1.2.1 minoura dmac_program_arraychain(self, xf)
362 1.1.2.1 minoura struct device *self;
363 1.1.2.1 minoura struct dmac_dma_xfer *xf;
364 1.1.2.1 minoura {
365 1.1.2.1 minoura struct dmac_softc *sc = (void*) self;
366 1.1.2.1 minoura struct dmac_channel_stat *chan = xf->dx_channel;
367 1.1.2.1 minoura int ch = chan->ch_channel;
368 1.1.2.1 minoura struct x68k_bus_dmamap *map = xf->dx_dmamap;
369 1.1.2.1 minoura int i, j;
370 1.1.2.1 minoura
371 1.1.2.1 minoura for (i=0, j=xf->dx_done; i<DMAC_MAPSIZE && j<map->dm_nsegs;
372 1.1.2.1 minoura i++, j++) {
373 1.1.2.3 minoura dmac_map[ch][i].da_addr = map->dm_segs[j].ds_addr;
374 1.1.2.2 minoura #ifdef DIAGNOSTIC
375 1.1.2.1 minoura if (map->dm_segs[j].ds_len > 0xff00)
376 1.1.2.2 minoura panic ("dmac_program_arraychain: wrong map: %d", map->dm_segs[j].ds_len);
377 1.1.2.2 minoura #endif
378 1.1.2.1 minoura dmac_map[ch][i].da_count = map->dm_segs[j].ds_len;
379 1.1.2.1 minoura }
380 1.1.2.1 minoura xf->dx_done = j;
381 1.1.2.1 minoura
382 1.1.2.1 minoura return i;
383 1.1.2.1 minoura }
384 1.1.2.1 minoura
385 1.1.2.1 minoura /*
386 1.1.2.1 minoura * interrupt handlers.
387 1.1.2.1 minoura */
388 1.1.2.1 minoura static int
389 1.1.2.1 minoura dmac_done(arg)
390 1.1.2.1 minoura void *arg;
391 1.1.2.1 minoura {
392 1.1.2.1 minoura struct dmac_channel_stat *chan = arg;
393 1.1.2.1 minoura struct dmac_softc *sc = (void*) chan->ch_softc;
394 1.1.2.1 minoura struct dmac_dma_xfer *xf = chan->ch_xfer_in_progress;
395 1.1.2.1 minoura struct x68k_bus_dmamap *map = xf->dx_dmamap;
396 1.1.2.1 minoura int c;
397 1.1.2.1 minoura
398 1.1.2.1 minoura DPRINTF (3, ("dmac_done\n"));
399 1.1.2.1 minoura bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
400 1.1.2.1 minoura
401 1.1.2.1 minoura if (xf->dx_done == map->dm_nsegs) {
402 1.1.2.1 minoura /* Done */
403 1.1.2.1 minoura chan->ch_xfer_in_progress = 0;
404 1.1.2.2 minoura return (*chan->ch_normal) (chan->ch_normalarg);
405 1.1.2.1 minoura }
406 1.1.2.1 minoura
407 1.1.2.1 minoura /* Continue transfer */
408 1.1.2.1 minoura DPRINTF (3, ("reprograming\n"));
409 1.1.2.1 minoura c = dmac_program_arraychain (&sc->sc_dev, xf);
410 1.1.2.1 minoura
411 1.1.2.1 minoura bus_space_write_4(sc->sc_bst, chan->ch_bht,
412 1.1.2.1 minoura DMAC_REG_BAR, (int) chan->ch_map);
413 1.1.2.1 minoura bus_space_write_4(sc->sc_bst, chan->ch_bht,
414 1.1.2.1 minoura DMAC_REG_DAR, (int) xf->dx_device);
415 1.1.2.1 minoura bus_space_write_1(sc->sc_bst, chan->ch_bht,
416 1.1.2.1 minoura DMAC_REG_CSR, 0xff);
417 1.1.2.1 minoura bus_space_write_2(sc->sc_bst, chan->ch_bht,
418 1.1.2.1 minoura DMAC_REG_BTCR, c);
419 1.1.2.1 minoura
420 1.1.2.1 minoura /* START!! */
421 1.1.2.1 minoura DDUMPREGS (3, ("restart\n"));
422 1.1.2.1 minoura bus_space_write_1(sc->sc_bst, chan->ch_bht,
423 1.1.2.1 minoura DMAC_REG_CCR, DMAC_CCR_STR|DMAC_CCR_INT);
424 1.1.2.1 minoura
425 1.1.2.1 minoura return 1;
426 1.1.2.1 minoura }
427 1.1.2.1 minoura
428 1.1.2.1 minoura static int
429 1.1.2.1 minoura dmac_error(arg)
430 1.1.2.1 minoura void *arg;
431 1.1.2.1 minoura {
432 1.1.2.1 minoura struct dmac_channel_stat *chan = arg;
433 1.1.2.1 minoura struct dmac_softc *sc = (void*) chan->ch_softc;
434 1.1.2.1 minoura
435 1.1.2.2 minoura printf ("DMAC transfer error CSR=%02x, CER=%02x\n",
436 1.1.2.2 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR),
437 1.1.2.2 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CER));
438 1.1.2.3 minoura DPRINTF(5, ("registers were:\n"));
439 1.1.2.3 minoura #ifdef DMAC_DEBUG
440 1.1.2.3 minoura if ((dmacdebug & 0x0f) > 5) {
441 1.1.2.3 minoura printf ("CSR=%02x, CER=%02x, DCR=%02x, OCR=%02x, SCR=%02x,"
442 1.1.2.3 minoura "CCR=%02x, CPR=%02x, GCR=%02x\n",
443 1.1.2.3 minoura dcsr, dcer, ddcr, docr, dscr, dccr, dcpr, dgcr);
444 1.1.2.3 minoura printf ("NIVR=%02x, EIVR=%02x, MTCR=%04x, BTCR=%04x, "
445 1.1.2.3 minoura "DFCR=%02x, MFCR=%02x, BFCR=%02x\n",
446 1.1.2.3 minoura dnivr, deivr, dmtcr, dbtcr, ddfcr, dmfcr, dbfcr);
447 1.1.2.3 minoura printf ("DAR=%08x, MAR=%08x, BAR=%08x\n",
448 1.1.2.3 minoura ddar, dmar, dbar);
449 1.1.2.3 minoura }
450 1.1.2.3 minoura #endif
451 1.1.2.3 minoura
452 1.1.2.1 minoura bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
453 1.1.2.1 minoura DDUMPREGS(3, ("dmac_error\n"));
454 1.1.2.1 minoura
455 1.1.2.2 minoura return (*chan->ch_error) (chan->ch_errorarg);
456 1.1.2.1 minoura }
457 1.1.2.1 minoura
458 1.1.2.1 minoura
459 1.1.2.1 minoura #ifdef DMAC_DEBUG
460 1.1.2.1 minoura static int
461 1.1.2.1 minoura dmac_dump_regs(void)
462 1.1.2.1 minoura {
463 1.1.2.1 minoura struct dmac_channel_stat *chan = debugchan;
464 1.1.2.1 minoura struct dmac_softc *sc;
465 1.1.2.1 minoura
466 1.1.2.1 minoura if ((chan == 0) || (dmacdebug & 0xf0)) return;
467 1.1.2.1 minoura sc = (void*) chan->ch_softc;
468 1.1.2.1 minoura
469 1.1.2.2 minoura printf ("DMAC channel %d registers\n", chan->ch_channel);
470 1.1.2.1 minoura printf ("CSR=%02x, CER=%02x, DCR=%02x, OCR=%02x, SCR=%02x,"
471 1.1.2.1 minoura "CCR=%02x, CPR=%02x, GCR=%02x\n",
472 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR),
473 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CER),
474 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_DCR),
475 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_OCR),
476 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_SCR),
477 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CCR),
478 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CPR),
479 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_GCR));
480 1.1.2.1 minoura printf ("NIVR=%02x, EIVR=%02x, MTCR=%04x, BTCR=%04x, DFCR=%02x,"
481 1.1.2.1 minoura "MFCR=%02x, BFCR=%02x\n",
482 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_NIVR),
483 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_EIVR),
484 1.1.2.1 minoura bus_space_read_2(sc->sc_bst, chan->ch_bht, DMAC_REG_MTCR),
485 1.1.2.1 minoura bus_space_read_2(sc->sc_bst, chan->ch_bht, DMAC_REG_BTCR),
486 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_DFCR),
487 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_MFCR),
488 1.1.2.1 minoura bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_BFCR));
489 1.1.2.1 minoura printf ("DAR=%08x, MAR=%08x, BAR=%08x\n",
490 1.1.2.1 minoura bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_DAR),
491 1.1.2.1 minoura bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_MAR),
492 1.1.2.1 minoura bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_BAR));
493 1.1.2.1 minoura
494 1.1.2.1 minoura return 0;
495 1.1.2.1 minoura }
496 1.1.2.1 minoura #endif
497