131-ARM-BCM5301X-Implement-SMP-support.patch 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  9. ---
  10. V2: Change code after receiving Florian's comments:
  11. 1) Use "mmio-sram"
  12. 2) Remove commented out ASM call
  13. 3) Fix coding style in ASM
  14. 4) Simplify finding OF node
  15. ---
  16. Documentation/devicetree/bindings/arm/bcm4708.txt | 24 ++++
  17. Documentation/devicetree/bindings/arm/cpus.txt | 1 +
  18. arch/arm/boot/dts/bcm4708.dtsi | 13 ++
  19. arch/arm/mach-bcm/Makefile | 3 +
  20. arch/arm/mach-bcm/bcm5301x_headsmp.S | 45 ++++++
  21. arch/arm/mach-bcm/bcm5301x_smp.c | 158 ++++++++++++++++++++++
  22. 6 files changed, 244 insertions(+)
  23. create mode 100644 arch/arm/mach-bcm/bcm5301x_headsmp.S
  24. create mode 100644 arch/arm/mach-bcm/bcm5301x_smp.c
  25. --- a/Documentation/devicetree/bindings/arm/bcm4708.txt
  26. +++ b/Documentation/devicetree/bindings/arm/bcm4708.txt
  27. @@ -6,3 +6,27 @@ Boards with the BCM4708 SoC shall have t
  28. Required root node property:
  29. compatible = "brcm,bcm4708";
  30. +
  31. +Optional sub-node properties:
  32. +
  33. +compatible = "mmio-sram" for SRAM access with IO memory region
  34. + This is needed for SMP-capable SoCs which use part of
  35. + SRAM for storing location of code to be executed by the
  36. + extra cores.
  37. + SMP support requires another sub-node with compatible
  38. + property "brcm,bcm4708-sysram".
  39. +
  40. +Example:
  41. +
  42. + sysram@ffff0000 {
  43. + compatible = "mmio-sram";
  44. + reg = <0xffff0000 0x10000>;
  45. + #address-cells = <1>;
  46. + #size-cells = <1>;
  47. + ranges = <0 0xffff0000 0x10000>;
  48. +
  49. + smp-sysram@0 {
  50. + compatible = "brcm,bcm4708-sysram";
  51. + reg = <0x0 0x1000>;
  52. + };
  53. + };
  54. --- a/Documentation/devicetree/bindings/arm/cpus.txt
  55. +++ b/Documentation/devicetree/bindings/arm/cpus.txt
  56. @@ -188,6 +188,7 @@ nodes to be present and contain the prop
  57. can be one of:
  58. "allwinner,sun6i-a31"
  59. "arm,psci"
  60. + "brcm,bcm4708-smp"
  61. "brcm,brahma-b15"
  62. "marvell,armada-375-smp"
  63. "marvell,armada-380-smp"
  64. --- a/arch/arm/boot/dts/bcm4708.dtsi
  65. +++ b/arch/arm/boot/dts/bcm4708.dtsi
  66. @@ -15,6 +15,7 @@
  67. cpus {
  68. #address-cells = <1>;
  69. #size-cells = <0>;
  70. + enable-method = "brcm,bcm4708-smp";
  71. cpu@0 {
  72. device_type = "cpu";
  73. @@ -31,4 +32,16 @@
  74. };
  75. };
  76. + sysram@ffff0000 {
  77. + compatible = "mmio-sram";
  78. + reg = <0xffff0000 0x10000>;
  79. + #address-cells = <1>;
  80. + #size-cells = <1>;
  81. + ranges = <0 0xffff0000 0x10000>;
  82. +
  83. + smp-sysram@0 {
  84. + compatible = "brcm,bcm4708-sysram";
  85. + reg = <0x0 0x1000>;
  86. + };
  87. + };
  88. };
  89. --- a/arch/arm/mach-bcm/Makefile
  90. +++ b/arch/arm/mach-bcm/Makefile
  91. @@ -33,6 +33,9 @@ obj-$(CONFIG_ARCH_BCM2835) += board_bcm2
  92. # BCM5301X
  93. obj-$(CONFIG_ARCH_BCM_5301X) += bcm_5301x.o
  94. +ifeq ($(CONFIG_SMP),y)
  95. +obj-$(CONFIG_ARCH_BCM_5301X) += bcm5301x_smp.o bcm5301x_headsmp.o
  96. +endif
  97. # BCM63XXx
  98. obj-$(CONFIG_ARCH_BCM_63XX) := bcm63xx.o
  99. --- /dev/null
  100. +++ b/arch/arm/mach-bcm/bcm5301x_headsmp.S
  101. @@ -0,0 +1,45 @@
  102. +/*
  103. + * Broadcom BCM470X / BCM5301X ARM platform code.
  104. + *
  105. + * Copyright (c) 2003 ARM Limited
  106. + * All Rights Reserved
  107. + *
  108. + * Licensed under the GNU/GPL. See COPYING for details.
  109. + */
  110. +#include <linux/linkage.h>
  111. +
  112. +/*
  113. + * BCM5301X specific entry point for secondary CPUs.
  114. + */
  115. +ENTRY(bcm5301x_secondary_startup)
  116. + mrc p15, 0, r0, c0, c0, 5
  117. + and r0, r0, #15
  118. + adr r4, 1f
  119. + ldmia r4, {r5, r6}
  120. + sub r4, r4, r5
  121. + add r6, r6, r4
  122. +pen: ldr r7, [r6]
  123. + cmp r7, r0
  124. + bne pen
  125. +
  126. + /*
  127. + * In case L1 cache has unpredictable contents at power-up
  128. + * clean its contents without flushing.
  129. + */
  130. + bl v7_invalidate_l1
  131. +
  132. + mov r0, #0
  133. + mcr p15, 0, r0, c7, c5, 0 /* Invalidate icache */
  134. + dsb
  135. + isb
  136. +
  137. + /*
  138. + * we've been released from the holding pen: secondary_stack
  139. + * should now contain the SVC stack for this core
  140. + */
  141. + b secondary_startup
  142. +ENDPROC(bcm5301x_secondary_startup)
  143. +
  144. + .align 2
  145. +1: .long .
  146. + .long pen_release
  147. --- /dev/null
  148. +++ b/arch/arm/mach-bcm/bcm5301x_smp.c
  149. @@ -0,0 +1,158 @@
  150. +/*
  151. + * Broadcom BCM470X / BCM5301X ARM platform code.
  152. + *
  153. + * Copyright (C) 2002 ARM Ltd.
  154. + * Copyright (C) 2015 Rafał Miłecki <zajec5@gmail.com>
  155. + *
  156. + * Licensed under the GNU/GPL. See COPYING for details.
  157. + */
  158. +
  159. +#include <asm/cacheflush.h>
  160. +#include <asm/delay.h>
  161. +#include <asm/smp_plat.h>
  162. +#include <asm/smp_scu.h>
  163. +
  164. +#include <linux/clockchips.h>
  165. +#include <linux/of.h>
  166. +#include <linux/of_address.h>
  167. +
  168. +#define SOC_ROM_LUT_OFF 0x400
  169. +
  170. +extern void bcm5301x_secondary_startup(void);
  171. +
  172. +static void __cpuinit write_pen_release(int val)
  173. +{
  174. + pen_release = val;
  175. + smp_wmb();
  176. + sync_cache_w(&pen_release);
  177. +}
  178. +
  179. +static DEFINE_SPINLOCK(boot_lock);
  180. +
  181. +static void __init bcm5301x_smp_secondary_set_entry(void (*entry_point)(void))
  182. +{
  183. + void __iomem *sysram_base_addr = NULL;
  184. + struct device_node *node;
  185. +
  186. + node = of_find_compatible_node(NULL, NULL, "brcm,bcm4708-sysram");
  187. + if (!of_device_is_available(node))
  188. + return;
  189. +
  190. + sysram_base_addr = of_iomap(node, 0);
  191. + if (!sysram_base_addr) {
  192. + pr_warn("Failed to map sysram\n");
  193. + return;
  194. + }
  195. +
  196. + writel(virt_to_phys(entry_point), sysram_base_addr + SOC_ROM_LUT_OFF);
  197. +
  198. + dsb_sev(); /* Exit WFI */
  199. + mb(); /* make sure write buffer is drained */
  200. +
  201. + iounmap(sysram_base_addr);
  202. +}
  203. +
  204. +static void __init bcm5301x_smp_prepare_cpus(unsigned int max_cpus)
  205. +{
  206. + void __iomem *scu_base;
  207. +
  208. + if (!scu_a9_has_base()) {
  209. + pr_warn("Unknown SCU base\n");
  210. + return;
  211. + }
  212. +
  213. + scu_base = ioremap((phys_addr_t)scu_a9_get_base(), SZ_256);
  214. + if (!scu_base) {
  215. + pr_err("Failed to remap SCU\n");
  216. + return;
  217. + }
  218. +
  219. + /* Initialise the SCU */
  220. + scu_enable(scu_base);
  221. +
  222. + /* Let CPUs know where to start */
  223. + bcm5301x_smp_secondary_set_entry(bcm5301x_secondary_startup);
  224. +
  225. + iounmap(scu_base);
  226. +}
  227. +
  228. +static void __cpuinit bcm5301x_smp_secondary_init(unsigned int cpu)
  229. +{
  230. + trace_hardirqs_off();
  231. +
  232. + /*
  233. + * let the primary processor know we're out of the
  234. + * pen, then head off into the C entry point
  235. + */
  236. + write_pen_release(-1);
  237. +
  238. + /*
  239. + * Synchronise with the boot thread.
  240. + */
  241. + spin_lock(&boot_lock);
  242. + spin_unlock(&boot_lock);
  243. +}
  244. +
  245. +static int __cpuinit bcm5301x_smp_boot_secondary(unsigned int cpu,
  246. + struct task_struct *idle)
  247. +{
  248. + unsigned long timeout;
  249. +
  250. + /*
  251. + * set synchronisation state between this boot processor
  252. + * and the secondary one
  253. + */
  254. + spin_lock(&boot_lock);
  255. +
  256. + /*
  257. + * The secondary processor is waiting to be released from
  258. + * the holding pen - release it, then wait for it to flag
  259. + * that it has been released by resetting pen_release.
  260. + *
  261. + * Note that "pen_release" is the hardware CPU ID, whereas
  262. + * "cpu" is Linux's internal ID.
  263. + */
  264. + write_pen_release(cpu_logical_map(cpu));
  265. +
  266. + /* Send the secondary CPU SEV */
  267. + dsb_sev();
  268. +
  269. + udelay(100);
  270. +
  271. + /*
  272. + * Send the secondary CPU a soft interrupt, thereby causing
  273. + * the boot monitor to read the system wide flags register,
  274. + * and branch to the address found there.
  275. + */
  276. + arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  277. +
  278. + /*
  279. + * Timeout set on purpose in jiffies so that on slow processors
  280. + * that must also have low HZ it will wait longer.
  281. + */
  282. + timeout = jiffies + (HZ * 10);
  283. + while (time_before(jiffies, timeout)) {
  284. + smp_rmb();
  285. + if (pen_release == -1)
  286. + break;
  287. +
  288. + udelay(10);
  289. + }
  290. +
  291. + /*
  292. + * now the secondary core is starting up let it run its
  293. + * calibrations, then wait for it to finish
  294. + */
  295. + spin_unlock(&boot_lock);
  296. +
  297. + return pen_release != -1 ? -ENOSYS : 0;
  298. +}
  299. +
  300. +static struct smp_operations bcm5301x_smp_ops __initdata = {
  301. + .smp_prepare_cpus = bcm5301x_smp_prepare_cpus,
  302. + .smp_secondary_init = bcm5301x_smp_secondary_init,
  303. + .smp_boot_secondary = bcm5301x_smp_boot_secondary,
  304. +};
  305. +
  306. +CPU_METHOD_OF_DECLARE(bcm5301x_smp, "brcm,bcm4708-smp",
  307. + &bcm5301x_smp_ops);