smp.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * File: arch/blackfin/mach-bf561/smp.c
  3. * Author: Philippe Gerum <rpm@xenomai.org>
  4. *
  5. * Copyright 2007 Analog Devices Inc.
  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; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see the file COPYING, or write
  19. * to the Free Software Foundation, Inc.,
  20. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/kernel.h>
  24. #include <linux/sched.h>
  25. #include <linux/delay.h>
  26. #include <asm/smp.h>
  27. #include <asm/dma.h>
  28. #define COREB_SRAM_BASE 0xff600000
  29. #define COREB_SRAM_SIZE 0x4000
  30. extern char coreb_trampoline_start, coreb_trampoline_end;
  31. static DEFINE_SPINLOCK(boot_lock);
  32. static cpumask_t cpu_callin_map;
  33. /*
  34. * platform_init_cpus() - Tell the world about how many cores we
  35. * have. This is called while setting up the architecture support
  36. * (setup_arch()), so don't be too demanding here with respect to
  37. * available kernel services.
  38. */
  39. void __init platform_init_cpus(void)
  40. {
  41. cpu_set(0, cpu_possible_map); /* CoreA */
  42. cpu_set(1, cpu_possible_map); /* CoreB */
  43. }
  44. void __init platform_prepare_cpus(unsigned int max_cpus)
  45. {
  46. int len;
  47. len = &coreb_trampoline_end - &coreb_trampoline_start + 1;
  48. BUG_ON(len > COREB_SRAM_SIZE);
  49. dma_memcpy((void *)COREB_SRAM_BASE, &coreb_trampoline_start, len);
  50. /* Both cores ought to be present on a bf561! */
  51. cpu_set(0, cpu_present_map); /* CoreA */
  52. cpu_set(1, cpu_present_map); /* CoreB */
  53. printk(KERN_INFO "CoreB bootstrap code to SRAM %p via DMA.\n", (void *)COREB_SRAM_BASE);
  54. }
  55. int __init setup_profiling_timer(unsigned int multiplier) /* not supported */
  56. {
  57. return -EINVAL;
  58. }
  59. void __cpuinit platform_secondary_init(unsigned int cpu)
  60. {
  61. local_irq_disable();
  62. /* Clone setup for peripheral interrupt sources from CoreA. */
  63. bfin_write_SICB_IMASK0(bfin_read_SICA_IMASK0());
  64. bfin_write_SICB_IMASK1(bfin_read_SICA_IMASK1());
  65. SSYNC();
  66. /* Clone setup for IARs from CoreA. */
  67. bfin_write_SICB_IAR0(bfin_read_SICA_IAR0());
  68. bfin_write_SICB_IAR1(bfin_read_SICA_IAR1());
  69. bfin_write_SICB_IAR2(bfin_read_SICA_IAR2());
  70. bfin_write_SICB_IAR3(bfin_read_SICA_IAR3());
  71. bfin_write_SICB_IAR4(bfin_read_SICA_IAR4());
  72. bfin_write_SICB_IAR5(bfin_read_SICA_IAR5());
  73. bfin_write_SICB_IAR6(bfin_read_SICA_IAR6());
  74. bfin_write_SICB_IAR7(bfin_read_SICA_IAR7());
  75. SSYNC();
  76. local_irq_enable();
  77. /* Calibrate loops per jiffy value. */
  78. calibrate_delay();
  79. /* Store CPU-private information to the cpu_data array. */
  80. bfin_setup_cpudata(cpu);
  81. /* We are done with local CPU inits, unblock the boot CPU. */
  82. cpu_set(cpu, cpu_callin_map);
  83. spin_lock(&boot_lock);
  84. spin_unlock(&boot_lock);
  85. }
  86. int __cpuinit platform_boot_secondary(unsigned int cpu, struct task_struct *idle)
  87. {
  88. unsigned long timeout;
  89. /* CoreB already running?! */
  90. BUG_ON((bfin_read_SICA_SYSCR() & COREB_SRAM_INIT) == 0);
  91. printk(KERN_INFO "Booting Core B.\n");
  92. spin_lock(&boot_lock);
  93. /* Kick CoreB, which should start execution from CORE_SRAM_BASE. */
  94. SSYNC();
  95. bfin_write_SICA_SYSCR(bfin_read_SICA_SYSCR() & ~COREB_SRAM_INIT);
  96. SSYNC();
  97. timeout = jiffies + 1 * HZ;
  98. while (time_before(jiffies, timeout)) {
  99. if (cpu_isset(cpu, cpu_callin_map))
  100. break;
  101. udelay(100);
  102. barrier();
  103. }
  104. spin_unlock(&boot_lock);
  105. return cpu_isset(cpu, cpu_callin_map) ? 0 : -ENOSYS;
  106. }
  107. void __init platform_request_ipi(irq_handler_t handler)
  108. {
  109. int ret;
  110. ret = request_irq(IRQ_SUPPLE_0, handler, IRQF_DISABLED,
  111. "SMP interrupt", handler);
  112. if (ret)
  113. panic("Cannot request supplemental interrupt 0 for IPI service\n");
  114. }
  115. void platform_send_ipi(cpumask_t callmap)
  116. {
  117. unsigned int cpu;
  118. for_each_cpu_mask(cpu, callmap) {
  119. BUG_ON(cpu >= 2);
  120. SSYNC();
  121. bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (6 + cpu)));
  122. SSYNC();
  123. }
  124. }
  125. void platform_send_ipi_cpu(unsigned int cpu)
  126. {
  127. BUG_ON(cpu >= 2);
  128. SSYNC();
  129. bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (6 + cpu)));
  130. SSYNC();
  131. }
  132. void platform_clear_ipi(unsigned int cpu)
  133. {
  134. BUG_ON(cpu >= 2);
  135. SSYNC();
  136. bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (10 + cpu)));
  137. SSYNC();
  138. }