platsmp.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 <asm/cacheflush.h>
  23. #include <asm/smp_plat.h>
  24. #include <asm/smp_scu.h>
  25. #include <asm/firmware.h>
  26. #include <mach/hardware.h>
  27. #include <mach/regs-clock.h>
  28. #include <mach/regs-pmu.h>
  29. #include <plat/cpu.h>
  30. #include "common.h"
  31. extern void exynos4_secondary_startup(void);
  32. static inline void __iomem *cpu_boot_reg_base(void)
  33. {
  34. if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1)
  35. return S5P_INFORM5;
  36. return S5P_VA_SYSRAM;
  37. }
  38. static inline void __iomem *cpu_boot_reg(int cpu)
  39. {
  40. void __iomem *boot_reg;
  41. boot_reg = cpu_boot_reg_base();
  42. if (soc_is_exynos4412())
  43. boot_reg += 4*cpu;
  44. else if (soc_is_exynos5420())
  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. __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
  58. outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
  59. }
  60. static void __iomem *scu_base_addr(void)
  61. {
  62. return (void __iomem *)(S5P_VA_SCU);
  63. }
  64. static DEFINE_SPINLOCK(boot_lock);
  65. static void exynos_secondary_init(unsigned int cpu)
  66. {
  67. /*
  68. * let the primary processor know we're out of the
  69. * pen, then head off into the C entry point
  70. */
  71. write_pen_release(-1);
  72. /*
  73. * Synchronise with the boot thread.
  74. */
  75. spin_lock(&boot_lock);
  76. spin_unlock(&boot_lock);
  77. }
  78. static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
  79. {
  80. unsigned long timeout;
  81. unsigned long phys_cpu = cpu_logical_map(cpu);
  82. /*
  83. * Set synchronisation state between this boot processor
  84. * and the secondary one
  85. */
  86. spin_lock(&boot_lock);
  87. /*
  88. * The secondary processor is waiting to be released from
  89. * the holding pen - release it, then wait for it to flag
  90. * that it has been released by resetting pen_release.
  91. *
  92. * Note that "pen_release" is the hardware CPU ID, whereas
  93. * "cpu" is Linux's internal ID.
  94. */
  95. write_pen_release(phys_cpu);
  96. if (!(__raw_readl(S5P_ARM_CORE1_STATUS) & S5P_CORE_LOCAL_PWR_EN)) {
  97. __raw_writel(S5P_CORE_LOCAL_PWR_EN,
  98. S5P_ARM_CORE1_CONFIGURATION);
  99. timeout = 10;
  100. /* wait max 10 ms until cpu1 is on */
  101. while ((__raw_readl(S5P_ARM_CORE1_STATUS)
  102. & S5P_CORE_LOCAL_PWR_EN) != 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. if (call_firmware_op(set_cpu_boot_addr, phys_cpu, boot_addr))
  128. __raw_writel(boot_addr, cpu_boot_reg(phys_cpu));
  129. call_firmware_op(cpu_boot, phys_cpu);
  130. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  131. if (pen_release == -1)
  132. break;
  133. udelay(10);
  134. }
  135. /*
  136. * now the secondary core is starting up let it run its
  137. * calibrations, then wait for it to finish
  138. */
  139. spin_unlock(&boot_lock);
  140. return pen_release != -1 ? -ENOSYS : 0;
  141. }
  142. /*
  143. * Initialise the CPU possible map early - this describes the CPUs
  144. * which may be present or become present in the system.
  145. */
  146. static void __init exynos_smp_init_cpus(void)
  147. {
  148. void __iomem *scu_base = scu_base_addr();
  149. unsigned int i, ncores;
  150. if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
  151. ncores = scu_base ? scu_get_core_count(scu_base) : 1;
  152. else
  153. /*
  154. * CPU Nodes are passed thru DT and set_cpu_possible
  155. * is set by "arm_dt_init_cpu_maps".
  156. */
  157. return;
  158. /* sanity check */
  159. if (ncores > nr_cpu_ids) {
  160. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  161. ncores, nr_cpu_ids);
  162. ncores = nr_cpu_ids;
  163. }
  164. for (i = 0; i < ncores; i++)
  165. set_cpu_possible(i, true);
  166. }
  167. static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
  168. {
  169. int i;
  170. if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
  171. scu_enable(scu_base_addr());
  172. /*
  173. * Write the address of secondary startup into the
  174. * system-wide flags register. The boot monitor waits
  175. * until it receives a soft interrupt, and then the
  176. * secondary CPU branches to this address.
  177. *
  178. * Try using firmware operation first and fall back to
  179. * boot register if it fails.
  180. */
  181. for (i = 1; i < max_cpus; ++i) {
  182. unsigned long phys_cpu;
  183. unsigned long boot_addr;
  184. phys_cpu = cpu_logical_map(i);
  185. boot_addr = virt_to_phys(exynos4_secondary_startup);
  186. if (call_firmware_op(set_cpu_boot_addr, phys_cpu, boot_addr))
  187. __raw_writel(boot_addr, cpu_boot_reg(phys_cpu));
  188. }
  189. }
  190. struct smp_operations exynos_smp_ops __initdata = {
  191. .smp_init_cpus = exynos_smp_init_cpus,
  192. .smp_prepare_cpus = exynos_smp_prepare_cpus,
  193. .smp_secondary_init = exynos_secondary_init,
  194. .smp_boot_secondary = exynos_boot_secondary,
  195. #ifdef CONFIG_HOTPLUG_CPU
  196. .cpu_die = exynos_cpu_die,
  197. #endif
  198. };