1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "qemu/osdep.h"
21#include "qemu-common.h"
22#include "qemu/timer.h"
23#include "hw/arm/omap.h"
24#include "hw/irq.h"
25#include "hw/arm/soc_dma.h"
26
27struct omap_dma_channel_s {
28
29 int burst[2];
30 int pack[2];
31 int endian[2];
32 int endian_lock[2];
33 int translate[2];
34 enum omap_dma_port port[2];
35 hwaddr addr[2];
36 omap_dma_addressing_t mode[2];
37 uint32_t elements;
38 uint16_t frames;
39 int32_t frame_index[2];
40 int16_t element_index[2];
41 int data_type;
42
43
44 int transparent_copy;
45 int constant_fill;
46 uint32_t color;
47 int prefetch;
48
49
50 int end_prog;
51 int repeat;
52 int auto_init;
53 int link_enabled;
54 int link_next_ch;
55
56
57 int interrupts;
58 int status;
59 int cstatus;
60
61
62 int active;
63 int enable;
64 int sync;
65 int src_sync;
66 int pending_request;
67 int waiting_end_prog;
68 uint16_t cpc;
69 int set_update;
70
71
72 int fs;
73 int bs;
74
75
76 int omap_3_1_compatible_disable;
77
78 qemu_irq irq;
79 struct omap_dma_channel_s *sibling;
80
81 struct omap_dma_reg_set_s {
82 hwaddr src, dest;
83 int frame;
84 int element;
85 int pck_element;
86 int frame_delta[2];
87 int elem_delta[2];
88 int frames;
89 int elements;
90 int pck_elements;
91 } active_set;
92
93 struct soc_dma_ch_s *dma;
94
95
96 int write_mode;
97 int priority;
98 int interleave_disabled;
99 int type;
100 int suspend;
101 int buf_disable;
102};
103
104struct omap_dma_s {
105 struct soc_dma_s *dma;
106 MemoryRegion iomem;
107
108 struct omap_mpu_state_s *mpu;
109 omap_clk clk;
110 qemu_irq irq[4];
111 void (*intr_update)(struct omap_dma_s *s);
112 enum omap_dma_model model;
113 int omap_3_1_mapping_disabled;
114
115 uint32_t gcr;
116 uint32_t ocp;
117 uint32_t caps[5];
118 uint32_t irqen[4];
119 uint32_t irqstat[4];
120
121 int chans;
122 struct omap_dma_channel_s ch[32];
123 struct omap_dma_lcd_channel_s lcd_ch;
124};
125
126
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)
133#define SYNC (1 << 6)
134#define END_PKT_INTR (1 << 7)
135#define TRANS_ERR_INTR (1 << 8)
136#define MISALIGN_INTR (1 << 11)
137
138static inline void omap_dma_interrupts_update(struct omap_dma_s *s)
139{
140 s->intr_update(s);
141}
142
143static void omap_dma_channel_load(struct omap_dma_channel_s *ch)
144{
145 struct omap_dma_reg_set_s *a = &ch->active_set;
146 int i, normal;
147 int omap_3_1 = !ch->omap_3_1_compatible_disable;
148
149
150
151
152
153
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];
159 a->frame = 0;
160 a->element = 0;
161 a->pck_element = 0;
162
163 if (unlikely(!ch->elements || !ch->frames)) {
164 printf("%s: bad DMA request\n", __FUNCTION__);
165 return;
166 }
167
168 for (i = 0; i < 2; i ++)
169 switch (ch->mode[i]) {
170 case constant:
171 a->elem_delta[i] = 0;
172 a->frame_delta[i] = 0;
173 break;
174 case post_incremented:
175 a->elem_delta[i] = ch->data_type;
176 a->frame_delta[i] = 0;
177 break;
178 case single_index:
179 a->elem_delta[i] = ch->data_type +
180 ch->element_index[omap_3_1 ? 0 : i] - 1;
181 a->frame_delta[i] = 0;
182 break;
183 case double_index:
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];
188 break;
189 default:
190 break;
191 }
192
193 normal = !ch->transparent_copy && !ch->constant_fill &&
194
195
196 (ch->endian[0] | ch->endian_lock[0]) ==
197 (ch->endian[1] | ch->endian_lock[1]);
198 for (i = 0; i < 2; i ++) {
199
200
201
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;
208 else
209 ch->dma->type[i] = soc_dma_access_other;
210
211 ch->dma->vaddr[i] = ch->addr[i];
212 }
213 soc_dma_ch_update(ch->dma);
214}
215
216static void omap_dma_activate_channel(struct omap_dma_s *s,
217 struct omap_dma_channel_s *ch)
218{
219 if (!ch->active) {
220 if (ch->set_update) {
221
222
223
224
225
226
227 omap_dma_channel_load(ch);
228 ch->set_update = 0;
229 }
230
231 ch->active = 1;
232 soc_dma_set_request(ch->dma, 1);
233 if (ch->sync)
234 ch->status |= SYNC;
235 }
236}
237
238static void omap_dma_deactivate_channel(struct omap_dma_s *s,
239 struct omap_dma_channel_s *ch)
240{
241
242 ch->cpc = ch->active_set.dest & 0xffff;
243
244 if (ch->pending_request && !ch->waiting_end_prog && ch->enable) {
245
246 ch->pending_request = 0;
247 return;
248 }
249
250
251
252 if (ch->sync && ch->enable && (s->dma->drqbmp & (1ULL << ch->sync)))
253 return;
254
255 if (ch->active) {
256 ch->active = 0;
257 ch->status &= ~SYNC;
258 soc_dma_set_request(ch->dma, 0);
259 }
260}
261
262static void omap_dma_enable_channel(struct omap_dma_s *s,
263 struct omap_dma_channel_s *ch)
264{
265 if (!ch->enable) {
266 ch->enable = 1;
267 ch->waiting_end_prog = 0;
268 omap_dma_channel_load(ch);
269
270
271
272 if ((!ch->sync) || (s->dma->drqbmp & (1ULL << ch->sync))) {
273 omap_dma_activate_channel(s, ch);
274 }
275 }
276}
277
278static void omap_dma_disable_channel(struct omap_dma_s *s,
279 struct omap_dma_channel_s *ch)
280{
281 if (ch->enable) {
282 ch->enable = 0;
283
284 ch->pending_request = 0;
285 omap_dma_deactivate_channel(s, ch);
286 }
287}
288
289static void omap_dma_channel_end_prog(struct omap_dma_s *s,
290 struct omap_dma_channel_s *ch)
291{
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);
297 }
298 }
299}
300
301static void omap_dma_interrupts_3_1_update(struct omap_dma_s *s)
302{
303 struct omap_dma_channel_s *ch = s->ch;
304
305
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);
312 if (ch[3].status)
313 qemu_irq_raise(ch[3].irq);
314 if (ch[4].status)
315 qemu_irq_raise(ch[4].irq);
316 if (ch[5].status)
317 qemu_irq_raise(ch[5].irq);
318}
319
320static void omap_dma_interrupts_3_2_update(struct omap_dma_s *s)
321{
322 struct omap_dma_channel_s *ch = s->ch;
323 int i;
324
325 for (i = s->chans; i; ch ++, i --)
326 if (ch->status)
327 qemu_irq_raise(ch->irq);
328}
329
330static void omap_dma_enable_3_1_mapping(struct omap_dma_s *s)
331{
332 s->omap_3_1_mapping_disabled = 0;
333 s->chans = 9;
334 s->intr_update = omap_dma_interrupts_3_1_update;
335}
336
337static void omap_dma_disable_3_1_mapping(struct omap_dma_s *s)
338{
339 s->omap_3_1_mapping_disabled = 1;
340 s->chans = 16;
341 s->intr_update = omap_dma_interrupts_3_2_update;
342}
343
344static void omap_dma_process_request(struct omap_dma_s *s, int request)
345{
346 int channel;
347 int drop_event = 0;
348 struct omap_dma_channel_s *ch = s->ch;
349
350 for (channel = 0; channel < s->chans; channel ++, ch ++) {
351 if (ch->enable && ch->sync == request) {
352 if (!ch->active)
353 omap_dma_activate_channel(s, ch);
354 else if (!ch->pending_request)
355 ch->pending_request = 1;
356 else {
357
358
359 ch->status |= EVENT_DROP_INTR;
360 drop_event = 1;
361 }
362 }
363 }
364
365 if (drop_event)
366 omap_dma_interrupts_update(s);
367}
368
369static void omap_dma_transfer_generic(struct soc_dma_ch_s *dma)
370{
371 uint8_t value[4];
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;
375#ifdef MULTI_REQ
376 uint16_t status = ch->status;
377#endif
378
379 do {
380
381
382 if (!ch->constant_fill)
383 cpu_physical_memory_read(a->src, value, ch->data_type);
384 else
385 *(uint32_t *) value = ch->color;
386
387 if (!ch->transparent_copy || *(uint32_t *) value != ch->color)
388 cpu_physical_memory_write(a->dest, value, ch->data_type);
389
390 a->src += a->elem_delta[0];
391 a->dest += a->elem_delta[1];
392 a->element ++;
393
394#ifndef MULTI_REQ
395 if (a->element == a->elements) {
396
397 a->element = 0;
398 a->src += a->frame_delta[0];
399 a->dest += a->frame_delta[1];
400 a->frame ++;
401
402
403 if (!ch->sync)
404 ch->cpc = a->dest & 0xffff;
405 }
406 } while ((bytes -= ch->data_type));
407#else
408
409 if (ch->sync && !ch->fs && !ch->bs)
410 omap_dma_deactivate_channel(s, ch);
411
412
413 if (a->element == 1 && a->frame == a->frames - 1)
414 if (ch->interrupts & LAST_FRAME_INTR)
415 ch->status |= LAST_FRAME_INTR;
416
417
418
419 if (a->element == (a->elements >> 1))
420 if (ch->interrupts & HALF_FRAME_INTR)
421 ch->status |= HALF_FRAME_INTR;
422
423 if (ch->fs && ch->bs) {
424 a->pck_element ++;
425
426 if (a->pck_element == a->pck_elements) {
427 a->pck_element = 0;
428
429
430 if ((ch->interrupts & END_PKT_INTR) && !ch->src_sync)
431 ch->status |= END_PKT_INTR;
432
433
434 if (ch->sync)
435 omap_dma_deactivate_channel(s, ch);
436 }
437 }
438
439 if (a->element == a->elements) {
440
441 a->element = 0;
442 a->src += a->frame_delta[0];
443 a->dest += a->frame_delta[1];
444 a->frame ++;
445
446
447 if (ch->sync && ch->fs && !ch->bs)
448 omap_dma_deactivate_channel(s, ch);
449
450
451 if (!ch->sync)
452 ch->cpc = a->dest & 0xffff;
453
454
455 if (ch->interrupts & END_FRAME_INTR)
456 ch->status |= END_FRAME_INTR;
457
458 if (a->frame == a->frames) {
459
460
461
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]);
467 } else {
468 if (!ch->auto_init)
469 omap_dma_disable_channel(s, ch);
470 else if (ch->repeat || ch->end_prog)
471 omap_dma_channel_load(ch);
472 else {
473 ch->waiting_end_prog = 1;
474 omap_dma_deactivate_channel(s, ch);
475 }
476 }
477
478 if (ch->interrupts & END_BLOCK_INTR)
479 ch->status |= END_BLOCK_INTR;
480 }
481 }
482 } while (status == ch->status && ch->active);
483
484 omap_dma_interrupts_update(s);
485#endif
486}
487
488enum {
489 omap_dma_intr_element_sync,
490 omap_dma_intr_last_frame,
491 omap_dma_intr_half_frame,
492 omap_dma_intr_frame,
493 omap_dma_intr_frame_sync,
494 omap_dma_intr_packet,
495 omap_dma_intr_packet_sync,
496 omap_dma_intr_block,
497 __omap_dma_intr_last,
498};
499
500static void omap_dma_transfer_setup(struct soc_dma_ch_s *dma)
501{
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];
507
508 a = &ch->active_set;
509
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))) {
514#if 0
515
516 if (ch->interrupts & TIMEOUT_INTR)
517 ch->status |= TIMEOUT_INTR;
518 omap_dma_deactivate_channel(s, ch);
519 continue;
520#endif
521 printf("%s: Bus time-out in DMA%i operation\n",
522 __FUNCTION__, dma->num);
523 }
524
525 min_elems = INT_MAX;
526
527
528
529#define INTR_CHECK(cond, id, nelements) \
530 if (cond) { \
531 elements[id] = nelements; \
532 if (elements[id] < min_elems) \
533 min_elems = elements[id]; \
534 } else \
535 elements[id] = INT_MAX;
536
537
538 INTR_CHECK(
539 ch->sync && !ch->fs && !ch->bs,
540 omap_dma_intr_element_sync,
541 1)
542
543
544
545
546
547
548 INTR_CHECK(
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))
554 INTR_CHECK(
555 ch->interrupts & HALF_FRAME_INTR,
556 omap_dma_intr_half_frame,
557 (a->elements >> 1) +
558 (a->element >= (a->elements >> 1) ? a->elements : 0) -
559 a->element)
560 INTR_CHECK(
561 ch->sync && ch->fs && (ch->interrupts & END_FRAME_INTR),
562 omap_dma_intr_frame,
563 a->elements - a->element)
564 INTR_CHECK(
565 ch->sync && ch->fs && !ch->bs,
566 omap_dma_intr_frame_sync,
567 a->elements - a->element)
568
569
570 INTR_CHECK(
571 ch->fs && ch->bs &&
572 (ch->interrupts & END_PKT_INTR) && !ch->src_sync,
573 omap_dma_intr_packet,
574 a->pck_elements - a->pck_element)
575 INTR_CHECK(
576 ch->fs && ch->bs && ch->sync,
577 omap_dma_intr_packet_sync,
578 a->pck_elements - a->pck_element)
579
580
581 INTR_CHECK(
582 1,
583 omap_dma_intr_block,
584 (a->frames - a->frame - 1) * a->elements +
585 (a->elements - a->element))
586
587 dma->bytes = min_elems * ch->data_type;
588
589
590
591#ifdef MULTI_REQ
592
593
594 if (dma->update) {
595#endif
596
597
598 if (min_elems == elements[omap_dma_intr_element_sync])
599 omap_dma_deactivate_channel(s, ch);
600
601
602 if (min_elems == elements[omap_dma_intr_last_frame])
603 ch->status |= LAST_FRAME_INTR;
604
605
606
607 if (min_elems == elements[omap_dma_intr_half_frame])
608 ch->status |= HALF_FRAME_INTR;
609
610
611 if (min_elems == elements[omap_dma_intr_packet])
612 ch->status |= END_PKT_INTR;
613
614
615 if (min_elems == elements[omap_dma_intr_packet_sync])
616 omap_dma_deactivate_channel(s, ch);
617
618
619 if (min_elems == elements[omap_dma_intr_frame_sync])
620 omap_dma_deactivate_channel(s, ch);
621
622
623 if (min_elems == elements[omap_dma_intr_frame])
624 ch->status |= END_FRAME_INTR;
625
626 if (min_elems == elements[omap_dma_intr_block]) {
627
628
629
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]);
634 } else {
635 if (!ch->auto_init)
636 omap_dma_disable_channel(s, ch);
637 else if (ch->repeat || ch->end_prog)
638 omap_dma_channel_load(ch);
639 else {
640 ch->waiting_end_prog = 1;
641 omap_dma_deactivate_channel(s, ch);
642 }
643 }
644
645 if (ch->interrupts & END_BLOCK_INTR)
646 ch->status |= END_BLOCK_INTR;
647 }
648
649
650 if (ch->fs && ch->bs) {
651 a->pck_element += min_elems;
652 a->pck_element %= a->pck_elements;
653 }
654
655
656
657#ifndef MULTI_REQ
658 if (dma->update) {
659#endif
660 a->element += min_elems;
661
662 frames = a->element / a->elements;
663 a->element = a->element % a->elements;
664 a->frame += frames;
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];
667
668
669 if (!ch->sync && frames)
670 ch->cpc = a->dest & 0xffff;
671
672
673
674#ifndef MULTI_REQ
675 }
676#else
677 }
678#endif
679
680 omap_dma_interrupts_update(s);
681}
682
683void omap_dma_reset(struct soc_dma_s *dma)
684{
685 int i;
686 struct omap_dma_s *s = dma->opaque;
687
688 soc_dma_reset(s->dma);
689 if (s->model < omap_dma_4)
690 s->gcr = 0x0004;
691 else
692 s->gcr = 0x00010010;
693 s->ocp = 0x00000000;
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;
699 s->lcd_ch.dual = 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;
721 s->ch[i].repeat = 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;
726 else
727 s->ch[i].interrupts = 0x0000;
728 s->ch[i].status = 0;
729 s->ch[i].cstatus = 0;
730 s->ch[i].active = 0;
731 s->ch[i].enable = 0;
732 s->ch[i].sync = 0;
733 s->ch[i].pending_request = 0;
734 s->ch[i].waiting_end_prog = 0;
735 s->ch[i].cpc = 0x0000;
736 s->ch[i].fs = 0;
737 s->ch[i].bs = 0;
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;
742 s->ch[i].type = 0;
743 }
744}
745
746static int omap_dma_ch_reg_read(struct omap_dma_s *s,
747 struct omap_dma_channel_s *ch, int reg, uint16_t *value)
748{
749 switch (reg) {
750 case 0x00:
751 *value = (ch->burst[1] << 14) |
752 (ch->pack[1] << 13) |
753 (ch->port[1] << 9) |
754 (ch->burst[0] << 7) |
755 (ch->pack[0] << 6) |
756 (ch->port[0] << 2) |
757 (ch->data_type >> 1);
758 break;
759
760 case 0x02:
761 if (s->model <= omap_dma_3_1)
762 *value = 0 << 10;
763 else
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) |
768 (ch->repeat << 9) |
769 (ch->auto_init << 8) |
770 (ch->enable << 7) |
771 (ch->priority << 6) |
772 (ch->fs << 5) | ch->sync;
773 break;
774
775 case 0x04:
776 *value = ch->interrupts;
777 break;
778
779 case 0x06:
780 *value = ch->status;
781 ch->status &= SYNC;
782 if (!ch->omap_3_1_compatible_disable && ch->sibling) {
783 *value |= (ch->sibling->status & 0x3f) << 6;
784 ch->sibling->status &= SYNC;
785 }
786 qemu_irq_lower(ch->irq);
787 break;
788
789 case 0x08:
790 *value = ch->addr[0] & 0x0000ffff;
791 break;
792
793 case 0x0a:
794 *value = ch->addr[0] >> 16;
795 break;
796
797 case 0x0c:
798 *value = ch->addr[1] & 0x0000ffff;
799 break;
800
801 case 0x0e:
802 *value = ch->addr[1] >> 16;
803 break;
804
805 case 0x10:
806 *value = ch->elements;
807 break;
808
809 case 0x12:
810 *value = ch->frames;
811 break;
812
813 case 0x14:
814 *value = ch->frame_index[0];
815 break;
816
817 case 0x16:
818 *value = ch->element_index[0];
819 break;
820
821 case 0x18:
822 if (ch->omap_3_1_compatible_disable)
823 *value = ch->active_set.src & 0xffff;
824 else
825 *value = ch->cpc;
826 break;
827
828 case 0x1a:
829 *value = ch->active_set.dest & 0xffff;
830 break;
831
832 case 0x1c:
833 *value = ch->element_index[1];
834 break;
835
836 case 0x1e:
837 *value = ch->frame_index[1];
838 break;
839
840 case 0x20:
841 *value = ch->color & 0xffff;
842 break;
843
844 case 0x22:
845 *value = ch->color >> 16;
846 break;
847
848 case 0x24:
849 *value = (ch->bs << 2) |
850 (ch->transparent_copy << 1) |
851 ch->constant_fill;
852 break;
853
854 case 0x28:
855 *value = (ch->link_enabled << 15) |
856 (ch->link_next_ch & 0xf);
857 break;
858
859 case 0x2a:
860 *value = (ch->interleave_disabled << 15) |
861 ch->type;
862 break;
863
864 default:
865 return 1;
866 }
867 return 0;
868}
869
870static int omap_dma_ch_reg_write(struct omap_dma_s *s,
871 struct omap_dma_channel_s *ch, int reg, uint16_t value)
872{
873 switch (reg) {
874 case 0x00:
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 printf("%s: invalid DMA port %i\n", __FUNCTION__,
883 ch->port[0]);
884 if (ch->port[1] >= __omap_dma_port_last)
885 printf("%s: invalid DMA port %i\n", __FUNCTION__,
886 ch->port[1]);
887 ch->data_type = 1 << (value & 3);
888 if ((value & 3) == 3) {
889 printf("%s: bad data_type for DMA channel\n", __FUNCTION__);
890 ch->data_type >>= 1;
891 }
892 break;
893
894 case 0x02:
895 ch->mode[1] = (omap_dma_addressing_t) ((value & 0xc000) >> 14);
896 ch->mode[0] = (omap_dma_addressing_t) ((value & 0x3000) >> 12);
897 ch->end_prog = (value & 0x0800) >> 11;
898 if (s->model >= omap_dma_3_2)
899 ch->omap_3_1_compatible_disable = (value >> 10) & 0x1;
900 ch->repeat = (value & 0x0200) >> 9;
901 ch->auto_init = (value & 0x0100) >> 8;
902 ch->priority = (value & 0x0040) >> 6;
903 ch->fs = (value & 0x0020) >> 5;
904 ch->sync = value & 0x001f;
905
906 if (value & 0x0080)
907 omap_dma_enable_channel(s, ch);
908 else
909 omap_dma_disable_channel(s, ch);
910
911 if (ch->end_prog)
912 omap_dma_channel_end_prog(s, ch);
913
914 break;
915
916 case 0x04:
917 ch->interrupts = value & 0x3f;
918 break;
919
920 case 0x06:
921 OMAP_RO_REG((hwaddr) reg);
922 break;
923
924 case 0x08:
925 ch->addr[0] &= 0xffff0000;
926 ch->addr[0] |= value;
927 break;
928
929 case 0x0a:
930 ch->addr[0] &= 0x0000ffff;
931 ch->addr[0] |= (uint32_t) value << 16;
932 break;
933
934 case 0x0c:
935 ch->addr[1] &= 0xffff0000;
936 ch->addr[1] |= value;
937 break;
938
939 case 0x0e:
940 ch->addr[1] &= 0x0000ffff;
941 ch->addr[1] |= (uint32_t) value << 16;
942 break;
943
944 case 0x10:
945 ch->elements = value;
946 break;
947
948 case 0x12:
949 ch->frames = value;
950 break;
951
952 case 0x14:
953 ch->frame_index[0] = (int16_t) value;
954 break;
955
956 case 0x16:
957 ch->element_index[0] = (int16_t) value;
958 break;
959
960 case 0x18:
961 OMAP_RO_REG((hwaddr) reg);
962 break;
963
964 case 0x1c:
965 ch->element_index[1] = (int16_t) value;
966 break;
967
968 case 0x1e:
969 ch->frame_index[1] = (int16_t) value;
970 break;
971
972 case 0x20:
973 ch->color &= 0xffff0000;
974 ch->color |= value;
975 break;
976
977 case 0x22:
978 ch->color &= 0xffff;
979 ch->color |= (uint32_t)value << 16;
980 break;
981
982 case 0x24:
983 ch->bs = (value >> 2) & 0x1;
984 ch->transparent_copy = (value >> 1) & 0x1;
985 ch->constant_fill = value & 0x1;
986 break;
987
988 case 0x28:
989 ch->link_enabled = (value >> 15) & 0x1;
990 if (value & (1 << 14)) {
991 ch->link_enabled = 0;
992 omap_dma_disable_channel(s, ch);
993 }
994 ch->link_next_ch = value & 0x1f;
995 break;
996
997 case 0x2a:
998 ch->interleave_disabled = (value >> 15) & 0x1;
999 ch->type = value & 0xf;
1000 break;
1001
1002 default:
1003 return 1;
1004 }
1005 return 0;
1006}
1007
1008static int omap_dma_3_2_lcd_write(struct omap_dma_lcd_channel_s *s, int offset,
1009 uint16_t value)
1010{
1011 switch (offset) {
1012 case 0xbc0:
1013 s->brust_f2 = (value >> 14) & 0x3;
1014 s->pack_f2 = (value >> 13) & 0x1;
1015 s->data_type_f2 = (1 << ((value >> 11) & 0x3));
1016 s->brust_f1 = (value >> 7) & 0x3;
1017 s->pack_f1 = (value >> 6) & 0x1;
1018 s->data_type_f1 = (1 << ((value >> 0) & 0x3));
1019 break;
1020
1021 case 0xbc2:
1022 s->mode_f2 = (value >> 14) & 0x3;
1023 s->mode_f1 = (value >> 12) & 0x3;
1024 s->end_prog = (value >> 11) & 0x1;
1025 s->omap_3_1_compatible_disable = (value >> 10) & 0x1;
1026 s->repeat = (value >> 9) & 0x1;
1027 s->auto_init = (value >> 8) & 0x1;
1028 s->running = (value >> 7) & 0x1;
1029 s->priority = (value >> 6) & 0x1;
1030 s->bs = (value >> 4) & 0x1;
1031 break;
1032
1033 case 0xbc4:
1034 s->dst = (value >> 8) & 0x1;
1035 s->src = ((value >> 6) & 0x3) << 1;
1036 s->condition = 0;
1037
1038 s->interrupts = (value >> 1) & 1;
1039 s->dual = value & 1;
1040 break;
1041
1042 case 0xbc8:
1043 s->src_f1_top &= 0xffff0000;
1044 s->src_f1_top |= 0x0000ffff & value;
1045 break;
1046
1047 case 0xbca:
1048 s->src_f1_top &= 0x0000ffff;
1049 s->src_f1_top |= (uint32_t)value << 16;
1050 break;
1051
1052 case 0xbcc:
1053 s->src_f1_bottom &= 0xffff0000;
1054 s->src_f1_bottom |= 0x0000ffff & value;
1055 break;
1056
1057 case 0xbce:
1058 s->src_f1_bottom &= 0x0000ffff;
1059 s->src_f1_bottom |= (uint32_t) value << 16;
1060 break;
1061
1062 case 0xbd0:
1063 s->src_f2_top &= 0xffff0000;
1064 s->src_f2_top |= 0x0000ffff & value;
1065 break;
1066
1067 case 0xbd2:
1068 s->src_f2_top &= 0x0000ffff;
1069 s->src_f2_top |= (uint32_t) value << 16;
1070 break;
1071
1072 case 0xbd4:
1073 s->src_f2_bottom &= 0xffff0000;
1074 s->src_f2_bottom |= 0x0000ffff & value;
1075 break;
1076
1077 case 0xbd6:
1078 s->src_f2_bottom &= 0x0000ffff;
1079 s->src_f2_bottom |= (uint32_t) value << 16;
1080 break;
1081
1082 case 0xbd8:
1083 s->element_index_f1 = value;
1084 break;
1085
1086 case 0xbda:
1087 s->frame_index_f1 &= 0xffff0000;
1088 s->frame_index_f1 |= 0x0000ffff & value;
1089 break;
1090
1091 case 0xbf4:
1092 s->frame_index_f1 &= 0x0000ffff;
1093 s->frame_index_f1 |= (uint32_t) value << 16;
1094 break;
1095
1096 case 0xbdc:
1097 s->element_index_f2 = value;
1098 break;
1099
1100 case 0xbde:
1101 s->frame_index_f2 &= 0xffff0000;
1102 s->frame_index_f2 |= 0x0000ffff & value;
1103 break;
1104
1105 case 0xbf6:
1106 s->frame_index_f2 &= 0x0000ffff;
1107 s->frame_index_f2 |= (uint32_t) value << 16;
1108 break;
1109
1110 case 0xbe0:
1111 s->elements_f1 = value;
1112 break;
1113
1114 case 0xbe4:
1115 s->frames_f1 = value;
1116 break;
1117
1118 case 0xbe2:
1119 s->elements_f2 = value;
1120 break;
1121
1122 case 0xbe6:
1123 s->frames_f2 = value;
1124 break;
1125
1126 case 0xbea:
1127 s->lch_type = value & 0xf;
1128 break;
1129
1130 default:
1131 return 1;
1132 }
1133 return 0;
1134}
1135
1136static int omap_dma_3_2_lcd_read(struct omap_dma_lcd_channel_s *s, int offset,
1137 uint16_t *ret)
1138{
1139 switch (offset) {
1140 case 0xbc0:
1141 *ret = (s->brust_f2 << 14) |
1142 (s->pack_f2 << 13) |
1143 ((s->data_type_f2 >> 1) << 11) |
1144 (s->brust_f1 << 7) |
1145 (s->pack_f1 << 6) |
1146 ((s->data_type_f1 >> 1) << 0);
1147 break;
1148
1149 case 0xbc2:
1150 *ret = (s->mode_f2 << 14) |
1151 (s->mode_f1 << 12) |
1152 (s->end_prog << 11) |
1153 (s->omap_3_1_compatible_disable << 10) |
1154 (s->repeat << 9) |
1155 (s->auto_init << 8) |
1156 (s->running << 7) |
1157 (s->priority << 6) |
1158 (s->bs << 4);
1159 break;
1160
1161 case 0xbc4:
1162 qemu_irq_lower(s->irq);
1163 *ret = (s->dst << 8) |
1164 ((s->src & 0x6) << 5) |
1165 (s->condition << 3) |
1166 (s->interrupts << 1) |
1167 s->dual;
1168 break;
1169
1170 case 0xbc8:
1171 *ret = s->src_f1_top & 0xffff;
1172 break;
1173
1174 case 0xbca:
1175 *ret = s->src_f1_top >> 16;
1176 break;
1177
1178 case 0xbcc:
1179 *ret = s->src_f1_bottom & 0xffff;
1180 break;
1181
1182 case 0xbce:
1183 *ret = s->src_f1_bottom >> 16;
1184 break;
1185
1186 case 0xbd0:
1187 *ret = s->src_f2_top & 0xffff;
1188 break;
1189
1190 case 0xbd2:
1191 *ret = s->src_f2_top >> 16;
1192 break;
1193
1194 case 0xbd4:
1195 *ret = s->src_f2_bottom & 0xffff;
1196 break;
1197
1198 case 0xbd6:
1199 *ret = s->src_f2_bottom >> 16;
1200 break;
1201
1202 case 0xbd8:
1203 *ret = s->element_index_f1;
1204 break;
1205
1206 case 0xbda:
1207 *ret = s->frame_index_f1 & 0xffff;
1208 break;
1209
1210 case 0xbf4:
1211 *ret = s->frame_index_f1 >> 16;
1212 break;
1213
1214 case 0xbdc:
1215 *ret = s->element_index_f2;
1216 break;
1217
1218 case 0xbde:
1219 *ret = s->frame_index_f2 & 0xffff;
1220 break;
1221
1222 case 0xbf6:
1223 *ret = s->frame_index_f2 >> 16;
1224 break;
1225
1226 case 0xbe0:
1227 *ret = s->elements_f1;
1228 break;
1229
1230 case 0xbe4:
1231 *ret = s->frames_f1;
1232 break;
1233
1234 case 0xbe2:
1235 *ret = s->elements_f2;
1236 break;
1237
1238 case 0xbe6:
1239 *ret = s->frames_f2;
1240 break;
1241
1242 case 0xbea:
1243 *ret = s->lch_type;
1244 break;
1245
1246 default:
1247 return 1;
1248 }
1249 return 0;
1250}
1251
1252static int omap_dma_3_1_lcd_write(struct omap_dma_lcd_channel_s *s, int offset,
1253 uint16_t value)
1254{
1255 switch (offset) {
1256 case 0x300:
1257 s->src = (value & 0x40) ? imif : emiff;
1258 s->condition = 0;
1259
1260 s->interrupts = (value >> 1) & 1;
1261 s->dual = value & 1;
1262 break;
1263
1264 case 0x302:
1265 s->src_f1_top &= 0xffff0000;
1266 s->src_f1_top |= 0x0000ffff & value;
1267 break;
1268
1269 case 0x304:
1270 s->src_f1_top &= 0x0000ffff;
1271 s->src_f1_top |= (uint32_t)value << 16;
1272 break;
1273
1274 case 0x306:
1275 s->src_f1_bottom &= 0xffff0000;
1276 s->src_f1_bottom |= 0x0000ffff & value;
1277 break;
1278
1279 case 0x308:
1280 s->src_f1_bottom &= 0x0000ffff;
1281 s->src_f1_bottom |= (uint32_t)value << 16;
1282 break;
1283
1284 case 0x30a:
1285 s->src_f2_top &= 0xffff0000;
1286 s->src_f2_top |= 0x0000ffff & value;
1287 break;
1288
1289 case 0x30c:
1290 s->src_f2_top &= 0x0000ffff;
1291 s->src_f2_top |= (uint32_t)value << 16;
1292 break;
1293
1294 case 0x30e:
1295 s->src_f2_bottom &= 0xffff0000;
1296 s->src_f2_bottom |= 0x0000ffff & value;
1297 break;
1298
1299 case 0x310:
1300 s->src_f2_bottom &= 0x0000ffff;
1301 s->src_f2_bottom |= (uint32_t)value << 16;
1302 break;
1303
1304 default:
1305 return 1;
1306 }
1307 return 0;
1308}
1309
1310static int omap_dma_3_1_lcd_read(struct omap_dma_lcd_channel_s *s, int offset,
1311 uint16_t *ret)
1312{
1313 int i;
1314
1315 switch (offset) {
1316 case 0x300:
1317 i = s->condition;
1318 s->condition = 0;
1319 qemu_irq_lower(s->irq);
1320 *ret = ((s->src == imif) << 6) | (i << 3) |
1321 (s->interrupts << 1) | s->dual;
1322 break;
1323
1324 case 0x302:
1325 *ret = s->src_f1_top & 0xffff;
1326 break;
1327
1328 case 0x304:
1329 *ret = s->src_f1_top >> 16;
1330 break;
1331
1332 case 0x306:
1333 *ret = s->src_f1_bottom & 0xffff;
1334 break;
1335
1336 case 0x308:
1337 *ret = s->src_f1_bottom >> 16;
1338 break;
1339
1340 case 0x30a:
1341 *ret = s->src_f2_top & 0xffff;
1342 break;
1343
1344 case 0x30c:
1345 *ret = s->src_f2_top >> 16;
1346 break;
1347
1348 case 0x30e:
1349 *ret = s->src_f2_bottom & 0xffff;
1350 break;
1351
1352 case 0x310:
1353 *ret = s->src_f2_bottom >> 16;
1354 break;
1355
1356 default:
1357 return 1;
1358 }
1359 return 0;
1360}
1361
1362static int omap_dma_sys_write(struct omap_dma_s *s, int offset, uint16_t value)
1363{
1364 switch (offset) {
1365 case 0x400:
1366 s->gcr = value;
1367 break;
1368
1369 case 0x404:
1370 if (value & 0x8)
1371 omap_dma_disable_3_1_mapping(s);
1372 else
1373 omap_dma_enable_3_1_mapping(s);
1374 break;
1375
1376 case 0x408:
1377 if (value & 0x1)
1378 omap_dma_reset(s->dma);
1379 break;
1380
1381 default:
1382 return 1;
1383 }
1384 return 0;
1385}
1386
1387static int omap_dma_sys_read(struct omap_dma_s *s, int offset,
1388 uint16_t *ret)
1389{
1390 switch (offset) {
1391 case 0x400:
1392 *ret = s->gcr;
1393 break;
1394
1395 case 0x404:
1396 *ret = s->omap_3_1_mapping_disabled << 3;
1397 break;
1398
1399 case 0x408:
1400 *ret = 0;
1401 break;
1402
1403 case 0x442:
1404 case 0x444:
1405 case 0x446:
1406 case 0x448:
1407 case 0x44a:
1408 case 0x44c:
1409 *ret = 1;
1410 break;
1411
1412 case 0x44e:
1413 *ret = (s->caps[0] >> 16) & 0xffff;
1414 break;
1415 case 0x450:
1416 *ret = (s->caps[0] >> 0) & 0xffff;
1417 break;
1418
1419 case 0x452:
1420 *ret = (s->caps[1] >> 16) & 0xffff;
1421 break;
1422 case 0x454:
1423 *ret = (s->caps[1] >> 0) & 0xffff;
1424 break;
1425
1426 case 0x456:
1427 *ret = s->caps[2];
1428 break;
1429
1430 case 0x458:
1431 *ret = s->caps[3];
1432 break;
1433
1434 case 0x45a:
1435 *ret = s->caps[4];
1436 break;
1437
1438 case 0x460:
1439 case 0x480:
1440 case 0x482:
1441 case 0x4c0:
1442 printf("%s: Physical Channel Status Registers not implemented.\n",
1443 __FUNCTION__);
1444 *ret = 0xff;
1445 break;
1446
1447 default:
1448 return 1;
1449 }
1450 return 0;
1451}
1452
1453static uint64_t omap_dma_read(void *opaque, hwaddr addr,
1454 unsigned size)
1455{
1456 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1457 int reg, ch;
1458 uint16_t ret;
1459
1460 if (size != 2) {
1461 return omap_badwidth_read16(opaque, addr);
1462 }
1463
1464 switch (addr) {
1465 case 0x300 ... 0x3fe:
1466 if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
1467 if (omap_dma_3_1_lcd_read(&s->lcd_ch, addr, &ret))
1468 break;
1469 return ret;
1470 }
1471
1472 case 0x000 ... 0x2fe:
1473 reg = addr & 0x3f;
1474 ch = (addr >> 6) & 0x0f;
1475 if (omap_dma_ch_reg_read(s, &s->ch[ch], reg, &ret))
1476 break;
1477 return ret;
1478
1479 case 0x404 ... 0x4fe:
1480 if (s->model <= omap_dma_3_1)
1481 break;
1482
1483 case 0x400:
1484 if (omap_dma_sys_read(s, addr, &ret))
1485 break;
1486 return ret;
1487
1488 case 0xb00 ... 0xbfe:
1489 if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
1490 if (omap_dma_3_2_lcd_read(&s->lcd_ch, addr, &ret))
1491 break;
1492 return ret;
1493 }
1494 break;
1495 }
1496
1497 OMAP_BAD_REG(addr);
1498 return 0;
1499}
1500
1501static void omap_dma_write(void *opaque, hwaddr addr,
1502 uint64_t value, unsigned size)
1503{
1504 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1505 int reg, ch;
1506
1507 if (size != 2) {
1508 omap_badwidth_write16(opaque, addr, value);
1509 return;
1510 }
1511
1512 switch (addr) {
1513 case 0x300 ... 0x3fe:
1514 if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
1515 if (omap_dma_3_1_lcd_write(&s->lcd_ch, addr, value))
1516 break;
1517 return;
1518 }
1519
1520 case 0x000 ... 0x2fe:
1521 reg = addr & 0x3f;
1522 ch = (addr >> 6) & 0x0f;
1523 if (omap_dma_ch_reg_write(s, &s->ch[ch], reg, value))
1524 break;
1525 return;
1526
1527 case 0x404 ... 0x4fe:
1528 if (s->model <= omap_dma_3_1)
1529 break;
1530 case 0x400:
1531
1532 if (omap_dma_sys_write(s, addr, value))
1533 break;
1534 return;
1535
1536 case 0xb00 ... 0xbfe:
1537 if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
1538 if (omap_dma_3_2_lcd_write(&s->lcd_ch, addr, value))
1539 break;
1540 return;
1541 }
1542 break;
1543 }
1544
1545 OMAP_BAD_REG(addr);
1546}
1547
1548static const MemoryRegionOps omap_dma_ops = {
1549 .read = omap_dma_read,
1550 .write = omap_dma_write,
1551 .endianness = DEVICE_NATIVE_ENDIAN,
1552};
1553
1554static void omap_dma_request(void *opaque, int drq, int req)
1555{
1556 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1557
1558 if (req) {
1559 if (~s->dma->drqbmp & (1ULL << drq)) {
1560 s->dma->drqbmp |= 1ULL << drq;
1561 omap_dma_process_request(s, drq);
1562 }
1563 } else
1564 s->dma->drqbmp &= ~(1ULL << drq);
1565}
1566
1567
1568static void omap_dma_clk_update(void *opaque, int line, int on)
1569{
1570 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1571 int i;
1572
1573 s->dma->freq = omap_clk_getrate(s->clk);
1574
1575 for (i = 0; i < s->chans; i ++)
1576 if (s->ch[i].active)
1577 soc_dma_set_request(s->ch[i].dma, on);
1578}
1579
1580static void omap_dma_setcaps(struct omap_dma_s *s)
1581{
1582 switch (s->model) {
1583 default:
1584 case omap_dma_3_1:
1585 break;
1586 case omap_dma_3_2:
1587 case omap_dma_4:
1588
1589 s->caps[0] =
1590 (1 << 19) |
1591 (1 << 18);
1592 s->caps[1] =
1593 (1 << 1);
1594 s->caps[2] =
1595 (1 << 8) |
1596 (1 << 7) |
1597 (1 << 6) |
1598 (1 << 5) |
1599 (1 << 4) |
1600 (1 << 3) |
1601 (1 << 2) |
1602 (1 << 1) |
1603 (1 << 0);
1604 s->caps[3] =
1605 (1 << 6) |
1606 (1 << 7) |
1607 (1 << 5) |
1608 (1 << 4) |
1609 (1 << 3) |
1610 (1 << 2) |
1611 (1 << 1) |
1612 (1 << 0);
1613 s->caps[4] =
1614 (1 << 7) |
1615 (1 << 6) |
1616 (1 << 5) |
1617 (1 << 4) |
1618 (1 << 3) |
1619 (1 << 2) |
1620 (1 << 1) |
1621 (1 << 0);
1622 break;
1623 }
1624}
1625
1626struct soc_dma_s *omap_dma_init(hwaddr base, qemu_irq *irqs,
1627 MemoryRegion *sysmem,
1628 qemu_irq lcd_irq, struct omap_mpu_state_s *mpu, omap_clk clk,
1629 enum omap_dma_model model)
1630{
1631 int num_irqs, memsize, i;
1632 struct omap_dma_s *s = g_new0(struct omap_dma_s, 1);
1633
1634 if (model <= omap_dma_3_1) {
1635 num_irqs = 6;
1636 memsize = 0x800;
1637 } else {
1638 num_irqs = 16;
1639 memsize = 0xc00;
1640 }
1641 s->model = model;
1642 s->mpu = mpu;
1643 s->clk = clk;
1644 s->lcd_ch.irq = lcd_irq;
1645 s->lcd_ch.mpu = mpu;
1646
1647 s->dma = soc_dma_init((model <= omap_dma_3_1) ? 9 : 16);
1648 s->dma->freq = omap_clk_getrate(clk);
1649 s->dma->transfer_fn = omap_dma_transfer_generic;
1650 s->dma->setup_fn = omap_dma_transfer_setup;
1651 s->dma->drq = qemu_allocate_irqs(omap_dma_request, s, 32);
1652 s->dma->opaque = s;
1653
1654 while (num_irqs --)
1655 s->ch[num_irqs].irq = irqs[num_irqs];
1656 for (i = 0; i < 3; i ++) {
1657 s->ch[i].sibling = &s->ch[i + 6];
1658 s->ch[i + 6].sibling = &s->ch[i];
1659 }
1660 for (i = (model <= omap_dma_3_1) ? 8 : 15; i >= 0; i --) {
1661 s->ch[i].dma = &s->dma->ch[i];
1662 s->dma->ch[i].opaque = &s->ch[i];
1663 }
1664
1665 omap_dma_setcaps(s);
1666 omap_clk_adduser(s->clk, qemu_allocate_irq(omap_dma_clk_update, s, 0));
1667 omap_dma_reset(s->dma);
1668 omap_dma_clk_update(s, 0, 1);
1669
1670 memory_region_init_io(&s->iomem, NULL, &omap_dma_ops, s, "omap.dma", memsize);
1671 memory_region_add_subregion(sysmem, base, &s->iomem);
1672
1673 mpu->drq = s->dma->drq;
1674
1675 return s->dma;
1676}
1677
1678static void omap_dma_interrupts_4_update(struct omap_dma_s *s)
1679{
1680 struct omap_dma_channel_s *ch = s->ch;
1681 uint32_t bmp, bit;
1682
1683 for (bmp = 0, bit = 1; bit; ch ++, bit <<= 1)
1684 if (ch->status) {
1685 bmp |= bit;
1686 ch->cstatus |= ch->status;
1687 ch->status = 0;
1688 }
1689 if ((s->irqstat[0] |= s->irqen[0] & bmp))
1690 qemu_irq_raise(s->irq[0]);
1691 if ((s->irqstat[1] |= s->irqen[1] & bmp))
1692 qemu_irq_raise(s->irq[1]);
1693 if ((s->irqstat[2] |= s->irqen[2] & bmp))
1694 qemu_irq_raise(s->irq[2]);
1695 if ((s->irqstat[3] |= s->irqen[3] & bmp))
1696 qemu_irq_raise(s->irq[3]);
1697}
1698
1699static uint64_t omap_dma4_read(void *opaque, hwaddr addr,
1700 unsigned size)
1701{
1702 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1703 int irqn = 0, chnum;
1704 struct omap_dma_channel_s *ch;
1705
1706 if (size == 1) {
1707 return omap_badwidth_read16(opaque, addr);
1708 }
1709
1710 switch (addr) {
1711 case 0x00:
1712 return 0x40;
1713
1714 case 0x14:
1715 irqn ++;
1716
1717 case 0x10:
1718 irqn ++;
1719
1720 case 0x0c:
1721 irqn ++;
1722
1723 case 0x08:
1724 return s->irqstat[irqn];
1725
1726 case 0x24:
1727 irqn ++;
1728
1729 case 0x20:
1730 irqn ++;
1731
1732 case 0x1c:
1733 irqn ++;
1734
1735 case 0x18:
1736 return s->irqen[irqn];
1737
1738 case 0x28:
1739 return 1;
1740
1741 case 0x2c:
1742 return s->ocp;
1743
1744 case 0x64:
1745 return s->caps[0];
1746 case 0x6c:
1747 return s->caps[2];
1748 case 0x70:
1749 return s->caps[3];
1750 case 0x74:
1751 return s->caps[4];
1752
1753 case 0x78:
1754 return s->gcr;
1755
1756 case 0x80 ... 0xfff:
1757 addr -= 0x80;
1758 chnum = addr / 0x60;
1759 ch = s->ch + chnum;
1760 addr -= chnum * 0x60;
1761 break;
1762
1763 default:
1764 OMAP_BAD_REG(addr);
1765 return 0;
1766 }
1767
1768
1769 switch (addr) {
1770 case 0x00:
1771 return (ch->buf_disable << 25) |
1772 (ch->src_sync << 24) |
1773 (ch->prefetch << 23) |
1774 ((ch->sync & 0x60) << 14) |
1775 (ch->bs << 18) |
1776 (ch->transparent_copy << 17) |
1777 (ch->constant_fill << 16) |
1778 (ch->mode[1] << 14) |
1779 (ch->mode[0] << 12) |
1780 (0 << 10) | (0 << 9) |
1781 (ch->suspend << 8) |
1782 (ch->enable << 7) |
1783 (ch->priority << 6) |
1784 (ch->fs << 5) | (ch->sync & 0x1f);
1785
1786 case 0x04:
1787 return (ch->link_enabled << 15) | ch->link_next_ch;
1788
1789 case 0x08:
1790 return ch->interrupts;
1791
1792 case 0x0c:
1793 return ch->cstatus;
1794
1795 case 0x10:
1796 return (ch->endian[0] << 21) |
1797 (ch->endian_lock[0] << 20) |
1798 (ch->endian[1] << 19) |
1799 (ch->endian_lock[1] << 18) |
1800 (ch->write_mode << 16) |
1801 (ch->burst[1] << 14) |
1802 (ch->pack[1] << 13) |
1803 (ch->translate[1] << 9) |
1804 (ch->burst[0] << 7) |
1805 (ch->pack[0] << 6) |
1806 (ch->translate[0] << 2) |
1807 (ch->data_type >> 1);
1808
1809 case 0x14:
1810 return ch->elements;
1811
1812 case 0x18:
1813 return ch->frames;
1814
1815 case 0x1c:
1816 return ch->addr[0];
1817
1818 case 0x20:
1819 return ch->addr[1];
1820
1821 case 0x24:
1822 return ch->element_index[0];
1823
1824 case 0x28:
1825 return ch->frame_index[0];
1826
1827 case 0x2c:
1828 return ch->element_index[1];
1829
1830 case 0x30:
1831 return ch->frame_index[1];
1832
1833 case 0x34:
1834 return ch->active_set.src & 0xffff;
1835
1836 case 0x38:
1837 return ch->active_set.dest & 0xffff;
1838
1839 case 0x3c:
1840 return ch->active_set.element;
1841
1842 case 0x40:
1843 return ch->active_set.frame;
1844
1845 case 0x44:
1846
1847 return ch->color;
1848
1849 default:
1850 OMAP_BAD_REG(addr);
1851 return 0;
1852 }
1853}
1854
1855static void omap_dma4_write(void *opaque, hwaddr addr,
1856 uint64_t value, unsigned size)
1857{
1858 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1859 int chnum, irqn = 0;
1860 struct omap_dma_channel_s *ch;
1861
1862 if (size == 1) {
1863 omap_badwidth_write16(opaque, addr, value);
1864 return;
1865 }
1866
1867 switch (addr) {
1868 case 0x14:
1869 irqn ++;
1870
1871 case 0x10:
1872 irqn ++;
1873
1874 case 0x0c:
1875 irqn ++;
1876
1877 case 0x08:
1878 s->irqstat[irqn] &= ~value;
1879 if (!s->irqstat[irqn])
1880 qemu_irq_lower(s->irq[irqn]);
1881 return;
1882
1883 case 0x24:
1884 irqn ++;
1885
1886 case 0x20:
1887 irqn ++;
1888
1889 case 0x1c:
1890 irqn ++;
1891
1892 case 0x18:
1893 s->irqen[irqn] = value;
1894 return;
1895
1896 case 0x2c:
1897 if (value & 2)
1898 omap_dma_reset(s->dma);
1899 s->ocp = value & 0x3321;
1900 if (((s->ocp >> 12) & 3) == 3)
1901 fprintf(stderr, "%s: invalid DMA power mode\n", __FUNCTION__);
1902 return;
1903
1904 case 0x78:
1905 s->gcr = value & 0x00ff00ff;
1906 if ((value & 0xff) == 0x00)
1907 fprintf(stderr, "%s: wrong FIFO depth in GCR\n", __FUNCTION__);
1908 return;
1909
1910 case 0x80 ... 0xfff:
1911 addr -= 0x80;
1912 chnum = addr / 0x60;
1913 ch = s->ch + chnum;
1914 addr -= chnum * 0x60;
1915 break;
1916
1917 case 0x00:
1918 case 0x28:
1919 case 0x64:
1920 case 0x6c:
1921 case 0x70:
1922 case 0x74:
1923 OMAP_RO_REG(addr);
1924 return;
1925
1926 default:
1927 OMAP_BAD_REG(addr);
1928 return;
1929 }
1930
1931
1932 switch (addr) {
1933 case 0x00:
1934 ch->buf_disable = (value >> 25) & 1;
1935 ch->src_sync = (value >> 24) & 1;
1936 if (ch->buf_disable && !ch->src_sync)
1937 fprintf(stderr, "%s: Buffering disable is not allowed in "
1938 "destination synchronised mode\n", __FUNCTION__);
1939 ch->prefetch = (value >> 23) & 1;
1940 ch->bs = (value >> 18) & 1;
1941 ch->transparent_copy = (value >> 17) & 1;
1942 ch->constant_fill = (value >> 16) & 1;
1943 ch->mode[1] = (omap_dma_addressing_t) ((value & 0xc000) >> 14);
1944 ch->mode[0] = (omap_dma_addressing_t) ((value & 0x3000) >> 12);
1945 ch->suspend = (value & 0x0100) >> 8;
1946 ch->priority = (value & 0x0040) >> 6;
1947 ch->fs = (value & 0x0020) >> 5;
1948 if (ch->fs && ch->bs && ch->mode[0] && ch->mode[1])
1949 fprintf(stderr, "%s: For a packet transfer at least one port "
1950 "must be constant-addressed\n", __FUNCTION__);
1951 ch->sync = (value & 0x001f) | ((value >> 14) & 0x0060);
1952
1953
1954 if (value & 0x0080)
1955 omap_dma_enable_channel(s, ch);
1956 else
1957 omap_dma_disable_channel(s, ch);
1958
1959 break;
1960
1961 case 0x04:
1962 ch->link_enabled = (value >> 15) & 0x1;
1963 ch->link_next_ch = value & 0x1f;
1964 break;
1965
1966 case 0x08:
1967 ch->interrupts = value & 0x09be;
1968 break;
1969
1970 case 0x0c:
1971 ch->cstatus &= ~value;
1972 break;
1973
1974 case 0x10:
1975 ch->endian[0] =(value >> 21) & 1;
1976 ch->endian_lock[0] =(value >> 20) & 1;
1977 ch->endian[1] =(value >> 19) & 1;
1978 ch->endian_lock[1] =(value >> 18) & 1;
1979 if (ch->endian[0] != ch->endian[1])
1980 fprintf(stderr, "%s: DMA endianness conversion enable attempt\n",
1981 __FUNCTION__);
1982 ch->write_mode = (value >> 16) & 3;
1983 ch->burst[1] = (value & 0xc000) >> 14;
1984 ch->pack[1] = (value & 0x2000) >> 13;
1985 ch->translate[1] = (value & 0x1e00) >> 9;
1986 ch->burst[0] = (value & 0x0180) >> 7;
1987 ch->pack[0] = (value & 0x0040) >> 6;
1988 ch->translate[0] = (value & 0x003c) >> 2;
1989 if (ch->translate[0] | ch->translate[1])
1990 fprintf(stderr, "%s: bad MReqAddressTranslate sideband signal\n",
1991 __FUNCTION__);
1992 ch->data_type = 1 << (value & 3);
1993 if ((value & 3) == 3) {
1994 printf("%s: bad data_type for DMA channel\n", __FUNCTION__);
1995 ch->data_type >>= 1;
1996 }
1997 break;
1998
1999 case 0x14:
2000 ch->set_update = 1;
2001 ch->elements = value & 0xffffff;
2002 break;
2003
2004 case 0x18:
2005 ch->frames = value & 0xffff;
2006 ch->set_update = 1;
2007 break;
2008
2009 case 0x1c:
2010 ch->addr[0] = (hwaddr) (uint32_t) value;
2011 ch->set_update = 1;
2012 break;
2013
2014 case 0x20:
2015 ch->addr[1] = (hwaddr) (uint32_t) value;
2016 ch->set_update = 1;
2017 break;
2018
2019 case 0x24:
2020 ch->element_index[0] = (int16_t) value;
2021 ch->set_update = 1;
2022 break;
2023
2024 case 0x28:
2025 ch->frame_index[0] = (int32_t) value;
2026 ch->set_update = 1;
2027 break;
2028
2029 case 0x2c:
2030 ch->element_index[1] = (int16_t) value;
2031 ch->set_update = 1;
2032 break;
2033
2034 case 0x30:
2035 ch->frame_index[1] = (int32_t) value;
2036 ch->set_update = 1;
2037 break;
2038
2039 case 0x44:
2040
2041 ch->color = value;
2042 break;
2043
2044 case 0x34:
2045 case 0x38:
2046 case 0x3c:
2047 case 0x40:
2048 OMAP_RO_REG(addr);
2049 break;
2050
2051 default:
2052 OMAP_BAD_REG(addr);
2053 }
2054}
2055
2056static const MemoryRegionOps omap_dma4_ops = {
2057 .read = omap_dma4_read,
2058 .write = omap_dma4_write,
2059 .endianness = DEVICE_NATIVE_ENDIAN,
2060};
2061
2062struct soc_dma_s *omap_dma4_init(hwaddr base, qemu_irq *irqs,
2063 MemoryRegion *sysmem,
2064 struct omap_mpu_state_s *mpu, int fifo,
2065 int chans, omap_clk iclk, omap_clk fclk)
2066{
2067 int i;
2068 struct omap_dma_s *s = g_new0(struct omap_dma_s, 1);
2069
2070 s->model = omap_dma_4;
2071 s->chans = chans;
2072 s->mpu = mpu;
2073 s->clk = fclk;
2074
2075 s->dma = soc_dma_init(s->chans);
2076 s->dma->freq = omap_clk_getrate(fclk);
2077 s->dma->transfer_fn = omap_dma_transfer_generic;
2078 s->dma->setup_fn = omap_dma_transfer_setup;
2079 s->dma->drq = qemu_allocate_irqs(omap_dma_request, s, 64);
2080 s->dma->opaque = s;
2081 for (i = 0; i < s->chans; i ++) {
2082 s->ch[i].dma = &s->dma->ch[i];
2083 s->dma->ch[i].opaque = &s->ch[i];
2084 }
2085
2086 memcpy(&s->irq, irqs, sizeof(s->irq));
2087 s->intr_update = omap_dma_interrupts_4_update;
2088
2089 omap_dma_setcaps(s);
2090 omap_clk_adduser(s->clk, qemu_allocate_irq(omap_dma_clk_update, s, 0));
2091 omap_dma_reset(s->dma);
2092 omap_dma_clk_update(s, 0, !!s->dma->freq);
2093
2094 memory_region_init_io(&s->iomem, NULL, &omap_dma4_ops, s, "omap.dma4", 0x1000);
2095 memory_region_add_subregion(sysmem, base, &s->iomem);
2096
2097 mpu->drq = s->dma->drq;
2098
2099 return s->dma;
2100}
2101
2102struct omap_dma_lcd_channel_s *omap_dma_get_lcdch(struct soc_dma_s *dma)
2103{
2104 struct omap_dma_s *s = dma->opaque;
2105
2106 return &s->lcd_ch;
2107}
2108