| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  *  Copyright (C) 2002 ARM Ltd. | 
 | 3 |  *  All Rights Reserved | 
 | 4 |  *  Copyright (c) 2010, Code Aurora Forum. All rights reserved. | 
 | 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> | 
 | 12 | #include <linux/errno.h> | 
 | 13 | #include <linux/delay.h> | 
 | 14 | #include <linux/device.h> | 
 | 15 | #include <linux/jiffies.h> | 
 | 16 | #include <linux/smp.h> | 
 | 17 | #include <linux/io.h> | 
 | 18 |  | 
 | 19 | #include <asm/hardware/gic.h> | 
 | 20 | #include <asm/cacheflush.h> | 
| Jeff Ohlstein | 41ff445 | 2011-04-07 17:41:09 -0700 | [diff] [blame] | 21 | #include <asm/cputype.h> | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 22 | #include <asm/mach-types.h> | 
| Will Deacon | eb50439 | 2012-01-20 12:01:12 +0100 | [diff] [blame] | 23 | #include <asm/smp_plat.h> | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 24 |  | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 25 | #include "scm-boot.h" | 
| David Brown | be2109e | 2012-09-12 16:01:40 -0700 | [diff] [blame] | 26 | #include "common.h" | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 27 |  | 
 | 28 | #define VDD_SC1_ARRAY_CLAMP_GFS_CTL 0x15A0 | 
 | 29 | #define SCSS_CPU1CORE_RESET 0xD80 | 
 | 30 | #define SCSS_DBG_STATUS_CORE_PWRDUP 0xE64 | 
 | 31 |  | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 32 | extern void msm_secondary_startup(void); | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 33 |  | 
 | 34 | static DEFINE_SPINLOCK(boot_lock); | 
 | 35 |  | 
| Jeff Ohlstein | 41ff445 | 2011-04-07 17:41:09 -0700 | [diff] [blame] | 36 | static inline int get_core_count(void) | 
 | 37 | { | 
 | 38 | 	/* 1 + the PART[1:0] field of MIDR */ | 
 | 39 | 	return ((read_cpuid_id() >> 4) & 3) + 1; | 
 | 40 | } | 
 | 41 |  | 
| Marc Zyngier | 44ea349 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 42 | static void __cpuinit msm_secondary_init(unsigned int cpu) | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 43 | { | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 44 | 	/* | 
 | 45 | 	 * if any interrupts are already enabled for the primary | 
 | 46 | 	 * core (e.g. timer irq), then they will not have been enabled | 
 | 47 | 	 * for us: do so | 
 | 48 | 	 */ | 
 | 49 | 	gic_secondary_init(0); | 
 | 50 |  | 
 | 51 | 	/* | 
 | 52 | 	 * let the primary processor know we're out of the | 
 | 53 | 	 * pen, then head off into the C entry point | 
 | 54 | 	 */ | 
 | 55 | 	pen_release = -1; | 
 | 56 | 	smp_wmb(); | 
 | 57 |  | 
 | 58 | 	/* | 
 | 59 | 	 * Synchronise with the boot thread. | 
 | 60 | 	 */ | 
 | 61 | 	spin_lock(&boot_lock); | 
 | 62 | 	spin_unlock(&boot_lock); | 
 | 63 | } | 
 | 64 |  | 
 | 65 | static __cpuinit void prepare_cold_cpu(unsigned int cpu) | 
 | 66 | { | 
 | 67 | 	int ret; | 
 | 68 | 	ret = scm_set_boot_addr(virt_to_phys(msm_secondary_startup), | 
 | 69 | 				SCM_FLAG_COLDBOOT_CPU1); | 
 | 70 | 	if (ret == 0) { | 
| Stephen Boyd | 2b222a2 | 2011-09-19 10:54:04 -0700 | [diff] [blame] | 71 | 		void __iomem *sc1_base_ptr; | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 72 | 		sc1_base_ptr = ioremap_nocache(0x00902000, SZ_4K*2); | 
 | 73 | 		if (sc1_base_ptr) { | 
 | 74 | 			writel(0, sc1_base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL); | 
 | 75 | 			writel(0, sc1_base_ptr + SCSS_CPU1CORE_RESET); | 
 | 76 | 			writel(3, sc1_base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP); | 
 | 77 | 			iounmap(sc1_base_ptr); | 
 | 78 | 		} | 
 | 79 | 	} else | 
 | 80 | 		printk(KERN_DEBUG "Failed to set secondary core boot " | 
 | 81 | 				  "address\n"); | 
 | 82 | } | 
 | 83 |  | 
