Skip to contentSkip to conversation

Add support for Aurora L2 Cache Controller

PATCH Superseded Gregory CLEMENT 2 participants 11 messages Sep 4, 2012 – Sep 5, 2012

Subsystems (4)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Add support for Aurora L2 Cache Controller

Hello,

This a the 2nd version of the patch set (the third if we include the RFC). See the end of this email for the changelog.

The purpose of this patch set is to add support for Aurora L2 Cache Controller used by Armada 370 and Armada XP SoCs. As it was initially designed by Marvell engineer to be compatible with the ARM L2 Cache Controller, we chose to reuse the existing code and to just extend it to support the differences and improvements brought by the Aurora controller.The diffstat looks like:

 Documentation/devicetree/bindings/arm/l2cc.txt  |    9 +
 arch/arm/boot/dts/armada-370.dtsi               |    6 +
 arch/arm/boot/dts/armada-xp.dtsi                |    7 +
 arch/arm/include/asm/hardware/cache-aurora-l2.h |   51 ++++
 arch/arm/include/asm/hardware/cache-l2x0.h      |    1 +
 arch/arm/mach-mvebu/Kconfig                     |    1 +
 arch/arm/mach-mvebu/irq-armada-370-xp.c         |    4 +
 arch/arm/mm/cache-l2x0.c                        |  298 +++++++++++++++++++++--
 8 files changed, 363 insertions(+), 14 deletions(-)

The main differences and improvements are:

- no cache id part number available through hardware (need to get it by the DT).
- always write through mode available.
- two flavors of the controller 'outer cache' and 'system cache' (the last one meaning maintenance operations on L1 are broadcasted to the L2 and L2 performs the same operation).
- in outer cache mode, the cache maintenance operations are improved and can be done on a range inside a page and are not limited to a cache line.
- during resume the controller need to restore the ctrl register.

The first patch adds some modifications in the driver infrastructure. As most of the outer cache functions can use the Aurora improvements, we had to introduce new functions. So we thought it was better to use a outer_cache_fns field inside l2x0_of_data and just memcopy it into outer_cache depending of the type of the l2x0 cache.

Changelog:
V2 -> V1:
- Rebased L2 pach set onto v3.6-rc4.
- Changed the compatible names to be more explicit, from aurora-cache-with-outer to aurora-outer-cache , and from aurora-cache-without-outer to aurora-system-cache.
- Add an isb() after the call to mcr in aurora_broadcast_l2_commands().
- Added the tested and reviewed-by from Lior Amsalem and Yehuda Yitschak.
- Tested on Armada 370 and Armada XP boards and ran benchmark without seeing any regression.

RFC -> V1:
- Rebased the series on to V3.6-rc3
- Added missing Signed-off-by
- Corrected a compilation warning that I have missed
- Ran benchmarks without seeing any regression

Benchmarks results are visible here:
https://github.com/MISL-EBU-System-SW/mainline-public/wiki/Non-official-cache-bench-results-on-the-mainline-Linux-port-%28-kernels-3.6-rcX%29-of-Armada-XP-and-Armada-370

The git branch aurora-L2-cache-ctrl is visible at
https://github.com/MISL-EBU-System-SW/mainline-public.git

Regards,

Gregory

#1 lore raw

PATCH v2 1/6 arm: cache-l2x0: make outer_cache_fns a field of l2x0_of_data

Instead of having multiple functions belonging to outer_cache and filling this structure on the fly, use a outer_cache_fns field inside l2x0_of_data and just memcopy it into outer_cache depending of the type of the l2x0 cache. For non DT case, the former code was kept.

Cc Barry Song <[email protected]>
Cc Will Deacon <[email protected]>
Cc Santosh Shilimkar <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Olof Johansson <[email protected]>
---
 arch/arm/mm/cache-l2x0.c |   38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)
arch/arm/mm/cache-l2x0.c +30 -8
index 2a8e380..3591940 100644
@@ -39,7 +39,7 @@ struct l2x0_regs l2x0_saved_regs;
 struct l2x0_of_data {
 	void (*setup)(const struct device_node *, u32 *, u32 *);
 	void (*save)(void);
-	void (*resume)(void);
+	struct outer_cache_fns outer_cache;
 };
 
 static inline void cache_wait_way(void __iomem *reg, unsigned long mask)
@@ -376,6 +376,7 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
 		writel_relaxed(1, l2x0_base + L2X0_CTRL);
 	}
 
+#ifndef CONFIG_OF
 	outer_cache.inv_range = l2x0_inv_range;
 	outer_cache.clean_range = l2x0_clean_range;
 	outer_cache.flush_range = l2x0_flush_range;
@@ -383,6 +384,7 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
 	outer_cache.flush_all = l2x0_flush_all;
 	outer_cache.inv_all = l2x0_inv_all;
 	outer_cache.disable = l2x0_disable;
+#endif
 
 	printk(KERN_INFO "%s cache controller enabled\n", type);
 	printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x, Cache size: %d B\n",
