1 From 707ab07695ea8953a5bb56512e7bb38ca79c5c38 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Thu, 19 Feb 2015 23:27:59 +0100
4 Subject: [PATCH V2] ARM: BCM5301X: Implement SMP support
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
11 V2: Change code after receiving Florian's comments:
13 2) Remove commented out ASM call
14 3) Fix coding style in ASM
15 4) Simplify finding OF node
17 Documentation/devicetree/bindings/arm/bcm4708.txt | 24 ++++
18 Documentation/devicetree/bindings/arm/cpus.txt | 1 +
19 arch/arm/boot/dts/bcm4708.dtsi | 13 ++
20 arch/arm/mach-bcm/Makefile | 3 +
21 arch/arm/mach-bcm/bcm5301x_headsmp.S | 45 ++++++
22 arch/arm/mach-bcm/bcm5301x_smp.c | 158 ++++++++++++++++++++++
23 6 files changed, 244 insertions(+)
24 create mode 100644 arch/arm/mach-bcm/bcm5301x_headsmp.S
25 create mode 100644 arch/arm/mach-bcm/bcm5301x_smp.c
27 diff --git a/Documentation/devicetree/bindings/arm/bcm4708.txt b/Documentation/devicetree/bindings/arm/bcm4708.txt
28 index 6b0f49f..3dd0e9d 100644
29 --- a/Documentation/devicetree/bindings/arm/bcm4708.txt
30 +++ b/Documentation/devicetree/bindings/arm/bcm4708.txt
31 @@ -6,3 +6,27 @@ Boards with the BCM4708 SoC shall have the following properties:
32 Required root node property:
34 compatible = "brcm,bcm4708";
36 +Optional sub-node properties:
38 +compatible = "mmio-sram" for SRAM access with IO memory region
39 + This is needed for SMP-capable SoCs which use part of
40 + SRAM for storing location of code to be executed by the
42 + SMP support requires another sub-node with compatible
43 + property "brcm,bcm4708-sysram".
48 + compatible = "mmio-sram";
49 + reg = <0xffff0000 0x10000>;
50 + #address-cells = <1>;
52 + ranges = <0 0xffff0000 0x10000>;
55 + compatible = "brcm,bcm4708-sysram";
59 diff --git a/Documentation/devicetree/bindings/arm/cpus.txt b/Documentation/devicetree/bindings/arm/cpus.txt
60 index 6aa331d..3507ae3 100644
61 --- a/Documentation/devicetree/bindings/arm/cpus.txt
62 +++ b/Documentation/devicetree/bindings/arm/cpus.txt
63 @@ -188,6 +188,7 @@ nodes to be present and contain the properties described below.
69 "marvell,armada-375-smp"
70 "marvell,armada-380-smp"
71 diff --git a/arch/arm/boot/dts/bcm4708.dtsi b/arch/arm/boot/dts/bcm4708.dtsi
72 index 31141e8..c0af5cc 100644
73 --- a/arch/arm/boot/dts/bcm4708.dtsi
74 +++ b/arch/arm/boot/dts/bcm4708.dtsi
79 + enable-method = "brcm,bcm4708-smp";
88 + compatible = "mmio-sram";
89 + reg = <0xffff0000 0x10000>;
90 + #address-cells = <1>;
92 + ranges = <0 0xffff0000 0x10000>;
95 + compatible = "brcm,bcm4708-sysram";
100 diff --git a/arch/arm/mach-bcm/Makefile b/arch/arm/mach-bcm/Makefile
101 index 4c38674..ca12727 100644
102 --- a/arch/arm/mach-bcm/Makefile
103 +++ b/arch/arm/mach-bcm/Makefile
104 @@ -33,6 +33,9 @@ obj-$(CONFIG_ARCH_BCM2835) += board_bcm2835.o
107 obj-$(CONFIG_ARCH_BCM_5301X) += bcm_5301x.o
108 +ifeq ($(CONFIG_SMP),y)
109 +obj-$(CONFIG_ARCH_BCM_5301X) += bcm5301x_smp.o bcm5301x_headsmp.o
113 obj-$(CONFIG_ARCH_BCM_63XX) := bcm63xx.o
114 diff --git a/arch/arm/mach-bcm/bcm5301x_headsmp.S b/arch/arm/mach-bcm/bcm5301x_headsmp.S
116 index 0000000..9ca8d20
118 +++ b/arch/arm/mach-bcm/bcm5301x_headsmp.S
121 + * Broadcom BCM470X / BCM5301X ARM platform code.
123 + * Copyright (c) 2003 ARM Limited
124 + * All Rights Reserved
126 + * Licensed under the GNU/GPL. See COPYING for details.
128 +#include <linux/linkage.h>
131 + * BCM5301X specific entry point for secondary CPUs.
133 +ENTRY(bcm5301x_secondary_startup)
134 + mrc p15, 0, r0, c0, c0, 5
145 + * In case L1 cache has unpredictable contents at power-up
146 + * clean its contents without flushing.
148 + bl v7_invalidate_l1
151 + mcr p15, 0, r0, c7, c5, 0 /* Invalidate icache */
156 + * we've been released from the holding pen: secondary_stack
157 + * should now contain the SVC stack for this core
159 + b secondary_startup
160 +ENDPROC(bcm5301x_secondary_startup)
165 diff --git a/arch/arm/mach-bcm/bcm5301x_smp.c b/arch/arm/mach-bcm/bcm5301x_smp.c
167 index 0000000..45d7089
169 +++ b/arch/arm/mach-bcm/bcm5301x_smp.c
172 + * Broadcom BCM470X / BCM5301X ARM platform code.
174 + * Copyright (C) 2002 ARM Ltd.
175 + * Copyright (C) 2015 Rafał Miłecki <zajec5@gmail.com>
177 + * Licensed under the GNU/GPL. See COPYING for details.
180 +#include <asm/cacheflush.h>
181 +#include <asm/delay.h>
182 +#include <asm/smp_plat.h>
183 +#include <asm/smp_scu.h>
185 +#include <linux/clockchips.h>
186 +#include <linux/of.h>
187 +#include <linux/of_address.h>
189 +#define SOC_ROM_LUT_OFF 0x400
191 +extern void bcm5301x_secondary_startup(void);
193 +static void __cpuinit write_pen_release(int val)
197 + sync_cache_w(&pen_release);
200 +static DEFINE_SPINLOCK(boot_lock);
202 +static void __init bcm5301x_smp_secondary_set_entry(void (*entry_point)(void))
204 + void __iomem *sysram_base_addr = NULL;
205 + struct device_node *node;
207 + node = of_find_compatible_node(NULL, NULL, "brcm,bcm4708-sysram");
208 + if (!of_device_is_available(node))
211 + sysram_base_addr = of_iomap(node, 0);
212 + if (!sysram_base_addr) {
213 + pr_warn("Failed to map sysram\n");
217 + writel(virt_to_phys(entry_point), sysram_base_addr + SOC_ROM_LUT_OFF);
219 + dsb_sev(); /* Exit WFI */
220 + mb(); /* make sure write buffer is drained */
222 + iounmap(sysram_base_addr);
225 +static void __init bcm5301x_smp_prepare_cpus(unsigned int max_cpus)
227 + void __iomem *scu_base;
229 + if (!scu_a9_has_base()) {
230 + pr_warn("Unknown SCU base\n");
234 + scu_base = ioremap((phys_addr_t)scu_a9_get_base(), SZ_256);
236 + pr_err("Failed to remap SCU\n");
240 + /* Initialise the SCU */
241 + scu_enable(scu_base);
243 + /* Let CPUs know where to start */
244 + bcm5301x_smp_secondary_set_entry(bcm5301x_secondary_startup);
249 +static void __cpuinit bcm5301x_smp_secondary_init(unsigned int cpu)
251 + trace_hardirqs_off();
254 + * let the primary processor know we're out of the
255 + * pen, then head off into the C entry point
257 + write_pen_release(-1);
260 + * Synchronise with the boot thread.
262 + spin_lock(&boot_lock);
263 + spin_unlock(&boot_lock);
266 +static int __cpuinit bcm5301x_smp_boot_secondary(unsigned int cpu,
267 + struct task_struct *idle)
269 + unsigned long timeout;
272 + * set synchronisation state between this boot processor
273 + * and the secondary one
275 + spin_lock(&boot_lock);
278 + * The secondary processor is waiting to be released from
279 + * the holding pen - release it, then wait for it to flag
280 + * that it has been released by resetting pen_release.
282 + * Note that "pen_release" is the hardware CPU ID, whereas
283 + * "cpu" is Linux's internal ID.
285 + write_pen_release(cpu_logical_map(cpu));
287 + /* Send the secondary CPU SEV */
293 + * Send the secondary CPU a soft interrupt, thereby causing
294 + * the boot monitor to read the system wide flags register,
295 + * and branch to the address found there.
297 + arch_send_wakeup_ipi_mask(cpumask_of(cpu));
300 + * Timeout set on purpose in jiffies so that on slow processors
301 + * that must also have low HZ it will wait longer.
303 + timeout = jiffies + (HZ * 10);
304 + while (time_before(jiffies, timeout)) {
306 + if (pen_release == -1)
313 + * now the secondary core is starting up let it run its
314 + * calibrations, then wait for it to finish
316 + spin_unlock(&boot_lock);
318 + return pen_release != -1 ? -ENOSYS : 0;
321 +static struct smp_operations bcm5301x_smp_ops __initdata = {
322 + .smp_prepare_cpus = bcm5301x_smp_prepare_cpus,
323 + .smp_secondary_init = bcm5301x_smp_secondary_init,
324 + .smp_boot_secondary = bcm5301x_smp_boot_secondary,
327 +CPU_METHOD_OF_DECLARE(bcm5301x_smp, "brcm,bcm4708-smp",
328 + &bcm5301x_smp_ops);