platsmp.c 3.3 KB

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