platsmp.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (C) 2002 ARM Ltd.
  3. * Copyright (C) 2008 STMicroelctronics.
  4. * Copyright (C) 2009 ST-Ericsson.
  5. * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
  6. *
  7. * This file is based on arm realview platform
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/errno.h>
  15. #include <linux/delay.h>
  16. #include <linux/device.h>
  17. #include <linux/smp.h>
  18. #include <linux/io.h>
  19. #include <asm/cacheflush.h>
  20. #include <asm/localtimer.h>
  21. #include <asm/smp_scu.h>
  22. #include <mach/hardware.h>
  23. /*
  24. * control for which core is the next to come out of the secondary
  25. * boot "holding pen"
  26. */
  27. volatile int __cpuinitdata pen_release = -1;
  28. static unsigned int __init get_core_count(void)
  29. {
  30. return scu_get_core_count(__io_address(UX500_SCU_BASE));
  31. }
  32. static DEFINE_SPINLOCK(boot_lock);
  33. void __cpuinit platform_secondary_init(unsigned int cpu)
  34. {
  35. trace_hardirqs_off();
  36. /*
  37. * if any interrupts are already enabled for the primary
  38. * core (e.g. timer irq), then they will not have been enabled
  39. * for us: do so
  40. */
  41. gic_cpu_init(0, __io_address(UX500_GIC_CPU_BASE));
  42. /*
  43. * let the primary processor know we're out of the
  44. * pen, then head off into the C entry point
  45. */
  46. pen_release = -1;
  47. /*
  48. * Synchronise with the boot thread.
  49. */
  50. spin_lock(&boot_lock);
  51. spin_unlock(&boot_lock);
  52. }
  53. int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
  54. {
  55. unsigned long timeout;
  56. /*
  57. * set synchronisation state between this boot processor
  58. * and the secondary one
  59. */
  60. spin_lock(&boot_lock);
  61. /*
  62. * The secondary processor is waiting to be released from
  63. * the holding pen - release it, then wait for it to flag
  64. * that it has been released by resetting pen_release.
  65. */
  66. pen_release = cpu;
  67. __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
  68. outer_clean_range(__pa(&pen_release), __pa(&pen_release) + 1);
  69. timeout = jiffies + (1 * HZ);
  70. while (time_before(jiffies, timeout)) {
  71. if (pen_release == -1)
  72. break;
  73. }
  74. /*
  75. * now the secondary core is starting up let it run its
  76. * calibrations, then wait for it to finish
  77. */
  78. spin_unlock(&boot_lock);
  79. return pen_release != -1 ? -ENOSYS : 0;
  80. }
  81. static void __init wakeup_secondary(void)
  82. {
  83. /* nobody is to be released from the pen yet */
  84. pen_release = -1;
  85. /*
  86. * write the address of secondary startup into the backup ram register
  87. * at offset 0x1FF4, then write the magic number 0xA1FEED01 to the
  88. * backup ram register at offset 0x1FF0, which is what boot rom code
  89. * is waiting for. This would wake up the secondary core from WFE
  90. */
  91. #define U8500_CPU1_JUMPADDR_OFFSET 0x1FF4
  92. __raw_writel(virt_to_phys(u8500_secondary_startup),
  93. __io_address(UX500_BACKUPRAM0_BASE) +
  94. U8500_CPU1_JUMPADDR_OFFSET);
  95. #define U8500_CPU1_WAKEMAGIC_OFFSET 0x1FF0
  96. __raw_writel(0xA1FEED01,
  97. __io_address(UX500_BACKUPRAM0_BASE) +
  98. U8500_CPU1_WAKEMAGIC_OFFSET);
  99. /* make sure write buffer is drained */
  100. mb();
  101. }
  102. /*
  103. * Initialise the CPU possible map early - this describes the CPUs
  104. * which may be present or become present in the system.
  105. */
  106. void __init smp_init_cpus(void)
  107. {
  108. unsigned int i, ncores = get_core_count();
  109. for (i = 0; i < ncores; i++)
  110. set_cpu_possible(i, true);
  111. }
  112. void __init smp_prepare_cpus(unsigned int max_cpus)
  113. {
  114. unsigned int ncores = get_core_count();
  115. unsigned int cpu = smp_processor_id();
  116. int i;
  117. /* sanity check */
  118. if (ncores == 0) {
  119. printk(KERN_ERR
  120. "U8500: strange CM count of 0? Default to 1\n");
  121. ncores = 1;
  122. }
  123. if (ncores > num_possible_cpus()) {
  124. printk(KERN_WARNING
  125. "U8500: no. of cores (%d) greater than configured "
  126. "maximum of %d - clipping\n",
  127. ncores, num_possible_cpus());
  128. ncores = num_possible_cpus();
  129. }
  130. smp_store_cpu_info(cpu);
  131. /*
  132. * are we trying to boot more cores than exist?
  133. */
  134. if (max_cpus > ncores)
  135. max_cpus = ncores;
  136. /*
  137. * Initialise the present map, which describes the set of CPUs
  138. * actually populated at the present time.
  139. */
  140. for (i = 0; i < max_cpus; i++)
  141. set_cpu_present(i, true);
  142. if (max_cpus > 1) {
  143. /*
  144. * Enable the local timer or broadcast device for the
  145. * boot CPU, but only if we have more than one CPU.
  146. */
  147. percpu_timer_setup();
  148. scu_enable(__io_address(UX500_SCU_BASE));
  149. wakeup_secondary();
  150. }
  151. }