blob: 5cedcf572104bcdf82b1b75ab61f89f4cdf19651 [file] [log] [blame]
Nicolas Pitre1e904e12012-05-02 20:56:52 -04001/*
2 * arch/arm/mach-vexpress/dcscb.c - Dual Cluster System Configuration Block
3 *
4 * Created by: Nicolas Pitre, May 2012
5 * Copyright: (C) 2012-2013 Linaro Limited
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/io.h>
Nicolas Pitre1e904e12012-05-02 20:56:52 -040015#include <linux/errno.h>
16#include <linux/of_address.h>
17#include <linux/vexpress.h>
Dave Martind41418c02012-07-17 14:25:44 +010018#include <linux/arm-cci.h>
Nicolas Pitre1e904e12012-05-02 20:56:52 -040019
20#include <asm/mcpm.h>
21#include <asm/proc-fns.h>
22#include <asm/cacheflush.h>
23#include <asm/cputype.h>
24#include <asm/cp15.h>
25
26
27#define RST_HOLD0 0x0
28#define RST_HOLD1 0x4
29#define SYS_SWRESET 0x8
30#define RST_STAT0 0xc
31#define RST_STAT1 0x10
32#define EAG_CFG_R 0x20
33#define EAG_CFG_W 0x24
34#define KFC_CFG_R 0x28
35#define KFC_CFG_W 0x2c
36#define DCS_CFG_R 0x30
37
Nicolas Pitre1e904e12012-05-02 20:56:52 -040038static void __iomem *dcscb_base;
Nicolas Pitre2f2df892012-07-18 16:41:16 -040039static int dcscb_allcpus_mask[2];
Nicolas Pitre1e904e12012-05-02 20:56:52 -040040
Nicolas Pitre323ab952015-03-14 21:13:48 -040041static int dcscb_cpu_powerup(unsigned int cpu, unsigned int cluster)
Nicolas Pitre1e904e12012-05-02 20:56:52 -040042{
43 unsigned int rst_hold, cpumask = (1 << cpu);
44
45 pr_debug("%s: cpu %u cluster %u\n", __func__, cpu, cluster);
Nicolas Pitre03fd5db2015-03-14 20:29:44 -040046 if (cluster >= 2 || !(cpumask & dcscb_allcpus_mask[cluster]))
Nicolas Pitre1e904e12012-05-02 20:56:52 -040047 return -EINVAL;
48
Nicolas Pitre323ab952015-03-14 21:13:48 -040049 rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
50 rst_hold &= ~(cpumask | (cpumask << 4));
51 writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
Nicolas Pitre1e904e12012-05-02 20:56:52 -040052 return 0;
53}
54
Nicolas Pitre323ab952015-03-14 21:13:48 -040055static int dcscb_cluster_powerup(unsigned int cluster)
Nicolas Pitre1e904e12012-05-02 20:56:52 -040056{
Nicolas Pitre323ab952015-03-14 21:13:48 -040057 unsigned int rst_hold;
Nicolas Pitre1e904e12012-05-02 20:56:52 -040058
Nicolas Pitre323ab952015-03-14 21:13:48 -040059 pr_debug("%s: cluster %u\n", __func__, cluster);
60 if (cluster >= 2)
61 return -EINVAL;
Nicolas Pitre1e904e12012-05-02 20:56:52 -040062
Nicolas Pitre323ab952015-03-14 21:13:48 -040063 /* remove cluster reset and add individual CPU's reset */
64 rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
65 rst_hold &= ~(1 << 8);
66 rst_hold |= dcscb_allcpus_mask[cluster];
67 writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
68 return 0;
Nicolas Pitre1e904e12012-05-02 20:56:52 -040069}
70
Nicolas Pitre323ab952015-03-14 21:13:48 -040071static void dcscb_cpu_powerdown_prepare(unsigned int cpu, unsigned int cluster)
Nicolas Pitre13eae1442012-07-16 22:07:10 -040072{
Nicolas Pitre323ab952015-03-14 21:13:48 -040073 unsigned int rst_hold;
Nicolas Pitre13eae1442012-07-16 22:07:10 -040074
75 pr_debug("%s: cpu %u cluster %u\n", __func__, cpu, cluster);
Nicolas Pitre03fd5db2015-03-14 20:29:44 -040076 BUG_ON(cluster >= 2 || !((1 << cpu) & dcscb_allcpus_mask[cluster]));
Nicolas Pitre323ab952015-03-14 21:13:48 -040077
78 rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
79 rst_hold |= (1 << cpu);
80 writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
Nicolas Pitre13eae1442012-07-16 22:07:10 -040081}
82
Nicolas Pitre323ab952015-03-14 21:13:48 -040083static void dcscb_cluster_powerdown_prepare(unsigned int cluster)
84{
85 unsigned int rst_hold;
86
87 pr_debug("%s: cluster %u\n", __func__, cluster);
88 BUG_ON(cluster >= 2);
89
90 rst_hold = readl_relaxed(dcscb_base + RST_HOLD0 + cluster * 4);
91 rst_hold |= (1 << 8);
92 writel_relaxed(rst_hold, dcscb_base + RST_HOLD0 + cluster * 4);
93}
94
95static void dcscb_cpu_cache_disable(void)
96{
97 /* Disable and flush the local CPU cache. */
98 v7_exit_coherency_flush(louis);
99}
100
101static void dcscb_cluster_cache_disable(void)
102{
103 /* Flush all cache levels for this cluster. */
104 v7_exit_coherency_flush(all);
105
106 /*
107 * A full outer cache flush could be needed at this point
108 * on platforms with such a cache, depending on where the
109 * outer cache sits. In some cases the notion of a "last
110 * cluster standing" would need to be implemented if the
111 * outer cache is shared across clusters. In any case, when
112 * the outer cache needs flushing, there is no concurrent
113 * access to the cache controller to worry about and no
114 * special locking besides what is already provided by the
115 * MCPM state machinery is needed.
116 */
117
118 /*
119 * Disable cluster-level coherency by masking
120 * incoming snoops and DVM messages:
121 */
122 cci_disable_port_by_cpu(read_cpuid_mpidr());
123}
124
125static const struct mcpm_platform_ops dcscb_power_ops = {
126 .cpu_powerup = dcscb_cpu_powerup,
127 .cluster_powerup = dcscb_cluster_powerup,
128 .cpu_powerdown_prepare = dcscb_cpu_powerdown_prepare,
129 .cluster_powerdown_prepare = dcscb_cluster_powerdown_prepare,
130 .cpu_cache_disable = dcscb_cpu_cache_disable,
131 .cluster_cache_disable = dcscb_cluster_cache_disable,
132};
133
Dave Martind41418c02012-07-17 14:25:44 +0100134extern void dcscb_power_up_setup(unsigned int affinity_level);
135
Nicolas Pitre1e904e12012-05-02 20:56:52 -0400136static int __init dcscb_init(void)
137{
138 struct device_node *node;
Nicolas Pitre2f2df892012-07-18 16:41:16 -0400139 unsigned int cfg;
Nicolas Pitre1e904e12012-05-02 20:56:52 -0400140 int ret;
141
Dave Martind41418c02012-07-17 14:25:44 +0100142 if (!cci_probed())
143 return -ENODEV;
144
Nicolas Pitre1e904e12012-05-02 20:56:52 -0400145 node = of_find_compatible_node(NULL, NULL, "arm,rtsm,dcscb");
146 if (!node)
147 return -ENODEV;
148 dcscb_base = of_iomap(node, 0);
149 if (!dcscb_base)
150 return -EADDRNOTAVAIL;
Nicolas Pitre2f2df892012-07-18 16:41:16 -0400151 cfg = readl_relaxed(dcscb_base + DCS_CFG_R);
152 dcscb_allcpus_mask[0] = (1 << (((cfg >> 16) >> (0 << 2)) & 0xf)) - 1;
153 dcscb_allcpus_mask[1] = (1 << (((cfg >> 16) >> (1 << 2)) & 0xf)) - 1;
Nicolas Pitre13eae1442012-07-16 22:07:10 -0400154
Nicolas Pitre1e904e12012-05-02 20:56:52 -0400155 ret = mcpm_platform_register(&dcscb_power_ops);
Dave Martind41418c02012-07-17 14:25:44 +0100156 if (!ret)
157 ret = mcpm_sync_init(dcscb_power_up_setup);
Nicolas Pitre1e904e12012-05-02 20:56:52 -0400158 if (ret) {
159 iounmap(dcscb_base);
160 return ret;
161 }
162
163 pr_info("VExpress DCSCB support installed\n");
164
165 /*
166 * Future entries into the kernel can now go
167 * through the cluster entry vectors.
168 */
169 vexpress_flags_set(virt_to_phys(mcpm_entry_point));
170
171 return 0;
172}
173
174early_initcall(dcscb_init);