platsmp.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/mach-axxia/platsmp.c
  4. *
  5. * Copyright (C) 2012 LSI Corporation
  6. */
  7. #include <linux/init.h>
  8. #include <linux/io.h>
  9. #include <linux/smp.h>
  10. #include <linux/of.h>
  11. #include <linux/of_address.h>
  12. #include <asm/cacheflush.h>
  13. /* Syscon register offsets for releasing cores from reset */
  14. #define SC_CRIT_WRITE_KEY 0x1000
  15. #define SC_RST_CPU_HOLD 0x1010
  16. /*
  17. * Write the kernel entry point for secondary CPUs to the specified address
  18. */
  19. static void write_release_addr(u32 release_phys)
  20. {
  21. u32 *virt = (u32 *) phys_to_virt(release_phys);
  22. writel_relaxed(__pa_symbol(secondary_startup), virt);
  23. /* Make sure this store is visible to other CPUs */
  24. smp_wmb();
  25. __cpuc_flush_dcache_area(virt, sizeof(u32));
  26. }
  27. static int axxia_boot_secondary(unsigned int cpu, struct task_struct *idle)
  28. {
  29. struct device_node *syscon_np;
  30. void __iomem *syscon;
  31. u32 tmp;
  32. syscon_np = of_find_compatible_node(NULL, NULL, "lsi,axxia-syscon");
  33. if (!syscon_np)
  34. return -ENOENT;
  35. syscon = of_iomap(syscon_np, 0);
  36. of_node_put(syscon_np);
  37. if (!syscon)
  38. return -ENOMEM;
  39. tmp = readl(syscon + SC_RST_CPU_HOLD);
  40. writel(0xab, syscon + SC_CRIT_WRITE_KEY);
  41. tmp &= ~(1 << cpu);
  42. writel(tmp, syscon + SC_RST_CPU_HOLD);
  43. return 0;
  44. }
  45. static void __init axxia_smp_prepare_cpus(unsigned int max_cpus)
  46. {
  47. int cpu_count = 0;
  48. int cpu;
  49. /*
  50. * Initialise the present map, which describes the set of CPUs actually
  51. * populated at the present time.
  52. */
  53. for_each_possible_cpu(cpu) {
  54. struct device_node *np;
  55. u32 release_phys;
  56. np = of_get_cpu_node(cpu, NULL);
  57. if (!np)
  58. continue;
  59. if (of_property_read_u32(np, "cpu-release-addr", &release_phys))
  60. continue;
  61. if (cpu_count < max_cpus) {
  62. set_cpu_present(cpu, true);
  63. cpu_count++;
  64. }
  65. if (release_phys != 0)
  66. write_release_addr(release_phys);
  67. }
  68. }
  69. static const struct smp_operations axxia_smp_ops __initconst = {
  70. .smp_prepare_cpus = axxia_smp_prepare_cpus,
  71. .smp_boot_secondary = axxia_boot_secondary,
  72. };
  73. CPU_METHOD_OF_DECLARE(axxia_smp, "lsi,syscon-release", &axxia_smp_ops);