blob: 248196809202337407044a7d649caef5d4a79e03 [file] [log] [blame]
Dinh Nguyen9c4566a2012-10-25 10:41:39 -06001/*
2 * Copyright 2010-2011 Calxeda, Inc.
3 * Copyright 2012 Pavel Machek <pavel@denx.de>
4 * Based on platsmp.c, Copyright (C) 2002 ARM Ltd.
5 * Copyright (C) 2012 Altera Corporation
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#include <linux/delay.h>
20#include <linux/init.h>
21#include <linux/smp.h>
22#include <linux/io.h>
23#include <linux/of.h>
24#include <linux/of_address.h>
25
26#include <asm/cacheflush.h>
27#include <asm/hardware/gic.h>
28#include <asm/smp_scu.h>
29#include <asm/smp_plat.h>
30
31#include "core.h"
32
33extern void __iomem *sys_manager_base_addr;
34extern void __iomem *rst_manager_base_addr;
35
36static void __cpuinit socfpga_secondary_init(unsigned int cpu)
37{
38 /*
39 * if any interrupts are already enabled for the primary
40 * core (e.g. timer irq), then they will not have been enabled
41 * for us: do so
42 */
43 gic_secondary_init(0);
44}
45
46static int __cpuinit socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
47{
48 int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
49
Dinh Nguyend6dd7352013-02-11 17:30:33 -060050 if (cpu1start_addr) {
51 memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060052
Dinh Nguyend6dd7352013-02-11 17:30:33 -060053 __raw_writel(virt_to_phys(socfpga_secondary_startup),
54 (sys_manager_base_addr + (cpu1start_addr & 0x000000ff)));
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060055
Dinh Nguyend6dd7352013-02-11 17:30:33 -060056 flush_cache_all();
57 smp_wmb();
58 outer_clean_range(0, trampoline_size);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060059
Dinh Nguyend6dd7352013-02-11 17:30:33 -060060 /* This will release CPU #1 out of reset.*/
61 __raw_writel(0, rst_manager_base_addr + 0x10);
62 }
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060063
64 return 0;
65}
66
67/*
68 * Initialise the CPU possible map early - this describes the CPUs
69 * which may be present or become present in the system.
70 */
71static void __init socfpga_smp_init_cpus(void)
72{
73 unsigned int i, ncores;
74
75 ncores = scu_get_core_count(socfpga_scu_base_addr);
76
77 for (i = 0; i < ncores; i++)
78 set_cpu_possible(i, true);
79
80 /* sanity check */
81 if (ncores > num_possible_cpus()) {
82 pr_warn("socfpga: no. of cores (%d) greater than configured"
83 "maximum of %d - clipping\n", ncores, num_possible_cpus());
84 ncores = num_possible_cpus();
85 }
86
87 for (i = 0; i < ncores; i++)
88 set_cpu_possible(i, true);
89
90 set_smp_cross_call(gic_raise_softirq);
91}
92
93static void __init socfpga_smp_prepare_cpus(unsigned int max_cpus)
94{
95 scu_enable(socfpga_scu_base_addr);
96}
97
98/*
99 * platform-specific code to shutdown a CPU
100 *
101 * Called with IRQs disabled
102 */
103static void socfpga_cpu_die(unsigned int cpu)
104{
105 cpu_do_idle();
106
107 /* We should have never returned from idle */
108 panic("cpu %d unexpectedly exit from shutdown\n", cpu);
109}
110
111struct smp_operations socfpga_smp_ops __initdata = {
112 .smp_init_cpus = socfpga_smp_init_cpus,
113 .smp_prepare_cpus = socfpga_smp_prepare_cpus,
114 .smp_secondary_init = socfpga_secondary_init,
115 .smp_boot_secondary = socfpga_boot_secondary,
116#ifdef CONFIG_HOTPLUG_CPU
117 .cpu_die = socfpga_cpu_die,
118#endif
119};