Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 ARM Ltd. |
| 3 | * All Rights Reserved |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 4 | * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/smp.h> |
Jeff Ohlstein | c05defe | 2012-01-31 19:53:16 -0800 | [diff] [blame] | 13 | #include <linux/cpu.h> |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 14 | |
| 15 | #include <asm/cacheflush.h> |
Will Deacon | eb50439 | 2012-01-20 12:01:12 +0100 | [diff] [blame] | 16 | #include <asm/smp_plat.h> |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 17 | #include <asm/vfp.h> |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 18 | |
Pratik Patel | 5827c83 | 2012-05-19 19:24:49 -0700 | [diff] [blame] | 19 | #include <mach/jtag.h> |
Jeff Ohlstein | c05defe | 2012-01-31 19:53:16 -0800 | [diff] [blame] | 20 | #include <mach/msm_rtb.h> |
| 21 | |
Matt Wagantall | 7cca464 | 2012-02-01 16:43:24 -0800 | [diff] [blame] | 22 | #include "pm.h" |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 23 | #include "spm.h" |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 24 | |
| 25 | extern volatile int pen_release; |
| 26 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 27 | struct msm_hotplug_device { |
| 28 | struct completion cpu_killed; |
| 29 | unsigned int warm_boot; |
| 30 | }; |
| 31 | |
| 32 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct msm_hotplug_device, |
| 33 | msm_hotplug_devices); |
| 34 | |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 35 | static inline void cpu_enter_lowpower(void) |
| 36 | { |
| 37 | /* Just flush the cache. Changing the coherency is not yet |
| 38 | * available on msm. */ |
| 39 | flush_cache_all(); |
| 40 | } |
| 41 | |
| 42 | static inline void cpu_leave_lowpower(void) |
| 43 | { |
| 44 | } |
| 45 | |
Stephen Boyd | f5e9082 | 2012-08-08 13:36:15 -0700 | [diff] [blame] | 46 | static inline void platform_do_lowpower(unsigned int cpu, int *spurious) |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 47 | { |
| 48 | /* Just enter wfi for now. TODO: Properly shut off the cpu. */ |
| 49 | for (;;) { |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 50 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 51 | msm_pm_cpu_enter_lowpower(cpu); |
Will Deacon | 1d3cfb3 | 2011-08-09 12:02:27 +0100 | [diff] [blame] | 52 | if (pen_release == cpu_logical_map(cpu)) { |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 53 | /* |
| 54 | * OK, proper wakeup, we're done |
| 55 | */ |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * getting here, means that we have come out of WFI without |
| 61 | * having been woken up - this shouldn't happen |
| 62 | * |
| 63 | * The trouble is, letting people know about this is not really |
| 64 | * possible, since we are currently running incoherently, and |
| 65 | * therefore cannot safely call printk() or anything else |
| 66 | */ |
Stephen Boyd | f5e9082 | 2012-08-08 13:36:15 -0700 | [diff] [blame] | 67 | (*spurious)++; |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | int platform_cpu_kill(unsigned int cpu) |
| 72 | { |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame^] | 73 | int ret; |
| 74 | |
| 75 | ret = msm_pm_wait_cpu_shutdown(cpu); |
| 76 | if (ret) |
| 77 | return 0; |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 78 | return 1; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * platform-specific code to shutdown a CPU |
| 83 | * |
| 84 | * Called with IRQs disabled |
| 85 | */ |
| 86 | void platform_cpu_die(unsigned int cpu) |
| 87 | { |
Stephen Boyd | f5e9082 | 2012-08-08 13:36:15 -0700 | [diff] [blame] | 88 | int spurious = 0; |
| 89 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 90 | if (unlikely(cpu != smp_processor_id())) { |
| 91 | pr_crit("%s: running on %u, should be %u\n", |
| 92 | __func__, smp_processor_id(), cpu); |
| 93 | BUG(); |
| 94 | } |
| 95 | complete(&__get_cpu_var(msm_hotplug_devices).cpu_killed); |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 96 | /* |
| 97 | * we're ready for shutdown now, so do it |
| 98 | */ |
| 99 | cpu_enter_lowpower(); |
Stephen Boyd | f5e9082 | 2012-08-08 13:36:15 -0700 | [diff] [blame] | 100 | platform_do_lowpower(cpu, &spurious); |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 101 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 102 | pr_debug("CPU%u: %s: normal wakeup\n", cpu, __func__); |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 103 | cpu_leave_lowpower(); |
Stephen Boyd | f5e9082 | 2012-08-08 13:36:15 -0700 | [diff] [blame] | 104 | |
| 105 | if (spurious) |
| 106 | pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious); |
Jeff Ohlstein | 9f1890a | 2010-12-02 12:11:27 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | int platform_cpu_disable(unsigned int cpu) |
| 110 | { |
| 111 | /* |
| 112 | * we don't allow CPU 0 to be shutdown (it is still too special |
| 113 | * e.g. clock tick interrupts) |
| 114 | */ |
| 115 | return cpu == 0 ? -EPERM : 0; |
| 116 | } |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 117 | |
Jeff Ohlstein | c05defe | 2012-01-31 19:53:16 -0800 | [diff] [blame] | 118 | #define CPU_SHIFT 0 |
| 119 | #define CPU_MASK 0xF |
| 120 | #define CPU_OF(n) (((n) & CPU_MASK) << CPU_SHIFT) |
| 121 | #define CPUSET_SHIFT 4 |
| 122 | #define CPUSET_MASK 0xFFFF |
| 123 | #define CPUSET_OF(n) (((n) & CPUSET_MASK) << CPUSET_SHIFT) |
| 124 | |
| 125 | static int hotplug_rtb_callback(struct notifier_block *nfb, |
| 126 | unsigned long action, void *hcpu) |
| 127 | { |
| 128 | /* |
| 129 | * Bits [19:4] of the data are the online mask, lower 4 bits are the |
| 130 | * cpu number that is being changed. Additionally, changes to the |
| 131 | * online_mask that will be done by the current hotplug will be made |
| 132 | * even though they aren't necessarily in the online mask yet. |
| 133 | * |
| 134 | * XXX: This design is limited to supporting at most 16 cpus |
| 135 | */ |
| 136 | int this_cpumask = CPUSET_OF(1 << (int)hcpu); |
| 137 | int cpumask = CPUSET_OF(cpumask_bits(cpu_online_mask)[0]); |
| 138 | int cpudata = CPU_OF((int)hcpu) | cpumask; |
| 139 | |
| 140 | switch (action & (~CPU_TASKS_FROZEN)) { |
| 141 | case CPU_STARTING: |
| 142 | uncached_logk(LOGK_HOTPLUG, (void *)(cpudata | this_cpumask)); |
| 143 | break; |
| 144 | case CPU_DYING: |
| 145 | uncached_logk(LOGK_HOTPLUG, (void *)(cpudata & ~this_cpumask)); |
| 146 | break; |
| 147 | default: |
| 148 | break; |
| 149 | } |
| 150 | |
| 151 | return NOTIFY_OK; |
| 152 | } |
| 153 | static struct notifier_block hotplug_rtb_notifier = { |
| 154 | .notifier_call = hotplug_rtb_callback, |
| 155 | }; |
| 156 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 157 | int msm_platform_secondary_init(unsigned int cpu) |
| 158 | { |
| 159 | int ret; |
| 160 | struct msm_hotplug_device *dev = &__get_cpu_var(msm_hotplug_devices); |
| 161 | |
| 162 | if (!dev->warm_boot) { |
| 163 | dev->warm_boot = 1; |
| 164 | init_completion(&dev->cpu_killed); |
| 165 | return 0; |
| 166 | } |
Pratik Patel | 17f3b82 | 2011-11-21 12:41:47 -0800 | [diff] [blame] | 167 | msm_jtag_restore_state(); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 168 | #if defined(CONFIG_VFP) && defined (CONFIG_CPU_PM) |
| 169 | vfp_pm_resume(); |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 170 | #endif |
| 171 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 172 | |
| 173 | return ret; |
| 174 | } |
Jeff Ohlstein | c05defe | 2012-01-31 19:53:16 -0800 | [diff] [blame] | 175 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 176 | static int __init init_hotplug(void) |
Jeff Ohlstein | c05defe | 2012-01-31 19:53:16 -0800 | [diff] [blame] | 177 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 178 | |
| 179 | struct msm_hotplug_device *dev = &__get_cpu_var(msm_hotplug_devices); |
| 180 | init_completion(&dev->cpu_killed); |
Jeff Ohlstein | c05defe | 2012-01-31 19:53:16 -0800 | [diff] [blame] | 181 | return register_hotcpu_notifier(&hotplug_rtb_notifier); |
| 182 | } |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 183 | early_initcall(init_hotplug); |