platsmp.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * plat smp support for CSR Marco dual-core SMP SoCs
  3. *
  4. * Copyright (c) 2012 Cambridge Silicon Radio Limited, a CSR plc group company.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/smp.h>
  10. #include <linux/delay.h>
  11. #include <linux/of.h>
  12. #include <linux/of_address.h>
  13. #include <linux/irqchip/arm-gic.h>
  14. #include <asm/page.h>
  15. #include <asm/mach/map.h>
  16. #include <asm/smp_plat.h>
  17. #include <asm/smp_scu.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/cputype.h>
  20. #include <mach/map.h>
  21. #include "common.h"
  22. static void __iomem *scu_base;
  23. static void __iomem *rsc_base;
  24. static DEFINE_SPINLOCK(boot_lock);
  25. static struct map_desc scu_io_desc __initdata = {
  26. .length = SZ_4K,
  27. .type = MT_DEVICE,
  28. };
  29. void __init sirfsoc_map_scu(void)
  30. {
  31. unsigned long base;
  32. /* Get SCU base */
  33. asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base));
  34. scu_io_desc.virtual = SIRFSOC_VA(base);
  35. scu_io_desc.pfn = __phys_to_pfn(base);
  36. iotable_init(&scu_io_desc, 1);
  37. scu_base = (void __iomem *)SIRFSOC_VA(base);
  38. }
  39. static void __cpuinit sirfsoc_secondary_init(unsigned int cpu)
  40. {
  41. /*
  42. * if any interrupts are already enabled for the primary
  43. * core (e.g. timer irq), then they will not have been enabled
  44. * for us: do so
  45. */
  46. gic_secondary_init(0);
  47. /*
  48. * let the primary processor know we're out of the
  49. * pen, then head off into the C entry point
  50. */
  51. pen_release = -1;
  52. smp_wmb();
  53. /*
  54. * Synchronise with the boot thread.
  55. */
  56. spin_lock(&boot_lock);
  57. spin_unlock(&boot_lock);
  58. }
  59. static struct of_device_id rsc_ids[] = {
  60. { .compatible = "sirf,marco-rsc" },
  61. {},
  62. };
  63. static int __cpuinit sirfsoc_boot_secondary(unsigned int cpu, struct task_struct *idle)
  64. {
  65. unsigned long timeout;
  66. struct device_node *np;
  67. np = of_find_matching_node(NULL, rsc_ids);
  68. if (!np)
  69. return -ENODEV;
  70. rsc_base = of_iomap(np, 0);
  71. if (!rsc_base)
  72. return -ENOMEM;
  73. /*
  74. * write the address of secondary startup into the sram register
  75. * at offset 0x2C, then write the magic number 0x3CAF5D62 to the
  76. * RSC register at offset 0x28, which is what boot rom code is
  77. * waiting for. This would wake up the secondary core from WFE
  78. */
  79. #define SIRFSOC_CPU1_JUMPADDR_OFFSET 0x2C
  80. __raw_writel(virt_to_phys(sirfsoc_secondary_startup),
  81. rsc_base + SIRFSOC_CPU1_JUMPADDR_OFFSET);
  82. #define SIRFSOC_CPU1_WAKEMAGIC_OFFSET 0x28
  83. __raw_writel(0x3CAF5D62,
  84. rsc_base + SIRFSOC_CPU1_WAKEMAGIC_OFFSET);
  85. /* make sure write buffer is drained */
  86. mb();
  87. spin_lock(&boot_lock);
  88. /*
  89. * The secondary processor is waiting to be released from
  90. * the holding pen - release it, then wait for it to flag
  91. * that it has been released by resetting pen_release.
  92. *
  93. * Note that "pen_release" is the hardware CPU ID, whereas
  94. * "cpu" is Linux's internal ID.
  95. */
  96. pen_release = cpu_logical_map(cpu);
  97. __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
  98. outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
  99. /*
  100. * Send the secondary CPU SEV, thereby causing the boot monitor to read
  101. * the JUMPADDR and WAKEMAGIC, and branch to the address found there.
  102. */
  103. dsb_sev();
  104. timeout = jiffies + (1 * HZ);
  105. while (time_before(jiffies, timeout)) {
  106. smp_rmb();
  107. if (pen_release == -1)
  108. break;
  109. udelay(10);
  110. }
  111. /*
  112. * now the secondary core is starting up let it run its
  113. * calibrations, then wait for it to finish
  114. */
  115. spin_unlock(&boot_lock);
  116. return pen_release != -1 ? -ENOSYS : 0;
  117. }
  118. static void __init sirfsoc_smp_prepare_cpus(unsigned int max_cpus)
  119. {
  120. scu_enable(scu_base);
  121. }
  122. struct smp_operations sirfsoc_smp_ops __initdata = {
  123. .smp_prepare_cpus = sirfsoc_smp_prepare_cpus,
  124. .smp_secondary_init = sirfsoc_secondary_init,
  125. .smp_boot_secondary = sirfsoc_boot_secondary,
  126. #ifdef CONFIG_HOTPLUG_CPU
  127. .cpu_die = sirfsoc_cpu_die,
  128. #endif
  129. };