smp-shx3.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * SH-X3 SMP
  3. *
  4. * Copyright (C) 2007 - 2010 Paul Mundt
  5. * Copyright (C) 2007 Magnus Damm
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/cpumask.h>
  14. #include <linux/smp.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/io.h>
  17. #include <linux/sched.h>
  18. #include <linux/delay.h>
  19. #include <linux/cpu.h>
  20. #include <asm/sections.h>
  21. #define STBCR_REG(phys_id) (0xfe400004 | (phys_id << 12))
  22. #define RESET_REG(phys_id) (0xfe400008 | (phys_id << 12))
  23. #define STBCR_MSTP 0x00000001
  24. #define STBCR_RESET 0x00000002
  25. #define STBCR_SLEEP 0x00000004
  26. #define STBCR_LTSLP 0x80000000
  27. static irqreturn_t ipi_interrupt_handler(int irq, void *arg)
  28. {
  29. unsigned int message = (unsigned int)(long)arg;
  30. unsigned int cpu = hard_smp_processor_id();
  31. unsigned int offs = 4 * cpu;
  32. unsigned int x;
  33. x = __raw_readl(0xfe410070 + offs); /* C0INITICI..CnINTICI */
  34. x &= (1 << (message << 2));
  35. __raw_writel(x, 0xfe410080 + offs); /* C0INTICICLR..CnINTICICLR */
  36. smp_message_recv(message);
  37. return IRQ_HANDLED;
  38. }
  39. static void shx3_smp_setup(void)
  40. {
  41. unsigned int cpu = 0;
  42. int i, num;
  43. init_cpu_possible(cpumask_of(cpu));
  44. /* Enable light sleep for the boot CPU */
  45. __raw_writel(__raw_readl(STBCR_REG(cpu)) | STBCR_LTSLP, STBCR_REG(cpu));
  46. __cpu_number_map[0] = 0;
  47. __cpu_logical_map[0] = 0;
  48. /*
  49. * Do this stupidly for now.. we don't have an easy way to probe
  50. * for the total number of cores.
  51. */
  52. for (i = 1, num = 0; i < NR_CPUS; i++) {
  53. set_cpu_possible(i, true);
  54. __cpu_number_map[i] = ++num;
  55. __cpu_logical_map[num] = i;
  56. }
  57. printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num);
  58. }
  59. static void shx3_prepare_cpus(unsigned int max_cpus)
  60. {
  61. int i;
  62. local_timer_setup(0);
  63. BUILD_BUG_ON(SMP_MSG_NR >= 8);
  64. for (i = 0; i < SMP_MSG_NR; i++)
  65. request_irq(104 + i, ipi_interrupt_handler,
  66. IRQF_PERCPU, "IPI", (void *)(long)i);
  67. for (i = 0; i < max_cpus; i++)
  68. set_cpu_present(i, true);
  69. }
  70. static void shx3_start_cpu(unsigned int cpu, unsigned long entry_point)
  71. {
  72. if (__in_29bit_mode())
  73. __raw_writel(entry_point, RESET_REG(cpu));
  74. else
  75. __raw_writel(virt_to_phys(entry_point), RESET_REG(cpu));
  76. if (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP))
  77. __raw_writel(STBCR_MSTP, STBCR_REG(cpu));
  78. while (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP))
  79. cpu_relax();
  80. /* Start up secondary processor by sending a reset */
  81. __raw_writel(STBCR_RESET | STBCR_LTSLP, STBCR_REG(cpu));
  82. }
  83. static unsigned int shx3_smp_processor_id(void)
  84. {
  85. return __raw_readl(0xff000048); /* CPIDR */
  86. }
  87. static void shx3_send_ipi(unsigned int cpu, unsigned int message)
  88. {
  89. unsigned long addr = 0xfe410070 + (cpu * 4);
  90. BUG_ON(cpu >= 4);
  91. __raw_writel(1 << (message << 2), addr); /* C0INTICI..CnINTICI */
  92. }
  93. static void shx3_update_boot_vector(unsigned int cpu)
  94. {
  95. __raw_writel(STBCR_MSTP, STBCR_REG(cpu));
  96. while (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP))
  97. cpu_relax();
  98. __raw_writel(STBCR_RESET, STBCR_REG(cpu));
  99. }
  100. static int
  101. shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  102. {
  103. unsigned int cpu = (unsigned int)hcpu;
  104. switch (action) {
  105. case CPU_UP_PREPARE:
  106. shx3_update_boot_vector(cpu);
  107. break;
  108. case CPU_ONLINE:
  109. pr_info("CPU %u is now online\n", cpu);
  110. break;
  111. case CPU_DEAD:
  112. break;
  113. }
  114. return NOTIFY_OK;
  115. }
  116. static struct notifier_block shx3_cpu_notifier = {
  117. .notifier_call = shx3_cpu_callback,
  118. };
  119. static int register_shx3_cpu_notifier(void)
  120. {
  121. register_hotcpu_notifier(&shx3_cpu_notifier);
  122. return 0;
  123. }
  124. late_initcall(register_shx3_cpu_notifier);
  125. struct plat_smp_ops shx3_smp_ops = {
  126. .smp_setup = shx3_smp_setup,
  127. .prepare_cpus = shx3_prepare_cpus,
  128. .start_cpu = shx3_start_cpu,
  129. .smp_processor_id = shx3_smp_processor_id,
  130. .send_ipi = shx3_send_ipi,
  131. .cpu_die = native_cpu_die,
  132. .cpu_disable = native_cpu_disable,
  133. .play_dead = native_play_dead,
  134. };