ARM: shmobile: Add CPU notifier based SCU boot vector code
[linux-2.6-block.git] / arch / arm / mach-shmobile / platsmp-scu.c
CommitLineData
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 */
916d6121 10#include <linux/cpu.h>
e7b1c963 11#include <linux/delay.h>
c970d4ef
MD
12#include <linux/init.h>
13#include <linux/io.h>
14#include <linux/smp.h>
e7b1c963 15#include <asm/cacheflush.h>
c970d4ef
MD
16#include <asm/smp_plat.h>
17#include <asm/smp_scu.h>
18#include <mach/common.h>
19
916d6121
MD
20static int shmobile_smp_scu_notifier_call(struct notifier_block *nfb,
21 unsigned long action, void *hcpu)
22{
23 unsigned int cpu = (long)hcpu;
24
25 switch (action) {
26 case CPU_UP_PREPARE:
27 /* For this particular CPU register SCU SMP boot vector */
28 shmobile_smp_hook(cpu, virt_to_phys(shmobile_boot_scu),
29 (unsigned long)shmobile_scu_base);
30 break;
31 };
32
33 return NOTIFY_OK;
34}
35
36static struct notifier_block shmobile_smp_scu_notifier = {
37 .notifier_call = shmobile_smp_scu_notifier_call,
38};
39
c970d4ef
MD
40void __init shmobile_smp_scu_prepare_cpus(unsigned int max_cpus)
41{
1d33a354
MD
42 /* install boot code shared by all CPUs */
43 shmobile_boot_fn = virt_to_phys(shmobile_smp_boot);
44 shmobile_boot_arg = MPIDR_HWID_BITMASK;
c970d4ef
MD
45
46 /* enable SCU and cache coherency on booting CPU */
47 scu_enable(shmobile_scu_base);
48 scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL);
916d6121
MD
49
50 /* Use CPU notifier for reset vector control */
51 register_cpu_notifier(&shmobile_smp_scu_notifier);
c970d4ef
MD
52}
53
54int shmobile_smp_scu_boot_secondary(unsigned int cpu, struct task_struct *idle)
55{
1d33a354
MD
56 /* For this particular CPU register SCU boot vector */
57 shmobile_smp_hook(cpu, virt_to_phys(shmobile_boot_scu),
58 (unsigned long)shmobile_scu_base);
c970d4ef
MD
59 return 0;
60}
e7b1c963
MD
61
62#ifdef CONFIG_HOTPLUG_CPU
63void shmobile_smp_scu_cpu_die(unsigned int cpu)
64{
1d33a354
MD
65 /* For this particular CPU deregister boot vector */
66 shmobile_smp_hook(cpu, 0, 0);
67
e7b1c963
MD
68 dsb();
69 flush_cache_all();
70
71 /* disable cache coherency */
72 scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF);
73
1d33a354
MD
74 /* jump to shared mach-shmobile sleep / reset code */
75 shmobile_smp_sleep();
e7b1c963
MD
76}
77
78static int shmobile_smp_scu_psr_core_disabled(int cpu)
79{
80 unsigned long mask = SCU_PM_POWEROFF << (cpu * 8);
81
82 if ((__raw_readl(shmobile_scu_base + 8) & mask) == mask)
83 return 1;
84
85 return 0;
86}
87
88int shmobile_smp_scu_cpu_kill(unsigned int cpu)
89{
90 int k;
91
92 /* this function is running on another CPU than the offline target,
93 * here we need wait for shutdown code in platform_cpu_die() to
94 * finish before asking SoC-specific code to power off the CPU core.
95 */
96 for (k = 0; k < 1000; k++) {
97 if (shmobile_smp_scu_psr_core_disabled(cpu))
98 return 1;
99
100 mdelay(1);
101 }
102
103 return 0;
104}
105#endif