Linux 5.7.7
[linux/fpc-iii.git] / arch / arm / plat-versatile / platsmp.c
blob3567296cec2ade5293b909b242111a18563f42fe
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/arch/arm/plat-versatile/platsmp.c
5 * Copyright (C) 2002 ARM Ltd.
6 * All Rights Reserved
8 * 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.
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>
20 #include <asm/cacheflush.h>
21 #include <asm/smp_plat.h>
23 #include <plat/platsmp.h>
26 * 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.
31 volatile int versatile_cpu_release = -1;
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
36 * or not. This is necessary for the hotplug code to work reliably.
38 static void versatile_write_cpu_release(int val)
40 versatile_cpu_release = val;
41 smp_wmb();
42 sync_cache_w(&versatile_cpu_release);
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.
51 static DEFINE_RAW_SPINLOCK(versatile_lock);
53 void versatile_secondary_init(unsigned int cpu)
56 * let the primary processor know we're out of the
57 * pen, then head off into the C entry point
59 versatile_write_cpu_release(-1);
62 * Synchronise with the boot thread.
64 raw_spin_lock(&versatile_lock);
65 raw_spin_unlock(&versatile_lock);
68 int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
70 unsigned long timeout;
73 * Set synchronisation state between this boot processor
74 * and the secondary one
76 raw_spin_lock(&versatile_lock);
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.
84 versatile_write_cpu_release(cpu_logical_map(cpu));
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.
91 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
93 timeout = jiffies + (1 * HZ);
94 while (time_before(jiffies, timeout)) {
95 smp_rmb();
96 if (versatile_cpu_release == -1)
97 break;
99 udelay(10);
103 * now the secondary core is starting up let it run its
104 * calibrations, then wait for it to finish
106 raw_spin_unlock(&versatile_lock);
108 return versatile_cpu_release != -1 ? -ENOSYS : 0;