2 * TI OMAP DMA gigacell.
4 * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
5 * Copyright (C) 2007-2008 Lauro Ramos Venancio <lauro.venancio@indt.org.br>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 #include "qemu-common.h"
23 #include "qemu/timer.h"
24 #include "hw/arm/omap.h"
26 #include "hw/arm/soc_dma.h"
28 struct omap_dma_channel_s
{
35 enum omap_dma_port port
[2];
37 omap_dma_addressing_t mode
[2];
40 int32_t frame_index
[2];
41 int16_t element_index
[2];
50 /* auto init and linked channel data */
57 /* interruption data */
77 int omap_3_1_compatible_disable
;
80 struct omap_dma_channel_s
*sibling
;
82 struct omap_dma_reg_set_s
{
94 struct soc_dma_ch_s
*dma
;
96 /* unused parameters */
99 int interleave_disabled
;
106 struct soc_dma_s
*dma
;
109 struct omap_mpu_state_s
*mpu
;
112 void (*intr_update
)(struct omap_dma_s
*s
);
113 enum omap_dma_model model
;
114 int omap_3_1_mapping_disabled
;
123 struct omap_dma_channel_s ch
[32];
124 struct omap_dma_lcd_channel_s lcd_ch
;
128 #define TIMEOUT_INTR (1 << 0)
129 #define EVENT_DROP_INTR (1 << 1)
130 #define HALF_FRAME_INTR (1 << 2)
131 #define END_FRAME_INTR (1 << 3)
132 #define LAST_FRAME_INTR (1 << 4)
133 #define END_BLOCK_INTR (1 << 5)
134 #define SYNC (1 << 6)
135 #define END_PKT_INTR (1 << 7)
136 #define TRANS_ERR_INTR (1 << 8)
137 #define MISALIGN_INTR (1 << 11)
139 static inline void omap_dma_interrupts_update(struct omap_dma_s
*s
)
144 static void omap_dma_channel_load(struct omap_dma_channel_s
*ch
)
146 struct omap_dma_reg_set_s
*a
= &ch
->active_set
;
148 int omap_3_1
= !ch
->omap_3_1_compatible_disable
;
151 * TODO: verify address ranges and alignment
152 * TODO: port endianness
155 a
->src
= ch
->addr
[0];
156 a
->dest
= ch
->addr
[1];
157 a
->frames
= ch
->frames
;
158 a
->elements
= ch
->elements
;
159 a
->pck_elements
= ch
->frame_index
[!ch
->src_sync
];
164 if (unlikely(!ch
->elements
|| !ch
->frames
)) {
165 printf("%s: bad DMA request\n", __func__
);
169 for (i
= 0; i
< 2; i
++)
170 switch (ch
->mode
[i
]) {
172 a
->elem_delta
[i
] = 0;
173 a
->frame_delta
[i
] = 0;
175 case post_incremented
:
176 a
->elem_delta
[i
] = ch
->data_type
;
177 a
->frame_delta
[i
] = 0;
180 a
->elem_delta
[i
] = ch
->data_type
+
181 ch
->element_index
[omap_3_1
? 0 : i
] - 1;
182 a
->frame_delta
[i
] = 0;
185 a
->elem_delta
[i
] = ch
->data_type
+
186 ch
->element_index
[omap_3_1
? 0 : i
] - 1;
187 a
->frame_delta
[i
] = ch
->frame_index
[omap_3_1
? 0 : i
] -
188 ch
->element_index
[omap_3_1
? 0 : i
];
194 normal
= !ch
->transparent_copy
&& !ch
->constant_fill
&&
195 /* FIFO is big-endian so either (ch->endian[n] == 1) OR
196 * (ch->endian_lock[n] == 1) mean no endianism conversion. */
197 (ch
->endian
[0] | ch
->endian_lock
[0]) ==
198 (ch
->endian
[1] | ch
->endian_lock
[1]);
199 for (i
= 0; i
< 2; i
++) {
200 /* TODO: for a->frame_delta[i] > 0 still use the fast path, just
201 * limit min_elems in omap_dma_transfer_setup to the nearest frame
203 if (!a
->elem_delta
[i
] && normal
&&
204 (a
->frames
== 1 || !a
->frame_delta
[i
]))
205 ch
->dma
->type
[i
] = soc_dma_access_const
;
206 else if (a
->elem_delta
[i
] == ch
->data_type
&& normal
&&
207 (a
->frames
== 1 || !a
->frame_delta
[i
]))
208 ch
->dma
->type
[i
] = soc_dma_access_linear
;
210 ch
->dma
->type
[i
] = soc_dma_access_other
;
212 ch
->dma
->vaddr
[i
] = ch
->addr
[i
];
214 soc_dma_ch_update(ch
->dma
);
217 static void omap_dma_activate_channel(struct omap_dma_s
*s
,
218 struct omap_dma_channel_s
*ch
)
221 if (ch
->set_update
) {
222 /* It's not clear when the active set is supposed to be
223 * loaded from registers. We're already loading it when the
224 * channel is enabled, and for some guests this is not enough
225 * but that may be also because of a race condition (no
226 * delays in qemu) in the guest code, which we're just
227 * working around here. */
228 omap_dma_channel_load(ch
);
233 soc_dma_set_request(ch
->dma
, 1);
239 static void omap_dma_deactivate_channel(struct omap_dma_s
*s
,
240 struct omap_dma_channel_s
*ch
)
243 ch
->cpc
= ch
->active_set
.dest
& 0xffff;
245 if (ch
->pending_request
&& !ch
->waiting_end_prog
&& ch
->enable
) {
246 /* Don't deactivate the channel */
247 ch
->pending_request
= 0;
251 /* Don't deactive the channel if it is synchronized and the DMA request is
253 if (ch
->sync
&& ch
->enable
&& (s
->dma
->drqbmp
& (1ULL << ch
->sync
)))
259 soc_dma_set_request(ch
->dma
, 0);
263 static void omap_dma_enable_channel(struct omap_dma_s
*s
,
264 struct omap_dma_channel_s
*ch
)
268 ch
->waiting_end_prog
= 0;
269 omap_dma_channel_load(ch
);
270 /* TODO: theoretically if ch->sync && ch->prefetch &&
271 * !s->dma->drqbmp[ch->sync], we should also activate and fetch
272 * from source and then stall until signalled. */
273 if ((!ch
->sync
) || (s
->dma
->drqbmp
& (1ULL << ch
->sync
))) {
274 omap_dma_activate_channel(s
, ch
);
279 static void omap_dma_disable_channel(struct omap_dma_s
*s
,
280 struct omap_dma_channel_s
*ch
)
284 /* Discard any pending request */
285 ch
->pending_request
= 0;
286 omap_dma_deactivate_channel(s
, ch
);
290 static void omap_dma_channel_end_prog(struct omap_dma_s
*s
,
291 struct omap_dma_channel_s
*ch
)
293 if (ch
->waiting_end_prog
) {
294 ch
->waiting_end_prog
= 0;
295 if (!ch
->sync
|| ch
->pending_request
) {
296 ch
->pending_request
= 0;
297 omap_dma_activate_channel(s
, ch
);
302 static void omap_dma_interrupts_3_1_update(struct omap_dma_s
*s
)
304 struct omap_dma_channel_s
*ch
= s
->ch
;
306 /* First three interrupts are shared between two channels each. */
307 if (ch
[0].status
| ch
[6].status
)
308 qemu_irq_raise(ch
[0].irq
);
309 if (ch
[1].status
| ch
[7].status
)
310 qemu_irq_raise(ch
[1].irq
);
311 if (ch
[2].status
| ch
[8].status
)
312 qemu_irq_raise(ch
[2].irq
);
314 qemu_irq_raise(ch
[3].irq
);
316 qemu_irq_raise(ch
[4].irq
);
318 qemu_irq_raise(ch
[5].irq
);
321 static void omap_dma_interrupts_3_2_update(struct omap_dma_s
*s
)
323 struct omap_dma_channel_s
*ch
= s
->ch
;
326 for (i
= s
->chans
; i
; ch
++, i
--)
328 qemu_irq_raise(ch
->irq
);
331 static void omap_dma_enable_3_1_mapping(struct omap_dma_s
*s
)
333 s
->omap_3_1_mapping_disabled
= 0;
335 s
->intr_update
= omap_dma_interrupts_3_1_update
;
338 static void omap_dma_disable_3_1_mapping(struct omap_dma_s
*s
)
340 s
->omap_3_1_mapping_disabled
= 1;
342 s
->intr_update
= omap_dma_interrupts_3_2_update
;
345 static void omap_dma_process_request(struct omap_dma_s
*s
, int request
)
349 struct omap_dma_channel_s
*ch
= s
->ch
;
351 for (channel
= 0; channel
< s
->chans
; channel
++, ch
++) {
352 if (ch
->enable
&& ch
->sync
== request
) {
354 omap_dma_activate_channel(s
, ch
);
355 else if (!ch
->pending_request
)
356 ch
->pending_request
= 1;
358 /* Request collision */
359 /* Second request received while processing other request */
360 ch
->status
|= EVENT_DROP_INTR
;
367 omap_dma_interrupts_update(s
);
370 static void omap_dma_transfer_generic(struct soc_dma_ch_s
*dma
)
373 struct omap_dma_channel_s
*ch
= dma
->opaque
;
374 struct omap_dma_reg_set_s
*a
= &ch
->active_set
;
375 int bytes
= dma
->bytes
;
377 uint16_t status
= ch
->status
;
381 /* Transfer a single element */
382 /* FIXME: check the endianness */
383 if (!ch
->constant_fill
)
384 cpu_physical_memory_read(a
->src
, value
, ch
->data_type
);
386 *(uint32_t *) value
= ch
->color
;
388 if (!ch
->transparent_copy
|| *(uint32_t *) value
!= ch
->color
)
389 cpu_physical_memory_write(a
->dest
, value
, ch
->data_type
);
391 a
->src
+= a
->elem_delta
[0];
392 a
->dest
+= a
->elem_delta
[1];
396 if (a
->element
== a
->elements
) {
399 a
->src
+= a
->frame_delta
[0];
400 a
->dest
+= a
->frame_delta
[1];
403 /* If the channel is async, update cpc */
405 ch
->cpc
= a
->dest
& 0xffff;
407 } while ((bytes
-= ch
->data_type
));
409 /* If the channel is element synchronized, deactivate it */
410 if (ch
->sync
&& !ch
->fs
&& !ch
->bs
)
411 omap_dma_deactivate_channel(s
, ch
);
413 /* If it is the last frame, set the LAST_FRAME interrupt */
414 if (a
->element
== 1 && a
->frame
== a
->frames
- 1)
415 if (ch
->interrupts
& LAST_FRAME_INTR
)
416 ch
->status
|= LAST_FRAME_INTR
;
418 /* If the half of the frame was reached, set the HALF_FRAME
420 if (a
->element
== (a
->elements
>> 1))
421 if (ch
->interrupts
& HALF_FRAME_INTR
)
422 ch
->status
|= HALF_FRAME_INTR
;
424 if (ch
->fs
&& ch
->bs
) {
426 /* Check if a full packet has beed transferred. */
427 if (a
->pck_element
== a
->pck_elements
) {
430 /* Set the END_PKT interrupt */
431 if ((ch
->interrupts
& END_PKT_INTR
) && !ch
->src_sync
)
432 ch
->status
|= END_PKT_INTR
;
434 /* If the channel is packet-synchronized, deactivate it */
436 omap_dma_deactivate_channel(s
, ch
);
440 if (a
->element
== a
->elements
) {
443 a
->src
+= a
->frame_delta
[0];
444 a
->dest
+= a
->frame_delta
[1];
447 /* If the channel is frame synchronized, deactivate it */
448 if (ch
->sync
&& ch
->fs
&& !ch
->bs
)
449 omap_dma_deactivate_channel(s
, ch
);
451 /* If the channel is async, update cpc */
453 ch
->cpc
= a
->dest
& 0xffff;
455 /* Set the END_FRAME interrupt */
456 if (ch
->interrupts
& END_FRAME_INTR
)
457 ch
->status
|= END_FRAME_INTR
;
459 if (a
->frame
== a
->frames
) {
461 /* Disable the channel */
463 if (ch
->omap_3_1_compatible_disable
) {
464 omap_dma_disable_channel(s
, ch
);
465 if (ch
->link_enabled
)
466 omap_dma_enable_channel(s
,
467 &s
->ch
[ch
->link_next_ch
]);
470 omap_dma_disable_channel(s
, ch
);
471 else if (ch
->repeat
|| ch
->end_prog
)
472 omap_dma_channel_load(ch
);
474 ch
->waiting_end_prog
= 1;
475 omap_dma_deactivate_channel(s
, ch
);
479 if (ch
->interrupts
& END_BLOCK_INTR
)
480 ch
->status
|= END_BLOCK_INTR
;
483 } while (status
== ch
->status
&& ch
->active
);
485 omap_dma_interrupts_update(s
);
490 omap_dma_intr_element_sync
,
491 omap_dma_intr_last_frame
,
492 omap_dma_intr_half_frame
,
494 omap_dma_intr_frame_sync
,
495 omap_dma_intr_packet
,
496 omap_dma_intr_packet_sync
,
498 __omap_dma_intr_last
,
501 static void omap_dma_transfer_setup(struct soc_dma_ch_s
*dma
)
503 struct omap_dma_port_if_s
*src_p
, *dest_p
;
504 struct omap_dma_reg_set_s
*a
;
505 struct omap_dma_channel_s
*ch
= dma
->opaque
;
506 struct omap_dma_s
*s
= dma
->dma
->opaque
;
507 int frames
, min_elems
, elements
[__omap_dma_intr_last
];
511 src_p
= &s
->mpu
->port
[ch
->port
[0]];
512 dest_p
= &s
->mpu
->port
[ch
->port
[1]];
513 if ((!ch
->constant_fill
&& !src_p
->addr_valid(s
->mpu
, a
->src
)) ||
514 (!dest_p
->addr_valid(s
->mpu
, a
->dest
))) {
517 if (ch
->interrupts
& TIMEOUT_INTR
)
518 ch
->status
|= TIMEOUT_INTR
;
519 omap_dma_deactivate_channel(s
, ch
);
522 printf("%s: Bus time-out in DMA%i operation\n",
528 /* Check all the conditions that terminate the transfer starting
529 * with those that can occur the soonest. */
530 #define INTR_CHECK(cond, id, nelements) \
532 elements[id] = nelements; \
533 if (elements[id] < min_elems) \
534 min_elems = elements[id]; \
536 elements[id] = INT_MAX;
540 ch
->sync
&& !ch
->fs
&& !ch
->bs
,
541 omap_dma_intr_element_sync
,
545 /* TODO: for transfers where entire frames can be read and written
546 * using memcpy() but a->frame_delta is non-zero, try to still do
547 * transfers using soc_dma but limit min_elems to a->elements - ...
548 * See also the TODO in omap_dma_channel_load. */
550 (ch
->interrupts
& LAST_FRAME_INTR
) &&
551 ((a
->frame
< a
->frames
- 1) || !a
->element
),
552 omap_dma_intr_last_frame
,
553 (a
->frames
- a
->frame
- 2) * a
->elements
+
554 (a
->elements
- a
->element
+ 1))
556 ch
->interrupts
& HALF_FRAME_INTR
,
557 omap_dma_intr_half_frame
,
559 (a
->element
>= (a
->elements
>> 1) ? a
->elements
: 0) -
562 ch
->sync
&& ch
->fs
&& (ch
->interrupts
& END_FRAME_INTR
),
564 a
->elements
- a
->element
)
566 ch
->sync
&& ch
->fs
&& !ch
->bs
,
567 omap_dma_intr_frame_sync
,
568 a
->elements
- a
->element
)
573 (ch
->interrupts
& END_PKT_INTR
) && !ch
->src_sync
,
574 omap_dma_intr_packet
,
575 a
->pck_elements
- a
->pck_element
)
577 ch
->fs
&& ch
->bs
&& ch
->sync
,
578 omap_dma_intr_packet_sync
,
579 a
->pck_elements
- a
->pck_element
)
585 (a
->frames
- a
->frame
- 1) * a
->elements
+
586 (a
->elements
- a
->element
))
588 dma
->bytes
= min_elems
* ch
->data_type
;
590 /* Set appropriate interrupts and/or deactivate channels */
593 /* TODO: should all of this only be done if dma->update, and otherwise
594 * inside omap_dma_transfer_generic below - check what's faster. */
598 /* If the channel is element synchronized, deactivate it */
599 if (min_elems
== elements
[omap_dma_intr_element_sync
])
600 omap_dma_deactivate_channel(s
, ch
);
602 /* If it is the last frame, set the LAST_FRAME interrupt */
603 if (min_elems
== elements
[omap_dma_intr_last_frame
])
604 ch
->status
|= LAST_FRAME_INTR
;
606 /* If exactly half of the frame was reached, set the HALF_FRAME
608 if (min_elems
== elements
[omap_dma_intr_half_frame
])
609 ch
->status
|= HALF_FRAME_INTR
;
611 /* If a full packet has been transferred, set the END_PKT interrupt */
612 if (min_elems
== elements
[omap_dma_intr_packet
])
613 ch
->status
|= END_PKT_INTR
;
615 /* If the channel is packet-synchronized, deactivate it */
616 if (min_elems
== elements
[omap_dma_intr_packet_sync
])
617 omap_dma_deactivate_channel(s
, ch
);
619 /* If the channel is frame synchronized, deactivate it */
620 if (min_elems
== elements
[omap_dma_intr_frame_sync
])
621 omap_dma_deactivate_channel(s
, ch
);
623 /* Set the END_FRAME interrupt */
624 if (min_elems
== elements
[omap_dma_intr_frame
])
625 ch
->status
|= END_FRAME_INTR
;
627 if (min_elems
== elements
[omap_dma_intr_block
]) {
629 /* Disable the channel */
631 if (ch
->omap_3_1_compatible_disable
) {
632 omap_dma_disable_channel(s
, ch
);
633 if (ch
->link_enabled
)
634 omap_dma_enable_channel(s
, &s
->ch
[ch
->link_next_ch
]);
637 omap_dma_disable_channel(s
, ch
);
638 else if (ch
->repeat
|| ch
->end_prog
)
639 omap_dma_channel_load(ch
);
641 ch
->waiting_end_prog
= 1;
642 omap_dma_deactivate_channel(s
, ch
);
646 if (ch
->interrupts
& END_BLOCK_INTR
)
647 ch
->status
|= END_BLOCK_INTR
;
650 /* Update packet number */
651 if (ch
->fs
&& ch
->bs
) {
652 a
->pck_element
+= min_elems
;
653 a
->pck_element
%= a
->pck_elements
;
656 /* TODO: check if we really need to update anything here or perhaps we
657 * can skip part of this. */
661 a
->element
+= min_elems
;
663 frames
= a
->element
/ a
->elements
;
664 a
->element
= a
->element
% a
->elements
;
666 a
->src
+= min_elems
* a
->elem_delta
[0] + frames
* a
->frame_delta
[0];
667 a
->dest
+= min_elems
* a
->elem_delta
[1] + frames
* a
->frame_delta
[1];
669 /* If the channel is async, update cpc */
670 if (!ch
->sync
&& frames
)
671 ch
->cpc
= a
->dest
& 0xffff;
673 /* TODO: if the destination port is IMIF or EMIFF, set the dirty
681 omap_dma_interrupts_update(s
);
684 void omap_dma_reset(struct soc_dma_s
*dma
)
687 struct omap_dma_s
*s
= dma
->opaque
;
689 soc_dma_reset(s
->dma
);
690 if (s
->model
< omap_dma_4
)
695 memset(&s
->irqstat
, 0, sizeof(s
->irqstat
));
696 memset(&s
->irqen
, 0, sizeof(s
->irqen
));
697 s
->lcd_ch
.src
= emiff
;
698 s
->lcd_ch
.condition
= 0;
699 s
->lcd_ch
.interrupts
= 0;
701 if (s
->model
< omap_dma_4
)
702 omap_dma_enable_3_1_mapping(s
);
703 for (i
= 0; i
< s
->chans
; i
++) {
704 s
->ch
[i
].suspend
= 0;
705 s
->ch
[i
].prefetch
= 0;
706 s
->ch
[i
].buf_disable
= 0;
707 s
->ch
[i
].src_sync
= 0;
708 memset(&s
->ch
[i
].burst
, 0, sizeof(s
->ch
[i
].burst
));
709 memset(&s
->ch
[i
].port
, 0, sizeof(s
->ch
[i
].port
));
710 memset(&s
->ch
[i
].mode
, 0, sizeof(s
->ch
[i
].mode
));
711 memset(&s
->ch
[i
].frame_index
, 0, sizeof(s
->ch
[i
].frame_index
));
712 memset(&s
->ch
[i
].element_index
, 0, sizeof(s
->ch
[i
].element_index
));
713 memset(&s
->ch
[i
].endian
, 0, sizeof(s
->ch
[i
].endian
));
714 memset(&s
->ch
[i
].endian_lock
, 0, sizeof(s
->ch
[i
].endian_lock
));
715 memset(&s
->ch
[i
].translate
, 0, sizeof(s
->ch
[i
].translate
));
716 s
->ch
[i
].write_mode
= 0;
717 s
->ch
[i
].data_type
= 0;
718 s
->ch
[i
].transparent_copy
= 0;
719 s
->ch
[i
].constant_fill
= 0;
720 s
->ch
[i
].color
= 0x00000000;
721 s
->ch
[i
].end_prog
= 0;
723 s
->ch
[i
].auto_init
= 0;
724 s
->ch
[i
].link_enabled
= 0;
725 if (s
->model
< omap_dma_4
)
726 s
->ch
[i
].interrupts
= 0x0003;
728 s
->ch
[i
].interrupts
= 0x0000;
730 s
->ch
[i
].cstatus
= 0;
734 s
->ch
[i
].pending_request
= 0;
735 s
->ch
[i
].waiting_end_prog
= 0;
736 s
->ch
[i
].cpc
= 0x0000;
739 s
->ch
[i
].omap_3_1_compatible_disable
= 0;
740 memset(&s
->ch
[i
].active_set
, 0, sizeof(s
->ch
[i
].active_set
));
741 s
->ch
[i
].priority
= 0;
742 s
->ch
[i
].interleave_disabled
= 0;
747 static int omap_dma_ch_reg_read(struct omap_dma_s
*s
,
748 struct omap_dma_channel_s
*ch
, int reg
, uint16_t *value
)
751 case 0x00: /* SYS_DMA_CSDP_CH0 */
752 *value
= (ch
->burst
[1] << 14) |
753 (ch
->pack
[1] << 13) |
755 (ch
->burst
[0] << 7) |
758 (ch
->data_type
>> 1);
761 case 0x02: /* SYS_DMA_CCR_CH0 */
762 if (s
->model
<= omap_dma_3_1
)
763 *value
= 0 << 10; /* FIFO_FLUSH reads as 0 */
765 *value
= ch
->omap_3_1_compatible_disable
<< 10;
766 *value
|= (ch
->mode
[1] << 14) |
767 (ch
->mode
[0] << 12) |
768 (ch
->end_prog
<< 11) |
770 (ch
->auto_init
<< 8) |
772 (ch
->priority
<< 6) |
773 (ch
->fs
<< 5) | ch
->sync
;
776 case 0x04: /* SYS_DMA_CICR_CH0 */
777 *value
= ch
->interrupts
;
780 case 0x06: /* SYS_DMA_CSR_CH0 */
783 if (!ch
->omap_3_1_compatible_disable
&& ch
->sibling
) {
784 *value
|= (ch
->sibling
->status
& 0x3f) << 6;
785 ch
->sibling
->status
&= SYNC
;
787 qemu_irq_lower(ch
->irq
);
790 case 0x08: /* SYS_DMA_CSSA_L_CH0 */
791 *value
= ch
->addr
[0] & 0x0000ffff;
794 case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
795 *value
= ch
->addr
[0] >> 16;
798 case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
799 *value
= ch
->addr
[1] & 0x0000ffff;
802 case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
803 *value
= ch
->addr
[1] >> 16;
806 case 0x10: /* SYS_DMA_CEN_CH0 */
807 *value
= ch
->elements
;
810 case 0x12: /* SYS_DMA_CFN_CH0 */
814 case 0x14: /* SYS_DMA_CFI_CH0 */
815 *value
= ch
->frame_index
[0];
818 case 0x16: /* SYS_DMA_CEI_CH0 */
819 *value
= ch
->element_index
[0];
822 case 0x18: /* SYS_DMA_CPC_CH0 or DMA_CSAC */
823 if (ch
->omap_3_1_compatible_disable
)
824 *value
= ch
->active_set
.src
& 0xffff; /* CSAC */
829 case 0x1a: /* DMA_CDAC */
830 *value
= ch
->active_set
.dest
& 0xffff; /* CDAC */
833 case 0x1c: /* DMA_CDEI */
834 *value
= ch
->element_index
[1];
837 case 0x1e: /* DMA_CDFI */
838 *value
= ch
->frame_index
[1];
841 case 0x20: /* DMA_COLOR_L */
842 *value
= ch
->color
& 0xffff;
845 case 0x22: /* DMA_COLOR_U */
846 *value
= ch
->color
>> 16;
849 case 0x24: /* DMA_CCR2 */
850 *value
= (ch
->bs
<< 2) |
851 (ch
->transparent_copy
<< 1) |
855 case 0x28: /* DMA_CLNK_CTRL */
856 *value
= (ch
->link_enabled
<< 15) |
857 (ch
->link_next_ch
& 0xf);
860 case 0x2a: /* DMA_LCH_CTRL */
861 *value
= (ch
->interleave_disabled
<< 15) |
871 static int omap_dma_ch_reg_write(struct omap_dma_s
*s
,
872 struct omap_dma_channel_s
*ch
, int reg
, uint16_t value
)
875 case 0x00: /* SYS_DMA_CSDP_CH0 */
876 ch
->burst
[1] = (value
& 0xc000) >> 14;
877 ch
->pack
[1] = (value
& 0x2000) >> 13;
878 ch
->port
[1] = (enum omap_dma_port
) ((value
& 0x1e00) >> 9);
879 ch
->burst
[0] = (value
& 0x0180) >> 7;
880 ch
->pack
[0] = (value
& 0x0040) >> 6;
881 ch
->port
[0] = (enum omap_dma_port
) ((value
& 0x003c) >> 2);
882 if (ch
->port
[0] >= __omap_dma_port_last
) {
883 qemu_log_mask(LOG_GUEST_ERROR
, "%s: invalid DMA port %i\n",
884 __func__
, ch
->port
[0]);
886 if (ch
->port
[1] >= __omap_dma_port_last
) {
887 qemu_log_mask(LOG_GUEST_ERROR
, "%s: invalid DMA port %i\n",
888 __func__
, ch
->port
[1]);
890 ch
->data_type
= 1 << (value
& 3);
891 if ((value
& 3) == 3) {
892 qemu_log_mask(LOG_GUEST_ERROR
,
893 "%s: bad data_type for DMA channel\n", __func__
);
898 case 0x02: /* SYS_DMA_CCR_CH0 */
899 ch
->mode
[1] = (omap_dma_addressing_t
) ((value
& 0xc000) >> 14);
900 ch
->mode
[0] = (omap_dma_addressing_t
) ((value
& 0x3000) >> 12);
901 ch
->end_prog
= (value
& 0x0800) >> 11;
902 if (s
->model
>= omap_dma_3_2
)
903 ch
->omap_3_1_compatible_disable
= (value
>> 10) & 0x1;
904 ch
->repeat
= (value
& 0x0200) >> 9;
905 ch
->auto_init
= (value
& 0x0100) >> 8;
906 ch
->priority
= (value
& 0x0040) >> 6;
907 ch
->fs
= (value
& 0x0020) >> 5;
908 ch
->sync
= value
& 0x001f;
911 omap_dma_enable_channel(s
, ch
);
913 omap_dma_disable_channel(s
, ch
);
916 omap_dma_channel_end_prog(s
, ch
);
920 case 0x04: /* SYS_DMA_CICR_CH0 */
921 ch
->interrupts
= value
& 0x3f;
924 case 0x06: /* SYS_DMA_CSR_CH0 */
925 OMAP_RO_REG((hwaddr
) reg
);
928 case 0x08: /* SYS_DMA_CSSA_L_CH0 */
929 ch
->addr
[0] &= 0xffff0000;
930 ch
->addr
[0] |= value
;
933 case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
934 ch
->addr
[0] &= 0x0000ffff;
935 ch
->addr
[0] |= (uint32_t) value
<< 16;
938 case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
939 ch
->addr
[1] &= 0xffff0000;
940 ch
->addr
[1] |= value
;
943 case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
944 ch
->addr
[1] &= 0x0000ffff;
945 ch
->addr
[1] |= (uint32_t) value
<< 16;
948 case 0x10: /* SYS_DMA_CEN_CH0 */
949 ch
->elements
= value
;
952 case 0x12: /* SYS_DMA_CFN_CH0 */
956 case 0x14: /* SYS_DMA_CFI_CH0 */
957 ch
->frame_index
[0] = (int16_t) value
;
960 case 0x16: /* SYS_DMA_CEI_CH0 */
961 ch
->element_index
[0] = (int16_t) value
;
964 case 0x18: /* SYS_DMA_CPC_CH0 or DMA_CSAC */
965 OMAP_RO_REG((hwaddr
) reg
);
968 case 0x1c: /* DMA_CDEI */
969 ch
->element_index
[1] = (int16_t) value
;
972 case 0x1e: /* DMA_CDFI */
973 ch
->frame_index
[1] = (int16_t) value
;
976 case 0x20: /* DMA_COLOR_L */
977 ch
->color
&= 0xffff0000;
981 case 0x22: /* DMA_COLOR_U */
983 ch
->color
|= (uint32_t)value
<< 16;
986 case 0x24: /* DMA_CCR2 */
987 ch
->bs
= (value
>> 2) & 0x1;
988 ch
->transparent_copy
= (value
>> 1) & 0x1;
989 ch
->constant_fill
= value
& 0x1;
992 case 0x28: /* DMA_CLNK_CTRL */
993 ch
->link_enabled
= (value
>> 15) & 0x1;
994 if (value
& (1 << 14)) { /* Stop_Lnk */
995 ch
->link_enabled
= 0;
996 omap_dma_disable_channel(s
, ch
);
998 ch
->link_next_ch
= value
& 0x1f;
1001 case 0x2a: /* DMA_LCH_CTRL */
1002 ch
->interleave_disabled
= (value
>> 15) & 0x1;
1003 ch
->type
= value
& 0xf;
1012 static int omap_dma_3_2_lcd_write(struct omap_dma_lcd_channel_s
*s
, int offset
,
1016 case 0xbc0: /* DMA_LCD_CSDP */
1017 s
->brust_f2
= (value
>> 14) & 0x3;
1018 s
->pack_f2
= (value
>> 13) & 0x1;
1019 s
->data_type_f2
= (1 << ((value
>> 11) & 0x3));
1020 s
->brust_f1
= (value
>> 7) & 0x3;
1021 s
->pack_f1
= (value
>> 6) & 0x1;
1022 s
->data_type_f1
= (1 << ((value
>> 0) & 0x3));
1025 case 0xbc2: /* DMA_LCD_CCR */
1026 s
->mode_f2
= (value
>> 14) & 0x3;
1027 s
->mode_f1
= (value
>> 12) & 0x3;
1028 s
->end_prog
= (value
>> 11) & 0x1;
1029 s
->omap_3_1_compatible_disable
= (value
>> 10) & 0x1;
1030 s
->repeat
= (value
>> 9) & 0x1;
1031 s
->auto_init
= (value
>> 8) & 0x1;
1032 s
->running
= (value
>> 7) & 0x1;
1033 s
->priority
= (value
>> 6) & 0x1;
1034 s
->bs
= (value
>> 4) & 0x1;
1037 case 0xbc4: /* DMA_LCD_CTRL */
1038 s
->dst
= (value
>> 8) & 0x1;
1039 s
->src
= ((value
>> 6) & 0x3) << 1;
1041 /* Assume no bus errors and thus no BUS_ERROR irq bits. */
1042 s
->interrupts
= (value
>> 1) & 1;
1043 s
->dual
= value
& 1;
1046 case 0xbc8: /* TOP_B1_L */
1047 s
->src_f1_top
&= 0xffff0000;
1048 s
->src_f1_top
|= 0x0000ffff & value
;
1051 case 0xbca: /* TOP_B1_U */
1052 s
->src_f1_top
&= 0x0000ffff;
1053 s
->src_f1_top
|= (uint32_t)value
<< 16;
1056 case 0xbcc: /* BOT_B1_L */
1057 s
->src_f1_bottom
&= 0xffff0000;
1058 s
->src_f1_bottom
|= 0x0000ffff & value
;
1061 case 0xbce: /* BOT_B1_U */
1062 s
->src_f1_bottom
&= 0x0000ffff;
1063 s
->src_f1_bottom
|= (uint32_t) value
<< 16;
1066 case 0xbd0: /* TOP_B2_L */
1067 s
->src_f2_top
&= 0xffff0000;
1068 s
->src_f2_top
|= 0x0000ffff & value
;
1071 case 0xbd2: /* TOP_B2_U */
1072 s
->src_f2_top
&= 0x0000ffff;
1073 s
->src_f2_top
|= (uint32_t) value
<< 16;
1076 case 0xbd4: /* BOT_B2_L */
1077 s
->src_f2_bottom
&= 0xffff0000;
1078 s
->src_f2_bottom
|= 0x0000ffff & value
;
1081 case 0xbd6: /* BOT_B2_U */
1082 s
->src_f2_bottom
&= 0x0000ffff;
1083 s
->src_f2_bottom
|= (uint32_t) value
<< 16;
1086 case 0xbd8: /* DMA_LCD_SRC_EI_B1 */
1087 s
->element_index_f1
= value
;
1090 case 0xbda: /* DMA_LCD_SRC_FI_B1_L */
1091 s
->frame_index_f1
&= 0xffff0000;
1092 s
->frame_index_f1
|= 0x0000ffff & value
;
1095 case 0xbf4: /* DMA_LCD_SRC_FI_B1_U */
1096 s
->frame_index_f1
&= 0x0000ffff;
1097 s
->frame_index_f1
|= (uint32_t) value
<< 16;
1100 case 0xbdc: /* DMA_LCD_SRC_EI_B2 */
1101 s
->element_index_f2
= value
;
1104 case 0xbde: /* DMA_LCD_SRC_FI_B2_L */
1105 s
->frame_index_f2
&= 0xffff0000;
1106 s
->frame_index_f2
|= 0x0000ffff & value
;
1109 case 0xbf6: /* DMA_LCD_SRC_FI_B2_U */
1110 s
->frame_index_f2
&= 0x0000ffff;
1111 s
->frame_index_f2
|= (uint32_t) value
<< 16;
1114 case 0xbe0: /* DMA_LCD_SRC_EN_B1 */
1115 s
->elements_f1
= value
;
1118 case 0xbe4: /* DMA_LCD_SRC_FN_B1 */
1119 s
->frames_f1
= value
;
1122 case 0xbe2: /* DMA_LCD_SRC_EN_B2 */
1123 s
->elements_f2
= value
;
1126 case 0xbe6: /* DMA_LCD_SRC_FN_B2 */
1127 s
->frames_f2
= value
;
1130 case 0xbea: /* DMA_LCD_LCH_CTRL */
1131 s
->lch_type
= value
& 0xf;
1140 static int omap_dma_3_2_lcd_read(struct omap_dma_lcd_channel_s
*s
, int offset
,
1144 case 0xbc0: /* DMA_LCD_CSDP */
1145 *ret
= (s
->brust_f2
<< 14) |
1146 (s
->pack_f2
<< 13) |
1147 ((s
->data_type_f2
>> 1) << 11) |
1148 (s
->brust_f1
<< 7) |
1150 ((s
->data_type_f1
>> 1) << 0);
1153 case 0xbc2: /* DMA_LCD_CCR */
1154 *ret
= (s
->mode_f2
<< 14) |
1155 (s
->mode_f1
<< 12) |
1156 (s
->end_prog
<< 11) |
1157 (s
->omap_3_1_compatible_disable
<< 10) |
1159 (s
->auto_init
<< 8) |
1161 (s
->priority
<< 6) |
1165 case 0xbc4: /* DMA_LCD_CTRL */
1166 qemu_irq_lower(s
->irq
);
1167 *ret
= (s
->dst
<< 8) |
1168 ((s
->src
& 0x6) << 5) |
1169 (s
->condition
<< 3) |
1170 (s
->interrupts
<< 1) |
1174 case 0xbc8: /* TOP_B1_L */
1175 *ret
= s
->src_f1_top
& 0xffff;
1178 case 0xbca: /* TOP_B1_U */
1179 *ret
= s
->src_f1_top
>> 16;
1182 case 0xbcc: /* BOT_B1_L */
1183 *ret
= s
->src_f1_bottom
& 0xffff;
1186 case 0xbce: /* BOT_B1_U */
1187 *ret
= s
->src_f1_bottom
>> 16;
1190 case 0xbd0: /* TOP_B2_L */
1191 *ret
= s
->src_f2_top
& 0xffff;
1194 case 0xbd2: /* TOP_B2_U */
1195 *ret
= s
->src_f2_top
>> 16;
1198 case 0xbd4: /* BOT_B2_L */
1199 *ret
= s
->src_f2_bottom
& 0xffff;
1202 case 0xbd6: /* BOT_B2_U */
1203 *ret
= s
->src_f2_bottom
>> 16;
1206 case 0xbd8: /* DMA_LCD_SRC_EI_B1 */
1207 *ret
= s
->element_index_f1
;
1210 case 0xbda: /* DMA_LCD_SRC_FI_B1_L */
1211 *ret
= s
->frame_index_f1
& 0xffff;
1214 case 0xbf4: /* DMA_LCD_SRC_FI_B1_U */
1215 *ret
= s
->frame_index_f1
>> 16;
1218 case 0xbdc: /* DMA_LCD_SRC_EI_B2 */
1219 *ret
= s
->element_index_f2
;
1222 case 0xbde: /* DMA_LCD_SRC_FI_B2_L */
1223 *ret
= s
->frame_index_f2
& 0xffff;
1226 case 0xbf6: /* DMA_LCD_SRC_FI_B2_U */
1227 *ret
= s
->frame_index_f2
>> 16;
1230 case 0xbe0: /* DMA_LCD_SRC_EN_B1 */
1231 *ret
= s
->elements_f1
;
1234 case 0xbe4: /* DMA_LCD_SRC_FN_B1 */
1235 *ret
= s
->frames_f1
;
1238 case 0xbe2: /* DMA_LCD_SRC_EN_B2 */
1239 *ret
= s
->elements_f2
;
1242 case 0xbe6: /* DMA_LCD_SRC_FN_B2 */
1243 *ret
= s
->frames_f2
;
1246 case 0xbea: /* DMA_LCD_LCH_CTRL */
1256 static int omap_dma_3_1_lcd_write(struct omap_dma_lcd_channel_s
*s
, int offset
,
1260 case 0x300: /* SYS_DMA_LCD_CTRL */
1261 s
->src
= (value
& 0x40) ? imif
: emiff
;
1263 /* Assume no bus errors and thus no BUS_ERROR irq bits. */
1264 s
->interrupts
= (value
>> 1) & 1;
1265 s
->dual
= value
& 1;
1268 case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
1269 s
->src_f1_top
&= 0xffff0000;
1270 s
->src_f1_top
|= 0x0000ffff & value
;
1273 case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
1274 s
->src_f1_top
&= 0x0000ffff;
1275 s
->src_f1_top
|= (uint32_t)value
<< 16;
1278 case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
1279 s
->src_f1_bottom
&= 0xffff0000;
1280 s
->src_f1_bottom
|= 0x0000ffff & value
;
1283 case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
1284 s
->src_f1_bottom
&= 0x0000ffff;
1285 s
->src_f1_bottom
|= (uint32_t)value
<< 16;
1288 case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
1289 s
->src_f2_top
&= 0xffff0000;
1290 s
->src_f2_top
|= 0x0000ffff & value
;
1293 case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
1294 s
->src_f2_top
&= 0x0000ffff;
1295 s
->src_f2_top
|= (uint32_t)value
<< 16;
1298 case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
1299 s
->src_f2_bottom
&= 0xffff0000;
1300 s
->src_f2_bottom
|= 0x0000ffff & value
;
1303 case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
1304 s
->src_f2_bottom
&= 0x0000ffff;
1305 s
->src_f2_bottom
|= (uint32_t)value
<< 16;
1314 static int omap_dma_3_1_lcd_read(struct omap_dma_lcd_channel_s
*s
, int offset
,
1320 case 0x300: /* SYS_DMA_LCD_CTRL */
1323 qemu_irq_lower(s
->irq
);
1324 *ret
= ((s
->src
== imif
) << 6) | (i
<< 3) |
1325 (s
->interrupts
<< 1) | s
->dual
;
1328 case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
1329 *ret
= s
->src_f1_top
& 0xffff;
1332 case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
1333 *ret
= s
->src_f1_top
>> 16;
1336 case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
1337 *ret
= s
->src_f1_bottom
& 0xffff;
1340 case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
1341 *ret
= s
->src_f1_bottom
>> 16;
1344 case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
1345 *ret
= s
->src_f2_top
& 0xffff;
1348 case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
1349 *ret
= s
->src_f2_top
>> 16;
1352 case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
1353 *ret
= s
->src_f2_bottom
& 0xffff;
1356 case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
1357 *ret
= s
->src_f2_bottom
>> 16;
1366 static int omap_dma_sys_write(struct omap_dma_s
*s
, int offset
, uint16_t value
)
1369 case 0x400: /* SYS_DMA_GCR */
1373 case 0x404: /* DMA_GSCR */
1375 omap_dma_disable_3_1_mapping(s
);
1377 omap_dma_enable_3_1_mapping(s
);
1380 case 0x408: /* DMA_GRST */
1382 omap_dma_reset(s
->dma
);
1391 static int omap_dma_sys_read(struct omap_dma_s
*s
, int offset
,
1395 case 0x400: /* SYS_DMA_GCR */
1399 case 0x404: /* DMA_GSCR */
1400 *ret
= s
->omap_3_1_mapping_disabled
<< 3;
1403 case 0x408: /* DMA_GRST */
1407 case 0x442: /* DMA_HW_ID */
1408 case 0x444: /* DMA_PCh2_ID */
1409 case 0x446: /* DMA_PCh0_ID */
1410 case 0x448: /* DMA_PCh1_ID */
1411 case 0x44a: /* DMA_PChG_ID */
1412 case 0x44c: /* DMA_PChD_ID */
1416 case 0x44e: /* DMA_CAPS_0_U */
1417 *ret
= (s
->caps
[0] >> 16) & 0xffff;
1419 case 0x450: /* DMA_CAPS_0_L */
1420 *ret
= (s
->caps
[0] >> 0) & 0xffff;
1423 case 0x452: /* DMA_CAPS_1_U */
1424 *ret
= (s
->caps
[1] >> 16) & 0xffff;
1426 case 0x454: /* DMA_CAPS_1_L */
1427 *ret
= (s
->caps
[1] >> 0) & 0xffff;
1430 case 0x456: /* DMA_CAPS_2 */
1434 case 0x458: /* DMA_CAPS_3 */
1438 case 0x45a: /* DMA_CAPS_4 */
1442 case 0x460: /* DMA_PCh2_SR */
1443 case 0x480: /* DMA_PCh0_SR */
1444 case 0x482: /* DMA_PCh1_SR */
1445 case 0x4c0: /* DMA_PChD_SR_0 */
1446 qemu_log_mask(LOG_UNIMP
,
1447 "%s: Physical Channel Status Registers not implemented\n",
1458 static uint64_t omap_dma_read(void *opaque
, hwaddr addr
,
1461 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1466 return omap_badwidth_read16(opaque
, addr
);
1470 case 0x300 ... 0x3fe:
1471 if (s
->model
<= omap_dma_3_1
|| !s
->omap_3_1_mapping_disabled
) {
1472 if (omap_dma_3_1_lcd_read(&s
->lcd_ch
, addr
, &ret
))
1477 case 0x000 ... 0x2fe:
1479 ch
= (addr
>> 6) & 0x0f;
1480 if (omap_dma_ch_reg_read(s
, &s
->ch
[ch
], reg
, &ret
))
1484 case 0x404 ... 0x4fe:
1485 if (s
->model
<= omap_dma_3_1
)
1489 if (omap_dma_sys_read(s
, addr
, &ret
))
1493 case 0xb00 ... 0xbfe:
1494 if (s
->model
== omap_dma_3_2
&& s
->omap_3_1_mapping_disabled
) {
1495 if (omap_dma_3_2_lcd_read(&s
->lcd_ch
, addr
, &ret
))
1506 static void omap_dma_write(void *opaque
, hwaddr addr
,
1507 uint64_t value
, unsigned size
)
1509 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1513 omap_badwidth_write16(opaque
, addr
, value
);
1518 case 0x300 ... 0x3fe:
1519 if (s
->model
<= omap_dma_3_1
|| !s
->omap_3_1_mapping_disabled
) {
1520 if (omap_dma_3_1_lcd_write(&s
->lcd_ch
, addr
, value
))
1525 case 0x000 ... 0x2fe:
1527 ch
= (addr
>> 6) & 0x0f;
1528 if (omap_dma_ch_reg_write(s
, &s
->ch
[ch
], reg
, value
))
1532 case 0x404 ... 0x4fe:
1533 if (s
->model
<= omap_dma_3_1
)
1537 if (omap_dma_sys_write(s
, addr
, value
))
1541 case 0xb00 ... 0xbfe:
1542 if (s
->model
== omap_dma_3_2
&& s
->omap_3_1_mapping_disabled
) {
1543 if (omap_dma_3_2_lcd_write(&s
->lcd_ch
, addr
, value
))
1553 static const MemoryRegionOps omap_dma_ops
= {
1554 .read
= omap_dma_read
,
1555 .write
= omap_dma_write
,
1556 .endianness
= DEVICE_NATIVE_ENDIAN
,
1559 static void omap_dma_request(void *opaque
, int drq
, int req
)
1561 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1562 /* The request pins are level triggered in QEMU. */
1564 if (~s
->dma
->drqbmp
& (1ULL << drq
)) {
1565 s
->dma
->drqbmp
|= 1ULL << drq
;
1566 omap_dma_process_request(s
, drq
);
1569 s
->dma
->drqbmp
&= ~(1ULL << drq
);
1572 /* XXX: this won't be needed once soc_dma knows about clocks. */
1573 static void omap_dma_clk_update(void *opaque
, int line
, int on
)
1575 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1578 s
->dma
->freq
= omap_clk_getrate(s
->clk
);
1580 for (i
= 0; i
< s
->chans
; i
++)
1581 if (s
->ch
[i
].active
)
1582 soc_dma_set_request(s
->ch
[i
].dma
, on
);
1585 static void omap_dma_setcaps(struct omap_dma_s
*s
)
1593 /* XXX Only available for sDMA */
1595 (1 << 19) | /* Constant Fill Capability */
1596 (1 << 18); /* Transparent BLT Capability */
1598 (1 << 1); /* 1-bit palettized capability (DMA 3.2 only) */
1600 (1 << 8) | /* SEPARATE_SRC_AND_DST_INDEX_CPBLTY */
1601 (1 << 7) | /* DST_DOUBLE_INDEX_ADRS_CPBLTY */
1602 (1 << 6) | /* DST_SINGLE_INDEX_ADRS_CPBLTY */
1603 (1 << 5) | /* DST_POST_INCRMNT_ADRS_CPBLTY */
1604 (1 << 4) | /* DST_CONST_ADRS_CPBLTY */
1605 (1 << 3) | /* SRC_DOUBLE_INDEX_ADRS_CPBLTY */
1606 (1 << 2) | /* SRC_SINGLE_INDEX_ADRS_CPBLTY */
1607 (1 << 1) | /* SRC_POST_INCRMNT_ADRS_CPBLTY */
1608 (1 << 0); /* SRC_CONST_ADRS_CPBLTY */
1610 (1 << 6) | /* BLOCK_SYNCHR_CPBLTY (DMA 4 only) */
1611 (1 << 7) | /* PKT_SYNCHR_CPBLTY (DMA 4 only) */
1612 (1 << 5) | /* CHANNEL_CHAINING_CPBLTY */
1613 (1 << 4) | /* LCh_INTERLEAVE_CPBLTY */
1614 (1 << 3) | /* AUTOINIT_REPEAT_CPBLTY (DMA 3.2 only) */
1615 (1 << 2) | /* AUTOINIT_ENDPROG_CPBLTY (DMA 3.2 only) */
1616 (1 << 1) | /* FRAME_SYNCHR_CPBLTY */
1617 (1 << 0); /* ELMNT_SYNCHR_CPBLTY */
1619 (1 << 7) | /* PKT_INTERRUPT_CPBLTY (DMA 4 only) */
1620 (1 << 6) | /* SYNC_STATUS_CPBLTY */
1621 (1 << 5) | /* BLOCK_INTERRUPT_CPBLTY */
1622 (1 << 4) | /* LAST_FRAME_INTERRUPT_CPBLTY */
1623 (1 << 3) | /* FRAME_INTERRUPT_CPBLTY */
1624 (1 << 2) | /* HALF_FRAME_INTERRUPT_CPBLTY */
1625 (1 << 1) | /* EVENT_DROP_INTERRUPT_CPBLTY */
1626 (1 << 0); /* TIMEOUT_INTERRUPT_CPBLTY (DMA 3.2 only) */
1631 struct soc_dma_s
*omap_dma_init(hwaddr base
, qemu_irq
*irqs
,
1632 MemoryRegion
*sysmem
,
1633 qemu_irq lcd_irq
, struct omap_mpu_state_s
*mpu
, omap_clk clk
,
1634 enum omap_dma_model model
)
1636 int num_irqs
, memsize
, i
;
1637 struct omap_dma_s
*s
= g_new0(struct omap_dma_s
, 1);
1639 if (model
<= omap_dma_3_1
) {
1649 s
->lcd_ch
.irq
= lcd_irq
;
1650 s
->lcd_ch
.mpu
= mpu
;
1652 s
->dma
= soc_dma_init((model
<= omap_dma_3_1
) ? 9 : 16);
1653 s
->dma
->freq
= omap_clk_getrate(clk
);
1654 s
->dma
->transfer_fn
= omap_dma_transfer_generic
;
1655 s
->dma
->setup_fn
= omap_dma_transfer_setup
;
1656 s
->dma
->drq
= qemu_allocate_irqs(omap_dma_request
, s
, 32);
1660 s
->ch
[num_irqs
].irq
= irqs
[num_irqs
];
1661 for (i
= 0; i
< 3; i
++) {
1662 s
->ch
[i
].sibling
= &s
->ch
[i
+ 6];
1663 s
->ch
[i
+ 6].sibling
= &s
->ch
[i
];
1665 for (i
= (model
<= omap_dma_3_1
) ? 8 : 15; i
>= 0; i
--) {
1666 s
->ch
[i
].dma
= &s
->dma
->ch
[i
];
1667 s
->dma
->ch
[i
].opaque
= &s
->ch
[i
];
1670 omap_dma_setcaps(s
);
1671 omap_clk_adduser(s
->clk
, qemu_allocate_irq(omap_dma_clk_update
, s
, 0));
1672 omap_dma_reset(s
->dma
);
1673 omap_dma_clk_update(s
, 0, 1);
1675 memory_region_init_io(&s
->iomem
, NULL
, &omap_dma_ops
, s
, "omap.dma", memsize
);
1676 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
1678 mpu
->drq
= s
->dma
->drq
;
1683 static void omap_dma_interrupts_4_update(struct omap_dma_s
*s
)
1685 struct omap_dma_channel_s
*ch
= s
->ch
;
1688 for (bmp
= 0, bit
= 1; bit
; ch
++, bit
<<= 1)
1691 ch
->cstatus
|= ch
->status
;
1694 if ((s
->irqstat
[0] |= s
->irqen
[0] & bmp
))
1695 qemu_irq_raise(s
->irq
[0]);
1696 if ((s
->irqstat
[1] |= s
->irqen
[1] & bmp
))
1697 qemu_irq_raise(s
->irq
[1]);
1698 if ((s
->irqstat
[2] |= s
->irqen
[2] & bmp
))
1699 qemu_irq_raise(s
->irq
[2]);
1700 if ((s
->irqstat
[3] |= s
->irqen
[3] & bmp
))
1701 qemu_irq_raise(s
->irq
[3]);
1704 static uint64_t omap_dma4_read(void *opaque
, hwaddr addr
,
1707 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1708 int irqn
= 0, chnum
;
1709 struct omap_dma_channel_s
*ch
;
1712 return omap_badwidth_read16(opaque
, addr
);
1716 case 0x00: /* DMA4_REVISION */
1719 case 0x14: /* DMA4_IRQSTATUS_L3 */
1722 case 0x10: /* DMA4_IRQSTATUS_L2 */
1725 case 0x0c: /* DMA4_IRQSTATUS_L1 */
1728 case 0x08: /* DMA4_IRQSTATUS_L0 */
1729 return s
->irqstat
[irqn
];
1731 case 0x24: /* DMA4_IRQENABLE_L3 */
1734 case 0x20: /* DMA4_IRQENABLE_L2 */
1737 case 0x1c: /* DMA4_IRQENABLE_L1 */
1740 case 0x18: /* DMA4_IRQENABLE_L0 */
1741 return s
->irqen
[irqn
];
1743 case 0x28: /* DMA4_SYSSTATUS */
1744 return 1; /* RESETDONE */
1746 case 0x2c: /* DMA4_OCP_SYSCONFIG */
1749 case 0x64: /* DMA4_CAPS_0 */
1751 case 0x6c: /* DMA4_CAPS_2 */
1753 case 0x70: /* DMA4_CAPS_3 */
1755 case 0x74: /* DMA4_CAPS_4 */
1758 case 0x78: /* DMA4_GCR */
1761 case 0x80 ... 0xfff:
1763 chnum
= addr
/ 0x60;
1765 addr
-= chnum
* 0x60;
1773 /* Per-channel registers */
1775 case 0x00: /* DMA4_CCR */
1776 return (ch
->buf_disable
<< 25) |
1777 (ch
->src_sync
<< 24) |
1778 (ch
->prefetch
<< 23) |
1779 ((ch
->sync
& 0x60) << 14) |
1781 (ch
->transparent_copy
<< 17) |
1782 (ch
->constant_fill
<< 16) |
1783 (ch
->mode
[1] << 14) |
1784 (ch
->mode
[0] << 12) |
1785 (0 << 10) | (0 << 9) |
1786 (ch
->suspend
<< 8) |
1788 (ch
->priority
<< 6) |
1789 (ch
->fs
<< 5) | (ch
->sync
& 0x1f);
1791 case 0x04: /* DMA4_CLNK_CTRL */
1792 return (ch
->link_enabled
<< 15) | ch
->link_next_ch
;
1794 case 0x08: /* DMA4_CICR */
1795 return ch
->interrupts
;
1797 case 0x0c: /* DMA4_CSR */
1800 case 0x10: /* DMA4_CSDP */
1801 return (ch
->endian
[0] << 21) |
1802 (ch
->endian_lock
[0] << 20) |
1803 (ch
->endian
[1] << 19) |
1804 (ch
->endian_lock
[1] << 18) |
1805 (ch
->write_mode
<< 16) |
1806 (ch
->burst
[1] << 14) |
1807 (ch
->pack
[1] << 13) |
1808 (ch
->translate
[1] << 9) |
1809 (ch
->burst
[0] << 7) |
1810 (ch
->pack
[0] << 6) |
1811 (ch
->translate
[0] << 2) |
1812 (ch
->data_type
>> 1);
1814 case 0x14: /* DMA4_CEN */
1815 return ch
->elements
;
1817 case 0x18: /* DMA4_CFN */
1820 case 0x1c: /* DMA4_CSSA */
1823 case 0x20: /* DMA4_CDSA */
1826 case 0x24: /* DMA4_CSEI */
1827 return ch
->element_index
[0];
1829 case 0x28: /* DMA4_CSFI */
1830 return ch
->frame_index
[0];
1832 case 0x2c: /* DMA4_CDEI */
1833 return ch
->element_index
[1];
1835 case 0x30: /* DMA4_CDFI */
1836 return ch
->frame_index
[1];
1838 case 0x34: /* DMA4_CSAC */
1839 return ch
->active_set
.src
& 0xffff;
1841 case 0x38: /* DMA4_CDAC */
1842 return ch
->active_set
.dest
& 0xffff;
1844 case 0x3c: /* DMA4_CCEN */
1845 return ch
->active_set
.element
;
1847 case 0x40: /* DMA4_CCFN */
1848 return ch
->active_set
.frame
;
1850 case 0x44: /* DMA4_COLOR */
1851 /* XXX only in sDMA */
1860 static void omap_dma4_write(void *opaque
, hwaddr addr
,
1861 uint64_t value
, unsigned size
)
1863 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1864 int chnum
, irqn
= 0;
1865 struct omap_dma_channel_s
*ch
;
1868 omap_badwidth_write16(opaque
, addr
, value
);
1873 case 0x14: /* DMA4_IRQSTATUS_L3 */
1876 case 0x10: /* DMA4_IRQSTATUS_L2 */
1879 case 0x0c: /* DMA4_IRQSTATUS_L1 */
1882 case 0x08: /* DMA4_IRQSTATUS_L0 */
1883 s
->irqstat
[irqn
] &= ~value
;
1884 if (!s
->irqstat
[irqn
])
1885 qemu_irq_lower(s
->irq
[irqn
]);
1888 case 0x24: /* DMA4_IRQENABLE_L3 */
1891 case 0x20: /* DMA4_IRQENABLE_L2 */
1894 case 0x1c: /* DMA4_IRQENABLE_L1 */
1897 case 0x18: /* DMA4_IRQENABLE_L0 */
1898 s
->irqen
[irqn
] = value
;
1901 case 0x2c: /* DMA4_OCP_SYSCONFIG */
1902 if (value
& 2) /* SOFTRESET */
1903 omap_dma_reset(s
->dma
);
1904 s
->ocp
= value
& 0x3321;
1905 if (((s
->ocp
>> 12) & 3) == 3) { /* MIDLEMODE */
1906 qemu_log_mask(LOG_GUEST_ERROR
, "%s: invalid DMA power mode\n",
1911 case 0x78: /* DMA4_GCR */
1912 s
->gcr
= value
& 0x00ff00ff;
1913 if ((value
& 0xff) == 0x00) { /* MAX_CHANNEL_FIFO_DEPTH */
1914 qemu_log_mask(LOG_GUEST_ERROR
, "%s: wrong FIFO depth in GCR\n",
1919 case 0x80 ... 0xfff:
1921 chnum
= addr
/ 0x60;
1923 addr
-= chnum
* 0x60;
1926 case 0x00: /* DMA4_REVISION */
1927 case 0x28: /* DMA4_SYSSTATUS */
1928 case 0x64: /* DMA4_CAPS_0 */
1929 case 0x6c: /* DMA4_CAPS_2 */
1930 case 0x70: /* DMA4_CAPS_3 */
1931 case 0x74: /* DMA4_CAPS_4 */
1940 /* Per-channel registers */
1942 case 0x00: /* DMA4_CCR */
1943 ch
->buf_disable
= (value
>> 25) & 1;
1944 ch
->src_sync
= (value
>> 24) & 1; /* XXX For CamDMA must be 1 */
1945 if (ch
->buf_disable
&& !ch
->src_sync
) {
1946 qemu_log_mask(LOG_GUEST_ERROR
,
1947 "%s: Buffering disable is not allowed in "
1948 "destination synchronised mode\n", __func__
);
1950 ch
->prefetch
= (value
>> 23) & 1;
1951 ch
->bs
= (value
>> 18) & 1;
1952 ch
->transparent_copy
= (value
>> 17) & 1;
1953 ch
->constant_fill
= (value
>> 16) & 1;
1954 ch
->mode
[1] = (omap_dma_addressing_t
) ((value
& 0xc000) >> 14);
1955 ch
->mode
[0] = (omap_dma_addressing_t
) ((value
& 0x3000) >> 12);
1956 ch
->suspend
= (value
& 0x0100) >> 8;
1957 ch
->priority
= (value
& 0x0040) >> 6;
1958 ch
->fs
= (value
& 0x0020) >> 5;
1959 if (ch
->fs
&& ch
->bs
&& ch
->mode
[0] && ch
->mode
[1]) {
1960 qemu_log_mask(LOG_GUEST_ERROR
,
1961 "%s: For a packet transfer at least one port "
1962 "must be constant-addressed\n", __func__
);
1964 ch
->sync
= (value
& 0x001f) | ((value
>> 14) & 0x0060);
1965 /* XXX must be 0x01 for CamDMA */
1968 omap_dma_enable_channel(s
, ch
);
1970 omap_dma_disable_channel(s
, ch
);
1974 case 0x04: /* DMA4_CLNK_CTRL */
1975 ch
->link_enabled
= (value
>> 15) & 0x1;
1976 ch
->link_next_ch
= value
& 0x1f;
1979 case 0x08: /* DMA4_CICR */
1980 ch
->interrupts
= value
& 0x09be;
1983 case 0x0c: /* DMA4_CSR */
1984 ch
->cstatus
&= ~value
;
1987 case 0x10: /* DMA4_CSDP */
1988 ch
->endian
[0] =(value
>> 21) & 1;
1989 ch
->endian_lock
[0] =(value
>> 20) & 1;
1990 ch
->endian
[1] =(value
>> 19) & 1;
1991 ch
->endian_lock
[1] =(value
>> 18) & 1;
1992 if (ch
->endian
[0] != ch
->endian
[1]) {
1993 qemu_log_mask(LOG_GUEST_ERROR
,
1994 "%s: DMA endianness conversion enable attempt\n",
1997 ch
->write_mode
= (value
>> 16) & 3;
1998 ch
->burst
[1] = (value
& 0xc000) >> 14;
1999 ch
->pack
[1] = (value
& 0x2000) >> 13;
2000 ch
->translate
[1] = (value
& 0x1e00) >> 9;
2001 ch
->burst
[0] = (value
& 0x0180) >> 7;
2002 ch
->pack
[0] = (value
& 0x0040) >> 6;
2003 ch
->translate
[0] = (value
& 0x003c) >> 2;
2004 if (ch
->translate
[0] | ch
->translate
[1]) {
2005 qemu_log_mask(LOG_GUEST_ERROR
,
2006 "%s: bad MReqAddressTranslate sideband signal\n",
2009 ch
->data_type
= 1 << (value
& 3);
2010 if ((value
& 3) == 3) {
2011 qemu_log_mask(LOG_GUEST_ERROR
,
2012 "%s: bad data_type for DMA channel\n", __func__
);
2013 ch
->data_type
>>= 1;
2017 case 0x14: /* DMA4_CEN */
2019 ch
->elements
= value
& 0xffffff;
2022 case 0x18: /* DMA4_CFN */
2023 ch
->frames
= value
& 0xffff;
2027 case 0x1c: /* DMA4_CSSA */
2028 ch
->addr
[0] = (hwaddr
) (uint32_t) value
;
2032 case 0x20: /* DMA4_CDSA */
2033 ch
->addr
[1] = (hwaddr
) (uint32_t) value
;
2037 case 0x24: /* DMA4_CSEI */
2038 ch
->element_index
[0] = (int16_t) value
;
2042 case 0x28: /* DMA4_CSFI */
2043 ch
->frame_index
[0] = (int32_t) value
;
2047 case 0x2c: /* DMA4_CDEI */
2048 ch
->element_index
[1] = (int16_t) value
;
2052 case 0x30: /* DMA4_CDFI */
2053 ch
->frame_index
[1] = (int32_t) value
;
2057 case 0x44: /* DMA4_COLOR */
2058 /* XXX only in sDMA */
2062 case 0x34: /* DMA4_CSAC */
2063 case 0x38: /* DMA4_CDAC */
2064 case 0x3c: /* DMA4_CCEN */
2065 case 0x40: /* DMA4_CCFN */
2074 static const MemoryRegionOps omap_dma4_ops
= {
2075 .read
= omap_dma4_read
,
2076 .write
= omap_dma4_write
,
2077 .endianness
= DEVICE_NATIVE_ENDIAN
,
2080 struct soc_dma_s
*omap_dma4_init(hwaddr base
, qemu_irq
*irqs
,
2081 MemoryRegion
*sysmem
,
2082 struct omap_mpu_state_s
*mpu
, int fifo
,
2083 int chans
, omap_clk iclk
, omap_clk fclk
)
2086 struct omap_dma_s
*s
= g_new0(struct omap_dma_s
, 1);
2088 s
->model
= omap_dma_4
;
2093 s
->dma
= soc_dma_init(s
->chans
);
2094 s
->dma
->freq
= omap_clk_getrate(fclk
);
2095 s
->dma
->transfer_fn
= omap_dma_transfer_generic
;
2096 s
->dma
->setup_fn
= omap_dma_transfer_setup
;
2097 s
->dma
->drq
= qemu_allocate_irqs(omap_dma_request
, s
, 64);
2099 for (i
= 0; i
< s
->chans
; i
++) {
2100 s
->ch
[i
].dma
= &s
->dma
->ch
[i
];
2101 s
->dma
->ch
[i
].opaque
= &s
->ch
[i
];
2104 memcpy(&s
->irq
, irqs
, sizeof(s
->irq
));
2105 s
->intr_update
= omap_dma_interrupts_4_update
;
2107 omap_dma_setcaps(s
);
2108 omap_clk_adduser(s
->clk
, qemu_allocate_irq(omap_dma_clk_update
, s
, 0));
2109 omap_dma_reset(s
->dma
);
2110 omap_dma_clk_update(s
, 0, !!s
->dma
->freq
);
2112 memory_region_init_io(&s
->iomem
, NULL
, &omap_dma4_ops
, s
, "omap.dma4", 0x1000);
2113 memory_region_add_subregion(sysmem
, base
, &s
->iomem
);
2115 mpu
->drq
= s
->dma
->drq
;
2120 struct omap_dma_lcd_channel_s
*omap_dma_get_lcdch(struct soc_dma_s
*dma
)
2122 struct omap_dma_s
*s
= dma
->opaque
;