1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4 */
5 #ifndef _ASM_LOONGARCH_H
6 #define _ASM_LOONGARCH_H
7
8 #include <linux/bits.h>
9 #include <linux/linkage.h>
10 #include <linux/types.h>
11
12 #ifndef __ASSEMBLY__
13 #include <larchintrin.h>
14
15 /* CPUCFG */
16 #define read_cpucfg(reg) __cpucfg(reg)
17
18 #endif /* !__ASSEMBLY__ */
19
20 #ifdef __ASSEMBLY__
21
22 /* LoongArch Registers */
23 #define REG_ZERO 0x0
24 #define REG_RA 0x1
25 #define REG_TP 0x2
26 #define REG_SP 0x3
27 #define REG_A0 0x4 /* Reused as V0 for return value */
28 #define REG_A1 0x5 /* Reused as V1 for return value */
29 #define REG_A2 0x6
30 #define REG_A3 0x7
31 #define REG_A4 0x8
32 #define REG_A5 0x9
33 #define REG_A6 0xa
34 #define REG_A7 0xb
35 #define REG_T0 0xc
36 #define REG_T1 0xd
37 #define REG_T2 0xe
38 #define REG_T3 0xf
39 #define REG_T4 0x10
40 #define REG_T5 0x11
41 #define REG_T6 0x12
42 #define REG_T7 0x13
43 #define REG_T8 0x14
44 #define REG_U0 0x15 /* Kernel uses it as percpu base */
45 #define REG_FP 0x16
46 #define REG_S0 0x17
47 #define REG_S1 0x18
48 #define REG_S2 0x19
49 #define REG_S3 0x1a
50 #define REG_S4 0x1b
51 #define REG_S5 0x1c
52 #define REG_S6 0x1d
53 #define REG_S7 0x1e
54 #define REG_S8 0x1f
55
56 #endif /* __ASSEMBLY__ */
57
58 /* Bit fields for CPUCFG registers */
59 #define LOONGARCH_CPUCFG0 0x0
60 #define CPUCFG0_PRID GENMASK(31, 0)
61
62 #define LOONGARCH_CPUCFG1 0x1
63 #define CPUCFG1_ISGR32 BIT(0)
64 #define CPUCFG1_ISGR64 BIT(1)
65 #define CPUCFG1_ISA GENMASK(1, 0)
66 #define CPUCFG1_PAGING BIT(2)
67 #define CPUCFG1_IOCSR BIT(3)
68 #define CPUCFG1_PABITS GENMASK(11, 4)
69 #define CPUCFG1_VABITS GENMASK(19, 12)
70 #define CPUCFG1_UAL BIT(20)
71 #define CPUCFG1_RI BIT(21)
72 #define CPUCFG1_EP BIT(22)
73 #define CPUCFG1_RPLV BIT(23)
74 #define CPUCFG1_HUGEPG BIT(24)
75 #define CPUCFG1_CRC32 BIT(25)
76 #define CPUCFG1_MSGINT BIT(26)
77
78 #define LOONGARCH_CPUCFG2 0x2
79 #define CPUCFG2_FP BIT(0)
80 #define CPUCFG2_FPSP BIT(1)
81 #define CPUCFG2_FPDP BIT(2)
82 #define CPUCFG2_FPVERS GENMASK(5, 3)
83 #define CPUCFG2_LSX BIT(6)
84 #define CPUCFG2_LASX BIT(7)
85 #define CPUCFG2_COMPLEX BIT(8)
86 #define CPUCFG2_CRYPTO BIT(9)
87 #define CPUCFG2_LVZP BIT(10)
88 #define CPUCFG2_LVZVER GENMASK(13, 11)
89 #define CPUCFG2_LLFTP BIT(14)
90 #define CPUCFG2_LLFTPREV GENMASK(17, 15)
91 #define CPUCFG2_X86BT BIT(18)
92 #define CPUCFG2_ARMBT BIT(19)
93 #define CPUCFG2_MIPSBT BIT(20)
94 #define CPUCFG2_LSPW BIT(21)
95 #define CPUCFG2_LAM BIT(22)
96 #define CPUCFG2_PTW BIT(24)
97
98 #define LOONGARCH_CPUCFG3 0x3
99 #define CPUCFG3_CCDMA BIT(0)
100 #define CPUCFG3_SFB BIT(1)
101 #define CPUCFG3_UCACC BIT(2)
102 #define CPUCFG3_LLEXC BIT(3)
103 #define CPUCFG3_SCDLY BIT(4)
104 #define CPUCFG3_LLDBAR BIT(5)
105 #define CPUCFG3_ITLBT BIT(6)
106 #define CPUCFG3_ICACHET BIT(7)
107 #define CPUCFG3_SPW_LVL GENMASK(10, 8)
108 #define CPUCFG3_SPW_HG_HF BIT(11)
109 #define CPUCFG3_RVA BIT(12)
110 #define CPUCFG3_RVAMAX GENMASK(16, 13)
111
112 #define LOONGARCH_CPUCFG4 0x4
113 #define CPUCFG4_CCFREQ GENMASK(31, 0)
114
115 #define LOONGARCH_CPUCFG5 0x5
116 #define CPUCFG5_CCMUL GENMASK(15, 0)
117 #define CPUCFG5_CCDIV GENMASK(31, 16)
118
119 #define LOONGARCH_CPUCFG6 0x6
120 #define CPUCFG6_PMP BIT(0)
121 #define CPUCFG6_PAMVER GENMASK(3, 1)
122 #define CPUCFG6_PMNUM GENMASK(7, 4)
123 #define CPUCFG6_PMNUM_SHIFT 4
124 #define CPUCFG6_PMBITS GENMASK(13, 8)
125 #define CPUCFG6_UPM BIT(14)
126
127 #define LOONGARCH_CPUCFG16 0x10
128 #define CPUCFG16_L1_IUPRE BIT(0)
129 #define CPUCFG16_L1_IUUNIFY BIT(1)
130 #define CPUCFG16_L1_DPRE BIT(2)
131 #define CPUCFG16_L2_IUPRE BIT(3)
132 #define CPUCFG16_L2_IUUNIFY BIT(4)
133 #define CPUCFG16_L2_IUPRIV BIT(5)
134 #define CPUCFG16_L2_IUINCL BIT(6)
135 #define CPUCFG16_L2_DPRE BIT(7)
136 #define CPUCFG16_L2_DPRIV BIT(8)
137 #define CPUCFG16_L2_DINCL BIT(9)
138 #define CPUCFG16_L3_IUPRE BIT(10)
139 #define CPUCFG16_L3_IUUNIFY BIT(11)
140 #define CPUCFG16_L3_IUPRIV BIT(12)
141 #define CPUCFG16_L3_IUINCL BIT(13)
142 #define CPUCFG16_L3_DPRE BIT(14)
143 #define CPUCFG16_L3_DPRIV BIT(15)
144 #define CPUCFG16_L3_DINCL BIT(16)
145
146 #define LOONGARCH_CPUCFG17 0x11
147 #define LOONGARCH_CPUCFG18 0x12
148 #define LOONGARCH_CPUCFG19 0x13
149 #define LOONGARCH_CPUCFG20 0x14
150 #define CPUCFG_CACHE_WAYS_M GENMASK(15, 0)
151 #define CPUCFG_CACHE_SETS_M GENMASK(23, 16)
152 #define CPUCFG_CACHE_LSIZE_M GENMASK(30, 24)
153 #define CPUCFG_CACHE_WAYS 0
154 #define CPUCFG_CACHE_SETS 16
155 #define CPUCFG_CACHE_LSIZE 24
156
157 #define LOONGARCH_CPUCFG48 0x30
158 #define CPUCFG48_MCSR_LCK BIT(0)
159 #define CPUCFG48_NAP_EN BIT(1)
160 #define CPUCFG48_VFPU_CG BIT(2)
161 #define CPUCFG48_RAM_CG BIT(3)
162
163 /*
164 * CPUCFG index area: 0x40000000 -- 0x400000ff
165 * SW emulation for KVM hypervirsor, see arch/loongarch/include/uapi/asm/kvm_para.h
166 */
167
168 #ifndef __ASSEMBLY__
169
170 /* CSR */
171 #define csr_read32(reg) __csrrd_w(reg)
172 #define csr_read64(reg) __csrrd_d(reg)
173 #define csr_write32(val, reg) __csrwr_w(val, reg)
174 #define csr_write64(val, reg) __csrwr_d(val, reg)
175 #define csr_xchg32(val, mask, reg) __csrxchg_w(val, mask, reg)
176 #define csr_xchg64(val, mask, reg) __csrxchg_d(val, mask, reg)
177
178 /* IOCSR */
179 #define iocsr_read32(reg) __iocsrrd_w(reg)
180 #define iocsr_read64(reg) __iocsrrd_d(reg)
181 #define iocsr_write32(val, reg) __iocsrwr_w(val, reg)
182 #define iocsr_write64(val, reg) __iocsrwr_d(val, reg)
183
184 #endif /* !__ASSEMBLY__ */
185
186 /* CSR register number */
187
188 /* Basic CSR registers */
189 #define LOONGARCH_CSR_CRMD 0x0 /* Current mode info */
190 #define CSR_CRMD_WE_SHIFT 9
191 #define CSR_CRMD_WE (_ULCAST_(0x1) << CSR_CRMD_WE_SHIFT)
192 #define CSR_CRMD_DACM_SHIFT 7
193 #define CSR_CRMD_DACM_WIDTH 2
194 #define CSR_CRMD_DACM (_ULCAST_(0x3) << CSR_CRMD_DACM_SHIFT)
195 #define CSR_CRMD_DACF_SHIFT 5
196 #define CSR_CRMD_DACF_WIDTH 2
197 #define CSR_CRMD_DACF (_ULCAST_(0x3) << CSR_CRMD_DACF_SHIFT)
198 #define CSR_CRMD_PG_SHIFT 4
199 #define CSR_CRMD_PG (_ULCAST_(0x1) << CSR_CRMD_PG_SHIFT)
200 #define CSR_CRMD_DA_SHIFT 3
201 #define CSR_CRMD_DA (_ULCAST_(0x1) << CSR_CRMD_DA_SHIFT)
202 #define CSR_CRMD_IE_SHIFT 2
203 #define CSR_CRMD_IE (_ULCAST_(0x1) << CSR_CRMD_IE_SHIFT)
204 #define CSR_CRMD_PLV_SHIFT 0
205 #define CSR_CRMD_PLV_WIDTH 2
206 #define CSR_CRMD_PLV (_ULCAST_(0x3) << CSR_CRMD_PLV_SHIFT)
207
208 #define PLV_KERN 0
209 #define PLV_USER 3
210 #define PLV_MASK 0x3
211
212 #define LOONGARCH_CSR_PRMD 0x1 /* Prev-exception mode info */
213 #define CSR_PRMD_PWE_SHIFT 3
214 #define CSR_PRMD_PWE (_ULCAST_(0x1) << CSR_PRMD_PWE_SHIFT)
215 #define CSR_PRMD_PIE_SHIFT 2
216 #define CSR_PRMD_PIE (_ULCAST_(0x1) << CSR_PRMD_PIE_SHIFT)
217 #define CSR_PRMD_PPLV_SHIFT 0
218 #define CSR_PRMD_PPLV_WIDTH 2
219 #define CSR_PRMD_PPLV (_ULCAST_(0x3) << CSR_PRMD_PPLV_SHIFT)
220
221 #define LOONGARCH_CSR_EUEN 0x2 /* Extended unit enable */
222 #define CSR_EUEN_LBTEN_SHIFT 3
223 #define CSR_EUEN_LBTEN (_ULCAST_(0x1) << CSR_EUEN_LBTEN_SHIFT)
224 #define CSR_EUEN_LASXEN_SHIFT 2
225 #define CSR_EUEN_LASXEN (_ULCAST_(0x1) << CSR_EUEN_LASXEN_SHIFT)
226 #define CSR_EUEN_LSXEN_SHIFT 1
227 #define CSR_EUEN_LSXEN (_ULCAST_(0x1) << CSR_EUEN_LSXEN_SHIFT)
228 #define CSR_EUEN_FPEN_SHIFT 0
229 #define CSR_EUEN_FPEN (_ULCAST_(0x1) << CSR_EUEN_FPEN_SHIFT)
230
231 #define LOONGARCH_CSR_MISC 0x3 /* Misc config */
232
233 #define LOONGARCH_CSR_ECFG 0x4 /* Exception config */
234 #define CSR_ECFG_VS_SHIFT 16
235 #define CSR_ECFG_VS_WIDTH 3
236 #define CSR_ECFG_VS_SHIFT_END (CSR_ECFG_VS_SHIFT + CSR_ECFG_VS_WIDTH - 1)
237 #define CSR_ECFG_VS (_ULCAST_(0x7) << CSR_ECFG_VS_SHIFT)
238 #define CSR_ECFG_IM_SHIFT 0
239 #define CSR_ECFG_IM_WIDTH 14
240 #define CSR_ECFG_IM (_ULCAST_(0x3fff) << CSR_ECFG_IM_SHIFT)
241
242 #define LOONGARCH_CSR_ESTAT 0x5 /* Exception status */
243 #define CSR_ESTAT_ESUBCODE_SHIFT 22
244 #define CSR_ESTAT_ESUBCODE_WIDTH 9
245 #define CSR_ESTAT_ESUBCODE (_ULCAST_(0x1ff) << CSR_ESTAT_ESUBCODE_SHIFT)
246 #define CSR_ESTAT_EXC_SHIFT 16
247 #define CSR_ESTAT_EXC_WIDTH 6
248 #define CSR_ESTAT_EXC (_ULCAST_(0x3f) << CSR_ESTAT_EXC_SHIFT)
249 #define CSR_ESTAT_IS_SHIFT 0
250 #define CSR_ESTAT_IS_WIDTH 15
251 #define CSR_ESTAT_IS (_ULCAST_(0x7fff) << CSR_ESTAT_IS_SHIFT)
252
253 #define LOONGARCH_CSR_ERA 0x6 /* Exception return address */
254
255 #define LOONGARCH_CSR_BADV 0x7 /* Bad virtual address */
256
257 #define LOONGARCH_CSR_BADI 0x8 /* Bad instruction */
258
259 #define LOONGARCH_CSR_EENTRY 0xc /* Exception entry */
260
261 /* TLB related CSR registers */
262 #define LOONGARCH_CSR_TLBIDX 0x10 /* TLB Index, EHINV, PageSize, NP */
263 #define CSR_TLBIDX_EHINV_SHIFT 31
264 #define CSR_TLBIDX_EHINV (_ULCAST_(1) << CSR_TLBIDX_EHINV_SHIFT)
265 #define CSR_TLBIDX_PS_SHIFT 24
266 #define CSR_TLBIDX_PS_WIDTH 6
267 #define CSR_TLBIDX_PS (_ULCAST_(0x3f) << CSR_TLBIDX_PS_SHIFT)
268 #define CSR_TLBIDX_IDX_SHIFT 0
269 #define CSR_TLBIDX_IDX_WIDTH 12
270 #define CSR_TLBIDX_IDX (_ULCAST_(0xfff) << CSR_TLBIDX_IDX_SHIFT)
271 #define CSR_TLBIDX_SIZEM 0x3f000000
272 #define CSR_TLBIDX_SIZE CSR_TLBIDX_PS_SHIFT
273 #define CSR_TLBIDX_IDXM 0xfff
274 #define CSR_INVALID_ENTRY(e) (CSR_TLBIDX_EHINV | e)
275
276 #define LOONGARCH_CSR_TLBEHI 0x11 /* TLB EntryHi */
277
278 #define LOONGARCH_CSR_TLBELO0 0x12 /* TLB EntryLo0 */
279 #define CSR_TLBLO0_RPLV_SHIFT 63
280 #define CSR_TLBLO0_RPLV (_ULCAST_(0x1) << CSR_TLBLO0_RPLV_SHIFT)
281 #define CSR_TLBLO0_NX_SHIFT 62
282 #define CSR_TLBLO0_NX (_ULCAST_(0x1) << CSR_TLBLO0_NX_SHIFT)
283 #define CSR_TLBLO0_NR_SHIFT 61
284 #define CSR_TLBLO0_NR (_ULCAST_(0x1) << CSR_TLBLO0_NR_SHIFT)
285 #define CSR_TLBLO0_PFN_SHIFT 12
286 #define CSR_TLBLO0_PFN_WIDTH 36
287 #define CSR_TLBLO0_PFN (_ULCAST_(0xfffffffff) << CSR_TLBLO0_PFN_SHIFT)
288 #define CSR_TLBLO0_GLOBAL_SHIFT 6
289 #define CSR_TLBLO0_GLOBAL (_ULCAST_(0x1) << CSR_TLBLO0_GLOBAL_SHIFT)
290 #define CSR_TLBLO0_CCA_SHIFT 4
291 #define CSR_TLBLO0_CCA_WIDTH 2
292 #define CSR_TLBLO0_CCA (_ULCAST_(0x3) << CSR_TLBLO0_CCA_SHIFT)
293 #define CSR_TLBLO0_PLV_SHIFT 2
294 #define CSR_TLBLO0_PLV_WIDTH 2
295 #define CSR_TLBLO0_PLV (_ULCAST_(0x3) << CSR_TLBLO0_PLV_SHIFT)
296 #define CSR_TLBLO0_WE_SHIFT 1
297 #define CSR_TLBLO0_WE (_ULCAST_(0x1) << CSR_TLBLO0_WE_SHIFT)
298 #define CSR_TLBLO0_V_SHIFT 0
299 #define CSR_TLBLO0_V (_ULCAST_(0x1) << CSR_TLBLO0_V_SHIFT)
300
301 #define LOONGARCH_CSR_TLBELO1 0x13 /* TLB EntryLo1 */
302 #define CSR_TLBLO1_RPLV_SHIFT 63
303 #define CSR_TLBLO1_RPLV (_ULCAST_(0x1) << CSR_TLBLO1_RPLV_SHIFT)
304 #define CSR_TLBLO1_NX_SHIFT 62
305 #define CSR_TLBLO1_NX (_ULCAST_(0x1) << CSR_TLBLO1_NX_SHIFT)
306 #define CSR_TLBLO1_NR_SHIFT 61
307 #define CSR_TLBLO1_NR (_ULCAST_(0x1) << CSR_TLBLO1_NR_SHIFT)
308 #define CSR_TLBLO1_PFN_SHIFT 12
309 #define CSR_TLBLO1_PFN_WIDTH 36
310 #define CSR_TLBLO1_PFN (_ULCAST_(0xfffffffff) << CSR_TLBLO1_PFN_SHIFT)
311 #define CSR_TLBLO1_GLOBAL_SHIFT 6
312 #define CSR_TLBLO1_GLOBAL (_ULCAST_(0x1) << CSR_TLBLO1_GLOBAL_SHIFT)
313 #define CSR_TLBLO1_CCA_SHIFT 4
314 #define CSR_TLBLO1_CCA_WIDTH 2
315 #define CSR_TLBLO1_CCA (_ULCAST_(0x3) << CSR_TLBLO1_CCA_SHIFT)
316 #define CSR_TLBLO1_PLV_SHIFT 2
317 #define CSR_TLBLO1_PLV_WIDTH 2
318 #define CSR_TLBLO1_PLV (_ULCAST_(0x3) << CSR_TLBLO1_PLV_SHIFT)
319 #define CSR_TLBLO1_WE_SHIFT 1
320 #define CSR_TLBLO1_WE (_ULCAST_(0x1) << CSR_TLBLO1_WE_SHIFT)
321 #define CSR_TLBLO1_V_SHIFT 0
322 #define CSR_TLBLO1_V (_ULCAST_(0x1) << CSR_TLBLO1_V_SHIFT)
323
324 #define LOONGARCH_CSR_GTLBC 0x15 /* Guest TLB control */
325 #define CSR_GTLBC_TGID_SHIFT 16
326 #define CSR_GTLBC_TGID_WIDTH 8
327 #define CSR_GTLBC_TGID_SHIFT_END (CSR_GTLBC_TGID_SHIFT + CSR_GTLBC_TGID_WIDTH - 1)
328 #define CSR_GTLBC_TGID (_ULCAST_(0xff) << CSR_GTLBC_TGID_SHIFT)
329 #define CSR_GTLBC_TOTI_SHIFT 13
330 #define CSR_GTLBC_TOTI (_ULCAST_(0x1) << CSR_GTLBC_TOTI_SHIFT)
331 #define CSR_GTLBC_USETGID_SHIFT 12
332 #define CSR_GTLBC_USETGID (_ULCAST_(0x1) << CSR_GTLBC_USETGID_SHIFT)
333 #define CSR_GTLBC_GMTLBSZ_SHIFT 0
334 #define CSR_GTLBC_GMTLBSZ_WIDTH 6
335 #define CSR_GTLBC_GMTLBSZ (_ULCAST_(0x3f) << CSR_GTLBC_GMTLBSZ_SHIFT)
336
337 #define LOONGARCH_CSR_TRGP 0x16 /* TLBR read guest info */
338 #define CSR_TRGP_RID_SHIFT 16
339 #define CSR_TRGP_RID_WIDTH 8
340 #define CSR_TRGP_RID (_ULCAST_(0xff) << CSR_TRGP_RID_SHIFT)
341 #define CSR_TRGP_GTLB_SHIFT 0
342 #define CSR_TRGP_GTLB (1 << CSR_TRGP_GTLB_SHIFT)
343
344 #define LOONGARCH_CSR_ASID 0x18 /* ASID */
345 #define CSR_ASID_BIT_SHIFT 16 /* ASIDBits */
346 #define CSR_ASID_BIT_WIDTH 8
347 #define CSR_ASID_BIT (_ULCAST_(0xff) << CSR_ASID_BIT_SHIFT)
348 #define CSR_ASID_ASID_SHIFT 0
349 #define CSR_ASID_ASID_WIDTH 10
350 #define CSR_ASID_ASID (_ULCAST_(0x3ff) << CSR_ASID_ASID_SHIFT)
351
352 #define LOONGARCH_CSR_PGDL 0x19 /* Page table base address when VA[VALEN-1] = 0 */
353
354 #define LOONGARCH_CSR_PGDH 0x1a /* Page table base address when VA[VALEN-1] = 1 */
355
356 #define LOONGARCH_CSR_PGD 0x1b /* Page table base */
357
358 #define LOONGARCH_CSR_PWCTL0 0x1c /* PWCtl0 */
359 #define CSR_PWCTL0_PTEW_SHIFT 30
360 #define CSR_PWCTL0_PTEW_WIDTH 2
361 #define CSR_PWCTL0_PTEW (_ULCAST_(0x3) << CSR_PWCTL0_PTEW_SHIFT)
362 #define CSR_PWCTL0_DIR1WIDTH_SHIFT 25
363 #define CSR_PWCTL0_DIR1WIDTH_WIDTH 5
364 #define CSR_PWCTL0_DIR1WIDTH (_ULCAST_(0x1f) << CSR_PWCTL0_DIR1WIDTH_SHIFT)
365 #define CSR_PWCTL0_DIR1BASE_SHIFT 20
366 #define CSR_PWCTL0_DIR1BASE_WIDTH 5
367 #define CSR_PWCTL0_DIR1BASE (_ULCAST_(0x1f) << CSR_PWCTL0_DIR1BASE_SHIFT)
368 #define CSR_PWCTL0_DIR0WIDTH_SHIFT 15
369 #define CSR_PWCTL0_DIR0WIDTH_WIDTH 5
370 #define CSR_PWCTL0_DIR0WIDTH (_ULCAST_(0x1f) << CSR_PWCTL0_DIR0WIDTH_SHIFT)
371 #define CSR_PWCTL0_DIR0BASE_SHIFT 10
372 #define CSR_PWCTL0_DIR0BASE_WIDTH 5
373 #define CSR_PWCTL0_DIR0BASE (_ULCAST_(0x1f) << CSR_PWCTL0_DIR0BASE_SHIFT)
374 #define CSR_PWCTL0_PTWIDTH_SHIFT 5
375 #define CSR_PWCTL0_PTWIDTH_WIDTH 5
376 #define CSR_PWCTL0_PTWIDTH (_ULCAST_(0x1f) << CSR_PWCTL0_PTWIDTH_SHIFT)
377 #define CSR_PWCTL0_PTBASE_SHIFT 0
378 #define CSR_PWCTL0_PTBASE_WIDTH 5
379 #define CSR_PWCTL0_PTBASE (_ULCAST_(0x1f) << CSR_PWCTL0_PTBASE_SHIFT)
380
381 #define LOONGARCH_CSR_PWCTL1 0x1d /* PWCtl1 */
382 #define CSR_PWCTL1_PTW_SHIFT 24
383 #define CSR_PWCTL1_PTW_WIDTH 1
384 #define CSR_PWCTL1_PTW (_ULCAST_(0x1) << CSR_PWCTL1_PTW_SHIFT)
385 #define CSR_PWCTL1_DIR3WIDTH_SHIFT 18
386 #define CSR_PWCTL1_DIR3WIDTH_WIDTH 5
387 #define CSR_PWCTL1_DIR3WIDTH (_ULCAST_(0x1f) << CSR_PWCTL1_DIR3WIDTH_SHIFT)
388 #define CSR_PWCTL1_DIR3BASE_SHIFT 12
389 #define CSR_PWCTL1_DIR3BASE_WIDTH 5
390 #define CSR_PWCTL1_DIR3BASE (_ULCAST_(0x1f) << CSR_PWCTL0_DIR3BASE_SHIFT)
391 #define CSR_PWCTL1_DIR2WIDTH_SHIFT 6
392 #define CSR_PWCTL1_DIR2WIDTH_WIDTH 5
393 #define CSR_PWCTL1_DIR2WIDTH (_ULCAST_(0x1f) << CSR_PWCTL1_DIR2WIDTH_SHIFT)
394 #define CSR_PWCTL1_DIR2BASE_SHIFT 0
395 #define CSR_PWCTL1_DIR2BASE_WIDTH 5
396 #define CSR_PWCTL1_DIR2BASE (_ULCAST_(0x1f) << CSR_PWCTL0_DIR2BASE_SHIFT)
397
398 #define LOONGARCH_CSR_STLBPGSIZE 0x1e
399 #define CSR_STLBPGSIZE_PS_WIDTH 6
400 #define CSR_STLBPGSIZE_PS (_ULCAST_(0x3f))
401
402 #define LOONGARCH_CSR_RVACFG 0x1f
403 #define CSR_RVACFG_RDVA_WIDTH 4
404 #define CSR_RVACFG_RDVA (_ULCAST_(0xf))
405
406 /* Config CSR registers */
407 #define LOONGARCH_CSR_CPUID 0x20 /* CPU core id */
408 #define CSR_CPUID_COREID_WIDTH 9
409 #define CSR_CPUID_COREID _ULCAST_(0x1ff)
410
411 #define LOONGARCH_CSR_PRCFG1 0x21 /* Config1 */
412 #define CSR_CONF1_VSMAX_SHIFT 12
413 #define CSR_CONF1_VSMAX_WIDTH 3
414 #define CSR_CONF1_VSMAX (_ULCAST_(7) << CSR_CONF1_VSMAX_SHIFT)
415 #define CSR_CONF1_TMRBITS_SHIFT 4
416 #define CSR_CONF1_TMRBITS_WIDTH 8
417 #define CSR_CONF1_TMRBITS (_ULCAST_(0xff) << CSR_CONF1_TMRBITS_SHIFT)
418 #define CSR_CONF1_KSNUM_WIDTH 4
419 #define CSR_CONF1_KSNUM _ULCAST_(0xf)
420
421 #define LOONGARCH_CSR_PRCFG2 0x22 /* Config2 */
422 #define CSR_CONF2_PGMASK_SUPP 0x3ffff000
423
424 #define LOONGARCH_CSR_PRCFG3 0x23 /* Config3 */
425 #define CSR_CONF3_STLBIDX_SHIFT 20
426 #define CSR_CONF3_STLBIDX_WIDTH 6
427 #define CSR_CONF3_STLBIDX (_ULCAST_(0x3f) << CSR_CONF3_STLBIDX_SHIFT)
428 #define CSR_CONF3_STLBWAYS_SHIFT 12
429 #define CSR_CONF3_STLBWAYS_WIDTH 8
430 #define CSR_CONF3_STLBWAYS (_ULCAST_(0xff) << CSR_CONF3_STLBWAYS_SHIFT)
431 #define CSR_CONF3_MTLBSIZE_SHIFT 4
432 #define CSR_CONF3_MTLBSIZE_WIDTH 8
433 #define CSR_CONF3_MTLBSIZE (_ULCAST_(0xff) << CSR_CONF3_MTLBSIZE_SHIFT)
434 #define CSR_CONF3_TLBTYPE_SHIFT 0
435 #define CSR_CONF3_TLBTYPE_WIDTH 4
436 #define CSR_CONF3_TLBTYPE (_ULCAST_(0xf) << CSR_CONF3_TLBTYPE_SHIFT)
437
438 /* KSave registers */
439 #define LOONGARCH_CSR_KS0 0x30
440 #define LOONGARCH_CSR_KS1 0x31
441 #define LOONGARCH_CSR_KS2 0x32
442 #define LOONGARCH_CSR_KS3 0x33
443 #define LOONGARCH_CSR_KS4 0x34
444 #define LOONGARCH_CSR_KS5 0x35
445 #define LOONGARCH_CSR_KS6 0x36
446 #define LOONGARCH_CSR_KS7 0x37
447 #define LOONGARCH_CSR_KS8 0x38
448
449 /* Exception allocated KS0, KS1 and KS2 statically */
450 #define EXCEPTION_KS0 LOONGARCH_CSR_KS0
451 #define EXCEPTION_KS1 LOONGARCH_CSR_KS1
452 #define EXCEPTION_KS2 LOONGARCH_CSR_KS2
453 #define EXC_KSAVE_MASK (1 << 0 | 1 << 1 | 1 << 2)
454
455 /* Percpu-data base allocated KS3 statically */
456 #define PERCPU_BASE_KS LOONGARCH_CSR_KS3
457 #define PERCPU_KSAVE_MASK (1 << 3)
458
459 /* KVM allocated KS4 and KS5 statically */
460 #define KVM_VCPU_KS LOONGARCH_CSR_KS4
461 #define KVM_TEMP_KS LOONGARCH_CSR_KS5
462 #define KVM_KSAVE_MASK (1 << 4 | 1 << 5)
463
464 /* Timer registers */
465 #define LOONGARCH_CSR_TMID 0x40 /* Timer ID */
466
467 #define LOONGARCH_CSR_TCFG 0x41 /* Timer config */
468 #define CSR_TCFG_VAL_SHIFT 2
469 #define CSR_TCFG_VAL_WIDTH 48
470 #define CSR_TCFG_VAL (_ULCAST_(0x3fffffffffff) << CSR_TCFG_VAL_SHIFT)
471 #define CSR_TCFG_PERIOD_SHIFT 1
472 #define CSR_TCFG_PERIOD (_ULCAST_(0x1) << CSR_TCFG_PERIOD_SHIFT)
473 #define CSR_TCFG_EN (_ULCAST_(0x1))
474
475 #define LOONGARCH_CSR_TVAL 0x42 /* Timer value */
476
477 #define LOONGARCH_CSR_CNTC 0x43 /* Timer offset */
478
479 #define LOONGARCH_CSR_TINTCLR 0x44 /* Timer interrupt clear */
480 #define CSR_TINTCLR_TI_SHIFT 0
481 #define CSR_TINTCLR_TI (1 << CSR_TINTCLR_TI_SHIFT)
482
483 /* Guest registers */
484 #define LOONGARCH_CSR_GSTAT 0x50 /* Guest status */
485 #define CSR_GSTAT_GID_SHIFT 16
486 #define CSR_GSTAT_GID_WIDTH 8
487 #define CSR_GSTAT_GID_SHIFT_END (CSR_GSTAT_GID_SHIFT + CSR_GSTAT_GID_WIDTH - 1)
488 #define CSR_GSTAT_GID (_ULCAST_(0xff) << CSR_GSTAT_GID_SHIFT)
489 #define CSR_GSTAT_GIDBIT_SHIFT 4
490 #define CSR_GSTAT_GIDBIT_WIDTH 6
491 #define CSR_GSTAT_GIDBIT (_ULCAST_(0x3f) << CSR_GSTAT_GIDBIT_SHIFT)
492 #define CSR_GSTAT_PVM_SHIFT 1
493 #define CSR_GSTAT_PVM (_ULCAST_(0x1) << CSR_GSTAT_PVM_SHIFT)
494 #define CSR_GSTAT_VM_SHIFT 0
495 #define CSR_GSTAT_VM (_ULCAST_(0x1) << CSR_GSTAT_VM_SHIFT)
496
497 #define LOONGARCH_CSR_GCFG 0x51 /* Guest config */
498 #define CSR_GCFG_GPERF_SHIFT 24
499 #define CSR_GCFG_GPERF_WIDTH 3
500 #define CSR_GCFG_GPERF (_ULCAST_(0x7) << CSR_GCFG_GPERF_SHIFT)
501 #define CSR_GCFG_GCI_SHIFT 20
502 #define CSR_GCFG_GCI_WIDTH 2
503 #define CSR_GCFG_GCI (_ULCAST_(0x3) << CSR_GCFG_GCI_SHIFT)
504 #define CSR_GCFG_GCI_ALL (_ULCAST_(0x0) << CSR_GCFG_GCI_SHIFT)
505 #define CSR_GCFG_GCI_HIT (_ULCAST_(0x1) << CSR_GCFG_GCI_SHIFT)
506 #define CSR_GCFG_GCI_SECURE (_ULCAST_(0x2) << CSR_GCFG_GCI_SHIFT)
507 #define CSR_GCFG_GCIP_SHIFT 16
508 #define CSR_GCFG_GCIP (_ULCAST_(0xf) << CSR_GCFG_GCIP_SHIFT)
509 #define CSR_GCFG_GCIP_ALL (_ULCAST_(0x1) << CSR_GCFG_GCIP_SHIFT)
510 #define CSR_GCFG_GCIP_HIT (_ULCAST_(0x1) << (CSR_GCFG_GCIP_SHIFT + 1))
511 #define CSR_GCFG_GCIP_SECURE (_ULCAST_(0x1) << (CSR_GCFG_GCIP_SHIFT + 2))
512 #define CSR_GCFG_TORU_SHIFT 15
513 #define CSR_GCFG_TORU (_ULCAST_(0x1) << CSR_GCFG_TORU_SHIFT)
514 #define CSR_GCFG_TORUP_SHIFT 14
515 #define CSR_GCFG_TORUP (_ULCAST_(0x1) << CSR_GCFG_TORUP_SHIFT)
516 #define CSR_GCFG_TOP_SHIFT 13
517 #define CSR_GCFG_TOP (_ULCAST_(0x1) << CSR_GCFG_TOP_SHIFT)
518 #define CSR_GCFG_TOPP_SHIFT 12
519 #define CSR_GCFG_TOPP (_ULCAST_(0x1) << CSR_GCFG_TOPP_SHIFT)
520 #define CSR_GCFG_TOE_SHIFT 11
521 #define CSR_GCFG_TOE (_ULCAST_(0x1) << CSR_GCFG_TOE_SHIFT)
522 #define CSR_GCFG_TOEP_SHIFT 10
523 #define CSR_GCFG_TOEP (_ULCAST_(0x1) << CSR_GCFG_TOEP_SHIFT)
524 #define CSR_GCFG_TIT_SHIFT 9
525 #define CSR_GCFG_TIT (_ULCAST_(0x1) << CSR_GCFG_TIT_SHIFT)
526 #define CSR_GCFG_TITP_SHIFT 8
527 #define CSR_GCFG_TITP (_ULCAST_(0x1) << CSR_GCFG_TITP_SHIFT)
528 #define CSR_GCFG_SIT_SHIFT 7
529 #define CSR_GCFG_SIT (_ULCAST_(0x1) << CSR_GCFG_SIT_SHIFT)
530 #define CSR_GCFG_SITP_SHIFT 6
531 #define CSR_GCFG_SITP (_ULCAST_(0x1) << CSR_GCFG_SITP_SHIFT)
532 #define CSR_GCFG_MATC_SHITF 4
533 #define CSR_GCFG_MATC_WIDTH 2
534 #define CSR_GCFG_MATC_MASK (_ULCAST_(0x3) << CSR_GCFG_MATC_SHITF)
535 #define CSR_GCFG_MATC_GUEST (_ULCAST_(0x0) << CSR_GCFG_MATC_SHITF)
536 #define CSR_GCFG_MATC_ROOT (_ULCAST_(0x1) << CSR_GCFG_MATC_SHITF)
537 #define CSR_GCFG_MATC_NEST (_ULCAST_(0x2) << CSR_GCFG_MATC_SHITF)
538 #define CSR_GCFG_MATP_NEST_SHIFT 2
539 #define CSR_GCFG_MATP_NEST (_ULCAST_(0x1) << CSR_GCFG_MATP_NEST_SHIFT)
540 #define CSR_GCFG_MATP_ROOT_SHIFT 1
541 #define CSR_GCFG_MATP_ROOT (_ULCAST_(0x1) << CSR_GCFG_MATP_ROOT_SHIFT)
542 #define CSR_GCFG_MATP_GUEST_SHIFT 0
543 #define CSR_GCFG_MATP_GUEST (_ULCAST_(0x1) << CSR_GCFG_MATP_GUEST_SHIFT)
544
545 #define LOONGARCH_CSR_GINTC 0x52 /* Guest interrupt control */
546 #define CSR_GINTC_HC_SHIFT 16
547 #define CSR_GINTC_HC_WIDTH 8
548 #define CSR_GINTC_HC (_ULCAST_(0xff) << CSR_GINTC_HC_SHIFT)
549 #define CSR_GINTC_PIP_SHIFT 8
550 #define CSR_GINTC_PIP_WIDTH 8
551 #define CSR_GINTC_PIP (_ULCAST_(0xff) << CSR_GINTC_PIP_SHIFT)
552 #define CSR_GINTC_VIP_SHIFT 0
553 #define CSR_GINTC_VIP_WIDTH 8
554 #define CSR_GINTC_VIP (_ULCAST_(0xff))
555
556 #define LOONGARCH_CSR_GCNTC 0x53 /* Guest timer offset */
557
558 /* LLBCTL register */
559 #define LOONGARCH_CSR_LLBCTL 0x60 /* LLBit control */
560 #define CSR_LLBCTL_ROLLB_SHIFT 0
561 #define CSR_LLBCTL_ROLLB (_ULCAST_(1) << CSR_LLBCTL_ROLLB_SHIFT)
562 #define CSR_LLBCTL_WCLLB_SHIFT 1
563 #define CSR_LLBCTL_WCLLB (_ULCAST_(1) << CSR_LLBCTL_WCLLB_SHIFT)
564 #define CSR_LLBCTL_KLO_SHIFT 2
565 #define CSR_LLBCTL_KLO (_ULCAST_(1) << CSR_LLBCTL_KLO_SHIFT)
566
567 /* Implement dependent */
568 #define LOONGARCH_CSR_IMPCTL1 0x80 /* Loongson config1 */
569 #define CSR_MISPEC_SHIFT 20
570 #define CSR_MISPEC_WIDTH 8
571 #define CSR_MISPEC (_ULCAST_(0xff) << CSR_MISPEC_SHIFT)
572 #define CSR_SSEN_SHIFT 18
573 #define CSR_SSEN (_ULCAST_(1) << CSR_SSEN_SHIFT)
574 #define CSR_SCRAND_SHIFT 17
575 #define CSR_SCRAND (_ULCAST_(1) << CSR_SCRAND_SHIFT)
576 #define CSR_LLEXCL_SHIFT 16
577 #define CSR_LLEXCL (_ULCAST_(1) << CSR_LLEXCL_SHIFT)
578 #define CSR_DISVC_SHIFT 15
579 #define CSR_DISVC (_ULCAST_(1) << CSR_DISVC_SHIFT)
580 #define CSR_VCLRU_SHIFT 14
581 #define CSR_VCLRU (_ULCAST_(1) << CSR_VCLRU_SHIFT)
582 #define CSR_DCLRU_SHIFT 13
583 #define CSR_DCLRU (_ULCAST_(1) << CSR_DCLRU_SHIFT)
584 #define CSR_FASTLDQ_SHIFT 12
585 #define CSR_FASTLDQ (_ULCAST_(1) << CSR_FASTLDQ_SHIFT)
586 #define CSR_USERCAC_SHIFT 11
587 #define CSR_USERCAC (_ULCAST_(1) << CSR_USERCAC_SHIFT)
588 #define CSR_ANTI_MISPEC_SHIFT 10
589 #define CSR_ANTI_MISPEC (_ULCAST_(1) << CSR_ANTI_MISPEC_SHIFT)
590 #define CSR_AUTO_FLUSHSFB_SHIFT 9
591 #define CSR_AUTO_FLUSHSFB (_ULCAST_(1) << CSR_AUTO_FLUSHSFB_SHIFT)
592 #define CSR_STFILL_SHIFT 8
593 #define CSR_STFILL (_ULCAST_(1) << CSR_STFILL_SHIFT)
594 #define CSR_LIFEP_SHIFT 7
595 #define CSR_LIFEP (_ULCAST_(1) << CSR_LIFEP_SHIFT)
596 #define CSR_LLSYNC_SHIFT 6
597 #define CSR_LLSYNC (_ULCAST_(1) << CSR_LLSYNC_SHIFT)
598 #define CSR_BRBTDIS_SHIFT 5
599 #define CSR_BRBTDIS (_ULCAST_(1) << CSR_BRBTDIS_SHIFT)
600 #define CSR_RASDIS_SHIFT 4
601 #define CSR_RASDIS (_ULCAST_(1) << CSR_RASDIS_SHIFT)
602 #define CSR_STPRE_SHIFT 2
603 #define CSR_STPRE_WIDTH 2
604 #define CSR_STPRE (_ULCAST_(3) << CSR_STPRE_SHIFT)
605 #define CSR_INSTPRE_SHIFT 1
606 #define CSR_INSTPRE (_ULCAST_(1) << CSR_INSTPRE_SHIFT)
607 #define CSR_DATAPRE_SHIFT 0
608 #define CSR_DATAPRE (_ULCAST_(1) << CSR_DATAPRE_SHIFT)
609
610 #define LOONGARCH_CSR_IMPCTL2 0x81 /* Loongson config2 */
611 #define CSR_FLUSH_MTLB_SHIFT 0
612 #define CSR_FLUSH_MTLB (_ULCAST_(1) << CSR_FLUSH_MTLB_SHIFT)
613 #define CSR_FLUSH_STLB_SHIFT 1
614 #define CSR_FLUSH_STLB (_ULCAST_(1) << CSR_FLUSH_STLB_SHIFT)
615 #define CSR_FLUSH_DTLB_SHIFT 2
616 #define CSR_FLUSH_DTLB (_ULCAST_(1) << CSR_FLUSH_DTLB_SHIFT)
617 #define CSR_FLUSH_ITLB_SHIFT 3
618 #define CSR_FLUSH_ITLB (_ULCAST_(1) << CSR_FLUSH_ITLB_SHIFT)
619 #define CSR_FLUSH_BTAC_SHIFT 4
620 #define CSR_FLUSH_BTAC (_ULCAST_(1) << CSR_FLUSH_BTAC_SHIFT)
621
622 #define LOONGARCH_CSR_GNMI 0x82
623
624 /* TLB Refill registers */
625 #define LOONGARCH_CSR_TLBRENTRY 0x88 /* TLB refill exception entry */
626 #define LOONGARCH_CSR_TLBRBADV 0x89 /* TLB refill badvaddr */
627 #define LOONGARCH_CSR_TLBRERA 0x8a /* TLB refill ERA */
628 #define LOONGARCH_CSR_TLBRSAVE 0x8b /* KSave for TLB refill exception */
629 #define LOONGARCH_CSR_TLBRELO0 0x8c /* TLB refill entrylo0 */
630 #define LOONGARCH_CSR_TLBRELO1 0x8d /* TLB refill entrylo1 */
631 #define LOONGARCH_CSR_TLBREHI 0x8e /* TLB refill entryhi */
632 #define CSR_TLBREHI_PS_SHIFT 0
633 #define CSR_TLBREHI_PS (_ULCAST_(0x3f) << CSR_TLBREHI_PS_SHIFT)
634 #define LOONGARCH_CSR_TLBRPRMD 0x8f /* TLB refill mode info */
635
636 /* Machine Error registers */
637 #define LOONGARCH_CSR_MERRCTL 0x90 /* MERRCTL */
638 #define LOONGARCH_CSR_MERRINFO1 0x91 /* MError info1 */
639 #define LOONGARCH_CSR_MERRINFO2 0x92 /* MError info2 */
640 #define LOONGARCH_CSR_MERRENTRY 0x93 /* MError exception entry */
641 #define LOONGARCH_CSR_MERRERA 0x94 /* MError exception ERA */
642 #define LOONGARCH_CSR_MERRSAVE 0x95 /* KSave for machine error exception */
643
644 #define LOONGARCH_CSR_CTAG 0x98 /* TagLo + TagHi */
645
646 #define LOONGARCH_CSR_ISR0 0xa0
647 #define LOONGARCH_CSR_ISR1 0xa1
648 #define LOONGARCH_CSR_ISR2 0xa2
649 #define LOONGARCH_CSR_ISR3 0xa3
650
651 #define LOONGARCH_CSR_IRR 0xa4
652
653 #define LOONGARCH_CSR_PRID 0xc0
654
655 /* Shadow MCSR : 0xc0 ~ 0xff */
656 #define LOONGARCH_CSR_MCSR0 0xc0 /* CPUCFG0 and CPUCFG1 */
657 #define MCSR0_INT_IMPL_SHIFT 58
658 #define MCSR0_INT_IMPL 0
659 #define MCSR0_IOCSR_BRD_SHIFT 57
660 #define MCSR0_IOCSR_BRD (_ULCAST_(1) << MCSR0_IOCSR_BRD_SHIFT)
661 #define MCSR0_HUGEPG_SHIFT 56
662 #define MCSR0_HUGEPG (_ULCAST_(1) << MCSR0_HUGEPG_SHIFT)
663 #define MCSR0_RPLMTLB_SHIFT 55
664 #define MCSR0_RPLMTLB (_ULCAST_(1) << MCSR0_RPLMTLB_SHIFT)
665 #define MCSR0_EP_SHIFT 54
666 #define MCSR0_EP (_ULCAST_(1) << MCSR0_EP_SHIFT)
667 #define MCSR0_RI_SHIFT 53
668 #define MCSR0_RI (_ULCAST_(1) << MCSR0_RI_SHIFT)
669 #define MCSR0_UAL_SHIFT 52
670 #define MCSR0_UAL (_ULCAST_(1) << MCSR0_UAL_SHIFT)
671 #define MCSR0_VABIT_SHIFT 44
672 #define MCSR0_VABIT_WIDTH 8
673 #define MCSR0_VABIT (_ULCAST_(0xff) << MCSR0_VABIT_SHIFT)
674 #define VABIT_DEFAULT 0x2f
675 #define MCSR0_PABIT_SHIFT 36
676 #define MCSR0_PABIT_WIDTH 8
677 #define MCSR0_PABIT (_ULCAST_(0xff) << MCSR0_PABIT_SHIFT)
678 #define PABIT_DEFAULT 0x2f
679 #define MCSR0_IOCSR_SHIFT 35
680 #define MCSR0_IOCSR (_ULCAST_(1) << MCSR0_IOCSR_SHIFT)
681 #define MCSR0_PAGING_SHIFT 34
682 #define MCSR0_PAGING (_ULCAST_(1) << MCSR0_PAGING_SHIFT)
683 #define MCSR0_GR64_SHIFT 33
684 #define MCSR0_GR64 (_ULCAST_(1) << MCSR0_GR64_SHIFT)
685 #define GR64_DEFAULT 1
686 #define MCSR0_GR32_SHIFT 32
687 #define MCSR0_GR32 (_ULCAST_(1) << MCSR0_GR32_SHIFT)
688 #define GR32_DEFAULT 0
689 #define MCSR0_PRID_WIDTH 32
690 #define MCSR0_PRID 0x14C010
691
692 #define LOONGARCH_CSR_MCSR1 0xc1 /* CPUCFG2 and CPUCFG3 */
693 #define MCSR1_HPFOLD_SHIFT 43
694 #define MCSR1_HPFOLD (_ULCAST_(1) << MCSR1_HPFOLD_SHIFT)
695 #define MCSR1_SPW_LVL_SHIFT 40
696 #define MCSR1_SPW_LVL_WIDTH 3
697 #define MCSR1_SPW_LVL (_ULCAST_(7) << MCSR1_SPW_LVL_SHIFT)
698 #define MCSR1_ICACHET_SHIFT 39
699 #define MCSR1_ICACHET (_ULCAST_(1) << MCSR1_ICACHET_SHIFT)
700 #define MCSR1_ITLBT_SHIFT 38
701 #define MCSR1_ITLBT (_ULCAST_(1) << MCSR1_ITLBT_SHIFT)
702 #define MCSR1_LLDBAR_SHIFT 37
703 #define MCSR1_LLDBAR (_ULCAST_(1) << MCSR1_LLDBAR_SHIFT)
704 #define MCSR1_SCDLY_SHIFT 36
705 #define MCSR1_SCDLY (_ULCAST_(1) << MCSR1_SCDLY_SHIFT)
706 #define MCSR1_LLEXC_SHIFT 35
707 #define MCSR1_LLEXC (_ULCAST_(1) << MCSR1_LLEXC_SHIFT)
708 #define MCSR1_UCACC_SHIFT 34
709 #define MCSR1_UCACC (_ULCAST_(1) << MCSR1_UCACC_SHIFT)
710 #define MCSR1_SFB_SHIFT 33
711 #define MCSR1_SFB (_ULCAST_(1) << MCSR1_SFB_SHIFT)
712 #define MCSR1_CCDMA_SHIFT 32
713 #define MCSR1_CCDMA (_ULCAST_(1) << MCSR1_CCDMA_SHIFT)
714 #define MCSR1_LAMO_SHIFT 22
715 #define MCSR1_LAMO (_ULCAST_(1) << MCSR1_LAMO_SHIFT)
716 #define MCSR1_LSPW_SHIFT 21
717 #define MCSR1_LSPW (_ULCAST_(1) << MCSR1_LSPW_SHIFT)
718 #define MCSR1_MIPSBT_SHIFT 20
719 #define MCSR1_MIPSBT (_ULCAST_(1) << MCSR1_MIPSBT_SHIFT)
720 #define MCSR1_ARMBT_SHIFT 19
721 #define MCSR1_ARMBT (_ULCAST_(1) << MCSR1_ARMBT_SHIFT)
722 #define MCSR1_X86BT_SHIFT 18
723 #define MCSR1_X86BT (_ULCAST_(1) << MCSR1_X86BT_SHIFT)
724 #define MCSR1_LLFTPVERS_SHIFT 15
725 #define MCSR1_LLFTPVERS_WIDTH 3
726 #define MCSR1_LLFTPVERS (_ULCAST_(7) << MCSR1_LLFTPVERS_SHIFT)
727 #define MCSR1_LLFTP_SHIFT 14
728 #define MCSR1_LLFTP (_ULCAST_(1) << MCSR1_LLFTP_SHIFT)
729 #define MCSR1_VZVERS_SHIFT 11
730 #define MCSR1_VZVERS_WIDTH 3
731 #define MCSR1_VZVERS (_ULCAST_(7) << MCSR1_VZVERS_SHIFT)
732 #define MCSR1_VZ_SHIFT 10
733 #define MCSR1_VZ (_ULCAST_(1) << MCSR1_VZ_SHIFT)
734 #define MCSR1_CRYPTO_SHIFT 9
735 #define MCSR1_CRYPTO (_ULCAST_(1) << MCSR1_CRYPTO_SHIFT)
736 #define MCSR1_COMPLEX_SHIFT 8
737 #define MCSR1_COMPLEX (_ULCAST_(1) << MCSR1_COMPLEX_SHIFT)
738 #define MCSR1_LASX_SHIFT 7
739 #define MCSR1_LASX (_ULCAST_(1) << MCSR1_LASX_SHIFT)
740 #define MCSR1_LSX_SHIFT 6
741 #define MCSR1_LSX (_ULCAST_(1) << MCSR1_LSX_SHIFT)
742 #define MCSR1_FPVERS_SHIFT 3
743 #define MCSR1_FPVERS_WIDTH 3
744 #define MCSR1_FPVERS (_ULCAST_(7) << MCSR1_FPVERS_SHIFT)
745 #define MCSR1_FPDP_SHIFT 2
746 #define MCSR1_FPDP (_ULCAST_(1) << MCSR1_FPDP_SHIFT)
747 #define MCSR1_FPSP_SHIFT 1
748 #define MCSR1_FPSP (_ULCAST_(1) << MCSR1_FPSP_SHIFT)
749 #define MCSR1_FP_SHIFT 0
750 #define MCSR1_FP (_ULCAST_(1) << MCSR1_FP_SHIFT)
751
752 #define LOONGARCH_CSR_MCSR2 0xc2 /* CPUCFG4 and CPUCFG5 */
753 #define MCSR2_CCDIV_SHIFT 48
754 #define MCSR2_CCDIV_WIDTH 16
755 #define MCSR2_CCDIV (_ULCAST_(0xffff) << MCSR2_CCDIV_SHIFT)
756 #define MCSR2_CCMUL_SHIFT 32
757 #define MCSR2_CCMUL_WIDTH 16
758 #define MCSR2_CCMUL (_ULCAST_(0xffff) << MCSR2_CCMUL_SHIFT)
759 #define MCSR2_CCFREQ_WIDTH 32
760 #define MCSR2_CCFREQ (_ULCAST_(0xffffffff))
761 #define CCFREQ_DEFAULT 0x5f5e100 /* 100MHz */
762
763 #define LOONGARCH_CSR_MCSR3 0xc3 /* CPUCFG6 */
764 #define MCSR3_UPM_SHIFT 14
765 #define MCSR3_UPM (_ULCAST_(1) << MCSR3_UPM_SHIFT)
766 #define MCSR3_PMBITS_SHIFT 8
767 #define MCSR3_PMBITS_WIDTH 6
768 #define MCSR3_PMBITS (_ULCAST_(0x3f) << MCSR3_PMBITS_SHIFT)
769 #define PMBITS_DEFAULT 0x40
770 #define MCSR3_PMNUM_SHIFT 4
771 #define MCSR3_PMNUM_WIDTH 4
772 #define MCSR3_PMNUM (_ULCAST_(0xf) << MCSR3_PMNUM_SHIFT)
773 #define MCSR3_PAMVER_SHIFT 1
774 #define MCSR3_PAMVER_WIDTH 3
775 #define MCSR3_PAMVER (_ULCAST_(0x7) << MCSR3_PAMVER_SHIFT)
776 #define MCSR3_PMP_SHIFT 0
777 #define MCSR3_PMP (_ULCAST_(1) << MCSR3_PMP_SHIFT)
778
779 #define LOONGARCH_CSR_MCSR8 0xc8 /* CPUCFG16 and CPUCFG17 */
780 #define MCSR8_L1I_SIZE_SHIFT 56
781 #define MCSR8_L1I_SIZE_WIDTH 7
782 #define MCSR8_L1I_SIZE (_ULCAST_(0x7f) << MCSR8_L1I_SIZE_SHIFT)
783 #define MCSR8_L1I_IDX_SHIFT 48
784 #define MCSR8_L1I_IDX_WIDTH 8
785 #define MCSR8_L1I_IDX (_ULCAST_(0xff) << MCSR8_L1I_IDX_SHIFT)
786 #define MCSR8_L1I_WAY_SHIFT 32
787 #define MCSR8_L1I_WAY_WIDTH 16
788 #define MCSR8_L1I_WAY (_ULCAST_(0xffff) << MCSR8_L1I_WAY_SHIFT)
789 #define MCSR8_L3DINCL_SHIFT 16
790 #define MCSR8_L3DINCL (_ULCAST_(1) << MCSR8_L3DINCL_SHIFT)
791 #define MCSR8_L3DPRIV_SHIFT 15
792 #define MCSR8_L3DPRIV (_ULCAST_(1) << MCSR8_L3DPRIV_SHIFT)
793 #define MCSR8_L3DPRE_SHIFT 14
794 #define MCSR8_L3DPRE (_ULCAST_(1) << MCSR8_L3DPRE_SHIFT)
795 #define MCSR8_L3IUINCL_SHIFT 13
796 #define MCSR8_L3IUINCL (_ULCAST_(1) << MCSR8_L3IUINCL_SHIFT)
797 #define MCSR8_L3IUPRIV_SHIFT 12
798 #define MCSR8_L3IUPRIV (_ULCAST_(1) << MCSR8_L3IUPRIV_SHIFT)
799 #define MCSR8_L3IUUNIFY_SHIFT 11
800 #define MCSR8_L3IUUNIFY (_ULCAST_(1) << MCSR8_L3IUUNIFY_SHIFT)
801 #define MCSR8_L3IUPRE_SHIFT 10
802 #define MCSR8_L3IUPRE (_ULCAST_(1) << MCSR8_L3IUPRE_SHIFT)
803 #define MCSR8_L2DINCL_SHIFT 9
804 #define MCSR8_L2DINCL (_ULCAST_(1) << MCSR8_L2DINCL_SHIFT)
805 #define MCSR8_L2DPRIV_SHIFT 8
806 #define MCSR8_L2DPRIV (_ULCAST_(1) << MCSR8_L2DPRIV_SHIFT)
807 #define MCSR8_L2DPRE_SHIFT 7
808 #define MCSR8_L2DPRE (_ULCAST_(1) << MCSR8_L2DPRE_SHIFT)
809 #define MCSR8_L2IUINCL_SHIFT 6
810 #define MCSR8_L2IUINCL (_ULCAST_(1) << MCSR8_L2IUINCL_SHIFT)
811 #define MCSR8_L2IUPRIV_SHIFT 5
812 #define MCSR8_L2IUPRIV (_ULCAST_(1) << MCSR8_L2IUPRIV_SHIFT)
813 #define MCSR8_L2IUUNIFY_SHIFT 4
814 #define MCSR8_L2IUUNIFY (_ULCAST_(1) << MCSR8_L2IUUNIFY_SHIFT)
815 #define MCSR8_L2IUPRE_SHIFT 3
816 #define MCSR8_L2IUPRE (_ULCAST_(1) << MCSR8_L2IUPRE_SHIFT)
817 #define MCSR8_L1DPRE_SHIFT 2
818 #define MCSR8_L1DPRE (_ULCAST_(1) << MCSR8_L1DPRE_SHIFT)
819 #define MCSR8_L1IUUNIFY_SHIFT 1
820 #define MCSR8_L1IUUNIFY (_ULCAST_(1) << MCSR8_L1IUUNIFY_SHIFT)
821 #define MCSR8_L1IUPRE_SHIFT 0
822 #define MCSR8_L1IUPRE (_ULCAST_(1) << MCSR8_L1IUPRE_SHIFT)
823
824 #define LOONGARCH_CSR_MCSR9 0xc9 /* CPUCFG18 and CPUCFG19 */
825 #define MCSR9_L2U_SIZE_SHIFT 56
826 #define MCSR9_L2U_SIZE_WIDTH 7
827 #define MCSR9_L2U_SIZE (_ULCAST_(0x7f) << MCSR9_L2U_SIZE_SHIFT)
828 #define MCSR9_L2U_IDX_SHIFT 48
829 #define MCSR9_L2U_IDX_WIDTH 8
830 #define MCSR9_L2U_IDX (_ULCAST_(0xff) << MCSR9_IDX_LOG_SHIFT)
831 #define MCSR9_L2U_WAY_SHIFT 32
832 #define MCSR9_L2U_WAY_WIDTH 16
833 #define MCSR9_L2U_WAY (_ULCAST_(0xffff) << MCSR9_L2U_WAY_SHIFT)
834 #define MCSR9_L1D_SIZE_SHIFT 24
835 #define MCSR9_L1D_SIZE_WIDTH 7
836 #define MCSR9_L1D_SIZE (_ULCAST_(0x7f) << MCSR9_L1D_SIZE_SHIFT)
837 #define MCSR9_L1D_IDX_SHIFT 16
838 #define MCSR9_L1D_IDX_WIDTH 8
839 #define MCSR9_L1D_IDX (_ULCAST_(0xff) << MCSR9_L1D_IDX_SHIFT)
840 #define MCSR9_L1D_WAY_SHIFT 0
841 #define MCSR9_L1D_WAY_WIDTH 16
842 #define MCSR9_L1D_WAY (_ULCAST_(0xffff) << MCSR9_L1D_WAY_SHIFT)
843
844 #define LOONGARCH_CSR_MCSR10 0xca /* CPUCFG20 */
845 #define MCSR10_L3U_SIZE_SHIFT 24
846 #define MCSR10_L3U_SIZE_WIDTH 7
847 #define MCSR10_L3U_SIZE (_ULCAST_(0x7f) << MCSR10_L3U_SIZE_SHIFT)
848 #define MCSR10_L3U_IDX_SHIFT 16
849 #define MCSR10_L3U_IDX_WIDTH 8
850 #define MCSR10_L3U_IDX (_ULCAST_(0xff) << MCSR10_L3U_IDX_SHIFT)
851 #define MCSR10_L3U_WAY_SHIFT 0
852 #define MCSR10_L3U_WAY_WIDTH 16
853 #define MCSR10_L3U_WAY (_ULCAST_(0xffff) << MCSR10_L3U_WAY_SHIFT)
854
855 #define LOONGARCH_CSR_MCSR24 0xf0 /* cpucfg48 */
856 #define MCSR24_RAMCG_SHIFT 3
857 #define MCSR24_RAMCG (_ULCAST_(1) << MCSR24_RAMCG_SHIFT)
858 #define MCSR24_VFPUCG_SHIFT 2
859 #define MCSR24_VFPUCG (_ULCAST_(1) << MCSR24_VFPUCG_SHIFT)
860 #define MCSR24_NAPEN_SHIFT 1
861 #define MCSR24_NAPEN (_ULCAST_(1) << MCSR24_NAPEN_SHIFT)
862 #define MCSR24_MCSRLOCK_SHIFT 0
863 #define MCSR24_MCSRLOCK (_ULCAST_(1) << MCSR24_MCSRLOCK_SHIFT)
864
865 /* Uncached accelerate windows registers */
866 #define LOONGARCH_CSR_UCAWIN 0x100
867 #define LOONGARCH_CSR_UCAWIN0_LO 0x102
868 #define LOONGARCH_CSR_UCAWIN0_HI 0x103
869 #define LOONGARCH_CSR_UCAWIN1_LO 0x104
870 #define LOONGARCH_CSR_UCAWIN1_HI 0x105
871 #define LOONGARCH_CSR_UCAWIN2_LO 0x106
872 #define LOONGARCH_CSR_UCAWIN2_HI 0x107
873 #define LOONGARCH_CSR_UCAWIN3_LO 0x108
874 #define LOONGARCH_CSR_UCAWIN3_HI 0x109
875
876 /* Direct Map windows registers */
877 #define LOONGARCH_CSR_DMWIN0 0x180 /* 64 direct map win0: MEM & IF */
878 #define LOONGARCH_CSR_DMWIN1 0x181 /* 64 direct map win1: MEM & IF */
879 #define LOONGARCH_CSR_DMWIN2 0x182 /* 64 direct map win2: MEM */
880 #define LOONGARCH_CSR_DMWIN3 0x183 /* 64 direct map win3: MEM */
881
882 /* Direct Map window 0/1/2/3 */
883 #define CSR_DMW0_PLV0 _CONST64_(1 << 0)
884 #define CSR_DMW0_VSEG _CONST64_(0x8000)
885 #define CSR_DMW0_BASE (CSR_DMW0_VSEG << DMW_PABITS)
886 #define CSR_DMW0_INIT (CSR_DMW0_BASE | CSR_DMW0_PLV0)
887
888 #define CSR_DMW1_PLV0 _CONST64_(1 << 0)
889 #define CSR_DMW1_MAT _CONST64_(1 << 4)
890 #define CSR_DMW1_VSEG _CONST64_(0x9000)
891 #define CSR_DMW1_BASE (CSR_DMW1_VSEG << DMW_PABITS)
892 #define CSR_DMW1_INIT (CSR_DMW1_BASE | CSR_DMW1_MAT | CSR_DMW1_PLV0)
893
894 #define CSR_DMW2_PLV0 _CONST64_(1 << 0)
895 #define CSR_DMW2_MAT _CONST64_(2 << 4)
896 #define CSR_DMW2_VSEG _CONST64_(0xa000)
897 #define CSR_DMW2_BASE (CSR_DMW2_VSEG << DMW_PABITS)
898 #define CSR_DMW2_INIT (CSR_DMW2_BASE | CSR_DMW2_MAT | CSR_DMW2_PLV0)
899
900 #define CSR_DMW3_INIT 0x0
901
902 /* Performance Counter registers */
903 #define LOONGARCH_CSR_PERFCTRL0 0x200 /* 32 perf event 0 config */
904 #define LOONGARCH_CSR_PERFCNTR0 0x201 /* 64 perf event 0 count value */
905 #define LOONGARCH_CSR_PERFCTRL1 0x202 /* 32 perf event 1 config */
906 #define LOONGARCH_CSR_PERFCNTR1 0x203 /* 64 perf event 1 count value */
907 #define LOONGARCH_CSR_PERFCTRL2 0x204 /* 32 perf event 2 config */
908 #define LOONGARCH_CSR_PERFCNTR2 0x205 /* 64 perf event 2 count value */
909 #define LOONGARCH_CSR_PERFCTRL3 0x206 /* 32 perf event 3 config */
910 #define LOONGARCH_CSR_PERFCNTR3 0x207 /* 64 perf event 3 count value */
911 #define CSR_PERFCTRL_PLV0 (_ULCAST_(1) << 16)
912 #define CSR_PERFCTRL_PLV1 (_ULCAST_(1) << 17)
913 #define CSR_PERFCTRL_PLV2 (_ULCAST_(1) << 18)
914 #define CSR_PERFCTRL_PLV3 (_ULCAST_(1) << 19)
915 #define CSR_PERFCTRL_IE (_ULCAST_(1) << 20)
916 #define CSR_PERFCTRL_EVENT 0x3ff
917
918 /* Debug registers */
919 #define LOONGARCH_CSR_MWPC 0x300 /* data breakpoint config */
920 #define LOONGARCH_CSR_MWPS 0x301 /* data breakpoint status */
921
922 #define LOONGARCH_CSR_DB0ADDR 0x310 /* data breakpoint 0 address */
923 #define LOONGARCH_CSR_DB0MASK 0x311 /* data breakpoint 0 mask */
924 #define LOONGARCH_CSR_DB0CTRL 0x312 /* data breakpoint 0 control */
925 #define LOONGARCH_CSR_DB0ASID 0x313 /* data breakpoint 0 asid */
926
927 #define LOONGARCH_CSR_DB1ADDR 0x318 /* data breakpoint 1 address */
928 #define LOONGARCH_CSR_DB1MASK 0x319 /* data breakpoint 1 mask */
929 #define LOONGARCH_CSR_DB1CTRL 0x31a /* data breakpoint 1 control */
930 #define LOONGARCH_CSR_DB1ASID 0x31b /* data breakpoint 1 asid */
931
932 #define LOONGARCH_CSR_DB2ADDR 0x320 /* data breakpoint 2 address */
933 #define LOONGARCH_CSR_DB2MASK 0x321 /* data breakpoint 2 mask */
934 #define LOONGARCH_CSR_DB2CTRL 0x322 /* data breakpoint 2 control */
935 #define LOONGARCH_CSR_DB2ASID 0x323 /* data breakpoint 2 asid */
936
937 #define LOONGARCH_CSR_DB3ADDR 0x328 /* data breakpoint 3 address */
938 #define LOONGARCH_CSR_DB3MASK 0x329 /* data breakpoint 3 mask */
939 #define LOONGARCH_CSR_DB3CTRL 0x32a /* data breakpoint 3 control */
940 #define LOONGARCH_CSR_DB3ASID 0x32b /* data breakpoint 3 asid */
941
942 #define LOONGARCH_CSR_DB4ADDR 0x330 /* data breakpoint 4 address */
943 #define LOONGARCH_CSR_DB4MASK 0x331 /* data breakpoint 4 maks */
944 #define LOONGARCH_CSR_DB4CTRL 0x332 /* data breakpoint 4 control */
945 #define LOONGARCH_CSR_DB4ASID 0x333 /* data breakpoint 4 asid */
946
947 #define LOONGARCH_CSR_DB5ADDR 0x338 /* data breakpoint 5 address */
948 #define LOONGARCH_CSR_DB5MASK 0x339 /* data breakpoint 5 mask */
949 #define LOONGARCH_CSR_DB5CTRL 0x33a /* data breakpoint 5 control */
950 #define LOONGARCH_CSR_DB5ASID 0x33b /* data breakpoint 5 asid */
951
952 #define LOONGARCH_CSR_DB6ADDR 0x340 /* data breakpoint 6 address */
953 #define LOONGARCH_CSR_DB6MASK 0x341 /* data breakpoint 6 mask */
954 #define LOONGARCH_CSR_DB6CTRL 0x342 /* data breakpoint 6 control */
955 #define LOONGARCH_CSR_DB6ASID 0x343 /* data breakpoint 6 asid */
956
957 #define LOONGARCH_CSR_DB7ADDR 0x348 /* data breakpoint 7 address */
958 #define LOONGARCH_CSR_DB7MASK 0x349 /* data breakpoint 7 mask */
959 #define LOONGARCH_CSR_DB7CTRL 0x34a /* data breakpoint 7 control */
960 #define LOONGARCH_CSR_DB7ASID 0x34b /* data breakpoint 7 asid */
961
962 #define LOONGARCH_CSR_FWPC 0x380 /* instruction breakpoint config */
963 #define LOONGARCH_CSR_FWPS 0x381 /* instruction breakpoint status */
964
965 #define LOONGARCH_CSR_IB0ADDR 0x390 /* inst breakpoint 0 address */
966 #define LOONGARCH_CSR_IB0MASK 0x391 /* inst breakpoint 0 mask */
967 #define LOONGARCH_CSR_IB0CTRL 0x392 /* inst breakpoint 0 control */
968 #define LOONGARCH_CSR_IB0ASID 0x393 /* inst breakpoint 0 asid */
969
970 #define LOONGARCH_CSR_IB1ADDR 0x398 /* inst breakpoint 1 address */
971 #define LOONGARCH_CSR_IB1MASK 0x399 /* inst breakpoint 1 mask */
972 #define LOONGARCH_CSR_IB1CTRL 0x39a /* inst breakpoint 1 control */
973 #define LOONGARCH_CSR_IB1ASID 0x39b /* inst breakpoint 1 asid */
974
975 #define LOONGARCH_CSR_IB2ADDR 0x3a0 /* inst breakpoint 2 address */
976 #define LOONGARCH_CSR_IB2MASK 0x3a1 /* inst breakpoint 2 mask */
977 #define LOONGARCH_CSR_IB2CTRL 0x3a2 /* inst breakpoint 2 control */
978 #define LOONGARCH_CSR_IB2ASID 0x3a3 /* inst breakpoint 2 asid */
979
980 #define LOONGARCH_CSR_IB3ADDR 0x3a8 /* inst breakpoint 3 address */
981 #define LOONGARCH_CSR_IB3MASK 0x3a9 /* breakpoint 3 mask */
982 #define LOONGARCH_CSR_IB3CTRL 0x3aa /* inst breakpoint 3 control */
983 #define LOONGARCH_CSR_IB3ASID 0x3ab /* inst breakpoint 3 asid */
984
985 #define LOONGARCH_CSR_IB4ADDR 0x3b0 /* inst breakpoint 4 address */
986 #define LOONGARCH_CSR_IB4MASK 0x3b1 /* inst breakpoint 4 mask */
987 #define LOONGARCH_CSR_IB4CTRL 0x3b2 /* inst breakpoint 4 control */
988 #define LOONGARCH_CSR_IB4ASID 0x3b3 /* inst breakpoint 4 asid */
989
990 #define LOONGARCH_CSR_IB5ADDR 0x3b8 /* inst breakpoint 5 address */
991 #define LOONGARCH_CSR_IB5MASK 0x3b9 /* inst breakpoint 5 mask */
992 #define LOONGARCH_CSR_IB5CTRL 0x3ba /* inst breakpoint 5 control */
993 #define LOONGARCH_CSR_IB5ASID 0x3bb /* inst breakpoint 5 asid */
994
995 #define LOONGARCH_CSR_IB6ADDR 0x3c0 /* inst breakpoint 6 address */
996 #define LOONGARCH_CSR_IB6MASK 0x3c1 /* inst breakpoint 6 mask */
997 #define LOONGARCH_CSR_IB6CTRL 0x3c2 /* inst breakpoint 6 control */
998 #define LOONGARCH_CSR_IB6ASID 0x3c3 /* inst breakpoint 6 asid */
999
1000 #define LOONGARCH_CSR_IB7ADDR 0x3c8 /* inst breakpoint 7 address */
1001 #define LOONGARCH_CSR_IB7MASK 0x3c9 /* inst breakpoint 7 mask */
1002 #define LOONGARCH_CSR_IB7CTRL 0x3ca /* inst breakpoint 7 control */
1003 #define LOONGARCH_CSR_IB7ASID 0x3cb /* inst breakpoint 7 asid */
1004
1005 #define LOONGARCH_CSR_DEBUG 0x500 /* debug config */
1006 #define LOONGARCH_CSR_DERA 0x501 /* debug era */
1007 #define LOONGARCH_CSR_DESAVE 0x502 /* debug save */
1008
1009 #define CSR_FWPC_SKIP_SHIFT 16
1010 #define CSR_FWPC_SKIP (_ULCAST_(1) << CSR_FWPC_SKIP_SHIFT)
1011
1012 /*
1013 * CSR_ECFG IM
1014 */
1015 #define ECFG0_IM 0x00005fff
1016 #define ECFGB_SIP0 0
1017 #define ECFGF_SIP0 (_ULCAST_(1) << ECFGB_SIP0)
1018 #define ECFGB_SIP1 1
1019 #define ECFGF_SIP1 (_ULCAST_(1) << ECFGB_SIP1)
1020 #define ECFGB_IP0 2
1021 #define ECFGF_IP0 (_ULCAST_(1) << ECFGB_IP0)
1022 #define ECFGB_IP1 3
1023 #define ECFGF_IP1 (_ULCAST_(1) << ECFGB_IP1)
1024 #define ECFGB_IP2 4
1025 #define ECFGF_IP2 (_ULCAST_(1) << ECFGB_IP2)
1026 #define ECFGB_IP3 5
1027 #define ECFGF_IP3 (_ULCAST_(1) << ECFGB_IP3)
1028 #define ECFGB_IP4 6
1029 #define ECFGF_IP4 (_ULCAST_(1) << ECFGB_IP4)
1030 #define ECFGB_IP5 7
1031 #define ECFGF_IP5 (_ULCAST_(1) << ECFGB_IP5)
1032 #define ECFGB_IP6 8
1033 #define ECFGF_IP6 (_ULCAST_(1) << ECFGB_IP6)
1034 #define ECFGB_IP7 9
1035 #define ECFGF_IP7 (_ULCAST_(1) << ECFGB_IP7)
1036 #define ECFGB_PMC 10
1037 #define ECFGF_PMC (_ULCAST_(1) << ECFGB_PMC)
1038 #define ECFGB_TIMER 11
1039 #define ECFGF_TIMER (_ULCAST_(1) << ECFGB_TIMER)
1040 #define ECFGB_IPI 12
1041 #define ECFGF_IPI (_ULCAST_(1) << ECFGB_IPI)
1042 #define ECFGF(hwirq) (_ULCAST_(1) << hwirq)
1043
1044 #define ESTATF_IP 0x00003fff
1045
1046 #define LOONGARCH_IOCSR_FEATURES 0x8
1047 #define IOCSRF_TEMP BIT_ULL(0)
1048 #define IOCSRF_NODECNT BIT_ULL(1)
1049 #define IOCSRF_MSI BIT_ULL(2)
1050 #define IOCSRF_EXTIOI BIT_ULL(3)
1051 #define IOCSRF_CSRIPI BIT_ULL(4)
1052 #define IOCSRF_FREQCSR BIT_ULL(5)
1053 #define IOCSRF_FREQSCALE BIT_ULL(6)
1054 #define IOCSRF_DVFSV1 BIT_ULL(7)
1055 #define IOCSRF_EIODECODE BIT_ULL(9)
1056 #define IOCSRF_FLATMODE BIT_ULL(10)
1057 #define IOCSRF_VM BIT_ULL(11)
1058 #define IOCSRF_AVEC BIT_ULL(15)
1059
1060 #define LOONGARCH_IOCSR_VENDOR 0x10
1061
1062 #define LOONGARCH_IOCSR_CPUNAME 0x20
1063
1064 #define LOONGARCH_IOCSR_NODECNT 0x408
1065
1066 #define LOONGARCH_IOCSR_MISC_FUNC 0x420
1067 #define IOCSR_MISC_FUNC_SOFT_INT BIT_ULL(10)
1068 #define IOCSR_MISC_FUNC_TIMER_RESET BIT_ULL(21)
1069 #define IOCSR_MISC_FUNC_EXT_IOI_EN BIT_ULL(48)
1070 #define IOCSR_MISC_FUNC_AVEC_EN BIT_ULL(51)
1071
1072 #define LOONGARCH_IOCSR_CPUTEMP 0x428
1073
1074 #define LOONGARCH_IOCSR_SMCMBX 0x51c
1075
1076 /* PerCore CSR, only accessible by local cores */
1077 #define LOONGARCH_IOCSR_IPI_STATUS 0x1000
1078 #define LOONGARCH_IOCSR_IPI_EN 0x1004
1079 #define LOONGARCH_IOCSR_IPI_SET 0x1008
1080 #define LOONGARCH_IOCSR_IPI_CLEAR 0x100c
1081 #define LOONGARCH_IOCSR_MBUF0 0x1020
1082 #define LOONGARCH_IOCSR_MBUF1 0x1028
1083 #define LOONGARCH_IOCSR_MBUF2 0x1030
1084 #define LOONGARCH_IOCSR_MBUF3 0x1038
1085
1086 #define LOONGARCH_IOCSR_IPI_SEND 0x1040
1087 #define IOCSR_IPI_SEND_IP_SHIFT 0
1088 #define IOCSR_IPI_SEND_CPU_SHIFT 16
1089 #define IOCSR_IPI_SEND_BLOCKING BIT(31)
1090
1091 #define LOONGARCH_IOCSR_MBUF_SEND 0x1048
1092 #define IOCSR_MBUF_SEND_BLOCKING BIT_ULL(31)
1093 #define IOCSR_MBUF_SEND_BOX_SHIFT 2
1094 #define IOCSR_MBUF_SEND_BOX_LO(box) (box << 1)
1095 #define IOCSR_MBUF_SEND_BOX_HI(box) ((box << 1) + 1)
1096 #define IOCSR_MBUF_SEND_CPU_SHIFT 16
1097 #define IOCSR_MBUF_SEND_BUF_SHIFT 32
1098 #define IOCSR_MBUF_SEND_H32_MASK 0xFFFFFFFF00000000ULL
1099
1100 #define LOONGARCH_IOCSR_ANY_SEND 0x1158
1101 #define IOCSR_ANY_SEND_BLOCKING BIT_ULL(31)
1102 #define IOCSR_ANY_SEND_CPU_SHIFT 16
1103 #define IOCSR_ANY_SEND_MASK_SHIFT 27
1104 #define IOCSR_ANY_SEND_BUF_SHIFT 32
1105 #define IOCSR_ANY_SEND_H32_MASK 0xFFFFFFFF00000000ULL
1106
1107 /* Register offset and bit definition for CSR access */
1108 #define LOONGARCH_IOCSR_TIMER_CFG 0x1060
1109 #define LOONGARCH_IOCSR_TIMER_TICK 0x1070
1110 #define IOCSR_TIMER_CFG_RESERVED (_ULCAST_(1) << 63)
1111 #define IOCSR_TIMER_CFG_PERIODIC (_ULCAST_(1) << 62)
1112 #define IOCSR_TIMER_CFG_EN (_ULCAST_(1) << 61)
1113 #define IOCSR_TIMER_MASK 0x0ffffffffffffULL
1114 #define IOCSR_TIMER_INITVAL_RST (_ULCAST_(0xffff) << 48)
1115
1116 #define LOONGARCH_IOCSR_EXTIOI_NODEMAP_BASE 0x14a0
1117 #define LOONGARCH_IOCSR_EXTIOI_IPMAP_BASE 0x14c0
1118 #define LOONGARCH_IOCSR_EXTIOI_EN_BASE 0x1600
1119 #define LOONGARCH_IOCSR_EXTIOI_BOUNCE_BASE 0x1680
1120 #define LOONGARCH_IOCSR_EXTIOI_ISR_BASE 0x1800
1121 #define LOONGARCH_IOCSR_EXTIOI_ROUTE_BASE 0x1c00
1122 #define IOCSR_EXTIOI_VECTOR_NUM 256
1123
1124 #ifndef __ASSEMBLY__
1125
drdtime(void)1126 static __always_inline u64 drdtime(void)
1127 {
1128 u64 val = 0;
1129
1130 __asm__ __volatile__(
1131 "rdtime.d %0, $zero\n\t"
1132 : "=r"(val)
1133 :
1134 );
1135 return val;
1136 }
1137
get_csr_cpuid(void)1138 static inline unsigned int get_csr_cpuid(void)
1139 {
1140 return csr_read32(LOONGARCH_CSR_CPUID);
1141 }
1142
csr_any_send(unsigned int addr,unsigned int data,unsigned int data_mask,unsigned int cpu)1143 static inline void csr_any_send(unsigned int addr, unsigned int data,
1144 unsigned int data_mask, unsigned int cpu)
1145 {
1146 uint64_t val = 0;
1147
1148 val = IOCSR_ANY_SEND_BLOCKING | addr;
1149 val |= (cpu << IOCSR_ANY_SEND_CPU_SHIFT);
1150 val |= (data_mask << IOCSR_ANY_SEND_MASK_SHIFT);
1151 val |= ((uint64_t)data << IOCSR_ANY_SEND_BUF_SHIFT);
1152 iocsr_write64(val, LOONGARCH_IOCSR_ANY_SEND);
1153 }
1154
read_csr_excode(void)1155 static inline unsigned int read_csr_excode(void)
1156 {
1157 return (csr_read32(LOONGARCH_CSR_ESTAT) & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT;
1158 }
1159
write_csr_index(unsigned int idx)1160 static inline void write_csr_index(unsigned int idx)
1161 {
1162 csr_xchg32(idx, CSR_TLBIDX_IDXM, LOONGARCH_CSR_TLBIDX);
1163 }
1164
read_csr_pagesize(void)1165 static inline unsigned int read_csr_pagesize(void)
1166 {
1167 return (csr_read32(LOONGARCH_CSR_TLBIDX) & CSR_TLBIDX_SIZEM) >> CSR_TLBIDX_SIZE;
1168 }
1169
write_csr_pagesize(unsigned int size)1170 static inline void write_csr_pagesize(unsigned int size)
1171 {
1172 csr_xchg32(size << CSR_TLBIDX_SIZE, CSR_TLBIDX_SIZEM, LOONGARCH_CSR_TLBIDX);
1173 }
1174
read_csr_tlbrefill_pagesize(void)1175 static inline unsigned int read_csr_tlbrefill_pagesize(void)
1176 {
1177 return (csr_read64(LOONGARCH_CSR_TLBREHI) & CSR_TLBREHI_PS) >> CSR_TLBREHI_PS_SHIFT;
1178 }
1179
write_csr_tlbrefill_pagesize(unsigned int size)1180 static inline void write_csr_tlbrefill_pagesize(unsigned int size)
1181 {
1182 csr_xchg64(size << CSR_TLBREHI_PS_SHIFT, CSR_TLBREHI_PS, LOONGARCH_CSR_TLBREHI);
1183 }
1184
1185 #define read_csr_asid() csr_read32(LOONGARCH_CSR_ASID)
1186 #define write_csr_asid(val) csr_write32(val, LOONGARCH_CSR_ASID)
1187 #define read_csr_entryhi() csr_read64(LOONGARCH_CSR_TLBEHI)
1188 #define write_csr_entryhi(val) csr_write64(val, LOONGARCH_CSR_TLBEHI)
1189 #define read_csr_entrylo0() csr_read64(LOONGARCH_CSR_TLBELO0)
1190 #define write_csr_entrylo0(val) csr_write64(val, LOONGARCH_CSR_TLBELO0)
1191 #define read_csr_entrylo1() csr_read64(LOONGARCH_CSR_TLBELO1)
1192 #define write_csr_entrylo1(val) csr_write64(val, LOONGARCH_CSR_TLBELO1)
1193 #define read_csr_ecfg() csr_read32(LOONGARCH_CSR_ECFG)
1194 #define write_csr_ecfg(val) csr_write32(val, LOONGARCH_CSR_ECFG)
1195 #define read_csr_estat() csr_read32(LOONGARCH_CSR_ESTAT)
1196 #define write_csr_estat(val) csr_write32(val, LOONGARCH_CSR_ESTAT)
1197 #define read_csr_tlbidx() csr_read32(LOONGARCH_CSR_TLBIDX)
1198 #define write_csr_tlbidx(val) csr_write32(val, LOONGARCH_CSR_TLBIDX)
1199 #define read_csr_euen() csr_read32(LOONGARCH_CSR_EUEN)
1200 #define write_csr_euen(val) csr_write32(val, LOONGARCH_CSR_EUEN)
1201 #define read_csr_cpuid() csr_read32(LOONGARCH_CSR_CPUID)
1202 #define read_csr_prcfg1() csr_read64(LOONGARCH_CSR_PRCFG1)
1203 #define write_csr_prcfg1(val) csr_write64(val, LOONGARCH_CSR_PRCFG1)
1204 #define read_csr_prcfg2() csr_read64(LOONGARCH_CSR_PRCFG2)
1205 #define write_csr_prcfg2(val) csr_write64(val, LOONGARCH_CSR_PRCFG2)
1206 #define read_csr_prcfg3() csr_read64(LOONGARCH_CSR_PRCFG3)
1207 #define write_csr_prcfg3(val) csr_write64(val, LOONGARCH_CSR_PRCFG3)
1208 #define read_csr_stlbpgsize() csr_read32(LOONGARCH_CSR_STLBPGSIZE)
1209 #define write_csr_stlbpgsize(val) csr_write32(val, LOONGARCH_CSR_STLBPGSIZE)
1210 #define read_csr_rvacfg() csr_read32(LOONGARCH_CSR_RVACFG)
1211 #define write_csr_rvacfg(val) csr_write32(val, LOONGARCH_CSR_RVACFG)
1212 #define write_csr_tintclear(val) csr_write32(val, LOONGARCH_CSR_TINTCLR)
1213 #define read_csr_impctl1() csr_read64(LOONGARCH_CSR_IMPCTL1)
1214 #define write_csr_impctl1(val) csr_write64(val, LOONGARCH_CSR_IMPCTL1)
1215 #define write_csr_impctl2(val) csr_write64(val, LOONGARCH_CSR_IMPCTL2)
1216
1217 #define read_csr_perfctrl0() csr_read64(LOONGARCH_CSR_PERFCTRL0)
1218 #define read_csr_perfcntr0() csr_read64(LOONGARCH_CSR_PERFCNTR0)
1219 #define read_csr_perfctrl1() csr_read64(LOONGARCH_CSR_PERFCTRL1)
1220 #define read_csr_perfcntr1() csr_read64(LOONGARCH_CSR_PERFCNTR1)
1221 #define read_csr_perfctrl2() csr_read64(LOONGARCH_CSR_PERFCTRL2)
1222 #define read_csr_perfcntr2() csr_read64(LOONGARCH_CSR_PERFCNTR2)
1223 #define read_csr_perfctrl3() csr_read64(LOONGARCH_CSR_PERFCTRL3)
1224 #define read_csr_perfcntr3() csr_read64(LOONGARCH_CSR_PERFCNTR3)
1225 #define write_csr_perfctrl0(val) csr_write64(val, LOONGARCH_CSR_PERFCTRL0)
1226 #define write_csr_perfcntr0(val) csr_write64(val, LOONGARCH_CSR_PERFCNTR0)
1227 #define write_csr_perfctrl1(val) csr_write64(val, LOONGARCH_CSR_PERFCTRL1)
1228 #define write_csr_perfcntr1(val) csr_write64(val, LOONGARCH_CSR_PERFCNTR1)
1229 #define write_csr_perfctrl2(val) csr_write64(val, LOONGARCH_CSR_PERFCTRL2)
1230 #define write_csr_perfcntr2(val) csr_write64(val, LOONGARCH_CSR_PERFCNTR2)
1231 #define write_csr_perfctrl3(val) csr_write64(val, LOONGARCH_CSR_PERFCTRL3)
1232 #define write_csr_perfcntr3(val) csr_write64(val, LOONGARCH_CSR_PERFCNTR3)
1233
1234 /*
1235 * Manipulate bits in a register.
1236 */
1237 #define __BUILD_CSR_COMMON(name) \
1238 static inline unsigned long \
1239 set_##name(unsigned long set) \
1240 { \
1241 unsigned long res, new; \
1242 \
1243 res = read_##name(); \
1244 new = res | set; \
1245 write_##name(new); \
1246 \
1247 return res; \
1248 } \
1249 \
1250 static inline unsigned long \
1251 clear_##name(unsigned long clear) \
1252 { \
1253 unsigned long res, new; \
1254 \
1255 res = read_##name(); \
1256 new = res & ~clear; \
1257 write_##name(new); \
1258 \
1259 return res; \
1260 } \
1261 \
1262 static inline unsigned long \
1263 change_##name(unsigned long change, unsigned long val) \
1264 { \
1265 unsigned long res, new; \
1266 \
1267 res = read_##name(); \
1268 new = res & ~change; \
1269 new |= (val & change); \
1270 write_##name(new); \
1271 \
1272 return res; \
1273 }
1274
1275 #define __BUILD_CSR_OP(name) __BUILD_CSR_COMMON(csr_##name)
1276
1277 __BUILD_CSR_OP(euen)
1278 __BUILD_CSR_OP(ecfg)
1279 __BUILD_CSR_OP(tlbidx)
1280
1281 #define set_csr_estat(val) \
1282 csr_xchg32(val, val, LOONGARCH_CSR_ESTAT)
1283 #define clear_csr_estat(val) \
1284 csr_xchg32(~(val), val, LOONGARCH_CSR_ESTAT)
1285
1286 #endif /* __ASSEMBLY__ */
1287
1288 /* Generic EntryLo bit definitions */
1289 #define ENTRYLO_V (_ULCAST_(1) << 0)
1290 #define ENTRYLO_D (_ULCAST_(1) << 1)
1291 #define ENTRYLO_PLV_SHIFT 2
1292 #define ENTRYLO_PLV (_ULCAST_(3) << ENTRYLO_PLV_SHIFT)
1293 #define ENTRYLO_C_SHIFT 4
1294 #define ENTRYLO_C (_ULCAST_(3) << ENTRYLO_C_SHIFT)
1295 #define ENTRYLO_G (_ULCAST_(1) << 6)
1296 #define ENTRYLO_NR (_ULCAST_(1) << 61)
1297 #define ENTRYLO_NX (_ULCAST_(1) << 62)
1298
1299 /* Values for PageSize register */
1300 #define PS_4K 0x0000000c
1301 #define PS_8K 0x0000000d
1302 #define PS_16K 0x0000000e
1303 #define PS_32K 0x0000000f
1304 #define PS_64K 0x00000010
1305 #define PS_128K 0x00000011
1306 #define PS_256K 0x00000012
1307 #define PS_512K 0x00000013
1308 #define PS_1M 0x00000014
1309 #define PS_2M 0x00000015
1310 #define PS_4M 0x00000016
1311 #define PS_8M 0x00000017
1312 #define PS_16M 0x00000018
1313 #define PS_32M 0x00000019
1314 #define PS_64M 0x0000001a
1315 #define PS_128M 0x0000001b
1316 #define PS_256M 0x0000001c
1317 #define PS_512M 0x0000001d
1318 #define PS_1G 0x0000001e
1319
1320 /* Default page size for a given kernel configuration */
1321 #ifdef CONFIG_PAGE_SIZE_4KB
1322 #define PS_DEFAULT_SIZE PS_4K
1323 #elif defined(CONFIG_PAGE_SIZE_16KB)
1324 #define PS_DEFAULT_SIZE PS_16K
1325 #elif defined(CONFIG_PAGE_SIZE_64KB)
1326 #define PS_DEFAULT_SIZE PS_64K
1327 #else
1328 #error Bad page size configuration!
1329 #endif
1330
1331 /* Default huge tlb size for a given kernel configuration */
1332 #ifdef CONFIG_PAGE_SIZE_4KB
1333 #define PS_HUGE_SIZE PS_1M
1334 #elif defined(CONFIG_PAGE_SIZE_16KB)
1335 #define PS_HUGE_SIZE PS_16M
1336 #elif defined(CONFIG_PAGE_SIZE_64KB)
1337 #define PS_HUGE_SIZE PS_256M
1338 #else
1339 #error Bad page size configuration for hugetlbfs!
1340 #endif
1341
1342 /* ExStatus.ExcCode */
1343 #define EXCCODE_RSV 0 /* Reserved */
1344 #define EXCCODE_TLBL 1 /* TLB miss on a load */
1345 #define EXCCODE_TLBS 2 /* TLB miss on a store */
1346 #define EXCCODE_TLBI 3 /* TLB miss on a ifetch */
1347 #define EXCCODE_TLBM 4 /* TLB modified fault */
1348 #define EXCCODE_TLBNR 5 /* TLB Read-Inhibit exception */
1349 #define EXCCODE_TLBNX 6 /* TLB Execution-Inhibit exception */
1350 #define EXCCODE_TLBPE 7 /* TLB Privilege Error */
1351 #define EXCCODE_ADE 8 /* Address Error */
1352 #define EXSUBCODE_ADEF 0 /* Fetch Instruction */
1353 #define EXSUBCODE_ADEM 1 /* Access Memory*/
1354 #define EXCCODE_ALE 9 /* Unalign Access */
1355 #define EXCCODE_BCE 10 /* Bounds Check Error */
1356 #define EXCCODE_SYS 11 /* System call */
1357 #define EXCCODE_BP 12 /* Breakpoint */
1358 #define EXCCODE_INE 13 /* Inst. Not Exist */
1359 #define EXCCODE_IPE 14 /* Inst. Privileged Error */
1360 #define EXCCODE_FPDIS 15 /* FPU Disabled */
1361 #define EXCCODE_LSXDIS 16 /* LSX Disabled */
1362 #define EXCCODE_LASXDIS 17 /* LASX Disabled */
1363 #define EXCCODE_FPE 18 /* Floating Point Exception */
1364 #define EXCSUBCODE_FPE 0 /* Floating Point Exception */
1365 #define EXCSUBCODE_VFPE 1 /* Vector Exception */
1366 #define EXCCODE_WATCH 19 /* WatchPoint Exception */
1367 #define EXCSUBCODE_WPEF 0 /* ... on Instruction Fetch */
1368 #define EXCSUBCODE_WPEM 1 /* ... on Memory Accesses */
1369 #define EXCCODE_BTDIS 20 /* Binary Trans. Disabled */
1370 #define EXCCODE_BTE 21 /* Binary Trans. Exception */
1371 #define EXCCODE_GSPR 22 /* Guest Privileged Error */
1372 #define EXCCODE_HVC 23 /* Hypercall */
1373 #define EXCCODE_GCM 24 /* Guest CSR modified */
1374 #define EXCSUBCODE_GCSC 0 /* Software caused */
1375 #define EXCSUBCODE_GCHC 1 /* Hardware caused */
1376 #define EXCCODE_SE 25 /* Security */
1377
1378 /* Interrupt numbers */
1379 #define INT_SWI0 0 /* Software Interrupts */
1380 #define INT_SWI1 1
1381 #define INT_HWI0 2 /* Hardware Interrupts */
1382 #define INT_HWI1 3
1383 #define INT_HWI2 4
1384 #define INT_HWI3 5
1385 #define INT_HWI4 6
1386 #define INT_HWI5 7
1387 #define INT_HWI6 8
1388 #define INT_HWI7 9
1389 #define INT_PCOV 10 /* Performance Counter Overflow */
1390 #define INT_TI 11 /* Timer */
1391 #define INT_IPI 12
1392 #define INT_NMI 13
1393 #define INT_AVEC 14
1394
1395 /* ExcCodes corresponding to interrupts */
1396 #define EXCCODE_INT_NUM (INT_AVEC + 1)
1397 #define EXCCODE_INT_START 64
1398 #define EXCCODE_INT_END (EXCCODE_INT_START + EXCCODE_INT_NUM - 1)
1399
1400 /* FPU Status Register Names */
1401 #ifndef CONFIG_AS_HAS_FCSR_CLASS
1402 #define LOONGARCH_FCSR0 $r0
1403 #define LOONGARCH_FCSR1 $r1
1404 #define LOONGARCH_FCSR2 $r2
1405 #define LOONGARCH_FCSR3 $r3
1406 #else
1407 #define LOONGARCH_FCSR0 $fcsr0
1408 #define LOONGARCH_FCSR1 $fcsr1
1409 #define LOONGARCH_FCSR2 $fcsr2
1410 #define LOONGARCH_FCSR3 $fcsr3
1411 #endif
1412
1413 /* FPU Status Register Values */
1414 #define FPU_CSR_RSVD 0xe0e0fce0
1415
1416 /*
1417 * X the exception cause indicator
1418 * E the exception enable
1419 * S the sticky/flag bit
1420 */
1421 #define FPU_CSR_ALL_X 0x1f000000
1422 #define FPU_CSR_INV_X 0x10000000
1423 #define FPU_CSR_DIV_X 0x08000000
1424 #define FPU_CSR_OVF_X 0x04000000
1425 #define FPU_CSR_UDF_X 0x02000000
1426 #define FPU_CSR_INE_X 0x01000000
1427
1428 #define FPU_CSR_ALL_S 0x001f0000
1429 #define FPU_CSR_INV_S 0x00100000
1430 #define FPU_CSR_DIV_S 0x00080000
1431 #define FPU_CSR_OVF_S 0x00040000
1432 #define FPU_CSR_UDF_S 0x00020000
1433 #define FPU_CSR_INE_S 0x00010000
1434
1435 #define FPU_CSR_ALL_E 0x0000001f
1436 #define FPU_CSR_INV_E 0x00000010
1437 #define FPU_CSR_DIV_E 0x00000008
1438 #define FPU_CSR_OVF_E 0x00000004
1439 #define FPU_CSR_UDF_E 0x00000002
1440 #define FPU_CSR_INE_E 0x00000001
1441
1442 /* Bits 8 and 9 of FPU Status Register specify the rounding mode */
1443 #define FPU_CSR_RM 0x300
1444 #define FPU_CSR_RN 0x000 /* nearest */
1445 #define FPU_CSR_RZ 0x100 /* towards zero */
1446 #define FPU_CSR_RU 0x200 /* towards +Infinity */
1447 #define FPU_CSR_RD 0x300 /* towards -Infinity */
1448
1449 /* Bit 6 of FPU Status Register specify the LBT TOP simulation mode */
1450 #define FPU_CSR_TM_SHIFT 0x6
1451 #define FPU_CSR_TM (_ULCAST_(1) << FPU_CSR_TM_SHIFT)
1452
1453 #define read_fcsr(source) \
1454 ({ \
1455 unsigned int __res; \
1456 \
1457 __asm__ __volatile__( \
1458 " movfcsr2gr %0, "__stringify(source)" \n" \
1459 : "=r" (__res)); \
1460 __res; \
1461 })
1462
1463 #define write_fcsr(dest, val) \
1464 do { \
1465 __asm__ __volatile__( \
1466 " movgr2fcsr "__stringify(dest)", %0 \n" \
1467 : : "r" (val)); \
1468 } while (0)
1469
1470 #endif /* _ASM_LOONGARCH_H */
1471