@@ -533,15 +535,34 @@ static void pl310_resume(void)
 }
 
 static const struct l2x0_of_data pl310_data = {
-	pl310_of_setup,
-	pl310_save,
-	pl310_resume,
+	.setup = pl310_of_setup,
+	.save  = pl310_save,
+	.outer_cache = {
+		.resume      = pl310_resume,
+		.inv_range   = l2x0_inv_range,
+		.clean_range = l2x0_clean_range,
+		.flush_range = l2x0_flush_range,
+		.sync        = l2x0_cache_sync,
+		.flush_all   = l2x0_flush_all,
+		.inv_all     = l2x0_inv_all,
+		.disable     = l2x0_disable,
+		.set_debug   = pl310_set_debug,
+	},
 };
 
 static const struct l2x0_of_data l2x0_data = {
-	l2x0_of_setup,
-	NULL,
-	l2x0_resume,
+	.setup = l2x0_of_setup,
+	.save  = NULL,
+	.outer_cache = {
+		.resume      = l2x0_resume,
+		.inv_range   = l2x0_inv_range,
+		.clean_range = l2x0_clean_range,
+		.flush_range = l2x0_flush_range,
+		.sync        = l2x0_cache_sync,
+		.flush_all   = l2x0_flush_all,
+		.inv_all     = l2x0_inv_all,
+		.disable     = l2x0_disable,
+	},
 };
 
 static const struct of_device_id l2x0_ids[] __initconst = {
@@ -583,7 +604,8 @@ int __init l2x0_of_init(u32 aux_val, u32 aux_mask)
 
 	l2x0_init(l2x0_base, aux_val, aux_mask);
 
-	outer_cache.resume = data->resume;
+	memcpy(&outer_cache, &data->outer_cache, sizeof(outer_cache));
+
 	return 0;
 }
 #endif
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 2/6 arm: cache-l2x0: add an optional register to save/restore

In reply to Gregory CLEMENT
Cc Barry Song <[email protected]>
Cc Rob Herring <[email protected]>
Cc Santosh Shilimkar <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Olof Johansson <[email protected]>
---
 arch/arm/include/asm/hardware/cache-l2x0.h |    1 +
 1 file changed, 1 insertion(+)
arch/arm/include/asm/hardware/cache-l2x0.h +1 -0
index c4c87bc..5f2c7b4 100644
@@ -126,6 +126,7 @@ struct l2x0_regs {
 	unsigned long filter_end;
 	unsigned long prefetch_ctrl;
 	unsigned long pwr_ctrl;
+	unsigned long ctrl;
 };
 
 extern struct l2x0_regs l2x0_saved_regs;
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v2 3/6 arm: cache-l2x0: add support for Aurora L2 cache ctrl

In reply to Gregory CLEMENT

Aurora Cache Controller was designed to be compatible with the ARM L2 Cache Controller. It comes with some difference or improvement such as:
- no cache id part number available through hardware (need to get it by the DT).
- always write through mode available.
- two flavors of the controller outer cache and system cache (meaning maintenance operations on L1 are broadcasted to the L2 and L2 performs the same operation).
- in outer cache mode, the cache maintenance operations are improved and can be done on a range inside a page and are not limited to a cache line.

Cc Barry Song <[email protected]>
Cc Will Deacon <[email protected]>
Cc Santosh Shilimkar <[email protected]>
Cc Rob Herring <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Olof Johansson <[email protected]>
---
 arch/arm/include/asm/hardware/cache-aurora-l2.h |   51 +++++
 arch/arm/mm/cache-l2x0.c                        |  260 ++++++++++++++++++++++-
 2 files changed, 305 insertions(+), 6 deletions(-)
 create mode 100644 arch/arm/include/asm/hardware/cache-aurora-l2.h
arch/arm/include/asm/hardware/cache-aurora-l2.h new file +51 -0
new file mode 100644
index 0000000..65dad20
@@ -0,0 +1,51 @@
+/*
+ * AURORA shared L2 cache controller support
+ *
+ * Copyright (C) 2012 Marvell
+ *
+ * Yehuda Yitschak <[email protected]>
+ * Gregory CLEMENT <[email protected]>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARM_HARDWARE_AURORA_L2_H
+#define __ASM_ARM_HARDWARE_AURORA_L2_H
+
+#define AURORA_SYNC_REG		    0x700
+#define AURORA_RANGE_BASE_ADDR_REG  0x720
+#define AURORA_FLUSH_PHY_ADDR_REG   0x7f0
+#define AURORA_INVAL_RANGE_REG	    0x774
+#define AURORA_CLEAN_RANGE_REG	    0x7b4
+#define AURORA_FLUSH_RANGE_REG	    0x7f4
+
+#define AURORA_ACR_REPLACEMENT_OFFSET	    27
+#define AURORA_ACR_REPLACEMENT_MASK	     \
+	(0x3 << AURORA_ACR_REPLACEMENT_OFFSET)
+#define AURORA_ACR_REPLACEMENT_TYPE_WAYRR    \
+	(0 << AURORA_ACR_REPLACEMENT_OFFSET)
+#define AURORA_ACR_REPLACEMENT_TYPE_LFSR     \
+	(1 << AURORA_ACR_REPLACEMENT_OFFSET)
+#define AURORA_ACR_REPLACEMENT_TYPE_SEMIPLRU \
+	(3 << AURORA_ACR_REPLACEMENT_OFFSET)
+
+#define AURORA_ACR_FORCE_WRITE_POLICY_OFFSET	0
+#define AURORA_ACR_FORCE_WRITE_POLICY_MASK	\
+	(0x3 << AURORA_ACR_FORCE_WRITE_POLICY_OFFSET)
+#define AURORA_ACR_FORCE_WRITE_POLICY_DIS	\
+	(0 << AURORA_ACR_FORCE_WRITE_POLICY_OFFSET)
+#define AURORA_ACR_FORCE_WRITE_BACK_POLICY	\
+	(1 << AURORA_ACR_FORCE_WRITE_POLICY_OFFSET)
+#define AURORA_ACR_FORCE_WRITE_THRO_POLICY	\
+	(2 << AURORA_ACR_FORCE_WRITE_POLICY_OFFSET)
+
+#define MAX_RANGE_SIZE		1024
+
+/* chose a number outside L2X0_CACHE_ID_PART_MASK to be sure to make
+ * the distinction between a number coming from hardware and a number
+ * coming from the device tree */
+#define AURORA_CACHE_ID	       0x100
+
+#endif /* __ASM_ARM_HARDWARE_AURORA_L2_H */
arch/arm/mm/cache-l2x0.c +254 -6

