Commit | Line | Data |
---|---|---|
c970d4ef MD |
1 | /* |
2 | * SMP support for SoCs with SCU covered by mach-shmobile | |
3 | * | |
4 | * Copyright (C) 2013 Magnus Damm | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | */ | |
e7b1c963 | 10 | #include <linux/delay.h> |
c970d4ef MD |
11 | #include <linux/init.h> |
12 | #include <linux/io.h> | |
13 | #include <linux/smp.h> | |
e7b1c963 | 14 | #include <asm/cacheflush.h> |
c970d4ef MD |
15 | #include <asm/smp_plat.h> |
16 | #include <asm/smp_scu.h> | |
17 | #include <mach/common.h> | |
18 | ||
19 | void __init shmobile_smp_scu_prepare_cpus(unsigned int max_cpus) | |
20 | { | |
1d33a354 MD |
21 | /* install boot code shared by all CPUs */ |
22 | shmobile_boot_fn = virt_to_phys(shmobile_smp_boot); | |
23 | shmobile_boot_arg = MPIDR_HWID_BITMASK; | |
c970d4ef MD |
24 | |
25 | /* enable SCU and cache coherency on booting CPU */ | |
26 | scu_enable(shmobile_scu_base); | |
27 | scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL); | |
28 | } | |
29 | ||
30 | int shmobile_smp_scu_boot_secondary(unsigned int cpu, struct task_struct *idle) | |
31 | { | |
1d33a354 MD |
32 | /* For this particular CPU register SCU boot vector */ |
33 | shmobile_smp_hook(cpu, virt_to_phys(shmobile_boot_scu), | |
34 | (unsigned long)shmobile_scu_base); | |
c970d4ef MD |
35 | return 0; |
36 | } | |
e7b1c963 MD |
37 | |
38 | #ifdef CONFIG_HOTPLUG_CPU | |
39 | void shmobile_smp_scu_cpu_die(unsigned int cpu) | |
40 | { | |
1d33a354 MD |
41 | /* For this particular CPU deregister boot vector */ |
42 | shmobile_smp_hook(cpu, 0, 0); | |
43 | ||
e7b1c963 MD |
44 | dsb(); |
45 | flush_cache_all(); | |
46 | ||
47 | /* disable cache coherency */ | |
48 | scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF); | |
49 | ||
1d33a354 MD |
50 | /* jump to shared mach-shmobile sleep / reset code */ |
51 | shmobile_smp_sleep(); | |
e7b1c963 MD |
52 | } |
53 | ||
54 | static int shmobile_smp_scu_psr_core_disabled(int cpu) | |
55 | { | |
56 | unsigned long mask = SCU_PM_POWEROFF << (cpu * 8); | |
57 | ||
58 | if ((__raw_readl(shmobile_scu_base + 8) & mask) == mask) | |
59 | return 1; | |
60 | ||
61 | return 0; | |
62 | } | |
63 | ||
64 | int shmobile_smp_scu_cpu_kill(unsigned int cpu) | |
65 | { | |
66 | int k; | |
67 | ||
68 | /* this function is running on another CPU than the offline target, | |
69 | * here we need wait for shutdown code in platform_cpu_die() to | |
70 | * finish before asking SoC-specific code to power off the CPU core. | |
71 | */ | |
72 | for (k = 0; k < 1000; k++) { | |
73 | if (shmobile_smp_scu_psr_core_disabled(cpu)) | |
74 | return 1; | |
75 | ||
76 | mdelay(1); | |
77 | } | |
78 | ||
79 | return 0; | |
80 | } | |
81 | #endif |