2 * Copyright (C) 2016 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <linux/bitops.h>
11 #include <linux/kernel.h>
12 #include <linux/psci.h>
13 #include <linux/sizes.h>
14 #include <asm/processor.h>
16 #include <asm/secure.h>
19 #include "../soc-info.h"
20 #include "arm-mpcore.h"
21 #include "cache-uniphier.h"
23 #define UNIPHIER_SMPCTRL_ROM_RSV2 0x59801208
25 void uniphier_smp_trampoline(void);
26 void uniphier_smp_trampoline_end(void);
27 u32 uniphier_smp_booted[CONFIG_ARMV7_PSCI_NR_CPUS];
29 static int uniphier_get_nr_cpus(void)
31 switch (uniphier_get_soc_type()) {
32 case SOC_UNIPHIER_SLD3:
33 case SOC_UNIPHIER_PRO4:
34 case SOC_UNIPHIER_PRO5:
36 case SOC_UNIPHIER_PXS2:
37 case SOC_UNIPHIER_LD6B:
44 static void uniphier_smp_kick_all_cpus(void)
46 const u32 target_ways = BIT(0);
48 u32 trmp_src = (unsigned long)uniphier_smp_trampoline;
49 u32 trmp_src_end = (unsigned long)uniphier_smp_trampoline_end;
50 u32 trmp_dest, trmp_dest_end;
54 nr_cpus = uniphier_get_nr_cpus();
58 for (i = 0; i < nr_cpus; i++) /* lock ways for all CPUs */
59 uniphier_cache_set_active_ways(i, 0);
60 uniphier_cache_inv_way(target_ways);
61 uniphier_cache_enable();
63 /* copy trampoline code */
64 uniphier_cache_prefetch_range(trmp_src, trmp_src_end, target_ways);
66 trmp_size = trmp_src_end - trmp_src;
68 trmp_dest = trmp_src & (SZ_64K - 1);
69 trmp_dest += SZ_1M - SZ_64K * 2;
71 trmp_dest_end = trmp_dest + trmp_size;
73 uniphier_cache_touch_range(trmp_dest, trmp_dest_end, target_ways);
75 writel(trmp_dest, UNIPHIER_SMPCTRL_ROM_RSV2);
77 asm("dsb ishst\n" /* Ensure the write to ROM_RSV2 is visible */
78 "sev"); /* Bring up all secondary CPUs from Boot ROM into U-Boot */
83 for (i = 1; i < nr_cpus; i++)
84 if (!uniphier_smp_booted[i])
90 /* barrier here because uniphier_smp_booted[] may be updated */
95 printf("warning: some of secondary CPUs may not boot\n");
97 uniphier_cache_disable();
100 void psci_board_init(void)
102 unsigned long scu_base;
105 asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (scu_base));
107 scu_ctrl = readl(scu_base + 0x30);
109 writel(scu_ctrl | 0x1, scu_base + 0x30);
111 scu_ctrl = readl(scu_base + SCU_CTRL);
112 scu_ctrl |= SCU_ENABLE | SCU_STANDBY_ENABLE;
113 writel(scu_ctrl, scu_base + SCU_CTRL);
115 tmp = readl(scu_base + SCU_SNSAC);
117 writel(tmp, scu_base + SCU_SNSAC);
119 uniphier_smp_kick_all_cpus();
122 void psci_arch_init(void)
126 asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr));
127 actlr |= 0x41; /* set SMP and FW bits */
128 asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr));
131 u32 uniphier_psci_holding_pen_release __secure_data = 0xffffffff;
133 int __secure psci_cpu_on(u32 function_id, u32 cpuid, u32 entry_point)
135 u32 cpu = cpuid & 0xff;
137 debug_puts("[U-Boot PSCI] psci_cpu_on: cpuid=");
139 debug_puts(", entry_point=");
140 debug_puth(entry_point);
143 psci_save_target_pc(cpu, entry_point);
145 /* We assume D-cache is off, so do not call flush_dcache() here */
146 uniphier_psci_holding_pen_release = cpu;
148 /* Send an event to wake up the secondary CPU. */
152 return PSCI_RET_SUCCESS;