Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 ARM Ltd. |
| 3 | * All Rights Reserved |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 4 | * Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -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 | |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 11 | #include <linux/kernel.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 12 | #include <linux/init.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 13 | #include <linux/cpumask.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 14 | #include <linux/delay.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 16 | #include <linux/io.h> |
| 17 | |
| 18 | #include <asm/hardware/gic.h> |
| 19 | #include <asm/cacheflush.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | #include <asm/cputype.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 21 | #include <asm/mach-types.h> |
| 22 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | #include <mach/socinfo.h> |
| 24 | #include <mach/smp.h> |
| 25 | #include <mach/hardware.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 26 | #include <mach/msm_iomap.h> |
| 27 | |
Matt Wagantall | 7cca464 | 2012-02-01 16:43:24 -0800 | [diff] [blame] | 28 | #include "pm.h" |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 29 | #include "scm-boot.h" |
Stepan Moskovchenko | 9bbe585 | 2012-01-09 13:28:28 -0800 | [diff] [blame] | 30 | #include "spm.h" |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 31 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 32 | int pen_release = -1; |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 33 | |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 34 | void __init platform_smp_prepare_cpus(unsigned int max_cpus) |
| 35 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void __init smp_init_cpus(void) |
| 39 | { |
| 40 | unsigned int i, ncores = get_core_count(); |
| 41 | |
| 42 | for (i = 0; i < ncores; i++) |
| 43 | cpu_set(i, cpu_possible_map); |
| 44 | |
| 45 | set_smp_cross_call(gic_raise_softirq); |
| 46 | } |
| 47 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 48 | static int __cpuinit scorpion_release_secondary(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 49 | { |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 50 | void *base_ptr = ioremap_nocache(0x00902000, SZ_4K*2); |
| 51 | if (!base_ptr) |
| 52 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 53 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 54 | writel_relaxed(0x0, base_ptr+0x15A0); |
| 55 | dmb(); |
| 56 | writel_relaxed(0x0, base_ptr+0xD80); |
| 57 | writel_relaxed(0x3, base_ptr+0xE64); |
| 58 | mb(); |
| 59 | iounmap(base_ptr); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 64 | static int __cpuinit krait_release_secondary_sim(unsigned long base, int cpu) |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 65 | { |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 66 | void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 67 | if (!base_ptr) |
| 68 | return -ENODEV; |
| 69 | |
| 70 | if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3()) { |
| 71 | writel_relaxed(0x10, base_ptr+0x04); |
| 72 | writel_relaxed(0x80, base_ptr+0x04); |
| 73 | } |
| 74 | |
| 75 | if (machine_is_apq8064_sim()) |
| 76 | writel_relaxed(0xf0000, base_ptr+0x04); |
| 77 | |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 78 | if (machine_is_copper_sim()) |
| 79 | writel_relaxed(0x9, base_ptr+0x04); |
| 80 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 81 | mb(); |
| 82 | iounmap(base_ptr); |
| 83 | return 0; |
| 84 | } |
| 85 | |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 86 | static int __cpuinit krait_release_secondary(unsigned long base, int cpu) |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 87 | { |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 88 | void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 89 | if (!base_ptr) |
| 90 | return -ENODEV; |
| 91 | |
Stepan Moskovchenko | 9bbe585 | 2012-01-09 13:28:28 -0800 | [diff] [blame] | 92 | msm_spm_turn_on_cpu_rail(cpu); |
| 93 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 94 | writel_relaxed(0x109, base_ptr+0x04); |
| 95 | writel_relaxed(0x101, base_ptr+0x04); |
| 96 | ndelay(300); |
| 97 | |
| 98 | writel_relaxed(0x121, base_ptr+0x04); |
| 99 | udelay(2); |
| 100 | |
| 101 | writel_relaxed(0x020, base_ptr+0x04); |
| 102 | udelay(2); |
| 103 | |
| 104 | writel_relaxed(0x000, base_ptr+0x04); |
| 105 | udelay(100); |
| 106 | |
| 107 | writel_relaxed(0x080, base_ptr+0x04); |
| 108 | mb(); |
| 109 | iounmap(base_ptr); |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static int __cpuinit release_secondary(unsigned int cpu) |
| 114 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 115 | BUG_ON(cpu >= get_core_count()); |
| 116 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 117 | if (cpu_is_msm8x60()) |
| 118 | return scorpion_release_secondary(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 119 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 120 | if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3() || |
| 121 | machine_is_apq8064_sim()) |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 122 | return krait_release_secondary_sim(0x02088000, cpu); |
| 123 | |
| 124 | if (machine_is_copper_sim()) |
| 125 | return krait_release_secondary_sim(0xf9088000, cpu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 126 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 127 | if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_apq8064()) |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 128 | return krait_release_secondary(0x02088000, cpu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 129 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 130 | WARN(1, "unknown CPU case in release_secondary\n"); |
| 131 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 134 | DEFINE_PER_CPU(int, cold_boot_done); |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 135 | static int cold_boot_flags[] = { |
| 136 | 0, |
| 137 | SCM_FLAG_COLDBOOT_CPU1, |
| 138 | SCM_FLAG_COLDBOOT_CPU2, |
| 139 | SCM_FLAG_COLDBOOT_CPU3, |
| 140 | }; |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 141 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 142 | /* Executed by primary CPU, brings other CPUs out of reset. Called at boot |
| 143 | as well as when a CPU is coming out of shutdown induced by echo 0 > |
| 144 | /sys/devices/.../cpuX. |
| 145 | */ |
| 146 | int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 147 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 148 | int cnt = 0; |
| 149 | int ret; |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 150 | int flag = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 151 | |
| 152 | pr_debug("Starting secondary CPU %d\n", cpu); |
| 153 | |
| 154 | /* Set preset_lpj to avoid subsequent lpj recalculations */ |
| 155 | preset_lpj = loops_per_jiffy; |
| 156 | |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 157 | if (cpu > 0 && cpu < ARRAY_SIZE(cold_boot_flags)) |
| 158 | flag = cold_boot_flags[cpu]; |
| 159 | else |
| 160 | __WARN(); |
| 161 | |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 162 | if (per_cpu(cold_boot_done, cpu) == false) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 163 | ret = scm_set_boot_addr((void *) |
| 164 | virt_to_phys(msm_secondary_startup), |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 165 | flag); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 166 | if (ret == 0) |
| 167 | release_secondary(cpu); |
| 168 | else |
| 169 | printk(KERN_DEBUG "Failed to set secondary core boot " |
| 170 | "address\n"); |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 171 | per_cpu(cold_boot_done, cpu) = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | pen_release = cpu; |
| 175 | dmac_flush_range((void *)&pen_release, |
| 176 | (void *)(&pen_release + sizeof(pen_release))); |
| 177 | __asm__("sev"); |
| 178 | mb(); |
| 179 | |
| 180 | /* Use smp_cross_call() to send a soft interrupt to wake up |
| 181 | * the other core. |
| 182 | */ |
| 183 | gic_raise_softirq(cpumask_of(cpu), 1); |
| 184 | |
| 185 | while (pen_release != 0xFFFFFFFF) { |
| 186 | dmac_inv_range((void *)&pen_release, |
| 187 | (void *)(&pen_release+sizeof(pen_release))); |
Maya Spivak | 0a42d69 | 2011-08-02 14:42:04 -0700 | [diff] [blame] | 188 | usleep(500); |
| 189 | if (cnt++ >= 10) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 190 | break; |
| 191 | } |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | /* Initialization routine for secondary CPUs after they are brought out of |
| 197 | * reset. |
| 198 | */ |
| 199 | void __cpuinit platform_secondary_init(unsigned int cpu) |
| 200 | { |
| 201 | pr_debug("CPU%u: Booted secondary processor\n", cpu); |
| 202 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 203 | WARN_ON(msm_platform_secondary_init(cpu)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 204 | |
| 205 | trace_hardirqs_off(); |
| 206 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 207 | gic_secondary_init(0); |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 208 | } |