Merge branch 'depends/clk-for-3.10' into next/cleanup
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-socfpga / platsmp.c
1 /*
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/smp_scu.h>
28 #include <asm/smp_plat.h>
29
30 #include "core.h"
31
32 extern void __iomem *sys_manager_base_addr;
33 extern void __iomem *rst_manager_base_addr;
34
35 static int __cpuinit socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
36 {
37         int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
38
39         if (cpu1start_addr) {
40                 memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
41
42                 __raw_writel(virt_to_phys(socfpga_secondary_startup),
43                         (sys_manager_base_addr + (cpu1start_addr & 0x000000ff)));
44
45                 flush_cache_all();
46                 smp_wmb();
47                 outer_clean_range(0, trampoline_size);
48
49                 /* This will release CPU #1 out of reset.*/
50                 __raw_writel(0, rst_manager_base_addr + 0x10);
51         }
52
53         return 0;
54 }
55
56 /*
57  * Initialise the CPU possible map early - this describes the CPUs
58  * which may be present or become present in the system.
59  */
60 static void __init socfpga_smp_init_cpus(void)
61 {
62         unsigned int i, ncores;
63
64         ncores = scu_get_core_count(socfpga_scu_base_addr);
65
66         for (i = 0; i < ncores; i++)
67                 set_cpu_possible(i, true);
68
69         /* sanity check */
70         if (ncores > num_possible_cpus()) {
71                 pr_warn("socfpga: no. of cores (%d) greater than configured"
72                         "maximum of %d - clipping\n", ncores, num_possible_cpus());
73                 ncores = num_possible_cpus();
74         }
75
76         for (i = 0; i < ncores; i++)
77                 set_cpu_possible(i, true);
78 }
79
80 static void __init socfpga_smp_prepare_cpus(unsigned int max_cpus)
81 {
82         scu_enable(socfpga_scu_base_addr);
83 }
84
85 /*
86  * platform-specific code to shutdown a CPU
87  *
88  * Called with IRQs disabled
89  */
90 static void socfpga_cpu_die(unsigned int cpu)
91 {
92         cpu_do_idle();
93
94         /* We should have never returned from idle */
95         panic("cpu %d unexpectedly exit from shutdown\n", cpu);
96 }
97
98 struct smp_operations socfpga_smp_ops __initdata = {
99         .smp_init_cpus          = socfpga_smp_init_cpus,
100         .smp_prepare_cpus       = socfpga_smp_prepare_cpus,
101         .smp_boot_secondary     = socfpga_boot_secondary,
102 #ifdef CONFIG_HOTPLUG_CPU
103         .cpu_die                = socfpga_cpu_die,
104 #endif
105 };