platsmp.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright 2014 Linaro Ltd.
  3. * Copyright (C) 2014 ZTE Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/delay.h>
  10. #include <linux/errno.h>
  11. #include <linux/init.h>
  12. #include <linux/io.h>
  13. #include <linux/jiffies.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/smp.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/cp15.h>
  19. #include <asm/fncpy.h>
  20. #include <asm/proc-fns.h>
  21. #include <asm/smp_scu.h>
  22. #include <asm/smp_plat.h>
  23. #include "core.h"
  24. #define AON_SYS_CTRL_RESERVED1 0xa8
  25. #define BUS_MATRIX_REMAP_CONFIG 0x00
  26. #define PCU_CPU0_CTRL 0x00
  27. #define PCU_CPU1_CTRL 0x04
  28. #define PCU_CPU1_ST 0x0c
  29. #define PCU_GLOBAL_CTRL 0x14
  30. #define PCU_EXPEND_CONTROL 0x34
  31. #define ZX_IRAM_BASE 0x00200000
  32. static void __iomem *pcu_base;
  33. static void __iomem *matrix_base;
  34. static void __iomem *scu_base;
  35. void __init zx_smp_prepare_cpus(unsigned int max_cpus)
  36. {
  37. struct device_node *np;
  38. unsigned long base = 0;
  39. void __iomem *aonsysctrl_base;
  40. void __iomem *sys_iram;
  41. base = scu_a9_get_base();
  42. scu_base = ioremap(base, SZ_256);
  43. if (!scu_base) {
  44. pr_err("%s: failed to map scu\n", __func__);
  45. return;
  46. }
  47. scu_enable(scu_base);
  48. np = of_find_compatible_node(NULL, NULL, "zte,sysctrl");
  49. if (!np) {
  50. pr_err("%s: failed to find sysctrl node\n", __func__);
  51. return;
  52. }
  53. aonsysctrl_base = of_iomap(np, 0);
  54. if (!aonsysctrl_base) {
  55. pr_err("%s: failed to map aonsysctrl\n", __func__);
  56. of_node_put(np);
  57. return;
  58. }
  59. /*
  60. * Write the address of secondary startup into the
  61. * system-wide flags register. The BootMonitor waits
  62. * until it receives a soft interrupt, and then the
  63. * secondary CPU branches to this address.
  64. */
  65. __raw_writel(virt_to_phys(zx_secondary_startup),
  66. aonsysctrl_base + AON_SYS_CTRL_RESERVED1);
  67. iounmap(aonsysctrl_base);
  68. of_node_put(np);
  69. np = of_find_compatible_node(NULL, NULL, "zte,zx296702-pcu");
  70. pcu_base = of_iomap(np, 0);
  71. of_node_put(np);
  72. WARN_ON(!pcu_base);
  73. np = of_find_compatible_node(NULL, NULL, "zte,zx-bus-matrix");
  74. matrix_base = of_iomap(np, 0);
  75. of_node_put(np);
  76. WARN_ON(!matrix_base);
  77. /* Map the first 4 KB IRAM for suspend usage */
  78. sys_iram = __arm_ioremap_exec(ZX_IRAM_BASE, PAGE_SIZE, false);
  79. zx_secondary_startup_pa = virt_to_phys(zx_secondary_startup);
  80. fncpy(sys_iram, &zx_resume_jump, zx_suspend_iram_sz);
  81. }
  82. static int zx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  83. {
  84. static bool first_boot = true;
  85. if (first_boot) {
  86. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  87. first_boot = false;
  88. return 0;
  89. }
  90. /* Swap the base address mapping between IRAM and IROM */
  91. writel_relaxed(0x1, matrix_base + BUS_MATRIX_REMAP_CONFIG);
  92. /* Power on CPU1 */
  93. writel_relaxed(0x0, pcu_base + PCU_CPU1_CTRL);
  94. /* Wait for power on ack */
  95. while (readl_relaxed(pcu_base + PCU_CPU1_ST) & 0x4)
  96. cpu_relax();
  97. /* Swap back the mapping of IRAM and IROM */
  98. writel_relaxed(0x0, matrix_base + BUS_MATRIX_REMAP_CONFIG);
  99. return 0;
  100. }
  101. #ifdef CONFIG_HOTPLUG_CPU
  102. static inline void cpu_enter_lowpower(void)
  103. {
  104. unsigned int v;
  105. asm volatile(
  106. "mcr p15, 0, %1, c7, c5, 0\n"
  107. " mcr p15, 0, %1, c7, c10, 4\n"
  108. /*
  109. * Turn off coherency
  110. */
  111. " mrc p15, 0, %0, c1, c0, 1\n"
  112. " bic %0, %0, %3\n"
  113. " mcr p15, 0, %0, c1, c0, 1\n"
  114. " mrc p15, 0, %0, c1, c0, 0\n"
  115. " bic %0, %0, %2\n"
  116. " mcr p15, 0, %0, c1, c0, 0\n"
  117. : "=&r" (v)
  118. : "r" (0), "Ir" (CR_C), "Ir" (0x40)
  119. : "cc");
  120. }
  121. static int zx_cpu_kill(unsigned int cpu)
  122. {
  123. unsigned long timeout = jiffies + msecs_to_jiffies(2000);
  124. writel_relaxed(0x2, pcu_base + PCU_CPU1_CTRL);
  125. while ((readl_relaxed(pcu_base + PCU_CPU1_ST) & 0x3) != 0x0) {
  126. if (time_after(jiffies, timeout)) {
  127. pr_err("*** cpu1 poweroff timeout\n");
  128. break;
  129. }
  130. }
  131. return 1;
  132. }
  133. static void zx_cpu_die(unsigned int cpu)
  134. {
  135. scu_power_mode(scu_base, SCU_PM_POWEROFF);
  136. cpu_enter_lowpower();
  137. while (1)
  138. cpu_do_idle();
  139. }
  140. #endif
  141. static void zx_secondary_init(unsigned int cpu)
  142. {
  143. scu_power_mode(scu_base, SCU_PM_NORMAL);
  144. }
  145. static const struct smp_operations zx_smp_ops __initconst = {
  146. .smp_prepare_cpus = zx_smp_prepare_cpus,
  147. .smp_secondary_init = zx_secondary_init,
  148. .smp_boot_secondary = zx_boot_secondary,
  149. #ifdef CONFIG_HOTPLUG_CPU
  150. .cpu_kill = zx_cpu_kill,
  151. .cpu_die = zx_cpu_die,
  152. #endif
  153. };
  154. CPU_METHOD_OF_DECLARE(zx_smp, "zte,zx296702-smp", &zx_smp_ops);