Merge branch 'linux-4.21' of git://github.com/skeggsb/linux into drm-fixes
[linux-2.6-microblaze.git] / arch / arm / plat-versatile / platsmp.c
1 /*
2  *  linux/arch/arm/plat-versatile/platsmp.c
3  *
4  *  Copyright (C) 2002 ARM Ltd.
5  *  All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This code is specific to the hardware found on ARM Realview and
12  * Versatile Express platforms where the CPUs are unable to be individually
13  * woken, and where there is no way to hot-unplug CPUs.  Real platforms
14  * should not copy this code.
15  */
16 #include <linux/init.h>
17 #include <linux/errno.h>
18 #include <linux/delay.h>
19 #include <linux/device.h>
20 #include <linux/jiffies.h>
21 #include <linux/smp.h>
22
23 #include <asm/cacheflush.h>
24 #include <asm/smp_plat.h>
25
26 #include <plat/platsmp.h>
27
28 /*
29  * versatile_cpu_release controls the release of CPUs from the holding
30  * pen in headsmp.S, which exists because we are not always able to
31  * control the release of individual CPUs from the board firmware.
32  * Production platforms do not need this.
33  */
34 volatile int versatile_cpu_release = -1;
35
36 /*
37  * Write versatile_cpu_release in a way that is guaranteed to be visible to
38  * all observers, irrespective of whether they're taking part in coherency
39  * or not.  This is necessary for the hotplug code to work reliably.
40  */
41 static void versatile_write_cpu_release(int val)
42 {
43         versatile_cpu_release = val;
44         smp_wmb();
45         sync_cache_w(&versatile_cpu_release);
46 }
47
48 /*
49  * versatile_lock exists to avoid running the loops_per_jiffy delay loop
50  * calibrations on the secondary CPU while the requesting CPU is using
51  * the limited-bandwidth bus - which affects the calibration value.
52  * Production platforms do not need this.
53  */
54 static DEFINE_RAW_SPINLOCK(versatile_lock);
55
56 void versatile_secondary_init(unsigned int cpu)
57 {
58         /*
59          * let the primary processor know we're out of the
60          * pen, then head off into the C entry point
61          */
62         versatile_write_cpu_release(-1);
63
64         /*
65          * Synchronise with the boot thread.
66          */
67         raw_spin_lock(&versatile_lock);
68         raw_spin_unlock(&versatile_lock);
69 }
70
71 int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
72 {
73         unsigned long timeout;
74
75         /*
76          * Set synchronisation state between this boot processor
77          * and the secondary one
78          */
79         raw_spin_lock(&versatile_lock);
80
81         /*
82          * This is really belt and braces; we hold unintended secondary
83          * CPUs in the holding pen until we're ready for them.  However,
84          * since we haven't sent them a soft interrupt, they shouldn't
85          * be there.
86          */
87         versatile_write_cpu_release(cpu_logical_map(cpu));
88
89         /*
90          * Send the secondary CPU a soft interrupt, thereby causing
91          * the boot monitor to read the system wide flags register,
92          * and branch to the address found there.
93          */
94         arch_send_wakeup_ipi_mask(cpumask_of(cpu));
95
96         timeout = jiffies + (1 * HZ);
97         while (time_before(jiffies, timeout)) {
98                 smp_rmb();
99                 if (versatile_cpu_release == -1)
100                         break;
101
102                 udelay(10);
103         }
104
105         /*
106          * now the secondary core is starting up let it run its
107          * calibrations, then wait for it to finish
108          */
109         raw_spin_unlock(&versatile_lock);
110
111         return versatile_cpu_release != -1 ? -ENOSYS : 0;
112 }