1
2
3
4
5
6
7
8
9
10
11#ifndef __MIPS_ASM_MIPS_CPS_H__
12#define __MIPS_ASM_MIPS_CPS_H__
13
14#include <linux/io.h>
15#include <linux/types.h>
16
17extern unsigned long __cps_access_bad_size(void)
18 __compiletime_error("Bad size for CPS accessor");
19
20#define CPS_ACCESSOR_A(unit, off, name) \
21static inline void *addr_##unit##_##name(void) \
22{ \
23 return mips_##unit##_base + (off); \
24}
25
26#define CPS_ACCESSOR_R(unit, sz, name) \
27static inline uint##sz##_t read_##unit##_##name(void) \
28{ \
29 uint64_t val64; \
30 \
31 switch (sz) { \
32 case 32: \
33 return __raw_readl(addr_##unit##_##name()); \
34 \
35 case 64: \
36 if (mips_cm_is64) \
37 return __raw_readq(addr_##unit##_##name()); \
38 \
39 val64 = __raw_readl(addr_##unit##_##name() + 4); \
40 val64 <<= 32; \
41 val64 |= __raw_readl(addr_##unit##_##name()); \
42 return val64; \
43 \
44 default: \
45 return __cps_access_bad_size(); \
46 } \
47}
48
49#define CPS_ACCESSOR_W(unit, sz, name) \
50static inline void write_##unit##_##name(uint##sz##_t val) \
51{ \
52 switch (sz) { \
53 case 32: \
54 __raw_writel(val, addr_##unit##_##name()); \
55 break; \
56 \
57 case 64: \
58 if (mips_cm_is64) { \
59 __raw_writeq(val, addr_##unit##_##name()); \
60 break; \
61 } \
62 \
63 __raw_writel((uint64_t)val >> 32, \
64 addr_##unit##_##name() + 4); \
65 __raw_writel(val, addr_##unit##_##name()); \
66 break; \
67 \
68 default: \
69 __cps_access_bad_size(); \
70 break; \
71 } \
72}
73
74#define CPS_ACCESSOR_M(unit, sz, name) \
75static inline void change_##unit##_##name(uint##sz##_t mask, \
76 uint##sz##_t val) \
77{ \
78 uint##sz##_t reg_val = read_##unit##_##name(); \
79 reg_val &= ~mask; \
80 reg_val |= val; \
81 write_##unit##_##name(reg_val); \
82} \
83 \
84static inline void set_##unit##_##name(uint##sz##_t val) \
85{ \
86 change_##unit##_##name(val, val); \
87} \
88 \
89static inline void clear_##unit##_##name(uint##sz##_t val) \
90{ \
91 change_##unit##_##name(val, 0); \
92}
93
94#define CPS_ACCESSOR_RO(unit, sz, off, name) \
95 CPS_ACCESSOR_A(unit, off, name) \
96 CPS_ACCESSOR_R(unit, sz, name)
97
98#define CPS_ACCESSOR_WO(unit, sz, off, name) \
99 CPS_ACCESSOR_A(unit, off, name) \
100 CPS_ACCESSOR_W(unit, sz, name)
101
102#define CPS_ACCESSOR_RW(unit, sz, off, name) \
103 CPS_ACCESSOR_A(unit, off, name) \
104 CPS_ACCESSOR_R(unit, sz, name) \
105 CPS_ACCESSOR_W(unit, sz, name) \
106 CPS_ACCESSOR_M(unit, sz, name)
107
108#include <asm/mips-cm.h>
109#include <asm/mips-cpc.h>
110#include <asm/mips-gic.h>
111
112
113
114
115
116
117static inline unsigned int mips_cps_numclusters(void)
118{
119 unsigned int num_clusters;
120
121 if (mips_cm_revision() < CM_REV_CM3_5)
122 return 1;
123
124 num_clusters = read_gcr_config() & CM_GCR_CONFIG_NUM_CLUSTERS;
125 num_clusters >>= __ffs(CM_GCR_CONFIG_NUM_CLUSTERS);
126 return num_clusters;
127}
128
129
130
131
132
133
134
135
136
137static inline uint64_t mips_cps_cluster_config(unsigned int cluster)
138{
139 uint64_t config;
140
141 if (mips_cm_revision() < CM_REV_CM3_5) {
142
143
144
145
146
147 WARN_ON(cluster != 0);
148 config = read_gcr_config();
149 } else {
150
151
152
153
154
155 mips_cm_lock_other(cluster, 0, 0, CM_GCR_Cx_OTHER_BLOCK_GLOBAL);
156 config = read_cpc_redir_config();
157 mips_cm_unlock_other();
158 }
159
160 return config;
161}
162
163
164
165
166
167
168
169
170static inline unsigned int mips_cps_numcores(unsigned int cluster)
171{
172 if (!mips_cm_present())
173 return 0;
174
175
176 return (mips_cps_cluster_config(cluster) + 1) & CM_GCR_CONFIG_PCORES;
177}
178
179
180
181
182
183
184
185
186static inline unsigned int mips_cps_numiocu(unsigned int cluster)
187{
188 unsigned int num_iocu;
189
190 if (!mips_cm_present())
191 return 0;
192
193 num_iocu = mips_cps_cluster_config(cluster) & CM_GCR_CONFIG_NUMIOCU;
194 num_iocu >>= __ffs(CM_GCR_CONFIG_NUMIOCU);
195 return num_iocu;
196}
197
198
199
200
201
202
203
204
205
206
207static inline unsigned int mips_cps_numvps(unsigned int cluster, unsigned int core)
208{
209 unsigned int cfg;
210
211 if (!mips_cm_present())
212 return 1;
213
214 if ((!IS_ENABLED(CONFIG_MIPS_MT_SMP) || !cpu_has_mipsmt)
215 && (!IS_ENABLED(CONFIG_CPU_MIPSR6) || !cpu_has_vp))
216 return 1;
217
218 mips_cm_lock_other(cluster, core, 0, CM_GCR_Cx_OTHER_BLOCK_LOCAL);
219
220 if (mips_cm_revision() < CM_REV_CM3_5) {
221
222
223
224
225 cfg = read_gcr_co_config();
226 } else {
227
228
229
230
231
232 cfg = read_cpc_co_config();
233 }
234
235 mips_cm_unlock_other();
236
237 return (cfg + 1) & CM_GCR_Cx_CONFIG_PVPE;
238}
239
240#endif
241