ARM: l2c: only unlock caches if NS_LOCKDOWN bit is set
[cascardo/linux.git] / arch / arm / mm / cache-l2x0.c
index e309c8f..95f3362 100644 (file)
@@ -42,6 +42,7 @@ struct l2c_init_data {
        void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
        void (*save)(void __iomem *);
        void (*configure)(void __iomem *);
+       void (*unlock)(void __iomem *, unsigned);
        struct outer_cache_fns outer_cache;
 };
 
@@ -110,14 +111,6 @@ static inline void l2c_unlock(void __iomem *base, unsigned num)
 
 static void l2c_configure(void __iomem *base)
 {
-       if (outer_cache.configure) {
-               outer_cache.configure(&l2x0_saved_regs);
-               return;
-       }
-
-       if (l2x0_data->configure)
-               l2x0_data->configure(base);
-
        l2c_write_sec(l2x0_saved_regs.aux_ctrl, base, L2X0_AUX_CTRL);
 }
 
@@ -129,14 +122,14 @@ static void l2c_enable(void __iomem *base, u32 aux, unsigned num_lock)
 {
        unsigned long flags;
 
-       /* Do not touch the controller if already enabled. */
-       if (readl_relaxed(base + L2X0_CTRL) & L2X0_CTRL_EN)
-               return;
-
        l2x0_saved_regs.aux_ctrl = aux;
-       l2c_configure(base);
 
-       l2c_unlock(base, num_lock);
+       if (outer_cache.configure)
+               outer_cache.configure(&l2x0_saved_regs);
+       else
+               l2x0_data->configure(base);
+
+       l2x0_data->unlock(base, num_lock);
 
        local_irq_save(flags);
        __l2c_op_way(base + L2X0_INV_WAY);
@@ -163,7 +156,11 @@ static void l2c_save(void __iomem *base)
 
 static void l2c_resume(void)
 {
-       l2c_enable(l2x0_base, l2x0_saved_regs.aux_ctrl, l2x0_data->num_lock);
+       void __iomem *base = l2x0_base;
+
+       /* Do not touch the controller if already enabled. */
+       if (!(readl_relaxed(base + L2X0_CTRL) & L2X0_CTRL_EN))
+               l2c_enable(base, l2x0_saved_regs.aux_ctrl, l2x0_data->num_lock);
 }
 
 /*
@@ -252,6 +249,8 @@ static const struct l2c_init_data l2c210_data __initconst = {
        .num_lock = 1,
        .enable = l2c_enable,
        .save = l2c_save,
+       .configure = l2c_configure,
+       .unlock = l2c_unlock,
        .outer_cache = {
                .inv_range = l2c210_inv_range,
                .clean_range = l2c210_clean_range,
@@ -403,12 +402,20 @@ static void l2c220_enable(void __iomem *base, u32 aux, unsigned num_lock)
        l2c_enable(base, aux, num_lock);
 }
 
+static void l2c220_unlock(void __iomem *base, unsigned num_lock)
+{
+       if (readl_relaxed(base + L2X0_AUX_CTRL) & L220_AUX_CTRL_NS_LOCKDOWN)
+               l2c_unlock(base, num_lock);
+}
+
 static const struct l2c_init_data l2c220_data = {
        .type = "L2C-220",
        .way_size_0 = SZ_8K,
        .num_lock = 1,
        .enable = l2c220_enable,
        .save = l2c_save,
+       .configure = l2c_configure,
+       .unlock = l2c220_unlock,
        .outer_cache = {
                .inv_range = l2c220_inv_range,
                .clean_range = l2c220_clean_range,
@@ -569,6 +576,8 @@ static void l2c310_configure(void __iomem *base)
 {
        unsigned revision;
 
+       l2c_configure(base);
+
        /* restore pl310 setup */
        l2c_write_sec(l2x0_saved_regs.tag_latency, base,
                      L310_TAG_LATENCY_CTRL);
@@ -755,6 +764,12 @@ static void l2c310_resume(void)
                set_auxcr(get_auxcr() | BIT(3) | BIT(2) | BIT(1));
 }
 
