Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 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> |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 27 | #include <asm/smp_scu.h> |
| 28 | #include <asm/smp_plat.h> |
| 29 | |
| 30 | #include "core.h" |
| 31 | |
Paul Gortmaker | 8bd26e3 | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 32 | static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle) |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 33 | { |
| 34 | int trampoline_size = &secondary_trampoline_end - &secondary_trampoline; |
| 35 | |
Dinh Nguyen | 3a4356c | 2014-10-01 05:44:48 -0500 | [diff] [blame] | 36 | if (socfpga_cpu1start_addr) { |
Alan Tull | d686ce4 | 2014-10-14 19:33:38 +0000 | [diff] [blame] | 37 | /* This will put CPU #1 into reset. */ |
| 38 | writel(RSTMGR_MPUMODRST_CPU1, |
| 39 | rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST); |
| 40 | |
Dinh Nguyen | d6dd735 | 2013-02-11 17:30:33 -0600 | [diff] [blame] | 41 | memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 42 | |
Alan Tull | d686ce4 | 2014-10-14 19:33:38 +0000 | [diff] [blame] | 43 | writel(virt_to_phys(socfpga_secondary_startup), |
| 44 | sys_manager_base_addr + (socfpga_cpu1start_addr & 0x000000ff)); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 45 | |
Dinh Nguyen | d6dd735 | 2013-02-11 17:30:33 -0600 | [diff] [blame] | 46 | flush_cache_all(); |
| 47 | smp_wmb(); |
| 48 | outer_clean_range(0, trampoline_size); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 49 | |
Alan Tull | d686ce4 | 2014-10-14 19:33:38 +0000 | [diff] [blame] | 50 | /* This will release CPU #1 out of reset. */ |
| 51 | writel(0, rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST); |
Dinh Nguyen | d6dd735 | 2013-02-11 17:30:33 -0600 | [diff] [blame] | 52 | } |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Initialise the CPU possible map early - this describes the CPUs |
| 59 | * which may be present or become present in the system. |
| 60 | */ |
| 61 | static void __init socfpga_smp_init_cpus(void) |
| 62 | { |
| 63 | unsigned int i, ncores; |
| 64 | |
| 65 | ncores = scu_get_core_count(socfpga_scu_base_addr); |
| 66 | |
| 67 | for (i = 0; i < ncores; i++) |
| 68 | set_cpu_possible(i, true); |
| 69 | |
| 70 | /* sanity check */ |
| 71 | if (ncores > num_possible_cpus()) { |
| 72 | pr_warn("socfpga: no. of cores (%d) greater than configured" |
| 73 | "maximum of %d - clipping\n", ncores, num_possible_cpus()); |
| 74 | ncores = num_possible_cpus(); |
| 75 | } |
| 76 | |
| 77 | for (i = 0; i < ncores; i++) |
| 78 | set_cpu_possible(i, true); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static void __init socfpga_smp_prepare_cpus(unsigned int max_cpus) |
| 82 | { |
| 83 | scu_enable(socfpga_scu_base_addr); |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * platform-specific code to shutdown a CPU |
| 88 | * |
| 89 | * Called with IRQs disabled |
| 90 | */ |
| 91 | static void socfpga_cpu_die(unsigned int cpu) |
| 92 | { |
Alan Tull | d686ce4 | 2014-10-14 19:33:38 +0000 | [diff] [blame] | 93 | /* Do WFI. If we wake up early, go back into WFI */ |
| 94 | while (1) |
| 95 | cpu_do_idle(); |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 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, |
Dinh Nguyen | 9c4566a | 2012-10-25 10:41:39 -0600 | [diff] [blame] | 101 | .smp_boot_secondary = socfpga_boot_secondary, |
| 102 | #ifdef CONFIG_HOTPLUG_CPU |
| 103 | .cpu_die = socfpga_cpu_die, |
| 104 | #endif |
| 105 | }; |