Blame view

arch/arm/mach-shmobile/platsmp-scu.c 2.34 KB
c970d4ef3   Magnus Damm   ARM: shmobile: In...
1
2
3
4
5
6
7
8
9
  /*
   * SMP support for SoCs with SCU covered by mach-shmobile
   *
   * Copyright (C) 2013  Magnus Damm
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   */
916d6121b   Magnus Damm   ARM: shmobile: Ad...
10
  #include <linux/cpu.h>
e7b1c9638   Magnus Damm   ARM: shmobile: Ad...
11
  #include <linux/delay.h>
c970d4ef3   Magnus Damm   ARM: shmobile: In...
12
13
14
  #include <linux/init.h>
  #include <linux/io.h>
  #include <linux/smp.h>
e7b1c9638   Magnus Damm   ARM: shmobile: Ad...
15
  #include <asm/cacheflush.h>
c970d4ef3   Magnus Damm   ARM: shmobile: In...
16
17
  #include <asm/smp_plat.h>
  #include <asm/smp_scu.h>
fd44aa5e5   Magnus Damm   ARM: shmobile: Mo...
18
  #include "common.h"
c970d4ef3   Magnus Damm   ARM: shmobile: In...
19

916d6121b   Magnus Damm   ARM: shmobile: Ad...
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  static int shmobile_smp_scu_notifier_call(struct notifier_block *nfb,
  					  unsigned long action, void *hcpu)
  {
  	unsigned int cpu = (long)hcpu;
  
  	switch (action) {
  	case CPU_UP_PREPARE:
  		/* For this particular CPU register SCU SMP boot vector */
  		shmobile_smp_hook(cpu, virt_to_phys(shmobile_boot_scu),
  				  (unsigned long)shmobile_scu_base);
  		break;
  	};
  
  	return NOTIFY_OK;
  }
  
  static struct notifier_block shmobile_smp_scu_notifier = {
  	.notifier_call = shmobile_smp_scu_notifier_call,
  };
c970d4ef3   Magnus Damm   ARM: shmobile: In...
39
40
  void __init shmobile_smp_scu_prepare_cpus(unsigned int max_cpus)
  {
1d33a354b   Magnus Damm   ARM: shmobile: Pe...
41
42
43
  	/* install boot code shared by all CPUs */
  	shmobile_boot_fn = virt_to_phys(shmobile_smp_boot);
  	shmobile_boot_arg = MPIDR_HWID_BITMASK;
c970d4ef3   Magnus Damm   ARM: shmobile: In...
44
45
46
47
  
  	/* enable SCU and cache coherency on booting CPU */
  	scu_enable(shmobile_scu_base);
  	scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL);
916d6121b   Magnus Damm   ARM: shmobile: Ad...
48
49
50
  
  	/* Use CPU notifier for reset vector control */
  	register_cpu_notifier(&shmobile_smp_scu_notifier);
c970d4ef3   Magnus Damm   ARM: shmobile: In...
51
  }
e7b1c9638   Magnus Damm   ARM: shmobile: Ad...
52
53
54
  #ifdef CONFIG_HOTPLUG_CPU
  void shmobile_smp_scu_cpu_die(unsigned int cpu)
  {
1d33a354b   Magnus Damm   ARM: shmobile: Pe...
55
56
  	/* For this particular CPU deregister boot vector */
  	shmobile_smp_hook(cpu, 0, 0);
e7b1c9638   Magnus Damm   ARM: shmobile: Ad...
57
58
59
60
61
  	dsb();
  	flush_cache_all();
  
  	/* disable cache coherency */
  	scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF);
1d33a354b   Magnus Damm   ARM: shmobile: Pe...
62
63
  	/* jump to shared mach-shmobile sleep / reset code */
  	shmobile_smp_sleep();
e7b1c9638   Magnus Damm   ARM: shmobile: Ad...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  }
  
  static int shmobile_smp_scu_psr_core_disabled(int cpu)
  {
  	unsigned long mask = SCU_PM_POWEROFF << (cpu * 8);
  
  	if ((__raw_readl(shmobile_scu_base + 8) & mask) == mask)
  		return 1;
  
  	return 0;
  }
  
  int shmobile_smp_scu_cpu_kill(unsigned int cpu)
  {
  	int k;
  
  	/* this function is running on another CPU than the offline target,
  	 * here we need wait for shutdown code in platform_cpu_die() to
  	 * finish before asking SoC-specific code to power off the CPU core.
  	 */
  	for (k = 0; k < 1000; k++) {
  		if (shmobile_smp_scu_psr_core_disabled(cpu))
  			return 1;
  
  		mdelay(1);
  	}
  
  	return 0;
  }
  #endif