smp-shx3.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * SH-X3 SMP
  3. *
  4. * Copyright (C) 2007 - 2008 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/cpumask.h>
  13. #include <linux/smp.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/io.h>
  16. #define STBCR_REG(phys_id) (0xfe400004 | (phys_id << 12))
  17. #define RESET_REG(phys_id) (0xfe400008 | (phys_id << 12))
  18. #define STBCR_MSTP 0x00000001
  19. #define STBCR_RESET 0x00000002
  20. #define STBCR_LTSLP 0x80000000
  21. static irqreturn_t ipi_interrupt_handler(int irq, void *arg)
  22. {
  23. unsigned int message = (unsigned int)(long)arg;
  24. unsigned int cpu = hard_smp_processor_id();
  25. unsigned int offs = 4 * cpu;
  26. unsigned int x;
  27. x = __raw_readl(0xfe410070 + offs); /* C0INITICI..CnINTICI */
  28. x &= (1 << (message << 2));
  29. __raw_writel(x, 0xfe410080 + offs); /* C0INTICICLR..CnINTICICLR */
  30. smp_message_recv(message);
  31. return IRQ_HANDLED;
  32. }
  33. void __init plat_smp_setup(void)
  34. {
  35. unsigned int cpu = 0;
  36. int i, num;
  37. init_cpu_possible(cpumask_of(cpu));
  38. /* Enable light sleep for the boot CPU */
  39. __raw_writel(__raw_readl(STBCR_REG(cpu)) | STBCR_LTSLP, STBCR_REG(cpu));
  40. __cpu_number_map[0] = 0;
  41. __cpu_logical_map[0] = 0;
  42. /*
  43. * Do this stupidly for now.. we don't have an easy way to probe
  44. * for the total number of cores.
  45. */
  46. for (i = 1, num = 0; i < NR_CPUS; i++) {
  47. set_cpu_possible(i, true);
  48. __cpu_number_map[i] = ++num;
  49. __cpu_logical_map[num] = i;
  50. }
  51. printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num);
  52. }
  53. void __init plat_prepare_cpus(unsigned int max_cpus)
  54. {
  55. int i;
  56. local_timer_setup(0);
  57. BUILD_BUG_ON(SMP_MSG_NR >= 8);
  58. for (i = 0; i < SMP_MSG_NR; i++)
  59. request_irq(104 + i, ipi_interrupt_handler, IRQF_DISABLED,
  60. "IPI", (void *)(long)i);
  61. }
  62. void plat_start_cpu(unsigned int cpu, unsigned long entry_point)
  63. {
  64. __raw_writel(entry_point, RESET_REG(cpu));
  65. if (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP))
  66. __raw_writel(STBCR_MSTP, STBCR_REG(cpu));
  67. while (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP))
  68. cpu_relax();
  69. /* Start up secondary processor by sending a reset */
  70. __raw_writel(STBCR_RESET | STBCR_LTSLP, STBCR_REG(cpu));
  71. }
  72. int plat_smp_processor_id(void)
  73. {
  74. return __raw_readl(0xff000048); /* CPIDR */
  75. }
  76. void plat_send_ipi(unsigned int cpu, unsigned int message)
  77. {
  78. unsigned long addr = 0xfe410070 + (cpu * 4);
  79. BUG_ON(cpu >= 4);
  80. __raw_writel(1 << (message << 2), addr); /* C0INTICI..CnINTICI */
  81. }