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. */
55 static const unsigned char pl080_id
[] =
56 { 0x80, 0x10, 0x04, 0x0a, 0x0d, 0xf0, 0x05, 0xb1 };
58 static const unsigned char pl081_id
[] =
59 { 0x81, 0x10, 0x04, 0x0a, 0x0d, 0xf0, 0x05, 0xb1 };
61 static void pl080_update(pl080_state
*s
)
63 if ((s
->tc_int
& s
->tc_mask
)
64 || (s
->err_int
& s
->err_mask
))
65 qemu_irq_raise(s
->irq
);
67 qemu_irq_lower(s
->irq
);
70 static void pl080_run(pl080_state
*s
)
86 for (c
= 0; c
< s
->nchannels
; c
++) {
87 if (s
->chan
[c
].conf
& PL080_CCONF_ITC
)
89 if (s
->chan
[c
].conf
& PL080_CCONF_IE
)
90 s
->err_mask
|= 1 << c
;
93 if ((s
->conf
& PL080_CONF_E
) == 0)
96 hw_error("DMA active\n");
97 /* If we are already in the middle of a DMA operation then indicate that
98 there may be new DMA requests and return immediately. */
105 for (c
= 0; c
< s
->nchannels
; c
++) {
108 /* Test if thiws channel has any pending DMA requests. */
109 if ((ch
->conf
& (PL080_CCONF_H
| PL080_CCONF_E
))
112 flow
= (ch
->conf
>> 11) & 7;
115 "pl080_run: Peripheral flow control not implemented\n");
117 src_id
= (ch
->conf
>> 1) & 0x1f;
118 dest_id
= (ch
->conf
>> 6) & 0x1f;
119 size
= ch
->ctrl
& 0xfff;
120 req
= s
->req_single
| s
->req_burst
;
125 if ((req
& (1u << dest_id
)) == 0)
129 if ((req
& (1u << src_id
)) == 0)
133 if ((req
& (1u << src_id
)) == 0
134 || (req
& (1u << dest_id
)) == 0)
141 /* Transfer one element. */
142 /* ??? Should transfer multiple elements for a burst request. */
143 /* ??? Unclear what the proper behavior is when source and
144 destination widths are different. */
145 swidth
= 1 << ((ch
->ctrl
>> 18) & 7);
146 dwidth
= 1 << ((ch
->ctrl
>> 21) & 7);
147 for (n
= 0; n
< dwidth
; n
+= swidth
) {
148 cpu_physical_memory_read(ch
->src
, buff
+ n
, swidth
);
149 if (ch
->ctrl
& PL080_CCTRL_SI
)
152 xsize
= (dwidth
< swidth
) ? swidth
: dwidth
;
153 /* ??? This may pad the value incorrectly for dwidth < 32. */
154 for (n
= 0; n
< xsize
; n
+= dwidth
) {
155 cpu_physical_memory_write(ch
->dest
+ n
, buff
+ n
, dwidth
);
156 if (ch
->ctrl
& PL080_CCTRL_DI
)
161 ch
->ctrl
= (ch
->ctrl
& 0xfffff000) | size
;
163 /* Transfer complete. */
165 ch
->src
= ldl_phys(ch
->lli
);
166 ch
->dest
= ldl_phys(ch
->lli
+ 4);
167 ch
->ctrl
= ldl_phys(ch
->lli
+ 12);
168 ch
->lli
= ldl_phys(ch
->lli
+ 8);
170 ch
->conf
&= ~PL080_CCONF_E
;
172 if (ch
->ctrl
& PL080_CCTRL_I
) {
183 static uint32_t pl080_read(void *opaque
, target_phys_addr_t offset
)
185 pl080_state
*s
= (pl080_state
*)opaque
;
189 if (offset
>= 0xfe0 && offset
< 0x1000) {
190 if (s
->nchannels
== 8) {
191 return pl080_id
[(offset
- 0xfe0) >> 2];
193 return pl081_id
[(offset
- 0xfe0) >> 2];
196 if (offset
>= 0x100 && offset
< 0x200) {
197 i
= (offset
& 0xe0) >> 5;
198 if (i
>= s
->nchannels
)
200 switch (offset
>> 2) {
201 case 0: /* SrcAddr */
202 return s
->chan
[i
].src
;
203 case 1: /* DestAddr */
204 return s
->chan
[i
].dest
;
206 return s
->chan
[i
].lli
;
207 case 3: /* Control */
208 return s
->chan
[i
].ctrl
;
209 case 4: /* Configuration */
210 return s
->chan
[i
].conf
;
215 switch (offset
>> 2) {
216 case 0: /* IntStatus */
217 return (s
->tc_int
& s
->tc_mask
) | (s
->err_int
& s
->err_mask
);
218 case 1: /* IntTCStatus */
219 return (s
->tc_int
& s
->tc_mask
);
220 case 3: /* IntErrorStatus */
221 return (s
->err_int
& s
->err_mask
);
222 case 5: /* RawIntTCStatus */
224 case 6: /* RawIntErrorStatus */
226 case 7: /* EnbldChns */
228 for (i
= 0; i
< s
->nchannels
; i
++) {
229 if (s
->chan
[i
].conf
& PL080_CCONF_E
)
233 case 8: /* SoftBReq */
234 case 9: /* SoftSReq */
235 case 10: /* SoftLBReq */
236 case 11: /* SoftLSReq */
237 /* ??? Implement these. */
239 case 12: /* Configuration */
245 hw_error("pl080_read: Bad offset %x\n", (int)offset
);
250 static void pl080_write(void *opaque
, target_phys_addr_t offset
,
253 pl080_state
*s
= (pl080_state
*)opaque
;
256 if (offset
>= 0x100 && offset
< 0x200) {
257 i
= (offset
& 0xe0) >> 5;
258 if (i
>= s
->nchannels
)
260 switch (offset
>> 2) {
261 case 0: /* SrcAddr */
262 s
->chan
[i
].src
= value
;
264 case 1: /* DestAddr */
265 s
->chan
[i
].dest
= value
;
268 s
->chan
[i
].lli
= value
;
270 case 3: /* Control */
271 s
->chan
[i
].ctrl
= value
;
273 case 4: /* Configuration */
274 s
->chan
[i
].conf
= value
;
279 switch (offset
>> 2) {
280 case 2: /* IntTCClear */
283 case 4: /* IntErrorClear */
284 s
->err_int
&= ~value
;
286 case 8: /* SoftBReq */
287 case 9: /* SoftSReq */
288 case 10: /* SoftLBReq */
289 case 11: /* SoftLSReq */
290 /* ??? Implement these. */
291 hw_error("pl080_write: Soft DMA not implemented\n");
293 case 12: /* Configuration */
295 if (s
->conf
& (PL080_CONF_M1
| PL080_CONF_M1
)) {
296 hw_error("pl080_write: Big-endian DMA not implemented\n");
305 hw_error("pl080_write: Bad offset %x\n", (int)offset
);
310 static CPUReadMemoryFunc
* const pl080_readfn
[] = {
316 static CPUWriteMemoryFunc
* const pl080_writefn
[] = {
322 static int pl08x_init(SysBusDevice
*dev
, int nchannels
)
325 pl080_state
*s
= FROM_SYSBUS(pl080_state
, dev
);
327 iomemtype
= cpu_register_io_memory(pl080_readfn
,
329 sysbus_init_mmio(dev
, 0x1000, iomemtype
);
330 sysbus_init_irq(dev
, &s
->irq
);
331 s
->nchannels
= nchannels
;
332 /* ??? Save/restore. */
336 static int pl080_init(SysBusDevice
*dev
)
338 return pl08x_init(dev
, 8);
341 static int pl081_init(SysBusDevice
*dev
)
343 return pl08x_init(dev
, 2);
346 /* The PL080 and PL081 are the same except for the number of channels
347 they implement (8 and 2 respectively). */
348 static void pl080_register_devices(void)
350 sysbus_register_dev("pl080", sizeof(pl080_state
), pl080_init
);
351 sysbus_register_dev("pl081", sizeof(pl080_state
), pl081_init
);
354 device_init(pl080_register_devices
)