platsmp.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Actions Semi Leopard
  4. *
  5. * This file is based on arm realview smp platform.
  6. *
  7. * Copyright 2012 Actions Semi Inc.
  8. * Author: Actions Semi, Inc.
  9. *
  10. * Copyright (c) 2017 Andreas Färber
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/io.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/smp.h>
  17. #include <linux/soc/actions/owl-sps.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/smp_plat.h>
  20. #include <asm/smp_scu.h>
  21. #define OWL_CPU1_ADDR 0x50
  22. #define OWL_CPU1_FLAG 0x5c
  23. #define OWL_CPUx_FLAG_BOOT 0x55aa
  24. #define OWL_SPS_PG_CTL_PWR_CPU2 BIT(5)
  25. #define OWL_SPS_PG_CTL_PWR_CPU3 BIT(6)
  26. #define OWL_SPS_PG_CTL_ACK_CPU2 BIT(21)
  27. #define OWL_SPS_PG_CTL_ACK_CPU3 BIT(22)
  28. static void __iomem *scu_base_addr;
  29. static void __iomem *sps_base_addr;
  30. static void __iomem *timer_base_addr;
  31. static int ncores;
  32. static int s500_wakeup_secondary(unsigned int cpu)
  33. {
  34. int ret;
  35. if (cpu > 3)
  36. return -EINVAL;
  37. /* The generic PM domain driver is not available this early. */
  38. switch (cpu) {
  39. case 2:
  40. ret = owl_sps_set_pg(sps_base_addr,
  41. OWL_SPS_PG_CTL_PWR_CPU2,
  42. OWL_SPS_PG_CTL_ACK_CPU2, true);
  43. if (ret)
  44. return ret;
  45. break;
  46. case 3:
  47. ret = owl_sps_set_pg(sps_base_addr,
  48. OWL_SPS_PG_CTL_PWR_CPU3,
  49. OWL_SPS_PG_CTL_ACK_CPU3, true);
  50. if (ret)
  51. return ret;
  52. break;
  53. }
  54. /* wait for CPUx to run to WFE instruction */
  55. udelay(200);
  56. writel(__pa_symbol(secondary_startup),
  57. timer_base_addr + OWL_CPU1_ADDR + (cpu - 1) * 4);
  58. writel(OWL_CPUx_FLAG_BOOT,
  59. timer_base_addr + OWL_CPU1_FLAG + (cpu - 1) * 4);
  60. dsb_sev();
  61. mb();
  62. return 0;
  63. }
  64. static int s500_smp_boot_secondary(unsigned int cpu, struct task_struct *idle)
  65. {
  66. int ret;
  67. ret = s500_wakeup_secondary(cpu);
  68. if (ret)
  69. return ret;
  70. udelay(10);
  71. smp_send_reschedule(cpu);
  72. writel(0, timer_base_addr + OWL_CPU1_ADDR + (cpu - 1) * 4);
  73. writel(0, timer_base_addr + OWL_CPU1_FLAG + (cpu - 1) * 4);
  74. return 0;
  75. }
  76. static void __init s500_smp_prepare_cpus(unsigned int max_cpus)
  77. {
  78. struct device_node *node;
  79. node = of_find_compatible_node(NULL, NULL, "actions,s500-timer");
  80. if (!node) {
  81. pr_err("%s: missing timer\n", __func__);
  82. return;
  83. }
  84. timer_base_addr = of_iomap(node, 0);
  85. if (!timer_base_addr) {
  86. pr_err("%s: could not map timer registers\n", __func__);
  87. return;
  88. }
  89. node = of_find_compatible_node(NULL, NULL, "actions,s500-sps");
  90. if (!node) {
  91. pr_err("%s: missing sps\n", __func__);
  92. return;
  93. }
  94. sps_base_addr = of_iomap(node, 0);
  95. if (!sps_base_addr) {
  96. pr_err("%s: could not map sps registers\n", __func__);
  97. return;
  98. }
  99. if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9) {
  100. node = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
  101. if (!node) {
  102. pr_err("%s: missing scu\n", __func__);
  103. return;
  104. }
  105. scu_base_addr = of_iomap(node, 0);
  106. if (!scu_base_addr) {
  107. pr_err("%s: could not map scu registers\n", __func__);
  108. return;
  109. }
  110. /*
  111. * While the number of cpus is gathered from dt, also get the
  112. * number of cores from the scu to verify this value when
  113. * booting the cores.
  114. */
  115. ncores = scu_get_core_count(scu_base_addr);
  116. pr_debug("%s: ncores %d\n", __func__, ncores);
  117. scu_enable(scu_base_addr);
  118. }
  119. }
  120. static const struct smp_operations s500_smp_ops __initconst = {
  121. .smp_prepare_cpus = s500_smp_prepare_cpus,
  122. .smp_boot_secondary = s500_smp_boot_secondary,
  123. };
  124. CPU_METHOD_OF_DECLARE(s500_smp, "actions,s500-smp", &s500_smp_ops);