platsmp.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (c) 2013 MundoReader S.L.
  3. * Author: Heiko Stuebner <heiko@sntech.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/delay.h>
  16. #include <linux/init.h>
  17. #include <linux/smp.h>
  18. #include <linux/io.h>
  19. #include <linux/of.h>
  20. #include <linux/of_address.h>
  21. #include <asm/cacheflush.h>
  22. #include <asm/cp15.h>
  23. #include <asm/smp_scu.h>
  24. #include <asm/smp_plat.h>
  25. #include <asm/mach/map.h>
  26. #include "core.h"
  27. static void __iomem *scu_base_addr;
  28. static void __iomem *sram_base_addr;
  29. static int ncores;
  30. #define PMU_PWRDN_CON 0x08
  31. #define PMU_PWRDN_ST 0x0c
  32. #define PMU_PWRDN_SCU 4
  33. static void __iomem *pmu_base_addr;
  34. static inline bool pmu_power_domain_is_on(int pd)
  35. {
  36. return !(readl_relaxed(pmu_base_addr + PMU_PWRDN_ST) & BIT(pd));
  37. }
  38. static void pmu_set_power_domain(int pd, bool on)
  39. {
  40. u32 val = readl_relaxed(pmu_base_addr + PMU_PWRDN_CON);
  41. if (on)
  42. val &= ~BIT(pd);
  43. else
  44. val |= BIT(pd);
  45. writel(val, pmu_base_addr + PMU_PWRDN_CON);
  46. while (pmu_power_domain_is_on(pd) != on) { }
  47. }
  48. /*
  49. * Handling of CPU cores
  50. */
  51. static int __cpuinit rockchip_boot_secondary(unsigned int cpu,
  52. struct task_struct *idle)
  53. {
  54. if (!sram_base_addr || !pmu_base_addr) {
  55. pr_err("%s: sram or pmu missing for cpu boot\n", __func__);
  56. return -ENXIO;
  57. }
  58. if (cpu >= ncores) {
  59. pr_err("%s: cpu %d outside maximum number of cpus %d\n",
  60. __func__, cpu, ncores);
  61. return -ENXIO;
  62. }
  63. /* start the core */
  64. pmu_set_power_domain(0 + cpu, true);
  65. return 0;
  66. }
  67. /**
  68. * rockchip_smp_prepare_sram - populate necessary sram block
  69. * Starting cores execute the code residing at the start of the on-chip sram
  70. * after power-on. Therefore make sure, this sram region is reserved and
  71. * big enough. After this check, copy the trampoline code that directs the
  72. * core to the real startup code in ram into the sram-region.
  73. * @node: mmio-sram device node
  74. */
  75. static int __init rockchip_smp_prepare_sram(struct device_node *node)
  76. {
  77. unsigned int trampoline_sz = &rockchip_secondary_trampoline_end -
  78. &rockchip_secondary_trampoline;
  79. struct resource res;
  80. unsigned int rsize;
  81. int ret;
  82. ret = of_address_to_resource(node, 0, &res);
  83. if (ret < 0) {
  84. pr_err("%s: could not get address for node %s\n",
  85. __func__, node->full_name);
  86. return ret;
  87. }
  88. rsize = resource_size(&res);
  89. if (rsize < trampoline_sz) {
  90. pr_err("%s: reserved block with size 0x%x is to small for trampoline size 0x%x\n",
  91. __func__, rsize, trampoline_sz);
  92. return -EINVAL;
  93. }
  94. sram_base_addr = of_iomap(node, 0);
  95. /* set the boot function for the sram code */
  96. rockchip_boot_fn = virt_to_phys(rockchip_secondary_startup);
  97. /* copy the trampoline to sram, that runs during startup of the core */
  98. memcpy(sram_base_addr, &rockchip_secondary_trampoline, trampoline_sz);
  99. flush_cache_all();
  100. outer_clean_range(0, trampoline_sz);
  101. dsb_sev();
  102. return 0;
  103. }
  104. static void __init rockchip_smp_prepare_cpus(unsigned int max_cpus)
  105. {
  106. struct device_node *node;
  107. unsigned int i;
  108. node = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
  109. if (!node) {
  110. pr_err("%s: missing scu\n", __func__);
  111. return;
  112. }
  113. scu_base_addr = of_iomap(node, 0);
  114. if (!scu_base_addr) {
  115. pr_err("%s: could not map scu registers\n", __func__);
  116. return;
  117. }
  118. node = of_find_compatible_node(NULL, NULL, "rockchip,rk3066-smp-sram");
  119. if (!node) {
  120. pr_err("%s: could not find sram dt node\n", __func__);
  121. return;
  122. }
  123. if (rockchip_smp_prepare_sram(node))
  124. return;
  125. node = of_find_compatible_node(NULL, NULL, "rockchip,rk3066-pmu");
  126. if (!node) {
  127. pr_err("%s: could not find pmu dt node\n", __func__);
  128. return;
  129. }
  130. pmu_base_addr = of_iomap(node, 0);
  131. if (!pmu_base_addr) {
  132. pr_err("%s: could not map pmu registers\n", __func__);
  133. return;
  134. }
  135. /* enable the SCU power domain */
  136. pmu_set_power_domain(PMU_PWRDN_SCU, true);
  137. /*
  138. * While the number of cpus is gathered from dt, also get the number
  139. * of cores from the scu to verify this value when booting the cores.
  140. */
  141. ncores = scu_get_core_count(scu_base_addr);
  142. scu_enable(scu_base_addr);
  143. /* Make sure that all cores except the first are really off */
  144. for (i = 1; i < ncores; i++)
  145. pmu_set_power_domain(0 + i, false);
  146. }
  147. #ifdef CONFIG_HOTPLUG_CPU
  148. static int rockchip_cpu_kill(unsigned int cpu)
  149. {
  150. pmu_set_power_domain(0 + cpu, false);
  151. return 1;
  152. }
  153. static void rockchip_cpu_die(unsigned int cpu)
  154. {
  155. v7_exit_coherency_flush(louis);
  156. while(1)
  157. cpu_do_idle();
  158. }
  159. #endif
  160. static struct smp_operations rockchip_smp_ops __initdata = {
  161. .smp_prepare_cpus = rockchip_smp_prepare_cpus,
  162. .smp_boot_secondary = rockchip_boot_secondary,
  163. #ifdef CONFIG_HOTPLUG_CPU
  164. .cpu_kill = rockchip_cpu_kill,
  165. .cpu_die = rockchip_cpu_die,
  166. #endif
  167. };
  168. CPU_METHOD_OF_DECLARE(rk3066_smp, "rockchip,rk3066-smp", &rockchip_smp_ops);