aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreentime Hu <greentime@andestech.com>2018-04-30 03:02:27 -0400
committerGreentime Hu <greentime@andestech.com>2018-05-23 01:26:22 -0400
commitabb90a24eade1f612324de0e6920041ef64795cb (patch)
tree67f24bc5d0c844db9c5d3f4c8aabe9d66e464273
parent8769c223491a7fbb345021e7004cbdffe024eaf8 (diff)
nds32: To fix a cache inconsistency issue by setting correct cacheability of NTC
The nds32 architecture will use physical memory when interrupt or exception comes and it will use the setting of NTC0-4. The original implementation didn't consider the DRAM start address may start from 1GB, 2GB or 3GB to cause this issue. It will write the data to DRAM if it is running in physical address however kernel will read the data with virtaul address through data cache. In this case, the data of DRAM is latest. This fix will set the correct cacheability to let kernel write/read the latest data in cache instead of DRAM. Signed-off-by: Greentime Hu <greentime@andestech.com>
-rw-r--r--arch/nds32/include/asm/bitfield.h1
-rw-r--r--arch/nds32/kernel/head.S28
2 files changed, 24 insertions, 5 deletions
diff --git a/arch/nds32/include/asm/bitfield.h b/arch/nds32/include/asm/bitfield.h
index 28b7d797fd59..8e84fc385b94 100644
--- a/arch/nds32/include/asm/bitfield.h
+++ b/arch/nds32/include/asm/bitfield.h
@@ -396,6 +396,7 @@
396#define MMU_CTL_D8KB 1 396#define MMU_CTL_D8KB 1
397#define MMU_CTL_UNA ( 0x1 << MMU_CTL_offUNA ) 397#define MMU_CTL_UNA ( 0x1 << MMU_CTL_offUNA )
398 398
399#define MMU_CTL_CACHEABLE_NON 0
399#define MMU_CTL_CACHEABLE_WB 2 400#define MMU_CTL_CACHEABLE_WB 2
400#define MMU_CTL_CACHEABLE_WT 3 401#define MMU_CTL_CACHEABLE_WT 3
401 402
diff --git a/arch/nds32/kernel/head.S b/arch/nds32/kernel/head.S
index 71f57bd70f3b..c5fdae174ced 100644
--- a/arch/nds32/kernel/head.S
+++ b/arch/nds32/kernel/head.S
@@ -57,14 +57,32 @@ _nodtb:
57 isb 57 isb
58 mtsr $r4, $L1_PPTB ! load page table pointer\n" 58 mtsr $r4, $L1_PPTB ! load page table pointer\n"
59 59
60/* set NTC0 cacheable/writeback, mutliple page size in use */ 60#ifdef CONFIG_CPU_DCACHE_DISABLE
61 #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_NON
62#else
63 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
64 #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_WT
65 #else
66 #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_WB
67 #endif
68#endif
69
70/* set NTC cacheability, mutliple page size in use */
61 mfsr $r3, $MMU_CTL 71 mfsr $r3, $MMU_CTL
62 li $r0, #~MMU_CTL_mskNTC0 72#if CONFIG_MEMORY_START >= 0xc0000000
63 and $r3, $r3, $r0 73 ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC3)
74#elif CONFIG_MEMORY_START >= 0x80000000
75 ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC2)
76#elif CONFIG_MEMORY_START >= 0x40000000
77 ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC1)
78#else
79 ori $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC0)
80#endif
81
64#ifdef CONFIG_ANDES_PAGE_SIZE_4KB 82#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
65 ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << MMU_CTL_offNTC0)) 83 ori $r3, $r3, #(MMU_CTL_mskMPZIU)
66#else 84#else
67 ori $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << MMU_CTL_offNTC0)|MMU_CTL_D8KB) 85 ori $r3, $r3, #(MMU_CTL_mskMPZIU|MMU_CTL_D8KB)
68#endif 86#endif
69#ifdef CONFIG_HW_SUPPORT_UNALIGNMENT_ACCESS 87#ifdef CONFIG_HW_SUPPORT_UNALIGNMENT_ACCESS
70 li $r0, #MMU_CTL_UNA 88 li $r0, #MMU_CTL_UNA