2 * arch/arm/mach-sti/platsmp.c
4 * Copyright (C) 2013 STMicroelectronics (R&D) Limited.
7 * Cloned from linux/arch/arm/mach-vexpress/platsmp.c
9 * Copyright (C) 2002 ARM Ltd.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
16 #include <linux/init.h>
17 #include <linux/errno.h>
18 #include <linux/delay.h>
19 #include <linux/smp.h>
22 #include <linux/of_address.h>
23 #include <linux/memblock.h>
25 #include <asm/cacheflush.h>
26 #include <asm/smp_plat.h>
27 #include <asm/smp_scu.h>
31 static void write_pen_release(int val
)
35 sync_cache_w(&pen_release
);
38 static DEFINE_SPINLOCK(boot_lock
);
40 static void sti_secondary_init(unsigned int cpu
)
43 * let the primary processor know we're out of the
44 * pen, then head off into the C entry point
46 write_pen_release(-1);
49 * Synchronise with the boot thread.
51 spin_lock(&boot_lock
);
52 spin_unlock(&boot_lock
);
55 static int sti_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
57 unsigned long timeout
;
60 * set synchronisation state between this boot processor
61 * and the secondary one
63 spin_lock(&boot_lock
);
66 * The secondary processor is waiting to be released from
67 * the holding pen - release it, then wait for it to flag
68 * that it has been released by resetting pen_release.
70 * Note that "pen_release" is the hardware CPU ID, whereas
71 * "cpu" is Linux's internal ID.
73 write_pen_release(cpu_logical_map(cpu
));
76 * Send the secondary CPU a soft interrupt, thereby causing
77 * it to jump to the secondary entrypoint.
79 arch_send_wakeup_ipi_mask(cpumask_of(cpu
));
81 timeout
= jiffies
+ (1 * HZ
);
82 while (time_before(jiffies
, timeout
)) {
84 if (pen_release
== -1)
91 * now the secondary core is starting up let it run its
92 * calibrations, then wait for it to finish
94 spin_unlock(&boot_lock
);
96 return pen_release
!= -1 ? -ENOSYS
: 0;
99 static void __init
sti_smp_prepare_cpus(unsigned int max_cpus
)
101 struct device_node
*np
;
102 void __iomem
*scu_base
;
103 u32 __iomem
*cpu_strt_ptr
;
106 unsigned long entry_pa
= __pa_symbol(sti_secondary_startup
);
108 np
= of_find_compatible_node(NULL
, NULL
, "arm,cortex-a9-scu");
111 scu_base
= of_iomap(np
, 0);
112 scu_enable(scu_base
);
119 for_each_possible_cpu(cpu
) {
121 np
= of_get_cpu_node(cpu
, NULL
);
126 if (of_property_read_u32(np
, "cpu-release-addr",
128 pr_err("CPU %d: missing or invalid cpu-release-addr "
134 * holding pen is usually configured in SBC DMEM but can also be
138 if (!memblock_is_memory(release_phys
))
140 ioremap(release_phys
, sizeof(release_phys
));
143 (u32 __iomem
*)phys_to_virt(release_phys
);
145 __raw_writel(entry_pa
, cpu_strt_ptr
);
148 * wmb so that data is actually written
149 * before cache flush is done
152 sync_cache_w(cpu_strt_ptr
);
154 if (!memblock_is_memory(release_phys
))
155 iounmap(cpu_strt_ptr
);
159 const struct smp_operations sti_smp_ops __initconst
= {
160 .smp_prepare_cpus
= sti_smp_prepare_cpus
,
161 .smp_secondary_init
= sti_secondary_init
,
162 .smp_boot_secondary
= sti_boot_secondary
,