smp-sh73a0.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * SMP support for R-Mobile / SH-Mobile - sh73a0 portion
  3. *
  4. * Copyright (C) 2010 Magnus Damm
  5. * Copyright (C) 2010 Takashi Yoshii
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/smp.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/io.h>
  25. #include <linux/delay.h>
  26. #include <linux/irqchip/arm-gic.h>
  27. #include <mach/common.h>
  28. #include <asm/cacheflush.h>
  29. #include <asm/smp_plat.h>
  30. #include <mach/sh73a0.h>
  31. #include <asm/smp_scu.h>
  32. #include <asm/smp_twd.h>
  33. #define WUPCR IOMEM(0xe6151010)
  34. #define SRESCR IOMEM(0xe6151018)
  35. #define PSTR IOMEM(0xe6151040)
  36. #define SBAR IOMEM(0xe6180020)
  37. #define APARMBAREA IOMEM(0xe6f10020)
  38. #define PSTR_SHUTDOWN_MODE 3
  39. static void __iomem *scu_base_addr(void)
  40. {
  41. return (void __iomem *)0xf0000000;
  42. }
  43. #ifdef CONFIG_HAVE_ARM_TWD
  44. static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, 0xf0000600, 29);
  45. void __init sh73a0_register_twd(void)
  46. {
  47. twd_local_timer_register(&twd_local_timer);
  48. }
  49. #endif
  50. static unsigned int __init sh73a0_get_core_count(void)
  51. {
  52. void __iomem *scu_base = scu_base_addr();
  53. return scu_get_core_count(scu_base);
  54. }
  55. static void __cpuinit sh73a0_secondary_init(unsigned int cpu)
  56. {
  57. gic_secondary_init(0);
  58. }
  59. static int __cpuinit sh73a0_boot_secondary(unsigned int cpu, struct task_struct *idle)
  60. {
  61. cpu = cpu_logical_map(cpu);
  62. if (((__raw_readl(PSTR) >> (4 * cpu)) & 3) == 3)
  63. __raw_writel(1 << cpu, WUPCR); /* wake up */
  64. else
  65. __raw_writel(1 << cpu, SRESCR); /* reset */
  66. return 0;
  67. }
  68. static void __init sh73a0_smp_prepare_cpus(unsigned int max_cpus)
  69. {
  70. scu_enable(scu_base_addr());
  71. /* Map the reset vector (in headsmp-sh73a0.S) */
  72. __raw_writel(0, APARMBAREA); /* 4k */
  73. __raw_writel(__pa(sh73a0_secondary_vector), SBAR);
  74. /* enable cache coherency on booting CPU */
  75. scu_power_mode(scu_base_addr(), SCU_PM_NORMAL);
  76. }
  77. static void __init sh73a0_smp_init_cpus(void)
  78. {
  79. unsigned int ncores = sh73a0_get_core_count();
  80. shmobile_smp_init_cpus(ncores);
  81. }
  82. #ifdef CONFIG_HOTPLUG_CPU
  83. static int sh73a0_cpu_kill(unsigned int cpu)
  84. {
  85. int k;
  86. u32 pstr;
  87. /*
  88. * wait until the power status register confirms the shutdown of the
  89. * offline target
  90. */
  91. for (k = 0; k < 1000; k++) {
  92. pstr = (__raw_readl(PSTR) >> (4 * cpu)) & 3;
  93. if (pstr == PSTR_SHUTDOWN_MODE)
  94. return 1;
  95. mdelay(1);
  96. }
  97. return 0;
  98. }
  99. static void sh73a0_cpu_die(unsigned int cpu)
  100. {
  101. /*
  102. * The ARM MPcore does not issue a cache coherency request for the L1
  103. * cache when powering off single CPUs. We must take care of this and
  104. * further caches.
  105. */
  106. dsb();
  107. flush_cache_all();
  108. /* Set power off mode. This takes the CPU out of the MP cluster */
  109. scu_power_mode(scu_base_addr(), SCU_PM_POWEROFF);
  110. /* Enter shutdown mode */
  111. cpu_do_idle();
  112. }
  113. #endif /* CONFIG_HOTPLUG_CPU */
  114. struct smp_operations sh73a0_smp_ops __initdata = {
  115. .smp_init_cpus = sh73a0_smp_init_cpus,
  116. .smp_prepare_cpus = sh73a0_smp_prepare_cpus,
  117. .smp_secondary_init = sh73a0_secondary_init,
  118. .smp_boot_secondary = sh73a0_boot_secondary,
  119. #ifdef CONFIG_HOTPLUG_CPU
  120. .cpu_kill = sh73a0_cpu_kill,
  121. .cpu_die = sh73a0_cpu_die,
  122. .cpu_disable = shmobile_cpu_disable_any,
  123. #endif
  124. };