Linux 3.11-rc3
[cris-mirror.git] / arch / arm / mach-prima2 / platsmp.c
blob3dbcb1ab6e37e5ea5eeedcc05c27e45b9e14ac2b
1 /*
2 * plat smp support for CSR Marco dual-core SMP SoCs
4 * Copyright (c) 2012 Cambridge Silicon Radio Limited, a CSR plc group company.
6 * Licensed under GPLv2 or later.
7 */
9 #include <linux/init.h>
10 #include <linux/smp.h>
11 #include <linux/delay.h>
12 #include <linux/of.h>
13 #include <linux/of_address.h>
14 #include <asm/page.h>
15 #include <asm/mach/map.h>
16 #include <asm/smp_plat.h>
17 #include <asm/smp_scu.h>
18 #include <asm/cacheflush.h>
19 #include <asm/cputype.h>
21 #include "common.h"
23 static void __iomem *scu_base;
24 static void __iomem *rsc_base;
26 static DEFINE_SPINLOCK(boot_lock);
28 static struct map_desc scu_io_desc __initdata = {
29 .length = SZ_4K,
30 .type = MT_DEVICE,
33 void __init sirfsoc_map_scu(void)
35 unsigned long base;
37 /* Get SCU base */
38 asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base));
40 scu_io_desc.virtual = SIRFSOC_VA(base);
41 scu_io_desc.pfn = __phys_to_pfn(base);
42 iotable_init(&scu_io_desc, 1);
44 scu_base = (void __iomem *)SIRFSOC_VA(base);
47 static void sirfsoc_secondary_init(unsigned int cpu)
50 * let the primary processor know we're out of the
51 * pen, then head off into the C entry point
53 pen_release = -1;
54 smp_wmb();
57 * Synchronise with the boot thread.
59 spin_lock(&boot_lock);
60 spin_unlock(&boot_lock);
63 static struct of_device_id rsc_ids[] = {
64 { .compatible = "sirf,marco-rsc" },
65 {},
68 static int sirfsoc_boot_secondary(unsigned int cpu, struct task_struct *idle)
70 unsigned long timeout;
71 struct device_node *np;
73 np = of_find_matching_node(NULL, rsc_ids);
74 if (!np)
75 return -ENODEV;
77 rsc_base = of_iomap(np, 0);
78 if (!rsc_base)
79 return -ENOMEM;
82 * write the address of secondary startup into the sram register
83 * at offset 0x2C, then write the magic number 0x3CAF5D62 to the
84 * RSC register at offset 0x28, which is what boot rom code is
85 * waiting for. This would wake up the secondary core from WFE
87 #define SIRFSOC_CPU1_JUMPADDR_OFFSET 0x2C
88 __raw_writel(virt_to_phys(sirfsoc_secondary_startup),
89 rsc_base + SIRFSOC_CPU1_JUMPADDR_OFFSET);
91 #define SIRFSOC_CPU1_WAKEMAGIC_OFFSET 0x28
92 __raw_writel(0x3CAF5D62,
93 rsc_base + SIRFSOC_CPU1_WAKEMAGIC_OFFSET);
95 /* make sure write buffer is drained */
96 mb();
98 spin_lock(&boot_lock);
101 * The secondary processor is waiting to be released from
102 * the holding pen - release it, then wait for it to flag
103 * that it has been released by resetting pen_release.
105 * Note that "pen_release" is the hardware CPU ID, whereas
106 * "cpu" is Linux's internal ID.
108 pen_release = cpu_logical_map(cpu);
109 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
110 outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
113 * Send the secondary CPU SEV, thereby causing the boot monitor to read
114 * the JUMPADDR and WAKEMAGIC, and branch to the address found there.
116 dsb_sev();
118 timeout = jiffies + (1 * HZ);
119 while (time_before(jiffies, timeout)) {
120 smp_rmb();
121 if (pen_release == -1)
122 break;
124 udelay(10);
128 * now the secondary core is starting up let it run its
129 * calibrations, then wait for it to finish
131 spin_unlock(&boot_lock);
133 return pen_release != -1 ? -ENOSYS : 0;
136 static void __init sirfsoc_smp_prepare_cpus(unsigned int max_cpus)
138 scu_enable(scu_base);
141 struct smp_operations sirfsoc_smp_ops __initdata = {
142 .smp_prepare_cpus = sirfsoc_smp_prepare_cpus,
143 .smp_secondary_init = sirfsoc_secondary_init,
144 .smp_boot_secondary = sirfsoc_boot_secondary,
145 #ifdef CONFIG_HOTPLUG_CPU
146 .cpu_die = sirfsoc_cpu_die,
147 #endif