platsmp.c 4.1 KB

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