platsmp.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2013 Linaro Ltd.
  4. * Copyright (c) 2013 HiSilicon Limited.
  5. * Based on arch/arm/mach-vexpress/platsmp.c, Copyright (C) 2002 ARM Ltd.
  6. */
  7. #include <linux/smp.h>
  8. #include <linux/io.h>
  9. #include <linux/of_address.h>
  10. #include <linux/delay.h>
  11. #include <asm/cacheflush.h>
  12. #include <asm/smp_plat.h>
  13. #include <asm/smp_scu.h>
  14. #include <asm/mach/map.h>
  15. #include "core.h"
  16. #define HIX5HD2_BOOT_ADDRESS 0xffff0000
  17. static void __iomem *ctrl_base;
  18. void hi3xxx_set_cpu_jump(int cpu, void *jump_addr)
  19. {
  20. cpu = cpu_logical_map(cpu);
  21. if (!cpu || !ctrl_base)
  22. return;
  23. writel_relaxed(__pa_symbol(jump_addr), ctrl_base + ((cpu - 1) << 2));
  24. }
  25. int hi3xxx_get_cpu_jump(int cpu)
  26. {
  27. cpu = cpu_logical_map(cpu);
  28. if (!cpu || !ctrl_base)
  29. return 0;
  30. return readl_relaxed(ctrl_base + ((cpu - 1) << 2));
  31. }
  32. static void __init hisi_enable_scu_a9(void)
  33. {
  34. unsigned long base = 0;
  35. void __iomem *scu_base = NULL;
  36. if (scu_a9_has_base()) {
  37. base = scu_a9_get_base();
  38. scu_base = ioremap(base, SZ_4K);
  39. if (!scu_base) {
  40. pr_err("ioremap(scu_base) failed\n");
  41. return;
  42. }
  43. scu_enable(scu_base);
  44. iounmap(scu_base);
  45. }
  46. }
  47. static void __init hi3xxx_smp_prepare_cpus(unsigned int max_cpus)
  48. {
  49. struct device_node *np = NULL;
  50. u32 offset = 0;
  51. hisi_enable_scu_a9();
  52. if (!ctrl_base) {
  53. np = of_find_compatible_node(NULL, NULL, "hisilicon,sysctrl");
  54. if (!np) {
  55. pr_err("failed to find hisilicon,sysctrl node\n");
  56. return;
  57. }
  58. ctrl_base = of_iomap(np, 0);
  59. if (!ctrl_base) {
  60. of_node_put(np);
  61. pr_err("failed to map address\n");
  62. return;
  63. }
  64. if (of_property_read_u32(np, "smp-offset", &offset) < 0) {
  65. of_node_put(np);
  66. pr_err("failed to find smp-offset property\n");
  67. return;
  68. }
  69. ctrl_base += offset;
  70. of_node_put(np);
  71. }
  72. }
  73. static int hi3xxx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  74. {
  75. hi3xxx_set_cpu(cpu, true);
  76. hi3xxx_set_cpu_jump(cpu, secondary_startup);
  77. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  78. return 0;
  79. }
  80. static const struct smp_operations hi3xxx_smp_ops __initconst = {
  81. .smp_prepare_cpus = hi3xxx_smp_prepare_cpus,
  82. .smp_boot_secondary = hi3xxx_boot_secondary,
  83. #ifdef CONFIG_HOTPLUG_CPU
  84. .cpu_die = hi3xxx_cpu_die,
  85. .cpu_kill = hi3xxx_cpu_kill,
  86. #endif
  87. };
  88. static void __init hisi_common_smp_prepare_cpus(unsigned int max_cpus)
  89. {
  90. hisi_enable_scu_a9();
  91. }
  92. static void hix5hd2_set_scu_boot_addr(phys_addr_t start_addr, phys_addr_t jump_addr)
  93. {
  94. void __iomem *virt;
  95. virt = ioremap(start_addr, PAGE_SIZE);
  96. writel_relaxed(0xe51ff004, virt); /* ldr pc, [pc, #-4] */
  97. writel_relaxed(jump_addr, virt + 4); /* pc jump phy address */
  98. iounmap(virt);
  99. }
  100. static int hix5hd2_boot_secondary(unsigned int cpu, struct task_struct *idle)
  101. {
  102. phys_addr_t jumpaddr;
  103. jumpaddr = __pa_symbol(secondary_startup);
  104. hix5hd2_set_scu_boot_addr(HIX5HD2_BOOT_ADDRESS, jumpaddr);
  105. hix5hd2_set_cpu(cpu, true);
  106. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  107. return 0;
  108. }
  109. static const struct smp_operations hix5hd2_smp_ops __initconst = {
  110. .smp_prepare_cpus = hisi_common_smp_prepare_cpus,
  111. .smp_boot_secondary = hix5hd2_boot_secondary,
  112. #ifdef CONFIG_HOTPLUG_CPU
  113. .cpu_die = hix5hd2_cpu_die,
  114. #endif
  115. };
  116. #define SC_SCTL_REMAP_CLR 0x00000100
  117. #define HIP01_BOOT_ADDRESS 0x80000000
  118. #define REG_SC_CTRL 0x000
  119. static void hip01_set_boot_addr(phys_addr_t start_addr, phys_addr_t jump_addr)
  120. {
  121. void __iomem *virt;
  122. virt = phys_to_virt(start_addr);
  123. writel_relaxed(0xe51ff004, virt);
  124. writel_relaxed(jump_addr, virt + 4);
  125. }
  126. static int hip01_boot_secondary(unsigned int cpu, struct task_struct *idle)
  127. {
  128. phys_addr_t jumpaddr;
  129. unsigned int remap_reg_value = 0;
  130. struct device_node *node;
  131. jumpaddr = __pa_symbol(secondary_startup);
  132. hip01_set_boot_addr(HIP01_BOOT_ADDRESS, jumpaddr);
  133. node = of_find_compatible_node(NULL, NULL, "hisilicon,hip01-sysctrl");
  134. if (WARN_ON(!node))
  135. return -1;
  136. ctrl_base = of_iomap(node, 0);
  137. of_node_put(node);
  138. /* set the secondary core boot from DDR */
  139. remap_reg_value = readl_relaxed(ctrl_base + REG_SC_CTRL);
  140. barrier();
  141. remap_reg_value |= SC_SCTL_REMAP_CLR;
  142. barrier();
  143. writel_relaxed(remap_reg_value, ctrl_base + REG_SC_CTRL);
  144. hip01_set_cpu(cpu, true);
  145. return 0;
  146. }
  147. static const struct smp_operations hip01_smp_ops __initconst = {
  148. .smp_prepare_cpus = hisi_common_smp_prepare_cpus,
  149. .smp_boot_secondary = hip01_boot_secondary,
  150. };
  151. CPU_METHOD_OF_DECLARE(hi3xxx_smp, "hisilicon,hi3620-smp", &hi3xxx_smp_ops);
  152. CPU_METHOD_OF_DECLARE(hix5hd2_smp, "hisilicon,hix5hd2-smp", &hix5hd2_smp_ops);
  153. CPU_METHOD_OF_DECLARE(hip01_smp, "hisilicon,hip01-smp", &hip01_smp_ops);