2 * Arm PrimeCell PL080/PL081 DMA controller
4 * Copyright (c) 2006 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licenced under the GPL.
12 #define PL080_MAX_CHANNELS 8
13 #define PL080_CONF_E 0x1
14 #define PL080_CONF_M1 0x2
15 #define PL080_CONF_M2 0x4
17 #define PL080_CCONF_H 0x40000
18 #define PL080_CCONF_A 0x20000
19 #define PL080_CCONF_L 0x10000
20 #define PL080_CCONF_ITC 0x08000
21 #define PL080_CCONF_IE 0x04000
22 #define PL080_CCONF_E 0x00001
24 #define PL080_CCTRL_I 0x80000000
25 #define PL080_CCTRL_DI 0x08000000
26 #define PL080_CCTRL_SI 0x04000000
27 #define PL080_CCTRL_D 0x02000000
28 #define PL080_CCTRL_S 0x01000000
48 pl080_channel chan
[PL080_MAX_CHANNELS
];
50 /* Flag to avoid recursive DMA invocations. */
56 static const unsigned char pl080_id
[] =
57 { 0x80, 0x10, 0x04, 0x0a, 0x0d, 0xf0, 0x05, 0xb1 };
59 static const unsigned char pl081_id
[] =
60 { 0x81, 0x10, 0x04, 0x0a, 0x0d, 0xf0, 0x05, 0xb1 };
62 static void pl080_update(pl080_state
*s
)
64 if ((s
->tc_int
& s
->tc_mask
)
65 || (s
->err_int
& s
->err_mask
))
66 pic_set_irq_new(s
->pic
, s
->irq
, 1);
68 pic_set_irq_new(s
->pic
, s
->irq
, 1);
71 static void pl080_run(pl080_state
*s
)
87 for (c
= 0; c
< s
->nchannels
; c
++) {
88 if (s
->chan
[c
].conf
& PL080_CCONF_ITC
)
90 if (s
->chan
[c
].conf
& PL080_CCONF_IE
)
91 s
->err_mask
|= 1 << c
;
94 if ((s
->conf
& PL080_CONF_E
) == 0)
97 cpu_abort(cpu_single_env
, "DMA active\n");
98 /* If we are already in the middle of a DMA operation then indicate that
99 there may be new DMA requests and return immediately. */
106 for (c
= 0; c
< s
->nchannels
; c
++) {
109 /* Test if thiws channel has any pending DMA requests. */
110 if ((ch
->conf
& (PL080_CCONF_H
| PL080_CCONF_E
))
113 flow
= (ch
->conf
>> 11) & 7;
115 cpu_abort(cpu_single_env
,
116 "pl080_run: Peripheral flow control not implemented\n");
118 src_id
= (ch
->conf
>> 1) & 0x1f;
119 dest_id
= (ch
->conf
>> 6) & 0x1f;
120 size
= ch
->ctrl
& 0xfff;
121 req
= s
->req_single
| s
->req_burst
;
126 if ((req
& (1u << dest_id
)) == 0)
130 if ((req
& (1u << src_id
)) == 0)
134 if ((req
& (1u << src_id
)) == 0
135 || (req
& (1u << dest_id
)) == 0)
142 /* Transfer one element. */
143 /* ??? Should transfer multiple elements for a burst request. */
144 /* ??? Unclear what the proper behavior is when source and
145 destination widths are different. */
146 swidth
= 1 << ((ch
->ctrl
>> 18) & 7);
147 dwidth
= 1 << ((ch
->ctrl
>> 21) & 7);
148 for (n
= 0; n
< dwidth
; n
+= swidth
) {
149 cpu_physical_memory_read(ch
->src
, buff
+ n
, swidth
);
150 if (ch
->ctrl
& PL080_CCTRL_SI
)
153 xsize
= (dwidth
< swidth
) ? swidth
: dwidth
;
154 /* ??? This may pad the value incorrectly for dwidth < 32. */
155 for (n
= 0; n
< xsize
; n
+= dwidth
) {
156 cpu_physical_memory_write(ch
->dest
+ n
, buff
+ n
, dwidth
);
157 if (ch
->ctrl
& PL080_CCTRL_DI
)
162 ch
->ctrl
= (ch
->ctrl
& 0xfffff000) | size
;
164 /* Transfer complete. */
166 ch
->src
= ldl_phys(ch
->lli
);
167 ch
->dest
= ldl_phys(ch
->lli
+ 4);
168 ch
->ctrl
= ldl_phys(ch
->lli
+ 12);
169 ch
->lli
= ldl_phys(ch
->lli
+ 8);
171 ch
->conf
&= ~PL080_CCONF_E
;
173 if (ch
->ctrl
& PL080_CCTRL_I
) {
184 static uint32_t pl080_read(void *opaque
, target_phys_addr_t offset
)
186 pl080_state
*s
= (pl080_state
*)opaque
;
191 if (offset
>= 0xfe0 && offset
< 0x1000) {
192 if (s
->nchannels
== 8) {
193 return pl080_id
[(offset
- 0xfe0) >> 2];
195 return pl081_id
[(offset
- 0xfe0) >> 2];
198 if (offset
>= 0x100 && offset
< 0x200) {
199 i
= (offset
& 0xe0) >> 5;
200 if (i
>= s
->nchannels
)
202 switch (offset
>> 2) {
203 case 0: /* SrcAddr */
204 return s
->chan
[i
].src
;
205 case 1: /* DestAddr */
206 return s
->chan
[i
].dest
;
208 return s
->chan
[i
].lli
;
209 case 3: /* Control */
210 return s
->chan
[i
].ctrl
;
211 case 4: /* Configuration */
212 return s
->chan
[i
].conf
;
217 switch (offset
>> 2) {
218 case 0: /* IntStatus */
219 return (s
->tc_int
& s
->tc_mask
) | (s
->err_int
& s
->err_mask
);
220 case 1: /* IntTCStatus */
221 return (s
->tc_int
& s
->tc_mask
);
222 case 3: /* IntErrorStatus */
223 return (s
->err_int
& s
->err_mask
);
224 case 5: /* RawIntTCStatus */
226 case 6: /* RawIntErrorStatus */
228 case 7: /* EnbldChns */
230 for (i
= 0; i
< s
->nchannels
; i
++) {
231 if (s
->chan
[i
].conf
& PL080_CCONF_E
)
235 case 8: /* SoftBReq */
236 case 9: /* SoftSReq */
237 case 10: /* SoftLBReq */
238 case 11: /* SoftLSReq */
239 /* ??? Implement these. */
241 case 12: /* Configuration */
247 cpu_abort(cpu_single_env
, "pl080_read: Bad offset %x\n", offset
);
252 static void pl080_write(void *opaque
, target_phys_addr_t offset
,
255 pl080_state
*s
= (pl080_state
*)opaque
;
259 if (offset
>= 0x100 && offset
< 0x200) {
260 i
= (offset
& 0xe0) >> 5;
261 if (i
>= s
->nchannels
)
263 switch (offset
>> 2) {
264 case 0: /* SrcAddr */
265 s
->chan
[i
].src
= value
;
267 case 1: /* DestAddr */
268 s
->chan
[i
].dest
= value
;
271 s
->chan
[i
].lli
= value
;
273 case 3: /* Control */
274 s
->chan
[i
].ctrl
= value
;
276 case 4: /* Configuration */
277 s
->chan
[i
].conf
= value
;
282 switch (offset
>> 2) {
283 case 2: /* IntTCClear */
286 case 4: /* IntErrorClear */
287 s
->err_int
&= ~value
;
289 case 8: /* SoftBReq */
290 case 9: /* SoftSReq */
291 case 10: /* SoftLBReq */
292 case 11: /* SoftLSReq */
293 /* ??? Implement these. */
294 cpu_abort(cpu_single_env
, "pl080_write: Soft DMA not implemented\n");
296 case 12: /* Configuration */
298 if (s
->conf
& (PL080_CONF_M1
| PL080_CONF_M1
)) {
299 cpu_abort(cpu_single_env
,
300 "pl080_write: Big-endian DMA not implemented\n");
309 cpu_abort(cpu_single_env
, "pl080_write: Bad offset %x\n", offset
);
314 static CPUReadMemoryFunc
*pl080_readfn
[] = {
320 static CPUWriteMemoryFunc
*pl080_writefn
[] = {
326 /* The PL080 and PL081 are the same except for the number of channels
327 they implement (8 and 2 respectively). */
328 void *pl080_init(uint32_t base
, void *pic
, int irq
, int nchannels
)
333 s
= (pl080_state
*)qemu_mallocz(sizeof(pl080_state
));
334 iomemtype
= cpu_register_io_memory(0, pl080_readfn
,
336 cpu_register_physical_memory(base
, 0x00000fff, iomemtype
);
340 s
->nchannels
= nchannels
;
341 /* ??? Save/restore. */