blob: c2008d6c72eb6b35bbbccdfc90fa56e98bd9b9e0 [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"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029#include "acpuclock.h"
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080030
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031#define SECONDARY_CPU_WAIT_MS 10
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080032
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033int pen_release = -1;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080034
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070035/* Initialize the present map (cpu_set(i, cpu_present_map)). */
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080036void __init platform_smp_prepare_cpus(unsigned int max_cpus)
37{
38 int i;
39
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080040 for (i = 0; i < max_cpus; i++)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041 cpu_set(i, cpu_present_map);
42}
43
44void __init smp_init_cpus(void)
45{
46 unsigned int i, ncores = get_core_count();
47
48 for (i = 0; i < ncores; i++)
49 cpu_set(i, cpu_possible_map);
50
51 set_smp_cross_call(gic_raise_softirq);
52}
53
54static void __cpuinit release_secondary(unsigned int cpu)
55{
56 void *base_ptr;
57
58 BUG_ON(cpu >= get_core_count());
59
60 /* KraitMP or ScorpionMP ? */
61 if ((read_cpuid_id() & 0xFF0) >> 4 != 0x2D) {
62 base_ptr = ioremap_nocache(0x02098000, SZ_4K);
63 if (base_ptr) {
64 if (machine_is_msm8960_sim() ||
65 machine_is_msm8960_rumi3()) {
66 writel_relaxed(0x10, base_ptr+0x04);
67 writel_relaxed(0x80, base_ptr+0x04);
68 } else if (get_core_count() == 2) {
69 writel_relaxed(0x109, base_ptr+0x04);
70 writel_relaxed(0x101, base_ptr+0x04);
71 ndelay(300);
72
73 writel_relaxed(0x121, base_ptr+0x04);
74 udelay(2);
75
76 writel_relaxed(0x020, base_ptr+0x04);
77 udelay(2);
78
79 writel_relaxed(0x000, base_ptr+0x04);
80 udelay(100);
81
82 writel_relaxed(0x080, base_ptr+0x04);
83 }
84 mb();
85 iounmap(base_ptr);
86 }
87 } else {
88 base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
89 if (base_ptr) {
90 writel_relaxed(0x0, base_ptr+0x15A0);
91 dmb();
92 writel_relaxed(0x0, base_ptr+0xD80);
93 writel_relaxed(0x3, base_ptr+0xE64);
94 mb();
95 iounmap(base_ptr);
96 }
97 }
98}
99
100/* Executed by primary CPU, brings other CPUs out of reset. Called at boot
101 as well as when a CPU is coming out of shutdown induced by echo 0 >
102 /sys/devices/.../cpuX.
103*/
104int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
105{
106 static int cold_boot_done;
107 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
115 if (cold_boot_done == false) {
116 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");
124 cold_boot_done = true;
125 }
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);
172
173 /* Setup acpuclock for non-primary CPU. */
174 acpuclock_secondary_init();
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800175}