blob: fde0d23121dc6e14acd614504d054d0c83f778c6 [file] [log] [blame]
Magnus Damm1c51ed42010-12-14 16:56:55 +09001/*
2 * SMP support for R-Mobile / SH-Mobile
3 *
4 * Copyright (C) 2010 Magnus Damm
Paul Mundtc4135212011-01-07 12:03:22 +09005 * Copyright (C) 2011 Paul Mundt
Magnus Damm1c51ed42010-12-14 16:56:55 +09006 *
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 Damm450cca42012-05-16 15:46:03 +090019#include <linux/of.h>
Russell King0f7b3322011-04-03 13:01:30 +010020#include <asm/hardware/gic.h>
Magnus Damm72f4d572010-12-14 16:57:11 +090021#include <asm/mach-types.h>
22#include <mach/common.h>
Magnus Dammbd5a8752012-05-16 15:45:25 +090023#include <mach/emev2.h>
Magnus Damm1c51ed42010-12-14 16:56:55 +090024
Magnus Damm873e9f72012-07-06 17:20:05 +090025#ifdef CONFIG_ARCH_SH73A0
Arnd Bergmann9601e872012-05-15 15:30:17 +000026#define is_sh73a0() (machine_is_ag5evm() || machine_is_kota2() || \
27 of_machine_is_compatible("renesas,sh73a0"))
Magnus Damm873e9f72012-07-06 17:20:05 +090028#else
29#define is_sh73a0() (0)
30#endif
31
Magnus Dammf40aaf62012-01-10 17:44:39 +090032#define is_r8a7779() machine_is_marzen()
Nobuhiro Iwamatsu6ae42bb2012-06-20 11:30:41 +020033
34#ifdef CONFIG_ARCH_EMEV2
Magnus Damm450cca42012-05-16 15:46:03 +090035#define is_emev2() of_machine_is_compatible("renesas,emev2")
Nobuhiro Iwamatsu6ae42bb2012-06-20 11:30:41 +020036#else
37#define is_emev2() (0)
38#endif
Magnus Damm28626632011-08-18 05:44:07 +000039
Magnus Damm1c51ed42010-12-14 16:56:55 +090040static unsigned int __init shmobile_smp_get_core_count(void)
41{
Magnus Damm28626632011-08-18 05:44:07 +000042 if (is_sh73a0())
Magnus Damm72f4d572010-12-14 16:57:11 +090043 return sh73a0_get_core_count();
44
Magnus Dammf40aaf62012-01-10 17:44:39 +090045 if (is_r8a7779())
46 return r8a7779_get_core_count();
47
Magnus Dammbd5a8752012-05-16 15:45:25 +090048 if (is_emev2())
49 return emev2_get_core_count();
50
Magnus Damm1c51ed42010-12-14 16:56:55 +090051 return 1;
52}
53
54static void __init shmobile_smp_prepare_cpus(void)
55{
Magnus Damm28626632011-08-18 05:44:07 +000056 if (is_sh73a0())
Magnus Damm72f4d572010-12-14 16:57:11 +090057 sh73a0_smp_prepare_cpus();
Magnus Dammf40aaf62012-01-10 17:44:39 +090058
59 if (is_r8a7779())
60 r8a7779_smp_prepare_cpus();
Magnus Dammbd5a8752012-05-16 15:45:25 +090061
62 if (is_emev2())
63 emev2_smp_prepare_cpus();
Magnus Damm1c51ed42010-12-14 16:56:55 +090064}
65
Magnus Damm8b306792011-12-28 16:47:16 +090066int shmobile_platform_cpu_kill(unsigned int cpu)
67{
Magnus Dammf40aaf62012-01-10 17:44:39 +090068 if (is_r8a7779())
69 return r8a7779_platform_cpu_kill(cpu);
70
Magnus Dammbd5a8752012-05-16 15:45:25 +090071 if (is_emev2())
72 return emev2_platform_cpu_kill(cpu);
73
Magnus Damm8b306792011-12-28 16:47:16 +090074 return 1;
75}
76
Magnus Damm1c51ed42010-12-14 16:56:55 +090077void __cpuinit platform_secondary_init(unsigned int cpu)
78{
79 trace_hardirqs_off();
Magnus Damm72f4d572010-12-14 16:57:11 +090080
Magnus Damm28626632011-08-18 05:44:07 +000081 if (is_sh73a0())
Magnus Damm72f4d572010-12-14 16:57:11 +090082 sh73a0_secondary_init(cpu);
Magnus Dammf40aaf62012-01-10 17:44:39 +090083
84 if (is_r8a7779())
85 r8a7779_secondary_init(cpu);
Magnus Dammbd5a8752012-05-16 15:45:25 +090086
87 if (is_emev2())
88 emev2_secondary_init(cpu);
Magnus Damm1c51ed42010-12-14 16:56:55 +090089}
90
91int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
92{
Magnus Damm28626632011-08-18 05:44:07 +000093 if (is_sh73a0())
Magnus Damm72f4d572010-12-14 16:57:11 +090094 return sh73a0_boot_secondary(cpu);
95
Magnus Dammf40aaf62012-01-10 17:44:39 +090096 if (is_r8a7779())
97 return r8a7779_boot_secondary(cpu);
98
Magnus Dammbd5a8752012-05-16 15:45:25 +090099 if (is_emev2())
100 return emev2_boot_secondary(cpu);
101
Magnus Damm1c51ed42010-12-14 16:56:55 +0900102 return -ENOSYS;
103}
104
105void __init smp_init_cpus(void)
106{
107 unsigned int ncores = shmobile_smp_get_core_count();
108 unsigned int i;
109
Russell Kinga06f9162011-10-20 22:04:18 +0100110 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 Damm1c51ed42010-12-14 16:56:55 +0900116 for (i = 0; i < ncores; i++)
117 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100118
119 set_smp_cross_call(gic_raise_softirq);
Magnus Damm1c51ed42010-12-14 16:56:55 +0900120}
121
Paul Mundtc4135212011-01-07 12:03:22 +0900122void __init platform_smp_prepare_cpus(unsigned int max_cpus)
Magnus Damm1c51ed42010-12-14 16:56:55 +0900123{
Paul Mundtc4135212011-01-07 12:03:22 +0900124 shmobile_smp_prepare_cpus();
Magnus Damm1c51ed42010-12-14 16:56:55 +0900125}