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-common.h"
21 #include "qemu-timer.h"
26 struct omap_dma_channel_s
{
33 enum omap_dma_port port
[2];
34 target_phys_addr_t addr
[2];
35 omap_dma_addressing_t mode
[2];
38 int32_t frame_index
[2];
39 int16_t element_index
[2];
48 /* auto init and linked channel data */
55 /* interruption data */
75 int omap_3_1_compatible_disable
;
78 struct omap_dma_channel_s
*sibling
;
80 struct omap_dma_reg_set_s
{
81 target_phys_addr_t src
, dest
;
92 struct soc_dma_ch_s
*dma
;
94 /* unused parameters */
97 int interleave_disabled
;
104 struct soc_dma_s
*dma
;
106 struct omap_mpu_state_s
*mpu
;
109 void (*intr_update
)(struct omap_dma_s
*s
);
110 enum omap_dma_model model
;
111 int omap_3_1_mapping_disabled
;
120 struct omap_dma_channel_s ch
[32];
121 struct omap_dma_lcd_channel_s lcd_ch
;
125 #define TIMEOUT_INTR (1 << 0)
126 #define EVENT_DROP_INTR (1 << 1)
127 #define HALF_FRAME_INTR (1 << 2)
128 #define END_FRAME_INTR (1 << 3)
129 #define LAST_FRAME_INTR (1 << 4)
130 #define END_BLOCK_INTR (1 << 5)
131 #define SYNC (1 << 6)
132 #define END_PKT_INTR (1 << 7)
133 #define TRANS_ERR_INTR (1 << 8)
134 #define MISALIGN_INTR (1 << 11)
136 static inline void omap_dma_interrupts_update(struct omap_dma_s
*s
)
138 return s
->intr_update(s
);
141 static void omap_dma_channel_load(struct omap_dma_channel_s
*ch
)
143 struct omap_dma_reg_set_s
*a
= &ch
->active_set
;
145 int omap_3_1
= !ch
->omap_3_1_compatible_disable
;
148 * TODO: verify address ranges and alignment
149 * TODO: port endianness
152 a
->src
= ch
->addr
[0];
153 a
->dest
= ch
->addr
[1];
154 a
->frames
= ch
->frames
;
155 a
->elements
= ch
->elements
;
156 a
->pck_elements
= ch
->frame_index
[!ch
->src_sync
];
161 if (unlikely(!ch
->elements
|| !ch
->frames
)) {
162 printf("%s: bad DMA request\n", __FUNCTION__
);
166 for (i
= 0; i
< 2; i
++)
167 switch (ch
->mode
[i
]) {
169 a
->elem_delta
[i
] = 0;
170 a
->frame_delta
[i
] = 0;
172 case post_incremented
:
173 a
->elem_delta
[i
] = ch
->data_type
;
174 a
->frame_delta
[i
] = 0;
177 a
->elem_delta
[i
] = ch
->data_type
+
178 ch
->element_index
[omap_3_1
? 0 : i
] - 1;
179 a
->frame_delta
[i
] = 0;
182 a
->elem_delta
[i
] = ch
->data_type
+
183 ch
->element_index
[omap_3_1
? 0 : i
] - 1;
184 a
->frame_delta
[i
] = ch
->frame_index
[omap_3_1
? 0 : i
] -
185 ch
->element_index
[omap_3_1
? 0 : i
];
191 normal
= !ch
->transparent_copy
&& !ch
->constant_fill
&&
192 /* FIFO is big-endian so either (ch->endian[n] == 1) OR
193 * (ch->endian_lock[n] == 1) mean no endianism conversion. */
194 (ch
->endian
[0] | ch
->endian_lock
[0]) ==
195 (ch
->endian
[1] | ch
->endian_lock
[1]);
196 for (i
= 0; i
< 2; i
++) {
197 /* TODO: for a->frame_delta[i] > 0 still use the fast path, just
198 * limit min_elems in omap_dma_transfer_setup to the nearest frame
200 if (!a
->elem_delta
[i
] && normal
&&
201 (a
->frames
== 1 || !a
->frame_delta
[i
]))
202 ch
->dma
->type
[i
] = soc_dma_access_const
;
203 else if (a
->elem_delta
[i
] == ch
->data_type
&& normal
&&
204 (a
->frames
== 1 || !a
->frame_delta
[i
]))
205 ch
->dma
->type
[i
] = soc_dma_access_linear
;
207 ch
->dma
->type
[i
] = soc_dma_access_other
;
209 ch
->dma
->vaddr
[i
] = ch
->addr
[i
];
211 soc_dma_ch_update(ch
->dma
);
214 static void omap_dma_activate_channel(struct omap_dma_s
*s
,
215 struct omap_dma_channel_s
*ch
)
218 if (ch
->set_update
) {
219 /* It's not clear when the active set is supposed to be
220 * loaded from registers. We're already loading it when the
221 * channel is enabled, and for some guests this is not enough
222 * but that may be also because of a race condition (no
223 * delays in qemu) in the guest code, which we're just
224 * working around here. */
225 omap_dma_channel_load(ch
);
230 soc_dma_set_request(ch
->dma
, 1);
236 static void omap_dma_deactivate_channel(struct omap_dma_s
*s
,
237 struct omap_dma_channel_s
*ch
)
240 ch
->cpc
= ch
->active_set
.dest
& 0xffff;
242 if (ch
->pending_request
&& !ch
->waiting_end_prog
&& ch
->enable
) {
243 /* Don't deactivate the channel */
244 ch
->pending_request
= 0;
248 /* Don't deactive the channel if it is synchronized and the DMA request is
250 if (ch
->sync
&& ch
->enable
&& (s
->dma
->drqbmp
& (1 << ch
->sync
)))
256 soc_dma_set_request(ch
->dma
, 0);
260 static void omap_dma_enable_channel(struct omap_dma_s
*s
,
261 struct omap_dma_channel_s
*ch
)
265 ch
->waiting_end_prog
= 0;
266 omap_dma_channel_load(ch
);
267 /* TODO: theoretically if ch->sync && ch->prefetch &&
268 * !s->dma->drqbmp[ch->sync], we should also activate and fetch
269 * from source and then stall until signalled. */
270 if ((!ch
->sync
) || (s
->dma
->drqbmp
& (1 << ch
->sync
)))
271 omap_dma_activate_channel(s
, ch
);
275 static void omap_dma_disable_channel(struct omap_dma_s
*s
,
276 struct omap_dma_channel_s
*ch
)
280 /* Discard any pending request */
281 ch
->pending_request
= 0;
282 omap_dma_deactivate_channel(s
, ch
);
286 static void omap_dma_channel_end_prog(struct omap_dma_s
*s
,
287 struct omap_dma_channel_s
*ch
)
289 if (ch
->waiting_end_prog
) {
290 ch
->waiting_end_prog
= 0;
291 if (!ch
->sync
|| ch
->pending_request
) {
292 ch
->pending_request
= 0;
293 omap_dma_activate_channel(s
, ch
);
298 static void omap_dma_interrupts_3_1_update(struct omap_dma_s
*s
)
300 struct omap_dma_channel_s
*ch
= s
->ch
;
302 /* First three interrupts are shared between two channels each. */
303 if (ch
[0].status
| ch
[6].status
)
304 qemu_irq_raise(ch
[0].irq
);
305 if (ch
[1].status
| ch
[7].status
)
306 qemu_irq_raise(ch
[1].irq
);
307 if (ch
[2].status
| ch
[8].status
)
308 qemu_irq_raise(ch
[2].irq
);
310 qemu_irq_raise(ch
[3].irq
);
312 qemu_irq_raise(ch
[4].irq
);
314 qemu_irq_raise(ch
[5].irq
);
317 static void omap_dma_interrupts_3_2_update(struct omap_dma_s
*s
)
319 struct omap_dma_channel_s
*ch
= s
->ch
;
322 for (i
= s
->chans
; i
; ch
++, i
--)
324 qemu_irq_raise(ch
->irq
);
327 static void omap_dma_enable_3_1_mapping(struct omap_dma_s
*s
)
329 s
->omap_3_1_mapping_disabled
= 0;
331 s
->intr_update
= omap_dma_interrupts_3_1_update
;
334 static void omap_dma_disable_3_1_mapping(struct omap_dma_s
*s
)
336 s
->omap_3_1_mapping_disabled
= 1;
338 s
->intr_update
= omap_dma_interrupts_3_2_update
;
341 static void omap_dma_process_request(struct omap_dma_s
*s
, int request
)
345 struct omap_dma_channel_s
*ch
= s
->ch
;
347 for (channel
= 0; channel
< s
->chans
; channel
++, ch
++) {
348 if (ch
->enable
&& ch
->sync
== request
) {
350 omap_dma_activate_channel(s
, ch
);
351 else if (!ch
->pending_request
)
352 ch
->pending_request
= 1;
354 /* Request collision */
355 /* Second request received while processing other request */
356 ch
->status
|= EVENT_DROP_INTR
;
363 omap_dma_interrupts_update(s
);
366 static void omap_dma_transfer_generic(struct soc_dma_ch_s
*dma
)
369 struct omap_dma_channel_s
*ch
= dma
->opaque
;
370 struct omap_dma_reg_set_s
*a
= &ch
->active_set
;
371 int bytes
= dma
->bytes
;
373 uint16_t status
= ch
->status
;
377 /* Transfer a single element */
378 /* FIXME: check the endianness */
379 if (!ch
->constant_fill
)
380 cpu_physical_memory_read(a
->src
, value
, ch
->data_type
);
382 *(uint32_t *) value
= ch
->color
;
384 if (!ch
->transparent_copy
|| *(uint32_t *) value
!= ch
->color
)
385 cpu_physical_memory_write(a
->dest
, value
, ch
->data_type
);
387 a
->src
+= a
->elem_delta
[0];
388 a
->dest
+= a
->elem_delta
[1];
392 if (a
->element
== a
->elements
) {
395 a
->src
+= a
->frame_delta
[0];
396 a
->dest
+= a
->frame_delta
[1];
399 /* If the channel is async, update cpc */
401 ch
->cpc
= a
->dest
& 0xffff;
403 } while ((bytes
-= ch
->data_type
));
405 /* If the channel is element synchronized, deactivate it */
406 if (ch
->sync
&& !ch
->fs
&& !ch
->bs
)
407 omap_dma_deactivate_channel(s
, ch
);
409 /* If it is the last frame, set the LAST_FRAME interrupt */
410 if (a
->element
== 1 && a
->frame
== a
->frames
- 1)
411 if (ch
->interrupts
& LAST_FRAME_INTR
)
412 ch
->status
|= LAST_FRAME_INTR
;
414 /* If the half of the frame was reached, set the HALF_FRAME
416 if (a
->element
== (a
->elements
>> 1))
417 if (ch
->interrupts
& HALF_FRAME_INTR
)
418 ch
->status
|= HALF_FRAME_INTR
;
420 if (ch
->fs
&& ch
->bs
) {
422 /* Check if a full packet has beed transferred. */
423 if (a
->pck_element
== a
->pck_elements
) {
426 /* Set the END_PKT interrupt */
427 if ((ch
->interrupts
& END_PKT_INTR
) && !ch
->src_sync
)
428 ch
->status
|= END_PKT_INTR
;
430 /* If the channel is packet-synchronized, deactivate it */
432 omap_dma_deactivate_channel(s
, ch
);
436 if (a
->element
== a
->elements
) {
439 a
->src
+= a
->frame_delta
[0];
440 a
->dest
+= a
->frame_delta
[1];
443 /* If the channel is frame synchronized, deactivate it */
444 if (ch
->sync
&& ch
->fs
&& !ch
->bs
)
445 omap_dma_deactivate_channel(s
, ch
);
447 /* If the channel is async, update cpc */
449 ch
->cpc
= a
->dest
& 0xffff;
451 /* Set the END_FRAME interrupt */
452 if (ch
->interrupts
& END_FRAME_INTR
)
453 ch
->status
|= END_FRAME_INTR
;
455 if (a
->frame
== a
->frames
) {
457 /* Disable the channel */
459 if (ch
->omap_3_1_compatible_disable
) {
460 omap_dma_disable_channel(s
, ch
);
461 if (ch
->link_enabled
)
462 omap_dma_enable_channel(s
,
463 &s
->ch
[ch
->link_next_ch
]);
466 omap_dma_disable_channel(s
, ch
);
467 else if (ch
->repeat
|| ch
->end_prog
)
468 omap_dma_channel_load(ch
);
470 ch
->waiting_end_prog
= 1;
471 omap_dma_deactivate_channel(s
, ch
);
475 if (ch
->interrupts
& END_BLOCK_INTR
)
476 ch
->status
|= END_BLOCK_INTR
;
479 } while (status
== ch
->status
&& ch
->active
);
481 omap_dma_interrupts_update(s
);
486 omap_dma_intr_element_sync
,
487 omap_dma_intr_last_frame
,
488 omap_dma_intr_half_frame
,
490 omap_dma_intr_frame_sync
,
491 omap_dma_intr_packet
,
492 omap_dma_intr_packet_sync
,
494 __omap_dma_intr_last
,
497 static void omap_dma_transfer_setup(struct soc_dma_ch_s
*dma
)
499 struct omap_dma_port_if_s
*src_p
, *dest_p
;
500 struct omap_dma_reg_set_s
*a
;
501 struct omap_dma_channel_s
*ch
= dma
->opaque
;
502 struct omap_dma_s
*s
= dma
->dma
->opaque
;
503 int frames
, min_elems
, elements
[__omap_dma_intr_last
];
507 src_p
= &s
->mpu
->port
[ch
->port
[0]];
508 dest_p
= &s
->mpu
->port
[ch
->port
[1]];
509 if ((!ch
->constant_fill
&& !src_p
->addr_valid(s
->mpu
, a
->src
)) ||
510 (!dest_p
->addr_valid(s
->mpu
, a
->dest
))) {
513 if (ch
->interrupts
& TIMEOUT_INTR
)
514 ch
->status
|= TIMEOUT_INTR
;
515 omap_dma_deactivate_channel(s
, ch
);
518 printf("%s: Bus time-out in DMA%i operation\n",
519 __FUNCTION__
, dma
->num
);
524 /* Check all the conditions that terminate the transfer starting
525 * with those that can occur the soonest. */
526 #define INTR_CHECK(cond, id, nelements) \
528 elements[id] = nelements; \
529 if (elements[id] < min_elems) \
530 min_elems = elements[id]; \
532 elements[id] = INT_MAX;
536 ch
->sync
&& !ch
->fs
&& !ch
->bs
,
537 omap_dma_intr_element_sync
,
541 /* TODO: for transfers where entire frames can be read and written
542 * using memcpy() but a->frame_delta is non-zero, try to still do
543 * transfers using soc_dma but limit min_elems to a->elements - ...
544 * See also the TODO in omap_dma_channel_load. */
546 (ch
->interrupts
& LAST_FRAME_INTR
) &&
547 ((a
->frame
< a
->frames
- 1) || !a
->element
),
548 omap_dma_intr_last_frame
,
549 (a
->frames
- a
->frame
- 2) * a
->elements
+
550 (a
->elements
- a
->element
+ 1))
552 ch
->interrupts
& HALF_FRAME_INTR
,
553 omap_dma_intr_half_frame
,
555 (a
->element
>= (a
->elements
>> 1) ? a
->elements
: 0) -
558 ch
->sync
&& ch
->fs
&& (ch
->interrupts
& END_FRAME_INTR
),
560 a
->elements
- a
->element
)
562 ch
->sync
&& ch
->fs
&& !ch
->bs
,
563 omap_dma_intr_frame_sync
,
564 a
->elements
- a
->element
)
569 (ch
->interrupts
& END_PKT_INTR
) && !ch
->src_sync
,
570 omap_dma_intr_packet
,
571 a
->pck_elements
- a
->pck_element
)
573 ch
->fs
&& ch
->bs
&& ch
->sync
,
574 omap_dma_intr_packet_sync
,
575 a
->pck_elements
- a
->pck_element
)
581 (a
->frames
- a
->frame
- 1) * a
->elements
+
582 (a
->elements
- a
->element
))
584 dma
->bytes
= min_elems
* ch
->data_type
;
586 /* Set appropriate interrupts and/or deactivate channels */
589 /* TODO: should all of this only be done if dma->update, and otherwise
590 * inside omap_dma_transfer_generic below - check what's faster. */
594 /* If the channel is element synchronized, deactivate it */
595 if (min_elems
== elements
[omap_dma_intr_element_sync
])
596 omap_dma_deactivate_channel(s
, ch
);
598 /* If it is the last frame, set the LAST_FRAME interrupt */
599 if (min_elems
== elements
[omap_dma_intr_last_frame
])
600 ch
->status
|= LAST_FRAME_INTR
;
602 /* If exactly half of the frame was reached, set the HALF_FRAME
604 if (min_elems
== elements
[omap_dma_intr_half_frame
])
605 ch
->status
|= HALF_FRAME_INTR
;
607 /* If a full packet has been transferred, set the END_PKT interrupt */
608 if (min_elems
== elements
[omap_dma_intr_packet
])
609 ch
->status
|= END_PKT_INTR
;
611 /* If the channel is packet-synchronized, deactivate it */
612 if (min_elems
== elements
[omap_dma_intr_packet_sync
])
613 omap_dma_deactivate_channel(s
, ch
);
615 /* If the channel is frame synchronized, deactivate it */
616 if (min_elems
== elements
[omap_dma_intr_frame_sync
])
617 omap_dma_deactivate_channel(s
, ch
);
619 /* Set the END_FRAME interrupt */
620 if (min_elems
== elements
[omap_dma_intr_frame
])
621 ch
->status
|= END_FRAME_INTR
;
623 if (min_elems
== elements
[omap_dma_intr_block
]) {
625 /* Disable the channel */
627 if (ch
->omap_3_1_compatible_disable
) {
628 omap_dma_disable_channel(s
, ch
);
629 if (ch
->link_enabled
)
630 omap_dma_enable_channel(s
, &s
->ch
[ch
->link_next_ch
]);
633 omap_dma_disable_channel(s
, ch
);
634 else if (ch
->repeat
|| ch
->end_prog
)
635 omap_dma_channel_load(ch
);
637 ch
->waiting_end_prog
= 1;
638 omap_dma_deactivate_channel(s
, ch
);
642 if (ch
->interrupts
& END_BLOCK_INTR
)
643 ch
->status
|= END_BLOCK_INTR
;
646 /* Update packet number */
647 if (ch
->fs
&& ch
->bs
) {
648 a
->pck_element
+= min_elems
;
649 a
->pck_element
%= a
->pck_elements
;
652 /* TODO: check if we really need to update anything here or perhaps we
653 * can skip part of this. */
657 a
->element
+= min_elems
;
659 frames
= a
->element
/ a
->elements
;
660 a
->element
= a
->element
% a
->elements
;
662 a
->src
+= min_elems
* a
->elem_delta
[0] + frames
* a
->frame_delta
[0];
663 a
->dest
+= min_elems
* a
->elem_delta
[1] + frames
* a
->frame_delta
[1];
665 /* If the channel is async, update cpc */
666 if (!ch
->sync
&& frames
)
667 ch
->cpc
= a
->dest
& 0xffff;
669 /* TODO: if the destination port is IMIF or EMIFF, set the dirty
673 omap_dma_interrupts_update(s
);
676 void omap_dma_reset(struct soc_dma_s
*dma
)
679 struct omap_dma_s
*s
= dma
->opaque
;
681 soc_dma_reset(s
->dma
);
682 if (s
->model
< omap_dma_4
)
687 memset(&s
->irqstat
, 0, sizeof(s
->irqstat
));
688 memset(&s
->irqen
, 0, sizeof(s
->irqen
));
689 s
->lcd_ch
.src
= emiff
;
690 s
->lcd_ch
.condition
= 0;
691 s
->lcd_ch
.interrupts
= 0;
693 if (s
->model
< omap_dma_4
)
694 omap_dma_enable_3_1_mapping(s
);
695 for (i
= 0; i
< s
->chans
; i
++) {
696 s
->ch
[i
].suspend
= 0;
697 s
->ch
[i
].prefetch
= 0;
698 s
->ch
[i
].buf_disable
= 0;
699 s
->ch
[i
].src_sync
= 0;
700 memset(&s
->ch
[i
].burst
, 0, sizeof(s
->ch
[i
].burst
));
701 memset(&s
->ch
[i
].port
, 0, sizeof(s
->ch
[i
].port
));
702 memset(&s
->ch
[i
].mode
, 0, sizeof(s
->ch
[i
].mode
));
703 memset(&s
->ch
[i
].frame_index
, 0, sizeof(s
->ch
[i
].frame_index
));
704 memset(&s
->ch
[i
].element_index
, 0, sizeof(s
->ch
[i
].element_index
));
705 memset(&s
->ch
[i
].endian
, 0, sizeof(s
->ch
[i
].endian
));
706 memset(&s
->ch
[i
].endian_lock
, 0, sizeof(s
->ch
[i
].endian_lock
));
707 memset(&s
->ch
[i
].translate
, 0, sizeof(s
->ch
[i
].translate
));
708 s
->ch
[i
].write_mode
= 0;
709 s
->ch
[i
].data_type
= 0;
710 s
->ch
[i
].transparent_copy
= 0;
711 s
->ch
[i
].constant_fill
= 0;
712 s
->ch
[i
].color
= 0x00000000;
713 s
->ch
[i
].end_prog
= 0;
715 s
->ch
[i
].auto_init
= 0;
716 s
->ch
[i
].link_enabled
= 0;
717 if (s
->model
< omap_dma_4
)
718 s
->ch
[i
].interrupts
= 0x0003;
720 s
->ch
[i
].interrupts
= 0x0000;
722 s
->ch
[i
].cstatus
= 0;
726 s
->ch
[i
].pending_request
= 0;
727 s
->ch
[i
].waiting_end_prog
= 0;
728 s
->ch
[i
].cpc
= 0x0000;
731 s
->ch
[i
].omap_3_1_compatible_disable
= 0;
732 memset(&s
->ch
[i
].active_set
, 0, sizeof(s
->ch
[i
].active_set
));
733 s
->ch
[i
].priority
= 0;
734 s
->ch
[i
].interleave_disabled
= 0;
739 static int omap_dma_ch_reg_read(struct omap_dma_s
*s
,
740 struct omap_dma_channel_s
*ch
, int reg
, uint16_t *value
)
743 case 0x00: /* SYS_DMA_CSDP_CH0 */
744 *value
= (ch
->burst
[1] << 14) |
745 (ch
->pack
[1] << 13) |
747 (ch
->burst
[0] << 7) |
750 (ch
->data_type
>> 1);
753 case 0x02: /* SYS_DMA_CCR_CH0 */
754 if (s
->model
<= omap_dma_3_1
)
755 *value
= 0 << 10; /* FIFO_FLUSH reads as 0 */
757 *value
= ch
->omap_3_1_compatible_disable
<< 10;
758 *value
|= (ch
->mode
[1] << 14) |
759 (ch
->mode
[0] << 12) |
760 (ch
->end_prog
<< 11) |
762 (ch
->auto_init
<< 8) |
764 (ch
->priority
<< 6) |
765 (ch
->fs
<< 5) | ch
->sync
;
768 case 0x04: /* SYS_DMA_CICR_CH0 */
769 *value
= ch
->interrupts
;
772 case 0x06: /* SYS_DMA_CSR_CH0 */
775 if (!ch
->omap_3_1_compatible_disable
&& ch
->sibling
) {
776 *value
|= (ch
->sibling
->status
& 0x3f) << 6;
777 ch
->sibling
->status
&= SYNC
;
779 qemu_irq_lower(ch
->irq
);
782 case 0x08: /* SYS_DMA_CSSA_L_CH0 */
783 *value
= ch
->addr
[0] & 0x0000ffff;
786 case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
787 *value
= ch
->addr
[0] >> 16;
790 case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
791 *value
= ch
->addr
[1] & 0x0000ffff;
794 case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
795 *value
= ch
->addr
[1] >> 16;
798 case 0x10: /* SYS_DMA_CEN_CH0 */
799 *value
= ch
->elements
;
802 case 0x12: /* SYS_DMA_CFN_CH0 */
806 case 0x14: /* SYS_DMA_CFI_CH0 */
807 *value
= ch
->frame_index
[0];
810 case 0x16: /* SYS_DMA_CEI_CH0 */
811 *value
= ch
->element_index
[0];
814 case 0x18: /* SYS_DMA_CPC_CH0 or DMA_CSAC */
815 if (ch
->omap_3_1_compatible_disable
)
816 *value
= ch
->active_set
.src
& 0xffff; /* CSAC */
821 case 0x1a: /* DMA_CDAC */
822 *value
= ch
->active_set
.dest
& 0xffff; /* CDAC */
825 case 0x1c: /* DMA_CDEI */
826 *value
= ch
->element_index
[1];
829 case 0x1e: /* DMA_CDFI */
830 *value
= ch
->frame_index
[1];
833 case 0x20: /* DMA_COLOR_L */
834 *value
= ch
->color
& 0xffff;
837 case 0x22: /* DMA_COLOR_U */
838 *value
= ch
->color
>> 16;
841 case 0x24: /* DMA_CCR2 */
842 *value
= (ch
->bs
<< 2) |
843 (ch
->transparent_copy
<< 1) |
847 case 0x28: /* DMA_CLNK_CTRL */
848 *value
= (ch
->link_enabled
<< 15) |
849 (ch
->link_next_ch
& 0xf);
852 case 0x2a: /* DMA_LCH_CTRL */
853 *value
= (ch
->interleave_disabled
<< 15) |
863 static int omap_dma_ch_reg_write(struct omap_dma_s
*s
,
864 struct omap_dma_channel_s
*ch
, int reg
, uint16_t value
)
867 case 0x00: /* SYS_DMA_CSDP_CH0 */
868 ch
->burst
[1] = (value
& 0xc000) >> 14;
869 ch
->pack
[1] = (value
& 0x2000) >> 13;
870 ch
->port
[1] = (enum omap_dma_port
) ((value
& 0x1e00) >> 9);
871 ch
->burst
[0] = (value
& 0x0180) >> 7;
872 ch
->pack
[0] = (value
& 0x0040) >> 6;
873 ch
->port
[0] = (enum omap_dma_port
) ((value
& 0x003c) >> 2);
874 ch
->data_type
= 1 << (value
& 3);
875 if (ch
->port
[0] >= __omap_dma_port_last
)
876 printf("%s: invalid DMA port %i\n", __FUNCTION__
,
878 if (ch
->port
[1] >= __omap_dma_port_last
)
879 printf("%s: invalid DMA port %i\n", __FUNCTION__
,
881 if ((value
& 3) == 3)
882 printf("%s: bad data_type for DMA channel\n", __FUNCTION__
);
885 case 0x02: /* SYS_DMA_CCR_CH0 */
886 ch
->mode
[1] = (omap_dma_addressing_t
) ((value
& 0xc000) >> 14);
887 ch
->mode
[0] = (omap_dma_addressing_t
) ((value
& 0x3000) >> 12);
888 ch
->end_prog
= (value
& 0x0800) >> 11;
889 if (s
->model
>= omap_dma_3_2
)
890 ch
->omap_3_1_compatible_disable
= (value
>> 10) & 0x1;
891 ch
->repeat
= (value
& 0x0200) >> 9;
892 ch
->auto_init
= (value
& 0x0100) >> 8;
893 ch
->priority
= (value
& 0x0040) >> 6;
894 ch
->fs
= (value
& 0x0020) >> 5;
895 ch
->sync
= value
& 0x001f;
898 omap_dma_enable_channel(s
, ch
);
900 omap_dma_disable_channel(s
, ch
);
903 omap_dma_channel_end_prog(s
, ch
);
907 case 0x04: /* SYS_DMA_CICR_CH0 */
908 ch
->interrupts
= value
& 0x3f;
911 case 0x06: /* SYS_DMA_CSR_CH0 */
912 OMAP_RO_REG((target_phys_addr_t
) reg
);
915 case 0x08: /* SYS_DMA_CSSA_L_CH0 */
916 ch
->addr
[0] &= 0xffff0000;
917 ch
->addr
[0] |= value
;
920 case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
921 ch
->addr
[0] &= 0x0000ffff;
922 ch
->addr
[0] |= (uint32_t) value
<< 16;
925 case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
926 ch
->addr
[1] &= 0xffff0000;
927 ch
->addr
[1] |= value
;
930 case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
931 ch
->addr
[1] &= 0x0000ffff;
932 ch
->addr
[1] |= (uint32_t) value
<< 16;
935 case 0x10: /* SYS_DMA_CEN_CH0 */
936 ch
->elements
= value
;
939 case 0x12: /* SYS_DMA_CFN_CH0 */
943 case 0x14: /* SYS_DMA_CFI_CH0 */
944 ch
->frame_index
[0] = (int16_t) value
;
947 case 0x16: /* SYS_DMA_CEI_CH0 */
948 ch
->element_index
[0] = (int16_t) value
;
951 case 0x18: /* SYS_DMA_CPC_CH0 or DMA_CSAC */
952 OMAP_RO_REG((target_phys_addr_t
) reg
);
955 case 0x1c: /* DMA_CDEI */
956 ch
->element_index
[1] = (int16_t) value
;
959 case 0x1e: /* DMA_CDFI */
960 ch
->frame_index
[1] = (int16_t) value
;
963 case 0x20: /* DMA_COLOR_L */
964 ch
->color
&= 0xffff0000;
968 case 0x22: /* DMA_COLOR_U */
970 ch
->color
|= value
<< 16;
973 case 0x24: /* DMA_CCR2 */
974 ch
->bs
= (value
>> 2) & 0x1;
975 ch
->transparent_copy
= (value
>> 1) & 0x1;
976 ch
->constant_fill
= value
& 0x1;
979 case 0x28: /* DMA_CLNK_CTRL */
980 ch
->link_enabled
= (value
>> 15) & 0x1;
981 if (value
& (1 << 14)) { /* Stop_Lnk */
982 ch
->link_enabled
= 0;
983 omap_dma_disable_channel(s
, ch
);
985 ch
->link_next_ch
= value
& 0x1f;
988 case 0x2a: /* DMA_LCH_CTRL */
989 ch
->interleave_disabled
= (value
>> 15) & 0x1;
990 ch
->type
= value
& 0xf;
999 static int omap_dma_3_2_lcd_write(struct omap_dma_lcd_channel_s
*s
, int offset
,
1003 case 0xbc0: /* DMA_LCD_CSDP */
1004 s
->brust_f2
= (value
>> 14) & 0x3;
1005 s
->pack_f2
= (value
>> 13) & 0x1;
1006 s
->data_type_f2
= (1 << ((value
>> 11) & 0x3));
1007 s
->brust_f1
= (value
>> 7) & 0x3;
1008 s
->pack_f1
= (value
>> 6) & 0x1;
1009 s
->data_type_f1
= (1 << ((value
>> 0) & 0x3));
1012 case 0xbc2: /* DMA_LCD_CCR */
1013 s
->mode_f2
= (value
>> 14) & 0x3;
1014 s
->mode_f1
= (value
>> 12) & 0x3;
1015 s
->end_prog
= (value
>> 11) & 0x1;
1016 s
->omap_3_1_compatible_disable
= (value
>> 10) & 0x1;
1017 s
->repeat
= (value
>> 9) & 0x1;
1018 s
->auto_init
= (value
>> 8) & 0x1;
1019 s
->running
= (value
>> 7) & 0x1;
1020 s
->priority
= (value
>> 6) & 0x1;
1021 s
->bs
= (value
>> 4) & 0x1;
1024 case 0xbc4: /* DMA_LCD_CTRL */
1025 s
->dst
= (value
>> 8) & 0x1;
1026 s
->src
= ((value
>> 6) & 0x3) << 1;
1028 /* Assume no bus errors and thus no BUS_ERROR irq bits. */
1029 s
->interrupts
= (value
>> 1) & 1;
1030 s
->dual
= value
& 1;
1033 case 0xbc8: /* TOP_B1_L */
1034 s
->src_f1_top
&= 0xffff0000;
1035 s
->src_f1_top
|= 0x0000ffff & value
;
1038 case 0xbca: /* TOP_B1_U */
1039 s
->src_f1_top
&= 0x0000ffff;
1040 s
->src_f1_top
|= value
<< 16;
1043 case 0xbcc: /* BOT_B1_L */
1044 s
->src_f1_bottom
&= 0xffff0000;
1045 s
->src_f1_bottom
|= 0x0000ffff & value
;
1048 case 0xbce: /* BOT_B1_U */
1049 s
->src_f1_bottom
&= 0x0000ffff;
1050 s
->src_f1_bottom
|= (uint32_t) value
<< 16;
1053 case 0xbd0: /* TOP_B2_L */
1054 s
->src_f2_top
&= 0xffff0000;
1055 s
->src_f2_top
|= 0x0000ffff & value
;
1058 case 0xbd2: /* TOP_B2_U */
1059 s
->src_f2_top
&= 0x0000ffff;
1060 s
->src_f2_top
|= (uint32_t) value
<< 16;
1063 case 0xbd4: /* BOT_B2_L */
1064 s
->src_f2_bottom
&= 0xffff0000;
1065 s
->src_f2_bottom
|= 0x0000ffff & value
;
1068 case 0xbd6: /* BOT_B2_U */
1069 s
->src_f2_bottom
&= 0x0000ffff;
1070 s
->src_f2_bottom
|= (uint32_t) value
<< 16;
1073 case 0xbd8: /* DMA_LCD_SRC_EI_B1 */
1074 s
->element_index_f1
= value
;
1077 case 0xbda: /* DMA_LCD_SRC_FI_B1_L */
1078 s
->frame_index_f1
&= 0xffff0000;
1079 s
->frame_index_f1
|= 0x0000ffff & value
;
1082 case 0xbf4: /* DMA_LCD_SRC_FI_B1_U */
1083 s
->frame_index_f1
&= 0x0000ffff;
1084 s
->frame_index_f1
|= (uint32_t) value
<< 16;
1087 case 0xbdc: /* DMA_LCD_SRC_EI_B2 */
1088 s
->element_index_f2
= value
;
1091 case 0xbde: /* DMA_LCD_SRC_FI_B2_L */
1092 s
->frame_index_f2
&= 0xffff0000;
1093 s
->frame_index_f2
|= 0x0000ffff & value
;
1096 case 0xbf6: /* DMA_LCD_SRC_FI_B2_U */
1097 s
->frame_index_f2
&= 0x0000ffff;
1098 s
->frame_index_f2
|= (uint32_t) value
<< 16;
1101 case 0xbe0: /* DMA_LCD_SRC_EN_B1 */
1102 s
->elements_f1
= value
;
1105 case 0xbe4: /* DMA_LCD_SRC_FN_B1 */
1106 s
->frames_f1
= value
;
1109 case 0xbe2: /* DMA_LCD_SRC_EN_B2 */
1110 s
->elements_f2
= value
;
1113 case 0xbe6: /* DMA_LCD_SRC_FN_B2 */
1114 s
->frames_f2
= value
;
1117 case 0xbea: /* DMA_LCD_LCH_CTRL */
1118 s
->lch_type
= value
& 0xf;
1127 static int omap_dma_3_2_lcd_read(struct omap_dma_lcd_channel_s
*s
, int offset
,
1131 case 0xbc0: /* DMA_LCD_CSDP */
1132 *ret
= (s
->brust_f2
<< 14) |
1133 (s
->pack_f2
<< 13) |
1134 ((s
->data_type_f2
>> 1) << 11) |
1135 (s
->brust_f1
<< 7) |
1137 ((s
->data_type_f1
>> 1) << 0);
1140 case 0xbc2: /* DMA_LCD_CCR */
1141 *ret
= (s
->mode_f2
<< 14) |
1142 (s
->mode_f1
<< 12) |
1143 (s
->end_prog
<< 11) |
1144 (s
->omap_3_1_compatible_disable
<< 10) |
1146 (s
->auto_init
<< 8) |
1148 (s
->priority
<< 6) |
1152 case 0xbc4: /* DMA_LCD_CTRL */
1153 qemu_irq_lower(s
->irq
);
1154 *ret
= (s
->dst
<< 8) |
1155 ((s
->src
& 0x6) << 5) |
1156 (s
->condition
<< 3) |
1157 (s
->interrupts
<< 1) |
1161 case 0xbc8: /* TOP_B1_L */
1162 *ret
= s
->src_f1_top
& 0xffff;
1165 case 0xbca: /* TOP_B1_U */
1166 *ret
= s
->src_f1_top
>> 16;
1169 case 0xbcc: /* BOT_B1_L */
1170 *ret
= s
->src_f1_bottom
& 0xffff;
1173 case 0xbce: /* BOT_B1_U */
1174 *ret
= s
->src_f1_bottom
>> 16;
1177 case 0xbd0: /* TOP_B2_L */
1178 *ret
= s
->src_f2_top
& 0xffff;
1181 case 0xbd2: /* TOP_B2_U */
1182 *ret
= s
->src_f2_top
>> 16;
1185 case 0xbd4: /* BOT_B2_L */
1186 *ret
= s
->src_f2_bottom
& 0xffff;
1189 case 0xbd6: /* BOT_B2_U */
1190 *ret
= s
->src_f2_bottom
>> 16;
1193 case 0xbd8: /* DMA_LCD_SRC_EI_B1 */
1194 *ret
= s
->element_index_f1
;
1197 case 0xbda: /* DMA_LCD_SRC_FI_B1_L */
1198 *ret
= s
->frame_index_f1
& 0xffff;
1201 case 0xbf4: /* DMA_LCD_SRC_FI_B1_U */
1202 *ret
= s
->frame_index_f1
>> 16;
1205 case 0xbdc: /* DMA_LCD_SRC_EI_B2 */
1206 *ret
= s
->element_index_f2
;
1209 case 0xbde: /* DMA_LCD_SRC_FI_B2_L */
1210 *ret
= s
->frame_index_f2
& 0xffff;
1213 case 0xbf6: /* DMA_LCD_SRC_FI_B2_U */
1214 *ret
= s
->frame_index_f2
>> 16;
1217 case 0xbe0: /* DMA_LCD_SRC_EN_B1 */
1218 *ret
= s
->elements_f1
;
1221 case 0xbe4: /* DMA_LCD_SRC_FN_B1 */
1222 *ret
= s
->frames_f1
;
1225 case 0xbe2: /* DMA_LCD_SRC_EN_B2 */
1226 *ret
= s
->elements_f2
;
1229 case 0xbe6: /* DMA_LCD_SRC_FN_B2 */
1230 *ret
= s
->frames_f2
;
1233 case 0xbea: /* DMA_LCD_LCH_CTRL */
1243 static int omap_dma_3_1_lcd_write(struct omap_dma_lcd_channel_s
*s
, int offset
,
1247 case 0x300: /* SYS_DMA_LCD_CTRL */
1248 s
->src
= (value
& 0x40) ? imif
: emiff
;
1250 /* Assume no bus errors and thus no BUS_ERROR irq bits. */
1251 s
->interrupts
= (value
>> 1) & 1;
1252 s
->dual
= value
& 1;
1255 case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
1256 s
->src_f1_top
&= 0xffff0000;
1257 s
->src_f1_top
|= 0x0000ffff & value
;
1260 case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
1261 s
->src_f1_top
&= 0x0000ffff;
1262 s
->src_f1_top
|= value
<< 16;
1265 case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
1266 s
->src_f1_bottom
&= 0xffff0000;
1267 s
->src_f1_bottom
|= 0x0000ffff & value
;
1270 case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
1271 s
->src_f1_bottom
&= 0x0000ffff;
1272 s
->src_f1_bottom
|= value
<< 16;
1275 case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
1276 s
->src_f2_top
&= 0xffff0000;
1277 s
->src_f2_top
|= 0x0000ffff & value
;
1280 case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
1281 s
->src_f2_top
&= 0x0000ffff;
1282 s
->src_f2_top
|= value
<< 16;
1285 case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
1286 s
->src_f2_bottom
&= 0xffff0000;
1287 s
->src_f2_bottom
|= 0x0000ffff & value
;
1290 case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
1291 s
->src_f2_bottom
&= 0x0000ffff;
1292 s
->src_f2_bottom
|= value
<< 16;
1301 static int omap_dma_3_1_lcd_read(struct omap_dma_lcd_channel_s
*s
, int offset
,
1307 case 0x300: /* SYS_DMA_LCD_CTRL */
1310 qemu_irq_lower(s
->irq
);
1311 *ret
= ((s
->src
== imif
) << 6) | (i
<< 3) |
1312 (s
->interrupts
<< 1) | s
->dual
;
1315 case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
1316 *ret
= s
->src_f1_top
& 0xffff;
1319 case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
1320 *ret
= s
->src_f1_top
>> 16;
1323 case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
1324 *ret
= s
->src_f1_bottom
& 0xffff;
1327 case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
1328 *ret
= s
->src_f1_bottom
>> 16;
1331 case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
1332 *ret
= s
->src_f2_top
& 0xffff;
1335 case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
1336 *ret
= s
->src_f2_top
>> 16;
1339 case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
1340 *ret
= s
->src_f2_bottom
& 0xffff;
1343 case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
1344 *ret
= s
->src_f2_bottom
>> 16;
1353 static int omap_dma_sys_write(struct omap_dma_s
*s
, int offset
, uint16_t value
)
1356 case 0x400: /* SYS_DMA_GCR */
1360 case 0x404: /* DMA_GSCR */
1362 omap_dma_disable_3_1_mapping(s
);
1364 omap_dma_enable_3_1_mapping(s
);
1367 case 0x408: /* DMA_GRST */
1369 omap_dma_reset(s
->dma
);
1378 static int omap_dma_sys_read(struct omap_dma_s
*s
, int offset
,
1382 case 0x400: /* SYS_DMA_GCR */
1386 case 0x404: /* DMA_GSCR */
1387 *ret
= s
->omap_3_1_mapping_disabled
<< 3;
1390 case 0x408: /* DMA_GRST */
1394 case 0x442: /* DMA_HW_ID */
1395 case 0x444: /* DMA_PCh2_ID */
1396 case 0x446: /* DMA_PCh0_ID */
1397 case 0x448: /* DMA_PCh1_ID */
1398 case 0x44a: /* DMA_PChG_ID */
1399 case 0x44c: /* DMA_PChD_ID */
1403 case 0x44e: /* DMA_CAPS_0_U */
1404 *ret
= (s
->caps
[0] >> 16) & 0xffff;
1406 case 0x450: /* DMA_CAPS_0_L */
1407 *ret
= (s
->caps
[0] >> 0) & 0xffff;
1410 case 0x452: /* DMA_CAPS_1_U */
1411 *ret
= (s
->caps
[1] >> 16) & 0xffff;
1413 case 0x454: /* DMA_CAPS_1_L */
1414 *ret
= (s
->caps
[1] >> 0) & 0xffff;
1417 case 0x456: /* DMA_CAPS_2 */
1421 case 0x458: /* DMA_CAPS_3 */
1425 case 0x45a: /* DMA_CAPS_4 */
1429 case 0x460: /* DMA_PCh2_SR */
1430 case 0x480: /* DMA_PCh0_SR */
1431 case 0x482: /* DMA_PCh1_SR */
1432 case 0x4c0: /* DMA_PChD_SR_0 */
1433 printf("%s: Physical Channel Status Registers not implemented.\n",
1444 static uint32_t omap_dma_read(void *opaque
, target_phys_addr_t addr
)
1446 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1451 case 0x300 ... 0x3fe:
1452 if (s
->model
<= omap_dma_3_1
|| !s
->omap_3_1_mapping_disabled
) {
1453 if (omap_dma_3_1_lcd_read(&s
->lcd_ch
, addr
, &ret
))
1458 case 0x000 ... 0x2fe:
1460 ch
= (addr
>> 6) & 0x0f;
1461 if (omap_dma_ch_reg_read(s
, &s
->ch
[ch
], reg
, &ret
))
1465 case 0x404 ... 0x4fe:
1466 if (s
->model
<= omap_dma_3_1
)
1470 if (omap_dma_sys_read(s
, addr
, &ret
))
1474 case 0xb00 ... 0xbfe:
1475 if (s
->model
== omap_dma_3_2
&& s
->omap_3_1_mapping_disabled
) {
1476 if (omap_dma_3_2_lcd_read(&s
->lcd_ch
, addr
, &ret
))
1487 static void omap_dma_write(void *opaque
, target_phys_addr_t addr
,
1490 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1494 case 0x300 ... 0x3fe:
1495 if (s
->model
<= omap_dma_3_1
|| !s
->omap_3_1_mapping_disabled
) {
1496 if (omap_dma_3_1_lcd_write(&s
->lcd_ch
, addr
, value
))
1501 case 0x000 ... 0x2fe:
1503 ch
= (addr
>> 6) & 0x0f;
1504 if (omap_dma_ch_reg_write(s
, &s
->ch
[ch
], reg
, value
))
1508 case 0x404 ... 0x4fe:
1509 if (s
->model
<= omap_dma_3_1
)
1513 if (omap_dma_sys_write(s
, addr
, value
))
1517 case 0xb00 ... 0xbfe:
1518 if (s
->model
== omap_dma_3_2
&& s
->omap_3_1_mapping_disabled
) {
1519 if (omap_dma_3_2_lcd_write(&s
->lcd_ch
, addr
, value
))
1529 static CPUReadMemoryFunc
*omap_dma_readfn
[] = {
1530 omap_badwidth_read16
,
1532 omap_badwidth_read16
,
1535 static CPUWriteMemoryFunc
*omap_dma_writefn
[] = {
1536 omap_badwidth_write16
,
1538 omap_badwidth_write16
,
1541 static void omap_dma_request(void *opaque
, int drq
, int req
)
1543 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1544 /* The request pins are level triggered in QEMU. */
1546 if (~s
->dma
->drqbmp
& (1 << drq
)) {
1547 s
->dma
->drqbmp
|= 1 << drq
;
1548 omap_dma_process_request(s
, drq
);
1551 s
->dma
->drqbmp
&= ~(1 << drq
);
1554 /* XXX: this won't be needed once soc_dma knows about clocks. */
1555 static void omap_dma_clk_update(void *opaque
, int line
, int on
)
1557 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1560 s
->dma
->freq
= omap_clk_getrate(s
->clk
);
1562 for (i
= 0; i
< s
->chans
; i
++)
1563 if (s
->ch
[i
].active
)
1564 soc_dma_set_request(s
->ch
[i
].dma
, on
);
1567 static void omap_dma_setcaps(struct omap_dma_s
*s
)
1575 /* XXX Only available for sDMA */
1577 (1 << 19) | /* Constant Fill Capability */
1578 (1 << 18); /* Transparent BLT Capability */
1580 (1 << 1); /* 1-bit palettized capability (DMA 3.2 only) */
1582 (1 << 8) | /* SEPARATE_SRC_AND_DST_INDEX_CPBLTY */
1583 (1 << 7) | /* DST_DOUBLE_INDEX_ADRS_CPBLTY */
1584 (1 << 6) | /* DST_SINGLE_INDEX_ADRS_CPBLTY */
1585 (1 << 5) | /* DST_POST_INCRMNT_ADRS_CPBLTY */
1586 (1 << 4) | /* DST_CONST_ADRS_CPBLTY */
1587 (1 << 3) | /* SRC_DOUBLE_INDEX_ADRS_CPBLTY */
1588 (1 << 2) | /* SRC_SINGLE_INDEX_ADRS_CPBLTY */
1589 (1 << 1) | /* SRC_POST_INCRMNT_ADRS_CPBLTY */
1590 (1 << 0); /* SRC_CONST_ADRS_CPBLTY */
1592 (1 << 6) | /* BLOCK_SYNCHR_CPBLTY (DMA 4 only) */
1593 (1 << 7) | /* PKT_SYNCHR_CPBLTY (DMA 4 only) */
1594 (1 << 5) | /* CHANNEL_CHAINING_CPBLTY */
1595 (1 << 4) | /* LCh_INTERLEAVE_CPBLTY */
1596 (1 << 3) | /* AUTOINIT_REPEAT_CPBLTY (DMA 3.2 only) */
1597 (1 << 2) | /* AUTOINIT_ENDPROG_CPBLTY (DMA 3.2 only) */
1598 (1 << 1) | /* FRAME_SYNCHR_CPBLTY */
1599 (1 << 0); /* ELMNT_SYNCHR_CPBLTY */
1601 (1 << 7) | /* PKT_INTERRUPT_CPBLTY (DMA 4 only) */
1602 (1 << 6) | /* SYNC_STATUS_CPBLTY */
1603 (1 << 5) | /* BLOCK_INTERRUPT_CPBLTY */
1604 (1 << 4) | /* LAST_FRAME_INTERRUPT_CPBLTY */
1605 (1 << 3) | /* FRAME_INTERRUPT_CPBLTY */
1606 (1 << 2) | /* HALF_FRAME_INTERRUPT_CPBLTY */
1607 (1 << 1) | /* EVENT_DROP_INTERRUPT_CPBLTY */
1608 (1 << 0); /* TIMEOUT_INTERRUPT_CPBLTY (DMA 3.2 only) */
1613 struct soc_dma_s
*omap_dma_init(target_phys_addr_t base
, qemu_irq
*irqs
,
1614 qemu_irq lcd_irq
, struct omap_mpu_state_s
*mpu
, omap_clk clk
,
1615 enum omap_dma_model model
)
1617 int iomemtype
, num_irqs
, memsize
, i
;
1618 struct omap_dma_s
*s
= (struct omap_dma_s
*)
1619 qemu_mallocz(sizeof(struct omap_dma_s
));
1621 if (model
<= omap_dma_3_1
) {
1631 s
->lcd_ch
.irq
= lcd_irq
;
1632 s
->lcd_ch
.mpu
= mpu
;
1634 s
->dma
= soc_dma_init((model
<= omap_dma_3_1
) ? 9 : 16);
1635 s
->dma
->freq
= omap_clk_getrate(clk
);
1636 s
->dma
->transfer_fn
= omap_dma_transfer_generic
;
1637 s
->dma
->setup_fn
= omap_dma_transfer_setup
;
1638 s
->dma
->drq
= qemu_allocate_irqs(omap_dma_request
, s
, 32);
1642 s
->ch
[num_irqs
].irq
= irqs
[num_irqs
];
1643 for (i
= 0; i
< 3; i
++) {
1644 s
->ch
[i
].sibling
= &s
->ch
[i
+ 6];
1645 s
->ch
[i
+ 6].sibling
= &s
->ch
[i
];
1647 for (i
= (model
<= omap_dma_3_1
) ? 8 : 15; i
>= 0; i
--) {
1648 s
->ch
[i
].dma
= &s
->dma
->ch
[i
];
1649 s
->dma
->ch
[i
].opaque
= &s
->ch
[i
];
1652 omap_dma_setcaps(s
);
1653 omap_clk_adduser(s
->clk
, qemu_allocate_irqs(omap_dma_clk_update
, s
, 1)[0]);
1654 omap_dma_reset(s
->dma
);
1655 omap_dma_clk_update(s
, 0, 1);
1657 iomemtype
= cpu_register_io_memory(omap_dma_readfn
,
1658 omap_dma_writefn
, s
);
1659 cpu_register_physical_memory(base
, memsize
, iomemtype
);
1661 mpu
->drq
= s
->dma
->drq
;
1666 static void omap_dma_interrupts_4_update(struct omap_dma_s
*s
)
1668 struct omap_dma_channel_s
*ch
= s
->ch
;
1671 for (bmp
= 0, bit
= 1; bit
; ch
++, bit
<<= 1)
1674 ch
->cstatus
|= ch
->status
;
1677 if ((s
->irqstat
[0] |= s
->irqen
[0] & bmp
))
1678 qemu_irq_raise(s
->irq
[0]);
1679 if ((s
->irqstat
[1] |= s
->irqen
[1] & bmp
))
1680 qemu_irq_raise(s
->irq
[1]);
1681 if ((s
->irqstat
[2] |= s
->irqen
[2] & bmp
))
1682 qemu_irq_raise(s
->irq
[2]);
1683 if ((s
->irqstat
[3] |= s
->irqen
[3] & bmp
))
1684 qemu_irq_raise(s
->irq
[3]);
1687 static uint32_t omap_dma4_read(void *opaque
, target_phys_addr_t addr
)
1689 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1690 int irqn
= 0, chnum
;
1691 struct omap_dma_channel_s
*ch
;
1694 case 0x00: /* DMA4_REVISION */
1697 case 0x14: /* DMA4_IRQSTATUS_L3 */
1699 case 0x10: /* DMA4_IRQSTATUS_L2 */
1701 case 0x0c: /* DMA4_IRQSTATUS_L1 */
1703 case 0x08: /* DMA4_IRQSTATUS_L0 */
1704 return s
->irqstat
[irqn
];
1706 case 0x24: /* DMA4_IRQENABLE_L3 */
1708 case 0x20: /* DMA4_IRQENABLE_L2 */
1710 case 0x1c: /* DMA4_IRQENABLE_L1 */
1712 case 0x18: /* DMA4_IRQENABLE_L0 */
1713 return s
->irqen
[irqn
];
1715 case 0x28: /* DMA4_SYSSTATUS */
1716 return 1; /* RESETDONE */
1718 case 0x2c: /* DMA4_OCP_SYSCONFIG */
1721 case 0x64: /* DMA4_CAPS_0 */
1723 case 0x6c: /* DMA4_CAPS_2 */
1725 case 0x70: /* DMA4_CAPS_3 */
1727 case 0x74: /* DMA4_CAPS_4 */
1730 case 0x78: /* DMA4_GCR */
1733 case 0x80 ... 0xfff:
1735 chnum
= addr
/ 0x60;
1737 addr
-= chnum
* 0x60;
1745 /* Per-channel registers */
1747 case 0x00: /* DMA4_CCR */
1748 return (ch
->buf_disable
<< 25) |
1749 (ch
->src_sync
<< 24) |
1750 (ch
->prefetch
<< 23) |
1751 ((ch
->sync
& 0x60) << 14) |
1753 (ch
->transparent_copy
<< 17) |
1754 (ch
->constant_fill
<< 16) |
1755 (ch
->mode
[1] << 14) |
1756 (ch
->mode
[0] << 12) |
1757 (0 << 10) | (0 << 9) |
1758 (ch
->suspend
<< 8) |
1760 (ch
->priority
<< 6) |
1761 (ch
->fs
<< 5) | (ch
->sync
& 0x1f);
1763 case 0x04: /* DMA4_CLNK_CTRL */
1764 return (ch
->link_enabled
<< 15) | ch
->link_next_ch
;
1766 case 0x08: /* DMA4_CICR */
1767 return ch
->interrupts
;
1769 case 0x0c: /* DMA4_CSR */
1772 case 0x10: /* DMA4_CSDP */
1773 return (ch
->endian
[0] << 21) |
1774 (ch
->endian_lock
[0] << 20) |
1775 (ch
->endian
[1] << 19) |
1776 (ch
->endian_lock
[1] << 18) |
1777 (ch
->write_mode
<< 16) |
1778 (ch
->burst
[1] << 14) |
1779 (ch
->pack
[1] << 13) |
1780 (ch
->translate
[1] << 9) |
1781 (ch
->burst
[0] << 7) |
1782 (ch
->pack
[0] << 6) |
1783 (ch
->translate
[0] << 2) |
1784 (ch
->data_type
>> 1);
1786 case 0x14: /* DMA4_CEN */
1787 return ch
->elements
;
1789 case 0x18: /* DMA4_CFN */
1792 case 0x1c: /* DMA4_CSSA */
1795 case 0x20: /* DMA4_CDSA */
1798 case 0x24: /* DMA4_CSEI */
1799 return ch
->element_index
[0];
1801 case 0x28: /* DMA4_CSFI */
1802 return ch
->frame_index
[0];
1804 case 0x2c: /* DMA4_CDEI */
1805 return ch
->element_index
[1];
1807 case 0x30: /* DMA4_CDFI */
1808 return ch
->frame_index
[1];
1810 case 0x34: /* DMA4_CSAC */
1811 return ch
->active_set
.src
& 0xffff;
1813 case 0x38: /* DMA4_CDAC */
1814 return ch
->active_set
.dest
& 0xffff;
1816 case 0x3c: /* DMA4_CCEN */
1817 return ch
->active_set
.element
;
1819 case 0x40: /* DMA4_CCFN */
1820 return ch
->active_set
.frame
;
1822 case 0x44: /* DMA4_COLOR */
1823 /* XXX only in sDMA */
1832 static void omap_dma4_write(void *opaque
, target_phys_addr_t addr
,
1835 struct omap_dma_s
*s
= (struct omap_dma_s
*) opaque
;
1836 int chnum
, irqn
= 0;
1837 struct omap_dma_channel_s
*ch
;
1840 case 0x14: /* DMA4_IRQSTATUS_L3 */
1842 case 0x10: /* DMA4_IRQSTATUS_L2 */
1844 case 0x0c: /* DMA4_IRQSTATUS_L1 */
1846 case 0x08: /* DMA4_IRQSTATUS_L0 */
1847 s
->irqstat
[irqn
] &= ~value
;
1848 if (!s
->irqstat
[irqn
])
1849 qemu_irq_lower(s
->irq
[irqn
]);
1852 case 0x24: /* DMA4_IRQENABLE_L3 */
1854 case 0x20: /* DMA4_IRQENABLE_L2 */
1856 case 0x1c: /* DMA4_IRQENABLE_L1 */
1858 case 0x18: /* DMA4_IRQENABLE_L0 */
1859 s
->irqen
[irqn
] = value
;
1862 case 0x2c: /* DMA4_OCP_SYSCONFIG */
1863 if (value
& 2) /* SOFTRESET */
1864 omap_dma_reset(s
->dma
);
1865 s
->ocp
= value
& 0x3321;
1866 if (((s
->ocp
>> 12) & 3) == 3) /* MIDLEMODE */
1867 fprintf(stderr
, "%s: invalid DMA power mode\n", __FUNCTION__
);
1870 case 0x78: /* DMA4_GCR */
1871 s
->gcr
= value
& 0x00ff00ff;
1872 if ((value
& 0xff) == 0x00) /* MAX_CHANNEL_FIFO_DEPTH */
1873 fprintf(stderr
, "%s: wrong FIFO depth in GCR\n", __FUNCTION__
);
1876 case 0x80 ... 0xfff:
1878 chnum
= addr
/ 0x60;
1880 addr
-= chnum
* 0x60;
1883 case 0x00: /* DMA4_REVISION */
1884 case 0x28: /* DMA4_SYSSTATUS */
1885 case 0x64: /* DMA4_CAPS_0 */
1886 case 0x6c: /* DMA4_CAPS_2 */
1887 case 0x70: /* DMA4_CAPS_3 */
1888 case 0x74: /* DMA4_CAPS_4 */
1897 /* Per-channel registers */
1899 case 0x00: /* DMA4_CCR */
1900 ch
->buf_disable
= (value
>> 25) & 1;
1901 ch
->src_sync
= (value
>> 24) & 1; /* XXX For CamDMA must be 1 */
1902 if (ch
->buf_disable
&& !ch
->src_sync
)
1903 fprintf(stderr
, "%s: Buffering disable is not allowed in "
1904 "destination synchronised mode\n", __FUNCTION__
);
1905 ch
->prefetch
= (value
>> 23) & 1;
1906 ch
->bs
= (value
>> 18) & 1;
1907 ch
->transparent_copy
= (value
>> 17) & 1;
1908 ch
->constant_fill
= (value
>> 16) & 1;
1909 ch
->mode
[1] = (omap_dma_addressing_t
) ((value
& 0xc000) >> 14);
1910 ch
->mode
[0] = (omap_dma_addressing_t
) ((value
& 0x3000) >> 12);
1911 ch
->suspend
= (value
& 0x0100) >> 8;
1912 ch
->priority
= (value
& 0x0040) >> 6;
1913 ch
->fs
= (value
& 0x0020) >> 5;
1914 if (ch
->fs
&& ch
->bs
&& ch
->mode
[0] && ch
->mode
[1])
1915 fprintf(stderr
, "%s: For a packet transfer at least one port "
1916 "must be constant-addressed\n", __FUNCTION__
);
1917 ch
->sync
= (value
& 0x001f) | ((value
>> 14) & 0x0060);
1918 /* XXX must be 0x01 for CamDMA */
1921 omap_dma_enable_channel(s
, ch
);
1923 omap_dma_disable_channel(s
, ch
);
1927 case 0x04: /* DMA4_CLNK_CTRL */
1928 ch
->link_enabled
= (value
>> 15) & 0x1;
1929 ch
->link_next_ch
= value
& 0x1f;
1932 case 0x08: /* DMA4_CICR */
1933 ch
->interrupts
= value
& 0x09be;
1936 case 0x0c: /* DMA4_CSR */
1937 ch
->cstatus
&= ~value
;
1940 case 0x10: /* DMA4_CSDP */
1941 ch
->endian
[0] =(value
>> 21) & 1;
1942 ch
->endian_lock
[0] =(value
>> 20) & 1;
1943 ch
->endian
[1] =(value
>> 19) & 1;
1944 ch
->endian_lock
[1] =(value
>> 18) & 1;
1945 if (ch
->endian
[0] != ch
->endian
[1])
1946 fprintf(stderr
, "%s: DMA endiannes conversion enable attempt\n",
1948 ch
->write_mode
= (value
>> 16) & 3;
1949 ch
->burst
[1] = (value
& 0xc000) >> 14;
1950 ch
->pack
[1] = (value
& 0x2000) >> 13;
1951 ch
->translate
[1] = (value
& 0x1e00) >> 9;
1952 ch
->burst
[0] = (value
& 0x0180) >> 7;
1953 ch
->pack
[0] = (value
& 0x0040) >> 6;
1954 ch
->translate
[0] = (value
& 0x003c) >> 2;
1955 if (ch
->translate
[0] | ch
->translate
[1])
1956 fprintf(stderr
, "%s: bad MReqAddressTranslate sideband signal\n",
1958 ch
->data_type
= 1 << (value
& 3);
1959 if ((value
& 3) == 3)
1960 printf("%s: bad data_type for DMA channel\n", __FUNCTION__
);
1963 case 0x14: /* DMA4_CEN */
1965 ch
->elements
= value
& 0xffffff;
1968 case 0x18: /* DMA4_CFN */
1969 ch
->frames
= value
& 0xffff;
1973 case 0x1c: /* DMA4_CSSA */
1974 ch
->addr
[0] = (target_phys_addr_t
) (uint32_t) value
;
1978 case 0x20: /* DMA4_CDSA */
1979 ch
->addr
[1] = (target_phys_addr_t
) (uint32_t) value
;
1983 case 0x24: /* DMA4_CSEI */
1984 ch
->element_index
[0] = (int16_t) value
;
1988 case 0x28: /* DMA4_CSFI */
1989 ch
->frame_index
[0] = (int32_t) value
;
1993 case 0x2c: /* DMA4_CDEI */
1994 ch
->element_index
[1] = (int16_t) value
;
1998 case 0x30: /* DMA4_CDFI */
1999 ch
->frame_index
[1] = (int32_t) value
;
2003 case 0x44: /* DMA4_COLOR */
2004 /* XXX only in sDMA */
2008 case 0x34: /* DMA4_CSAC */
2009 case 0x38: /* DMA4_CDAC */
2010 case 0x3c: /* DMA4_CCEN */
2011 case 0x40: /* DMA4_CCFN */
2020 static CPUReadMemoryFunc
*omap_dma4_readfn
[] = {
2021 omap_badwidth_read16
,
2026 static CPUWriteMemoryFunc
*omap_dma4_writefn
[] = {
2027 omap_badwidth_write16
,
2032 struct soc_dma_s
*omap_dma4_init(target_phys_addr_t base
, qemu_irq
*irqs
,
2033 struct omap_mpu_state_s
*mpu
, int fifo
,
2034 int chans
, omap_clk iclk
, omap_clk fclk
)
2037 struct omap_dma_s
*s
= (struct omap_dma_s
*)
2038 qemu_mallocz(sizeof(struct omap_dma_s
));
2040 s
->model
= omap_dma_4
;
2045 s
->dma
= soc_dma_init(s
->chans
);
2046 s
->dma
->freq
= omap_clk_getrate(fclk
);
2047 s
->dma
->transfer_fn
= omap_dma_transfer_generic
;
2048 s
->dma
->setup_fn
= omap_dma_transfer_setup
;
2049 s
->dma
->drq
= qemu_allocate_irqs(omap_dma_request
, s
, 64);
2051 for (i
= 0; i
< s
->chans
; i
++) {
2052 s
->ch
[i
].dma
= &s
->dma
->ch
[i
];
2053 s
->dma
->ch
[i
].opaque
= &s
->ch
[i
];
2056 memcpy(&s
->irq
, irqs
, sizeof(s
->irq
));
2057 s
->intr_update
= omap_dma_interrupts_4_update
;
2059 omap_dma_setcaps(s
);
2060 omap_clk_adduser(s
->clk
, qemu_allocate_irqs(omap_dma_clk_update
, s
, 1)[0]);
2061 omap_dma_reset(s
->dma
);
2062 omap_dma_clk_update(s
, 0, !!s
->dma
->freq
);
2064 iomemtype
= cpu_register_io_memory(omap_dma4_readfn
,
2065 omap_dma4_writefn
, s
);
2066 cpu_register_physical_memory(base
, 0x1000, iomemtype
);
2068 mpu
->drq
= s
->dma
->drq
;
2073 struct omap_dma_lcd_channel_s
*omap_dma_get_lcdch(struct soc_dma_s
*dma
)
2075 struct omap_dma_s
*s
= dma
->opaque
;