omap-smp.c 4.6 KB

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