platsmp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 <mach/hardware.h>
  24. #include <asm/mach-types.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. /*
  39. * if any interrupts are already enabled for the primary
  40. * core (e.g. timer irq), then they will not have been enabled
  41. * for us: do so
  42. */
  43. gic_secondary_init(0);
  44. /*
  45. * Synchronise with the boot thread.
  46. */
  47. spin_lock(&boot_lock);
  48. spin_unlock(&boot_lock);
  49. }
  50. int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
  51. {
  52. unsigned long old_boot_vector;
  53. unsigned long boot_vector;
  54. unsigned long timeout;
  55. u32 reg;
  56. /*
  57. * set synchronisation state between this boot processor
  58. * and the secondary one
  59. */
  60. spin_lock(&boot_lock);
  61. /* set the reset vector to point to the secondary_startup routine */
  62. boot_vector = virt_to_phys(tegra_secondary_startup);
  63. old_boot_vector = readl(EVP_CPU_RESET_VECTOR);
  64. writel(boot_vector, EVP_CPU_RESET_VECTOR);
  65. /* enable cpu clock on cpu1 */
  66. reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  67. writel(reg & ~(1<<9), CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  68. reg = (1<<13) | (1<<9) | (1<<5) | (1<<1);
  69. writel(reg, CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
  70. smp_wmb();
  71. flush_cache_all();
  72. /* unhalt the cpu */
  73. writel(0, IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + 0x14);
  74. timeout = jiffies + (1 * HZ);
  75. while (time_before(jiffies, timeout)) {
  76. if (readl(EVP_CPU_RESET_VECTOR) != boot_vector)
  77. break;
  78. udelay(10);
  79. }
  80. /* put the old boot vector back */
  81. writel(old_boot_vector, EVP_CPU_RESET_VECTOR);
  82. /*
  83. * now the secondary core is starting up let it run its
  84. * calibrations, then wait for it to finish
  85. */
  86. spin_unlock(&boot_lock);
  87. return 0;
  88. }
  89. /*
  90. * Initialise the CPU possible map early - this describes the CPUs
  91. * which may be present or become present in the system.
  92. */
  93. void __init smp_init_cpus(void)
  94. {
  95. unsigned int i, ncores = scu_get_core_count(scu_base);
  96. if (ncores > NR_CPUS) {
  97. printk(KERN_ERR "Tegra: no. of cores (%u) greater than configured (%u), clipping\n",
  98. ncores, NR_CPUS);
  99. ncores = NR_CPUS;
  100. }
  101. for (i = 0; i < ncores; i++)
  102. cpu_set(i, cpu_possible_map);
  103. set_smp_cross_call(gic_raise_softirq);
  104. }
  105. void __init platform_smp_prepare_cpus(unsigned int max_cpus)
  106. {
  107. int i;
  108. /*
  109. * Initialise the present map, which describes the set of CPUs
  110. * actually populated at the present time.
  111. */
  112. for (i = 0; i < max_cpus; i++)
  113. set_cpu_present(i, true);
  114. scu_enable(scu_base);
  115. }