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