Skip to contentSkip to conversation

ARM: bcm281xx: Add L2 cache enable code

PATCH New Christian Daudt 4 participants 11 messages Mar 5, 2013 – Apr 11, 2013 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: bcm281xx: Add L2 cache enable code

- Adds a module to provide calls into secure monitor mode
- Uses this module to make secure monitor calls to enable L2 cache.

NOTE: This patch applies on top of the yet-unmerged 28x11 timer patch:
https://patchwork.kernel.org/patch/2186561/

Documentation/devicetree/bindings/misc/smc.txt new file +14 -0
new file mode 100644
index 0000000..cd8c729
@@ -0,0 +1,14 @@
+Broadcom Secure Monitor Bounce buffer
+-----------------------------------------------------
+This binding defines the location of the bounce buffer
+used for non-secure to secure communications.
+
+Required properties:
+- compatible : "bcm,kona-smc"
+- reg : Location and size of bounce buffer
+
+Example:
+	smc at 0x3404c000 {
+		compatible = "bcm,kona-smc";
+		reg = <0x3404c000 0x400>; //1 KiB in SRAM
+	};
arch/arm/boot/dts/bcm11351.dtsi +5 -0
index 8f71f40..d057d27 100644
@@ -55,4 +55,9 @@
 		clock-frequency = <32768>;
 	};
 
+	smc at 0x3404c000 {
+		compatible = "bcm,kona-smc";
+		reg = <0x3404c000 0x400>; //1 KiB in SRAM
+	};
+
 };
arch/arm/mach-bcm/Makefile +3 -1
index bbf4122..6adb6aec 100644
@@ -10,4 +10,6 @@
 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 
-obj-$(CONFIG_ARCH_BCM) := board_bcm.o
+obj-$(CONFIG_ARCH_BCM)		:= board_bcm.o bcm_kona_smc.o bcm_kona_smc_asm.o
+plus_sec := $(call as-instr,.arch_extension sec,+sec)
+AFLAGS_bcm_kona_smc_asm.o	:=-Wa,-march=armv7-a$(plus_sec)
arch/arm/mach-bcm/bcm_kona_smc.c new file +118 -0

118 lines not on this page · raw message

arch/arm/mach-bcm/bcm_kona_smc.h new file +80 -0

80 lines not on this page · raw message

arch/arm/mach-bcm/bcm_kona_smc_asm.S new file +41 -0

41 lines not on this page · raw message

arch/arm/mach-bcm/board_bcm.c +33 -1
index 2595935..1edd82e 100644
@@ -16,12 +16,44 @@
 #include <linux/device.h>
 #include <linux/platform_device.h>
 #include <linux/irqchip.h>
+#include <asm/hardware/cache-l2x0.h>
 #include <linux/clocksource.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/time.h>
 
 
