Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 ARM Ltd. |
| 3 | * All Rights Reserved |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4 | * Copyright (c) 2010-2011, 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 | |
| 11 | #include <linux/init.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 12 | #include <linux/cpumask.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 13 | #include <linux/delay.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 15 | #include <linux/io.h> |
| 16 | |
| 17 | #include <asm/hardware/gic.h> |
| 18 | #include <asm/cacheflush.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 19 | #include <asm/cputype.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 20 | #include <asm/mach-types.h> |
| 21 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | #include <mach/socinfo.h> |
| 23 | #include <mach/smp.h> |
| 24 | #include <mach/hardware.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 25 | #include <mach/msm_iomap.h> |
| 26 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | #include "pm.h" |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 28 | #include "scm-boot.h" |
| 29 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | int pen_release = -1; |
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 | /* Initialize the present map (cpu_set(i, cpu_present_map)). */ |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 33 | void __init platform_smp_prepare_cpus(unsigned int max_cpus) |
| 34 | { |
| 35 | int i; |
| 36 | |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 37 | for (i = 0; i < max_cpus; i++) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | cpu_set(i, cpu_present_map); |
| 39 | } |
| 40 | |
| 41 | void __init smp_init_cpus(void) |
| 42 | { |
| 43 | unsigned int i, ncores = get_core_count(); |
| 44 | |
| 45 | for (i = 0; i < ncores; i++) |
| 46 | cpu_set(i, cpu_possible_map); |
| 47 | |
| 48 | set_smp_cross_call(gic_raise_softirq); |
| 49 | } |
| 50 | |
| 51 | static void __cpuinit release_secondary(unsigned int cpu) |
| 52 | { |
| 53 | void *base_ptr; |
| 54 | |
| 55 | BUG_ON(cpu >= get_core_count()); |
| 56 | |
| 57 | /* KraitMP or ScorpionMP ? */ |
| 58 | if ((read_cpuid_id() & 0xFF0) >> 4 != 0x2D) { |
| 59 | base_ptr = ioremap_nocache(0x02098000, SZ_4K); |
| 60 | if (base_ptr) { |
| 61 | if (machine_is_msm8960_sim() || |
| 62 | machine_is_msm8960_rumi3()) { |
| 63 | writel_relaxed(0x10, base_ptr+0x04); |
| 64 | writel_relaxed(0x80, base_ptr+0x04); |
| 65 | } else if (get_core_count() == 2) { |
| 66 | writel_relaxed(0x109, base_ptr+0x04); |
| 67 | writel_relaxed(0x101, base_ptr+0x04); |
| 68 | ndelay(300); |
| 69 | |
| 70 | writel_relaxed(0x121, base_ptr+0x04); |
| 71 | udelay(2); |
| 72 | |
| 73 | writel_relaxed(0x020, base_ptr+0x04); |
| 74 | udelay(2); |
| 75 | |
| 76 | writel_relaxed(0x000, base_ptr+0x04); |
| 77 | udelay(100); |
| 78 | |
| 79 | writel_relaxed(0x080, base_ptr+0x04); |
| 80 | } |
| 81 | mb(); |
| 82 | iounmap(base_ptr); |
| 83 | } |
| 84 | } else { |
| 85 | base_ptr = ioremap_nocache(0x00902000, SZ_4K*2); |
| 86 | if (base_ptr) { |
| 87 | writel_relaxed(0x0, base_ptr+0x15A0); |
| 88 | dmb(); |
| 89 | writel_relaxed(0x0, base_ptr+0xD80); |
| 90 | writel_relaxed(0x3, base_ptr+0xE64); |
| 91 | mb(); |
| 92 | iounmap(base_ptr); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 97 | DEFINE_PER_CPU(int, cold_boot_done); |
| 98 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 99 | /* Executed by primary CPU, brings other CPUs out of reset. Called at boot |
| 100 | as well as when a CPU is coming out of shutdown induced by echo 0 > |
| 101 | /sys/devices/.../cpuX. |
| 102 | */ |
| 103 | int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 104 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 105 | int cnt = 0; |
| 106 | int ret; |
| 107 | |
| 108 | pr_debug("Starting secondary CPU %d\n", cpu); |
| 109 | |
| 110 | /* Set preset_lpj to avoid subsequent lpj recalculations */ |
| 111 | preset_lpj = loops_per_jiffy; |
| 112 | |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 113 | if (per_cpu(cold_boot_done, cpu) == false) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 114 | ret = scm_set_boot_addr((void *) |
| 115 | virt_to_phys(msm_secondary_startup), |
| 116 | SCM_FLAG_COLDBOOT_CPU1); |
| 117 | if (ret == 0) |
| 118 | release_secondary(cpu); |
| 119 | else |
| 120 | printk(KERN_DEBUG "Failed to set secondary core boot " |
| 121 | "address\n"); |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 122 | per_cpu(cold_boot_done, cpu) = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | pen_release = cpu; |
| 126 | dmac_flush_range((void *)&pen_release, |
| 127 | (void *)(&pen_release + sizeof(pen_release))); |
| 128 | __asm__("sev"); |
| 129 | mb(); |
| 130 | |
| 131 | /* Use smp_cross_call() to send a soft interrupt to wake up |
| 132 | * the other core. |
| 133 | */ |
| 134 | gic_raise_softirq(cpumask_of(cpu), 1); |
| 135 | |
| 136 | while (pen_release != 0xFFFFFFFF) { |
| 137 | dmac_inv_range((void *)&pen_release, |
| 138 | (void *)(&pen_release+sizeof(pen_release))); |
Maya Spivak | 0a42d69 | 2011-08-02 14:42:04 -0700 | [diff] [blame^] | 139 | usleep(500); |
| 140 | if (cnt++ >= 10) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 141 | break; |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | /* Initialization routine for secondary CPUs after they are brought out of |
| 148 | * reset. |
| 149 | */ |
| 150 | void __cpuinit platform_secondary_init(unsigned int cpu) |
| 151 | { |
| 152 | pr_debug("CPU%u: Booted secondary processor\n", cpu); |
| 153 | |
| 154 | #ifdef CONFIG_HOTPLUG_CPU |
| 155 | WARN_ON(msm_pm_platform_secondary_init(cpu)); |
| 156 | #endif |
| 157 | |
| 158 | trace_hardirqs_off(); |
| 159 | |
| 160 | /* Edge trigger PPIs except AVS_SVICINT and AVS_SVICINTSWDONE */ |
| 161 | writel(0xFFFFD7FF, MSM_QGIC_DIST_BASE + GIC_DIST_CONFIG + 4); |
| 162 | |
| 163 | /* RUMI does not adhere to GIC spec by enabling STIs by default. |
| 164 | * Enable/clear is supposed to be RO for STIs, but is RW on RUMI. |
| 165 | */ |
| 166 | if (!machine_is_msm8x60_sim()) |
| 167 | writel(0x0000FFFF, MSM_QGIC_DIST_BASE + GIC_DIST_ENABLE_SET); |
| 168 | |
| 169 | gic_secondary_init(0); |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 170 | } |