platsmp.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 <asm/hardware/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 <mach/msm_iomap.h>
  23. #include "scm-boot.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. /* Mask for edge trigger PPIs except AVS_SVICINT and AVS_SVICINTSWDONE */
  28. #define GIC_PPI_EDGE_MASK 0xFFFFD7FF
  29. extern void msm_secondary_startup(void);
  30. /*
  31. * control for which core is the next to come out of the secondary
  32. * boot "holding pen".
  33. */
  34. volatile int pen_release = -1;
  35. static DEFINE_SPINLOCK(boot_lock);
  36. static inline int get_core_count(void)
  37. {
  38. /* 1 + the PART[1:0] field of MIDR */
  39. return ((read_cpuid_id() >> 4) & 3) + 1;
  40. }
  41. void __cpuinit platform_secondary_init(unsigned int cpu)
  42. {
  43. /* Configure edge-triggered PPIs */
  44. writel(GIC_PPI_EDGE_MASK, MSM_QGIC_DIST_BASE + GIC_DIST_CONFIG + 4);
  45. /*
  46. * if any interrupts are already enabled for the primary
  47. * core (e.g. timer irq), then they will not have been enabled
  48. * for us: do so
  49. */
  50. gic_secondary_init(0);
  51. /*
  52. * let the primary processor know we're out of the
  53. * pen, then head off into the C entry point
  54. */
  55. pen_release = -1;
  56. smp_wmb();
  57. /*
  58. * Synchronise with the boot thread.
  59. */
  60. spin_lock(&boot_lock);
  61. spin_unlock(&boot_lock);
  62. }
  63. static __cpuinit void prepare_cold_cpu(unsigned int cpu)
  64. {
  65. int ret;
  66. ret = scm_set_boot_addr(virt_to_phys(msm_secondary_startup),
  67. SCM_FLAG_COLDBOOT_CPU1);
  68. if (ret == 0) {
  69. void __iomem *sc1_base_ptr;
  70. sc1_base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
  71. if (sc1_base_ptr) {
  72. writel(0, sc1_base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL);
  73. writel(0, sc1_base_ptr + SCSS_CPU1CORE_RESET);
  74. writel(3, sc1_base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP);
  75. iounmap(sc1_base_ptr);
  76. }
  77. } else
  78. printk(KERN_DEBUG "Failed to set secondary core boot "
  79. "address\n");
  80. }
  81. int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
  82. {
  83. unsigned long timeout;
  84. static int cold_boot_done;
  85. /* Only need to bring cpu out of reset this way once */
  86. if (cold_boot_done == false) {
  87. prepare_cold_cpu(cpu);
  88. cold_boot_done = true;
  89. }
  90. /*
  91. * set synchronisation state between this boot processor
  92. * and the secondary one
  93. */
  94. spin_lock(&boot_lock);
  95. /*
  96. * The secondary processor is waiting to be released from
  97. * the holding pen - release it, then wait for it to flag
  98. * that it has been released by resetting pen_release.
  99. *
  100. * Note that "pen_release" is the hardware CPU ID, whereas
  101. * "cpu" is Linux's internal ID.
  102. */
  103. pen_release = cpu_logical_map(cpu);
  104. __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
  105. outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
  106. /*
  107. * Send the secondary CPU a soft interrupt, thereby causing
  108. * the boot monitor to read the system wide flags register,
  109. * and branch to the address found there.
  110. */
  111. gic_raise_softirq(cpumask_of(cpu), 1);
  112. timeout = jiffies + (1 * HZ);
  113. while (time_before(jiffies, timeout)) {
  114. smp_rmb();
  115. if (pen_release == -1)
  116. break;
  117. udelay(10);
  118. }
  119. /*
  120. * now the secondary core is starting up let it run its
  121. * calibrations, then wait for it to finish
  122. */
  123. spin_unlock(&boot_lock);
  124. return pen_release != -1 ? -ENOSYS : 0;
  125. }
  126. /*
  127. * Initialise the CPU possible map early - this describes the CPUs
  128. * which may be present or become present in the system. The msm8x60
  129. * does not support the ARM SCU, so just set the possible cpu mask to
  130. * NR_CPUS.
  131. */
  132. void __init smp_init_cpus(void)
  133. {
  134. unsigned int i, ncores = get_core_count();
  135. if (ncores > nr_cpu_ids) {
  136. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  137. ncores, nr_cpu_ids);
  138. ncores = nr_cpu_ids;
  139. }
  140. for (i = 0; i < ncores; i++)
  141. set_cpu_possible(i, true);
  142. set_smp_cross_call(gic_raise_softirq);
  143. }
  144. void __init platform_smp_prepare_cpus(unsigned int max_cpus)
  145. {
  146. }