+#include "bcm_kona_smc.h"
+
+#ifdef CONFIG_CACHE_L2X0
+static int __init kona_l2_cache_init(void)
+{
+	/*
+	 * Currently there is no SSAPI for setting the L2 cache aux register,
+	 * so the default value (0x1e050000) applies.
+	 */
+	bcm_kona_smc(SSAPI_ENABLE_L2_CACHE, 0, 0, 0, 0);
+
+	/*
+	 * The aux_val and aux_mask have no effect since L2 cache is already
+	 * enabled.  Pass 0s for aux_val and 1s for aux_mask for default value.
+	 */
+	l2x0_of_init(0, ~0);
+
+	return 0;
+}
+#endif /* CONFIG_CACHE_L2X0 */
+
+static void __init init_irq(void)
+{
+	irqchip_init();
+	bcm_kona_smc_init();
+
+#ifdef CONFIG_CACHE_L2X0
+	kona_l2_cache_init();
+#endif /* CONFIG_CACHE_L2X0 */
+}
+
 static void __init board_init(void)
 {
 	of_platform_populate(NULL, of_default_bus_match_table, NULL,
@@ -31,7 +63,7 @@ static void __init board_init(void)
 static const char * const bcm11351_dt_compat[] = { "bcm,bcm11351", NULL, };
 
 DT_MACHINE_START(BCM11351_DT, "Broadcom Application Processor")
-	.init_irq = irqchip_init,
+	.init_irq = init_irq,
 	.init_time = clocksource_of_init,
 	.init_machine = board_init,
 	.dt_compat = bcm11351_dt_compat,
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 ARM: bcm281xx: Add L2 cache enable code

Quoted 10 lines · Christian Daudt
Documentation/devicetree/bindings/misc/smc.txt new file +4 -0
new file mode 100644
index 0000000..cd8c729
@@ -0,0 +1,14 @@
+Broadcom Secure Monitor Bounce buffer
+-----------------------------------------------------
+This binding defines the location of the bounce buffer
+used for non-secure to secure communications.

Documentation/devicetree/bindings/misc/smc.txt line 14

Quoted 10 lines
Documentation/devicetree/bindings/misc/smc.txt new file +10 -0
+
+Required properties:
+- compatible : "bcm,kona-smc"
+- reg : Location and size of bounce buffer
+
+Example:
+	smc at 0x3404c000 {
+		compatible = "bcm,kona-smc";
+		reg = <0x3404c000 0x400>; //1 KiB in SRAM
+	};

For other firmware interfaces like this, we tend to list the specific commands that the firmware understands. If you think there might be different versions to consider, you might want to model this like

Documentation/devicetree/bindings/arm/psci.txt

arch/arm/mach-bcm/bcm_kona_smc_asm.S line 24

Quoted 13 lines
arch/arm/mach-bcm/bcm_kona_smc_asm.S new file +8 -0
new file mode 100644
index 0000000..a160848
+/*
+ * int bcm_kona_smc_asm(u32 service_id, u32 buffer_addr)
+ */
+
+ENTRY(bcm_kona_smc_asm)
+	stmfd	sp!, {r4-r12, lr}
+	mov	r4, r0		@ service_id
+	mov	r5, #3		@ Keep IRQ and FIQ off in SM

Why not just use an inline assembly?

arch/arm/mach-bcm/bcm_kona_smc_asm.S

Quoted 8 lines
arch/arm/mach-bcm/bcm_kona_smc_asm.S new file +8 -0
+#ifdef CONFIG_CACHE_L2X0
+static int __init kona_l2_cache_init(void)
+{
+	/*
+	 * Currently there is no SSAPI for setting the L2 cache aux register,
+	 * so the default value (0x1e050000) applies.
+	 */
+	bcm_kona_smc(SSAPI_ENABLE_L2_CACHE, 0, 0, 0, 0);

This can be written in a nicer way as

static int __init kona_l2_cache_init(void)

{
	if (!IS_ENABLED(CONFIG_CACHE_L2X0))
		return 0;
	...
}

To remove the need for the #ifdef.

arch/arm/mach-bcm/bcm_kona_smc_asm.S

Quoted 9 lines
arch/arm/mach-bcm/bcm_kona_smc_asm.S new file +9 -0
+static void __init init_irq(void)
+{
+	irqchip_init();
+	bcm_kona_smc_init();
+
+#ifdef CONFIG_CACHE_L2X0
+	kona_l2_cache_init();
+#endif /* CONFIG_CACHE_L2X0 */
+}

Why are you calling bcm_kona_smc_init() and kona_l2_cache_init() from init_irq()?

It seems completely unrelated to interrupt handling.

Arnd

#10 lore raw

PATCH 1/1 ARM: bcm281xx: Add L2 cache enable code

In reply to Christian Daudt

Documentation/devicetree/bindings/misc/smc.txt line 12

Quoted 8 lines · Christian Daudt

- Adds a module to provide calls into secure monitor mode
- Uses this module to make secure monitor calls to enable L2 cache.

Documentation/devicetree/bindings/misc/smc.txt +3 -0
 
+Example:
+	smc at 0x3404c000 {
+		compatible = "bcm,kona-smc";

Both here in this example, and ...

arch/arm/boot/dts/bcm11351.dtsi line 59

Quoted 4 lines
arch/arm/boot/dts/bcm11351.dtsi +2 -0
 
+	smc at 0x3404c000 {
+		compatible = "bcm,kona-smc";

Here in the actual .dts file, you should include the specific ID of the SoC too, so that if there are Soc-specific bugs, the compatible property that's required to determine this is present from the start. In other words,

compatible = "bcm,bcm11351-smc", "bcm,kona-smc";

(which SoC ID you use in the example is arbitrary, but it may as well match the .dts file you're editing in the patch).

#2 lore raw

PATCH 1/1 ARM: bcm281xx: Add L2 cache enable code

In reply to Arnd Bergmann
Quoted 26 lines · Arnd Bergmann
Quoted 10 lines · Christian Daudt
Documentation/devicetree/bindings/misc/smc.txt new file +4 -0
new file mode 100644
index 0000000..cd8c729
@@ -0,0 +1,14 @@
+Broadcom Secure Monitor Bounce buffer
+-----------------------------------------------------
+This binding defines the location of the bounce buffer
+used for non-secure to secure communications.

Documentation/devicetree/bindings/misc/smc.txt line 14

Quoted 10 lines
Documentation/devicetree/bindings/misc/smc.txt new file +10 -0
+
+Required properties:
+- compatible : "bcm,kona-smc"
+- reg : Location and size of bounce buffer
+
+Example:
+	smc at 0x3404c000 {
+		compatible = "bcm,kona-smc";
+		reg = <0x3404c000 0x400>; //1 KiB in SRAM
+	};

For other firmware interfaces like this, we tend to list the specific commands that the firmware understands. If you think there might be different versions to consider, you might want to model this like

Quoted 1 line

Documentation/devicetree/bindings/arm/psci.txt

This interface is stable and in shipping products at this time, and so the api will remain constant.

Quoted 6 lines
Quoted 6 lines
arch/arm/mach-bcm/bcm_kona_smc_asm.S new file +1 -0
new file mode 100644
index 0000000..a160848
+/*
Quoted 8 lines

arch/arm/mach-bcm/bcm_kona_smc_asm.S line 24

Quoted 7 lines

+ * int bcm_kona_smc_asm(u32 service_id, u32 buffer_addr)
+ */

arch/arm/mach-bcm/bcm_kona_smc_asm.S new file +5 -0
+
+ENTRY(bcm_kona_smc_asm)
+	stmfd	sp!, {r4-r12, lr}
+	mov	r4, r0		@ service_id
+	mov	r5, #3		@ Keep IRQ and FIQ off in SM

Why not just use an inline assembly?

We ran into problems with some gcc versions messing up the "arch_extension sec" when passing it to the assembler, so we broke it out to its own .S file following the example of omap and highbank. I suspect that they did it for the same reason.

Quoted 11 lines

arch/arm/mach-bcm/bcm_kona_smc_asm.S

Quoted 9 lines
arch/arm/mach-bcm/bcm_kona_smc_asm.S new file +8 -0
+#ifdef CONFIG_CACHE_L2X0
+static int __init kona_l2_cache_init(void)
+{
+	/*
+	 * Currently there is no SSAPI for setting the L2 cache aux register,
+	 * so the default value (0x1e050000) applies.
+	 */
+	bcm_kona_smc(SSAPI_ENABLE_L2_CACHE, 0, 0, 0, 0);

This can be written in a nicer way as

Quoted 8 lines

static int __init kona_l2_cache_init(void)

{
	if (!IS_ENABLED(CONFIG_CACHE_L2X0))
		return 0;
	...
}

To remove the need for the #ifdef.

ok. done.

Quoted 11 lines

arch/arm/mach-bcm/bcm_kona_smc_asm.S

Quoted 9 lines
arch/arm/mach-bcm/bcm_kona_smc_asm.S new file +9 -0
+static void __init init_irq(void)
+{
+	irqchip_init();
+	bcm_kona_smc_init();
+
+#ifdef CONFIG_CACHE_L2X0
+	kona_l2_cache_init();
+#endif /* CONFIG_CACHE_L2X0 */
+}

Why are you calling bcm_kona_smc_init() and kona_l2_cache_init() from init_irq()?

Quoted 2 lines

It seems completely unrelated to interrupt handling.

It was originally in init_machine section but I was told that that was too late and init_irq would be better, and I saw that highbank also has it in init_irq. I agree that it is unrelated to irq - is there a better place to put this in ?

thanks,
csd

#11 lore raw

PATCH 1/1 ARM: bcm281xx: Add L2 cache enable code

In reply to Stephen Warren
Quoted 16 lines · Stephen Warren

Documentation/devicetree/bindings/misc/smc.txt line 12

Quoted 6 lines · Christian Daudt

- Adds a module to provide calls into secure monitor mode
- Uses this module to make secure monitor calls to enable L2 cache.

Documentation/devicetree/bindings/misc/smc.txt +3 -0
+Example:
+	smc at 0x3404c000 {
+		compatible = "bcm,kona-smc";

Both here in this example, and ...

arch/arm/boot/dts/bcm11351.dtsi

Quoted 3 lines
arch/arm/boot/dts/bcm11351.dtsi +2 -0
+	smc at 0x3404c000 {
+		compatible = "bcm,kona-smc";

Here in the actual .dts file, you should include the specific ID of the SoC too, so that if there are Soc-specific bugs, the compatible property that's required to determine this is present from the start. In other words,

Quoted 5 lines

compatible = "bcm,bcm11351-smc", "bcm,kona-smc";

(which SoC ID you use in the example is arbitrary, but it may as well match the .dts file you're editing in the patch).

ok. done.

thanks,
csd

#3 lore raw

PATCH 1/1 ARM: bcm281xx: Add L2 cache enable code

In reply to Christian Daudt
Quoted 9 lines · Christian Daudt
Quoted 6 lines · Arnd Bergmann

On Tuesday 05 March 2013, Christian Daudt wrote:
For other firmware interfaces like this, we tend to list the specific commands that the firmware understands. If you think there might be different versions to consider, you might want to model this like

Documentation/devicetree/bindings/arm/psci.txt

This interface is stable and in shipping products at this time, and so the api will remain constant.

But what about future products? Wouldn't they be able to extend the current interface in a compatible way?

Quoted 11 lines
Quoted 11 lines

arch/arm/mach-bcm/board_bcm.c line 55

Quoted 9 lines
arch/arm/mach-bcm/board_bcm.c +9 -0
+static void __init init_irq(void)
+{
+	irqchip_init();
+	bcm_kona_smc_init();
+
+#ifdef CONFIG_CACHE_L2X0
+	kona_l2_cache_init();
+#endif /* CONFIG_CACHE_L2X0 */
+}

Why are you calling bcm_kona_smc_init() and kona_l2_cache_init() from init_irq()?

Quoted 6 lines
Quoted 2 lines

It seems completely unrelated to interrupt handling.

It was originally in init_machine section but I was told that that was too late and init_irq would be better, and I saw that highbank also has it in init_irq. I agree that it is unrelated to irq - is there a better place to put this in ?

IMHO the later the better. Do you know what issues were caused by having it in init_machine?

Arnd

#5 lore raw

PATCH 1/1 ARM: bcm281xx: Add L2 cache enable code

In reply to a message not in the archive
Quoted 11 lines · Christian Daudt
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Christian Daudt
Quoted 6 lines · Arnd Bergmann

On Tuesday 05 March 2013, Christian Daudt wrote:
For other firmware interfaces like this, we tend to list the specific commands that the firmware understands. If you think there might be different versions to consider, you might want to model this like

Documentation/devicetree/bindings/arm/psci.txt

This interface is stable and in shipping products at this time, and so the api will remain constant.

Quoted 8 lines
Quoted 2 lines

But what about future products? Wouldn't they be able to extend the current interface in a compatible way?

It is highly unlikely that for this family we will be extending that API but even if that is done, it can just added #defines in the C header. Is DT seen as the way to define Software APIs going forward ? It should be trivial to implement this, I'm just trying to understand where the line is drawn between describing APIs in DT vs C headers going forward.

We tend to do it in cases where the software has no other way to find out what interfaces are supported. I guess if it becomes necessary, we can use a different "compatible" value for an extended future version of this, but that scales only to so many different variants.

Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

It was originally in init_machine section but I was told that that was too late and init_irq would be better, and I saw that highbank also has it in init_irq. I agree that it is unrelated to irq - is there a better place to put this in ?

IMHO the later the better. Do you know what issues were caused by having it in init_machine?

This is some feedback I got a while back:
"From kernel 3.4 on-wards i think ( if i remember correctly) cache sync might be called before your board_init function and you might have to do this in init_irq. "

Quoted 8 lines

I just looked through where l2x0_of_init is currently called and here's the list:
early_initcall (exynos4, omap2, sirf, ux500)
init_irq (highbank, imx6q)
init_machine (socfpga, v2m_dt_init)

so seems to be everywhere :) So I can move it back to init_machineif that's where itshould be.

Hmm, let's try to solve this another time, I don't think there is an easy answer. Maybe we really need a common entry point for the cache controller setup, or move it completely out of platform specific code for the case where it can be probed from DT.

Thanks for doing the research!

Arnd

#6 lore raw

PATCH 1/1 ARM: bcm281xx: Add L2 cache enable code

Quoted 17 lines · Arnd Bergmann
Quoted 17 lines
Quoted 6 lines
Quoted 4 lines

It was originally in init_machine section but I was told that that was too late and init_irq would be better, and I saw that highbank also has it in init_irq. I agree that it is unrelated to irq - is there a better place to put this in ?

IMHO the later the better. Do you know what issues were caused by having it in init_machine?

This is some feedback I got a while back:
"From kernel 3.4 on-wards i think ( if i remember correctly) cache sync might be called before your board_init function and you might have to do this in init_irq. "

I just looked through where l2x0_of_init is currently called and here's the list:
early_initcall (exynos4, omap2, sirf, ux500)
init_irq (highbank, imx6q)
init_machine (socfpga, v2m_dt_init)

Quoted 9 lines
Quoted 2 lines

so seems to be everywhere :) So I can move it back to init_machineif that's where itshould be.

Hmm, let's try to solve this another time, I don't think there is an easy answer. Maybe we really need a common entry point for the cache controller setup, or move it completely out of platform specific code for the case where it can be probed from DT.

Thanks for doing the research!

So for the time being should it stay in init_irq or init_machine ?

Thanks,
csd

#7 lore raw

[GIT PULL] ARM: bcm281xx firmware tags

In reply to Arnd Bergmann

Hi Arnd, Olof,
Please pull the branch below - it contains the BCM281xx l2 cache
enabling code.

Thanks,
csd

The following changes since commit 07961ac7c0ee8b546658717034fe692fd12eefa9:

Linux 3.9-rc5 (2013-03-31 15:12:43 -0700)

are available in the git repository at:

git://github.com/broadcom/bcm11351.git tags/fw-for-3.10

for you to fetch changes up to 7f6c62e2695bcb1547afdeb4ad3bcdf8c610be2c:

ARM: bcm281xx: Add DT support for SMC handler (2013-04-09 09:21:59 -0700)

----------------------------------------------------------------
l2cache driver for bcm281xx SoC

----------------------------------------------------------------
Christian Daudt (2):
ARM: bcm281xx: Add L2 cache enable code
ARM: bcm281xx: Add DT support for SMC handler

  Documentation/devicetree/bindings/misc/smc.txt |   14 +++++++++++
  arch/arm/boot/dts/bcm11351.dtsi                |    5 ++++
  arch/arm/mach-bcm/Makefile                     |    4 +++-
  arch/arm/mach-bcm/bcm_kona_smc.c               |  118 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  arch/arm/mach-bcm/bcm_kona_smc.h               |   80 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  arch/arm/mach-bcm/bcm_kona_smc_asm.S           |   41 
++++++++++++++++++++++++++++++++
  arch/arm/mach-bcm/board_bcm.c                  |   23 ++++++++++++++++++
  7 files changed, 284 insertions(+), 1 deletion(-)

create mode 100644 Documentation/devicetree/bindings/misc/smc.txt create mode 100644 arch/arm/mach-bcm/bcm_kona_smc.c create mode 100644 arch/arm/mach-bcm/bcm_kona_smc.h create mode 100644 arch/arm/mach-bcm/bcm_kona_smc_asm.S

#8 lore raw

[GIT PULL] ARM: bcm281xx firmware tags

Quoted 8 lines · Christian Daudt

Hi Arnd, Olof,
Please pull the branch below - it contains the BCM281xx l2 cache
enabling code.

Thanks,
csd

Quoted 7 lines

The following changes since commit 07961ac7c0ee8b546658717034fe692fd12eefa9:

Linux 3.9-rc5 (2013-03-31 15:12:43 -0700)

are available in the git repository at:

git://github.com/broadcom/bcm11351.git tags/fw-for-3.10

Thanks, pulled into next/soc (local branch name bcm/smc-l2)

-Olof

#9 lore raw

[GIT PULL] ARM: bcm281xx firmware tags

Quoted 11 lines · Olof Johansson
Quoted 10 lines · Christian Daudt

Hi Arnd, Olof,
Please pull the branch below - it contains the BCM281xx l2 cache
enabling code.

Thanks,
csd

The following changes since commit 07961ac7c0ee8b546658717034fe692fd12eefa9:

Quoted 7 lines
Quoted 5 lines

Linux 3.9-rc5 (2013-03-31 15:12:43 -0700)

are available in the git repository at:

git://github.com/broadcom/bcm11351.git tags/fw-for-3.10

Thanks, pulled into next/soc (local branch name bcm/smc-l2)

Based on later thread about the exynos smc ops, I moved this branch over to next/firmware instead.

-Olof