platsmp.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/cacheflush.h>
  18. #include <asm/cputype.h>
  19. #include <asm/mach-types.h>
  20. #include <asm/smp_plat.h>
  21. #include "scm-boot.h"
  22. #include "common.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. extern void msm_secondary_startup(void);
  27. static DEFINE_SPINLOCK(boot_lock);
  28. static inline int get_core_count(void)
  29. {
  30. /* 1 + the PART[1:0] field of MIDR */
  31. return ((read_cpuid_id() >> 4) & 3) + 1;
  32. }
  33. static void msm_secondary_init(unsigned int cpu)
  34. {
  35. /*
  36. * let the primary processor know we're out of the
  37. * pen, then head off into the C entry point
  38. */
  39. pen_release = -1;
  40. smp_wmb();
  41. /*
  42. * Synchronise with the boot thread.
  43. */
  44. spin_lock(&boot_lock);
  45. spin_unlock(&boot_lock);
  46. }
  47. static void prepare_cold_cpu(unsigned int cpu)
  48. {
  49. int ret;
  50. ret = scm_set_boot_addr(virt_to_phys(msm_secondary_startup),
  51. SCM_FLAG_COLDBOOT_CPU1);
  52. if (ret == 0) {
  53. void __iomem *sc1_base_ptr;
  54. sc1_base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
  55. if (sc1_base_ptr) {
  56. writel(0, sc1_base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL);
  57. writel(0, sc1_base_ptr + SCSS_CPU1CORE_RESET);
  58. writel(3, sc1_base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP);
  59. iounmap(sc1_base_ptr);
  60. }
  61. } else
  62. printk(KERN_DEBUG "Failed to set secondary core boot "
  63. "address\n");
  64. }
  65. static int msm_boot_secondary(unsigned int cpu, struct task_struct *idle)
  66. {
  67. unsigned long timeout;
  68. static int cold_boot_done;
  69. /* Only need to bring cpu out of reset this way once */
  70. if (cold_boot_done == false) {
  71. prepare_cold_cpu(cpu);
  72. cold_boot_done = true;
  73. }
  74. /*
  75. * set synchronisation state between this boot processor
  76. * and the secondary one
  77. */
  78. spin_lock(&boot_lock);
  79. /*
  80. * The secondary processor is waiting to be released from
  81. * the holding pen - release it, then wait for it to flag
  82. * that it has been released by resetting pen_release.
  83. *
  84. * Note that "pen_release" is the hardware CPU ID, whereas
  85. * "cpu" is Linux's internal ID.
  86. */
  87. pen_release = cpu_logical_map(cpu);
  88. sync_cache_w(&pen_release);
  89. /*
  90. * Send the secondary CPU a soft interrupt, thereby causing
  91. * the boot monitor to read the system wide flags register,
  92. * and branch to the address found there.
  93. */
  94. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  95. timeout = jiffies + (1 * HZ);
  96. while (time_before(jiffies, timeout)) {
  97. smp_rmb();
  98. if (pen_release == -1)
  99. break;
  100. udelay(10);
  101. }
  102. /*
  103. * now the secondary core is starting up let it run its
  104. * calibrations, then wait for it to finish
  105. */
  106. spin_unlock(&boot_lock);
  107. return pen_release != -1 ? -ENOSYS : 0;
  108. }
  109. /*
  110. * Initialise the CPU possible map early - this describes the CPUs
  111. * which may be present or become present in the system. The msm8x60
  112. * does not support the ARM SCU, so just set the possible cpu mask to
  113. * NR_CPUS.
  114. */
  115. static void __init msm_smp_init_cpus(void)
  116. {
  117. unsigned int i, ncores = get_core_count();
  118. if (ncores > nr_cpu_ids) {
  119. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  120. ncores, nr_cpu_ids);
  121. ncores = nr_cpu_ids;
  122. }
  123. for (i = 0; i < ncores; i++)
  124. set_cpu_possible(i, true);
  125. }
  126. static void __init msm_smp_prepare_cpus(unsigned int max_cpus)
  127. {
  128. }
  129. struct smp_operations msm_smp_ops __initdata = {
  130. .smp_init_cpus = msm_smp_init_cpus,
  131. .smp_prepare_cpus = msm_smp_prepare_cpus,
  132. .smp_secondary_init = msm_secondary_init,
  133. .smp_boot_secondary = msm_boot_secondary,
  134. #ifdef CONFIG_HOTPLUG_CPU
  135. .cpu_die = msm_cpu_die,
  136. #endif
  137. };