blob: 201191cf68f324ca970e93162d46500214b449a5 [file] [log] [blame]
Thomas Gleixner9952f692019-05-28 10:10:04 -07001// SPDX-License-Identifier: GPL-2.0-only
Dinh Nguyen9c4566a2012-10-25 10:41:39 -06002/*
3 * Copyright 2010-2011 Calxeda, Inc.
4 * Copyright 2012 Pavel Machek <pavel@denx.de>
5 * Based on platsmp.c, Copyright (C) 2002 ARM Ltd.
6 * Copyright (C) 2012 Altera Corporation
Dinh Nguyen9c4566a2012-10-25 10:41:39 -06007 */
8#include <linux/delay.h>
9#include <linux/init.h>
10#include <linux/smp.h>
11#include <linux/io.h>
12#include <linux/of.h>
13#include <linux/of_address.h>
14
15#include <asm/cacheflush.h>
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060016#include <asm/smp_scu.h>
17#include <asm/smp_plat.h>
18
19#include "core.h"
20
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040021static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060022{
Takashi Iwai20a09c82021-11-18 15:25:08 +010023 int trampoline_size = secondary_trampoline_end - secondary_trampoline;
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060024
Dinh Nguyen3a4356c2014-10-01 05:44:48 -050025 if (socfpga_cpu1start_addr) {
Alan Tulld686ce42014-10-14 19:33:38 +000026 /* This will put CPU #1 into reset. */
27 writel(RSTMGR_MPUMODRST_CPU1,
28 rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST);
29
Takashi Iwai20a09c82021-11-18 15:25:08 +010030 memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060031
Florian Fainelli64fc2a92017-01-15 03:59:29 +010032 writel(__pa_symbol(secondary_startup),
Alan Tulld686ce42014-10-14 19:33:38 +000033 sys_manager_base_addr + (socfpga_cpu1start_addr & 0x000000ff));
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060034
Dinh Nguyend6dd7352013-02-11 17:30:33 -060035 flush_cache_all();
36 smp_wmb();
37 outer_clean_range(0, trampoline_size);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060038
Alan Tulld686ce42014-10-14 19:33:38 +000039 /* This will release CPU #1 out of reset. */
40 writel(0, rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST);
Dinh Nguyend6dd7352013-02-11 17:30:33 -060041 }
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060042
43 return 0;
44}
45
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050046static int socfpga_a10_boot_secondary(unsigned int cpu, struct task_struct *idle)
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060047{
Takashi Iwai20a09c82021-11-18 15:25:08 +010048 int trampoline_size = secondary_trampoline_end - secondary_trampoline;
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060049
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050050 if (socfpga_cpu1start_addr) {
51 writel(RSTMGR_MPUMODRST_CPU1, rst_manager_base_addr +
52 SOCFPGA_A10_RSTMGR_MODMPURST);
Takashi Iwai20a09c82021-11-18 15:25:08 +010053 memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060054
Florian Fainelli64fc2a92017-01-15 03:59:29 +010055 writel(__pa_symbol(secondary_startup),
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050056 sys_manager_base_addr + (socfpga_cpu1start_addr & 0x00000fff));
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060057
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050058 flush_cache_all();
59 smp_wmb();
60 outer_clean_range(0, trampoline_size);
61
62 /* This will release CPU #1 out of reset. */
63 writel(0, rst_manager_base_addr + SOCFPGA_A10_RSTMGR_MODMPURST);
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060064 }
65
Dinh Nguyen45be0cd2015-06-02 21:14:02 -050066 return 0;
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060067}
68
69static void __init socfpga_smp_prepare_cpus(unsigned int max_cpus)
70{
Dinh Nguyen122694a2015-05-12 16:49:21 -050071 struct device_node *np;
72 void __iomem *socfpga_scu_base_addr;
73
74 np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
75 if (!np) {
76 pr_err("%s: missing scu\n", __func__);
77 return;
78 }
79
80 socfpga_scu_base_addr = of_iomap(np, 0);
81 if (!socfpga_scu_base_addr)
82 return;
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060083 scu_enable(socfpga_scu_base_addr);
84}
85
Arnd Bergmann5d37e802016-02-23 15:08:42 +010086#ifdef CONFIG_HOTPLUG_CPU
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060087/*
88 * platform-specific code to shutdown a CPU
89 *
90 * Called with IRQs disabled
91 */
92static void socfpga_cpu_die(unsigned int cpu)
93{
Alan Tulld686ce42014-10-14 19:33:38 +000094 /* Do WFI. If we wake up early, go back into WFI */
95 while (1)
96 cpu_do_idle();
Dinh Nguyen9c4566a2012-10-25 10:41:39 -060097}
98
Hiraku Toyookab33612e2015-06-10 07:47:19 +000099/*
100 * We need a dummy function so that platform_can_cpu_hotplug() knows
101 * we support CPU hotplug. However, the function does not need to do
102 * anything, because CPUs going offline just do WFI. We could reset
103 * the CPUs but it would increase power consumption.
104 */
105static int socfpga_cpu_kill(unsigned int cpu)
106{
107 return 1;
108}
Arnd Bergmann5d37e802016-02-23 15:08:42 +0100109#endif
Hiraku Toyookab33612e2015-06-10 07:47:19 +0000110
Masahiro Yamada75305272015-11-15 10:39:53 +0900111static const struct smp_operations socfpga_smp_ops __initconst = {
Dinh Nguyen9c4566a2012-10-25 10:41:39 -0600112 .smp_prepare_cpus = socfpga_smp_prepare_cpus,
Dinh Nguyen9c4566a2012-10-25 10:41:39 -0600113 .smp_boot_secondary = socfpga_boot_secondary,
114#ifdef CONFIG_HOTPLUG_CPU
115 .cpu_die = socfpga_cpu_die,
Hiraku Toyookab33612e2015-06-10 07:47:19 +0000116 .cpu_kill = socfpga_cpu_kill,
Dinh Nguyen9c4566a2012-10-25 10:41:39 -0600117#endif
118};
Dinh Nguyen5f763ef2015-06-02 21:14:01 -0500119
Masahiro Yamada75305272015-11-15 10:39:53 +0900120static const struct smp_operations socfpga_a10_smp_ops __initconst = {
Dinh Nguyen45be0cd2015-06-02 21:14:02 -0500121 .smp_prepare_cpus = socfpga_smp_prepare_cpus,
122 .smp_boot_secondary = socfpga_a10_boot_secondary,
123#ifdef CONFIG_HOTPLUG_CPU
124 .cpu_die = socfpga_cpu_die,
Hiraku Toyookab33612e2015-06-10 07:47:19 +0000125 .cpu_kill = socfpga_cpu_kill,
Dinh Nguyen45be0cd2015-06-02 21:14:02 -0500126#endif
127};
128
Dinh Nguyen5f763ef2015-06-02 21:14:01 -0500129CPU_METHOD_OF_DECLARE(socfpga_smp, "altr,socfpga-smp", &socfpga_smp_ops);
Dinh Nguyen45be0cd2015-06-02 21:14:02 -0500130CPU_METHOD_OF_DECLARE(socfpga_a10_smp, "altr,socfpga-a10-smp", &socfpga_a10_smp_ops);