platsmp.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C) 2002 ARM Ltd.
  3. * All Rights Reserved
  4. * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/errno.h>
  12. #include <linux/delay.h>
  13. #include <linux/device.h>
  14. #include <linux/jiffies.h>
  15. #include <linux/smp.h>
  16. #include <linux/io.h>
  17. #include <linux/irqchip/arm-gic.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/cputype.h>
  20. #include <asm/mach-types.h>
  21. #include <asm/smp_plat.h>
  22. #include "scm-boot.h"
  23. #include "common.h"
  24. #define VDD_SC1_ARRAY_CLAMP_GFS_CTL 0x15A0
  25. #define SCSS_CPU1CORE_RESET 0xD80
  26. #define SCSS_DBG_STATUS_CORE_PWRDUP 0xE64
  27. extern void msm_secondary_startup(void);
  28. static DEFINE_SPINLOCK(boot_lock);
  29. static inline int get_core_count(void)
  30. {
  31. /* 1 + the PART[1:0] field of MIDR */
  32. return ((read_cpuid_id() >> 4) & 3) + 1;
  33. }
  34. static void __cpuinit msm_secondary_init(unsigned int cpu)
  35. {
  36. /*
  37. * if any interrupts are already enabled for the primary
  38. * core (e.g. timer irq), then they will not have been enabled
  39. * for us: do so
  40. */
  41. gic_secondary_init(0);
  42. /*
  43. * let the primary processor know we're out of the
  44. * pen, then head off into the C entry point
  45. */
  46. pen_release = -1;
  47. smp_wmb();
  48. /*
  49. * Synchronise with the boot thread.
  50. */
  51. spin_lock(&boot_lock);
  52. spin_unlock(&boot_lock);
  53. }
  54. static __cpuinit void prepare_cold_cpu(unsigned int cpu)
  55. {
  56. int ret;
  57. ret = scm_set_boot_addr(virt_to_phys(msm_secondary_startup),
  58. SCM_FLAG_COLDBOOT_CPU1);
  59. if (ret == 0) {
  60. void __iomem *sc1_base_ptr;
  61. sc1_base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
  62. if (sc1_base_ptr) {
  63. writel(0, sc1_base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL);
  64. writel(0, sc1_base_ptr + SCSS_CPU1CORE_RESET);
  65. writel(3, sc1_base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP);
  66. iounmap(sc1_base_ptr);
  67. }
  68. } else
  69. printk(KERN_DEBUG "Failed to set secondary core boot "
  70. "address\n");
  71. }
  72. static int __cpuinit msm_boot_secondary(unsigned int cpu, struct task_struct *idle)
  73. {
  74. unsigned long timeout;
  75. static int cold_boot_done;
  76. /* Only need to bring cpu out of reset this way once */
  77. if (cold_boot_done == false) {
  78. prepare_cold_cpu(cpu);
  79. cold_boot_done = true;
  80. }
  81. /*
  82. * set synchronisation state between this boot processor
  83. * and the secondary one
  84. */
  85. spin_lock(&boot_lock);
  86. /*
  87. * The secondary processor is waiting to be released from
  88. * the holding pen - release it, then wait for it to flag
  89. * that it has been released by resetting pen_release.
  90. *
  91. * Note that "pen_release" is the hardware CPU ID, whereas
  92. * "cpu" is Linux's internal ID.
  93. */
  94. pen_release = cpu_logical_map(cpu);
  95. __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
  96. outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
  97. /*
  98. * Send the secondary CPU a soft interrupt, thereby causing
  99. * the boot monitor to read the system wide flags register,
  100. * and branch to the address found there.
  101. */
  102. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  103. timeout = jiffies + (1 * HZ);
  104. while (time_before(jiffies, timeout)) {
  105. smp_rmb();
  106. if (pen_release == -1)
  107. break;
  108. udelay(10);
  109. }
  110. /*
  111. * now the secondary core is starting up let it run its
  112. * calibrations, then wait for it to finish
  113. */
  114. spin_unlock(&boot_lock);
  115. return pen_release != -1 ? -ENOSYS : 0;
  116. }
  117. /*
  118. * Initialise the CPU possible map early - this describes the CPUs
  119. * which may be present or become present in the system. The msm8x60
  120. * does not support the ARM SCU, so just set the possible cpu mask to
  121. * NR_CPUS.
  122. */
  123. static void __init msm_smp_init_cpus(void)
  124. {
  125. unsigned int i, ncores = get_core_count();
  126. if (ncores > nr_cpu_ids) {
  127. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  128. ncores, nr_cpu_ids);
  129. ncores = nr_cpu_ids;
  130. }
  131. for (i = 0; i < ncores; i++)
  132. set_cpu_possible(i, true);
  133. }
  134. static void __init msm_smp_prepare_cpus(unsigned int max_cpus)
  135. {
  136. }
  137. struct smp_operations msm_smp_ops __initdata = {
  138. .smp_init_cpus = msm_smp_init_cpus,
  139. .smp_prepare_cpus = msm_smp_prepare_cpus,
  140. .smp_secondary_init = msm_secondary_init,
  141. .smp_boot_secondary = msm_boot_secondary,
  142. #ifdef CONFIG_HOTPLUG_CPU
  143. .cpu_die = msm_cpu_die,
  144. #endif
  145. };