Update version for v2.8.0 release
[qemu/ar7.git] / hw / dma / omap_dma.c
blobf6f86f96391097a6ee40a731f807b2a6cef626ad
1 /*
2 * TI OMAP DMA gigacell.
4 * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
5 * Copyright (C) 2007-2008 Lauro Ramos Venancio <lauro.venancio@indt.org.br>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
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"
27 struct omap_dma_channel_s {
28 /* transfer data */
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;
43 /* transfer type */
44 int transparent_copy;
45 int constant_fill;
46 uint32_t color;
47 int prefetch;
49 /* auto init and linked channel data */
50 int end_prog;
51 int repeat;
52 int auto_init;
53 int link_enabled;
54 int link_next_ch;
56 /* interruption data */
57 int interrupts;
58 int status;
59 int cstatus;
61 /* state data */
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;
71 /* sync type */
72 int fs;
73 int bs;
75 /* compatibility */
76 int omap_3_1_compatible_disable;
78 qemu_irq irq;
79 struct omap_dma_channel_s *sibling;
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;
93 struct soc_dma_ch_s *dma;
95 /* unused parameters */
96 int write_mode;
97 int priority;
98 int interleave_disabled;
99 int type;
100 int suspend;
101 int buf_disable;
104 struct omap_dma_s {
105 struct soc_dma_s *dma;
106 MemoryRegion iomem;
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;
115 uint32_t gcr;
116 uint32_t ocp;
117 uint32_t caps[5];
118 uint32_t irqen[4];
119 uint32_t irqstat[4];
121 int chans;
122 struct omap_dma_channel_s ch[32];
123 struct omap_dma_lcd_channel_s lcd_ch;
126 /* Interrupts */
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)
138 static inline void omap_dma_interrupts_update(struct omap_dma_s *s)
140 s->intr_update(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;
146 int i, normal;
147 int omap_3_1 = !ch->omap_3_1_compatible_disable;
150 * TODO: verify address ranges and alignment
151 * TODO: port endianness
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;
163 if (unlikely(!ch->elements || !ch->frames)) {
164 printf("%s: bad DMA request\n", __FUNCTION__);
165 return;
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;
193 normal = !ch->transparent_copy && !ch->constant_fill &&
194 /* FIFO is big-endian so either (ch->endian[n] == 1) OR
195 * (ch->endian_lock[n] == 1) mean no endianism conversion. */
196 (ch->endian[0] | ch->endian_lock[0]) ==
197 (ch->endian[1] | ch->endian_lock[1]);
198 for (i = 0; i < 2; i ++) {
199 /* TODO: for a->frame_delta[i] > 0 still use the fast path, just
200 * limit min_elems in omap_dma_transfer_setup to the nearest frame
201 * end. */
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;
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)
219 if (!ch->active) {
220 if (ch->set_update) {
221 /* It's not clear when the active set is supposed to be
222 * loaded from registers. We're already loading it when the
223 * channel is enabled, and for some guests this is not enough
224 * but that may be also because of a race condition (no
225 * delays in qemu) in the guest code, which we're just
226 * working around here. */
227 omap_dma_channel_load(ch);
228 ch->set_update = 0;
231 ch->active = 1;
232 soc_dma_set_request(ch->dma, 1);
233 if (ch->sync)
234 ch->status |= SYNC;
238 static void omap_dma_deactivate_channel(struct omap_dma_s *s,
239 struct omap_dma_channel_s *ch)
241 /* Update cpc */
242 ch->cpc = ch->active_set.dest & 0xffff;
244 if (ch->pending_request && !ch->waiting_end_prog && ch->enable) {
245 /* Don't deactivate the channel */
246 ch->pending_request = 0;
247 return;
250 /* Don't deactive the channel if it is synchronized and the DMA request is
251 active */
252 if (ch->sync && ch->enable && (s->dma->drqbmp & (1ULL << ch->sync)))
253 return;
255 if (ch->active) {
256 ch->active = 0;
257 ch->status &= ~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)
265 if (!ch->enable) {
266 ch->enable = 1;
267 ch->waiting_end_prog = 0;
268 omap_dma_channel_load(ch);
269 /* TODO: theoretically if ch->sync && ch->prefetch &&
270 * !s->dma->drqbmp[ch->sync], we should also activate and fetch
271 * from source and then stall until signalled. */
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)
281 if (ch->enable) {
282 ch->enable = 0;
283 /* Discard any pending request */
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;
305 /* First three interrupts are shared between two channels each. */
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);
320 static void omap_dma_interrupts_3_2_update(struct omap_dma_s *s)
322 struct omap_dma_channel_s *ch = s->ch;
323 int i;
325 for (i = s->chans; i; ch ++, i --)
326 if (ch->status)
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;
333 s->chans = 9;
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;
340 s->chans = 16;
341 s->intr_update = omap_dma_interrupts_3_2_update;
344 static void omap_dma_process_request(struct omap_dma_s *s, int request)
346 int channel;
347 int drop_event = 0;
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) {
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 /* Request collision */
358 /* Second request received while processing other request */
359 ch->status |= EVENT_DROP_INTR;
360 drop_event = 1;
365 if (drop_event)
366 omap_dma_interrupts_update(s);
369 static void omap_dma_transfer_generic(struct soc_dma_ch_s *dma)
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
379 do {
380 /* Transfer a single element */
381 /* FIXME: check the endianness */
382 if (!ch->constant_fill)
383 cpu_physical_memory_read(a->src, value, ch->data_type);
384 else
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];
392 a->element ++;
394 #ifndef MULTI_REQ
395 if (a->element == a->elements) {
396 /* End of Frame */
397 a->element = 0;
398 a->src += a->frame_delta[0];
399 a->dest += a->frame_delta[1];
400 a->frame ++;
402 /* If the channel is async, update cpc */
403 if (!ch->sync)
404 ch->cpc = a->dest & 0xffff;
406 } while ((bytes -= ch->data_type));
407 #else
408 /* If the channel is element synchronized, deactivate it */
409 if (ch->sync && !ch->fs && !ch->bs)
410 omap_dma_deactivate_channel(s, ch);
412 /* If it is the last frame, set the LAST_FRAME interrupt */
413 if (a->element == 1 && a->frame == a->frames - 1)
414 if (ch->interrupts & LAST_FRAME_INTR)
415 ch->status |= LAST_FRAME_INTR;
417 /* If the half of the frame was reached, set the HALF_FRAME
418 interrupt */
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) {
424 a->pck_element ++;
425 /* Check if a full packet has beed transferred. */
426 if (a->pck_element == a->pck_elements) {
427 a->pck_element = 0;
429 /* Set the END_PKT interrupt */
430 if ((ch->interrupts & END_PKT_INTR) && !ch->src_sync)
431 ch->status |= END_PKT_INTR;
433 /* If the channel is packet-synchronized, deactivate it */
434 if (ch->sync)
435 omap_dma_deactivate_channel(s, ch);
439 if (a->element == a->elements) {
440 /* End of Frame */
441 a->element = 0;
442 a->src += a->frame_delta[0];
443 a->dest += a->frame_delta[1];
444 a->frame ++;
446 /* If the channel is frame synchronized, deactivate it */
447 if (ch->sync && ch->fs && !ch->bs)
448 omap_dma_deactivate_channel(s, ch);
450 /* If the channel is async, update cpc */
451 if (!ch->sync)
452 ch->cpc = a->dest & 0xffff;
454 /* Set the END_FRAME interrupt */
455 if (ch->interrupts & END_FRAME_INTR)
456 ch->status |= END_FRAME_INTR;
458 if (a->frame == a->frames) {
459 /* End of Block */
460 /* Disable the channel */
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);
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);
485 #endif
488 enum {
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,
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];
508 a = &ch->active_set;
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 /* Bus time-out */
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);
525 min_elems = INT_MAX;
527 /* Check all the conditions that terminate the transfer starting
528 * with those that can occur the soonest. */
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;
537 /* Elements */
538 INTR_CHECK(
539 ch->sync && !ch->fs && !ch->bs,
540 omap_dma_intr_element_sync,
543 /* Frames */
544 /* TODO: for transfers where entire frames can be read and written
545 * using memcpy() but a->frame_delta is non-zero, try to still do
546 * transfers using soc_dma but limit min_elems to a->elements - ...
547 * See also the TODO in omap_dma_channel_load. */
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)
569 /* Packets */
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)
580 /* Blocks */
581 INTR_CHECK(
583 omap_dma_intr_block,
584 (a->frames - a->frame - 1) * a->elements +
585 (a->elements - a->element))
587 dma->bytes = min_elems * ch->data_type;
589 /* Set appropriate interrupts and/or deactivate channels */
591 #ifdef MULTI_REQ
592 /* TODO: should all of this only be done if dma->update, and otherwise
593 * inside omap_dma_transfer_generic below - check what's faster. */
594 if (dma->update) {
595 #endif
597 /* If the channel is element synchronized, deactivate it */
598 if (min_elems == elements[omap_dma_intr_element_sync])
599 omap_dma_deactivate_channel(s, ch);
601 /* If it is the last frame, set the LAST_FRAME interrupt */
602 if (min_elems == elements[omap_dma_intr_last_frame])
603 ch->status |= LAST_FRAME_INTR;
605 /* If exactly half of the frame was reached, set the HALF_FRAME
606 interrupt */
607 if (min_elems == elements[omap_dma_intr_half_frame])
608 ch->status |= HALF_FRAME_INTR;
610 /* If a full packet has been transferred, set the END_PKT interrupt */
611 if (min_elems == elements[omap_dma_intr_packet])
612 ch->status |= END_PKT_INTR;
614 /* If the channel is packet-synchronized, deactivate it */
615 if (min_elems == elements[omap_dma_intr_packet_sync])
616 omap_dma_deactivate_channel(s, ch);
618 /* If the channel is frame synchronized, deactivate it */
619 if (min_elems == elements[omap_dma_intr_frame_sync])
620 omap_dma_deactivate_channel(s, ch);
622 /* Set the END_FRAME interrupt */
623 if (min_elems == elements[omap_dma_intr_frame])
624 ch->status |= END_FRAME_INTR;
626 if (min_elems == elements[omap_dma_intr_block]) {
627 /* End of Block */
628 /* Disable the channel */
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);
645 if (ch->interrupts & END_BLOCK_INTR)
646 ch->status |= END_BLOCK_INTR;
649 /* Update packet number */
650 if (ch->fs && ch->bs) {
651 a->pck_element += min_elems;
652 a->pck_element %= a->pck_elements;
655 /* TODO: check if we really need to update anything here or perhaps we
656 * can skip part of this. */
657 #ifndef MULTI_REQ
658 if (dma->update) {
659 #endif
660 a->element += min_elems;
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];
668 /* If the channel is async, update cpc */
669 if (!ch->sync && frames)
670 ch->cpc = a->dest & 0xffff;
672 /* TODO: if the destination port is IMIF or EMIFF, set the dirty
673 * bits on it. */
674 #ifndef MULTI_REQ
676 #else
678 #endif
680 omap_dma_interrupts_update(s);
683 void omap_dma_reset(struct soc_dma_s *dma)
685 int i;
686 struct omap_dma_s *s = dma->opaque;
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;
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)
749 switch (reg) {
750 case 0x00: /* SYS_DMA_CSDP_CH0 */
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;
760 case 0x02: /* SYS_DMA_CCR_CH0 */
761 if (s->model <= omap_dma_3_1)
762 *value = 0 << 10; /* FIFO_FLUSH reads as 0 */
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;
775 case 0x04: /* SYS_DMA_CICR_CH0 */
776 *value = ch->interrupts;
777 break;
779 case 0x06: /* SYS_DMA_CSR_CH0 */
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;
786 qemu_irq_lower(ch->irq);
787 break;
789 case 0x08: /* SYS_DMA_CSSA_L_CH0 */
790 *value = ch->addr[0] & 0x0000ffff;
791 break;
793 case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
794 *value = ch->addr[0] >> 16;
795 break;
797 case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
798 *value = ch->addr[1] & 0x0000ffff;
799 break;
801 case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
802 *value = ch->addr[1] >> 16;
803 break;
805 case 0x10: /* SYS_DMA_CEN_CH0 */
806 *value = ch->elements;
807 break;
809 case 0x12: /* SYS_DMA_CFN_CH0 */
810 *value = ch->frames;
811 break;
813 case 0x14: /* SYS_DMA_CFI_CH0 */
814 *value = ch->frame_index[0];
815 break;
817 case 0x16: /* SYS_DMA_CEI_CH0 */
818 *value = ch->element_index[0];
819 break;
821 case 0x18: /* SYS_DMA_CPC_CH0 or DMA_CSAC */
822 if (ch->omap_3_1_compatible_disable)
823 *value = ch->active_set.src & 0xffff; /* CSAC */
824 else
825 *value = ch->cpc;
826 break;
828 case 0x1a: /* DMA_CDAC */
829 *value = ch->active_set.dest & 0xffff; /* CDAC */
830 break;
832 case 0x1c: /* DMA_CDEI */
833 *value = ch->element_index[1];
834 break;
836 case 0x1e: /* DMA_CDFI */
837 *value = ch->frame_index[1];
838 break;
840 case 0x20: /* DMA_COLOR_L */
841 *value = ch->color & 0xffff;
842 break;
844 case 0x22: /* DMA_COLOR_U */
845 *value = ch->color >> 16;
846 break;
848 case 0x24: /* DMA_CCR2 */
849 *value = (ch->bs << 2) |
850 (ch->transparent_copy << 1) |
851 ch->constant_fill;
852 break;
854 case 0x28: /* DMA_CLNK_CTRL */
855 *value = (ch->link_enabled << 15) |
856 (ch->link_next_ch & 0xf);
857 break;
859 case 0x2a: /* DMA_LCH_CTRL */
860 *value = (ch->interleave_disabled << 15) |
861 ch->type;
862 break;
864 default:
865 return 1;
867 return 0;
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)
873 switch (reg) {
874 case 0x00: /* SYS_DMA_CSDP_CH0 */
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 ch->data_type = 1 << (value & 3);
882 if (ch->port[0] >= __omap_dma_port_last)
883 printf("%s: invalid DMA port %i\n", __FUNCTION__,
884 ch->port[0]);
885 if (ch->port[1] >= __omap_dma_port_last)
886 printf("%s: invalid DMA port %i\n", __FUNCTION__,
887 ch->port[1]);
888 if ((value & 3) == 3)
889 printf("%s: bad data_type for DMA channel\n", __FUNCTION__);
890 break;
892 case 0x02: /* SYS_DMA_CCR_CH0 */
893 ch->mode[1] = (omap_dma_addressing_t) ((value & 0xc000) >> 14);
894 ch->mode[0] = (omap_dma_addressing_t) ((value & 0x3000) >> 12);
895 ch->end_prog = (value & 0x0800) >> 11;
896 if (s->model >= omap_dma_3_2)
897 ch->omap_3_1_compatible_disable = (value >> 10) & 0x1;
898 ch->repeat = (value & 0x0200) >> 9;
899 ch->auto_init = (value & 0x0100) >> 8;
900 ch->priority = (value & 0x0040) >> 6;
901 ch->fs = (value & 0x0020) >> 5;
902 ch->sync = value & 0x001f;
904 if (value & 0x0080)
905 omap_dma_enable_channel(s, ch);
906 else
907 omap_dma_disable_channel(s, ch);
909 if (ch->end_prog)
910 omap_dma_channel_end_prog(s, ch);
912 break;
914 case 0x04: /* SYS_DMA_CICR_CH0 */
915 ch->interrupts = value & 0x3f;
916 break;
918 case 0x06: /* SYS_DMA_CSR_CH0 */
919 OMAP_RO_REG((hwaddr) reg);
920 break;
922 case 0x08: /* SYS_DMA_CSSA_L_CH0 */
923 ch->addr[0] &= 0xffff0000;
924 ch->addr[0] |= value;
925 break;
927 case 0x0a: /* SYS_DMA_CSSA_U_CH0 */
928 ch->addr[0] &= 0x0000ffff;
929 ch->addr[0] |= (uint32_t) value << 16;
930 break;
932 case 0x0c: /* SYS_DMA_CDSA_L_CH0 */
933 ch->addr[1] &= 0xffff0000;
934 ch->addr[1] |= value;
935 break;
937 case 0x0e: /* SYS_DMA_CDSA_U_CH0 */
938 ch->addr[1] &= 0x0000ffff;
939 ch->addr[1] |= (uint32_t) value << 16;
940 break;
942 case 0x10: /* SYS_DMA_CEN_CH0 */
943 ch->elements = value;
944 break;
946 case 0x12: /* SYS_DMA_CFN_CH0 */
947 ch->frames = value;
948 break;
950 case 0x14: /* SYS_DMA_CFI_CH0 */
951 ch->frame_index[0] = (int16_t) value;
952 break;
954 case 0x16: /* SYS_DMA_CEI_CH0 */
955 ch->element_index[0] = (int16_t) value;
956 break;
958 case 0x18: /* SYS_DMA_CPC_CH0 or DMA_CSAC */
959 OMAP_RO_REG((hwaddr) reg);
960 break;
962 case 0x1c: /* DMA_CDEI */
963 ch->element_index[1] = (int16_t) value;
964 break;
966 case 0x1e: /* DMA_CDFI */
967 ch->frame_index[1] = (int16_t) value;
968 break;
970 case 0x20: /* DMA_COLOR_L */
971 ch->color &= 0xffff0000;
972 ch->color |= value;
973 break;
975 case 0x22: /* DMA_COLOR_U */
976 ch->color &= 0xffff;
977 ch->color |= (uint32_t)value << 16;
978 break;
980 case 0x24: /* DMA_CCR2 */
981 ch->bs = (value >> 2) & 0x1;
982 ch->transparent_copy = (value >> 1) & 0x1;
983 ch->constant_fill = value & 0x1;
984 break;
986 case 0x28: /* DMA_CLNK_CTRL */
987 ch->link_enabled = (value >> 15) & 0x1;
988 if (value & (1 << 14)) { /* Stop_Lnk */
989 ch->link_enabled = 0;
990 omap_dma_disable_channel(s, ch);
992 ch->link_next_ch = value & 0x1f;
993 break;
995 case 0x2a: /* DMA_LCH_CTRL */
996 ch->interleave_disabled = (value >> 15) & 0x1;
997 ch->type = value & 0xf;
998 break;
1000 default:
1001 return 1;
1003 return 0;
1006 static int omap_dma_3_2_lcd_write(struct omap_dma_lcd_channel_s *s, int offset,
1007 uint16_t value)
1009 switch (offset) {
1010 case 0xbc0: /* DMA_LCD_CSDP */
1011 s->brust_f2 = (value >> 14) & 0x3;
1012 s->pack_f2 = (value >> 13) & 0x1;
1013 s->data_type_f2 = (1 << ((value >> 11) & 0x3));
1014 s->brust_f1 = (value >> 7) & 0x3;
1015 s->pack_f1 = (value >> 6) & 0x1;
1016 s->data_type_f1 = (1 << ((value >> 0) & 0x3));
1017 break;
1019 case 0xbc2: /* DMA_LCD_CCR */
1020 s->mode_f2 = (value >> 14) & 0x3;
1021 s->mode_f1 = (value >> 12) & 0x3;
1022 s->end_prog = (value >> 11) & 0x1;
1023 s->omap_3_1_compatible_disable = (value >> 10) & 0x1;
1024 s->repeat = (value >> 9) & 0x1;
1025 s->auto_init = (value >> 8) & 0x1;
1026 s->running = (value >> 7) & 0x1;
1027 s->priority = (value >> 6) & 0x1;
1028 s->bs = (value >> 4) & 0x1;
1029 break;
1031 case 0xbc4: /* DMA_LCD_CTRL */
1032 s->dst = (value >> 8) & 0x1;
1033 s->src = ((value >> 6) & 0x3) << 1;
1034 s->condition = 0;
1035 /* Assume no bus errors and thus no BUS_ERROR irq bits. */
1036 s->interrupts = (value >> 1) & 1;
1037 s->dual = value & 1;
1038 break;
1040 case 0xbc8: /* TOP_B1_L */
1041 s->src_f1_top &= 0xffff0000;
1042 s->src_f1_top |= 0x0000ffff & value;
1043 break;
1045 case 0xbca: /* TOP_B1_U */
1046 s->src_f1_top &= 0x0000ffff;
1047 s->src_f1_top |= (uint32_t)value << 16;
1048 break;
1050 case 0xbcc: /* BOT_B1_L */
1051 s->src_f1_bottom &= 0xffff0000;
1052 s->src_f1_bottom |= 0x0000ffff & value;
1053 break;
1055 case 0xbce: /* BOT_B1_U */
1056 s->src_f1_bottom &= 0x0000ffff;
1057 s->src_f1_bottom |= (uint32_t) value << 16;
1058 break;
1060 case 0xbd0: /* TOP_B2_L */
1061 s->src_f2_top &= 0xffff0000;
1062 s->src_f2_top |= 0x0000ffff & value;
1063 break;
1065 case 0xbd2: /* TOP_B2_U */
1066 s->src_f2_top &= 0x0000ffff;
1067 s->src_f2_top |= (uint32_t) value << 16;
1068 break;
1070 case 0xbd4: /* BOT_B2_L */
1071 s->src_f2_bottom &= 0xffff0000;
1072 s->src_f2_bottom |= 0x0000ffff & value;
1073 break;
1075 case 0xbd6: /* BOT_B2_U */
1076 s->src_f2_bottom &= 0x0000ffff;
1077 s->src_f2_bottom |= (uint32_t) value << 16;
1078 break;
1080 case 0xbd8: /* DMA_LCD_SRC_EI_B1 */
1081 s->element_index_f1 = value;
1082 break;
1084 case 0xbda: /* DMA_LCD_SRC_FI_B1_L */
1085 s->frame_index_f1 &= 0xffff0000;
1086 s->frame_index_f1 |= 0x0000ffff & value;
1087 break;
1089 case 0xbf4: /* DMA_LCD_SRC_FI_B1_U */
1090 s->frame_index_f1 &= 0x0000ffff;
1091 s->frame_index_f1 |= (uint32_t) value << 16;
1092 break;
1094 case 0xbdc: /* DMA_LCD_SRC_EI_B2 */
1095 s->element_index_f2 = value;
1096 break;
1098 case 0xbde: /* DMA_LCD_SRC_FI_B2_L */
1099 s->frame_index_f2 &= 0xffff0000;
1100 s->frame_index_f2 |= 0x0000ffff & value;
1101 break;
1103 case 0xbf6: /* DMA_LCD_SRC_FI_B2_U */
1104 s->frame_index_f2 &= 0x0000ffff;
1105 s->frame_index_f2 |= (uint32_t) value << 16;
1106 break;
1108 case 0xbe0: /* DMA_LCD_SRC_EN_B1 */
1109 s->elements_f1 = value;
1110 break;
1112 case 0xbe4: /* DMA_LCD_SRC_FN_B1 */
1113 s->frames_f1 = value;
1114 break;
1116 case 0xbe2: /* DMA_LCD_SRC_EN_B2 */
1117 s->elements_f2 = value;
1118 break;
1120 case 0xbe6: /* DMA_LCD_SRC_FN_B2 */
1121 s->frames_f2 = value;
1122 break;
1124 case 0xbea: /* DMA_LCD_LCH_CTRL */
1125 s->lch_type = value & 0xf;
1126 break;
1128 default:
1129 return 1;
1131 return 0;
1134 static int omap_dma_3_2_lcd_read(struct omap_dma_lcd_channel_s *s, int offset,
1135 uint16_t *ret)
1137 switch (offset) {
1138 case 0xbc0: /* DMA_LCD_CSDP */
1139 *ret = (s->brust_f2 << 14) |
1140 (s->pack_f2 << 13) |
1141 ((s->data_type_f2 >> 1) << 11) |
1142 (s->brust_f1 << 7) |
1143 (s->pack_f1 << 6) |
1144 ((s->data_type_f1 >> 1) << 0);
1145 break;
1147 case 0xbc2: /* DMA_LCD_CCR */
1148 *ret = (s->mode_f2 << 14) |
1149 (s->mode_f1 << 12) |
1150 (s->end_prog << 11) |
1151 (s->omap_3_1_compatible_disable << 10) |
1152 (s->repeat << 9) |
1153 (s->auto_init << 8) |
1154 (s->running << 7) |
1155 (s->priority << 6) |
1156 (s->bs << 4);
1157 break;
1159 case 0xbc4: /* DMA_LCD_CTRL */
1160 qemu_irq_lower(s->irq);
1161 *ret = (s->dst << 8) |
1162 ((s->src & 0x6) << 5) |
1163 (s->condition << 3) |
1164 (s->interrupts << 1) |
1165 s->dual;
1166 break;
1168 case 0xbc8: /* TOP_B1_L */
1169 *ret = s->src_f1_top & 0xffff;
1170 break;
1172 case 0xbca: /* TOP_B1_U */
1173 *ret = s->src_f1_top >> 16;
1174 break;
1176 case 0xbcc: /* BOT_B1_L */
1177 *ret = s->src_f1_bottom & 0xffff;
1178 break;
1180 case 0xbce: /* BOT_B1_U */
1181 *ret = s->src_f1_bottom >> 16;
1182 break;
1184 case 0xbd0: /* TOP_B2_L */
1185 *ret = s->src_f2_top & 0xffff;
1186 break;
1188 case 0xbd2: /* TOP_B2_U */
1189 *ret = s->src_f2_top >> 16;
1190 break;
1192 case 0xbd4: /* BOT_B2_L */
1193 *ret = s->src_f2_bottom & 0xffff;
1194 break;
1196 case 0xbd6: /* BOT_B2_U */
1197 *ret = s->src_f2_bottom >> 16;
1198 break;
1200 case 0xbd8: /* DMA_LCD_SRC_EI_B1 */
1201 *ret = s->element_index_f1;
1202 break;
1204 case 0xbda: /* DMA_LCD_SRC_FI_B1_L */
1205 *ret = s->frame_index_f1 & 0xffff;
1206 break;
1208 case 0xbf4: /* DMA_LCD_SRC_FI_B1_U */
1209 *ret = s->frame_index_f1 >> 16;
1210 break;
1212 case 0xbdc: /* DMA_LCD_SRC_EI_B2 */
1213 *ret = s->element_index_f2;
1214 break;
1216 case 0xbde: /* DMA_LCD_SRC_FI_B2_L */
1217 *ret = s->frame_index_f2 & 0xffff;
1218 break;
1220 case 0xbf6: /* DMA_LCD_SRC_FI_B2_U */
1221 *ret = s->frame_index_f2 >> 16;
1222 break;
1224 case 0xbe0: /* DMA_LCD_SRC_EN_B1 */
1225 *ret = s->elements_f1;
1226 break;
1228 case 0xbe4: /* DMA_LCD_SRC_FN_B1 */
1229 *ret = s->frames_f1;
1230 break;
1232 case 0xbe2: /* DMA_LCD_SRC_EN_B2 */
1233 *ret = s->elements_f2;
1234 break;
1236 case 0xbe6: /* DMA_LCD_SRC_FN_B2 */
1237 *ret = s->frames_f2;
1238 break;
1240 case 0xbea: /* DMA_LCD_LCH_CTRL */
1241 *ret = s->lch_type;
1242 break;
1244 default:
1245 return 1;
1247 return 0;
1250 static int omap_dma_3_1_lcd_write(struct omap_dma_lcd_channel_s *s, int offset,
1251 uint16_t value)
1253 switch (offset) {
1254 case 0x300: /* SYS_DMA_LCD_CTRL */
1255 s->src = (value & 0x40) ? imif : emiff;
1256 s->condition = 0;
1257 /* Assume no bus errors and thus no BUS_ERROR irq bits. */
1258 s->interrupts = (value >> 1) & 1;
1259 s->dual = value & 1;
1260 break;
1262 case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
1263 s->src_f1_top &= 0xffff0000;
1264 s->src_f1_top |= 0x0000ffff & value;
1265 break;
1267 case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
1268 s->src_f1_top &= 0x0000ffff;
1269 s->src_f1_top |= (uint32_t)value << 16;
1270 break;
1272 case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
1273 s->src_f1_bottom &= 0xffff0000;
1274 s->src_f1_bottom |= 0x0000ffff & value;
1275 break;
1277 case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
1278 s->src_f1_bottom &= 0x0000ffff;
1279 s->src_f1_bottom |= (uint32_t)value << 16;
1280 break;
1282 case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
1283 s->src_f2_top &= 0xffff0000;
1284 s->src_f2_top |= 0x0000ffff & value;
1285 break;
1287 case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
1288 s->src_f2_top &= 0x0000ffff;
1289 s->src_f2_top |= (uint32_t)value << 16;
1290 break;
1292 case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
1293 s->src_f2_bottom &= 0xffff0000;
1294 s->src_f2_bottom |= 0x0000ffff & value;
1295 break;
1297 case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
1298 s->src_f2_bottom &= 0x0000ffff;
1299 s->src_f2_bottom |= (uint32_t)value << 16;
1300 break;
1302 default:
1303 return 1;
1305 return 0;
1308 static int omap_dma_3_1_lcd_read(struct omap_dma_lcd_channel_s *s, int offset,
1309 uint16_t *ret)
1311 int i;
1313 switch (offset) {
1314 case 0x300: /* SYS_DMA_LCD_CTRL */
1315 i = s->condition;
1316 s->condition = 0;
1317 qemu_irq_lower(s->irq);
1318 *ret = ((s->src == imif) << 6) | (i << 3) |
1319 (s->interrupts << 1) | s->dual;
1320 break;
1322 case 0x302: /* SYS_DMA_LCD_TOP_F1_L */
1323 *ret = s->src_f1_top & 0xffff;
1324 break;
1326 case 0x304: /* SYS_DMA_LCD_TOP_F1_U */
1327 *ret = s->src_f1_top >> 16;
1328 break;
1330 case 0x306: /* SYS_DMA_LCD_BOT_F1_L */
1331 *ret = s->src_f1_bottom & 0xffff;
1332 break;
1334 case 0x308: /* SYS_DMA_LCD_BOT_F1_U */
1335 *ret = s->src_f1_bottom >> 16;
1336 break;
1338 case 0x30a: /* SYS_DMA_LCD_TOP_F2_L */
1339 *ret = s->src_f2_top & 0xffff;
1340 break;
1342 case 0x30c: /* SYS_DMA_LCD_TOP_F2_U */
1343 *ret = s->src_f2_top >> 16;
1344 break;
1346 case 0x30e: /* SYS_DMA_LCD_BOT_F2_L */
1347 *ret = s->src_f2_bottom & 0xffff;
1348 break;
1350 case 0x310: /* SYS_DMA_LCD_BOT_F2_U */
1351 *ret = s->src_f2_bottom >> 16;
1352 break;
1354 default:
1355 return 1;
1357 return 0;
1360 static int omap_dma_sys_write(struct omap_dma_s *s, int offset, uint16_t value)
1362 switch (offset) {
1363 case 0x400: /* SYS_DMA_GCR */
1364 s->gcr = value;
1365 break;
1367 case 0x404: /* DMA_GSCR */
1368 if (value & 0x8)
1369 omap_dma_disable_3_1_mapping(s);
1370 else
1371 omap_dma_enable_3_1_mapping(s);
1372 break;
1374 case 0x408: /* DMA_GRST */
1375 if (value & 0x1)
1376 omap_dma_reset(s->dma);
1377 break;
1379 default:
1380 return 1;
1382 return 0;
1385 static int omap_dma_sys_read(struct omap_dma_s *s, int offset,
1386 uint16_t *ret)
1388 switch (offset) {
1389 case 0x400: /* SYS_DMA_GCR */
1390 *ret = s->gcr;
1391 break;
1393 case 0x404: /* DMA_GSCR */
1394 *ret = s->omap_3_1_mapping_disabled << 3;
1395 break;
1397 case 0x408: /* DMA_GRST */
1398 *ret = 0;
1399 break;
1401 case 0x442: /* DMA_HW_ID */
1402 case 0x444: /* DMA_PCh2_ID */
1403 case 0x446: /* DMA_PCh0_ID */
1404 case 0x448: /* DMA_PCh1_ID */
1405 case 0x44a: /* DMA_PChG_ID */
1406 case 0x44c: /* DMA_PChD_ID */
1407 *ret = 1;
1408 break;
1410 case 0x44e: /* DMA_CAPS_0_U */
1411 *ret = (s->caps[0] >> 16) & 0xffff;
1412 break;
1413 case 0x450: /* DMA_CAPS_0_L */
1414 *ret = (s->caps[0] >> 0) & 0xffff;
1415 break;
1417 case 0x452: /* DMA_CAPS_1_U */
1418 *ret = (s->caps[1] >> 16) & 0xffff;
1419 break;
1420 case 0x454: /* DMA_CAPS_1_L */
1421 *ret = (s->caps[1] >> 0) & 0xffff;
1422 break;
1424 case 0x456: /* DMA_CAPS_2 */
1425 *ret = s->caps[2];
1426 break;
1428 case 0x458: /* DMA_CAPS_3 */
1429 *ret = s->caps[3];
1430 break;
1432 case 0x45a: /* DMA_CAPS_4 */
1433 *ret = s->caps[4];
1434 break;
1436 case 0x460: /* DMA_PCh2_SR */
1437 case 0x480: /* DMA_PCh0_SR */
1438 case 0x482: /* DMA_PCh1_SR */
1439 case 0x4c0: /* DMA_PChD_SR_0 */
1440 printf("%s: Physical Channel Status Registers not implemented.\n",
1441 __FUNCTION__);
1442 *ret = 0xff;
1443 break;
1445 default:
1446 return 1;
1448 return 0;
1451 static uint64_t omap_dma_read(void *opaque, hwaddr addr,
1452 unsigned size)
1454 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1455 int reg, ch;
1456 uint16_t ret;
1458 if (size != 2) {
1459 return omap_badwidth_read16(opaque, addr);
1462 switch (addr) {
1463 case 0x300 ... 0x3fe:
1464 if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
1465 if (omap_dma_3_1_lcd_read(&s->lcd_ch, addr, &ret))
1466 break;
1467 return ret;
1469 /* Fall through. */
1470 case 0x000 ... 0x2fe:
1471 reg = addr & 0x3f;
1472 ch = (addr >> 6) & 0x0f;
1473 if (omap_dma_ch_reg_read(s, &s->ch[ch], reg, &ret))
1474 break;
1475 return ret;
1477 case 0x404 ... 0x4fe:
1478 if (s->model <= omap_dma_3_1)
1479 break;
1480 /* Fall through. */
1481 case 0x400:
1482 if (omap_dma_sys_read(s, addr, &ret))
1483 break;
1484 return ret;
1486 case 0xb00 ... 0xbfe:
1487 if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
1488 if (omap_dma_3_2_lcd_read(&s->lcd_ch, addr, &ret))
1489 break;
1490 return ret;
1492 break;
1495 OMAP_BAD_REG(addr);
1496 return 0;
1499 static void omap_dma_write(void *opaque, hwaddr addr,
1500 uint64_t value, unsigned size)
1502 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1503 int reg, ch;
1505 if (size != 2) {
1506 omap_badwidth_write16(opaque, addr, value);
1507 return;
1510 switch (addr) {
1511 case 0x300 ... 0x3fe:
1512 if (s->model <= omap_dma_3_1 || !s->omap_3_1_mapping_disabled) {
1513 if (omap_dma_3_1_lcd_write(&s->lcd_ch, addr, value))
1514 break;
1515 return;
1517 /* Fall through. */
1518 case 0x000 ... 0x2fe:
1519 reg = addr & 0x3f;
1520 ch = (addr >> 6) & 0x0f;
1521 if (omap_dma_ch_reg_write(s, &s->ch[ch], reg, value))
1522 break;
1523 return;
1525 case 0x404 ... 0x4fe:
1526 if (s->model <= omap_dma_3_1)
1527 break;
1528 case 0x400:
1529 /* Fall through. */
1530 if (omap_dma_sys_write(s, addr, value))
1531 break;
1532 return;
1534 case 0xb00 ... 0xbfe:
1535 if (s->model == omap_dma_3_2 && s->omap_3_1_mapping_disabled) {
1536 if (omap_dma_3_2_lcd_write(&s->lcd_ch, addr, value))
1537 break;
1538 return;
1540 break;
1543 OMAP_BAD_REG(addr);
1546 static const MemoryRegionOps omap_dma_ops = {
1547 .read = omap_dma_read,
1548 .write = omap_dma_write,
1549 .endianness = DEVICE_NATIVE_ENDIAN,
1552 static void omap_dma_request(void *opaque, int drq, int req)
1554 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1555 /* The request pins are level triggered in QEMU. */
1556 if (req) {
1557 if (~s->dma->drqbmp & (1ULL << drq)) {
1558 s->dma->drqbmp |= 1ULL << drq;
1559 omap_dma_process_request(s, drq);
1561 } else
1562 s->dma->drqbmp &= ~(1ULL << drq);
1565 /* XXX: this won't be needed once soc_dma knows about clocks. */
1566 static void omap_dma_clk_update(void *opaque, int line, int on)
1568 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1569 int i;
1571 s->dma->freq = omap_clk_getrate(s->clk);
1573 for (i = 0; i < s->chans; i ++)
1574 if (s->ch[i].active)
1575 soc_dma_set_request(s->ch[i].dma, on);
1578 static void omap_dma_setcaps(struct omap_dma_s *s)
1580 switch (s->model) {
1581 default:
1582 case omap_dma_3_1:
1583 break;
1584 case omap_dma_3_2:
1585 case omap_dma_4:
1586 /* XXX Only available for sDMA */
1587 s->caps[0] =
1588 (1 << 19) | /* Constant Fill Capability */
1589 (1 << 18); /* Transparent BLT Capability */
1590 s->caps[1] =
1591 (1 << 1); /* 1-bit palettized capability (DMA 3.2 only) */
1592 s->caps[2] =
1593 (1 << 8) | /* SEPARATE_SRC_AND_DST_INDEX_CPBLTY */
1594 (1 << 7) | /* DST_DOUBLE_INDEX_ADRS_CPBLTY */
1595 (1 << 6) | /* DST_SINGLE_INDEX_ADRS_CPBLTY */
1596 (1 << 5) | /* DST_POST_INCRMNT_ADRS_CPBLTY */
1597 (1 << 4) | /* DST_CONST_ADRS_CPBLTY */
1598 (1 << 3) | /* SRC_DOUBLE_INDEX_ADRS_CPBLTY */
1599 (1 << 2) | /* SRC_SINGLE_INDEX_ADRS_CPBLTY */
1600 (1 << 1) | /* SRC_POST_INCRMNT_ADRS_CPBLTY */
1601 (1 << 0); /* SRC_CONST_ADRS_CPBLTY */
1602 s->caps[3] =
1603 (1 << 6) | /* BLOCK_SYNCHR_CPBLTY (DMA 4 only) */
1604 (1 << 7) | /* PKT_SYNCHR_CPBLTY (DMA 4 only) */
1605 (1 << 5) | /* CHANNEL_CHAINING_CPBLTY */
1606 (1 << 4) | /* LCh_INTERLEAVE_CPBLTY */
1607 (1 << 3) | /* AUTOINIT_REPEAT_CPBLTY (DMA 3.2 only) */
1608 (1 << 2) | /* AUTOINIT_ENDPROG_CPBLTY (DMA 3.2 only) */
1609 (1 << 1) | /* FRAME_SYNCHR_CPBLTY */
1610 (1 << 0); /* ELMNT_SYNCHR_CPBLTY */
1611 s->caps[4] =
1612 (1 << 7) | /* PKT_INTERRUPT_CPBLTY (DMA 4 only) */
1613 (1 << 6) | /* SYNC_STATUS_CPBLTY */
1614 (1 << 5) | /* BLOCK_INTERRUPT_CPBLTY */
1615 (1 << 4) | /* LAST_FRAME_INTERRUPT_CPBLTY */
1616 (1 << 3) | /* FRAME_INTERRUPT_CPBLTY */
1617 (1 << 2) | /* HALF_FRAME_INTERRUPT_CPBLTY */
1618 (1 << 1) | /* EVENT_DROP_INTERRUPT_CPBLTY */
1619 (1 << 0); /* TIMEOUT_INTERRUPT_CPBLTY (DMA 3.2 only) */
1620 break;
1624 struct soc_dma_s *omap_dma_init(hwaddr base, qemu_irq *irqs,
1625 MemoryRegion *sysmem,
1626 qemu_irq lcd_irq, struct omap_mpu_state_s *mpu, omap_clk clk,
1627 enum omap_dma_model model)
1629 int num_irqs, memsize, i;
1630 struct omap_dma_s *s = g_new0(struct omap_dma_s, 1);
1632 if (model <= omap_dma_3_1) {
1633 num_irqs = 6;
1634 memsize = 0x800;
1635 } else {
1636 num_irqs = 16;
1637 memsize = 0xc00;
1639 s->model = model;
1640 s->mpu = mpu;
1641 s->clk = clk;
1642 s->lcd_ch.irq = lcd_irq;
1643 s->lcd_ch.mpu = mpu;
1645 s->dma = soc_dma_init((model <= omap_dma_3_1) ? 9 : 16);
1646 s->dma->freq = omap_clk_getrate(clk);
1647 s->dma->transfer_fn = omap_dma_transfer_generic;
1648 s->dma->setup_fn = omap_dma_transfer_setup;
1649 s->dma->drq = qemu_allocate_irqs(omap_dma_request, s, 32);
1650 s->dma->opaque = s;
1652 while (num_irqs --)
1653 s->ch[num_irqs].irq = irqs[num_irqs];
1654 for (i = 0; i < 3; i ++) {
1655 s->ch[i].sibling = &s->ch[i + 6];
1656 s->ch[i + 6].sibling = &s->ch[i];
1658 for (i = (model <= omap_dma_3_1) ? 8 : 15; i >= 0; i --) {
1659 s->ch[i].dma = &s->dma->ch[i];
1660 s->dma->ch[i].opaque = &s->ch[i];
1663 omap_dma_setcaps(s);
1664 omap_clk_adduser(s->clk, qemu_allocate_irq(omap_dma_clk_update, s, 0));
1665 omap_dma_reset(s->dma);
1666 omap_dma_clk_update(s, 0, 1);
1668 memory_region_init_io(&s->iomem, NULL, &omap_dma_ops, s, "omap.dma", memsize);
1669 memory_region_add_subregion(sysmem, base, &s->iomem);
1671 mpu->drq = s->dma->drq;
1673 return s->dma;
1676 static void omap_dma_interrupts_4_update(struct omap_dma_s *s)
1678 struct omap_dma_channel_s *ch = s->ch;
1679 uint32_t bmp, bit;
1681 for (bmp = 0, bit = 1; bit; ch ++, bit <<= 1)
1682 if (ch->status) {
1683 bmp |= bit;
1684 ch->cstatus |= ch->status;
1685 ch->status = 0;
1687 if ((s->irqstat[0] |= s->irqen[0] & bmp))
1688 qemu_irq_raise(s->irq[0]);
1689 if ((s->irqstat[1] |= s->irqen[1] & bmp))
1690 qemu_irq_raise(s->irq[1]);
1691 if ((s->irqstat[2] |= s->irqen[2] & bmp))
1692 qemu_irq_raise(s->irq[2]);
1693 if ((s->irqstat[3] |= s->irqen[3] & bmp))
1694 qemu_irq_raise(s->irq[3]);
1697 static uint64_t omap_dma4_read(void *opaque, hwaddr addr,
1698 unsigned size)
1700 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1701 int irqn = 0, chnum;
1702 struct omap_dma_channel_s *ch;
1704 if (size == 1) {
1705 return omap_badwidth_read16(opaque, addr);
1708 switch (addr) {
1709 case 0x00: /* DMA4_REVISION */
1710 return 0x40;
1712 case 0x14: /* DMA4_IRQSTATUS_L3 */
1713 irqn ++;
1714 /* fall through */
1715 case 0x10: /* DMA4_IRQSTATUS_L2 */
1716 irqn ++;
1717 /* fall through */
1718 case 0x0c: /* DMA4_IRQSTATUS_L1 */
1719 irqn ++;
1720 /* fall through */
1721 case 0x08: /* DMA4_IRQSTATUS_L0 */
1722 return s->irqstat[irqn];
1724 case 0x24: /* DMA4_IRQENABLE_L3 */
1725 irqn ++;
1726 /* fall through */
1727 case 0x20: /* DMA4_IRQENABLE_L2 */
1728 irqn ++;
1729 /* fall through */
1730 case 0x1c: /* DMA4_IRQENABLE_L1 */
1731 irqn ++;
1732 /* fall through */
1733 case 0x18: /* DMA4_IRQENABLE_L0 */
1734 return s->irqen[irqn];
1736 case 0x28: /* DMA4_SYSSTATUS */
1737 return 1; /* RESETDONE */
1739 case 0x2c: /* DMA4_OCP_SYSCONFIG */
1740 return s->ocp;
1742 case 0x64: /* DMA4_CAPS_0 */
1743 return s->caps[0];
1744 case 0x6c: /* DMA4_CAPS_2 */
1745 return s->caps[2];
1746 case 0x70: /* DMA4_CAPS_3 */
1747 return s->caps[3];
1748 case 0x74: /* DMA4_CAPS_4 */
1749 return s->caps[4];
1751 case 0x78: /* DMA4_GCR */
1752 return s->gcr;
1754 case 0x80 ... 0xfff:
1755 addr -= 0x80;
1756 chnum = addr / 0x60;
1757 ch = s->ch + chnum;
1758 addr -= chnum * 0x60;
1759 break;
1761 default:
1762 OMAP_BAD_REG(addr);
1763 return 0;
1766 /* Per-channel registers */
1767 switch (addr) {
1768 case 0x00: /* DMA4_CCR */
1769 return (ch->buf_disable << 25) |
1770 (ch->src_sync << 24) |
1771 (ch->prefetch << 23) |
1772 ((ch->sync & 0x60) << 14) |
1773 (ch->bs << 18) |
1774 (ch->transparent_copy << 17) |
1775 (ch->constant_fill << 16) |
1776 (ch->mode[1] << 14) |
1777 (ch->mode[0] << 12) |
1778 (0 << 10) | (0 << 9) |
1779 (ch->suspend << 8) |
1780 (ch->enable << 7) |
1781 (ch->priority << 6) |
1782 (ch->fs << 5) | (ch->sync & 0x1f);
1784 case 0x04: /* DMA4_CLNK_CTRL */
1785 return (ch->link_enabled << 15) | ch->link_next_ch;
1787 case 0x08: /* DMA4_CICR */
1788 return ch->interrupts;
1790 case 0x0c: /* DMA4_CSR */
1791 return ch->cstatus;
1793 case 0x10: /* DMA4_CSDP */
1794 return (ch->endian[0] << 21) |
1795 (ch->endian_lock[0] << 20) |
1796 (ch->endian[1] << 19) |
1797 (ch->endian_lock[1] << 18) |
1798 (ch->write_mode << 16) |
1799 (ch->burst[1] << 14) |
1800 (ch->pack[1] << 13) |
1801 (ch->translate[1] << 9) |
1802 (ch->burst[0] << 7) |
1803 (ch->pack[0] << 6) |
1804 (ch->translate[0] << 2) |
1805 (ch->data_type >> 1);
1807 case 0x14: /* DMA4_CEN */
1808 return ch->elements;
1810 case 0x18: /* DMA4_CFN */
1811 return ch->frames;
1813 case 0x1c: /* DMA4_CSSA */
1814 return ch->addr[0];
1816 case 0x20: /* DMA4_CDSA */
1817 return ch->addr[1];
1819 case 0x24: /* DMA4_CSEI */
1820 return ch->element_index[0];
1822 case 0x28: /* DMA4_CSFI */
1823 return ch->frame_index[0];
1825 case 0x2c: /* DMA4_CDEI */
1826 return ch->element_index[1];
1828 case 0x30: /* DMA4_CDFI */
1829 return ch->frame_index[1];
1831 case 0x34: /* DMA4_CSAC */
1832 return ch->active_set.src & 0xffff;
1834 case 0x38: /* DMA4_CDAC */
1835 return ch->active_set.dest & 0xffff;
1837 case 0x3c: /* DMA4_CCEN */
1838 return ch->active_set.element;
1840 case 0x40: /* DMA4_CCFN */
1841 return ch->active_set.frame;
1843 case 0x44: /* DMA4_COLOR */
1844 /* XXX only in sDMA */
1845 return ch->color;
1847 default:
1848 OMAP_BAD_REG(addr);
1849 return 0;
1853 static void omap_dma4_write(void *opaque, hwaddr addr,
1854 uint64_t value, unsigned size)
1856 struct omap_dma_s *s = (struct omap_dma_s *) opaque;
1857 int chnum, irqn = 0;
1858 struct omap_dma_channel_s *ch;
1860 if (size == 1) {
1861 omap_badwidth_write16(opaque, addr, value);
1862 return;
1865 switch (addr) {
1866 case 0x14: /* DMA4_IRQSTATUS_L3 */
1867 irqn ++;
1868 /* fall through */
1869 case 0x10: /* DMA4_IRQSTATUS_L2 */
1870 irqn ++;
1871 /* fall through */
1872 case 0x0c: /* DMA4_IRQSTATUS_L1 */
1873 irqn ++;
1874 /* fall through */
1875 case 0x08: /* DMA4_IRQSTATUS_L0 */
1876 s->irqstat[irqn] &= ~value;
1877 if (!s->irqstat[irqn])
1878 qemu_irq_lower(s->irq[irqn]);
1879 return;
1881 case 0x24: /* DMA4_IRQENABLE_L3 */
1882 irqn ++;
1883 /* fall through */
1884 case 0x20: /* DMA4_IRQENABLE_L2 */
1885 irqn ++;
1886 /* fall through */
1887 case 0x1c: /* DMA4_IRQENABLE_L1 */
1888 irqn ++;
1889 /* fall through */
1890 case 0x18: /* DMA4_IRQENABLE_L0 */
1891 s->irqen[irqn] = value;
1892 return;
1894 case 0x2c: /* DMA4_OCP_SYSCONFIG */
1895 if (value & 2) /* SOFTRESET */
1896 omap_dma_reset(s->dma);
1897 s->ocp = value & 0x3321;
1898 if (((s->ocp >> 12) & 3) == 3) /* MIDLEMODE */
1899 fprintf(stderr, "%s: invalid DMA power mode\n", __FUNCTION__);
1900 return;
1902 case 0x78: /* DMA4_GCR */
1903 s->gcr = value & 0x00ff00ff;
1904 if ((value & 0xff) == 0x00) /* MAX_CHANNEL_FIFO_DEPTH */
1905 fprintf(stderr, "%s: wrong FIFO depth in GCR\n", __FUNCTION__);
1906 return;
1908 case 0x80 ... 0xfff:
1909 addr -= 0x80;
1910 chnum = addr / 0x60;
1911 ch = s->ch + chnum;
1912 addr -= chnum * 0x60;
1913 break;
1915 case 0x00: /* DMA4_REVISION */
1916 case 0x28: /* DMA4_SYSSTATUS */
1917 case 0x64: /* DMA4_CAPS_0 */
1918 case 0x6c: /* DMA4_CAPS_2 */
1919 case 0x70: /* DMA4_CAPS_3 */
1920 case 0x74: /* DMA4_CAPS_4 */
1921 OMAP_RO_REG(addr);
1922 return;
1924 default:
1925 OMAP_BAD_REG(addr);
1926 return;
1929 /* Per-channel registers */
1930 switch (addr) {
1931 case 0x00: /* DMA4_CCR */
1932 ch->buf_disable = (value >> 25) & 1;
1933 ch->src_sync = (value >> 24) & 1; /* XXX For CamDMA must be 1 */
1934 if (ch->buf_disable && !ch->src_sync)
1935 fprintf(stderr, "%s: Buffering disable is not allowed in "
1936 "destination synchronised mode\n", __FUNCTION__);
1937 ch->prefetch = (value >> 23) & 1;
1938 ch->bs = (value >> 18) & 1;
1939 ch->transparent_copy = (value >> 17) & 1;
1940 ch->constant_fill = (value >> 16) & 1;
1941 ch->mode[1] = (omap_dma_addressing_t) ((value & 0xc000) >> 14);
1942 ch->mode[0] = (omap_dma_addressing_t) ((value & 0x3000) >> 12);
1943 ch->suspend = (value & 0x0100) >> 8;
1944 ch->priority = (value & 0x0040) >> 6;
1945 ch->fs = (value & 0x0020) >> 5;
1946 if (ch->fs && ch->bs && ch->mode[0] && ch->mode[1])
1947 fprintf(stderr, "%s: For a packet transfer at least one port "
1948 "must be constant-addressed\n", __FUNCTION__);
1949 ch->sync = (value & 0x001f) | ((value >> 14) & 0x0060);
1950 /* XXX must be 0x01 for CamDMA */
1952 if (value & 0x0080)
1953 omap_dma_enable_channel(s, ch);
1954 else
1955 omap_dma_disable_channel(s, ch);
1957 break;
1959 case 0x04: /* DMA4_CLNK_CTRL */
1960 ch->link_enabled = (value >> 15) & 0x1;
1961 ch->link_next_ch = value & 0x1f;
1962 break;
1964 case 0x08: /* DMA4_CICR */
1965 ch->interrupts = value & 0x09be;
1966 break;
1968 case 0x0c: /* DMA4_CSR */
1969 ch->cstatus &= ~value;
1970 break;
1972 case 0x10: /* DMA4_CSDP */
1973 ch->endian[0] =(value >> 21) & 1;
1974 ch->endian_lock[0] =(value >> 20) & 1;
1975 ch->endian[1] =(value >> 19) & 1;
1976 ch->endian_lock[1] =(value >> 18) & 1;
1977 if (ch->endian[0] != ch->endian[1])
1978 fprintf(stderr, "%s: DMA endianness conversion enable attempt\n",
1979 __FUNCTION__);
1980 ch->write_mode = (value >> 16) & 3;
1981 ch->burst[1] = (value & 0xc000) >> 14;
1982 ch->pack[1] = (value & 0x2000) >> 13;
1983 ch->translate[1] = (value & 0x1e00) >> 9;
1984 ch->burst[0] = (value & 0x0180) >> 7;
1985 ch->pack[0] = (value & 0x0040) >> 6;
1986 ch->translate[0] = (value & 0x003c) >> 2;
1987 if (ch->translate[0] | ch->translate[1])
1988 fprintf(stderr, "%s: bad MReqAddressTranslate sideband signal\n",
1989 __FUNCTION__);
1990 ch->data_type = 1 << (value & 3);
1991 if ((value & 3) == 3)
1992 printf("%s: bad data_type for DMA channel\n", __FUNCTION__);
1993 break;
1995 case 0x14: /* DMA4_CEN */
1996 ch->set_update = 1;
1997 ch->elements = value & 0xffffff;
1998 break;
2000 case 0x18: /* DMA4_CFN */
2001 ch->frames = value & 0xffff;
2002 ch->set_update = 1;
2003 break;
2005 case 0x1c: /* DMA4_CSSA */
2006 ch->addr[0] = (hwaddr) (uint32_t) value;
2007 ch->set_update = 1;
2008 break;
2010 case 0x20: /* DMA4_CDSA */
2011 ch->addr[1] = (hwaddr) (uint32_t) value;
2012 ch->set_update = 1;
2013 break;
2015 case 0x24: /* DMA4_CSEI */
2016 ch->element_index[0] = (int16_t) value;
2017 ch->set_update = 1;
2018 break;
2020 case 0x28: /* DMA4_CSFI */
2021 ch->frame_index[0] = (int32_t) value;
2022 ch->set_update = 1;
2023 break;
2025 case 0x2c: /* DMA4_CDEI */
2026 ch->element_index[1] = (int16_t) value;
2027 ch->set_update = 1;
2028 break;
2030 case 0x30: /* DMA4_CDFI */
2031 ch->frame_index[1] = (int32_t) value;
2032 ch->set_update = 1;
2033 break;
2035 case 0x44: /* DMA4_COLOR */
2036 /* XXX only in sDMA */
2037 ch->color = value;
2038 break;
2040 case 0x34: /* DMA4_CSAC */
2041 case 0x38: /* DMA4_CDAC */
2042 case 0x3c: /* DMA4_CCEN */
2043 case 0x40: /* DMA4_CCFN */
2044 OMAP_RO_REG(addr);
2045 break;
2047 default:
2048 OMAP_BAD_REG(addr);
2052 static const MemoryRegionOps omap_dma4_ops = {
2053 .read = omap_dma4_read,
2054 .write = omap_dma4_write,
2055 .endianness = DEVICE_NATIVE_ENDIAN,
2058 struct soc_dma_s *omap_dma4_init(hwaddr base, qemu_irq *irqs,
2059 MemoryRegion *sysmem,
2060 struct omap_mpu_state_s *mpu, int fifo,
2061 int chans, omap_clk iclk, omap_clk fclk)
2063 int i;
2064 struct omap_dma_s *s = g_new0(struct omap_dma_s, 1);
2066 s->model = omap_dma_4;
2067 s->chans = chans;
2068 s->mpu = mpu;
2069 s->clk = fclk;
2071 s->dma = soc_dma_init(s->chans);
2072 s->dma->freq = omap_clk_getrate(fclk);
2073 s->dma->transfer_fn = omap_dma_transfer_generic;
2074 s->dma->setup_fn = omap_dma_transfer_setup;
2075 s->dma->drq = qemu_allocate_irqs(omap_dma_request, s, 64);
2076 s->dma->opaque = s;
2077 for (i = 0; i < s->chans; i ++) {
2078 s->ch[i].dma = &s->dma->ch[i];
2079 s->dma->ch[i].opaque = &s->ch[i];
2082 memcpy(&s->irq, irqs, sizeof(s->irq));
2083 s->intr_update = omap_dma_interrupts_4_update;
2085 omap_dma_setcaps(s);
2086 omap_clk_adduser(s->clk, qemu_allocate_irq(omap_dma_clk_update, s, 0));
2087 omap_dma_reset(s->dma);
2088 omap_dma_clk_update(s, 0, !!s->dma->freq);
2090 memory_region_init_io(&s->iomem, NULL, &omap_dma4_ops, s, "omap.dma4", 0x1000);
2091 memory_region_add_subregion(sysmem, base, &s->iomem);
2093 mpu->drq = s->dma->drq;
2095 return s->dma;
2098 struct omap_dma_lcd_channel_s *omap_dma_get_lcdch(struct soc_dma_s *dma)
2100 struct omap_dma_s *s = dma->opaque;
2102 return &s->lcd_ch;