+static void l2c310_unlock(void __iomem *base, unsigned num_lock)
+{
+       if (readl_relaxed(base + L2X0_AUX_CTRL) & L310_AUX_CTRL_NS_LOCKDOWN)
+               l2c_unlock(base, num_lock);
+}
+
 static const struct l2c_init_data l2c310_init_fns __initconst = {
        .type = "L2C-310",
        .way_size_0 = SZ_8K,
@@ -763,6 +778,7 @@ static const struct l2c_init_data l2c310_init_fns __initconst = {
        .fixup = l2c310_fixup,
        .save = l2c310_save,
        .configure = l2c310_configure,
+       .unlock = l2c310_unlock,
        .outer_cache = {
                .inv_range = l2c210_inv_range,
                .clean_range = l2c210_clean_range,
@@ -1066,6 +1082,8 @@ static const struct l2c_init_data of_l2c210_data __initconst = {
        .of_parse = l2x0_of_parse,
        .enable = l2c_enable,
        .save = l2c_save,
+       .configure = l2c_configure,
+       .unlock = l2c_unlock,
        .outer_cache = {
                .inv_range   = l2c210_inv_range,
                .clean_range = l2c210_clean_range,
@@ -1084,6 +1102,8 @@ static const struct l2c_init_data of_l2c220_data __initconst = {
        .of_parse = l2x0_of_parse,
        .enable = l2c220_enable,
        .save = l2c_save,
+       .configure = l2c_configure,
+       .unlock = l2c220_unlock,
        .outer_cache = {
                .inv_range   = l2c220_inv_range,
                .clean_range = l2c220_clean_range,
@@ -1211,6 +1231,7 @@ static const struct l2c_init_data of_l2c310_data __initconst = {
        .fixup = l2c310_fixup,
        .save  = l2c310_save,
        .configure = l2c310_configure,
+       .unlock = l2c310_unlock,
        .outer_cache = {
                .inv_range   = l2c210_inv_range,
                .clean_range = l2c210_clean_range,
@@ -1240,6 +1261,7 @@ static const struct l2c_init_data of_l2c310_coherent_data __initconst = {
        .fixup = l2c310_fixup,
        .save  = l2c310_save,
        .configure = l2c310_configure,
+       .unlock = l2c310_unlock,
        .outer_cache = {
                .inv_range   = l2c210_inv_range,
                .clean_range = l2c210_clean_range,
@@ -1416,6 +1438,8 @@ static const struct l2c_init_data of_aurora_with_outer_data __initconst = {
        .enable = l2c_enable,
        .fixup = aurora_fixup,
        .save  = aurora_save,
+       .configure = l2c_configure,
+       .unlock = l2c_unlock,
        .outer_cache = {
                .inv_range   = aurora_inv_range,
                .clean_range = aurora_clean_range,
@@ -1435,6 +1459,8 @@ static const struct l2c_init_data of_aurora_no_outer_data __initconst = {
        .enable = aurora_enable_no_outer,
        .fixup = aurora_fixup,
        .save  = aurora_save,
+       .configure = l2c_configure,
+       .unlock = l2c_unlock,
        .outer_cache = {
                .resume      = l2c_resume,
        },
@@ -1585,6 +1611,7 @@ static const struct l2c_init_data of_bcm_l2x0_data __initconst = {
        .enable = l2c310_enable,
        .save  = l2c310_save,
        .configure = l2c310_configure,
+       .unlock = l2c310_unlock,
        .outer_cache = {
                .inv_range   = bcm_inv_range,
                .clean_range = bcm_clean_range,
@@ -1608,6 +1635,7 @@ static void __init tauros3_save(void __iomem *base)
 
 static void tauros3_configure(void __iomem *base)
 {
+       l2c_configure(base);
        writel_relaxed(l2x0_saved_regs.aux2_ctrl,
                       base + TAUROS3_AUX2_CTRL);
        writel_relaxed(l2x0_saved_regs.prefetch_ctrl,
@@ -1621,6 +1649,7 @@ static const struct l2c_init_data of_tauros3_data __initconst = {
        .enable = l2c_enable,
        .save  = tauros3_save,
        .configure = tauros3_configure,
+       .unlock = l2c_unlock,
        /* Tauros3 broadcasts L1 cache operations to L2 */
        .outer_cache = {
                .resume      = l2c_resume,