| Marc Zyngier | 44ea349 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 84 | static int __cpuinit msm_boot_secondary(unsigned int cpu, struct task_struct *idle) | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 85 | { | 
 | 86 | 	unsigned long timeout; | 
 | 87 | 	static int cold_boot_done; | 
 | 88 |  | 
 | 89 | 	/* Only need to bring cpu out of reset this way once */ | 
 | 90 | 	if (cold_boot_done == false) { | 
 | 91 | 		prepare_cold_cpu(cpu); | 
 | 92 | 		cold_boot_done = true; | 
 | 93 | 	} | 
 | 94 |  | 
 | 95 | 	/* | 
 | 96 | 	 * set synchronisation state between this boot processor | 
 | 97 | 	 * and the secondary one | 
 | 98 | 	 */ | 
 | 99 | 	spin_lock(&boot_lock); | 
 | 100 |  | 
 | 101 | 	/* | 
 | 102 | 	 * The secondary processor is waiting to be released from | 
 | 103 | 	 * the holding pen - release it, then wait for it to flag | 
 | 104 | 	 * that it has been released by resetting pen_release. | 
 | 105 | 	 * | 
 | 106 | 	 * Note that "pen_release" is the hardware CPU ID, whereas | 
 | 107 | 	 * "cpu" is Linux's internal ID. | 
 | 108 | 	 */ | 
| Will Deacon | 1d3cfb3 | 2011-08-09 12:02:27 +0100 | [diff] [blame] | 109 | 	pen_release = cpu_logical_map(cpu); | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 110 | 	__cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release)); | 
 | 111 | 	outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1)); | 
 | 112 |  | 
 | 113 | 	/* | 
 | 114 | 	 * Send the secondary CPU a soft interrupt, thereby causing | 
 | 115 | 	 * the boot monitor to read the system wide flags register, | 
 | 116 | 	 * and branch to the address found there. | 
 | 117 | 	 */ | 
| Russell King | ffae894 | 2012-06-11 20:24:44 +0100 | [diff] [blame] | 118 | 	gic_raise_softirq(cpumask_of(cpu), 0); | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 119 |  | 
 | 120 | 	timeout = jiffies + (1 * HZ); | 
 | 121 | 	while (time_before(jiffies, timeout)) { | 
 | 122 | 		smp_rmb(); | 
 | 123 | 		if (pen_release == -1) | 
 | 124 | 			break; | 
 | 125 |  | 
 | 126 | 		udelay(10); | 
 | 127 | 	} | 
 | 128 |  | 
 | 129 | 	/* | 
 | 130 | 	 * now the secondary core is starting up let it run its | 
 | 131 | 	 * calibrations, then wait for it to finish | 
 | 132 | 	 */ | 
 | 133 | 	spin_unlock(&boot_lock); | 
 | 134 |  | 
 | 135 | 	return pen_release != -1 ? -ENOSYS : 0; | 
 | 136 | } | 
 | 137 |  | 
 | 138 | /* | 
 | 139 |  * Initialise the CPU possible map early - this describes the CPUs | 
 | 140 |  * which may be present or become present in the system. The msm8x60 | 
 | 141 |  * does not support the ARM SCU, so just set the possible cpu mask to | 
 | 142 |  * NR_CPUS. | 
 | 143 |  */ | 
| Marc Zyngier | 44ea349 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 144 | static void __init msm_smp_init_cpus(void) | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 145 | { | 
| Jeff Ohlstein | 41ff445 | 2011-04-07 17:41:09 -0700 | [diff] [blame] | 146 | 	unsigned int i, ncores = get_core_count(); | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 147 |  | 
| Russell King | a06f916 | 2011-10-20 22:04:18 +0100 | [diff] [blame] | 148 | 	if (ncores > nr_cpu_ids) { | 
 | 149 | 		pr_warn("SMP: %u cores greater than maximum (%u), clipping\n", | 
 | 150 | 			ncores, nr_cpu_ids); | 
 | 151 | 		ncores = nr_cpu_ids; | 
 | 152 | 	} | 
 | 153 |  | 
| Jeff Ohlstein | 41ff445 | 2011-04-07 17:41:09 -0700 | [diff] [blame] | 154 | 	for (i = 0; i < ncores; i++) | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 155 | 		set_cpu_possible(i, true); | 
| Russell King | 0f7b332 | 2011-04-03 13:01:30 +0100 | [diff] [blame] | 156 |  | 
 | 157 |         set_smp_cross_call(gic_raise_softirq); | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 158 | } | 
 | 159 |  | 
| Marc Zyngier | 44ea349 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 160 | static void __init msm_smp_prepare_cpus(unsigned int max_cpus) | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 161 | { | 
| Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 162 | } | 
| Marc Zyngier | 44ea349 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 163 |  | 
 | 164 | struct smp_operations msm_smp_ops __initdata = { | 
 | 165 | 	.smp_init_cpus		= msm_smp_init_cpus, | 
 | 166 | 	.smp_prepare_cpus	= msm_smp_prepare_cpus, | 
 | 167 | 	.smp_secondary_init	= msm_secondary_init, | 
 | 168 | 	.smp_boot_secondary	= msm_boot_secondary, | 
 | 169 | #ifdef CONFIG_HOTPLUG_CPU | 
 | 170 | 	.cpu_die		= msm_cpu_die, | 
 | 171 | #endif | 
 | 172 | }; |