]> git.proxmox.com Git - mirror_qemu.git/blob - target/arm/cpregs.h
6596c2a1233ce1c1375977f718c7781ebc9dcecd
[mirror_qemu.git] / target / arm / cpregs.h
1 /*
2 * QEMU ARM CP Register access and descriptions
3 *
4 * Copyright (c) 2022 Linaro Ltd
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see
18 * <http://www.gnu.org/licenses/gpl-2.0.html>
19 */
20
21 #ifndef TARGET_ARM_CPREGS_H
22 #define TARGET_ARM_CPREGS_H
23
24 /*
25 * ARMCPRegInfo type field bits:
26 */
27 enum {
28 /*
29 * Register must be handled specially during translation.
30 * The method is one of the values below:
31 */
32 ARM_CP_SPECIAL_MASK = 0x000f,
33 /* Special: no change to PE state: writes ignored, reads ignored. */
34 ARM_CP_NOP = 0x0001,
35 /* Special: sysreg is WFI, for v5 and v6. */
36 ARM_CP_WFI = 0x0002,
37 /* Special: sysreg is NZCV. */
38 ARM_CP_NZCV = 0x0003,
39 /* Special: sysreg is CURRENTEL. */
40 ARM_CP_CURRENTEL = 0x0004,
41 /* Special: sysreg is DC ZVA or similar. */
42 ARM_CP_DC_ZVA = 0x0005,
43 ARM_CP_DC_GVA = 0x0006,
44 ARM_CP_DC_GZVA = 0x0007,
45
46 /* Flag: reads produce resetvalue; writes ignored. */
47 ARM_CP_CONST = 1 << 4,
48 /* Flag: For ARM_CP_STATE_AA32, sysreg is 64-bit. */
49 ARM_CP_64BIT = 1 << 5,
50 /*
51 * Flag: TB should not be ended after a write to this register
52 * (the default is that the TB ends after cp writes).
53 */
54 ARM_CP_SUPPRESS_TB_END = 1 << 6,
55 /*
56 * Flag: Permit a register definition to override a previous definition
57 * for the same (cp, is64, crn, crm, opc1, opc2) tuple: either the new
58 * or the old must have the ARM_CP_OVERRIDE bit set.
59 */
60 ARM_CP_OVERRIDE = 1 << 7,
61 /*
62 * Flag: Register is an alias view of some underlying state which is also
63 * visible via another register, and that the other register is handling
64 * migration and reset; registers marked ARM_CP_ALIAS will not be migrated
65 * but may have their state set by syncing of register state from KVM.
66 */
67 ARM_CP_ALIAS = 1 << 8,
68 /*
69 * Flag: Register does I/O and therefore its accesses need to be marked
70 * with gen_io_start() and also end the TB. In particular, registers which
71 * implement clocks or timers require this.
72 */
73 ARM_CP_IO = 1 << 9,
74 /*
75 * Flag: Register has no underlying state and does not support raw access
76 * for state saving/loading; it will not be used for either migration or
77 * KVM state synchronization. Typically this is for "registers" which are
78 * actually used as instructions for cache maintenance and so on.
79 */
80 ARM_CP_NO_RAW = 1 << 10,
81 /*
82 * Flag: The read or write hook might raise an exception; the generated
83 * code will synchronize the CPU state before calling the hook so that it
84 * is safe for the hook to call raise_exception().
85 */
86 ARM_CP_RAISES_EXC = 1 << 11,
87 /*
88 * Flag: Writes to the sysreg might change the exception level - typically
89 * on older ARM chips. For those cases we need to re-read the new el when
90 * recomputing the translation flags.
91 */
92 ARM_CP_NEWEL = 1 << 12,
93 /*
94 * Flag: Access check for this sysreg is identical to accessing FPU state
95 * from an instruction: use translation fp_access_check().
96 */
97 ARM_CP_FPU = 1 << 13,
98 /*
99 * Flag: Access check for this sysreg is identical to accessing SVE state
100 * from an instruction: use translation sve_access_check().
101 */
102 ARM_CP_SVE = 1 << 14,
103 /* Flag: Do not expose in gdb sysreg xml. */
104 ARM_CP_NO_GDB = 1 << 15,
105 /*
106 * Flags: If EL3 but not EL2...
107 * - UNDEF: discard the cpreg,
108 * - KEEP: retain the cpreg as is,
109 * - C_NZ: set const on the cpreg, but retain resetvalue,
110 * - else: set const on the cpreg, zero resetvalue, aka RES0.
111 * See rule RJFFP in section D1.1.3 of DDI0487H.a.
112 */
113 ARM_CP_EL3_NO_EL2_UNDEF = 1 << 16,
114 ARM_CP_EL3_NO_EL2_KEEP = 1 << 17,
115 ARM_CP_EL3_NO_EL2_C_NZ = 1 << 18,
116 /*
117 * Flag: Access check for this sysreg is constrained by the
118 * ARM pseudocode function CheckSMEAccess().
119 */
120 ARM_CP_SME = 1 << 19,
121 };
122
123 /*
124 * Valid values for ARMCPRegInfo state field, indicating which of
125 * the AArch32 and AArch64 execution states this register is visible in.
126 * If the reginfo doesn't explicitly specify then it is AArch32 only.
127 * If the reginfo is declared to be visible in both states then a second
128 * reginfo is synthesised for the AArch32 view of the AArch64 register,
129 * such that the AArch32 view is the lower 32 bits of the AArch64 one.
130 * Note that we rely on the values of these enums as we iterate through
131 * the various states in some places.
132 */
133 typedef enum {
134 ARM_CP_STATE_AA32 = 0,
135 ARM_CP_STATE_AA64 = 1,
136 ARM_CP_STATE_BOTH = 2,
137 } CPState;
138
139 /*
140 * ARM CP register secure state flags. These flags identify security state
141 * attributes for a given CP register entry.
142 * The existence of both or neither secure and non-secure flags indicates that
143 * the register has both a secure and non-secure hash entry. A single one of
144 * these flags causes the register to only be hashed for the specified
145 * security state.
146 * Although definitions may have any combination of the S/NS bits, each
147 * registered entry will only have one to identify whether the entry is secure
148 * or non-secure.
149 */
150 typedef enum {
151 ARM_CP_SECSTATE_BOTH = 0, /* define one cpreg for each secstate */
152 ARM_CP_SECSTATE_S = (1 << 0), /* bit[0]: Secure state register */
153 ARM_CP_SECSTATE_NS = (1 << 1), /* bit[1]: Non-secure state register */
154 } CPSecureState;
155
156 /*
157 * Access rights:
158 * We define bits for Read and Write access for what rev C of the v7-AR ARM ARM
159 * defines as PL0 (user), PL1 (fiq/irq/svc/abt/und/sys, ie privileged), and
160 * PL2 (hyp). The other level which has Read and Write bits is Secure PL1
161 * (ie any of the privileged modes in Secure state, or Monitor mode).
162 * If a register is accessible in one privilege level it's always accessible
163 * in higher privilege levels too. Since "Secure PL1" also follows this rule
164 * (ie anything visible in PL2 is visible in S-PL1, some things are only
165 * visible in S-PL1) but "Secure PL1" is a bit of a mouthful, we bend the
166 * terminology a little and call this PL3.
167 * In AArch64 things are somewhat simpler as the PLx bits line up exactly
168 * with the ELx exception levels.
169 *
170 * If access permissions for a register are more complex than can be
171 * described with these bits, then use a laxer set of restrictions, and
172 * do the more restrictive/complex check inside a helper function.
173 */
174 typedef enum {
175 PL3_R = 0x80,
176 PL3_W = 0x40,
177 PL2_R = 0x20 | PL3_R,
178 PL2_W = 0x10 | PL3_W,
179 PL1_R = 0x08 | PL2_R,
180 PL1_W = 0x04 | PL2_W,
181 PL0_R = 0x02 | PL1_R,
182 PL0_W = 0x01 | PL1_W,
183
184 /*
185 * For user-mode some registers are accessible to EL0 via a kernel
186 * trap-and-emulate ABI. In this case we define the read permissions
187 * as actually being PL0_R. However some bits of any given register
188 * may still be masked.
189 */
190 #ifdef CONFIG_USER_ONLY
191 PL0U_R = PL0_R,
192 #else
193 PL0U_R = PL1_R,
194 #endif
195
196 PL3_RW = PL3_R | PL3_W,
197 PL2_RW = PL2_R | PL2_W,
198 PL1_RW = PL1_R | PL1_W,
199 PL0_RW = PL0_R | PL0_W,
200 } CPAccessRights;
201
202 typedef enum CPAccessResult {
203 /* Access is permitted */
204 CP_ACCESS_OK = 0,
205
206 /*
207 * Combined with one of the following, the low 2 bits indicate the
208 * target exception level. If 0, the exception is taken to the usual
209 * target EL (EL1 or PL1 if in EL0, otherwise to the current EL).
210 */
211 CP_ACCESS_EL_MASK = 3,
212
213 /*
214 * Access fails due to a configurable trap or enable which would
215 * result in a categorized exception syndrome giving information about
216 * the failing instruction (ie syndrome category 0x3, 0x4, 0x5, 0x6,
217 * 0xc or 0x18).
218 */
219 CP_ACCESS_TRAP = (1 << 2),
220 CP_ACCESS_TRAP_EL2 = CP_ACCESS_TRAP | 2,
221 CP_ACCESS_TRAP_EL3 = CP_ACCESS_TRAP | 3,
222
223 /*
224 * Access fails and results in an exception syndrome 0x0 ("uncategorized").
225 * Note that this is not a catch-all case -- the set of cases which may
226 * result in this failure is specifically defined by the architecture.
227 * This trap is always to the usual target EL, never directly to a
228 * specified target EL.
229 */
230 CP_ACCESS_TRAP_UNCATEGORIZED = (2 << 2),
231 } CPAccessResult;
232
233 /* Indexes into fgt_read[] */
234 #define FGTREG_HFGRTR 0
235 #define FGTREG_HDFGRTR 1
236 /* Indexes into fgt_write[] */
237 #define FGTREG_HFGWTR 0
238 #define FGTREG_HDFGWTR 1
239 /* Indexes into fgt_exec[] */
240 #define FGTREG_HFGITR 0
241
242 FIELD(HFGRTR_EL2, AFSR0_EL1, 0, 1)
243 FIELD(HFGRTR_EL2, AFSR1_EL1, 1, 1)
244 FIELD(HFGRTR_EL2, AIDR_EL1, 2, 1)
245 FIELD(HFGRTR_EL2, AMAIR_EL1, 3, 1)
246 FIELD(HFGRTR_EL2, APDAKEY, 4, 1)
247 FIELD(HFGRTR_EL2, APDBKEY, 5, 1)
248 FIELD(HFGRTR_EL2, APGAKEY, 6, 1)
249 FIELD(HFGRTR_EL2, APIAKEY, 7, 1)
250 FIELD(HFGRTR_EL2, APIBKEY, 8, 1)
251 FIELD(HFGRTR_EL2, CCSIDR_EL1, 9, 1)
252 FIELD(HFGRTR_EL2, CLIDR_EL1, 10, 1)
253 FIELD(HFGRTR_EL2, CONTEXTIDR_EL1, 11, 1)
254 FIELD(HFGRTR_EL2, CPACR_EL1, 12, 1)
255 FIELD(HFGRTR_EL2, CSSELR_EL1, 13, 1)
256 FIELD(HFGRTR_EL2, CTR_EL0, 14, 1)
257 FIELD(HFGRTR_EL2, DCZID_EL0, 15, 1)
258 FIELD(HFGRTR_EL2, ESR_EL1, 16, 1)
259 FIELD(HFGRTR_EL2, FAR_EL1, 17, 1)
260 FIELD(HFGRTR_EL2, ISR_EL1, 18, 1)
261 FIELD(HFGRTR_EL2, LORC_EL1, 19, 1)
262 FIELD(HFGRTR_EL2, LOREA_EL1, 20, 1)
263 FIELD(HFGRTR_EL2, LORID_EL1, 21, 1)
264 FIELD(HFGRTR_EL2, LORN_EL1, 22, 1)
265 FIELD(HFGRTR_EL2, LORSA_EL1, 23, 1)
266 FIELD(HFGRTR_EL2, MAIR_EL1, 24, 1)
267 FIELD(HFGRTR_EL2, MIDR_EL1, 25, 1)
268 FIELD(HFGRTR_EL2, MPIDR_EL1, 26, 1)
269 FIELD(HFGRTR_EL2, PAR_EL1, 27, 1)
270 FIELD(HFGRTR_EL2, REVIDR_EL1, 28, 1)
271 FIELD(HFGRTR_EL2, SCTLR_EL1, 29, 1)
272 FIELD(HFGRTR_EL2, SCXTNUM_EL1, 30, 1)
273 FIELD(HFGRTR_EL2, SCXTNUM_EL0, 31, 1)
274 FIELD(HFGRTR_EL2, TCR_EL1, 32, 1)
275 FIELD(HFGRTR_EL2, TPIDR_EL1, 33, 1)
276 FIELD(HFGRTR_EL2, TPIDRRO_EL0, 34, 1)
277 FIELD(HFGRTR_EL2, TPIDR_EL0, 35, 1)
278 FIELD(HFGRTR_EL2, TTBR0_EL1, 36, 1)
279 FIELD(HFGRTR_EL2, TTBR1_EL1, 37, 1)
280 FIELD(HFGRTR_EL2, VBAR_EL1, 38, 1)
281 FIELD(HFGRTR_EL2, ICC_IGRPENN_EL1, 39, 1)
282 FIELD(HFGRTR_EL2, ERRIDR_EL1, 40, 1)
283 FIELD(HFGRTR_EL2, ERRSELR_EL1, 41, 1)
284 FIELD(HFGRTR_EL2, ERXFR_EL1, 42, 1)
285 FIELD(HFGRTR_EL2, ERXCTLR_EL1, 43, 1)
286 FIELD(HFGRTR_EL2, ERXSTATUS_EL1, 44, 1)
287 FIELD(HFGRTR_EL2, ERXMISCN_EL1, 45, 1)
288 FIELD(HFGRTR_EL2, ERXPFGF_EL1, 46, 1)
289 FIELD(HFGRTR_EL2, ERXPFGCTL_EL1, 47, 1)
290 FIELD(HFGRTR_EL2, ERXPFGCDN_EL1, 48, 1)
291 FIELD(HFGRTR_EL2, ERXADDR_EL1, 49, 1)
292 FIELD(HFGRTR_EL2, NACCDATA_EL1, 50, 1)
293 /* 51-53: RES0 */
294 FIELD(HFGRTR_EL2, NSMPRI_EL1, 54, 1)
295 FIELD(HFGRTR_EL2, NTPIDR2_EL0, 55, 1)
296 /* 56-63: RES0 */
297
298 /* These match HFGRTR but bits for RO registers are RES0 */
299 FIELD(HFGWTR_EL2, AFSR0_EL1, 0, 1)
300 FIELD(HFGWTR_EL2, AFSR1_EL1, 1, 1)
301 FIELD(HFGWTR_EL2, AMAIR_EL1, 3, 1)
302 FIELD(HFGWTR_EL2, APDAKEY, 4, 1)
303 FIELD(HFGWTR_EL2, APDBKEY, 5, 1)
304 FIELD(HFGWTR_EL2, APGAKEY, 6, 1)
305 FIELD(HFGWTR_EL2, APIAKEY, 7, 1)
306 FIELD(HFGWTR_EL2, APIBKEY, 8, 1)
307 FIELD(HFGWTR_EL2, CONTEXTIDR_EL1, 11, 1)
308 FIELD(HFGWTR_EL2, CPACR_EL1, 12, 1)
309 FIELD(HFGWTR_EL2, CSSELR_EL1, 13, 1)
310 FIELD(HFGWTR_EL2, ESR_EL1, 16, 1)
311 FIELD(HFGWTR_EL2, FAR_EL1, 17, 1)
312 FIELD(HFGWTR_EL2, LORC_EL1, 19, 1)
313 FIELD(HFGWTR_EL2, LOREA_EL1, 20, 1)
314 FIELD(HFGWTR_EL2, LORN_EL1, 22, 1)
315 FIELD(HFGWTR_EL2, LORSA_EL1, 23, 1)
316 FIELD(HFGWTR_EL2, MAIR_EL1, 24, 1)
317 FIELD(HFGWTR_EL2, PAR_EL1, 27, 1)
318 FIELD(HFGWTR_EL2, SCTLR_EL1, 29, 1)
319 FIELD(HFGWTR_EL2, SCXTNUM_EL1, 30, 1)
320 FIELD(HFGWTR_EL2, SCXTNUM_EL0, 31, 1)
321 FIELD(HFGWTR_EL2, TCR_EL1, 32, 1)
322 FIELD(HFGWTR_EL2, TPIDR_EL1, 33, 1)
323 FIELD(HFGWTR_EL2, TPIDRRO_EL0, 34, 1)
324 FIELD(HFGWTR_EL2, TPIDR_EL0, 35, 1)
325 FIELD(HFGWTR_EL2, TTBR0_EL1, 36, 1)
326 FIELD(HFGWTR_EL2, TTBR1_EL1, 37, 1)
327 FIELD(HFGWTR_EL2, VBAR_EL1, 38, 1)
328 FIELD(HFGWTR_EL2, ICC_IGRPENN_EL1, 39, 1)
329 FIELD(HFGWTR_EL2, ERRSELR_EL1, 41, 1)
330 FIELD(HFGWTR_EL2, ERXCTLR_EL1, 43, 1)
331 FIELD(HFGWTR_EL2, ERXSTATUS_EL1, 44, 1)
332 FIELD(HFGWTR_EL2, ERXMISCN_EL1, 45, 1)
333 FIELD(HFGWTR_EL2, ERXPFGCTL_EL1, 47, 1)
334 FIELD(HFGWTR_EL2, ERXPFGCDN_EL1, 48, 1)
335 FIELD(HFGWTR_EL2, ERXADDR_EL1, 49, 1)
336 FIELD(HFGWTR_EL2, NACCDATA_EL1, 50, 1)
337 FIELD(HFGWTR_EL2, NSMPRI_EL1, 54, 1)
338 FIELD(HFGWTR_EL2, NTPIDR2_EL0, 55, 1)
339
340 FIELD(HFGITR_EL2, ICIALLUIS, 0, 1)
341 FIELD(HFGITR_EL2, ICIALLU, 1, 1)
342 FIELD(HFGITR_EL2, ICIVAU, 2, 1)
343 FIELD(HFGITR_EL2, DCIVAC, 3, 1)
344 FIELD(HFGITR_EL2, DCISW, 4, 1)
345 FIELD(HFGITR_EL2, DCCSW, 5, 1)
346 FIELD(HFGITR_EL2, DCCISW, 6, 1)
347 FIELD(HFGITR_EL2, DCCVAU, 7, 1)
348 FIELD(HFGITR_EL2, DCCVAP, 8, 1)
349 FIELD(HFGITR_EL2, DCCVADP, 9, 1)
350 FIELD(HFGITR_EL2, DCCIVAC, 10, 1)
351 FIELD(HFGITR_EL2, DCZVA, 11, 1)
352 FIELD(HFGITR_EL2, ATS1E1R, 12, 1)
353 FIELD(HFGITR_EL2, ATS1E1W, 13, 1)
354 FIELD(HFGITR_EL2, ATS1E0R, 14, 1)
355 FIELD(HFGITR_EL2, ATS1E0W, 15, 1)
356 FIELD(HFGITR_EL2, ATS1E1RP, 16, 1)
357 FIELD(HFGITR_EL2, ATS1E1WP, 17, 1)
358 FIELD(HFGITR_EL2, TLBIVMALLE1OS, 18, 1)
359 FIELD(HFGITR_EL2, TLBIVAE1OS, 19, 1)
360 FIELD(HFGITR_EL2, TLBIASIDE1OS, 20, 1)
361 FIELD(HFGITR_EL2, TLBIVAAE1OS, 21, 1)
362 FIELD(HFGITR_EL2, TLBIVALE1OS, 22, 1)
363 FIELD(HFGITR_EL2, TLBIVAALE1OS, 23, 1)
364 FIELD(HFGITR_EL2, TLBIRVAE1OS, 24, 1)
365 FIELD(HFGITR_EL2, TLBIRVAAE1OS, 25, 1)
366 FIELD(HFGITR_EL2, TLBIRVALE1OS, 26, 1)
367 FIELD(HFGITR_EL2, TLBIRVAALE1OS, 27, 1)
368 FIELD(HFGITR_EL2, TLBIVMALLE1IS, 28, 1)
369 FIELD(HFGITR_EL2, TLBIVAE1IS, 29, 1)
370 FIELD(HFGITR_EL2, TLBIASIDE1IS, 30, 1)
371 FIELD(HFGITR_EL2, TLBIVAAE1IS, 31, 1)
372 FIELD(HFGITR_EL2, TLBIVALE1IS, 32, 1)
373 FIELD(HFGITR_EL2, TLBIVAALE1IS, 33, 1)
374 FIELD(HFGITR_EL2, TLBIRVAE1IS, 34, 1)
375 FIELD(HFGITR_EL2, TLBIRVAAE1IS, 35, 1)
376 FIELD(HFGITR_EL2, TLBIRVALE1IS, 36, 1)
377 FIELD(HFGITR_EL2, TLBIRVAALE1IS, 37, 1)
378 FIELD(HFGITR_EL2, TLBIRVAE1, 38, 1)
379 FIELD(HFGITR_EL2, TLBIRVAAE1, 39, 1)
380 FIELD(HFGITR_EL2, TLBIRVALE1, 40, 1)
381 FIELD(HFGITR_EL2, TLBIRVAALE1, 41, 1)
382 FIELD(HFGITR_EL2, TLBIVMALLE1, 42, 1)
383 FIELD(HFGITR_EL2, TLBIVAE1, 43, 1)
384 FIELD(HFGITR_EL2, TLBIASIDE1, 44, 1)
385 FIELD(HFGITR_EL2, TLBIVAAE1, 45, 1)
386 FIELD(HFGITR_EL2, TLBIVALE1, 46, 1)
387 FIELD(HFGITR_EL2, TLBIVAALE1, 47, 1)
388 FIELD(HFGITR_EL2, CFPRCTX, 48, 1)
389 FIELD(HFGITR_EL2, DVPRCTX, 49, 1)
390 FIELD(HFGITR_EL2, CPPRCTX, 50, 1)
391 FIELD(HFGITR_EL2, ERET, 51, 1)
392 FIELD(HFGITR_EL2, SVC_EL0, 52, 1)
393 FIELD(HFGITR_EL2, SVC_EL1, 53, 1)
394 FIELD(HFGITR_EL2, DCCVAC, 54, 1)
395 FIELD(HFGITR_EL2, NBRBINJ, 55, 1)
396 FIELD(HFGITR_EL2, NBRBIALL, 56, 1)
397
398 FIELD(HDFGRTR_EL2, DBGBCRN_EL1, 0, 1)
399 FIELD(HDFGRTR_EL2, DBGBVRN_EL1, 1, 1)
400 FIELD(HDFGRTR_EL2, DBGWCRN_EL1, 2, 1)
401 FIELD(HDFGRTR_EL2, DBGWVRN_EL1, 3, 1)
402 FIELD(HDFGRTR_EL2, MDSCR_EL1, 4, 1)
403 FIELD(HDFGRTR_EL2, DBGCLAIM, 5, 1)
404 FIELD(HDFGRTR_EL2, DBGAUTHSTATUS_EL1, 6, 1)
405 FIELD(HDFGRTR_EL2, DBGPRCR_EL1, 7, 1)
406 /* 8: RES0: OSLAR_EL1 is WO */
407 FIELD(HDFGRTR_EL2, OSLSR_EL1, 9, 1)
408 FIELD(HDFGRTR_EL2, OSECCR_EL1, 10, 1)
409 FIELD(HDFGRTR_EL2, OSDLR_EL1, 11, 1)
410 FIELD(HDFGRTR_EL2, PMEVCNTRN_EL0, 12, 1)
411 FIELD(HDFGRTR_EL2, PMEVTYPERN_EL0, 13, 1)
412 FIELD(HDFGRTR_EL2, PMCCFILTR_EL0, 14, 1)
413 FIELD(HDFGRTR_EL2, PMCCNTR_EL0, 15, 1)
414 FIELD(HDFGRTR_EL2, PMCNTEN, 16, 1)
415 FIELD(HDFGRTR_EL2, PMINTEN, 17, 1)
416 FIELD(HDFGRTR_EL2, PMOVS, 18, 1)
417 FIELD(HDFGRTR_EL2, PMSELR_EL0, 19, 1)
418 /* 20: RES0: PMSWINC_EL0 is WO */
419 /* 21: RES0: PMCR_EL0 is WO */
420 FIELD(HDFGRTR_EL2, PMMIR_EL1, 22, 1)
421 FIELD(HDFGRTR_EL2, PMBLIMITR_EL1, 23, 1)
422 FIELD(HDFGRTR_EL2, PMBPTR_EL1, 24, 1)
423 FIELD(HDFGRTR_EL2, PMBSR_EL1, 25, 1)
424 FIELD(HDFGRTR_EL2, PMSCR_EL1, 26, 1)
425 FIELD(HDFGRTR_EL2, PMSEVFR_EL1, 27, 1)
426 FIELD(HDFGRTR_EL2, PMSFCR_EL1, 28, 1)
427 FIELD(HDFGRTR_EL2, PMSICR_EL1, 29, 1)
428 FIELD(HDFGRTR_EL2, PMSIDR_EL1, 30, 1)
429 FIELD(HDFGRTR_EL2, PMSIRR_EL1, 31, 1)
430 FIELD(HDFGRTR_EL2, PMSLATFR_EL1, 32, 1)
431 FIELD(HDFGRTR_EL2, TRC, 33, 1)
432 FIELD(HDFGRTR_EL2, TRCAUTHSTATUS, 34, 1)
433 FIELD(HDFGRTR_EL2, TRCAUXCTLR, 35, 1)
434 FIELD(HDFGRTR_EL2, TRCCLAIM, 36, 1)
435 FIELD(HDFGRTR_EL2, TRCCNTVRn, 37, 1)
436 /* 38, 39: RES0 */
437 FIELD(HDFGRTR_EL2, TRCID, 40, 1)
438 FIELD(HDFGRTR_EL2, TRCIMSPECN, 41, 1)
439 /* 42: RES0: TRCOSLAR is WO */
440 FIELD(HDFGRTR_EL2, TRCOSLSR, 43, 1)
441 FIELD(HDFGRTR_EL2, TRCPRGCTLR, 44, 1)
442 FIELD(HDFGRTR_EL2, TRCSEQSTR, 45, 1)
443 FIELD(HDFGRTR_EL2, TRCSSCSRN, 46, 1)
444 FIELD(HDFGRTR_EL2, TRCSTATR, 47, 1)
445 FIELD(HDFGRTR_EL2, TRCVICTLR, 48, 1)
446 /* 49: RES0: TRFCR_EL1 is WO */
447 FIELD(HDFGRTR_EL2, TRBBASER_EL1, 50, 1)
448 FIELD(HDFGRTR_EL2, TRBIDR_EL1, 51, 1)
449 FIELD(HDFGRTR_EL2, TRBLIMITR_EL1, 52, 1)
450 FIELD(HDFGRTR_EL2, TRBMAR_EL1, 53, 1)
451 FIELD(HDFGRTR_EL2, TRBPTR_EL1, 54, 1)
452 FIELD(HDFGRTR_EL2, TRBSR_EL1, 55, 1)
453 FIELD(HDFGRTR_EL2, TRBTRG_EL1, 56, 1)
454 FIELD(HDFGRTR_EL2, PMUSERENR_EL0, 57, 1)
455 FIELD(HDFGRTR_EL2, PMCEIDN_EL0, 58, 1)
456 FIELD(HDFGRTR_EL2, NBRBIDR, 59, 1)
457 FIELD(HDFGRTR_EL2, NBRBCTL, 60, 1)
458 FIELD(HDFGRTR_EL2, NBRBDATA, 61, 1)
459 FIELD(HDFGRTR_EL2, NPMSNEVFR_EL1, 62, 1)
460 FIELD(HDFGRTR_EL2, PMBIDR_EL1, 63, 1)
461
462 /*
463 * These match HDFGRTR_EL2, but bits for RO registers are RES0.
464 * A few bits are for WO registers, where the HDFGRTR_EL2 bit is RES0.
465 */
466 FIELD(HDFGWTR_EL2, DBGBCRN_EL1, 0, 1)
467 FIELD(HDFGWTR_EL2, DBGBVRN_EL1, 1, 1)
468 FIELD(HDFGWTR_EL2, DBGWCRN_EL1, 2, 1)
469 FIELD(HDFGWTR_EL2, DBGWVRN_EL1, 3, 1)
470 FIELD(HDFGWTR_EL2, MDSCR_EL1, 4, 1)
471 FIELD(HDFGWTR_EL2, DBGCLAIM, 5, 1)
472 FIELD(HDFGWTR_EL2, DBGPRCR_EL1, 7, 1)
473 FIELD(HDFGWTR_EL2, OSLAR_EL1, 8, 1)
474 FIELD(HDFGWTR_EL2, OSLSR_EL1, 9, 1)
475 FIELD(HDFGWTR_EL2, OSECCR_EL1, 10, 1)
476 FIELD(HDFGWTR_EL2, OSDLR_EL1, 11, 1)
477 FIELD(HDFGWTR_EL2, PMEVCNTRN_EL0, 12, 1)
478 FIELD(HDFGWTR_EL2, PMEVTYPERN_EL0, 13, 1)
479 FIELD(HDFGWTR_EL2, PMCCFILTR_EL0, 14, 1)
480 FIELD(HDFGWTR_EL2, PMCCNTR_EL0, 15, 1)
481 FIELD(HDFGWTR_EL2, PMCNTEN, 16, 1)
482 FIELD(HDFGWTR_EL2, PMINTEN, 17, 1)
483 FIELD(HDFGWTR_EL2, PMOVS, 18, 1)
484 FIELD(HDFGWTR_EL2, PMSELR_EL0, 19, 1)
485 FIELD(HDFGWTR_EL2, PMSWINC_EL0, 20, 1)
486 FIELD(HDFGWTR_EL2, PMCR_EL0, 21, 1)
487 FIELD(HDFGWTR_EL2, PMBLIMITR_EL1, 23, 1)
488 FIELD(HDFGWTR_EL2, PMBPTR_EL1, 24, 1)
489 FIELD(HDFGWTR_EL2, PMBSR_EL1, 25, 1)
490 FIELD(HDFGWTR_EL2, PMSCR_EL1, 26, 1)
491 FIELD(HDFGWTR_EL2, PMSEVFR_EL1, 27, 1)
492 FIELD(HDFGWTR_EL2, PMSFCR_EL1, 28, 1)
493 FIELD(HDFGWTR_EL2, PMSICR_EL1, 29, 1)
494 FIELD(HDFGWTR_EL2, PMSIRR_EL1, 31, 1)
495 FIELD(HDFGWTR_EL2, PMSLATFR_EL1, 32, 1)
496 FIELD(HDFGWTR_EL2, TRC, 33, 1)
497 FIELD(HDFGWTR_EL2, TRCAUXCTLR, 35, 1)
498 FIELD(HDFGWTR_EL2, TRCCLAIM, 36, 1)
499 FIELD(HDFGWTR_EL2, TRCCNTVRn, 37, 1)
500 FIELD(HDFGWTR_EL2, TRCIMSPECN, 41, 1)
501 FIELD(HDFGWTR_EL2, TRCOSLAR, 42, 1)
502 FIELD(HDFGWTR_EL2, TRCPRGCTLR, 44, 1)
503 FIELD(HDFGWTR_EL2, TRCSEQSTR, 45, 1)
504 FIELD(HDFGWTR_EL2, TRCSSCSRN, 46, 1)
505 FIELD(HDFGWTR_EL2, TRCVICTLR, 48, 1)
506 FIELD(HDFGWTR_EL2, TRFCR_EL1, 49, 1)
507 FIELD(HDFGWTR_EL2, TRBBASER_EL1, 50, 1)
508 FIELD(HDFGWTR_EL2, TRBLIMITR_EL1, 52, 1)
509 FIELD(HDFGWTR_EL2, TRBMAR_EL1, 53, 1)
510 FIELD(HDFGWTR_EL2, TRBPTR_EL1, 54, 1)
511 FIELD(HDFGWTR_EL2, TRBSR_EL1, 55, 1)
512 FIELD(HDFGWTR_EL2, TRBTRG_EL1, 56, 1)
513 FIELD(HDFGWTR_EL2, PMUSERENR_EL0, 57, 1)
514 FIELD(HDFGWTR_EL2, NBRBCTL, 60, 1)
515 FIELD(HDFGWTR_EL2, NBRBDATA, 61, 1)
516 FIELD(HDFGWTR_EL2, NPMSNEVFR_EL1, 62, 1)
517
518 /* Which fine-grained trap bit register to check, if any */
519 FIELD(FGT, TYPE, 10, 3)
520 FIELD(FGT, REV, 9, 1) /* Is bit sense reversed? */
521 FIELD(FGT, IDX, 6, 3) /* Index within a uint64_t[] array */
522 FIELD(FGT, BITPOS, 0, 6) /* Bit position within the uint64_t */
523
524 /*
525 * Macros to define FGT_##bitname enum constants to use in ARMCPRegInfo::fgt
526 * fields. We assume for brevity's sake that there are no duplicated
527 * bit names across the various FGT registers.
528 */
529 #define DO_BIT(REG, BITNAME) \
530 FGT_##BITNAME = FGT_##REG | R_##REG##_EL2_##BITNAME##_SHIFT
531
532 /* Some bits have reversed sense, so 0 means trap and 1 means not */
533 #define DO_REV_BIT(REG, BITNAME) \
534 FGT_##BITNAME = FGT_##REG | FGT_REV | R_##REG##_EL2_##BITNAME##_SHIFT
535
536 typedef enum FGTBit {
537 /*
538 * These bits tell us which register arrays to use:
539 * if FGT_R is set then reads are checked against fgt_read[];
540 * if FGT_W is set then writes are checked against fgt_write[];
541 * if FGT_EXEC is set then all accesses are checked against fgt_exec[].
542 *
543 * For almost all bits in the R/W register pairs, the bit exists in
544 * both registers for a RW register, in HFGRTR/HDFGRTR for a RO register
545 * with the corresponding HFGWTR/HDFGTWTR bit being RES0, and vice-versa
546 * for a WO register. There are unfortunately a couple of exceptions
547 * (PMCR_EL0, TRFCR_EL1) where the register being trapped is RW but
548 * the FGT system only allows trapping of writes, not reads.
549 *
550 * Note that we arrange these bits so that a 0 FGTBit means "no trap".
551 */
552 FGT_R = 1 << R_FGT_TYPE_SHIFT,
553 FGT_W = 2 << R_FGT_TYPE_SHIFT,
554 FGT_EXEC = 4 << R_FGT_TYPE_SHIFT,
555 FGT_RW = FGT_R | FGT_W,
556 /* Bit to identify whether trap bit is reversed sense */
557 FGT_REV = R_FGT_REV_MASK,
558
559 /*
560 * If a bit exists in HFGRTR/HDFGRTR then either the register being
561 * trapped is RO or the bit also exists in HFGWTR/HDFGWTR, so we either
562 * want to trap for both reads and writes or else it's harmless to mark
563 * it as trap-on-writes.
564 * If a bit exists only in HFGWTR/HDFGWTR then either the register being
565 * trapped is WO, or else it is one of the two oddball special cases
566 * which are RW but have only a write trap. We mark these as only
567 * FGT_W so we get the right behaviour for those special cases.
568 * (If a bit was added in future that provided only a read trap for an
569 * RW register we'd need to do something special to get the FGT_R bit
570 * only. But this seems unlikely to happen.)
571 *
572 * So for the DO_BIT/DO_REV_BIT macros: use FGT_HFGRTR/FGT_HDFGRTR if
573 * the bit exists in that register. Otherwise use FGT_HFGWTR/FGT_HDFGWTR.
574 */
575 FGT_HFGRTR = FGT_RW | (FGTREG_HFGRTR << R_FGT_IDX_SHIFT),
576 FGT_HFGWTR = FGT_W | (FGTREG_HFGWTR << R_FGT_IDX_SHIFT),
577 FGT_HDFGRTR = FGT_RW | (FGTREG_HDFGRTR << R_FGT_IDX_SHIFT),
578 FGT_HDFGWTR = FGT_W | (FGTREG_HDFGWTR << R_FGT_IDX_SHIFT),
579 FGT_HFGITR = FGT_EXEC | (FGTREG_HFGITR << R_FGT_IDX_SHIFT),
580
581 /* Trap bits in HFGRTR_EL2 / HFGWTR_EL2, starting from bit 0. */
582 DO_BIT(HFGRTR, AFSR0_EL1),
583 DO_BIT(HFGRTR, AFSR1_EL1),
584 DO_BIT(HFGRTR, AIDR_EL1),
585 DO_BIT(HFGRTR, AMAIR_EL1),
586 DO_BIT(HFGRTR, APDAKEY),
587 DO_BIT(HFGRTR, APDBKEY),
588 DO_BIT(HFGRTR, APGAKEY),
589 DO_BIT(HFGRTR, APIAKEY),
590 DO_BIT(HFGRTR, APIBKEY),
591 DO_BIT(HFGRTR, CCSIDR_EL1),
592 DO_BIT(HFGRTR, CLIDR_EL1),
593 DO_BIT(HFGRTR, CONTEXTIDR_EL1),
594 DO_BIT(HFGRTR, CPACR_EL1),
595 DO_BIT(HFGRTR, CSSELR_EL1),
596 DO_BIT(HFGRTR, CTR_EL0),
597 DO_BIT(HFGRTR, DCZID_EL0),
598 DO_BIT(HFGRTR, ESR_EL1),
599 DO_BIT(HFGRTR, FAR_EL1),
600 DO_BIT(HFGRTR, ISR_EL1),
601 DO_BIT(HFGRTR, LORC_EL1),
602 DO_BIT(HFGRTR, LOREA_EL1),
603 DO_BIT(HFGRTR, LORID_EL1),
604 DO_BIT(HFGRTR, LORN_EL1),
605 DO_BIT(HFGRTR, LORSA_EL1),
606 DO_BIT(HFGRTR, MAIR_EL1),
607 DO_BIT(HFGRTR, MIDR_EL1),
608 DO_BIT(HFGRTR, MPIDR_EL1),
609 DO_BIT(HFGRTR, PAR_EL1),
610 DO_BIT(HFGRTR, REVIDR_EL1),
611 DO_BIT(HFGRTR, SCTLR_EL1),
612 DO_BIT(HFGRTR, SCXTNUM_EL1),
613 DO_BIT(HFGRTR, SCXTNUM_EL0),
614 DO_BIT(HFGRTR, TCR_EL1),
615 DO_BIT(HFGRTR, TPIDR_EL1),
616 DO_BIT(HFGRTR, TPIDRRO_EL0),
617 DO_BIT(HFGRTR, TPIDR_EL0),
618 DO_BIT(HFGRTR, TTBR0_EL1),
619 DO_BIT(HFGRTR, TTBR1_EL1),
620 DO_BIT(HFGRTR, VBAR_EL1),
621 DO_BIT(HFGRTR, ICC_IGRPENN_EL1),
622 DO_BIT(HFGRTR, ERRIDR_EL1),
623 DO_REV_BIT(HFGRTR, NSMPRI_EL1),
624 DO_REV_BIT(HFGRTR, NTPIDR2_EL0),
625
626 /* Trap bits in HDFGRTR_EL2 / HDFGWTR_EL2, starting from bit 0. */
627 DO_BIT(HDFGRTR, DBGBCRN_EL1),
628 DO_BIT(HDFGRTR, DBGBVRN_EL1),
629 DO_BIT(HDFGRTR, DBGWCRN_EL1),
630 DO_BIT(HDFGRTR, DBGWVRN_EL1),
631 DO_BIT(HDFGRTR, MDSCR_EL1),
632 DO_BIT(HDFGRTR, DBGCLAIM),
633 DO_BIT(HDFGWTR, OSLAR_EL1),
634 DO_BIT(HDFGRTR, OSLSR_EL1),
635 DO_BIT(HDFGRTR, OSECCR_EL1),
636 DO_BIT(HDFGRTR, OSDLR_EL1),
637 DO_BIT(HDFGRTR, PMEVCNTRN_EL0),
638 DO_BIT(HDFGRTR, PMEVTYPERN_EL0),
639 DO_BIT(HDFGRTR, PMCCFILTR_EL0),
640 DO_BIT(HDFGRTR, PMCCNTR_EL0),
641 DO_BIT(HDFGRTR, PMCNTEN),
642 DO_BIT(HDFGRTR, PMINTEN),
643 DO_BIT(HDFGRTR, PMOVS),
644 DO_BIT(HDFGRTR, PMSELR_EL0),
645 DO_BIT(HDFGWTR, PMSWINC_EL0),
646 DO_BIT(HDFGWTR, PMCR_EL0),
647 DO_BIT(HDFGRTR, PMMIR_EL1),
648 DO_BIT(HDFGRTR, PMCEIDN_EL0),
649
650 /* Trap bits in HFGITR_EL2, starting from bit 0 */
651 DO_BIT(HFGITR, ICIALLUIS),
652 DO_BIT(HFGITR, ICIALLU),
653 DO_BIT(HFGITR, ICIVAU),
654 DO_BIT(HFGITR, DCIVAC),
655 DO_BIT(HFGITR, DCISW),
656 DO_BIT(HFGITR, DCCSW),
657 DO_BIT(HFGITR, DCCISW),
658 DO_BIT(HFGITR, DCCVAU),
659 DO_BIT(HFGITR, DCCVAP),
660 DO_BIT(HFGITR, DCCVADP),
661 DO_BIT(HFGITR, DCCIVAC),
662 DO_BIT(HFGITR, DCZVA),
663 } FGTBit;
664
665 #undef DO_BIT
666 #undef DO_REV_BIT
667
668 typedef struct ARMCPRegInfo ARMCPRegInfo;
669
670 /*
671 * Access functions for coprocessor registers. These cannot fail and
672 * may not raise exceptions.
673 */
674 typedef uint64_t CPReadFn(CPUARMState *env, const ARMCPRegInfo *opaque);
675 typedef void CPWriteFn(CPUARMState *env, const ARMCPRegInfo *opaque,
676 uint64_t value);
677 /* Access permission check functions for coprocessor registers. */
678 typedef CPAccessResult CPAccessFn(CPUARMState *env,
679 const ARMCPRegInfo *opaque,
680 bool isread);
681 /* Hook function for register reset */
682 typedef void CPResetFn(CPUARMState *env, const ARMCPRegInfo *opaque);
683
684 #define CP_ANY 0xff
685
686 /* Definition of an ARM coprocessor register */
687 struct ARMCPRegInfo {
688 /* Name of register (useful mainly for debugging, need not be unique) */
689 const char *name;
690 /*
691 * Location of register: coprocessor number and (crn,crm,opc1,opc2)
692 * tuple. Any of crm, opc1 and opc2 may be CP_ANY to indicate a
693 * 'wildcard' field -- any value of that field in the MRC/MCR insn
694 * will be decoded to this register. The register read and write
695 * callbacks will be passed an ARMCPRegInfo with the crn/crm/opc1/opc2
696 * used by the program, so it is possible to register a wildcard and
697 * then behave differently on read/write if necessary.
698 * For 64 bit registers, only crm and opc1 are relevant; crn and opc2
699 * must both be zero.
700 * For AArch64-visible registers, opc0 is also used.
701 * Since there are no "coprocessors" in AArch64, cp is purely used as a
702 * way to distinguish (for KVM's benefit) guest-visible system registers
703 * from demuxed ones provided to preserve the "no side effects on
704 * KVM register read/write from QEMU" semantics. cp==0x13 is guest
705 * visible (to match KVM's encoding); cp==0 will be converted to
706 * cp==0x13 when the ARMCPRegInfo is registered, for convenience.
707 */
708 uint8_t cp;
709 uint8_t crn;
710 uint8_t crm;
711 uint8_t opc0;
712 uint8_t opc1;
713 uint8_t opc2;
714 /* Execution state in which this register is visible: ARM_CP_STATE_* */
715 CPState state;
716 /* Register type: ARM_CP_* bits/values */
717 int type;
718 /* Access rights: PL*_[RW] */
719 CPAccessRights access;
720 /* Security state: ARM_CP_SECSTATE_* bits/values */
721 CPSecureState secure;
722 /*
723 * Which fine-grained trap register bit to check, if any. This
724 * value encodes both the trap register and bit within it.
725 */
726 FGTBit fgt;
727 /*
728 * The opaque pointer passed to define_arm_cp_regs_with_opaque() when
729 * this register was defined: can be used to hand data through to the
730 * register read/write functions, since they are passed the ARMCPRegInfo*.
731 */
732 void *opaque;
733 /*
734 * Value of this register, if it is ARM_CP_CONST. Otherwise, if
735 * fieldoffset is non-zero, the reset value of the register.
736 */
737 uint64_t resetvalue;
738 /*
739 * Offset of the field in CPUARMState for this register.
740 * This is not needed if either:
741 * 1. type is ARM_CP_CONST or one of the ARM_CP_SPECIALs
742 * 2. both readfn and writefn are specified
743 */
744 ptrdiff_t fieldoffset; /* offsetof(CPUARMState, field) */
745
746 /*
747 * Offsets of the secure and non-secure fields in CPUARMState for the
748 * register if it is banked. These fields are only used during the static
749 * registration of a register. During hashing the bank associated
750 * with a given security state is copied to fieldoffset which is used from
751 * there on out.
752 *
753 * It is expected that register definitions use either fieldoffset or
754 * bank_fieldoffsets in the definition but not both. It is also expected
755 * that both bank offsets are set when defining a banked register. This
756 * use indicates that a register is banked.
757 */
758 ptrdiff_t bank_fieldoffsets[2];
759
760 /*
761 * Function for making any access checks for this register in addition to
762 * those specified by the 'access' permissions bits. If NULL, no extra
763 * checks required. The access check is performed at runtime, not at
764 * translate time.
765 */
766 CPAccessFn *accessfn;
767 /*
768 * Function for handling reads of this register. If NULL, then reads
769 * will be done by loading from the offset into CPUARMState specified
770 * by fieldoffset.
771 */
772 CPReadFn *readfn;
773 /*
774 * Function for handling writes of this register. If NULL, then writes
775 * will be done by writing to the offset into CPUARMState specified
776 * by fieldoffset.
777 */
778 CPWriteFn *writefn;
779 /*
780 * Function for doing a "raw" read; used when we need to copy
781 * coprocessor state to the kernel for KVM or out for
782 * migration. This only needs to be provided if there is also a
783 * readfn and it has side effects (for instance clear-on-read bits).
784 */
785 CPReadFn *raw_readfn;
786 /*
787 * Function for doing a "raw" write; used when we need to copy KVM
788 * kernel coprocessor state into userspace, or for inbound
789 * migration. This only needs to be provided if there is also a
790 * writefn and it masks out "unwritable" bits or has write-one-to-clear
791 * or similar behaviour.
792 */
793 CPWriteFn *raw_writefn;
794 /*
795 * Function for resetting the register. If NULL, then reset will be done
796 * by writing resetvalue to the field specified in fieldoffset. If
797 * fieldoffset is 0 then no reset will be done.
798 */
799 CPResetFn *resetfn;
800
801 /*
802 * "Original" writefn and readfn.
803 * For ARMv8.1-VHE register aliases, we overwrite the read/write
804 * accessor functions of various EL1/EL0 to perform the runtime
805 * check for which sysreg should actually be modified, and then
806 * forwards the operation. Before overwriting the accessors,
807 * the original function is copied here, so that accesses that
808 * really do go to the EL1/EL0 version proceed normally.
809 * (The corresponding EL2 register is linked via opaque.)
810 */
811 CPReadFn *orig_readfn;
812 CPWriteFn *orig_writefn;
813 };
814
815 /*
816 * Macros which are lvalues for the field in CPUARMState for the
817 * ARMCPRegInfo *ri.
818 */
819 #define CPREG_FIELD32(env, ri) \
820 (*(uint32_t *)((char *)(env) + (ri)->fieldoffset))
821 #define CPREG_FIELD64(env, ri) \
822 (*(uint64_t *)((char *)(env) + (ri)->fieldoffset))
823
824 void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, const ARMCPRegInfo *reg,
825 void *opaque);
826
827 static inline void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *regs)
828 {
829 define_one_arm_cp_reg_with_opaque(cpu, regs, NULL);
830 }
831
832 void define_arm_cp_regs_with_opaque_len(ARMCPU *cpu, const ARMCPRegInfo *regs,
833 void *opaque, size_t len);
834
835 #define define_arm_cp_regs_with_opaque(CPU, REGS, OPAQUE) \
836 do { \
837 QEMU_BUILD_BUG_ON(ARRAY_SIZE(REGS) == 0); \
838 define_arm_cp_regs_with_opaque_len(CPU, REGS, OPAQUE, \
839 ARRAY_SIZE(REGS)); \
840 } while (0)
841
842 #define define_arm_cp_regs(CPU, REGS) \
843 define_arm_cp_regs_with_opaque(CPU, REGS, NULL)
844
845 const ARMCPRegInfo *get_arm_cp_reginfo(GHashTable *cpregs, uint32_t encoded_cp);
846
847 /*
848 * Definition of an ARM co-processor register as viewed from
849 * userspace. This is used for presenting sanitised versions of
850 * registers to userspace when emulating the Linux AArch64 CPU
851 * ID/feature ABI (advertised as HWCAP_CPUID).
852 */
853 typedef struct ARMCPRegUserSpaceInfo {
854 /* Name of register */
855 const char *name;
856
857 /* Is the name actually a glob pattern */
858 bool is_glob;
859
860 /* Only some bits are exported to user space */
861 uint64_t exported_bits;
862
863 /* Fixed bits are applied after the mask */
864 uint64_t fixed_bits;
865 } ARMCPRegUserSpaceInfo;
866
867 void modify_arm_cp_regs_with_len(ARMCPRegInfo *regs, size_t regs_len,
868 const ARMCPRegUserSpaceInfo *mods,
869 size_t mods_len);
870
871 #define modify_arm_cp_regs(REGS, MODS) \
872 do { \
873 QEMU_BUILD_BUG_ON(ARRAY_SIZE(REGS) == 0); \
874 QEMU_BUILD_BUG_ON(ARRAY_SIZE(MODS) == 0); \
875 modify_arm_cp_regs_with_len(REGS, ARRAY_SIZE(REGS), \
876 MODS, ARRAY_SIZE(MODS)); \
877 } while (0)
878
879 /* CPWriteFn that can be used to implement writes-ignored behaviour */
880 void arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri,
881 uint64_t value);
882 /* CPReadFn that can be used for read-as-zero behaviour */
883 uint64_t arm_cp_read_zero(CPUARMState *env, const ARMCPRegInfo *ri);
884
885 /* CPWriteFn that just writes the value to ri->fieldoffset */
886 void raw_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value);
887
888 /*
889 * CPResetFn that does nothing, for use if no reset is required even
890 * if fieldoffset is non zero.
891 */
892 void arm_cp_reset_ignore(CPUARMState *env, const ARMCPRegInfo *opaque);
893
894 /*
895 * Return true if this reginfo struct's field in the cpu state struct
896 * is 64 bits wide.
897 */
898 static inline bool cpreg_field_is_64bit(const ARMCPRegInfo *ri)
899 {
900 return (ri->state == ARM_CP_STATE_AA64) || (ri->type & ARM_CP_64BIT);
901 }
902
903 static inline bool cp_access_ok(int current_el,
904 const ARMCPRegInfo *ri, int isread)
905 {
906 return (ri->access >> ((current_el * 2) + isread)) & 1;
907 }
908
909 /* Raw read of a coprocessor register (as needed for migration, etc) */
910 uint64_t read_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri);
911
912 /*
913 * Return true if the cp register encoding is in the "feature ID space" as
914 * defined by FEAT_IDST (and thus should be reported with ER_ELx.EC
915 * as EC_SYSTEMREGISTERTRAP rather than EC_UNCATEGORIZED).
916 */
917 static inline bool arm_cpreg_encoding_in_idspace(uint8_t opc0, uint8_t opc1,
918 uint8_t opc2,
919 uint8_t crn, uint8_t crm)
920 {
921 return opc0 == 3 && (opc1 == 0 || opc1 == 1 || opc1 == 3) &&
922 crn == 0 && crm < 8;
923 }
924
925 /*
926 * As arm_cpreg_encoding_in_idspace(), but take the encoding from an
927 * ARMCPRegInfo.
928 */
929 static inline bool arm_cpreg_in_idspace(const ARMCPRegInfo *ri)
930 {
931 return ri->state == ARM_CP_STATE_AA64 &&
932 arm_cpreg_encoding_in_idspace(ri->opc0, ri->opc1, ri->opc2,
933 ri->crn, ri->crm);
934 }
935
936 #endif /* TARGET_ARM_CPREGS_H */