platsmp.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2010-2011 Calxeda, Inc.
  3. * Copyright 2012 Pavel Machek <pavel@denx.de>
  4. * Based on platsmp.c, Copyright (C) 2002 ARM Ltd.
  5. * Copyright (C) 2012 Altera Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/init.h>
  21. #include <linux/smp.h>
  22. #include <linux/io.h>
  23. #include <linux/of.h>
  24. #include <linux/of_address.h>
  25. #include <linux/irqchip/arm-gic.h>
  26. #include <asm/cacheflush.h>
  27. #include <asm/smp_scu.h>
  28. #include <asm/smp_plat.h>
  29. #include "core.h"
  30. extern void __iomem *sys_manager_base_addr;
  31. extern void __iomem *rst_manager_base_addr;
  32. static void __cpuinit socfpga_secondary_init(unsigned int cpu)
  33. {
  34. /*
  35. * if any interrupts are already enabled for the primary
  36. * core (e.g. timer irq), then they will not have been enabled
  37. * for us: do so
  38. */
  39. gic_secondary_init(0);
  40. }
  41. static int __cpuinit socfpga_boot_secondary(unsigned int cpu, struct task_struct *idle)
  42. {
  43. int trampoline_size = &secondary_trampoline_end - &secondary_trampoline;
  44. if (cpu1start_addr) {
  45. memcpy(phys_to_virt(0), &secondary_trampoline, trampoline_size);
  46. __raw_writel(virt_to_phys(socfpga_secondary_startup),
  47. (sys_manager_base_addr + (cpu1start_addr & 0x000000ff)));
  48. flush_cache_all();
  49. smp_wmb();
  50. outer_clean_range(0, trampoline_size);
  51. /* This will release CPU #1 out of reset.*/
  52. __raw_writel(0, rst_manager_base_addr + 0x10);
  53. }
  54. return 0;
  55. }
  56. /*
  57. * Initialise the CPU possible map early - this describes the CPUs
  58. * which may be present or become present in the system.
  59. */
  60. static void __init socfpga_smp_init_cpus(void)
  61. {
  62. unsigned int i, ncores;
  63. ncores = scu_get_core_count(socfpga_scu_base_addr);
  64. for (i = 0; i < ncores; i++)
  65. set_cpu_possible(i, true);
  66. /* sanity check */
  67. if (ncores > num_possible_cpus()) {
  68. pr_warn("socfpga: no. of cores (%d) greater than configured"
  69. "maximum of %d - clipping\n", ncores, num_possible_cpus());
  70. ncores = num_possible_cpus();
  71. }
  72. for (i = 0; i < ncores; i++)
  73. set_cpu_possible(i, true);
  74. }
  75. static void __init socfpga_smp_prepare_cpus(unsigned int max_cpus)
  76. {
  77. scu_enable(socfpga_scu_base_addr);
  78. }
  79. /*
  80. * platform-specific code to shutdown a CPU
  81. *
  82. * Called with IRQs disabled
  83. */
  84. static void socfpga_cpu_die(unsigned int cpu)
  85. {
  86. cpu_do_idle();
  87. /* We should have never returned from idle */
  88. panic("cpu %d unexpectedly exit from shutdown\n", cpu);
  89. }
  90. struct smp_operations socfpga_smp_ops __initdata = {
  91. .smp_init_cpus = socfpga_smp_init_cpus,
  92. .smp_prepare_cpus = socfpga_smp_prepare_cpus,
  93. .smp_secondary_init = socfpga_secondary_init,
  94. .smp_boot_secondary = socfpga_boot_secondary,
  95. #ifdef CONFIG_HOTPLUG_CPU
  96. .cpu_die = socfpga_cpu_die,
  97. #endif
  98. };