blob: 3567296cec2ade5293b909b242111a18563f42fe [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Russell King0462b442011-01-19 10:24:56 +00002/*
3 * linux/arch/arm/plat-versatile/platsmp.c
4 *
5 * Copyright (C) 2002 ARM Ltd.
6 * All Rights Reserved
7 *
Russell Kingd9b778e2018-12-13 12:54:26 +00008 * This code is specific to the hardware found on ARM Realview and
9 * Versatile Express platforms where the CPUs are unable to be individually
10 * woken, and where there is no way to hot-unplug CPUs. Real platforms
11 * should not copy this code.
Russell King0462b442011-01-19 10:24:56 +000012 */
13#include <linux/init.h>
14#include <linux/errno.h>
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <linux/jiffies.h>
18#include <linux/smp.h>
19
20#include <asm/cacheflush.h>
Will Deaconeb504392012-01-20 12:01:12 +010021#include <asm/smp_plat.h>
Russell King0462b442011-01-19 10:24:56 +000022
Ben Dooks4091af62016-06-08 18:16:10 +010023#include <plat/platsmp.h>
24
Russell King0462b442011-01-19 10:24:56 +000025/*
Russell Kingd9b778e2018-12-13 12:54:26 +000026 * versatile_cpu_release controls the release of CPUs from the holding
27 * pen in headsmp.S, which exists because we are not always able to
28 * control the release of individual CPUs from the board firmware.
29 * Production platforms do not need this.
30 */
31volatile int versatile_cpu_release = -1;
32
33/*
34 * Write versatile_cpu_release in a way that is guaranteed to be visible to
35 * all observers, irrespective of whether they're taking part in coherency
Russell King0462b442011-01-19 10:24:56 +000036 * or not. This is necessary for the hotplug code to work reliably.
37 */
Russell Kingd9b778e2018-12-13 12:54:26 +000038static void versatile_write_cpu_release(int val)
Russell King0462b442011-01-19 10:24:56 +000039{
Russell Kingd9b778e2018-12-13 12:54:26 +000040 versatile_cpu_release = val;
Russell King0462b442011-01-19 10:24:56 +000041 smp_wmb();
Russell Kingd9b778e2018-12-13 12:54:26 +000042 sync_cache_w(&versatile_cpu_release);
Russell King0462b442011-01-19 10:24:56 +000043}
44
Russell Kingd9b778e2018-12-13 12:54:26 +000045/*
46 * versatile_lock exists to avoid running the loops_per_jiffy delay loop
47 * calibrations on the secondary CPU while the requesting CPU is using
48 * the limited-bandwidth bus - which affects the calibration value.
49 * Production platforms do not need this.
50 */
51static DEFINE_RAW_SPINLOCK(versatile_lock);
Russell King0462b442011-01-19 10:24:56 +000052
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040053void versatile_secondary_init(unsigned int cpu)
Russell King0462b442011-01-19 10:24:56 +000054{
55 /*
Russell King0462b442011-01-19 10:24:56 +000056 * let the primary processor know we're out of the
57 * pen, then head off into the C entry point
58 */
Russell Kingd9b778e2018-12-13 12:54:26 +000059 versatile_write_cpu_release(-1);
Russell King0462b442011-01-19 10:24:56 +000060
61 /*
62 * Synchronise with the boot thread.
63 */
Russell Kingd9b778e2018-12-13 12:54:26 +000064 raw_spin_lock(&versatile_lock);
65 raw_spin_unlock(&versatile_lock);
Russell King0462b442011-01-19 10:24:56 +000066}
67
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040068int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
Russell King0462b442011-01-19 10:24:56 +000069{
70 unsigned long timeout;
71
72 /*
73 * Set synchronisation state between this boot processor
74 * and the secondary one
75 */
Russell Kingd9b778e2018-12-13 12:54:26 +000076 raw_spin_lock(&versatile_lock);
Russell King0462b442011-01-19 10:24:56 +000077
78 /*
79 * This is really belt and braces; we hold unintended secondary
80 * CPUs in the holding pen until we're ready for them. However,
81 * since we haven't sent them a soft interrupt, they shouldn't
82 * be there.
83 */
Russell Kingd9b778e2018-12-13 12:54:26 +000084 versatile_write_cpu_release(cpu_logical_map(cpu));
Russell King0462b442011-01-19 10:24:56 +000085
86 /*
87 * Send the secondary CPU a soft interrupt, thereby causing
88 * the boot monitor to read the system wide flags register,
89 * and branch to the address found there.
90 */
Rob Herringb1cffeb2012-11-26 15:05:48 -060091 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
Russell King0462b442011-01-19 10:24:56 +000092
93 timeout = jiffies + (1 * HZ);
94 while (time_before(jiffies, timeout)) {
95 smp_rmb();
Russell Kingd9b778e2018-12-13 12:54:26 +000096 if (versatile_cpu_release == -1)
Russell King0462b442011-01-19 10:24:56 +000097 break;
98
99 udelay(10);
100 }
101
102 /*
103 * now the secondary core is starting up let it run its
104 * calibrations, then wait for it to finish
105 */
Russell Kingd9b778e2018-12-13 12:54:26 +0000106 raw_spin_unlock(&versatile_lock);
Russell King0462b442011-01-19 10:24:56 +0000107
Russell Kingd9b778e2018-12-13 12:54:26 +0000108 return versatile_cpu_release != -1 ? -ENOSYS : 0;
Russell King0462b442011-01-19 10:24:56 +0000109}