Skip to content

Commit 7610eba

Browse files
decsnycfriedt
authored andcommitted
drivers: dma_mcux_edma: Simplify cache attr macros
The dependency on the chosen node for dtcm can be expressed in Kconfig language. Cache we care about is CPU DCACHE, not the meaningless "MCUX Cache" The macros can be reordered to be simpler by having only one level of conditional (no nesting) instead of three levels. Move this code closer in the file to where this cache attribute macro is actually going to be used (the init macro) instead of randomly splitting up the struct definitions at the top. Signed-off-by: Declan Snyder <[email protected]>
1 parent 4d34bee commit 7610eba

File tree

2 files changed

+19
-32
lines changed

2 files changed

+19
-32
lines changed

drivers/dma/Kconfig.mcux_edma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ config DMA_MCUX_USE_DTCM_FOR_DMA_DESCRIPTORS
5858
bool "Use DTCM for DMA descriptors"
5959
default y
6060
depends on DT_HAS_NXP_IMX_DTCM_ENABLED
61+
depends on $(dt_chosen_enabled,zephyr_dtcm)
6162
help
6263
When this option is activated, the descriptors for DMA transfer are
6364
located in the DTCM (Data Tightly Coupled Memory).

drivers/dma/dma_mcux_edma.c

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,38 +62,6 @@ struct dma_mcux_edma_config {
6262
edma_tcd_t (*tcdpool)[CONFIG_DMA_TCD_QUEUE_SIZE];
6363
};
6464

65-
66-
#if defined(CONFIG_HAS_MCUX_CACHE) || defined(CONFIG_HAS_MCUX_XCACHE)
67-
68-
#ifdef CONFIG_DMA_MCUX_USE_DTCM_FOR_DMA_DESCRIPTORS
69-
70-
#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm))
71-
#define EDMA_TCDPOOL_CACHE_ATTR __dtcm_noinit_section
72-
#else /* DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) */
73-
#error Selected DTCM for MCUX DMA descriptors but no DTCM section.
74-
#endif /* DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) */
75-
76-
#elif defined(CONFIG_NOCACHE_MEMORY)
77-
#define EDMA_TCDPOOL_CACHE_ATTR __nocache
78-
#else
79-
/*
80-
* Note: the TCD pool *must* be in non cacheable memory. All of the NXP SOCs
81-
* that support caching memory have their default SRAM regions defined as a
82-
* non cached memory region, but if the default SRAM region is changed EDMA
83-
* TCD pools would be moved to cacheable memory, resulting in DMA cache
84-
* coherency issues.
85-
*/
86-
87-
#define EDMA_TCDPOOL_CACHE_ATTR
88-
89-
#endif /* CONFIG_DMA_MCUX_USE_DTCM_FOR_DMA_DESCRIPTORS */
90-
91-
#else /* CONFIG_HAS_MCUX_CACHE */
92-
93-
#define EDMA_TCDPOOL_CACHE_ATTR
94-
95-
#endif /* CONFIG_HAS_MCUX_CACHE */
96-
9765
struct dma_mcux_channel_transfer_edma_settings {
9866
uint32_t source_data_size;
9967
uint32_t dest_data_size;
@@ -1021,6 +989,24 @@ static int dma_mcux_edma_init(const struct device *dev)
1021989
#define DMA_TCD_ALIGN_SIZE 32
1022990
#endif
1023991

992+
/*
993+
* Note: the TCD pool *must* be in non cacheable memory. All of the NXP SOCs
994+
* that support caching memory have their default SRAM regions defined as a
995+
* non cached memory region, but if the default SRAM region is changed EDMA
996+
* TCD pools would be moved to cacheable memory, resulting in DMA cache
997+
* coherency issues.
998+
*/
999+
#if !defined(CONFIG_CPU_HAS_DCACHE)
1000+
/* no cache means no worries */
1001+
#define EDMA_TCDPOOL_CACHE_ATTR
1002+
#elif defined(CONFIG_DMA_MCUX_USE_DTCM_FOR_DMA_DESCRIPTORS)
1003+
#define EDMA_TCDPOOL_CACHE_ATTR __dtcm_noinit_section
1004+
#elif defined(CONFIG_NOCACHE_MEMORY)
1005+
#define EDMA_TCDPOOL_CACHE_ATTR __nocache
1006+
#else
1007+
#error Unexpected or disallowed cache situation for dma descriptors
1008+
#endif
1009+
10241010
/*
10251011
* define the dma
10261012
*/

0 commit comments

Comments
 (0)