platsmp.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #if 0
  31. #define SYS_CPU_CTL 0x208 //1668e
  32. #else
  33. //#define SYS_CPU_CTL 0x2d0 //1668Q
  34. #define SYS_CPU_CTL 0x34 //1668ED
  35. #endif
  36. int ark_cpun_start(u32 address, int cpu)
  37. {
  38. u32 trampoline_code_size = &ark_secondary_trampoline_end -
  39. &ark_secondary_trampoline;
  40. struct device_node *node, *sysnode;
  41. struct resource res;
  42. int ret;
  43. node = of_find_compatible_node(NULL, NULL, "arkmicro,arke-iram");
  44. if (!node) {
  45. pr_err("%s: could not find iram dt node\n", __func__);
  46. return -1;
  47. }
  48. sysnode = of_find_compatible_node(NULL, NULL, "arkmicro,ark-sregs");
  49. if (!sysnode) {
  50. pr_err("%s: could not find sregs dt node\n", __func__);
  51. return -1;
  52. }
  53. ret = of_address_to_resource(node, 0, &res);
  54. if (ret < 0) {
  55. pr_err("%s: could not get address for node %pOF\n",
  56. __func__, node);
  57. return ret;
  58. }
  59. /* MS: Expectation that SLCR are directly map and accessible */
  60. /* Not possible to jump to non aligned address */
  61. if (!(address & 3) && (!address || (address >= trampoline_code_size))) {
  62. /* Store pointer to ioremap area which points to address 0x0 */
  63. static u8 __iomem *iram_base, *sys_base;
  64. u32 val;
  65. u32 trampoline_size = &ark_secondary_trampoline_jump -
  66. &ark_secondary_trampoline;
  67. if (address) {
  68. iram_base = of_iomap(node, 0);
  69. if (!iram_base) {
  70. pr_warn("BOOTUP jump vectors not accessible\n");
  71. return -1;
  72. }
  73. sys_base = of_iomap(sysnode, 0);
  74. if (!sys_base) {
  75. pr_warn("sysreg not accessible\n");
  76. return -1;
  77. }
  78. /*
  79. * This is elegant way how to jump to any address
  80. * 0x0: Load address at 0x8 to r0
  81. * 0x4: Jump by mov instruction
  82. * 0x8: Jumping address
  83. */
  84. memcpy((__force void *)iram_base, &ark_secondary_trampoline,
  85. trampoline_size);
  86. writel(address, iram_base + trampoline_size);
  87. flush_cache_all();
  88. outer_flush_range(res.start, trampoline_code_size);
  89. smp_wmb();
  90. /* start cpun */
  91. val = readl(sys_base + SYS_CPU_CTL);
  92. #if 0
  93. val |= 1 << (6 + cpu);
  94. #else
  95. val |= 1 << (cpu);
  96. #endif
  97. writel(val, sys_base + SYS_CPU_CTL);
  98. //iounmap(iram_base);
  99. //iounmap(sys_base);
  100. }
  101. return 0;
  102. }
  103. pr_warn("Can't start CPU%d: Wrong starting address %x\n", cpu, address);
  104. return -1;
  105. }
  106. EXPORT_SYMBOL(ark_cpun_start);
  107. static int ark_boot_secondary(unsigned int cpu, struct task_struct *idle)
  108. {
  109. return ark_cpun_start(__pa_symbol(secondary_startup), cpu);
  110. }
  111. static void __init ark_smp_prepare_cpus(unsigned int max_cpus)
  112. {
  113. }
  114. const struct smp_operations ark_smp_ops __initconst = {
  115. .smp_prepare_cpus = ark_smp_prepare_cpus,
  116. .smp_boot_secondary = ark_boot_secondary,
  117. };
  118. CPU_METHOD_OF_DECLARE(arke_smp, "arkmicro,arke-smp", &ark_smp_ops);