20
#include "qemu/osdep.h"
22
#include "qemu/timer.h"
23
#include "hw/arm/omap.h"
25
#include "hw/arm/soc_dma.h"
27
struct omap_dma_channel_s {
34
enum omap_dma_port port[2];
36
omap_dma_addressing_t mode[2];
39
int32_t frame_index[2];
40
int16_t element_index[2];
76
int omap_3_1_compatible_disable;
79
struct omap_dma_channel_s *sibling;
81
struct omap_dma_reg_set_s {
93
struct soc_dma_ch_s *dma;
98
int interleave_disabled;
105
struct soc_dma_s *dma;
108
struct omap_mpu_state_s *mpu;
111
void (*intr_update)(struct omap_dma_s *s);
112
enum omap_dma_model model;
113
int omap_3_1_mapping_disabled;
122
struct omap_dma_channel_s ch[32];
123
struct omap_dma_lcd_channel_s lcd_ch;
127
#define TIMEOUT_INTR (1 << 0)
128
#define EVENT_DROP_INTR (1 << 1)
129
#define HALF_FRAME_INTR (1 << 2)
130
#define END_FRAME_INTR (1 << 3)
131
#define LAST_FRAME_INTR (1 << 4)
132
#define END_BLOCK_INTR (1 << 5)
134
#define END_PKT_INTR (1 << 7)
135
#define TRANS_ERR_INTR (1 << 8)
136
#define MISALIGN_INTR (1 << 11)
138
static inline void omap_dma_interrupts_update(struct omap_dma_s *s)
143
static void omap_dma_channel_load(struct omap_dma_channel_s *ch)
145
struct omap_dma_reg_set_s *a = &ch->active_set;
147
int omap_3_1 = !ch->omap_3_1_compatible_disable;
154
a->src = ch->addr[0];
155
a->dest = ch->addr[1];
156
a->frames = ch->frames;
157
a->elements = ch->elements;
158
a->pck_elements = ch->frame_index[!ch->src_sync];
163
if (unlikely(!ch->elements || !ch->frames)) {
164
printf("%s: bad DMA request\n", __func__);
168
for (i = 0; i < 2; i ++)
169
switch (ch->mode[i]) {
171
a->elem_delta[i] = 0;
172
a->frame_delta[i] = 0;
174
case post_incremented:
175
a->elem_delta[i] = ch->data_type;
176
a->frame_delta[i] = 0;
179
a->elem_delta[i] = ch->data_type +
180
ch->element_index[omap_3_1 ? 0 : i] - 1;
181
a->frame_delta[i] = 0;
184
a->elem_delta[i] = ch->data_type +
185
ch->element_index[omap_3_1 ? 0 : i] - 1;
186
a->frame_delta[i] = ch->frame_index[omap_3_1 ? 0 : i] -
187
ch->element_index[omap_3_1 ? 0 : i];
193
normal = !ch->transparent_copy && !ch->constant_fill &&
196
(ch->endian[0] | ch->endian_lock[0]) ==
197
(ch->endian[1] | ch->endian_lock[1]);
198
for (i = 0; i < 2; i ++) {
202
if (!a->elem_delta[i] && normal &&
203
(a->frames == 1 || !a->frame_delta[i]))
204
ch->dma->type[i] = soc_dma_access_const;
205
else if (a->elem_delta[i] == ch->data_type && normal &&
206
(a->frames == 1 || !a->frame_delta[i]))
207
ch->dma->type[i] = soc_dma_access_linear;
209
ch->dma->type[i] = soc_dma_access_other;
211
ch->dma->vaddr[i] = ch->addr[i];
213
soc_dma_ch_update(ch->dma);
216
static void omap_dma_activate_channel(struct omap_dma_s *s,
217
struct omap_dma_channel_s *ch)
220
if (ch->set_update) {
227
omap_dma_channel_load(ch);
232
soc_dma_set_request(ch->dma, 1);
238
static void omap_dma_deactivate_channel(struct omap_dma_s *s,
239
struct omap_dma_channel_s *ch)
242
ch->cpc = ch->active_set.dest & 0xffff;
244
if (ch->pending_request && !ch->waiting_end_prog && ch->enable) {
246
ch->pending_request = 0;
252
if (ch->sync && ch->enable && (s->dma->drqbmp & (1ULL << ch->sync)))
258
soc_dma_set_request(ch->dma, 0);
262
static void omap_dma_enable_channel(struct omap_dma_s *s,
263
struct omap_dma_channel_s *ch)
267
ch->waiting_end_prog = 0;
268
omap_dma_channel_load(ch);
272
if ((!ch->sync) || (s->dma->drqbmp & (1ULL << ch->sync))) {
273
omap_dma_activate_channel(s, ch);
278
static void omap_dma_disable_channel(struct omap_dma_s *s,
279
struct omap_dma_channel_s *ch)
284
ch->pending_request = 0;
285
omap_dma_deactivate_channel(s, ch);
289
static void omap_dma_channel_end_prog(struct omap_dma_s *s,
290
struct omap_dma_channel_s *ch)
292
if (ch->waiting_end_prog) {
293
ch->waiting_end_prog = 0;
294
if (!ch->sync || ch->pending_request) {
295
ch->pending_request = 0;
296
omap_dma_activate_channel(s, ch);
301
static void omap_dma_interrupts_3_1_update(struct omap_dma_s *s)
303
struct omap_dma_channel_s *ch = s->ch;
306
if (ch[0].status | ch[6].status)
307
qemu_irq_raise(ch[0].irq);
308
if (ch[1].status | ch[7].status)
309
qemu_irq_raise(ch[1].irq);
310
if (ch[2].status | ch[8].status)
311
qemu_irq_raise(ch[2].irq);
313
qemu_irq_raise(ch[3].irq);
315
qemu_irq_raise(ch[4].irq);
317
qemu_irq_raise(ch[5].irq);
320
static void omap_dma_interrupts_3_2_update(struct omap_dma_s *s)
322
struct omap_dma_channel_s *ch = s->ch;
325
for (i = s->chans; i; ch ++, i --)
327
qemu_irq_raise(ch->irq);
330
static void omap_dma_enable_3_1_mapping(struct omap_dma_s *s)
332
s->omap_3_1_mapping_disabled = 0;
334
s->intr_update = omap_dma_interrupts_3_1_update;
337
static void omap_dma_disable_3_1_mapping(struct omap_dma_s *s)
339
s->omap_3_1_mapping_disabled = 1;
341
s->intr_update = omap_dma_interrupts_3_2_update;
344
static void omap_dma_process_request(struct omap_dma_s *s, int request)
348
struct omap_dma_channel_s *ch = s->ch;
350
for (channel = 0; channel < s->chans; channel ++, ch ++) {
351
if (ch->enable && ch->sync == request) {
353
omap_dma_activate_channel(s, ch);
354
else if (!ch->pending_request)
355
ch->pending_request = 1;
359
ch->status |= EVENT_DROP_INTR;
366
omap_dma_interrupts_update(s);
369
static void omap_dma_transfer_generic(struct soc_dma_ch_s *dma)
372
struct omap_dma_channel_s *ch = dma->opaque;
373
struct omap_dma_reg_set_s *a = &ch->active_set;
374
int bytes = dma->bytes;
376
uint16_t status = ch->status;
382
if (!ch->constant_fill)
383
cpu_physical_memory_read(a->src, value, ch->data_type);
385
*(uint32_t *) value = ch->color;
387
if (!ch->transparent_copy || *(uint32_t *) value != ch->color)
388
cpu_physical_memory_write(a->dest, value, ch->data_type);
390
a->src += a->elem_delta[0];
391
a->dest += a->elem_delta[1];
395
if (a->element == a->elements) {
398
a->src += a->frame_delta[0];
399
a->dest += a->frame_delta[1];
404
ch->cpc = a->dest & 0xffff;
406
} while ((bytes -= ch->data_type));
409
if (ch->sync && !ch->fs && !ch->bs)
410
omap_dma_deactivate_channel(s, ch);
413
if (a->element == 1 && a->frame == a->frames - 1)
414
if (ch->interrupts & LAST_FRAME_INTR)
415
ch->status |= LAST_FRAME_INTR;
419
if (a->element == (a->elements >> 1))
420
if (ch->interrupts & HALF_FRAME_INTR)
421
ch->status |= HALF_FRAME_INTR;
423
if (ch->fs && ch->bs) {
426
if (a->pck_element == a->pck_elements) {
430
if ((ch->interrupts & END_PKT_INTR) && !ch->src_sync)
431
ch->status |= END_PKT_INTR;
435
omap_dma_deactivate_channel(s, ch);
439
if (a->element == a->elements) {
442
a->src += a->frame_delta[0];
443
a->dest += a->frame_delta[1];
447
if (ch->sync && ch->fs && !ch->bs)
448
omap_dma_deactivate_channel(s, ch);
452
ch->cpc = a->dest & 0xffff;
455
if (ch->interrupts & END_FRAME_INTR)
456
ch->status |= END_FRAME_INTR;
458
if (a->frame == a->frames) {
462
if (ch->omap_3_1_compatible_disable) {
463
omap_dma_disable_channel(s, ch);
464
if (ch->link_enabled)
465
omap_dma_enable_channel(s,
466
&s->ch[ch->link_next_ch]);
469
omap_dma_disable_channel(s, ch);
470
else if (ch->repeat || ch->end_prog)
471
omap_dma_channel_load(ch);
473
ch->waiting_end_prog = 1;
474
omap_dma_deactivate_channel(s, ch);
478
if (ch->interrupts & END_BLOCK_INTR)
479
ch->status |= END_BLOCK_INTR;
482
} while (status == ch->status && ch->active);
484
omap_dma_interrupts_update(s);
489
omap_dma_intr_element_sync,
490
omap_dma_intr_last_frame,
491
omap_dma_intr_half_frame,
493
omap_dma_intr_frame_sync,
494
omap_dma_intr_packet,
495
omap_dma_intr_packet_sync,
497
__omap_dma_intr_last,
500
static void omap_dma_transfer_setup(struct soc_dma_ch_s *dma)
502
struct omap_dma_port_if_s *src_p, *dest_p;
503
struct omap_dma_reg_set_s *a;
504
struct omap_dma_channel_s *ch = dma->opaque;
505
struct omap_dma_s *s = dma->dma->opaque;
506
int frames, min_elems, elements[__omap_dma_intr_last];
510
src_p = &s->mpu->port[ch->port[0]];
511
dest_p = &s->mpu->port[ch->port[1]];
512
if ((!ch->constant_fill && !src_p->addr_valid(s->mpu, a->src)) ||
513
(!dest_p->addr_valid(s->mpu, a->dest))) {
516
if (ch->interrupts & TIMEOUT_INTR)
517
ch->status |= TIMEOUT_INTR;
518
omap_dma_deactivate_channel(s, ch);
521
printf("%s: Bus time-out in DMA%i operation\n",
529
#define INTR_CHECK(cond, id, nelements) \
531
elements[id] = nelements; \
532
if (elements[id] < min_elems) \
533
min_elems = elements[id]; \
535
elements[id] = INT_MAX;
539
ch->sync && !ch->fs && !ch->bs,
540
omap_dma_intr_element_sync,
549
(ch->interrupts & LAST_FRAME_INTR) &&
550
((a->frame < a->frames - 1) || !a->element),
551
omap_dma_intr_last_frame,
552
(a->frames - a->frame - 2) * a->elements +
553
(a->elements - a->element + 1))
555
ch->interrupts & HALF_FRAME_INTR,
556
omap_dma_intr_half_frame,
558
(a->element >= (a->elements >> 1) ? a->elements : 0) -
561
ch->sync && ch->fs && (ch->interrupts & END_FRAME_INTR),
563
a->elements - a->element)
565
ch->sync && ch->fs && !ch->bs,
566
omap_dma_intr_frame_sync,
567
a->elements - a->element)
572
(ch->interrupts & END_PKT_INTR) && !ch->src_sync,
573
omap_dma_intr_packet,
574
a->pck_elements - a->pck_element)
576
ch->fs && ch->bs && ch->sync,
577
omap_dma_intr_packet_sync,
578
a->pck_elements - a->pck_element)
584
(a->frames - a->frame - 1) * a->elements +
585
(a->elements - a->element))
587
dma->bytes = min_elems * ch->data_type;
598
if (min_elems == elements[omap_dma_intr_element_sync])
599
omap_dma_deactivate_channel(s, ch);
602
if (min_elems == elements[omap_dma_intr_last_frame])
603
ch->status |= LAST_FRAME_INTR;
607
if (min_elems == elements[omap_dma_intr_half_frame])
608
ch->status |= HALF_FRAME_INTR;
611
if (min_elems == elements[omap_dma_intr_packet])
612
ch->status |= END_PKT_INTR;
615
if (min_elems == elements[omap_dma_intr_packet_sync])
616
omap_dma_deactivate_channel(s, ch);
619
if (min_elems == elements[omap_dma_intr_frame_sync])
620
omap_dma_deactivate_channel(s, ch);
623
if (min_elems == elements[omap_dma_intr_frame])
624
ch->status |= END_FRAME_INTR;
626
if (min_elems == elements[omap_dma_intr_block]) {
630
if (ch->omap_3_1_compatible_disable) {
631
omap_dma_disable_channel(s, ch);
632
if (ch->link_enabled)
633
omap_dma_enable_channel(s, &s->ch[ch->link_next_ch]);
636
omap_dma_disable_channel(s, ch);
637
else if (ch->repeat || ch->end_prog)
638
omap_dma_channel_load(ch);
640
ch->waiting_end_prog = 1;
641
omap_dma_deactivate_channel(s, ch);
645
if (ch->interrupts & END_BLOCK_INTR)
646
ch->status |= END_BLOCK_INTR;
650
if (ch->fs && ch->bs) {
651
a->pck_element += min_elems;
652
a->pck_element %= a->pck_elements;
660
a->element += min_elems;
662
frames = a->element / a->elements;
663
a->element = a->element % a->elements;
665
a->src += min_elems * a->elem_delta[0] + frames * a->frame_delta[0];
666
a->dest += min_elems * a->elem_delta[1] + frames * a->frame_delta[1];
669
if (!ch->sync && frames)
670
ch->cpc = a->dest & 0xffff;
680
omap_dma_interrupts_update(s);
683
void omap_dma_reset(struct soc_dma_s *dma)
686
struct omap_dma_s *s = dma->opaque;
688
soc_dma_reset(s->dma);
689
if (s->model < omap_dma_4)
694
memset(&s->irqstat, 0, sizeof(s->irqstat));
695
memset(&s->irqen, 0, sizeof(s->irqen));
696
s->lcd_ch.src = emiff;
697
s->lcd_ch.condition = 0;
698
s->lcd_ch.interrupts = 0;
700
if (s->model < omap_dma_4)
701
omap_dma_enable_3_1_mapping(s);
702
for (i = 0; i < s->chans; i ++) {
703
s->ch[i].suspend = 0;
704
s->ch[i].prefetch = 0;
705
s->ch[i].buf_disable = 0;
706
s->ch[i].src_sync = 0;
707
memset(&s->ch[i].burst, 0, sizeof(s->ch[i].burst));
708
memset(&s->ch[i].port, 0, sizeof(s->ch[i].port));
709
memset(&s->ch[i].mode, 0, sizeof(s->ch[i].mode));
710
memset(&s->ch[i].frame_index, 0, sizeof(s->ch[i].frame_index));
711
memset(&s->ch[i].element_index, 0, sizeof(s->ch[i].element_index));
712
memset(&s->ch[i].endian, 0, sizeof(s->ch[i].endian));
713
memset(&s->ch[i].endian_lock, 0, sizeof(s->ch[i].endian_lock));
714
memset(&s->ch[i].translate, 0, sizeof(s->ch[i].translate));
715
s->ch[i].write_mode = 0;
716
s->ch[i].data_type = 0;
717
s->ch[i].transparent_copy = 0;
718
s->ch[i].constant_fill = 0;
719
s->ch[i].color = 0x00000000;
720
s->ch[i].end_prog = 0;
722
s->ch[i].auto_init = 0;
723
s->ch[i].link_enabled = 0;
724
if (s->model < omap_dma_4)
725
s->ch[i].interrupts = 0x0003;
727
s->ch[i].interrupts = 0x0000;
729
s->ch[i].cstatus = 0;
733
s->ch[i].pending_request = 0;
734
s->ch[i].waiting_end_prog = 0;
735
s->ch[i].cpc = 0x0000;
738
s->ch[i].omap_3_1_compatible_disable = 0;
739
memset(&s->ch[i].active_set, 0, sizeof(s->ch[i].active_set));
740
s->ch[i].priority = 0;
741
s->ch[i].interleave_disabled = 0;
746
static int omap_dma_ch_reg_read(struct omap_dma_s *s,
747
struct omap_dma_channel_s *ch, int reg, uint16_t *value)
751
*value = (ch->burst[1] << 14) |
752
(ch->pack[1] << 13) |
754
(ch->burst[0] << 7) |
757
(ch->data_type >> 1);
761
if (s->model <= omap_dma_3_1)
764
*value = ch->omap_3_1_compatible_disable << 10;
765
*value |= (ch->mode[1] << 14) |
766
(ch->mode[0] << 12) |
767
(ch->end_prog << 11) |
769
(ch->auto_init << 8) |
771
(ch->priority << 6) |
772
(ch->fs << 5) | ch->sync;
776
*value = ch->interrupts;
782
if (!ch->omap_3_1_compatible_disable && ch->sibling) {
783
*value |= (ch->sibling->status & 0x3f) << 6;
784
ch->sibling->status &= SYNC;
786
qemu_irq_lower(ch->irq);
790
*value = ch->addr[0] & 0x0000ffff;
794
*value = ch->addr[0] >> 16;
798
*value = ch->addr[1] & 0x0000ffff;
802
*value = ch->addr[1] >> 16;
806
*value = ch->elements;
814
*value = ch->frame_index[0];
818
*value = ch->element_index[0];
822
if (ch->omap_3_1_compatible_disable)
823
*value = ch->active_set.src & 0xffff;
829
*value = ch->active_set.dest & 0xffff;
833
*value = ch->element_index[1];
837
*value = ch->frame_index[1];
841
*value = ch->color & 0xffff;
845
*value = ch->color >> 16;
849
*value = (ch->bs << 2) |
850
(ch->transparent_copy << 1) |
855
*value = (ch->link_enabled << 15) |
856
(ch->link_next_ch & 0xf);
860
*value = (ch->interleave_disabled << 15) |
870
static int omap_dma_ch_reg_write(struct omap_dma_s *s,
871
struct omap_dma_channel_s *ch, int reg, uint16_t value)
875
ch->burst[1] = (value & 0xc000) >> 14;
876
ch->pack[1] = (value & 0x2000) >> 13;
877
ch->port[1] = (enum omap_dma_port) ((value & 0x1e00) >> 9);
878
ch->burst[0] = (value & 0x0180) >> 7;
879
ch->pack[0] = (value & 0x0040) >> 6;
880
ch->port[0] = (enum omap_dma_port) ((value & 0x003c) >> 2);
881
if (ch->port[0] >= __omap_dma_port_last) {
882
qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid DMA port %i\n",
883
__func__, ch->port[0]);
885
if (ch->port[1] >= __omap_dma_port_last) {
886
qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid DMA port %i\n",
887
__func__, ch->port[1]);
889
ch->data_type = 1 << (value & 3);
890
if ((value & 3) == 3) {
891
qemu_log_mask(LOG_GUEST_ERROR,
892
"%s: bad data_type for DMA channel\n", __func__);
898
ch->mode[1] = (omap_dma_addressing_t) ((value & 0xc000) >> 14);
899
ch->mode[0] = (omap_dma_addressing_t) ((value & 0x3000) >> 12);
900
ch->end_prog = (value & 0x0800) >> 11;
901
if (s->model >= omap_dma_3_2)
902
ch->omap_3_1_compatible_disable = (value >> 10) & 0x1;
903
ch->repeat = (value & 0x0200) >> 9;
904
ch->auto_init = (value & 0x0100) >> 8;
905
ch->priority = (value & 0x0040) >> 6;
906
ch->fs = (value & 0x0020) >> 5;
907
ch->sync = value & 0x001f;
910
omap_dma_enable_channel(s, ch);
912
omap_dma_disable_channel(s, ch);
915
omap_dma_channel_end_prog(s, ch);
920
ch->interrupts = value & 0x3f;
924
OMAP_RO_REG((hwaddr) reg);
928
ch->addr[0] &= 0xffff0000;
929
ch->addr[0] |= value;
933
ch->addr[0] &= 0x0000ffff;
934
ch->addr[0] |= (uint32_t) value << 16;
938
ch->addr[1] &= 0xffff0000;
939
ch->addr[1] |= value;
943
ch->addr[1] &= 0x0000ffff;
944
ch->addr[1] |= (uint32_t) value << 16;
948
ch->elements = value;
956
ch->frame_index[0] = (int16_t) value;
960
ch->element_index[0] = (int16_t) value;
964
OMAP_RO_REG((hwaddr) reg);
968
ch->element_index[1] = (int16_t) value;
972
ch->frame_index[1] = (int16_t) value;
976
ch->color &= 0xffff0000;
982
ch->color |= (uint32_t)value << 16;
986
ch->bs = (value >> 2) & 0x1;
987
ch->transparent_copy = (value >> 1) & 0x1;
988
ch->constant_fill = value & 0x1;
992
ch->link_enabled = (value >> 15) & 0x1;
993
if (value & (1 << 14)) {
994
ch->link_enabled = 0;
995
omap_dma_disable_channel(s, ch);
997
ch->link_next_ch = value & 0x1f;
1001
ch->interleave_disabled = (value >> 15) & 0x1;
1002
ch->type = value & 0xf;
1011
static int omap_dma_3_2_lcd_write(struct omap_dma_lcd_channel_s *s, int offset,
1016
s->brust_f2 = (value >> 14) & 0x3;
1017
s->pack_f2 = (value >> 13) & 0x1;
1018
s->data_type_f2 = (1 << ((value >> 11) & 0x3));
1019
s->brust_f1 = (value >> 7) & 0x3;
1020
s->pack_f1 = (value >> 6) & 0x1;
1021
s->data_type_f1 = (1 << ((value >> 0) & 0x3));
1025
s->mode_f2 = (value >> 14) & 0x3;
1026
s->mode_f1 = (value >> 12) & 0x3;
1027
s->end_prog = (value >> 11) & 0x1;
1028
s->omap_3_1_compatible_disable = (value >> 10) & 0x1;
1029
s->repeat = (value >> 9) & 0x1;
1030
s->auto_init = (value >> 8) & 0x1;
1031
s->running = (value >> 7) & 0x1;
1032
s->priority = (value >> 6) & 0x1;
1033
s->bs = (value >> 4) & 0x1;
1037
s->dst = (value >> 8) & 0x1;
1038
s->src = ((value >> 6) & 0x3) << 1;
1041
s->interrupts = (value >> 1) & 1;
1042
s->dual = value & 1;
1046
s->src_f1_top &= 0xffff0000;
1047
s->src_f1_top |= 0x0000ffff & value;
1051
s->src_f1_top &= 0x0000ffff;
1052
s->src_f1_top |= (uint32_t)value << 16;
1056
s->src_f1_bottom &= 0xffff0000;
1057
s->src_f1_bottom |= 0x0000ffff & value;
1061
s->src_f1_bottom &= 0x0000ffff;
1062
s->src_f1_bottom |= (uint32_t) value << 16;
1066
s->src_f2_top &= 0xffff0000;
1067
s->src_f2_top |= 0x0000ffff & value;
1071
s->src_f2_top &= 0x0000ffff;
1072
s->src_f2_top |= (uint32_t) value << 16;
1076
s->src_f2_bottom &= 0xffff0000;
1077
s->src_f2_bottom |= 0x0000ffff & value;
1081
s->src_f2_bottom &= 0x0000ffff;
1082
s->src_f2_bottom |= (uint32_t) value << 16;
1086
s->element_index_f1 = value;
1090
s->frame_index_f1 &= 0xffff0000;
1091
s->frame_index_f1 |= 0x0000ffff & value;
1095
s->frame_index_f1 &= 0x0000ffff;
1096
s->frame_index_f1 |= (uint32_t) value << 16;
1100
s->element_index_f2 = value;
1104
s->frame_index_f2 &= 0xffff0000;
1105
s->frame_index_f2 |= 0x0000ffff & value;
1109
s->frame_index_f2 &= 0x0000ffff;
1110
s->frame_index_f2 |= (uint32_t) value << 16;
1114
s->elements_f1 = value;
1118
s->frames_f1 = value;
1122
s->elements_f2 = value;
1126
s->frames_f2 = value;
1130
s->lch_type = value & 0xf;
1139
static int omap_dma_3_2_lcd_read(struct omap_dma_lcd_channel_s *s, int offset,
1144
*ret = (s->brust_f2 << 14) |
1145
(s->pack_f2 << 13) |
1146
((s->data_type_f2 >> 1) << 11) |
1147
(s->brust_f1 << 7) |
1149
((s->data_type_f1 >> 1) << 0);
1153
*ret = (s->mode_f2 << 14) |
1154
(s->mode_f1 << 12) |
1155
(s->end_prog << 11) |
1156
(s->omap_3_1_compatible_disable << 10) |
1158
(s->auto_init << 8) |
1160
(s->priority << 6) |
1165
qemu_irq_lower(s->irq);
1166
*ret = (s->dst << 8) |
1167
((s->src & 0x6) << 5) |
1168
(s->condition << 3) |
1169
(s->interrupts << 1) |
1174
*ret = s->src_f1_top & 0xffff;
1178
*ret = s->src_f1_top >> 16;
1182
*ret = s->src_f1_bottom & 0xffff;
1186
*ret = s->src_f1_bottom >> 16;
1190
*ret = s->src_f2_top & 0xffff;
1194
*ret = s->src_f2_top >> 16;
1198
*ret = s->src_f2_bottom & 0xffff;
1202
*ret = s->src_f2_bottom >> 16;
1206
*ret = s->element_index_f1;
1210
*ret = s->frame_index_f1 & 0xffff;
1214
*ret = s->frame_index_f1 >> 16;
1218
*ret = s->element_index_f2;
1222
*ret = s->frame_index_f2 & 0xffff;
1226
*ret = s->frame_index_f2 >> 16;
1230
*ret = s->elements_f1;
1234
*ret = s->frames_f1;
1238
*ret = s->elements_f2;
1242
*ret = s->frames_f2;
1255
static int omap_dma_3_1_lcd_write(struct omap_dma_lcd_channel_s *s, int offset,
1260
s->src = (value & 0x40) ? imif : emiff;
1263
s->interrupts = (value >> 1) & 1;
1264
s->dual = value & 1;
1268
s->src_f1_top &= 0xffff0000;
1269
s->src_f1_top |= 0x0000ffff & value;
1273
s->src_f1_top &= 0x0000ffff;
1274
s->src_f1_top |= (uint32_t)value << 16;
1278
s->src_f1_bottom &= 0xffff0000;
1279
s->src_f1_bottom |= 0x0000ffff & value;
1283
s->src_f1_bottom &= 0x0000ffff;
1284
s->src_f1_bottom |= (uint32_t)value << 16;
1288
s->src_f2_top &= 0xffff0000;
1289
s->src_f2_top |= 0x0000ffff & value;
1293
s->src_f2_top &= 0x0000ffff;
1294
s->src_f2_top |= (uint32_t)value << 16;
1298
s->src_f2_bottom &= 0xffff0000;
1299
s->src_f2_bottom |= 0x0000ffff & value;
1303
s->src_f2_bottom &= 0x0000ffff;
1304
s->src_f2_bottom |= (uint32_t)value << 16;
1313
static int omap_dma_3_1_lcd_read(struct omap_dma_lcd_channel_s *s, int offset,
1322
qemu_irq_lower(s->irq);
1323
*ret = ((s->src == imif) << 6) | (i << 3) |
1324
(s->interrupts << 1) | s->dual;
1328
*ret = s->src_f1_top & 0xffff;
1332
*ret = s->src_f1_top >> 16;
1336
*ret = s->src_f1_bottom & 0xffff;
1340
*ret = s->src_f1_bottom >> 16;
1344
*ret = s->src_f2_top & 0xffff;
1348
*ret = s->src_f2_top >> 16;
1352
*ret = s->src_f2_bottom & 0xffff;
1356
*ret = s->src_f2_bottom >> 16;
1365
static int omap_dma_sys_write(struct omap_dma_s *s, int offset, uint16_t value)
1374
omap_dma_disable_3_1_mapping(s);
1376
omap_dma_enable_3_1_mapping(s);
1381
omap_dma_reset(s->dma);
1390
static int omap_dma_sys_read(struct omap_dma_s *s, int offset,
1399
*ret = s->omap_3_1_mapping_disabled << 3;
1416
*ret = (s->caps[0] >> 16) & 0xffff;
1419
*ret = (s->caps[0] >> 0) & 0xffff;
1423
*ret = (s->caps[1] >> 16) & 0xffff;
1426
*ret = (s->caps[1] >> 0) & 0xffff;
1445
qemu_log_mask(LOG_UNIMP,
1446
"%s: Physical Channel Status Registers not implemented\n",
1457
static uint64_t omap_dma_read(void *opaque, hwaddr addr, unsigned size)
1459
struct omap_dma_s *s = opaque;
1464
return omap_badwidth_read16(opaque, addr);
1468
case 0x300 ... 0x3fe:
1469
if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
1470
if (omap_dma_3_1_lcd_read(&s->lcd_ch, addr, &ret))
1475
case 0x000 ... 0x2fe:
1477
ch = (addr >> 6) & 0x0f;
1478
if (omap_dma_ch_reg_read(s, &s->ch[ch], reg, &ret))
1482
case 0x404 ... 0x4fe:
1483
if (s->model <= omap_dma_3_1)
1487
if (omap_dma_sys_read(s, addr, &ret))
1491
case 0xb00 ... 0xbfe:
1492
if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
1493
if (omap_dma_3_2_lcd_read(&s->lcd_ch, addr, &ret))
1504
static void omap_dma_write(void *opaque, hwaddr addr,
1505
uint64_t value, unsigned size)
1507
struct omap_dma_s *s = opaque;
1511
omap_badwidth_write16(opaque, addr, value);
1516
case 0x300 ... 0x3fe:
1517
if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
1518
if (omap_dma_3_1_lcd_write(&s->lcd_ch, addr, value))
1523
case 0x000 ... 0x2fe:
1525
ch = (addr >> 6) & 0x0f;
1526
if (omap_dma_ch_reg_write(s, &s->ch[ch], reg, value))
1530
case 0x404 ... 0x4fe:
1531
if (s->model <= omap_dma_3_1)
1535
if (omap_dma_sys_write(s, addr, value))
1539
case 0xb00 ... 0xbfe:
1540
if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
1541
if (omap_dma_3_2_lcd_write(&s->lcd_ch, addr, value))
1551
static const MemoryRegionOps omap_dma_ops = {
1552
.read = omap_dma_read,
1553
.write = omap_dma_write,
1554
.endianness = DEVICE_NATIVE_ENDIAN,
1557
static void omap_dma_request(void *opaque, int drq, int req)
1559
struct omap_dma_s *s = opaque;
1562
if (~s->dma->drqbmp & (1ULL << drq)) {
1563
s->dma->drqbmp |= 1ULL << drq;
1564
omap_dma_process_request(s, drq);
1567
s->dma->drqbmp &= ~(1ULL << drq);
1571
static void omap_dma_clk_update(void *opaque, int line, int on)
1573
struct omap_dma_s *s = opaque;
1576
s->dma->freq = omap_clk_getrate(s->clk);
1578
for (i = 0; i < s->chans; i ++)
1579
if (s->ch[i].active)
1580
soc_dma_set_request(s->ch[i].dma, on);
1583
static void omap_dma_setcaps(struct omap_dma_s *s)
1629
struct soc_dma_s *omap_dma_init(hwaddr base, qemu_irq *irqs,
1630
MemoryRegion *sysmem,
1631
qemu_irq lcd_irq, struct omap_mpu_state_s *mpu, omap_clk clk,
1632
enum omap_dma_model model)
1634
int num_irqs, memsize, i;
1635
struct omap_dma_s *s = g_new0(struct omap_dma_s, 1);
1637
if (model <= omap_dma_3_1) {
1647
s->lcd_ch.irq = lcd_irq;
1648
s->lcd_ch.mpu = mpu;
1650
s->dma = soc_dma_init((model <= omap_dma_3_1) ? 9 : 16);
1651
s->dma->freq = omap_clk_getrate(clk);
1652
s->dma->transfer_fn = omap_dma_transfer_generic;
1653
s->dma->setup_fn = omap_dma_transfer_setup;
1654
s->dma->drq = qemu_allocate_irqs(omap_dma_request, s, 32);
1658
s->ch[num_irqs].irq = irqs[num_irqs];
1659
for (i = 0; i < 3; i ++) {
1660
s->ch[i].sibling = &s->ch[i + 6];
1661
s->ch[i + 6].sibling = &s->ch[i];
1663
for (i = (model <= omap_dma_3_1) ? 8 : 15; i >= 0; i --) {
1664
s->ch[i].dma = &s->dma->ch[i];
1665
s->dma->ch[i].opaque = &s->ch[i];
1668
omap_dma_setcaps(s);
1669
omap_clk_adduser(s->clk, qemu_allocate_irq(omap_dma_clk_update, s, 0));
1670
omap_dma_reset(s->dma);
1671
omap_dma_clk_update(s, 0, 1);
1673
memory_region_init_io(&s->iomem, NULL, &omap_dma_ops, s, "omap.dma", memsize);
1674
memory_region_add_subregion(sysmem, base, &s->iomem);
1676
mpu->drq = s->dma->drq;
1681
static void omap_dma_interrupts_4_update(struct omap_dma_s *s)
1683
struct omap_dma_channel_s *ch = s->ch;
1686
for (bmp = 0, bit = 1; bit; ch ++, bit <<= 1)
1689
ch->cstatus |= ch->status;
1692
if ((s->irqstat[0] |= s->irqen[0] & bmp))
1693
qemu_irq_raise(s->irq[0]);
1694
if ((s->irqstat[1] |= s->irqen[1] & bmp))
1695
qemu_irq_raise(s->irq[1]);
1696
if ((s->irqstat[2] |= s->irqen[2] & bmp))
1697
qemu_irq_raise(s->irq[2]);
1698
if ((s->irqstat[3] |= s->irqen[3] & bmp))
1699
qemu_irq_raise(s->irq[3]);
1702
static uint64_t omap_dma4_read(void *opaque, hwaddr addr,
1705
struct omap_dma_s *s = opaque;
1706
int irqn = 0, chnum;
1707
struct omap_dma_channel_s *ch;
1710
return omap_badwidth_read16(opaque, addr);
1727
return s->irqstat[irqn];
1739
return s->irqen[irqn];
1759
case 0x80 ... 0xfff:
1761
chnum = addr / 0x60;
1763
addr -= chnum * 0x60;
1774
return (ch->buf_disable << 25) |
1775
(ch->src_sync << 24) |
1776
(ch->prefetch << 23) |
1777
((ch->sync & 0x60) << 14) |
1779
(ch->transparent_copy << 17) |
1780
(ch->constant_fill << 16) |
1781
(ch->mode[1] << 14) |
1782
(ch->mode[0] << 12) |
1783
(0 << 10) | (0 << 9) |
1784
(ch->suspend << 8) |
1786
(ch->priority << 6) |
1787
(ch->fs << 5) | (ch->sync & 0x1f);
1790
return (ch->link_enabled << 15) | ch->link_next_ch;
1793
return ch->interrupts;
1799
return (ch->endian[0] << 21) |
1800
(ch->endian_lock[0] << 20) |
1801
(ch->endian[1] << 19) |
1802
(ch->endian_lock[1] << 18) |
1803
(ch->write_mode << 16) |
1804
(ch->burst[1] << 14) |
1805
(ch->pack[1] << 13) |
1806
(ch->translate[1] << 9) |
1807
(ch->burst[0] << 7) |
1808
(ch->pack[0] << 6) |
1809
(ch->translate[0] << 2) |
1810
(ch->data_type >> 1);
1813
return ch->elements;
1825
return ch->element_index[0];
1828
return ch->frame_index[0];
1831
return ch->element_index[1];
1834
return ch->frame_index[1];
1837
return ch->active_set.src & 0xffff;
1840
return ch->active_set.dest & 0xffff;
1843
return ch->active_set.element;
1846
return ch->active_set.frame;
1858
static void omap_dma4_write(void *opaque, hwaddr addr,
1859
uint64_t value, unsigned size)
1861
struct omap_dma_s *s = opaque;
1862
int chnum, irqn = 0;
1863
struct omap_dma_channel_s *ch;
1866
omap_badwidth_write16(opaque, addr, value);
1881
s->irqstat[irqn] &= ~value;
1882
if (!s->irqstat[irqn])
1883
qemu_irq_lower(s->irq[irqn]);
1896
s->irqen[irqn] = value;
1901
omap_dma_reset(s->dma);
1902
s->ocp = value & 0x3321;
1903
if (((s->ocp >> 12) & 3) == 3) {
1904
qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid DMA power mode\n",
1910
s->gcr = value & 0x00ff00ff;
1911
if ((value & 0xff) == 0x00) {
1912
qemu_log_mask(LOG_GUEST_ERROR, "%s: wrong FIFO depth in GCR\n",
1917
case 0x80 ... 0xfff:
1919
chnum = addr / 0x60;
1921
addr -= chnum * 0x60;
1941
ch->buf_disable = (value >> 25) & 1;
1942
ch->src_sync = (value >> 24) & 1;
1943
if (ch->buf_disable && !ch->src_sync) {
1944
qemu_log_mask(LOG_GUEST_ERROR,
1945
"%s: Buffering disable is not allowed in "
1946
"destination synchronised mode\n", __func__);
1948
ch->prefetch = (value >> 23) & 1;
1949
ch->bs = (value >> 18) & 1;
1950
ch->transparent_copy = (value >> 17) & 1;
1951
ch->constant_fill = (value >> 16) & 1;
1952
ch->mode[1] = (omap_dma_addressing_t) ((value & 0xc000) >> 14);
1953
ch->mode[0] = (omap_dma_addressing_t) ((value & 0x3000) >> 12);
1954
ch->suspend = (value & 0x0100) >> 8;
1955
ch->priority = (value & 0x0040) >> 6;
1956
ch->fs = (value & 0x0020) >> 5;
1957
if (ch->fs && ch->bs && ch->mode[0] && ch->mode[1]) {
1958
qemu_log_mask(LOG_GUEST_ERROR,
1959
"%s: For a packet transfer at least one port "
1960
"must be constant-addressed\n", __func__);
1962
ch->sync = (value & 0x001f) | ((value >> 14) & 0x0060);
1966
omap_dma_enable_channel(s, ch);
1968
omap_dma_disable_channel(s, ch);
1973
ch->link_enabled = (value >> 15) & 0x1;
1974
ch->link_next_ch = value & 0x1f;
1978
ch->interrupts = value & 0x09be;
1982
ch->cstatus &= ~value;
1986
ch->endian[0] =(value >> 21) & 1;
1987
ch->endian_lock[0] =(value >> 20) & 1;
1988
ch->endian[1] =(value >> 19) & 1;
1989
ch->endian_lock[1] =(value >> 18) & 1;
1990
if (ch->endian[0] != ch->endian[1]) {
1991
qemu_log_mask(LOG_GUEST_ERROR,
1992
"%s: DMA endianness conversion enable attempt\n",
1995
ch->write_mode = (value >> 16) & 3;
1996
ch->burst[1] = (value & 0xc000) >> 14;
1997
ch->pack[1] = (value & 0x2000) >> 13;
1998
ch->translate[1] = (value & 0x1e00) >> 9;
1999
ch->burst[0] = (value & 0x0180) >> 7;
2000
ch->pack[0] = (value & 0x0040) >> 6;
2001
ch->translate[0] = (value & 0x003c) >> 2;
2002
if (ch->translate[0] | ch->translate[1]) {
2003
qemu_log_mask(LOG_GUEST_ERROR,
2004
"%s: bad MReqAddressTranslate sideband signal\n",
2007
ch->data_type = 1 << (value & 3);
2008
if ((value & 3) == 3) {
2009
qemu_log_mask(LOG_GUEST_ERROR,
2010
"%s: bad data_type for DMA channel\n", __func__);
2011
ch->data_type >>= 1;
2017
ch->elements = value & 0xffffff;
2021
ch->frames = value & 0xffff;
2026
ch->addr[0] = (hwaddr) (uint32_t) value;
2031
ch->addr[1] = (hwaddr) (uint32_t) value;
2036
ch->element_index[0] = (int16_t) value;
2041
ch->frame_index[0] = (int32_t) value;
2046
ch->element_index[1] = (int16_t) value;
2051
ch->frame_index[1] = (int32_t) value;
2072
static const MemoryRegionOps omap_dma4_ops = {
2073
.read = omap_dma4_read,
2074
.write = omap_dma4_write,
2075
.endianness = DEVICE_NATIVE_ENDIAN,
2078
struct soc_dma_s *omap_dma4_init(hwaddr base, qemu_irq *irqs,
2079
MemoryRegion *sysmem,
2080
struct omap_mpu_state_s *mpu, int fifo,
2081
int chans, omap_clk iclk, omap_clk fclk)
2084
struct omap_dma_s *s = g_new0(struct omap_dma_s, 1);
2086
s->model = omap_dma_4;
2091
s->dma = soc_dma_init(s->chans);
2092
s->dma->freq = omap_clk_getrate(fclk);
2093
s->dma->transfer_fn = omap_dma_transfer_generic;
2094
s->dma->setup_fn = omap_dma_transfer_setup;
2095
s->dma->drq = qemu_allocate_irqs(omap_dma_request, s, 64);
2097
for (i = 0; i < s->chans; i ++) {
2098
s->ch[i].dma = &s->dma->ch[i];
2099
s->dma->ch[i].opaque = &s->ch[i];
2102
memcpy(&s->irq, irqs, sizeof(s->irq));
2103
s->intr_update = omap_dma_interrupts_4_update;
2105
omap_dma_setcaps(s);
2106
omap_clk_adduser(s->clk, qemu_allocate_irq(omap_dma_clk_update, s, 0));
2107
omap_dma_reset(s->dma);
2108
omap_dma_clk_update(s, 0, !!s->dma->freq);
2110
memory_region_init_io(&s->iomem, NULL, &omap_dma4_ops, s, "omap.dma4", 0x1000);
2111
memory_region_add_subregion(sysmem, base, &s->iomem);
2113
mpu->drq = s->dma->drq;
2118
struct omap_dma_lcd_channel_s *omap_dma_get_lcdch(struct soc_dma_s *dma)
2120
struct omap_dma_s *s = dma->opaque;