platsmp.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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/irqchip/arm-gic.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 <mach/hardware.h>
  28. #include <mach/regs-clock.h>
  29. #include <mach/regs-pmu.h>
  30. #include <plat/cpu.h>
  31. #include "common.h"
  32. extern void exynos4_secondary_startup(void);
  33. static inline void __iomem *cpu_boot_reg_base(void)
  34. {
  35. if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1)
  36. return S5P_INFORM5;
  37. return S5P_VA_SYSRAM;
  38. }
  39. static inline void __iomem *cpu_boot_reg(int cpu)
  40. {
  41. void __iomem *boot_reg;
  42. boot_reg = cpu_boot_reg_base();
  43. if (soc_is_exynos4412())
  44. boot_reg += 4*cpu;
  45. return boot_reg;
  46. }
  47. /*
  48. * Write pen_release in a way that is guaranteed to be visible to all
  49. * observers, irrespective of whether they're taking part in coherency
  50. * or not. This is necessary for the hotplug code to work reliably.
  51. */
  52. static void write_pen_release(int val)
  53. {
  54. pen_release = val;
  55. smp_wmb();
  56. __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
  57. outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
  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 __cpuinit exynos_secondary_init(unsigned int cpu)
  65. {
  66. /*
  67. * if any interrupts are already enabled for the primary
  68. * core (e.g. timer irq), then they will not have been enabled
  69. * for us: do so
  70. */
  71. gic_secondary_init(0);
  72. /*
  73. * let the primary processor know we're out of the
  74. * pen, then head off into the C entry point
  75. */
  76. write_pen_release(-1);
  77. /*
  78. * Synchronise with the boot thread.
  79. */
  80. spin_lock(&boot_lock);
  81. spin_unlock(&boot_lock);
  82. }
  83. static int __cpuinit exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
  84. {
  85. unsigned long timeout;
  86. unsigned long phys_cpu = cpu_logical_map(cpu);
  87. /*
  88. * Set synchronisation state between this boot processor
  89. * and the secondary one
  90. */
  91. spin_lock(&boot_lock);
  92. /*
  93. * The secondary processor is waiting to be released from
  94. * the holding pen - release it, then wait for it to flag
  95. * that it has been released by resetting pen_release.
  96. *
  97. * Note that "pen_release" is the hardware CPU ID, whereas
  98. * "cpu" is Linux's internal ID.
  99. */
  100. write_pen_release(phys_cpu);
  101. if (!(__raw_readl(S5P_ARM_CORE1_STATUS) & S5P_CORE_LOCAL_PWR_EN)) {
  102. __raw_writel(S5P_CORE_LOCAL_PWR_EN,
  103. S5P_ARM_CORE1_CONFIGURATION);
  104. timeout = 10;
  105. /* wait max 10 ms until cpu1 is on */
  106. while ((__raw_readl(S5P_ARM_CORE1_STATUS)
  107. & S5P_CORE_LOCAL_PWR_EN) != S5P_CORE_LOCAL_PWR_EN) {
  108. if (timeout-- == 0)
  109. break;
  110. mdelay(1);
  111. }
  112. if (timeout == 0) {
  113. printk(KERN_ERR "cpu1 power enable failed");
  114. spin_unlock(&boot_lock);
  115. return -ETIMEDOUT;
  116. }
  117. }
  118. /*
  119. * Send the secondary CPU a soft interrupt, thereby causing
  120. * the boot monitor to read the system wide flags register,
  121. * and branch to the address found there.
  122. */
  123. timeout = jiffies + (1 * HZ);
  124. while (time_before(jiffies, timeout)) {
  125. unsigned long boot_addr;
  126. smp_rmb();
  127. boot_addr = virt_to_phys(exynos4_secondary_startup);
  128. /*
  129. * Try to set boot address using firmware first
  130. * and fall back to boot register if it fails.
  131. */
  132. if (call_firmware_op(set_cpu_boot_addr, phys_cpu, boot_addr))
  133. __raw_writel(boot_addr, cpu_boot_reg(phys_cpu));
  134. call_firmware_op(cpu_boot, phys_cpu);
  135. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  136. if (pen_release == -1)
  137. break;
  138. udelay(10);
  139. }
  140. /*
  141. * now the secondary core is starting up let it run its
  142. * calibrations, then wait for it to finish
  143. */
  144. spin_unlock(&boot_lock);
  145. return pen_release != -1 ? -ENOSYS : 0;
  146. }
  147. /*
  148. * Initialise the CPU possible map early - this describes the CPUs
  149. * which may be present or become present in the system.
  150. */
  151. static void __init exynos_smp_init_cpus(void)
  152. {
  153. void __iomem *scu_base = scu_base_addr();
  154. unsigned int i, ncores;
  155. if (soc_is_exynos5250())
  156. ncores = 2;
  157. else
  158. ncores = scu_base ? scu_get_core_count(scu_base) : 1;
  159. /* sanity check */
  160. if (ncores > nr_cpu_ids) {
  161. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  162. ncores, nr_cpu_ids);
  163. ncores = nr_cpu_ids;
  164. }
  165. for (i = 0; i < ncores; i++)
  166. set_cpu_possible(i, true);
  167. }
  168. static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
  169. {
  170. int i;
  171. if (!(soc_is_exynos5250() || soc_is_exynos5440()))
  172. scu_enable(scu_base_addr());
  173. /*
  174. * Write the address of secondary startup into the
  175. * system-wide flags register. The boot monitor waits
  176. * until it receives a soft interrupt, and then the
  177. * secondary CPU branches to this address.
  178. *
  179. * Try using firmware operation first and fall back to
  180. * boot register if it fails.
  181. */
  182. for (i = 1; i < max_cpus; ++i) {
  183. unsigned long phys_cpu;
  184. unsigned long boot_addr;
  185. phys_cpu = cpu_logical_map(i);
  186. boot_addr = virt_to_phys(exynos4_secondary_startup);
  187. if (call_firmware_op(set_cpu_boot_addr, phys_cpu, boot_addr))
  188. __raw_writel(boot_addr, cpu_boot_reg(phys_cpu));
  189. }
  190. }
  191. struct smp_operations exynos_smp_ops __initdata = {
  192. .smp_init_cpus = exynos_smp_init_cpus,
  193. .smp_prepare_cpus = exynos_smp_prepare_cpus,
  194. .smp_secondary_init = exynos_secondary_init,
  195. .smp_boot_secondary = exynos_boot_secondary,
  196. #ifdef CONFIG_HOTPLUG_CPU
  197. .cpu_die = exynos_cpu_die,
  198. #endif
  199. };