psci.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Socionext Inc.
  4. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  5. */
  6. #include <common.h>
  7. #include <cpu_func.h>
  8. #include <asm/cache.h>
  9. #include <linux/bitops.h>
  10. #include <linux/delay.h>
  11. #include <linux/io.h>
  12. #include <linux/kernel.h>
  13. #include <linux/printk.h>
  14. #include <linux/psci.h>
  15. #include <linux/sizes.h>
  16. #include <asm/processor.h>
  17. #include <asm/psci.h>
  18. #include <asm/secure.h>
  19. #include "../debug.h"
  20. #include "../soc-info.h"
  21. #include "arm-mpcore.h"
  22. #include "cache-uniphier.h"
  23. #define UNIPHIER_SMPCTRL_ROM_RSV2 0x59801208
  24. void uniphier_smp_trampoline(void);
  25. void uniphier_smp_trampoline_end(void);
  26. u32 uniphier_smp_booted[CONFIG_ARMV7_PSCI_NR_CPUS];
  27. static int uniphier_get_nr_cpus(void)
  28. {
  29. switch (uniphier_get_soc_id()) {
  30. case UNIPHIER_PRO4_ID:
  31. case UNIPHIER_PRO5_ID:
  32. return 2;
  33. case UNIPHIER_PXS2_ID:
  34. case UNIPHIER_LD6B_ID:
  35. return 4;
  36. default:
  37. return 1;
  38. }
  39. }
  40. static void uniphier_smp_kick_all_cpus(void)
  41. {
  42. const u32 target_ways = BIT(0);
  43. size_t trmp_size;
  44. u32 trmp_src = (unsigned long)uniphier_smp_trampoline;
  45. u32 trmp_src_end = (unsigned long)uniphier_smp_trampoline_end;
  46. u32 trmp_dest, trmp_dest_end;
  47. int nr_cpus, i;
  48. int timeout = 1000;
  49. nr_cpus = uniphier_get_nr_cpus();
  50. if (nr_cpus == 1)
  51. return;
  52. for (i = 0; i < nr_cpus; i++) /* lock ways for all CPUs */
  53. uniphier_cache_set_active_ways(i, 0);
  54. uniphier_cache_inv_way(target_ways);
  55. uniphier_cache_enable();
  56. /* copy trampoline code */
  57. uniphier_cache_prefetch_range(trmp_src, trmp_src_end, target_ways);
  58. trmp_size = trmp_src_end - trmp_src;
  59. trmp_dest = trmp_src & (SZ_64K - 1);
  60. trmp_dest += SZ_1M - SZ_64K * 2;
  61. trmp_dest_end = trmp_dest + trmp_size;
  62. uniphier_cache_touch_range(trmp_dest, trmp_dest_end, target_ways);
  63. writel(trmp_dest, UNIPHIER_SMPCTRL_ROM_RSV2);
  64. asm("dsb ishst\n" /* Ensure the write to ROM_RSV2 is visible */
  65. "sev"); /* Bring up all secondary CPUs from Boot ROM into U-Boot */
  66. while (--timeout) {
  67. int all_booted = 1;
  68. for (i = 1; i < nr_cpus; i++)
  69. if (!uniphier_smp_booted[i])
  70. all_booted = 0;
  71. if (all_booted)
  72. break;
  73. udelay(1);
  74. /* barrier here because uniphier_smp_booted[] may be updated */
  75. cpu_relax();
  76. }
  77. if (!timeout)
  78. pr_warn("warning: some of secondary CPUs may not boot\n");
  79. uniphier_cache_disable();
  80. }
  81. void psci_board_init(void)
  82. {
  83. unsigned long scu_base;
  84. u32 scu_ctrl, tmp;
  85. asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (scu_base));
  86. scu_ctrl = readl(scu_base + 0x30);
  87. if (!(scu_ctrl & 1))
  88. writel(scu_ctrl | 0x1, scu_base + 0x30);
  89. scu_ctrl = readl(scu_base + SCU_CTRL);
  90. scu_ctrl |= SCU_ENABLE | SCU_STANDBY_ENABLE;
  91. writel(scu_ctrl, scu_base + SCU_CTRL);
  92. tmp = readl(scu_base + SCU_SNSAC);
  93. tmp |= 0xfff;
  94. writel(tmp, scu_base + SCU_SNSAC);
  95. uniphier_smp_kick_all_cpus();
  96. }
  97. void psci_arch_init(void)
  98. {
  99. u32 actlr;
  100. asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr));
  101. actlr |= 0x41; /* set SMP and FW bits */
  102. asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr));
  103. }
  104. u32 uniphier_psci_holding_pen_release __secure_data = 0xffffffff;
  105. s32 __secure psci_cpu_on(u32 function_id, u32 cpuid, u32 entry_point,
  106. u32 context_id)
  107. {
  108. u32 cpu = cpuid & 0xff;
  109. debug_puts("[U-Boot PSCI] psci_cpu_on: cpuid=");
  110. debug_puth(cpuid);
  111. debug_puts(", entry_point=");
  112. debug_puth(entry_point);
  113. debug_puts(", context_id=");
  114. debug_puth(context_id);
  115. debug_puts("\n");
  116. psci_save(cpu, entry_point, context_id);
  117. /* We assume D-cache is off, so do not call flush_dcache() here */
  118. uniphier_psci_holding_pen_release = cpu;
  119. /* Send an event to wake up the secondary CPU. */
  120. asm("dsb ishst\n"
  121. "sev");
  122. return PSCI_RET_SUCCESS;
  123. }
  124. void __secure psci_system_reset(void)
  125. {
  126. reset_cpu(0);
  127. }