blob: 07945748b57141f2c216d729a6f895d36227be7a [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>
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060027#include <asm/smp_scu.h>
28#include <asm/smp_plat.h>
29
30#include "core.h"
31
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040032static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060033{
34 int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
35
Dinh Nguyen3a4356c2014-10-01 05:44:48 -050036 if (socfpga_cpu1start_addr) {
Alan Tulld686ce42014-10-14 19:33:38 +000037 /* This will put CPU #1 into reset. */
38 writel(RSTMGR_MPUMODRST_CPU1,
39 rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST);
40
Dinh Nguyend6dd7352013-02-11 17:30:33 -060041 memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060042
Russell King02b4e272015-05-19 17:06:44 +010043 writel(virt_to_phys(secondary_startup),
Alan Tulld686ce42014-10-14 19:33:38 +000044 sys_manager_base_addr + (socfpga_cpu1start_addr & 0x000000ff));
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060045
Dinh Nguyend6dd7352013-02-11 17:30:33 -060046 flush_cache_all();
47 smp_wmb();
48 outer_clean_range(0, trampoline_size);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060049
Alan Tulld686ce42014-10-14 19:33:38 +000050 /* This will release CPU #1 out of reset. */
51 writel(0, rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST);
Dinh Nguyend6dd7352013-02-11 17:30:33 -060052 }
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060053
54 return 0;
55}
56
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050057static int socfpga_a10_boot_secondary(unsigned int cpu, struct task_struct *idle)
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060058{
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050059 int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060060
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050061 if (socfpga_cpu1start_addr) {
62 writel(RSTMGR_MPUMODRST_CPU1, rst_manager_base_addr +
63 SOCFPGA_A10_RSTMGR_MODMPURST);
64 memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060065
Kevin Hilman89b8da02015-06-11 15:41:58 -070066 writel(virt_to_phys(secondary_startup),
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050067 sys_manager_base_addr + (socfpga_cpu1start_addr & 0x00000fff));
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060068
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050069 flush_cache_all();
70 smp_wmb();
71 outer_clean_range(0, trampoline_size);
72
73 /* This will release CPU #1 out of reset. */
74 writel(0, rst_manager_base_addr + SOCFPGA_A10_RSTMGR_MODMPURST);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060075 }
76
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050077 return 0;
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060078}
79
80static void __init socfpga_smp_prepare_cpus(unsigned int max_cpus)
81{
Dinh Nguyen122694a2015-05-12 16:49:21 -050082 struct device_node *np;
83 void __iomem *socfpga_scu_base_addr;
84
85 np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
86 if (!np) {
87 pr_err("%s: missing scu\n", __func__);
88 return;
89 }
90
91 socfpga_scu_base_addr = of_iomap(np, 0);
92 if (!socfpga_scu_base_addr)
93 return;
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060094 scu_enable(socfpga_scu_base_addr);
95}
96
Arnd Bergmann5d37e802016-02-23 15:08:42 +010097#ifdef CONFIG_HOTPLUG_CPU
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060098/*
99 * platform-specific code to shutdown a CPU
100 *
101 * Called with IRQs disabled
102 */
103static void socfpga_cpu_die(unsigned int cpu)
104{
Alan Tulld686ce42014-10-14 19:33:38 +0000105 /* Do WFI. If we wake up early, go back into WFI */
106 while (1)
107 cpu_do_idle();
Dinh Nguyen9c4566a2012-10-25 10:41:39 -0600108}
109
Hiraku Toyookab33612e2015-06-10 07:47:19 +0000110/*
111 * We need a dummy function so that platform_can_cpu_hotplug() knows
112 * we support CPU hotplug. However, the function does not need to do
113 * anything, because CPUs going offline just do WFI. We could reset
114 * the CPUs but it would increase power consumption.
115 */
116static int socfpga_cpu_kill(unsigned int cpu)
117{
118 return 1;
119}
Arnd Bergmann5d37e802016-02-23 15:08:42 +0100120#endif
Hiraku Toyookab33612e2015-06-10 07:47:19 +0000121
Masahiro Yamada75305272015-11-15 10:39:53 +0900122static const struct smp_operations socfpga_smp_ops __initconst = {
Dinh Nguyen9c4566a2012-10-25 10:41:39 -0600123 .smp_prepare_cpus = socfpga_smp_prepare_cpus,
Dinh Nguyen9c4566a2012-10-25 10:41:39 -0600124 .smp_boot_secondary = socfpga_boot_secondary,
125#ifdef CONFIG_HOTPLUG_CPU
126 .cpu_die = socfpga_cpu_die,
Hiraku Toyookab33612e2015-06-10 07:47:19 +0000127 .cpu_kill = socfpga_cpu_kill,
Dinh Nguyen9c4566a2012-10-25 10:41:39 -0600128#endif
129};
Dinh Nguyen5f763ef2015-06-02 21:14:01 -0500130
Masahiro Yamada75305272015-11-15 10:39:53 +0900131static const struct smp_operations socfpga_a10_smp_ops __initconst = {
Dinh Nguyen45be0cd2015-06-02 21:14:02 -0500132 .smp_prepare_cpus = socfpga_smp_prepare_cpus,
133 .smp_boot_secondary = socfpga_a10_boot_secondary,
134#ifdef CONFIG_HOTPLUG_CPU
135 .cpu_die = socfpga_cpu_die,
Hiraku Toyookab33612e2015-06-10 07:47:19 +0000136 .cpu_kill = socfpga_cpu_kill,
Dinh Nguyen45be0cd2015-06-02 21:14:02 -0500137#endif
138};
139
Dinh Nguyen5f763ef2015-06-02 21:14:01 -0500140CPU_METHOD_OF_DECLARE(socfpga_smp, "altr,socfpga-smp", &socfpga_smp_ops);
Dinh Nguyen45be0cd2015-06-02 21:14:02 -0500141CPU_METHOD_OF_DECLARE(socfpga_a10_smp, "altr,socfpga-a10-smp", &socfpga_a10_smp_ops);