platsmp.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright 2011 Freescale Semiconductor, Inc.
  4. * Copyright 2011 Linaro Ltd.
  5. */
  6. #include <linux/init.h>
  7. #include <linux/of_address.h>
  8. #include <linux/of.h>
  9. #include <linux/smp.h>
  10. #include <asm/cacheflush.h>
  11. #include <asm/page.h>
  12. #include <asm/smp_scu.h>
  13. #include <asm/mach/map.h>
  14. #include "common.h"
  15. #include "hardware.h"
  16. u32 g_diag_reg;
  17. static void __iomem *scu_base;
  18. static struct map_desc scu_io_desc __initdata = {
  19. /* .virtual and .pfn are run-time assigned */
  20. .length = SZ_4K,
  21. .type = MT_DEVICE,
  22. };
  23. void __init imx_scu_map_io(void)
  24. {
  25. unsigned long base;
  26. /* Get SCU base */
  27. asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base));
  28. scu_io_desc.virtual = IMX_IO_P2V(base);
  29. scu_io_desc.pfn = __phys_to_pfn(base);
  30. iotable_init(&scu_io_desc, 1);
  31. scu_base = IMX_IO_ADDRESS(base);
  32. }
  33. static int imx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  34. {
  35. imx_set_cpu_jump(cpu, v7_secondary_startup);
  36. imx_enable_cpu(cpu, true);
  37. return 0;
  38. }
  39. /*
  40. * Initialise the CPU possible map early - this describes the CPUs
  41. * which may be present or become present in the system.
  42. */
  43. static void __init imx_smp_init_cpus(void)
  44. {
  45. int i, ncores;
  46. ncores = scu_get_core_count(scu_base);
  47. for (i = ncores; i < NR_CPUS; i++)
  48. set_cpu_possible(i, false);
  49. }
  50. void imx_smp_prepare(void)
  51. {
  52. scu_enable(scu_base);
  53. }
  54. static void __init imx_smp_prepare_cpus(unsigned int max_cpus)
  55. {
  56. imx_smp_prepare();
  57. /*
  58. * The diagnostic register holds the errata bits. Mostly bootloader
  59. * does not bring up secondary cores, so that when errata bits are set
  60. * in bootloader, they are set only for boot cpu. But on a SMP
  61. * configuration, it should be equally done on every single core.
  62. * Read the register from boot cpu here, and will replicate it into
  63. * secondary cores when booting them.
  64. */
  65. asm("mrc p15, 0, %0, c15, c0, 1" : "=r" (g_diag_reg) : : "cc");
  66. sync_cache_w(&g_diag_reg);
  67. }
  68. const struct smp_operations imx_smp_ops __initconst = {
  69. .smp_init_cpus = imx_smp_init_cpus,
  70. .smp_prepare_cpus = imx_smp_prepare_cpus,
  71. .smp_boot_secondary = imx_boot_secondary,
  72. #ifdef CONFIG_HOTPLUG_CPU
  73. .cpu_die = imx_cpu_die,
  74. .cpu_kill = imx_cpu_kill,
  75. #endif
  76. };
  77. /*
  78. * Initialise the CPU possible map early - this describes the CPUs
  79. * which may be present or become present in the system.
  80. */
  81. static void __init imx7_smp_init_cpus(void)
  82. {
  83. struct device_node *np;
  84. int i, ncores = 0;
  85. /* The iMX7D SCU does not report core count, get it from DT */
  86. for_each_of_cpu_node(np)
  87. ncores++;
  88. for (i = ncores; i < NR_CPUS; i++)
  89. set_cpu_possible(i, false);
  90. }
  91. const struct smp_operations imx7_smp_ops __initconst = {
  92. .smp_init_cpus = imx7_smp_init_cpus,
  93. .smp_boot_secondary = imx_boot_secondary,
  94. #ifdef CONFIG_HOTPLUG_CPU
  95. .cpu_die = imx_cpu_die,
  96. .cpu_kill = imx_cpu_kill,
  97. #endif
  98. };
  99. #define DCFG_CCSR_SCRATCHRW1 0x200
  100. static int ls1021a_boot_secondary(unsigned int cpu, struct task_struct *idle)
  101. {
  102. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  103. return 0;
  104. }
  105. static void __init ls1021a_smp_prepare_cpus(unsigned int max_cpus)
  106. {
  107. struct device_node *np;
  108. void __iomem *dcfg_base;
  109. unsigned long paddr;
  110. np = of_find_compatible_node(NULL, NULL, "fsl,ls1021a-dcfg");
  111. dcfg_base = of_iomap(np, 0);
  112. of_node_put(np);
  113. BUG_ON(!dcfg_base);
  114. paddr = __pa_symbol(secondary_startup);
  115. writel_relaxed(cpu_to_be32(paddr), dcfg_base + DCFG_CCSR_SCRATCHRW1);
  116. iounmap(dcfg_base);
  117. }
  118. const struct smp_operations ls1021a_smp_ops __initconst = {
  119. .smp_prepare_cpus = ls1021a_smp_prepare_cpus,
  120. .smp_boot_secondary = ls1021a_boot_secondary,
  121. };