smp.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright 2007-2009 Analog Devices Inc.
  3. * Philippe Gerum <rpm@xenomai.org>
  4. *
  5. * Licensed under the GPL-2 or later.
  6. */
  7. #include <linux/init.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/delay.h>
  11. #include <asm/smp.h>
  12. #include <asm/dma.h>
  13. #include <asm/time.h>
  14. static DEFINE_SPINLOCK(boot_lock);
  15. /*
  16. * platform_init_cpus() - Tell the world about how many cores we
  17. * have. This is called while setting up the architecture support
  18. * (setup_arch()), so don't be too demanding here with respect to
  19. * available kernel services.
  20. */
  21. void __init platform_init_cpus(void)
  22. {
  23. cpu_set(0, cpu_possible_map); /* CoreA */
  24. cpu_set(1, cpu_possible_map); /* CoreB */
  25. }
  26. void __init platform_prepare_cpus(unsigned int max_cpus)
  27. {
  28. bfin_relocate_coreb_l1_mem();
  29. /* Both cores ought to be present on a bf561! */
  30. cpu_set(0, cpu_present_map); /* CoreA */
  31. cpu_set(1, cpu_present_map); /* CoreB */
  32. }
  33. int __init setup_profiling_timer(unsigned int multiplier) /* not supported */
  34. {
  35. return -EINVAL;
  36. }
  37. void __cpuinit platform_secondary_init(unsigned int cpu)
  38. {
  39. /* Clone setup for peripheral interrupt sources from CoreA. */
  40. bfin_write_SICB_IMASK0(bfin_read_SIC_IMASK0());
  41. bfin_write_SICB_IMASK1(bfin_read_SIC_IMASK1());
  42. SSYNC();
  43. /* Clone setup for IARs from CoreA. */
  44. bfin_write_SICB_IAR0(bfin_read_SIC_IAR0());
  45. bfin_write_SICB_IAR1(bfin_read_SIC_IAR1());
  46. bfin_write_SICB_IAR2(bfin_read_SIC_IAR2());
  47. bfin_write_SICB_IAR3(bfin_read_SIC_IAR3());
  48. bfin_write_SICB_IAR4(bfin_read_SIC_IAR4());
  49. bfin_write_SICB_IAR5(bfin_read_SIC_IAR5());
  50. bfin_write_SICB_IAR6(bfin_read_SIC_IAR6());
  51. bfin_write_SICB_IAR7(bfin_read_SIC_IAR7());
  52. bfin_write_SICB_IWR0(IWR_DISABLE_ALL);
  53. bfin_write_SICB_IWR1(IWR_DISABLE_ALL);
  54. SSYNC();
  55. /* Store CPU-private information to the cpu_data array. */
  56. bfin_setup_cpudata(cpu);
  57. /* We are done with local CPU inits, unblock the boot CPU. */
  58. set_cpu_online(cpu, true);
  59. spin_lock(&boot_lock);
  60. spin_unlock(&boot_lock);
  61. }
  62. int __cpuinit platform_boot_secondary(unsigned int cpu, struct task_struct *idle)
  63. {
  64. unsigned long timeout;
  65. printk(KERN_INFO "Booting Core B.\n");
  66. spin_lock(&boot_lock);
  67. if ((bfin_read_SYSCR() & COREB_SRAM_INIT) == 0) {
  68. /* CoreB already running, sending ipi to wakeup it */
  69. platform_send_ipi_cpu(cpu, IRQ_SUPPLE_0);
  70. } else {
  71. /* Kick CoreB, which should start execution from CORE_SRAM_BASE. */
  72. bfin_write_SYSCR(bfin_read_SYSCR() & ~COREB_SRAM_INIT);
  73. SSYNC();
  74. }
  75. timeout = jiffies + 1 * HZ;
  76. while (time_before(jiffies, timeout)) {
  77. if (cpu_online(cpu))
  78. break;
  79. udelay(100);
  80. barrier();
  81. }
  82. if (cpu_online(cpu)) {
  83. /* release the lock and let coreb run */
  84. spin_unlock(&boot_lock);
  85. return 0;
  86. } else
  87. panic("CPU%u: processor failed to boot\n", cpu);
  88. }
  89. static const char supple0[] = "IRQ_SUPPLE_0";
  90. static const char supple1[] = "IRQ_SUPPLE_1";
  91. void __init platform_request_ipi(int irq, void *handler)
  92. {
  93. int ret;
  94. const char *name = (irq == IRQ_SUPPLE_0) ? supple0 : supple1;
  95. ret = request_irq(irq, handler, IRQF_DISABLED | IRQF_PERCPU, name, handler);
  96. if (ret)
  97. panic("Cannot request %s for IPI service", name);
  98. }
  99. void platform_send_ipi(cpumask_t callmap, int irq)
  100. {
  101. unsigned int cpu;
  102. int offset = (irq == IRQ_SUPPLE_0) ? 6 : 8;
  103. for_each_cpu_mask(cpu, callmap) {
  104. BUG_ON(cpu >= 2);
  105. SSYNC();
  106. bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu)));
  107. SSYNC();
  108. }
  109. }
  110. void platform_send_ipi_cpu(unsigned int cpu, int irq)
  111. {
  112. int offset = (irq == IRQ_SUPPLE_0) ? 6 : 8;
  113. BUG_ON(cpu >= 2);
  114. SSYNC();
  115. bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu)));
  116. SSYNC();
  117. }
  118. void platform_clear_ipi(unsigned int cpu, int irq)
  119. {
  120. int offset = (irq == IRQ_SUPPLE_0) ? 10 : 12;
  121. BUG_ON(cpu >= 2);
  122. SSYNC();
  123. bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (offset + cpu)));
  124. SSYNC();
  125. }
  126. /*
  127. * Setup core B's local core timer.
  128. * In SMP, core timer is used for clock event device.
  129. */
  130. void __cpuinit bfin_local_timer_setup(void)
  131. {
  132. #if defined(CONFIG_TICKSOURCE_CORETMR)
  133. struct irq_data *data = irq_get_irq_data(IRQ_CORETMR);
  134. struct irq_chip *chip = irq_data_get_irq_chip(data);
  135. bfin_coretmr_init();
  136. bfin_coretmr_clockevent_init();
  137. chip->irq_unmask(data);
  138. #else
  139. /* Power down the core timer, just to play safe. */
  140. bfin_write_TCNTL(0);
  141. #endif
  142. }