]> git.sur5r.net Git - u-boot/blobdiff - arch/arm/lib/cache-cp15.c
serial: zynq: Use BIT macros instead of shifts and full hex numbers
[u-boot] / arch / arm / lib / cache-cp15.c
index 3aabda156b319779bfee87d2da6e0c17ec38b960..0688f1e6a679fb77ea0836669235df87dbe18d28 100644 (file)
@@ -1,19 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2002
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/system.h>
 #include <asm/cache.h>
 #include <linux/compiler.h>
+#include <asm/armv7_mpu.h>
 
 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#ifdef CONFIG_SYS_ARM_MMU
 __weak void arm_init_before_mmu(void)
 {
 }
@@ -22,16 +23,6 @@ __weak void arm_init_domains(void)
 {
 }
 
-static void cp_delay (void)
-{
-       volatile int i;
-
-       /* copro seems to need some delay between reading and writing */
-       for (i = 0; i < 100; i++)
-               nop();
-       asm volatile("" : : : "memory");
-}
-
 void set_section_dcache(int section, enum dcache_option option)
 {
 #ifdef CONFIG_ARMV7_LPAE
@@ -66,15 +57,32 @@ void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
 #else
        u32 *page_table = (u32 *)gd->arch.tlb_addr;
 #endif
+       unsigned long startpt, stoppt;
        unsigned long upto, end;
 
        end = ALIGN(start + size, MMU_SECTION_SIZE) >> MMU_SECTION_SHIFT;
        start = start >> MMU_SECTION_SHIFT;
-       debug("%s: start=%pa, size=%zu, option=%d\n", __func__, &start, size,
+#ifdef CONFIG_ARMV7_LPAE
+       debug("%s: start=%pa, size=%zu, option=%llx\n", __func__, &start, size,
              option);
+#else
+       debug("%s: start=%pa, size=%zu, option=0x%x\n", __func__, &start, size,
+             option);
+#endif
        for (upto = start; upto < end; upto++)
                set_section_dcache(upto, option);
-       mmu_page_table_flush((u32)&page_table[start], (u32)&page_table[end]);
+
+       /*
+        * Make sure range is cache line aligned
+        * Only CPU maintains page tables, hence it is safe to always
+        * flush complete cache lines...
+        */
+
+       startpt = (unsigned long)&page_table[start];
+       startpt &= ~(CONFIG_SYS_CACHELINE_SIZE - 1);
+       stoppt = (unsigned long)&page_table[end];
+       stoppt = ALIGN(stoppt, CONFIG_SYS_CACHELINE_SIZE);
+       mmu_page_table_flush(startpt, stoppt);
 }
 
 __weak void dram_bank_mmu_setup(int bank)
@@ -112,7 +120,7 @@ static inline void mmu_setup(void)
                dram_bank_mmu_setup(i);
        }
 
-#ifdef CONFIG_ARMV7_LPAE
+#if defined(CONFIG_ARMV7_LPAE) && __LINUX_ARM_ARCH__ != 4
        /* Set up 4 PTE entries pointing to our 4 1GB page tables */
        for (i = 0; i < 4; i++) {
                u64 *page_table = (u64 *)(gd->arch.tlb_addr + (4096 * 4));
@@ -130,7 +138,7 @@ static inline void mmu_setup(void)
 #endif
 
        if (is_hyp()) {
-               /* Set HCTR to enable LPAE */
+               /* Set HTCR to enable LPAE */
                asm volatile("mcr p15, 4, %0, c2, c0, 2"
                        : : "r" (reg) : "memory");
                /* Set HTTBR0 */
@@ -154,7 +162,16 @@ static inline void mmu_setup(void)
                asm volatile("mcr p15, 0, %0, c10, c2, 0"
                        : : "r" (MEMORY_ATTRIBUTES) : "memory");
        }
-#elif defined(CONFIG_CPU_V7)
+#elif defined(CONFIG_CPU_V7A)
+       if (is_hyp()) {
+               /* Set HTCR to disable LPAE */
+               asm volatile("mcr p15, 4, %0, c2, c0, 2"
+                       : : "r" (0) : "memory");
+       } else {
+               /* Set TTBCR to disable LPAE */
+               asm volatile("mcr p15, 0, %0, c2, c0, 2"
+                       : : "r" (0) : "memory");
+       }
        /* Set TTBR0 */
        reg = gd->arch.tlb_addr & TTBR0_BASE_ADDR_MASK;
 #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
@@ -179,7 +196,6 @@ static inline void mmu_setup(void)
 
        /* and enable the mmu */
        reg = get_cr(); /* get control reg. */
-       cp_delay();
        set_cr(reg | CR_M);
 }
 
@@ -187,17 +203,24 @@ static int mmu_enabled(void)
 {
        return get_cr() & CR_M;
 }
+#endif /* CONFIG_SYS_ARM_MMU */
 
 /* cache_bit must be either CR_I or CR_C */
 static void cache_enable(uint32_t cache_bit)
 {
        uint32_t reg;
 
-       /* The data cache is not active unless the mmu is enabled too */
+       /* The data cache is not active unless the mmu/mpu is enabled too */
+#ifdef CONFIG_SYS_ARM_MMU
        if ((cache_bit == CR_C) && !mmu_enabled())
                mmu_setup();
+#elif defined(CONFIG_SYS_ARM_MPU)
+       if ((cache_bit == CR_C) && !mpu_enabled()) {
+               printf("Consider enabling MPU before enabling caches\n");
+               return;
+       }
+#endif
        reg = get_cr(); /* get control reg. */
-       cp_delay();
        set_cr(reg | cache_bit);
 }
 
@@ -207,7 +230,6 @@ static void cache_disable(uint32_t cache_bit)
        uint32_t reg;
 
        reg = get_cr();
-       cp_delay();
 
        if (cache_bit == CR_C) {
                /* if cache isn;t enabled no need to disable */
@@ -217,7 +239,7 @@ static void cache_disable(uint32_t cache_bit)
                cache_bit |= CR_M;
        }
        reg = get_cr();
-       cp_delay();
+
        if (cache_bit == (CR_C | CR_M))
                flush_dcache_all();
        set_cr(reg & ~cache_bit);