smp.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2001, 2002, 2003 Broadcom Corporation
  4. */
  5. #include <linux/init.h>
  6. #include <linux/delay.h>
  7. #include <linux/interrupt.h>
  8. #include <linux/smp.h>
  9. #include <linux/kernel_stat.h>
  10. #include <linux/sched/task_stack.h>
  11. #include <asm/mmu_context.h>
  12. #include <asm/io.h>
  13. #include <asm/fw/cfe/cfe_api.h>
  14. #include <asm/sibyte/sb1250.h>
  15. #include <asm/sibyte/sb1250_regs.h>
  16. #include <asm/sibyte/sb1250_int.h>
  17. static void *mailbox_set_regs[] = {
  18. IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_SET_CPU),
  19. IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_SET_CPU)
  20. };
  21. static void *mailbox_clear_regs[] = {
  22. IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_CLR_CPU),
  23. IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_CLR_CPU)
  24. };
  25. static void *mailbox_regs[] = {
  26. IOADDR(A_IMR_CPU0_BASE + R_IMR_MAILBOX_CPU),
  27. IOADDR(A_IMR_CPU1_BASE + R_IMR_MAILBOX_CPU)
  28. };
  29. /*
  30. * SMP init and finish on secondary CPUs
  31. */
  32. void sb1250_smp_init(void)
  33. {
  34. unsigned int imask = STATUSF_IP4 | STATUSF_IP3 | STATUSF_IP2 |
  35. STATUSF_IP1 | STATUSF_IP0;
  36. /* Set interrupt mask, but don't enable */
  37. change_c0_status(ST0_IM, imask);
  38. }
  39. /*
  40. * These are routines for dealing with the sb1250 smp capabilities
  41. * independent of board/firmware
  42. */
  43. /*
  44. * Simple enough; everything is set up, so just poke the appropriate mailbox
  45. * register, and we should be set
  46. */
  47. static void sb1250_send_ipi_single(int cpu, unsigned int action)
  48. {
  49. __raw_writeq((((u64)action) << 48), mailbox_set_regs[cpu]);
  50. }
  51. static inline void sb1250_send_ipi_mask(const struct cpumask *mask,
  52. unsigned int action)
  53. {
  54. unsigned int i;
  55. for_each_cpu(i, mask)
  56. sb1250_send_ipi_single(i, action);
  57. }
  58. /*
  59. * Code to run on secondary just after probing the CPU
  60. */
  61. static void sb1250_init_secondary(void)
  62. {
  63. extern void sb1250_smp_init(void);
  64. sb1250_smp_init();
  65. }
  66. /*
  67. * Do any tidying up before marking online and running the idle
  68. * loop
  69. */
  70. static void sb1250_smp_finish(void)
  71. {
  72. extern void sb1250_clockevent_init(void);
  73. sb1250_clockevent_init();
  74. local_irq_enable();
  75. }
  76. /*
  77. * Setup the PC, SP, and GP of a secondary processor and start it
  78. * running!
  79. */
  80. static int sb1250_boot_secondary(int cpu, struct task_struct *idle)
  81. {
  82. int retval;
  83. retval = cfe_cpu_start(cpu_logical_map(cpu), &smp_bootstrap,
  84. __KSTK_TOS(idle),
  85. (unsigned long)task_thread_info(idle), 0);
  86. if (retval != 0)
  87. printk("cfe_start_cpu(%i) returned %i\n" , cpu, retval);
  88. return retval;
  89. }
  90. /*
  91. * Use CFE to find out how many CPUs are available, setting up
  92. * cpu_possible_mask and the logical/physical mappings.
  93. * XXXKW will the boot CPU ever not be physical 0?
  94. *
  95. * Common setup before any secondaries are started
  96. */
  97. static void __init sb1250_smp_setup(void)
  98. {
  99. int i, num;
  100. init_cpu_possible(cpumask_of(0));
  101. __cpu_number_map[0] = 0;
  102. __cpu_logical_map[0] = 0;
  103. for (i = 1, num = 0; i < NR_CPUS; i++) {
  104. if (cfe_cpu_stop(i) == 0) {
  105. set_cpu_possible(i, true);
  106. __cpu_number_map[i] = ++num;
  107. __cpu_logical_map[num] = i;
  108. }
  109. }
  110. printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num);
  111. }
  112. static void __init sb1250_prepare_cpus(unsigned int max_cpus)
  113. {
  114. }
  115. const struct plat_smp_ops sb_smp_ops = {
  116. .send_ipi_single = sb1250_send_ipi_single,
  117. .send_ipi_mask = sb1250_send_ipi_mask,
  118. .init_secondary = sb1250_init_secondary,
  119. .smp_finish = sb1250_smp_finish,
  120. .boot_secondary = sb1250_boot_secondary,
  121. .smp_setup = sb1250_smp_setup,
  122. .prepare_cpus = sb1250_prepare_cpus,
  123. };
  124. void sb1250_mailbox_interrupt(void)
  125. {
  126. int cpu = smp_processor_id();
  127. int irq = K_INT_MBOX_0;
  128. unsigned int action;
  129. kstat_incr_irq_this_cpu(irq);
  130. /* Load the mailbox register to figure out what we're supposed to do */
  131. action = (____raw_readq(mailbox_regs[cpu]) >> 48) & 0xffff;
  132. /* Clear the mailbox to clear the interrupt */
  133. ____raw_writeq(((u64)action) << 48, mailbox_clear_regs[cpu]);
  134. if (action & SMP_RESCHEDULE_YOURSELF)
  135. scheduler_ipi();
  136. if (action & SMP_CALL_FUNCTION) {
  137. irq_enter();
  138. generic_smp_call_function_interrupt();
  139. irq_exit();
  140. }
  141. }