platsmp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. trace_hardirqs_off();
  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_cpu_init(0, IO_ADDRESS(TEGRA_ARM_PERIF_BASE) + 0x100);
  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. }
  104. void __init platform_smp_prepare_cpus(unsigned int max_cpus)
  105. {
  106. int i;
  107. /*
  108. * Initialise the present map, which describes the set of CPUs
  109. * actually populated at the present time.
  110. */
  111. for (i = 0; i < max_cpus; i++)
  112. set_cpu_present(i, true);
  113. scu_enable(scu_base);
  114. }