root / hw / pl080.c @ eb173de6
History | View | Annotate | Download (9.4 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | e69954b9 | pbrook | * Arm PrimeCell PL080/PL081 DMA controller
|
3 | cdbdb648 | pbrook | *
|
4 | cdbdb648 | pbrook | * Copyright (c) 2006 CodeSourcery.
|
5 | cdbdb648 | pbrook | * Written by Paul Brook
|
6 | cdbdb648 | pbrook | *
|
7 | cdbdb648 | pbrook | * This code is licenced under the GPL.
|
8 | cdbdb648 | pbrook | */
|
9 | cdbdb648 | pbrook | |
10 | 87ecb68b | pbrook | #include "hw.h" |
11 | 87ecb68b | pbrook | #include "primecell.h" |
12 | cdbdb648 | pbrook | |
13 | e69954b9 | pbrook | #define PL080_MAX_CHANNELS 8 |
14 | cdbdb648 | pbrook | #define PL080_CONF_E 0x1 |
15 | cdbdb648 | pbrook | #define PL080_CONF_M1 0x2 |
16 | cdbdb648 | pbrook | #define PL080_CONF_M2 0x4 |
17 | cdbdb648 | pbrook | |
18 | cdbdb648 | pbrook | #define PL080_CCONF_H 0x40000 |
19 | cdbdb648 | pbrook | #define PL080_CCONF_A 0x20000 |
20 | cdbdb648 | pbrook | #define PL080_CCONF_L 0x10000 |
21 | cdbdb648 | pbrook | #define PL080_CCONF_ITC 0x08000 |
22 | cdbdb648 | pbrook | #define PL080_CCONF_IE 0x04000 |
23 | cdbdb648 | pbrook | #define PL080_CCONF_E 0x00001 |
24 | cdbdb648 | pbrook | |
25 | cdbdb648 | pbrook | #define PL080_CCTRL_I 0x80000000 |
26 | cdbdb648 | pbrook | #define PL080_CCTRL_DI 0x08000000 |
27 | cdbdb648 | pbrook | #define PL080_CCTRL_SI 0x04000000 |
28 | cdbdb648 | pbrook | #define PL080_CCTRL_D 0x02000000 |
29 | cdbdb648 | pbrook | #define PL080_CCTRL_S 0x01000000 |
30 | cdbdb648 | pbrook | |
31 | cdbdb648 | pbrook | typedef struct { |
32 | cdbdb648 | pbrook | uint32_t src; |
33 | cdbdb648 | pbrook | uint32_t dest; |
34 | cdbdb648 | pbrook | uint32_t lli; |
35 | cdbdb648 | pbrook | uint32_t ctrl; |
36 | cdbdb648 | pbrook | uint32_t conf; |
37 | cdbdb648 | pbrook | } pl080_channel; |
38 | cdbdb648 | pbrook | |
39 | cdbdb648 | pbrook | typedef struct { |
40 | cdbdb648 | pbrook | uint32_t base; |
41 | cdbdb648 | pbrook | uint8_t tc_int; |
42 | cdbdb648 | pbrook | uint8_t tc_mask; |
43 | cdbdb648 | pbrook | uint8_t err_int; |
44 | cdbdb648 | pbrook | uint8_t err_mask; |
45 | cdbdb648 | pbrook | uint32_t conf; |
46 | cdbdb648 | pbrook | uint32_t sync; |
47 | cdbdb648 | pbrook | uint32_t req_single; |
48 | cdbdb648 | pbrook | uint32_t req_burst; |
49 | e69954b9 | pbrook | pl080_channel chan[PL080_MAX_CHANNELS]; |
50 | e69954b9 | pbrook | int nchannels;
|
51 | cdbdb648 | pbrook | /* Flag to avoid recursive DMA invocations. */
|
52 | cdbdb648 | pbrook | int running;
|
53 | d537cf6c | pbrook | qemu_irq irq; |
54 | cdbdb648 | pbrook | } pl080_state; |
55 | cdbdb648 | pbrook | |
56 | cdbdb648 | pbrook | static const unsigned char pl080_id[] = |
57 | cdbdb648 | pbrook | { 0x80, 0x10, 0x04, 0x0a, 0x0d, 0xf0, 0x05, 0xb1 }; |
58 | cdbdb648 | pbrook | |
59 | e69954b9 | pbrook | static const unsigned char pl081_id[] = |
60 | e69954b9 | pbrook | { 0x81, 0x10, 0x04, 0x0a, 0x0d, 0xf0, 0x05, 0xb1 }; |
61 | e69954b9 | pbrook | |
62 | cdbdb648 | pbrook | static void pl080_update(pl080_state *s) |
63 | cdbdb648 | pbrook | { |
64 | cdbdb648 | pbrook | if ((s->tc_int & s->tc_mask)
|
65 | cdbdb648 | pbrook | || (s->err_int & s->err_mask)) |
66 | d537cf6c | pbrook | qemu_irq_raise(s->irq); |
67 | cdbdb648 | pbrook | else
|
68 | d537cf6c | pbrook | qemu_irq_lower(s->irq); |
69 | cdbdb648 | pbrook | } |
70 | cdbdb648 | pbrook | |
71 | cdbdb648 | pbrook | static void pl080_run(pl080_state *s) |
72 | cdbdb648 | pbrook | { |
73 | cdbdb648 | pbrook | int c;
|
74 | cdbdb648 | pbrook | int flow;
|
75 | cdbdb648 | pbrook | pl080_channel *ch; |
76 | cdbdb648 | pbrook | int swidth;
|
77 | cdbdb648 | pbrook | int dwidth;
|
78 | cdbdb648 | pbrook | int xsize;
|
79 | cdbdb648 | pbrook | int n;
|
80 | cdbdb648 | pbrook | int src_id;
|
81 | cdbdb648 | pbrook | int dest_id;
|
82 | cdbdb648 | pbrook | int size;
|
83 | cdbdb648 | pbrook | char buff[4]; |
84 | cdbdb648 | pbrook | uint32_t req; |
85 | cdbdb648 | pbrook | |
86 | cdbdb648 | pbrook | s->tc_mask = 0;
|
87 | e69954b9 | pbrook | for (c = 0; c < s->nchannels; c++) { |
88 | cdbdb648 | pbrook | if (s->chan[c].conf & PL080_CCONF_ITC)
|
89 | cdbdb648 | pbrook | s->tc_mask |= 1 << c;
|
90 | cdbdb648 | pbrook | if (s->chan[c].conf & PL080_CCONF_IE)
|
91 | cdbdb648 | pbrook | s->err_mask |= 1 << c;
|
92 | cdbdb648 | pbrook | } |
93 | cdbdb648 | pbrook | |
94 | cdbdb648 | pbrook | if ((s->conf & PL080_CONF_E) == 0) |
95 | cdbdb648 | pbrook | return;
|
96 | cdbdb648 | pbrook | |
97 | cdbdb648 | pbrook | cpu_abort(cpu_single_env, "DMA active\n");
|
98 | cdbdb648 | pbrook | /* If we are already in the middle of a DMA operation then indicate that
|
99 | cdbdb648 | pbrook | there may be new DMA requests and return immediately. */
|
100 | cdbdb648 | pbrook | if (s->running) {
|
101 | cdbdb648 | pbrook | s->running++; |
102 | cdbdb648 | pbrook | return;
|
103 | cdbdb648 | pbrook | } |
104 | cdbdb648 | pbrook | s->running = 1;
|
105 | cdbdb648 | pbrook | while (s->running) {
|
106 | e69954b9 | pbrook | for (c = 0; c < s->nchannels; c++) { |
107 | cdbdb648 | pbrook | ch = &s->chan[c]; |
108 | cdbdb648 | pbrook | again:
|
109 | cdbdb648 | pbrook | /* Test if thiws channel has any pending DMA requests. */
|
110 | cdbdb648 | pbrook | if ((ch->conf & (PL080_CCONF_H | PL080_CCONF_E))
|
111 | cdbdb648 | pbrook | != PL080_CCONF_E) |
112 | cdbdb648 | pbrook | continue;
|
113 | cdbdb648 | pbrook | flow = (ch->conf >> 11) & 7; |
114 | cdbdb648 | pbrook | if (flow >= 4) { |
115 | 5fafdf24 | ths | cpu_abort(cpu_single_env, |
116 | cdbdb648 | pbrook | "pl080_run: Peripheral flow control not implemented\n");
|
117 | cdbdb648 | pbrook | } |
118 | cdbdb648 | pbrook | src_id = (ch->conf >> 1) & 0x1f; |
119 | cdbdb648 | pbrook | dest_id = (ch->conf >> 6) & 0x1f; |
120 | cdbdb648 | pbrook | size = ch->ctrl & 0xfff;
|
121 | cdbdb648 | pbrook | req = s->req_single | s->req_burst; |
122 | cdbdb648 | pbrook | switch (flow) {
|
123 | cdbdb648 | pbrook | case 0: |
124 | cdbdb648 | pbrook | break;
|
125 | cdbdb648 | pbrook | case 1: |
126 | cdbdb648 | pbrook | if ((req & (1u << dest_id)) == 0) |
127 | cdbdb648 | pbrook | size = 0;
|
128 | cdbdb648 | pbrook | break;
|
129 | cdbdb648 | pbrook | case 2: |
130 | cdbdb648 | pbrook | if ((req & (1u << src_id)) == 0) |
131 | cdbdb648 | pbrook | size = 0;
|
132 | cdbdb648 | pbrook | break;
|
133 | cdbdb648 | pbrook | case 3: |
134 | cdbdb648 | pbrook | if ((req & (1u << src_id)) == 0 |
135 | cdbdb648 | pbrook | || (req & (1u << dest_id)) == 0) |
136 | cdbdb648 | pbrook | size = 0;
|
137 | cdbdb648 | pbrook | break;
|
138 | cdbdb648 | pbrook | } |
139 | cdbdb648 | pbrook | if (!size)
|
140 | cdbdb648 | pbrook | continue;
|
141 | cdbdb648 | pbrook | |
142 | cdbdb648 | pbrook | /* Transfer one element. */
|
143 | cdbdb648 | pbrook | /* ??? Should transfer multiple elements for a burst request. */
|
144 | cdbdb648 | pbrook | /* ??? Unclear what the proper behavior is when source and
|
145 | cdbdb648 | pbrook | destination widths are different. */
|
146 | cdbdb648 | pbrook | swidth = 1 << ((ch->ctrl >> 18) & 7); |
147 | cdbdb648 | pbrook | dwidth = 1 << ((ch->ctrl >> 21) & 7); |
148 | cdbdb648 | pbrook | for (n = 0; n < dwidth; n+= swidth) { |
149 | cdbdb648 | pbrook | cpu_physical_memory_read(ch->src, buff + n, swidth); |
150 | cdbdb648 | pbrook | if (ch->ctrl & PL080_CCTRL_SI)
|
151 | cdbdb648 | pbrook | ch->src += swidth; |
152 | cdbdb648 | pbrook | } |
153 | cdbdb648 | pbrook | xsize = (dwidth < swidth) ? swidth : dwidth; |
154 | cdbdb648 | pbrook | /* ??? This may pad the value incorrectly for dwidth < 32. */
|
155 | cdbdb648 | pbrook | for (n = 0; n < xsize; n += dwidth) { |
156 | cdbdb648 | pbrook | cpu_physical_memory_write(ch->dest + n, buff + n, dwidth); |
157 | cdbdb648 | pbrook | if (ch->ctrl & PL080_CCTRL_DI)
|
158 | cdbdb648 | pbrook | ch->dest += swidth; |
159 | cdbdb648 | pbrook | } |
160 | cdbdb648 | pbrook | |
161 | cdbdb648 | pbrook | size--; |
162 | cdbdb648 | pbrook | ch->ctrl = (ch->ctrl & 0xfffff000) | size;
|
163 | cdbdb648 | pbrook | if (size == 0) { |
164 | cdbdb648 | pbrook | /* Transfer complete. */
|
165 | cdbdb648 | pbrook | if (ch->lli) {
|
166 | cdbdb648 | pbrook | ch->src = ldl_phys(ch->lli); |
167 | cdbdb648 | pbrook | ch->dest = ldl_phys(ch->lli + 4);
|
168 | cdbdb648 | pbrook | ch->ctrl = ldl_phys(ch->lli + 12);
|
169 | cdbdb648 | pbrook | ch->lli = ldl_phys(ch->lli + 8);
|
170 | cdbdb648 | pbrook | } else {
|
171 | cdbdb648 | pbrook | ch->conf &= ~PL080_CCONF_E; |
172 | cdbdb648 | pbrook | } |
173 | cdbdb648 | pbrook | if (ch->ctrl & PL080_CCTRL_I) {
|
174 | cdbdb648 | pbrook | s->tc_int |= 1 << c;
|
175 | cdbdb648 | pbrook | } |
176 | cdbdb648 | pbrook | } |
177 | cdbdb648 | pbrook | goto again;
|
178 | cdbdb648 | pbrook | } |
179 | cdbdb648 | pbrook | if (--s->running)
|
180 | cdbdb648 | pbrook | s->running = 1;
|
181 | cdbdb648 | pbrook | } |
182 | cdbdb648 | pbrook | } |
183 | cdbdb648 | pbrook | |
184 | cdbdb648 | pbrook | static uint32_t pl080_read(void *opaque, target_phys_addr_t offset) |
185 | cdbdb648 | pbrook | { |
186 | cdbdb648 | pbrook | pl080_state *s = (pl080_state *)opaque; |
187 | cdbdb648 | pbrook | uint32_t i; |
188 | cdbdb648 | pbrook | uint32_t mask; |
189 | cdbdb648 | pbrook | |
190 | cdbdb648 | pbrook | offset -= s->base; |
191 | cdbdb648 | pbrook | if (offset >= 0xfe0 && offset < 0x1000) { |
192 | e69954b9 | pbrook | if (s->nchannels == 8) { |
193 | e69954b9 | pbrook | return pl080_id[(offset - 0xfe0) >> 2]; |
194 | e69954b9 | pbrook | } else {
|
195 | e69954b9 | pbrook | return pl081_id[(offset - 0xfe0) >> 2]; |
196 | e69954b9 | pbrook | } |
197 | cdbdb648 | pbrook | } |
198 | cdbdb648 | pbrook | if (offset >= 0x100 && offset < 0x200) { |
199 | cdbdb648 | pbrook | i = (offset & 0xe0) >> 5; |
200 | e69954b9 | pbrook | if (i >= s->nchannels)
|
201 | e69954b9 | pbrook | goto bad_offset;
|
202 | cdbdb648 | pbrook | switch (offset >> 2) { |
203 | cdbdb648 | pbrook | case 0: /* SrcAddr */ |
204 | cdbdb648 | pbrook | return s->chan[i].src;
|
205 | cdbdb648 | pbrook | case 1: /* DestAddr */ |
206 | cdbdb648 | pbrook | return s->chan[i].dest;
|
207 | cdbdb648 | pbrook | case 2: /* LLI */ |
208 | cdbdb648 | pbrook | return s->chan[i].lli;
|
209 | cdbdb648 | pbrook | case 3: /* Control */ |
210 | cdbdb648 | pbrook | return s->chan[i].ctrl;
|
211 | cdbdb648 | pbrook | case 4: /* Configuration */ |
212 | cdbdb648 | pbrook | return s->chan[i].conf;
|
213 | cdbdb648 | pbrook | default:
|
214 | cdbdb648 | pbrook | goto bad_offset;
|
215 | cdbdb648 | pbrook | } |
216 | cdbdb648 | pbrook | } |
217 | cdbdb648 | pbrook | switch (offset >> 2) { |
218 | cdbdb648 | pbrook | case 0: /* IntStatus */ |
219 | cdbdb648 | pbrook | return (s->tc_int & s->tc_mask) | (s->err_int & s->err_mask);
|
220 | cdbdb648 | pbrook | case 1: /* IntTCStatus */ |
221 | cdbdb648 | pbrook | return (s->tc_int & s->tc_mask);
|
222 | cdbdb648 | pbrook | case 3: /* IntErrorStatus */ |
223 | cdbdb648 | pbrook | return (s->err_int & s->err_mask);
|
224 | cdbdb648 | pbrook | case 5: /* RawIntTCStatus */ |
225 | cdbdb648 | pbrook | return s->tc_int;
|
226 | cdbdb648 | pbrook | case 6: /* RawIntErrorStatus */ |
227 | cdbdb648 | pbrook | return s->err_int;
|
228 | cdbdb648 | pbrook | case 7: /* EnbldChns */ |
229 | cdbdb648 | pbrook | mask = 0;
|
230 | e69954b9 | pbrook | for (i = 0; i < s->nchannels; i++) { |
231 | cdbdb648 | pbrook | if (s->chan[i].conf & PL080_CCONF_E)
|
232 | cdbdb648 | pbrook | mask |= 1 << i;
|
233 | cdbdb648 | pbrook | } |
234 | cdbdb648 | pbrook | return mask;
|
235 | cdbdb648 | pbrook | case 8: /* SoftBReq */ |
236 | cdbdb648 | pbrook | case 9: /* SoftSReq */ |
237 | cdbdb648 | pbrook | case 10: /* SoftLBReq */ |
238 | cdbdb648 | pbrook | case 11: /* SoftLSReq */ |
239 | cdbdb648 | pbrook | /* ??? Implement these. */
|
240 | cdbdb648 | pbrook | return 0; |
241 | cdbdb648 | pbrook | case 12: /* Configuration */ |
242 | cdbdb648 | pbrook | return s->conf;
|
243 | cdbdb648 | pbrook | case 13: /* Sync */ |
244 | cdbdb648 | pbrook | return s->sync;
|
245 | cdbdb648 | pbrook | default:
|
246 | cdbdb648 | pbrook | bad_offset:
|
247 | 4d1165fa | pbrook | cpu_abort(cpu_single_env, "pl080_read: Bad offset %x\n", (int)offset); |
248 | cdbdb648 | pbrook | return 0; |
249 | cdbdb648 | pbrook | } |
250 | cdbdb648 | pbrook | } |
251 | cdbdb648 | pbrook | |
252 | cdbdb648 | pbrook | static void pl080_write(void *opaque, target_phys_addr_t offset, |
253 | cdbdb648 | pbrook | uint32_t value) |
254 | cdbdb648 | pbrook | { |
255 | cdbdb648 | pbrook | pl080_state *s = (pl080_state *)opaque; |
256 | cdbdb648 | pbrook | int i;
|
257 | cdbdb648 | pbrook | |
258 | cdbdb648 | pbrook | offset -= s->base; |
259 | cdbdb648 | pbrook | if (offset >= 0x100 && offset < 0x200) { |
260 | cdbdb648 | pbrook | i = (offset & 0xe0) >> 5; |
261 | e69954b9 | pbrook | if (i >= s->nchannels)
|
262 | e69954b9 | pbrook | goto bad_offset;
|
263 | cdbdb648 | pbrook | switch (offset >> 2) { |
264 | cdbdb648 | pbrook | case 0: /* SrcAddr */ |
265 | cdbdb648 | pbrook | s->chan[i].src = value; |
266 | cdbdb648 | pbrook | break;
|
267 | cdbdb648 | pbrook | case 1: /* DestAddr */ |
268 | cdbdb648 | pbrook | s->chan[i].dest = value; |
269 | cdbdb648 | pbrook | break;
|
270 | cdbdb648 | pbrook | case 2: /* LLI */ |
271 | cdbdb648 | pbrook | s->chan[i].lli = value; |
272 | cdbdb648 | pbrook | break;
|
273 | cdbdb648 | pbrook | case 3: /* Control */ |
274 | cdbdb648 | pbrook | s->chan[i].ctrl = value; |
275 | cdbdb648 | pbrook | break;
|
276 | cdbdb648 | pbrook | case 4: /* Configuration */ |
277 | cdbdb648 | pbrook | s->chan[i].conf = value; |
278 | cdbdb648 | pbrook | pl080_run(s); |
279 | cdbdb648 | pbrook | break;
|
280 | cdbdb648 | pbrook | } |
281 | cdbdb648 | pbrook | } |
282 | cdbdb648 | pbrook | switch (offset >> 2) { |
283 | cdbdb648 | pbrook | case 2: /* IntTCClear */ |
284 | cdbdb648 | pbrook | s->tc_int &= ~value; |
285 | cdbdb648 | pbrook | break;
|
286 | cdbdb648 | pbrook | case 4: /* IntErrorClear */ |
287 | cdbdb648 | pbrook | s->err_int &= ~value; |
288 | cdbdb648 | pbrook | break;
|
289 | cdbdb648 | pbrook | case 8: /* SoftBReq */ |
290 | cdbdb648 | pbrook | case 9: /* SoftSReq */ |
291 | cdbdb648 | pbrook | case 10: /* SoftLBReq */ |
292 | cdbdb648 | pbrook | case 11: /* SoftLSReq */ |
293 | cdbdb648 | pbrook | /* ??? Implement these. */
|
294 | cdbdb648 | pbrook | cpu_abort(cpu_single_env, "pl080_write: Soft DMA not implemented\n");
|
295 | cdbdb648 | pbrook | break;
|
296 | cdbdb648 | pbrook | case 12: /* Configuration */ |
297 | cdbdb648 | pbrook | s->conf = value; |
298 | cdbdb648 | pbrook | if (s->conf & (PL080_CONF_M1 | PL080_CONF_M1)) {
|
299 | cdbdb648 | pbrook | cpu_abort(cpu_single_env, |
300 | cdbdb648 | pbrook | "pl080_write: Big-endian DMA not implemented\n");
|
301 | cdbdb648 | pbrook | } |
302 | cdbdb648 | pbrook | pl080_run(s); |
303 | cdbdb648 | pbrook | break;
|
304 | cdbdb648 | pbrook | case 13: /* Sync */ |
305 | cdbdb648 | pbrook | s->sync = value; |
306 | cdbdb648 | pbrook | break;
|
307 | cdbdb648 | pbrook | default:
|
308 | e69954b9 | pbrook | bad_offset:
|
309 | 4d1165fa | pbrook | cpu_abort(cpu_single_env, "pl080_write: Bad offset %x\n", (int)offset); |
310 | cdbdb648 | pbrook | } |
311 | cdbdb648 | pbrook | pl080_update(s); |
312 | cdbdb648 | pbrook | } |
313 | cdbdb648 | pbrook | |
314 | cdbdb648 | pbrook | static CPUReadMemoryFunc *pl080_readfn[] = {
|
315 | cdbdb648 | pbrook | pl080_read, |
316 | cdbdb648 | pbrook | pl080_read, |
317 | cdbdb648 | pbrook | pl080_read |
318 | cdbdb648 | pbrook | }; |
319 | cdbdb648 | pbrook | |
320 | cdbdb648 | pbrook | static CPUWriteMemoryFunc *pl080_writefn[] = {
|
321 | cdbdb648 | pbrook | pl080_write, |
322 | cdbdb648 | pbrook | pl080_write, |
323 | cdbdb648 | pbrook | pl080_write |
324 | cdbdb648 | pbrook | }; |
325 | cdbdb648 | pbrook | |
326 | e69954b9 | pbrook | /* The PL080 and PL081 are the same except for the number of channels
|
327 | e69954b9 | pbrook | they implement (8 and 2 respectively). */
|
328 | d537cf6c | pbrook | void *pl080_init(uint32_t base, qemu_irq irq, int nchannels) |
329 | cdbdb648 | pbrook | { |
330 | cdbdb648 | pbrook | int iomemtype;
|
331 | cdbdb648 | pbrook | pl080_state *s; |
332 | cdbdb648 | pbrook | |
333 | cdbdb648 | pbrook | s = (pl080_state *)qemu_mallocz(sizeof(pl080_state));
|
334 | cdbdb648 | pbrook | iomemtype = cpu_register_io_memory(0, pl080_readfn,
|
335 | cdbdb648 | pbrook | pl080_writefn, s); |
336 | 187337f8 | pbrook | cpu_register_physical_memory(base, 0x00001000, iomemtype);
|
337 | cdbdb648 | pbrook | s->base = base; |
338 | cdbdb648 | pbrook | s->irq = irq; |
339 | e69954b9 | pbrook | s->nchannels = nchannels; |
340 | cdbdb648 | pbrook | /* ??? Save/restore. */
|
341 | cdbdb648 | pbrook | return s;
|
342 | cdbdb648 | pbrook | } |