1
2
3
4
5
6
7
8#ifndef LOONGARCH_CPU_CSR_H
9#define LOONGARCH_CPU_CSR_H
10
11#include "hw/registerfields.h"
12
13
14
15
16#define LOONGARCH_CSR_CRMD 0x0
17
18#define LOONGARCH_CSR_PRMD 0x1
19FIELD(CSR_PRMD, PPLV, 0, 2)
20FIELD(CSR_PRMD, PIE, 2, 1)
21FIELD(CSR_PRMD, PWE, 3, 1)
22
23#define LOONGARCH_CSR_EUEN 0x2
24FIELD(CSR_EUEN, FPE, 0, 1)
25FIELD(CSR_EUEN, SXE, 1, 1)
26FIELD(CSR_EUEN, ASXE, 2, 1)
27FIELD(CSR_EUEN, BTE, 3, 1)
28
29#define LOONGARCH_CSR_MISC 0x3
30FIELD(CSR_MISC, VA32, 0, 4)
31FIELD(CSR_MISC, DRDTL, 4, 4)
32FIELD(CSR_MISC, RPCNTL, 8, 4)
33FIELD(CSR_MISC, ALCL, 12, 4)
34FIELD(CSR_MISC, DWPL, 16, 3)
35
36#define LOONGARCH_CSR_ECFG 0x4
37FIELD(CSR_ECFG, LIE, 0, 13)
38FIELD(CSR_ECFG, VS, 16, 3)
39
40#define LOONGARCH_CSR_ESTAT 0x5
41FIELD(CSR_ESTAT, IS, 0, 13)
42FIELD(CSR_ESTAT, ECODE, 16, 6)
43FIELD(CSR_ESTAT, ESUBCODE, 22, 9)
44
45#define LOONGARCH_CSR_ERA 0x6
46
47#define LOONGARCH_CSR_BADV 0x7
48
49#define LOONGARCH_CSR_BADI 0x8
50
51#define LOONGARCH_CSR_EENTRY 0xc
52
53
54#define LOONGARCH_CSR_TLBIDX 0x10
55FIELD(CSR_TLBIDX, INDEX, 0, 12)
56FIELD(CSR_TLBIDX, PS, 24, 6)
57FIELD(CSR_TLBIDX, NE, 31, 1)
58
59#define LOONGARCH_CSR_TLBEHI 0x11
60FIELD(CSR_TLBEHI, VPPN, 13, 35)
61
62#define LOONGARCH_CSR_TLBELO0 0x12
63#define LOONGARCH_CSR_TLBELO1 0x13
64FIELD(TLBENTRY, V, 0, 1)
65FIELD(TLBENTRY, D, 1, 1)
66FIELD(TLBENTRY, PLV, 2, 2)
67FIELD(TLBENTRY, MAT, 4, 2)
68FIELD(TLBENTRY, G, 6, 1)
69FIELD(TLBENTRY, PPN, 12, 36)
70FIELD(TLBENTRY, NR, 61, 1)
71FIELD(TLBENTRY, NX, 62, 1)
72FIELD(TLBENTRY, RPLV, 63, 1)
73
74#define LOONGARCH_CSR_ASID 0x18
75FIELD(CSR_ASID, ASID, 0, 10)
76FIELD(CSR_ASID, ASIDBITS, 16, 8)
77
78
79#define LOONGARCH_CSR_PGDL 0x19
80
81#define LOONGARCH_CSR_PGDH 0x1a
82
83#define LOONGARCH_CSR_PGD 0x1b
84
85
86#define LOONGARCH_CSR_PWCL 0x1c
87FIELD(CSR_PWCL, PTBASE, 0, 5)
88FIELD(CSR_PWCL, PTWIDTH, 5, 5)
89FIELD(CSR_PWCL, DIR1_BASE, 10, 5)
90FIELD(CSR_PWCL, DIR1_WIDTH, 15, 5)
91FIELD(CSR_PWCL, DIR2_BASE, 20, 5)
92FIELD(CSR_PWCL, DIR2_WIDTH, 25, 5)
93FIELD(CSR_PWCL, PTEWIDTH, 30, 2)
94
95
96#define LOONGARCH_CSR_PWCH 0x1d
97FIELD(CSR_PWCH, DIR3_BASE, 0, 6)
98FIELD(CSR_PWCH, DIR3_WIDTH, 6, 6)
99FIELD(CSR_PWCH, DIR4_BASE, 12, 6)
100FIELD(CSR_PWCH, DIR4_WIDTH, 18, 6)
101
102#define LOONGARCH_CSR_STLBPS 0x1e
103FIELD(CSR_STLBPS, PS, 0, 5)
104
105#define LOONGARCH_CSR_RVACFG 0x1f
106FIELD(CSR_RVACFG, RBITS, 0, 4)
107
108
109#define LOONGARCH_CSR_CPUID 0x20
110
111#define LOONGARCH_CSR_PRCFG1 0x21
112FIELD(CSR_PRCFG1, SAVE_NUM, 0, 4)
113FIELD(CSR_PRCFG1, TIMER_BITS, 4, 8)
114FIELD(CSR_PRCFG1, VSMAX, 12, 3)
115
116#define LOONGARCH_CSR_PRCFG2 0x22
117
118#define LOONGARCH_CSR_PRCFG3 0x23
119FIELD(CSR_PRCFG3, TLB_TYPE, 0, 4)
120FIELD(CSR_PRCFG3, MTLB_ENTRY, 4, 8)
121FIELD(CSR_PRCFG3, STLB_WAYS, 12, 8)
122FIELD(CSR_PRCFG3, STLB_SETS, 20, 8)
123
124
125
126
127
128#define LOONGARCH_CSR_SAVE(N) (0x30 + N)
129
130
131#define LOONGARCH_CSR_TID 0x40
132
133#define LOONGARCH_CSR_TCFG 0x41
134FIELD(CSR_TCFG, EN, 0, 1)
135FIELD(CSR_TCFG, PERIODIC, 1, 1)
136FIELD(CSR_TCFG, INIT_VAL, 2, 46)
137
138#define LOONGARCH_CSR_TVAL 0x42
139
140#define LOONGARCH_CSR_CNTC 0x43
141
142#define LOONGARCH_CSR_TICLR 0x44
143
144
145#define LOONGARCH_CSR_LLBCTL 0x60
146FIELD(CSR_LLBCTL, ROLLB, 0, 1)
147FIELD(CSR_LLBCTL, WCLLB, 1, 1)
148FIELD(CSR_LLBCTL, KLO, 2, 1)
149
150
151#define LOONGARCH_CSR_IMPCTL1 0x80
152
153#define LOONGARCH_CSR_IMPCTL2 0x81
154
155
156#define LOONGARCH_CSR_TLBRENTRY 0x88
157#define LOONGARCH_CSR_TLBRBADV 0x89
158#define LOONGARCH_CSR_TLBRERA 0x8a
159#define LOONGARCH_CSR_TLBRSAVE 0x8b
160FIELD(CSR_TLBRERA, ISTLBR, 0, 1)
161FIELD(CSR_TLBRERA, PC, 2, 62)
162#define LOONGARCH_CSR_TLBRELO0 0x8c
163#define LOONGARCH_CSR_TLBRELO1 0x8d
164#define LOONGARCH_CSR_TLBREHI 0x8e
165FIELD(CSR_TLBREHI, PS, 0, 6)
166FIELD(CSR_TLBREHI, VPPN, 13, 35)
167#define LOONGARCH_CSR_TLBRPRMD 0x8f
168FIELD(CSR_TLBRPRMD, PPLV, 0, 2)
169FIELD(CSR_TLBRPRMD, PIE, 2, 1)
170FIELD(CSR_TLBRPRMD, PWE, 4, 1)
171
172
173#define LOONGARCH_CSR_MERRCTL 0x90
174FIELD(CSR_MERRCTL, ISMERR, 0, 1)
175#define LOONGARCH_CSR_MERRINFO1 0x91
176#define LOONGARCH_CSR_MERRINFO2 0x92
177#define LOONGARCH_CSR_MERRENTRY 0x93
178#define LOONGARCH_CSR_MERRERA 0x94
179#define LOONGARCH_CSR_MERRSAVE 0x95
180
181#define LOONGARCH_CSR_CTAG 0x98
182
183
184#define LOONGARCH_CSR_DMW(N) (0x180 + N)
185FIELD(CSR_DMW, PLV0, 0, 1)
186FIELD(CSR_DMW, PLV1, 1, 1)
187FIELD(CSR_DMW, PLV2, 2, 1)
188FIELD(CSR_DMW, PLV3, 3, 1)
189FIELD(CSR_DMW, MAT, 4, 2)
190FIELD(CSR_DMW, VSEG, 60, 4)
191
192#define dmw_va2pa(va) \
193 (va & MAKE_64BIT_MASK(0, TARGET_VIRT_ADDR_SPACE_BITS))
194
195
196#define LOONGARCH_CSR_DBG 0x500
197FIELD(CSR_DBG, DST, 0, 1)
198FIELD(CSR_DBG, DREV, 1, 7)
199FIELD(CSR_DBG, DEI, 8, 1)
200FIELD(CSR_DBG, DCL, 9, 1)
201FIELD(CSR_DBG, DFW, 10, 1)
202FIELD(CSR_DBG, DMW, 11, 1)
203FIELD(CSR_DBG, ECODE, 16, 6)
204
205#define LOONGARCH_CSR_DERA 0x501
206#define LOONGARCH_CSR_DSAVE 0x502
207
208#endif
209