342 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v2 3/6 arm: cache-l2x0: add support for Aurora L2 cache ctrl

Quoted 29 lines · Gregory CLEMENT
arch/arm/mm/cache-l2x0.c +7 -0
index 3591940..684c188 100644
@@ -25,6 +25,7 @@
 
 #include <asm/cacheflush.h>
 #include <asm/hardware/cache-l2x0.h>
+#include <asm/hardware/cache-aurora-l2.h>
 
 #define CACHE_LINE_SIZE                32
 
@@ -33,6 +34,11 @@ static DEFINE_RAW_SPINLOCK(l2x0_lock);
 static u32 l2x0_way_mask;      /* Bitmask of active ways */
 static u32 l2x0_size;
 static unsigned long sync_reg_offset = L2X0_CACHE_SYNC;
+static int l2_wt_override;
+
+/* Aurora don't have the cache ID register available, so we have to
+ * pass it though the device tree */
+static u32  cache_id_part_number_from_dt;
 
 struct l2x0_regs l2x0_saved_regs;
 
@@ -275,6 +281,130 @@ static void l2x0_flush_range(unsigned long start, unsigned long end)
        cache_sync();
        raw_spin_unlock_irqrestore(&l2x0_lock, flags);
 }
+/*

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 294

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+ * Note that the end addresses passed to Linux primitives are
+ * noninclusive, while the hardware cache range operations use
+ * inclusive start and end addresses.
+ */
+static unsigned long calc_range_end(unsigned long start, unsigned long end)
+{
+       unsigned long range_end;
+
+       BUG_ON(start & (CACHE_LINE_SIZE - 1));
+       BUG_ON(end & (CACHE_LINE_SIZE - 1));

Seems a bit overkill to use BUG_ON here. Can you not just ALIGN the addresses instead?

Quoted 8 lines
arch/arm/mm/cache-l2x0.c +8 -0
+       /*
+        * Try to process all cache lines between 'start' and 'end'.
+        */
+       range_end = end;
+
+       /*
+        * Limit the number of cache lines processed at once,
+        * since cache range operations stall the CPU pipeline

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 313

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+        * until completion.
+        */
+       if (range_end > start + MAX_RANGE_SIZE)
+               range_end = start + MAX_RANGE_SIZE;
+
+       /*
+        * Cache range operations can't straddle a page boundary.
+        */
+       if (range_end > (start | (PAGE_SIZE - 1)) + 1)
+               range_end = (start | (PAGE_SIZE - 1)) + 1;

PAGE_ALIGN(start) instead of these bitwise operations?

Quoted 4 lines
arch/arm/mm/cache-l2x0.c +4 -0
+       return range_end;
+}
+
+static void aurora_pa_range(unsigned long start, unsigned long end,

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 328

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+                       unsigned long offset)
+{
+       unsigned long flags;
+
+       /*
+        * Make sure 'start' and 'end' reference the same page, as
+        * L2 is PIPT and range operations only do a TLB lookup on
+        * the start address.
+        */
+       BUG_ON((start ^ end) & ~(PAGE_SIZE - 1));

Eek. I think you should instead split this into multiple operations, one for each page contained in the range.

Quoted 7 lines
arch/arm/mm/cache-l2x0.c +7 -0
+       raw_spin_lock_irqsave(&l2x0_lock, flags);
+       writel(start, l2x0_base + AURORA_RANGE_BASE_ADDR_REG);
+       writel(end, l2x0_base + offset);
+       raw_spin_unlock_irqrestore(&l2x0_lock, flags);
+
+       cache_sync();
+}

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 345

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+
+static void aurora_inv_range(unsigned long start, unsigned long end)
+{
+       /*
+        * Clean and invalidate partial first cache line.
+        */
+       if (start & (CACHE_LINE_SIZE - 1)) {
+               writel((start & ~(CACHE_LINE_SIZE - 1)) & ~0x1f,
+                       l2x0_base + AURORA_FLUSH_PHY_ADDR_REG);
+               cache_sync();

writel implies a cache_sync if you have CONFIG_ARM_DMA_MEM_BUFFERABLE (there are other places in your code where this comment also applies). For v7, this is always the case.

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 345

Quoted 2 lines
arch/arm/mm/cache-l2x0.c +2 -0
+               start = (start | (CACHE_LINE_SIZE - 1)) + 1;
+       }

It's pretty strange for a cache to be able to operate only on a subset of a cacheline. Should you not just be rounding everything up to cache line size?

Quoted 11 lines
arch/arm/mm/cache-l2x0.c +11 -0
+       /*
+        * Clean and invalidate partial last cache line.
+        */
+       if (start < end && end & (CACHE_LINE_SIZE - 1)) {
+               writel((end & ~(CACHE_LINE_SIZE - 1)) & ~0x1f,
+                       l2x0_base + AURORA_FLUSH_PHY_ADDR_REG);
+               cache_sync();
+               end &= ~(CACHE_LINE_SIZE - 1);
+       }
+
+       /*

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 369

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+        * Invalidate all full cache lines between 'start' and 'end'.
+        */
+       while (start < end) {
+               unsigned long range_end = calc_range_end(start, end);
+               aurora_pa_range(start, range_end - CACHE_LINE_SIZE,
+                               AURORA_INVAL_RANGE_REG);
+               start = range_end;
+       }
+
+       dsb();

Why? (same for the other dsbs following writels/cache_syncs).

arch/arm/mm/cache-l2x0.c void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask) · line 452

