summaryrefslogtreecommitdiff
path: root/arch/arm/mach-imx/platsmp.c
blob: 72f8e5fbba40a26f7213a6c7ac200c7c40239153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
 * Copyright 2011 Freescale Semiconductor, Inc.
 * Copyright 2011 Linaro Ltd.
 *
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

#include <linux/init.h>
#include <linux/smp.h>
#include <asm/cacheflush.h>
#include <asm/page.h>
#include <asm/smp_scu.h>
#include <asm/mach/map.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/delay.h>
#include <asm/smp_plat.h>

#include "common.h"
#include "hardware.h"

#define SCU_STANDBY_ENABLE	(1 << 5)

#define	SCFG_CORE0_SFT_RST	0x130
#define	SCFG_REVCR		0x200
#define	SCFG_CORESRENCR		0x204
#define	SCFG_SPARECR4		0x50C

#define	DCFG_CCSR_BRR		0x0E4
#define	DCFG_CCSR_SCRATCHRW1	0x200

#define	DCSR_RCPM2_DEBUG1	0x400
#define	DCSR_RCPM2_DEBUG2	0x414

#define	CCSR_TWAITSR0		0x04C

#define	STRIDE_4B		4

u32 g_diag_reg;
static void __iomem *scu_base;
static void __iomem *dcfg_base;
static void __iomem *scfg_base;
static void __iomem *dcsr_rcpm2_base;
static void __iomem *rcpm_base;
static u32 secondary_pre_boot_entry;

static struct map_desc scu_io_desc __initdata = {
	/* .virtual and .pfn are run-time assigned */
	.length		= SZ_4K,
	.type		= MT_DEVICE,
};

void __init imx_scu_map_io(void)
{
	unsigned long base;

	/* Get SCU base */
	asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base));

	scu_io_desc.virtual = IMX_IO_P2V(base);
	scu_io_desc.pfn = __phys_to_pfn(base);
	iotable_init(&scu_io_desc, 1);

	scu_base = IMX_IO_ADDRESS(base);
}

void imx_scu_standby_enable(void)
{
	u32 val = readl_relaxed(scu_base);

	val |= SCU_STANDBY_ENABLE;
	writel_relaxed(val, scu_base);
}

static int imx_boot_secondary(unsigned int cpu, struct task_struct *idle)
{
	imx_set_cpu_jump(cpu, v7_secondary_startup);
	imx_enable_cpu(cpu, true);
	return 0;
}

/*
 * Initialise the CPU possible map early - this describes the CPUs
 * which may be present or become present in the system.
 */
static void __init imx_smp_init_cpus(void)
{
	int i, ncores;

	ncores = scu_get_core_count(scu_base);

	for (i = ncores; i < NR_CPUS; i++)
		set_cpu_possible(i, false);
}

void imx_smp_prepare(void)
{
	scu_enable(scu_base);
}

static void __init imx_smp_prepare_cpus(unsigned int max_cpus)
{
	imx_smp_prepare();

	/*
	 * The diagnostic register holds the errata bits.  Mostly bootloader
	 * does not bring up secondary cores, so that when errata bits are set
	 * in bootloader, they are set only for boot cpu.  But on a SMP
	 * configuration, it should be equally done on every single core.
	 * Read the register from boot cpu here, and will replicate it into
	 * secondary cores when booting them.
	 */
	asm("mrc p15, 0, %0, c15, c0, 1" : "=r" (g_diag_reg) : : "cc");
	__cpuc_flush_dcache_area(&g_diag_reg, sizeof(g_diag_reg));
	outer_clean_range(__pa(&g_diag_reg), __pa(&g_diag_reg + 1));
}

struct smp_operations  imx_smp_ops __initdata = {
	.smp_init_cpus		= imx_smp_init_cpus,
	.smp_prepare_cpus	= imx_smp_prepare_cpus,
	.smp_boot_secondary	= imx_boot_secondary,
#ifdef CONFIG_HOTPLUG_CPU
	.cpu_die		= imx_cpu_die,
	.cpu_kill		= imx_cpu_kill,
#endif
};

