ARM: 8640/1: Add support for CONFIG_DEBUG_VIRTUAL
[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>
fd44aa5e 18#include "common.h"
c970d4ef 19
d2613f56 20
8701d808
GU
21static phys_addr_t shmobile_scu_base_phys;
22static void __iomem *shmobile_scu_base;
d2613f56 23
657ebf7a 24static int shmobile_scu_cpu_prepare(unsigned int cpu)
916d6121 25{
657ebf7a
SAS
26 /* For this particular CPU register SCU SMP boot vector */
27 shmobile_smp_hook(cpu, virt_to_phys(shmobile_boot_scu),
28 shmobile_scu_base_phys);
29 return 0;
916d6121
MD
30}
31
8701d808
GU
32void __init shmobile_smp_scu_prepare_cpus(phys_addr_t scu_base_phys,
33 unsigned int max_cpus)
c970d4ef 34{
1d33a354
MD
35 /* install boot code shared by all CPUs */
36 shmobile_boot_fn = virt_to_phys(shmobile_smp_boot);
c970d4ef
MD
37
38 /* enable SCU and cache coherency on booting CPU */
8701d808
GU
39 shmobile_scu_base_phys = scu_base_phys;
40 shmobile_scu_base = ioremap(scu_base_phys, PAGE_SIZE);
c970d4ef
MD
41 scu_enable(shmobile_scu_base);
42 scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL);
916d6121
MD
43
44 /* Use CPU notifier for reset vector control */
657ebf7a
SAS
45 cpuhp_setup_state_nocalls(CPUHP_ARM_SHMOBILE_SCU_PREPARE,
46 "arm/shmobile-scu:prepare",
47 shmobile_scu_cpu_prepare, NULL);
c970d4ef
MD
48}
49
e7b1c963
MD
50#ifdef CONFIG_HOTPLUG_CPU
51void shmobile_smp_scu_cpu_die(unsigned int cpu)
52{
1d33a354
MD
53 /* For this particular CPU deregister boot vector */
54 shmobile_smp_hook(cpu, 0, 0);
55
e7b1c963
MD
56 dsb();
57 flush_cache_all();
58
59 /* disable cache coherency */
60 scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF);
61
1d33a354
MD
62 /* jump to shared mach-shmobile sleep / reset code */
63 shmobile_smp_sleep();
e7b1c963
MD
64}
65
66static int shmobile_smp_scu_psr_core_disabled(int cpu)
67{
68 unsigned long mask = SCU_PM_POWEROFF << (cpu * 8);
69
70 if ((__raw_readl(shmobile_scu_base + 8) & mask) == mask)
71 return 1;
72
73 return 0;
74}
75
76int shmobile_smp_scu_cpu_kill(unsigned int cpu)
77{
78 int k;
79
80 /* this function is running on another CPU than the offline target,
81 * here we need wait for shutdown code in platform_cpu_die() to
82 * finish before asking SoC-specific code to power off the CPU core.
83 */
84 for (k = 0; k < 1000; k++) {
85 if (shmobile_smp_scu_psr_core_disabled(cpu))
86 return 1;
87
88 mdelay(1);
89 }
90
91 return 0;
92}
93#endif