platsmp.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * linux/arch/arm/mach-tegra/platsmp.c
  3. *
  4. * Copyright (C) 2002 ARM Ltd.
  5. * All Rights Reserved
  6. *
  7. * Copyright (C) 2009 Palm
  8. * All Rights Reserved
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/errno.h>
  16. #include <linux/delay.h>
  17. #include <linux/device.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/smp.h>
  20. #include <linux/io.h>
  21. #include <asm/cacheflush.h>
  22. #include <asm/hardware/gic.h>
  23. #include <asm/mach-types.h>
  24. #include <asm/smp_scu.h>
  25. #include <asm/smp_plat.h>
  26. #include <mach/powergate.h>
  27. #include "fuse.h"
  28. #include "flowctrl.h"
  29. #include "reset.h"
  30. #include "tegra_cpu_car.h"
  31. #include "common.h"
  32. #include "iomap.h"
  33. extern void tegra_secondary_startup(void);
  34. static cpumask_t tegra_cpu_init_mask;
  35. static void __iomem *scu_base = IO_ADDRESS(TEGRA_ARM_PERIF_BASE);
  36. #define EVP_CPU_RESET_VECTOR \
  37. (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)
  38. static void __cpuinit tegra_secondary_init(unsigned int cpu)
  39. {
  40. /*
  41. * if any interrupts are already enabled for the primary
  42. * core (e.g. timer irq), then they will not have been enabled
  43. * for us: do so
  44. */
  45. gic_secondary_init(0);
  46. cpumask_set_cpu(cpu, &tegra_cpu_init_mask);
  47. }
  48. static int tegra20_power_up_cpu(unsigned int cpu)
  49. {
  50. /* Enable the CPU clock. */
  51. tegra_enable_cpu_clock(cpu);
  52. /* Clear flow controller CSR. */
  53. flowctrl_write_cpu_csr(cpu, 0);
  54. return 0;
  55. }
  56. static int tegra30_power_up_cpu(unsigned int cpu)
  57. {
  58. int ret, pwrgateid;
  59. unsigned long timeout;
  60. pwrgateid = tegra_cpu_powergate_id(cpu);
  61. if (pwrgateid < 0)
  62. return pwrgateid;
  63. /*
  64. * The power up sequence of cold boot CPU and warm boot CPU
  65. * was different.
  66. *
  67. * For warm boot CPU that was resumed from CPU hotplug, the
  68. * power will be resumed automatically after un-halting the
  69. * flow controller of the warm boot CPU. We need to wait for
  70. * the confirmaiton that the CPU is powered then removing
  71. * the IO clamps.
  72. * For cold boot CPU, do not wait. After the cold boot CPU be
  73. * booted, it will run to tegra_secondary_init() and set
  74. * tegra_cpu_init_mask which influences what tegra30_power_up_cpu()
  75. * next time around.
  76. */
  77. if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
  78. timeout = jiffies + 5*HZ;
  79. do {
  80. if (!tegra_powergate_is_powered(pwrgateid))
  81. goto remove_clamps;
  82. udelay(10);
  83. } while (time_before(jiffies, timeout));
  84. }
  85. /*
  86. * The power status of the cold boot CPU is power gated as
  87. * default. To power up the cold boot CPU, the power should
  88. * be un-gated by un-toggling the power gate register
  89. * manually.
  90. */
  91. if (!tegra_powergate_is_powered(pwrgateid)) {
  92. ret = tegra_powergate_power_on(pwrgateid);
  93. if (ret)
  94. return ret;
  95. /* Wait for the power to come up. */
  96. timeout = jiffies + 10*HZ;
  97. while (tegra_powergate_is_powered(pwrgateid)) {
  98. if (time_after(jiffies, timeout))
  99. return -ETIMEDOUT;
  100. udelay(10);
  101. }
  102. }
  103. remove_clamps:
  104. /* CPU partition is powered. Enable the CPU clock. */
  105. tegra_enable_cpu_clock(cpu);
  106. udelay(10);
  107. /* Remove I/O clamps. */
  108. ret = tegra_powergate_remove_clamping(pwrgateid);
  109. udelay(10);
  110. /* Clear flow controller CSR. */
  111. flowctrl_write_cpu_csr(cpu, 0);
  112. return 0;
  113. }
  114. static int __cpuinit tegra_boot_secondary(unsigned int cpu, struct task_struct *idle)
  115. {
  116. int status;
  117. cpu = cpu_logical_map(cpu);
  118. /*
  119. * Force the CPU into reset. The CPU must remain in reset when the
  120. * flow controller state is cleared (which will cause the flow
  121. * controller to stop driving reset if the CPU has been power-gated
  122. * via the flow controller). This will have no effect on first boot
  123. * of the CPU since it should already be in reset.
  124. */
  125. tegra_put_cpu_in_reset(cpu);
  126. /*
  127. * Unhalt the CPU. If the flow controller was used to power-gate the
  128. * CPU this will cause the flow controller to stop driving reset.
  129. * The CPU will remain in reset because the clock and reset block
  130. * is now driving reset.
  131. */
  132. flowctrl_write_cpu_halt(cpu, 0);
  133. switch (tegra_chip_id) {
  134. case TEGRA20:
  135. status = tegra20_power_up_cpu(cpu);
  136. break;
  137. case TEGRA30:
  138. status = tegra30_power_up_cpu(cpu);
  139. break;
  140. default:
  141. status = -EINVAL;
  142. break;
  143. }
  144. if (status)
  145. goto done;
  146. /* Take the CPU out of reset. */
  147. tegra_cpu_out_of_reset(cpu);
  148. done:
  149. return status;
  150. }
  151. /*
  152. * Initialise the CPU possible map early - this describes the CPUs
  153. * which may be present or become present in the system.
  154. */
  155. static void __init tegra_smp_init_cpus(void)
  156. {
  157. unsigned int i, ncores = scu_get_core_count(scu_base);
  158. if (ncores > nr_cpu_ids) {
  159. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  160. ncores, nr_cpu_ids);
  161. ncores = nr_cpu_ids;
  162. }
  163. for (i = 0; i < ncores; i++)
  164. set_cpu_possible(i, true);
  165. set_smp_cross_call(gic_raise_softirq);
  166. }
  167. static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
  168. {
  169. /* Always mark the boot CPU (CPU0) as initialized. */
  170. cpumask_set_cpu(0, &tegra_cpu_init_mask);
  171. scu_enable(scu_base);
  172. }
  173. struct smp_operations tegra_smp_ops __initdata = {
  174. .smp_init_cpus = tegra_smp_init_cpus,
  175. .smp_prepare_cpus = tegra_smp_prepare_cpus,
  176. .smp_secondary_init = tegra_secondary_init,
  177. .smp_boot_secondary = tegra_boot_secondary,
  178. #ifdef CONFIG_HOTPLUG_CPU
  179. .cpu_kill = tegra_cpu_kill,
  180. .cpu_die = tegra_cpu_die,
  181. .cpu_disable = tegra_cpu_disable,
  182. #endif
  183. };