]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - arch/arm/mm/cache-l2x0.c
Merge branches 'irq-core-for-linus' and 'core-locking-for-linus' of git://git.kernel...
[karo-tx-linux.git] / arch / arm / mm / cache-l2x0.c
index 9310d618070b659526eb8ac066163e6a727e1469..170c9bb958666afc587e6b94c6e424f43b939a88 100644 (file)
@@ -28,6 +28,7 @@
 static void __iomem *l2x0_base;
 static DEFINE_SPINLOCK(l2x0_lock);
 static uint32_t l2x0_way_mask; /* Bitmask of active ways */
+static uint32_t l2x0_size;
 
 static inline void cache_wait_way(void __iomem *reg, unsigned long mask)
 {
@@ -124,6 +125,18 @@ static void l2x0_flush_all(void)
        spin_unlock_irqrestore(&l2x0_lock, flags);
 }
 
+static void l2x0_clean_all(void)
+{
+       unsigned long flags;
+
+       /* clean all ways */
+       spin_lock_irqsave(&l2x0_lock, flags);
+       writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_CLEAN_WAY);
+       cache_wait_way(l2x0_base + L2X0_CLEAN_WAY, l2x0_way_mask);
+       cache_sync();
+       spin_unlock_irqrestore(&l2x0_lock, flags);
+}
+
 static void l2x0_inv_all(void)
 {
        unsigned long flags;
@@ -182,6 +195,11 @@ static void l2x0_clean_range(unsigned long start, unsigned long end)
        void __iomem *base = l2x0_base;
        unsigned long flags;
 
+       if ((end - start) >= l2x0_size) {
+               l2x0_clean_all();
+               return;
+       }
+
        spin_lock_irqsave(&l2x0_lock, flags);
        start &= ~(CACHE_LINE_SIZE - 1);
        while (start < end) {
@@ -207,6 +225,11 @@ static void l2x0_flush_range(unsigned long start, unsigned long end)
        void __iomem *base = l2x0_base;
        unsigned long flags;
 
+       if ((end - start) >= l2x0_size) {
+               l2x0_flush_all();
+               return;
+       }
+
        spin_lock_irqsave(&l2x0_lock, flags);
        start &= ~(CACHE_LINE_SIZE - 1);
        while (start < end) {
@@ -242,6 +265,7 @@ void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)
 {
        __u32 aux;
        __u32 cache_id;
+       __u32 way_size = 0;
        int ways;
        const char *type;
 
@@ -275,6 +299,13 @@ void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)
 
        l2x0_way_mask = (1 << ways) - 1;
 
+       /*
+        * L2 cache Size =  Way size * Number of ways
+        */
+       way_size = (aux & L2X0_AUX_CTRL_WAY_SIZE_MASK) >> 17;
+       way_size = 1 << (way_size + 3);
+       l2x0_size = ways * way_size * SZ_1K;
+
        /*
         * Check if l2x0 controller is already enabled.
         * If you are booting from non-secure mode
@@ -300,6 +331,6 @@ void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)
        outer_cache.disable = l2x0_disable;
 
        printk(KERN_INFO "%s cache controller enabled\n", type);
-       printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x\n",
-                        ways, cache_id, aux);
+       printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x, Cache size: %d B\n",
+                       ways, cache_id, aux, l2x0_size);
 }