Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Sanitise coherentio semantics

The coherentio variable has previously been used as a boolean value,
indicating whether the user specified that coherent I/O should be
enabled or disabled. It failed to take into account the case where the
user does not specify any preference, in which case it makes sense that
we should default to coherent I/O if the hardware supports it
(hw_coherentio is non-zero).

Introduce an enum to clarify the 3 different values of coherentio & use
it throughout the code, modifying plat_device_is_coherent() &
r4k_cache_init() to take into account the default case.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: Paul Burton <paul.burton@imgtec.com>
Patchwork: https://patchwork.linux-mips.org/patch/14347/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Paul Burton and committed by
Ralf Baechle
f2302023 87dd9a4d

+31 -14
+3 -3
arch/mips/alchemy/common/setup.c
··· 48 48 clear_c0_config(1 << 19); /* Clear Config[OD] */ 49 49 50 50 hw_coherentio = 0; 51 - coherentio = 1; 51 + coherentio = IO_COHERENCE_ENABLED; 52 52 switch (alchemy_get_cputype()) { 53 53 case ALCHEMY_CPU_AU1000: 54 54 case ALCHEMY_CPU_AU1500: 55 55 case ALCHEMY_CPU_AU1100: 56 - coherentio = 0; 56 + coherentio = IO_COHERENCE_DISABLED; 57 57 break; 58 58 case ALCHEMY_CPU_AU1200: 59 59 /* Au1200 AB USB does not support coherent memory */ 60 60 if (0 == (read_c0_prid() & PRID_REV_MASK)) 61 - coherentio = 0; 61 + coherentio = IO_COHERENCE_DISABLED; 62 62 break; 63 63 } 64 64
+9 -3
arch/mips/include/asm/dma-coherence.h
··· 9 9 #ifndef __ASM_DMA_COHERENCE_H 10 10 #define __ASM_DMA_COHERENCE_H 11 11 12 + enum coherent_io_user_state { 13 + IO_COHERENCE_DEFAULT, 14 + IO_COHERENCE_ENABLED, 15 + IO_COHERENCE_DISABLED, 16 + }; 17 + 12 18 #ifdef CONFIG_DMA_MAYBE_COHERENT 13 - extern int coherentio; 19 + extern enum coherent_io_user_state coherentio; 14 20 extern int hw_coherentio; 15 21 #else 16 22 #ifdef CONFIG_DMA_COHERENT 17 - #define coherentio 1 23 + #define coherentio IO_COHERENCE_ENABLED 18 24 #else 19 - #define coherentio 0 25 + #define coherentio IO_COHERENCE_DISABLED 20 26 #endif 21 27 #define hw_coherentio 0 22 28 #endif /* CONFIG_DMA_MAYBE_COHERENT */
+9 -1
arch/mips/include/asm/mach-generic/dma-coherence.h
··· 49 49 50 50 static inline int plat_device_is_coherent(struct device *dev) 51 51 { 52 - return coherentio; 52 + switch (coherentio) { 53 + default: 54 + case IO_COHERENCE_DEFAULT: 55 + return hw_coherentio; 56 + case IO_COHERENCE_ENABLED: 57 + return 1; 58 + case IO_COHERENCE_DISABLED: 59 + return 0; 60 + } 53 61 } 54 62 55 63 #ifndef plat_post_dma_flush
+2 -1
arch/mips/mm/c-r4k.c
··· 1935 1935 __local_flush_icache_user_range = local_r4k_flush_icache_user_range; 1936 1936 1937 1937 #if defined(CONFIG_DMA_NONCOHERENT) || defined(CONFIG_DMA_MAYBE_COHERENT) 1938 - if (coherentio) { 1938 + if ((coherentio == IO_COHERENCE_ENABLED) || 1939 + ((coherentio == IO_COHERENCE_DEFAULT) && hw_coherentio)) { 1939 1940 _dma_cache_wback_inv = (void *)cache_noop; 1940 1941 _dma_cache_wback = (void *)cache_noop; 1941 1942 _dma_cache_inv = (void *)cache_noop;
+4 -3
arch/mips/mm/dma-default.c
··· 25 25 #include <dma-coherence.h> 26 26 27 27 #ifdef CONFIG_DMA_MAYBE_COHERENT 28 - int coherentio = 0; /* User defined DMA coherency from command line. */ 28 + /* User defined DMA coherency from command line. */ 29 + enum coherent_io_user_state coherentio = IO_COHERENCE_DEFAULT; 29 30 EXPORT_SYMBOL_GPL(coherentio); 30 31 int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */ 31 32 32 33 static int __init setcoherentio(char *str) 33 34 { 34 - coherentio = 1; 35 + coherentio = IO_COHERENCE_ENABLED; 35 36 pr_info("Hardware DMA cache coherency (command line)\n"); 36 37 return 0; 37 38 } ··· 40 39 41 40 static int __init setnocoherentio(char *str) 42 41 { 43 - coherentio = 0; 42 + coherentio = IO_COHERENCE_DISABLED; 44 43 pr_info("Software DMA cache coherency (command line)\n"); 45 44 return 0; 46 45 }
+2 -2
arch/mips/mti-malta/malta-setup.c
··· 154 154 * coherency instead. 155 155 */ 156 156 if (plat_enable_iocoherency()) { 157 - if (coherentio == 0) 157 + if (coherentio == IO_COHERENCE_DISABLED) 158 158 pr_info("Hardware DMA cache coherency disabled\n"); 159 159 else 160 160 pr_info("Hardware DMA cache coherency enabled\n"); 161 161 } else { 162 - if (coherentio == 1) 162 + if (coherentio == IO_COHERENCE_ENABLED) 163 163 pr_info("Hardware DMA cache coherency unsupported, but enabled from command line!\n"); 164 164 else 165 165 pr_info("Software DMA cache coherency enabled\n");
+2 -1
arch/mips/pci/pci-alchemy.c
··· 429 429 430 430 /* Au1500 revisions older than AD have borked coherent PCI */ 431 431 if ((alchemy_get_cputype() == ALCHEMY_CPU_AU1500) && 432 - (read_c0_prid() < 0x01030202) && !coherentio) { 432 + (read_c0_prid() < 0x01030202) && 433 + (coherentio == IO_COHERENCE_DISABLED)) { 433 434 val = __raw_readl(ctx->regs + PCI_REG_CONFIG); 434 435 val |= PCI_CONFIG_NC; 435 436 __raw_writel(val, ctx->regs + PCI_REG_CONFIG);