diff mbox series

[PATCH-for-9.1?,v2,3/4] hw/sd/sdhci: Read ADMA2_64 descriptor with a single dma_memory_read()

Message ID 20240731212501.44385-4-philmd@linaro.org
State New
Headers show
Series hw/sd/sdhci: Check ADMA descriptors can be accessed | expand

Commit Message

Philippe Mathieu-Daudé July 31, 2024, 9:25 p.m. UTC
Instead of 3 consecutive dma_memory_read() calls, use
a packed structure to read the descriptor in a single
call.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/sd/sdhci.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 0a95f49b93..2d8fa3151a 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -740,16 +740,20 @@  static void get_adma_description(SDHCIState *s, ADMADescr *dscr)
         }
     case SDHC_CTRL_ADMA2_64:
         {
-            dma_memory_read(s->dma_as, entry_addr, &dscr->attr, 1,
+            struct {
+                uint8_t attr;
+                uint8_t pad;
+                uint16_t length;
+                uint64_t addr;
+            } QEMU_PACKED adma2;
+            QEMU_BUILD_BUG_ON(sizeof(adma2) != 12);
+
+            dma_memory_read(s->dma_as, entry_addr, &adma2, sizeof(adma2),
                             MEMTXATTRS_UNSPECIFIED);
-            dma_memory_read(s->dma_as, entry_addr + 2, &dscr->length, 2,
-                            MEMTXATTRS_UNSPECIFIED);
-            dscr->length = le16_to_cpu(dscr->length);
-            dma_memory_read(s->dma_as, entry_addr + 4, &dscr->addr, 8,
-                            MEMTXATTRS_UNSPECIFIED);
-            dscr->addr = le64_to_cpu(dscr->addr);
-            dscr->attr &= (uint8_t) ~0xC0;
-            dscr->incr = 12;
+            dscr->length = le16_to_cpu(adma2.length);
+            dscr->addr = le64_to_cpu(adma2.addr);
+            dscr->attr = adma2.attr & (uint8_t) ~0xc0;
+            dscr->incr = sizeof(adma2);
             trace_adma_description("ADMA2_64", dscr);
             break;
         }