platsmp.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * This file contains Xilinx specific SMP code, used to start up
  3. * the second processor.
  4. *
  5. * Copyright (C) 2011-2013 Xilinx
  6. *
  7. * based on linux/arch/arm/mach-realview/platsmp.c
  8. *
  9. * Copyright (C) 2002 ARM Ltd.
  10. *
  11. * This software is licensed under the terms of the GNU General Public
  12. * License version 2, as published by the Free Software Foundation, and
  13. * may be copied, distributed, and modified under those terms.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. */
  20. #include <linux/export.h>
  21. #include <linux/jiffies.h>
  22. #include <linux/init.h>
  23. #include <linux/io.h>
  24. #include <linux/of.h>
  25. #include <linux/of_address.h>
  26. #include <asm/cacheflush.h>
  27. #include <linux/irqchip/arm-gic.h>
  28. #include <linux/delay.h>
  29. #include "common.h"
  30. #define SYS_CPU_CTL 0x208
  31. int ark_cpun_start(u32 address, int cpu)
  32. {
  33. u32 trampoline_code_size = &ark_secondary_trampoline_end -
  34. &ark_secondary_trampoline;
  35. struct device_node *node, *sysnode;
  36. struct resource res;
  37. int ret;
  38. node = of_find_compatible_node(NULL, NULL, "arkmicro,arke-iram");
  39. if (!node) {
  40. pr_err("%s: could not find iram dt node\n", __func__);
  41. return -1;
  42. }
  43. sysnode = of_find_compatible_node(NULL, NULL, "arkmicro,ark-sregs");
  44. if (!sysnode) {
  45. pr_err("%s: could not find sregs dt node\n", __func__);
  46. return -1;
  47. }
  48. ret = of_address_to_resource(node, 0, &res);
  49. if (ret < 0) {
  50. pr_err("%s: could not get address for node %pOF\n",
  51. __func__, node);
  52. return ret;
  53. }
  54. /* MS: Expectation that SLCR are directly map and accessible */
  55. /* Not possible to jump to non aligned address */
  56. if (!(address & 3) && (!address || (address >= trampoline_code_size))) {
  57. /* Store pointer to ioremap area which points to address 0x0 */
  58. static u8 __iomem *iram_base, *sys_base;
  59. u32 val;
  60. u32 trampoline_size = &ark_secondary_trampoline_jump -
  61. &ark_secondary_trampoline;
  62. if (address) {
  63. iram_base = of_iomap(node, 0);
  64. if (!iram_base) {
  65. pr_warn("BOOTUP jump vectors not accessible\n");
  66. return -1;
  67. }
  68. sys_base = of_iomap(sysnode, 0);
  69. if (!sys_base) {
  70. pr_warn("sysreg not accessible\n");
  71. return -1;
  72. }
  73. /*
  74. * This is elegant way how to jump to any address
  75. * 0x0: Load address at 0x8 to r0
  76. * 0x4: Jump by mov instruction
  77. * 0x8: Jumping address
  78. */
  79. memcpy((__force void *)iram_base, &ark_secondary_trampoline,
  80. trampoline_size);
  81. writel(address, iram_base + trampoline_size);
  82. flush_cache_all();
  83. outer_flush_range(res.start, trampoline_code_size);
  84. smp_wmb();
  85. /* start cpun */
  86. val = readl(sys_base + SYS_CPU_CTL);
  87. val |= 1 << (6 + cpu);
  88. writel(val, sys_base + SYS_CPU_CTL);
  89. //iounmap(iram_base);
  90. //iounmap(sys_base);
  91. }
  92. return 0;
  93. }
  94. pr_warn("Can't start CPU%d: Wrong starting address %x\n", cpu, address);
  95. return -1;
  96. }
  97. EXPORT_SYMBOL(ark_cpun_start);
  98. static int ark_boot_secondary(unsigned int cpu, struct task_struct *idle)
  99. {
  100. return ark_cpun_start(__pa_symbol(secondary_startup), cpu);
  101. }
  102. static void __init ark_smp_prepare_cpus(unsigned int max_cpus)
  103. {
  104. }
  105. const struct smp_operations ark_smp_ops __initconst = {
  106. .smp_prepare_cpus = ark_smp_prepare_cpus,
  107. .smp_boot_secondary = ark_boot_secondary,
  108. };
  109. CPU_METHOD_OF_DECLARE(arke_smp, "arkmicro,arke-smp", &ark_smp_ops);