platsmp.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 <mach/hardware.h>
  23. #include <asm/mach-types.h>
  24. #include <asm/localtimer.h>
  25. #include <asm/smp_scu.h>
  26. #include <mach/iomap.h>
  27. extern void tegra_secondary_startup(void);
  28. static DEFINE_SPINLOCK(boot_lock);
  29. static void __iomem *scu_base = IO_ADDRESS(TEGRA_ARM_PERIF_BASE);
  30. #define EVP_CPU_RESET_VECTOR \
  31. (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)
  32. #define CLK_RST_CONTROLLER_CLK_CPU_CMPLX \
  33. (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x4c)
  34. #define CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR \
  35. (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x344)
  36. void __cpuinit platform_secondary_init(unsigned int cpu)
  37. {
  38. trace_hardirqs_off();
  39. /*
  40. * if any interrupts are already enabled for the primary
  41. * core (e.g. timer irq), then they will not have been enabled
  42. * for us: do so
  43. */
  44. gic_cpu_init(0, IO_ADDRESS(TEGRA_ARM_PERIF_BASE) + 0x100);
  45. /*
  46. * Synchronise with the boot thread.
  47. */
  48. spin_lock(&boot_lock);
  49. spin_unlock(&boot_lock);
  50. }
  51. int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
  52. {
  53. unsigned long old_boot_vector;
  54. unsigned long boot_vector;
  55. unsigned long timeout;
  56. u32 reg;
  57. /*
  58. * set synchronisation state between this boot processor
  59. * and the secondary one
  60. */
  61. spin_lock(&boot_lock);
  62. /* set the reset vector to point to the secondary_startup routine */
  63. boot_vector = virt_to_phys(tegra_secondary_startup);
  64. old_boot_vector = readl(EVP_CPU_RESET_VECTOR);
  65. writel(boot_vector, EVP_CPU_RESET_VECTOR);
  66. /* enable cpu clock on cpu1 */
  67. reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  68. writel(reg & ~(1<<9), CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  69. reg = (1<<13) | (1<<9) | (1<<5) | (1<<1);
  70. writel(reg, CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
  71. smp_wmb();
  72. flush_cache_all();
  73. /* unhalt the cpu */
  74. writel(0, IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + 0x14);
  75. timeout = jiffies + (1 * HZ);
  76. while (time_before(jiffies, timeout)) {
  77. if (readl(EVP_CPU_RESET_VECTOR) != boot_vector)
  78. break;
  79. udelay(10);
  80. }
  81. /* put the old boot vector back */
  82. writel(old_boot_vector, EVP_CPU_RESET_VECTOR);
  83. /*
  84. * now the secondary core is starting up let it run its
  85. * calibrations, then wait for it to finish
  86. */
  87. spin_unlock(&boot_lock);
  88. return 0;
  89. }
  90. /*
  91. * Initialise the CPU possible map early - this describes the CPUs
  92. * which may be present or become present in the system.
  93. */
  94. void __init smp_init_cpus(void)
  95. {
  96. unsigned int i, ncores = scu_get_core_count(scu_base);
  97. for (i = 0; i < ncores; i++)
  98. cpu_set(i, cpu_possible_map);
  99. }
  100. void __init smp_prepare_cpus(unsigned int max_cpus)
  101. {
  102. unsigned int ncores = scu_get_core_count(scu_base);
  103. unsigned int cpu = smp_processor_id();
  104. int i;
  105. smp_store_cpu_info(cpu);
  106. /*
  107. * are we trying to boot more cores than exist?
  108. */
  109. if (max_cpus > ncores)
  110. max_cpus = ncores;
  111. /*
  112. * Initialise the present map, which describes the set of CPUs
  113. * actually populated at the present time.
  114. */
  115. for (i = 0; i < max_cpus; i++)
  116. set_cpu_present(i, true);
  117. /*
  118. * Initialise the SCU if there are more than one CPU and let
  119. * them know where to start. Note that, on modern versions of
  120. * MILO, the "poke" doesn't actually do anything until each
  121. * individual core is sent a soft interrupt to get it out of
  122. * WFI
  123. */
  124. if (max_cpus > 1) {
  125. percpu_timer_setup();
  126. scu_enable(scu_base);
  127. }
  128. }