blob: da1d5ad5bd4531ae3d142e8a65f39de6d67eae56 [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>
24#include <mach/hardware.h>
Rabin Vincent92389ca2010-12-08 11:07:57 +053025#include <mach/setup.h>
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010026
Linus Walleij4d5336d2011-05-06 12:56:27 +010027/* This is called from headsmp.S to wakeup the secondary core */
28extern void u8500_secondary_startup(void);
29
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010030/*
31 * control for which core is the next to come out of the secondary
32 * boot "holding pen"
33 */
Jonas Aaberg3c5728e2010-12-15 08:36:02 +010034volatile int pen_release = -1;
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010035
Russell King3705ff62010-12-18 10:53:12 +000036/*
37 * Write pen_release in a way that is guaranteed to be visible to all
38 * observers, irrespective of whether they're taking part in coherency
39 * or not. This is necessary for the hotplug code to work reliably.
40 */
41static void write_pen_release(int val)
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010042{
Russell King3705ff62010-12-18 10:53:12 +000043 pen_release = val;
44 smp_wmb();
45 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
46 outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010047}
48
Rabin Vincent92389ca2010-12-08 11:07:57 +053049static void __iomem *scu_base_addr(void)
50{
Arnd Bergmann815aceb2012-05-14 16:29:32 +020051 if (cpu_is_u8500_family())
Rabin Vincent92389ca2010-12-08 11:07:57 +053052 return __io_address(U8500_SCU_BASE);
53 else
54 ux500_unknown_soc();
55
56 return NULL;
57}
58
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010059static DEFINE_SPINLOCK(boot_lock);
60
61void __cpuinit platform_secondary_init(unsigned int cpu)
62{
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010063 /*
64 * if any interrupts are already enabled for the primary
65 * core (e.g. timer irq), then they will not have been enabled
66 * for us: do so
67 */
Russell King38489532010-12-04 16:01:03 +000068 gic_secondary_init(0);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010069
70 /*
71 * let the primary processor know we're out of the
72 * pen, then head off into the C entry point
73 */
Russell King3705ff62010-12-18 10:53:12 +000074 write_pen_release(-1);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010075
76 /*
77 * Synchronise with the boot thread.
78 */
79 spin_lock(&boot_lock);
80 spin_unlock(&boot_lock);
81}
82
83int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
84{
85 unsigned long timeout;
86
87 /*
88 * set synchronisation state between this boot processor
89 * and the secondary one
90 */
91 spin_lock(&boot_lock);
92
93 /*
94 * The secondary processor is waiting to be released from
95 * the holding pen - release it, then wait for it to flag
96 * that it has been released by resetting pen_release.
97 */
Will Deacon28763482011-08-09 12:21:36 +010098 write_pen_release(cpu_logical_map(cpu));
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010099
Jonas Aaberg7d28e3e2011-12-22 09:22:56 +0100100 smp_send_reschedule(cpu);
Sundar Iyer9d704c02010-09-15 10:45:51 +0100101
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100102 timeout = jiffies + (1 * HZ);
103 while (time_before(jiffies, timeout)) {
104 if (pen_release == -1)
105 break;
106 }
107
108 /*
109 * now the secondary core is starting up let it run its
110 * calibrations, then wait for it to finish
111 */
112 spin_unlock(&boot_lock);
113
114 return pen_release != -1 ? -ENOSYS : 0;
115}
116
117static void __init wakeup_secondary(void)
118{
Rabin Vincent92389ca2010-12-08 11:07:57 +0530119 void __iomem *backupram;
120
Arnd Bergmann815aceb2012-05-14 16:29:32 +0200121 if (cpu_is_u8500_family())
Rabin Vincent92389ca2010-12-08 11:07:57 +0530122 backupram = __io_address(U8500_BACKUPRAM0_BASE);
123 else
124 ux500_unknown_soc();
125
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100126 /*
127 * write the address of secondary startup into the backup ram register
128 * at offset 0x1FF4, then write the magic number 0xA1FEED01 to the
129 * backup ram register at offset 0x1FF0, which is what boot rom code
130 * is waiting for. This would wake up the secondary core from WFE
131 */
Rabin Vincent92389ca2010-12-08 11:07:57 +0530132#define UX500_CPU1_JUMPADDR_OFFSET 0x1FF4
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100133 __raw_writel(virt_to_phys(u8500_secondary_startup),
Rabin Vincent92389ca2010-12-08 11:07:57 +0530134 backupram + UX500_CPU1_JUMPADDR_OFFSET);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100135
Rabin Vincent92389ca2010-12-08 11:07:57 +0530136#define UX500_CPU1_WAKEMAGIC_OFFSET 0x1FF0
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100137 __raw_writel(0xA1FEED01,
Rabin Vincent92389ca2010-12-08 11:07:57 +0530138 backupram + UX500_CPU1_WAKEMAGIC_OFFSET);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100139
140 /* make sure write buffer is drained */
141 mb();
142}
143
144/*
145 * Initialise the CPU possible map early - this describes the CPUs
146 * which may be present or become present in the system.
147 */
148void __init smp_init_cpus(void)
149{
Rabin Vincent92389ca2010-12-08 11:07:57 +0530150 void __iomem *scu_base = scu_base_addr();
Russell Kingfd778f02010-12-02 18:09:37 +0000151 unsigned int i, ncores;
152
Rabin Vincent92389ca2010-12-08 11:07:57 +0530153 ncores = scu_base ? scu_get_core_count(scu_base) : 1;
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100154
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100155 /* sanity check */
Russell Kinga06f9162011-10-20 22:04:18 +0100156 if (ncores > nr_cpu_ids) {
157 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
158 ncores, nr_cpu_ids);
159 ncores = nr_cpu_ids;
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100160 }
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100161
162 for (i = 0; i < ncores; i++)
163 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100164
165 set_smp_cross_call(gic_raise_softirq);
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100166}
167
Russell King05c74a62010-12-03 11:09:48 +0000168void __init platform_smp_prepare_cpus(unsigned int max_cpus)
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100169{
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100170
Rabin Vincent92389ca2010-12-08 11:07:57 +0530171 scu_enable(scu_base_addr());
Russell King05c74a62010-12-03 11:09:48 +0000172 wakeup_secondary();
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100173}