platsmp.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <asm/page.h>
  14. #include <asm/mach/map.h>
  15. #include <asm/smp_plat.h>
  16. #include <asm/smp_scu.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/cputype.h>
  19. #include "common.h"
  20. static void __iomem *clk_base;
  21. static DEFINE_SPINLOCK(boot_lock);
  22. static void sirfsoc_secondary_init(unsigned int cpu)
  23. {
  24. /*
  25. * let the primary processor know we're out of the
  26. * pen, then head off into the C entry point
  27. */
  28. pen_release = -1;
  29. smp_wmb();
  30. /*
  31. * Synchronise with the boot thread.
  32. */
  33. spin_lock(&boot_lock);
  34. spin_unlock(&boot_lock);
  35. }
  36. static const struct of_device_id clk_ids[] = {
  37. { .compatible = "sirf,atlas7-clkc" },
  38. {},
  39. };
  40. static int sirfsoc_boot_secondary(unsigned int cpu, struct task_struct *idle)
  41. {
  42. unsigned long timeout;
  43. struct device_node *np;
  44. np = of_find_matching_node(NULL, clk_ids);
  45. if (!np)
  46. return -ENODEV;
  47. clk_base = of_iomap(np, 0);
  48. if (!clk_base)
  49. return -ENOMEM;
  50. /*
  51. * write the address of secondary startup into the clkc register
  52. * at offset 0x2bC, then write the magic number 0x3CAF5D62 to the
  53. * clkc register at offset 0x2b8, which is what boot rom code is
  54. * waiting for. This would wake up the secondary core from WFE
  55. */
  56. #define SIRFSOC_CPU1_JUMPADDR_OFFSET 0x2bc
  57. __raw_writel(__pa_symbol(sirfsoc_secondary_startup),
  58. clk_base + SIRFSOC_CPU1_JUMPADDR_OFFSET);
  59. #define SIRFSOC_CPU1_WAKEMAGIC_OFFSET 0x2b8
  60. __raw_writel(0x3CAF5D62,
  61. clk_base + SIRFSOC_CPU1_WAKEMAGIC_OFFSET);
  62. /* make sure write buffer is drained */
  63. mb();
  64. spin_lock(&boot_lock);
  65. /*
  66. * The secondary processor is waiting to be released from
  67. * the holding pen - release it, then wait for it to flag
  68. * that it has been released by resetting pen_release.
  69. *
  70. * Note that "pen_release" is the hardware CPU ID, whereas
  71. * "cpu" is Linux's internal ID.
  72. */
  73. pen_release = cpu_logical_map(cpu);
  74. sync_cache_w(&pen_release);
  75. /*
  76. * Send the secondary CPU SEV, thereby causing the boot monitor to read
  77. * the JUMPADDR and WAKEMAGIC, and branch to the address found there.
  78. */
  79. dsb_sev();
  80. timeout = jiffies + (1 * HZ);
  81. while (time_before(jiffies, timeout)) {
  82. smp_rmb();
  83. if (pen_release == -1)
  84. break;
  85. udelay(10);
  86. }
  87. /*
  88. * now the secondary core is starting up let it run its
  89. * calibrations, then wait for it to finish
  90. */
  91. spin_unlock(&boot_lock);
  92. return pen_release != -1 ? -ENOSYS : 0;
  93. }
  94. const struct smp_operations sirfsoc_smp_ops __initconst = {
  95. .smp_secondary_init = sirfsoc_secondary_init,
  96. .smp_boot_secondary = sirfsoc_boot_secondary,
  97. #ifdef CONFIG_HOTPLUG_CPU
  98. .cpu_die = sirfsoc_cpu_die,
  99. #endif
  100. };