Thomas Gleixner | 9952f69 | 2019-05-28 10:10:04 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 2 | /* |
| 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 Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 7 | */ |
| 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 Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 16 | #include <asm/smp_scu.h> |
| 17 | #include <asm/smp_plat.h> |
| 18 | |
| 19 | #include "core.h" |
| 20 | |
Paul Gortmaker | 8bd26e3 | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 21 | static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle) |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 22 | { |
Takashi Iwai | 20a09c8 | 2021-11-18 15:25:08 +0100 | [diff] [blame] | 23 | int trampoline_size = secondary_trampoline_end - secondary_trampoline; |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 24 | |
Dinh Nguyen | 3a4356c | 2014-10-01 05:44:48 -0500 | [diff] [blame] | 25 | if (socfpga_cpu1start_addr) { |
Alan Tull | d686ce4 | 2014-10-14 19:33:38 +0000 | [diff] [blame] | 26 | /* This will put CPU #1 into reset. */ |
| 27 | writel(RSTMGR_MPUMODRST_CPU1, |
| 28 | rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST); |
| 29 | |
Takashi Iwai | 20a09c8 | 2021-11-18 15:25:08 +0100 | [diff] [blame] | 30 | memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 31 | |
Florian Fainelli | 64fc2a9 | 2017-01-15 03:59:29 +0100 | [diff] [blame] | 32 | writel(__pa_symbol(secondary_startup), |
Alan Tull | d686ce4 | 2014-10-14 19:33:38 +0000 | [diff] [blame] | 33 | sys_manager_base_addr + (socfpga_cpu1start_addr & 0x000000ff)); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 34 | |
Dinh Nguyen | d6dd735 | 2013-02-11 17:30:33 -0600 | [diff] [blame] | 35 | flush_cache_all(); |
| 36 | smp_wmb(); |
| 37 | outer_clean_range(0, trampoline_size); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 38 | |
Alan Tull | d686ce4 | 2014-10-14 19:33:38 +0000 | [diff] [blame] | 39 | /* This will release CPU #1 out of reset. */ |
| 40 | writel(0, rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST); |
Dinh Nguyen | d6dd735 | 2013-02-11 17:30:33 -0600 | [diff] [blame] | 41 | } |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Dinh Nguyen | 45be0cd | 2015-06-02 21:14:02 -0500 | [diff] [blame] | 46 | static int socfpga_a10_boot_secondary(unsigned int cpu, struct task_struct *idle) |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 47 | { |
Takashi Iwai | 20a09c8 | 2021-11-18 15:25:08 +0100 | [diff] [blame] | 48 | int trampoline_size = secondary_trampoline_end - secondary_trampoline; |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 49 | |
Dinh Nguyen | 45be0cd | 2015-06-02 21:14:02 -0500 | [diff] [blame] | 50 | if (socfpga_cpu1start_addr) { |
| 51 | writel(RSTMGR_MPUMODRST_CPU1, rst_manager_base_addr + |
| 52 | SOCFPGA_A10_RSTMGR_MODMPURST); |
Takashi Iwai | 20a09c8 | 2021-11-18 15:25:08 +0100 | [diff] [blame] | 53 | memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 54 | |
Florian Fainelli | 64fc2a9 | 2017-01-15 03:59:29 +0100 | [diff] [blame] | 55 | writel(__pa_symbol(secondary_startup), |
Dinh Nguyen | 45be0cd | 2015-06-02 21:14:02 -0500 | [diff] [blame] | 56 | sys_manager_base_addr + (socfpga_cpu1start_addr & 0x00000fff)); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 57 | |
Dinh Nguyen | 45be0cd | 2015-06-02 21:14:02 -0500 | [diff] [blame] | 58 | 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 Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 64 | } |
| 65 | |
Dinh Nguyen | 45be0cd | 2015-06-02 21:14:02 -0500 | [diff] [blame] | 66 | return 0; |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static void __init socfpga_smp_prepare_cpus(unsigned int max_cpus) |
| 70 | { |
Dinh Nguyen | 122694a | 2015-05-12 16:49:21 -0500 | [diff] [blame] | 71 | 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 Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 83 | scu_enable(socfpga_scu_base_addr); |
| 84 | } |
| 85 | |
Arnd Bergmann | 5d37e80 | 2016-02-23 15:08:42 +0100 | [diff] [blame] | 86 | #ifdef CONFIG_HOTPLUG_CPU |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 87 | /* |
| 88 | * platform-specific code to shutdown a CPU |
| 89 | * |
| 90 | * Called with IRQs disabled |
| 91 | */ |
| 92 | static void socfpga_cpu_die(unsigned int cpu) |
| 93 | { |
Alan Tull | d686ce4 | 2014-10-14 19:33:38 +0000 | [diff] [blame] | 94 | /* Do WFI. If we wake up early, go back into WFI */ |
| 95 | while (1) |
| 96 | cpu_do_idle(); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 97 | } |
| 98 | |
Hiraku Toyooka | b33612e | 2015-06-10 07:47:19 +0000 | [diff] [blame] | 99 | /* |
| 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 | */ |
| 105 | static int socfpga_cpu_kill(unsigned int cpu) |
| 106 | { |
| 107 | return 1; |
| 108 | } |
Arnd Bergmann | 5d37e80 | 2016-02-23 15:08:42 +0100 | [diff] [blame] | 109 | #endif |
Hiraku Toyooka | b33612e | 2015-06-10 07:47:19 +0000 | [diff] [blame] | 110 | |
Masahiro Yamada | 7530527 | 2015-11-15 10:39:53 +0900 | [diff] [blame] | 111 | static const struct smp_operations socfpga_smp_ops __initconst = { |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 112 | .smp_prepare_cpus = socfpga_smp_prepare_cpus, |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 113 | .smp_boot_secondary = socfpga_boot_secondary, |
| 114 | #ifdef CONFIG_HOTPLUG_CPU |
| 115 | .cpu_die = socfpga_cpu_die, |
Hiraku Toyooka | b33612e | 2015-06-10 07:47:19 +0000 | [diff] [blame] | 116 | .cpu_kill = socfpga_cpu_kill, |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 117 | #endif |
| 118 | }; |
Dinh Nguyen | 5f763ef | 2015-06-02 21:14:01 -0500 | [diff] [blame] | 119 | |
Masahiro Yamada | 7530527 | 2015-11-15 10:39:53 +0900 | [diff] [blame] | 120 | static const struct smp_operations socfpga_a10_smp_ops __initconst = { |
Dinh Nguyen | 45be0cd | 2015-06-02 21:14:02 -0500 | [diff] [blame] | 121 | .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 Toyooka | b33612e | 2015-06-10 07:47:19 +0000 | [diff] [blame] | 125 | .cpu_kill = socfpga_cpu_kill, |
Dinh Nguyen | 45be0cd | 2015-06-02 21:14:02 -0500 | [diff] [blame] | 126 | #endif |
| 127 | }; |
| 128 | |
Dinh Nguyen | 5f763ef | 2015-06-02 21:14:01 -0500 | [diff] [blame] | 129 | CPU_METHOD_OF_DECLARE(socfpga_smp, "altr,socfpga-smp", &socfpga_smp_ops); |
Dinh Nguyen | 45be0cd | 2015-06-02 21:14:02 -0500 | [diff] [blame] | 130 | CPU_METHOD_OF_DECLARE(socfpga_a10_smp, "altr,socfpga-a10-smp", &socfpga_a10_smp_ops); |