omap-smp.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * OMAP4 SMP source file. It contains platform specific fucntions
  3. * needed for the linux smp kernel.
  4. *
  5. * Copyright (C) 2009 Texas Instruments, Inc.
  6. *
  7. * Author:
  8. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  9. *
  10. * Platform file needed for the OMAP4 SMP. This file is based on arm
  11. * realview smp platform.
  12. * * Copyright (c) 2002 ARM Limited.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/device.h>
  20. #include <linux/smp.h>
  21. #include <linux/io.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/hardware/gic.h>
  24. #include <asm/smp_scu.h>
  25. #include <mach/hardware.h>
  26. #include <mach/omap-secure.h>
  27. #include "iomap.h"
  28. #include "common.h"
  29. #include "clockdomain.h"
  30. /* SCU base address */
  31. static void __iomem *scu_base;
  32. static DEFINE_SPINLOCK(boot_lock);
  33. void __iomem *omap4_get_scu_base(void)
  34. {
  35. return scu_base;
  36. }
  37. void __cpuinit platform_secondary_init(unsigned int cpu)
  38. {
  39. /*
  40. * Configure ACTRL and enable NS SMP bit access on CPU1 on HS device.
  41. * OMAP44XX EMU/HS devices - CPU0 SMP bit access is enabled in PPA
  42. * init and for CPU1, a secure PPA API provided. CPU0 must be ON
  43. * while executing NS_SMP API on CPU1 and PPA version must be 1.4.0+.
  44. * OMAP443X GP devices- SMP bit isn't accessible.
  45. * OMAP446X GP devices - SMP bit access is enabled on both CPUs.
  46. */
  47. if (cpu_is_omap443x() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  48. omap_secure_dispatcher(OMAP4_PPA_CPU_ACTRL_SMP_INDEX,
  49. 4, 0, 0, 0, 0, 0);
  50. /*
  51. * If any interrupts are already enabled for the primary
  52. * core (e.g. timer irq), then they will not have been enabled
  53. * for us: do so
  54. */
  55. gic_secondary_init(0);
  56. /*
  57. * Synchronise with the boot thread.
  58. */
  59. spin_lock(&boot_lock);
  60. spin_unlock(&boot_lock);
  61. }
  62. int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
  63. {
  64. static struct clockdomain *cpu1_clkdm;
  65. static bool booted;
  66. /*
  67. * Set synchronisation state between this boot processor
  68. * and the secondary one
  69. */
  70. spin_lock(&boot_lock);
  71. /*
  72. * Update the AuxCoreBoot0 with boot state for secondary core.
  73. * omap_secondary_startup() routine will hold the secondary core till
  74. * the AuxCoreBoot1 register is updated with cpu state
  75. * A barrier is added to ensure that write buffer is drained
  76. */
  77. omap_modify_auxcoreboot0(0x200, 0xfffffdff);
  78. flush_cache_all();
  79. smp_wmb();
  80. if (!cpu1_clkdm)
  81. cpu1_clkdm = clkdm_lookup("mpu1_clkdm");
  82. /*
  83. * The SGI(Software Generated Interrupts) are not wakeup capable
  84. * from low power states. This is known limitation on OMAP4 and
  85. * needs to be worked around by using software forced clockdomain
  86. * wake-up. To wakeup CPU1, CPU0 forces the CPU1 clockdomain to
  87. * software force wakeup. The clockdomain is then put back to
  88. * hardware supervised mode.
  89. * More details can be found in OMAP4430 TRM - Version J
  90. * Section :
  91. * 4.3.4.2 Power States of CPU0 and CPU1
  92. */
  93. if (booted) {
  94. clkdm_wakeup(cpu1_clkdm);
  95. clkdm_allow_idle(cpu1_clkdm);
  96. } else {
  97. dsb_sev();
  98. booted = true;
  99. }
  100. gic_raise_softirq(cpumask_of(cpu), 1);
  101. /*
  102. * Now the secondary core is starting up let it run its
  103. * calibrations, then wait for it to finish
  104. */
  105. spin_unlock(&boot_lock);
  106. return 0;
  107. }
  108. static void __init wakeup_secondary(void)
  109. {
  110. /*
  111. * Write the address of secondary startup routine into the
  112. * AuxCoreBoot1 where ROM code will jump and start executing
  113. * on secondary core once out of WFE
  114. * A barrier is added to ensure that write buffer is drained
  115. */
  116. omap_auxcoreboot_addr(virt_to_phys(omap_secondary_startup));
  117. smp_wmb();
  118. /*
  119. * Send a 'sev' to wake the secondary core from WFE.
  120. * Drain the outstanding writes to memory
  121. */
  122. dsb_sev();
  123. mb();
  124. }
  125. /*
  126. * Initialise the CPU possible map early - this describes the CPUs
  127. * which may be present or become present in the system.
  128. */
  129. void __init smp_init_cpus(void)
  130. {
  131. unsigned int i, ncores;
  132. /*
  133. * Currently we can't call ioremap here because
  134. * SoC detection won't work until after init_early.
  135. */
  136. scu_base = OMAP2_L4_IO_ADDRESS(OMAP44XX_SCU_BASE);
  137. BUG_ON(!scu_base);
  138. ncores = scu_get_core_count(scu_base);
  139. /* sanity check */
  140. if (ncores > nr_cpu_ids) {
  141. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  142. ncores, nr_cpu_ids);
  143. ncores = nr_cpu_ids;
  144. }
  145. for (i = 0; i < ncores; i++)
  146. set_cpu_possible(i, true);
  147. set_smp_cross_call(gic_raise_softirq);
  148. }
  149. void __init platform_smp_prepare_cpus(unsigned int max_cpus)
  150. {
  151. /*
  152. * Initialise the SCU and wake up the secondary core using
  153. * wakeup_secondary().
  154. */
  155. scu_enable(scu_base);
  156. wakeup_secondary();
  157. }