platsmp.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* linux/arch/arm/mach-exynos4/platsmp.c
  2. *
  3. * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * Cloned from linux/arch/arm/mach-vexpress/platsmp.c
  7. *
  8. * Copyright (C) 2002 ARM Ltd.
  9. * All Rights Reserved
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/delay.h>
  18. #include <linux/device.h>
  19. #include <linux/jiffies.h>
  20. #include <linux/smp.h>
  21. #include <linux/io.h>
  22. #include <linux/of_address.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/smp_plat.h>
  25. #include <asm/smp_scu.h>
  26. #include <asm/firmware.h>
  27. #include "common.h"
  28. #include "regs-pmu.h"
  29. extern void exynos4_secondary_startup(void);
  30. static inline void __iomem *cpu_boot_reg_base(void)
  31. {
  32. if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1)
  33. return S5P_INFORM5;
  34. return sysram_base_addr;
  35. }
  36. static inline void __iomem *cpu_boot_reg(int cpu)
  37. {
  38. void __iomem *boot_reg;
  39. boot_reg = cpu_boot_reg_base();
  40. if (!boot_reg)
  41. return ERR_PTR(-ENODEV);
  42. if (soc_is_exynos4412())
  43. boot_reg += 4*cpu;
  44. else if (soc_is_exynos5420() || soc_is_exynos5800())
  45. boot_reg += 4;
  46. return boot_reg;
  47. }
  48. /*
  49. * Write pen_release in a way that is guaranteed to be visible to all
  50. * observers, irrespective of whether they're taking part in coherency
  51. * or not. This is necessary for the hotplug code to work reliably.
  52. */
  53. static void write_pen_release(int val)
  54. {
  55. pen_release = val;
  56. smp_wmb();
  57. sync_cache_w(&pen_release);
  58. }
  59. static void __iomem *scu_base_addr(void)
  60. {
  61. return (void __iomem *)(S5P_VA_SCU);
  62. }
  63. static DEFINE_SPINLOCK(boot_lock);
  64. static void exynos_secondary_init(unsigned int cpu)
  65. {
  66. /*
  67. * let the primary processor know we're out of the
  68. * pen, then head off into the C entry point
  69. */
  70. write_pen_release(-1);
  71. /*
  72. * Synchronise with the boot thread.
  73. */
  74. spin_lock(&boot_lock);
  75. spin_unlock(&boot_lock);
  76. }
  77. static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
  78. {
  79. unsigned long timeout;
  80. u32 mpidr = cpu_logical_map(cpu);
  81. u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  82. int ret = -ENOSYS;
  83. /*
  84. * Set synchronisation state between this boot processor
  85. * and the secondary one
  86. */
  87. spin_lock(&boot_lock);
  88. /*
  89. * The secondary processor is waiting to be released from
  90. * the holding pen - release it, then wait for it to flag
  91. * that it has been released by resetting pen_release.
  92. *
  93. * Note that "pen_release" is the hardware CPU core ID, whereas
  94. * "cpu" is Linux's internal ID.
  95. */
  96. write_pen_release(core_id);
  97. if (!exynos_cpu_power_state(core_id)) {
  98. exynos_cpu_power_up(core_id);
  99. timeout = 10;
  100. /* wait max 10 ms until cpu1 is on */
  101. while (exynos_cpu_power_state(core_id)
  102. != S5P_CORE_LOCAL_PWR_EN) {
  103. if (timeout-- == 0)
  104. break;
  105. mdelay(1);
  106. }
  107. if (timeout == 0) {
  108. printk(KERN_ERR "cpu1 power enable failed");
  109. spin_unlock(&boot_lock);
  110. return -ETIMEDOUT;
  111. }
  112. }
  113. /*
  114. * Send the secondary CPU a soft interrupt, thereby causing
  115. * the boot monitor to read the system wide flags register,
  116. * and branch to the address found there.
  117. */
  118. timeout = jiffies + (1 * HZ);
  119. while (time_before(jiffies, timeout)) {
  120. unsigned long boot_addr;
  121. smp_rmb();
  122. boot_addr = virt_to_phys(exynos4_secondary_startup);
  123. /*
  124. * Try to set boot address using firmware first
  125. * and fall back to boot register if it fails.
  126. */
  127. ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
  128. if (ret && ret != -ENOSYS)
  129. goto fail;
  130. if (ret == -ENOSYS) {
  131. void __iomem *boot_reg = cpu_boot_reg(core_id);
  132. if (IS_ERR(boot_reg)) {
  133. ret = PTR_ERR(boot_reg);
  134. goto fail;
  135. }
  136. __raw_writel(boot_addr, cpu_boot_reg(core_id));
  137. }
  138. call_firmware_op(cpu_boot, core_id);
  139. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  140. if (pen_release == -1)
  141. break;
  142. udelay(10);
  143. }
  144. /*
  145. * now the secondary core is starting up let it run its
  146. * calibrations, then wait for it to finish
  147. */
  148. fail:
  149. spin_unlock(&boot_lock);
  150. return pen_release != -1 ? ret : 0;
  151. }
  152. /*
  153. * Initialise the CPU possible map early - this describes the CPUs
  154. * which may be present or become present in the system.
  155. */
  156. static void __init exynos_smp_init_cpus(void)
  157. {
  158. void __iomem *scu_base = scu_base_addr();
  159. unsigned int i, ncores;
  160. if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
  161. ncores = scu_base ? scu_get_core_count(scu_base) : 1;
  162. else
  163. /*
  164. * CPU Nodes are passed thru DT and set_cpu_possible
  165. * is set by "arm_dt_init_cpu_maps".
  166. */
  167. return;
  168. /* sanity check */
  169. if (ncores > nr_cpu_ids) {
  170. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  171. ncores, nr_cpu_ids);
  172. ncores = nr_cpu_ids;
  173. }
  174. for (i = 0; i < ncores; i++)
  175. set_cpu_possible(i, true);
  176. }
  177. static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
  178. {
  179. int i;
  180. exynos_sysram_init();
  181. if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
  182. scu_enable(scu_base_addr());
  183. /*
  184. * Write the address of secondary startup into the
  185. * system-wide flags register. The boot monitor waits
  186. * until it receives a soft interrupt, and then the
  187. * secondary CPU branches to this address.
  188. *
  189. * Try using firmware operation first and fall back to
  190. * boot register if it fails.
  191. */
  192. for (i = 1; i < max_cpus; ++i) {
  193. unsigned long boot_addr;
  194. u32 mpidr;
  195. u32 core_id;
  196. int ret;
  197. mpidr = cpu_logical_map(i);
  198. core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  199. boot_addr = virt_to_phys(exynos4_secondary_startup);
  200. ret = call_firmware_op(set_cpu_boot_addr, core_id, boot_addr);
  201. if (ret && ret != -ENOSYS)
  202. break;
  203. if (ret == -ENOSYS) {
  204. void __iomem *boot_reg = cpu_boot_reg(core_id);
  205. if (IS_ERR(boot_reg))
  206. break;
  207. __raw_writel(boot_addr, cpu_boot_reg(core_id));
  208. }
  209. }
  210. }
  211. struct smp_operations exynos_smp_ops __initdata = {
  212. .smp_init_cpus = exynos_smp_init_cpus,
  213. .smp_prepare_cpus = exynos_smp_prepare_cpus,
  214. .smp_secondary_init = exynos_secondary_init,
  215. .smp_boot_secondary = exynos_boot_secondary,
  216. #ifdef CONFIG_HOTPLUG_CPU
  217. .cpu_die = exynos_cpu_die,
  218. #endif
  219. };