blob: 3f40a12b80dbeac4189e43bbc3bdf4a539db7cec [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 -070030int pen_release = -1;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080031
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032/* Initialize the present map (cpu_set(i, cpu_present_map)). */
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080033void __init platform_smp_prepare_cpus(unsigned int max_cpus)
34{
35 int i;
36
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080037 for (i = 0; i < max_cpus; i++)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070038 cpu_set(i, cpu_present_map);
39}
40
41void __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
51static 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 Moskovchenko20a12332011-09-13 13:54:59 -070097DEFINE_PER_CPU(int, cold_boot_done);
98
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070099/* 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*/
103int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
104{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700105 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 Moskovchenko20a12332011-09-13 13:54:59 -0700113 if (per_cpu(cold_boot_done, cpu) == false) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114 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 Moskovchenko20a12332011-09-13 13:54:59 -0700122 per_cpu(cold_boot_done, cpu) = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700123 }
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 Spivak0a42d692011-08-02 14:42:04 -0700139 usleep(500);
140 if (cnt++ >= 10)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141 break;
142 }
143
144 return 0;
145}
146
147/* Initialization routine for secondary CPUs after they are brought out of
148 * reset.
149*/
150void __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 Ohlsteine14411d2010-11-30 13:06:36 -0800170}