MIPS: Add option to disable software I/O coherency.
PATCH v3 1/1 MIPS: Add option to disable software I/O coherency.
From: "Steven J. Hill" <[email protected]>
Some MIPS controllers have hardware I/O coherency. This patch detects those and turns off software coherency. A new kernel command line option also allows the user to manually turn software coherency on or off.
Signed-off-by Steven J. Hill <[email protected]>
--- arch/mips/include/asm/mach-generic/dma-coherence.h | 5 +- arch/mips/mm/c-r4k.c | 34 +++++++--- arch/mips/mm/dma-default.c | 6 +- arch/mips/mti-malta/malta-setup.c | 71 ++++++++++++++++++++ 4 files changed, 105 insertions(+), 11 deletions(-)
arch/mips/include/asm/mach-generic/dma-coherence.h +4 -1
@@ -57,13 +57,16 @@ static inline int plat_dma_mapping_error(struct device *dev,return 0 ; } +extern int coherentio; +extern int hw_coherentio; +static inline int plat_device_is_coherent (struct device *dev) {#ifdef CONFIG_DMA_COHERENT return 1 ;#endif #ifdef CONFIG_DMA_NONCOHERENT -return 0 ; +return coherentio;#endif }
arch/mips/mm/c-r4k.c +26 -8
@@ -1379,19 +1379,34 @@ static void __cpuinit coherency_setup(void) } } -#if defined(CONFIG_DMA_NONCOHERENT ) - -static int __cpuinitdata coherentio; +int coherentio =0 ;/* no DMA cache coherency (may be set by user) */ +int hw_coherentio =0 ;/* no HW DMA cache coherency (reflects real HW) */ static int __init setcoherentio (char *str) { - coherentio =1 ; +if (coherentio ==0 ) +pr_info ("Command line enabling coherentio" +" (this will break...)!!\n" ); + coherentio =1 ; +pr_info ("Hardware DMA cache coherency (command line)\n" );return 0 ; } -early_param ("coherentio" , setcoherentio); -#endif + +static int __init setnocoherentio (char *str) +{ +if (coherentio <0 ) +pr_info ("Command line checking done before" +" plat_setup_iocoherency!!\n" ); +if (coherentio ==1 ) +pr_info ("Command line disabling coherentio\n" ); + + coherentio =0 ; +pr_info ("Software DMA cache coherency (command line)\n" ); +return 0 ; +} +early_param ("nocoherentio" , setnocoherentio);static void __cpuinit r4k_cache_error_setup (void ) {
@@ -1415,6 +1430,7 @@ void __cpuinit r4k_cache_init(void) {extern void build_clear_page (void );extern void build_copy_page (void ); +extern int coherentio;struct cpuinfo_mips *c = ¤t_cpu_data;probe_pcache ();
@@ -1474,9 +1490,11 @@ void __cpuinit r4k_cache_init(void)build_clear_page ();build_copy_page (); -#if !defined(CONFIG_MIPS_CMP ) + +/* We want to run CMP kernels on core(s) with and without coherent caches */ +/* Therefore can't use CONFIG_MIPS_CMP to decide to flush cache */ local_r4k___flush_cache_all (NULL ); -#endif +coherency_setup (); board_cache_error_setup = r4k_cache_error_setup; }
arch/mips/mm/dma-default.c +4 -2
@@ -115,7 +115,8 @@ static void *mips_dma_alloc_coherent(struct device *dev, size_t size,if (!plat_device_is_coherent (dev)) {dma_cache_wback_inv ((unsigned long ) ret, size); - ret =UNCAC_ADDR (ret); +if (!hw_coherentio) + ret =UNCAC_ADDR (ret); } }
@@ -143,7 +144,8 @@ static void mips_dma_free_coherent(struct device *dev, size_t size, void *vaddr,plat_unmap_dma_mem (dev, dma_handle, size,DMA_BIDIRECTIONAL );if (!plat_device_is_coherent (dev)) - addr =CAC_ADDR (addr); +if (!hw_coherentio) + addr =CAC_ADDR (addr);free_pages (addr,get_order (size)); }
arch/mips/mti-malta/malta-setup.c +71 -0
89 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Quoted 7 lines · Steven J. Hill
From: "Steven J. Hill" <[email protected]>
Some MIPS controllers have hardware I/O coherency. This patch detects those and turns off software coherency. A new kernel command line option also allows the user to manually turn software coherency on or off.
Quoted 7 lines
Signed-off-by Steven J. Hill <[email protected]>--- arch/mips/include/asm/mach-generic/dma-coherence.h | 5 +- arch/mips/mm/c-r4k.c | 34 +++++++--- arch/mips/mm/dma-default.c | 6 +- arch/mips/mti-malta/malta-setup.c | 71 ++++++++++++++++++++ 4 files changed, 105 insertions(+), 11 deletions(-)
Tested successfully on my RM7035C-based system that has CONFIG_DMA_NONCOHERENT set. My system works fine with this patch applied.
Tested-by Shane McDonald <[email protected]>