smp.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. static DEFINE_SPINLOCK(boot_lock);
  29. static cpumask_t cpu_callin_map;
  30. /*
  31. * platform_init_cpus() - Tell the world about how many cores we
  32. * have. This is called while setting up the architecture support
  33. * (setup_arch()), so don't be too demanding here with respect to
  34. * available kernel services.
  35. */
  36. void __init platform_init_cpus(void)
  37. {
  38. cpu_set(0, cpu_possible_map); /* CoreA */
  39. cpu_set(1, cpu_possible_map); /* CoreB */
  40. }
  41. void __init platform_prepare_cpus(unsigned int max_cpus)
  42. {
  43. int len;
  44. len = &coreb_trampoline_end - &coreb_trampoline_start + 1;
  45. BUG_ON(len > L1_CODE_LENGTH);
  46. dma_memcpy((void *)COREB_L1_CODE_START, &coreb_trampoline_start, len);
  47. /* Both cores ought to be present on a bf561! */
  48. cpu_set(0, cpu_present_map); /* CoreA */
  49. cpu_set(1, cpu_present_map); /* CoreB */
  50. printk(KERN_INFO "CoreB bootstrap code to SRAM %p via DMA.\n", (void *)COREB_L1_CODE_START);
  51. }
  52. int __init setup_profiling_timer(unsigned int multiplier) /* not supported */
  53. {
  54. return -EINVAL;
  55. }
  56. void __cpuinit platform_secondary_init(unsigned int cpu)
  57. {
  58. local_irq_disable();
  59. /* Clone setup for peripheral interrupt sources from CoreA. */
  60. bfin_write_SICB_IMASK0(bfin_read_SICA_IMASK0());
  61. bfin_write_SICB_IMASK1(bfin_read_SICA_IMASK1());
  62. SSYNC();
  63. /* Clone setup for IARs from CoreA. */
  64. bfin_write_SICB_IAR0(bfin_read_SICA_IAR0());
  65. bfin_write_SICB_IAR1(bfin_read_SICA_IAR1());
  66. bfin_write_SICB_IAR2(bfin_read_SICA_IAR2());
  67. bfin_write_SICB_IAR3(bfin_read_SICA_IAR3());
  68. bfin_write_SICB_IAR4(bfin_read_SICA_IAR4());
  69. bfin_write_SICB_IAR5(bfin_read_SICA_IAR5());
  70. bfin_write_SICB_IAR6(bfin_read_SICA_IAR6());
  71. bfin_write_SICB_IAR7(bfin_read_SICA_IAR7());
  72. SSYNC();
  73. local_irq_enable();
  74. /* Calibrate loops per jiffy value. */
  75. calibrate_delay();
  76. /* Store CPU-private information to the cpu_data array. */
  77. bfin_setup_cpudata(cpu);
  78. /* We are done with local CPU inits, unblock the boot CPU. */
  79. cpu_set(cpu, cpu_callin_map);
  80. spin_lock(&boot_lock);
  81. spin_unlock(&boot_lock);
  82. }
  83. int __cpuinit platform_boot_secondary(unsigned int cpu, struct task_struct *idle)
  84. {
  85. unsigned long timeout;
  86. /* CoreB already running?! */
  87. BUG_ON((bfin_read_SICA_SYSCR() & COREB_SRAM_INIT) == 0);
  88. printk(KERN_INFO "Booting Core B.\n");
  89. spin_lock(&boot_lock);
  90. /* Kick CoreB, which should start execution from CORE_SRAM_BASE. */
  91. SSYNC();
  92. bfin_write_SICA_SYSCR(bfin_read_SICA_SYSCR() & ~COREB_SRAM_INIT);
  93. SSYNC();
  94. timeout = jiffies + 1 * HZ;
  95. while (time_before(jiffies, timeout)) {
  96. if (cpu_isset(cpu, cpu_callin_map))
  97. break;
  98. udelay(100);
  99. barrier();
  100. }
  101. spin_unlock(&boot_lock);
  102. return cpu_isset(cpu, cpu_callin_map) ? 0 : -ENOSYS;
  103. }
  104. void __init platform_request_ipi(irq_handler_t handler)
  105. {
  106. int ret;
  107. ret = request_irq(IRQ_SUPPLE_0, handler, IRQF_DISABLED,
  108. "SMP interrupt", handler);
  109. if (ret)
  110. panic("Cannot request supplemental interrupt 0 for IPI service\n");
  111. }
  112. void platform_send_ipi(cpumask_t callmap)
  113. {
  114. unsigned int cpu;
  115. for_each_cpu_mask(cpu, callmap) {
  116. BUG_ON(cpu >= 2);
  117. SSYNC();
  118. bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (6 + cpu)));
  119. SSYNC();
  120. }
  121. }
  122. void platform_send_ipi_cpu(unsigned int cpu)
  123. {
  124. BUG_ON(cpu >= 2);
  125. SSYNC();
  126. bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (6 + cpu)));
  127. SSYNC();
  128. }
  129. void platform_clear_ipi(unsigned int cpu)
  130. {
  131. BUG_ON(cpu >= 2);
  132. SSYNC();
  133. bfin_write_SICB_SYSCR(bfin_read_SICB_SYSCR() | (1 << (10 + cpu)));
  134. SSYNC();
  135. }