blob: e231e7b60b838a07a359ff6d9c1ed8aebda03835 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamadae8a92932016-08-10 16:08:49 +09002/*
3 * Copyright (C) 2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadae8a92932016-08-10 16:08:49 +09005 */
6
7#include <common.h>
Simon Glass62270f42019-11-14 12:57:35 -07008#include <cpu_func.h>
Simon Glass90526e92020-05-10 11:39:56 -06009#include <asm/cache.h>
Masahiro Yamadae8a92932016-08-10 16:08:49 +090010#include <linux/bitops.h>
Masahiro Yamadadd74b942017-10-13 19:21:55 +090011#include <linux/delay.h>
Masahiro Yamadae8a92932016-08-10 16:08:49 +090012#include <linux/io.h>
13#include <linux/kernel.h>
Masahiro Yamadadd74b942017-10-13 19:21:55 +090014#include <linux/printk.h>
Masahiro Yamadae8a92932016-08-10 16:08:49 +090015#include <linux/psci.h>
16#include <linux/sizes.h>
17#include <asm/processor.h>
18#include <asm/psci.h>
19#include <asm/secure.h>
20
21#include "../debug.h"
22#include "../soc-info.h"
23#include "arm-mpcore.h"
24#include "cache-uniphier.h"
25
26#define UNIPHIER_SMPCTRL_ROM_RSV2 0x59801208
27
28void uniphier_smp_trampoline(void);
29void uniphier_smp_trampoline_end(void);
30u32 uniphier_smp_booted[CONFIG_ARMV7_PSCI_NR_CPUS];
31
32static int uniphier_get_nr_cpus(void)
33{
Masahiro Yamadae27d6c72017-01-21 18:05:26 +090034 switch (uniphier_get_soc_id()) {
Masahiro Yamadae27d6c72017-01-21 18:05:26 +090035 case UNIPHIER_PRO4_ID:
36 case UNIPHIER_PRO5_ID:
Masahiro Yamadae8a92932016-08-10 16:08:49 +090037 return 2;
Masahiro Yamadae27d6c72017-01-21 18:05:26 +090038 case UNIPHIER_PXS2_ID:
39 case UNIPHIER_LD6B_ID:
Masahiro Yamadae8a92932016-08-10 16:08:49 +090040 return 4;
41 default:
42 return 1;
43 }
44}
45
46static void uniphier_smp_kick_all_cpus(void)
47{
48 const u32 target_ways = BIT(0);
49 size_t trmp_size;
50 u32 trmp_src = (unsigned long)uniphier_smp_trampoline;
51 u32 trmp_src_end = (unsigned long)uniphier_smp_trampoline_end;
52 u32 trmp_dest, trmp_dest_end;
53 int nr_cpus, i;
54 int timeout = 1000;
55
56 nr_cpus = uniphier_get_nr_cpus();
57 if (nr_cpus == 1)
58 return;
59
60 for (i = 0; i < nr_cpus; i++) /* lock ways for all CPUs */
61 uniphier_cache_set_active_ways(i, 0);
62 uniphier_cache_inv_way(target_ways);
63 uniphier_cache_enable();
64
65 /* copy trampoline code */
66 uniphier_cache_prefetch_range(trmp_src, trmp_src_end, target_ways);
67
68 trmp_size = trmp_src_end - trmp_src;
69
70 trmp_dest = trmp_src & (SZ_64K - 1);
71 trmp_dest += SZ_1M - SZ_64K * 2;
72
73 trmp_dest_end = trmp_dest + trmp_size;
74
75 uniphier_cache_touch_range(trmp_dest, trmp_dest_end, target_ways);
76
77 writel(trmp_dest, UNIPHIER_SMPCTRL_ROM_RSV2);
78
79 asm("dsb ishst\n" /* Ensure the write to ROM_RSV2 is visible */
80 "sev"); /* Bring up all secondary CPUs from Boot ROM into U-Boot */
81
82 while (--timeout) {
83 int all_booted = 1;
84
85 for (i = 1; i < nr_cpus; i++)
86 if (!uniphier_smp_booted[i])
87 all_booted = 0;
88 if (all_booted)
89 break;
90 udelay(1);
91
92 /* barrier here because uniphier_smp_booted[] may be updated */
93 cpu_relax();
94 }
95
96 if (!timeout)
Masahiro Yamadadd74b942017-10-13 19:21:55 +090097 pr_warn("warning: some of secondary CPUs may not boot\n");
Masahiro Yamadae8a92932016-08-10 16:08:49 +090098
99 uniphier_cache_disable();
100}
101
102void psci_board_init(void)
103{
104 unsigned long scu_base;
105 u32 scu_ctrl, tmp;
106
107 asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (scu_base));
108
109 scu_ctrl = readl(scu_base + 0x30);
110 if (!(scu_ctrl & 1))
111 writel(scu_ctrl | 0x1, scu_base + 0x30);
112
113 scu_ctrl = readl(scu_base + SCU_CTRL);
114 scu_ctrl |= SCU_ENABLE | SCU_STANDBY_ENABLE;
115 writel(scu_ctrl, scu_base + SCU_CTRL);
116
117 tmp = readl(scu_base + SCU_SNSAC);
118 tmp |= 0xfff;
119 writel(tmp, scu_base + SCU_SNSAC);
120
121 uniphier_smp_kick_all_cpus();
122}
123
124void psci_arch_init(void)
125{
126 u32 actlr;
127
128 asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (actlr));
129 actlr |= 0x41; /* set SMP and FW bits */
130 asm("mcr p15, 0, %0, c1, c0, 1" : : "r" (actlr));
131}
132
133u32 uniphier_psci_holding_pen_release __secure_data = 0xffffffff;
134
Patrick Delaunaye21e3ff2019-07-22 14:19:20 +0200135s32 __secure psci_cpu_on(u32 function_id, u32 cpuid, u32 entry_point,
Patrick Delaunay4f7dc2e2018-04-16 10:15:10 +0200136 u32 context_id)
Masahiro Yamadae8a92932016-08-10 16:08:49 +0900137{
138 u32 cpu = cpuid & 0xff;
139
140 debug_puts("[U-Boot PSCI] psci_cpu_on: cpuid=");
141 debug_puth(cpuid);
142 debug_puts(", entry_point=");
143 debug_puth(entry_point);
Patrick Delaunay4f7dc2e2018-04-16 10:15:10 +0200144 debug_puts(", context_id=");
145 debug_puth(context_id);
Masahiro Yamadae8a92932016-08-10 16:08:49 +0900146 debug_puts("\n");
147
Patrick Delaunay4f7dc2e2018-04-16 10:15:10 +0200148 psci_save(cpu, entry_point, context_id);
Masahiro Yamadae8a92932016-08-10 16:08:49 +0900149
150 /* We assume D-cache is off, so do not call flush_dcache() here */
151 uniphier_psci_holding_pen_release = cpu;
152
153 /* Send an event to wake up the secondary CPU. */
154 asm("dsb ishst\n"
155 "sev");
156
157 return PSCI_RET_SUCCESS;
158}
Masahiro Yamada928f3242016-08-25 21:03:41 +0900159
Patrick Delaunaye21e3ff2019-07-22 14:19:20 +0200160void __secure psci_system_reset(void)
Masahiro Yamada928f3242016-08-25 21:03:41 +0900161{
162 reset_cpu(0);
163}