All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/dma/soc_dma: Replace if-else chain with array lookup
@ 2026-06-20 17:13 Evgeny Kolmakov
  2026-06-20 20:23 ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Evgeny Kolmakov @ 2026-06-20 17:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Evgeny Kolmakov

Refactor transfer_fn assignment in soc_dma_ch_update()
via array lookup as suggested by the TODO comment.

Signed-off-by: Evgeny Kolmakov <randomjack94dev@gmail.com>
---
 hw/dma/soc_dma.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/hw/dma/soc_dma.c b/hw/dma/soc_dma.c
index d5c52b804f..a5b1ef9f61 100644
--- a/hw/dma/soc_dma.c
+++ b/hw/dma/soc_dma.c
@@ -163,6 +163,16 @@ static inline enum soc_dma_port_type soc_dma_ch_update_type(
 
 void soc_dma_ch_update(struct soc_dma_ch_s *ch)
 {
+    static const soc_dma_transfer_t transfer_fn[2][2] = {
+        [soc_dma_port_mem] = {
+            [soc_dma_port_mem] = transfer_mem2mem,
+            [soc_dma_port_fifo] = transfer_mem2fifo,
+        },
+        [soc_dma_port_fifo] = {
+            [soc_dma_port_mem] = transfer_fifo2mem,
+            [soc_dma_port_fifo] = transfer_fifo2fifo,
+        },
+    };
     enum soc_dma_port_type src, dst;
 
     src = soc_dma_ch_update_type(ch, 0);
@@ -171,21 +181,16 @@ void soc_dma_ch_update(struct soc_dma_ch_s *ch)
         ch->transfer_fn = ch->dma->transfer_fn;
         return;
     }
-    dst = soc_dma_ch_update_type(ch, 1);
 
-    /* TODO: use src and dst as array indices.  */
-    if (src == soc_dma_port_mem && dst == soc_dma_port_mem)
-        ch->transfer_fn = transfer_mem2mem;
-    else if (src == soc_dma_port_mem && dst == soc_dma_port_fifo)
-        ch->transfer_fn = transfer_mem2fifo;
-    else if (src == soc_dma_port_fifo && dst == soc_dma_port_mem)
-        ch->transfer_fn = transfer_fifo2mem;
-    else if (src == soc_dma_port_fifo && dst == soc_dma_port_fifo)
-        ch->transfer_fn = transfer_fifo2fifo;
-    else
+    dst = soc_dma_ch_update_type(ch, 1);
+    if (dst == soc_dma_port_other) {
+        ch->update = 0;
         ch->transfer_fn = ch->dma->transfer_fn;
+        return;
+    }
 
-    ch->update = (dst != soc_dma_port_other);
+    ch->update = 1;
+    ch->transfer_fn = transfer_fn[src][dst];
 }
 
 static void soc_dma_ch_freq_update(struct dma_s *s)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/dma/soc_dma: Replace if-else chain with array lookup
  2026-06-20 17:13 [PATCH] hw/dma/soc_dma: Replace if-else chain with array lookup Evgeny Kolmakov
@ 2026-06-20 20:23 ` Peter Maydell
  2026-06-20 20:33   ` Evgeny
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2026-06-20 20:23 UTC (permalink / raw)
  To: Evgeny Kolmakov; +Cc: qemu-devel, qemu-trivial

On Sat, 20 Jun 2026 at 18:20, Evgeny Kolmakov <randomjack94dev@gmail.com> wrote:
>
> Refactor transfer_fn assignment in soc_dma_ch_update()
> via array lookup as suggested by the TODO comment.
>
> Signed-off-by: Evgeny Kolmakov <randomjack94dev@gmail.com>

Any particular reason why you're looking at this ancient
code? It's used only by the omap SoC -- if we care enough
to do anything to it then converting it to qdev is fairly
high up the list...

thanks
-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/dma/soc_dma: Replace if-else chain with array lookup
  2026-06-20 20:23 ` Peter Maydell
@ 2026-06-20 20:33   ` Evgeny
  2026-06-21 13:48     ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Evgeny @ 2026-06-20 20:33 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, qemu-trivial

[-- Attachment #1: Type: text/plain, Size: 825 bytes --]

Dear Peter,

No particular reason.

Just found a small refactor-like TODO comment.
Did not think about this code being ancient.
Feel free to discard the patch then.

Thank you for your time!

Best regards,
Evgeny

On Sat, Jun 20, 2026 at 11:23 PM Peter Maydell <peter.maydell@linaro.org>
wrote:

> On Sat, 20 Jun 2026 at 18:20, Evgeny Kolmakov <randomjack94dev@gmail.com>
> wrote:
> >
> > Refactor transfer_fn assignment in soc_dma_ch_update()
> > via array lookup as suggested by the TODO comment.
> >
> > Signed-off-by: Evgeny Kolmakov <randomjack94dev@gmail.com>
>
> Any particular reason why you're looking at this ancient
> code? It's used only by the omap SoC -- if we care enough
> to do anything to it then converting it to qdev is fairly
> high up the list...
>
> thanks
> -- PMM
>

[-- Attachment #2: Type: text/html, Size: 1403 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hw/dma/soc_dma: Replace if-else chain with array lookup
  2026-06-20 20:33   ` Evgeny
@ 2026-06-21 13:48     ` Peter Maydell
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2026-06-21 13:48 UTC (permalink / raw)
  To: Evgeny; +Cc: qemu-devel, qemu-trivial

On Sat, 20 Jun 2026 at 21:33, Evgeny <randomjack94dev@gmail.com> wrote:
>
> Dear Peter,
>
> No particular reason.
>
> Just found a small refactor-like TODO comment.
> Did not think about this code being ancient.
> Feel free to discard the patch then.

No worries. Unfortunately QEMU has a fair bit of
old code, so TODO comments are often a bit misleading
about how worthwhile making some change is. Some of
them effectively degrade into "we could do this but
it isn't worth the time" :-/

-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-21 13:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-20 17:13 [PATCH] hw/dma/soc_dma: Replace if-else chain with array lookup Evgeny Kolmakov
2026-06-20 20:23 ` Peter Maydell
2026-06-20 20:33   ` Evgeny
2026-06-21 13:48     ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.