This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ed4a351f9878c20b8149b99a4b4d7515ab8afd0d
Author: Peter van der Perk <[email protected]>
AuthorDate: Tue Apr 28 14:32:23 2026 +0200

    arch/arm/imx9: eDMA fix SG TCM address calculation
    
    DLASTSGA needs to be offest for TCM backdoor address.
    Cleanup as well using inline helper for calculuation.
    
    Signed-off-by: Peter van der Perk <[email protected]>
---
 arch/arm/src/imx9/imx9_edma.c | 71 ++++++++++++++++++++++++++++++-------------
 1 file changed, 50 insertions(+), 21 deletions(-)

diff --git a/arch/arm/src/imx9/imx9_edma.c b/arch/arm/src/imx9/imx9_edma.c
index ce4c6e3488f..efa043fb876 100644
--- a/arch/arm/src/imx9/imx9_edma.c
+++ b/arch/arm/src/imx9/imx9_edma.c
@@ -354,6 +354,50 @@ static inline void imx9_tcd_chanlink(uint8_t flags,
 }
 #endif
 
+/****************************************************************************
+ * Name: imx9_edma_addr_to_dmaaddr
+ *
+ * Description:
+ *  Remap addr to eDMA address space if needed.
+ *
+ ****************************************************************************/
+
+static inline uint32_t imx9_edma_addr_to_dmaaddr(uintptr_t addr)
+{
+#ifdef CONFIG_ARCH_CHIP_IMX95_M7
+  if (addr >= (uintptr_t)_ram_start &&
+      addr <  (uintptr_t)_ram_end)
+    {
+      addr += DTCM_BACKDOOR_OFFSET;
+    }
+#endif
+
+  return (uint32_t)addr;
+}
+
+/****************************************************************************
+ * Name: imx9_edma_dmaaddr_to_addr
+ *
+ * Description:
+ *  Convert eDMA address back to CPU-visible address space.
+ *
+ ****************************************************************************/
+
+static inline uintptr_t imx9_edma_dmaaddr_to_addr(uint32_t dmaaddr)
+{
+  uintptr_t addr = (uintptr_t)dmaaddr;
+
+#ifdef CONFIG_ARCH_CHIP_IMX95_M7
+  if (addr >= (uintptr_t)_ram_start + DTCM_BACKDOOR_OFFSET &&
+      addr <  (uintptr_t)_ram_end   + DTCM_BACKDOOR_OFFSET)
+    {
+      addr -= DTCM_BACKDOOR_OFFSET;
+    }
+#endif
+
+  return addr;
+}
+
 /****************************************************************************
  * Name: imx9_tcd_configure
  *
@@ -367,7 +411,7 @@ static inline void imx9_tcd_chanlink(uint8_t flags,
 static inline void imx9_tcd_configure(struct imx9_edmatcd_s *tcd,
                             const struct imx9_edma_xfrconfig_s *config)
 {
-  tcd->saddr    = config->saddr;
+  tcd->saddr    = imx9_edma_addr_to_dmaaddr(config->saddr);
   tcd->soff     = config->soff;
   tcd->attr     = EDMA_TCD_ATTR_SSIZE(config->ssize) |  /* Transfer Attributes 
*/
                   EDMA_TCD_ATTR_DSIZE(config->dsize);
@@ -379,7 +423,7 @@ static inline void imx9_tcd_configure(struct imx9_edmatcd_s 
*tcd,
   tcd->slast    = config->flags & EDMA_CONFIG_LOOPSRC ?
                                   -(config->iter * config->nbytes) : 0;
 
-  tcd->daddr    = config->daddr;
+  tcd->daddr    = imx9_edma_addr_to_dmaaddr(config->daddr);
   tcd->doff     = config->doff;
   tcd->citer    = config->iter & EDMA_TCD_CITER_MASK;
   tcd->biter    = config->iter & EDMA_TCD_BITER_MASK;
@@ -390,22 +434,6 @@ static inline void imx9_tcd_configure(struct 
imx9_edmatcd_s *tcd,
   tcd->dlastsga = config->flags & EDMA_CONFIG_LOOPDEST ?
                                   -(config->iter * config->nbytes) : 0;
 
-#ifdef CONFIG_ARCH_CHIP_IMX95_M7
-  /* Remap address to backdoor address for eDMA */
-
-  if (tcd->saddr >= (uint32_t)_ram_start &&
-      tcd->saddr < (uint32_t)_ram_end)
-    {
-        tcd->saddr += DTCM_BACKDOOR_OFFSET;
-    }
-
-  if (tcd->daddr >= (uint32_t)_ram_start &&
-      tcd->daddr < (uint32_t)_ram_end)
-    {
-        tcd->daddr += DTCM_BACKDOOR_OFFSET;
-    }
-#endif
-
   /* And special case flags */
 
 #ifdef CONFIG_IMX9_EDMA_ELINK
@@ -501,7 +529,8 @@ static void imx9_dmaterminate(struct imx9_dmach_s *dmach, 
int result)
        */
 
        next = dmach->flags & EDMA_CONFIG_LOOPDEST ?
-              NULL : (struct imx9_edmatcd_s *)((uintptr_t)tcd->dlastsga);
+              NULL : (struct imx9_edmatcd_s *)
+              imx9_edma_dmaaddr_to_addr(tcd->dlastsga);
 
        imx9_tcd_free_nolock(tcd);
     }
@@ -1256,7 +1285,7 @@ int imx9_dmach_xfrsetup(DMACH_HANDLE handle,
       regval16      |= EDMA_TCD_CSR_ESG;
       prev->csr      = regval16;
 
-      prev->dlastsga = (uint32_t)((uintptr_t)tcd);
+      prev->dlastsga = imx9_edma_addr_to_dmaaddr((uintptr_t)tcd);
       dmach->tail    = tcd;
 
       /* Clean cache associated with the previous TCD memory */
@@ -1278,7 +1307,7 @@ int imx9_dmach_xfrsetup(DMACH_HANDLE handle,
           regval16 |= EDMA_TCD_CSR_ESG;
           putreg16(regval16, base + IMX9_EDMA_TCD_CSR_OFFSET);
 
-          putreg32((uint32_t)((uintptr_t)tcd),
+          putreg32(imx9_edma_addr_to_dmaaddr((uintptr_t)tcd),
                    base + IMX9_EDMA_TCD_DLAST_SGA_OFFSET);
         }
     }

Reply via email to