smp.c 3.6 KB

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