nds32: To fix a cache inconsistency issue by setting correct cacheability of NTC
authorGreentime Hu <greentime@andestech.com>
Mon, 30 Apr 2018 07:02:27 +0000 (15:02 +0800)
committerGreentime Hu <greentime@andestech.com>
Wed, 23 May 2018 05:26:22 +0000 (13:26 +0800)
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>
arch/nds32/include/asm/bitfield.h
arch/nds32/kernel/head.S

index 28b7d797fd59baa289c3a507d04242f17fc52c6a..8e84fc385b946c391b932777d49bb82d05e25598 100644 (file)
 #define MMU_CTL_D8KB           1
 #define MMU_CTL_UNA            ( 0x1  << MMU_CTL_offUNA )
 
+#define MMU_CTL_CACHEABLE_NON   0
 #define MMU_CTL_CACHEABLE_WB   2
 #define MMU_CTL_CACHEABLE_WT   3
 
index 71f57bd70f3b8ce109b3e842d7f16819964a45e4..c5fdae174ced5ac3ff2b28fdb24e80c3884b6af4 100644 (file)
@@ -57,14 +57,32 @@ _nodtb:
        isb
        mtsr    $r4, $L1_PPTB       ! load page table pointer\n"
 
-/* set NTC0 cacheable/writeback, mutliple page size in use */
+#ifdef CONFIG_CPU_DCACHE_DISABLE
+       #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_NON
+#else
+       #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
+               #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_WT
+       #else
+               #define MMU_CTL_NTCC MMU_CTL_CACHEABLE_WB
+       #endif
+#endif
+
+/* set NTC cacheability, mutliple page size in use */
        mfsr    $r3, $MMU_CTL
-       li      $r0, #~MMU_CTL_mskNTC0
-       and     $r3, $r3, $r0
+#if CONFIG_MEMORY_START >= 0xc0000000
+       ori     $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC3)
+#elif CONFIG_MEMORY_START >= 0x80000000
+       ori     $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC2)
+#elif CONFIG_MEMORY_START >= 0x40000000
+       ori     $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC1)
+#else
+       ori     $r3, $r3, (MMU_CTL_NTCC << MMU_CTL_offNTC0)
+#endif
+
 #ifdef CONFIG_ANDES_PAGE_SIZE_4KB
-       ori     $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << MMU_CTL_offNTC0))
+       ori     $r3, $r3, #(MMU_CTL_mskMPZIU)
 #else
-       ori     $r3, $r3, #(MMU_CTL_mskMPZIU|(MMU_CTL_CACHEABLE_WB << MMU_CTL_offNTC0)|MMU_CTL_D8KB)
+       ori     $r3, $r3, #(MMU_CTL_mskMPZIU|MMU_CTL_D8KB)
 #endif
 #ifdef CONFIG_HW_SUPPORT_UNALIGNMENT_ACCESS
        li      $r0, #MMU_CTL_UNA