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