platsmp.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2013 Linaro Ltd.
  3. * Copyright (c) 2013 Hisilicon Limited.
  4. * Based on arch/arm/mach-vexpress/platsmp.c, Copyright (C) 2002 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. */
  10. #include <linux/smp.h>
  11. #include <linux/io.h>
  12. #include <linux/of_address.h>
  13. #include <linux/delay.h>
  14. #include <asm/cacheflush.h>
  15. #include <asm/smp_plat.h>
  16. #include <asm/smp_scu.h>
  17. #include <asm/mach/map.h>
  18. #include "core.h"
  19. #define HIX5HD2_BOOT_ADDRESS 0xffff0000
  20. static void __iomem *ctrl_base;
  21. void hi3xxx_set_cpu_jump(int cpu, void *jump_addr)
  22. {
  23. cpu = cpu_logical_map(cpu);
  24. if (!cpu || !ctrl_base)
  25. return;
  26. writel_relaxed(virt_to_phys(jump_addr), ctrl_base + ((cpu - 1) << 2));
  27. }
  28. int hi3xxx_get_cpu_jump(int cpu)
  29. {
  30. cpu = cpu_logical_map(cpu);
  31. if (!cpu || !ctrl_base)
  32. return 0;
  33. return readl_relaxed(ctrl_base + ((cpu - 1) << 2));
  34. }
  35. static void __init hisi_enable_scu_a9(void)
  36. {
  37. unsigned long base = 0;
  38. void __iomem *scu_base = NULL;
  39. if (scu_a9_has_base()) {
  40. base = scu_a9_get_base();
  41. scu_base = ioremap(base, SZ_4K);
  42. if (!scu_base) {
  43. pr_err("ioremap(scu_base) failed\n");
  44. return;
  45. }
  46. scu_enable(scu_base);
  47. iounmap(scu_base);
  48. }
  49. }
  50. static void __init hi3xxx_smp_prepare_cpus(unsigned int max_cpus)
  51. {
  52. struct device_node *np = NULL;
  53. u32 offset = 0;
  54. hisi_enable_scu_a9();
  55. if (!ctrl_base) {
  56. np = of_find_compatible_node(NULL, NULL, "hisilicon,sysctrl");
  57. if (!np) {
  58. pr_err("failed to find hisilicon,sysctrl node\n");
  59. return;
  60. }
  61. ctrl_base = of_iomap(np, 0);
  62. if (!ctrl_base) {
  63. pr_err("failed to map address\n");
  64. return;
  65. }
  66. if (of_property_read_u32(np, "smp-offset", &offset) < 0) {
  67. pr_err("failed to find smp-offset property\n");
  68. return;
  69. }
  70. ctrl_base += offset;
  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, [rc, #-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 = virt_to_phys(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 = virt_to_phys(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. /* set the secondary core boot from DDR */
  138. remap_reg_value = readl_relaxed(ctrl_base + REG_SC_CTRL);
  139. barrier();
  140. remap_reg_value |= SC_SCTL_REMAP_CLR;
  141. barrier();
  142. writel_relaxed(remap_reg_value, ctrl_base + REG_SC_CTRL);
  143. hip01_set_cpu(cpu, true);
  144. return 0;
  145. }
  146. static const struct smp_operations hip01_smp_ops __initconst = {
  147. .smp_prepare_cpus = hisi_common_smp_prepare_cpus,
  148. .smp_boot_secondary = hip01_boot_secondary,
  149. };
  150. CPU_METHOD_OF_DECLARE(hi3xxx_smp, "hisilicon,hi3620-smp", &hi3xxx_smp_ops);
  151. CPU_METHOD_OF_DECLARE(hix5hd2_smp, "hisilicon,hix5hd2-smp", &hix5hd2_smp_ops);
  152. CPU_METHOD_OF_DECLARE(hip01_smp, "hisilicon,hip01-smp", &hip01_smp_ops);