static int ls1021a_secondary_iomap(void)
{
	struct device_node *np;
	int ret;

	np = of_find_compatible_node(NULL, NULL, "fsl,ls1021a-dcfg");
	if (!np) {
		pr_err("%s: failed to find dcfg node.\n", __func__);
		ret = -ENODEV;
		goto dcfg_err;
	}

	dcfg_base = of_iomap(np, 0);
	of_node_put(np);
	if (!dcfg_base) {
		pr_err("%s: failed to map dcfg.\n", __func__);
		ret = -ENOMEM;
		goto dcfg_err;
	}

	np = of_find_compatible_node(NULL, NULL, "fsl,ls1021a-scfg");
	if (!np) {
		pr_err("%s: failed to find scfg node.\n", __func__);
		ret = -ENODEV;
		goto scfg_err;
	}

	scfg_base = of_iomap(np, 0);
	of_node_put(np);
	if (!scfg_base) {
		pr_err("%s: failed to map scfg.\n", __func__);
		ret = -ENOMEM;
		goto scfg_err;
	}

	np = of_find_compatible_node(NULL, NULL, "fsl,ls1021a-dcsr-rcpm");
	if (!np) {
		pr_err("%s: failed to find dcsr node.\n", __func__);
		ret = -ENODEV;
		goto dcsr_err;
	}

	dcsr_rcpm2_base = of_iomap(np, 1);
	of_node_put(np);
	if (!dcsr_rcpm2_base) {
		pr_err("%s: failed to map dcsr.\n", __func__);
		ret = -ENOMEM;
		goto dcsr_err;
	}

	np = of_find_compatible_node(NULL, NULL, "fsl,qoriq-rcpm-2.1");
	if (!np) {
		pr_err("%s(): failed to find the RCPM node.\n", __func__);
		ret = -ENODEV;
		goto rcpm_err;
	}

	rcpm_base = of_iomap(np, 0);
	of_node_put(np);
	if (!rcpm_base) {
		pr_err("%s: failed to map rcpm.\n", __func__);
		ret = -ENOMEM;
		goto rcpm_err;
	}

	return 0;

rcpm_err:
	iounmap(dcsr_rcpm2_base);
dcsr_err:
	iounmap(scfg_base);
scfg_err:
	iounmap(dcfg_base);
dcfg_err:
	return ret;
}

u32 ls1_get_cpu_arg(int cpu)
{
	BUG_ON(!rcpm_base);

	cpu = cpu_logical_map(cpu);
	return ioread32be(rcpm_base + CCSR_TWAITSR0) & (1 << cpu);
}

void ls1021a_set_secondary_entry(void)
{
	unsigned long paddr;

	if (dcfg_base) {
		paddr = virt_to_phys(secondary_startup);
		writel_relaxed(cpu_to_be32(paddr),
				dcfg_base + DCFG_CCSR_SCRATCHRW1);
	}
}

static int ls1021a_reset_secondary(unsigned int cpu)
{
	u32 tmp;

	if (!scfg_base || !dcfg_base || !dcsr_rcpm2_base)
		return -ENOMEM;

	writel_relaxed(secondary_pre_boot_entry,
			dcfg_base + DCFG_CCSR_SCRATCHRW1);

	/* Apply LS1021A specific to write to the BE SCFG space */
	tmp = ioread32be(scfg_base + SCFG_REVCR);
	iowrite32be(0xffffffff, scfg_base + SCFG_REVCR);

	/* Soft reset secondary core */
	iowrite32be(0x80000000, scfg_base + SCFG_CORESRENCR);
	iowrite32be(0x80000000, scfg_base +
				SCFG_CORE0_SFT_RST + STRIDE_4B * cpu);
	mdelay(15);

	/* Release secondary core */
	iowrite32be(1 << cpu, dcfg_base + DCFG_CCSR_BRR);

	ls1021a_set_secondary_entry();

	/* Disable core soft reset register */
	iowrite32be(0x0, scfg_base + SCFG_CORESRENCR);

	/* Revert back to the default */
	iowrite32be(tmp, scfg_base + SCFG_REVCR);

	return 0;
}

static int ls1021a_boot_secondary(unsigned int cpu, struct task_struct *idle)
{
	int ret = 0;

	if (system_state == SYSTEM_RUNNING)
		ret = ls1021a_reset_secondary(cpu);

	udelay(1);

	arch_send_wakeup_ipi_mask(cpumask_of(cpu));

	return ret;
}

static void __init ls1021a_smp_prepare_cpus(unsigned int max_cpus)
{
	ls1021a_secondary_iomap();

	secondary_pre_boot_entry = readl_relaxed(dcfg_base +
						DCFG_CCSR_SCRATCHRW1);

	ls1021a_set_secondary_entry();
}

struct smp_operations  ls1021a_smp_ops __initdata = {
	.smp_prepare_cpus	= ls1021a_smp_prepare_cpus,
	.smp_boot_secondary	= ls1021a_boot_secondary,
#ifdef CONFIG_HOTPLUG_CPU
	.cpu_die                = ls1021a_cpu_die,
	.cpu_kill               = ls1021a_cpu_kill,
#endif
};