psci.c 3.5 KB

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