Nicolas Pitre | e8db288 | 2012-04-12 02:45:22 -0400 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/common/mcpm_entry.c -- entry point for multi-cluster PM |
| 3 | * |
| 4 | * Created by: Nicolas Pitre, March 2012 |
| 5 | * Copyright: (C) 2012-2013 Linaro Limited |
| 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 | |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/irqflags.h> |
Nicolas Pitre | 3721924 | 2014-06-24 18:32:51 +0100 | [diff] [blame] | 15 | #include <linux/cpu_pm.h> |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 16 | |
Nicolas Pitre | e8db288 | 2012-04-12 02:45:22 -0400 | [diff] [blame] | 17 | #include <asm/mcpm.h> |
| 18 | #include <asm/cacheflush.h> |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 19 | #include <asm/idmap.h> |
Dave Martin | 7fe31d2 | 2012-07-17 14:25:42 +0100 | [diff] [blame] | 20 | #include <asm/cputype.h> |
Nicolas Pitre | 3721924 | 2014-06-24 18:32:51 +0100 | [diff] [blame] | 21 | #include <asm/suspend.h> |
Nicolas Pitre | e8db288 | 2012-04-12 02:45:22 -0400 | [diff] [blame] | 22 | |
Nicolas Pitre | 7cc8b99 | 2015-04-28 14:11:07 -0400 | [diff] [blame^] | 23 | |
| 24 | struct sync_struct mcpm_sync; |
| 25 | |
| 26 | /* |
| 27 | * __mcpm_cpu_going_down: Indicates that the cpu is being torn down. |
| 28 | * This must be called at the point of committing to teardown of a CPU. |
| 29 | * The CPU cache (SCTRL.C bit) is expected to still be active. |
| 30 | */ |
| 31 | static void __mcpm_cpu_going_down(unsigned int cpu, unsigned int cluster) |
| 32 | { |
| 33 | mcpm_sync.clusters[cluster].cpus[cpu].cpu = CPU_GOING_DOWN; |
| 34 | sync_cache_w(&mcpm_sync.clusters[cluster].cpus[cpu].cpu); |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * __mcpm_cpu_down: Indicates that cpu teardown is complete and that the |
| 39 | * cluster can be torn down without disrupting this CPU. |
| 40 | * To avoid deadlocks, this must be called before a CPU is powered down. |
| 41 | * The CPU cache (SCTRL.C bit) is expected to be off. |
| 42 | * However L2 cache might or might not be active. |
| 43 | */ |
| 44 | static void __mcpm_cpu_down(unsigned int cpu, unsigned int cluster) |
| 45 | { |
| 46 | dmb(); |
| 47 | mcpm_sync.clusters[cluster].cpus[cpu].cpu = CPU_DOWN; |
| 48 | sync_cache_w(&mcpm_sync.clusters[cluster].cpus[cpu].cpu); |
| 49 | sev(); |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * __mcpm_outbound_leave_critical: Leave the cluster teardown critical section. |
| 54 | * @state: the final state of the cluster: |
| 55 | * CLUSTER_UP: no destructive teardown was done and the cluster has been |
| 56 | * restored to the previous state (CPU cache still active); or |
| 57 | * CLUSTER_DOWN: the cluster has been torn-down, ready for power-off |
| 58 | * (CPU cache disabled, L2 cache either enabled or disabled). |
| 59 | */ |
| 60 | static void __mcpm_outbound_leave_critical(unsigned int cluster, int state) |
| 61 | { |
| 62 | dmb(); |
| 63 | mcpm_sync.clusters[cluster].cluster = state; |
| 64 | sync_cache_w(&mcpm_sync.clusters[cluster].cluster); |
| 65 | sev(); |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * __mcpm_outbound_enter_critical: Enter the cluster teardown critical section. |
| 70 | * This function should be called by the last man, after local CPU teardown |
| 71 | * is complete. CPU cache expected to be active. |
| 72 | * |
| 73 | * Returns: |
| 74 | * false: the critical section was not entered because an inbound CPU was |
| 75 | * observed, or the cluster is already being set up; |
| 76 | * true: the critical section was entered: it is now safe to tear down the |
| 77 | * cluster. |
| 78 | */ |
| 79 | static bool __mcpm_outbound_enter_critical(unsigned int cpu, unsigned int cluster) |
| 80 | { |
| 81 | unsigned int i; |
| 82 | struct mcpm_sync_struct *c = &mcpm_sync.clusters[cluster]; |
| 83 | |
| 84 | /* Warn inbound CPUs that the cluster is being torn down: */ |
| 85 | c->cluster = CLUSTER_GOING_DOWN; |
| 86 | sync_cache_w(&c->cluster); |
| 87 | |
| 88 | /* Back out if the inbound cluster is already in the critical region: */ |
| 89 | sync_cache_r(&c->inbound); |
| 90 | if (c->inbound == INBOUND_COMING_UP) |
| 91 | goto abort; |
| 92 | |
| 93 | /* |
| 94 | * Wait for all CPUs to get out of the GOING_DOWN state, so that local |
| 95 | * teardown is complete on each CPU before tearing down the cluster. |
| 96 | * |
| 97 | * If any CPU has been woken up again from the DOWN state, then we |
| 98 | * shouldn't be taking the cluster down at all: abort in that case. |
| 99 | */ |
| 100 | sync_cache_r(&c->cpus); |
| 101 | for (i = 0; i < MAX_CPUS_PER_CLUSTER; i++) { |
| 102 | int cpustate; |
| 103 | |
| 104 | if (i == cpu) |
| 105 | continue; |
| 106 | |
| 107 | while (1) { |
| 108 | cpustate = c->cpus[i].cpu; |
| 109 | if (cpustate != CPU_GOING_DOWN) |
| 110 | break; |
| 111 | |
| 112 | wfe(); |
| 113 | sync_cache_r(&c->cpus[i].cpu); |
| 114 | } |
| 115 | |
| 116 | switch (cpustate) { |
| 117 | case CPU_DOWN: |
| 118 | continue; |
| 119 | |
| 120 | default: |
| 121 | goto abort; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return true; |
| 126 | |
| 127 | abort: |
| 128 | __mcpm_outbound_leave_critical(cluster, CLUSTER_UP); |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | static int __mcpm_cluster_state(unsigned int cluster) |
| 133 | { |
| 134 | sync_cache_r(&mcpm_sync.clusters[cluster].cluster); |
| 135 | return mcpm_sync.clusters[cluster].cluster; |
| 136 | } |
| 137 | |
Nicolas Pitre | e8db288 | 2012-04-12 02:45:22 -0400 | [diff] [blame] | 138 | extern unsigned long mcpm_entry_vectors[MAX_NR_CLUSTERS][MAX_CPUS_PER_CLUSTER]; |
| 139 | |
| 140 | void mcpm_set_entry_vector(unsigned cpu, unsigned cluster, void *ptr) |
| 141 | { |
| 142 | unsigned long val = ptr ? virt_to_phys(ptr) : 0; |
| 143 | mcpm_entry_vectors[cluster][cpu] = val; |
| 144 | sync_cache_w(&mcpm_entry_vectors[cluster][cpu]); |
| 145 | } |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 146 | |
Nicolas Pitre | de885d1 | 2012-11-27 23:11:20 -0500 | [diff] [blame] | 147 | extern unsigned long mcpm_entry_early_pokes[MAX_NR_CLUSTERS][MAX_CPUS_PER_CLUSTER][2]; |
| 148 | |
| 149 | void mcpm_set_early_poke(unsigned cpu, unsigned cluster, |
| 150 | unsigned long poke_phys_addr, unsigned long poke_val) |
| 151 | { |
| 152 | unsigned long *poke = &mcpm_entry_early_pokes[cluster][cpu][0]; |
| 153 | poke[0] = poke_phys_addr; |
| 154 | poke[1] = poke_val; |
Nicolas Pitre | efcfc46 | 2013-12-09 16:10:18 +0100 | [diff] [blame] | 155 | __sync_cache_range_w(poke, 2 * sizeof(*poke)); |
Nicolas Pitre | de885d1 | 2012-11-27 23:11:20 -0500 | [diff] [blame] | 156 | } |
| 157 | |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 158 | static const struct mcpm_platform_ops *platform_ops; |
| 159 | |
| 160 | int __init mcpm_platform_register(const struct mcpm_platform_ops *ops) |
| 161 | { |
| 162 | if (platform_ops) |
| 163 | return -EBUSY; |
| 164 | platform_ops = ops; |
| 165 | return 0; |
| 166 | } |
| 167 | |
Nicolas Pitre | 4530e4b | 2014-04-22 00:25:35 +0100 | [diff] [blame] | 168 | bool mcpm_is_available(void) |
| 169 | { |
| 170 | return (platform_ops) ? true : false; |
| 171 | } |
| 172 | |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 173 | /* |
| 174 | * We can't use regular spinlocks. In the switcher case, it is possible |
| 175 | * for an outbound CPU to call power_down() after its inbound counterpart |
| 176 | * is already live using the same logical CPU number which trips lockdep |
| 177 | * debugging. |
| 178 | */ |
| 179 | static arch_spinlock_t mcpm_lock = __ARCH_SPIN_LOCK_UNLOCKED; |
| 180 | |
| 181 | static int mcpm_cpu_use_count[MAX_NR_CLUSTERS][MAX_CPUS_PER_CLUSTER]; |
| 182 | |
| 183 | static inline bool mcpm_cluster_unused(unsigned int cluster) |
| 184 | { |
| 185 | int i, cnt; |
| 186 | for (i = 0, cnt = 0; i < MAX_CPUS_PER_CLUSTER; i++) |
| 187 | cnt |= mcpm_cpu_use_count[cluster][i]; |
| 188 | return !cnt; |
| 189 | } |
| 190 | |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 191 | int mcpm_cpu_power_up(unsigned int cpu, unsigned int cluster) |
| 192 | { |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 193 | bool cpu_is_down, cluster_is_down; |
| 194 | int ret = 0; |
| 195 | |
Nicolas Pitre | 77404d8 | 2015-04-28 13:44:00 -0400 | [diff] [blame] | 196 | pr_debug("%s: cpu %u cluster %u\n", __func__, cpu, cluster); |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 197 | if (!platform_ops) |
| 198 | return -EUNATCH; /* try not to shadow power_up errors */ |
| 199 | might_sleep(); |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 200 | |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 201 | /* |
| 202 | * Since this is called with IRQs enabled, and no arch_spin_lock_irq |
| 203 | * variant exists, we need to disable IRQs manually here. |
| 204 | */ |
| 205 | local_irq_disable(); |
| 206 | arch_spin_lock(&mcpm_lock); |
| 207 | |
| 208 | cpu_is_down = !mcpm_cpu_use_count[cluster][cpu]; |
| 209 | cluster_is_down = mcpm_cluster_unused(cluster); |
| 210 | |
| 211 | mcpm_cpu_use_count[cluster][cpu]++; |
| 212 | /* |
| 213 | * The only possible values are: |
| 214 | * 0 = CPU down |
| 215 | * 1 = CPU (still) up |
| 216 | * 2 = CPU requested to be up before it had a chance |
| 217 | * to actually make itself down. |
| 218 | * Any other value is a bug. |
| 219 | */ |
| 220 | BUG_ON(mcpm_cpu_use_count[cluster][cpu] != 1 && |
| 221 | mcpm_cpu_use_count[cluster][cpu] != 2); |
| 222 | |
| 223 | if (cluster_is_down) |
| 224 | ret = platform_ops->cluster_powerup(cluster); |
| 225 | if (cpu_is_down && !ret) |
| 226 | ret = platform_ops->cpu_powerup(cpu, cluster); |
| 227 | |
| 228 | arch_spin_unlock(&mcpm_lock); |
| 229 | local_irq_enable(); |
| 230 | return ret; |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | typedef void (*phys_reset_t)(unsigned long); |
| 234 | |
| 235 | void mcpm_cpu_power_down(void) |
| 236 | { |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 237 | unsigned int mpidr, cpu, cluster; |
| 238 | bool cpu_going_down, last_man; |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 239 | phys_reset_t phys_reset; |
| 240 | |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 241 | mpidr = read_cpuid_mpidr(); |
| 242 | cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); |
| 243 | cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); |
| 244 | pr_debug("%s: cpu %u cluster %u\n", __func__, cpu, cluster); |
Nicolas Pitre | 77404d8 | 2015-04-28 13:44:00 -0400 | [diff] [blame] | 245 | if (WARN_ON_ONCE(!platform_ops)) |
| 246 | return; |
| 247 | BUG_ON(!irqs_disabled()); |
| 248 | |
| 249 | setup_mm_for_reboot(); |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 250 | |
| 251 | __mcpm_cpu_going_down(cpu, cluster); |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 252 | arch_spin_lock(&mcpm_lock); |
| 253 | BUG_ON(__mcpm_cluster_state(cluster) != CLUSTER_UP); |
| 254 | |
| 255 | mcpm_cpu_use_count[cluster][cpu]--; |
| 256 | BUG_ON(mcpm_cpu_use_count[cluster][cpu] != 0 && |
| 257 | mcpm_cpu_use_count[cluster][cpu] != 1); |
| 258 | cpu_going_down = !mcpm_cpu_use_count[cluster][cpu]; |
| 259 | last_man = mcpm_cluster_unused(cluster); |
| 260 | |
| 261 | if (last_man && __mcpm_outbound_enter_critical(cpu, cluster)) { |
| 262 | platform_ops->cpu_powerdown_prepare(cpu, cluster); |
| 263 | platform_ops->cluster_powerdown_prepare(cluster); |
| 264 | arch_spin_unlock(&mcpm_lock); |
| 265 | platform_ops->cluster_cache_disable(); |
| 266 | __mcpm_outbound_leave_critical(cluster, CLUSTER_DOWN); |
| 267 | } else { |
| 268 | if (cpu_going_down) |
| 269 | platform_ops->cpu_powerdown_prepare(cpu, cluster); |
| 270 | arch_spin_unlock(&mcpm_lock); |
| 271 | /* |
| 272 | * If cpu_going_down is false here, that means a power_up |
| 273 | * request raced ahead of us. Even if we do not want to |
| 274 | * shut this CPU down, the caller still expects execution |
| 275 | * to return through the system resume entry path, like |
| 276 | * when the WFI is aborted due to a new IRQ or the like.. |
| 277 | * So let's continue with cache cleaning in all cases. |
| 278 | */ |
| 279 | platform_ops->cpu_cache_disable(); |
| 280 | } |
| 281 | |
| 282 | __mcpm_cpu_down(cpu, cluster); |
| 283 | |
| 284 | /* Now we are prepared for power-down, do it: */ |
| 285 | if (cpu_going_down) |
| 286 | wfi(); |
| 287 | |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 288 | /* |
| 289 | * It is possible for a power_up request to happen concurrently |
| 290 | * with a power_down request for the same CPU. In this case the |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 291 | * CPU might not be able to actually enter a powered down state |
| 292 | * with the WFI instruction if the power_up request has removed |
| 293 | * the required reset condition. We must perform a re-entry in |
| 294 | * the kernel as if the power_up method just had deasserted reset |
| 295 | * on the CPU. |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 296 | */ |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 297 | phys_reset = (phys_reset_t)(unsigned long)virt_to_phys(cpu_reset); |
| 298 | phys_reset(virt_to_phys(mcpm_entry_point)); |
| 299 | |
| 300 | /* should never get here */ |
| 301 | BUG(); |
| 302 | } |
| 303 | |
Dave Martin | 166aaf3 | 2014-04-17 16:58:39 +0100 | [diff] [blame] | 304 | int mcpm_wait_for_cpu_powerdown(unsigned int cpu, unsigned int cluster) |
Dave Martin | 0de0d64 | 2013-10-01 19:58:17 +0100 | [diff] [blame] | 305 | { |
| 306 | int ret; |
| 307 | |
Dave Martin | 166aaf3 | 2014-04-17 16:58:39 +0100 | [diff] [blame] | 308 | if (WARN_ON_ONCE(!platform_ops || !platform_ops->wait_for_powerdown)) |
Dave Martin | 0de0d64 | 2013-10-01 19:58:17 +0100 | [diff] [blame] | 309 | return -EUNATCH; |
| 310 | |
Dave Martin | 166aaf3 | 2014-04-17 16:58:39 +0100 | [diff] [blame] | 311 | ret = platform_ops->wait_for_powerdown(cpu, cluster); |
Dave Martin | 0de0d64 | 2013-10-01 19:58:17 +0100 | [diff] [blame] | 312 | if (ret) |
| 313 | pr_warn("%s: cpu %u, cluster %u failed to power down (%d)\n", |
| 314 | __func__, cpu, cluster, ret); |
| 315 | |
| 316 | return ret; |
| 317 | } |
| 318 | |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 319 | void mcpm_cpu_suspend(u64 expected_residency) |
| 320 | { |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 321 | if (WARN_ON_ONCE(!platform_ops)) |
Nicolas Pitre | d0cdef6 | 2013-09-25 23:26:24 +0100 | [diff] [blame] | 322 | return; |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 323 | |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 324 | /* Some platforms might have to enable special resume modes, etc. */ |
| 325 | if (platform_ops->cpu_suspend_prepare) { |
| 326 | unsigned int mpidr = read_cpuid_mpidr(); |
| 327 | unsigned int cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); |
| 328 | unsigned int cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); |
| 329 | arch_spin_lock(&mcpm_lock); |
| 330 | platform_ops->cpu_suspend_prepare(cpu, cluster); |
| 331 | arch_spin_unlock(&mcpm_lock); |
| 332 | } |
| 333 | mcpm_cpu_power_down(); |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | int mcpm_cpu_powered_up(void) |
| 337 | { |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 338 | unsigned int mpidr, cpu, cluster; |
| 339 | bool cpu_was_down, first_man; |
| 340 | unsigned long flags; |
| 341 | |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 342 | if (!platform_ops) |
| 343 | return -EUNATCH; |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 344 | |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 345 | mpidr = read_cpuid_mpidr(); |
| 346 | cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); |
| 347 | cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); |
| 348 | local_irq_save(flags); |
| 349 | arch_spin_lock(&mcpm_lock); |
| 350 | |
| 351 | cpu_was_down = !mcpm_cpu_use_count[cluster][cpu]; |
| 352 | first_man = mcpm_cluster_unused(cluster); |
| 353 | |
| 354 | if (first_man && platform_ops->cluster_is_up) |
| 355 | platform_ops->cluster_is_up(cluster); |
| 356 | if (cpu_was_down) |
| 357 | mcpm_cpu_use_count[cluster][cpu] = 1; |
| 358 | if (platform_ops->cpu_is_up) |
| 359 | platform_ops->cpu_is_up(cpu, cluster); |
| 360 | |
| 361 | arch_spin_unlock(&mcpm_lock); |
| 362 | local_irq_restore(flags); |
| 363 | |
Nicolas Pitre | 7c2b860 | 2012-09-20 16:05:37 -0400 | [diff] [blame] | 364 | return 0; |
| 365 | } |
Dave Martin | 7fe31d2 | 2012-07-17 14:25:42 +0100 | [diff] [blame] | 366 | |
Nicolas Pitre | 3721924 | 2014-06-24 18:32:51 +0100 | [diff] [blame] | 367 | #ifdef CONFIG_ARM_CPU_SUSPEND |
| 368 | |
| 369 | static int __init nocache_trampoline(unsigned long _arg) |
| 370 | { |
| 371 | void (*cache_disable)(void) = (void *)_arg; |
| 372 | unsigned int mpidr = read_cpuid_mpidr(); |
| 373 | unsigned int cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); |
| 374 | unsigned int cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); |
| 375 | phys_reset_t phys_reset; |
| 376 | |
| 377 | mcpm_set_entry_vector(cpu, cluster, cpu_resume); |
| 378 | setup_mm_for_reboot(); |
| 379 | |
| 380 | __mcpm_cpu_going_down(cpu, cluster); |
| 381 | BUG_ON(!__mcpm_outbound_enter_critical(cpu, cluster)); |
| 382 | cache_disable(); |
| 383 | __mcpm_outbound_leave_critical(cluster, CLUSTER_DOWN); |
| 384 | __mcpm_cpu_down(cpu, cluster); |
| 385 | |
| 386 | phys_reset = (phys_reset_t)(unsigned long)virt_to_phys(cpu_reset); |
| 387 | phys_reset(virt_to_phys(mcpm_entry_point)); |
| 388 | BUG(); |
| 389 | } |
| 390 | |
| 391 | int __init mcpm_loopback(void (*cache_disable)(void)) |
| 392 | { |
| 393 | int ret; |
| 394 | |
| 395 | /* |
| 396 | * We're going to soft-restart the current CPU through the |
| 397 | * low-level MCPM code by leveraging the suspend/resume |
| 398 | * infrastructure. Let's play it safe by using cpu_pm_enter() |
| 399 | * in case the CPU init code path resets the VFP or similar. |
| 400 | */ |
| 401 | local_irq_disable(); |
| 402 | local_fiq_disable(); |
| 403 | ret = cpu_pm_enter(); |
| 404 | if (!ret) { |
| 405 | ret = cpu_suspend((unsigned long)cache_disable, nocache_trampoline); |
| 406 | cpu_pm_exit(); |
| 407 | } |
| 408 | local_fiq_enable(); |
| 409 | local_irq_enable(); |
| 410 | if (ret) |
| 411 | pr_err("%s returned %d\n", __func__, ret); |
| 412 | return ret; |
| 413 | } |
| 414 | |
| 415 | #endif |
| 416 | |
Dave Martin | 7fe31d2 | 2012-07-17 14:25:42 +0100 | [diff] [blame] | 417 | extern unsigned long mcpm_power_up_setup_phys; |
| 418 | |
| 419 | int __init mcpm_sync_init( |
| 420 | void (*power_up_setup)(unsigned int affinity_level)) |
| 421 | { |
| 422 | unsigned int i, j, mpidr, this_cluster; |
| 423 | |
| 424 | BUILD_BUG_ON(MCPM_SYNC_CLUSTER_SIZE * MAX_NR_CLUSTERS != sizeof mcpm_sync); |
| 425 | BUG_ON((unsigned long)&mcpm_sync & (__CACHE_WRITEBACK_GRANULE - 1)); |
| 426 | |
| 427 | /* |
| 428 | * Set initial CPU and cluster states. |
| 429 | * Only one cluster is assumed to be active at this point. |
| 430 | */ |
| 431 | for (i = 0; i < MAX_NR_CLUSTERS; i++) { |
| 432 | mcpm_sync.clusters[i].cluster = CLUSTER_DOWN; |
| 433 | mcpm_sync.clusters[i].inbound = INBOUND_NOT_COMING_UP; |
| 434 | for (j = 0; j < MAX_CPUS_PER_CLUSTER; j++) |
| 435 | mcpm_sync.clusters[i].cpus[j].cpu = CPU_DOWN; |
| 436 | } |
| 437 | mpidr = read_cpuid_mpidr(); |
| 438 | this_cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 439 | for_each_online_cpu(i) { |
| 440 | mcpm_cpu_use_count[this_cluster][i] = 1; |
Dave Martin | 7fe31d2 | 2012-07-17 14:25:42 +0100 | [diff] [blame] | 441 | mcpm_sync.clusters[this_cluster].cpus[i].cpu = CPU_UP; |
Nicolas Pitre | d3a8754 | 2015-03-11 18:16:13 -0400 | [diff] [blame] | 442 | } |
Dave Martin | 7fe31d2 | 2012-07-17 14:25:42 +0100 | [diff] [blame] | 443 | mcpm_sync.clusters[this_cluster].cluster = CLUSTER_UP; |
| 444 | sync_cache_w(&mcpm_sync); |
| 445 | |
| 446 | if (power_up_setup) { |
| 447 | mcpm_power_up_setup_phys = virt_to_phys(power_up_setup); |
| 448 | sync_cache_w(&mcpm_power_up_setup_phys); |
| 449 | } |
| 450 | |
| 451 | return 0; |
| 452 | } |