smp.c 4.6 KB

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