platsmp.c 3.8 KB

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