1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
/* $OpenBSD: pxa2x0_dmac.c,v 1.3 2006/04/04 11:37:05 pascoe Exp $ */
/*
* Copyright (c) 2005 Christopher Pascoe <pascoe@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* DMA Controller Handler for the Intel PXA2X0 processor.
*/
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/evcount.h>
#include <uvm/uvm_extern.h>
#include <machine/bus.h>
#include <machine/intr.h>
#include <machine/lock.h>
#include <arm/xscale/pxa2x0reg.h>
#include <arm/xscale/pxa2x0var.h>
#include <arm/xscale/pxa2x0_dmac.h>
typedef void (*pxadmac_intrhandler)(void *);
struct pxadmac_softc {
struct device sc_dev;
bus_space_tag_t sc_bust;
bus_space_handle_t sc_bush;
void *sc_ih;
int sc_nchan;
int sc_npri;
pxadmac_intrhandler sc_intrhandlers[DMAC_N_CHANNELS_PXA27X];
void *sc_intrargs[DMAC_N_CHANNELS_PXA27X];
};
int pxadmac_intr(void *);
/*
* DMAC autoconf glue
*/
int pxadmac_match(struct device *, void *, void *);
void pxadmac_attach(struct device *, struct device *, void *);
struct cfattach pxadmac_ca = {
sizeof(struct pxadmac_softc), pxadmac_match, pxadmac_attach
};
struct cfdriver pxadmac_cd = {
NULL, "pxadmac", DV_DULL
};
static struct pxadmac_softc *pxadmac_softc = NULL;
int
pxadmac_match(struct device *parent, void *cf, void *aux)
{
struct pxaip_attach_args *pxa = aux;
if (pxadmac_softc != NULL || pxa->pxa_addr != PXA2X0_DMAC_BASE)
return (0);
return (1);
}
void
pxadmac_attach(struct device *parent, struct device *self, void *args)
{
struct pxadmac_softc *sc = (struct pxadmac_softc *)self;
struct pxaip_attach_args *pxa = args;
bus_size_t bus_size;
sc->sc_bust = pxa->pxa_iot;
printf(": DMA Controller\n");
if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) == CPU_ID_PXA27X) {
sc->sc_nchan = DMAC_N_CHANNELS_PXA27X;
sc->sc_npri = DMAC_N_PRIORITIES_PXA27X;
bus_size = PXA27X_DMAC_SIZE;
} else {
sc->sc_nchan = DMAC_N_CHANNELS;
sc->sc_npri = DMAC_N_PRIORITIES;
bus_size = PXA2X0_DMAC_SIZE;
}
if (bus_space_map(sc->sc_bust, pxa->pxa_addr, bus_size, 0,
&sc->sc_bush)) {
printf("%s: Can't map registers!\n", sc->sc_dev.dv_xname);
return;
}
sc->sc_ih = pxa2x0_intr_establish(pxa->pxa_intr, IPL_BIO,
pxadmac_intr, sc, "pxadmac");
if (sc->sc_ih == NULL) {
printf(": unable to establish interrupt\n");
bus_space_unmap(sc->sc_bust, sc->sc_bush, bus_size);
return;
}
pxadmac_softc = sc;
}
/* Perform non-descriptor based DMA to a FIFO */
int
pxa2x0_dma_to_fifo(int periph, int chan, bus_addr_t fifo_addr, int width,
int burstsize, bus_addr_t src_addr, int length, void (*intr)(void *),
void *intrarg)
{
struct pxadmac_softc *sc = pxadmac_softc;
uint32_t cmd;
if (periph < 0 || periph > 63 || periph == 23) {
printf("pxa2x0_dma_to_fifo: bogus peripheral %d", periph);
return EINVAL;
}
if (chan < 0 || chan >= sc->sc_nchan) {
printf("pxa2x0_dma_to_fifo: bogus dma channel %d", chan);
return EINVAL;
}
if (length < 0 || length > DCMD_LENGTH_MASK) {
printf("pxa2x0_dma_to_fifo: bogus length %d", length);
return EINVAL;
}
cmd = (length & DCMD_LENGTH_MASK) | DCMD_INCSRCADDR | DCMD_FLOWTRG
| DCMD_ENDIRQEN;
switch (width) {
case 1:
cmd |= DCMD_WIDTH_1;
break;
case 4:
cmd |= DCMD_WIDTH_4;
break;
default:
printf("pxa2x0_dma_to_fifo: bogus width %d", width);
return EINVAL;
}
switch (burstsize) {
case 8:
cmd |= DCMD_SIZE_8;
break;
case 16:
cmd |= DCMD_SIZE_16;
break;
case 32:
cmd |= DCMD_SIZE_32;
break;
default:
printf("pxa2x0_dma_to_fifo: bogus burstsize %d", burstsize);
return EINVAL;
}
/* XXX: abort anything already in progress, hopefully nothing. */
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DCSR(chan),
DCSR_NODESCFETCH);
/* Save handler for interrupt-on-completion. */
sc->sc_intrhandlers[chan] = intr;
sc->sc_intrargs[chan] = intrarg;
/* Map peripheral to channel for flow control setup. */
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DRCMR(periph),
chan | DRCMR_MAPVLD);
/* Setup transfer addresses. */
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DDADR(chan),
DDADR_STOP);
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DSADR(chan),
src_addr);
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DTADR(chan),
fifo_addr);
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DCMD(chan),
cmd);
/* Start the transfer. */
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DCSR(chan),
DCSR_RUN | DCSR_NODESCFETCH);
return 0;
}
/* Perform non-descriptor based DMA from a FIFO */
int
pxa2x0_dma_from_fifo(int periph, int chan, bus_addr_t fifo_addr, int width,
int burstsize, bus_addr_t trg_addr, int length, void (*intr)(void *),
void *intrarg)
{
struct pxadmac_softc *sc = pxadmac_softc;
uint32_t cmd;
if (periph < 0 || periph > 63 || periph == 23) {
printf("pxa2x0_dma_from_fifo: bogus peripheral %d", periph);
return EINVAL;
}
if (chan < 0 || chan >= sc->sc_nchan) {
printf("pxa2x0_dma_from_fifo: bogus dma channel %d", chan);
return EINVAL;
}
if (length < 0 || length > DCMD_LENGTH_MASK) {
printf("pxa2x0_dma_from_fifo: bogus length %d", length);
return EINVAL;
}
cmd = (length & DCMD_LENGTH_MASK) | DCMD_INCTRGADDR | DCMD_FLOWSRC
| DCMD_ENDIRQEN;
switch (width) {
case 1:
cmd |= DCMD_WIDTH_1;
break;
case 4:
cmd |= DCMD_WIDTH_4;
break;
default:
printf("pxa2x0_dma_from_fifo: bogus width %d", width);
return EINVAL;
}
switch (burstsize) {
case 8:
cmd |= DCMD_SIZE_8;
break;
case 16:
cmd |= DCMD_SIZE_16;
break;
case 32:
cmd |= DCMD_SIZE_32;
break;
default:
printf("pxa2x0_dma_from_fifo: bogus burstsize %d", burstsize);
return EINVAL;
}
/* XXX: abort anything already in progress, hopefully nothing. */
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DCSR(chan),
DCSR_NODESCFETCH);
/* Save handler for interrupt-on-completion. */
sc->sc_intrhandlers[chan] = intr;
sc->sc_intrargs[chan] = intrarg;
/* Map peripheral to channel for flow control setup. */
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DRCMR(periph),
chan | DRCMR_MAPVLD);
/* Setup transfer addresses. */
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DDADR(chan),
DDADR_STOP);
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DSADR(chan),
fifo_addr);
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DTADR(chan),
trg_addr);
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DCMD(chan),
cmd);
/* Start the transfer. */
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DCSR(chan),
DCSR_RUN | DCSR_NODESCFETCH);
return 0;
}
int
pxadmac_intr(void *v)
{
struct pxadmac_softc *sc = v;
u_int32_t dint, dcsr;
int chan;
/* Interrupt for us? */
dint = bus_space_read_4(sc->sc_bust, sc->sc_bush, DMAC_DINT);
if (!dint)
return 0;
/* Process individual channels and run handlers. */
/* XXX: this does not respect priority order for channels. */
for (chan = 0; dint != 0 && chan < 32; chan++) {
/* Don't ack channels that weren't ready at call time. */
if ((dint & (1 << chan)) == 0)
continue;
dint &= ~(1 << chan);
/* Acknowledge individual channel interrupt. */
dcsr = bus_space_read_4(sc->sc_bust, sc->sc_bush,
DMAC_DCSR(chan));
bus_space_write_4(sc->sc_bust, sc->sc_bush, DMAC_DCSR(chan),
dcsr & 0x7C80021F);
/* Call the registered handler. */
if (sc->sc_intrhandlers[chan])
sc->sc_intrhandlers[chan](sc->sc_intrargs[chan]);
}
return 1;
}
|