blob: 1a92e071bd61335e423f2f8aa13b3f888b4c1747 [file] [log] [blame]
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +01001/*
2 * Copyright (C) 2002 ARM Ltd.
3 * Copyright (C) 2008 STMicroelctronics.
4 * Copyright (C) 2009 ST-Ericsson.
5 * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
6 *
7 * This file is based on arm realview platform
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#include <linux/init.h>
14#include <linux/errno.h>
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <linux/smp.h>
18#include <linux/io.h>
19
20#include <asm/cacheflush.h>
Russell King0f7b3322011-04-03 13:01:30 +010021#include <asm/hardware/gic.h>
Will Deaconeb504392012-01-20 12:01:12 +010022#include <asm/smp_plat.h>
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010023#include <asm/smp_scu.h>
Linus Walleij7a4f2602012-09-19 19:31:19 +020024
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010025#include <mach/hardware.h>
Rabin Vincent92389ca2010-12-08 11:07:57 +053026#include <mach/setup.h>
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010027
Linus Walleij7a4f2602012-09-19 19:31:19 +020028#include "id.h"
29
Linus Walleij4d5336d2011-05-06 12:56:27 +010030/* This is called from headsmp.S to wakeup the secondary core */
31extern void u8500_secondary_startup(void);
32
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010033/*
Russell King3705ff62010-12-18 10:53:12 +000034 * Write pen_release in a way that is guaranteed to be visible to all
35 * observers, irrespective of whether they're taking part in coherency
36 * or not. This is necessary for the hotplug code to work reliably.
37 */
38static void write_pen_release(int val)
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010039{
Russell King3705ff62010-12-18 10:53:12 +000040 pen_release = val;
41 smp_wmb();
42 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
43 outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010044}
45
Rabin Vincent92389ca2010-12-08 11:07:57 +053046static void __iomem *scu_base_addr(void)
47{
Linus Walleije1bbb552012-08-09 17:10:36 +020048 if (cpu_is_u8500_family() || cpu_is_ux540_family())
Rabin Vincent92389ca2010-12-08 11:07:57 +053049 return __io_address(U8500_SCU_BASE);
50 else
51 ux500_unknown_soc();
52
53 return NULL;
54}
55
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010056static DEFINE_SPINLOCK(boot_lock);
57
Marc Zyngier5ac21a92011-09-08 13:15:22 +010058static void __cpuinit ux500_secondary_init(unsigned int cpu)
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010059{
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010060 /*
61 * if any interrupts are already enabled for the primary
62 * core (e.g. timer irq), then they will not have been enabled
63 * for us: do so
64 */
Russell King38489532010-12-04 16:01:03 +000065 gic_secondary_init(0);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010066
67 /*
68 * let the primary processor know we're out of the
69 * pen, then head off into the C entry point
70 */
Russell King3705ff62010-12-18 10:53:12 +000071 write_pen_release(-1);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010072
73 /*
74 * Synchronise with the boot thread.
75 */
76 spin_lock(&boot_lock);
77 spin_unlock(&boot_lock);
78}
79
Marc Zyngier5ac21a92011-09-08 13:15:22 +010080static int __cpuinit ux500_boot_secondary(unsigned int cpu, struct task_struct *idle)
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010081{
82 unsigned long timeout;
83
84 /*
85 * set synchronisation state between this boot processor
86 * and the secondary one
87 */
88 spin_lock(&boot_lock);
89
90 /*
91 * The secondary processor is waiting to be released from
92 * the holding pen - release it, then wait for it to flag
93 * that it has been released by resetting pen_release.
94 */
Will Deacon28763482011-08-09 12:21:36 +010095 write_pen_release(cpu_logical_map(cpu));
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010096
Jonas Aaberg7d28e3e2011-12-22 09:22:56 +010097 smp_send_reschedule(cpu);
Sundar Iyer9d704c02010-09-15 10:45:51 +010098
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010099 timeout = jiffies + (1 * HZ);
100 while (time_before(jiffies, timeout)) {
101 if (pen_release == -1)
102 break;
103 }
104
105 /*
106 * now the secondary core is starting up let it run its
107 * calibrations, then wait for it to finish
108 */
109 spin_unlock(&boot_lock);
110
111 return pen_release != -1 ? -ENOSYS : 0;
112}
113
114static void __init wakeup_secondary(void)
115{
Rabin Vincent92389ca2010-12-08 11:07:57 +0530116 void __iomem *backupram;
117
Loic PALLARDY79964bc2012-09-03 15:10:23 +0200118 if (cpu_is_u8500_family() || cpu_is_ux540_family())
Rabin Vincent92389ca2010-12-08 11:07:57 +0530119 backupram = __io_address(U8500_BACKUPRAM0_BASE);
120 else
121 ux500_unknown_soc();
122
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100123 /*
124 * write the address of secondary startup into the backup ram register
125 * at offset 0x1FF4, then write the magic number 0xA1FEED01 to the
126 * backup ram register at offset 0x1FF0, which is what boot rom code
127 * is waiting for. This would wake up the secondary core from WFE
128 */
Rabin Vincent92389ca2010-12-08 11:07:57 +0530129#define UX500_CPU1_JUMPADDR_OFFSET 0x1FF4
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100130 __raw_writel(virt_to_phys(u8500_secondary_startup),
Rabin Vincent92389ca2010-12-08 11:07:57 +0530131 backupram + UX500_CPU1_JUMPADDR_OFFSET);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100132
Rabin Vincent92389ca2010-12-08 11:07:57 +0530133#define UX500_CPU1_WAKEMAGIC_OFFSET 0x1FF0
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100134 __raw_writel(0xA1FEED01,
Rabin Vincent92389ca2010-12-08 11:07:57 +0530135 backupram + UX500_CPU1_WAKEMAGIC_OFFSET);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100136
137 /* make sure write buffer is drained */
138 mb();
139}
140
141/*
142 * Initialise the CPU possible map early - this describes the CPUs
143 * which may be present or become present in the system.
144 */
Marc Zyngier5ac21a92011-09-08 13:15:22 +0100145static void __init ux500_smp_init_cpus(void)
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100146{
Rabin Vincent92389ca2010-12-08 11:07:57 +0530147 void __iomem *scu_base = scu_base_addr();
Russell Kingfd778f02010-12-02 18:09:37 +0000148 unsigned int i, ncores;
149
Rabin Vincent92389ca2010-12-08 11:07:57 +0530150 ncores = scu_base ? scu_get_core_count(scu_base) : 1;
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100151
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100152 /* sanity check */
Russell Kinga06f9162011-10-20 22:04:18 +0100153 if (ncores > nr_cpu_ids) {
154 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
155 ncores, nr_cpu_ids);
156 ncores = nr_cpu_ids;
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100157 }
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100158
159 for (i = 0; i < ncores; i++)
160 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100161
162 set_smp_cross_call(gic_raise_softirq);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100163}
164
Marc Zyngier5ac21a92011-09-08 13:15:22 +0100165static void __init ux500_smp_prepare_cpus(unsigned int max_cpus)
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100166{
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100167
Rabin Vincent92389ca2010-12-08 11:07:57 +0530168 scu_enable(scu_base_addr());
Russell King05c74a62010-12-03 11:09:48 +0000169 wakeup_secondary();
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100170}
Marc Zyngier5ac21a92011-09-08 13:15:22 +0100171
172struct smp_operations ux500_smp_ops __initdata = {
173 .smp_init_cpus = ux500_smp_init_cpus,
174 .smp_prepare_cpus = ux500_smp_prepare_cpus,
175 .smp_secondary_init = ux500_secondary_init,
176 .smp_boot_secondary = ux500_boot_secondary,
177#ifdef CONFIG_HOTPLUG_CPU
178 .cpu_die = ux500_cpu_die,
179#endif
180};