platsmp.c 4.1 KB

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