1*bef6a77fSGustavo Romero /*
2*bef6a77fSGustavo Romero * ARM MemTag convenience functions.
3*bef6a77fSGustavo Romero *
4*bef6a77fSGustavo Romero * This code is licensed under the GNU GPL v2 or later.
5*bef6a77fSGustavo Romero *
6*bef6a77fSGustavo Romero * SPDX-License-Identifier: LGPL-2.1-or-later
7*bef6a77fSGustavo Romero */
8*bef6a77fSGustavo Romero
9*bef6a77fSGustavo Romero #include "qemu/osdep.h"
10*bef6a77fSGustavo Romero #include "qemu.h"
11*bef6a77fSGustavo Romero #include "mte_user_helper.h"
12*bef6a77fSGustavo Romero
arm_set_mte_tcf0(CPUArchState * env,abi_long value)13*bef6a77fSGustavo Romero void arm_set_mte_tcf0(CPUArchState *env, abi_long value)
14*bef6a77fSGustavo Romero {
15*bef6a77fSGustavo Romero /*
16*bef6a77fSGustavo Romero * Write PR_MTE_TCF to SCTLR_EL1[TCF0].
17*bef6a77fSGustavo Romero *
18*bef6a77fSGustavo Romero * The kernel has a per-cpu configuration for the sysadmin,
19*bef6a77fSGustavo Romero * /sys/devices/system/cpu/cpu<N>/mte_tcf_preferred,
20*bef6a77fSGustavo Romero * which qemu does not implement.
21*bef6a77fSGustavo Romero *
22*bef6a77fSGustavo Romero * Because there is no performance difference between the modes, and
23*bef6a77fSGustavo Romero * because SYNC is most useful for debugging MTE errors, choose SYNC
24*bef6a77fSGustavo Romero * as the preferred mode. With this preference, and the way the API
25*bef6a77fSGustavo Romero * uses only two bits, there is no way for the program to select
26*bef6a77fSGustavo Romero * ASYMM mode.
27*bef6a77fSGustavo Romero */
28*bef6a77fSGustavo Romero unsigned tcf = 0;
29*bef6a77fSGustavo Romero if (value & PR_MTE_TCF_SYNC) {
30*bef6a77fSGustavo Romero tcf = 1;
31*bef6a77fSGustavo Romero } else if (value & PR_MTE_TCF_ASYNC) {
32*bef6a77fSGustavo Romero tcf = 2;
33*bef6a77fSGustavo Romero }
34*bef6a77fSGustavo Romero env->cp15.sctlr_el[1] = deposit64(env->cp15.sctlr_el[1], 38, 2, tcf);
35*bef6a77fSGustavo Romero }
36