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