Quoted 5 lines
arch/arm/mm/cache-l2x0.c +1 -0
@@ -312,18 +449,22 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
        u32 cache_id;
        u32 way_size = 0;
        int ways;
+       int way_size_shift = 3;

Can this be expressed in terms of a named constant? (something like L2X0_AUX_CTRL_WAY_SIZE_MASK).

Quoted 20 lines
arch/arm/mm/cache-l2x0.c +11 -1
        /* Determine the number of ways */
-       switch (cache_id & L2X0_CACHE_ID_PART_MASK) {
+       switch (cache_id) {
        case L2X0_CACHE_ID_PART_L310:
                if (aux & (1 << 16))
                        ways = 16;
@@ -340,6 +481,30 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
                ways = (aux >> 13) & 0xf;
                type = "L210";
                break;
+
+       case AURORA_CACHE_ID:
+               sync_reg_offset = AURORA_SYNC_REG;
+
+               switch ((aux >> 13) & 0xf) {
+               case 3:
+                       ways = 4;
+                       break;
+               case 7:
+                       ways = 8;

arch/arm/mm/cache-l2x0.c void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask) · line 503

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+                       break;
+               case 11:
+                       ways = 16;
+                       break;
+               case 15:
+                       ways = 32;
+                       break;
+               default:
+                       ways = 8;
+                       break;

Do the 3,7,11,15 correspond to something meaningful or can you do:

	ways = 2 << ((n + 1) >> 2);

instead?

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 714

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+static void aurora_resume(void)
+{
+       u32 u;
+
+       u = readl(l2x0_base + L2X0_CTRL);
+       if (!(u & 1)) {

We should probably add a L2X0_CTRL_EN define and use that (also update the enabling code to use it as well).

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 725

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+static void __init aurora_broadcast_l2_commands(void)
+{
+       __u32 u;
+       /* Enable Broadcasting of cache commands to L2*/
+       __asm__ __volatile__("mrc p15, 1, %0, c15, c2, 0" : "=r"(u));
+       u |= 0x100;             /* Set the FW bit */

Again, just add a AURORA_CTRL_FW define for this.

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+static void __init aurora_of_setup(const struct device_node *np,
+                               u32 *aux_val, u32 *aux_mask)
+{
+       u32 val = AURORA_ACR_REPLACEMENT_TYPE_SEMIPLRU;
+       u32 mask =  AURORA_ACR_REPLACEMENT_MASK;
+

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 745

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+       of_property_read_u32(np, "cache-id-part",
+                       &cache_id_part_number_from_dt);
+
+       /* Determine and save the write policy */
+       l2_wt_override = of_property_read_bool(np, "wt-override");
+
+       if (l2_wt_override) {
+               val |= AURORA_ACR_FORCE_WRITE_THRO_POLICY;
+               mask |= AURORA_ACR_FORCE_WRITE_POLICY_MASK;
+       }

smp_mb() after the assignment to l2_wt_override?

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 751

Quoted 5 lines
arch/arm/mm/cache-l2x0.c +5 -0
+       *aux_val &= ~mask;
+       *aux_val |= val;
+       *aux_mask &= ~mask;
+}
+

Will

#5 lore raw

PATCH v2 3/6 arm: cache-l2x0: add support for Aurora L2 cache ctrl

Hi Will,

thanks for you review

Quoted 34 lines · Gregory CLEMENT
Quoted 34 lines
arch/arm/mm/cache-l2x0.c +12 -0
index 3591940..684c188 100644
@@ -25,6 +25,7 @@
 
 #include <asm/cacheflush.h>
 #include <asm/hardware/cache-l2x0.h>
+#include <asm/hardware/cache-aurora-l2.h>
 
 #define CACHE_LINE_SIZE                32
 
@@ -33,6 +34,11 @@ static DEFINE_RAW_SPINLOCK(l2x0_lock);
 static u32 l2x0_way_mask;      /* Bitmask of active ways */
 static u32 l2x0_size;
 static unsigned long sync_reg_offset = L2X0_CACHE_SYNC;
+static int l2_wt_override;
+
+/* Aurora don't have the cache ID register available, so we have to
+ * pass it though the device tree */
+static u32  cache_id_part_number_from_dt;
 
 struct l2x0_regs l2x0_saved_regs;
 
@@ -275,6 +281,130 @@ static void l2x0_flush_range(unsigned long start, unsigned long end)
        cache_sync();
        raw_spin_unlock_irqrestore(&l2x0_lock, flags);
 }
+/*
+ * Note that the end addresses passed to Linux primitives are
+ * noninclusive, while the hardware cache range operations use
+ * inclusive start and end addresses.
+ */
+static unsigned long calc_range_end(unsigned long start, unsigned long end)
Quoted 8 lines

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 294

Quoted 5 lines
arch/arm/mm/cache-l2x0.c +5 -0
+{
+       unsigned long range_end;
+
+       BUG_ON(start & (CACHE_LINE_SIZE - 1));
+       BUG_ON(end & (CACHE_LINE_SIZE - 1));

Seems a bit overkill to use BUG_ON here. Can you not just ALIGN the addresses instead?

OK I can align them and issue a warning about it.

Quoted 13 lines
Quoted 13 lines
arch/arm/mm/cache-l2x0.c +12 -0
+       /*
+        * Try to process all cache lines between 'start' and 'end'.
+        */
+       range_end = end;
+
+       /*
+        * Limit the number of cache lines processed at once,
+        * since cache range operations stall the CPU pipeline
+        * until completion.
+        */
+       if (range_end > start + MAX_RANGE_SIZE)
+               range_end = start + MAX_RANGE_SIZE;
Quoted 8 lines

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 313

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+
+       /*
+        * Cache range operations can't straddle a page boundary.
+        */
+       if (range_end > (start | (PAGE_SIZE - 1)) + 1)
+               range_end = (start | (PAGE_SIZE - 1)) + 1;

PAGE_ALIGN(start) instead of these bitwise operations?

Yes it's better.

Quoted 10 lines
Quoted 10 lines
arch/arm/mm/cache-l2x0.c +9 -0
+       return range_end;
+}
+
+static void aurora_pa_range(unsigned long start, unsigned long end,
+                       unsigned long offset)
+{
+       unsigned long flags;
+
+       /*
Quoted 8 lines

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 328

Quoted 5 lines
arch/arm/mm/cache-l2x0.c +5 -0
+        * Make sure 'start' and 'end' reference the same page, as
+        * L2 is PIPT and range operations only do a TLB lookup on
+        * the start address.
+        */
+       BUG_ON((start ^ end) & ~(PAGE_SIZE - 1));

Eek. I think you should instead split this into multiple operations, one for each page contained in the range.

Actually this function is already called for each page. Before each call we use calc_range_end() which ensure that start address and end address are in the same page. Maybe I can just removed this test and move the comment on top of the function.

Quoted 14 lines
Quoted 14 lines
arch/arm/mm/cache-l2x0.c +13 -0
+       raw_spin_lock_irqsave(&l2x0_lock, flags);
+       writel(start, l2x0_base + AURORA_RANGE_BASE_ADDR_REG);
+       writel(end, l2x0_base + offset);
+       raw_spin_unlock_irqrestore(&l2x0_lock, flags);
+
+       cache_sync();
+}
+
+static void aurora_inv_range(unsigned long start, unsigned long end)
+{
+       /*
+        * Clean and invalidate partial first cache line.
+        */
Quoted 8 lines

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 345

Quoted 4 lines
arch/arm/mm/cache-l2x0.c +4 -0
+       if (start & (CACHE_LINE_SIZE - 1)) {
+               writel((start & ~(CACHE_LINE_SIZE - 1)) & ~0x1f,
+                       l2x0_base + AURORA_FLUSH_PHY_ADDR_REG);
+               cache_sync();

writel implies a cache_sync if you have CONFIG_ARM_DMA_MEM_BUFFERABLE (there are other places in your code where this comment also applies). For v7, this is always the case.

As the aurora cache controller is only use with v7 CPU, then we can removed them.

Quoted 6 lines

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 345

Quoted 3 lines
arch/arm/mm/cache-l2x0.c +2 -0
+               start = (start | (CACHE_LINE_SIZE - 1)) + 1;
+       }

It's pretty strange for a cache to be able to operate only on a subset of a cacheline. Should you not just be rounding everything up to cache line size?

We have CACHE_LINE_SIZE = 32 and we mask it with 0x1F. So indeed we can round everything to cache line size and make only one call.

Quoted 16 lines
Quoted 16 lines
arch/arm/mm/cache-l2x0.c +15 -0
+       /*
+        * Clean and invalidate partial last cache line.
+        */
+       if (start < end && end & (CACHE_LINE_SIZE - 1)) {
+               writel((end & ~(CACHE_LINE_SIZE - 1)) & ~0x1f,
+                       l2x0_base + AURORA_FLUSH_PHY_ADDR_REG);
+               cache_sync();
+               end &= ~(CACHE_LINE_SIZE - 1);
+       }
+
+       /*
+        * Invalidate all full cache lines between 'start' and 'end'.
+        */
+       while (start < end) {
+               unsigned long range_end = calc_range_end(start, end);
Quoted 8 lines

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 369

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+               aurora_pa_range(start, range_end - CACHE_LINE_SIZE,
+                               AURORA_INVAL_RANGE_REG);
+               start = range_end;
+       }
+
+       dsb();

Why? (same for the other dsbs following writels/cache_syncs).

I will ask if it is really needed.

Quoted 9 lines

arch/arm/mm/cache-l2x0.c void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask) · line 452

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +1 -0
@@ -312,18 +449,22 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
        u32 cache_id;
        u32 way_size = 0;
        int ways;
+       int way_size_shift = 3;

Can this be expressed in terms of a named constant? (something like L2X0_AUX_CTRL_WAY_SIZE_MASK).

Sure.

Quoted 34 lines
Quoted 21 lines
arch/arm/mm/cache-l2x0.c +11 -1
        /* Determine the number of ways */
-       switch (cache_id & L2X0_CACHE_ID_PART_MASK) {
+       switch (cache_id) {
        case L2X0_CACHE_ID_PART_L310:
                if (aux & (1 << 16))
                        ways = 16;
@@ -340,6 +481,30 @@ void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask)
                ways = (aux >> 13) & 0xf;
                type = "L210";
                break;
+
+       case AURORA_CACHE_ID:
+               sync_reg_offset = AURORA_SYNC_REG;
+
+               switch ((aux >> 13) & 0xf) {
+               case 3:
+                       ways = 4;
+                       break;
+               case 7:
+                       ways = 8;

arch/arm/mm/cache-l2x0.c void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask) · line 503

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+                       break;
+               case 11:
+                       ways = 16;
+                       break;
+               case 15:
+                       ways = 32;
+                       break;
+               default:
+                       ways = 8;
+                       break;

Do the 3,7,11,15 correspond to something meaningful or can you do:

Quoted 3 lines
	ways = 2 << ((n + 1) >> 2);

instead?

Good, you found the logic behind this series! I will use it.

Quoted 11 lines

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 714

Quoted 7 lines
arch/arm/mm/cache-l2x0.c +6 -0
+static void aurora_resume(void)
+{
+       u32 u;
+
+       u = readl(l2x0_base + L2X0_CTRL);
+       if (!(u & 1)) {

We should probably add a L2X0_CTRL_EN define and use that (also update the enabling code to use it as well).

Should it be a separate patch or can I include it with this one?

Quoted 8 lines

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 725

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+static void __init aurora_broadcast_l2_commands(void)
+{
+       __u32 u;
+       /* Enable Broadcasting of cache commands to L2*/
+       __asm__ __volatile__("mrc p15, 1, %0, c15, c2, 0" : "=r"(u));
+       u |= 0x100;             /* Set the FW bit */

Again, just add a AURORA_CTRL_FW define for this.

OK

Quoted 11 lines
Quoted 11 lines
arch/arm/mm/cache-l2x0.c +10 -0
+static void __init aurora_of_setup(const struct device_node *np,
+                               u32 *aux_val, u32 *aux_mask)
+{
+       u32 val = AURORA_ACR_REPLACEMENT_TYPE_SEMIPLRU;
+       u32 mask =  AURORA_ACR_REPLACEMENT_MASK;
+
+       of_property_read_u32(np, "cache-id-part",
+                       &cache_id_part_number_from_dt);
+
+       /* Determine and save the write policy */
Quoted 8 lines

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 745

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+       l2_wt_override = of_property_read_bool(np, "wt-override");
+
+       if (l2_wt_override) {
+               val |= AURORA_ACR_FORCE_WRITE_THRO_POLICY;
+               mask |= AURORA_ACR_FORCE_WRITE_POLICY_MASK;
+       }

smp_mb() after the assignment to l2_wt_override?

Sorry I don't get your point, why do you think we need this?

Quoted 9 lines

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 751

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +5 -0
+       *aux_val &= ~mask;
+       *aux_val |= val;
+       *aux_mask &= ~mask;
+}
+

Will

Signature · 4 lines
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#6 lore raw

PATCH v2 3/6 arm: cache-l2x0: add support for Aurora L2 cache ctrl

Quoted 24 lines · Gregory CLEMENT
Quoted 15 lines
Quoted 15 lines
arch/arm/mm/cache-l2x0.c +15 -0
+       /*
+        * Clean and invalidate partial last cache line.
+        */
+       if (start < end && end & (CACHE_LINE_SIZE - 1)) {
+               writel((end & ~(CACHE_LINE_SIZE - 1)) & ~0x1f,
+                       l2x0_base + AURORA_FLUSH_PHY_ADDR_REG);
+               cache_sync();
+               end &= ~(CACHE_LINE_SIZE - 1);
+       }
+
+       /*
+        * Invalidate all full cache lines between 'start' and 'end'.
+        */
+       while (start < end) {
+               unsigned long range_end = calc_range_end(start, end);
Quoted 8 lines

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 369

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+               aurora_pa_range(start, range_end - CACHE_LINE_SIZE,
+                               AURORA_INVAL_RANGE_REG);
+               start = range_end;
+       }
+
+       dsb();

Why? (same for the other dsbs following writels/cache_syncs).

Quoted 1 line

I will ask if it is really needed.

I just think you'll get the dsb() via aurora_pa_range, so you shouldn't need the extra one after the loop.

Quoted 11 lines
Quoted 10 lines

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 714

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+static void aurora_resume(void)
+{
+       u32 u;
+
+       u = readl(l2x0_base + L2X0_CTRL);
+       if (!(u & 1)) {

We should probably add a L2X0_CTRL_EN define and use that (also update the enabling code to use it as well).

Quoted 1 line

Should it be a separate patch or can I include it with this one?

I think you can just include it here (it's trivial to implement).

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+static void __init aurora_of_setup(const struct device_node *np,
+                               u32 *aux_val, u32 *aux_mask)
+{
+       u32 val = AURORA_ACR_REPLACEMENT_TYPE_SEMIPLRU;
+       u32 mask =  AURORA_ACR_REPLACEMENT_MASK;
+
+       of_property_read_u32(np, "cache-id-part",
+                       &cache_id_part_number_from_dt);
+
+       /* Determine and save the write policy */
Quoted 8 lines

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 745

Quoted 6 lines
arch/arm/mm/cache-l2x0.c +6 -0
+       l2_wt_override = of_property_read_bool(np, "wt-override");
+
+       if (l2_wt_override) {
+               val |= AURORA_ACR_FORCE_WRITE_THRO_POLICY;
+               mask |= AURORA_ACR_FORCE_WRITE_POLICY_MASK;
+       }

smp_mb() after the assignment to l2_wt_override?

Quoted 1 line

Sorry I don't get your point, why do you think we need this?

In case you get an outer_cache operation from a different core before the assignment to l2_wt_override has become visible, in which case you might accidentally skip the operation (e.g. if it's clean). This may well be overkill, since we probably have the same problem for stuff like the base address already.

Will

#7 lore raw

PATCH v2 3/6 arm: cache-l2x0: add support for Aurora L2 cache ctrl

Quoted 25 lines · Will Deacon
Quoted 24 lines · Gregory CLEMENT
Quoted 23 lines
Quoted 11 lines
arch/arm/mm/cache-l2x0.c +11 -0
+       /*
+        * Clean and invalidate partial last cache line.
+        */
+       if (start < end && end & (CACHE_LINE_SIZE - 1)) {
+               writel((end & ~(CACHE_LINE_SIZE - 1)) & ~0x1f,
+                       l2x0_base + AURORA_FLUSH_PHY_ADDR_REG);
+               cache_sync();
+               end &= ~(CACHE_LINE_SIZE - 1);
+       }
+
+       /*

arch/arm/mm/cache-l2x0.c static void l2x0_flush_range(unsigned long start, unsigned long end) · line 369

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+        * Invalidate all full cache lines between 'start' and 'end'.
+        */
+       while (start < end) {
+               unsigned long range_end = calc_range_end(start, end);
+               aurora_pa_range(start, range_end - CACHE_LINE_SIZE,
+                               AURORA_INVAL_RANGE_REG);
+               start = range_end;
+       }
+
+       dsb();

Why? (same for the other dsbs following writels/cache_syncs).

Quoted 4 lines
Quoted 1 line

I will ask if it is really needed.

I just think you'll get the dsb() via aurora_pa_range, so you shouldn't need the extra one after the loop.

Well actually we get a cache_sync() and not a dsb from aurora_pa_range. But I've just received the confirmation that the cache_sync is enough, so I will remove the dsb.

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 714

Quoted 7 lines
arch/arm/mm/cache-l2x0.c +6 -0
+static void aurora_resume(void)
+{
+       u32 u;
+
+       u = readl(l2x0_base + L2X0_CTRL);
+       if (!(u & 1)) {

We should probably add a L2X0_CTRL_EN define and use that (also update the enabling code to use it as well).

Quoted 3 lines
Quoted 1 line

Should it be a separate patch or can I include it with this one?

I think you can just include it here (it's trivial to implement).

OK (it's already done).

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 7 lines
arch/arm/mm/cache-l2x0.c +6 -0
+static void __init aurora_of_setup(const struct device_node *np,
+                               u32 *aux_val, u32 *aux_mask)
+{
+       u32 val = AURORA_ACR_REPLACEMENT_TYPE_SEMIPLRU;
+       u32 mask =  AURORA_ACR_REPLACEMENT_MASK;
+

arch/arm/mm/cache-l2x0.c static void pl310_resume(void) · line 745

Quoted 10 lines
arch/arm/mm/cache-l2x0.c +10 -0
+       of_property_read_u32(np, "cache-id-part",
+                       &cache_id_part_number_from_dt);
+
+       /* Determine and save the write policy */
+       l2_wt_override = of_property_read_bool(np, "wt-override");
+
+       if (l2_wt_override) {
+               val |= AURORA_ACR_FORCE_WRITE_THRO_POLICY;
+               mask |= AURORA_ACR_FORCE_WRITE_POLICY_MASK;
+       }

smp_mb() after the assignment to l2_wt_override?

Quoted 7 lines
Quoted 1 line

Sorry I don't get your point, why do you think we need this?

In case you get an outer_cache operation from a different core before the assignment to l2_wt_override has become visible, in which case you might accidentally skip the operation (e.g. if it's clean). This may well be overkill, since we probably have the same problem for stuff like the base address already.

But aurora_of_setup is called during the init, and this init is called before any smp initializations: when this function is called only one core is running. So there is no need to worry about it.

Quoted 3 lines

Will

Signature · 4 lines
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#8 lore raw

PATCH v2 4/6 arm: mvebu: add L2 cache support

In reply to Gregory CLEMENT
Cc Jason Cooper <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Olof Johansson <[email protected]>
---
 arch/arm/mach-mvebu/Kconfig             |    1 +
 arch/arm/mach-mvebu/irq-armada-370-xp.c |    4 ++++
 2 files changed, 5 insertions(+)
arch/arm/mach-mvebu/Kconfig +1 -0
index caa2c5e..e20c5e9 100644
@@ -6,6 +6,7 @@ config MACH_ARMADA_370_XP
 	bool "Marvell Armada 370 and Aramada XP boards"
 	select ARMADA_370_XP_TIMER
 	select CPU_V7
+	select CACHE_L2X0
 	help
 
 	  Say 'Y' here if you want your kernel to support boards based on
arch/arm/mach-mvebu/irq-armada-370-xp.c +4 -0
index 5f5f939..570be84 100644
@@ -24,6 +24,7 @@
 #include <linux/irqdomain.h>
 #include <asm/mach/arch.h>
 #include <asm/exception.h>
+#include <asm/hardware/cache-l2x0.h>
 
 /* Interrupt Controller Registers Map */
 #define ARMADA_370_XP_INT_SET_MASK_OFFS		(0x48)
@@ -130,4 +131,7 @@ static const struct of_device_id mpic_of_match[] __initconst = {
 void __init armada_370_xp_init_irq(void)
 {
 	of_irq_init(mpic_of_match);
+#ifdef CONFIG_CACHE_L2X0
+	l2x0_of_init(0, ~0UL);
+#endif
 }
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v2 5/6 arm: mvebu: add Aurora L2 Cache Controller to the DT

In reply to Gregory CLEMENT
Cc Jason Cooper <[email protected]>
Cc Andrew Lunn <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Olof Johansson <[email protected]>
---
 arch/arm/boot/dts/armada-370.dtsi |    6 ++++++
 arch/arm/boot/dts/armada-xp.dtsi  |    7 +++++++
 2 files changed, 13 insertions(+)
arch/arm/boot/dts/armada-370.dtsi +6 -0
index 3228ccc..fa60478 100644
@@ -20,6 +20,12 @@
 / {
 	model = "Marvell Armada 370 family SoC";
 	compatible = "marvell,armada370", "marvell,armada-370-xp";
+	L2: l2-cache {
+		compatible = "marvell,aurora-outer-cache";
+		reg = <0xd0008000 0x1000>;
+		cache-id-part = <0x100>;
+		wt-override;
+	};
 
 	mpic: interrupt-controller at d0020000 {
 	      reg = <0xd0020a00 0x1d0>,
arch/arm/boot/dts/armada-xp.dtsi +7 -0
index 71d6b5d..0186f62 100644
@@ -22,6 +22,13 @@
 	model = "Marvell Armada XP family SoC";
 	compatible = "marvell,armadaxp", "marvell,armada-370-xp";
 
+	L2: l2-cache {
+		compatible = "marvell,aurora-system-cache";
+		reg = <0xd0008000 0x1000>;
+		cache-id-part = <0x100>;
+		wt-override;
+	};
+
 	mpic: interrupt-controller at d0020000 {
 	      reg = <0xd0020a00 0x1d0>,
 		    <0xd0021870 0x58>;
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v2 6/6 arm: l2x0: add aurora related properties to OF binding

In reply to Gregory CLEMENT

Aurora is a L2 Cache Controller designed to be compatible with the L2x0 Cache Controller. L2X0 OF bindings are extended to support some specificity of Aurora (no cache id part number available through hardware, always write through mode, choice between outer cache and system cache).

Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Russell King <[email protected]>
Cc Barry Song <[email protected]>
Cc Will Deacon <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Olof Johansson <[email protected]>
---
 Documentation/devicetree/bindings/arm/l2cc.txt |    9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/arm/l2cc.txt +9 -0
index 7ca5216..76b0ee6 100644
@@ -10,6 +10,12 @@ Required properties:
 	"arm,pl310-cache"
 	"arm,l220-cache"
 	"arm,l210-cache"
+	"marvell,aurora-system-cache": Marvell Controller designed to be
+     compatible with the ARM one, with system cache mode (meaning
+     maintenance operations on L1 are broadcasted to the L2 and L2
+     performs the same operation).
+	"marvell,"aurora-outer-cache: Marvell Controller designed to be
+	 compatible with the ARM one with outer cache mode.
 - cache-unified : Specifies the cache is a unified cache.
 - cache-level : Should be set to 2 for a level 2 cache.
 - reg : Physical base address and size of cache controller's memory mapped
@@ -29,6 +35,9 @@ Optional properties:
   filter. Addresses in the filter window are directed to the M1 port. Other
   addresses will go to the M0 port.
 - interrupts : 1 combined interrupt.
+- cache-id-part: cache id part number to be used if it is not present
+  on hardware
+- wt-override: If present then L2 is forced to Write through mode
 
 Example:
 
Signature · 1 line
1.7.9.5