platsmp.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * This file contains Xilinx specific SMP code, used to start up
  4. * the second processor.
  5. *
  6. * Copyright (C) 2011-2013 Xilinx
  7. *
  8. * based on linux/arch/arm/mach-realview/platsmp.c
  9. *
  10. * Copyright (C) 2002 ARM Ltd.
  11. */
  12. #include <linux/export.h>
  13. #include <linux/jiffies.h>
  14. #include <linux/init.h>
  15. #include <linux/io.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/smp_plat.h>
  18. #include <asm/smp_scu.h>
  19. #include <linux/irqchip/arm-gic.h>
  20. #include "common.h"
  21. /*
  22. * Store number of cores in the system
  23. * Because of scu_get_core_count() must be in __init section and can't
  24. * be called from zynq_cpun_start() because it is not in __init section.
  25. */
  26. static int ncores;
  27. int zynq_cpun_start(u32 address, int cpu)
  28. {
  29. u32 trampoline_code_size = &zynq_secondary_trampoline_end -
  30. &zynq_secondary_trampoline;
  31. u32 phy_cpuid = cpu_logical_map(cpu);
  32. /* MS: Expectation that SLCR are directly map and accessible */
  33. /* Not possible to jump to non aligned address */
  34. if (!(address & 3) && (!address || (address >= trampoline_code_size))) {
  35. /* Store pointer to ioremap area which points to address 0x0 */
  36. static u8 __iomem *zero;
  37. u32 trampoline_size = &zynq_secondary_trampoline_jump -
  38. &zynq_secondary_trampoline;
  39. zynq_slcr_cpu_stop(phy_cpuid);
  40. if (address) {
  41. if (__pa(PAGE_OFFSET)) {
  42. zero = ioremap(0, trampoline_code_size);
  43. if (!zero) {
  44. pr_warn("BOOTUP jump vectors not accessible\n");
  45. return -1;
  46. }
  47. } else {
  48. zero = (__force u8 __iomem *)PAGE_OFFSET;
  49. }
  50. /*
  51. * This is elegant way how to jump to any address
  52. * 0x0: Load address at 0x8 to r0
  53. * 0x4: Jump by mov instruction
  54. * 0x8: Jumping address
  55. */
  56. memcpy_toio(zero, &zynq_secondary_trampoline,
  57. trampoline_size);
  58. writel(address, zero + trampoline_size);
  59. flush_cache_all();
  60. outer_flush_range(0, trampoline_code_size);
  61. smp_wmb();
  62. if (__pa(PAGE_OFFSET))
  63. iounmap(zero);
  64. }
  65. zynq_slcr_cpu_start(phy_cpuid);
  66. return 0;
  67. }
  68. pr_warn("Can't start CPU%d: Wrong starting address %x\n", cpu, address);
  69. return -1;
  70. }
  71. EXPORT_SYMBOL(zynq_cpun_start);
  72. static int zynq_boot_secondary(unsigned int cpu, struct task_struct *idle)
  73. {
  74. return zynq_cpun_start(__pa_symbol(secondary_startup_arm), cpu);
  75. }
  76. /*
  77. * Initialise the CPU possible map early - this describes the CPUs
  78. * which may be present or become present in the system.
  79. */
  80. static void __init zynq_smp_init_cpus(void)
  81. {
  82. int i;
  83. ncores = scu_get_core_count(zynq_scu_base);
  84. for (i = 0; i < ncores && i < CONFIG_NR_CPUS; i++)
  85. set_cpu_possible(i, true);
  86. }
  87. static void __init zynq_smp_prepare_cpus(unsigned int max_cpus)
  88. {
  89. scu_enable(zynq_scu_base);
  90. }
  91. /**
  92. * zynq_secondary_init - Initialize secondary CPU cores
  93. * @cpu: CPU that is initialized
  94. *
  95. * This function is in the hotplug path. Don't move it into the
  96. * init section!!
  97. */
  98. static void zynq_secondary_init(unsigned int cpu)
  99. {
  100. zynq_core_pm_init();
  101. }
  102. #ifdef CONFIG_HOTPLUG_CPU
  103. static int zynq_cpu_kill(unsigned cpu)
  104. {
  105. unsigned long timeout = jiffies + msecs_to_jiffies(50);
  106. while (zynq_slcr_cpu_state_read(cpu))
  107. if (time_after(jiffies, timeout))
  108. return 0;
  109. zynq_slcr_cpu_stop(cpu);
  110. return 1;
  111. }
  112. /**
  113. * zynq_cpu_die - Let a CPU core die
  114. * @cpu: Dying CPU
  115. *
  116. * Platform-specific code to shutdown a CPU.
  117. * Called with IRQs disabled on the dying CPU.
  118. */
  119. static void zynq_cpu_die(unsigned int cpu)
  120. {
  121. zynq_slcr_cpu_state_write(cpu, true);
  122. /*
  123. * there is no power-control hardware on this platform, so all
  124. * we can do is put the core into WFI; this is safe as the calling
  125. * code will have already disabled interrupts
  126. */
  127. for (;;)
  128. cpu_do_idle();
  129. }
  130. #endif
  131. const struct smp_operations zynq_smp_ops __initconst = {
  132. .smp_init_cpus = zynq_smp_init_cpus,
  133. .smp_prepare_cpus = zynq_smp_prepare_cpus,
  134. .smp_boot_secondary = zynq_boot_secondary,
  135. .smp_secondary_init = zynq_secondary_init,
  136. #ifdef CONFIG_HOTPLUG_CPU
  137. .cpu_die = zynq_cpu_die,
  138. .cpu_kill = zynq_cpu_kill,
  139. #endif
  140. };