platsmp.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2010-2011 Calxeda, Inc.
  4. * Copyright 2012 Pavel Machek <[email protected]>
  5. * Based on platsmp.c, Copyright (C) 2002 ARM Ltd.
  6. * Copyright (C) 2012 Altera Corporation
  7. */
  8. #include <linux/delay.h>
  9. #include <linux/init.h>
  10. #include <linux/smp.h>
  11. #include <linux/io.h>
  12. #include <linux/of.h>
  13. #include <linux/of_address.h>
  14. #include <asm/cacheflush.h>
  15. #include <asm/smp_scu.h>
  16. #include <asm/smp_plat.h>
  17. #include "core.h"
  18. static int socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
  19. {
  20. int trampoline_size = secondary_trampoline_end - secondary_trampoline;
  21. if (socfpga_cpu1start_addr) {
  22. /* This will put CPU #1 into reset. */
  23. writel(RSTMGR_MPUMODRST_CPU1,
  24. rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST);
  25. memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
  26. writel(__pa_symbol(secondary_startup),
  27. sys_manager_base_addr + (socfpga_cpu1start_addr & 0x000000ff));
  28. flush_cache_all();
  29. smp_wmb();
  30. outer_clean_range(0, trampoline_size);
  31. /* This will release CPU #1 out of reset. */
  32. writel(0, rst_manager_base_addr + SOCFPGA_RSTMGR_MODMPURST);
  33. }
  34. return 0;
  35. }
  36. static int socfpga_a10_boot_secondary(unsigned int cpu, struct task_struct *idle)
  37. {
  38. int trampoline_size = secondary_trampoline_end - secondary_trampoline;
  39. if (socfpga_cpu1start_addr) {
  40. writel(RSTMGR_MPUMODRST_CPU1, rst_manager_base_addr +
  41. SOCFPGA_A10_RSTMGR_MODMPURST);
  42. memcpy(phys_to_virt(0), secondary_trampoline, trampoline_size);
  43. writel(__pa_symbol(secondary_startup),
  44. sys_manager_base_addr + (socfpga_cpu1start_addr & 0x00000fff));
  45. flush_cache_all();
  46. smp_wmb();
  47. outer_clean_range(0, trampoline_size);
  48. /* This will release CPU #1 out of reset. */
  49. writel(0, rst_manager_base_addr + SOCFPGA_A10_RSTMGR_MODMPURST);
  50. }
  51. return 0;
  52. }
  53. static void __init socfpga_smp_prepare_cpus(unsigned int max_cpus)
  54. {
  55. struct device_node *np;
  56. void __iomem *socfpga_scu_base_addr;
  57. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
  58. if (!np) {
  59. pr_err("%s: missing scu\n", __func__);
  60. return;
  61. }
  62. socfpga_scu_base_addr = of_iomap(np, 0);
  63. if (!socfpga_scu_base_addr)
  64. return;
  65. scu_enable(socfpga_scu_base_addr);
  66. }
  67. #ifdef CONFIG_HOTPLUG_CPU
  68. /*
  69. * platform-specific code to shutdown a CPU
  70. *
  71. * Called with IRQs disabled
  72. */
  73. static void socfpga_cpu_die(unsigned int cpu)
  74. {
  75. /* Do WFI. If we wake up early, go back into WFI */
  76. while (1)
  77. cpu_do_idle();
  78. }
  79. /*
  80. * We need a dummy function so that platform_can_cpu_hotplug() knows
  81. * we support CPU hotplug. However, the function does not need to do
  82. * anything, because CPUs going offline just do WFI. We could reset
  83. * the CPUs but it would increase power consumption.
  84. */
  85. static int socfpga_cpu_kill(unsigned int cpu)
  86. {
  87. return 1;
  88. }
  89. #endif
  90. static const struct smp_operations socfpga_smp_ops __initconst = {
  91. .smp_prepare_cpus = socfpga_smp_prepare_cpus,
  92. .smp_boot_secondary = socfpga_boot_secondary,
  93. #ifdef CONFIG_HOTPLUG_CPU
  94. .cpu_die = socfpga_cpu_die,
  95. .cpu_kill = socfpga_cpu_kill,
  96. #endif
  97. };
  98. static const struct smp_operations socfpga_a10_smp_ops __initconst = {
  99. .smp_prepare_cpus = socfpga_smp_prepare_cpus,
  100. .smp_boot_secondary = socfpga_a10_boot_secondary,
  101. #ifdef CONFIG_HOTPLUG_CPU
  102. .cpu_die = socfpga_cpu_die,
  103. .cpu_kill = socfpga_cpu_kill,
  104. #endif
  105. };
  106. CPU_METHOD_OF_DECLARE(socfpga_smp, "altr,socfpga-smp", &socfpga_smp_ops);
  107. CPU_METHOD_OF_DECLARE(socfpga_a10_smp, "altr,socfpga-a10-smp", &socfpga_a10_smp_ops);