platsmp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <asm/cacheflush.h>
  14. #include <asm/smp_plat.h>
  15. #include <asm/smp_scu.h>
  16. #include "core.h"
  17. #define HIX5HD2_BOOT_ADDRESS 0xffff0000
  18. static void __iomem *ctrl_base;
  19. void hi3xxx_set_cpu_jump(int cpu, void *jump_addr)
  20. {
  21. cpu = cpu_logical_map(cpu);
  22. if (!cpu || !ctrl_base)
  23. return;
  24. writel_relaxed(virt_to_phys(jump_addr), ctrl_base + ((cpu - 1) << 2));
  25. }
  26. int hi3xxx_get_cpu_jump(int cpu)
  27. {
  28. cpu = cpu_logical_map(cpu);
  29. if (!cpu || !ctrl_base)
  30. return 0;
  31. return readl_relaxed(ctrl_base + ((cpu - 1) << 2));
  32. }
  33. static void __init hisi_enable_scu_a9(void)
  34. {
  35. unsigned long base = 0;
  36. void __iomem *scu_base = NULL;
  37. if (scu_a9_has_base()) {
  38. base = scu_a9_get_base();
  39. scu_base = ioremap(base, SZ_4K);
  40. if (!scu_base) {
  41. pr_err("ioremap(scu_base) failed\n");
  42. return;
  43. }
  44. scu_enable(scu_base);
  45. iounmap(scu_base);
  46. }
  47. }
  48. static void __init hi3xxx_smp_prepare_cpus(unsigned int max_cpus)
  49. {
  50. struct device_node *np = NULL;
  51. u32 offset = 0;
  52. hisi_enable_scu_a9();
  53. if (!ctrl_base) {
  54. np = of_find_compatible_node(NULL, NULL, "hisilicon,sysctrl");
  55. if (!np) {
  56. pr_err("failed to find hisilicon,sysctrl node\n");
  57. return;
  58. }
  59. ctrl_base = of_iomap(np, 0);
  60. if (!ctrl_base) {
  61. pr_err("failed to map address\n");
  62. return;
  63. }
  64. if (of_property_read_u32(np, "smp-offset", &offset) < 0) {
  65. pr_err("failed to find smp-offset property\n");
  66. return;
  67. }
  68. ctrl_base += offset;
  69. }
  70. }
  71. static int hi3xxx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  72. {
  73. hi3xxx_set_cpu(cpu, true);
  74. hi3xxx_set_cpu_jump(cpu, secondary_startup);
  75. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  76. return 0;
  77. }
  78. struct smp_operations hi3xxx_smp_ops __initdata = {
  79. .smp_prepare_cpus = hi3xxx_smp_prepare_cpus,
  80. .smp_boot_secondary = hi3xxx_boot_secondary,
  81. #ifdef CONFIG_HOTPLUG_CPU
  82. .cpu_die = hi3xxx_cpu_die,
  83. .cpu_kill = hi3xxx_cpu_kill,
  84. #endif
  85. };
  86. static void __init hix5hd2_smp_prepare_cpus(unsigned int max_cpus)
  87. {
  88. hisi_enable_scu_a9();
  89. }
  90. void hix5hd2_set_scu_boot_addr(phys_addr_t start_addr, phys_addr_t jump_addr)
  91. {
  92. void __iomem *virt;
  93. virt = ioremap(start_addr, PAGE_SIZE);
  94. writel_relaxed(0xe51ff004, virt); /* ldr pc, [rc, #-4] */
  95. writel_relaxed(jump_addr, virt + 4); /* pc jump phy address */
  96. iounmap(virt);
  97. }
  98. static int hix5hd2_boot_secondary(unsigned int cpu, struct task_struct *idle)
  99. {
  100. phys_addr_t jumpaddr;
  101. jumpaddr = virt_to_phys(hix5hd2_secondary_startup);
  102. hix5hd2_set_scu_boot_addr(HIX5HD2_BOOT_ADDRESS, jumpaddr);
  103. hix5hd2_set_cpu(cpu, true);
  104. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  105. return 0;
  106. }
  107. struct smp_operations hix5hd2_smp_ops __initdata = {
  108. .smp_prepare_cpus = hix5hd2_smp_prepare_cpus,
  109. .smp_boot_secondary = hix5hd2_boot_secondary,
  110. #ifdef CONFIG_HOTPLUG_CPU
  111. .cpu_die = hix5hd2_cpu_die,
  112. #endif
  113. };
  114. CPU_METHOD_OF_DECLARE(hi3xxx_smp, "hisilicon,hi3620-smp", &hi3xxx_smp_ops);
  115. CPU_METHOD_OF_DECLARE(hix5hd2_smp, "hisilicon,hix5hd2-smp", &hix5hd2_smp_ops);