Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 1 | /* |
| 2 | * SMP support for R-Mobile / SH-Mobile |
| 3 | * |
| 4 | * Copyright (C) 2010 Magnus Damm |
Paul Mundt | c413521 | 2011-01-07 12:03:22 +0900 | [diff] [blame] | 5 | * Copyright (C) 2011 Paul Mundt |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 6 | * |
| 7 | * Based on vexpress, Copyright (C) 2002 ARM Ltd, All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/smp.h> |
| 18 | #include <linux/io.h> |
Magnus Damm | 450cca4 | 2012-05-16 15:46:03 +0900 | [diff] [blame] | 19 | #include <linux/of.h> |
Russell King | 0f7b332 | 2011-04-03 13:01:30 +0100 | [diff] [blame] | 20 | #include <asm/hardware/gic.h> |
Magnus Damm | 72f4d57 | 2010-12-14 16:57:11 +0900 | [diff] [blame] | 21 | #include <asm/mach-types.h> |
| 22 | #include <mach/common.h> |
Magnus Damm | bd5a875 | 2012-05-16 15:45:25 +0900 | [diff] [blame] | 23 | #include <mach/emev2.h> |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 24 | |
Magnus Damm | 873e9f7 | 2012-07-06 17:20:05 +0900 | [diff] [blame] | 25 | #ifdef CONFIG_ARCH_SH73A0 |
Arnd Bergmann | 9601e87 | 2012-05-15 15:30:17 +0000 | [diff] [blame] | 26 | #define is_sh73a0() (machine_is_ag5evm() || machine_is_kota2() || \ |
| 27 | of_machine_is_compatible("renesas,sh73a0")) |
Magnus Damm | 873e9f7 | 2012-07-06 17:20:05 +0900 | [diff] [blame] | 28 | #else |
| 29 | #define is_sh73a0() (0) |
| 30 | #endif |
| 31 | |
Magnus Damm | f40aaf6 | 2012-01-10 17:44:39 +0900 | [diff] [blame] | 32 | #define is_r8a7779() machine_is_marzen() |
Nobuhiro Iwamatsu | 6ae42bb | 2012-06-20 11:30:41 +0200 | [diff] [blame] | 33 | |
| 34 | #ifdef CONFIG_ARCH_EMEV2 |
Magnus Damm | 450cca4 | 2012-05-16 15:46:03 +0900 | [diff] [blame] | 35 | #define is_emev2() of_machine_is_compatible("renesas,emev2") |
Nobuhiro Iwamatsu | 6ae42bb | 2012-06-20 11:30:41 +0200 | [diff] [blame] | 36 | #else |
| 37 | #define is_emev2() (0) |
| 38 | #endif |
Magnus Damm | 2862663 | 2011-08-18 05:44:07 +0000 | [diff] [blame] | 39 | |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 40 | static unsigned int __init shmobile_smp_get_core_count(void) |
| 41 | { |
Magnus Damm | 2862663 | 2011-08-18 05:44:07 +0000 | [diff] [blame] | 42 | if (is_sh73a0()) |
Magnus Damm | 72f4d57 | 2010-12-14 16:57:11 +0900 | [diff] [blame] | 43 | return sh73a0_get_core_count(); |
| 44 | |
Magnus Damm | f40aaf6 | 2012-01-10 17:44:39 +0900 | [diff] [blame] | 45 | if (is_r8a7779()) |
| 46 | return r8a7779_get_core_count(); |
| 47 | |
Magnus Damm | bd5a875 | 2012-05-16 15:45:25 +0900 | [diff] [blame] | 48 | if (is_emev2()) |
| 49 | return emev2_get_core_count(); |
| 50 | |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | static void __init shmobile_smp_prepare_cpus(void) |
| 55 | { |
Magnus Damm | 2862663 | 2011-08-18 05:44:07 +0000 | [diff] [blame] | 56 | if (is_sh73a0()) |
Magnus Damm | 72f4d57 | 2010-12-14 16:57:11 +0900 | [diff] [blame] | 57 | sh73a0_smp_prepare_cpus(); |
Magnus Damm | f40aaf6 | 2012-01-10 17:44:39 +0900 | [diff] [blame] | 58 | |
| 59 | if (is_r8a7779()) |
| 60 | r8a7779_smp_prepare_cpus(); |
Magnus Damm | bd5a875 | 2012-05-16 15:45:25 +0900 | [diff] [blame] | 61 | |
| 62 | if (is_emev2()) |
| 63 | emev2_smp_prepare_cpus(); |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 64 | } |
| 65 | |
Magnus Damm | 8b30679 | 2011-12-28 16:47:16 +0900 | [diff] [blame] | 66 | int shmobile_platform_cpu_kill(unsigned int cpu) |
| 67 | { |
Magnus Damm | f40aaf6 | 2012-01-10 17:44:39 +0900 | [diff] [blame] | 68 | if (is_r8a7779()) |
| 69 | return r8a7779_platform_cpu_kill(cpu); |
| 70 | |
Magnus Damm | bd5a875 | 2012-05-16 15:45:25 +0900 | [diff] [blame] | 71 | if (is_emev2()) |
| 72 | return emev2_platform_cpu_kill(cpu); |
| 73 | |
Magnus Damm | 8b30679 | 2011-12-28 16:47:16 +0900 | [diff] [blame] | 74 | return 1; |
| 75 | } |
| 76 | |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 77 | void __cpuinit platform_secondary_init(unsigned int cpu) |
| 78 | { |
| 79 | trace_hardirqs_off(); |
Magnus Damm | 72f4d57 | 2010-12-14 16:57:11 +0900 | [diff] [blame] | 80 | |
Magnus Damm | 2862663 | 2011-08-18 05:44:07 +0000 | [diff] [blame] | 81 | if (is_sh73a0()) |
Magnus Damm | 72f4d57 | 2010-12-14 16:57:11 +0900 | [diff] [blame] | 82 | sh73a0_secondary_init(cpu); |
Magnus Damm | f40aaf6 | 2012-01-10 17:44:39 +0900 | [diff] [blame] | 83 | |
| 84 | if (is_r8a7779()) |
| 85 | r8a7779_secondary_init(cpu); |
Magnus Damm | bd5a875 | 2012-05-16 15:45:25 +0900 | [diff] [blame] | 86 | |
| 87 | if (is_emev2()) |
| 88 | emev2_secondary_init(cpu); |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 92 | { |
Magnus Damm | 2862663 | 2011-08-18 05:44:07 +0000 | [diff] [blame] | 93 | if (is_sh73a0()) |
Magnus Damm | 72f4d57 | 2010-12-14 16:57:11 +0900 | [diff] [blame] | 94 | return sh73a0_boot_secondary(cpu); |
| 95 | |
Magnus Damm | f40aaf6 | 2012-01-10 17:44:39 +0900 | [diff] [blame] | 96 | if (is_r8a7779()) |
| 97 | return r8a7779_boot_secondary(cpu); |
| 98 | |
Magnus Damm | bd5a875 | 2012-05-16 15:45:25 +0900 | [diff] [blame] | 99 | if (is_emev2()) |
| 100 | return emev2_boot_secondary(cpu); |
| 101 | |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 102 | return -ENOSYS; |
| 103 | } |
| 104 | |
| 105 | void __init smp_init_cpus(void) |
| 106 | { |
| 107 | unsigned int ncores = shmobile_smp_get_core_count(); |
| 108 | unsigned int i; |
| 109 | |
Russell King | a06f916 | 2011-10-20 22:04:18 +0100 | [diff] [blame] | 110 | if (ncores > nr_cpu_ids) { |
| 111 | pr_warn("SMP: %u cores greater than maximum (%u), clipping\n", |
| 112 | ncores, nr_cpu_ids); |
| 113 | ncores = nr_cpu_ids; |
| 114 | } |
| 115 | |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 116 | for (i = 0; i < ncores; i++) |
| 117 | set_cpu_possible(i, true); |
Russell King | 0f7b332 | 2011-04-03 13:01:30 +0100 | [diff] [blame] | 118 | |
| 119 | set_smp_cross_call(gic_raise_softirq); |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 120 | } |
| 121 | |
Paul Mundt | c413521 | 2011-01-07 12:03:22 +0900 | [diff] [blame] | 122 | void __init platform_smp_prepare_cpus(unsigned int max_cpus) |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 123 | { |
Paul Mundt | c413521 | 2011-01-07 12:03:22 +0900 | [diff] [blame] | 124 | shmobile_smp_prepare_cpus(); |
Magnus Damm | 1c51ed4 | 2010-12-14 16:56:55 +0900 | [diff] [blame] | 125 | } |