xref: /OK3568_Linux_fs/kernel/arch/arm/mach-vexpress/dcscb.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * arch/arm/mach-vexpress/dcscb.c - Dual Cluster System Configuration Block
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Created by:	Nicolas Pitre, May 2012
6*4882a593Smuzhiyun  * Copyright:	(C) 2012-2013  Linaro Limited
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/init.h>
10*4882a593Smuzhiyun #include <linux/kernel.h>
11*4882a593Smuzhiyun #include <linux/io.h>
12*4882a593Smuzhiyun #include <linux/errno.h>
13*4882a593Smuzhiyun #include <linux/of_address.h>
14*4882a593Smuzhiyun #include <linux/vexpress.h>
15*4882a593Smuzhiyun #include <linux/arm-cci.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include <asm/mcpm.h>
18*4882a593Smuzhiyun #include <asm/proc-fns.h>
19*4882a593Smuzhiyun #include <asm/cacheflush.h>
20*4882a593Smuzhiyun #include <asm/cputype.h>
21*4882a593Smuzhiyun #include <asm/cp15.h>
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #include "core.h"
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #define RST_HOLD0	0x0
26*4882a593Smuzhiyun #define RST_HOLD1	0x4
27*4882a593Smuzhiyun #define SYS_SWRESET	0x8
28*4882a593Smuzhiyun #define RST_STAT0	0xc
29*4882a593Smuzhiyun #define RST_STAT1	0x10
30*4882a593Smuzhiyun #define EAG_CFG_R	0x20
31*4882a593Smuzhiyun #define EAG_CFG_W	0x24
32*4882a593Smuzhiyun #define KFC_CFG_R	0x28
33*4882a593Smuzhiyun #define KFC_CFG_W	0x2c
34*4882a593Smuzhiyun #define DCS_CFG_R	0x30
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun static void __iomem *dcscb_base;
37*4882a593Smuzhiyun static int dcscb_allcpus_mask[2];
38*4882a593Smuzhiyun 
dcscb_cpu_powerup(unsigned int cpu,unsigned int cluster)39*4882a593Smuzhiyun static int dcscb_cpu_powerup(unsigned int cpu, unsigned int cluster)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun 	unsigned int rst_hold, cpumask = (1 << cpu);
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	pr_debug("%s: cpu %u cluster %u\n", __func__, cpu, cluster);
44*4882a593Smuzhiyun 	if (cluster >= 2 || !(cpumask & dcscb_allcpus_mask[cluster]))
45*4882a593Smuzhiyun 		return -EINVAL;
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun 	rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
48*4882a593Smuzhiyun 	rst_hold &= ~(cpumask | (cpumask << 4));
49*4882a593Smuzhiyun 	writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
50*4882a593Smuzhiyun 	return 0;
51*4882a593Smuzhiyun }
52*4882a593Smuzhiyun 
dcscb_cluster_powerup(unsigned int cluster)53*4882a593Smuzhiyun static int dcscb_cluster_powerup(unsigned int cluster)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun 	unsigned int rst_hold;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	pr_debug("%s: cluster %u\n", __func__, cluster);
58*4882a593Smuzhiyun 	if (cluster >= 2)
59*4882a593Smuzhiyun 		return -EINVAL;
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	/* remove cluster reset and add individual CPU's reset */
62*4882a593Smuzhiyun 	rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
63*4882a593Smuzhiyun 	rst_hold &= ~(1 << 8);
64*4882a593Smuzhiyun 	rst_hold |= dcscb_allcpus_mask[cluster];
65*4882a593Smuzhiyun 	writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
66*4882a593Smuzhiyun 	return 0;
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun 
dcscb_cpu_powerdown_prepare(unsigned int cpu,unsigned int cluster)69*4882a593Smuzhiyun static void dcscb_cpu_powerdown_prepare(unsigned int cpu, unsigned int cluster)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun 	unsigned int rst_hold;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 	pr_debug("%s: cpu %u cluster %u\n", __func__, cpu, cluster);
74*4882a593Smuzhiyun 	BUG_ON(cluster >= 2 || !((1 << cpu) & dcscb_allcpus_mask[cluster]));
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
77*4882a593Smuzhiyun 	rst_hold |= (1 << cpu);
78*4882a593Smuzhiyun 	writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun 
dcscb_cluster_powerdown_prepare(unsigned int cluster)81*4882a593Smuzhiyun static void dcscb_cluster_powerdown_prepare(unsigned int cluster)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun 	unsigned int rst_hold;
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun 	pr_debug("%s: cluster %u\n", __func__, cluster);
86*4882a593Smuzhiyun 	BUG_ON(cluster >= 2);
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 	rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
89*4882a593Smuzhiyun 	rst_hold |= (1 << 8);
90*4882a593Smuzhiyun 	writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun 
dcscb_cpu_cache_disable(void)93*4882a593Smuzhiyun static void dcscb_cpu_cache_disable(void)
94*4882a593Smuzhiyun {
95*4882a593Smuzhiyun 	/* Disable and flush the local CPU cache. */
96*4882a593Smuzhiyun 	v7_exit_coherency_flush(louis);
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun 
dcscb_cluster_cache_disable(void)99*4882a593Smuzhiyun static void dcscb_cluster_cache_disable(void)
100*4882a593Smuzhiyun {
101*4882a593Smuzhiyun 	/* Flush all cache levels for this cluster. */
102*4882a593Smuzhiyun 	v7_exit_coherency_flush(all);
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	/*
105*4882a593Smuzhiyun 	 * A full outer cache flush could be needed at this point
106*4882a593Smuzhiyun 	 * on platforms with such a cache, depending on where the
107*4882a593Smuzhiyun 	 * outer cache sits. In some cases the notion of a "last
108*4882a593Smuzhiyun 	 * cluster standing" would need to be implemented if the
109*4882a593Smuzhiyun 	 * outer cache is shared across clusters. In any case, when
110*4882a593Smuzhiyun 	 * the outer cache needs flushing, there is no concurrent
111*4882a593Smuzhiyun 	 * access to the cache controller to worry about and no
112*4882a593Smuzhiyun 	 * special locking besides what is already provided by the
113*4882a593Smuzhiyun 	 * MCPM state machinery is needed.
114*4882a593Smuzhiyun 	 */
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	/*
117*4882a593Smuzhiyun 	 * Disable cluster-level coherency by masking
118*4882a593Smuzhiyun 	 * incoming snoops and DVM messages:
119*4882a593Smuzhiyun 	 */
120*4882a593Smuzhiyun 	cci_disable_port_by_cpu(read_cpuid_mpidr());
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun static const struct mcpm_platform_ops dcscb_power_ops = {
124*4882a593Smuzhiyun 	.cpu_powerup		= dcscb_cpu_powerup,
125*4882a593Smuzhiyun 	.cluster_powerup	= dcscb_cluster_powerup,
126*4882a593Smuzhiyun 	.cpu_powerdown_prepare	= dcscb_cpu_powerdown_prepare,
127*4882a593Smuzhiyun 	.cluster_powerdown_prepare = dcscb_cluster_powerdown_prepare,
128*4882a593Smuzhiyun 	.cpu_cache_disable	= dcscb_cpu_cache_disable,
129*4882a593Smuzhiyun 	.cluster_cache_disable	= dcscb_cluster_cache_disable,
130*4882a593Smuzhiyun };
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun extern void dcscb_power_up_setup(unsigned int affinity_level);
133*4882a593Smuzhiyun 
dcscb_init(void)134*4882a593Smuzhiyun static int __init dcscb_init(void)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun 	struct device_node *node;
137*4882a593Smuzhiyun 	unsigned int cfg;
138*4882a593Smuzhiyun 	int ret;
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	if (!cci_probed())
141*4882a593Smuzhiyun 		return -ENODEV;
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	node = of_find_compatible_node(NULL, NULL, "arm,rtsm,dcscb");
144*4882a593Smuzhiyun 	if (!node)
145*4882a593Smuzhiyun 		return -ENODEV;
146*4882a593Smuzhiyun 	dcscb_base = of_iomap(node, 0);
147*4882a593Smuzhiyun 	of_node_put(node);
148*4882a593Smuzhiyun 	if (!dcscb_base)
149*4882a593Smuzhiyun 		return -EADDRNOTAVAIL;
150*4882a593Smuzhiyun 	cfg = readl_relaxed(dcscb_base + DCS_CFG_R);
151*4882a593Smuzhiyun 	dcscb_allcpus_mask[0] = (1 << (((cfg >> 16) >> (0 << 2)) & 0xf)) - 1;
152*4882a593Smuzhiyun 	dcscb_allcpus_mask[1] = (1 << (((cfg >> 16) >> (1 << 2)) & 0xf)) - 1;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	ret = mcpm_platform_register(&dcscb_power_ops);
155*4882a593Smuzhiyun 	if (!ret)
156*4882a593Smuzhiyun 		ret = mcpm_sync_init(dcscb_power_up_setup);
157*4882a593Smuzhiyun 	if (ret) {
158*4882a593Smuzhiyun 		iounmap(dcscb_base);
159*4882a593Smuzhiyun 		return ret;
160*4882a593Smuzhiyun 	}
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	pr_info("VExpress DCSCB support installed\n");
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun 	/*
165*4882a593Smuzhiyun 	 * Future entries into the kernel can now go
166*4882a593Smuzhiyun 	 * through the cluster entry vectors.
167*4882a593Smuzhiyun 	 */
168*4882a593Smuzhiyun 	vexpress_flags_set(__pa_symbol(mcpm_entry_point));
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	return 0;
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun early_initcall(dcscb_init);
174